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
1,501
0
https://github.com/openssl/openssl/blob/9b340281873643d2b8a33047dc8bfa607f7e0c3c/crypto/lhash/lhash.c/#L191
static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg, OPENSSL_LH_DOALL_FUNC func, OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg) { int i; OPENSSL_LH_NODE *a, *n; if (lh == NULL) return; for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { n = a->next; if (use_arg) func_arg(a->data, arg); else func(a->data); a = n; } } }
['static int test_custom_exts(int tst)\n{\n SSL_CTX *cctx = NULL, *sctx = NULL, *sctx2 = NULL;\n SSL *clientssl = NULL, *serverssl = NULL;\n int testresult = 0;\n static int server = 1;\n static int client = 0;\n SSL_SESSION *sess = NULL;\n unsigned int context;\n#if defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_TLS1_3)\n if (tst < 3)\n return 1;\n#endif\n clntaddoldcb = clntparseoldcb = srvaddoldcb = srvparseoldcb = 0;\n clntaddnewcb = clntparsenewcb = srvaddnewcb = srvparsenewcb = 0;\n snicb = 0;\n if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),\n TLS1_VERSION, TLS_MAX_VERSION,\n &sctx, &cctx, cert, privkey)))\n goto end;\n if (tst == 2\n && !TEST_true(create_ssl_ctx_pair(TLS_server_method(), NULL,\n TLS1_VERSION, TLS_MAX_VERSION,\n &sctx2, NULL, cert, privkey)))\n goto end;\n if (tst < 3) {\n SSL_CTX_set_options(cctx, SSL_OP_NO_TLSv1_3);\n SSL_CTX_set_options(sctx, SSL_OP_NO_TLSv1_3);\n if (sctx2 != NULL)\n SSL_CTX_set_options(sctx2, SSL_OP_NO_TLSv1_3);\n }\n if (tst == 4) {\n context = SSL_EXT_CLIENT_HELLO\n | SSL_EXT_TLS1_2_SERVER_HELLO\n | SSL_EXT_TLS1_3_SERVER_HELLO\n | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS\n | SSL_EXT_TLS1_3_CERTIFICATE\n | SSL_EXT_TLS1_3_NEW_SESSION_TICKET;\n } else {\n context = SSL_EXT_CLIENT_HELLO\n | SSL_EXT_TLS1_2_SERVER_HELLO\n | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS;\n }\n if (tst == 0) {\n if (!TEST_true(SSL_CTX_add_client_custom_ext(cctx, TEST_EXT_TYPE1,\n old_add_cb, old_free_cb,\n &client, old_parse_cb,\n &client)))\n goto end;\n } else {\n if (!TEST_true(SSL_CTX_add_custom_ext(cctx, TEST_EXT_TYPE1, context,\n new_add_cb, new_free_cb,\n &client, new_parse_cb, &client)))\n goto end;\n }\n if (!TEST_false(SSL_CTX_add_client_custom_ext(cctx, TEST_EXT_TYPE1,\n old_add_cb, old_free_cb,\n &client, old_parse_cb,\n &client))\n || !TEST_false(SSL_CTX_add_custom_ext(cctx, TEST_EXT_TYPE1,\n context, new_add_cb,\n new_free_cb, &client,\n new_parse_cb, &client)))\n goto end;\n if (tst == 0) {\n if (!TEST_true(SSL_CTX_add_server_custom_ext(sctx, TEST_EXT_TYPE1,\n old_add_cb, old_free_cb,\n &server, old_parse_cb,\n &server)))\n goto end;\n } else {\n if (!TEST_true(SSL_CTX_add_custom_ext(sctx, TEST_EXT_TYPE1, context,\n new_add_cb, new_free_cb,\n &server, new_parse_cb, &server)))\n goto end;\n if (sctx2 != NULL\n && !TEST_true(SSL_CTX_add_custom_ext(sctx2, TEST_EXT_TYPE1,\n context, new_add_cb,\n new_free_cb, &server,\n new_parse_cb, &server)))\n goto end;\n }\n if (!TEST_false(SSL_CTX_add_server_custom_ext(sctx, TEST_EXT_TYPE1,\n old_add_cb, old_free_cb,\n &server, old_parse_cb,\n &server))\n || !TEST_false(SSL_CTX_add_custom_ext(sctx, TEST_EXT_TYPE1,\n context, new_add_cb,\n new_free_cb, &server,\n new_parse_cb, &server)))\n goto end;\n if (tst == 2) {\n if (!TEST_true(SSL_CTX_set_tlsext_servername_callback(sctx, sni_cb))\n || !TEST_true(SSL_CTX_set_tlsext_servername_arg(sctx, sctx2)))\n goto end;\n }\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl,\n &clientssl, NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl, clientssl,\n SSL_ERROR_NONE)))\n goto end;\n if (tst == 0) {\n if (clntaddoldcb != 1\n || clntparseoldcb != 1\n || srvaddoldcb != 1\n || srvparseoldcb != 1)\n goto end;\n } else if (tst == 1 || tst == 2 || tst == 3) {\n if (clntaddnewcb != 1\n || clntparsenewcb != 1\n || srvaddnewcb != 1\n || srvparsenewcb != 1\n || (tst != 2 && snicb != 0)\n || (tst == 2 && snicb != 1))\n goto end;\n } else {\n if (clntaddnewcb != 1\n || clntparsenewcb != 5\n || srvaddnewcb != 5\n || srvparsenewcb != 1)\n goto end;\n }\n sess = SSL_get1_session(clientssl);\n SSL_shutdown(clientssl);\n SSL_shutdown(serverssl);\n SSL_free(serverssl);\n SSL_free(clientssl);\n serverssl = clientssl = NULL;\n if (tst == 3) {\n testresult = 1;\n goto end;\n }\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,\n NULL, NULL))\n || !TEST_true(SSL_set_session(clientssl, sess))\n || !TEST_true(create_ssl_connection(serverssl, clientssl,\n SSL_ERROR_NONE)))\n goto end;\n if (tst == 0) {\n if (clntaddoldcb != 2\n || clntparseoldcb != 1\n || srvaddoldcb != 1\n || srvparseoldcb != 1)\n goto end;\n } else if (tst == 1 || tst == 2 || tst == 3) {\n if (clntaddnewcb != 2\n || clntparsenewcb != 2\n || srvaddnewcb != 2\n || srvparsenewcb != 2)\n goto end;\n } else {\n if (clntaddnewcb != 2\n || clntparsenewcb != 8\n || srvaddnewcb != 8\n || srvparsenewcb != 2)\n goto end;\n }\n testresult = 1;\nend:\n SSL_SESSION_free(sess);\n SSL_free(serverssl);\n SSL_free(clientssl);\n SSL_CTX_free(sctx2);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl != NULL)\n serverssl = *sssl;\n else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n goto error;\n if (*cssl != NULL)\n clientssl = *cssl;\n else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n goto error;\n if (SSL_is_dtls(clientssl)) {\n if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n goto error;\n } else {\n if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n goto error;\n }\n if (s_to_c_fbio != NULL\n && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n goto error;\n if (c_to_s_fbio != NULL\n && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n goto error;\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return NULL;\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return NULL;\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->references = 1;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n OPENSSL_free(s);\n s = NULL;\n goto err;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->max_early_data = ctx->max_early_data;\n s->recv_max_early_data = ctx->recv_max_early_data;\n s->num_tickets = ctx->num_tickets;\n s->pha_enabled = ctx->pha_enabled;\n s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n if (s->tls13_ciphersuites == NULL)\n goto err;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n s->allow_early_data_cb = ctx->allow_early_data_cb;\n s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(a->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n OPENSSL_secure_free(a->ext.secure);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
1,502
0
https://github.com/openssl/openssl/blob/8fa6a40be2935ca109a28cc43d28cd27051ada01/crypto/bn/bn_add.c/#L230
int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) { int max,min,dif; register BN_ULONG t1,t2,*ap,*bp,*rp; int i,carry; #if defined(IRIX_CC_BUG) && !defined(LINT) int dummy; #endif bn_check_top(a); bn_check_top(b); max = a->top; min = b->top; dif = max - min; if (dif < 0) { BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); return(0); } if (bn_wexpand(r,max) == NULL) return(0); ap=a->d; bp=b->d; rp=r->d; #if 1 carry=0; for (i = min; i != 0; i--) { t1= *(ap++); t2= *(bp++); if (carry) { carry=(t1 <= t2); t1=(t1-t2-1)&BN_MASK2; } else { carry=(t1 < t2); t1=(t1-t2)&BN_MASK2; } #if defined(IRIX_CC_BUG) && !defined(LINT) dummy=t1; #endif *(rp++)=t1&BN_MASK2; } #else carry=bn_sub_words(rp,ap,bp,min); ap+=min; bp+=min; rp+=min; #endif if (carry) { if (!dif) return 0; while (dif) { dif--; t1 = *(ap++); t2 = (t1-1)&BN_MASK2; *(rp++) = t2; if (t1) break; } } #if 0 memcpy(rp,ap,sizeof(*rp)*(max-i)); #else if (rp != ap) { for (;;) { if (!dif--) break; rp[0]=ap[0]; if (!dif--) break; rp[1]=ap[1]; if (!dif--) break; rp[2]=ap[2]; if (!dif--) break; rp[3]=ap[3]; rp+=4; ap+=4; } } #endif r->top=max; r->neg=0; bn_correct_top(r); return(1); }
['int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n\tBN_RECP_CTX *recp, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\tconst BIGNUM *ca;\n\tBN_CTX_start(ctx);\n\tif ((a = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\tca = a;\n\t\t}\n\telse\n\t\tca=x;\n\tret = BN_div_recp(NULL,r,ca,recp,ctx);\nerr:\n\tBN_CTX_end(ctx);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n\tBN_RECP_CTX *recp, BN_CTX *ctx)\n\t{\n\tint i,j,ret=0;\n\tBIGNUM *a,*b,*d,*r;\n\tBN_CTX_start(ctx);\n\ta=BN_CTX_get(ctx);\n\tb=BN_CTX_get(ctx);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td=BN_CTX_get(ctx);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr=BN_CTX_get(ctx);\n\tif (a == NULL || b == NULL || d == NULL || r == NULL) goto err;\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tif (!BN_copy(r,m)) return 0;\n\t\tBN_CTX_end(ctx);\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits<<1;\n\tif (j>i) i=j;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (recp->shift == -1) goto err;\n\tif (!BN_rshift(a,m,recp->num_bits)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,i-recp->num_bits)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n#if 1\n\tj=0;\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tif(dv) bn_check_top(dv);\n\tif(rem) bn_check_top(rem);\n\treturn(ret);\n\t}', 'int BN_ucmp(const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG t1,t2,*ap,*bp;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\ti=a->top-b->top;\n\tif (i != 0) return(i);\n\tap=a->d;\n\tbp=b->d;\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tt1= ap[i];\n\t\tt2= bp[i];\n\t\tif (t1 != t2)\n\t\t\treturn((t1 > t2) ? 1 : -1);\n\t\t}\n\treturn(0);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint max,min,dif;\n\tregister BN_ULONG t1,t2,*ap,*bp,*rp;\n\tint i,carry;\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\tint dummy;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tmax = a->top;\n\tmin = b->top;\n\tdif = max - min;\n\tif (dif < 0)\n\t\t{\n\t\tBNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);\n\t\treturn(0);\n\t\t}\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n#if 1\n\tcarry=0;\n\tfor (i = min; i != 0; i--)\n\t\t{\n\t\tt1= *(ap++);\n\t\tt2= *(bp++);\n\t\tif (carry)\n\t\t\t{\n\t\t\tcarry=(t1 <= t2);\n\t\t\tt1=(t1-t2-1)&BN_MASK2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tcarry=(t1 < t2);\n\t\t\tt1=(t1-t2)&BN_MASK2;\n\t\t\t}\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\t\tdummy=t1;\n#endif\n\t\t*(rp++)=t1&BN_MASK2;\n\t\t}\n#else\n\tcarry=bn_sub_words(rp,ap,bp,min);\n\tap+=min;\n\tbp+=min;\n\trp+=min;\n#endif\n\tif (carry)\n\t\t{\n\t\tif (!dif)\n\t\t\treturn 0;\n\t\twhile (dif)\n\t\t\t{\n\t\t\tdif--;\n\t\t\tt1 = *(ap++);\n\t\t\tt2 = (t1-1)&BN_MASK2;\n\t\t\t*(rp++) = t2;\n\t\t\tif (t1)\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n#if 0\n\tmemcpy(rp,ap,sizeof(*rp)*(max-i));\n#else\n\tif (rp != ap)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (!dif--) break;\n\t\t\trp[0]=ap[0];\n\t\t\tif (!dif--) break;\n\t\t\trp[1]=ap[1];\n\t\t\tif (!dif--) break;\n\t\t\trp[2]=ap[2];\n\t\t\tif (!dif--) break;\n\t\t\trp[3]=ap[3];\n\t\t\trp+=4;\n\t\t\tap+=4;\n\t\t\t}\n\t\t}\n#endif\n\tr->top=max;\n\tr->neg=0;\n\tbn_correct_top(r);\n\treturn(1);\n\t}']
1,503
0
https://github.com/libav/libav/blob/0ebe3b8e2bf74503d7c9cc383e29254a3cb06d55/ffmpeg.c/#L3341
static void opt_output_file(const char *filename) { AVFormatContext *oc; int use_video, use_audio, use_subtitle; int input_has_video, input_has_audio, input_has_subtitle; AVFormatParameters params, *ap = &params; if (!strcmp(filename, "-")) filename = "pipe:"; oc = avformat_alloc_context(); if (!file_oformat) { file_oformat = guess_format(NULL, filename, NULL); if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); av_exit(1); } } oc->oformat = file_oformat; av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && av_strstart(filename, "http:", NULL)) { int err = read_ffserver_streams(oc, filename); if (err < 0) { print_error(filename, err); av_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; if (nb_input_files > 0) { check_audio_video_sub_inputs(&input_has_video, &input_has_audio, &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; if (!input_has_subtitle) use_subtitle = 0; } if (audio_disable) { use_audio = 0; } if (video_disable) { use_video = 0; } if (subtitle_disable) { use_subtitle = 0; } if (use_video) { new_video_stream(oc); } if (use_audio) { new_audio_stream(oc); } if (use_subtitle) { new_subtitle_stream(oc); } oc->timestamp = rec_timestamp; for(; metadata_count>0; metadata_count--){ av_metadata_set(&oc->metadata, metadata[metadata_count-1].key, metadata[metadata_count-1].value); } av_metadata_conv(oc, oc->oformat->metadata_conv, NULL); } output_files[nb_output_files++] = oc; if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR_NUMEXPECTED); av_exit(1); } } if (!(oc->oformat->flags & AVFMT_NOFILE)) { if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (url_exist(filename)) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); av_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); av_exit(1); } } } if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { fprintf(stderr, "Could not open '%s'\n", filename); av_exit(1); } } memset(ap, 0, sizeof(*ap)); if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); av_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->loop_output = loop_output; oc->flags |= AVFMT_FLAG_NONBLOCK; set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM); file_oformat = NULL; file_iformat = NULL; }
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = &params;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!file_oformat) {\n file_oformat = guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n av_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) {\n use_audio = 0;\n }\n if (video_disable) {\n use_video = 0;\n }\n if (subtitle_disable) {\n use_subtitle = 0;\n }\n if (use_video) {\n new_video_stream(oc);\n }\n if (use_audio) {\n new_audio_stream(oc);\n }\n if (use_subtitle) {\n new_subtitle_stream(oc);\n }\n oc->timestamp = rec_timestamp;\n for(; metadata_count>0; metadata_count--){\n av_metadata_set(&oc->metadata, metadata[metadata_count-1].key,\n metadata[metadata_count-1].value);\n }\n av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n av_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n av_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n av_exit(1);\n }\n }\n }\n if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {\n fprintf(stderr, "Could not open \'%s\'\\n", filename);\n av_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n av_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);\n file_oformat = NULL;\n file_iformat = NULL;\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
1,504
0
https://github.com/libav/libav/blob/77b0443544fd5f5c3f974b7a4fa4f2f18f7ba8df/libavformat/matroskadec.c/#L873
static int matroska_decode_buffer(uint8_t** buf, int* buf_size, MatroskaTrack *track) { MatroskaTrackEncoding *encodings = track->encodings.elem; uint8_t* data = *buf; int isize = *buf_size; uint8_t* pkt_data = NULL; int pkt_size = isize; int result = 0; int olen; switch (encodings[0].compression.algo) { case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP: return encodings[0].compression.settings.size; case MATROSKA_TRACK_ENCODING_COMP_LZO: do { olen = pkt_size *= 3; pkt_data = av_realloc(pkt_data, pkt_size+LZO_OUTPUT_PADDING); result = lzo1x_decode(pkt_data, &olen, data, &isize); } while (result==LZO_OUTPUT_FULL && pkt_size<10000000); if (result) goto failed; pkt_size -= olen; break; #ifdef CONFIG_ZLIB case MATROSKA_TRACK_ENCODING_COMP_ZLIB: { z_stream zstream = {0}; if (inflateInit(&zstream) != Z_OK) return -1; zstream.next_in = data; zstream.avail_in = isize; do { pkt_size *= 3; pkt_data = av_realloc(pkt_data, pkt_size); zstream.avail_out = pkt_size - zstream.total_out; zstream.next_out = pkt_data + zstream.total_out; result = inflate(&zstream, Z_NO_FLUSH); } while (result==Z_OK && pkt_size<10000000); pkt_size = zstream.total_out; inflateEnd(&zstream); if (result != Z_STREAM_END) goto failed; break; } #endif #ifdef CONFIG_BZLIB case MATROSKA_TRACK_ENCODING_COMP_BZLIB: { bz_stream bzstream = {0}; if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK) return -1; bzstream.next_in = data; bzstream.avail_in = isize; do { pkt_size *= 3; pkt_data = av_realloc(pkt_data, pkt_size); bzstream.avail_out = pkt_size - bzstream.total_out_lo32; bzstream.next_out = pkt_data + bzstream.total_out_lo32; result = BZ2_bzDecompress(&bzstream); } while (result==BZ_OK && pkt_size<10000000); pkt_size = bzstream.total_out_lo32; BZ2_bzDecompressEnd(&bzstream); if (result != BZ_STREAM_END) goto failed; break; } #endif default: return -1; } *buf = pkt_data; *buf_size = pkt_size; return 0; failed: av_free(pkt_data); return -1; }
['static int matroska_decode_buffer(uint8_t** buf, int* buf_size,\n MatroskaTrack *track)\n{\n MatroskaTrackEncoding *encodings = track->encodings.elem;\n uint8_t* data = *buf;\n int isize = *buf_size;\n uint8_t* pkt_data = NULL;\n int pkt_size = isize;\n int result = 0;\n int olen;\n switch (encodings[0].compression.algo) {\n case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:\n return encodings[0].compression.settings.size;\n case MATROSKA_TRACK_ENCODING_COMP_LZO:\n do {\n olen = pkt_size *= 3;\n pkt_data = av_realloc(pkt_data,\n pkt_size+LZO_OUTPUT_PADDING);\n result = lzo1x_decode(pkt_data, &olen, data, &isize);\n } while (result==LZO_OUTPUT_FULL && pkt_size<10000000);\n if (result)\n goto failed;\n pkt_size -= olen;\n break;\n#ifdef CONFIG_ZLIB\n case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {\n z_stream zstream = {0};\n if (inflateInit(&zstream) != Z_OK)\n return -1;\n zstream.next_in = data;\n zstream.avail_in = isize;\n do {\n pkt_size *= 3;\n pkt_data = av_realloc(pkt_data, pkt_size);\n zstream.avail_out = pkt_size - zstream.total_out;\n zstream.next_out = pkt_data + zstream.total_out;\n result = inflate(&zstream, Z_NO_FLUSH);\n } while (result==Z_OK && pkt_size<10000000);\n pkt_size = zstream.total_out;\n inflateEnd(&zstream);\n if (result != Z_STREAM_END)\n goto failed;\n break;\n }\n#endif\n#ifdef CONFIG_BZLIB\n case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {\n bz_stream bzstream = {0};\n if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)\n return -1;\n bzstream.next_in = data;\n bzstream.avail_in = isize;\n do {\n pkt_size *= 3;\n pkt_data = av_realloc(pkt_data, pkt_size);\n bzstream.avail_out = pkt_size - bzstream.total_out_lo32;\n bzstream.next_out = pkt_data + bzstream.total_out_lo32;\n result = BZ2_bzDecompress(&bzstream);\n } while (result==BZ_OK && pkt_size<10000000);\n pkt_size = bzstream.total_out_lo32;\n BZ2_bzDecompressEnd(&bzstream);\n if (result != BZ_STREAM_END)\n goto failed;\n break;\n }\n#endif\n default:\n return -1;\n }\n *buf = pkt_data;\n *buf_size = pkt_size;\n return 0;\n failed:\n av_free(pkt_data);\n return -1;\n}', 'void *av_realloc(void *ptr, unsigned int size)\n{\n#ifdef CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}']
1,505
0
https://github.com/libav/libav/blob/c5fcdb440237f06f6c954185ab60970cabf786a2/libavcodec/cavs.c/#L414
static inline void mc_dir_part(AVSContext *h, AVFrame *pic, int chroma_height,int delta,int list,uint8_t *dest_y, uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset, int src_y_offset,qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op,cavs_vector *mv) { const int mx= mv->x + src_x_offset*8; const int my= mv->y + src_y_offset*8; const int luma_xy= (mx&3) + ((my&3)<<2); uint8_t * src_y = pic->data[0] + (mx >> 2) + (my >> 2) * h->l_stride; uint8_t * src_cb = pic->data[1] + (mx >> 3) + (my >> 3) * h->c_stride; uint8_t * src_cr = pic->data[2] + (mx >> 3) + (my >> 3) * h->c_stride; int extra_width = 0; int extra_height= extra_width; int emu=0; const int full_mx= mx>>2; const int full_my= my>>2; const int pic_width = 16*h->mb_width; const int pic_height = 16*h->mb_height; if (!pic->data[0]) return; if(mx&7) extra_width -= 3; if(my&7) extra_height -= 3; if( full_mx < 0-extra_width || full_my < 0-extra_height || full_mx + 16 > pic_width + extra_width || full_my + 16 > pic_height + extra_height){ h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride, 16+5, 16+5 , full_mx-2, full_my-2, pic_width, pic_height); src_y= h->edge_emu_buffer + 2 + 2*h->l_stride; emu=1; } qpix_op[luma_xy](dest_y, src_y, h->l_stride); if(emu){ h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb, h->c_stride, 9, 9 , (mx>>3), (my>>3), pic_width>>1, pic_height>>1); src_cb= h->edge_emu_buffer; } chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7); if(emu){ h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr, h->c_stride, 9, 9 , (mx>>3), (my>>3), pic_width>>1, pic_height>>1); src_cr= h->edge_emu_buffer; } chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7); }
['void ff_cavs_inter(AVSContext *h, enum cavs_mb mb_type) {\n if(ff_cavs_partition_flags[mb_type] == 0){\n mc_part_std(h, 8, 0, h->cy, h->cu, h->cv, 0, 0,\n h->cdsp.put_cavs_qpel_pixels_tab[0],\n h->h264chroma.put_h264_chroma_pixels_tab[0],\n h->cdsp.avg_cavs_qpel_pixels_tab[0],\n h->h264chroma.avg_h264_chroma_pixels_tab[0],\n &h->mv[MV_FWD_X0]);\n }else{\n mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 0,\n h->cdsp.put_cavs_qpel_pixels_tab[1],\n h->h264chroma.put_h264_chroma_pixels_tab[1],\n h->cdsp.avg_cavs_qpel_pixels_tab[1],\n h->h264chroma.avg_h264_chroma_pixels_tab[1],\n &h->mv[MV_FWD_X0]);\n mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 0,\n h->cdsp.put_cavs_qpel_pixels_tab[1],\n h->h264chroma.put_h264_chroma_pixels_tab[1],\n h->cdsp.avg_cavs_qpel_pixels_tab[1],\n h->h264chroma.avg_h264_chroma_pixels_tab[1],\n &h->mv[MV_FWD_X1]);\n mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 0, 4,\n h->cdsp.put_cavs_qpel_pixels_tab[1],\n h->h264chroma.put_h264_chroma_pixels_tab[1],\n h->cdsp.avg_cavs_qpel_pixels_tab[1],\n h->h264chroma.avg_h264_chroma_pixels_tab[1],\n &h->mv[MV_FWD_X2]);\n mc_part_std(h, 4, 0, h->cy, h->cu, h->cv, 4, 4,\n h->cdsp.put_cavs_qpel_pixels_tab[1],\n h->h264chroma.put_h264_chroma_pixels_tab[1],\n h->cdsp.avg_cavs_qpel_pixels_tab[1],\n h->h264chroma.avg_h264_chroma_pixels_tab[1],\n &h->mv[MV_FWD_X3]);\n }\n}', 'static inline void mc_part_std(AVSContext *h,int chroma_height,int delta,\n uint8_t *dest_y,uint8_t *dest_cb,uint8_t *dest_cr,\n int x_offset, int y_offset,qpel_mc_func *qpix_put,\n h264_chroma_mc_func chroma_put,qpel_mc_func *qpix_avg,\n h264_chroma_mc_func chroma_avg, cavs_vector *mv)\n{\n qpel_mc_func *qpix_op= qpix_put;\n h264_chroma_mc_func chroma_op= chroma_put;\n dest_y += 2*x_offset + 2*y_offset*h->l_stride;\n dest_cb += x_offset + y_offset*h->c_stride;\n dest_cr += x_offset + y_offset*h->c_stride;\n x_offset += 8*h->mbx;\n y_offset += 8*h->mby;\n if(mv->ref >= 0){\n AVFrame *ref = h->DPB[mv->ref].f;\n mc_dir_part(h, ref, chroma_height, delta, 0,\n dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_op, chroma_op, mv);\n qpix_op= qpix_avg;\n chroma_op= chroma_avg;\n }\n if((mv+MV_BWD_OFFS)->ref >= 0){\n AVFrame *ref = h->DPB[0].f;\n mc_dir_part(h, ref, chroma_height, delta, 1,\n dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_op, chroma_op, mv+MV_BWD_OFFS);\n }\n}', 'static inline void mc_dir_part(AVSContext *h, AVFrame *pic,\n int chroma_height,int delta,int list,uint8_t *dest_y,\n uint8_t *dest_cb,uint8_t *dest_cr,int src_x_offset,\n int src_y_offset,qpel_mc_func *qpix_op,\n h264_chroma_mc_func chroma_op,cavs_vector *mv)\n{\n const int mx= mv->x + src_x_offset*8;\n const int my= mv->y + src_y_offset*8;\n const int luma_xy= (mx&3) + ((my&3)<<2);\n uint8_t * src_y = pic->data[0] + (mx >> 2) + (my >> 2) * h->l_stride;\n uint8_t * src_cb = pic->data[1] + (mx >> 3) + (my >> 3) * h->c_stride;\n uint8_t * src_cr = pic->data[2] + (mx >> 3) + (my >> 3) * h->c_stride;\n int extra_width = 0;\n int extra_height= extra_width;\n int emu=0;\n const int full_mx= mx>>2;\n const int full_my= my>>2;\n const int pic_width = 16*h->mb_width;\n const int pic_height = 16*h->mb_height;\n if (!pic->data[0])\n return;\n if(mx&7) extra_width -= 3;\n if(my&7) extra_height -= 3;\n if( full_mx < 0-extra_width\n || full_my < 0-extra_height\n || full_mx + 16 > pic_width + extra_width\n || full_my + 16 > pic_height + extra_height){\n h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_y - 2 - 2*h->l_stride, h->l_stride,\n 16+5, 16+5 , full_mx-2, full_my-2, pic_width, pic_height);\n src_y= h->edge_emu_buffer + 2 + 2*h->l_stride;\n emu=1;\n }\n qpix_op[luma_xy](dest_y, src_y, h->l_stride);\n if(emu){\n h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cb, h->c_stride,\n 9, 9 , (mx>>3), (my>>3), pic_width>>1, pic_height>>1);\n src_cb= h->edge_emu_buffer;\n }\n chroma_op(dest_cb, src_cb, h->c_stride, chroma_height, mx&7, my&7);\n if(emu){\n h->vdsp.emulated_edge_mc(h->edge_emu_buffer, src_cr, h->c_stride,\n 9, 9 , (mx>>3), (my>>3), pic_width>>1, pic_height>>1);\n src_cr= h->edge_emu_buffer;\n }\n chroma_op(dest_cr, src_cr, h->c_stride, chroma_height, mx&7, my&7);\n}']
1,506
0
https://github.com/openssl/openssl/blob/85bcf27cccd8f5f569886479ad96a0c33444404c/crypto/modes/ocb128.c/#L168
static OCB_BLOCK *ocb_lookup_l(OCB128_CONTEXT * ctx, size_t index) { if (index <= ctx->l_index) { return ctx->l + index; } ctx->l_index++; if (ctx->l_index == ctx->max_l_index) { ctx->max_l_index *= 2; ctx->l = OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK)); if (!ctx->l) return NULL; } ocb_double(ctx->l + (index - 1), ctx->l + index); return ctx->l + index; }
['int CRYPTO_ocb128_aad(OCB128_CONTEXT * ctx, const unsigned char *aad,\n size_t len)\n{\n u64 all_num_blocks, num_blocks;\n u64 i;\n OCB_BLOCK tmp1;\n OCB_BLOCK tmp2;\n int last_len;\n num_blocks = len / 16;\n all_num_blocks = num_blocks + ctx->blocks_hashed;\n for (i = ctx->blocks_hashed + 1; i <= all_num_blocks; i++) {\n OCB_BLOCK *lookup;\n OCB_BLOCK *aad_block;\n lookup = ocb_lookup_l(ctx, ocb_ntz(i));\n if (!lookup)\n return 0;\n ocb_block16_xor(&ctx->offset_aad, lookup, &ctx->offset_aad);\n aad_block = (OCB_BLOCK *) (aad + ((i - ctx->blocks_hashed - 1) * 16));\n ocb_block16_xor(&ctx->offset_aad, aad_block, &tmp1);\n ocb_encrypt(ctx, &tmp1, &tmp2, ctx->keyenc);\n ocb_block16_xor(&ctx->sum, &tmp2, &ctx->sum);\n }\n last_len = len % 16;\n if (last_len > 0) {\n ocb_block16_xor(&ctx->offset_aad, &ctx->l_star, &ctx->offset_aad);\n memset((void *)&tmp1, 0, 16);\n memcpy((void *)&tmp1, aad + (num_blocks * 16), last_len);\n ((unsigned char *)&tmp1)[last_len] = 0x80;\n ocb_block16_xor(&ctx->offset_aad, &tmp1, &tmp2);\n ocb_encrypt(ctx, &tmp2, &tmp1, ctx->keyenc);\n ocb_block16_xor(&ctx->sum, &tmp1, &ctx->sum);\n }\n ctx->blocks_hashed = all_num_blocks;\n return 1;\n}', 'static u32 ocb_ntz(u64 n)\n{\n u32 cnt = 0;\n while (!(n & 1)) {\n n >>= 1;\n cnt++;\n }\n return cnt;\n}', 'static OCB_BLOCK *ocb_lookup_l(OCB128_CONTEXT * ctx, size_t index)\n{\n if (index <= ctx->l_index) {\n return ctx->l + index;\n }\n ctx->l_index++;\n if (ctx->l_index == ctx->max_l_index) {\n ctx->max_l_index *= 2;\n ctx->l = OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK));\n if (!ctx->l)\n return NULL;\n }\n ocb_double(ctx->l + (index - 1), ctx->l + index);\n return ctx->l + index;\n}']
1,507
0
https://github.com/libav/libav/blob/077b55943330150db0eafd36bbee614697cabd98/libavcodec/qtrle.c/#L126
static inline void qtrle_decode_2n4bpp(QtrleContext *s, int row_ptr, int lines_to_change, int bpp) { int rle_code, i; int pixel_ptr; int row_inc = s->frame->linesize[0]; unsigned char pi[16]; unsigned char *rgb = s->frame->data[0]; int pixel_limit = s->frame->linesize[0] * s->avctx->height; int num_pixels = (bpp == 4) ? 8 : 16; while (lines_to_change--) { pixel_ptr = row_ptr + (num_pixels * (bytestream2_get_byte(&s->g) - 1)); CHECK_PIXEL_PTR(0); while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) { if (rle_code == 0) { pixel_ptr += (num_pixels * (bytestream2_get_byte(&s->g) - 1)); CHECK_PIXEL_PTR(0); } else if (rle_code < 0) { rle_code = -rle_code; for (i = num_pixels-1; i >= 0; i--) { pi[num_pixels-1-i] = (bytestream2_peek_byte(&s->g) >> ((i*bpp) & 0x07)) & ((1<<bpp)-1); bytestream2_skip(&s->g, ((i & ((num_pixels>>2)-1)) == 0)); } CHECK_PIXEL_PTR(rle_code * num_pixels); while (rle_code--) { for (i = 0; i < num_pixels; i++) rgb[pixel_ptr++] = pi[i]; } } else { rle_code *= 4; CHECK_PIXEL_PTR(rle_code*(num_pixels>>2)); while (rle_code--) { if(bpp == 4) { int x = bytestream2_get_byte(&s->g); rgb[pixel_ptr++] = (x >> 4) & 0x0f; rgb[pixel_ptr++] = x & 0x0f; } else { int x = bytestream2_get_byte(&s->g); rgb[pixel_ptr++] = (x >> 6) & 0x03; rgb[pixel_ptr++] = (x >> 4) & 0x03; rgb[pixel_ptr++] = (x >> 2) & 0x03; rgb[pixel_ptr++] = x & 0x03; } } } } row_ptr += row_inc; } }
['static inline void qtrle_decode_2n4bpp(QtrleContext *s, int row_ptr,\n int lines_to_change, int bpp)\n{\n int rle_code, i;\n int pixel_ptr;\n int row_inc = s->frame->linesize[0];\n unsigned char pi[16];\n unsigned char *rgb = s->frame->data[0];\n int pixel_limit = s->frame->linesize[0] * s->avctx->height;\n int num_pixels = (bpp == 4) ? 8 : 16;\n while (lines_to_change--) {\n pixel_ptr = row_ptr + (num_pixels * (bytestream2_get_byte(&s->g) - 1));\n CHECK_PIXEL_PTR(0);\n while ((rle_code = (signed char)bytestream2_get_byte(&s->g)) != -1) {\n if (rle_code == 0) {\n pixel_ptr += (num_pixels * (bytestream2_get_byte(&s->g) - 1));\n CHECK_PIXEL_PTR(0);\n } else if (rle_code < 0) {\n rle_code = -rle_code;\n for (i = num_pixels-1; i >= 0; i--) {\n pi[num_pixels-1-i] = (bytestream2_peek_byte(&s->g) >> ((i*bpp) & 0x07)) & ((1<<bpp)-1);\n bytestream2_skip(&s->g, ((i & ((num_pixels>>2)-1)) == 0));\n }\n CHECK_PIXEL_PTR(rle_code * num_pixels);\n while (rle_code--) {\n for (i = 0; i < num_pixels; i++)\n rgb[pixel_ptr++] = pi[i];\n }\n } else {\n rle_code *= 4;\n CHECK_PIXEL_PTR(rle_code*(num_pixels>>2));\n while (rle_code--) {\n if(bpp == 4) {\n int x = bytestream2_get_byte(&s->g);\n rgb[pixel_ptr++] = (x >> 4) & 0x0f;\n rgb[pixel_ptr++] = x & 0x0f;\n } else {\n int x = bytestream2_get_byte(&s->g);\n rgb[pixel_ptr++] = (x >> 6) & 0x03;\n rgb[pixel_ptr++] = (x >> 4) & 0x03;\n rgb[pixel_ptr++] = (x >> 2) & 0x03;\n rgb[pixel_ptr++] = x & 0x03;\n }\n }\n }\n }\n row_ptr += row_inc;\n }\n}', 'DEF(unsigned int, byte, 1, AV_RB8 , AV_WB8)']
1,508
0
https://github.com/libav/libav/blob/06ed4873e6e6aed8ec7cc24285d610ef4060880e/libavformat/oggdec.c/#L65
static int ogg_save (AVFormatContext * s) { struct ogg *ogg = s->priv_data; struct ogg_state *ost = av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams)); int i; ost->pos = url_ftell (s->pb); ost->curidx = ogg->curidx; ost->next = ogg->state; ost->nstreams = ogg->nstreams; memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams)); for (i = 0; i < ogg->nstreams; i++){ struct ogg_stream *os = ogg->streams + i; os->buf = av_malloc (os->bufsize); memset (os->buf, 0, os->bufsize); memcpy (os->buf, ost->streams[i].buf, os->bufpos); } ogg->state = ost; return 0; }
['static int\nogg_save (AVFormatContext * s)\n{\n struct ogg *ogg = s->priv_data;\n struct ogg_state *ost =\n av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams));\n int i;\n ost->pos = url_ftell (s->pb);\n ost->curidx = ogg->curidx;\n ost->next = ogg->state;\n ost->nstreams = ogg->nstreams;\n memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));\n for (i = 0; i < ogg->nstreams; i++){\n struct ogg_stream *os = ogg->streams + i;\n os->buf = av_malloc (os->bufsize);\n memset (os->buf, 0, os->bufsize);\n memcpy (os->buf, ost->streams[i].buf, os->bufpos);\n }\n ogg->state = ost;\n return 0;\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}', 'int64_t url_ftell(AVIOContext *s)\n{\n return avio_seek(s, 0, SEEK_CUR);\n}']
1,509
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 svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame)\n{\n SVQ1Context *s = avctx->priv_data;\n BitstreamContext *bc = &s->bc;\n int frame_size_code;\n bitstream_skip(bc, 8);\n s->nonref = 0;\n switch (bitstream_read(bc, 2)) {\n case 0:\n frame->pict_type = AV_PICTURE_TYPE_I;\n break;\n case 2:\n s->nonref = 1;\n case 1:\n frame->pict_type = AV_PICTURE_TYPE_P;\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, "Invalid frame type.\\n");\n return AVERROR_INVALIDDATA;\n }\n if (frame->pict_type == AV_PICTURE_TYPE_I) {\n if (s->frame_code == 0x50 || s->frame_code == 0x60) {\n int csum = bitstream_read(bc, 16);\n csum = ff_svq1_packet_checksum(bc->buffer, bc->size_in_bits >> 3,\n csum);\n ff_dlog(avctx, "%s checksum (%02x) for packet data\\n",\n (csum == 0) ? "correct" : "incorrect", csum);\n }\n if ((s->frame_code ^ 0x10) >= 0x50) {\n uint8_t msg[256];\n svq1_parse_string(bc, msg);\n av_log(avctx, AV_LOG_INFO,\n "embedded message: \\"%s\\"\\n", (char *)msg);\n }\n bitstream_skip(bc, 2);\n bitstream_skip(bc, 2);\n bitstream_skip(bc, 1);\n frame_size_code = bitstream_read(bc, 3);\n if (frame_size_code == 7) {\n s->width = bitstream_read(bc, 12);\n s->height = bitstream_read(bc, 12);\n if (!s->width || !s->height)\n return AVERROR_INVALIDDATA;\n } else {\n s->width = ff_svq1_frame_size_table[frame_size_code][0];\n s->height = ff_svq1_frame_size_table[frame_size_code][1];\n }\n }\n if (bitstream_read_bit(bc) == 1) {\n bitstream_skip(bc, 1);\n bitstream_skip(bc, 1);\n if (bitstream_read(bc, 2) != 0)\n return AVERROR_INVALIDDATA;\n }\n if (bitstream_read_bit(bc) == 1) {\n bitstream_skip(bc, 1);\n bitstream_skip(bc, 4);\n bitstream_skip(bc, 1);\n bitstream_skip(bc, 2);\n while (bitstream_read_bit(bc) == 1)\n bitstream_skip(bc, 8);\n }\n return 0;\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}']
1,510
0
https://github.com/libav/libav/blob/4ab26cb4cc9af2ab2199105aa273aa23e1f27911/libavformat/flvdec.c/#L775
static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) { FLVContext *flv = s->priv_data; int ret, i, type, size, flags, is_audio; int64_t next, pos; int64_t dts, pts = AV_NOPTS_VALUE; int sample_rate = 0, channels = 0; AVStream *st = NULL; for(;;avio_skip(s->pb, 4)){ pos = avio_tell(s->pb); type = avio_r8(s->pb); size = avio_rb24(s->pb); dts = avio_rb24(s->pb); dts |= avio_r8(s->pb) << 24; av_dlog(s, "type:%d, size:%d, dts:%"PRId64"\n", type, size, dts); if (s->pb->eof_reached) return AVERROR_EOF; avio_skip(s->pb, 3); flags = 0; if (flv->validate_next < flv->validate_count) { int64_t validate_pos = flv->validate_index[flv->validate_next].pos; if (pos == validate_pos) { if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <= VALIDATE_INDEX_TS_THRESH) { flv->validate_next++; } else { clear_index_entries(s, validate_pos); flv->validate_count = 0; } } else if (pos > validate_pos) { clear_index_entries(s, validate_pos); flv->validate_count = 0; } } if(size == 0) continue; next= size + avio_tell(s->pb); if (type == FLV_TAG_TYPE_AUDIO) { is_audio=1; flags = avio_r8(s->pb); size--; } else if (type == FLV_TAG_TYPE_VIDEO) { is_audio=0; flags = avio_r8(s->pb); size--; if ((flags & 0xf0) == 0x50) goto skip; } else { if (type == FLV_TAG_TYPE_META && size > 13+1+4) if (flv_read_metabody(s, next) > 0) { return flv_data_packet(s, pkt, dts, next); } else av_log(s, AV_LOG_DEBUG, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags); skip: avio_seek(s->pb, next, SEEK_SET); continue; } if (!size) continue; for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; if (is_audio && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { if (flv_same_audio_codec(st->codec, flags)) { break; } } else if (!is_audio && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (flv_same_video_codec(st->codec, flags)) { break; } } } if(i == s->nb_streams){ st = create_stream(s, is_audio ? AVMEDIA_TYPE_AUDIO : AVMEDIA_TYPE_VIDEO); s->ctx_flags &= ~AVFMTCTX_NOHEADER; } av_dlog(s, "%d %X %d \n", is_audio, flags, st->discard); if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio)) ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio)) || st->discard >= AVDISCARD_ALL ){ avio_seek(s->pb, next, SEEK_SET); continue; } if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME); break; } if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE)){ int size; const int64_t pos= avio_tell(s->pb); const int64_t fsize= avio_size(s->pb); avio_seek(s->pb, fsize-4, SEEK_SET); size= avio_rb32(s->pb); avio_seek(s->pb, fsize-3-size, SEEK_SET); if(size == avio_rb24(s->pb) + 11){ uint32_t ts = avio_rb24(s->pb); ts |= avio_r8(s->pb) << 24; s->duration = ts * (int64_t)AV_TIME_BASE / 1000; } avio_seek(s->pb, pos, SEEK_SET); } if(is_audio){ int bits_per_coded_sample; channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) { st->codec->channels = channels; st->codec->sample_rate = sample_rate; st->codec->bits_per_coded_sample = bits_per_coded_sample; } if(!st->codec->codec_id){ flv_set_audio_codec(s, st, st->codec, flags & FLV_AUDIO_CODECID_MASK); flv->last_sample_rate = sample_rate = st->codec->sample_rate; flv->last_channels = channels = st->codec->channels; } else { AVCodecContext ctx; ctx.sample_rate = sample_rate; flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK); sample_rate = ctx.sample_rate; } }else{ size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK); } if (st->codec->codec_id == AV_CODEC_ID_AAC || st->codec->codec_id == AV_CODEC_ID_H264) { int type = avio_r8(s->pb); size--; if (st->codec->codec_id == AV_CODEC_ID_H264) { int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000; pts = dts + cts; if (cts < 0) { flv->wrong_dts = 1; av_log(s, AV_LOG_WARNING, "negative cts, previous timestamps might be wrong\n"); } if (flv->wrong_dts) dts = AV_NOPTS_VALUE; } if (type == 0) { if (st->codec->extradata) { if ((ret = flv_queue_extradata(flv, s->pb, is_audio, size)) < 0) return ret; ret = AVERROR(EAGAIN); goto leave; } if ((ret = flv_get_extradata(s, st, size)) < 0) return ret; if (st->codec->codec_id == AV_CODEC_ID_AAC) { MPEG4AudioConfig cfg; avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, st->codec->extradata_size * 8, 1); st->codec->channels = cfg.channels; if (cfg.ext_sample_rate) st->codec->sample_rate = cfg.ext_sample_rate; else st->codec->sample_rate = cfg.sample_rate; av_dlog(s, "mp4a config channels %d sample rate %d\n", st->codec->channels, st->codec->sample_rate); } ret = AVERROR(EAGAIN); goto leave; } } if (!size) { ret = AVERROR(EAGAIN); goto leave; } ret= av_get_packet(s->pb, pkt, size); if (ret < 0) { return AVERROR(EIO); } pkt->size = ret; pkt->dts = dts; pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts; pkt->stream_index = st->index; if (flv->new_extradata[is_audio]) { uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, flv->new_extradata_size[is_audio]); if (side) { memcpy(side, flv->new_extradata[is_audio], flv->new_extradata_size[is_audio]); av_freep(&flv->new_extradata[is_audio]); flv->new_extradata_size[is_audio] = 0; } } if (is_audio && (sample_rate != flv->last_sample_rate || channels != flv->last_channels)) { flv->last_sample_rate = sample_rate; flv->last_channels = channels; ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0); } if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)) pkt->flags |= AV_PKT_FLAG_KEY; leave: avio_skip(s->pb, 4); return ret; }
['static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n FLVContext *flv = s->priv_data;\n int ret, i, type, size, flags, is_audio;\n int64_t next, pos;\n int64_t dts, pts = AV_NOPTS_VALUE;\n int sample_rate = 0, channels = 0;\n AVStream *st = NULL;\n for(;;avio_skip(s->pb, 4)){\n pos = avio_tell(s->pb);\n type = avio_r8(s->pb);\n size = avio_rb24(s->pb);\n dts = avio_rb24(s->pb);\n dts |= avio_r8(s->pb) << 24;\n av_dlog(s, "type:%d, size:%d, dts:%"PRId64"\\n", type, size, dts);\n if (s->pb->eof_reached)\n return AVERROR_EOF;\n avio_skip(s->pb, 3);\n flags = 0;\n if (flv->validate_next < flv->validate_count) {\n int64_t validate_pos = flv->validate_index[flv->validate_next].pos;\n if (pos == validate_pos) {\n if (FFABS(dts - flv->validate_index[flv->validate_next].dts) <=\n VALIDATE_INDEX_TS_THRESH) {\n flv->validate_next++;\n } else {\n clear_index_entries(s, validate_pos);\n flv->validate_count = 0;\n }\n } else if (pos > validate_pos) {\n clear_index_entries(s, validate_pos);\n flv->validate_count = 0;\n }\n }\n if(size == 0)\n continue;\n next= size + avio_tell(s->pb);\n if (type == FLV_TAG_TYPE_AUDIO) {\n is_audio=1;\n flags = avio_r8(s->pb);\n size--;\n } else if (type == FLV_TAG_TYPE_VIDEO) {\n is_audio=0;\n flags = avio_r8(s->pb);\n size--;\n if ((flags & 0xf0) == 0x50)\n goto skip;\n } else {\n if (type == FLV_TAG_TYPE_META && size > 13+1+4)\n if (flv_read_metabody(s, next) > 0) {\n return flv_data_packet(s, pkt, dts, next);\n }\n else\n av_log(s, AV_LOG_DEBUG, "skipping flv packet: type %d, size %d, flags %d\\n", type, size, flags);\n skip:\n avio_seek(s->pb, next, SEEK_SET);\n continue;\n }\n if (!size)\n continue;\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (is_audio && st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n if (flv_same_audio_codec(st->codec, flags)) {\n break;\n }\n } else\n if (!is_audio && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n if (flv_same_video_codec(st->codec, flags)) {\n break;\n }\n }\n }\n if(i == s->nb_streams){\n st = create_stream(s,\n is_audio ? AVMEDIA_TYPE_AUDIO : AVMEDIA_TYPE_VIDEO);\n s->ctx_flags &= ~AVFMTCTX_NOHEADER;\n }\n av_dlog(s, "%d %X %d \\n", is_audio, flags, st->discard);\n if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio))\n ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio))\n || st->discard >= AVDISCARD_ALL\n ){\n avio_seek(s->pb, next, SEEK_SET);\n continue;\n }\n if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)\n av_add_index_entry(st, pos, dts, size, 0, AVINDEX_KEYFRAME);\n break;\n }\n if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE)){\n int size;\n const int64_t pos= avio_tell(s->pb);\n const int64_t fsize= avio_size(s->pb);\n avio_seek(s->pb, fsize-4, SEEK_SET);\n size= avio_rb32(s->pb);\n avio_seek(s->pb, fsize-3-size, SEEK_SET);\n if(size == avio_rb24(s->pb) + 11){\n uint32_t ts = avio_rb24(s->pb);\n ts |= avio_r8(s->pb) << 24;\n s->duration = ts * (int64_t)AV_TIME_BASE / 1000;\n }\n avio_seek(s->pb, pos, SEEK_SET);\n }\n if(is_audio){\n int bits_per_coded_sample;\n channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;\n sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3);\n bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;\n if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) {\n st->codec->channels = channels;\n st->codec->sample_rate = sample_rate;\n st->codec->bits_per_coded_sample = bits_per_coded_sample;\n }\n if(!st->codec->codec_id){\n flv_set_audio_codec(s, st, st->codec, flags & FLV_AUDIO_CODECID_MASK);\n flv->last_sample_rate = sample_rate = st->codec->sample_rate;\n flv->last_channels = channels = st->codec->channels;\n } else {\n AVCodecContext ctx;\n ctx.sample_rate = sample_rate;\n flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK);\n sample_rate = ctx.sample_rate;\n }\n }else{\n size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK);\n }\n if (st->codec->codec_id == AV_CODEC_ID_AAC ||\n st->codec->codec_id == AV_CODEC_ID_H264) {\n int type = avio_r8(s->pb);\n size--;\n if (st->codec->codec_id == AV_CODEC_ID_H264) {\n int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000;\n pts = dts + cts;\n if (cts < 0) {\n flv->wrong_dts = 1;\n av_log(s, AV_LOG_WARNING, "negative cts, previous timestamps might be wrong\\n");\n }\n if (flv->wrong_dts)\n dts = AV_NOPTS_VALUE;\n }\n if (type == 0) {\n if (st->codec->extradata) {\n if ((ret = flv_queue_extradata(flv, s->pb, is_audio, size)) < 0)\n return ret;\n ret = AVERROR(EAGAIN);\n goto leave;\n }\n if ((ret = flv_get_extradata(s, st, size)) < 0)\n return ret;\n if (st->codec->codec_id == AV_CODEC_ID_AAC) {\n MPEG4AudioConfig cfg;\n avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata,\n st->codec->extradata_size * 8, 1);\n st->codec->channels = cfg.channels;\n if (cfg.ext_sample_rate)\n st->codec->sample_rate = cfg.ext_sample_rate;\n else\n st->codec->sample_rate = cfg.sample_rate;\n av_dlog(s, "mp4a config channels %d sample rate %d\\n",\n st->codec->channels, st->codec->sample_rate);\n }\n ret = AVERROR(EAGAIN);\n goto leave;\n }\n }\n if (!size) {\n ret = AVERROR(EAGAIN);\n goto leave;\n }\n ret= av_get_packet(s->pb, pkt, size);\n if (ret < 0) {\n return AVERROR(EIO);\n }\n pkt->size = ret;\n pkt->dts = dts;\n pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts;\n pkt->stream_index = st->index;\n if (flv->new_extradata[is_audio]) {\n uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA,\n flv->new_extradata_size[is_audio]);\n if (side) {\n memcpy(side, flv->new_extradata[is_audio],\n flv->new_extradata_size[is_audio]);\n av_freep(&flv->new_extradata[is_audio]);\n flv->new_extradata_size[is_audio] = 0;\n }\n }\n if (is_audio && (sample_rate != flv->last_sample_rate ||\n channels != flv->last_channels)) {\n flv->last_sample_rate = sample_rate;\n flv->last_channels = channels;\n ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);\n }\n if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))\n pkt->flags |= AV_PKT_FLAG_KEY;\nleave:\n avio_skip(s->pb, 4);\n return ret;\n}']
1,511
0
https://github.com/openssl/openssl/blob/23dd0c9f8dc6f7edf4b872d13e5644dfbbee585b/crypto/asn1/a_i2d_fp.c/#L79
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) { BIO *b; int ret; if ((b = BIO_new(BIO_s_file())) == NULL) { ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB); return (0); } BIO_set_fp(b, out, BIO_NOCLOSE); ret = ASN1_item_i2d_bio(it, b, x); BIO_free(b); return (ret); }
['int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)\n{\n BIO *b;\n int ret;\n if ((b = BIO_new(BIO_s_file())) == NULL) {\n ASN1err(ASN1_F_ASN1_ITEM_I2D_FP, ERR_R_BUF_LIB);\n return (0);\n }\n BIO_set_fp(b, out, BIO_NOCLOSE);\n ret = ASN1_item_i2d_bio(it, b, x);\n BIO_free(b);\n return (ret);\n}', 'const BIO_METHOD *BIO_s_file(void)\n{\n return (&methods_filep);\n}', 'BIO *BIO_new(const BIO_METHOD *method)\n{\n BIO *ret = OPENSSL_malloc(sizeof(*ret));\n if (ret == NULL) {\n BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n if (!BIO_set(ret, method)) {\n OPENSSL_free(ret);\n ret = NULL;\n }\n return (ret);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)\n{\n long ret;\n long (*cb) (BIO *, int, const char *, int, long, long);\n if (b == NULL)\n return (0);\n if ((b->method == NULL) || (b->method->ctrl == NULL)) {\n BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);\n return (-2);\n }\n cb = b->callback;\n if ((cb != NULL) &&\n ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))\n return (ret);\n ret = b->method->ctrl(b, cmd, larg, parg);\n if (cb != NULL)\n ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);\n return (ret);\n}']
1,512
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/rsa/rsa_pss.c/#L133
int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash, const EVP_MD *Hash, const EVP_MD *mgf1Hash, const unsigned char *EM, int sLen) { int i; int ret = 0; int hLen, maskedDBLen, MSBits, emLen; const unsigned char *H; unsigned char *DB = NULL; EVP_MD_CTX *ctx = EVP_MD_CTX_new(); unsigned char H_[EVP_MAX_MD_SIZE]; if (ctx == NULL) goto err; if (mgf1Hash == NULL) mgf1Hash = Hash; hLen = EVP_MD_size(Hash); if (hLen < 0) goto err; if (sLen == -1) sLen = hLen; else if (sLen == -2) sLen = -2; else if (sLen < -2) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_SLEN_CHECK_FAILED); goto err; } MSBits = (BN_num_bits(rsa->n) - 1) & 0x7; emLen = RSA_size(rsa); if (EM[0] & (0xFF << MSBits)) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_FIRST_OCTET_INVALID); goto err; } if (MSBits == 0) { EM++; emLen--; } if (emLen < (hLen + sLen + 2)) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_DATA_TOO_LARGE); goto err; } if (EM[emLen - 1] != 0xbc) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_LAST_OCTET_INVALID); goto err; } maskedDBLen = emLen - hLen - 1; H = EM + maskedDBLen; DB = OPENSSL_malloc(maskedDBLen); if (DB == NULL) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE); goto err; } if (PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0) goto err; for (i = 0; i < maskedDBLen; i++) DB[i] ^= EM[i]; if (MSBits) DB[0] &= 0xFF >> (8 - MSBits); for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++) ; if (DB[i++] != 0x1) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_SLEN_RECOVERY_FAILED); goto err; } if (sLen >= 0 && (maskedDBLen - i) != sLen) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_SLEN_CHECK_FAILED); goto err; } if (!EVP_DigestInit_ex(ctx, Hash, NULL) || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) || !EVP_DigestUpdate(ctx, mHash, hLen)) goto err; if (maskedDBLen - i) { if (!EVP_DigestUpdate(ctx, DB + i, maskedDBLen - i)) goto err; } if (!EVP_DigestFinal_ex(ctx, H_, NULL)) goto err; if (memcmp(H_, H, hLen)) { RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_BAD_SIGNATURE); ret = 0; } else ret = 1; err: OPENSSL_free(DB); EVP_MD_CTX_free(ctx); return ret; }
['static int pkey_rsa_verify(EVP_PKEY_CTX *ctx,\n const unsigned char *sig, size_t siglen,\n const unsigned char *tbs, size_t tbslen)\n{\n RSA_PKEY_CTX *rctx = ctx->data;\n RSA *rsa = ctx->pkey->pkey.rsa;\n size_t rslen;\n if (rctx->md) {\n if (rctx->pad_mode == RSA_PKCS1_PADDING)\n return RSA_verify(EVP_MD_type(rctx->md), tbs, tbslen,\n sig, siglen, rsa);\n if (rctx->pad_mode == RSA_X931_PADDING) {\n if (pkey_rsa_verifyrecover(ctx, NULL, &rslen, sig, siglen) <= 0)\n return 0;\n } else if (rctx->pad_mode == RSA_PKCS1_PSS_PADDING) {\n int ret;\n if (!setup_tbuf(rctx, ctx))\n return -1;\n ret = RSA_public_decrypt(siglen, sig, rctx->tbuf,\n rsa, RSA_NO_PADDING);\n if (ret <= 0)\n return 0;\n ret = RSA_verify_PKCS1_PSS_mgf1(rsa, tbs,\n rctx->md, rctx->mgf1md,\n rctx->tbuf, rctx->saltlen);\n if (ret <= 0)\n return 0;\n return 1;\n } else\n return -1;\n } else {\n if (!setup_tbuf(rctx, ctx))\n return -1;\n rslen = RSA_public_decrypt(siglen, sig, rctx->tbuf,\n rsa, rctx->pad_mode);\n if (rslen == 0)\n return 0;\n }\n if ((rslen != tbslen) || memcmp(tbs, rctx->tbuf, rslen))\n return 0;\n return 1;\n}', 'static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk)\n{\n if (ctx->tbuf)\n return 1;\n ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey));\n if (ctx->tbuf == NULL)\n return 0;\n return 1;\n}', 'int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,\n const EVP_MD *Hash, const EVP_MD *mgf1Hash,\n const unsigned char *EM, int sLen)\n{\n int i;\n int ret = 0;\n int hLen, maskedDBLen, MSBits, emLen;\n const unsigned char *H;\n unsigned char *DB = NULL;\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n unsigned char H_[EVP_MAX_MD_SIZE];\n if (ctx == NULL)\n goto err;\n if (mgf1Hash == NULL)\n mgf1Hash = Hash;\n hLen = EVP_MD_size(Hash);\n if (hLen < 0)\n goto err;\n if (sLen == -1)\n sLen = hLen;\n else if (sLen == -2)\n sLen = -2;\n else if (sLen < -2) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_SLEN_CHECK_FAILED);\n goto err;\n }\n MSBits = (BN_num_bits(rsa->n) - 1) & 0x7;\n emLen = RSA_size(rsa);\n if (EM[0] & (0xFF << MSBits)) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_FIRST_OCTET_INVALID);\n goto err;\n }\n if (MSBits == 0) {\n EM++;\n emLen--;\n }\n if (emLen < (hLen + sLen + 2)) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_DATA_TOO_LARGE);\n goto err;\n }\n if (EM[emLen - 1] != 0xbc) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_LAST_OCTET_INVALID);\n goto err;\n }\n maskedDBLen = emLen - hLen - 1;\n H = EM + maskedDBLen;\n DB = OPENSSL_malloc(maskedDBLen);\n if (DB == NULL) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0)\n goto err;\n for (i = 0; i < maskedDBLen; i++)\n DB[i] ^= EM[i];\n if (MSBits)\n DB[0] &= 0xFF >> (8 - MSBits);\n for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++) ;\n if (DB[i++] != 0x1) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_SLEN_RECOVERY_FAILED);\n goto err;\n }\n if (sLen >= 0 && (maskedDBLen - i) != sLen) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_SLEN_CHECK_FAILED);\n goto err;\n }\n if (!EVP_DigestInit_ex(ctx, Hash, NULL)\n || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes)\n || !EVP_DigestUpdate(ctx, mHash, hLen))\n goto err;\n if (maskedDBLen - i) {\n if (!EVP_DigestUpdate(ctx, DB + i, maskedDBLen - i))\n goto err;\n }\n if (!EVP_DigestFinal_ex(ctx, H_, NULL))\n goto err;\n if (memcmp(H_, H, hLen)) {\n RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, RSA_R_BAD_SIGNATURE);\n ret = 0;\n } else\n ret = 1;\n err:\n OPENSSL_free(DB);\n EVP_MD_CTX_free(ctx);\n return ret;\n}']
1,513
0
https://github.com/apache/httpd/blob/306542f55f696caf5ae1ce0e679d894e1bb78ad6/server/scoreboard.c/#L451
static void copy_request(char *rbuf, apr_size_t rbuflen, request_rec *r) { char *p; if (r->the_request == NULL) { apr_cpystrn(rbuf, "NULL", rbuflen); return; } if (r->parsed_uri.password == NULL) { p = r->the_request; } else { p = apr_pstrcat(r->pool, r->method, " ", apr_uri_unparse(r->pool, &r->parsed_uri, APR_URI_UNP_OMITPASSWORD), r->assbackwards ? NULL : " ", r->protocol, NULL); } if (!ap_mod_status_reqtail) { apr_cpystrn(rbuf, p, rbuflen); } else { apr_size_t slen = strlen(p); if (slen < rbuflen) { apr_cpystrn(rbuf, p, rbuflen); } else { apr_cpystrn(rbuf, p+(slen-rbuflen+1), rbuflen); } } }
['static apr_status_t eor_bucket_cleanup(void *data)\n{\n request_rec **rp = data;\n if (*rp) {\n request_rec *r = *rp;\n *rp = NULL;\n ap_update_child_status(r->connection->sbh, SERVER_BUSY_LOG, r);\n ap_run_log_transaction(r);\n if (ap_extended_status) {\n ap_increment_counts(r->connection->sbh, r);\n }\n }\n return APR_SUCCESS;\n}', 'AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status,\n request_rec *r)\n{\n if (!sbh || (sbh->child_num < 0))\n return -1;\n return update_child_status_internal(sbh->child_num, sbh->thread_num,\n status,\n r ? r->connection : NULL,\n r);\n}', 'static int update_child_status_internal(int child_num,\n int thread_num,\n int status,\n conn_rec *c,\n request_rec *r)\n{\n int old_status;\n worker_score *ws;\n process_score *ps;\n int mpm_generation;\n ws = &ap_scoreboard_image->servers[child_num][thread_num];\n old_status = ws->status;\n ws->status = status;\n ps = &ap_scoreboard_image->parent[child_num];\n if (status == SERVER_READY\n && old_status == SERVER_STARTING) {\n ws->thread_num = child_num * thread_limit + thread_num;\n ap_mpm_query(AP_MPMQ_GENERATION, &mpm_generation);\n ps->generation = mpm_generation;\n }\n if (ap_extended_status) {\n if (status == SERVER_READY || status == SERVER_DEAD) {\n if (status == SERVER_DEAD) {\n ws->my_access_count = 0L;\n ws->my_bytes_served = 0L;\n }\n ws->conn_count = 0;\n ws->conn_bytes = 0;\n ws->last_used = apr_time_now();\n }\n if (r) {\n const char *client = ap_get_remote_host(c, r->per_dir_config,\n REMOTE_NOLOOKUP, NULL);\n if (!client || !strcmp(client, c->client_ip)) {\n apr_cpystrn(ws->client, r->useragent_ip, sizeof(ws->client));\n }\n else {\n apr_cpystrn(ws->client, client, sizeof(ws->client));\n }\n copy_request(ws->request, sizeof(ws->request), r);\n if (r->server) {\n apr_snprintf(ws->vhost, sizeof(ws->vhost), "%s:%d",\n r->server->server_hostname,\n r->connection->local_addr->port);\n }\n }\n else if (c) {\n apr_cpystrn(ws->client, ap_get_remote_host(c, NULL,\n REMOTE_NOLOOKUP, NULL), sizeof(ws->client));\n ws->request[0]=\'\\0\';\n ws->vhost[0]=\'\\0\';\n }\n }\n return old_status;\n}', 'static void copy_request(char *rbuf, apr_size_t rbuflen, request_rec *r)\n{\n char *p;\n if (r->the_request == NULL) {\n apr_cpystrn(rbuf, "NULL", rbuflen);\n return;\n }\n if (r->parsed_uri.password == NULL) {\n p = r->the_request;\n }\n else {\n p = apr_pstrcat(r->pool, r->method, " ",\n apr_uri_unparse(r->pool, &r->parsed_uri,\n APR_URI_UNP_OMITPASSWORD),\n r->assbackwards ? NULL : " ", r->protocol, NULL);\n }\n if (!ap_mod_status_reqtail) {\n apr_cpystrn(rbuf, p, rbuflen);\n }\n else {\n apr_size_t slen = strlen(p);\n if (slen < rbuflen) {\n apr_cpystrn(rbuf, p, rbuflen);\n }\n else {\n apr_cpystrn(rbuf, p+(slen-rbuflen+1), rbuflen);\n }\n }\n}']
1,514
0
https://github.com/openssl/openssl/blob/0f3ffbd1581fad58095fedcc32b0da42a486b8b7/crypto/rand/rand_lib.c/#L356
void RAND_add(const void *buf, int num, double randomness) { const RAND_METHOD *meth = RAND_get_rand_method(); if (meth->add != NULL) meth->add(buf, num, randomness); }
['void RAND_add(const void *buf, int num, double randomness)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth->add != NULL)\n meth->add(buf, num, randomness);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n const RAND_METHOD *tmp_meth = NULL;\n if (!RUN_ONCE(&rand_init, do_rand_init))\n return NULL;\n CRYPTO_THREAD_write_lock(rand_meth_lock);\n if (default_RAND_meth == NULL) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e;\n if ((e = ENGINE_get_default_RAND()) != NULL\n && (tmp_meth = ENGINE_get_RAND(e)) != NULL) {\n funct_ref = e;\n default_RAND_meth = tmp_meth;\n } else {\n ENGINE_finish(e);\n default_RAND_meth = &rand_meth;\n }\n#else\n default_RAND_meth = &rand_meth;\n#endif\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
1,515
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/mem.c/#L245
void CRYPTO_free(void *str) { #ifdef CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0); free(str); CRYPTO_mem_debug_free(str, 1); } else { free(str); } #else free(str); #endif }
['X509_EXTENSION *OCSP_accept_responses_new(char **oids)\n{\n int nid;\n STACK_OF(ASN1_OBJECT) *sk = NULL;\n ASN1_OBJECT *o = NULL;\n X509_EXTENSION *x = NULL;\n if ((sk = sk_ASN1_OBJECT_new_null()) == NULL)\n goto err;\n while (oids && *oids) {\n if ((nid = OBJ_txt2nid(*oids)) != NID_undef && (o = OBJ_nid2obj(nid)))\n sk_ASN1_OBJECT_push(sk, o);\n oids++;\n }\n x = X509V3_EXT_i2d(NID_id_pkix_OCSP_acceptableResponses, 0, sk);\n err:\n sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);\n return x;\n}', 'int OBJ_txt2nid(const char *s)\n{\n ASN1_OBJECT *obj;\n int nid;\n obj = OBJ_txt2obj(s, 0);\n nid = OBJ_obj2nid(obj);\n ASN1_OBJECT_free(obj);\n return nid;\n}', 'void ASN1_OBJECT_free(ASN1_OBJECT *a)\n{\n if (a == NULL)\n return;\n if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) {\n#ifndef CONST_STRICT\n OPENSSL_free((void*)a->sn);\n OPENSSL_free((void*)a->ln);\n#endif\n a->sn = a->ln = NULL;\n }\n if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {\n OPENSSL_free((void*)a->data);\n a->data = NULL;\n a->length = 0;\n }\n if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)\n OPENSSL_free(a);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
1,516
0
https://github.com/libav/libav/blob/6cecd63005b29a1dc3a5104e6ac85fd112705122/libavcodec/g726.c/#L378
static int g726_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; G726Context *c = avctx->priv_data; short *samples = data; GetBitContext gb; init_get_bits(&gb, buf, buf_size * 8); while (get_bits_count(&gb) + c->code_size <= buf_size*8) *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); if(buf_size*8 != get_bits_count(&gb)) av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); *data_size = (uint8_t*)samples - (uint8_t*)data; return buf_size; }
['static int g726_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 G726Context *c = avctx->priv_data;\n short *samples = data;\n GetBitContext gb;\n init_get_bits(&gb, buf, buf_size * 8);\n while (get_bits_count(&gb) + c->code_size <= buf_size*8)\n *samples++ = g726_decode(c, get_bits(&gb, c->code_size));\n if(buf_size*8 != get_bits_count(&gb))\n av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\\n");\n *data_size = (uint8_t*)samples - (uint8_t*)data;\n return buf_size;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline int get_bits_count(GetBitContext *s){\n return s->index;\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}']
1,517
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); }
['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 int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'int BN_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}']
1,518
0
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_lib.c/#L291
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) { bn_check_top(b); if (a == b) return a; if (bn_wexpand(a, b->top) == NULL) return NULL; if (b->top > 0) memcpy(a->d, b->d, sizeof(b->d[0]) * b->top); a->neg = b->neg; a->top = b->top; a->flags |= b->flags & BN_FLG_FIXED_TOP; bn_check_top(a); return a; }
['int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,\n const BIGNUM *order, const BIGNUM *cofactor)\n{\n if (generator == NULL) {\n ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (group->generator == NULL) {\n group->generator = EC_POINT_new(group);\n if (group->generator == NULL)\n return 0;\n }\n if (!EC_POINT_copy(group->generator, generator))\n return 0;\n if (order != NULL) {\n if (!BN_copy(group->order, order))\n return 0;\n } else\n BN_zero(group->order);\n if (cofactor != NULL) {\n if (!BN_copy(group->cofactor, cofactor))\n return 0;\n } else\n BN_zero(group->cofactor);\n if (BN_is_odd(group->order)) {\n return ec_precompute_mont_data(group);\n }\n BN_MONT_CTX_free(group->mont_data);\n group->mont_data = NULL;\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}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'static int ec_precompute_mont_data(EC_GROUP *group)\n{\n BN_CTX *ctx = BN_CTX_new();\n int ret = 0;\n BN_MONT_CTX_free(group->mont_data);\n group->mont_data = NULL;\n if (ctx == NULL)\n goto err;\n group->mont_data = BN_MONT_CTX_new();\n if (group->mont_data == NULL)\n goto err;\n if (!BN_MONT_CTX_set(group->mont_data, group->order, ctx)) {\n BN_MONT_CTX_free(group->mont_data);\n group->mont_data = NULL;\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n mont->RR.d[i] = 0;\n mont->RR.top = ret;\n mont->RR.flags |= BN_FLG_FIXED_TOP;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
1,519
0
https://github.com/libav/libav/blob/daf98908118074e96199ca7195663af4543d3808/avconv.c/#L2747
static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder) { const char *codec_string = encoder ? "encoder" : "decoder"; AVCodec *codec; if(!name) return CODEC_ID_NONE; codec = encoder ? avcodec_find_encoder_by_name(name) : avcodec_find_decoder_by_name(name); if(!codec) { av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name); exit_program(1); } if(codec->type != type) { av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name); exit_program(1); } return codec->id; }
['static enum CodecID find_codec_or_die(const char *name, enum AVMediaType type, int encoder)\n{\n const char *codec_string = encoder ? "encoder" : "decoder";\n AVCodec *codec;\n if(!name)\n return CODEC_ID_NONE;\n codec = encoder ?\n avcodec_find_encoder_by_name(name) :\n avcodec_find_decoder_by_name(name);\n if(!codec) {\n av_log(NULL, AV_LOG_FATAL, "Unknown %s \'%s\'\\n", codec_string, name);\n exit_program(1);\n }\n if(codec->type != type) {\n av_log(NULL, AV_LOG_FATAL, "Invalid %s type \'%s\'\\n", codec_string, name);\n exit_program(1);\n }\n return codec->id;\n}']
1,520
0
https://github.com/libav/libav/blob/3adba2de3d0c4903cf310fcce80ebac4dd972fd3/libavcodec/rv34.c/#L239
static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc) { int coeffs[4]; coeffs[0] = modulo_three_table[code][0]; coeffs[1] = modulo_three_table[code][1]; coeffs[2] = modulo_three_table[code][2]; coeffs[3] = modulo_three_table[code][3]; decode_coeff(dst , coeffs[0], 3, gb, vlc); if(is_block2){ decode_coeff(dst+8, coeffs[1], 2, gb, vlc); decode_coeff(dst+1, coeffs[2], 2, gb, vlc); }else{ decode_coeff(dst+1, coeffs[1], 2, gb, vlc); decode_coeff(dst+8, coeffs[2], 2, gb, vlc); } decode_coeff(dst+9, coeffs[3], 2, gb, vlc); }
['static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)\n{\n MpegEncContext *s = &r->s;\n GetBitContext *gb = &s->gb;\n int cbp, cbp2;\n int i, blknum, blkoff;\n LOCAL_ALIGNED_16(DCTELEM, block16, [64]);\n int luma_dc_quant;\n int dist;\n int mb_pos = s->mb_x + s->mb_y * s->mb_stride;\n memset(r->avail_cache, 0, sizeof(r->avail_cache));\n fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4);\n dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width;\n if(s->mb_x && dist)\n r->avail_cache[5] =\n r->avail_cache[9] = s->current_picture_ptr->f.mb_type[mb_pos - 1];\n if(dist >= s->mb_width)\n r->avail_cache[2] =\n r->avail_cache[3] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride];\n if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1)\n r->avail_cache[4] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride + 1];\n if(s->mb_x && dist > s->mb_width)\n r->avail_cache[1] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride - 1];\n s->qscale = r->si.quant;\n cbp = cbp2 = rv34_decode_mb_header(r, intra_types);\n r->cbp_luma [mb_pos] = cbp;\n r->cbp_chroma[mb_pos] = cbp >> 16;\n if(s->pict_type == AV_PICTURE_TYPE_I)\n r->deblock_coefs[mb_pos] = 0xFFFF;\n else\n r->deblock_coefs[mb_pos] = rv34_set_deblock_coef(r) | r->cbp_luma[mb_pos];\n s->current_picture_ptr->f.qscale_table[mb_pos] = s->qscale;\n if(cbp == -1)\n return -1;\n luma_dc_quant = r->block_type == RV34_MB_P_MIX16x16 ? r->luma_dc_quant_p[s->qscale] : r->luma_dc_quant_i[s->qscale];\n if(r->is16){\n memset(block16, 0, 64 * sizeof(*block16));\n rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0);\n rv34_dequant4x4_16x16(block16, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]);\n r->rdsp.rv34_inv_transform_tab[1](block16);\n }\n for(i = 0; i < 16; i++, cbp >>= 1){\n if(!r->is16 && !(cbp & 1)) continue;\n blknum = ((i & 2) >> 1) + ((i & 8) >> 2);\n blkoff = ((i & 1) << 2) + ((i & 4) << 3);\n if(cbp & 1)\n rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->luma_vlc, 0);\n rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[s->qscale],rv34_qscale_tab[s->qscale]);\n if(r->is16)\n s->block[blknum][blkoff] = block16[(i & 3) | ((i & 0xC) << 1)];\n r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff);\n }\n if(r->block_type == RV34_MB_P_MIX16x16)\n r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1);\n for(; i < 24; i++, cbp >>= 1){\n if(!(cbp & 1)) continue;\n blknum = ((i & 4) >> 2) + 4;\n blkoff = ((i & 1) << 2) + ((i & 2) << 4);\n rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->chroma_vlc, 1);\n rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]);\n r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff);\n }\n if (IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos]))\n rv34_output_macroblock(r, intra_types, cbp2, r->is16);\n else\n rv34_apply_differences(r, cbp2);\n return 0;\n}', 'static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){\n uint8_t *p= (uint8_t*)vp;\n assert(size==1 || size==2 || size==4);\n assert(w<=4);\n w *= size;\n stride *= size;\n assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);\n assert((stride&(w-1))==0);\n if(w==2){\n const uint16_t v= size==4 ? val : val*0x0101;\n *(uint16_t*)(p + 0*stride)= v;\n if(h==1) return;\n *(uint16_t*)(p + 1*stride)= v;\n if(h==2) return;\n *(uint16_t*)(p + 2*stride)= v;\n *(uint16_t*)(p + 3*stride)= v;\n }else if(w==4){\n const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101;\n *(uint32_t*)(p + 0*stride)= v;\n if(h==1) return;\n *(uint32_t*)(p + 1*stride)= v;\n if(h==2) return;\n *(uint32_t*)(p + 2*stride)= v;\n *(uint32_t*)(p + 3*stride)= v;\n }else if(w==8){\n#if HAVE_FAST_64BIT\n const uint64_t v= size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL;\n *(uint64_t*)(p + 0*stride)= v;\n if(h==1) return;\n *(uint64_t*)(p + 1*stride)= v;\n if(h==2) return;\n *(uint64_t*)(p + 2*stride)= v;\n *(uint64_t*)(p + 3*stride)= v;\n }else if(w==16){\n const uint64_t v= val*0x0100000001ULL;\n *(uint64_t*)(p + 0+0*stride)= v;\n *(uint64_t*)(p + 8+0*stride)= v;\n *(uint64_t*)(p + 0+1*stride)= v;\n *(uint64_t*)(p + 8+1*stride)= v;\n if(h==2) return;\n *(uint64_t*)(p + 0+2*stride)= v;\n *(uint64_t*)(p + 8+2*stride)= v;\n *(uint64_t*)(p + 0+3*stride)= v;\n *(uint64_t*)(p + 8+3*stride)= v;\n#else\n const uint32_t v= size==2 ? val*0x00010001 : val;\n *(uint32_t*)(p + 0+0*stride)= v;\n *(uint32_t*)(p + 4+0*stride)= v;\n if(h==1) return;\n *(uint32_t*)(p + 0+1*stride)= v;\n *(uint32_t*)(p + 4+1*stride)= v;\n if(h==2) return;\n *(uint32_t*)(p + 0+2*stride)= v;\n *(uint32_t*)(p + 4+2*stride)= v;\n *(uint32_t*)(p + 0+3*stride)= v;\n *(uint32_t*)(p + 4+3*stride)= v;\n }else if(w==16){\n *(uint32_t*)(p + 0+0*stride)= val;\n *(uint32_t*)(p + 4+0*stride)= val;\n *(uint32_t*)(p + 8+0*stride)= val;\n *(uint32_t*)(p +12+0*stride)= val;\n *(uint32_t*)(p + 0+1*stride)= val;\n *(uint32_t*)(p + 4+1*stride)= val;\n *(uint32_t*)(p + 8+1*stride)= val;\n *(uint32_t*)(p +12+1*stride)= val;\n if(h==2) return;\n *(uint32_t*)(p + 0+2*stride)= val;\n *(uint32_t*)(p + 4+2*stride)= val;\n *(uint32_t*)(p + 8+2*stride)= val;\n *(uint32_t*)(p +12+2*stride)= val;\n *(uint32_t*)(p + 0+3*stride)= val;\n *(uint32_t*)(p + 4+3*stride)= val;\n *(uint32_t*)(p + 8+3*stride)= val;\n *(uint32_t*)(p +12+3*stride)= val;\n#endif\n }else\n assert(0);\n assert(h==4);\n}', 'static inline void rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc)\n{\n int code, pattern;\n code = get_vlc2(gb, rvlc->first_pattern[fc].table, 9, 2);\n pattern = code & 0x7;\n code >>= 3;\n decode_subblock(dst, code, 0, gb, &rvlc->coefficient);\n if(pattern & 4){\n code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2);\n decode_subblock(dst + 2, code, 0, gb, &rvlc->coefficient);\n }\n if(pattern & 2){\n code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2);\n decode_subblock(dst + 8*2, code, 1, gb, &rvlc->coefficient);\n }\n if(pattern & 1){\n code = get_vlc2(gb, rvlc->third_pattern[sc].table, 9, 2);\n decode_subblock(dst + 8*2+2, code, 0, gb, &rvlc->coefficient);\n }\n}', 'static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],\n int bits, int max_depth)\n{\n int code;\n OPEN_READER(re, s);\n UPDATE_CACHE(re, s);\n GET_VLC(code, re, s, table, bits, max_depth);\n CLOSE_READER(re, s);\n return code;\n}', 'static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc)\n{\n int coeffs[4];\n coeffs[0] = modulo_three_table[code][0];\n coeffs[1] = modulo_three_table[code][1];\n coeffs[2] = modulo_three_table[code][2];\n coeffs[3] = modulo_three_table[code][3];\n decode_coeff(dst , coeffs[0], 3, gb, vlc);\n if(is_block2){\n decode_coeff(dst+8, coeffs[1], 2, gb, vlc);\n decode_coeff(dst+1, coeffs[2], 2, gb, vlc);\n }else{\n decode_coeff(dst+1, coeffs[1], 2, gb, vlc);\n decode_coeff(dst+8, coeffs[2], 2, gb, vlc);\n }\n decode_coeff(dst+9, coeffs[3], 2, gb, vlc);\n}']
1,521
0
https://github.com/openssl/openssl/blob/5ea564f154ebe8bda2a0e091a312e2058edf437f/crypto/bn/bn_shift.c/#L115
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 OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n int i, n = 0, len, nid, first, use_bn;\n BIGNUM *bl;\n unsigned long l;\n const unsigned char *p;\n char tbuf[DECIMAL_SIZE(i) + DECIMAL_SIZE(l) + 2];\n if (buf && buf_len > 0)\n buf[0] = \'\\0\';\n if ((a == NULL) || (a->data == NULL))\n return (0);\n if (!no_name && (nid = OBJ_obj2nid(a)) != NID_undef) {\n const char *s;\n s = OBJ_nid2ln(nid);\n if (s == NULL)\n s = OBJ_nid2sn(nid);\n if (s) {\n if (buf)\n OPENSSL_strlcpy(buf, s, buf_len);\n n = strlen(s);\n return n;\n }\n }\n len = a->length;\n p = a->data;\n first = 1;\n bl = NULL;\n while (len > 0) {\n l = 0;\n use_bn = 0;\n for (;;) {\n unsigned char c = *p++;\n len--;\n if ((len == 0) && (c & 0x80))\n goto err;\n if (use_bn) {\n if (!BN_add_word(bl, c & 0x7f))\n goto err;\n } else\n l |= c & 0x7f;\n if (!(c & 0x80))\n break;\n if (!use_bn && (l > (ULONG_MAX >> 7L))) {\n if (bl == NULL && (bl = BN_new()) == NULL)\n goto err;\n if (!BN_set_word(bl, l))\n goto err;\n use_bn = 1;\n }\n if (use_bn) {\n if (!BN_lshift(bl, bl, 7))\n goto err;\n } else\n l <<= 7L;\n }\n if (first) {\n first = 0;\n if (l >= 80) {\n i = 2;\n if (use_bn) {\n if (!BN_sub_word(bl, 80))\n goto err;\n } else\n l -= 80;\n } else {\n i = (int)(l / 40);\n l -= (long)(i * 40);\n }\n if (buf && (buf_len > 1)) {\n *buf++ = i + \'0\';\n *buf = \'\\0\';\n buf_len--;\n }\n n++;\n }\n if (use_bn) {\n char *bndec;\n bndec = BN_bn2dec(bl);\n if (!bndec)\n goto err;\n i = strlen(bndec);\n if (buf) {\n if (buf_len > 1) {\n *buf++ = \'.\';\n *buf = \'\\0\';\n buf_len--;\n }\n OPENSSL_strlcpy(buf, bndec, buf_len);\n if (i > buf_len) {\n buf += buf_len;\n buf_len = 0;\n } else {\n buf += i;\n buf_len -= i;\n }\n }\n n++;\n n += i;\n OPENSSL_free(bndec);\n } else {\n BIO_snprintf(tbuf, sizeof tbuf, ".%lu", l);\n i = strlen(tbuf);\n if (buf && (buf_len > 0)) {\n OPENSSL_strlcpy(buf, tbuf, buf_len);\n if (i > buf_len) {\n buf += buf_len;\n buf_len = 0;\n } else {\n buf += i;\n buf_len -= i;\n }\n }\n n += i;\n l = 0;\n }\n }\n BN_free(bl);\n return n;\n err:\n BN_free(bl);\n return -1;\n}', 'int BN_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_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}']
1,522
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_lib.c/#L423
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); }
['static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n\t X509 *x, X509 *xca, EVP_PKEY *pkey, char *serialfile, int create,\n\t int days)\n\t{\n\tint ret=0;\n\tBIO *io=NULL;\n\tMS_STATIC char buf2[1024];\n\tchar *buf=NULL,*p;\n\tBIGNUM *serial=NULL;\n\tASN1_INTEGER *bs=NULL,bs2;\n\tX509_STORE_CTX xsc;\n\tEVP_PKEY *upkey;\n\tupkey = X509_get_pubkey(xca);\n\tEVP_PKEY_copy_parameters(upkey,pkey);\n\tEVP_PKEY_free(upkey);\n\tX509_STORE_CTX_init(&xsc,ctx,x,NULL);\n\tbuf=(char *)Malloc(EVP_PKEY_size(pkey)*2+\n\t\t((serialfile == NULL)\n\t\t\t?(strlen(CAfile)+strlen(POSTFIX)+1)\n\t\t\t:(strlen(serialfile)))+1);\n\tif (buf == NULL) { BIO_printf(bio_err,"out of mem\\n"); goto end; }\n\tif (serialfile == NULL)\n\t\t{\n\t\tstrcpy(buf,CAfile);\n\t\tfor (p=buf; *p; p++)\n\t\t\tif (*p == \'.\')\n\t\t\t\t{\n\t\t\t\t*p=\'\\0\';\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\tstrcat(buf,POSTFIX);\n\t\t}\n\telse\n\t\tstrcpy(buf,serialfile);\n\tserial=BN_new();\n\tbs=ASN1_INTEGER_new();\n\tif ((serial == NULL) || (bs == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tio=BIO_new(BIO_s_file());\n\tif (io == NULL)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (BIO_read_filename(io,buf) <= 0)\n\t\t{\n\t\tif (!create)\n\t\t\t{\n\t\t\tperror(buf);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tASN1_INTEGER_set(bs,0);\n\t\t\tBN_zero(serial);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (!a2i_ASN1_INTEGER(io,bs,buf2,1024))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load serial number from %s\\n",buf);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tserial=BN_bin2bn(bs->data,bs->length,serial);\n\t\t\tif (serial == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"error converting bin 2 bn");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (!BN_add_word(serial,1))\n\t\t{ BIO_printf(bio_err,"add_word failure\\n"); goto end; }\n\tbs2.data=(unsigned char *)buf2;\n\tbs2.length=BN_bn2bin(serial,bs2.data);\n\tif (BIO_write_filename(io,buf) <= 0)\n\t\t{\n\t\tBIO_printf(bio_err,"error attempting to write serial number file\\n");\n\t\tperror(buf);\n\t\tgoto end;\n\t\t}\n\ti2a_ASN1_INTEGER(io,&bs2);\n\tBIO_puts(io,"\\n");\n\tBIO_free(io);\n\tio=NULL;\n\tif (!X509_STORE_add_cert(ctx,x)) goto end;\n\tX509_STORE_CTX_set_cert(&xsc,x);\n\tif (!reqfile && !X509_verify_cert(&xsc))\n\t\tgoto end;\n\tif (!X509_check_private_key(xca,pkey))\n\t\t{\n\t\tBIO_printf(bio_err,"CA certificate and CA private key do not match\\n");\n\t\tgoto end;\n\t\t}\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end;\n\tif (!X509_set_serialNumber(x,bs)) goto end;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL)\n\t\tgoto end;\n\tif (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)\n\t\tgoto end;\n\tupkey=X509_get_pubkey(x);\n\tif (!EVP_PKEY_missing_parameters(pkey) &&\n\t\t(EVP_PKEY_cmp_parameters(pkey,upkey) == 0))\n\t\t{\n\t\tEVP_PKEY_save_parameters(upkey,0);\n\t\tX509_set_pubkey(x,upkey);\n\t\t}\n\tEVP_PKEY_free(upkey);\n\tif (!X509_sign(x,pkey,digest)) goto end;\n\tret=1;\nend:\n\tX509_STORE_CTX_cleanup(&xsc);\n\tif (!ret)\n\t\tERR_print_errors(bio_err);\n\tif (buf != NULL) Free(buf);\n\tif (bs != NULL) ASN1_INTEGER_free(bs);\n\tif (io != NULL)\tBIO_free(io);\n\tif (serial != NULL) BN_free(serial);\n\treturn(ret);\n\t}', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->max=0;\n\tret->d=NULL;\n\treturn(ret);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i,n;\n\tif (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);\n\tn=sizeof(BN_ULONG)/BN_BYTES;\n\ta->neg=0;\n\ta->top=0;\n\ta->d[0]=(BN_ULONG)w&BN_MASK2;\n\tif (a->d[0] != 0) a->top=1;\n\tfor (i=1; i<n; i++)\n\t\t{\n#ifndef SIXTY_FOUR_BIT\n\t\tw>>=BN_BITS4;\n\t\tw>>=BN_BITS4;\n#endif\n\t\ta->d[i]=(BN_ULONG)w&BN_MASK2;\n\t\tif (a->d[i] != 0) a->top=i+1;\n\t\t}\n\treturn(1);\n\t}', '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}']
1,523
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_shift.c/#L159
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } r->neg = a->neg; nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_lshift1(r, a))\n return 0;\n bn_check_top(r);\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_lshift1(BIGNUM *r, const BIGNUM *a)\n{\n register BN_ULONG *ap, *rp, t, c;\n int i;\n bn_check_top(r);\n bn_check_top(a);\n if (r != a) {\n r->neg = a->neg;\n if (bn_wexpand(r, a->top + 1) == NULL)\n return (0);\n r->top = a->top;\n } else {\n if (bn_wexpand(r, a->top + 1) == NULL)\n return (0);\n }\n ap = a->d;\n rp = r->d;\n c = 0;\n for (i = 0; i < a->top; i++) {\n t = *(ap++);\n *(rp++) = ((t << 1) | c) & BN_MASK2;\n c = (t & BN_TBIT) ? 1 : 0;\n }\n if (c) {\n *rp = 1;\n r->top++;\n }\n bn_check_top(r);\n return (1);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n r->neg = a->neg;\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
1,524
0
https://gitlab.com/libtiff/libtiff/blob/bf3589510740d30f231bdbc340502622cbcc5984/tools/tiff2pdf.c/#L1988
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); if (sbc[0] != (uint64)(tmsize_t)sbc[0]) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } t2p->tiff_datasize=(tmsize_t)sbc[0]; return; } #endif #ifdef ZIP_SUPPORT if(t2p->pdf_compression == T2P_COMPRESS_ZIP){ TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc); if (sbc[0] != (uint64)(tmsize_t)sbc[0]) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } 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 -=2; k +=2; } k = checkAdd64(k, 2, t2p); k = checkAdd64(k, 6, 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 if (sbc[0] != (uint64)(tmsize_t)sbc[0]) {\n TIFFError(TIFF2PDF_MODULE, "Integer overflow");\n t2p->t2p_error = T2P_ERR_ERROR;\n }\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 if (sbc[0] != (uint64)(tmsize_t)sbc[0]) {\n TIFFError(TIFF2PDF_MODULE, "Integer overflow");\n t2p->t2p_error = T2P_ERR_ERROR;\n }\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 -=2;\n\t\t\t\tk +=2;\n\t\t\t}\n\t\t\tk = checkAdd64(k, 2, t2p);\n\t\t\tk = checkAdd64(k, 6, 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}']
1,525
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_sqr.c/#L162
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) { int i, j, max; const BN_ULONG *ap; BN_ULONG *rp; max = n * 2; ap = a; rp = r; rp[0] = rp[max - 1] = 0; rp++; j = n; if (--j > 0) { ap++; rp[j] = bn_mul_words(rp, ap, j, ap[-1]); rp += 2; } for (i = n - 2; i > 0; i--) { j--; ap++; rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); rp += 2; } bn_add_words(r, r, r, max); bn_sqr_words(tmp, a, n); bn_add_words(r, r, tmp, max); }
['int 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 if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!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}', 'int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a;\n const BIGNUM *ca;\n BN_CTX_start(ctx);\n if ((a = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (y != NULL) {\n if (x == y) {\n if (!BN_sqr(a, x, ctx))\n goto err;\n } else {\n if (!BN_mul(a, x, y, ctx))\n goto err;\n }\n ca = a;\n } else\n ca = x;\n ret = BN_div_recp(NULL, r, ca, recp, ctx);\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
1,526
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/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; }
['ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,\n const BIGNUM *in_kinv, const BIGNUM *in_r,\n EC_KEY *eckey)\n{\n int ok = 0, i;\n BIGNUM *kinv = NULL, *s, *m = NULL, *tmp = NULL;\n const BIGNUM *order, *ckinv;\n BN_CTX *ctx = NULL;\n const EC_GROUP *group;\n ECDSA_SIG *ret;\n const BIGNUM *priv_key;\n group = EC_KEY_get0_group(eckey);\n priv_key = EC_KEY_get0_private_key(eckey);\n if (group == NULL || priv_key == NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_PASSED_NULL_PARAMETER);\n return NULL;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return NULL;\n }\n ret = ECDSA_SIG_new();\n if (ret == NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n s = ret->s;\n if ((ctx = BN_CTX_new()) == NULL ||\n (tmp = BN_new()) == NULL || (m = BN_new()) == NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_EC_LIB);\n goto err;\n }\n i = BN_num_bits(order);\n if (8 * dgst_len > i)\n dgst_len = (i + 7) / 8;\n if (!BN_bin2bn(dgst, dgst_len, m)) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);\n goto err;\n }\n do {\n if (in_kinv == NULL || in_r == NULL) {\n if (!ecdsa_sign_setup(eckey, ctx, &kinv, &ret->r, dgst, dgst_len)) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_ECDSA_LIB);\n goto err;\n }\n ckinv = kinv;\n } else {\n ckinv = in_kinv;\n if (BN_copy(ret->r, in_r) == NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n }\n if (!BN_mod_mul(tmp, priv_key, ret->r, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_add_quick(s, tmp, m, order)) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(s, s, ckinv, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (BN_is_zero(s)) {\n if (in_kinv != NULL && in_r != NULL) {\n ECerr(EC_F_OSSL_ECDSA_SIGN_SIG, EC_R_NEED_NEW_SETUP_VALUES);\n goto err;\n }\n } else\n break;\n }\n while (1);\n ok = 1;\n err:\n if (!ok) {\n ECDSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(tmp);\n BN_clear_free(kinv);\n return ret;\n}', 'static int ecdsa_sign_setup(EC_KEY *eckey, 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 = NULL, *r = NULL, *X = NULL;\n const BIGNUM *order;\n EC_POINT *tmp_point = NULL;\n const EC_GROUP *group;\n int ret = 0;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return 0;\n }\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n } else\n ctx = ctx_in;\n k = BN_new();\n r = BN_new();\n X = BN_new();\n if (k == NULL || r == NULL || X == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if ((tmp_point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n do {\n do\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce\n (k, order, EC_KEY_get0_private_key(eckey), dgst, dlen,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n } else {\n if (!BN_priv_rand_range(k, order)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n }\n while (BN_is_zero(k));\n if (!BN_add(k, k, order))\n goto err;\n if (BN_num_bits(k) <= BN_num_bits(order))\n if (!BN_add(k, k, order))\n goto err;\n if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==\n NID_X9_62_prime_field) {\n if (!EC_POINT_get_affine_coordinates_GFp\n (group, tmp_point, X, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#ifndef OPENSSL_NO_EC2M\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group,\n tmp_point, X, NULL,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#endif\n if (!BN_nnmod(r, X, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n }\n while (BN_is_zero(r));\n if (EC_GROUP_get_mont_data(group) != NULL) {\n if (!BN_set_word(X, 2)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_sub(X, order, X, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(X, BN_FLG_CONSTTIME);\n if (!BN_mod_exp_mont_consttime\n (k, k, X, order, ctx, EC_GROUP_get_mont_data(group))) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n } else {\n if (!BN_mod_inverse(k, k, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n }\n BN_clear_free(*rp);\n BN_clear_free(*kinvp);\n *rp = r;\n *kinvp = k;\n ret = 1;\n err:\n if (!ret) {\n BN_clear_free(k);\n BN_clear_free(r);\n }\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n EC_POINT_free(tmp_point);\n BN_clear_free(X);\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_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}']
1,527
0
https://github.com/libav/libav/blob/a8475bbdb64e638bd8161df9647876fd23f8a29a/libavcodec/aacsbr.c/#L1195
static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct, float *out, float X[2][38][64], float mdct_buf[2][64], float *v0, int *v_off, const unsigned int div) { int i, n; const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; float *v; for (i = 0; i < 32; i++) { if (*v_off == 0) { int saved_samples = (1280 - 128) >> div; memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div); } else { *v_off -= 128 >> div; } v = v0 + *v_off; if (div) { for (n = 0; n < 32; n++) { X[0][i][ n] = -X[0][i][n]; X[0][i][32+n] = X[1][i][31-n]; } ff_imdct_half(mdct, mdct_buf[0], X[0][i]); for (n = 0; n < 32; n++) { v[ n] = mdct_buf[0][63 - 2*n]; v[63 - n] = -mdct_buf[0][62 - 2*n]; } } else { for (n = 1; n < 64; n+=2) { X[1][i][n] = -X[1][i][n]; } ff_imdct_half(mdct, mdct_buf[0], X[0][i]); ff_imdct_half(mdct, mdct_buf[1], X[1][i]); for (n = 0; n < 64; n++) { v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ]; v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ]; } } dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div); dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div); dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div); out += 64 >> div; } }
['void ff_sbr_apply(AACContext *ac, SpectralBandReplication *sbr, int id_aac,\n float* L, float* R)\n{\n int downsampled = ac->m4ac.ext_sample_rate < sbr->sample_rate;\n int ch;\n int nch = (id_aac == TYPE_CPE) ? 2 : 1;\n if (sbr->start) {\n sbr_dequant(sbr, id_aac);\n }\n for (ch = 0; ch < nch; ch++) {\n sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, ch ? R : L, sbr->data[ch].analysis_filterbank_samples,\n (float*)sbr->qmf_filter_scratch,\n sbr->data[ch].W, 1/(-1024 * ac->sf_scale));\n sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W);\n if (sbr->start) {\n sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]);\n sbr_chirp(sbr, &sbr->data[ch]);\n sbr_hf_gen(ac, sbr, sbr->X_high, sbr->X_low, sbr->alpha0, sbr->alpha1,\n sbr->data[ch].bw_array, sbr->data[ch].t_env,\n sbr->data[ch].bs_num_env);\n sbr_mapping(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);\n sbr_env_estimate(sbr->e_curr, sbr->X_high, sbr, &sbr->data[ch]);\n sbr_gain_calc(ac, sbr, &sbr->data[ch], sbr->data[ch].e_a);\n sbr_hf_assemble(sbr->data[ch].Y, sbr->X_high, sbr, &sbr->data[ch],\n sbr->data[ch].e_a);\n }\n sbr_x_gen(sbr, sbr->X[ch], sbr->X_low, sbr->data[ch].Y, ch);\n }\n if (ac->m4ac.ps == 1) {\n if (sbr->ps.start) {\n ff_ps_apply(ac->avctx, &sbr->ps, sbr->X[0], sbr->X[1], sbr->kx[1] + sbr->m[1]);\n } else {\n memcpy(sbr->X[1], sbr->X[0], sizeof(sbr->X[0]));\n }\n nch = 2;\n }\n sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, L, sbr->X[0], sbr->qmf_filter_scratch,\n sbr->data[0].synthesis_filterbank_samples,\n &sbr->data[0].synthesis_filterbank_samples_offset,\n downsampled);\n if (nch == 2)\n sbr_qmf_synthesis(&ac->dsp, &sbr->mdct, R, sbr->X[1], sbr->qmf_filter_scratch,\n sbr->data[1].synthesis_filterbank_samples,\n &sbr->data[1].synthesis_filterbank_samples_offset,\n downsampled);\n}', 'static void sbr_qmf_synthesis(DSPContext *dsp, FFTContext *mdct,\n float *out, float X[2][38][64],\n float mdct_buf[2][64],\n float *v0, int *v_off, const unsigned int div)\n{\n int i, n;\n const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us;\n float *v;\n for (i = 0; i < 32; i++) {\n if (*v_off == 0) {\n int saved_samples = (1280 - 128) >> div;\n memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float));\n *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div);\n } else {\n *v_off -= 128 >> div;\n }\n v = v0 + *v_off;\n if (div) {\n for (n = 0; n < 32; n++) {\n X[0][i][ n] = -X[0][i][n];\n X[0][i][32+n] = X[1][i][31-n];\n }\n ff_imdct_half(mdct, mdct_buf[0], X[0][i]);\n for (n = 0; n < 32; n++) {\n v[ n] = mdct_buf[0][63 - 2*n];\n v[63 - n] = -mdct_buf[0][62 - 2*n];\n }\n } else {\n for (n = 1; n < 64; n+=2) {\n X[1][i][n] = -X[1][i][n];\n }\n ff_imdct_half(mdct, mdct_buf[0], X[0][i]);\n ff_imdct_half(mdct, mdct_buf[1], X[1][i]);\n for (n = 0; n < 64; n++) {\n v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ];\n v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ];\n }\n }\n dsp->vector_fmul_add(out, v , sbr_qmf_window , zero64, 64 >> div);\n dsp->vector_fmul_add(out, v + ( 192 >> div), sbr_qmf_window + ( 64 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + ( 256 >> div), sbr_qmf_window + (128 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + ( 448 >> div), sbr_qmf_window + (192 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + ( 512 >> div), sbr_qmf_window + (256 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + ( 704 >> div), sbr_qmf_window + (320 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + ( 768 >> div), sbr_qmf_window + (384 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + ( 960 >> div), sbr_qmf_window + (448 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + (1024 >> div), sbr_qmf_window + (512 >> div), out , 64 >> div);\n dsp->vector_fmul_add(out, v + (1216 >> div), sbr_qmf_window + (576 >> div), out , 64 >> div);\n out += 64 >> div;\n }\n}']
1,528
0
https://github.com/libav/libav/blob/b297129bdb0e779824db9b50440570212df58353/ffmpeg.c/#L3460
static void opt_output_file(const char *filename) { AVFormatContext *oc; int use_video, use_audio, use_subtitle; int input_has_video, input_has_audio, input_has_subtitle; AVFormatParameters params, *ap = &params; AVOutputFormat *file_oformat; if (!strcmp(filename, "-")) filename = "pipe:"; oc = avformat_alloc_context(); if (!oc) { print_error(filename, AVERROR(ENOMEM)); av_exit(1); } if (last_asked_format) { file_oformat = av_guess_format(last_asked_format, NULL, NULL); if (!file_oformat) { fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format); av_exit(1); } last_asked_format = NULL; } else { file_oformat = av_guess_format(NULL, filename, NULL); if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); av_exit(1); } } oc->oformat = file_oformat; av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && av_strstart(filename, "http:", NULL)) { int err = read_ffserver_streams(oc, filename); if (err < 0) { print_error(filename, err); av_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; if (nb_input_files > 0) { check_audio_video_sub_inputs(&input_has_video, &input_has_audio, &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; if (!input_has_subtitle) use_subtitle = 0; } if (audio_disable) { use_audio = 0; } if (video_disable) { use_video = 0; } if (subtitle_disable) { use_subtitle = 0; } if (use_video) { new_video_stream(oc); } if (use_audio) { new_audio_stream(oc); } if (use_subtitle) { new_subtitle_stream(oc); } oc->timestamp = rec_timestamp; for(; metadata_count>0; metadata_count--){ av_metadata_set(&oc->metadata, metadata[metadata_count-1].key, metadata[metadata_count-1].value); } av_metadata_conv(oc, oc->oformat->metadata_conv, NULL); } output_files[nb_output_files++] = oc; if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR_NUMEXPECTED); av_exit(1); } } if (!(oc->oformat->flags & AVFMT_NOFILE)) { if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (url_exist(filename)) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); av_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); av_exit(1); } } } if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { fprintf(stderr, "Could not open '%s'\n", filename); av_exit(1); } } memset(ap, 0, sizeof(*ap)); if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); av_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->loop_output = loop_output; oc->flags |= AVFMT_FLAG_NONBLOCK; set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM); }
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = &params;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n av_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n av_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n av_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) {\n use_audio = 0;\n }\n if (video_disable) {\n use_video = 0;\n }\n if (subtitle_disable) {\n use_subtitle = 0;\n }\n if (use_video) {\n new_video_stream(oc);\n }\n if (use_audio) {\n new_audio_stream(oc);\n }\n if (use_subtitle) {\n new_subtitle_stream(oc);\n }\n oc->timestamp = rec_timestamp;\n for(; metadata_count>0; metadata_count--){\n av_metadata_set(&oc->metadata, metadata[metadata_count-1].key,\n metadata[metadata_count-1].value);\n }\n av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n av_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n av_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n av_exit(1);\n }\n }\n }\n if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {\n fprintf(stderr, "Could not open \'%s\'\\n", filename);\n av_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n av_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n switch(err) {\n case AVERROR_NUMEXPECTED:\n fprintf(stderr, "%s: Incorrect image filename syntax.\\n"\n "Use \'%%d\' to specify the image number:\\n"\n " for img1.jpg, img2.jpg, ..., use \'img%%d.jpg\';\\n"\n " for img001.jpg, img002.jpg, ..., use \'img%%03d.jpg\'.\\n",\n filename);\n break;\n case AVERROR_INVALIDDATA:\n fprintf(stderr, "%s: Error while parsing header\\n", filename);\n break;\n case AVERROR_NOFMT:\n fprintf(stderr, "%s: Unknown format\\n", filename);\n break;\n case AVERROR(EIO):\n fprintf(stderr, "%s: I/O error occurred\\n"\n "Usually that means that input file is truncated and/or corrupted.\\n",\n filename);\n break;\n case AVERROR(ENOMEM):\n fprintf(stderr, "%s: memory allocation error occurred\\n", filename);\n break;\n case AVERROR(ENOENT):\n fprintf(stderr, "%s: no such file or directory\\n", filename);\n break;\n#if CONFIG_NETWORK\n case AVERROR(FF_NETERROR(EPROTONOSUPPORT)):\n fprintf(stderr, "%s: Unsupported network protocol\\n", filename);\n break;\n#endif\n default:\n fprintf(stderr, "%s: Error while opening file\\n", filename);\n break;\n }\n}']
1,529
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_shift.c/#L165
int BN_rshift(BIGNUM *r, const BIGNUM *a, int n) { int i, j, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l, tmp; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; rb = n % BN_BITS2; lb = BN_BITS2 - rb; if (nw >= a->top || a->top == 0) { BN_zero(r); return 1; } i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2; if (r != a) { if (bn_wexpand(r, i) == NULL) return 0; r->neg = a->neg; } else { if (n == 0) return 1; } f = &(a->d[nw]); t = r->d; j = a->top - nw; r->top = i; if (rb == 0) { for (i = j; i != 0; i--) *(t++) = *(f++); } else { l = *(f++); for (i = j - 1; i != 0; i--) { tmp = (l >> rb) & BN_MASK2; l = *(f++); *(t++) = (tmp | (l << lb)) & BN_MASK2; } if ((l = (l >> rb) & BN_MASK2)) *(t) = l; } if (!r->top) r->neg = 0; bn_check_top(r); return 1; }
['static int test_div_recip(void)\n{\n BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL;\n BN_RECP_CTX *recp = NULL;\n int st = 0, i;\n if (!TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_ptr(c = BN_new())\n || !TEST_ptr(d = BN_new())\n || !TEST_ptr(e = BN_new())\n || !TEST_ptr(recp = BN_RECP_CTX_new()))\n goto err;\n for (i = 0; i < NUM0 + NUM1; i++) {\n if (i < NUM1) {\n BN_bntest_rand(a, 400, 0, 0);\n BN_copy(b, a);\n BN_lshift(a, a, i);\n BN_add_word(a, i);\n } else\n BN_bntest_rand(b, 50 + 3 * (i - NUM1), 0, 0);\n a->neg = rand_neg();\n b->neg = rand_neg();\n BN_RECP_CTX_set(recp, b, ctx);\n BN_div_recp(d, c, a, recp, ctx);\n BN_mul(e, d, b, ctx);\n BN_add(d, e, c);\n BN_sub(d, d, a);\n if (!TEST_BN_eq_zero(d))\n goto err;\n }\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n BN_free(e);\n BN_RECP_CTX_free(recp);\n return st;\n}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!BN_copy(&(recp->N), d))\n return 0;\n BN_zero(&(recp->Nr));\n recp->num_bits = BN_num_bits(d);\n recp->shift = 0;\n return 1;\n}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int i, j, ret = 0;\n BIGNUM *a, *b, *d, *r;\n BN_CTX_start(ctx);\n d = (dv != NULL) ? dv : BN_CTX_get(ctx);\n r = (rem != NULL) ? rem : BN_CTX_get(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_ucmp(m, &(recp->N)) < 0) {\n BN_zero(d);\n if (!BN_copy(r, m)) {\n BN_CTX_end(ctx);\n return 0;\n }\n BN_CTX_end(ctx);\n return 1;\n }\n i = BN_num_bits(m);\n j = recp->num_bits << 1;\n if (j > i)\n i = j;\n if (i != recp->shift)\n recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx);\n if (recp->shift == -1)\n goto err;\n if (!BN_rshift(a, m, recp->num_bits))\n goto err;\n if (!BN_mul(b, a, &(recp->Nr), ctx))\n goto err;\n if (!BN_rshift(d, b, i - recp->num_bits))\n goto err;\n d->neg = 0;\n if (!BN_mul(b, &(recp->N), d, ctx))\n goto err;\n if (!BN_usub(r, m, b))\n goto err;\n r->neg = 0;\n j = 0;\n while (BN_ucmp(r, &(recp->N)) >= 0) {\n if (j++ > 2) {\n BNerr(BN_F_BN_DIV_RECP, BN_R_BAD_RECIPROCAL);\n goto err;\n }\n if (!BN_usub(r, r, &(recp->N)))\n goto err;\n if (!BN_add_word(d, 1))\n goto err;\n }\n r->neg = BN_is_zero(r) ? 0 : m->neg;\n d->neg = m->neg ^ recp->N.neg;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(dv);\n bn_check_top(rem);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, j, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l, tmp;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n rb = n % BN_BITS2;\n lb = BN_BITS2 - rb;\n if (nw >= a->top || a->top == 0) {\n BN_zero(r);\n return 1;\n }\n i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n if (r != a) {\n 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}']
1,530
0
https://github.com/libav/libav/blob/c9ef6b09326a24010bf86d6b0d19cfa42df4d546/libavformat/oggdec.c/#L66
static int ogg_save(AVFormatContext *s) { struct ogg *ogg = s->priv_data; struct ogg_state *ost = av_malloc(sizeof(*ost) + (ogg->nstreams - 1) * sizeof(*ogg->streams)); int i; ost->pos = avio_tell(s->pb); ost->curidx = ogg->curidx; ost->next = ogg->state; ost->nstreams = ogg->nstreams; memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams)); for (i = 0; i < ogg->nstreams; i++) { struct ogg_stream *os = ogg->streams + i; os->buf = av_mallocz(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(os->buf, ost->streams[i].buf, os->bufpos); } ogg->state = ost; return 0; }
['static int ogg_save(AVFormatContext *s)\n{\n struct ogg *ogg = s->priv_data;\n struct ogg_state *ost =\n av_malloc(sizeof(*ost) + (ogg->nstreams - 1) * sizeof(*ogg->streams));\n int i;\n ost->pos = avio_tell(s->pb);\n ost->curidx = ogg->curidx;\n ost->next = ogg->state;\n ost->nstreams = ogg->nstreams;\n memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams));\n for (i = 0; i < ogg->nstreams; i++) {\n struct ogg_stream *os = ogg->streams + i;\n os->buf = av_mallocz(os->bufsize + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(os->buf, ost->streams[i].buf, os->bufpos);\n }\n ogg->state = ost;\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if (size > (INT_MAX - 32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size + 32);\n if (!ptr)\n return ptr;\n diff = ((-(long)ptr - 1) & 31) + 1;\n ptr = (char *)ptr + diff;\n ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr, 32, size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32, size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'static av_always_inline int64_t avio_tell(AVIOContext *s)\n{\n return avio_seek(s, 0, SEEK_CUR);\n}']
1,531
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L393
int BN_set_word(BIGNUM *a, BN_ULONG w) { bn_check_top(a); if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL) return 0; a->neg = 0; a->d[0] = w; a->top = (w ? 1 : 0); bn_check_top(a); return 1; }
['static int dh_builtin_genparams(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n BIGNUM *t1, *t2;\n int g, ok = -1;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (!ret->p && ((ret->p = BN_new()) == NULL))\n goto err;\n if (!ret->g && ((ret->g = BN_new()) == NULL))\n goto err;\n if (generator <= 1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);\n goto err;\n }\n if (generator == DH_GENERATOR_2) {\n if (!BN_set_word(t1, 24))\n goto err;\n if (!BN_set_word(t2, 11))\n goto err;\n g = 2;\n } else if (generator == DH_GENERATOR_5) {\n if (!BN_set_word(t1, 10))\n goto err;\n if (!BN_set_word(t2, 3))\n goto err;\n g = 5;\n } else {\n if (!BN_set_word(t1, 2))\n goto err;\n if (!BN_set_word(t2, 1))\n goto err;\n g = generator;\n }\n if (!BN_generate_prime_ex(ret->p, prime_len, 1, t1, t2, cb))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n if (!BN_set_word(ret->g, g))\n goto err;\n ok = 1;\n err:\n if (ok == -1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB);\n ok = 0;\n }\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}']
1,532
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_mont.c/#L208
static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont) { BIGNUM *n; BN_ULONG *ap, *np, *rp, n0, v, carry; int nl, max, i; n = &(mont->N); nl = n->top; if (nl == 0) { ret->top = 0; return (1); } max = (2 * nl); if (bn_wexpand(r, max) == NULL) return (0); r->neg ^= n->neg; np = n->d; rp = r->d; i = max - r->top; if (i) memset(&rp[r->top], 0, sizeof(*rp) * i); r->top = max; n0 = mont->n0[0]; for (carry = 0, i = 0; i < nl; i++, rp++) { v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2); v = (v + carry + rp[nl]) & BN_MASK2; carry |= (v != rp[nl]); carry &= (v <= rp[nl]); rp[nl] = v; } if (bn_wexpand(ret, nl) == NULL) return (0); ret->top = nl; ret->neg = r->neg; rp = ret->d; ap = &(r->d[nl]); # define BRANCH_FREE 1 # if BRANCH_FREE { BN_ULONG *nrp; size_t m; v = bn_sub_words(rp, ap, np, nl) - carry; m = (0 - (size_t)v); nrp = (BN_ULONG *)(((PTR_SIZE_INT) rp & ~m) | ((PTR_SIZE_INT) ap & m)); for (i = 0, nl -= 4; i < nl; i += 4) { BN_ULONG t1, t2, t3, t4; t1 = nrp[i + 0]; t2 = nrp[i + 1]; t3 = nrp[i + 2]; ap[i + 0] = 0; t4 = nrp[i + 3]; ap[i + 1] = 0; rp[i + 0] = t1; ap[i + 2] = 0; rp[i + 1] = t2; ap[i + 3] = 0; rp[i + 2] = t3; rp[i + 3] = t4; } for (nl += 4; i < nl; i++) rp[i] = nrp[i], ap[i] = 0; } # else if (bn_sub_words(rp, ap, np, nl) - carry) memcpy(rp, ap, nl * sizeof(BN_ULONG)); # endif bn_correct_top(r); bn_correct_top(ret); bn_check_top(ret); return (1); }
['int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n int retn = 0;\n#ifdef MONT_WORD\n BIGNUM *t;\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) && BN_copy(t, a))\n retn = BN_from_montgomery_word(ret, t, mont);\n BN_CTX_end(ctx);\n#else\n BIGNUM *t1, *t2;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t1 == NULL || t2 == NULL)\n goto err;\n if (!BN_copy(t1, a))\n goto err;\n BN_mask_bits(t1, mont->ri);\n if (!BN_mul(t2, t1, &mont->Ni, ctx))\n goto err;\n BN_mask_bits(t2, mont->ri);\n if (!BN_mul(t1, t2, &mont->N, ctx))\n goto err;\n if (!BN_add(t2, a, t1))\n goto err;\n if (!BN_rshift(ret, t2, mont->ri))\n goto err;\n if (BN_ucmp(ret, &(mont->N)) >= 0) {\n if (!BN_usub(ret, ret, &(mont->N)))\n goto err;\n }\n retn = 1;\n bn_check_top(ret);\n err:\n BN_CTX_end(ctx);\n#endif\n return (retn);\n}', 'static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return (1);\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return (0);\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n i = max - r->top;\n if (i)\n memset(&rp[r->top], 0, sizeof(*rp) * i);\n r->top = max;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return (0);\n ret->top = nl;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n# define BRANCH_FREE 1\n# if BRANCH_FREE\n {\n BN_ULONG *nrp;\n size_t m;\n v = bn_sub_words(rp, ap, np, nl) - carry;\n m = (0 - (size_t)v);\n nrp =\n (BN_ULONG *)(((PTR_SIZE_INT) rp & ~m) | ((PTR_SIZE_INT) ap & m));\n for (i = 0, nl -= 4; i < nl; i += 4) {\n BN_ULONG t1, t2, t3, t4;\n t1 = nrp[i + 0];\n t2 = nrp[i + 1];\n t3 = nrp[i + 2];\n ap[i + 0] = 0;\n t4 = nrp[i + 3];\n ap[i + 1] = 0;\n rp[i + 0] = t1;\n ap[i + 2] = 0;\n rp[i + 1] = t2;\n ap[i + 3] = 0;\n rp[i + 2] = t3;\n rp[i + 3] = t4;\n }\n for (nl += 4; i < nl; i++)\n rp[i] = nrp[i], ap[i] = 0;\n }\n# else\n if (bn_sub_words(rp, ap, np, nl) - carry)\n memcpy(rp, ap, nl * sizeof(BN_ULONG));\n# endif\n bn_correct_top(r);\n bn_correct_top(ret);\n bn_check_top(ret);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
1,533
0
https://github.com/openssl/openssl/blob/55525742f4c2bf416013fc3a75ec642775d97f80/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int RSA_eay_private_encrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM *f, *ret, *br, *res;\n\tint i,j,k,num=0,r= -1;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tint local_blinding = 0;\n\tBN_BLINDING *blinding = NULL;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_CTX_start(ctx);\n\tf = BN_CTX_get(ctx);\n\tbr = BN_CTX_get(ctx);\n\tret = BN_CTX_get(ctx);\n\tnum = BN_num_bytes(rsa->n);\n\tbuf = OPENSSL_malloc(num);\n\tif(!f || !ret || !buf)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\ti=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_X931_PADDING:\n\t\ti=RSA_padding_add_X931(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\ti=RSA_padding_add_none(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_SSLV23_PADDING:\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (i <= 0) goto err;\n\tif (BN_bin2bn(buf,num,f) == NULL) goto err;\n\tif (BN_ucmp(f, rsa->n) >= 0)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n\t\tgoto err;\n\t\t}\n\tif (!(rsa->flags & RSA_FLAG_NO_BLINDING))\n\t\t{\n\t\tblinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n\t\tif (blinding == NULL)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (blinding != NULL)\n\t\tif (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx))\n\t\t\tgoto err;\n\tif ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||\n\t\t((rsa->p != NULL) &&\n\t\t(rsa->q != NULL) &&\n\t\t(rsa->dmp1 != NULL) &&\n\t\t(rsa->dmq1 != NULL) &&\n\t\t(rsa->iqmp != NULL)) )\n\t\t{\n\t\tif (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tBIGNUM local_d;\n\t\tBIGNUM *d = NULL;\n\t\tif (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))\n\t\t\t{\n\t\t\tBN_init(&local_d);\n\t\t\td = &local_d;\n\t\t\tBN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n\t\t\t}\n\t\telse\n\t\t\td = rsa->d;\n\t\tMONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);\n\t\tif (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,\n\t\t\t\trsa->_method_mod_n)) goto err;\n\t\t}\n\tif (blinding)\n\t\tif (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx))\n\t\t\tgoto err;\n\tif (padding == RSA_X931_PADDING)\n\t\t{\n\t\tBN_sub(f, rsa->n, ret);\n\t\tif (BN_cmp(ret, f))\n\t\t\tres = f;\n\t\telse\n\t\t\tres = ret;\n\t\t}\n\telse\n\t\tres = ret;\n\tj=BN_num_bytes(res);\n\ti=BN_bn2bin(res,&(to[num-j]));\n\tfor (k=0; k<(num-i); k++)\n\t\tto[k]=0;\n\tr=num;\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint got_write_lock = 0;\n\tBN_MONT_CTX *ret;\n\tCRYPTO_r_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\tCRYPTO_r_unlock(lock);\n\t\tCRYPTO_w_lock(lock);\n\t\tgot_write_lock = 1;\n\t\tif (!*pmont)\n\t\t\t{\n\t\t\tret = BN_MONT_CTX_new();\n\t\t\tif (ret && !BN_MONT_CTX_set(ret, mod, ctx))\n\t\t\t\tBN_MONT_CTX_free(ret);\n\t\t\telse\n\t\t\t\t*pmont = ret;\n\t\t\t}\n\t\t}\n\tret = *pmont;\n\tif (got_write_lock)\n\t\tCRYPTO_w_unlock(lock);\n\telse\n\t\tCRYPTO_r_unlock(lock);\n\treturn ret;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM local_A, local_B;\n\tBIGNUM *pA, *pB;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
1,534
0
https://github.com/openssl/openssl/blob/43a0449fe6ce18b750803be8a115a412a7235496/crypto/bn/bn_rand.c/#L82
static int bnrand(int testing, BIGNUM *rnd, int bits, int top, int bottom) { unsigned char *buf = NULL; int ret = 0, bit, bytes, mask; time_t tim; if (bits == 0) { if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY) goto toosmall; BN_zero(rnd); return 1; } if (bits < 0 || (bits == 1 && top > 0)) goto toosmall; bytes = (bits + 7) / 8; bit = (bits - 1) % 8; mask = 0xff << (bit + 1); buf = OPENSSL_malloc(bytes); if (buf == NULL) { BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE); goto err; } time(&tim); RAND_add(&tim, sizeof(tim), 0.0); if (RAND_bytes(buf, bytes) <= 0) goto err; if (testing) { int i; unsigned char c; for (i = 0; i < bytes; i++) { if (RAND_bytes(&c, 1) <= 0) goto err; if (c >= 128 && i > 0) buf[i] = buf[i - 1]; else if (c < 42) buf[i] = 0; else if (c < 84) buf[i] = 255; } } if (top >= 0) { if (top) { if (bit == 0) { buf[0] = 1; buf[1] |= 0x80; } else { buf[0] |= (3 << (bit - 1)); } } else { buf[0] |= (1 << bit); } } buf[0] &= ~mask; if (bottom) buf[bytes - 1] |= 1; if (!BN_bin2bn(buf, bytes, rnd)) goto err; ret = 1; err: OPENSSL_clear_free(buf, bytes); bn_check_top(rnd); return (ret); toosmall: BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL); return 0; }
['static int test_gf2m_mod()\n{\n BIGNUM *a = NULL, *b[2] = {NULL,NULL}, *c = NULL, *d = NULL, *e = NULL;\n int i, j, st = 0;\n if (!TEST_ptr(a = BN_new())\n || !TEST_ptr(b[0] = BN_new())\n || !TEST_ptr(b[1] = BN_new())\n || !TEST_ptr(c = BN_new())\n || !TEST_ptr(d = BN_new())\n || !TEST_ptr(e = BN_new()))\n goto err;\n BN_GF2m_arr2poly(p0, b[0]);\n BN_GF2m_arr2poly(p1, b[1]);\n for (i = 0; i < NUM0; i++) {\n BN_bntest_rand(a, 1024, 0, 0);\n for (j = 0; j < 2; j++) {\n BN_GF2m_mod(c, a, b[j]);\n BN_GF2m_add(d, a, c);\n BN_GF2m_mod(e, d, b[j]);\n if (!TEST_BN_eq_zero(e))\n goto err;\n }\n }\n st = 1;\n err:\n BN_free(a);\n BN_free(b[0]);\n BN_free(b[1]);\n BN_free(c);\n BN_free(d);\n BN_free(e);\n return st;\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(1, rnd, bits, top, bottom);\n}', 'static int bnrand(int testing, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n if (testing) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', '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}']
1,535
0
https://github.com/libav/libav/blob/831018b0bbe26a603802a9022472f714a59293be/libavcodec/bitstream.h/#L237
static inline void skip_remaining(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE bc->bits >>= n; #else bc->bits <<= n; #endif bc->bits_left -= n; }
['static int decode_mb(CLVContext *c, int x, int y)\n{\n int i, has_ac[6], off;\n for (i = 0; i < 6; i++)\n has_ac[i] = bitstream_read_bit(&c->bc);\n off = x * 16 + y * 16 * c->pic->linesize[0];\n for (i = 0; i < 4; i++) {\n if (decode_block(c, c->block, has_ac[i], c->ac_quant) < 0)\n return AVERROR_INVALIDDATA;\n if (!x && !(i & 1)) {\n c->block[0] += c->top_dc[0];\n c->top_dc[0] = c->block[0];\n } else {\n c->block[0] += c->left_dc[(i & 2) >> 1];\n }\n c->left_dc[(i & 2) >> 1] = c->block[0];\n c->block[0] *= c->luma_dc_quant;\n clv_dct(c->block);\n if (i == 2)\n off += c->pic->linesize[0] * 8;\n c->idsp.put_pixels_clamped(c->block,\n c->pic->data[0] + off + (i & 1) * 8,\n c->pic->linesize[0]);\n }\n off = x * 8 + y * 8 * c->pic->linesize[1];\n for (i = 1; i < 3; i++) {\n if (decode_block(c, c->block, has_ac[i + 3], c->ac_quant) < 0)\n return AVERROR_INVALIDDATA;\n if (!x) {\n c->block[0] += c->top_dc[i];\n c->top_dc[i] = c->block[0];\n } else {\n c->block[0] += c->left_dc[i + 1];\n }\n c->left_dc[i + 1] = c->block[0];\n c->block[0] *= c->chroma_dc_quant;\n clv_dct(c->block);\n c->idsp.put_pixels_clamped(c->block, c->pic->data[i] + off,\n c->pic->linesize[i]);\n }\n return 0;\n}', 'static inline int decode_block(CLVContext *ctx, int16_t *blk, int has_ac,\n int ac_quant)\n{\n BitstreamContext *bc = &ctx->bc;\n int idx = 1, last = 0, val, skip;\n memset(blk, 0, sizeof(*blk) * 64);\n blk[0] = bitstream_read_vlc(bc, ctx->dc_vlc.table, 9, 3);\n if (blk[0] < 0)\n return AVERROR_INVALIDDATA;\n blk[0] -= 63;\n if (!has_ac)\n return 0;\n while (idx < 64 && !last) {\n val = bitstream_read_vlc(bc, ctx->ac_vlc.table, 9, 2);\n if (val < 0)\n return AVERROR_INVALIDDATA;\n if (val != 0x1BFF) {\n last = val >> 12;\n skip = (val >> 4) & 0xFF;\n val &= 0xF;\n if (bitstream_read_bit(bc))\n val = -val;\n } else {\n last = bitstream_read_bit(bc);\n skip = bitstream_read(bc, 6);\n val = bitstream_read_signed(bc, 8);\n }\n if (val) {\n int aval = FFABS(val), sign = val < 0;\n val = ac_quant * (2 * aval + 1);\n if (!(ac_quant & 1))\n val--;\n if (sign)\n val = -val;\n }\n idx += skip;\n if (idx >= 64)\n return AVERROR_INVALIDDATA;\n blk[ff_zigzag_direct[idx++]] = val;\n }\n return (idx <= 64 && last) ? 0 : -1;\n}', 'static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2],\n int bits, int max_depth)\n{\n int nb_bits;\n unsigned idx = bitstream_peek(bc, bits);\n int code = table[idx][0];\n int n = table[idx][1];\n if (max_depth > 1 && n < 0) {\n skip_remaining(bc, bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n if (max_depth > 2 && n < 0) {\n skip_remaining(bc, nb_bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n }\n }\n skip_remaining(bc, n);\n return code;\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
1,536
0
https://github.com/openssl/openssl/blob/b1860d6c71733314417d053a72af66ae72e8268e/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)\n{\n BIGNUM *r1, *m1, *vrfy, *r2, *m[RSA_MAX_PRIME_NUM - 2];\n int ret = 0, i, ex_primes = 0;\n RSA_PRIME_INFO *pinfo;\n BN_CTX_start(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n m1 = BN_CTX_get(ctx);\n vrfy = BN_CTX_get(ctx);\n if (vrfy == NULL)\n goto err;\n if (rsa->version == RSA_ASN1_VERSION_MULTI\n && ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0\n || ex_primes > RSA_MAX_PRIME_NUM - 2))\n goto err;\n {\n BIGNUM *p = BN_new(), *q = BN_new();\n if (p == NULL || q == NULL) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME);\n if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) {\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_p, rsa->lock, p, ctx)\n || !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,\n rsa->lock, q, ctx)) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n if (ex_primes > 0) {\n BIGNUM *r = BN_new();\n if (r == NULL) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(r, pinfo->r, BN_FLG_CONSTTIME);\n if (!BN_MONT_CTX_set_locked(&pinfo->m, rsa->lock, r, ctx)) {\n BN_free(p);\n BN_free(q);\n BN_free(r);\n goto err;\n }\n }\n BN_free(r);\n }\n }\n BN_free(p);\n BN_free(q);\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 {\n BIGNUM *c = BN_new();\n if (c == NULL)\n goto err;\n BN_with_flags(c, I, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, c, rsa->q, ctx)) {\n BN_free(c);\n goto err;\n }\n {\n BIGNUM *dmq1 = BN_new();\n if (dmq1 == NULL) {\n BN_free(c);\n goto err;\n }\n BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,\n rsa->_method_mod_q)) {\n BN_free(c);\n BN_free(dmq1);\n goto err;\n }\n BN_free(dmq1);\n }\n if (!BN_mod(r1, c, rsa->p, ctx)) {\n BN_free(c);\n goto err;\n }\n BN_free(c);\n }\n {\n BIGNUM *dmp1 = BN_new();\n if (dmp1 == NULL)\n goto err;\n BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,\n rsa->_method_mod_p)) {\n BN_free(dmp1);\n goto err;\n }\n BN_free(dmp1);\n }\n if (ex_primes > 0) {\n BIGNUM *di = BN_new(), *cc = BN_new();\n if (cc == NULL || di == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n if ((m[i] = BN_CTX_get(ctx)) == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(cc, I, BN_FLG_CONSTTIME);\n BN_with_flags(di, pinfo->d, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, cc, pinfo->r, ctx)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(m[i], r1, di, pinfo->r, ctx, pinfo->m)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n }\n BN_free(cc);\n BN_free(di);\n }\n if (!BN_sub(r0, r0, m1))\n goto err;\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->iqmp, ctx))\n goto err;\n {\n BIGNUM *pr1 = BN_new();\n if (pr1 == NULL)\n goto err;\n BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);\n if (!BN_mod(r0, pr1, rsa->p, ctx)) {\n BN_free(pr1);\n goto err;\n }\n BN_free(pr1);\n }\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->q, ctx))\n goto err;\n if (!BN_add(r0, r1, m1))\n goto err;\n if (ex_primes > 0) {\n BIGNUM *pr2 = BN_new();\n if (pr2 == NULL)\n goto err;\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n if (!BN_sub(r1, m[i], r0)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r2, r1, pinfo->t, ctx)) {\n BN_free(pr2);\n goto err;\n }\n BN_with_flags(pr2, r2, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, pr2, pinfo->r, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (BN_is_negative(r1))\n if (!BN_add(r1, r1, pinfo->r)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r1, r1, pinfo->pp, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_add(r0, r0, r1)) {\n BN_free(pr2);\n goto err;\n }\n }\n BN_free(pr2);\n }\n if (rsa->e && rsa->n) {\n if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n if (!BN_sub(vrfy, vrfy, I))\n goto err;\n if (!BN_mod(vrfy, vrfy, rsa->n, ctx))\n goto err;\n if (BN_is_negative(vrfy))\n if (!BN_add(vrfy, vrfy, rsa->n))\n goto err;\n if (!BN_is_zero(vrfy)) {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', '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 if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int 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}']
1,537
0
https://github.com/libav/libav/blob/a082ac412520cd5d812bd57e5ccdad2af557125b/libavcodec/proresenc.c/#L559
static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic, int trellis_node, int x, int y, int mbs_per_slice) { ProresContext *ctx = avctx->priv_data; int i, q, pq, xp, yp; const uint16_t *src; int slice_width_factor = av_log2(mbs_per_slice); int num_cblocks[MAX_PLANES], pwidth; int plane_factor[MAX_PLANES], is_chroma[MAX_PLANES]; const int min_quant = ctx->profile_info->min_quant; const int max_quant = ctx->profile_info->max_quant; int error, bits, bits_limit; int mbs, prev, cur, new_score; int slice_bits[TRELLIS_WIDTH], slice_score[TRELLIS_WIDTH]; mbs = x + mbs_per_slice; for (i = 0; i < ctx->num_planes; i++) { is_chroma[i] = (i == 1 || i == 2); plane_factor[i] = slice_width_factor + 2; if (is_chroma[i]) plane_factor[i] += ctx->chroma_factor - 3; if (!is_chroma[i] || ctx->chroma_factor == CFACTOR_Y444) { xp = x << 4; yp = y << 4; num_cblocks[i] = 4; pwidth = avctx->width; } else { xp = x << 3; yp = y << 4; num_cblocks[i] = 2; pwidth = avctx->width >> 1; } src = (const uint16_t*)(pic->data[i] + yp * pic->linesize[i]) + xp; get_slice_data(ctx, src, pic->linesize[i], xp, yp, pwidth, avctx->height, ctx->blocks[i], mbs_per_slice, num_cblocks[i]); } for (q = min_quant; q <= max_quant; q++) { ctx->nodes[trellis_node + q].prev_node = -1; ctx->nodes[trellis_node + q].quant = q; } for (q = min_quant; q <= max_quant; q++) { bits = 0; error = 0; for (i = 0; i < ctx->num_planes; i++) { bits += estimate_slice_plane(ctx, &error, i, src, pic->linesize[i], mbs_per_slice, num_cblocks[i], plane_factor[i], ctx->quants[q]); } if (bits > 65000 * 8) { error = SCORE_LIMIT; break; } slice_bits[q] = bits; slice_score[q] = error; } bits_limit = mbs * ctx->bits_per_mb; for (pq = min_quant; pq <= max_quant; pq++) { prev = trellis_node - TRELLIS_WIDTH + pq; for (q = min_quant; q <= max_quant; q++) { cur = trellis_node + q; bits = ctx->nodes[prev].bits + slice_bits[q]; error = slice_score[q]; if (bits > bits_limit) error = SCORE_LIMIT; if (ctx->nodes[prev].score < SCORE_LIMIT && error < SCORE_LIMIT) new_score = ctx->nodes[prev].score + error; else new_score = SCORE_LIMIT; if (ctx->nodes[cur].prev_node == -1 || ctx->nodes[cur].score >= new_score) { ctx->nodes[cur].bits = bits; ctx->nodes[cur].score = new_score; ctx->nodes[cur].prev_node = prev; } } } error = ctx->nodes[trellis_node + min_quant].score; pq = trellis_node + min_quant; for (q = min_quant + 1; q <= max_quant; q++) { if (ctx->nodes[trellis_node + q].score <= error) { error = ctx->nodes[trellis_node + q].score; pq = trellis_node + q; } } return pq; }
['static int find_slice_quant(AVCodecContext *avctx, const AVFrame *pic,\n int trellis_node, int x, int y, int mbs_per_slice)\n{\n ProresContext *ctx = avctx->priv_data;\n int i, q, pq, xp, yp;\n const uint16_t *src;\n int slice_width_factor = av_log2(mbs_per_slice);\n int num_cblocks[MAX_PLANES], pwidth;\n int plane_factor[MAX_PLANES], is_chroma[MAX_PLANES];\n const int min_quant = ctx->profile_info->min_quant;\n const int max_quant = ctx->profile_info->max_quant;\n int error, bits, bits_limit;\n int mbs, prev, cur, new_score;\n int slice_bits[TRELLIS_WIDTH], slice_score[TRELLIS_WIDTH];\n mbs = x + mbs_per_slice;\n for (i = 0; i < ctx->num_planes; i++) {\n is_chroma[i] = (i == 1 || i == 2);\n plane_factor[i] = slice_width_factor + 2;\n if (is_chroma[i])\n plane_factor[i] += ctx->chroma_factor - 3;\n if (!is_chroma[i] || ctx->chroma_factor == CFACTOR_Y444) {\n xp = x << 4;\n yp = y << 4;\n num_cblocks[i] = 4;\n pwidth = avctx->width;\n } else {\n xp = x << 3;\n yp = y << 4;\n num_cblocks[i] = 2;\n pwidth = avctx->width >> 1;\n }\n src = (const uint16_t*)(pic->data[i] + yp * pic->linesize[i]) + xp;\n get_slice_data(ctx, src, pic->linesize[i], xp, yp,\n pwidth, avctx->height, ctx->blocks[i],\n mbs_per_slice, num_cblocks[i]);\n }\n for (q = min_quant; q <= max_quant; q++) {\n ctx->nodes[trellis_node + q].prev_node = -1;\n ctx->nodes[trellis_node + q].quant = q;\n }\n for (q = min_quant; q <= max_quant; q++) {\n bits = 0;\n error = 0;\n for (i = 0; i < ctx->num_planes; i++) {\n bits += estimate_slice_plane(ctx, &error, i,\n src, pic->linesize[i],\n mbs_per_slice,\n num_cblocks[i], plane_factor[i],\n ctx->quants[q]);\n }\n if (bits > 65000 * 8) {\n error = SCORE_LIMIT;\n break;\n }\n slice_bits[q] = bits;\n slice_score[q] = error;\n }\n bits_limit = mbs * ctx->bits_per_mb;\n for (pq = min_quant; pq <= max_quant; pq++) {\n prev = trellis_node - TRELLIS_WIDTH + pq;\n for (q = min_quant; q <= max_quant; q++) {\n cur = trellis_node + q;\n bits = ctx->nodes[prev].bits + slice_bits[q];\n error = slice_score[q];\n if (bits > bits_limit)\n error = SCORE_LIMIT;\n if (ctx->nodes[prev].score < SCORE_LIMIT && error < SCORE_LIMIT)\n new_score = ctx->nodes[prev].score + error;\n else\n new_score = SCORE_LIMIT;\n if (ctx->nodes[cur].prev_node == -1 ||\n ctx->nodes[cur].score >= new_score) {\n ctx->nodes[cur].bits = bits;\n ctx->nodes[cur].score = new_score;\n ctx->nodes[cur].prev_node = prev;\n }\n }\n }\n error = ctx->nodes[trellis_node + min_quant].score;\n pq = trellis_node + min_quant;\n for (q = min_quant + 1; q <= max_quant; q++) {\n if (ctx->nodes[trellis_node + q].score <= error) {\n error = ctx->nodes[trellis_node + q].score;\n pq = trellis_node + q;\n }\n }\n return pq;\n}']
1,538
0
https://github.com/libav/libav/blob/99ccd2ba10eac2b282c272ad9e75f082123c765a/libavformat/srtp.c/#L129
int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr) { uint8_t iv[16] = { 0 }, hmac[20]; int len = *lenptr; int av_uninit(seq_largest); uint32_t ssrc, av_uninit(roc); uint64_t index; int rtcp, hmac_size; if (len < 2) return AVERROR_INVALIDDATA; rtcp = RTP_PT_IS_RTCP(buf[1]); hmac_size = rtcp ? s->rtcp_hmac_size : s->rtp_hmac_size; if (len < hmac_size) return AVERROR_INVALIDDATA; av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth)); av_hmac_update(s->hmac, buf, len - hmac_size); if (!rtcp) { int seq = AV_RB16(buf + 2); uint32_t v; uint8_t rocbuf[4]; seq_largest = s->seq_initialized ? s->seq_largest : seq; v = roc = s->roc; if (seq_largest < 32768) { if (seq - seq_largest > 32768) v = roc - 1; } else { if (seq_largest - 32768 > seq) v = roc + 1; } if (v == roc) { seq_largest = FFMAX(seq_largest, seq); } else if (v == roc + 1) { seq_largest = seq; roc = v; } index = seq + (((uint64_t)v) << 16); AV_WB32(rocbuf, roc); av_hmac_update(s->hmac, rocbuf, 4); } av_hmac_final(s->hmac, hmac, sizeof(hmac)); if (memcmp(hmac, buf + len - hmac_size, hmac_size)) { av_log(NULL, AV_LOG_WARNING, "HMAC mismatch\n"); return AVERROR_INVALIDDATA; } len -= hmac_size; *lenptr = len; if (len < 12) return AVERROR_INVALIDDATA; if (rtcp) { uint32_t srtcp_index = AV_RB32(buf + len - 4); len -= 4; *lenptr = len; ssrc = AV_RB32(buf + 4); index = srtcp_index & 0x7fffffff; buf += 8; len -= 8; if (!(srtcp_index & 0x80000000)) return 0; } else { int ext, csrc; s->seq_initialized = 1; s->seq_largest = seq_largest; s->roc = roc; csrc = buf[0] & 0x0f; ext = buf[0] & 0x10; ssrc = AV_RB32(buf + 8); buf += 12; len -= 12; buf += 4 * csrc; len -= 4 * csrc; if (len < 0) return AVERROR_INVALIDDATA; if (ext) { if (len < 4) return AVERROR_INVALIDDATA; ext = (AV_RB16(buf + 2) + 1) * 4; if (len < ext) return AVERROR_INVALIDDATA; len -= ext; buf += ext; } } create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc); av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0); encrypt_counter(s->aes, iv, buf, len); return 0; }
['int ff_srtp_decrypt(struct SRTPContext *s, uint8_t *buf, int *lenptr)\n{\n uint8_t iv[16] = { 0 }, hmac[20];\n int len = *lenptr;\n int av_uninit(seq_largest);\n uint32_t ssrc, av_uninit(roc);\n uint64_t index;\n int rtcp, hmac_size;\n if (len < 2)\n return AVERROR_INVALIDDATA;\n rtcp = RTP_PT_IS_RTCP(buf[1]);\n hmac_size = rtcp ? s->rtcp_hmac_size : s->rtp_hmac_size;\n if (len < hmac_size)\n return AVERROR_INVALIDDATA;\n av_hmac_init(s->hmac, rtcp ? s->rtcp_auth : s->rtp_auth, sizeof(s->rtp_auth));\n av_hmac_update(s->hmac, buf, len - hmac_size);\n if (!rtcp) {\n int seq = AV_RB16(buf + 2);\n uint32_t v;\n uint8_t rocbuf[4];\n seq_largest = s->seq_initialized ? s->seq_largest : seq;\n v = roc = s->roc;\n if (seq_largest < 32768) {\n if (seq - seq_largest > 32768)\n v = roc - 1;\n } else {\n if (seq_largest - 32768 > seq)\n v = roc + 1;\n }\n if (v == roc) {\n seq_largest = FFMAX(seq_largest, seq);\n } else if (v == roc + 1) {\n seq_largest = seq;\n roc = v;\n }\n index = seq + (((uint64_t)v) << 16);\n AV_WB32(rocbuf, roc);\n av_hmac_update(s->hmac, rocbuf, 4);\n }\n av_hmac_final(s->hmac, hmac, sizeof(hmac));\n if (memcmp(hmac, buf + len - hmac_size, hmac_size)) {\n av_log(NULL, AV_LOG_WARNING, "HMAC mismatch\\n");\n return AVERROR_INVALIDDATA;\n }\n len -= hmac_size;\n *lenptr = len;\n if (len < 12)\n return AVERROR_INVALIDDATA;\n if (rtcp) {\n uint32_t srtcp_index = AV_RB32(buf + len - 4);\n len -= 4;\n *lenptr = len;\n ssrc = AV_RB32(buf + 4);\n index = srtcp_index & 0x7fffffff;\n buf += 8;\n len -= 8;\n if (!(srtcp_index & 0x80000000))\n return 0;\n } else {\n int ext, csrc;\n s->seq_initialized = 1;\n s->seq_largest = seq_largest;\n s->roc = roc;\n csrc = buf[0] & 0x0f;\n ext = buf[0] & 0x10;\n ssrc = AV_RB32(buf + 8);\n buf += 12;\n len -= 12;\n buf += 4 * csrc;\n len -= 4 * csrc;\n if (len < 0)\n return AVERROR_INVALIDDATA;\n if (ext) {\n if (len < 4)\n return AVERROR_INVALIDDATA;\n ext = (AV_RB16(buf + 2) + 1) * 4;\n if (len < ext)\n return AVERROR_INVALIDDATA;\n len -= ext;\n buf += ext;\n }\n }\n create_iv(iv, rtcp ? s->rtcp_salt : s->rtp_salt, index, ssrc);\n av_aes_init(s->aes, rtcp ? s->rtcp_key : s->rtp_key, 128, 0);\n encrypt_counter(s->aes, iv, buf, len);\n return 0;\n}']
1,539
0
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/lhash/lhash.c/#L122
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return NULL; } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return ret; }
['static int client_setup_sni_before_state(void)\n{\n SSL_CTX *ctx;\n SSL *con = NULL;\n BIO *rbio;\n BIO *wbio;\n char *hostname = NULL;\n int ret = 0;\n ctx = SSL_CTX_new(TLS_method());\n if (!TEST_ptr(ctx))\n goto end;\n con = SSL_new(ctx);\n if (!TEST_ptr(con))\n goto end;\n SSL_set_tlsext_host_name(con, host);\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 if (!TEST_int_le(SSL_connect(con), 0))\n goto end;\n if (!TEST_true(get_sni_from_client_hello(wbio, &hostname)))\n goto end;\n if (!TEST_str_eq(hostname, host))\n goto end;\n ret = 1;\nend:\n OPENSSL_free(hostname);\n SSL_free(con);\n SSL_CTX_free(ctx);\n return ret;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL)\n goto err;\n if (RAND_get_rand_method() == RAND_OpenSSL()) {\n s->drbg = RAND_DRBG_new(NID_aes_128_ctr, RAND_DRBG_FLAG_CTR_USE_DF,\n RAND_DRBG_get0_global());\n if (s->drbg == NULL\n || RAND_DRBG_instantiate(s->drbg, NULL, 0) == 0) {\n CRYPTO_THREAD_lock_free(s->lock);\n goto err;\n }\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->references = 1;\n s->max_early_data = ctx->max_early_data;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof s->sid_ctx))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n BIO_free_all(s->rbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n RAND_DRBG_free(s->drbg);\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return 1;\n } else\n return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return NULL;\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return ret;\n}']
1,540
0
https://github.com/libav/libav/blob/cf53c48615658a6019ffb7e8453913bbfd38cb27/libavcodec/h264.h/#L969
static void fill_decode_caches(H264Context *h, int mb_type){ MpegEncContext * const s = &h->s; int topleft_xy, top_xy, topright_xy, left_xy[2]; int topleft_type, top_type, topright_type, left_type[2]; const uint8_t * left_block= h->left_block; int i; topleft_xy = h->topleft_mb_xy ; top_xy = h->top_mb_xy ; topright_xy = h->topright_mb_xy; left_xy[0] = h->left_mb_xy[0] ; left_xy[1] = h->left_mb_xy[1] ; topleft_type = h->topleft_type ; top_type = h->top_type ; topright_type= h->topright_type ; left_type[0] = h->left_type[0] ; left_type[1] = h->left_type[1] ; if(!IS_SKIP(mb_type)){ if(IS_INTRA(mb_type)){ int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available= h->top_samples_available= h->left_samples_available= 0xFFFF; h->topright_samples_available= 0xEEEA; if(!(top_type & type_mask)){ h->topleft_samples_available= 0xB3FF; h->top_samples_available= 0x33FF; h->topright_samples_available= 0x26EA; } if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){ if(IS_INTERLACED(mb_type)){ if(!(left_type[0] & type_mask)){ h->topleft_samples_available&= 0xDFFF; h->left_samples_available&= 0x5FFF; } if(!(left_type[1] & type_mask)){ h->topleft_samples_available&= 0xFF5F; h->left_samples_available&= 0xFF5F; } }else{ int left_typei = s->current_picture.mb_type[left_xy[0] + s->mb_stride]; assert(left_xy[0] == left_xy[1]); if(!((left_typei & type_mask) && (left_type[0] & type_mask))){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } }else{ if(!(left_type[0] & type_mask)){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } if(!(topleft_type & type_mask)) h->topleft_samples_available&= 0x7FFF; if(!(topright_type & type_mask)) h->topright_samples_available&= 0xFBFF; if(IS_INTRA4x4(mb_type)){ if(IS_INTRA4x4(top_type)){ AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); }else{ h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask); } for(i=0; i<2; i++){ if(IS_INTRA4x4(left_type[i])){ int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[i]]; h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]]; h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]]; }else{ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[i] & type_mask); } } } } if(top_type){ AV_COPY32(&h->non_zero_count_cache[4+8* 0], &h->non_zero_count[top_xy][4*3]); if(CHROMA444){ AV_COPY32(&h->non_zero_count_cache[4+8* 5], &h->non_zero_count[top_xy][4* 7]); AV_COPY32(&h->non_zero_count_cache[4+8*10], &h->non_zero_count[top_xy][4*11]); }else{ AV_COPY32(&h->non_zero_count_cache[4+8* 5], &h->non_zero_count[top_xy][4* 5]); AV_COPY32(&h->non_zero_count_cache[4+8*10], &h->non_zero_count[top_xy][4* 9]); } }else{ uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040; AV_WN32A(&h->non_zero_count_cache[4+8* 0], top_empty); AV_WN32A(&h->non_zero_count_cache[4+8* 5], top_empty); AV_WN32A(&h->non_zero_count_cache[4+8*10], top_empty); } for (i=0; i<2; i++) { if(left_type[i]){ h->non_zero_count_cache[3+8* 1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]]; h->non_zero_count_cache[3+8* 2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]]; if(CHROMA444){ h->non_zero_count_cache[3+8* 6 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]+4*4]; h->non_zero_count_cache[3+8* 7 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]+4*4]; h->non_zero_count_cache[3+8*11 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]+8*4]; h->non_zero_count_cache[3+8*12 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]+8*4]; }else{ h->non_zero_count_cache[3+8* 6 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]]; h->non_zero_count_cache[3+8*11 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]]; } }else{ h->non_zero_count_cache[3+8* 1 + 2*8*i]= h->non_zero_count_cache[3+8* 2 + 2*8*i]= h->non_zero_count_cache[3+8* 6 + 2*8*i]= h->non_zero_count_cache[3+8* 7 + 2*8*i]= h->non_zero_count_cache[3+8*11 + 2*8*i]= h->non_zero_count_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64; } } if( CABAC ) { if(top_type) { h->top_cbp = h->cbp_table[top_xy]; } else { h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } if (left_type[0]) { h->left_cbp = (h->cbp_table[left_xy[0]] & 0x7F0) | ((h->cbp_table[left_xy[0]]>>(left_block[0]&(~1)))&2) | (((h->cbp_table[left_xy[1]]>>(left_block[2]&(~1)))&2) << 2); } else { h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } } } if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ int list; for(list=0; list<h->list_count; list++){ if(!USES_LIST(mb_type, list)){ continue; } assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); h->mv_cache_clean[list]= 0; if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); h->ref_cache[list][scan8[0] + 0 - 1*8]= h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 2]; h->ref_cache[list][scan8[0] + 2 - 1*8]= h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 3]; }else{ AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101); } if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){ for(i=0; i<2; i++){ int cache_idx = scan8[0] - 1 + i*2*8; if(USES_LIST(left_type[i], list)){ const int b_xy= h->mb2b_xy[left_xy[i]] + 3; const int b8_xy= 4*left_xy[i] + 1; AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]); AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]); h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + (left_block[0+i*2]&~1)]; h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + (left_block[1+i*2]&~1)]; }else{ AV_ZERO32(h->mv_cache [list][cache_idx ]); AV_ZERO32(h->mv_cache [list][cache_idx+8]); h->ref_cache[list][cache_idx ]= h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } }else{ if(USES_LIST(left_type[0], list)){ const int b_xy= h->mb2b_xy[left_xy[0]] + 3; const int b8_xy= 4*left_xy[0] + 1; AV_COPY32(h->mv_cache[list][scan8[0] - 1], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]]); h->ref_cache[list][scan8[0] - 1]= s->current_picture.ref_index[list][b8_xy + (left_block[0]&~1)]; }else{ AV_ZERO32(h->mv_cache [list][scan8[0] - 1]); h->ref_cache[list][scan8[0] - 1]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if(USES_LIST(topright_type, list)){ const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]); h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][4*topright_xy + 2]; }else{ AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]); h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if(h->ref_cache[list][scan8[0] + 4 - 1*8] < 0){ if(USES_LIST(topleft_type, list)){ const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride); const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2); AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]); h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]); h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF) continue; if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) { h->ref_cache[list][scan8[4 ]] = h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; AV_ZERO32(h->mv_cache [list][scan8[4 ]]); AV_ZERO32(h->mv_cache [list][scan8[12]]); if( CABAC ) { if(USES_LIST(top_type, list)){ const int b_xy= h->mb2br_xy[top_xy]; AV_COPY64(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]); }else{ AV_ZERO64(h->mvd_cache[list][scan8[0] + 0 - 1*8]); } if(USES_LIST(left_type[0], list)){ const int b_xy= h->mb2br_xy[left_xy[0]] + 6; AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy - left_block[0]]); AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy - left_block[1]]); }else{ AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 0*8]); AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 1*8]); } if(USES_LIST(left_type[1], list)){ const int b_xy= h->mb2br_xy[left_xy[1]] + 6; AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy - left_block[2]]); AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy - left_block[3]]); }else{ AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 2*8]); AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 3*8]); } AV_ZERO16(h->mvd_cache [list][scan8[4 ]]); AV_ZERO16(h->mvd_cache [list][scan8[12]]); if(h->slice_type_nos == AV_PICTURE_TYPE_B){ fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1); if(IS_DIRECT(top_type)){ AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1)); }else if(IS_8X8(top_type)){ int b8_xy = 4*top_xy; h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy + 2]; h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 3]; }else{ AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1)); } if(IS_DIRECT(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[4*left_xy[0] + 1 + (left_block[0]&~1)]; else h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1; if(IS_DIRECT(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[4*left_xy[1] + 1 + (left_block[2]&~1)]; else h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1; } } } if(FRAME_MBAFF){ #define MAP_MVS\ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) if(MB_FIELD){ #define MAP_F2F(idx, mb_type)\ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] <<= 1;\ h->mv_cache[list][idx][1] /= 2;\ h->mvd_cache[list][idx][1] >>=1;\ } MAP_MVS #undef MAP_F2F }else{ #define MAP_F2F(idx, mb_type)\ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] >>= 1;\ h->mv_cache[list][idx][1] <<= 1;\ h->mvd_cache[list][idx][1] <<= 1;\ } MAP_MVS #undef MAP_F2F } } } } h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); }
['static void av_unused decode_mb_skip(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int mb_type=0;\n memset(h->non_zero_count[mb_xy], 0, 48);\n if(MB_FIELD)\n mb_type|= MB_TYPE_INTERLACED;\n if( h->slice_type_nos == AV_PICTURE_TYPE_B )\n {\n mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;\n if(h->direct_spatial_mv_pred){\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n }\n ff_h264_pred_direct_motion(h, &mb_type);\n mb_type|= MB_TYPE_SKIP;\n }\n else\n {\n int mx, my;\n mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n pred_pskip_motion(h, &mx, &my);\n fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);\n fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);\n }\n write_back_motion(h, mb_type);\n s->current_picture.mb_type[mb_xy]= mb_type;\n s->current_picture.qscale_table[mb_xy]= s->qscale;\n h->slice_table[ mb_xy ]= h->slice_num;\n h->prev_mb_skipped= 1;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n static const uint8_t left_block_options[4][32]={\n {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},\n {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},\n {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},\n {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[1] = left_xy[0] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1);\n topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1);\n top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[0] = left_xy[0];\n h->left_mb_xy[1] = left_xy[1];\n h->topleft_type = s->current_picture.mb_type[topleft_xy] ;\n h->top_type = s->current_picture.mb_type[top_xy] ;\n h->topright_type= s->current_picture.mb_type[topright_xy];\n h->left_type[0] = s->current_picture.mb_type[left_xy[0]] ;\n h->left_type[1] = s->current_picture.mb_type[left_xy[1]] ;\n if(FMO){\n if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 0;\n }else{\n if(h->slice_table[topleft_xy ] != h->slice_num){\n h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 0;\n }\n }\n if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n int topleft_type, top_type, topright_type, left_type[2];\n const uint8_t * left_block= h->left_block;\n int i;\n topleft_xy = h->topleft_mb_xy ;\n top_xy = h->top_mb_xy ;\n topright_xy = h->topright_mb_xy;\n left_xy[0] = h->left_mb_xy[0] ;\n left_xy[1] = h->left_mb_xy[1] ;\n topleft_type = h->topleft_type ;\n top_type = h->top_type ;\n topright_type= h->topright_type ;\n left_type[0] = h->left_type[0] ;\n left_type[1] = h->left_type[1] ;\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[1] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = s->current_picture.mb_type[left_xy[0] + s->mb_stride];\n assert(left_xy[0] == left_xy[1]);\n if(!((left_typei & type_mask) && (left_type[0] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n }else{\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[i])){\n int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[i]];\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];\n }else{\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[i] & type_mask);\n }\n }\n }\n }\n if(top_type){\n AV_COPY32(&h->non_zero_count_cache[4+8* 0], &h->non_zero_count[top_xy][4*3]);\n if(CHROMA444){\n AV_COPY32(&h->non_zero_count_cache[4+8* 5], &h->non_zero_count[top_xy][4* 7]);\n AV_COPY32(&h->non_zero_count_cache[4+8*10], &h->non_zero_count[top_xy][4*11]);\n }else{\n AV_COPY32(&h->non_zero_count_cache[4+8* 5], &h->non_zero_count[top_xy][4* 5]);\n AV_COPY32(&h->non_zero_count_cache[4+8*10], &h->non_zero_count[top_xy][4* 9]);\n }\n }else{\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&h->non_zero_count_cache[4+8* 0], top_empty);\n AV_WN32A(&h->non_zero_count_cache[4+8* 5], top_empty);\n AV_WN32A(&h->non_zero_count_cache[4+8*10], top_empty);\n }\n for (i=0; i<2; i++) {\n if(left_type[i]){\n h->non_zero_count_cache[3+8* 1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]];\n h->non_zero_count_cache[3+8* 2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]];\n if(CHROMA444){\n h->non_zero_count_cache[3+8* 6 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]+4*4];\n h->non_zero_count_cache[3+8* 7 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]+4*4];\n h->non_zero_count_cache[3+8*11 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]+8*4];\n h->non_zero_count_cache[3+8*12 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]+8*4];\n }else{\n h->non_zero_count_cache[3+8* 6 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]];\n h->non_zero_count_cache[3+8*11 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]];\n }\n }else{\n h->non_zero_count_cache[3+8* 1 + 2*8*i]=\n h->non_zero_count_cache[3+8* 2 + 2*8*i]=\n h->non_zero_count_cache[3+8* 6 + 2*8*i]=\n h->non_zero_count_cache[3+8* 7 + 2*8*i]=\n h->non_zero_count_cache[3+8*11 + 2*8*i]=\n h->non_zero_count_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else {\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp = (h->cbp_table[left_xy[0]] & 0x7F0)\n | ((h->cbp_table[left_xy[0]]>>(left_block[0]&(~1)))&2)\n | (((h->cbp_table[left_xy[1]]>>(left_block[2]&(~1)))&2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n for(list=0; list<h->list_count; list++){\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n h->mv_cache_clean[list]= 0;\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);\n h->ref_cache[list][scan8[0] + 0 - 1*8]=\n h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 2];\n h->ref_cache[list][scan8[0] + 2 - 1*8]=\n h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 3];\n }else{\n AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);\n AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){\n for(i=0; i<2; i++){\n int cache_idx = scan8[0] - 1 + i*2*8;\n if(USES_LIST(left_type[i], list)){\n const int b_xy= h->mb2b_xy[left_xy[i]] + 3;\n const int b8_xy= 4*left_xy[i] + 1;\n AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]);\n AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]);\n h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + (left_block[0+i*2]&~1)];\n h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + (left_block[1+i*2]&~1)];\n }else{\n AV_ZERO32(h->mv_cache [list][cache_idx ]);\n AV_ZERO32(h->mv_cache [list][cache_idx+8]);\n h->ref_cache[list][cache_idx ]=\n h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n }else{\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2b_xy[left_xy[0]] + 3;\n const int b8_xy= 4*left_xy[0] + 1;\n AV_COPY32(h->mv_cache[list][scan8[0] - 1], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]]);\n h->ref_cache[list][scan8[0] - 1]= s->current_picture.ref_index[list][b8_xy + (left_block[0]&~1)];\n }else{\n AV_ZERO32(h->mv_cache [list][scan8[0] - 1]);\n h->ref_cache[list][scan8[0] - 1]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;\n AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][4*topright_xy + 2];\n }else{\n AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(h->ref_cache[list][scan8[0] + 4 - 1*8] < 0){\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride);\n const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) {\n h->ref_cache[list][scan8[4 ]] =\n h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;\n AV_ZERO32(h->mv_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mv_cache [list][scan8[12]]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2br_xy[top_xy];\n AV_COPY64(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]);\n }else{\n AV_ZERO64(h->mvd_cache[list][scan8[0] + 0 - 1*8]);\n }\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2br_xy[left_xy[0]] + 6;\n AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy - left_block[0]]);\n AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy - left_block[1]]);\n }else{\n AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 0*8]);\n AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 1*8]);\n }\n if(USES_LIST(left_type[1], list)){\n const int b_xy= h->mb2br_xy[left_xy[1]] + 6;\n AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy - left_block[2]]);\n AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy - left_block[3]]);\n }else{\n AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 2*8]);\n AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 3*8]);\n }\n AV_ZERO16(h->mvd_cache [list][scan8[4 ]]);\n AV_ZERO16(h->mvd_cache [list][scan8[12]]);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = 4*top_xy;\n h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy + 2];\n h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 3];\n }else{\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[4*left_xy[0] + 1 + (left_block[0]&~1)];\n else\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[4*left_xy[1] + 1 + (left_block[2]&~1)];\n else\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[1])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] >>=1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]);\n}']
1,541
0
https://github.com/openssl/openssl/blob/3dd303129ff478349aaf9ddd12ee711c235f8a36/apps/ca.c/#L2916
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, ASN1_GENERALIZEDTIME **pinvtm, const char *str)\n\t{\n\tchar *tmp = NULL;\n\tchar *rtime_str, *reason_str = NULL, *arg_str = NULL, *p;\n\tint reason_code = -1;\n\tint ret = 0;\n\tunsigned int i;\n\tASN1_OBJECT *hold = NULL;\n\tASN1_GENERALIZEDTIME *comp_time = NULL;\n\ttmp = BUF_strdup(str);\n\tp = strchr(tmp, \',\');\n\trtime_str = tmp;\n\tif (p)\n\t\t{\n\t\t*p = \'\\0\';\n\t\tp++;\n\t\treason_str = p;\n\t\tp = strchr(p, \',\');\n\t\tif (p)\n\t\t\t{\n\t\t\t*p = \'\\0\';\n\t\t\targ_str = p + 1;\n\t\t\t}\n\t\t}\n\tif (prevtm)\n\t\t{\n\t\t*prevtm = ASN1_UTCTIME_new();\n\t\tif (!ASN1_UTCTIME_set_string(*prevtm, rtime_str))\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "invalid revocation date %s\\n", rtime_str);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (reason_str)\n\t\t{\n\t\tfor (i = 0; i < NUM_REASONS; i++)\n\t\t\t{\n\t\t\tif(!strcasecmp(reason_str, crl_reasons[i]))\n\t\t\t\t{\n\t\t\t\treason_code = i;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (reason_code == OCSP_REVOKED_STATUS_NOSTATUS)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "invalid reason code %s\\n", reason_str);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (reason_code == 7)\n\t\t\treason_code = OCSP_REVOKED_STATUS_REMOVEFROMCRL;\n\t\telse if (reason_code == 8)\n\t\t\t{\n\t\t\tif (!arg_str)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err, "missing hold instruction\\n");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\treason_code = OCSP_REVOKED_STATUS_CERTIFICATEHOLD;\n\t\t\thold = OBJ_txt2obj(arg_str, 0);\n\t\t\tif (!hold)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err, "invalid object identifier %s\\n", arg_str);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (phold) *phold = hold;\n\t\t\t}\n\t\telse if ((reason_code == 9) || (reason_code == 10))\n\t\t\t{\n\t\t\tif (!arg_str)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err, "missing compromised time\\n");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tcomp_time = ASN1_GENERALIZEDTIME_new();\n\t\t\tif (!ASN1_GENERALIZEDTIME_set_string(comp_time, arg_str))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err, "invalid compromised time %s\\n", arg_str);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (reason_code == 9)\n\t\t\t\treason_code = OCSP_REVOKED_STATUS_KEYCOMPROMISE;\n\t\t\telse\n\t\t\t\treason_code = OCSP_REVOKED_STATUS_CACOMPROMISE;\n\t\t\t}\n\t\t}\n\tif (preason) *preason = reason_code;\n\tif (pinvtm) *pinvtm = comp_time;\n\telse ASN1_GENERALIZEDTIME_free(comp_time);\n\tret = 1;\n\terr:\n\tif (tmp) OPENSSL_free(tmp);\n\tif (!phold) ASN1_OBJECT_free(hold);\n\tif (!pinvtm) ASN1_GENERALIZEDTIME_free(comp_time);\n\treturn ret;\n\t}', 'char *BUF_strdup(const char *str)\n\t{\n\tif (str == NULL) return(NULL);\n\treturn BUF_strndup(str, strlen(str));\n\t}']
1,542
0
https://github.com/libav/libav/blob/df84d7d9bdf6b8e6896c711880f130b72738c828/libavcodec/mpegaudiodec.c/#L897
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr, int32_t sb_samples[SBLIMIT]) { register MPA_INT *synth_buf; register const MPA_INT *w, *w2, *p; int j, offset; OUT_INT *samples2; #if FRAC_BITS <= 15 int32_t tmp[32]; int sum, sum2; #else int64_t sum, sum2; #endif offset = *synth_buf_offset; synth_buf = synth_buf_ptr + offset; #if FRAC_BITS <= 15 dct32(tmp, sb_samples); for(j=0;j<32;j++) { synth_buf[j] = av_clip_int16(tmp[j]); } #else dct32(synth_buf, sb_samples); #endif memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT)); samples2 = samples + 31 * incr; w = window; w2 = window + 31; sum = *dither_state; p = synth_buf + 16; SUM8(MACS, sum, w, p); p = synth_buf + 48; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); samples += incr; w++; for(j=1;j<16;j++) { sum2 = 0; p = synth_buf + 16 + j; SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); p = synth_buf + 48 - j; SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); *samples = round_sample(&sum); samples += incr; sum += sum2; *samples2 = round_sample(&sum); samples2 -= incr; w++; w2--; } p = synth_buf + 32; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); *dither_state= sum; offset = (offset - 32) & 511; *synth_buf_offset = offset; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n int32_t sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}']
1,543
0
https://github.com/libav/libav/blob/7ff018c1cb43a5fe5ee2049d325cdd785852067a/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 void read_const_block_data(ALSDecContext *ctx, ALSBlockData *bd)\n{\n ALSSpecificConfig *sconf = &ctx->sconf;\n AVCodecContext *avctx = ctx->avctx;\n BitstreamContext *bc = &ctx->bc;\n *bd->raw_samples = 0;\n *bd->const_block = bitstream_read_bit(bc);\n bd->js_blocks = bitstream_read_bit(bc);\n bitstream_skip(bc, 5);\n if (*bd->const_block) {\n unsigned int const_val_bits = sconf->floating ? 24 : avctx->bits_per_raw_sample;\n *bd->raw_samples = bitstream_read_signed(bc, const_val_bits);\n }\n *bd->const_block = 1;\n}', 'static inline int32_t bitstream_read_signed(BitstreamContext *bc, unsigned n)\n{\n return sign_extend(bitstream_read(bc, n), n);\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}']
1,544
0
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/record/ssl3_record.c/#L180
int ssl3_get_record(SSL *s) { int ssl_major, ssl_minor, al; int enc_err, n, i, ret = -1; SSL3_RECORD *rr; SSL3_BUFFER *rbuf; SSL_SESSION *sess; unsigned char *p; unsigned char md[EVP_MAX_MD_SIZE]; short version; unsigned mac_size; unsigned int num_recs = 0; unsigned int max_recs; unsigned int j; rr = RECORD_LAYER_get_rrec(&s->rlayer); rbuf = RECORD_LAYER_get_rbuf(&s->rlayer); max_recs = s->max_pipelines; if (max_recs == 0) max_recs = 1; sess = s->session; do { if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) || (RECORD_LAYER_get_packet_length(&s->rlayer) < SSL3_RT_HEADER_LENGTH)) { n = ssl3_read_n(s, SSL3_RT_HEADER_LENGTH, SSL3_BUFFER_get_len(rbuf), 0, num_recs == 0 ? 1 : 0); if (n <= 0) return (n); RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY); p = RECORD_LAYER_get_packet(&s->rlayer); if (s->server && RECORD_LAYER_is_first_record(&s->rlayer) && (p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) { rr[num_recs].type = SSL3_RT_HANDSHAKE; rr[num_recs].rec_version = SSL2_VERSION; rr[num_recs].length = ((p[0] & 0x7f) << 8) | p[1]; if (rr[num_recs].length > SSL3_BUFFER_get_len(rbuf) - SSL2_RT_HEADER_LENGTH) { al = SSL_AD_RECORD_OVERFLOW; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_PACKET_LENGTH_TOO_LONG); goto f_err; } if (rr[num_recs].length < MIN_SSL2_RECORD_LEN) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_LENGTH_TOO_SHORT); goto f_err; } } else { if (s->msg_callback) s->msg_callback(0, 0, SSL3_RT_HEADER, p, 5, s, s->msg_callback_arg); rr[num_recs].type = *(p++); ssl_major = *(p++); ssl_minor = *(p++); version = (ssl_major << 8) | ssl_minor; rr[num_recs].rec_version = version; n2s(p, rr[num_recs].length); if (!s->first_packet && version != s->version) { SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_WRONG_VERSION_NUMBER); if ((s->version & 0xFF00) == (version & 0xFF00) && !s->enc_write_ctx && !s->write_hash) { if (rr->type == SSL3_RT_ALERT) { goto err; } s->version = (unsigned short)version; } al = SSL_AD_PROTOCOL_VERSION; goto f_err; } if ((version >> 8) != SSL3_VERSION_MAJOR) { if (RECORD_LAYER_is_first_record(&s->rlayer)) { p = RECORD_LAYER_get_packet(&s->rlayer); if (strncmp((char *)p, "GET ", 4) == 0 || strncmp((char *)p, "POST ", 5) == 0 || strncmp((char *)p, "HEAD ", 5) == 0 || strncmp((char *)p, "PUT ", 4) == 0) { SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_HTTP_REQUEST); goto err; } else if (strncmp((char *)p, "CONNE", 5) == 0) { SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_HTTPS_PROXY_REQUEST); goto err; } SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_WRONG_VERSION_NUMBER); goto err; } else { SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_WRONG_VERSION_NUMBER); al = SSL_AD_PROTOCOL_VERSION; goto f_err; } } if (rr[num_recs].length > SSL3_BUFFER_get_len(rbuf) - SSL3_RT_HEADER_LENGTH) { al = SSL_AD_RECORD_OVERFLOW; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_PACKET_LENGTH_TOO_LONG); goto f_err; } } } if (rr[num_recs].rec_version == SSL2_VERSION) { i = rr[num_recs].length + SSL2_RT_HEADER_LENGTH - SSL3_RT_HEADER_LENGTH; } else { i = rr[num_recs].length; } if (i > 0) { n = ssl3_read_n(s, i, i, 1, 0); if (n <= 0) return (n); } RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER); if (rr[num_recs].rec_version == SSL2_VERSION) { rr[num_recs].input = &(RECORD_LAYER_get_packet(&s->rlayer)[SSL2_RT_HEADER_LENGTH]); } else { rr[num_recs].input = &(RECORD_LAYER_get_packet(&s->rlayer)[SSL3_RT_HEADER_LENGTH]); } if (rr[num_recs].length > SSL3_RT_MAX_ENCRYPTED_LENGTH) { al = SSL_AD_RECORD_OVERFLOW; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_ENCRYPTED_LENGTH_TOO_LONG); goto f_err; } rr[num_recs].data = rr[num_recs].input; rr[num_recs].orig_len = rr[num_recs].length; rr[num_recs].read = 0; num_recs++; RECORD_LAYER_reset_packet_length(&s->rlayer); RECORD_LAYER_clear_first_record(&s->rlayer); } while (num_recs < max_recs && rr[num_recs - 1].type == SSL3_RT_APPLICATION_DATA && SSL_USE_EXPLICIT_IV(s) && s->enc_read_ctx != NULL && (EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_read_ctx)) & EVP_CIPH_FLAG_PIPELINE) && ssl3_record_app_data_waiting(s)); if (SSL_USE_ETM(s) && s->read_hash) { unsigned char *mac; mac_size = EVP_MD_CTX_size(s->read_hash); OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE); for (j = 0; j < num_recs; j++) { if (rr[j].length < mac_size) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_LENGTH_TOO_SHORT); goto f_err; } rr[j].length -= mac_size; mac = rr[j].data + rr[j].length; i = s->method->ssl3_enc->mac(s, &rr[j], md, 0 ); if (i < 0 || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0) { al = SSL_AD_BAD_RECORD_MAC; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC); goto f_err; } } } enc_err = s->method->ssl3_enc->enc(s, rr, num_recs, 0); if (enc_err == 0) { al = SSL_AD_DECRYPTION_FAILED; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_BLOCK_CIPHER_PAD_IS_WRONG); goto f_err; } #ifdef SSL_DEBUG printf("dec %d\n", rr->length); { unsigned int z; for (z = 0; z < rr->length; z++) printf("%02X%c", rr->data[z], ((z + 1) % 16) ? ' ' : '\n'); } printf("\n"); #endif if ((sess != NULL) && (s->enc_read_ctx != NULL) && (EVP_MD_CTX_md(s->read_hash) != NULL) && !SSL_USE_ETM(s)) { unsigned char *mac = NULL; unsigned char mac_tmp[EVP_MAX_MD_SIZE]; mac_size = EVP_MD_CTX_size(s->read_hash); OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE); for (j = 0; j < num_recs; j++) { if (rr[j].orig_len < mac_size || (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE && rr[j].orig_len < mac_size + 1)) { al = SSL_AD_DECODE_ERROR; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_LENGTH_TOO_SHORT); goto f_err; } if (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE) { mac = mac_tmp; ssl3_cbc_copy_mac(mac_tmp, &rr[j], mac_size); rr[j].length -= mac_size; } else { rr[j].length -= mac_size; mac = &rr[j].data[rr[j].length]; } i = s->method->ssl3_enc->mac(s, &rr[j], md, 0 ); if (i < 0 || mac == NULL || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0) enc_err = -1; if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_size) enc_err = -1; } } if (enc_err < 0) { al = SSL_AD_BAD_RECORD_MAC; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC); goto f_err; } for (j = 0; j < num_recs; j++) { if (s->expand != NULL) { if (rr[j].length > SSL3_RT_MAX_COMPRESSED_LENGTH) { al = SSL_AD_RECORD_OVERFLOW; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_COMPRESSED_LENGTH_TOO_LONG); goto f_err; } if (!ssl3_do_uncompress(s, &rr[j])) { al = SSL_AD_DECOMPRESSION_FAILURE; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_BAD_DECOMPRESSION); goto f_err; } } if (rr[j].length > SSL3_RT_MAX_PLAIN_LENGTH) { al = SSL_AD_RECORD_OVERFLOW; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_DATA_LENGTH_TOO_LONG); goto f_err; } rr[j].off = 0; if (rr[j].length == 0) { RECORD_LAYER_inc_empty_record_count(&s->rlayer); if (RECORD_LAYER_get_empty_record_count(&s->rlayer) > MAX_EMPTY_RECORDS) { al = SSL_AD_UNEXPECTED_MESSAGE; SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_RECORD_TOO_SMALL); goto f_err; } } else { RECORD_LAYER_reset_empty_record_count(&s->rlayer); } } RECORD_LAYER_set_numrpipes(&s->rlayer, num_recs); return 1; f_err: ssl3_send_alert(s, SSL3_AL_FATAL, al); err: return ret; }
['int ssl3_get_record(SSL *s)\n{\n int ssl_major, ssl_minor, al;\n int enc_err, n, i, ret = -1;\n SSL3_RECORD *rr;\n SSL3_BUFFER *rbuf;\n SSL_SESSION *sess;\n unsigned char *p;\n unsigned char md[EVP_MAX_MD_SIZE];\n short version;\n unsigned mac_size;\n unsigned int num_recs = 0;\n unsigned int max_recs;\n unsigned int j;\n rr = RECORD_LAYER_get_rrec(&s->rlayer);\n rbuf = RECORD_LAYER_get_rbuf(&s->rlayer);\n max_recs = s->max_pipelines;\n if (max_recs == 0)\n max_recs = 1;\n sess = s->session;\n do {\n if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) ||\n (RECORD_LAYER_get_packet_length(&s->rlayer)\n < SSL3_RT_HEADER_LENGTH)) {\n n = ssl3_read_n(s, SSL3_RT_HEADER_LENGTH,\n SSL3_BUFFER_get_len(rbuf), 0,\n num_recs == 0 ? 1 : 0);\n if (n <= 0)\n return (n);\n RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);\n p = RECORD_LAYER_get_packet(&s->rlayer);\n if (s->server && RECORD_LAYER_is_first_record(&s->rlayer)\n && (p[0] & 0x80) && (p[2] == SSL2_MT_CLIENT_HELLO)) {\n rr[num_recs].type = SSL3_RT_HANDSHAKE;\n rr[num_recs].rec_version = SSL2_VERSION;\n rr[num_recs].length = ((p[0] & 0x7f) << 8) | p[1];\n if (rr[num_recs].length > SSL3_BUFFER_get_len(rbuf)\n - SSL2_RT_HEADER_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_PACKET_LENGTH_TOO_LONG);\n goto f_err;\n }\n if (rr[num_recs].length < MIN_SSL2_RECORD_LEN) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n } else {\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, p, 5, s,\n s->msg_callback_arg);\n rr[num_recs].type = *(p++);\n ssl_major = *(p++);\n ssl_minor = *(p++);\n version = (ssl_major << 8) | ssl_minor;\n rr[num_recs].rec_version = version;\n n2s(p, rr[num_recs].length);\n if (!s->first_packet && version != s->version) {\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_WRONG_VERSION_NUMBER);\n if ((s->version & 0xFF00) == (version & 0xFF00)\n && !s->enc_write_ctx && !s->write_hash) {\n if (rr->type == SSL3_RT_ALERT) {\n goto err;\n }\n s->version = (unsigned short)version;\n }\n al = SSL_AD_PROTOCOL_VERSION;\n goto f_err;\n }\n if ((version >> 8) != SSL3_VERSION_MAJOR) {\n if (RECORD_LAYER_is_first_record(&s->rlayer)) {\n p = RECORD_LAYER_get_packet(&s->rlayer);\n if (strncmp((char *)p, "GET ", 4) == 0 ||\n strncmp((char *)p, "POST ", 5) == 0 ||\n strncmp((char *)p, "HEAD ", 5) == 0 ||\n strncmp((char *)p, "PUT ", 4) == 0) {\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_HTTP_REQUEST);\n goto err;\n } else if (strncmp((char *)p, "CONNE", 5) == 0) {\n SSLerr(SSL_F_SSL3_GET_RECORD,\n SSL_R_HTTPS_PROXY_REQUEST);\n goto err;\n }\n SSLerr(SSL_F_SSL3_GET_RECORD,\n SSL_R_WRONG_VERSION_NUMBER);\n goto err;\n } else {\n SSLerr(SSL_F_SSL3_GET_RECORD,\n SSL_R_WRONG_VERSION_NUMBER);\n al = SSL_AD_PROTOCOL_VERSION;\n goto f_err;\n }\n }\n if (rr[num_recs].length >\n SSL3_BUFFER_get_len(rbuf) - SSL3_RT_HEADER_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_PACKET_LENGTH_TOO_LONG);\n goto f_err;\n }\n }\n }\n if (rr[num_recs].rec_version == SSL2_VERSION) {\n i = rr[num_recs].length + SSL2_RT_HEADER_LENGTH\n - SSL3_RT_HEADER_LENGTH;\n } else {\n i = rr[num_recs].length;\n }\n if (i > 0) {\n n = ssl3_read_n(s, i, i, 1, 0);\n if (n <= 0)\n return (n);\n }\n RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER);\n if (rr[num_recs].rec_version == SSL2_VERSION) {\n rr[num_recs].input =\n &(RECORD_LAYER_get_packet(&s->rlayer)[SSL2_RT_HEADER_LENGTH]);\n } else {\n rr[num_recs].input =\n &(RECORD_LAYER_get_packet(&s->rlayer)[SSL3_RT_HEADER_LENGTH]);\n }\n if (rr[num_recs].length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);\n goto f_err;\n }\n rr[num_recs].data = rr[num_recs].input;\n rr[num_recs].orig_len = rr[num_recs].length;\n rr[num_recs].read = 0;\n num_recs++;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n RECORD_LAYER_clear_first_record(&s->rlayer);\n } while (num_recs < max_recs\n && rr[num_recs - 1].type == SSL3_RT_APPLICATION_DATA\n && SSL_USE_EXPLICIT_IV(s)\n && s->enc_read_ctx != NULL\n && (EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_read_ctx))\n & EVP_CIPH_FLAG_PIPELINE)\n && ssl3_record_app_data_waiting(s));\n if (SSL_USE_ETM(s) && s->read_hash) {\n unsigned char *mac;\n mac_size = EVP_MD_CTX_size(s->read_hash);\n OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n for (j = 0; j < num_recs; j++) {\n if (rr[j].length < mac_size) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n rr[j].length -= mac_size;\n mac = rr[j].data + rr[j].length;\n i = s->method->ssl3_enc->mac(s, &rr[j], md, 0 );\n if (i < 0 || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0) {\n al = SSL_AD_BAD_RECORD_MAC;\n SSLerr(SSL_F_SSL3_GET_RECORD,\n SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);\n goto f_err;\n }\n }\n }\n enc_err = s->method->ssl3_enc->enc(s, rr, num_recs, 0);\n if (enc_err == 0) {\n al = SSL_AD_DECRYPTION_FAILED;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);\n goto f_err;\n }\n#ifdef SSL_DEBUG\n printf("dec %d\\n", rr->length);\n {\n unsigned int z;\n for (z = 0; z < rr->length; z++)\n printf("%02X%c", rr->data[z], ((z + 1) % 16) ? \' \' : \'\\n\');\n }\n printf("\\n");\n#endif\n if ((sess != NULL) &&\n (s->enc_read_ctx != NULL) &&\n (EVP_MD_CTX_md(s->read_hash) != NULL) && !SSL_USE_ETM(s)) {\n unsigned char *mac = NULL;\n unsigned char mac_tmp[EVP_MAX_MD_SIZE];\n mac_size = EVP_MD_CTX_size(s->read_hash);\n OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n for (j = 0; j < num_recs; j++) {\n if (rr[j].orig_len < mac_size ||\n (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n rr[j].orig_len < mac_size + 1)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n if (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE) {\n mac = mac_tmp;\n ssl3_cbc_copy_mac(mac_tmp, &rr[j], mac_size);\n rr[j].length -= mac_size;\n } else {\n rr[j].length -= mac_size;\n mac = &rr[j].data[rr[j].length];\n }\n i = s->method->ssl3_enc->mac(s, &rr[j], md, 0 );\n if (i < 0 || mac == NULL\n || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0)\n enc_err = -1;\n if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_size)\n enc_err = -1;\n }\n }\n if (enc_err < 0) {\n al = SSL_AD_BAD_RECORD_MAC;\n SSLerr(SSL_F_SSL3_GET_RECORD,\n SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);\n goto f_err;\n }\n for (j = 0; j < num_recs; j++) {\n if (s->expand != NULL) {\n if (rr[j].length > SSL3_RT_MAX_COMPRESSED_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_COMPRESSED_LENGTH_TOO_LONG);\n goto f_err;\n }\n if (!ssl3_do_uncompress(s, &rr[j])) {\n al = SSL_AD_DECOMPRESSION_FAILURE;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_BAD_DECOMPRESSION);\n goto f_err;\n }\n }\n if (rr[j].length > SSL3_RT_MAX_PLAIN_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_DATA_LENGTH_TOO_LONG);\n goto f_err;\n }\n rr[j].off = 0;\n if (rr[j].length == 0) {\n RECORD_LAYER_inc_empty_record_count(&s->rlayer);\n if (RECORD_LAYER_get_empty_record_count(&s->rlayer)\n > MAX_EMPTY_RECORDS) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_SSL3_GET_RECORD, SSL_R_RECORD_TOO_SMALL);\n goto f_err;\n }\n } else {\n RECORD_LAYER_reset_empty_record_count(&s->rlayer);\n }\n }\n RECORD_LAYER_set_numrpipes(&s->rlayer, num_recs);\n return 1;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n return ret;\n}', 'int ssl3_read_n(SSL *s, int n, int max, int extend, int clearold)\n{\n int i, len, left;\n size_t align = 0;\n unsigned char *pkt;\n SSL3_BUFFER *rb;\n if (n <= 0)\n return n;\n rb = &s->rlayer.rbuf;\n if (rb->buf == NULL)\n if (!ssl3_setup_read_buffer(s))\n return -1;\n left = rb->left;\n#if defined(SSL3_ALIGN_PAYLOAD) && SSL3_ALIGN_PAYLOAD!=0\n align = (size_t)rb->buf + SSL3_RT_HEADER_LENGTH;\n align = SSL3_ALIGN_PAYLOAD - 1 - ((align - 1) % SSL3_ALIGN_PAYLOAD);\n#endif\n if (!extend) {\n if (left == 0)\n rb->offset = align;\n else if (align != 0 && left >= SSL3_RT_HEADER_LENGTH) {\n pkt = rb->buf + rb->offset;\n if (pkt[0] == SSL3_RT_APPLICATION_DATA\n && (pkt[3] << 8 | pkt[4]) >= 128) {\n memmove(rb->buf + align, pkt, left);\n rb->offset = align;\n }\n }\n s->rlayer.packet = rb->buf + rb->offset;\n s->rlayer.packet_length = 0;\n }\n if (SSL_IS_DTLS(s)) {\n if (left == 0 && extend)\n return 0;\n if (left > 0 && n > left)\n n = left;\n }\n if (left >= n) {\n s->rlayer.packet_length += n;\n rb->left = left - n;\n rb->offset += n;\n return (n);\n }\n len = s->rlayer.packet_length;\n pkt = rb->buf + align;\n if (s->rlayer.packet != pkt && clearold == 1) {\n memmove(pkt, s->rlayer.packet, len + left);\n s->rlayer.packet = pkt;\n rb->offset = len + align;\n }\n if (n > (int)(rb->len - rb->offset)) {\n SSLerr(SSL_F_SSL3_READ_N, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n if (!s->rlayer.read_ahead && !SSL_IS_DTLS(s))\n max = n;\n else {\n if (max < n)\n max = n;\n if (max > (int)(rb->len - rb->offset))\n max = rb->len - rb->offset;\n }\n while (left < n) {\n clear_sys_error();\n if (s->rbio != NULL) {\n s->rwstate = SSL_READING;\n i = BIO_read(s->rbio, pkt + len + left, max - left);\n } else {\n SSLerr(SSL_F_SSL3_READ_N, SSL_R_READ_BIO_NOT_SET);\n i = -1;\n }\n if (i <= 0) {\n rb->left = left;\n if (s->mode & SSL_MODE_RELEASE_BUFFERS && !SSL_IS_DTLS(s))\n if (len + left == 0)\n ssl3_release_read_buffer(s);\n return (i);\n }\n left += i;\n if (SSL_IS_DTLS(s)) {\n if (n > left)\n n = left;\n }\n }\n rb->offset += n;\n rb->left = left - n;\n s->rlayer.packet_length += n;\n s->rwstate = SSL_NOTHING;\n return (n);\n}']
1,545
0
https://gitlab.com/libtiff/libtiff/blob/0d521dfab0613833a7ce4c146f4f1411f6270105/libtiff/tif_swab.c/#L296
void TIFFReverseBits(uint8* cp, tmsize_t n) { for (; n > 8; n -= 8) { cp[0] = TIFFBitRevTable[cp[0]]; cp[1] = TIFFBitRevTable[cp[1]]; cp[2] = TIFFBitRevTable[cp[2]]; cp[3] = TIFFBitRevTable[cp[3]]; cp[4] = TIFFBitRevTable[cp[4]]; cp[5] = TIFFBitRevTable[cp[5]]; cp[6] = TIFFBitRevTable[cp[6]]; cp[7] = TIFFBitRevTable[cp[7]]; cp += 8; } while (n-- > 0) { *cp = TIFFBitRevTable[*cp]; cp++; } }
['DECLAREreadFunc(readContigTilesIntoBuffer)\n{\n\tint status = 1;\n\ttsize_t tilesize = TIFFTileSize(in);\n\ttdata_t tilebuf;\n\tuint32 imagew = TIFFScanlineSize(in);\n\tuint32 tilew = TIFFTileRowSize(in);\n\tint iskew = imagew - tilew;\n\tuint8* bufp = (uint8*) buf;\n\tuint32 tw, tl;\n\tuint32 row;\n\t(void) spp;\n\ttilebuf = _TIFFmalloc(tilesize);\n\tif (tilebuf == 0)\n\t\treturn 0;\n\t_TIFFmemset(tilebuf, 0, tilesize);\n\t(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);\n\t(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);\n\tfor (row = 0; row < imagelength; row += tl) {\n\t\tuint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;\n\t\tuint32 colb = 0;\n\t\tuint32 col;\n\t\tfor (col = 0; col < imagewidth && colb < imagew; col += tw) {\n\t\t\tif (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0\n\t\t\t && !ignore) {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t "Error, can\'t read tile at %lu %lu",\n\t\t\t\t (unsigned long) col,\n\t\t\t\t (unsigned long) row);\n\t\t\t\tstatus = 0;\n\t\t\t\tgoto done;\n\t\t\t}\n\t\t\tif (colb + tilew > imagew) {\n\t\t\t\tuint32 width = imagew - colb;\n\t\t\t\tuint32 oskew = tilew - width;\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t tilebuf, nrow, width,\n\t\t\t\t oskew + iskew, oskew );\n\t\t\t} else\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t tilebuf, nrow, tilew,\n\t\t\t\t iskew, 0);\n\t\t\tcolb += tilew;\n\t\t}\n\t\tbufp += imagew * nrow;\n\t}\ndone:\n\t_TIFFfree(tilebuf);\n\treturn status;\n}', 'tmsize_t\nTIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFReadEncodedTile(tif,\n\t TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n if( td->td_compression == COMPRESSION_NONE &&\n size!=(tmsize_t)(-1) && size >= tilesize &&\n !isMapped(tif) &&\n ((tif->tif_flags&TIFF_NOREADRAW)==0) )\n {\n if (TIFFReadRawTile1(tif, tile, buf, tilesize, module) != tilesize)\n return ((tmsize_t)(-1));\n if (!isFillOrder(tif, td->td_fillorder) &&\n (tif->tif_flags & TIFF_NOBITREV) == 0)\n TIFFReverseBits(buf,tilesize);\n (*tif->tif_postdecode)(tif,buf,tilesize);\n return (tilesize);\n }\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)\n return 0;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif ((int64)bytecount <= 0) {\n#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\t\ttif->tif_rawdata = NULL;\n\t\t\t\ttif->tif_rawdatasize = 0;\n\t\t\t}\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t\ttif->tif_flags |= TIFF_BUFFERMMAP;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (tif->tif_flags&TIFF_BUFFERMMAP) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'void\nTIFFReverseBits(uint8* cp, tmsize_t n)\n{\n\tfor (; n > 8; n -= 8) {\n\t\tcp[0] = TIFFBitRevTable[cp[0]];\n\t\tcp[1] = TIFFBitRevTable[cp[1]];\n\t\tcp[2] = TIFFBitRevTable[cp[2]];\n\t\tcp[3] = TIFFBitRevTable[cp[3]];\n\t\tcp[4] = TIFFBitRevTable[cp[4]];\n\t\tcp[5] = TIFFBitRevTable[cp[5]];\n\t\tcp[6] = TIFFBitRevTable[cp[6]];\n\t\tcp[7] = TIFFBitRevTable[cp[7]];\n\t\tcp += 8;\n\t}\n\twhile (n-- > 0) {\n\t\t*cp = TIFFBitRevTable[*cp];\n\t\tcp++;\n\t}\n}']
1,546
0
https://github.com/libav/libav/blob/bb174ff1f963052af3c292145e4b301f7145256e/libavcodec/vorbis_enc.c/#L176
static void ready_codebook(vorbis_enc_codebook *cb) { int i; ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); if (!cb->lookup) { cb->pow2 = cb->dimentions = NULL; } else { int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); for (i = 0; i < cb->nentries; i++) { float last = 0; int j; int div = 1; for (j = 0; j < cb->ndimentions; j++) { int off; if (cb->lookup == 1) off = (i / div) % vals; else off = i * cb->ndimentions + j; cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta; if (cb->seq_p) last = cb->dimentions[i * cb->ndimentions + j]; cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j]; div *= vals; } cb->pow2[i] /= 2.; } } }
['static void ready_codebook(vorbis_enc_codebook *cb)\n{\n int i;\n ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);\n if (!cb->lookup) {\n cb->pow2 = cb->dimentions = NULL;\n } else {\n int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions);\n cb->pow2 = av_mallocz(sizeof(float) * cb->nentries);\n for (i = 0; i < cb->nentries; i++) {\n float last = 0;\n int j;\n int div = 1;\n for (j = 0; j < cb->ndimentions; j++) {\n int off;\n if (cb->lookup == 1)\n off = (i / div) % vals;\n else\n off = i * cb->ndimentions + j;\n cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta;\n if (cb->seq_p)\n last = cb->dimentions[i * cb->ndimentions + j];\n cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j];\n div *= vals;\n }\n cb->pow2[i] /= 2.;\n }\n }\n}', 'static int cb_lookup_vals(int lookup, int dimentions, int entries)\n{\n if (lookup == 1)\n return ff_vorbis_nth_root(entries, dimentions);\n else if (lookup == 2)\n return dimentions *entries;\n return 0;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}']
1,547
0
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L290
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) { bn_check_top(b); if (a == b) return a; if (bn_wexpand(a, b->top) == NULL) return NULL; if (b->top > 0) memcpy(a->d, b->d, sizeof(b->d[0]) * b->top); a->neg = b->neg; a->top = b->top; a->flags |= b->flags & BN_FLG_FIXED_TOP; bn_check_top(a); return a; }
['static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)\n{\n BIGNUM *r1, *m1, *vrfy, *r2, *m[RSA_MAX_PRIME_NUM - 2];\n int ret = 0, i, ex_primes = 0;\n RSA_PRIME_INFO *pinfo;\n BN_CTX_start(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n m1 = BN_CTX_get(ctx);\n vrfy = BN_CTX_get(ctx);\n if (vrfy == NULL)\n goto err;\n if (rsa->version == RSA_ASN1_VERSION_MULTI\n && ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0\n || ex_primes > RSA_MAX_PRIME_NUM - 2))\n goto err;\n {\n BIGNUM *p = BN_new(), *q = BN_new();\n if (p == NULL || q == NULL) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME);\n if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) {\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_p, rsa->lock, p, ctx)\n || !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,\n rsa->lock, q, ctx)) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n if (ex_primes > 0) {\n BIGNUM *r = BN_new();\n if (r == NULL) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(r, pinfo->r, BN_FLG_CONSTTIME);\n if (!BN_MONT_CTX_set_locked(&pinfo->m, rsa->lock, r, ctx)) {\n BN_free(p);\n BN_free(q);\n BN_free(r);\n goto err;\n }\n }\n BN_free(r);\n }\n }\n BN_free(p);\n BN_free(q);\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 {\n BIGNUM *c = BN_new();\n if (c == NULL)\n goto err;\n BN_with_flags(c, I, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, c, rsa->q, ctx)) {\n BN_free(c);\n goto err;\n }\n {\n BIGNUM *dmq1 = BN_new();\n if (dmq1 == NULL) {\n BN_free(c);\n goto err;\n }\n BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,\n rsa->_method_mod_q)) {\n BN_free(c);\n BN_free(dmq1);\n goto err;\n }\n BN_free(dmq1);\n }\n if (!BN_mod(r1, c, rsa->p, ctx)) {\n BN_free(c);\n goto err;\n }\n BN_free(c);\n }\n {\n BIGNUM *dmp1 = BN_new();\n if (dmp1 == NULL)\n goto err;\n BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,\n rsa->_method_mod_p)) {\n BN_free(dmp1);\n goto err;\n }\n BN_free(dmp1);\n }\n if (ex_primes > 0) {\n BIGNUM *di = BN_new(), *cc = BN_new();\n if (cc == NULL || di == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n if ((m[i] = BN_CTX_get(ctx)) == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(cc, I, BN_FLG_CONSTTIME);\n BN_with_flags(di, pinfo->d, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, cc, pinfo->r, ctx)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(m[i], r1, di, pinfo->r, ctx, pinfo->m)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n }\n BN_free(cc);\n BN_free(di);\n }\n if (!BN_sub(r0, r0, m1))\n goto err;\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->iqmp, ctx))\n goto err;\n {\n BIGNUM *pr1 = BN_new();\n if (pr1 == NULL)\n goto err;\n BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);\n if (!BN_mod(r0, pr1, rsa->p, ctx)) {\n BN_free(pr1);\n goto err;\n }\n BN_free(pr1);\n }\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->q, ctx))\n goto err;\n if (!BN_add(r0, r1, m1))\n goto err;\n if (ex_primes > 0) {\n BIGNUM *pr2 = BN_new();\n if (pr2 == NULL)\n goto err;\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n if (!BN_sub(r1, m[i], r0)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r2, r1, pinfo->t, ctx)) {\n BN_free(pr2);\n goto err;\n }\n BN_with_flags(pr2, r2, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, pr2, pinfo->r, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (BN_is_negative(r1))\n if (!BN_add(r1, r1, pinfo->r)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r1, r1, pinfo->pp, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_add(r0, r0, r1)) {\n BN_free(pr2);\n goto err;\n }\n }\n BN_free(pr2);\n }\n if (rsa->e && rsa->n) {\n if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n if (!BN_sub(vrfy, vrfy, I))\n goto err;\n if (!BN_mod(vrfy, vrfy, rsa->n, ctx))\n goto err;\n if (BN_is_negative(vrfy))\n if (!BN_add(vrfy, vrfy, rsa->n))\n goto err;\n if (!BN_is_zero(vrfy)) {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_with_flags(BIGNUM *dest, const BIGNUM *b, int flags)\n{\n dest->d = b->d;\n dest->top = b->top;\n dest->dmax = b->dmax;\n dest->neg = b->neg;\n dest->flags = ((dest->flags & BN_FLG_MALLOCED)\n | (b->flags & ~BN_FLG_MALLOCED)\n | BN_FLG_STATIC_DATA | flags);\n}', '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 if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}']
1,548
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_ctx.c/#L328
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *d, *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (d == NULL || r == NULL || t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#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}', '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}']
1,549
0
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/lhash/lhash.c/#L285
void lh_doall_arg(LHASH *lh, void (*func)(), char *arg) { int i; LHASH_NODE *a,*n; for (i=lh->num_nodes-1; i>=0; i--) { a=lh->b[i]; while (a != NULL) { n=a->next; func(a->data,arg); a=n; } } }
['int MAIN(int argc, char **argv)\n\t{\n\tint ret=1;\n\tX509_REQ *req=NULL;\n\tX509 *x=NULL,*xca=NULL;\n\tEVP_PKEY *Upkey=NULL,*CApkey=NULL;\n\tint i,num,badops=0;\n\tBIO *out=NULL;\n\tBIO *STDout=NULL;\n\tint informat,outformat,keyformat,CAformat,CAkeyformat;\n\tchar *infile=NULL,*outfile=NULL,*keyfile=NULL,*CAfile=NULL;\n\tchar *CAkeyfile=NULL,*CAserial=NULL;\n\tint text=0,serial=0,hash=0,subject=0,issuer=0,startdate=0,enddate=0;\n\tint noout=0,sign_flag=0,CA_flag=0,CA_createserial=0;\n\tint C=0;\n\tint x509req=0,days=DEF_DAYS,modulus=0;\n\tchar **pp;\n\tX509_STORE *ctx=NULL;\n\tX509_REQ *rq=NULL;\n\tint fingerprint=0;\n\tchar buf[256];\n\tconst EVP_MD *md_alg,*digest=EVP_md5();\n\tLHASH *extconf = NULL;\n\tchar *extsect = NULL, *extfile = NULL;\n\treqfile=0;\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tSTDout=BIO_new_fp(stdout,BIO_NOCLOSE);\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tkeyformat=FORMAT_PEM;\n\tCAformat=FORMAT_PEM;\n\tCAkeyformat=FORMAT_PEM;\n\tctx=X509_STORE_new();\n\tif (ctx == NULL) goto end;\n\tX509_STORE_set_verify_cb_func(ctx,callb);\n\targc--;\n\targv++;\n\tnum=0;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,"-inform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-req") == 0)\n\t\t\treqfile=1;\n\t\telse if (strcmp(*argv,"-CAform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAkeyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-days") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tdays=atoi(*(++argv));\n\t\t\tif (days == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"bad number of days\\n");\n\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (strcmp(*argv,"-config") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\textfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-signkey") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyfile= *(++argv);\n\t\t\tsign_flag= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CA") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\tCA_flag= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAkey") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAkeyfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAserial") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAserial= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-C") == 0)\n\t\t\tC= ++num;\n\t\telse if (strcmp(*argv,"-serial") == 0)\n\t\t\tserial= ++num;\n\t\telse if (strcmp(*argv,"-modulus") == 0)\n\t\t\tmodulus= ++num;\n\t\telse if (strcmp(*argv,"-x509toreq") == 0)\n\t\t\tx509req= ++num;\n\t\telse if (strcmp(*argv,"-text") == 0)\n\t\t\ttext= ++num;\n\t\telse if (strcmp(*argv,"-hash") == 0)\n\t\t\thash= ++num;\n\t\telse if (strcmp(*argv,"-subject") == 0)\n\t\t\tsubject= ++num;\n\t\telse if (strcmp(*argv,"-issuer") == 0)\n\t\t\tissuer= ++num;\n\t\telse if (strcmp(*argv,"-fingerprint") == 0)\n\t\t\tfingerprint= ++num;\n\t\telse if (strcmp(*argv,"-dates") == 0)\n\t\t\t{\n\t\t\tstartdate= ++num;\n\t\t\tenddate= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-startdate") == 0)\n\t\t\tstartdate= ++num;\n\t\telse if (strcmp(*argv,"-enddate") == 0)\n\t\t\tenddate= ++num;\n\t\telse if (strcmp(*argv,"-noout") == 0)\n\t\t\tnoout= ++num;\n\t\telse if (strcmp(*argv,"-CAcreateserial") == 0)\n\t\t\tCA_createserial= ++num;\n\t\telse if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)\n\t\t\t{\n\t\t\tdigest=md_alg;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\nbad:\n\t\tfor (pp=x509_usage; (*pp != NULL); pp++)\n\t\t\tBIO_printf(bio_err,*pp);\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n\tX509V3_add_standard_extensions();\n\tif (!X509_STORE_set_default_paths(ctx))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM))\n\t\t{ CAkeyfile=CAfile; }\n\telse if ((CA_flag) && (CAkeyfile == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"need to specify a CAkey if using the CA command\\n");\n\t\tgoto end;\n\t\t}\n\tif (extfile) {\n\t\tlong errorline;\n\t\tX509V3_CTX ctx2;\n\t\tif (!(extconf=CONF_load(NULL,extfile,&errorline))) {\n\t\t\tif (errorline <= 0)\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t"error loading the config file \'%s\'\\n",\n\t\t\t\t\t\t\t\textfile);\n \telse\n \tBIO_printf(bio_err,\n\t\t\t\t "error on line %ld of config file \'%s\'\\n"\n\t\t\t\t\t\t\t,errorline,extfile);\n\t\t\tgoto end;\n\t\t}\n\t\tif(!(extsect = CONF_get_string(extconf, "default",\n\t\t\t\t\t "extensions"))) extsect = "default";\n\t\tX509V3_set_ctx_test(&ctx2);\n\t\tX509V3_set_conf_lhash(&ctx2, extconf);\n\t\tif(!X509V3_EXT_add_conf(extconf, &ctx2, extsect, NULL)) {\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t"Error Loading extension section %s\\n",\n\t\t\t\t\t\t\t\t extsect);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n }\n\t}\n\tif (reqfile)\n\t\t{\n\t\tEVP_PKEY *pkey;\n\t\tX509_CINF *ci;\n\t\tBIO *in;\n\t\tif (!sign_flag && !CA_flag)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"We need a private key to sign with\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tin=BIO_new(BIO_s_file());\n\t\tif (in == NULL)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (infile == NULL)\n\t\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(infile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\treq=PEM_read_bio_X509_REQ(in,NULL,NULL);\n\t\tBIO_free(in);\n\t\tif (req == NULL) { perror(infile); goto end; }\n\t\tif (\t(req->req_info == NULL) ||\n\t\t\t(req->req_info->pubkey == NULL) ||\n\t\t\t(req->req_info->pubkey->public_key == NULL) ||\n\t\t\t(req->req_info->pubkey->public_key->data == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"The certificate request appears to corrupted\\n");\n\t\t\tBIO_printf(bio_err,"It does not contain a public key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((pkey=X509_REQ_get_pubkey(req)) == NULL)\n\t {\n\t BIO_printf(bio_err,"error unpacking public key\\n");\n\t goto end;\n\t }\n\t\ti=X509_REQ_verify(req,pkey);\n\t\tEVP_PKEY_free(pkey);\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Signature verification error\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t if (i == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Signature did not match the certificate request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\tBIO_printf(bio_err,"Signature ok\\n");\n\t\tX509_NAME_oneline(req->req_info->subject,buf,256);\n\t\tBIO_printf(bio_err,"subject=%s\\n",buf);\n\t\tif ((x=X509_new()) == NULL) goto end;\n\t\tci=x->cert_info;\n\t\tif (!ASN1_INTEGER_set(X509_get_serialNumber(x),0)) goto end;\n\t\tif (!X509_set_issuer_name(x,req->req_info->subject)) goto end;\n\t\tif (!X509_set_subject_name(x,req->req_info->subject)) goto end;\n\t\tX509_gmtime_adj(X509_get_notBefore(x),0);\n\t X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);\n#if 0\n\t\tX509_PUBKEY_free(ci->key);\n\t\tci->key=req->req_info->pubkey;\n\t req->req_info->pubkey=NULL;\n#else\n\t\tpkey = X509_REQ_get_pubkey(req);\n\t\tX509_set_pubkey(x,pkey);\n\t\tEVP_PKEY_free(pkey);\n#endif\n\t\t}\n\telse\n\t\tx=load_cert(infile,informat);\n\tif (x == NULL) goto end;\n\tif (CA_flag)\n\t\t{\n\t\txca=load_cert(CAfile,CAformat);\n\t\tif (xca == NULL) goto end;\n\t\t}\n\tif (!noout || text)\n\t\t{\n\t\tOBJ_create("2.99999.3",\n\t\t\t"SET.ex3","SET x509v3 extension 3");\n\t\tout=BIO_new(BIO_s_file());\n\t\tif (out == NULL)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (outfile == NULL)\n\t\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(outfile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (num)\n\t\t{\n\t\tfor (i=1; i<=num; i++)\n\t\t\t{\n\t\t\tif (issuer == i)\n\t\t\t\t{\n\t\t\t\tX509_NAME_oneline(X509_get_issuer_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"issuer= %s\\n",buf);\n\t\t\t\t}\n\t\t\telse if (subject == i)\n\t\t\t\t{\n\t\t\t\tX509_NAME_oneline(X509_get_subject_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"subject=%s\\n",buf);\n\t\t\t\t}\n\t\t\telse if (serial == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"serial=");\n\t\t\t\ti2a_ASN1_INTEGER(STDout,x->cert_info->serialNumber);\n\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (hash == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"%08lx\\n",X509_subject_name_hash(x));\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif (modulus == i)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY *pkey;\n\t\t\t\tpkey=X509_get_pubkey(x);\n\t\t\t\tif (pkey == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Modulus=unavailable\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(STDout,"Modulus=");\n#ifndef NO_RSA\n\t\t\t\tif (pkey->type == EVP_PKEY_RSA)\n\t\t\t\t\tBN_print(STDout,pkey->pkey.rsa->n);\n\t\t\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\t\t\tBN_print(STDout,pkey->pkey.dsa->pub_key);\n\t\t\t\telse\n#endif\n\t\t\t\t\tBIO_printf(STDout,"Wrong Algorithm type");\n\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\tEVP_PKEY_free(pkey);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif (C == i)\n\t\t\t\t{\n\t\t\t\tunsigned char *d;\n\t\t\t\tchar *m;\n\t\t\t\tint y,z;\n\t\t\t\tX509_NAME_oneline(X509_get_subject_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"/* subject:%s */\\n",buf);\n\t\t\t\tm=X509_NAME_oneline(\n\t\t\t\t\tX509_get_issuer_name(x),buf,256);\n\t\t\t\tBIO_printf(STDout,"/* issuer :%s */\\n",buf);\n\t\t\t\tz=i2d_X509(x,NULL);\n\t\t\t\tm=Malloc(z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tz=i2d_X509_NAME(X509_get_subject_name(x),&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_subject_name[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f) BIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tz=i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x),&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_public_key[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f)\n\t\t\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tz=i2d_X509(x,&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_certificate[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f)\n\t\t\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tFree(m);\n\t\t\t\t}\n\t\t\telse if (text == i)\n\t\t\t\t{\n\t\t\t\tX509_print(out,x);\n\t\t\t\t}\n\t\t\telse if (startdate == i)\n\t\t\t\t{\n\t\t\t\tBIO_puts(STDout,"notBefore=");\n\t\t\t\tASN1_TIME_print(STDout,X509_get_notBefore(x));\n\t\t\t\tBIO_puts(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (enddate == i)\n\t\t\t\t{\n\t\t\t\tBIO_puts(STDout,"notAfter=");\n\t\t\t\tASN1_TIME_print(STDout,X509_get_notAfter(x));\n\t\t\t\tBIO_puts(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (fingerprint == i)\n\t\t\t\t{\n\t\t\t\tint j;\n\t\t\t\tunsigned int n;\n\t\t\t\tunsigned char md[EVP_MAX_MD_SIZE];\n\t\t\t\tif (!X509_digest(x,EVP_md5(),md,&n))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(STDout,"MD5 Fingerprint=");\n\t\t\t\tfor (j=0; j<(int)n; j++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"%02X%c",md[j],\n\t\t\t\t\t\t(j+1 == (int)n)\n\t\t\t\t\t\t?\'\\n\':\':\');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if ((sign_flag == i) && (x509req == 0))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"Getting Private key\\n");\n\t\t\t\tif (Upkey == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tUpkey=load_key(keyfile,keyformat);\n\t\t\t\t\tif (Upkey == NULL) goto end;\n\t\t\t\t\t}\n#ifndef NO_DSA\n\t\t if (Upkey->type == EVP_PKEY_DSA)\n\t\t digest=EVP_dss1();\n#endif\n\t\t\t\tif (!sign(x,Upkey,days,digest,\n\t\t\t\t\t\t extconf, extsect)) goto end;\n\t\t\t\t}\n\t\t\telse if (CA_flag == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"Getting CA Private Key\\n");\n\t\t\t\tif (CAkeyfile != NULL)\n\t\t\t\t\t{\n\t\t\t\t\tCApkey=load_key(CAkeyfile,CAkeyformat);\n\t\t\t\t\tif (CApkey == NULL) goto end;\n\t\t\t\t\t}\n#ifndef NO_DSA\n\t\t if (CApkey->type == EVP_PKEY_DSA)\n\t\t digest=EVP_dss1();\n#endif\n\t\t\t\tif (!x509_certify(ctx,CAfile,digest,x,xca,\n\t\t\t\t\tCApkey, CAserial,CA_createserial,days,\n\t\t\t\t\textconf, extsect))\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\telse if (x509req == i)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY *pk;\n\t\t\t\tBIO_printf(bio_err,"Getting request Private Key\\n");\n\t\t\t\tif (keyfile == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"no request key file specified\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tpk=load_key(keyfile,FORMAT_PEM);\n\t\t\t\t\tif (pk == NULL) goto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(bio_err,"Generating certificate request\\n");\n\t\t\t\trq=X509_to_X509_REQ(x,pk,EVP_md5());\n\t\t\t\tEVP_PKEY_free(pk);\n\t\t\t\tif (rq == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!noout)\n\t\t\t\t\t{\n\t\t\t\t\tX509_REQ_print(out,rq);\n\t\t\t\t\tPEM_write_bio_X509_REQ(out,rq);\n\t\t\t\t\t}\n\t\t\t\tnoout=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (noout)\n\t\t{\n\t\tret=0;\n\t\tgoto end;\n\t\t}\n\tif \t(outformat == FORMAT_ASN1)\n\t\ti=i2d_X509_bio(out,x);\n\telse if (outformat == FORMAT_PEM)\n\t\ti=PEM_write_bio_X509(out,x);\n\telse if (outformat == FORMAT_NETSCAPE)\n\t\t{\n\t\tASN1_HEADER ah;\n\t\tASN1_OCTET_STRING os;\n\t\tos.data=(unsigned char *)CERT_HDR;\n\t\tos.length=strlen(CERT_HDR);\n\t\tah.header= &os;\n\t\tah.data=(char *)x;\n\t\tah.meth=X509_asn1_meth();\n\t\ti=ASN1_i2d_bio(i2d_ASN1_HEADER,out,(unsigned char *)&ah);\n\t\t}\n\telse\t{\n\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\tgoto end;\n\t\t}\n\tif (!i) {\n\t\tBIO_printf(bio_err,"unable to write certificate\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tret=0;\nend:\n\tOBJ_cleanup();\n\tCONF_free(extconf);\n\tBIO_free(out);\n\tBIO_free(STDout);\n\tX509_STORE_free(ctx);\n\tX509_REQ_free(req);\n\tX509_free(x);\n\tX509_free(xca);\n\tEVP_PKEY_free(Upkey);\n\tEVP_PKEY_free(CApkey);\n\tX509_REQ_free(rq);\n\tX509V3_EXT_cleanup();\n\tEXIT(ret);\n\t}', 'LHASH *CONF_load(LHASH *h, char *file, long *line)\n\t{\n\tLHASH *ret=NULL;\n\tFILE *in=NULL;\n#define BUFSIZE\t512\n\tchar btmp[16];\n\tint bufnum=0,i,ii;\n\tBUF_MEM *buff=NULL;\n\tchar *s,*p,*end;\n\tint again,n;\n\tlong eline=0;\n\tCONF_VALUE *v=NULL,*vv,*tv;\n\tCONF_VALUE *sv=NULL;\n\tchar *section=NULL,*buf;\n\tSTACK *section_sk=NULL,*ts;\n\tchar *start,*psection,*pname;\n\tif ((buff=BUF_MEM_new()) == NULL)\n\t\t{\n\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);\n\t\tgoto err;\n\t\t}\n\tin=fopen(file,"rb");\n\tif (in == NULL)\n\t\t{\n\t\tSYSerr(SYS_F_FOPEN,get_last_sys_error());\n\t\tERR_set_error_data(BUF_strdup(file),\n\t\t\tERR_TXT_MALLOCED|ERR_TXT_STRING);\n\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);\n\t\tgoto err;\n\t\t}\n\tsection=(char *)Malloc(10);\n\tif (section == NULL)\n\t\t{\n\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tstrcpy(section,"default");\n\tif (h == NULL)\n\t\t{\n\t\tif ((ret=lh_new(hash,cmp)) == NULL)\n\t\t\t{\n\t\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\telse\n\t\tret=h;\n\tsv=new_section(ret,section);\n\tif (sv == NULL)\n\t\t{\n\t\tCONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);\n\t\tgoto err;\n\t\t}\n\tsection_sk=(STACK *)sv->value;\n\tbufnum=0;\n\tfor (;;)\n\t\t{\n\t\tagain=0;\n\t\tif (!BUF_MEM_grow(buff,bufnum+BUFSIZE))\n\t\t\t{\n\t\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp= &(buff->data[bufnum]);\n\t\t*p=\'\\0\';\n\t\tfgets(p,BUFSIZE-1,in);\n\t\tp[BUFSIZE-1]=\'\\0\';\n\t\tii=i=strlen(p);\n\t\tif (i == 0) break;\n\t\twhile (i > 0)\n\t\t\t{\n\t\t\tif ((p[i-1] != \'\\r\') && (p[i-1] != \'\\n\'))\n\t\t\t\tbreak;\n\t\t\telse\n\t\t\t\ti--;\n\t\t\t}\n\t\tif (i == ii)\n\t\t\tagain=1;\n\t\telse\n\t\t\t{\n\t\t\tp[i]=\'\\0\';\n\t\t\teline++;\n\t\t\t}\n\t\tbufnum+=i;\n\t\tv=NULL;\n\t\tif (bufnum >= 1)\n\t\t\t{\n\t\t\tp= &(buff->data[bufnum-1]);\n\t\t\tif (\tIS_ESC(p[0]) &&\n\t\t\t\t((bufnum <= 1) || !IS_ESC(p[-1])))\n\t\t\t\t{\n\t\t\t\tbufnum--;\n\t\t\t\tagain=1;\n\t\t\t\t}\n\t\t\t}\n\t\tif (again) continue;\n\t\tbufnum=0;\n\t\tbuf=buff->data;\n\t\tclear_comments(buf);\n\t\tn=strlen(buf);\n\t\ts=eat_ws(buf);\n\t\tif (IS_EOF(*s)) continue;\n\t\tif (*s == \'[\')\n\t\t\t{\n\t\t\tchar *ss;\n\t\t\ts++;\n\t\t\tstart=eat_ws(s);\n\t\t\tss=start;\nagain:\n\t\t\tend=eat_alpha_numeric(ss);\n\t\t\tp=eat_ws(end);\n\t\t\tif (*p != \']\')\n\t\t\t\t{\n\t\t\t\tif (*p != \'\\0\')\n\t\t\t\t\t{\n\t\t\t\t\tss=p;\n\t\t\t\t\tgoto again;\n\t\t\t\t\t}\n\t\t\t\tCONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_CLOSE_SQUARE_BRACKET);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t*end=\'\\0\';\n\t\t\tif (!str_copy(ret,NULL,&section,start)) goto err;\n\t\t\tif ((sv=get_section(ret,section)) == NULL)\n\t\t\t\tsv=new_section(ret,section);\n\t\t\tif (sv == NULL)\n\t\t\t\t{\n\t\t\t\tCONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tsection_sk=(STACK *)sv->value;\n\t\t\tcontinue;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpname=s;\n\t\t\tpsection=NULL;\n\t\t\tend=eat_alpha_numeric(s);\n\t\t\tif ((end[0] == \':\') && (end[1] == \':\'))\n\t\t\t\t{\n\t\t\t\t*end=\'\\0\';\n\t\t\t\tend+=2;\n\t\t\t\tpsection=pname;\n\t\t\t\tpname=end;\n\t\t\t\tend=eat_alpha_numeric(end);\n\t\t\t\t}\n\t\t\tp=eat_ws(end);\n\t\t\tif (*p != \'=\')\n\t\t\t\t{\n\t\t\t\tCONFerr(CONF_F_CONF_LOAD,CONF_R_MISSING_EQUAL_SIGN);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t*end=\'\\0\';\n\t\t\tp++;\n\t\t\tstart=eat_ws(p);\n\t\t\twhile (!IS_EOF(*p))\n\t\t\t\tp++;\n\t\t\tp--;\n\t\t\twhile ((p != start) && (IS_WS(*p)))\n\t\t\t\tp--;\n\t\t\tp++;\n\t\t\t*p=\'\\0\';\n\t\t\tif ((v=(CONF_VALUE *)Malloc(sizeof(CONF_VALUE))) == NULL)\n\t\t\t\t{\n\t\t\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (psection == NULL) psection=section;\n\t\t\tv->name=(char *)Malloc(strlen(pname)+1);\n\t\t\tv->value=NULL;\n\t\t\tif (v->name == NULL)\n\t\t\t\t{\n\t\t\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tstrcpy(v->name,pname);\n\t\t\tif (!str_copy(ret,psection,&(v->value),start)) goto err;\n\t\t\tif (strcmp(psection,section) != 0)\n\t\t\t\t{\n\t\t\t\tif ((tv=get_section(ret,psection))\n\t\t\t\t\t== NULL)\n\t\t\t\t\ttv=new_section(ret,psection);\n\t\t\t\tif (tv == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tCONFerr(CONF_F_CONF_LOAD,CONF_R_UNABLE_TO_CREATE_NEW_SECTION);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tts=(STACK *)tv->value;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ttv=sv;\n\t\t\t\tts=section_sk;\n\t\t\t\t}\n\t\t\tv->section=tv->section;\n\t\t\tif (!sk_push(ts,(char *)v))\n\t\t\t\t{\n\t\t\t\tCONFerr(CONF_F_CONF_LOAD,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tvv=(CONF_VALUE *)lh_insert(ret,(char *)v);\n\t\t\tif (vv != NULL)\n\t\t\t\t{\n\t\t\t\tsk_delete_ptr(ts,(char *)vv);\n\t\t\t\tFree(vv->name);\n\t\t\t\tFree(vv->value);\n\t\t\t\tFree(vv);\n\t\t\t\t}\n\t\t\tv=NULL;\n\t\t\t}\n\t\t}\n\tif (buff != NULL) BUF_MEM_free(buff);\n\tif (section != NULL) Free(section);\n\tif (in != NULL) fclose(in);\n\treturn(ret);\nerr:\n\tif (buff != NULL) BUF_MEM_free(buff);\n\tif (section != NULL) Free(section);\n\tif (line != NULL) *line=eline;\n\tsprintf(btmp,"%ld",eline);\n\tERR_add_error_data(2,"line ",btmp);\n\tif (in != NULL) fclose(in);\n\tif ((h != ret) && (ret != NULL)) CONF_free(ret);\n\tif (v != NULL)\n\t\t{\n\t\tif (v->name != NULL) Free(v->name);\n\t\tif (v->value != NULL) Free(v->value);\n\t\tif (v != NULL) Free(v);\n\t\t}\n\treturn(NULL);\n\t}', 'void CONF_free(LHASH *conf)\n\t{\n\tif (conf == NULL) return;\n\tconf->down_load=0;\n\tlh_doall_arg(conf,(void (*)())value_free_hash,(char *)conf);\n\tlh_doall_arg(conf,(void (*)())value_free_stack,(char *)conf);\n\tlh_free(conf);\n\t}', 'void lh_doall_arg(LHASH *lh, void (*func)(), char *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tfunc(a->data,arg);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
1,550
0
https://github.com/libav/libav/blob/8a49d2bcbe7573bb4b765728b2578fac0d19763f/libavcodec/h264_mvpred.h/#L391
static void fill_decode_neighbors(H264Context *h, int mb_type) { const int mb_xy = h->mb_xy; int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; static const uint8_t left_block_options[4][32] = { { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 }, { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 }, { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }, { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 } }; h->topleft_partition = -1; top_xy = mb_xy - (h->mb_stride << MB_FIELD); topleft_xy = top_xy - 1; topright_xy = top_xy + 1; left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; h->left_block = left_block_options[0]; if (FRAME_MBAFF) { const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]); const int curr_mb_field_flag = IS_INTERLACED(mb_type); if (h->mb_y & 1) { if (left_mb_field_flag != curr_mb_field_flag) { left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1; if (curr_mb_field_flag) { left_xy[LBOT] += h->mb_stride; h->left_block = left_block_options[3]; } else { topleft_xy += h->mb_stride; h->topleft_partition = 0; h->left_block = left_block_options[1]; } } } else { if (curr_mb_field_flag) { topleft_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1); topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1); top_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1); } if (left_mb_field_flag != curr_mb_field_flag) { if (curr_mb_field_flag) { left_xy[LBOT] += h->mb_stride; h->left_block = left_block_options[3]; } else { h->left_block = left_block_options[2]; } } } } h->topleft_mb_xy = topleft_xy; h->top_mb_xy = top_xy; h->topright_mb_xy = topright_xy; h->left_mb_xy[LTOP] = left_xy[LTOP]; h->left_mb_xy[LBOT] = left_xy[LBOT]; h->topleft_type = h->cur_pic.mb_type[topleft_xy]; h->top_type = h->cur_pic.mb_type[top_xy]; h->topright_type = h->cur_pic.mb_type[topright_xy]; h->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]]; h->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]]; if (FMO) { if (h->slice_table[topleft_xy] != h->slice_num) h->topleft_type = 0; if (h->slice_table[top_xy] != h->slice_num) h->top_type = 0; if (h->slice_table[left_xy[LTOP]] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0; } else { if (h->slice_table[topleft_xy] != h->slice_num) { h->topleft_type = 0; if (h->slice_table[top_xy] != h->slice_num) h->top_type = 0; if (h->slice_table[left_xy[LTOP]] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0; } } if (h->slice_table[topright_xy] != h->slice_num) h->topright_type = 0; }
['static void fill_decode_neighbors(H264Context *h, int mb_type)\n{\n const int mb_xy = h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n static const uint8_t left_block_options[4][32] = {\n { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },\n { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },\n { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },\n { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }\n };\n h->topleft_partition = -1;\n top_xy = mb_xy - (h->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy = top_xy + 1;\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;\n h->left_block = left_block_options[0];\n if (FRAME_MBAFF) {\n const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if (h->mb_y & 1) {\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += h->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += h->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n } else {\n if (curr_mb_field_flag) {\n topleft_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);\n topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);\n top_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[LBOT] += h->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy = topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = h->cur_pic.mb_type[topleft_xy];\n h->top_type = h->cur_pic.mb_type[top_xy];\n h->topright_type = h->cur_pic.mb_type[topright_xy];\n h->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];\n h->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];\n if (FMO) {\n if (h->slice_table[topleft_xy] != h->slice_num)\n h->topleft_type = 0;\n if (h->slice_table[top_xy] != h->slice_num)\n h->top_type = 0;\n if (h->slice_table[left_xy[LTOP]] != h->slice_num)\n h->left_type[LTOP] = h->left_type[LBOT] = 0;\n } else {\n if (h->slice_table[topleft_xy] != h->slice_num) {\n h->topleft_type = 0;\n if (h->slice_table[top_xy] != h->slice_num)\n h->top_type = 0;\n if (h->slice_table[left_xy[LTOP]] != h->slice_num)\n h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if (h->slice_table[topright_xy] != h->slice_num)\n h->topright_type = 0;\n}']
1,551
0
https://github.com/openssl/openssl/blob/8ae173bb57819a23717fd3c8e7c51cb62f4268d0/crypto/asn1_dsa.c/#L125
size_t encode_der_integer(const BIGNUM *n, unsigned char **ppout, size_t len) { unsigned char *out = NULL; unsigned char **pp = NULL; size_t produced; size_t c; size_t cont_len; if (len < 1 || BN_is_negative(n)) return 0; cont_len = BN_num_bits(n) / 8 + 1; if (ppout != NULL) { out = *ppout; pp = &out; *out++ = ID_INTEGER; } produced = 1; if ((c = encode_der_length(cont_len, pp, len - produced)) == 0) return 0; produced += c; if (cont_len > len - produced) return 0; if (pp != NULL) { if (BN_bn2binpad(n, out, (int)cont_len) != (int)cont_len) return 0; out += cont_len; *ppout = out; } produced += cont_len; return produced; }
['int i2d_DSA_SIG(const DSA_SIG *sig, unsigned char **ppout)\n{\n unsigned char *buf = NULL;\n unsigned char *tmp;\n unsigned char **pp = NULL;\n size_t len;\n size_t encoded_len;\n if (ppout != NULL && *ppout == NULL) {\n if ((len = encode_der_dsa_sig(sig->r, sig->s, NULL, SIZE_MAX)) == 0)\n return -1;\n buf = OPENSSL_malloc(len);\n if (buf == NULL)\n return -1;\n tmp = buf;\n pp = &tmp;\n } else {\n len = SIZE_MAX;\n pp = ppout;\n }\n if ((encoded_len = encode_der_dsa_sig(sig->r, sig->s, pp, len)) == 0) {\n OPENSSL_free(buf);\n return -1;\n }\n if (buf != NULL)\n *ppout = buf;\n return (int)encoded_len;\n}', 'size_t encode_der_dsa_sig(const BIGNUM *r, const BIGNUM *s,\n unsigned char **ppout, size_t len)\n{\n unsigned char *out = NULL;\n unsigned char **pp = NULL;\n size_t produced;\n size_t c;\n size_t r_der_len;\n size_t s_der_len;\n size_t cont_len;\n if (len < 1\n || (r_der_len = encode_der_integer(r, NULL, SIZE_MAX)) == 0\n || (s_der_len = encode_der_integer(s, NULL, SIZE_MAX)) == 0)\n return 0;\n cont_len = r_der_len + s_der_len;\n if (ppout != NULL) {\n out = *ppout;\n pp = &out;\n *out++ = ID_SEQUENCE;\n }\n produced = 1;\n if ((c = encode_der_length(cont_len, pp, len - produced)) == 0)\n return 0;\n produced += c;\n if ((c = encode_der_integer(r, pp, len - produced)) == 0)\n return 0;\n produced += c;\n if ((c = encode_der_integer(s, pp, len - produced)) == 0)\n return 0;\n produced += c;\n if (pp != NULL)\n *ppout = out;\n return produced;\n}', 'size_t encode_der_integer(const BIGNUM *n, unsigned char **ppout, size_t len)\n{\n unsigned char *out = NULL;\n unsigned char **pp = NULL;\n size_t produced;\n size_t c;\n size_t cont_len;\n if (len < 1 || BN_is_negative(n))\n return 0;\n cont_len = BN_num_bits(n) / 8 + 1;\n if (ppout != NULL) {\n out = *ppout;\n pp = &out;\n *out++ = ID_INTEGER;\n }\n produced = 1;\n if ((c = encode_der_length(cont_len, pp, len - produced)) == 0)\n return 0;\n produced += c;\n if (cont_len > len - produced)\n return 0;\n if (pp != NULL) {\n if (BN_bn2binpad(n, out, (int)cont_len) != (int)cont_len)\n return 0;\n out += cont_len;\n *ppout = out;\n }\n produced += cont_len;\n return produced;\n}']
1,552
0
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int srp_Verify_N_and_g(const BIGNUM *N, const BIGNUM *g)\n{\n BN_CTX *bn_ctx = BN_CTX_new();\n BIGNUM *p = BN_new();\n BIGNUM *r = BN_new();\n int ret =\n g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&\n BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n p != NULL && BN_rshift1(p, N) &&\n BN_is_prime_ex(p, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n r != NULL &&\n BN_mod_exp(r, g, p, N, bn_ctx) &&\n BN_add_word(r, 1) && BN_cmp(r, N) == 0;\n BN_free(r);\n BN_free(p);\n BN_CTX_free(bn_ctx);\n return ret;\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n BN_GENCB *cb)\n{\n return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, status, ret = -1;\n BN_CTX *ctx = NULL;\n if (BN_cmp(w, BN_value_one()) <= 0)\n return 0;\n if (BN_is_odd(w)) {\n if (BN_is_word(w, 3))\n return 1;\n } else {\n return BN_is_word(w, 2);\n }\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(w, primes[i]);\n if (mod == (BN_ULONG)-1)\n return -1;\n if (mod == 0)\n return BN_is_word(w, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n return -1;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);\n if (!ret)\n goto err;\n ret = (status == BN_PRIMETEST_PROBABLY_PRIME);\nerr:\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a;\n const BIGNUM *ca;\n BN_CTX_start(ctx);\n if ((a = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (y != NULL) {\n if (x == y) {\n if (!BN_sqr(a, x, ctx))\n goto err;\n } else {\n if (!BN_mul(a, x, y, ctx))\n goto err;\n }\n ca = a;\n } else\n ca = x;\n ret = BN_div_recp(NULL, r, ca, recp, ctx);\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return ret;\n}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int i, j, ret = 0;\n BIGNUM *a, *b, *d, *r;\n BN_CTX_start(ctx);\n d = (dv != NULL) ? dv : BN_CTX_get(ctx);\n r = (rem != NULL) ? rem : BN_CTX_get(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_ucmp(m, &(recp->N)) < 0) {\n BN_zero(d);\n if (!BN_copy(r, m)) {\n BN_CTX_end(ctx);\n return 0;\n }\n BN_CTX_end(ctx);\n return 1;\n }\n i = BN_num_bits(m);\n j = recp->num_bits << 1;\n if (j > i)\n i = j;\n if (i != recp->shift)\n recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx);\n if (recp->shift == -1)\n goto err;\n if (!BN_rshift(a, m, recp->num_bits))\n goto err;\n if (!BN_mul(b, a, &(recp->Nr), ctx))\n goto err;\n if (!BN_rshift(d, b, i - recp->num_bits))\n goto err;\n d->neg = 0;\n if (!BN_mul(b, &(recp->N), d, ctx))\n goto err;\n if (!BN_usub(r, m, b))\n goto err;\n r->neg = 0;\n j = 0;\n while (BN_ucmp(r, &(recp->N)) >= 0) {\n if (j++ > 2) {\n BNerr(BN_F_BN_DIV_RECP, BN_R_BAD_RECIPROCAL);\n goto err;\n }\n if (!BN_usub(r, r, &(recp->N)))\n goto err;\n if (!BN_add_word(d, 1))\n goto err;\n }\n r->neg = BN_is_zero(r) ? 0 : m->neg;\n d->neg = m->neg ^ recp->N.neg;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(dv);\n bn_check_top(rem);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n 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}']
1,553
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/bn/bn_lib.c/#L561
BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret) { unsigned int i, m; unsigned int n; BN_ULONG l; BIGNUM *bn = NULL; if (ret == NULL) ret = bn = BN_new(); if (ret == NULL) return (NULL); bn_check_top(ret); l = 0; n = len; if (n == 0) { ret->top = 0; return (ret); } i = ((n - 1) / BN_BYTES) + 1; m = ((n - 1) % (BN_BYTES)); if (bn_wexpand(ret, (int)i) == NULL) { BN_free(bn); return NULL; } ret->top = i; ret->neg = 0; while (n--) { l = (l << 8L) | *(s++); if (m-- == 0) { ret->d[--i] = l; l = 0; m = BN_BYTES - 1; } } bn_correct_top(ret); return (ret); }
['static ASN1_INTEGER *next_serial(const char *serialfile)\n{\n int ret = 0;\n BIO *in = NULL;\n ASN1_INTEGER *serial = NULL;\n BIGNUM *bn = NULL;\n if ((serial = ASN1_INTEGER_new()) == NULL)\n goto err;\n if ((in = BIO_new_file(serialfile, "r")) == NULL) {\n ERR_clear_error();\n BIO_printf(bio_err, "Warning: could not open file %s for "\n "reading, using serial number: 1\\n", serialfile);\n if (!ASN1_INTEGER_set(serial, 1))\n goto err;\n } else {\n char buf[1024];\n if (!a2i_ASN1_INTEGER(in, serial, buf, sizeof(buf))) {\n BIO_printf(bio_err, "unable to load number from %s\\n",\n serialfile);\n goto err;\n }\n if ((bn = ASN1_INTEGER_to_BN(serial, NULL)) == NULL)\n goto err;\n ASN1_INTEGER_free(serial);\n serial = NULL;\n if (!BN_add_word(bn, 1))\n goto err;\n if ((serial = BN_to_ASN1_INTEGER(bn, NULL)) == NULL)\n goto err;\n }\n ret = 1;\n err:\n if (!ret) {\n ASN1_INTEGER_free(serial);\n serial = NULL;\n }\n BIO_free_all(in);\n BN_free(bn);\n return serial;\n}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n ASN1_STRING *ret;\n ret = OPENSSL_malloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->length = 0;\n ret->type = type;\n ret->data = NULL;\n ret->flags = 0;\n return (ret);\n}', "int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)\n{\n int i, j, k, m, n, again, bufsize;\n unsigned char *s = NULL, *sp;\n unsigned char *bufp;\n int num = 0, slen = 0, first = 1;\n bs->type = V_ASN1_INTEGER;\n bufsize = BIO_gets(bp, buf, size);\n for (;;) {\n if (bufsize < 1)\n goto err;\n i = bufsize;\n if (buf[i - 1] == '\\n')\n buf[--i] = '\\0';\n if (i == 0)\n goto err;\n if (buf[i - 1] == '\\r')\n buf[--i] = '\\0';\n if (i == 0)\n goto err;\n again = (buf[i - 1] == '\\\\');\n for (j = 0; j < i; j++) {\n#ifndef CHARSET_EBCDIC\n if (!(((buf[j] >= '0') && (buf[j] <= '9')) ||\n ((buf[j] >= 'a') && (buf[j] <= 'f')) ||\n ((buf[j] >= 'A') && (buf[j] <= 'F'))))\n#else\n if (!isxdigit(buf[j]))\n#endif\n {\n i = j;\n break;\n }\n }\n buf[i] = '\\0';\n if (i < 2)\n goto err;\n bufp = (unsigned char *)buf;\n if (first) {\n first = 0;\n if ((bufp[0] == '0') && (buf[1] == '0')) {\n bufp += 2;\n i -= 2;\n }\n }\n k = 0;\n i -= again;\n if (i % 2 != 0) {\n ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_ODD_NUMBER_OF_CHARS);\n return 0;\n }\n i /= 2;\n if (num + i > slen) {\n sp = OPENSSL_realloc_clean(s, slen, num + i * 2);\n if (sp == NULL) {\n ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(s);\n return 0;\n }\n s = sp;\n slen = num + i * 2;\n }\n for (j = 0; j < i; j++, k += 2) {\n for (n = 0; n < 2; n++) {\n m = bufp[k + n];\n if ((m >= '0') && (m <= '9'))\n m -= '0';\n else if ((m >= 'a') && (m <= 'f'))\n m = m - 'a' + 10;\n else if ((m >= 'A') && (m <= 'F'))\n m = m - 'A' + 10;\n else {\n ASN1err(ASN1_F_A2I_ASN1_INTEGER,\n ASN1_R_NON_HEX_CHARACTERS);\n goto err;\n }\n s[num + j] <<= 4;\n s[num + j] |= m;\n }\n }\n num += i;\n if (again)\n bufsize = BIO_gets(bp, buf, size);\n else\n break;\n }\n bs->length = num;\n bs->data = s;\n return 1;\n err:\n ASN1err(ASN1_F_A2I_ASN1_INTEGER, ASN1_R_SHORT_LINE);\n return 0;\n}", 'BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)\n{\n return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);\n}', 'static BIGNUM *asn1_string_to_bn(const ASN1_INTEGER *ai, BIGNUM *bn,\n int itype)\n{\n BIGNUM *ret;\n if ((ai->type & ~V_ASN1_NEG) != itype) {\n ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_WRONG_INTEGER_TYPE);\n return NULL;\n }\n ret = BN_bin2bn(ai->data, ai->length, bn);\n if (ret == 0) {\n ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_BN_LIB);\n return NULL;\n }\n if (ai->type & V_ASN1_NEG)\n BN_set_negative(ret, 1);\n return ret;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return (NULL);\n bn_check_top(ret);\n l = 0;\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 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}']
1,554
0
https://github.com/openssl/openssl/blob/20bf3d8b22f8c1a3529034007d3618fd1fc4fa16/crypto/evp/pmeth_lib.c/#L582
int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md) { OSSL_PARAM sig_md_params[3], *p = sig_md_params; size_t mdsize; const char *name; if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) { ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED); return -2; } if (ctx->op.sig.sigprovctx == NULL) return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG, EVP_PKEY_CTRL_MD, 0, (void *)(md)); if (md == NULL) { name = ""; mdsize = 0; } else { mdsize = EVP_MD_size(md); name = EVP_MD_name(md); } *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST, (char *)name, strlen(name) + 1); *p++ = OSSL_PARAM_construct_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE, &mdsize); *p++ = OSSL_PARAM_construct_end(); return EVP_PKEY_CTX_set_params(ctx, sig_md_params); }
['int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)\n{\n OSSL_PARAM sig_md_params[3], *p = sig_md_params;\n size_t mdsize;\n const char *name;\n if (ctx == NULL || !EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx)) {\n ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);\n return -2;\n }\n if (ctx->op.sig.sigprovctx == NULL)\n return EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_TYPE_SIG,\n EVP_PKEY_CTRL_MD, 0, (void *)(md));\n if (md == NULL) {\n name = "";\n mdsize = 0;\n } else {\n mdsize = EVP_MD_size(md);\n name = EVP_MD_name(md);\n }\n *p++ = OSSL_PARAM_construct_utf8_string(OSSL_SIGNATURE_PARAM_DIGEST,\n (char *)name,\n strlen(name) + 1);\n *p++ = OSSL_PARAM_construct_size_t(OSSL_SIGNATURE_PARAM_DIGEST_SIZE,\n &mdsize);\n *p++ = OSSL_PARAM_construct_end();\n return EVP_PKEY_CTX_set_params(ctx, sig_md_params);\n}', 'const char *EVP_MD_name(const EVP_MD *md)\n{\n if (md->prov != NULL)\n return md->name;\n#ifndef FIPS_MODE\n return OBJ_nid2sn(EVP_MD_nid(md));\n#else\n return NULL;\n#endif\n}']
1,555
0
https://github.com/openssl/openssl/blob/1dc920c8de5b7109727a21163843feecdf06a8cf/crypto/objects/obj_dat.c/#L479
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) { int i,idx=0,n=0,len,nid; unsigned long l; unsigned char *p; const char *s; char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2]; if (buf_len <= 0) return(0); if ((a == NULL) || (a->data == NULL)) { buf[0]='\0'; return(0); } if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) { len=a->length; p=a->data; idx=0; l=0; while (idx < a->length) { l|=(p[idx]&0x7f); if (!(p[idx] & 0x80)) break; l<<=7L; idx++; } idx++; i=(int)(l/40); if (i > 2) i=2; l-=(long)(i*40); sprintf(tbuf,"%d.%lu",i,l); i=strlen(tbuf); strncpy(buf,tbuf,buf_len); buf_len-=i; buf+=i; n+=i; l=0; for (; idx<len; idx++) { l|=p[idx]&0x7f; if (!(p[idx] & 0x80)) { sprintf(tbuf,".%lu",l); i=strlen(tbuf); if (buf_len > 0) strncpy(buf,tbuf,buf_len); buf_len-=i; buf+=i; n+=i; l=0; } l<<=7L; } } else { s=OBJ_nid2ln(nid); if (s == NULL) s=OBJ_nid2sn(nid); strncpy(buf,s,buf_len); n=strlen(s); } buf[buf_len-1]='\0'; return(n); }
['int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,\n\t ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)\n{\n\tEVP_PBE_CTL *pbetmp, pbelu;\n\tint i;\n\tpbelu.pbe_nid = OBJ_obj2nid(pbe_obj);\n\tif (pbelu.pbe_nid != NID_undef) i = sk_find(pbe_algs, (char *)&pbelu);\n\telse i = -1;\n\tif (i == -1) {\n\t\tchar obj_tmp[80];\n\t\tEVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM);\n\t\tif (!pbe_obj) strcpy (obj_tmp, "NULL");\n\t\telse i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj);\n\t\tERR_add_error_data(2, "TYPE=", obj_tmp);\n\t\treturn 0;\n\t}\n\tif(!pass) passlen = 0;\n\telse if (passlen == -1) passlen = strlen(pass);\n\tpbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);\n\ti = (*pbetmp->keygen)(ctx, pass, passlen, param, pbetmp->cipher,\n\t\t\t\t\t\t pbetmp->md, en_de);\n\tif (!i) {\n\t\tEVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_KEYGEN_FAILURE);\n\t\treturn 0;\n\t}\n\treturn 1;\n}', 'int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)\n{\n\treturn OBJ_obj2txt(buf, buf_len, a, 0);\n}', 'int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n\tint i,idx=0,n=0,len,nid;\n\tunsigned long l;\n\tunsigned char *p;\n\tconst char *s;\n\tchar tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];\n\tif (buf_len <= 0) return(0);\n\tif ((a == NULL) || (a->data == NULL)) {\n\t\tbuf[0]=\'\\0\';\n\t\treturn(0);\n\t}\n\tif (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {\n\t\tlen=a->length;\n\t\tp=a->data;\n\t\tidx=0;\n\t\tl=0;\n\t\twhile (idx < a->length) {\n\t\t\tl|=(p[idx]&0x7f);\n\t\t\tif (!(p[idx] & 0x80)) break;\n\t\t\tl<<=7L;\n\t\t\tidx++;\n\t\t}\n\t\tidx++;\n\t\ti=(int)(l/40);\n\t\tif (i > 2) i=2;\n\t\tl-=(long)(i*40);\n\t\tsprintf(tbuf,"%d.%lu",i,l);\n\t\ti=strlen(tbuf);\n\t\tstrncpy(buf,tbuf,buf_len);\n\t\tbuf_len-=i;\n\t\tbuf+=i;\n\t\tn+=i;\n\t\tl=0;\n\t\tfor (; idx<len; idx++) {\n\t\t\tl|=p[idx]&0x7f;\n\t\t\tif (!(p[idx] & 0x80)) {\n\t\t\t\tsprintf(tbuf,".%lu",l);\n\t\t\t\ti=strlen(tbuf);\n\t\t\t\tif (buf_len > 0)\n\t\t\t\t\tstrncpy(buf,tbuf,buf_len);\n\t\t\t\tbuf_len-=i;\n\t\t\t\tbuf+=i;\n\t\t\t\tn+=i;\n\t\t\t\tl=0;\n\t\t\t}\n\t\t\tl<<=7L;\n\t\t}\n\t} else {\n\t\ts=OBJ_nid2ln(nid);\n\t\tif (s == NULL)\n\t\t\ts=OBJ_nid2sn(nid);\n\t\tstrncpy(buf,s,buf_len);\n\t\tn=strlen(s);\n\t}\n\tbuf[buf_len-1]=\'\\0\';\n\treturn(n);\n}']
1,556
0
https://github.com/libav/libav/blob/124c21d79f2124d028890022e98ea853a834a964/libavcodec/vorbis.c/#L40
unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { unsigned int ret=0, i, j; do { ++ret; for(i=0,j=ret;i<n-1;i++) j*=ret; } while (j<=x); return ret - 1; }
['static av_cold int vorbis_encode_init(AVCodecContext * avccontext)\n{\n vorbis_enc_context * venc = avccontext->priv_data;\n if (avccontext->channels != 2) {\n av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\\n");\n return -1;\n }\n create_vorbis_context(venc, avccontext);\n if (avccontext->flags & CODEC_FLAG_QSCALE)\n venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;\n else\n venc->quality = 1.;\n venc->quality *= venc->quality;\n avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);\n avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);\n avccontext->coded_frame = avcodec_alloc_frame();\n avccontext->coded_frame->key_frame = 1;\n return 0;\n}', 'static void create_vorbis_context(vorbis_enc_context * venc, AVCodecContext * avccontext) {\n vorbis_enc_floor * fc;\n vorbis_enc_residue * rc;\n vorbis_enc_mapping * mc;\n int i, book;\n venc->channels = avccontext->channels;\n venc->sample_rate = avccontext->sample_rate;\n venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11;\n venc->ncodebooks = FF_ARRAY_ELEMS(cvectors);\n venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks);\n for (book = 0; book < venc->ncodebooks; book++) {\n vorbis_enc_codebook * cb = &venc->codebooks[book];\n int vals;\n cb->ndimentions = cvectors[book].dim;\n cb->nentries = cvectors[book].real_len;\n cb->min = cvectors[book].min;\n cb->delta = cvectors[book].delta;\n cb->lookup = cvectors[book].lookup;\n cb->seq_p = 0;\n cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries);\n cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries);\n memcpy(cb->lens, cvectors[book].clens, cvectors[book].len);\n memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len);\n if (cb->lookup) {\n vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n cb->quantlist = av_malloc(sizeof(int) * vals);\n for (i = 0; i < vals; i++)\n cb->quantlist[i] = cvectors[book].quant[i];\n } else {\n cb->quantlist = NULL;\n }\n ready_codebook(cb);\n }\n venc->nfloors = 1;\n venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors);\n fc = &venc->floors[0];\n fc->partitions = 8;\n fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions);\n fc->nclasses = 0;\n for (i = 0; i < fc->partitions; i++) {\n static const int a[] = {0,1,2,2,3,3,4,4};\n fc->partition_to_class[i] = a[i];\n fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]);\n }\n fc->nclasses++;\n fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses);\n for (i = 0; i < fc->nclasses; i++) {\n vorbis_enc_floor_class * c = &fc->classes[i];\n int j, books;\n c->dim = floor_classes[i].dim;\n c->subclass = floor_classes[i].subclass;\n c->masterbook = floor_classes[i].masterbook;\n books = (1 << c->subclass);\n c->books = av_malloc(sizeof(int) * books);\n for (j = 0; j < books; j++)\n c->books[j] = floor_classes[i].nbooks[j];\n }\n fc->multiplier = 2;\n fc->rangebits = venc->log2_blocksize[0] - 1;\n fc->values = 2;\n for (i = 0; i < fc->partitions; i++)\n fc->values += fc->classes[fc->partition_to_class[i]].dim;\n fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values);\n fc->list[0].x = 0;\n fc->list[1].x = 1 << fc->rangebits;\n for (i = 2; i < fc->values; i++) {\n static const int a[] = {\n 93, 23,372, 6, 46,186,750, 14, 33, 65,\n 130,260,556, 3, 10, 18, 28, 39, 55, 79,\n 111,158,220,312,464,650,850\n };\n fc->list[i].x = a[i - 2];\n }\n ff_vorbis_ready_floor1_list(fc->list, fc->values);\n venc->nresidues = 1;\n venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);\n rc = &venc->residues[0];\n rc->type = 2;\n rc->begin = 0;\n rc->end = 1600;\n rc->partition_size = 32;\n rc->classifications = 10;\n rc->classbook = 15;\n rc->books = av_malloc(sizeof(*rc->books) * rc->classifications);\n {\n static const int8_t a[10][8] = {\n { -1, -1, -1, -1, -1, -1, -1, -1, },\n { -1, -1, 16, -1, -1, -1, -1, -1, },\n { -1, -1, 17, -1, -1, -1, -1, -1, },\n { -1, -1, 18, -1, -1, -1, -1, -1, },\n { -1, -1, 19, -1, -1, -1, -1, -1, },\n { -1, -1, 20, -1, -1, -1, -1, -1, },\n { -1, -1, 21, -1, -1, -1, -1, -1, },\n { 22, 23, -1, -1, -1, -1, -1, -1, },\n { 24, 25, -1, -1, -1, -1, -1, -1, },\n { 26, 27, 28, -1, -1, -1, -1, -1, },\n };\n memcpy(rc->books, a, sizeof a);\n }\n ready_residue(rc, venc);\n venc->nmappings = 1;\n venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings);\n mc = &venc->mappings[0];\n mc->submaps = 1;\n mc->mux = av_malloc(sizeof(int) * venc->channels);\n for (i = 0; i < venc->channels; i++)\n mc->mux[i] = 0;\n mc->floor = av_malloc(sizeof(int) * mc->submaps);\n mc->residue = av_malloc(sizeof(int) * mc->submaps);\n for (i = 0; i < mc->submaps; i++) {\n mc->floor[i] = 0;\n mc->residue[i] = 0;\n }\n mc->coupling_steps = venc->channels == 2 ? 1 : 0;\n mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps);\n mc->angle = av_malloc(sizeof(int) * mc->coupling_steps);\n if (mc->coupling_steps) {\n mc->magnitude[0] = 0;\n mc->angle[0] = 1;\n }\n venc->nmodes = 1;\n venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes);\n venc->modes[0].blockflag = 0;\n venc->modes[0].mapping = 0;\n venc->have_saved = 0;\n venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);\n venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]));\n venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);\n venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2);\n venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6];\n venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6];\n ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0);\n ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0);\n}', 'int ff_mdct_init(MDCTContext *s, int nbits, int inverse)\n{\n int n, n4, i;\n double alpha;\n memset(s, 0, sizeof(*s));\n n = 1 << nbits;\n s->nbits = nbits;\n s->n = n;\n n4 = n >> 2;\n s->tcos = av_malloc(n4 * sizeof(FFTSample));\n if (!s->tcos)\n goto fail;\n s->tsin = av_malloc(n4 * sizeof(FFTSample));\n if (!s->tsin)\n goto fail;\n for(i=0;i<n4;i++) {\n alpha = 2 * M_PI * (i + 1.0 / 8.0) / n;\n s->tcos[i] = -cos(alpha);\n s->tsin[i] = -sin(alpha);\n }\n if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0)\n goto fail;\n return 0;\n fail:\n av_freep(&s->tcos);\n av_freep(&s->tsin);\n return -1;\n}', 'static int put_main_header(vorbis_enc_context * venc, uint8_t ** out) {\n int i;\n PutBitContext pb;\n uint8_t buffer[50000] = {0}, * p = buffer;\n int buffer_len = sizeof buffer;\n int len, hlens[3];\n init_put_bits(&pb, p, buffer_len);\n put_bits(&pb, 8, 1);\n for (i = 0; "vorbis"[i]; i++)\n put_bits(&pb, 8, "vorbis"[i]);\n put_bits(&pb, 32, 0);\n put_bits(&pb, 8, venc->channels);\n put_bits(&pb, 32, venc->sample_rate);\n put_bits(&pb, 32, 0);\n put_bits(&pb, 32, 0);\n put_bits(&pb, 32, 0);\n put_bits(&pb, 4, venc->log2_blocksize[0]);\n put_bits(&pb, 4, venc->log2_blocksize[1]);\n put_bits(&pb, 1, 1);\n flush_put_bits(&pb);\n hlens[0] = (put_bits_count(&pb) + 7) / 8;\n buffer_len -= hlens[0];\n p += hlens[0];\n init_put_bits(&pb, p, buffer_len);\n put_bits(&pb, 8, 3);\n for (i = 0; "vorbis"[i]; i++)\n put_bits(&pb, 8, "vorbis"[i]);\n put_bits(&pb, 32, 0);\n put_bits(&pb, 32, 0);\n put_bits(&pb, 1, 1);\n flush_put_bits(&pb);\n hlens[1] = (put_bits_count(&pb) + 7) / 8;\n buffer_len -= hlens[1];\n p += hlens[1];\n init_put_bits(&pb, p, buffer_len);\n put_bits(&pb, 8, 5);\n for (i = 0; "vorbis"[i]; i++)\n put_bits(&pb, 8, "vorbis"[i]);\n put_bits(&pb, 8, venc->ncodebooks - 1);\n for (i = 0; i < venc->ncodebooks; i++)\n put_codebook_header(&pb, &venc->codebooks[i]);\n put_bits(&pb, 6, 0);\n put_bits(&pb, 16, 0);\n put_bits(&pb, 6, venc->nfloors - 1);\n for (i = 0; i < venc->nfloors; i++)\n put_floor_header(&pb, &venc->floors[i]);\n put_bits(&pb, 6, venc->nresidues - 1);\n for (i = 0; i < venc->nresidues; i++)\n put_residue_header(&pb, &venc->residues[i]);\n put_bits(&pb, 6, venc->nmappings - 1);\n for (i = 0; i < venc->nmappings; i++) {\n vorbis_enc_mapping * mc = &venc->mappings[i];\n int j;\n put_bits(&pb, 16, 0);\n put_bits(&pb, 1, mc->submaps > 1);\n if (mc->submaps > 1)\n put_bits(&pb, 4, mc->submaps - 1);\n put_bits(&pb, 1, !!mc->coupling_steps);\n if (mc->coupling_steps) {\n put_bits(&pb, 8, mc->coupling_steps - 1);\n for (j = 0; j < mc->coupling_steps; j++) {\n put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]);\n put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]);\n }\n }\n put_bits(&pb, 2, 0);\n if (mc->submaps > 1)\n for (j = 0; j < venc->channels; j++)\n put_bits(&pb, 4, mc->mux[j]);\n for (j = 0; j < mc->submaps; j++) {\n put_bits(&pb, 8, 0);\n put_bits(&pb, 8, mc->floor[j]);\n put_bits(&pb, 8, mc->residue[j]);\n }\n }\n put_bits(&pb, 6, venc->nmodes - 1);\n for (i = 0; i < venc->nmodes; i++) {\n put_bits(&pb, 1, venc->modes[i].blockflag);\n put_bits(&pb, 16, 0);\n put_bits(&pb, 16, 0);\n put_bits(&pb, 8, venc->modes[i].mapping);\n }\n put_bits(&pb, 1, 1);\n flush_put_bits(&pb);\n hlens[2] = (put_bits_count(&pb) + 7) / 8;\n len = hlens[0] + hlens[1] + hlens[2];\n p = *out = av_mallocz(64 + len + len/255);\n *p++ = 2;\n p += av_xiphlacing(p, hlens[0]);\n p += av_xiphlacing(p, hlens[1]);\n buffer_len = 0;\n for (i = 0; i < 3; i++) {\n memcpy(p, buffer + buffer_len, hlens[i]);\n p += hlens[i];\n buffer_len += hlens[i];\n }\n return p - *out;\n}', 'static void put_codebook_header(PutBitContext * pb, vorbis_enc_codebook * cb) {\n int i;\n int ordered = 0;\n put_bits(pb, 24, 0x564342);\n put_bits(pb, 16, cb->ndimentions);\n put_bits(pb, 24, cb->nentries);\n for (i = 1; i < cb->nentries; i++)\n if (cb->lens[i] < cb->lens[i-1]) break;\n if (i == cb->nentries)\n ordered = 1;\n put_bits(pb, 1, ordered);\n if (ordered) {\n int len = cb->lens[0];\n put_bits(pb, 5, len - 1);\n i = 0;\n while (i < cb->nentries) {\n int j;\n for (j = 0; j+i < cb->nentries; j++)\n if (cb->lens[j+i] != len) break;\n put_bits(pb, ilog(cb->nentries - i), j);\n i += j;\n len++;\n }\n } else {\n int sparse = 0;\n for (i = 0; i < cb->nentries; i++)\n if (!cb->lens[i]) break;\n if (i != cb->nentries)\n sparse = 1;\n put_bits(pb, 1, sparse);\n for (i = 0; i < cb->nentries; i++) {\n if (sparse) put_bits(pb, 1, !!cb->lens[i]);\n if (cb->lens[i]) put_bits(pb, 5, cb->lens[i] - 1);\n }\n }\n put_bits(pb, 4, cb->lookup);\n if (cb->lookup) {\n int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n int bits = ilog(cb->quantlist[0]);\n for (i = 1; i < tmp; i++)\n bits = FFMAX(bits, ilog(cb->quantlist[i]));\n put_float(pb, cb->min);\n put_float(pb, cb->delta);\n put_bits(pb, 4, bits - 1);\n put_bits(pb, 1, cb->seq_p);\n for (i = 0; i < tmp; i++)\n put_bits(pb, bits, cb->quantlist[i]);\n }\n}', 'static int cb_lookup_vals(int lookup, int dimentions, int entries) {\n if (lookup == 1) return ff_vorbis_nth_root(entries, dimentions);\n else if (lookup == 2) return dimentions * entries;\n return 0;\n}', 'unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) {\n unsigned int ret=0, i, j;\n do {\n ++ret;\n for(i=0,j=ret;i<n-1;i++) j*=ret;\n } while (j<=x);\n return ret - 1;\n}']
1,557
0
https://github.com/libav/libav/blob/adfdcf87b15d70ae5fcf9ddf28e400fb2ba5c8fe/libavcodec/rv40.c/#L483
static void rv40_loop_filter(RV34DecContext *r, int row) { MpegEncContext *s = &r->s; int mb_pos, mb_x; int i, j, k; uint8_t *Y, *C; int alpha, beta, betaY, betaC; int q; int mbtype[4]; int mb_strong[4]; int clip[4]; int cbp[4]; int uvcbp[4][2]; int mvmasks[4]; mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos]; if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF; if(IS_INTRA(mbtype)) r->cbp_chroma[mb_pos] = 0xFF; } mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int y_h_deblock, y_v_deblock; int c_v_deblock[2], c_h_deblock[2]; int clip_left; int avail[4]; int y_to_deblock, c_to_deblock[2]; q = s->current_picture_ptr->f.qscale_table[mb_pos]; alpha = rv40_alpha_tab[q]; beta = rv40_beta_tab [q]; betaY = betaC = beta * 3; if(s->width * s->height <= 176*144) betaY += beta; avail[0] = 1; avail[1] = row; avail[2] = mb_x; avail[3] = row < s->mb_height - 1; for(i = 0; i < 4; i++){ if(avail[i]){ int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; mvmasks[i] = r->deblock_coefs[pos]; mbtype [i] = s->current_picture_ptr->f.mb_type[pos]; cbp [i] = r->cbp_luma[pos]; uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; uvcbp[i][1] = r->cbp_chroma[pos] >> 4; }else{ mvmasks[i] = 0; mbtype [i] = mbtype[0]; cbp [i] = 0; uvcbp[i][0] = uvcbp[i][1] = 0; } mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]); clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q]; } y_to_deblock = mvmasks[POS_CUR] | (mvmasks[POS_BOTTOM] << 16); y_h_deblock = y_to_deblock | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW) | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12); y_v_deblock = y_to_deblock | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL) | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3); if(!mb_x) y_v_deblock &= ~MASK_Y_LEFT_COL; if(!row) y_h_deblock &= ~MASK_Y_TOP_ROW; if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])) y_h_deblock &= ~(MASK_Y_TOP_ROW << 16); for(i = 0; i < 2; i++){ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i]; c_v_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL) | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1); c_h_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2) | (uvcbp[POS_CUR][i] << 2); if(!mb_x) c_v_deblock[i] &= ~MASK_C_LEFT_COL; if(!row) c_h_deblock[i] &= ~MASK_C_TOP_ROW; if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]) c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4); } for(j = 0; j < 16; j += 4){ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize; for(i = 0; i < 4; i++, Y += 4){ int ij = i + j; int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; int dither = j ? ij : i*4; if(y_h_deblock & (MASK_BOTTOM << ij)){ r->rdsp.rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither, y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, clip_cur, alpha, beta, betaY, 0, 0); } if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; else clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; r->rdsp.rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 0); } if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ r->rdsp.rv40_h_loop_filter(Y, s->linesize, dither, clip_cur, mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0, alpha, beta, betaY, 0, 1); } if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; r->rdsp.rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 1); } } } for(k = 0; k < 2; k++){ for(j = 0; j < 2; j++){ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; for(i = 0; i < 2; i++, C += 4){ int ij = i + j*2; int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; r->rdsp.rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8, clip_bot, clip_cur, alpha, beta, betaC, 1, 0); } if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; else clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; r->rdsp.rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 0); } if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; r->rdsp.rv40_h_loop_filter(C, s->uvlinesize, i*8, clip_cur, clip_top, alpha, beta, betaC, 1, 1); } if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; r->rdsp.rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 1); } } } } } }
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->f.qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->f.mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n r->rdsp.rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur,\n alpha, beta, betaY, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n r->rdsp.rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n r->rdsp.rv40_h_loop_filter(Y, s->linesize, dither,\n clip_cur,\n mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n r->rdsp.rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n r->rdsp.rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n r->rdsp.rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n r->rdsp.rv40_h_loop_filter(C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n r->rdsp.rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1);\n }\n }\n }\n }\n }\n}']
1,558
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/asn1/asn1_lib.c/#L222
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; }
['PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)\n{\n\tPKCS8_PRIV_KEY_INFO *p8;\n#ifndef NO_DSA\n\tASN1_INTEGER *dpkey;\n\tunsigned char *p, *q;\n\tint len;\n#endif\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#ifndef NO_RSA\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#endif\n#ifndef NO_DSA\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#endif\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_PRIMITIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMITIVE_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}']
1,559
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); }
['int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,\n const char *grp)\n{\n SRP_gN *GN = SRP_get_default_gN(grp);\n if (GN == NULL)\n return -1;\n s->srp_ctx.N = BN_dup(GN->N);\n s->srp_ctx.g = BN_dup(GN->g);\n BN_clear_free(s->srp_ctx.v);\n s->srp_ctx.v = NULL;\n BN_clear_free(s->srp_ctx.s);\n s->srp_ctx.s = NULL;\n if (!SRP_create_verifier_BN\n (user, pass, &s->srp_ctx.s, &s->srp_ctx.v, GN->N, GN->g))\n return -1;\n return 1;\n}', '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}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_mont(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 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 (!d || !r || !val[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 if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_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}']
1,560
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L765
int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n) { int i; BN_ULONG aa, bb; aa = a[n - 1]; bb = b[n - 1]; if (aa != bb) return ((aa > bb) ? 1 : -1); for (i = n - 2; i >= 0; i--) { aa = a[i]; bb = b[i]; if (aa != bb) return ((aa > bb) ? 1 : -1); } return (0); }
['int gost2001_do_verify(const unsigned char *dgst, int dgst_len,\n DSA_SIG *sig, EC_KEY *ec)\n{\n BN_CTX *ctx = BN_CTX_new();\n const EC_GROUP *group = EC_KEY_get0_group(ec);\n BIGNUM *order;\n BIGNUM *md = NULL, *e = NULL, *R = NULL, *v = NULL, *z1 = NULL, *z2 =\n NULL;\n BIGNUM *X = NULL, *tmp = NULL;\n EC_POINT *C = NULL;\n const EC_POINT *pub_key = NULL;\n int ok = 0;\n if (!ctx || !group) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n BN_CTX_start(ctx);\n order = BN_CTX_get(ctx);\n e = BN_CTX_get(ctx);\n z1 = BN_CTX_get(ctx);\n z2 = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n R = BN_CTX_get(ctx);\n v = BN_CTX_get(ctx);\n if (!order || !e || !z1 || !z2 || !tmp || !X || !R || !v) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n pub_key = EC_KEY_get0_public_key(ec);\n if (!pub_key || !EC_GROUP_get_order(group, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||\n (BN_cmp(sig->s, order) >= 1) || (BN_cmp(sig->r, order) >= 1)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY,\n GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n goto err;\n }\n md = hashsum2bn(dgst);\n if (!md || !BN_mod(e, md, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef DEBUG_SIGN\n fprintf(stderr, "digest as bignum: ");\n BN_print_fp(stderr, md);\n fprintf(stderr, "\\ndigest mod q: ");\n BN_print_fp(stderr, e);\n#endif\n if (BN_is_zero(e) && !BN_one(e)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n v = BN_mod_inverse(v, e, order, ctx);\n if (!v\n || !BN_mod_mul(z1, sig->s, v, order, ctx)\n || !BN_sub(tmp, order, sig->r)\n || !BN_mod_mul(z2, tmp, v, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef DEBUG_SIGN\n fprintf(stderr, "\\nInverted digest value: ");\n BN_print_fp(stderr, v);\n fprintf(stderr, "\\nz1: ");\n BN_print_fp(stderr, z1);\n fprintf(stderr, "\\nz2: ");\n BN_print_fp(stderr, z2);\n#endif\n C = EC_POINT_new(group);\n if (!C) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EC_POINT_mul(group, C, z1, pub_key, z2, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);\n goto err;\n }\n if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);\n goto err;\n }\n if (!BN_mod(R, X, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef DEBUG_SIGN\n fprintf(stderr, "\\nX=");\n BN_print_fp(stderr, X);\n fprintf(stderr, "\\nX mod q=");\n BN_print_fp(stderr, R);\n fprintf(stderr, "\\n");\n#endif\n if (BN_cmp(R, sig->r) != 0) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH);\n } else {\n ok = 1;\n }\n err:\n EC_POINT_free(C);\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n BN_free(md);\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}']
1,561
0
https://github.com/openssl/openssl/blob/c922ebe23247ff9ee07310fa30647623c0547cd9/ssl/statem/statem_clnt.c/#L2885
int tls_construct_client_verify(SSL *s, WPACKET *pkt) { EVP_PKEY *pkey; const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys]; EVP_MD_CTX *mctx = NULL; unsigned u = 0; long hdatalen = 0; void *hdata; unsigned char *sig = NULL; mctx = EVP_MD_CTX_new(); if (mctx == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE); goto err; } pkey = s->cert->key->privatekey; hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata); if (hdatalen <= 0) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR); goto err; } if (SSL_USE_SIGALGS(s)&& !tls12_get_sigandhash(pkt, pkey, md)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR); goto err; } #ifdef SSL_DEBUG fprintf(stderr, "Using client alg %s\n", EVP_MD_name(md)); #endif sig = OPENSSL_malloc(EVP_PKEY_size(pkey)); if (sig == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE); goto err; } if (!EVP_SignInit_ex(mctx, md, NULL) || !EVP_SignUpdate(mctx, hdata, hdatalen) || (s->version == SSL3_VERSION && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET, (int)s->session->master_key_length, s->session->master_key)) || !EVP_SignFinal(mctx, sig, &u, pkey)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB); goto err; } #ifndef OPENSSL_NO_GOST { int pktype = EVP_PKEY_id(pkey); if (pktype == NID_id_GostR3410_2001 || pktype == NID_id_GostR3410_2012_256 || pktype == NID_id_GostR3410_2012_512) BUF_reverse(sig, NULL, u); } #endif if (!WPACKET_sub_memcpy_u16(pkt, sig, u)) { SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR); goto err; } if (!ssl3_digest_cached_records(s, 0)) goto err; OPENSSL_free(sig); EVP_MD_CTX_free(mctx); return 1; err: OPENSSL_free(sig); EVP_MD_CTX_free(mctx); ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); return 0; }
['int tls_construct_client_verify(SSL *s, WPACKET *pkt)\n{\n EVP_PKEY *pkey;\n const EVP_MD *md = s->s3->tmp.md[s->cert->key - s->cert->pkeys];\n EVP_MD_CTX *mctx = NULL;\n unsigned u = 0;\n long hdatalen = 0;\n void *hdata;\n unsigned char *sig = NULL;\n mctx = EVP_MD_CTX_new();\n if (mctx == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n pkey = s->cert->key->privatekey;\n hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata);\n if (hdatalen <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (SSL_USE_SIGALGS(s)&& !tls12_get_sigandhash(pkt, pkey, md)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef SSL_DEBUG\n fprintf(stderr, "Using client alg %s\\n", EVP_MD_name(md));\n#endif\n sig = OPENSSL_malloc(EVP_PKEY_size(pkey));\n if (sig == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EVP_SignInit_ex(mctx, md, NULL)\n || !EVP_SignUpdate(mctx, hdata, hdatalen)\n || (s->version == SSL3_VERSION\n && !EVP_MD_CTX_ctrl(mctx, EVP_CTRL_SSL3_MASTER_SECRET,\n (int)s->session->master_key_length,\n s->session->master_key))\n || !EVP_SignFinal(mctx, sig, &u, pkey)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_EVP_LIB);\n goto err;\n }\n#ifndef OPENSSL_NO_GOST\n {\n int pktype = EVP_PKEY_id(pkey);\n if (pktype == NID_id_GostR3410_2001\n || pktype == NID_id_GostR3410_2012_256\n || pktype == NID_id_GostR3410_2012_512)\n BUF_reverse(sig, NULL, u);\n }\n#endif\n if (!WPACKET_sub_memcpy_u16(pkt, sig, u)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!ssl3_digest_cached_records(s, 0))\n goto err;\n OPENSSL_free(sig);\n EVP_MD_CTX_free(mctx);\n return 1;\n err:\n OPENSSL_free(sig);\n EVP_MD_CTX_free(mctx);\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n return 0;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)\n{\n long ret;\n if (b == NULL)\n return 0;\n if ((b->method == NULL) || (b->method->ctrl == NULL)) {\n BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);\n return -2;\n }\n if (b->callback != NULL || b->callback_ex != NULL) {\n ret = bio_call_callback(b, BIO_CB_CTRL, parg, 0, cmd, larg, 1L, NULL);\n if (ret <= 0)\n return ret;\n }\n ret = b->method->ctrl(b, cmd, larg, parg);\n if (b->callback != NULL || b->callback_ex != NULL)\n ret = bio_call_callback(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, 0, cmd,\n larg, ret, NULL);\n return ret;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}']
1,562
0
https://github.com/libav/libav/blob/0699dbb8478886826dedb1c33a0b74142a1cd863/libavcodec/mpegvideo.c/#L626
int MPV_common_init(MpegEncContext *s) { int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads; if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) s->mb_height = (s->height + 31) / 32 * 2; else if (s->codec_id != CODEC_ID_H264) s->mb_height = (s->height + 15) / 16; if(s->avctx->pix_fmt == PIX_FMT_NONE){ av_log(s->avctx, AV_LOG_ERROR, "decoding to PIX_FMT_NONE is not supported.\n"); return -1; } if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){ av_log(s->avctx, AV_LOG_ERROR, "too many threads\n"); return -1; } if((s->width || s->height) && av_image_check_size(s->width, s->height, 0, s->avctx)) return -1; dsputil_init(&s->dsp, s->avctx); ff_dct_common_init(s); s->flags= s->avctx->flags; s->flags2= s->avctx->flags2; if (s->width && s->height) { s->mb_width = (s->width + 15) / 16; s->mb_stride = s->mb_width + 1; s->b8_stride = s->mb_width*2 + 1; s->b4_stride = s->mb_width*4 + 1; mb_array_size= s->mb_height * s->mb_stride; mv_table_size= (s->mb_height+2) * s->mb_stride + 1; avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), &(s->chroma_y_shift) ); s->h_edge_pos= s->mb_width*16; s->v_edge_pos= s->mb_height*16; s->mb_num = s->mb_width * s->mb_height; s->block_wrap[0]= s->block_wrap[1]= s->block_wrap[2]= s->block_wrap[3]= s->b8_stride; s->block_wrap[4]= s->block_wrap[5]= s->mb_stride; y_size = s->b8_stride * (2 * s->mb_height + 1); c_size = s->mb_stride * (s->mb_height + 1); yc_size = y_size + 2 * c_size; s->codec_tag = ff_toupper4(s->avctx->codec_tag); s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag); s->avctx->coded_frame= (AVFrame*)&s->current_picture; FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) for(y=0; y<s->mb_height; y++){ for(x=0; x<s->mb_width; x++){ s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; } } s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; if (s->encoding) { FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail) s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1; s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1; s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; if(s->msmpeg4_version){ FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail); } FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail); FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) if(s->avctx->noise_reduction){ FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail) } } } FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail) for(i = 0; i < MAX_PICTURE_COUNT; i++) { avcodec_get_frame_defaults((AVFrame *)&s->picture[i]); } if (s->width && s->height) { FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail) if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ for(i=0; i<2; i++){ int j, k; for(j=0; j<2; j++){ for(k=0; k<2; k++){ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail) s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; } FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail) s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]+ s->mb_stride + 1; } FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail) } } if (s->out_format == FMT_H263) { FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail); s->coded_block= s->coded_block_base + s->b8_stride + 1; FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail) FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail) } if (s->h263_pred || s->h263_plus || !s->encoding) { FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail); s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; s->dc_val[2] = s->dc_val[1] + c_size; for(i=0;i<yc_size;i++) s->dc_val_base[i] = 1024; } FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail); memset(s->mbintra_table, 1, mb_array_size); FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail); FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail); s->parse_context.state= -1; if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); } } s->context_initialized = 1; if (s->width && s->height) { s->thread_context[0]= s; threads = s->avctx->thread_count; for(i=1; i<threads; i++){ s->thread_context[i]= av_malloc(sizeof(MpegEncContext)); memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); } for(i=0; i<threads; i++){ if(init_duplicate_context(s->thread_context[i], s) < 0) goto fail; s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; } } return 0; fail: MPV_common_end(s); return -1; }
['int MPV_common_init(MpegEncContext *s)\n{\n int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads;\n if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)\n s->mb_height = (s->height + 31) / 32 * 2;\n else if (s->codec_id != CODEC_ID_H264)\n s->mb_height = (s->height + 15) / 16;\n if(s->avctx->pix_fmt == PIX_FMT_NONE){\n av_log(s->avctx, AV_LOG_ERROR, "decoding to PIX_FMT_NONE is not supported.\\n");\n return -1;\n }\n if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){\n av_log(s->avctx, AV_LOG_ERROR, "too many threads\\n");\n return -1;\n }\n if((s->width || s->height) && av_image_check_size(s->width, s->height, 0, s->avctx))\n return -1;\n dsputil_init(&s->dsp, s->avctx);\n ff_dct_common_init(s);\n s->flags= s->avctx->flags;\n s->flags2= s->avctx->flags2;\n if (s->width && s->height) {\n s->mb_width = (s->width + 15) / 16;\n s->mb_stride = s->mb_width + 1;\n s->b8_stride = s->mb_width*2 + 1;\n s->b4_stride = s->mb_width*4 + 1;\n mb_array_size= s->mb_height * s->mb_stride;\n mv_table_size= (s->mb_height+2) * s->mb_stride + 1;\n avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift),\n &(s->chroma_y_shift) );\n s->h_edge_pos= s->mb_width*16;\n s->v_edge_pos= s->mb_height*16;\n s->mb_num = s->mb_width * s->mb_height;\n s->block_wrap[0]=\n s->block_wrap[1]=\n s->block_wrap[2]=\n s->block_wrap[3]= s->b8_stride;\n s->block_wrap[4]=\n s->block_wrap[5]= s->mb_stride;\n y_size = s->b8_stride * (2 * s->mb_height + 1);\n c_size = s->mb_stride * (s->mb_height + 1);\n yc_size = y_size + 2 * c_size;\n s->codec_tag = ff_toupper4(s->avctx->codec_tag);\n s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag);\n s->avctx->coded_frame= (AVFrame*)&s->current_picture;\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail)\n for(y=0; y<s->mb_height; y++){\n for(x=0; x<s->mb_width; x++){\n s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride;\n }\n }\n s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width;\n if (s->encoding) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t), fail)\n s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;\n s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;\n s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;\n s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1;\n s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1;\n s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;\n if(s->msmpeg4_version){\n FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int), fail);\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->avctx->stats_out, 256, fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type , mb_array_size * sizeof(uint16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail)\n if(s->avctx->noise_reduction){\n FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail)\n }\n }\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail)\n for(i = 0; i < MAX_PICTURE_COUNT; i++) {\n avcodec_get_frame_defaults((AVFrame *)&s->picture[i]);\n }\n if (s->width && s->height) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail)\n if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){\n for(i=0; i<2; i++){\n int j, k;\n for(j=0; j<2; j++){\n for(k=0; k<2; k++){\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail)\n s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1;\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail)\n s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]+ s->mb_stride + 1;\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail)\n }\n }\n if (s->out_format == FMT_H263) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);\n s->coded_block= s->coded_block_base + s->b8_stride + 1;\n FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail)\n FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail)\n }\n if (s->h263_pred || s->h263_plus || !s->encoding) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail);\n s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;\n s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;\n s->dc_val[2] = s->dc_val[1] + c_size;\n for(i=0;i<yc_size;i++)\n s->dc_val_base[i] = 1024;\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);\n memset(s->mbintra_table, 1, mb_array_size);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail);\n s->parse_context.state= -1;\n if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){\n s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);\n s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);\n s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH);\n }\n }\n s->context_initialized = 1;\n if (s->width && s->height) {\n s->thread_context[0]= s;\n threads = s->avctx->thread_count;\n for(i=1; i<threads; i++){\n s->thread_context[i]= av_malloc(sizeof(MpegEncContext));\n memcpy(s->thread_context[i], s, sizeof(MpegEncContext));\n }\n for(i=0; i<threads; i++){\n if(init_duplicate_context(s->thread_context[i], s) < 0)\n goto fail;\n s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count;\n s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count;\n }\n }\n return 0;\n fail:\n MPV_common_end(s);\n return -1;\n}']
1,563
0
https://github.com/libav/libav/blob/2ee054c2153c32790851cc1095c50d3a89cf2dcc/libavcodec/dv.c/#L180
static av_cold int dvvideo_init(AVCodecContext *avctx) { DVVideoContext *s = avctx->priv_data; DSPContext dsp; static int done = 0; int i, j; if (!done) { VLC dv_vlc; uint16_t new_dv_vlc_bits[NB_DV_VLC*2]; uint8_t new_dv_vlc_len[NB_DV_VLC*2]; uint8_t new_dv_vlc_run[NB_DV_VLC*2]; int16_t new_dv_vlc_level[NB_DV_VLC*2]; done = 1; for (i = 0; i < DV_ANCHOR_SIZE; i++) dv_anchor[i] = (void*)(size_t)i; for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) { new_dv_vlc_bits[j] = dv_vlc_bits[i]; new_dv_vlc_len[j] = dv_vlc_len[i]; new_dv_vlc_run[j] = dv_vlc_run[i]; new_dv_vlc_level[j] = dv_vlc_level[i]; if (dv_vlc_level[i]) { new_dv_vlc_bits[j] <<= 1; new_dv_vlc_len[j]++; j++; new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1; new_dv_vlc_len[j] = dv_vlc_len[i] + 1; new_dv_vlc_run[j] = dv_vlc_run[i]; new_dv_vlc_level[j] = -dv_vlc_level[i]; } } init_vlc(&dv_vlc, TEX_VLC_BITS, j, new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0); assert(dv_vlc.table_size == 1184); for (i = 0; i < dv_vlc.table_size; i++){ int code = dv_vlc.table[i][0]; int len = dv_vlc.table[i][1]; int level, run; if (len < 0){ run = 0; level = code; } else { run = new_dv_vlc_run [code] + 1; level = new_dv_vlc_level[code]; } dv_rl_vlc[i].len = len; dv_rl_vlc[i].level = level; dv_rl_vlc[i].run = run; } free_vlc(&dv_vlc); for (i = 0; i < NB_DV_VLC - 1; i++) { if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE) continue; #ifdef DV_CODEC_TINY_TARGET if (dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE) continue; #endif if (dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size != 0) continue; dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].vlc = dv_vlc_bits[i] << (!!dv_vlc_level[i]); dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size = dv_vlc_len[i] + (!!dv_vlc_level[i]); } for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) { #ifdef DV_CODEC_TINY_TARGET for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) { if (dv_vlc_map[i][j].size == 0) { dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + dv_vlc_map[0][j].size; } } #else for (j = 1; j < DV_VLC_MAP_LEV_SIZE/2; j++) { if (dv_vlc_map[i][j].size == 0) { dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc | (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size)); dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size + dv_vlc_map[0][j].size; } dv_vlc_map[i][((uint16_t)(-j))&0x1ff].vlc = dv_vlc_map[i][j].vlc | 1; dv_vlc_map[i][((uint16_t)(-j))&0x1ff].size = dv_vlc_map[i][j].size; } #endif } } dsputil_init(&dsp, avctx); s->get_pixels = dsp.get_pixels; s->fdct[0] = dsp.fdct; s->idct_put[0] = dsp.idct_put; for (i = 0; i < 64; i++) s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]]; s->fdct[1] = dsp.fdct248; s->idct_put[1] = ff_simple_idct248_put; if (avctx->lowres){ for (i = 0; i < 64; i++){ int j = ff_zigzag248_direct[i]; s->dv_zigzag[1][i] = dsp.idct_permutation[(j & 7) + (j & 8) * 4 + (j & 48) / 2]; } }else memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64); dv_build_unquantize_tables(s, dsp.idct_permutation); avctx->coded_frame = &s->picture; s->avctx = avctx; return 0; }
['static av_cold int dvvideo_init(AVCodecContext *avctx)\n{\n DVVideoContext *s = avctx->priv_data;\n DSPContext dsp;\n static int done = 0;\n int i, j;\n if (!done) {\n VLC dv_vlc;\n uint16_t new_dv_vlc_bits[NB_DV_VLC*2];\n uint8_t new_dv_vlc_len[NB_DV_VLC*2];\n uint8_t new_dv_vlc_run[NB_DV_VLC*2];\n int16_t new_dv_vlc_level[NB_DV_VLC*2];\n done = 1;\n for (i = 0; i < DV_ANCHOR_SIZE; i++)\n dv_anchor[i] = (void*)(size_t)i;\n for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) {\n new_dv_vlc_bits[j] = dv_vlc_bits[i];\n new_dv_vlc_len[j] = dv_vlc_len[i];\n new_dv_vlc_run[j] = dv_vlc_run[i];\n new_dv_vlc_level[j] = dv_vlc_level[i];\n if (dv_vlc_level[i]) {\n new_dv_vlc_bits[j] <<= 1;\n new_dv_vlc_len[j]++;\n j++;\n new_dv_vlc_bits[j] = (dv_vlc_bits[i] << 1) | 1;\n new_dv_vlc_len[j] = dv_vlc_len[i] + 1;\n new_dv_vlc_run[j] = dv_vlc_run[i];\n new_dv_vlc_level[j] = -dv_vlc_level[i];\n }\n }\n init_vlc(&dv_vlc, TEX_VLC_BITS, j,\n new_dv_vlc_len, 1, 1, new_dv_vlc_bits, 2, 2, 0);\n assert(dv_vlc.table_size == 1184);\n for (i = 0; i < dv_vlc.table_size; i++){\n int code = dv_vlc.table[i][0];\n int len = dv_vlc.table[i][1];\n int level, run;\n if (len < 0){\n run = 0;\n level = code;\n } else {\n run = new_dv_vlc_run [code] + 1;\n level = new_dv_vlc_level[code];\n }\n dv_rl_vlc[i].len = len;\n dv_rl_vlc[i].level = level;\n dv_rl_vlc[i].run = run;\n }\n free_vlc(&dv_vlc);\n for (i = 0; i < NB_DV_VLC - 1; i++) {\n if (dv_vlc_run[i] >= DV_VLC_MAP_RUN_SIZE)\n continue;\n#ifdef DV_CODEC_TINY_TARGET\n if (dv_vlc_level[i] >= DV_VLC_MAP_LEV_SIZE)\n continue;\n#endif\n if (dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size != 0)\n continue;\n dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].vlc =\n dv_vlc_bits[i] << (!!dv_vlc_level[i]);\n dv_vlc_map[dv_vlc_run[i]][dv_vlc_level[i]].size =\n dv_vlc_len[i] + (!!dv_vlc_level[i]);\n }\n for (i = 0; i < DV_VLC_MAP_RUN_SIZE; i++) {\n#ifdef DV_CODEC_TINY_TARGET\n for (j = 1; j < DV_VLC_MAP_LEV_SIZE; j++) {\n if (dv_vlc_map[i][j].size == 0) {\n dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc |\n (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size));\n dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size +\n dv_vlc_map[0][j].size;\n }\n }\n#else\n for (j = 1; j < DV_VLC_MAP_LEV_SIZE/2; j++) {\n if (dv_vlc_map[i][j].size == 0) {\n dv_vlc_map[i][j].vlc = dv_vlc_map[0][j].vlc |\n (dv_vlc_map[i-1][0].vlc << (dv_vlc_map[0][j].size));\n dv_vlc_map[i][j].size = dv_vlc_map[i-1][0].size +\n dv_vlc_map[0][j].size;\n }\n dv_vlc_map[i][((uint16_t)(-j))&0x1ff].vlc =\n dv_vlc_map[i][j].vlc | 1;\n dv_vlc_map[i][((uint16_t)(-j))&0x1ff].size =\n dv_vlc_map[i][j].size;\n }\n#endif\n }\n }\n dsputil_init(&dsp, avctx);\n s->get_pixels = dsp.get_pixels;\n s->fdct[0] = dsp.fdct;\n s->idct_put[0] = dsp.idct_put;\n for (i = 0; i < 64; i++)\n s->dv_zigzag[0][i] = dsp.idct_permutation[ff_zigzag_direct[i]];\n s->fdct[1] = dsp.fdct248;\n s->idct_put[1] = ff_simple_idct248_put;\n if (avctx->lowres){\n for (i = 0; i < 64; i++){\n int j = ff_zigzag248_direct[i];\n s->dv_zigzag[1][i] = dsp.idct_permutation[(j & 7) + (j & 8) * 4 + (j & 48) / 2];\n }\n }else\n memcpy(s->dv_zigzag[1], ff_zigzag248_direct, 64);\n dv_build_unquantize_tables(s, dsp.idct_permutation);\n avctx->coded_frame = &s->picture;\n s->avctx = avctx;\n return 0;\n}']
1,564
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/ssl/ssl_rsa.c/#L979
int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file) { unsigned char *serverinfo = NULL; size_t serverinfo_length = 0; unsigned char *extension = 0; long extension_length = 0; char *name = NULL; char *header = NULL; char namePrefix[] = "SERVERINFO FOR "; int ret = 0; BIO *bin = NULL; size_t num_extensions = 0; if (ctx == NULL || file == NULL) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_PASSED_NULL_PARAMETER); goto end; } bin = BIO_new(BIO_s_file()); if (bin == NULL) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_BUF_LIB); goto end; } if (BIO_read_filename(bin, file) <= 0) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_SYS_LIB); goto end; } for (num_extensions = 0;; num_extensions++) { if (PEM_read_bio(bin, &name, &header, &extension, &extension_length) == 0) { if (num_extensions == 0) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, SSL_R_NO_PEM_EXTENSIONS); goto end; } else break; } if (strlen(name) < strlen(namePrefix)) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, SSL_R_PEM_NAME_TOO_SHORT); goto end; } if (strncmp(name, namePrefix, strlen(namePrefix)) != 0) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, SSL_R_PEM_NAME_BAD_PREFIX); goto end; } if (extension_length < 4 || (extension[2] << 8) + extension[3] != extension_length - 4) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, SSL_R_BAD_DATA); goto end; } serverinfo = OPENSSL_realloc(serverinfo, serverinfo_length + extension_length); if (serverinfo == NULL) { SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_MALLOC_FAILURE); goto end; } memcpy(serverinfo + serverinfo_length, extension, extension_length); serverinfo_length += extension_length; OPENSSL_free(name); name = NULL; OPENSSL_free(header); header = NULL; OPENSSL_free(extension); extension = NULL; } ret = SSL_CTX_use_serverinfo(ctx, serverinfo, serverinfo_length); end: OPENSSL_free(name); OPENSSL_free(header); OPENSSL_free(extension); OPENSSL_free(serverinfo); BIO_free(bin); return ret; }
['int SSL_CTX_use_serverinfo_file(SSL_CTX *ctx, const char *file)\n{\n unsigned char *serverinfo = NULL;\n size_t serverinfo_length = 0;\n unsigned char *extension = 0;\n long extension_length = 0;\n char *name = NULL;\n char *header = NULL;\n char namePrefix[] = "SERVERINFO FOR ";\n int ret = 0;\n BIO *bin = NULL;\n size_t num_extensions = 0;\n if (ctx == NULL || file == NULL) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE,\n ERR_R_PASSED_NULL_PARAMETER);\n goto end;\n }\n bin = BIO_new(BIO_s_file());\n if (bin == NULL) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_BUF_LIB);\n goto end;\n }\n if (BIO_read_filename(bin, file) <= 0) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_SYS_LIB);\n goto end;\n }\n for (num_extensions = 0;; num_extensions++) {\n if (PEM_read_bio(bin, &name, &header, &extension, &extension_length)\n == 0) {\n if (num_extensions == 0) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE,\n SSL_R_NO_PEM_EXTENSIONS);\n goto end;\n } else\n break;\n }\n if (strlen(name) < strlen(namePrefix)) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE,\n SSL_R_PEM_NAME_TOO_SHORT);\n goto end;\n }\n if (strncmp(name, namePrefix, strlen(namePrefix)) != 0) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE,\n SSL_R_PEM_NAME_BAD_PREFIX);\n goto end;\n }\n if (extension_length < 4\n || (extension[2] << 8) + extension[3] != extension_length - 4) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, SSL_R_BAD_DATA);\n goto end;\n }\n serverinfo =\n OPENSSL_realloc(serverinfo, serverinfo_length + extension_length);\n if (serverinfo == NULL) {\n SSLerr(SSL_F_SSL_CTX_USE_SERVERINFO_FILE, ERR_R_MALLOC_FAILURE);\n goto end;\n }\n memcpy(serverinfo + serverinfo_length, extension, extension_length);\n serverinfo_length += extension_length;\n OPENSSL_free(name);\n name = NULL;\n OPENSSL_free(header);\n header = NULL;\n OPENSSL_free(extension);\n extension = NULL;\n }\n ret = SSL_CTX_use_serverinfo(ctx, serverinfo, serverinfo_length);\n end:\n OPENSSL_free(name);\n OPENSSL_free(header);\n OPENSSL_free(extension);\n OPENSSL_free(serverinfo);\n BIO_free(bin);\n return ret;\n}', 'int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,\n long *len)\n{\n EVP_ENCODE_CTX *ctx = EVP_ENCODE_CTX_new();\n int end = 0, i, k, bl = 0, hl = 0, nohead = 0;\n char buf[256];\n BUF_MEM *nameB;\n BUF_MEM *headerB;\n BUF_MEM *dataB, *tmpB;\n if (ctx == NULL) {\n PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE);\n return (0);\n }\n nameB = BUF_MEM_new();\n headerB = BUF_MEM_new();\n dataB = BUF_MEM_new();\n if ((nameB == NULL) || (headerB == NULL) || (dataB == NULL)) {\n goto err;\n }\n buf[254] = \'\\0\';\n for (;;) {\n i = BIO_gets(bp, buf, 254);\n if (i <= 0) {\n PEMerr(PEM_F_PEM_READ_BIO, PEM_R_NO_START_LINE);\n goto err;\n }\n while ((i >= 0) && (buf[i] <= \' \'))\n i--;\n buf[++i] = \'\\n\';\n buf[++i] = \'\\0\';\n if (strncmp(buf, "-----BEGIN ", 11) == 0) {\n i = strlen(&(buf[11]));\n if (strncmp(&(buf[11 + i - 6]), "-----\\n", 6) != 0)\n continue;\n if (!BUF_MEM_grow(nameB, i + 9)) {\n PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(nameB->data, &(buf[11]), i - 6);\n nameB->data[i - 6] = \'\\0\';\n break;\n }\n }\n hl = 0;\n if (!BUF_MEM_grow(headerB, 256)) {\n PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n headerB->data[0] = \'\\0\';\n for (;;) {\n i = BIO_gets(bp, buf, 254);\n if (i <= 0)\n break;\n while ((i >= 0) && (buf[i] <= \' \'))\n i--;\n buf[++i] = \'\\n\';\n buf[++i] = \'\\0\';\n if (buf[0] == \'\\n\')\n break;\n if (!BUF_MEM_grow(headerB, hl + i + 9)) {\n PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (strncmp(buf, "-----END ", 9) == 0) {\n nohead = 1;\n break;\n }\n memcpy(&(headerB->data[hl]), buf, i);\n headerB->data[hl + i] = \'\\0\';\n hl += i;\n }\n bl = 0;\n if (!BUF_MEM_grow(dataB, 1024)) {\n PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n dataB->data[0] = \'\\0\';\n if (!nohead) {\n for (;;) {\n i = BIO_gets(bp, buf, 254);\n if (i <= 0)\n break;\n while ((i >= 0) && (buf[i] <= \' \'))\n i--;\n buf[++i] = \'\\n\';\n buf[++i] = \'\\0\';\n if (i != 65)\n end = 1;\n if (strncmp(buf, "-----END ", 9) == 0)\n break;\n if (i > 65)\n break;\n if (!BUF_MEM_grow_clean(dataB, i + bl + 9)) {\n PEMerr(PEM_F_PEM_READ_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(&(dataB->data[bl]), buf, i);\n dataB->data[bl + i] = \'\\0\';\n bl += i;\n if (end) {\n buf[0] = \'\\0\';\n i = BIO_gets(bp, buf, 254);\n if (i <= 0)\n break;\n while ((i >= 0) && (buf[i] <= \' \'))\n i--;\n buf[++i] = \'\\n\';\n buf[++i] = \'\\0\';\n break;\n }\n }\n } else {\n tmpB = headerB;\n headerB = dataB;\n dataB = tmpB;\n bl = hl;\n }\n i = strlen(nameB->data);\n if ((strncmp(buf, "-----END ", 9) != 0) ||\n (strncmp(nameB->data, &(buf[9]), i) != 0) ||\n (strncmp(&(buf[9 + i]), "-----\\n", 6) != 0)) {\n PEMerr(PEM_F_PEM_READ_BIO, PEM_R_BAD_END_LINE);\n goto err;\n }\n EVP_DecodeInit(ctx);\n i = EVP_DecodeUpdate(ctx,\n (unsigned char *)dataB->data, &bl,\n (unsigned char *)dataB->data, bl);\n if (i < 0) {\n PEMerr(PEM_F_PEM_READ_BIO, PEM_R_BAD_BASE64_DECODE);\n goto err;\n }\n i = EVP_DecodeFinal(ctx, (unsigned char *)&(dataB->data[bl]), &k);\n if (i < 0) {\n PEMerr(PEM_F_PEM_READ_BIO, PEM_R_BAD_BASE64_DECODE);\n goto err;\n }\n bl += k;\n if (bl == 0)\n goto err;\n *name = nameB->data;\n *header = headerB->data;\n *data = (unsigned char *)dataB->data;\n *len = bl;\n OPENSSL_free(nameB);\n OPENSSL_free(headerB);\n OPENSSL_free(dataB);\n EVP_ENCODE_CTX_free(ctx);\n return (1);\n err:\n BUF_MEM_free(nameB);\n BUF_MEM_free(headerB);\n BUF_MEM_free(dataB);\n EVP_ENCODE_CTX_free(ctx);\n return (0);\n}']
1,565
0
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int test_mod_exp_zero(void)\n{\n BIGNUM *a = NULL, *p = NULL, *m = NULL;\n BIGNUM *r = NULL;\n BN_ULONG one_word = 1;\n BN_CTX *ctx = BN_CTX_new();\n int ret = 1, failed = 0;\n if (!TEST_ptr(m = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(p = BN_new())\n || !TEST_ptr(r = BN_new()))\n goto err;\n BN_one(m);\n BN_one(a);\n BN_zero(p);\n if (!TEST_true(BN_rand(a, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)))\n goto err;\n if (!TEST_true(BN_mod_exp(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_recp(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_recp", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_simple(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_simple", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont(r, a, p, m, ctx, NULL)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL)))\n goto err;\n if (!TEST_BN_eq_zero(r)) {\n TEST_error("BN_mod_exp_mont_word failed: "\n "1 ** 0 mod 1 = r (should be 0)");\n BN_print_var(r);\n goto err;\n }\n ret = !failed;\n err:\n BN_free(r);\n BN_free(a);\n BN_free(p);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_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}']
1,566
0
https://github.com/libav/libav/blob/5150dd532b142d7032854a362228dd40142a8e94/libavcodec/aacenc.c/#L254
static void apply_window_and_mdct(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, short *audio, int channel) { int i, j, k; const float * lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; const float * swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; const float * pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { memcpy(s->output, sce->saved, sizeof(float)*1024); if (sce->ics.window_sequence[0] == LONG_STOP_SEQUENCE) { memset(s->output, 0, sizeof(s->output[0]) * 448); for (i = 448; i < 576; i++) s->output[i] = sce->saved[i] * pwindow[i - 448]; for (i = 576; i < 704; i++) s->output[i] = sce->saved[i]; } if (sce->ics.window_sequence[0] != LONG_START_SEQUENCE) { for (i = 0, j = channel; i < 1024; i++, j += avctx->channels) { s->output[i+1024] = audio[j] * lwindow[1024 - i - 1]; sce->saved[i] = audio[j] * lwindow[i]; } } else { for (i = 0, j = channel; i < 448; i++, j += avctx->channels) s->output[i+1024] = audio[j]; for (; i < 576; i++, j += avctx->channels) s->output[i+1024] = audio[j] * swindow[576 - i - 1]; memset(s->output+1024+576, 0, sizeof(s->output[0]) * 448); for (i = 0, j = channel; i < 1024; i++, j += avctx->channels) sce->saved[i] = audio[j]; } ff_mdct_calc(&s->mdct1024, sce->coeffs, s->output); } else { for (k = 0; k < 1024; k += 128) { for (i = 448 + k; i < 448 + k + 256; i++) s->output[i - 448 - k] = (i < 1024) ? sce->saved[i] : audio[channel + (i-1024)*avctx->channels]; s->dsp.vector_fmul (s->output, k ? swindow : pwindow, 128); s->dsp.vector_fmul_reverse(s->output+128, s->output+128, swindow, 128); ff_mdct_calc(&s->mdct128, sce->coeffs + k, s->output); } for (i = 0, j = channel; i < 1024; i++, j += avctx->channels) sce->saved[i] = audio[j]; } }
['static void apply_window_and_mdct(AVCodecContext *avctx, AACEncContext *s,\n SingleChannelElement *sce, short *audio, int channel)\n{\n int i, j, k;\n const float * lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024;\n const float * swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128;\n const float * pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128;\n if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {\n memcpy(s->output, sce->saved, sizeof(float)*1024);\n if (sce->ics.window_sequence[0] == LONG_STOP_SEQUENCE) {\n memset(s->output, 0, sizeof(s->output[0]) * 448);\n for (i = 448; i < 576; i++)\n s->output[i] = sce->saved[i] * pwindow[i - 448];\n for (i = 576; i < 704; i++)\n s->output[i] = sce->saved[i];\n }\n if (sce->ics.window_sequence[0] != LONG_START_SEQUENCE) {\n for (i = 0, j = channel; i < 1024; i++, j += avctx->channels) {\n s->output[i+1024] = audio[j] * lwindow[1024 - i - 1];\n sce->saved[i] = audio[j] * lwindow[i];\n }\n } else {\n for (i = 0, j = channel; i < 448; i++, j += avctx->channels)\n s->output[i+1024] = audio[j];\n for (; i < 576; i++, j += avctx->channels)\n s->output[i+1024] = audio[j] * swindow[576 - i - 1];\n memset(s->output+1024+576, 0, sizeof(s->output[0]) * 448);\n for (i = 0, j = channel; i < 1024; i++, j += avctx->channels)\n sce->saved[i] = audio[j];\n }\n ff_mdct_calc(&s->mdct1024, sce->coeffs, s->output);\n } else {\n for (k = 0; k < 1024; k += 128) {\n for (i = 448 + k; i < 448 + k + 256; i++)\n s->output[i - 448 - k] = (i < 1024)\n ? sce->saved[i]\n : audio[channel + (i-1024)*avctx->channels];\n s->dsp.vector_fmul (s->output, k ? swindow : pwindow, 128);\n s->dsp.vector_fmul_reverse(s->output+128, s->output+128, swindow, 128);\n ff_mdct_calc(&s->mdct128, sce->coeffs + k, s->output);\n }\n for (i = 0, j = channel; i < 1024; i++, j += avctx->channels)\n sce->saved[i] = audio[j];\n }\n}']
1,567
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/apps/s_server.c/#L2115
static int sv_body(const char *hostname, int s, int stype, unsigned char *context) { char *buf = NULL; fd_set readfds; int ret = 1, width; int k, i; unsigned long l; SSL *con = NULL; BIO *sbio; struct timeval timeout; #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) struct timeval tv; #else struct timeval *timeoutp; #endif buf = app_malloc(bufsize, "server buffer"); #ifdef FIONBIO if (s_nbio) { unsigned long sl = 1; if (!s_quiet) BIO_printf(bio_err, "turning on non blocking io\n"); if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0) ERR_print_errors(bio_err); } #endif if (con == NULL) { con = SSL_new(ctx); if (s_tlsextdebug) { SSL_set_tlsext_debug_callback(con, tlsext_cb); SSL_set_tlsext_debug_arg(con, bio_s_out); } if (context && !SSL_set_session_id_context(con, context, strlen((char *)context))) { BIO_printf(bio_err, "Error setting session id context\n"); ret = -1; goto err; } } if (!SSL_clear(con)) { BIO_printf(bio_err, "Error clearing SSL connection\n"); ret = -1; goto err; } #ifndef OPENSSL_NO_DTLS if (stype == SOCK_DGRAM) { sbio = BIO_new_dgram(s, BIO_NOCLOSE); if (enable_timeouts) { timeout.tv_sec = 0; timeout.tv_usec = DGRAM_RCV_TIMEOUT; BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout); timeout.tv_sec = 0; timeout.tv_usec = DGRAM_SND_TIMEOUT; BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout); } if (socket_mtu) { if (socket_mtu < DTLS_get_link_min_mtu(con)) { BIO_printf(bio_err, "MTU too small. Must be at least %ld\n", DTLS_get_link_min_mtu(con)); ret = -1; BIO_free(sbio); goto err; } SSL_set_options(con, SSL_OP_NO_QUERY_MTU); if (!DTLS_set_link_mtu(con, socket_mtu)) { BIO_printf(bio_err, "Failed to set MTU\n"); ret = -1; BIO_free(sbio); goto err; } } else BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL); SSL_set_options(con, SSL_OP_COOKIE_EXCHANGE); } else #endif sbio = BIO_new_socket(s, BIO_NOCLOSE); if (s_nbio_test) { BIO *test; test = BIO_new(BIO_f_nbio_test()); sbio = BIO_push(test, sbio); } #ifndef OPENSSL_NO_JPAKE if (jpake_secret) jpake_server_auth(bio_s_out, sbio, jpake_secret); #endif SSL_set_bio(con, sbio, sbio); SSL_set_accept_state(con); if (s_debug) { BIO_set_callback(SSL_get_rbio(con), bio_dump_callback); BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out); } if (s_msg) { #ifndef OPENSSL_NO_SSL_TRACE if (s_msg == 2) SSL_set_msg_callback(con, SSL_trace); else #endif SSL_set_msg_callback(con, msg_cb); SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out); } if (s_tlsextdebug) { SSL_set_tlsext_debug_callback(con, tlsext_cb); SSL_set_tlsext_debug_arg(con, bio_s_out); } width = s + 1; for (;;) { int read_from_terminal; int read_from_sslcon; read_from_terminal = 0; read_from_sslcon = SSL_pending(con) || (async && SSL_waiting_for_async(con)); if (!read_from_sslcon) { FD_ZERO(&readfds); #if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE) openssl_fdset(fileno(stdin), &readfds); #endif openssl_fdset(s, &readfds); #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) tv.tv_sec = 1; tv.tv_usec = 0; i = select(width, (void *)&readfds, NULL, NULL, &tv); if ((i < 0) || (!i && !_kbhit())) continue; if (_kbhit()) read_from_terminal = 1; #else if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_get_timeout(con, &timeout)) timeoutp = &timeout; else timeoutp = NULL; i = select(width, (void *)&readfds, NULL, NULL, timeoutp); if ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_handle_timeout(con) > 0) { BIO_printf(bio_err, "TIMEOUT occurred\n"); } if (i <= 0) continue; if (FD_ISSET(fileno(stdin), &readfds)) read_from_terminal = 1; #endif if (FD_ISSET(s, &readfds)) read_from_sslcon = 1; } if (read_from_terminal) { if (s_crlf) { int j, lf_num; i = raw_read_stdin(buf, bufsize / 2); lf_num = 0; for (j = 0; j < i; j++) if (buf[j] == '\n') lf_num++; for (j = i - 1; j >= 0; j--) { buf[j + lf_num] = buf[j]; if (buf[j] == '\n') { lf_num--; i++; buf[j + lf_num] = '\r'; } } assert(lf_num == 0); } else i = raw_read_stdin(buf, bufsize); if (!s_quiet && !s_brief) { if ((i <= 0) || (buf[0] == 'Q')) { BIO_printf(bio_s_out, "DONE\n"); (void)BIO_flush(bio_s_out); SHUTDOWN(s); close_accept_socket(); ret = -11; goto err; } if ((i <= 0) || (buf[0] == 'q')) { BIO_printf(bio_s_out, "DONE\n"); (void)BIO_flush(bio_s_out); if (SSL_version(con) != DTLS1_VERSION) SHUTDOWN(s); goto err; } #ifndef OPENSSL_NO_HEARTBEATS if ((buf[0] == 'B') && ((buf[1] == '\n') || (buf[1] == '\r'))) { BIO_printf(bio_err, "HEARTBEATING\n"); SSL_heartbeat(con); i = 0; continue; } #endif if ((buf[0] == 'r') && ((buf[1] == '\n') || (buf[1] == '\r'))) { SSL_renegotiate(con); i = SSL_do_handshake(con); printf("SSL_do_handshake -> %d\n", i); i = 0; continue; } if ((buf[0] == 'R') && ((buf[1] == '\n') || (buf[1] == '\r'))) { SSL_set_verify(con, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, NULL); SSL_renegotiate(con); i = SSL_do_handshake(con); printf("SSL_do_handshake -> %d\n", i); i = 0; continue; } if (buf[0] == 'P') { static const char *str = "Lets print some clear text\n"; BIO_write(SSL_get_wbio(con), str, strlen(str)); } if (buf[0] == 'S') { print_stats(bio_s_out, SSL_get_SSL_CTX(con)); } } #ifdef CHARSET_EBCDIC ebcdic2ascii(buf, buf, i); #endif l = k = 0; for (;;) { #ifdef RENEG { static count = 0; if (++count == 100) { count = 0; SSL_renegotiate(con); } } #endif k = SSL_write(con, &(buf[l]), (unsigned int)i); #ifndef OPENSSL_NO_SRP while (SSL_get_error(con, k) == SSL_ERROR_WANT_X509_LOOKUP) { BIO_printf(bio_s_out, "LOOKUP renego during write\n"); srp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); if (srp_callback_parm.user) BIO_printf(bio_s_out, "LOOKUP done %s\n", srp_callback_parm.user->info); else BIO_printf(bio_s_out, "LOOKUP not successful\n"); k = SSL_write(con, &(buf[l]), (unsigned int)i); } #endif switch (SSL_get_error(con, k)) { case SSL_ERROR_NONE: break; case SSL_ERROR_WANT_ASYNC: BIO_printf(bio_s_out, "Write BLOCK (Async)\n"); wait_for_async(con); break; case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_READ: case SSL_ERROR_WANT_X509_LOOKUP: BIO_printf(bio_s_out, "Write BLOCK\n"); break; case SSL_ERROR_SYSCALL: case SSL_ERROR_SSL: BIO_printf(bio_s_out, "ERROR\n"); (void)BIO_flush(bio_s_out); ERR_print_errors(bio_err); ret = 1; goto err; case SSL_ERROR_ZERO_RETURN: BIO_printf(bio_s_out, "DONE\n"); (void)BIO_flush(bio_s_out); ret = 1; goto err; } if (k > 0) { l += k; i -= k; } if (i <= 0) break; } } if (read_from_sslcon) { if ((!async || !SSL_waiting_for_async(con)) && !SSL_is_init_finished(con)) { i = init_ssl_connection(con); if (i < 0) { ret = 0; goto err; } else if (i == 0) { ret = 1; goto err; } } else { again: i = SSL_read(con, (char *)buf, bufsize); #ifndef OPENSSL_NO_SRP while (SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP) { BIO_printf(bio_s_out, "LOOKUP renego during read\n"); srp_callback_parm.user = SRP_VBASE_get_by_user(srp_callback_parm.vb, srp_callback_parm.login); if (srp_callback_parm.user) BIO_printf(bio_s_out, "LOOKUP done %s\n", srp_callback_parm.user->info); else BIO_printf(bio_s_out, "LOOKUP not successful\n"); i = SSL_read(con, (char *)buf, bufsize); } #endif switch (SSL_get_error(con, i)) { case SSL_ERROR_NONE: #ifdef CHARSET_EBCDIC ascii2ebcdic(buf, buf, i); #endif raw_write_stdout(buf, (unsigned int)i); if (SSL_pending(con)) goto again; break; case SSL_ERROR_WANT_ASYNC: BIO_printf(bio_s_out, "Read BLOCK (Async)\n"); wait_for_async(con); break; case SSL_ERROR_WANT_WRITE: case SSL_ERROR_WANT_READ: BIO_printf(bio_s_out, "Read BLOCK\n"); break; case SSL_ERROR_SYSCALL: case SSL_ERROR_SSL: BIO_printf(bio_s_out, "ERROR\n"); (void)BIO_flush(bio_s_out); ERR_print_errors(bio_err); ret = 1; goto err; case SSL_ERROR_ZERO_RETURN: BIO_printf(bio_s_out, "DONE\n"); (void)BIO_flush(bio_s_out); ret = 1; goto err; } } } } err: if (con != NULL) { BIO_printf(bio_s_out, "shutting down SSL\n"); SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); SSL_free(con); } BIO_printf(bio_s_out, "CONNECTION CLOSED\n"); OPENSSL_clear_free(buf, bufsize); if (ret >= 0) BIO_printf(bio_s_out, "ACCEPT\n"); (void)BIO_flush(bio_s_out); return (ret); }
['static int sv_body(const char *hostname, int s, int stype,\n unsigned char *context)\n{\n char *buf = NULL;\n fd_set readfds;\n int ret = 1, width;\n int k, i;\n unsigned long l;\n SSL *con = NULL;\n BIO *sbio;\n struct timeval timeout;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n struct timeval tv;\n#else\n struct timeval *timeoutp;\n#endif\n buf = app_malloc(bufsize, "server buffer");\n#ifdef FIONBIO\n if (s_nbio) {\n unsigned long sl = 1;\n if (!s_quiet)\n BIO_printf(bio_err, "turning on non blocking io\\n");\n if (BIO_socket_ioctl(s, FIONBIO, &sl) < 0)\n ERR_print_errors(bio_err);\n }\n#endif\n if (con == NULL) {\n con = SSL_new(ctx);\n if (s_tlsextdebug) {\n SSL_set_tlsext_debug_callback(con, tlsext_cb);\n SSL_set_tlsext_debug_arg(con, bio_s_out);\n }\n if (context\n && !SSL_set_session_id_context(con,\n context, strlen((char *)context))) {\n BIO_printf(bio_err, "Error setting session id context\\n");\n ret = -1;\n goto err;\n }\n }\n if (!SSL_clear(con)) {\n BIO_printf(bio_err, "Error clearing SSL connection\\n");\n ret = -1;\n goto err;\n }\n#ifndef OPENSSL_NO_DTLS\n if (stype == SOCK_DGRAM) {\n sbio = BIO_new_dgram(s, BIO_NOCLOSE);\n if (enable_timeouts) {\n timeout.tv_sec = 0;\n timeout.tv_usec = DGRAM_RCV_TIMEOUT;\n BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n timeout.tv_sec = 0;\n timeout.tv_usec = DGRAM_SND_TIMEOUT;\n BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n }\n if (socket_mtu) {\n if (socket_mtu < DTLS_get_link_min_mtu(con)) {\n BIO_printf(bio_err, "MTU too small. Must be at least %ld\\n",\n DTLS_get_link_min_mtu(con));\n ret = -1;\n BIO_free(sbio);\n goto err;\n }\n SSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n if (!DTLS_set_link_mtu(con, socket_mtu)) {\n BIO_printf(bio_err, "Failed to set MTU\\n");\n ret = -1;\n BIO_free(sbio);\n goto err;\n }\n } else\n BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n SSL_set_options(con, SSL_OP_COOKIE_EXCHANGE);\n } else\n#endif\n sbio = BIO_new_socket(s, BIO_NOCLOSE);\n if (s_nbio_test) {\n BIO *test;\n test = BIO_new(BIO_f_nbio_test());\n sbio = BIO_push(test, sbio);\n }\n#ifndef OPENSSL_NO_JPAKE\n if (jpake_secret)\n jpake_server_auth(bio_s_out, sbio, jpake_secret);\n#endif\n SSL_set_bio(con, sbio, sbio);\n SSL_set_accept_state(con);\n if (s_debug) {\n BIO_set_callback(SSL_get_rbio(con), bio_dump_callback);\n BIO_set_callback_arg(SSL_get_rbio(con), (char *)bio_s_out);\n }\n if (s_msg) {\n#ifndef OPENSSL_NO_SSL_TRACE\n if (s_msg == 2)\n SSL_set_msg_callback(con, SSL_trace);\n else\n#endif\n SSL_set_msg_callback(con, msg_cb);\n SSL_set_msg_callback_arg(con, bio_s_msg ? bio_s_msg : bio_s_out);\n }\n if (s_tlsextdebug) {\n SSL_set_tlsext_debug_callback(con, tlsext_cb);\n SSL_set_tlsext_debug_arg(con, bio_s_out);\n }\n width = s + 1;\n for (;;) {\n int read_from_terminal;\n int read_from_sslcon;\n read_from_terminal = 0;\n read_from_sslcon = SSL_pending(con)\n || (async && SSL_waiting_for_async(con));\n if (!read_from_sslcon) {\n FD_ZERO(&readfds);\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)\n openssl_fdset(fileno(stdin), &readfds);\n#endif\n openssl_fdset(s, &readfds);\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n tv.tv_sec = 1;\n tv.tv_usec = 0;\n i = select(width, (void *)&readfds, NULL, NULL, &tv);\n if ((i < 0) || (!i && !_kbhit()))\n continue;\n if (_kbhit())\n read_from_terminal = 1;\n#else\n if ((SSL_version(con) == DTLS1_VERSION) &&\n DTLSv1_get_timeout(con, &timeout))\n timeoutp = &timeout;\n else\n timeoutp = NULL;\n i = select(width, (void *)&readfds, NULL, NULL, timeoutp);\n if ((SSL_version(con) == DTLS1_VERSION)\n && DTLSv1_handle_timeout(con) > 0) {\n BIO_printf(bio_err, "TIMEOUT occurred\\n");\n }\n if (i <= 0)\n continue;\n if (FD_ISSET(fileno(stdin), &readfds))\n read_from_terminal = 1;\n#endif\n if (FD_ISSET(s, &readfds))\n read_from_sslcon = 1;\n }\n if (read_from_terminal) {\n if (s_crlf) {\n int j, lf_num;\n i = raw_read_stdin(buf, bufsize / 2);\n lf_num = 0;\n for (j = 0; j < i; j++)\n if (buf[j] == \'\\n\')\n lf_num++;\n for (j = i - 1; j >= 0; j--) {\n buf[j + lf_num] = buf[j];\n if (buf[j] == \'\\n\') {\n lf_num--;\n i++;\n buf[j + lf_num] = \'\\r\';\n }\n }\n assert(lf_num == 0);\n } else\n i = raw_read_stdin(buf, bufsize);\n if (!s_quiet && !s_brief) {\n if ((i <= 0) || (buf[0] == \'Q\')) {\n BIO_printf(bio_s_out, "DONE\\n");\n (void)BIO_flush(bio_s_out);\n SHUTDOWN(s);\n close_accept_socket();\n ret = -11;\n goto err;\n }\n if ((i <= 0) || (buf[0] == \'q\')) {\n BIO_printf(bio_s_out, "DONE\\n");\n (void)BIO_flush(bio_s_out);\n if (SSL_version(con) != DTLS1_VERSION)\n SHUTDOWN(s);\n goto err;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if ((buf[0] == \'B\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n BIO_printf(bio_err, "HEARTBEATING\\n");\n SSL_heartbeat(con);\n i = 0;\n continue;\n }\n#endif\n if ((buf[0] == \'r\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n SSL_renegotiate(con);\n i = SSL_do_handshake(con);\n printf("SSL_do_handshake -> %d\\n", i);\n i = 0;\n continue;\n }\n if ((buf[0] == \'R\') && ((buf[1] == \'\\n\') || (buf[1] == \'\\r\'))) {\n SSL_set_verify(con,\n SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE,\n NULL);\n SSL_renegotiate(con);\n i = SSL_do_handshake(con);\n printf("SSL_do_handshake -> %d\\n", i);\n i = 0;\n continue;\n }\n if (buf[0] == \'P\') {\n static const char *str = "Lets print some clear text\\n";\n BIO_write(SSL_get_wbio(con), str, strlen(str));\n }\n if (buf[0] == \'S\') {\n print_stats(bio_s_out, SSL_get_SSL_CTX(con));\n }\n }\n#ifdef CHARSET_EBCDIC\n ebcdic2ascii(buf, buf, i);\n#endif\n l = k = 0;\n for (;;) {\n#ifdef RENEG\n {\n static count = 0;\n if (++count == 100) {\n count = 0;\n SSL_renegotiate(con);\n }\n }\n#endif\n k = SSL_write(con, &(buf[l]), (unsigned int)i);\n#ifndef OPENSSL_NO_SRP\n while (SSL_get_error(con, k) == SSL_ERROR_WANT_X509_LOOKUP) {\n BIO_printf(bio_s_out, "LOOKUP renego during write\\n");\n srp_callback_parm.user =\n SRP_VBASE_get_by_user(srp_callback_parm.vb,\n srp_callback_parm.login);\n if (srp_callback_parm.user)\n BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n srp_callback_parm.user->info);\n else\n BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n k = SSL_write(con, &(buf[l]), (unsigned int)i);\n }\n#endif\n switch (SSL_get_error(con, k)) {\n case SSL_ERROR_NONE:\n break;\n case SSL_ERROR_WANT_ASYNC:\n BIO_printf(bio_s_out, "Write BLOCK (Async)\\n");\n wait_for_async(con);\n break;\n case SSL_ERROR_WANT_WRITE:\n case SSL_ERROR_WANT_READ:\n case SSL_ERROR_WANT_X509_LOOKUP:\n BIO_printf(bio_s_out, "Write BLOCK\\n");\n break;\n case SSL_ERROR_SYSCALL:\n case SSL_ERROR_SSL:\n BIO_printf(bio_s_out, "ERROR\\n");\n (void)BIO_flush(bio_s_out);\n ERR_print_errors(bio_err);\n ret = 1;\n goto err;\n case SSL_ERROR_ZERO_RETURN:\n BIO_printf(bio_s_out, "DONE\\n");\n (void)BIO_flush(bio_s_out);\n ret = 1;\n goto err;\n }\n if (k > 0) {\n l += k;\n i -= k;\n }\n if (i <= 0)\n break;\n }\n }\n if (read_from_sslcon) {\n if ((!async || !SSL_waiting_for_async(con))\n && !SSL_is_init_finished(con)) {\n i = init_ssl_connection(con);\n if (i < 0) {\n ret = 0;\n goto err;\n } else if (i == 0) {\n ret = 1;\n goto err;\n }\n } else {\n again:\n i = SSL_read(con, (char *)buf, bufsize);\n#ifndef OPENSSL_NO_SRP\n while (SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP) {\n BIO_printf(bio_s_out, "LOOKUP renego during read\\n");\n srp_callback_parm.user =\n SRP_VBASE_get_by_user(srp_callback_parm.vb,\n srp_callback_parm.login);\n if (srp_callback_parm.user)\n BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n srp_callback_parm.user->info);\n else\n BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n i = SSL_read(con, (char *)buf, bufsize);\n }\n#endif\n switch (SSL_get_error(con, i)) {\n case SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n ascii2ebcdic(buf, buf, i);\n#endif\n raw_write_stdout(buf, (unsigned int)i);\n if (SSL_pending(con))\n goto again;\n break;\n case SSL_ERROR_WANT_ASYNC:\n BIO_printf(bio_s_out, "Read BLOCK (Async)\\n");\n wait_for_async(con);\n break;\n case SSL_ERROR_WANT_WRITE:\n case SSL_ERROR_WANT_READ:\n BIO_printf(bio_s_out, "Read BLOCK\\n");\n break;\n case SSL_ERROR_SYSCALL:\n case SSL_ERROR_SSL:\n BIO_printf(bio_s_out, "ERROR\\n");\n (void)BIO_flush(bio_s_out);\n ERR_print_errors(bio_err);\n ret = 1;\n goto err;\n case SSL_ERROR_ZERO_RETURN:\n BIO_printf(bio_s_out, "DONE\\n");\n (void)BIO_flush(bio_s_out);\n ret = 1;\n goto err;\n }\n }\n }\n }\n err:\n if (con != NULL) {\n BIO_printf(bio_s_out, "shutting down SSL\\n");\n SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n SSL_free(con);\n }\n BIO_printf(bio_s_out, "CONNECTION CLOSED\\n");\n OPENSSL_clear_free(buf, bufsize);\n if (ret >= 0)\n BIO_printf(bio_s_out, "ACCEPT\\n");\n (void)BIO_flush(bio_s_out);\n return (ret);\n}', 'void* app_malloc(int sz, const char *what)\n{\n void *vp = OPENSSL_malloc(sz);\n if (vp == NULL) {\n BIO_printf(bio_err, "%s: Could not allocate %d bytes for %s\\n",\n opt_getprog(), sz, what);\n ERR_print_errors(bio_err);\n exit(1);\n }\n return vp;\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}', '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 RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\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 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n s->ctx = ctx;\n s->tlsext_debug_cb = 0;\n s->tlsext_debug_arg = NULL;\n s->tlsext_ticket_expected = 0;\n s->tlsext_status_type = -1;\n s->tlsext_status_expected = 0;\n s->tlsext_ocsp_ids = NULL;\n s->tlsext_ocsp_exts = NULL;\n s->tlsext_ocsp_resp = NULL;\n s->tlsext_ocsp_resplen = -1;\n CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n if (ctx->tlsext_ecpointformatlist) {\n s->tlsext_ecpointformatlist =\n OPENSSL_memdup(ctx->tlsext_ecpointformatlist,\n ctx->tlsext_ecpointformatlist_length);\n if (!s->tlsext_ecpointformatlist)\n goto err;\n s->tlsext_ecpointformatlist_length =\n ctx->tlsext_ecpointformatlist_length;\n }\n if (ctx->tlsext_ellipticcurvelist) {\n s->tlsext_ellipticcurvelist =\n OPENSSL_memdup(ctx->tlsext_ellipticcurvelist,\n ctx->tlsext_ellipticcurvelist_length);\n if (!s->tlsext_ellipticcurvelist)\n goto err;\n s->tlsext_ellipticcurvelist_length =\n ctx->tlsext_ellipticcurvelist_length;\n }\n# endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n s->next_proto_negotiated = NULL;\n# endif\n if (s->ctx->alpn_client_proto_list) {\n s->alpn_client_proto_list =\n OPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n if (s->alpn_client_proto_list == NULL)\n goto err;\n memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n s->ctx->alpn_client_proto_list_len);\n s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n }\n 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 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->job = NULL;\n return (s);\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\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 SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL);\n#ifdef REF_PRINT\n REF_PRINT("SSL", s);\n#endif\n if (i > 0)\n return;\n#ifdef REF_CHECK\n if (i < 0) {\n fprintf(stderr, "SSL_free, bad reference count\\n");\n abort();\n }\n#endif\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n if (s->bbio != NULL) {\n if (s->bbio == s->wbio) {\n s->wbio = BIO_pop(s->wbio);\n }\n BIO_free(s->bbio);\n s->bbio = NULL;\n }\n BIO_free_all(s->rbio);\n if (s->wbio != s->rbio)\n BIO_free_all(s->wbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->tlsext_hostname);\n SSL_CTX_free(s->initial_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->tlsext_ecpointformatlist);\n OPENSSL_free(s->tlsext_ellipticcurvelist);\n#endif\n sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, X509_EXTENSION_free);\n sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n OPENSSL_free(s->tlsext_ocsp_resp);\n OPENSSL_free(s->alpn_client_proto_list);\n sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->next_proto_negotiated);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n OPENSSL_free(s);\n}', 'long SSL_callback_ctrl(SSL *s, int cmd, void (*fp) (void))\n{\n switch (cmd) {\n case SSL_CTRL_SET_MSG_CALLBACK:\n s->msg_callback = (void (*)\n (int write_p, int version, int content_type,\n const void *buf, size_t len, SSL *ssl,\n void *arg))(fp);\n return 1;\n default:\n return (s->method->ssl_callback_ctrl(s, cmd, fp));\n }\n}']
1,568
0
https://github.com/libav/libav/blob/97ae370078e5ee8e78269fe4d7b4f457e82bd758/libavformat/rtpdec_h264.c/#L193
static int h264_handle_packet(AVFormatContext *ctx, PayloadContext *data, AVStream *st, AVPacket * pkt, uint32_t * timestamp, const uint8_t * buf, int len, int flags) { uint8_t nal = buf[0]; uint8_t type = (nal & 0x1f); int result= 0; uint8_t start_sequence[] = { 0, 0, 0, 1 }; #ifdef DEBUG assert(data); assert(data->cookie == MAGIC_COOKIE); #endif assert(buf); if (type >= 1 && type <= 23) type = 1; switch (type) { case 0: case 1: av_new_packet(pkt, len+sizeof(start_sequence)); memcpy(pkt->data, start_sequence, sizeof(start_sequence)); memcpy(pkt->data+sizeof(start_sequence), buf, len); #ifdef DEBUG data->packet_types_received[nal & 0x1f]++; #endif break; case 24: buf++; len--; { int pass= 0; int total_length= 0; uint8_t *dst= NULL; for(pass= 0; pass<2; pass++) { const uint8_t *src= buf; int src_len= len; do { uint16_t nal_size = AV_RB16(src); src += 2; src_len -= 2; if (nal_size <= src_len) { if(pass==0) { total_length+= sizeof(start_sequence)+nal_size; } else { assert(dst); memcpy(dst, start_sequence, sizeof(start_sequence)); dst+= sizeof(start_sequence); memcpy(dst, src, nal_size); #ifdef DEBUG data->packet_types_received[*src & 0x1f]++; #endif dst+= nal_size; } } else { av_log(ctx, AV_LOG_ERROR, "nal size exceeds length: %d %d\n", nal_size, src_len); } src += nal_size; src_len -= nal_size; if (src_len < 0) av_log(ctx, AV_LOG_ERROR, "Consumed more bytes than we got! (%d)\n", src_len); } while (src_len > 2); if(pass==0) { av_new_packet(pkt, total_length); dst= pkt->data; } else { assert(dst-pkt->data==total_length); } } } break; case 25: case 26: case 27: case 29: av_log(ctx, AV_LOG_ERROR, "Unhandled type (%d) (See RFC for implementation details\n", type); result= -1; break; case 28: buf++; len--; { uint8_t fu_indicator = nal; uint8_t fu_header = *buf; uint8_t start_bit = fu_header >> 7; uint8_t nal_type = (fu_header & 0x1f); uint8_t reconstructed_nal; reconstructed_nal = fu_indicator & (0xe0); reconstructed_nal |= nal_type; buf++; len--; #ifdef DEBUG if (start_bit) data->packet_types_received[nal_type]++; #endif if(start_bit) { av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len); memcpy(pkt->data, start_sequence, sizeof(start_sequence)); pkt->data[sizeof(start_sequence)]= reconstructed_nal; memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len); } else { av_new_packet(pkt, len); memcpy(pkt->data, buf, len); } } break; case 30: case 31: default: av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type); result= -1; break; } pkt->stream_index = st->index; return result; }
['static int h264_handle_packet(AVFormatContext *ctx,\n PayloadContext *data,\n AVStream *st,\n AVPacket * pkt,\n uint32_t * timestamp,\n const uint8_t * buf,\n int len, int flags)\n{\n uint8_t nal = buf[0];\n uint8_t type = (nal & 0x1f);\n int result= 0;\n uint8_t start_sequence[] = { 0, 0, 0, 1 };\n#ifdef DEBUG\n assert(data);\n assert(data->cookie == MAGIC_COOKIE);\n#endif\n assert(buf);\n if (type >= 1 && type <= 23)\n type = 1;\n switch (type) {\n case 0:\n case 1:\n av_new_packet(pkt, len+sizeof(start_sequence));\n memcpy(pkt->data, start_sequence, sizeof(start_sequence));\n memcpy(pkt->data+sizeof(start_sequence), buf, len);\n#ifdef DEBUG\n data->packet_types_received[nal & 0x1f]++;\n#endif\n break;\n case 24:\n buf++;\n len--;\n {\n int pass= 0;\n int total_length= 0;\n uint8_t *dst= NULL;\n for(pass= 0; pass<2; pass++) {\n const uint8_t *src= buf;\n int src_len= len;\n do {\n uint16_t nal_size = AV_RB16(src);\n src += 2;\n src_len -= 2;\n if (nal_size <= src_len) {\n if(pass==0) {\n total_length+= sizeof(start_sequence)+nal_size;\n } else {\n assert(dst);\n memcpy(dst, start_sequence, sizeof(start_sequence));\n dst+= sizeof(start_sequence);\n memcpy(dst, src, nal_size);\n#ifdef DEBUG\n data->packet_types_received[*src & 0x1f]++;\n#endif\n dst+= nal_size;\n }\n } else {\n av_log(ctx, AV_LOG_ERROR,\n "nal size exceeds length: %d %d\\n", nal_size, src_len);\n }\n src += nal_size;\n src_len -= nal_size;\n if (src_len < 0)\n av_log(ctx, AV_LOG_ERROR,\n "Consumed more bytes than we got! (%d)\\n", src_len);\n } while (src_len > 2);\n if(pass==0) {\n av_new_packet(pkt, total_length);\n dst= pkt->data;\n } else {\n assert(dst-pkt->data==total_length);\n }\n }\n }\n break;\n case 25:\n case 26:\n case 27:\n case 29:\n av_log(ctx, AV_LOG_ERROR,\n "Unhandled type (%d) (See RFC for implementation details\\n",\n type);\n result= -1;\n break;\n case 28:\n buf++;\n len--;\n {\n uint8_t fu_indicator = nal;\n uint8_t fu_header = *buf;\n uint8_t start_bit = fu_header >> 7;\n uint8_t nal_type = (fu_header & 0x1f);\n uint8_t reconstructed_nal;\n reconstructed_nal = fu_indicator & (0xe0);\n reconstructed_nal |= nal_type;\n buf++;\n len--;\n#ifdef DEBUG\n if (start_bit)\n data->packet_types_received[nal_type]++;\n#endif\n if(start_bit) {\n av_new_packet(pkt, sizeof(start_sequence)+sizeof(nal)+len);\n memcpy(pkt->data, start_sequence, sizeof(start_sequence));\n pkt->data[sizeof(start_sequence)]= reconstructed_nal;\n memcpy(pkt->data+sizeof(start_sequence)+sizeof(nal), buf, len);\n } else {\n av_new_packet(pkt, len);\n memcpy(pkt->data, buf, len);\n }\n }\n break;\n case 30:\n case 31:\n default:\n av_log(ctx, AV_LOG_ERROR, "Undefined type (%d)", type);\n result= -1;\n break;\n }\n pkt->stream_index = st->index;\n return result;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n uint8_t *data = NULL;\n if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (data) {\n memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n } else\n size = 0;\n av_init_packet(pkt);\n pkt->data = data;\n pkt->size = size;\n pkt->destruct = av_destruct_packet;\n if (!data)\n return AVERROR(ENOMEM);\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n assert(size);\n if (size > (INT_MAX-32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void av_init_packet(AVPacket *pkt)\n{\n pkt->pts = AV_NOPTS_VALUE;\n pkt->dts = AV_NOPTS_VALUE;\n pkt->pos = -1;\n pkt->duration = 0;\n pkt->convergence_duration = 0;\n pkt->flags = 0;\n pkt->stream_index = 0;\n pkt->destruct = NULL;\n pkt->side_data = NULL;\n pkt->side_data_elems = 0;\n}']
1,569
0
https://github.com/openssl/openssl/blob/249a77f5fb6407185e0a6ad44cd88eda2b6f8946/crypto/lhash/lhash.c/#L240
void *lh_delete(_LHASH *lh, const void *data) { unsigned long hash; LHASH_NODE *nn,**rn; void *ret; lh->error=0; rn=getrn(lh,data,&hash); if (*rn == NULL) { lh->num_no_delete++; return(NULL); } else { nn= *rn; *rn=nn->next; ret=nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) contract(lh); return(ret); }
['static APP_INFO *pop_info(void)\n\t{\n\tAPP_INFO tmp;\n\tAPP_INFO *ret = NULL;\n\tif (amih != NULL)\n\t\t{\n\t\tCRYPTO_THREADID_current(&tmp.threadid);\n\t\tif ((ret=lh_APP_INFO_delete(amih,&tmp)) != NULL)\n\t\t\t{\n\t\t\tAPP_INFO *next=ret->next;\n\t\t\tif (next != NULL)\n\t\t\t\t{\n\t\t\t\tnext->references++;\n\t\t\t\t(void)lh_APP_INFO_insert(amih,next);\n\t\t\t\t}\n#ifdef LEVITTE_DEBUG_MEM\n\t\t\tif (CRYPTO_THREADID_cmp(&ret->threadid, &tmp.threadid))\n\t\t\t\t{\n\t\t\t\tfprintf(stderr, "pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\\n",\n\t\t\t\t\tCRYPTO_THREADID_hash(&ret->threadid),\n\t\t\t\t\tCRYPTO_THREADID_hash(&tmp.threadid));\n\t\t\t\tabort();\n\t\t\t\t}\n#endif\n\t\t\tif (--(ret->references) <= 0)\n\t\t\t\t{\n\t\t\t\tret->next = NULL;\n\t\t\t\tif (next != NULL)\n\t\t\t\t\tnext->references--;\n\t\t\t\tOPENSSL_free(ret);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}', 'void *lh_delete(_LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
1,570
0
https://github.com/libav/libav/blob/5634f30c4a25c17c1de26703948efeafb733413d/libavcodec/ps.c/#L956
static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34) { int e, b, k, n; float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11; float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12; float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21; float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22; int8_t *opd_hist = ps->opd_hist; int8_t *ipd_hist = ps->ipd_hist; int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf; int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf; int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf; int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf; const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB; memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0])); memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0])); memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0])); memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0])); memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0])); memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0])); memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0])); memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0])); if (is34) { remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); if (ps->enable_ipdopd) { remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); } if (!ps->is34bands_old) { map_val_20_to_34(H11[0][0]); map_val_20_to_34(H11[1][0]); map_val_20_to_34(H12[0][0]); map_val_20_to_34(H12[1][0]); map_val_20_to_34(H21[0][0]); map_val_20_to_34(H21[1][0]); map_val_20_to_34(H22[0][0]); map_val_20_to_34(H22[1][0]); ipdopd_reset(ipd_hist, opd_hist); } } else { remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); if (ps->enable_ipdopd) { remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0); remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0); } if (ps->is34bands_old) { map_val_34_to_20(H11[0][0]); map_val_34_to_20(H11[1][0]); map_val_34_to_20(H12[0][0]); map_val_34_to_20(H12[1][0]); map_val_34_to_20(H21[0][0]); map_val_34_to_20(H21[1][0]); map_val_34_to_20(H22[0][0]); map_val_34_to_20(H22[1][0]); ipdopd_reset(ipd_hist, opd_hist); } } for (e = 0; e < ps->num_env; e++) { for (b = 0; b < NR_PAR_BANDS[is34]; b++) { float h11, h12, h21, h22; h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0]; h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1]; h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2]; h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3]; if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) { float h11i, h12i, h21i, h22i; float ipd_adj_re, ipd_adj_im; int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b]; int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b]; float opd_re = pd_re_smooth[opd_idx]; float opd_im = pd_im_smooth[opd_idx]; float ipd_re = pd_re_smooth[ipd_idx]; float ipd_im = pd_im_smooth[ipd_idx]; opd_hist[b] = opd_idx & 0x3F; ipd_hist[b] = ipd_idx & 0x3F; ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im; ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im; h11i = h11 * opd_im; h11 = h11 * opd_re; h12i = h12 * ipd_adj_im; h12 = h12 * ipd_adj_re; h21i = h21 * opd_im; h21 = h21 * opd_re; h22i = h22 * ipd_adj_im; h22 = h22 * ipd_adj_re; H11[1][e+1][b] = h11i; H12[1][e+1][b] = h12i; H21[1][e+1][b] = h21i; H22[1][e+1][b] = h22i; } H11[0][e+1][b] = h11; H12[0][e+1][b] = h12; H21[0][e+1][b] = h21; H22[0][e+1][b] = h22; } for (k = 0; k < NR_BANDS[is34]; k++) { float h11r, h12r, h21r, h22r; float h11i, h12i, h21i, h22i; float h11r_step, h12r_step, h21r_step, h22r_step; float h11i_step, h12i_step, h21i_step, h22i_step; int start = ps->border_position[e]; int stop = ps->border_position[e+1]; float width = 1.f / (stop - start); b = k_to_i[k]; h11r = H11[0][e][b]; h12r = H12[0][e][b]; h21r = H21[0][e][b]; h22r = H22[0][e][b]; if (!PS_BASELINE && ps->enable_ipdopd) { if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) { h11i = -H11[1][e][b]; h12i = -H12[1][e][b]; h21i = -H21[1][e][b]; h22i = -H22[1][e][b]; } else { h11i = H11[1][e][b]; h12i = H12[1][e][b]; h21i = H21[1][e][b]; h22i = H22[1][e][b]; } } h11r_step = (H11[0][e+1][b] - h11r) * width; h12r_step = (H12[0][e+1][b] - h12r) * width; h21r_step = (H21[0][e+1][b] - h21r) * width; h22r_step = (H22[0][e+1][b] - h22r) * width; if (!PS_BASELINE && ps->enable_ipdopd) { h11i_step = (H11[1][e+1][b] - h11i) * width; h12i_step = (H12[1][e+1][b] - h12i) * width; h21i_step = (H21[1][e+1][b] - h21i) * width; h22i_step = (H22[1][e+1][b] - h22i) * width; } for (n = start + 1; n <= stop; n++) { float l_re = l[k][n][0]; float l_im = l[k][n][1]; float r_re = r[k][n][0]; float r_im = r[k][n][1]; h11r += h11r_step; h12r += h12r_step; h21r += h21r_step; h22r += h22r_step; if (!PS_BASELINE && ps->enable_ipdopd) { h11i += h11i_step; h12i += h12i_step; h21i += h21i_step; h22i += h22i_step; l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im; l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re; r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im; r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re; } else { l[k][n][0] = h11r*l_re + h21r*r_re; l[k][n][1] = h11r*l_im + h21r*r_im; r[k][n][0] = h12r*l_re + h22r*r_re; r[k][n][1] = h12r*l_im + h22r*r_im; } } } } }
['static void stereo_processing(PSContext *ps, float (*l)[32][2], float (*r)[32][2], int is34)\n{\n int e, b, k, n;\n float (*H11)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H11;\n float (*H12)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H12;\n float (*H21)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H21;\n float (*H22)[PS_MAX_NUM_ENV+1][PS_MAX_NR_IIDICC] = ps->H22;\n int8_t *opd_hist = ps->opd_hist;\n int8_t *ipd_hist = ps->ipd_hist;\n int8_t iid_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t icc_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t ipd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t opd_mapped_buf[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC];\n int8_t (*iid_mapped)[PS_MAX_NR_IIDICC] = iid_mapped_buf;\n int8_t (*icc_mapped)[PS_MAX_NR_IIDICC] = icc_mapped_buf;\n int8_t (*ipd_mapped)[PS_MAX_NR_IIDICC] = ipd_mapped_buf;\n int8_t (*opd_mapped)[PS_MAX_NR_IIDICC] = opd_mapped_buf;\n const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;\n const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB;\n memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0]));\n memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0]));\n memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0]));\n memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0]));\n memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0]));\n memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0]));\n memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0]));\n memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0]));\n if (is34) {\n remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);\n remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);\n if (ps->enable_ipdopd) {\n remap34(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n remap34(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n }\n if (!ps->is34bands_old) {\n map_val_20_to_34(H11[0][0]);\n map_val_20_to_34(H11[1][0]);\n map_val_20_to_34(H12[0][0]);\n map_val_20_to_34(H12[1][0]);\n map_val_20_to_34(H21[0][0]);\n map_val_20_to_34(H21[1][0]);\n map_val_20_to_34(H22[0][0]);\n map_val_20_to_34(H22[1][0]);\n ipdopd_reset(ipd_hist, opd_hist);\n }\n } else {\n remap20(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1);\n remap20(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1);\n if (ps->enable_ipdopd) {\n remap20(&ipd_mapped, ps->ipd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n remap20(&opd_mapped, ps->opd_par, ps->nr_ipdopd_par, ps->num_env, 0);\n }\n if (ps->is34bands_old) {\n map_val_34_to_20(H11[0][0]);\n map_val_34_to_20(H11[1][0]);\n map_val_34_to_20(H12[0][0]);\n map_val_34_to_20(H12[1][0]);\n map_val_34_to_20(H21[0][0]);\n map_val_34_to_20(H21[1][0]);\n map_val_34_to_20(H22[0][0]);\n map_val_34_to_20(H22[1][0]);\n ipdopd_reset(ipd_hist, opd_hist);\n }\n }\n for (e = 0; e < ps->num_env; e++) {\n for (b = 0; b < NR_PAR_BANDS[is34]; b++) {\n float h11, h12, h21, h22;\n h11 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][0];\n h12 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][1];\n h21 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][2];\n h22 = H_LUT[iid_mapped[e][b] + 7 + 23 * ps->iid_quant][icc_mapped[e][b]][3];\n if (!PS_BASELINE && ps->enable_ipdopd && b < ps->nr_ipdopd_par) {\n float h11i, h12i, h21i, h22i;\n float ipd_adj_re, ipd_adj_im;\n int opd_idx = opd_hist[b] * 8 + opd_mapped[e][b];\n int ipd_idx = ipd_hist[b] * 8 + ipd_mapped[e][b];\n float opd_re = pd_re_smooth[opd_idx];\n float opd_im = pd_im_smooth[opd_idx];\n float ipd_re = pd_re_smooth[ipd_idx];\n float ipd_im = pd_im_smooth[ipd_idx];\n opd_hist[b] = opd_idx & 0x3F;\n ipd_hist[b] = ipd_idx & 0x3F;\n ipd_adj_re = opd_re*ipd_re + opd_im*ipd_im;\n ipd_adj_im = opd_im*ipd_re - opd_re*ipd_im;\n h11i = h11 * opd_im;\n h11 = h11 * opd_re;\n h12i = h12 * ipd_adj_im;\n h12 = h12 * ipd_adj_re;\n h21i = h21 * opd_im;\n h21 = h21 * opd_re;\n h22i = h22 * ipd_adj_im;\n h22 = h22 * ipd_adj_re;\n H11[1][e+1][b] = h11i;\n H12[1][e+1][b] = h12i;\n H21[1][e+1][b] = h21i;\n H22[1][e+1][b] = h22i;\n }\n H11[0][e+1][b] = h11;\n H12[0][e+1][b] = h12;\n H21[0][e+1][b] = h21;\n H22[0][e+1][b] = h22;\n }\n for (k = 0; k < NR_BANDS[is34]; k++) {\n float h11r, h12r, h21r, h22r;\n float h11i, h12i, h21i, h22i;\n float h11r_step, h12r_step, h21r_step, h22r_step;\n float h11i_step, h12i_step, h21i_step, h22i_step;\n int start = ps->border_position[e];\n int stop = ps->border_position[e+1];\n float width = 1.f / (stop - start);\n b = k_to_i[k];\n h11r = H11[0][e][b];\n h12r = H12[0][e][b];\n h21r = H21[0][e][b];\n h22r = H22[0][e][b];\n if (!PS_BASELINE && ps->enable_ipdopd) {\n if ((is34 && k <= 13 && k >= 9) || (!is34 && k <= 1)) {\n h11i = -H11[1][e][b];\n h12i = -H12[1][e][b];\n h21i = -H21[1][e][b];\n h22i = -H22[1][e][b];\n } else {\n h11i = H11[1][e][b];\n h12i = H12[1][e][b];\n h21i = H21[1][e][b];\n h22i = H22[1][e][b];\n }\n }\n h11r_step = (H11[0][e+1][b] - h11r) * width;\n h12r_step = (H12[0][e+1][b] - h12r) * width;\n h21r_step = (H21[0][e+1][b] - h21r) * width;\n h22r_step = (H22[0][e+1][b] - h22r) * width;\n if (!PS_BASELINE && ps->enable_ipdopd) {\n h11i_step = (H11[1][e+1][b] - h11i) * width;\n h12i_step = (H12[1][e+1][b] - h12i) * width;\n h21i_step = (H21[1][e+1][b] - h21i) * width;\n h22i_step = (H22[1][e+1][b] - h22i) * width;\n }\n for (n = start + 1; n <= stop; n++) {\n float l_re = l[k][n][0];\n float l_im = l[k][n][1];\n float r_re = r[k][n][0];\n float r_im = r[k][n][1];\n h11r += h11r_step;\n h12r += h12r_step;\n h21r += h21r_step;\n h22r += h22r_step;\n if (!PS_BASELINE && ps->enable_ipdopd) {\n h11i += h11i_step;\n h12i += h12i_step;\n h21i += h21i_step;\n h22i += h22i_step;\n l[k][n][0] = h11r*l_re + h21r*r_re - h11i*l_im - h21i*r_im;\n l[k][n][1] = h11r*l_im + h21r*r_im + h11i*l_re + h21i*r_re;\n r[k][n][0] = h12r*l_re + h22r*r_re - h12i*l_im - h22i*r_im;\n r[k][n][1] = h12r*l_im + h22r*r_im + h12i*l_re + h22i*r_re;\n } else {\n l[k][n][0] = h11r*l_re + h21r*r_re;\n l[k][n][1] = h11r*l_im + h21r*r_im;\n r[k][n][0] = h12r*l_re + h22r*r_re;\n r[k][n][1] = h12r*l_im + h22r*r_im;\n }\n }\n }\n }\n}']
1,571
0
https://github.com/libav/libav/blob/2f99117f6ff24ce5be2abb9e014cb8b86c2aa0e0/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 seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size)\n{\n const unsigned char *data_end = data + data_size;\n BitstreamContext bc;\n int flags, i, j, x, y, op;\n unsigned char c[3];\n unsigned char *dst;\n uint32_t *palette;\n flags = *data++;\n if (flags & 1) {\n palette = (uint32_t *)seq->frame->data[1];\n if (data_end - data < 256 * 3)\n return AVERROR_INVALIDDATA;\n for (i = 0; i < 256; i++) {\n for (j = 0; j < 3; j++, data++)\n c[j] = (*data << 2) | (*data >> 4);\n palette[i] = AV_RB24(c);\n }\n seq->frame->palette_has_changed = 1;\n }\n if (flags & 2) {\n if (data_end - data < 128)\n return AVERROR_INVALIDDATA;\n bitstream_init(&bc, data, 128 * 8);\n data += 128;\n for (y = 0; y < 128; y += 8)\n for (x = 0; x < 256; x += 8) {\n dst = &seq->frame->data[0][y * seq->frame->linesize[0] + x];\n op = bitstream_read(&bc, 2);\n switch (op) {\n case 1:\n data = seq_decode_op1(seq, data, data_end, dst);\n break;\n case 2:\n data = seq_decode_op2(seq, data, data_end, dst);\n break;\n case 3:\n data = seq_decode_op3(seq, data, data_end, dst);\n break;\n }\n if (!data)\n return AVERROR_INVALIDDATA;\n }\n }\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
1,572
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/modes/ccm128.c/#L477
size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len) { unsigned int M = (ctx->nonce.c[0] >> 3) & 7; M *= 2; M += 2; if (len < M) return 0; memcpy(tag, ctx->cmac.c, M); return M; }
['static int aes_ccm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,\n const unsigned char *in, size_t len)\n{\n EVP_AES_CCM_CTX *cctx = ctx->cipher_data;\n CCM128_CONTEXT *ccm = &cctx->ccm;\n if (!cctx->iv_set && !cctx->key_set)\n return -1;\n if (!ctx->encrypt && !cctx->tag_set)\n return -1;\n if (!out) {\n if (!in) {\n if (CRYPTO_ccm128_setiv(ccm, ctx->iv, 15 - cctx->L, len))\n return -1;\n cctx->len_set = 1;\n return len;\n }\n if (!cctx->len_set && len)\n return -1;\n CRYPTO_ccm128_aad(ccm, in, len);\n return len;\n }\n if (!in)\n return 0;\n if (!cctx->len_set) {\n if (CRYPTO_ccm128_setiv(ccm, ctx->iv, 15 - cctx->L, len))\n return -1;\n cctx->len_set = 1;\n }\n if (ctx->encrypt) {\n if (cctx->str ? CRYPTO_ccm128_encrypt_ccm64(ccm, in, out, len,\n cctx->str) :\n CRYPTO_ccm128_encrypt(ccm, in, out, len))\n return -1;\n cctx->tag_set = 1;\n return len;\n } else {\n int rv = -1;\n if (cctx->str ? !CRYPTO_ccm128_decrypt_ccm64(ccm, in, out, len,\n cctx->str) :\n !CRYPTO_ccm128_decrypt(ccm, in, out, len)) {\n unsigned char tag[16];\n if (CRYPTO_ccm128_tag(ccm, tag, cctx->M)) {\n if (!CRYPTO_memcmp(tag, ctx->buf, cctx->M))\n rv = len;\n }\n }\n if (rv == -1)\n OPENSSL_cleanse(out, len);\n cctx->iv_set = 0;\n cctx->tag_set = 0;\n cctx->len_set = 0;\n return rv;\n }\n}', 'size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len)\n{\n unsigned int M = (ctx->nonce.c[0] >> 3) & 7;\n M *= 2;\n M += 2;\n if (len < M)\n return 0;\n memcpy(tag, ctx->cmac.c, M);\n return M;\n}']
1,573
0
https://github.com/libav/libav/blob/18b59956e0e94017f1b519bb42c7c937b2f9f8a4/libavformat/assdec.c/#L159
static int read_packet(AVFormatContext *s, AVPacket *pkt) { ASSContext *ass = s->priv_data; uint8_t *p, *end; if(ass->event_index >= ass->event_count) return AVERROR(EIO); p= ass->event[ ass->event_index ]; end= strchr(p, '\n'); av_new_packet(pkt, end ? end-p+1 : strlen(p)); pkt->flags |= AV_PKT_FLAG_KEY; pkt->pos= p - ass->event_buffer + s->streams[0]->codec->extradata_size; pkt->pts= pkt->dts= get_pts(p); memcpy(pkt->data, p, pkt->size); ass->event_index++; return 0; }
["static int read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n ASSContext *ass = s->priv_data;\n uint8_t *p, *end;\n if(ass->event_index >= ass->event_count)\n return AVERROR(EIO);\n p= ass->event[ ass->event_index ];\n end= strchr(p, '\\n');\n av_new_packet(pkt, end ? end-p+1 : strlen(p));\n pkt->flags |= AV_PKT_FLAG_KEY;\n pkt->pos= p - ass->event_buffer + s->streams[0]->codec->extradata_size;\n pkt->pts= pkt->dts= get_pts(p);\n memcpy(pkt->data, p, pkt->size);\n ass->event_index++;\n return 0;\n}", 'int av_new_packet(AVPacket *pkt, int size)\n{\n uint8_t *data= NULL;\n if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (data){\n memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n }else\n size=0;\n av_init_packet(pkt);\n pkt->data = data;\n pkt->size = size;\n pkt->destruct = av_destruct_packet;\n if(!data)\n return AVERROR(ENOMEM);\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n assert(size);\n if (size > (INT_MAX-32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void av_init_packet(AVPacket *pkt)\n{\n pkt->pts = AV_NOPTS_VALUE;\n pkt->dts = AV_NOPTS_VALUE;\n pkt->pos = -1;\n pkt->duration = 0;\n pkt->convergence_duration = 0;\n pkt->flags = 0;\n pkt->stream_index = 0;\n pkt->destruct= NULL;\n pkt->side_data = NULL;\n pkt->side_data_elems = 0;\n}', 'static int64_t get_pts(const uint8_t *p)\n{\n int hour, min, sec, hsec;\n if(sscanf(p, "%*[^,],%d:%d:%d%*c%d", &hour, &min, &sec, &hsec) != 4)\n return AV_NOPTS_VALUE;\n min+= 60*hour;\n sec+= 60*min;\n return sec*100+hsec;\n}']
1,574
1
https://github.com/nginx/nginx/blob/c18658e9fec66b2564a3dcc9a24d401d77a0d986/src/http/ngx_http_request.c/#L3519
static ngx_int_t ngx_http_post_action(ngx_http_request_t *r) { ngx_http_core_loc_conf_t *clcf; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); if (clcf->post_action.data == NULL) { return NGX_DECLINED; } if (r->post_action && r->uri_changes == 0) { return NGX_DECLINED; } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "post action: \"%V\"", &clcf->post_action); r->main->count--; r->http_version = NGX_HTTP_VERSION_9; r->header_only = 1; r->post_action = 1; r->read_event_handler = ngx_http_block_reading; if (clcf->post_action.data[0] == '/') { ngx_http_internal_redirect(r, &clcf->post_action, NULL); } else { ngx_http_named_location(r, &clcf->post_action); } return NGX_OK; }
['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 u->buffer.start = NULL;\n u->cache_status = NGX_HTTP_CACHE_MISS;\n u->request_sent = 1;\n }\n if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) {\n rc = NGX_ERROR;\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 if (ngx_http_upstream_set_local(r, u, u->conf->local) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (u->conf->socket_keepalive) {\n u->peer.so_keepalive = 1;\n }\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 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->sockaddr) {\n if (u->resolved->port == 0\n && u->resolved->sockaddr->sa_family != AF_UNIX)\n {\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 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 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 u->upstream = uscf;\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 void\nngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_int_t rc;\n ngx_connection_t *c;\n r->connection->log->action = "connecting to upstream";\n if (u->state && u->state->response_time == (ngx_msec_t) -1) {\n u->state->response_time = ngx_current_msec - u->start_time;\n }\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 u->start_time = ngx_current_msec;\n u->state->response_time = (ngx_msec_t) -1;\n u->state->connect_time = (ngx_msec_t) -1;\n u->state->header_time = (ngx_msec_t) -1;\n rc = ngx_event_connect_peer(&u->peer);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream connect: %i", rc);\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->peer = u->peer.name;\n if (rc == NGX_BUSY) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE);\n return;\n }\n if (rc == NGX_DECLINED) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n c = u->peer.connection;\n c->requests++;\n c->data = r;\n c->write->handler = ngx_http_upstream_handler;\n c->read->handler = ngx_http_upstream_handler;\n u->write_event_handler = ngx_http_upstream_send_request_handler;\n u->read_event_handler = ngx_http_upstream_process_header;\n c->sendfile &= r->connection->sendfile;\n u->output.sendfile = c->sendfile;\n if (r->connection->tcp_nopush == NGX_TCP_NOPUSH_DISABLED) {\n c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;\n }\n if (c->pool == NULL) {\n c->pool = ngx_create_pool(128, r->connection->log);\n if (c->pool == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n }\n c->log = r->connection->log;\n c->pool->log = c->log;\n c->read->log = c->log;\n c->write->log = c->log;\n u->writer.out = NULL;\n u->writer.last = &u->writer.out;\n u->writer.connection = c;\n u->writer.limit = 0;\n if (u->request_sent) {\n if (ngx_http_upstream_reinit(r, u) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n }\n if (r->request_body\n && r->request_body->buf\n && r->request_body->temp_file\n && r == r->main)\n {\n u->output.free = ngx_alloc_chain_link(r->pool);\n if (u->output.free == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->output.free->buf = r->request_body->buf;\n u->output.free->next = NULL;\n u->output.allocated = 1;\n r->request_body->buf->pos = r->request_body->buf->start;\n r->request_body->buf->last = r->request_body->buf->start;\n r->request_body->buf->tag = u->output.tag;\n }\n u->request_sent = 0;\n u->request_body_sent = 0;\n u->request_body_blocked = 0;\n if (rc == NGX_AGAIN) {\n ngx_add_timer(c->write, u->conf->connect_timeout);\n return;\n }\n#if (NGX_HTTP_SSL)\n if (u->ssl && c->ssl == NULL) {\n ngx_http_upstream_ssl_init_connection(r, u, c);\n return;\n }\n#endif\n ngx_http_upstream_send_request(r, u, 1);\n}', 'static void\nngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,\n ngx_uint_t ft_type)\n{\n ngx_msec_t timeout;\n ngx_uint_t status, state;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http next upstream, %xi", ft_type);\n if (u->peer.sockaddr) {\n if (u->peer.connection) {\n u->state->bytes_sent = u->peer.connection->sent;\n }\n if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403\n || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404)\n {\n state = NGX_PEER_NEXT;\n } else {\n state = NGX_PEER_FAILED;\n }\n u->peer.free(&u->peer, u->peer.data, state);\n u->peer.sockaddr = NULL;\n }\n if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT,\n "upstream timed out");\n }\n if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {\n u->peer.tries++;\n }\n switch (ft_type) {\n case NGX_HTTP_UPSTREAM_FT_TIMEOUT:\n case NGX_HTTP_UPSTREAM_FT_HTTP_504:\n status = NGX_HTTP_GATEWAY_TIME_OUT;\n break;\n case NGX_HTTP_UPSTREAM_FT_HTTP_500:\n status = NGX_HTTP_INTERNAL_SERVER_ERROR;\n break;\n case NGX_HTTP_UPSTREAM_FT_HTTP_503:\n status = NGX_HTTP_SERVICE_UNAVAILABLE;\n break;\n case NGX_HTTP_UPSTREAM_FT_HTTP_403:\n status = NGX_HTTP_FORBIDDEN;\n break;\n case NGX_HTTP_UPSTREAM_FT_HTTP_404:\n status = NGX_HTTP_NOT_FOUND;\n break;\n case NGX_HTTP_UPSTREAM_FT_HTTP_429:\n status = NGX_HTTP_TOO_MANY_REQUESTS;\n break;\n default:\n status = NGX_HTTP_BAD_GATEWAY;\n }\n if (r->connection->error) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_CLIENT_CLOSED_REQUEST);\n return;\n }\n u->state->status = status;\n timeout = u->conf->next_upstream_timeout;\n if (u->request_sent\n && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH)))\n {\n ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT;\n }\n if (u->peer.tries == 0\n || ((u->conf->next_upstream & ft_type) != ft_type)\n || (u->request_sent && r->request_body_no_buffering)\n || (timeout && ngx_current_msec - u->peer.start_time >= timeout))\n {\n#if (NGX_HTTP_CACHE)\n if (u->cache_status == NGX_HTTP_CACHE_EXPIRED\n && ((u->conf->cache_use_stale & ft_type) || r->cache->stale_error))\n {\n ngx_int_t rc;\n rc = u->reinit_request(r);\n if (rc != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u, rc);\n return;\n }\n u->cache_status = NGX_HTTP_CACHE_STALE;\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_HTTP_INTERNAL_SERVER_ERROR;\n }\n ngx_http_upstream_finalize_request(r, u, rc);\n return;\n }\n#endif\n ngx_http_upstream_finalize_request(r, u, status);\n return;\n }\n if (u->peer.connection) {\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 (NGX_HTTP_SSL)\n if (u->peer.connection->ssl) {\n u->peer.connection->ssl->no_wait_shutdown = 1;\n u->peer.connection->ssl->no_send_shutdown = 1;\n (void) ngx_ssl_shutdown(u->peer.connection);\n }\n#endif\n if (u->peer.connection->pool) {\n ngx_destroy_pool(u->peer.connection->pool);\n }\n ngx_close_connection(u->peer.connection);\n u->peer.connection = NULL;\n }\n ngx_http_upstream_connect(r, u);\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 == (ngx_msec_t) -1) {\n u->state->response_time = ngx_current_msec - u->start_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 if (u->peer.connection) {\n u->state->bytes_sent = u->peer.connection->sent;\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 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 if (ngx_http_upstream_process_trailers(r, u) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_ERROR);\n return;\n }\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 c->timedout = 1;\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}', '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}']
1,575
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/test/evp_test.c/#L1632
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}']
1,576
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/stack/stack.c/#L328
void *sk_value(const _STACK *st, int i) { if (!st || (i < 0) || (i >= st->num)) return NULL; return st->data[i]; }
['int SMIME_text(BIO *in, BIO *out)\n{\n char iobuf[4096];\n int len;\n STACK_OF(MIME_HEADER) *headers;\n MIME_HEADER *hdr;\n if ((headers = mime_parse_hdr(in)) == NULL) {\n ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_PARSE_ERROR);\n return 0;\n }\n if ((hdr = mime_hdr_find(headers, "content-type")) == NULL\n || hdr->value == NULL) {\n ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_MIME_NO_CONTENT_TYPE);\n sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n return 0;\n }\n if (strcmp(hdr->value, "text/plain")) {\n ASN1err(ASN1_F_SMIME_TEXT, ASN1_R_INVALID_MIME_TYPE);\n ERR_add_error_data(2, "type: ", hdr->value);\n sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n return 0;\n }\n sk_MIME_HEADER_pop_free(headers, mime_hdr_free);\n while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)\n BIO_write(out, iobuf, len);\n if (len < 0)\n return 0;\n return 1;\n}', 'static STACK_OF(MIME_HEADER) *mime_parse_hdr(BIO *bio)\n{\n char *p, *q, c;\n char *ntmp;\n char linebuf[MAX_SMLEN];\n MIME_HEADER *mhdr = NULL;\n STACK_OF(MIME_HEADER) *headers;\n int len, state, save_state = 0;\n headers = sk_MIME_HEADER_new(mime_hdr_cmp);\n if (headers == NULL)\n return NULL;\n while ((len = BIO_gets(bio, linebuf, MAX_SMLEN)) > 0) {\n if (mhdr && isspace((unsigned char)linebuf[0]))\n state = MIME_NAME;\n else\n state = MIME_START;\n ntmp = NULL;\n for (p = linebuf, q = linebuf; (c = *p) && (c != \'\\r\') && (c != \'\\n\');\n p++) {\n switch (state) {\n case MIME_START:\n if (c == \':\') {\n state = MIME_TYPE;\n *p = 0;\n ntmp = strip_ends(q);\n q = p + 1;\n }\n break;\n case MIME_TYPE:\n if (c == \';\') {\n mime_debug("Found End Value\\n");\n *p = 0;\n mhdr = mime_hdr_new(ntmp, strip_ends(q));\n sk_MIME_HEADER_push(headers, mhdr);\n ntmp = NULL;\n q = p + 1;\n state = MIME_NAME;\n } else if (c == \'(\') {\n save_state = state;\n state = MIME_COMMENT;\n }\n break;\n case MIME_COMMENT:\n if (c == \')\') {\n state = save_state;\n }\n break;\n case MIME_NAME:\n if (c == \'=\') {\n state = MIME_VALUE;\n *p = 0;\n ntmp = strip_ends(q);\n q = p + 1;\n }\n break;\n case MIME_VALUE:\n if (c == \';\') {\n state = MIME_NAME;\n *p = 0;\n mime_hdr_addparam(mhdr, ntmp, strip_ends(q));\n ntmp = NULL;\n q = p + 1;\n } else if (c == \'"\') {\n mime_debug("Found Quote\\n");\n state = MIME_QUOTE;\n } else if (c == \'(\') {\n save_state = state;\n state = MIME_COMMENT;\n }\n break;\n case MIME_QUOTE:\n if (c == \'"\') {\n mime_debug("Found Match Quote\\n");\n state = MIME_VALUE;\n }\n break;\n }\n }\n if (state == MIME_TYPE) {\n mhdr = mime_hdr_new(ntmp, strip_ends(q));\n sk_MIME_HEADER_push(headers, mhdr);\n } else if (state == MIME_VALUE)\n mime_hdr_addparam(mhdr, ntmp, strip_ends(q));\n if (p == linebuf)\n break;\n }\n return headers;\n}', 'DEFINE_STACK_OF(MIME_HEADER)', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', 'static MIME_HEADER *mime_hdr_find(STACK_OF(MIME_HEADER) *hdrs, char *name)\n{\n MIME_HEADER htmp;\n int idx;\n htmp.name = name;\n idx = sk_MIME_HEADER_find(hdrs, &htmp);\n if (idx < 0)\n return NULL;\n return sk_MIME_HEADER_value(hdrs, idx);\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}']
1,577
0
https://github.com/libav/libav/blob/44594cc7980a4651aba8ac40c59192c283634748/ffmpeg.c/#L3589
static void opt_output_file(const char *filename) { AVFormatContext *oc; int err, use_video, use_audio, use_subtitle; int input_has_video, input_has_audio, input_has_subtitle; AVFormatParameters params, *ap = &params; AVOutputFormat *file_oformat; AVMetadataTag *tag = NULL; if (!strcmp(filename, "-")) filename = "pipe:"; oc = avformat_alloc_context(); if (!oc) { print_error(filename, AVERROR(ENOMEM)); ffmpeg_exit(1); } if (last_asked_format) { file_oformat = av_guess_format(last_asked_format, NULL, NULL); if (!file_oformat) { fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format); ffmpeg_exit(1); } last_asked_format = NULL; } else { file_oformat = av_guess_format(NULL, filename, NULL); if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); ffmpeg_exit(1); } } oc->oformat = file_oformat; av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && av_strstart(filename, "http:", NULL)) { int err = read_ffserver_streams(oc, filename); if (err < 0) { print_error(filename, err); ffmpeg_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; if (nb_input_files > 0) { check_audio_video_sub_inputs(&input_has_video, &input_has_audio, &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; if (!input_has_subtitle) use_subtitle = 0; } if (audio_disable) use_audio = 0; if (video_disable) use_video = 0; if (subtitle_disable) use_subtitle = 0; if (use_video) new_video_stream(oc, nb_output_files); if (use_audio) new_audio_stream(oc, nb_output_files); if (use_subtitle) new_subtitle_stream(oc, nb_output_files); oc->timestamp = recording_timestamp; while ((tag = av_metadata_get(metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) av_metadata_set2(&oc->metadata, tag->key, tag->value, 0); av_metadata_free(&metadata); } output_files[nb_output_files++] = oc; if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR_NUMEXPECTED); ffmpeg_exit(1); } } if (!(oc->oformat->flags & AVFMT_NOFILE)) { if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (url_exist(filename)) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); ffmpeg_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); ffmpeg_exit(1); } } } if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) { print_error(filename, err); ffmpeg_exit(1); } } memset(ap, 0, sizeof(*ap)); if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); ffmpeg_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->loop_output = loop_output; oc->flags |= AVFMT_FLAG_NONBLOCK; set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL); nb_streamid_map = 0; av_freep(&forced_key_frames); }
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = &params;\n AVOutputFormat *file_oformat;\n AVMetadataTag *tag = NULL;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n ffmpeg_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n ffmpeg_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) use_audio = 0;\n if (video_disable) use_video = 0;\n if (subtitle_disable) use_subtitle = 0;\n if (use_video) new_video_stream(oc, nb_output_files);\n if (use_audio) new_audio_stream(oc, nb_output_files);\n if (use_subtitle) new_subtitle_stream(oc, nb_output_files);\n oc->timestamp = recording_timestamp;\n while ((tag = av_metadata_get(metadata, "", tag, AV_METADATA_IGNORE_SUFFIX)))\n av_metadata_set2(&oc->metadata, tag->key, tag->value, 0);\n av_metadata_free(&metadata);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n ffmpeg_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n ffmpeg_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n ffmpeg_exit(1);\n }\n }\n }\n if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n ffmpeg_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);\n nb_streamid_map = 0;\n av_freep(&forced_key_frames);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n size_t len = 0;\n while (++len < size && *src)\n *dst++ = *src++;\n if (len <= size)\n *dst = 0;\n return len + strlen(src) - 1;\n}']
1,578
0
https://github.com/nginx/nginx/blob/8f0f4c10e91a82e6f636d792c14cc608c06ca37d/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; }
['ngx_int_t\nngx_http_process_request_uri(ngx_http_request_t *r)\n{\n ngx_http_core_srv_conf_t *cscf;\n if (r->args_start) {\n r->uri.len = r->args_start - 1 - r->uri_start;\n } else {\n r->uri.len = r->uri_end - r->uri_start;\n }\n if (r->complex_uri || r->quoted_uri) {\n r->uri.data = ngx_pnalloc(r->pool, r->uri.len + 1);\n if (r->uri.data == NULL) {\n ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_ERROR;\n }\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n if (ngx_http_parse_complex_uri(r, cscf->merge_slashes) != NGX_OK) {\n r->uri.len = 0;\n ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,\n "client sent invalid request");\n ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);\n return NGX_ERROR;\n }\n } else {\n r->uri.data = r->uri_start;\n }\n r->unparsed_uri.len = r->uri_end - r->uri_start;\n r->unparsed_uri.data = r->uri_start;\n r->valid_unparsed_uri = r->space_in_uri ? 0 : 1;\n if (r->uri_ext) {\n if (r->args_start) {\n r->exten.len = r->args_start - 1 - r->uri_ext;\n } else {\n r->exten.len = r->uri_end - r->uri_ext;\n }\n r->exten.data = r->uri_ext;\n }\n if (r->args_start && r->uri_end > r->args_start) {\n r->args.len = r->uri_end - r->args_start;\n r->args.data = r->args_start;\n }\n#if (NGX_WIN32)\n {\n u_char *p, *last;\n p = r->uri.data;\n last = r->uri.data + r->uri.len;\n while (p < last) {\n if (*p++ == \':\') {\n if (p < last && *p == \'$\') {\n ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,\n "client sent unsafe win32 URI");\n ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);\n return NGX_ERROR;\n }\n }\n }\n p = r->uri.data + r->uri.len - 1;\n while (p > r->uri.data) {\n if (*p == \' \') {\n p--;\n continue;\n }\n if (*p == \'.\') {\n p--;\n continue;\n }\n break;\n }\n if (p != r->uri.data + r->uri.len - 1) {\n r->uri.len = p + 1 - r->uri.data;\n ngx_http_set_exten(r);\n }\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http uri: \\"%V\\"", &r->uri);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http args: \\"%V\\"", &r->args);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http exten: \\"%V\\"", &r->exten);\n return NGX_OK;\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n r->main->subrequests++;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'ngx_int_t\nngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)\n{\n ngx_uint_t i, err;\n ngx_http_err_page_t *err_page;\n ngx_http_core_loc_conf_t *clcf;\n ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http special response: %i, \\"%V?%V\\"",\n error, &r->uri, &r->args);\n r->err_status = error;\n if (r->keepalive) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:\n case NGX_HTTP_REQUEST_URI_TOO_LARGE:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_INTERNAL_SERVER_ERROR:\n case NGX_HTTP_NOT_IMPLEMENTED:\n r->keepalive = 0;\n }\n }\n if (r->lingering_close) {\n switch (error) {\n case NGX_HTTP_BAD_REQUEST:\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n r->lingering_close = 0;\n }\n }\n r->headers_out.content_type.len = 0;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {\n if (clcf->recursive_error_pages == 0) {\n r->error_page = 1;\n }\n err_page = clcf->error_pages->elts;\n for (i = 0; i < clcf->error_pages->nelts; i++) {\n if (err_page[i].status == error) {\n return ngx_http_send_error_page(r, &err_page[i]);\n }\n }\n }\n r->expect_tested = 1;\n if (ngx_http_discard_request_body(r) != NGX_OK) {\n r->keepalive = 0;\n }\n if (clcf->msie_refresh\n && r->headers_in.msie\n && (error == NGX_HTTP_MOVED_PERMANENTLY\n || error == NGX_HTTP_MOVED_TEMPORARILY))\n {\n return ngx_http_send_refresh(r);\n }\n if (error == NGX_HTTP_CREATED) {\n err = 0;\n } else if (error == NGX_HTTP_NO_CONTENT) {\n err = 0;\n } else if (error >= NGX_HTTP_MOVED_PERMANENTLY\n && error < NGX_HTTP_LAST_3XX)\n {\n err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;\n } else if (error >= NGX_HTTP_BAD_REQUEST\n && error < NGX_HTTP_LAST_4XX)\n {\n err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_OFF_4XX;\n } else if (error >= NGX_HTTP_NGINX_CODES\n && error < NGX_HTTP_LAST_5XX)\n {\n err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_OFF_5XX;\n switch (error) {\n case NGX_HTTP_TO_HTTPS:\n case NGX_HTTPS_CERT_ERROR:\n case NGX_HTTPS_NO_CERT:\n case NGX_HTTP_REQUEST_HEADER_TOO_LARGE:\n r->err_status = NGX_HTTP_BAD_REQUEST;\n break;\n }\n } else {\n err = 0;\n }\n return ngx_http_send_special_response(r, clcf, err);\n}', 'static ngx_int_t\nngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)\n{\n ngx_int_t overwrite;\n ngx_str_t uri, args;\n ngx_table_elt_t *location;\n ngx_http_core_loc_conf_t *clcf;\n overwrite = err_page->overwrite;\n if (overwrite && overwrite != NGX_HTTP_OK) {\n r->expect_tested = 1;\n }\n if (overwrite >= 0) {\n r->err_status = overwrite;\n }\n if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {\n return NGX_ERROR;\n }\n if (uri.data[0] == \'/\') {\n if (err_page->value.lengths) {\n ngx_http_split_args(r, &uri, &args);\n } else {\n args = err_page->args;\n }\n if (r->method != NGX_HTTP_HEAD) {\n r->method = NGX_HTTP_GET;\n r->method_name = ngx_http_get_name;\n }\n return ngx_http_internal_redirect(r, &uri, &args);\n }\n if (uri.data[0] == \'@\') {\n return ngx_http_named_location(r, &uri);\n }\n location = ngx_list_push(&r->headers_out.headers);\n if (location == NULL) {\n return NGX_ERROR;\n }\n if (overwrite != NGX_HTTP_MOVED_PERMANENTLY\n && overwrite != NGX_HTTP_MOVED_TEMPORARILY\n && overwrite != NGX_HTTP_SEE_OTHER\n && overwrite != NGX_HTTP_TEMPORARY_REDIRECT)\n {\n r->err_status = NGX_HTTP_MOVED_TEMPORARILY;\n }\n location->hash = 1;\n ngx_str_set(&location->key, "Location");\n location->value = uri;\n ngx_http_clear_location(r);\n r->headers_out.location = location;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->msie_refresh && r->headers_in.msie) {\n return ngx_http_send_refresh(r);\n }\n return ngx_http_send_special_response(r, clcf, r->err_status\n - NGX_HTTP_MOVED_PERMANENTLY\n + NGX_HTTP_OFF_3XX);\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internally redirecting to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n ngx_str_null(&r->args);\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->valid_unparsed_uri = 0;\n r->add_uri_to_alias = 0;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}', "void\nngx_http_set_exten(ngx_http_request_t *r)\n{\n ngx_int_t i;\n ngx_str_null(&r->exten);\n for (i = r->uri.len - 1; i > 1; i--) {\n if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') {\n r->exten.len = r->uri.len - i - 1;\n r->exten.data = &r->uri.data[i + 1];\n return;\n } else if (r->uri.data[i] == '/') {\n return;\n }\n }\n return;\n}"]
1,579
0
https://github.com/libav/libav/blob/a72cad0a6c05aa74940101e937cb3dc602d7d67b/libavcodec/vmdav.c/#L305
static void vmd_decode(VmdVideoContext *s) { int i; unsigned int *palette32; unsigned char r, g, b; const unsigned char *p = s->buf + 16; const unsigned char *pb; unsigned int pb_size; unsigned char meth; unsigned char *dp; unsigned char *pp; unsigned char len; int ofs; int frame_x, frame_y; int frame_width, frame_height; frame_x = AV_RL16(&s->buf[6]); frame_y = AV_RL16(&s->buf[8]); frame_width = AV_RL16(&s->buf[10]) - frame_x + 1; frame_height = AV_RL16(&s->buf[12]) - frame_y + 1; if (frame_x < 0 || frame_width < 0 || frame_x >= s->avctx->width || frame_width > s->avctx->width || frame_x + frame_width > s->avctx->width) return; if (frame_y < 0 || frame_height < 0 || frame_y >= s->avctx->height || frame_height > s->avctx->height || frame_y + frame_height > s->avctx->height) return; if ((frame_width == s->avctx->width && frame_height == s->avctx->height) && (frame_x || frame_y)) { s->x_off = frame_x; s->y_off = frame_y; } frame_x -= s->x_off; frame_y -= s->y_off; if (s->prev_frame.data[0] && (frame_x || frame_y || (frame_width != s->avctx->width) || (frame_height != s->avctx->height))) { memcpy(s->frame.data[0], s->prev_frame.data[0], s->avctx->height * s->frame.linesize[0]); } if (s->buf[15] & 0x02) { p += 2; palette32 = (unsigned int *)s->palette; for (i = 0; i < PALETTE_COUNT; i++) { r = *p++ * 4; g = *p++ * 4; b = *p++ * 4; palette32[i] = (r << 16) | (g << 8) | (b); } s->size -= (256 * 3 + 2); } if (s->size > 0) { pb = p; pb_size = s->buf + s->size - pb; if (pb_size < 1) return; meth = *pb++; pb_size--; if (meth & 0x80) { lz_unpack(pb, pb_size, s->unpack_buffer, s->unpack_buffer_size); meth &= 0x7F; pb = s->unpack_buffer; pb_size = s->unpack_buffer_size; } dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x]; pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x]; switch (meth) { case 1: for (i = 0; i < frame_height; i++) { ofs = 0; do { if (pb_size < 1) return; len = *pb++; pb_size--; if (len & 0x80) { len = (len & 0x7F) + 1; if (ofs + len > frame_width || pb_size < len) return; memcpy(&dp[ofs], pb, len); pb += len; pb_size -= len; ofs += len; } else { if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) return; memcpy(&dp[ofs], &pp[ofs], len + 1); ofs += len + 1; } } while (ofs < frame_width); if (ofs > frame_width) { av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n", ofs, frame_width); break; } dp += s->frame.linesize[0]; pp += s->prev_frame.linesize[0]; } break; case 2: for (i = 0; i < frame_height; i++) { if (pb_size < frame_width) return; memcpy(dp, pb, frame_width); pb += frame_width; pb_size -= frame_width; dp += s->frame.linesize[0]; pp += s->prev_frame.linesize[0]; } break; case 3: for (i = 0; i < frame_height; i++) { ofs = 0; do { if (pb_size < 1) return; len = *pb++; pb_size--; if (len & 0x80) { len = (len & 0x7F) + 1; if (pb_size < 1) return; if (*pb++ == 0xFF) len = rle_unpack(pb, &dp[ofs], len, pb_size, frame_width - ofs); else { if (pb_size < len) return; memcpy(&dp[ofs], pb, len); } pb += len; pb_size -= 1 + len; ofs += len; } else { if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) return; memcpy(&dp[ofs], &pp[ofs], len + 1); ofs += len + 1; } } while (ofs < frame_width); if (ofs > frame_width) { av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\n", ofs, frame_width); } dp += s->frame.linesize[0]; pp += s->prev_frame.linesize[0]; } break; } } }
['static void vmd_decode(VmdVideoContext *s)\n{\n int i;\n unsigned int *palette32;\n unsigned char r, g, b;\n const unsigned char *p = s->buf + 16;\n const unsigned char *pb;\n unsigned int pb_size;\n unsigned char meth;\n unsigned char *dp;\n unsigned char *pp;\n unsigned char len;\n int ofs;\n int frame_x, frame_y;\n int frame_width, frame_height;\n frame_x = AV_RL16(&s->buf[6]);\n frame_y = AV_RL16(&s->buf[8]);\n frame_width = AV_RL16(&s->buf[10]) - frame_x + 1;\n frame_height = AV_RL16(&s->buf[12]) - frame_y + 1;\n if (frame_x < 0 || frame_width < 0 ||\n frame_x >= s->avctx->width ||\n frame_width > s->avctx->width ||\n frame_x + frame_width > s->avctx->width)\n return;\n if (frame_y < 0 || frame_height < 0 ||\n frame_y >= s->avctx->height ||\n frame_height > s->avctx->height ||\n frame_y + frame_height > s->avctx->height)\n return;\n if ((frame_width == s->avctx->width && frame_height == s->avctx->height) &&\n (frame_x || frame_y)) {\n s->x_off = frame_x;\n s->y_off = frame_y;\n }\n frame_x -= s->x_off;\n frame_y -= s->y_off;\n if (s->prev_frame.data[0] &&\n (frame_x || frame_y || (frame_width != s->avctx->width) ||\n (frame_height != s->avctx->height))) {\n memcpy(s->frame.data[0], s->prev_frame.data[0],\n s->avctx->height * s->frame.linesize[0]);\n }\n if (s->buf[15] & 0x02) {\n p += 2;\n palette32 = (unsigned int *)s->palette;\n for (i = 0; i < PALETTE_COUNT; i++) {\n r = *p++ * 4;\n g = *p++ * 4;\n b = *p++ * 4;\n palette32[i] = (r << 16) | (g << 8) | (b);\n }\n s->size -= (256 * 3 + 2);\n }\n if (s->size > 0) {\n pb = p;\n pb_size = s->buf + s->size - pb;\n if (pb_size < 1)\n return;\n meth = *pb++; pb_size--;\n if (meth & 0x80) {\n lz_unpack(pb, pb_size,\n s->unpack_buffer, s->unpack_buffer_size);\n meth &= 0x7F;\n pb = s->unpack_buffer;\n pb_size = s->unpack_buffer_size;\n }\n dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x];\n pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];\n switch (meth) {\n case 1:\n for (i = 0; i < frame_height; i++) {\n ofs = 0;\n do {\n if (pb_size < 1)\n return;\n len = *pb++;\n pb_size--;\n if (len & 0x80) {\n len = (len & 0x7F) + 1;\n if (ofs + len > frame_width || pb_size < len)\n return;\n memcpy(&dp[ofs], pb, len);\n pb += len;\n pb_size -= len;\n ofs += len;\n } else {\n if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])\n return;\n memcpy(&dp[ofs], &pp[ofs], len + 1);\n ofs += len + 1;\n }\n } while (ofs < frame_width);\n if (ofs > frame_width) {\n av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\\n",\n ofs, frame_width);\n break;\n }\n dp += s->frame.linesize[0];\n pp += s->prev_frame.linesize[0];\n }\n break;\n case 2:\n for (i = 0; i < frame_height; i++) {\n if (pb_size < frame_width)\n return;\n memcpy(dp, pb, frame_width);\n pb += frame_width;\n pb_size -= frame_width;\n dp += s->frame.linesize[0];\n pp += s->prev_frame.linesize[0];\n }\n break;\n case 3:\n for (i = 0; i < frame_height; i++) {\n ofs = 0;\n do {\n if (pb_size < 1)\n return;\n len = *pb++;\n pb_size--;\n if (len & 0x80) {\n len = (len & 0x7F) + 1;\n if (pb_size < 1)\n return;\n if (*pb++ == 0xFF)\n len = rle_unpack(pb, &dp[ofs], len, pb_size, frame_width - ofs);\n else {\n if (pb_size < len)\n return;\n memcpy(&dp[ofs], pb, len);\n }\n pb += len;\n pb_size -= 1 + len;\n ofs += len;\n } else {\n if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])\n return;\n memcpy(&dp[ofs], &pp[ofs], len + 1);\n ofs += len + 1;\n }\n } while (ofs < frame_width);\n if (ofs > frame_width) {\n av_log(s->avctx, AV_LOG_ERROR, "VMD video: offset > width (%d > %d)\\n",\n ofs, frame_width);\n }\n dp += s->frame.linesize[0];\n pp += s->prev_frame.linesize[0];\n }\n break;\n }\n }\n}']
1,580
0
https://github.com/openssl/openssl/blob/4dfc8f1f0b3ff85adfdca3a37be5df7928092f07/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int generate_key(DH *dh)\n\t{\n\tint ok=0;\n\tint generate_new_key=0;\n\tunsigned l;\n\tBN_CTX *ctx;\n\tBN_MONT_CTX *mont=NULL;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tctx = BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tif (dh->priv_key == NULL)\n\t\t{\n\t\tpriv_key=BN_new();\n\t\tif (priv_key == NULL) goto err;\n\t\tgenerate_new_key=1;\n\t\t}\n\telse\n\t\tpriv_key=dh->priv_key;\n\tif (dh->pub_key == NULL)\n\t\t{\n\t\tpub_key=BN_new();\n\t\tif (pub_key == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dh->pub_key;\n\tif (dh->flags & DH_FLAG_CACHE_MONT_P)\n\t\t{\n\t\tmont = BN_MONT_CTX_set_locked(&dh->method_mont_p,\n\t\t\t\tCRYPTO_LOCK_DH, dh->p, ctx);\n\t\tif (!mont)\n\t\t\tgoto err;\n\t\t}\n\tif (generate_new_key)\n\t\t{\n\t\tl = dh->length ? dh->length : BN_num_bits(dh->p)-1;\n\t\tif (!BN_rand(priv_key, l, 0, 0)) goto err;\n\t\t}\n\t{\n\t\tBIGNUM local_prk;\n\t\tBIGNUM *prk;\n\t\tif ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t\t{\n\t\t\tBN_init(&local_prk);\n\t\t\tprk = &local_prk;\n\t\t\tBN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME);\n\t\t\t}\n\t\telse\n\t\t\tprk = priv_key;\n\t\tif (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) goto err;\n\t}\n\tdh->pub_key=pub_key;\n\tdh->priv_key=priv_key;\n\tok=1;\nerr:\n\tif (ok != 1)\n\t\tDHerr(DH_F_GENERATE_KEY,ERR_R_BN_LIB);\n\tif ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);\n\tBN_CTX_free(ctx);\n\treturn(ok);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint got_write_lock = 0;\n\tCRYPTO_r_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\tCRYPTO_r_unlock(lock);\n\t\tCRYPTO_w_lock(lock);\n\t\tgot_write_lock = 1;\n\t\tif (!*pmont)\n\t\t\t{\n\t\t\tBN_MONT_CTX *mtmp;\n\t\t\tmtmp = BN_MONT_CTX_new();\n\t\t\tif (mtmp && !BN_MONT_CTX_set(mtmp, mod, ctx))\n\t\t\t\tBN_MONT_CTX_free(mtmp);\n\t\t\telse\n\t\t\t\t*pmont = mtmp;\n\t\t\t}\n\t\t}\n\tif (got_write_lock)\n\t\tCRYPTO_w_unlock(lock);\n\telse\n\t\tCRYPTO_r_unlock(lock);\n\treturn *pmont;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
1,581
1
https://github.com/openssl/openssl/blob/6d4c65835de4ed9aa0a37e3234055d075fe0bc58/crypto/bn/bn_ctx.c/#L355
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(n);\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED);\n\t\treturn(0);\n\t\t}\n\tif (r != NULL)\n\t\tret = BN_mod_mul(n, n, r, b->mod, ctx);\n\telse\n\t\tret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);\n\tif (ret >= 0)\n\t\t{\n\t\tif (!BN_BLINDING_update(b,ctx))\n\t\t\treturn(0);\n\t\t}\n\tbn_check_top(n);\n\treturn(ret);\n\t}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n\tBN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint ret=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tBN_CTX_start(ctx);\n\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_nnmod(r,t,m,ctx)) goto err;\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);\n\t\tgoto err;\n\t\t}\n\tif (--(b->counter) == 0 && b->e != NULL &&\n\t\t!(b->flags & BN_BLINDING_NO_RECREATE))\n\t\t{\n\t\tif (!BN_BLINDING_create_param(b, NULL, NULL, ctx, NULL, NULL))\n\t\t\tgoto err;\n\t\t}\n\telse if (!(b->flags & BN_BLINDING_NO_UPDATE))\n\t\t{\n\t\tif (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;\n\t\tif (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;\n\t\t}\n\tret=1;\nerr:\n\tif (b->counter == 0)\n\t\tb->counter = BN_BLINDING_COUNTER;\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (t == NULL)\n\t\t\t\tgoto err;\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
1,582
0
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/pkcs7/pk7_attr.c/#L161
int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, const unsigned char *md, int mdlen) { ASN1_OCTET_STRING *os; os = ASN1_OCTET_STRING_new(); if (os == NULL) return 0; if (!ASN1_STRING_set(os, md, mdlen) || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest, V_ASN1_OCTET_STRING, os)) { ASN1_OCTET_STRING_free(os); return 0; } return 1; }
['int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si,\n const unsigned char *md, int mdlen)\n{\n ASN1_OCTET_STRING *os;\n os = ASN1_OCTET_STRING_new();\n if (os == NULL)\n return 0;\n if (!ASN1_STRING_set(os, md, mdlen)\n || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest,\n V_ASN1_OCTET_STRING, os)) {\n ASN1_OCTET_STRING_free(os);\n return 0;\n }\n return 1;\n}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n ASN1_STRING *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->type = type;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n unsigned char *c;\n const char *data = _data;\n if (len < 0) {\n if (data == NULL)\n return (0);\n else\n len = strlen(data);\n }\n if ((str->length < len) || (str->data == NULL)) {\n c = str->data;\n str->data = OPENSSL_realloc(c, len + 1);\n if (str->data == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n str->data = c;\n return (0);\n }\n }\n str->length = len;\n if (data != NULL) {\n memcpy(str->data, data, len);\n str->data[len] = '\\0';\n }\n return (1);\n}", 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'int PKCS7_add_signed_attribute(PKCS7_SIGNER_INFO *p7si, int nid, int atrtype,\n void *value)\n{\n return (add_attribute(&(p7si->auth_attr), nid, atrtype, value));\n}', 'static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,\n void *value)\n{\n X509_ATTRIBUTE *attr = NULL;\n if (*sk == NULL) {\n if ((*sk = sk_X509_ATTRIBUTE_new_null()) == NULL)\n return 0;\n new_attrib:\n if ((attr = X509_ATTRIBUTE_create(nid, atrtype, value)) == NULL)\n return 0;\n if (!sk_X509_ATTRIBUTE_push(*sk, attr)) {\n X509_ATTRIBUTE_free(attr);\n return 0;\n }\n } else {\n int i;\n for (i = 0; i < sk_X509_ATTRIBUTE_num(*sk); i++) {\n attr = sk_X509_ATTRIBUTE_value(*sk, i);\n if (OBJ_obj2nid(X509_ATTRIBUTE_get0_object(attr)) == nid) {\n X509_ATTRIBUTE_free(attr);\n attr = X509_ATTRIBUTE_create(nid, atrtype, value);\n if (attr == NULL)\n return 0;\n if (!sk_X509_ATTRIBUTE_set(*sk, i, attr)) {\n X509_ATTRIBUTE_free(attr);\n return 0;\n }\n goto end;\n }\n }\n goto new_attrib;\n }\n end:\n return (1);\n}', '_STACK *sk_new_null(void)\n{\n return sk_new((int (*)(const void *, const void *))0);\n}', '_STACK *sk_new(int (*c) (const void *, const void *))\n{\n _STACK *ret;\n if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL)\n goto err;\n if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL)\n goto err;\n ret->comp = c;\n ret->num_alloc = MIN_NODES;\n return (ret);\n err:\n OPENSSL_free(ret);\n return (NULL);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', 'void ASN1_STRING_free(ASN1_STRING *a)\n{\n if (a == NULL)\n return;\n if (!(a->flags & ASN1_STRING_FLAG_NDEF))\n OPENSSL_free(a->data);\n if (!(a->flags & ASN1_STRING_FLAG_EMBED))\n OPENSSL_free(a);\n}']
1,583
0
https://github.com/libav/libav/blob/78f318be59a8e6174f21c2d7c3403ef325c73011/libavcodec/smacker.c/#L286
static int decode_header_trees(SmackVContext *smk) { GetBitContext gb; int mmap_size, mclr_size, full_size, type_size; mmap_size = AV_RL32(smk->avctx->extradata); mclr_size = AV_RL32(smk->avctx->extradata + 4); full_size = AV_RL32(smk->avctx->extradata + 8); type_size = AV_RL32(smk->avctx->extradata + 12); init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8); if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n"); smk->mmap_tbl = av_malloc(sizeof(int) * 2); smk->mmap_tbl[0] = 0; smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1; } else { smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size); } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n"); smk->mclr_tbl = av_malloc(sizeof(int) * 2); smk->mclr_tbl[0] = 0; smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1; } else { smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size); } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n"); smk->full_tbl = av_malloc(sizeof(int) * 2); smk->full_tbl[0] = 0; smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1; } else { smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size); } if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n"); smk->type_tbl = av_malloc(sizeof(int) * 2); smk->type_tbl[0] = 0; smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1; } else { smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size); } return 0; }
['static int decode_header_trees(SmackVContext *smk) {\n GetBitContext gb;\n int mmap_size, mclr_size, full_size, type_size;\n mmap_size = AV_RL32(smk->avctx->extradata);\n mclr_size = AV_RL32(smk->avctx->extradata + 4);\n full_size = AV_RL32(smk->avctx->extradata + 8);\n type_size = AV_RL32(smk->avctx->extradata + 12);\n init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\\n");\n smk->mmap_tbl = av_malloc(sizeof(int) * 2);\n smk->mmap_tbl[0] = 0;\n smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;\n } else {\n smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size);\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\\n");\n smk->mclr_tbl = av_malloc(sizeof(int) * 2);\n smk->mclr_tbl[0] = 0;\n smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;\n } else {\n smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size);\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\\n");\n smk->full_tbl = av_malloc(sizeof(int) * 2);\n smk->full_tbl[0] = 0;\n smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;\n } else {\n smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size);\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\\n");\n smk->type_tbl = av_malloc(sizeof(int) * 2);\n smk->type_tbl[0] = 0;\n smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;\n } else {\n smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size);\n }\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n s->buffer_end = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index = 0;\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3);\n s->bit_count = 32 + 8*((intptr_t)buffer & 3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n index++;\n s->index = index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
1,584
0
https://github.com/openssl/openssl/blob/6a69e8694af23dae1d1927813932f4296d133416/test/sslcorrupttest.c/#L18
static void copy_flags(BIO *bio) { int flags; BIO *next = BIO_next(bio); flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS); BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS); BIO_set_flags(bio, flags); }
['static void copy_flags(BIO *bio)\n{\n int flags;\n BIO *next = BIO_next(bio);\n flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);\n BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);\n BIO_set_flags(bio, flags);\n}', 'BIO *BIO_next(BIO *b)\n{\n if (b == NULL)\n return NULL;\n return b->next_bio;\n}', 'int BIO_test_flags(const BIO *b, int flags)\n{\n return (b->flags & flags);\n}']
1,585
0
https://github.com/openssl/openssl/blob/33af4421f2ae5e4d0da3a121f51820f4b49a724c/ssl/ssl_lib.c/#L1343
STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num, STACK_OF(SSL_CIPHER) **skp) { 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\tSSL_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 char * const *, const char * const *))0);\n\t}', 'STACK *sk_new(int (*c)(const char * const *, const char * const *))\n\t{\n\tSTACK *ret;\n\tint i;\n\tif ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)\n\t\tgoto err;\n\tif ((ret->data=(char **)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\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}', 'int sk_push(STACK *st, char *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}']
1,586
0
https://github.com/openssl/openssl/blob/23dd0c9f8dc6f7edf4b872d13e5644dfbbee585b/crypto/evp/p_verify.c/#L38
int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, unsigned int siglen, EVP_PKEY *pkey) { unsigned char m[EVP_MAX_MD_SIZE]; unsigned int m_len = 0; int i = 0; EVP_PKEY_CTX *pkctx = NULL; if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_FINALISE)) { if (!EVP_DigestFinal_ex(ctx, m, &m_len)) goto err; } else { int rv = 0; EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new(); if (tmp_ctx == NULL) { EVPerr(EVP_F_EVP_VERIFYFINAL, ERR_R_MALLOC_FAILURE); return 0; } rv = EVP_MD_CTX_copy_ex(tmp_ctx, ctx); if (rv) rv = EVP_DigestFinal_ex(tmp_ctx, m, &m_len); EVP_MD_CTX_free(tmp_ctx); if (!rv) return 0; } i = -1; pkctx = EVP_PKEY_CTX_new(pkey, NULL); if (pkctx == NULL) goto err; if (EVP_PKEY_verify_init(pkctx) <= 0) goto err; if (EVP_PKEY_CTX_set_signature_md(pkctx, EVP_MD_CTX_md(ctx)) <= 0) goto err; i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len); err: EVP_PKEY_CTX_free(pkctx); return i; }
['int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf,\n unsigned int siglen, EVP_PKEY *pkey)\n{\n unsigned char m[EVP_MAX_MD_SIZE];\n unsigned int m_len = 0;\n int i = 0;\n EVP_PKEY_CTX *pkctx = NULL;\n if (EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_FINALISE)) {\n if (!EVP_DigestFinal_ex(ctx, m, &m_len))\n goto err;\n } else {\n int rv = 0;\n EVP_MD_CTX *tmp_ctx = EVP_MD_CTX_new();\n if (tmp_ctx == NULL) {\n EVPerr(EVP_F_EVP_VERIFYFINAL, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n rv = EVP_MD_CTX_copy_ex(tmp_ctx, ctx);\n if (rv)\n rv = EVP_DigestFinal_ex(tmp_ctx, m, &m_len);\n EVP_MD_CTX_free(tmp_ctx);\n if (!rv)\n return 0;\n }\n i = -1;\n pkctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pkctx == NULL)\n goto err;\n if (EVP_PKEY_verify_init(pkctx) <= 0)\n goto err;\n if (EVP_PKEY_CTX_set_signature_md(pkctx, EVP_MD_CTX_md(ctx)) <= 0)\n goto err;\n i = EVP_PKEY_verify(pkctx, sigbuf, siglen, m, m_len);\n err:\n EVP_PKEY_CTX_free(pkctx);\n return i;\n}', 'int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)\n{\n return (ctx->flags & flags);\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n unsigned char *tmp_buf;\n if ((in == NULL) || (in->digest == NULL)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);\n return 0;\n }\n#ifndef OPENSSL_NO_ENGINE\n if (in->engine && !ENGINE_init(in->engine)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);\n return 0;\n }\n#endif\n if (out->digest == in->digest) {\n tmp_buf = out->md_data;\n EVP_MD_CTX_set_flags(out, EVP_MD_CTX_FLAG_REUSE);\n } else\n tmp_buf = NULL;\n EVP_MD_CTX_reset(out);\n memcpy(out, in, sizeof(*out));\n out->md_data = NULL;\n out->pctx = NULL;\n if (in->md_data && out->digest->ctx_size) {\n if (tmp_buf)\n out->md_data = tmp_buf;\n else {\n out->md_data = OPENSSL_malloc(out->digest->ctx_size);\n if (out->md_data == NULL) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n memcpy(out->md_data, in->md_data, out->digest->ctx_size);\n }\n out->update = in->update;\n if (in->pctx) {\n out->pctx = EVP_PKEY_CTX_dup(in->pctx);\n if (!out->pctx) {\n EVP_MD_CTX_reset(out);\n return 0;\n }\n }\n if (out->digest->copy)\n return out->digest->copy(out, in);\n return 1;\n}', 'int ENGINE_init(ENGINE *e)\n{\n int ret;\n if (e == NULL) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n CRYPTO_THREAD_write_lock(global_engine_lock);\n ret = engine_unlocked_init(e);\n CRYPTO_THREAD_unlock(global_engine_lock);\n return ret;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', '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}']
1,587
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)]; }
['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}', '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}']
1,588
0
https://github.com/openssl/openssl/blob/ea09abc80892920ee5db4de82bed7a193b5896f0/ssl/packet.c/#L49
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { if (!ossl_assert(pkt->subs != NULL && len != 0)) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) { size_t newlen; size_t reflen; reflen = (len > pkt->buf->length) ? len : pkt->buf->length; if (reflen > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = reflen * 2; if (newlen < DEFAULT_BUF_SIZE) newlen = DEFAULT_BUF_SIZE; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } if (allocbytes != NULL) *allocbytes = WPACKET_get_curr(pkt); return 1; }
['int tls_construct_client_hello(SSL *s, WPACKET *pkt)\n{\n unsigned char *p;\n size_t sess_id_len;\n int i, protverr;\n#ifndef OPENSSL_NO_COMP\n SSL_COMP *comp;\n#endif\n SSL_SESSION *sess = s->session;\n unsigned char *session_id;\n protverr = ssl_set_client_hello_version(s);\n if (protverr != 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n protverr);\n return 0;\n }\n if (sess == NULL\n || !ssl_version_supported(s, sess->ssl_version, NULL)\n || !SSL_SESSION_is_resumable(sess)) {\n if (s->hello_retry_request == SSL_HRR_NONE\n && !ssl_get_new_session(s, 0)) {\n return 0;\n }\n }\n p = s->s3->client_random;\n if (SSL_IS_DTLS(s)) {\n size_t idx;\n i = 1;\n for (idx = 0; idx < sizeof(s->s3->client_random); idx++) {\n if (p[idx]) {\n i = 0;\n break;\n }\n }\n } else {\n i = (s->hello_retry_request == SSL_HRR_NONE);\n }\n if (i && ssl_fill_hello_random(s, 0, p, sizeof(s->s3->client_random),\n DOWNGRADE_NONE) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, s->client_version)\n || !WPACKET_memcpy(pkt, s->s3->client_random, SSL3_RANDOM_SIZE)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n session_id = s->session->session_id;\n if (s->new_session || s->session->ssl_version == TLS1_3_VERSION) {\n if (s->version == TLS1_3_VERSION\n && (s->options & SSL_OP_ENABLE_MIDDLEBOX_COMPAT) != 0) {\n sess_id_len = sizeof(s->tmp_session_id);\n s->tmp_session_id_len = sess_id_len;\n session_id = s->tmp_session_id;\n if (s->hello_retry_request == SSL_HRR_NONE\n && RAND_bytes(s->tmp_session_id, sess_id_len) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n } else {\n sess_id_len = 0;\n }\n } else {\n assert(s->session->session_id_length <= sizeof(s->session->session_id));\n sess_id_len = s->session->session_id_length;\n if (s->version == TLS1_3_VERSION) {\n s->tmp_session_id_len = sess_id_len;\n memcpy(s->tmp_session_id, s->session->session_id, sess_id_len);\n }\n }\n if (!WPACKET_start_sub_packet_u8(pkt)\n || (sess_id_len != 0 && !WPACKET_memcpy(pkt, session_id,\n sess_id_len))\n || !WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (SSL_IS_DTLS(s)) {\n if (s->d1->cookie_len > sizeof(s->d1->cookie)\n || !WPACKET_sub_memcpy_u8(pkt, s->d1->cookie,\n s->d1->cookie_len)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_start_sub_packet_u16(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), pkt)) {\n return 0;\n }\n if (!WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_start_sub_packet_u8(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n#ifndef OPENSSL_NO_COMP\n if (ssl_allow_compression(s)\n && s->ctx->comp_methods\n && (SSL_IS_DTLS(s) || s->s3->tmp.max_ver < TLS1_3_VERSION)) {\n int compnum = sk_SSL_COMP_num(s->ctx->comp_methods);\n for (i = 0; i < compnum; i++) {\n comp = sk_SSL_COMP_value(s->ctx->comp_methods, i);\n if (!WPACKET_put_bytes_u8(pkt, comp->id)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n }\n#endif\n if (!WPACKET_put_bytes_u8(pkt, 0) || !WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CLIENT_HELLO,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!tls_construct_extensions(s, pkt, SSL_EXT_CLIENT_HELLO, NULL, 0)) {\n return 0;\n }\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n if ((sub = OPENSSL_zalloc(sizeof(*sub))) == NULL) {\n SSLerr(SSL_F_WPACKET_START_SUB_PACKET_LEN__, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
1,589
0
https://github.com/libav/libav/blob/73b02e24604961e49a63ca34203d8f6c56612117/ffmpeg.c/#L3142
static void new_audio_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *audio_enc; int codec_id; st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); av_exit(1); } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO); bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters; audio_bitstream_filters= NULL; if(thread_count>1) avcodec_thread_init(st->codec, thread_count); audio_enc = st->codec; audio_enc->codec_type = CODEC_TYPE_AUDIO; if(audio_codec_tag) audio_enc->codec_tag= audio_codec_tag; if (oc->oformat->flags & AVFMT_GLOBALHEADER) { audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER; } if (audio_stream_copy) { st->stream_copy = 1; audio_enc->channels = audio_channels; } else { AVCodec *codec; set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); if (audio_codec_name) { codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1); codec = avcodec_find_encoder_by_name(audio_codec_name); output_codecs[nb_ocodecs] = codec; } else { codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO); codec = avcodec_find_encoder(codec_id); } audio_enc->codec_id = codec_id; if (audio_qscale > QSCALE_NONE) { audio_enc->flags |= CODEC_FLAG_QSCALE; audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale; } audio_enc->thread_count = thread_count; audio_enc->channels = audio_channels; audio_enc->sample_fmt = audio_sample_fmt; audio_enc->channel_layout = channel_layout; if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels) audio_enc->channel_layout = 0; if(codec && codec->sample_fmts){ const enum SampleFormat *p= codec->sample_fmts; for(; *p!=-1; p++){ if(*p == audio_enc->sample_fmt) break; } if(*p == -1) audio_enc->sample_fmt = codec->sample_fmts[0]; } } nb_ocodecs++; audio_enc->sample_rate = audio_sample_rate; audio_enc->time_base= (AVRational){1, audio_sample_rate}; if (audio_language) { av_metadata_set(&st->metadata, "language", audio_language); av_free(audio_language); audio_language = NULL; } audio_disable = 0; av_freep(&audio_codec_name); audio_stream_copy = 0; }
['static void new_audio_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *audio_enc;\n int codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;\n audio_bitstream_filters= NULL;\n if(thread_count>1)\n avcodec_thread_init(st->codec, thread_count);\n audio_enc = st->codec;\n audio_enc->codec_type = CODEC_TYPE_AUDIO;\n if(audio_codec_tag)\n audio_enc->codec_tag= audio_codec_tag;\n if (oc->oformat->flags & AVFMT_GLOBALHEADER) {\n audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if (audio_stream_copy) {\n st->stream_copy = 1;\n audio_enc->channels = audio_channels;\n } else {\n AVCodec *codec;\n set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (audio_codec_name) {\n codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);\n codec = avcodec_find_encoder_by_name(audio_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);\n codec = avcodec_find_encoder(codec_id);\n }\n audio_enc->codec_id = codec_id;\n if (audio_qscale > QSCALE_NONE) {\n audio_enc->flags |= CODEC_FLAG_QSCALE;\n audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;\n }\n audio_enc->thread_count = thread_count;\n audio_enc->channels = audio_channels;\n audio_enc->sample_fmt = audio_sample_fmt;\n audio_enc->channel_layout = channel_layout;\n if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)\n audio_enc->channel_layout = 0;\n if(codec && codec->sample_fmts){\n const enum SampleFormat *p= codec->sample_fmts;\n for(; *p!=-1; p++){\n if(*p == audio_enc->sample_fmt)\n break;\n }\n if(*p == -1)\n audio_enc->sample_fmt = codec->sample_fmts[0];\n }\n }\n nb_ocodecs++;\n audio_enc->sample_rate = audio_sample_rate;\n audio_enc->time_base= (AVRational){1, audio_sample_rate};\n if (audio_language) {\n av_metadata_set(&st->metadata, "language", audio_language);\n av_free(audio_language);\n audio_language = NULL;\n }\n audio_disable = 0;\n av_freep(&audio_codec_name);\n audio_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n 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}']
1,590
0
https://github.com/openssl/openssl/blob/0f3e6045898e9aa5d0249e61c874b1f153ae54fa/crypto/asn1/x_req.c/#L204
X509_REQ *X509_REQ_new(void) { X509_REQ *ret=NULL; ASN1_CTX c; M_ASN1_New_Malloc(ret,X509_REQ); ret->references=1; M_ASN1_New(ret->req_info,X509_REQ_INFO_new); M_ASN1_New(ret->sig_alg,X509_ALGOR_new); M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); return(ret); M_ASN1_New_Error(ASN1_F_X509_REQ_NEW); }
['X509_REQ *X509_REQ_new(void)\n\t{\n\tX509_REQ *ret=NULL;\n\tASN1_CTX c;\n\tM_ASN1_New_Malloc(ret,X509_REQ);\n\tret->references=1;\n\tM_ASN1_New(ret->req_info,X509_REQ_INFO_new);\n\tM_ASN1_New(ret->sig_alg,X509_ALGOR_new);\n\tM_ASN1_New(ret->signature,ASN1_BIT_STRING_new);\n\treturn(ret);\n\tM_ASN1_New_Error(ASN1_F_X509_REQ_NEW);\n\t}']
1,591
0
https://github.com/libav/libav/blob/046f081b46c8479820409cf8f530b988221bd15b/ffmpeg.c/#L4195
static int opt_preset(const char *opt, const char *arg) { FILE *f=NULL; char filename[1000], tmp[1000], tmp2[1000], line[1000]; char *codec_name = *opt == 'v' ? video_codec_name : *opt == 'a' ? audio_codec_name : subtitle_codec_name; if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) { fprintf(stderr, "File for preset '%s' not found\n", arg); ffmpeg_exit(1); } while(!feof(f)){ int e= fscanf(f, "%999[^\n]\n", line) - 1; if(line[0] == '#' && !e) continue; e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2; if(e){ fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line); ffmpeg_exit(1); } if(!strcmp(tmp, "acodec")){ opt_audio_codec(tmp2); }else if(!strcmp(tmp, "vcodec")){ opt_video_codec(tmp2); }else if(!strcmp(tmp, "scodec")){ opt_subtitle_codec(tmp2); }else if(!strcmp(tmp, "dcodec")){ opt_data_codec(tmp2); }else if(opt_default(tmp, tmp2) < 0){ fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2); ffmpeg_exit(1); } } fclose(f); return 0; }
['static int opt_preset(const char *opt, const char *arg)\n{\n FILE *f=NULL;\n char filename[1000], tmp[1000], tmp2[1000], line[1000];\n char *codec_name = *opt == \'v\' ? video_codec_name :\n *opt == \'a\' ? audio_codec_name :\n subtitle_codec_name;\n if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == \'f\', codec_name))) {\n fprintf(stderr, "File for preset \'%s\' not found\\n", arg);\n ffmpeg_exit(1);\n }\n while(!feof(f)){\n int e= fscanf(f, "%999[^\\n]\\n", line) - 1;\n if(line[0] == \'#\' && !e)\n continue;\n e|= sscanf(line, "%999[^=]=%999[^\\n]\\n", tmp, tmp2) - 2;\n if(e){\n fprintf(stderr, "%s: Invalid syntax: \'%s\'\\n", filename, line);\n ffmpeg_exit(1);\n }\n if(!strcmp(tmp, "acodec")){\n opt_audio_codec(tmp2);\n }else if(!strcmp(tmp, "vcodec")){\n opt_video_codec(tmp2);\n }else if(!strcmp(tmp, "scodec")){\n opt_subtitle_codec(tmp2);\n }else if(!strcmp(tmp, "dcodec")){\n opt_data_codec(tmp2);\n }else if(opt_default(tmp, tmp2) < 0){\n fprintf(stderr, "%s: Invalid option or argument: \'%s\', parsed as \'%s\' = \'%s\'\\n", filename, line, tmp, tmp2);\n ffmpeg_exit(1);\n }\n }\n fclose(f);\n return 0;\n}']
1,592
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/ssl/t1_lib.c/#L1418
unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned char *limit, int *al) { int extdatalen = 0; unsigned char *orig = buf; unsigned char *ret = buf; #ifndef OPENSSL_NO_EC int using_ecc = 0; if (s->version >= TLS1_VERSION || SSL_IS_DTLS(s)) { int i; unsigned long alg_k, alg_a; STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s); for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) { const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i); alg_k = c->algorithm_mkey; alg_a = c->algorithm_auth; if ((alg_k & (SSL_kECDHE | SSL_kECDHr | SSL_kECDHe | SSL_kECDHEPSK) || (alg_a & SSL_aECDSA))) { using_ecc = 1; break; } } } #endif ret += 2; if (ret >= limit) return NULL; if (s->renegotiate) { int el; if (!ssl_add_clienthello_renegotiate_ext(s, 0, &el, 0)) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } if ((limit - ret - 4 - el) < 0) return NULL; s2n(TLSEXT_TYPE_renegotiate, ret); s2n(el, ret); if (!ssl_add_clienthello_renegotiate_ext(s, ret, &el, el)) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } ret += el; } if (s->client_version == SSL3_VERSION) goto done; if (s->tlsext_hostname != NULL) { unsigned long size_str; long lenmax; if ((lenmax = limit - ret - 9) < 0 || (size_str = strlen(s->tlsext_hostname)) > (unsigned long)lenmax) return NULL; s2n(TLSEXT_TYPE_server_name, ret); s2n(size_str + 5, ret); s2n(size_str + 3, ret); *(ret++) = (unsigned char)TLSEXT_NAMETYPE_host_name; s2n(size_str, ret); memcpy(ret, s->tlsext_hostname, size_str); ret += size_str; } #ifndef OPENSSL_NO_SRP if (s->srp_ctx.login != NULL) { int login_len = strlen(s->srp_ctx.login); if (login_len > 255 || login_len == 0) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } if ((limit - ret - 5 - login_len) < 0) return NULL; s2n(TLSEXT_TYPE_srp, ret); s2n(login_len + 1, ret); (*ret++) = (unsigned char)login_len; memcpy(ret, s->srp_ctx.login, login_len); ret += login_len; } #endif #ifndef OPENSSL_NO_EC if (using_ecc) { long lenmax; const unsigned char *pcurves, *pformats; size_t num_curves, num_formats, curves_list_len; size_t i; unsigned char *etmp; tls1_get_formatlist(s, &pformats, &num_formats); if ((lenmax = limit - ret - 5) < 0) return NULL; if (num_formats > (size_t)lenmax) return NULL; if (num_formats > 255) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } s2n(TLSEXT_TYPE_ec_point_formats, ret); s2n(num_formats + 1, ret); *(ret++) = (unsigned char)num_formats; memcpy(ret, pformats, num_formats); ret += num_formats; pcurves = s->tlsext_ellipticcurvelist; if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves)) return NULL; if ((lenmax = limit - ret - 6) < 0) return NULL; if (num_curves > (size_t)lenmax / 2) return NULL; if (num_curves > 65532 / 2) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } s2n(TLSEXT_TYPE_elliptic_curves, ret); etmp = ret + 4; for (i = 0; i < num_curves; i++, pcurves += 2) { if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) { *etmp++ = pcurves[0]; *etmp++ = pcurves[1]; } } curves_list_len = etmp - ret - 4; s2n(curves_list_len + 2, ret); s2n(curves_list_len, ret); ret += curves_list_len; } #endif if (tls_use_ticket(s)) { int ticklen; if (!s->new_session && s->session && s->session->tlsext_tick) ticklen = s->session->tlsext_ticklen; else if (s->session && s->tlsext_session_ticket && s->tlsext_session_ticket->data) { ticklen = s->tlsext_session_ticket->length; s->session->tlsext_tick = OPENSSL_malloc(ticklen); if (s->session->tlsext_tick == NULL) return NULL; memcpy(s->session->tlsext_tick, s->tlsext_session_ticket->data, ticklen); s->session->tlsext_ticklen = ticklen; } else ticklen = 0; if (ticklen == 0 && s->tlsext_session_ticket && s->tlsext_session_ticket->data == NULL) goto skip_ext; if ((long)(limit - ret - 4 - ticklen) < 0) return NULL; s2n(TLSEXT_TYPE_session_ticket, ret); s2n(ticklen, ret); if (ticklen) { memcpy(ret, s->session->tlsext_tick, ticklen); ret += ticklen; } } skip_ext: if (SSL_USE_SIGALGS(s)) { size_t salglen; const unsigned char *salg; unsigned char *etmp; salglen = tls12_get_psigalgs(s, &salg); if ((size_t)(limit - ret) < salglen + 6) return NULL; s2n(TLSEXT_TYPE_signature_algorithms, ret); etmp = ret; ret += 4; salglen = tls12_copy_sigalgs(s, ret, salg, salglen); s2n(salglen + 2, etmp); s2n(salglen, etmp); ret += salglen; } if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) { int i; long extlen, idlen, itmp; OCSP_RESPID *id; idlen = 0; for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) { id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i); itmp = i2d_OCSP_RESPID(id, NULL); if (itmp <= 0) return NULL; idlen += itmp + 2; } if (s->tlsext_ocsp_exts) { extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL); if (extlen < 0) return NULL; } else extlen = 0; if ((long)(limit - ret - 7 - extlen - idlen) < 0) return NULL; s2n(TLSEXT_TYPE_status_request, ret); if (extlen + idlen > 0xFFF0) return NULL; s2n(extlen + idlen + 5, ret); *(ret++) = TLSEXT_STATUSTYPE_ocsp; s2n(idlen, ret); for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) { unsigned char *q = ret; id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i); ret += 2; itmp = i2d_OCSP_RESPID(id, &ret); s2n(itmp, q); } s2n(extlen, ret); if (extlen > 0) i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ret); } #ifndef OPENSSL_NO_HEARTBEATS if ((limit - ret - 4 - 1) < 0) return NULL; s2n(TLSEXT_TYPE_heartbeat, ret); s2n(1, ret); if (s->tlsext_heartbeat & SSL_TLSEXT_HB_DONT_RECV_REQUESTS) *(ret++) = SSL_TLSEXT_HB_DONT_SEND_REQUESTS; else *(ret++) = SSL_TLSEXT_HB_ENABLED; #endif #ifndef OPENSSL_NO_NEXTPROTONEG if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) { if (limit - ret - 4 < 0) return NULL; s2n(TLSEXT_TYPE_next_proto_neg, ret); s2n(0, ret); } #endif if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) { if ((size_t)(limit - ret) < 6 + s->alpn_client_proto_list_len) return NULL; s2n(TLSEXT_TYPE_application_layer_protocol_negotiation, ret); s2n(2 + s->alpn_client_proto_list_len, ret); s2n(s->alpn_client_proto_list_len, ret); memcpy(ret, s->alpn_client_proto_list, s->alpn_client_proto_list_len); ret += s->alpn_client_proto_list_len; } #ifndef OPENSSL_NO_SRTP if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) { int el; if (ssl_add_clienthello_use_srtp_ext(s, 0, &el, 0)) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } if ((limit - ret - 4 - el) < 0) return NULL; s2n(TLSEXT_TYPE_use_srtp, ret); s2n(el, ret); if (ssl_add_clienthello_use_srtp_ext(s, ret, &el, el)) { SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR); return NULL; } ret += el; } #endif custom_ext_init(&s->cert->cli_ext); if (!custom_ext_add(s, 0, &ret, limit, al)) return NULL; #ifdef TLSEXT_TYPE_encrypt_then_mac s2n(TLSEXT_TYPE_encrypt_then_mac, ret); s2n(0, ret); #endif s2n(TLSEXT_TYPE_extended_master_secret, ret); s2n(0, ret); if (s->options & SSL_OP_TLSEXT_PADDING) { int hlen = ret - (unsigned char *)s->init_buf->data; if (hlen > 0xff && hlen < 0x200) { hlen = 0x200 - hlen; if (hlen >= 4) hlen -= 4; else hlen = 0; s2n(TLSEXT_TYPE_padding, ret); s2n(hlen, ret); memset(ret, 0, hlen); ret += hlen; } } done: if ((extdatalen = ret - orig - 2) == 0) return orig; s2n(extdatalen, orig); return ret; }
['unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf,\n unsigned char *limit, int *al)\n{\n int extdatalen = 0;\n unsigned char *orig = buf;\n unsigned char *ret = buf;\n#ifndef OPENSSL_NO_EC\n int using_ecc = 0;\n if (s->version >= TLS1_VERSION || SSL_IS_DTLS(s)) {\n int i;\n unsigned long alg_k, alg_a;\n STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {\n const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n alg_k = c->algorithm_mkey;\n alg_a = c->algorithm_auth;\n if ((alg_k & (SSL_kECDHE | SSL_kECDHr | SSL_kECDHe | SSL_kECDHEPSK)\n || (alg_a & SSL_aECDSA))) {\n using_ecc = 1;\n break;\n }\n }\n }\n#endif\n ret += 2;\n if (ret >= limit)\n return NULL;\n if (s->renegotiate) {\n int el;\n if (!ssl_add_clienthello_renegotiate_ext(s, 0, &el, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n if ((limit - ret - 4 - el) < 0)\n return NULL;\n s2n(TLSEXT_TYPE_renegotiate, ret);\n s2n(el, ret);\n if (!ssl_add_clienthello_renegotiate_ext(s, ret, &el, el)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n ret += el;\n }\n if (s->client_version == SSL3_VERSION)\n goto done;\n if (s->tlsext_hostname != NULL) {\n unsigned long size_str;\n long lenmax;\n if ((lenmax = limit - ret - 9) < 0\n || (size_str =\n strlen(s->tlsext_hostname)) > (unsigned long)lenmax)\n return NULL;\n s2n(TLSEXT_TYPE_server_name, ret);\n s2n(size_str + 5, ret);\n s2n(size_str + 3, ret);\n *(ret++) = (unsigned char)TLSEXT_NAMETYPE_host_name;\n s2n(size_str, ret);\n memcpy(ret, s->tlsext_hostname, size_str);\n ret += size_str;\n }\n#ifndef OPENSSL_NO_SRP\n if (s->srp_ctx.login != NULL) {\n int login_len = strlen(s->srp_ctx.login);\n if (login_len > 255 || login_len == 0) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n if ((limit - ret - 5 - login_len) < 0)\n return NULL;\n s2n(TLSEXT_TYPE_srp, ret);\n s2n(login_len + 1, ret);\n (*ret++) = (unsigned char)login_len;\n memcpy(ret, s->srp_ctx.login, login_len);\n ret += login_len;\n }\n#endif\n#ifndef OPENSSL_NO_EC\n if (using_ecc) {\n long lenmax;\n const unsigned char *pcurves, *pformats;\n size_t num_curves, num_formats, curves_list_len;\n size_t i;\n unsigned char *etmp;\n tls1_get_formatlist(s, &pformats, &num_formats);\n if ((lenmax = limit - ret - 5) < 0)\n return NULL;\n if (num_formats > (size_t)lenmax)\n return NULL;\n if (num_formats > 255) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n s2n(TLSEXT_TYPE_ec_point_formats, ret);\n s2n(num_formats + 1, ret);\n *(ret++) = (unsigned char)num_formats;\n memcpy(ret, pformats, num_formats);\n ret += num_formats;\n pcurves = s->tlsext_ellipticcurvelist;\n if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves))\n return NULL;\n if ((lenmax = limit - ret - 6) < 0)\n return NULL;\n if (num_curves > (size_t)lenmax / 2)\n return NULL;\n if (num_curves > 65532 / 2) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n s2n(TLSEXT_TYPE_elliptic_curves, ret);\n etmp = ret + 4;\n for (i = 0; i < num_curves; i++, pcurves += 2) {\n if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n *etmp++ = pcurves[0];\n *etmp++ = pcurves[1];\n }\n }\n curves_list_len = etmp - ret - 4;\n s2n(curves_list_len + 2, ret);\n s2n(curves_list_len, ret);\n ret += curves_list_len;\n }\n#endif\n if (tls_use_ticket(s)) {\n int ticklen;\n if (!s->new_session && s->session && s->session->tlsext_tick)\n ticklen = s->session->tlsext_ticklen;\n else if (s->session && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data) {\n ticklen = s->tlsext_session_ticket->length;\n s->session->tlsext_tick = OPENSSL_malloc(ticklen);\n if (s->session->tlsext_tick == NULL)\n return NULL;\n memcpy(s->session->tlsext_tick,\n s->tlsext_session_ticket->data, ticklen);\n s->session->tlsext_ticklen = ticklen;\n } else\n ticklen = 0;\n if (ticklen == 0 && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data == NULL)\n goto skip_ext;\n if ((long)(limit - ret - 4 - ticklen) < 0)\n return NULL;\n s2n(TLSEXT_TYPE_session_ticket, ret);\n s2n(ticklen, ret);\n if (ticklen) {\n memcpy(ret, s->session->tlsext_tick, ticklen);\n ret += ticklen;\n }\n }\n skip_ext:\n if (SSL_USE_SIGALGS(s)) {\n size_t salglen;\n const unsigned char *salg;\n unsigned char *etmp;\n salglen = tls12_get_psigalgs(s, &salg);\n if ((size_t)(limit - ret) < salglen + 6)\n return NULL;\n s2n(TLSEXT_TYPE_signature_algorithms, ret);\n etmp = ret;\n ret += 4;\n salglen = tls12_copy_sigalgs(s, ret, salg, salglen);\n s2n(salglen + 2, etmp);\n s2n(salglen, etmp);\n ret += salglen;\n }\n if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) {\n int i;\n long extlen, idlen, itmp;\n OCSP_RESPID *id;\n idlen = 0;\n for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n itmp = i2d_OCSP_RESPID(id, NULL);\n if (itmp <= 0)\n return NULL;\n idlen += itmp + 2;\n }\n if (s->tlsext_ocsp_exts) {\n extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n if (extlen < 0)\n return NULL;\n } else\n extlen = 0;\n if ((long)(limit - ret - 7 - extlen - idlen) < 0)\n return NULL;\n s2n(TLSEXT_TYPE_status_request, ret);\n if (extlen + idlen > 0xFFF0)\n return NULL;\n s2n(extlen + idlen + 5, ret);\n *(ret++) = TLSEXT_STATUSTYPE_ocsp;\n s2n(idlen, ret);\n for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n unsigned char *q = ret;\n id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n ret += 2;\n itmp = i2d_OCSP_RESPID(id, &ret);\n s2n(itmp, q);\n }\n s2n(extlen, ret);\n if (extlen > 0)\n i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ret);\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if ((limit - ret - 4 - 1) < 0)\n return NULL;\n s2n(TLSEXT_TYPE_heartbeat, ret);\n s2n(1, ret);\n if (s->tlsext_heartbeat & SSL_TLSEXT_HB_DONT_RECV_REQUESTS)\n *(ret++) = SSL_TLSEXT_HB_DONT_SEND_REQUESTS;\n else\n *(ret++) = SSL_TLSEXT_HB_ENABLED;\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) {\n if (limit - ret - 4 < 0)\n return NULL;\n s2n(TLSEXT_TYPE_next_proto_neg, ret);\n s2n(0, ret);\n }\n#endif\n if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) {\n if ((size_t)(limit - ret) < 6 + s->alpn_client_proto_list_len)\n return NULL;\n s2n(TLSEXT_TYPE_application_layer_protocol_negotiation, ret);\n s2n(2 + s->alpn_client_proto_list_len, ret);\n s2n(s->alpn_client_proto_list_len, ret);\n memcpy(ret, s->alpn_client_proto_list, s->alpn_client_proto_list_len);\n ret += s->alpn_client_proto_list_len;\n }\n#ifndef OPENSSL_NO_SRTP\n if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) {\n int el;\n if (ssl_add_clienthello_use_srtp_ext(s, 0, &el, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n if ((limit - ret - 4 - el) < 0)\n return NULL;\n s2n(TLSEXT_TYPE_use_srtp, ret);\n s2n(el, ret);\n if (ssl_add_clienthello_use_srtp_ext(s, ret, &el, el)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return NULL;\n }\n ret += el;\n }\n#endif\n custom_ext_init(&s->cert->cli_ext);\n if (!custom_ext_add(s, 0, &ret, limit, al))\n return NULL;\n#ifdef TLSEXT_TYPE_encrypt_then_mac\n s2n(TLSEXT_TYPE_encrypt_then_mac, ret);\n s2n(0, ret);\n#endif\n s2n(TLSEXT_TYPE_extended_master_secret, ret);\n s2n(0, ret);\n if (s->options & SSL_OP_TLSEXT_PADDING) {\n int hlen = ret - (unsigned char *)s->init_buf->data;\n if (hlen > 0xff && hlen < 0x200) {\n hlen = 0x200 - hlen;\n if (hlen >= 4)\n hlen -= 4;\n else\n hlen = 0;\n s2n(TLSEXT_TYPE_padding, ret);\n s2n(hlen, ret);\n memset(ret, 0, hlen);\n ret += hlen;\n }\n }\n done:\n if ((extdatalen = ret - orig - 2) == 0)\n return orig;\n s2n(extdatalen, orig);\n return ret;\n}']
1,593
0
https://github.com/openssl/openssl/blob/846ec07d904f9cc81d486db0db14fb84f61ff6e5/crypto/mem.c/#L245
void CRYPTO_free(void *str) { #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0); free(str); CRYPTO_mem_debug_free(str, 1); } else { free(str); } #else free(str); #endif }
['int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,\n int len)\n{\n static const unsigned char *salt[3] = {\n#ifndef CHARSET_EBCDIC\n (const unsigned char *)"A",\n (const unsigned char *)"BB",\n (const unsigned char *)"CCC",\n#else\n (const unsigned char *)"\\x41",\n (const unsigned char *)"\\x42\\x42",\n (const unsigned char *)"\\x43\\x43\\x43",\n#endif\n };\n unsigned char buf[EVP_MAX_MD_SIZE];\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n int i, ret = 0;\n unsigned int n;\n#ifdef OPENSSL_SSL_TRACE_CRYPTO\n unsigned char *tmpout = out;\n#endif\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n for (i = 0; i < 3; i++) {\n if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0\n || EVP_DigestUpdate(ctx, salt[i],\n strlen((const char *)salt[i])) <= 0\n || EVP_DigestUpdate(ctx, p, len) <= 0\n || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_DigestFinal_ex(ctx, buf, &n) <= 0\n || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0\n || EVP_DigestUpdate(ctx, p, len) <= 0\n || EVP_DigestUpdate(ctx, buf, n) <= 0\n || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {\n SSLerr(SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);\n ret = 0;\n break;\n }\n out += n;\n ret += n;\n }\n EVP_MD_CTX_free(ctx);\n#ifdef OPENSSL_SSL_TRACE_CRYPTO\n if (ret > 0 && s->msg_callback) {\n s->msg_callback(2, s->version, TLS1_RT_CRYPTO_PREMASTER,\n p, len, s, s->msg_callback_arg);\n s->msg_callback(2, s->version, TLS1_RT_CRYPTO_CLIENT_RANDOM,\n s->s3->client_random, SSL3_RANDOM_SIZE,\n s, s->msg_callback_arg);\n s->msg_callback(2, s->version, TLS1_RT_CRYPTO_SERVER_RANDOM,\n s->s3->server_random, SSL3_RANDOM_SIZE,\n s, s->msg_callback_arg);\n s->msg_callback(2, s->version, TLS1_RT_CRYPTO_MASTER,\n tmpout, SSL3_MASTER_SECRET_SIZE,\n s, s->msg_callback_arg);\n }\n#endif\n OPENSSL_cleanse(buf, sizeof(buf));\n return (ret);\n}', 'int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)\n{\n EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n#ifndef OPENSSL_NO_ENGINE\n if (ctx->engine && ctx->digest && (!type ||\n (type\n && (type->type ==\n ctx->digest->type))))\n goto skip_to_init;\n if (type) {\n if (ctx->engine)\n ENGINE_finish(ctx->engine);\n if (impl) {\n if (!ENGINE_init(impl)) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n return 0;\n }\n } else\n impl = ENGINE_get_digest_engine(type->type);\n if (impl) {\n const EVP_MD *d = ENGINE_get_digest(impl, type->type);\n if (!d) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n ENGINE_finish(impl);\n return 0;\n }\n type = d;\n ctx->engine = impl;\n } else\n ctx->engine = NULL;\n } else {\n if (!ctx->digest) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);\n return 0;\n }\n type = ctx->digest;\n }\n#endif\n if (ctx->digest != type) {\n if (ctx->digest && ctx->digest->ctx_size)\n OPENSSL_free(ctx->md_data);\n ctx->digest = type;\n if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {\n ctx->update = type->update;\n ctx->md_data = OPENSSL_malloc(type->ctx_size);\n if (ctx->md_data == NULL) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n }\n#ifndef OPENSSL_NO_ENGINE\n skip_to_init:\n#endif\n if (ctx->pctx) {\n int r;\n r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,\n EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);\n if (r <= 0 && (r != -2))\n return 0;\n }\n if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)\n return 1;\n return ctx->digest->init(ctx);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
1,594
0
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L901
PUT_HEVC_QPEL_HV(1, 1)
['QPEL(12)', 'PUT_HEVC_QPEL_HV(1, 1)']
1,595
0
https://github.com/libav/libav/blob/53c20f17c78d1d8a0fc2505868f201e69ff59cc5/libavcodec/vp8dsp.c/#L105
static void vp8_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride) { int i, t0, t1, t2, t3; int16_t tmp[16]; for (i = 0; i < 4; i++) { t0 = block[0 * 4 + i] + block[2 * 4 + i]; t1 = block[0 * 4 + i] - block[2 * 4 + i]; t2 = MUL_35468(block[1 * 4 + i]) - MUL_20091(block[3 * 4 + i]); t3 = MUL_20091(block[1 * 4 + i]) + MUL_35468(block[3 * 4 + i]); block[0 * 4 + i] = 0; block[1 * 4 + i] = 0; block[2 * 4 + i] = 0; block[3 * 4 + i] = 0; tmp[i * 4 + 0] = t0 + t3; tmp[i * 4 + 1] = t1 + t2; tmp[i * 4 + 2] = t1 - t2; tmp[i * 4 + 3] = t0 - t3; } for (i = 0; i < 4; i++) { t0 = tmp[0 * 4 + i] + tmp[2 * 4 + i]; t1 = tmp[0 * 4 + i] - tmp[2 * 4 + i]; t2 = MUL_35468(tmp[1 * 4 + i]) - MUL_20091(tmp[3 * 4 + i]); t3 = MUL_20091(tmp[1 * 4 + i]) + MUL_35468(tmp[3 * 4 + i]); dst[0] = av_clip_uint8(dst[0] + ((t0 + t3 + 4) >> 3)); dst[1] = av_clip_uint8(dst[1] + ((t1 + t2 + 4) >> 3)); dst[2] = av_clip_uint8(dst[2] + ((t1 - t2 + 4) >> 3)); dst[3] = av_clip_uint8(dst[3] + ((t0 - t3 + 4) >> 3)); dst += stride; } }
['static void vp8_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)\n{\n int i, t0, t1, t2, t3;\n int16_t tmp[16];\n for (i = 0; i < 4; i++) {\n t0 = block[0 * 4 + i] + block[2 * 4 + i];\n t1 = block[0 * 4 + i] - block[2 * 4 + i];\n t2 = MUL_35468(block[1 * 4 + i]) - MUL_20091(block[3 * 4 + i]);\n t3 = MUL_20091(block[1 * 4 + i]) + MUL_35468(block[3 * 4 + i]);\n block[0 * 4 + i] = 0;\n block[1 * 4 + i] = 0;\n block[2 * 4 + i] = 0;\n block[3 * 4 + i] = 0;\n tmp[i * 4 + 0] = t0 + t3;\n tmp[i * 4 + 1] = t1 + t2;\n tmp[i * 4 + 2] = t1 - t2;\n tmp[i * 4 + 3] = t0 - t3;\n }\n for (i = 0; i < 4; i++) {\n t0 = tmp[0 * 4 + i] + tmp[2 * 4 + i];\n t1 = tmp[0 * 4 + i] - tmp[2 * 4 + i];\n t2 = MUL_35468(tmp[1 * 4 + i]) - MUL_20091(tmp[3 * 4 + i]);\n t3 = MUL_20091(tmp[1 * 4 + i]) + MUL_35468(tmp[3 * 4 + i]);\n dst[0] = av_clip_uint8(dst[0] + ((t0 + t3 + 4) >> 3));\n dst[1] = av_clip_uint8(dst[1] + ((t1 + t2 + 4) >> 3));\n dst[2] = av_clip_uint8(dst[2] + ((t1 - t2 + 4) >> 3));\n dst[3] = av_clip_uint8(dst[3] + ((t0 - t3 + 4) >> 3));\n dst += stride;\n }\n}']
1,596
0
https://github.com/libav/libav/blob/4cd19f6e7851ee6afb08eb346c82d5574fa2b699/libavcodec/ra288.c/#L184
static int ra288_decode_frame(AVCodecContext * avctx, void *data, int *data_size, const uint8_t * buf, int buf_size) { float *out = data; int i, j; RA288Context *ractx = avctx->priv_data; GetBitContext gb; if (buf_size < avctx->block_align) { av_log(avctx, AV_LOG_ERROR, "Error! Input buffer is too small [%d<%d]\n", buf_size, avctx->block_align); return 0; } if (*data_size < 32*5*4) return -1; init_get_bits(&gb, buf, avctx->block_align * 8); for (i=0; i < 32; i++) { float gain = amptable[get_bits(&gb, 3)]; int cb_coef = get_bits(&gb, 6 + (i&1)); decode(ractx, gain, cb_coef); for (j=0; j < 5; j++) *(out++) = ractx->sp_hist[70 + 36 + j]; if ((i & 7) == 3) { backward_filter(ractx->sp_hist, ractx->sp_rec, syn_window, ractx->sp_lpc, syn_bw_tab, 36, 40, 35, 70); backward_filter(ractx->gain_hist, ractx->gain_rec, gain_window, ractx->gain_lpc, gain_bw_tab, 10, 8, 20, 28); } } *data_size = (char *)out - (char *)data; return avctx->block_align; }
['static int ra288_decode_frame(AVCodecContext * avctx, void *data,\n int *data_size, const uint8_t * buf,\n int buf_size)\n{\n float *out = data;\n int i, j;\n RA288Context *ractx = avctx->priv_data;\n GetBitContext gb;\n if (buf_size < avctx->block_align) {\n av_log(avctx, AV_LOG_ERROR,\n "Error! Input buffer is too small [%d<%d]\\n",\n buf_size, avctx->block_align);\n return 0;\n }\n if (*data_size < 32*5*4)\n return -1;\n init_get_bits(&gb, buf, avctx->block_align * 8);\n for (i=0; i < 32; i++) {\n float gain = amptable[get_bits(&gb, 3)];\n int cb_coef = get_bits(&gb, 6 + (i&1));\n decode(ractx, gain, cb_coef);\n for (j=0; j < 5; j++)\n *(out++) = ractx->sp_hist[70 + 36 + j];\n if ((i & 7) == 3) {\n backward_filter(ractx->sp_hist, ractx->sp_rec, syn_window,\n ractx->sp_lpc, syn_bw_tab, 36, 40, 35, 70);\n backward_filter(ractx->gain_hist, ractx->gain_rec, gain_window,\n ractx->gain_lpc, gain_bw_tab, 10, 8, 20, 28);\n }\n }\n *data_size = (char *)out - (char *)data;\n return avctx->block_align;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_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}']
1,597
0
https://github.com/openssl/openssl/blob/8839324450b569a6253e0dd237ee3e417ef17771/crypto/mem.c/#L312
void CRYPTO_free(void *str, const char *file, int line) { INCREMENT(free_count); if (free_impl != NULL && free_impl != &CRYPTO_free) { free_impl(str, file, line); return; } #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 ssl_ctx_make_profiles(const char *profiles_string,\n STACK_OF(SRTP_PROTECTION_PROFILE) **out)\n{\n STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;\n char *col;\n char *ptr = (char *)profiles_string;\n SRTP_PROTECTION_PROFILE *p;\n if ((profiles = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL) {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);\n return 1;\n }\n do {\n col = strchr(ptr, ':');\n if (!find_profile_by_name(ptr, &p, col ? (size_t)(col - ptr)\n : strlen(ptr))) {\n if (sk_SRTP_PROTECTION_PROFILE_find(profiles, p) >= 0) {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);\n goto err;\n }\n if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, p)) {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);\n goto err;\n }\n } else {\n SSLerr(SSL_F_SSL_CTX_MAKE_PROFILES,\n SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);\n goto err;\n }\n if (col)\n ptr = col + 1;\n } while (col);\n sk_SRTP_PROTECTION_PROFILE_free(*out);\n *out = profiles;\n return 0;\n err:\n sk_SRTP_PROTECTION_PROFILE_free(profiles);\n return 1;\n}", 'DEFINE_STACK_OF(SRTP_PROTECTION_PROFILE)', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n return OPENSSL_sk_insert(st, data, st->num);\n}', 'int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)\n{\n if (st->num == max_nodes)\n return 0;\n if (!sk_reserve(st, 1, 0))\n return 0;\n if ((loc >= st->num) || (loc < 0)) {\n st->data[st->num] = data;\n } else {\n memmove(&st->data[loc + 1], &st->data[loc],\n sizeof(st->data[0]) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return st->num;\n}', 'static int sk_reserve(OPENSSL_STACK *st, int n, int exact)\n{\n const void **tmpdata;\n int num_alloc;\n if (n > max_nodes - st->num)\n return 0;\n num_alloc = st->num + n;\n if (num_alloc < min_nodes)\n num_alloc = min_nodes;\n if (st->data == NULL) {\n if ((st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc)) == NULL) {\n CRYPTOerr(CRYPTO_F_SK_RESERVE, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n st->num_alloc = num_alloc;\n return 1;\n }\n if (!exact) {\n if (num_alloc <= st->num_alloc)\n return 1;\n num_alloc = compute_growth(num_alloc, st->num_alloc);\n if (num_alloc == 0)\n return 0;\n } else if (num_alloc == st->num_alloc) {\n return 1;\n }\n tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);\n if (tmpdata == NULL)\n return 0;\n st->data = tmpdata;\n st->num_alloc = num_alloc;\n return 1;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n INCREMENT(realloc_count);\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n FAILTEST();\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)(file); (void)(line);\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#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}']
1,598
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['static int dh_builtin_genparams(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n BIGNUM *t1, *t2;\n int g, ok = -1;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (!ret->p && ((ret->p = BN_new()) == NULL))\n goto err;\n if (!ret->g && ((ret->g = BN_new()) == NULL))\n goto err;\n if (generator <= 1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);\n goto err;\n }\n if (generator == DH_GENERATOR_2) {\n if (!BN_set_word(t1, 24))\n goto err;\n if (!BN_set_word(t2, 11))\n goto err;\n g = 2;\n } else if (generator == DH_GENERATOR_5) {\n if (!BN_set_word(t1, 10))\n goto err;\n if (!BN_set_word(t2, 3))\n goto err;\n g = 5;\n } else {\n if (!BN_set_word(t1, 2))\n goto err;\n if (!BN_set_word(t2, 1))\n goto err;\n g = generator;\n }\n if (!BN_generate_prime_ex(ret->p, prime_len, 1, t1, t2, cb))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n if (!BN_set_word(ret->g, g))\n goto err;\n ok = 1;\n err:\n if (ok == -1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB);\n ok = 0;\n }\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
1,599
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/lhash/lhash.c/#L296
void lh_doall_arg(LHASH *lh, void (*func)(), char *arg) { int i; LHASH_NODE *a,*n; for (i=lh->num_nodes-1; i>=0; i--) { a=lh->b[i]; while (a != NULL) { n=a->next; func(a->data,arg); a=n; } } }
['int MAIN(int argc, char **argv)\n\t{\n\tdouble totalTime = 0.0;\n\tint nConn = 0;\n\tSSL *scon=NULL;\n\tlong finishtime=0;\n\tint ret=1,i;\n\tMS_STATIC char buf[1024*8];\n\tint ver;\n#if !defined(NO_SSL2) && !defined(NO_SSL3)\n\ts_time_meth=SSLv23_client_method();\n#elif !defined(NO_SSL3)\n\ts_time_meth=SSLv3_client_method();\n#elif !defined(NO_SSL2)\n\ts_time_meth=SSLv2_client_method();\n#endif\n\tif( parseArgs( argc, argv ) < 0 )\n\t\tgoto end;\n\tSSLeay_add_ssl_algorithms();\n\tif ((tm_ctx=SSL_CTX_new(s_time_meth)) == NULL) return(1);\n\tSSL_CTX_set_quiet_shutdown(tm_ctx,1);\n\tif (st_bugs) SSL_CTX_set_options(tm_ctx,SSL_OP_ALL);\n\tSSL_CTX_set_cipher_list(tm_ctx,tm_cipher);\n\tif(!set_cert_stuff(tm_ctx,t_cert_file,t_key_file))\n\t\tgoto end;\n\tSSL_load_error_strings();\n\tif ((!SSL_CTX_load_verify_locations(tm_ctx,CAfile,CApath)) ||\n\t\t(!SSL_CTX_set_default_verify_paths(tm_ctx)))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tif (tm_cipher == NULL)\n\t\ttm_cipher = getenv("SSL_CIPHER");\n\tif (tm_cipher == NULL ) {\n\t\tfprintf( stderr, "No CIPHER specified\\n" );\n\t}\n\tif (!(perform & 1)) goto next;\n\tprintf( "Collecting connection statistics for %d seconds\\n", maxTime );\n\tbytes_read=0;\n\tfinishtime=(long)time(NULL)+maxTime;\n\ttm_Time_F(START);\n\tfor (;;)\n\t\t{\n\t\tif (finishtime < time(NULL)) break;\n#ifdef WIN32_STUFF\n\t\tif( flushWinMsgs(0) == -1 )\n\t\t\tgoto end;\n\t\tif( waitingToDie || exitNow )\n\t\t\tgoto end;\n#endif\n\t\tif( (scon = doConnection( NULL )) == NULL )\n\t\t\tgoto end;\n\t\tif (s_www_path != NULL)\n\t\t\t{\n\t\t\tsprintf(buf,"GET %s HTTP/1.0\\r\\n\\r\\n",s_www_path);\n\t\t\tSSL_write(scon,buf,strlen(buf));\n\t\t\twhile ((i=SSL_read(scon,buf,sizeof(buf))) > 0)\n\t\t\t\tbytes_read+=i;\n\t\t\t}\n#ifdef NO_SHUTDOWN\n\t\tSSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\t\tSSL_shutdown(scon);\n#endif\n\t\tSHUTDOWN2(SSL_get_fd(scon));\n\t\tnConn += 1;\n\t\tif (SSL_session_reused(scon))\n\t\t\tver=\'r\';\n\t\telse\n\t\t\t{\n\t\t\tver=SSL_version(scon);\n\t\t\tif (ver == TLS1_VERSION)\n\t\t\t\tver=\'t\';\n\t\t\telse if (ver == SSL3_VERSION)\n\t\t\t\tver=\'3\';\n\t\t\telse if (ver == SSL2_VERSION)\n\t\t\t\tver=\'2\';\n\t\t\telse\n\t\t\t\tver=\'*\';\n\t\t\t}\n\t\tfputc(ver,stdout);\n\t\tfflush(stdout);\n\t\tSSL_free( scon );\n\t\tscon=NULL;\n\t\t}\n\ttotalTime += tm_Time_F(STOP);\n\ti=(int)(time(NULL)-finishtime+maxTime);\n\tprintf( "\\n\\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);\n\tprintf( "%d connections in %ld real seconds, %ld bytes read per connection\\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);\nnext:\n\tif (!(perform & 2)) goto end;\n\tprintf( "\\n\\nNow timing with session id reuse.\\n" );\n\tif( (scon = doConnection( NULL )) == NULL )\n\t\t{\n\t\tfprintf( stderr, "Unable to get connection\\n" );\n\t\tgoto end;\n\t\t}\n\tif (s_www_path != NULL)\n\t\t{\n\t\tsprintf(buf,"GET %s HTTP/1.0\\r\\n\\r\\n",s_www_path);\n\t\tSSL_write(scon,buf,strlen(buf));\n\t\twhile (SSL_read(scon,buf,sizeof(buf)) > 0)\n\t\t\t;\n\t\t}\n#ifdef NO_SHUTDOWN\n\tSSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\tSSL_shutdown(scon);\n#endif\n\tSHUTDOWN2(SSL_get_fd(scon));\n\tnConn = 0;\n\ttotalTime = 0.0;\n\tfinishtime=time(NULL)+maxTime;\n\tprintf( "starting\\n" );\n\tbytes_read=0;\n\ttm_Time_F(START);\n\tfor (;;)\n\t\t{\n\t\tif (finishtime < time(NULL)) break;\n#ifdef WIN32_STUFF\n\t\tif( flushWinMsgs(0) == -1 )\n\t\t\tgoto end;\n\t\tif( waitingToDie || exitNow )\n\t\t\tgoto end;\n#endif\n\t \tif( (doConnection( scon )) == NULL )\n\t\t\tgoto end;\n\t\tif (s_www_path)\n\t\t\t{\n\t\t\tsprintf(buf,"GET %s HTTP/1.0\\r\\n\\r\\n",s_www_path);\n\t\t\tSSL_write(scon,buf,strlen(buf));\n\t\t\twhile ((i=SSL_read(scon,buf,sizeof(buf))) > 0)\n\t\t\t\tbytes_read+=i;\n\t\t\t}\n#ifdef NO_SHUTDOWN\n\t\tSSL_set_shutdown(scon,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\t\tSSL_shutdown(scon);\n#endif\n\t\tSHUTDOWN2(SSL_get_fd(scon));\n\t\tnConn += 1;\n\t\tif (SSL_session_reused(scon))\n\t\t\tver=\'r\';\n\t\telse\n\t\t\t{\n\t\t\tver=SSL_version(scon);\n\t\t\tif (ver == TLS1_VERSION)\n\t\t\t\tver=\'t\';\n\t\t\telse if (ver == SSL3_VERSION)\n\t\t\t\tver=\'3\';\n\t\t\telse if (ver == SSL2_VERSION)\n\t\t\t\tver=\'2\';\n\t\t\telse\n\t\t\t\tver=\'*\';\n\t\t\t}\n\t\tfputc(ver,stdout);\n\t\tfflush(stdout);\n\t\t}\n\ttotalTime += tm_Time_F(STOP);\n\tprintf( "\\n\\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\\n", nConn, totalTime, ((double)nConn/totalTime),bytes_read);\n\tprintf( "%d connections in %ld real seconds, %ld bytes read per connection\\n",nConn,time(NULL)-finishtime+maxTime,bytes_read/nConn);\n\tret=0;\nend:\n\tif (scon != NULL) SSL_free(scon);\n\tif (tm_ctx != NULL)\n\t\t{\n\t\tSSL_CTX_free(tm_ctx);\n\t\ttm_ctx=NULL;\n\t\t}\n\tEXIT(ret);\n\t}', 'static SSL *doConnection(SSL *scon)\n\t{\n\tBIO *conn;\n\tSSL *serverCon;\n\tint width, i;\n\tfd_set readfds;\n\tif ((conn=BIO_new(BIO_s_connect())) == NULL)\n\t\treturn(NULL);\n\tBIO_set_conn_hostname(conn,host);\n\tif (scon == NULL)\n\t\tserverCon=(SSL *)SSL_new(tm_ctx);\n\telse\n\t\t{\n\t\tserverCon=scon;\n\t\tSSL_set_connect_state(serverCon);\n\t\t}\n\tSSL_set_bio(serverCon,conn,conn);\n#if 0\n\tif( scon != NULL )\n\t\tSSL_set_session(serverCon,SSL_get_session(scon));\n#endif\n\tfor(;;) {\n\t\ti=SSL_connect(serverCon);\n\t\tif (BIO_sock_should_retry(i))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DELAY\\n");\n\t\t\ti=SSL_get_fd(serverCon);\n\t\t\twidth=i+1;\n\t\t\tFD_ZERO(&readfds);\n\t\t\tFD_SET(i,&readfds);\n\t\t\tselect(width,&readfds,NULL,NULL,NULL);\n\t\t\tcontinue;\n\t\t\t}\n\t\tbreak;\n\t\t}\n\tif(i <= 0)\n\t\t{\n\t\tBIO_printf(bio_err,"ERROR\\n");\n\t\tif (verify_error != X509_V_OK)\n\t\t\tBIO_printf(bio_err,"verify error:%s\\n",\n\t\t\t\tX509_verify_cert_error_string(verify_error));\n\t\telse\n\t\t\tERR_print_errors(bio_err);\n\t\tif (scon == NULL)\n\t\t\tSSL_free(serverCon);\n\t\treturn NULL;\n\t\t}\n\treturn serverCon;\n\t}', 'void SSL_free(SSL *s)\n\t{\n\tint i;\n\tif(s == NULL)\n\t return;\n\ti=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);\n#ifdef REF_PRINT\n\tREF_PRINT("SSL",s);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"SSL_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tCRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data);\n\tif (s->bbio != NULL)\n\t\t{\n\t\tif (s->bbio == s->wbio)\n\t\t\t{\n\t\t\ts->wbio=BIO_pop(s->wbio);\n\t\t\t}\n\t\tBIO_free(s->bbio);\n\t\ts->bbio=NULL;\n\t\t}\n\tif (s->rbio != NULL)\n\t\tBIO_free_all(s->rbio);\n\tif ((s->wbio != NULL) && (s->wbio != s->rbio))\n\t\tBIO_free_all(s->wbio);\n\tif (s->init_buf != NULL) BUF_MEM_free(s->init_buf);\n\tif (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);\n\tif (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);\n\tif (s->session != NULL)\n\t\t{\n\t\tssl_clear_bad_session(s);\n\t\tSSL_SESSION_free(s->session);\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (s->cert != NULL) ssl_cert_free(s->cert);\n\tif (s->ctx) SSL_CTX_free(s->ctx);\n\tif (s->client_CA != NULL)\n\t\tsk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);\n\tif (s->method != NULL) s->method->ssl_free(s);\n\tFree((char *)s);\n\t}', 'void X509_STORE_free(X509_STORE *vfy)\n\t{\n\tint i;\n\tSTACK *sk;\n\tX509_LOOKUP *lu;\n\tif(vfy == NULL)\n\t return;\n\tsk=vfy->get_cert_methods;\n\tfor (i=0; i<sk_num(sk); i++)\n\t\t{\n\t\tlu=(X509_LOOKUP *)sk_value(sk,i);\n\t\tX509_LOOKUP_shutdown(lu);\n\t\tX509_LOOKUP_free(lu);\n\t\t}\n\tsk_free(sk);\n\tCRYPTO_free_ex_data(x509_store_meth,(char *)vfy,&vfy->ex_data);\n\tlh_doall(vfy->certs,cleanup);\n\tlh_free(vfy->certs);\n\tFree(vfy);\n\t}', 'void lh_doall(LHASH *lh, void (*func)())\n\t{\n\tlh_doall_arg(lh,func,NULL);\n\t}', 'void lh_doall_arg(LHASH *lh, void (*func)(), char *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tfunc(a->data,arg);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
1,600
0
https://github.com/openssl/openssl/blob/d4b009d5f88875ac0e3ac0b2b9689ed16a4c88dc/crypto/lhash/lhash.c/#L249
static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) { int i; LHASH_NODE *a, *n; if (lh == NULL) return; for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { n = a->next; if (use_arg) func_arg(a->data, arg); else func(a->data); a = n; } } }
['int s_time_main(int argc, char **argv)\n{\n char buf[1024 * 8];\n SSL *scon = NULL;\n SSL_CTX *ctx = NULL;\n const SSL_METHOD *meth = NULL;\n char *CApath = NULL, *CAfile = NULL, *cipher = NULL, *www_path = NULL;\n char *host = SSL_CONNECT_NAME, *certfile = NULL, *keyfile = NULL, *prog;\n double totalTime = 0.0;\n int noCApath = 0, noCAfile = 0;\n int maxtime = SECONDS, nConn = 0, perform = 3, ret = 1, i, st_bugs =\n 0, ver;\n long bytes_read = 0, finishtime = 0;\n OPTION_CHOICE o;\n meth = TLS_client_method();\n verify_depth = 0;\n verify_error = X509_V_OK;\n prog = opt_init(argc, argv, s_time_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(s_time_options);\n ret = 0;\n goto end;\n case OPT_CONNECT:\n host = opt_arg();\n break;\n case OPT_REUSE:\n perform = 2;\n break;\n case OPT_NEW:\n perform = 1;\n break;\n case OPT_VERIFY:\n if (!opt_int(opt_arg(), &verify_depth))\n goto opthelp;\n BIO_printf(bio_err, "%s: verify depth is %d\\n",\n prog, verify_depth);\n break;\n case OPT_CERT:\n certfile = opt_arg();\n break;\n case OPT_KEY:\n keyfile = opt_arg();\n break;\n case OPT_CAPATH:\n CApath = opt_arg();\n break;\n case OPT_CAFILE:\n CAfile = opt_arg();\n break;\n case OPT_NOCAPATH:\n noCApath = 1;\n break;\n case OPT_NOCAFILE:\n noCAfile = 1;\n break;\n case OPT_CIPHER:\n cipher = opt_arg();\n break;\n case OPT_BUGS:\n st_bugs = 1;\n break;\n case OPT_TIME:\n if (!opt_int(opt_arg(), &maxtime))\n goto opthelp;\n break;\n case OPT_WWW:\n www_path = opt_arg();\n if (strlen(www_path) > MYBUFSIZ - 100) {\n BIO_printf(bio_err, "%s: -www option too long\\n", prog);\n goto end;\n }\n break;\n case OPT_SSL3:\n#ifndef OPENSSL_NO_SSL3\n meth = SSLv3_client_method();\n#endif\n break;\n }\n }\n argc = opt_num_rest();\n argv = opt_rest();\n if (cipher == NULL)\n cipher = getenv("SSL_CIPHER");\n if (cipher == NULL) {\n BIO_printf(bio_err, "No CIPHER specified\\n");\n goto end;\n }\n if ((ctx = SSL_CTX_new(meth)) == NULL)\n goto end;\n SSL_CTX_set_quiet_shutdown(ctx, 1);\n if (st_bugs)\n SSL_CTX_set_options(ctx, SSL_OP_ALL);\n if (!SSL_CTX_set_cipher_list(ctx, cipher))\n goto end;\n if (!set_cert_stuff(ctx, certfile, keyfile))\n goto end;\n if (!ctx_set_verify_locations(ctx, CAfile, CApath, noCAfile, noCApath)) {\n ERR_print_errors(bio_err);\n goto end;\n }\n if (!(perform & 1))\n goto next;\n printf("Collecting connection statistics for %d seconds\\n", maxtime);\n bytes_read = 0;\n finishtime = (long)time(NULL) + maxtime;\n tm_Time_F(START);\n for (;;) {\n if (finishtime < (long)time(NULL))\n break;\n if ((scon = doConnection(NULL, host, ctx)) == NULL)\n goto end;\n if (www_path != NULL) {\n BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\\r\\n\\r\\n",\n www_path);\n if (SSL_write(scon, buf, strlen(buf)) <= 0)\n goto end;\n while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)\n bytes_read += i;\n }\n#ifdef NO_SHUTDOWN\n SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n#else\n SSL_shutdown(scon);\n#endif\n SHUTDOWN2(SSL_get_fd(scon));\n nConn += 1;\n if (SSL_session_reused(scon))\n ver = \'r\';\n else {\n ver = SSL_version(scon);\n if (ver == TLS1_VERSION)\n ver = \'t\';\n else if (ver == SSL3_VERSION)\n ver = \'3\';\n else\n ver = \'*\';\n }\n fputc(ver, stdout);\n fflush(stdout);\n SSL_free(scon);\n scon = NULL;\n }\n totalTime += tm_Time_F(STOP);\n i = (int)((long)time(NULL) - finishtime + maxtime);\n printf\n ("\\n\\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\\n",\n nConn, totalTime, ((double)nConn / totalTime), bytes_read);\n printf\n ("%d connections in %ld real seconds, %ld bytes read per connection\\n",\n nConn, (long)time(NULL) - finishtime + maxtime, bytes_read / nConn);\n next:\n if (!(perform & 2))\n goto end;\n printf("\\n\\nNow timing with session id reuse.\\n");\n if ((scon = doConnection(NULL, host, ctx)) == NULL) {\n BIO_printf(bio_err, "Unable to get connection\\n");\n goto end;\n }\n if (www_path != NULL) {\n BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\\r\\n\\r\\n", www_path);\n if (SSL_write(scon, buf, strlen(buf)) <= 0)\n goto end;\n while (SSL_read(scon, buf, sizeof(buf)) > 0)\n continue;\n }\n#ifdef NO_SHUTDOWN\n SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n#else\n SSL_shutdown(scon);\n#endif\n SHUTDOWN2(SSL_get_fd(scon));\n nConn = 0;\n totalTime = 0.0;\n finishtime = (long)time(NULL) + maxtime;\n printf("starting\\n");\n bytes_read = 0;\n tm_Time_F(START);\n for (;;) {\n if (finishtime < (long)time(NULL))\n break;\n if ((doConnection(scon, host, ctx)) == NULL)\n goto end;\n if (www_path) {\n BIO_snprintf(buf, sizeof buf, "GET %s HTTP/1.0\\r\\n\\r\\n",\n www_path);\n if (SSL_write(scon, buf, strlen(buf)) <= 0)\n goto end;\n while ((i = SSL_read(scon, buf, sizeof(buf))) > 0)\n bytes_read += i;\n }\n#ifdef NO_SHUTDOWN\n SSL_set_shutdown(scon, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);\n#else\n SSL_shutdown(scon);\n#endif\n SHUTDOWN2(SSL_get_fd(scon));\n nConn += 1;\n if (SSL_session_reused(scon))\n ver = \'r\';\n else {\n ver = SSL_version(scon);\n if (ver == TLS1_VERSION)\n ver = \'t\';\n else if (ver == SSL3_VERSION)\n ver = \'3\';\n else\n ver = \'*\';\n }\n fputc(ver, stdout);\n fflush(stdout);\n }\n totalTime += tm_Time_F(STOP);\n printf\n ("\\n\\n%d connections in %.2fs; %.2f connections/user sec, bytes read %ld\\n",\n nConn, totalTime, ((double)nConn / totalTime), bytes_read);\n printf\n ("%d connections in %ld real seconds, %ld bytes read per connection\\n",\n nConn, (long)time(NULL) - finishtime + maxtime, bytes_read / nConn);\n ret = 0;\n end:\n SSL_free(scon);\n SSL_CTX_free(ctx);\n return (ret);\n}', 'static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx)\n{\n BIO *conn;\n SSL *serverCon;\n int width, i;\n fd_set readfds;\n if ((conn = BIO_new(BIO_s_connect())) == NULL)\n return (NULL);\n BIO_set_conn_hostname(conn, host);\n if (scon == NULL)\n serverCon = SSL_new(ctx);\n else {\n serverCon = scon;\n SSL_set_connect_state(serverCon);\n }\n SSL_set_bio(serverCon, conn, conn);\n for (;;) {\n i = SSL_connect(serverCon);\n if (BIO_sock_should_retry(i)) {\n BIO_printf(bio_err, "DELAY\\n");\n i = SSL_get_fd(serverCon);\n width = i + 1;\n FD_ZERO(&readfds);\n openssl_fdset(i, &readfds);\n select(width, (void *)&readfds, NULL, NULL, NULL);\n continue;\n }\n break;\n }\n if (i <= 0) {\n BIO_printf(bio_err, "ERROR\\n");\n if (verify_error != X509_V_OK)\n BIO_printf(bio_err, "verify error:%s\\n",\n X509_verify_cert_error_string(verify_error));\n else\n ERR_print_errors(bio_err);\n if (scon == NULL)\n SSL_free(serverCon);\n return NULL;\n }\n return serverCon;\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 RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\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 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n s->ctx = ctx;\n s->tlsext_debug_cb = 0;\n s->tlsext_debug_arg = NULL;\n s->tlsext_ticket_expected = 0;\n s->tlsext_status_type = -1;\n s->tlsext_status_expected = 0;\n s->tlsext_ocsp_ids = NULL;\n s->tlsext_ocsp_exts = NULL;\n s->tlsext_ocsp_resp = NULL;\n s->tlsext_ocsp_resplen = -1;\n CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n if (ctx->tlsext_ecpointformatlist) {\n s->tlsext_ecpointformatlist =\n OPENSSL_memdup(ctx->tlsext_ecpointformatlist,\n ctx->tlsext_ecpointformatlist_length);\n if (!s->tlsext_ecpointformatlist)\n goto err;\n s->tlsext_ecpointformatlist_length =\n ctx->tlsext_ecpointformatlist_length;\n }\n if (ctx->tlsext_ellipticcurvelist) {\n s->tlsext_ellipticcurvelist =\n OPENSSL_memdup(ctx->tlsext_ellipticcurvelist,\n ctx->tlsext_ellipticcurvelist_length);\n if (!s->tlsext_ellipticcurvelist)\n goto err;\n s->tlsext_ellipticcurvelist_length =\n ctx->tlsext_ellipticcurvelist_length;\n }\n# endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n s->next_proto_negotiated = NULL;\n# endif\n if (s->ctx->alpn_client_proto_list) {\n s->alpn_client_proto_list =\n OPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n if (s->alpn_client_proto_list == NULL)\n goto err;\n memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n s->ctx->alpn_client_proto_list_len);\n s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n }\n 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 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->job = NULL;\n return (s);\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL);\n#ifdef REF_PRINT\n REF_PRINT("SSL", s);\n#endif\n if (i > 0)\n return;\n#ifdef REF_CHECK\n if (i < 0) {\n fprintf(stderr, "SSL_free, bad reference count\\n");\n abort();\n }\n#endif\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n if (s->bbio != NULL) {\n if (s->bbio == s->wbio) {\n s->wbio = BIO_pop(s->wbio);\n }\n BIO_free(s->bbio);\n s->bbio = NULL;\n }\n BIO_free_all(s->rbio);\n if (s->wbio != s->rbio)\n BIO_free_all(s->wbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->tlsext_hostname);\n SSL_CTX_free(s->initial_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->tlsext_ecpointformatlist);\n OPENSSL_free(s->tlsext_ellipticcurvelist);\n#endif\n sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, X509_EXTENSION_free);\n sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n OPENSSL_free(s->tlsext_ocsp_resp);\n OPENSSL_free(s->alpn_client_proto_list);\n sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->next_proto_negotiated);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_SSL_CTX);\n#ifdef REF_PRINT\n REF_PRINT("SSL_CTX", a);\n#endif\n if (i > 0)\n return;\n#ifdef REF_CHECK\n if (i < 0) {\n fprintf(stderr, "SSL_CTX_free, bad reference count\\n");\n abort();\n }\n#endif\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->client_CA, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n if (a->client_cert_engine)\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->tlsext_ecpointformatlist);\n OPENSSL_free(a->tlsext_ellipticcurvelist);\n#endif\n OPENSSL_free(a->alpn_client_proto_list);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n i = CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;\n CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = 0;\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load = i;\n CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n{\n doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n}', 'static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n{\n int i;\n LHASH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']