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
34,901
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_mul.c/#L641
int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { int top,al,bl; BIGNUM *rr; #ifdef BN_RECURSION BIGNUM *t; int i,j,k; #endif #ifdef BN_COUNT printf("BN_mul %d * %d\n",a->top,b->top); #endif bn_check_top(a); bn_check_top(b); bn_check_top(r); al=a->top; bl=b->top; r->neg=a->neg^b->neg; if ((al == 0) || (bl == 0)) { BN_zero(r); return(1); } top=al+bl; if ((r == a) || (r == b)) rr= &(ctx->bn[ctx->tos+1]); else rr=r; #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) if (al == bl) { # ifdef BN_MUL_COMBA if (al == 8) { if (bn_wexpand(rr,16) == NULL) return(0); r->top=16; bn_mul_comba8(rr->d,a->d,b->d); goto end; } else # endif #ifdef BN_RECURSION if (al < BN_MULL_SIZE_NORMAL) #endif { if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); goto end; } # ifdef BN_RECURSION goto symetric; # endif } #endif #ifdef BN_RECURSION else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) { if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); goto end; } else { i=(al-bl); if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) { bn_wexpand(b,al); b->d[bl]=0; bl++; goto symetric; } else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) { bn_wexpand(a,bl); a->d[al]=0; al++; goto symetric; } } #endif if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); #ifdef BN_RECURSION if (0) { symetric: j=BN_num_bits_word((BN_ULONG)al); j=1<<(j-1); k=j+j; t= &(ctx->bn[ctx->tos]); if (al == j) { bn_wexpand(t,k*2); bn_wexpand(rr,k*2); bn_mul_recursive(rr->d,a->d,b->d,al,t->d); } else { bn_wexpand(a,k); bn_wexpand(b,k); bn_wexpand(t,k*4); bn_wexpand(rr,k*4); for (i=a->top; i<k; i++) a->d[i]=0; for (i=b->top; i<k; i++) b->d[i]=0; bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); } rr->top=top; } #endif #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) end: #endif bn_fix_top(rr); if (r != rr) BN_copy(r,rr); return(1); }
['int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,\n\t\t DSA *dsa)\n\t{\n\tBN_CTX *ctx;\n\tBIGNUM u1,u2,t1;\n\tBN_MONT_CTX *mont=NULL;\n\tint ret = -1;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_init(&u1);\n\tBN_init(&u2);\n\tBN_init(&t1);\n\tif ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;\n\tif (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;\n\tif (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;\n\tif (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;\n\tif ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,\n\t\t\t\tdsa->p,ctx)) goto err;\n\t\t}\n\tmont=(BN_MONT_CTX *)dsa->method_mont_p;\n#if 0\n\t{\n\tBIGNUM t2;\n\tBN_init(&t2);\n\tif (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;\n\tif (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;\n\tif (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;\n\tBN_free(&t2);\n\t}\n\tif (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;\n#else\n\t{\n\tif (!BN_mod_exp2_mont(&t1,dsa->g,&u1,dsa->pub_key,&u2,dsa->p,ctx,mont))\n\t\tgoto err;\n\tif (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;\n\t}\n#endif\n\tret=(BN_ucmp(&u1, sig->r) == 0);\n\terr:\n\tif (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_free(&u1);\n\tBN_free(&u2);\n\tBN_free(&t1);\n\treturn(ret);\n\t}', 'int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,\n\t BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;\n\tint start=1,ts=0,x,y;\n\tBIGNUM *d,*aa1,*aa2,*r;\n\tBIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a1);\n\tbn_check_top(p1);\n\tbn_check_top(a2);\n\tbn_check_top(p2);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits1=BN_num_bits(p1);\n\tbits2=BN_num_bits(p2);\n\tif ((bits1 == 0) && (bits2 == 0))\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tbits=(bits1 > bits2)?bits1:bits2;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&(val[0][0]));\n\tBN_init(&(val[1][1]));\n\tBN_init(&(val[0][1]));\n\tBN_init(&(val[1][0]));\n\tts=1;\n\tif (BN_ucmp(a1,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[1][0]),a1,m,ctx);\n\t\taa1= &(val[1][0]);\n\t\t}\n\telse\n\t\taa1=a1;\n\tif (BN_ucmp(a2,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0][1]),a2,m,ctx);\n\t\taa2= &(val[0][1]);\n\t\t}\n\telse\n\t\taa2=a2;\n\tif (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;\n\tif (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(&(val[1][1]),\n\t\t&(val[1][0]),&(val[0][1]),mont,ctx))\n\t\tgoto err;\n#if 0\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits > 250)\n\t\twindow=5;\n\telse if (bits >= 120)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n#else\n\twindow=EXP2_TABLE_BITS;\n#endif\n\tk=1<<window;\n\tfor (x=0; x<k; x++)\n\t\t{\n\t\tif (x >= 2)\n\t\t\t{\n\t\t\tBN_init(&(val[x][0]));\n\t\t\tBN_init(&(val[x][1]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][0]),\n\t\t\t\t&(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][1]),\n\t\t\t\t&(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;\n\t\t\t}\n\t\tfor (y=2; y<k; y++)\n\t\t\t{\n\t\t\tBN_init(&(val[x][y]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][y]),\n\t\t\t\t&(val[x][y-1]),&(val[0][1]),mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tts=k;\n\tstart=1;\n\txvalue=0;\n\tyvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\txvalue=BN_is_bit_set(p1,wstart);\n\t\tyvalue=BN_is_bit_set(p2,wstart);\n\t\tif (!(xvalue || yvalue))\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\twstart--;\n\t\t\tif (wstart < 0) break;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\txvalue+=xvalue;\n\t\t\txvalue|=BN_is_bit_set(p1,wstart-i);\n\t\t\tyvalue+=yvalue;\n\t\t\tyvalue|=BN_is_bit_set(p2,wstart-i);\n\t\t\t}\n\t\tif (!start)\n\t\t\tfor (j=0; j<i; j++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (xvalue || yvalue)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),\n\t\t\t\tmont,ctx)) goto err;\n\t\t\t}\n\t\twstart-=i;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\t{\n\t\tfor (j=0; j<ts; j++)\n\t\t\t{\n\t\t\tBN_clear_free(&(val[i][j]));\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}']
34,902
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/lhash/lhash.c/#L254
char *lh_delete(LHASH *lh, char *data) { unsigned long hash; LHASH_NODE *nn,**rn; char *ret; lh->error=0; rn=getrn(lh,data,&hash); if (*rn == NULL) { lh->num_no_delete++; return(NULL); } else { nn= *rn; *rn=nn->next; ret=nn->data; Free((char *)nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) contract(lh); return(ret); }
['static int sv_body(char *hostname, int s, char *context)\n\t{\n\tchar *buf=NULL;\n\tfd_set readfds;\n\tint ret=1,width;\n\tint k,i;\n\tunsigned long l;\n\tSSL *con=NULL;\n\tBIO *sbio;\n\tif ((buf=Malloc(bufsize)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto err;\n\t\t}\n#ifdef FIONBIO\n\tif (s_nbio)\n\t\t{\n\t\tunsigned long sl=1;\n\t\tif (!s_quiet)\n\t\t\tBIO_printf(bio_err,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)\n\t\t\tERR_print_errors(bio_err);\n\t\t}\n#endif\n\tif (con == NULL) {\n\t\tcon=(SSL *)SSL_new(ctx);\n\t\tif(context)\n\t\t SSL_set_session_id_context(con, context, strlen(context));\n\t}\n\tSSL_clear(con);\n\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (s_nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_accept_state(con);\n\tif (s_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(SSL_get_rbio(con),bio_dump_cb);\n\t\tBIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);\n\t\t}\n\twidth=s+1;\n\tfor (;;)\n\t\t{\n\t\tFD_ZERO(&readfds);\n#ifndef WINDOWS\n\t\tFD_SET(fileno(stdin),&readfds);\n#endif\n\t\tFD_SET(s,&readfds);\n\t\ti=select(width,&readfds,NULL,NULL,NULL);\n\t\tif (i <= 0) continue;\n\t\tif (FD_ISSET(fileno(stdin),&readfds))\n\t\t\t{\n\t\t\ti=read(fileno(stdin),buf,bufsize);\n\t\t\tif (!s_quiet)\n\t\t\t\t{\n\t\t\t\tif ((i <= 0) || (buf[0] == \'Q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tclose_accept_socket();\n\t\t\t\t\tret= -11;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((i <= 0) || (buf[0] == \'q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'r\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'R\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_set_verify(con,\n\t\t\t\t\t\tSSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'P\')\n\t\t\t\t\t{\n\t\t\t\t\tstatic char *str="Lets print some clear text\\n";\n\t\t\t\t\tBIO_write(SSL_get_wbio(con),str,strlen(str));\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'S\')\n\t\t\t\t\t{\n\t\t\t\t\tprint_stats(bio_s_out,SSL_get_SSL_CTX(con));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tl=k=0;\n\t\t\tfor (;;)\n\t\t\t\t{\n#ifdef RENEG\n{ static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } }\n#endif\n\t\t\t\tk=SSL_write(con,&(buf[l]),(unsigned int)i);\n\t\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Write BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tl+=k;\n\t\t\t\ti-=k;\n\t\t\t\tif (i <= 0) break;\n\t\t\t\t}\n\t\t\t}\n\t\tif (FD_ISSET(s,&readfds))\n\t\t\t{\n\t\t\tif (!SSL_is_init_finished(con))\n\t\t\t\t{\n\t\t\t\ti=init_ssl_connection(con);\n\t\t\t\tif (i < 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=0;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse if (i == 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\nagain:\n\t\t\t\ti=SSL_read(con,(char *)buf,bufsize);\n\t\t\t\tswitch (SSL_get_error(con,i))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\t\twrite(fileno(stdout),buf,\n\t\t\t\t\t\t(unsigned int)i);\n\t\t\t\t\tif (SSL_pending(con)) goto again;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Read BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\nerr:\n\tBIO_printf(bio_s_out,"shutting down SSL\\n");\n#if 1\n\tSSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\tSSL_shutdown(con);\n#endif\n\tif (con != NULL) SSL_free(con);\n\tBIO_printf(bio_s_out,"CONNECTION CLOSED\\n");\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bufsize);\n\t\tFree(buf);\n\t\t}\n\tif (ret >= 0)\n\t\tBIO_printf(bio_s_out,"ACCEPT\\n");\n\treturn(ret);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)Malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n\tif (ctx->default_cert != NULL)\n\t\t{\n\t\tCRYPTO_add(&ctx->default_cert->references,1,\n\t\t\t CRYPTO_LOCK_SSL_CERT);\n\t\ts->cert=ctx->default_cert;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_callback=ctx->default_verify_callback;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\t{\n\t\tSSL_CTX_free(ctx);\n\t\tFree(s);\n\t\tgoto err;\n\t\t}\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\ts->options=ctx->options;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(ssl_meth,(char *)s,&s->ex_data);\n\treturn(s);\nerr:\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tint state;\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#endif\n\tstate=s->state;\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n\ts->read_ahead=s->ctx->read_ahead;\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->first_packet=0;\n#if 1\n\tif ((s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
34,903
0
https://github.com/openssl/openssl/blob/7bf7333d688264f6d389c1c3c87c127f484b2efa/apps/x509.c/#L1228
static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest, CONF *conf, char *section) { EVP_PKEY *pktmp; pktmp = X509_get_pubkey(x); EVP_PKEY_copy_parameters(pktmp,pkey); EVP_PKEY_save_parameters(pktmp,1); EVP_PKEY_free(pktmp); if (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err; if (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err; if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL) goto err; if (!X509_set_pubkey(x,pkey)) goto err; if (clrext) { while (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); } if (conf) { X509V3_CTX ctx; X509_set_version(x,2); X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0); X509V3_set_nconf(&ctx, conf); if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err; } if (!X509_sign(x,pkey,digest)) goto err; return 1; err: ERR_print_errors(bio_err); return 0; }
['static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest,\n\t\t\t\t\t\tCONF *conf, char *section)\n\t{\n\tEVP_PKEY *pktmp;\n\tpktmp = X509_get_pubkey(x);\n\tEVP_PKEY_copy_parameters(pktmp,pkey);\n\tEVP_PKEY_save_parameters(pktmp,1);\n\tEVP_PKEY_free(pktmp);\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err;\n\tif (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)\n\t\tgoto err;\n\tif (!X509_set_pubkey(x,pkey)) goto err;\n\tif (clrext)\n\t\t{\n\t\twhile (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);\n\t\t}\n\tif (conf)\n\t\t{\n\t\tX509V3_CTX ctx;\n\t\tX509_set_version(x,2);\n X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0);\n X509V3_set_nconf(&ctx, conf);\n if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err;\n\t\t}\n\tif (!X509_sign(x,pkey,digest)) goto err;\n\treturn 1;\nerr:\n\tERR_print_errors(bio_err);\n\treturn 0;\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tconst EVP_PKEY_ASN1_METHOD *meth;\n\tif (key == NULL) goto error;\n\tif (key->pkey != NULL)\n\t\t{\n\t\tCRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\t\treturn key->pkey;\n\t\t}\n\tif (key->public_key == NULL) goto error;\n\tif ((ret = EVP_PKEY_new()) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\tgoto error;\n\t\t}\n\tmeth = EVP_PKEY_asn1_find(OBJ_obj2nid(key->algor->algorithm));\n\tif (meth)\n\t\t{\n\t\tif (meth->pub_decode)\n\t\t\t{\n\t\t\tif (!meth->pub_decode(ret, key))\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\t\t\tX509_R_PUBLIC_KEY_DECODE_ERROR);\n\t\t\t\tgoto error;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\tX509_R_METHOD_NOT_SUPPORTED);\n\t\t\tgoto error;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_UNSUPPORTED_ALGORITHM);\n\t\tgoto error;\n\t\t}\n\tkey->pkey = ret;\n\tCRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\treturn ret;\n\terror:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'EVP_PKEY *EVP_PKEY_new(void)\n\t{\n\tEVP_PKEY *ret;\n\tret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));\n\tif (ret == NULL)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->type=EVP_PKEY_NONE;\n\tret->references=1;\n\tret->ameth=NULL;\n\tret->pkey.ptr=NULL;\n\tret->attributes=NULL;\n\tret->save_parameters=1;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n\t{\n\tif (to->type != from->type)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);\n\t\tgoto err;\n\t\t}\n\tif (EVP_PKEY_missing_parameters(from))\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);\n\t\tgoto err;\n\t\t}\n\tif (from->ameth && from->ameth->param_copy)\n\t\treturn from->ameth->param_copy(to, from);\nerr:\n\treturn 0;\n\t}']
34,904
1
https://github.com/openssl/openssl/blob/98c03302fb7b855647aa14022f61f5fb272e514a/crypto/ec/ecp_nist.c/#L160
int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx) { int ret = 0; BN_CTX *ctx_new = NULL; if (!group || !r || !a) { ECerr(EC_F_EC_GFP_NIST_FIELD_SQR, EC_R_PASSED_NULL_PARAMETER); goto err; } if (!ctx) if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err; if (!BN_sqr(r, a, ctx)) goto err; if (!group->field_mod_func(r, r, group->field, ctx)) goto err; ret = 1; err: BN_CTX_free(ctx_new); return ret; }
['int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,\n BN_CTX *ctx)\n{\n int ret = 0;\n BN_CTX *ctx_new = NULL;\n if (!group || !r || !a) {\n ECerr(EC_F_EC_GFP_NIST_FIELD_SQR, EC_R_PASSED_NULL_PARAMETER);\n goto err;\n }\n if (!ctx)\n if ((ctx_new = ctx = BN_CTX_new()) == NULL)\n goto err;\n if (!BN_sqr(r, a, ctx))\n goto err;\n if (!group->field_mod_func(r, r, group->field, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_free(ctx_new);\n return ret;\n}', 'void BN_CTX_free(BN_CTX *ctx)\n{\n#ifdef BN_CTX_DEBUG\n {\n BN_POOL_ITEM *pool = ctx->pool.head;\n fprintf(stderr, "BN_CTX_free, stack-size=%d, pool-bignums=%d\\n",\n ctx->stack.size, ctx->pool.size);\n fprintf(stderr, "dmaxs: ");\n while (pool) {\n unsigned loop = 0;\n while (loop < BN_CTX_POOL_SIZE)\n fprintf(stderr, "%02x ", pool->vals[loop++].dmax);\n pool = pool->next;\n }\n fprintf(stderr, "\\n");\n }\n#endif\n BN_STACK_finish(&ctx->stack);\n BN_POOL_finish(&ctx->pool);\n OPENSSL_free(ctx);\n}', 'static void BN_STACK_finish(BN_STACK *st)\n{\n OPENSSL_free(st->indexes);\n st->indexes = NULL;\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}', 'static void BN_POOL_finish(BN_POOL *p)\n{\n unsigned int loop;\n BIGNUM *bn;\n while (p->head) {\n for (loop = 0, bn = p->head->vals; loop++ < BN_CTX_POOL_SIZE; bn++)\n if (bn->d)\n BN_clear_free(bn);\n p->current = p->head->next;\n OPENSSL_free(p->head);\n p->head = p->current;\n }\n}']
34,905
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L265
static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ const int lt= src[-1-1*stride]; LOAD_TOP_EDGE LOAD_LEFT_EDGE src[0+0*stride]= src[1+2*stride]=(lt + t0 + 1)>>1; src[1+0*stride]= src[2+2*stride]=(t0 + t1 + 1)>>1; src[2+0*stride]= src[3+2*stride]=(t1 + t2 + 1)>>1; src[3+0*stride]=(t2 + t3 + 1)>>1; src[0+1*stride]= src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; src[1+1*stride]= src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; src[2+1*stride]= src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; }
['static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){\n const int lt= src[-1-1*stride];\n LOAD_TOP_EDGE\n LOAD_LEFT_EDGE\n src[0+0*stride]=\n src[1+2*stride]=(lt + t0 + 1)>>1;\n src[1+0*stride]=\n src[2+2*stride]=(t0 + t1 + 1)>>1;\n src[2+0*stride]=\n src[3+2*stride]=(t1 + t2 + 1)>>1;\n src[3+0*stride]=(t2 + t3 + 1)>>1;\n src[0+1*stride]=\n src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2;\n src[1+1*stride]=\n src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2;\n src[2+1*stride]=\n src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2;\n src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2;\n src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2;\n src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;\n}']
34,906
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/mem.c/#L244
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 }
['static int def_load_bio(CONF *conf, BIO *in, long *line)\n{\n#define CONFBUFSIZE 512\n int bufnum = 0, i, ii;\n BUF_MEM *buff = NULL;\n char *s, *p, *end;\n int again;\n long eline = 0;\n char btmp[DECIMAL_SIZE(eline) + 1];\n CONF_VALUE *v = NULL, *tv;\n CONF_VALUE *sv = NULL;\n char *section = NULL, *buf;\n char *start, *psection, *pname;\n void *h = (void *)(conf->data);\n if ((buff = BUF_MEM_new()) == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB);\n goto err;\n }\n section = OPENSSL_strdup("default");\n if (section == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (_CONF_new_data(conf) == 0) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n sv = _CONF_new_section(conf, section);\n if (sv == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_UNABLE_TO_CREATE_NEW_SECTION);\n goto err;\n }\n bufnum = 0;\n again = 0;\n for (;;) {\n if (!BUF_MEM_grow(buff, bufnum + CONFBUFSIZE)) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_BUF_LIB);\n goto err;\n }\n p = &(buff->data[bufnum]);\n *p = \'\\0\';\n BIO_gets(in, p, CONFBUFSIZE - 1);\n p[CONFBUFSIZE - 1] = \'\\0\';\n ii = i = strlen(p);\n if (i == 0 && !again)\n break;\n again = 0;\n while (i > 0) {\n if ((p[i - 1] != \'\\r\') && (p[i - 1] != \'\\n\'))\n break;\n else\n i--;\n }\n if (ii && i == ii)\n again = 1;\n else {\n p[i] = \'\\0\';\n eline++;\n }\n bufnum += i;\n v = NULL;\n if (bufnum >= 1) {\n p = &(buff->data[bufnum - 1]);\n if (IS_ESC(conf, p[0]) && ((bufnum <= 1) || !IS_ESC(conf, p[-1]))) {\n bufnum--;\n again = 1;\n }\n }\n if (again)\n continue;\n bufnum = 0;\n buf = buff->data;\n clear_comments(conf, buf);\n s = eat_ws(conf, buf);\n if (IS_EOF(conf, *s))\n continue;\n if (*s == \'[\') {\n char *ss;\n s++;\n start = eat_ws(conf, s);\n ss = start;\n again:\n end = eat_alpha_numeric(conf, ss);\n p = eat_ws(conf, end);\n if (*p != \']\') {\n if (*p != \'\\0\' && ss != p) {\n ss = p;\n goto again;\n }\n CONFerr(CONF_F_DEF_LOAD_BIO,\n CONF_R_MISSING_CLOSE_SQUARE_BRACKET);\n goto err;\n }\n *end = \'\\0\';\n if (!str_copy(conf, NULL, &section, start))\n goto err;\n if ((sv = _CONF_get_section(conf, section)) == NULL)\n sv = _CONF_new_section(conf, section);\n if (sv == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO,\n CONF_R_UNABLE_TO_CREATE_NEW_SECTION);\n goto err;\n }\n continue;\n } else {\n pname = s;\n psection = NULL;\n end = eat_alpha_numeric(conf, s);\n if ((end[0] == \':\') && (end[1] == \':\')) {\n *end = \'\\0\';\n end += 2;\n psection = pname;\n pname = end;\n end = eat_alpha_numeric(conf, end);\n }\n p = eat_ws(conf, end);\n if (*p != \'=\') {\n CONFerr(CONF_F_DEF_LOAD_BIO, CONF_R_MISSING_EQUAL_SIGN);\n goto err;\n }\n *end = \'\\0\';\n p++;\n start = eat_ws(conf, p);\n while (!IS_EOF(conf, *p))\n p++;\n p--;\n while ((p != start) && (IS_WS(conf, *p)))\n p--;\n p++;\n *p = \'\\0\';\n if ((v = OPENSSL_malloc(sizeof(*v))) == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (psection == NULL)\n psection = section;\n v->name = OPENSSL_malloc(strlen(pname) + 1);\n v->value = NULL;\n if (v->name == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n OPENSSL_strlcpy(v->name, pname, strlen(pname) + 1);\n if (!str_copy(conf, psection, &(v->value), start))\n goto err;\n if (strcmp(psection, section) != 0) {\n if ((tv = _CONF_get_section(conf, psection))\n == NULL)\n tv = _CONF_new_section(conf, psection);\n if (tv == NULL) {\n CONFerr(CONF_F_DEF_LOAD_BIO,\n CONF_R_UNABLE_TO_CREATE_NEW_SECTION);\n goto err;\n }\n } else\n tv = sv;\n if (_CONF_add_string(conf, tv, v) == 0) {\n CONFerr(CONF_F_DEF_LOAD_BIO, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n v = NULL;\n }\n }\n BUF_MEM_free(buff);\n OPENSSL_free(section);\n return (1);\n err:\n BUF_MEM_free(buff);\n OPENSSL_free(section);\n if (line != NULL)\n *line = eline;\n BIO_snprintf(btmp, sizeof btmp, "%ld", eline);\n ERR_add_error_data(2, "line ", btmp);\n if (h != conf->data) {\n CONF_free(conf->data);\n conf->data = NULL;\n }\n if (v != NULL) {\n OPENSSL_free(v->name);\n OPENSSL_free(v->value);\n OPENSSL_free(v);\n }\n return (0);\n}', 'size_t BUF_MEM_grow(BUF_MEM *str, size_t len)\n{\n char *ret;\n size_t n;\n if (str->length >= len) {\n str->length = len;\n return (len);\n }\n if (str->max >= len) {\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n return (len);\n }\n if (len > LIMIT_BEFORE_EXPANSION) {\n BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n n = (len + 3) / 3 * 4;\n if ((str->flags & BUF_MEM_FLAG_SECURE))\n ret = sec_alloc_realloc(str, n);\n else\n ret = OPENSSL_realloc(str->data, n);\n if (ret == NULL) {\n BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);\n len = 0;\n } else {\n str->data = ret;\n str->max = n;\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n }\n return (len);\n}', 'static char *sec_alloc_realloc(BUF_MEM *str, size_t len)\n{\n char *ret;\n ret = OPENSSL_secure_malloc(len);\n if (str->data != NULL) {\n if (ret != NULL)\n memcpy(ret, str->data, str->length);\n OPENSSL_secure_free(str->data);\n }\n return (ret);\n}', 'void CRYPTO_secure_free(void *ptr)\n{\n#ifdef IMPLEMENTED\n size_t actual_size;\n if (ptr == NULL)\n return;\n if (!secure_mem_initialized) {\n CRYPTO_free(ptr);\n return;\n }\n LOCK();\n actual_size = sh_actual_size(ptr);\n CLEAR(ptr, actual_size);\n secure_mem_used -= actual_size;\n sh_free(ptr);\n UNLOCK();\n#else\n CRYPTO_free(ptr);\n#endif\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}']
34,907
0
https://github.com/openssl/openssl/blob/c869c3ada944bc42a6c00e0433c9d523c4426cde/crypto/x509/x509_lu.c/#L631
X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, X509_OBJECT *x) { int idx, i; X509_OBJECT *obj; idx = sk_X509_OBJECT_find(h, x); if (idx == -1) return NULL; if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL)) return sk_X509_OBJECT_value(h, idx); for (i = idx; i < sk_X509_OBJECT_num(h); i++) { obj = sk_X509_OBJECT_value(h, i); if (x509_object_cmp ((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x)) return NULL; if (x->type == X509_LU_X509) { if (!X509_cmp(obj->data.x509, x->data.x509)) return obj; } else if (x->type == X509_LU_CRL) { if (!X509_CRL_match(obj->data.crl, x->data.crl)) return obj; } else return obj; } return NULL; }
['X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h,\n X509_OBJECT *x)\n{\n int idx, i;\n X509_OBJECT *obj;\n idx = sk_X509_OBJECT_find(h, x);\n if (idx == -1)\n return NULL;\n if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL))\n return sk_X509_OBJECT_value(h, idx);\n for (i = idx; i < sk_X509_OBJECT_num(h); i++) {\n obj = sk_X509_OBJECT_value(h, i);\n if (x509_object_cmp\n ((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x))\n return NULL;\n if (x->type == X509_LU_X509) {\n if (!X509_cmp(obj->data.x509, x->data.x509))\n return obj;\n } else if (x->type == X509_LU_CRL) {\n if (!X509_CRL_match(obj->data.crl, x->data.crl))\n return obj;\n } else\n return obj;\n }\n return NULL;\n}', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n int ret_val_options)\n{\n const void *r;\n int i;\n if (st == NULL || st->num == 0)\n return -1;\n if (st->comp == NULL) {\n for (i = 0; i < st->num; i++)\n if (st->data[i] == data)\n return i;\n return -1;\n }\n if (!st->sorted) {\n if (st->num > 1)\n qsort(st->data, st->num, sizeof(void *), st->comp);\n st->sorted = 1;\n }\n if (data == NULL)\n return -1;\n r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n ret_val_options);\n return r == NULL ? -1 : (int)((const void **)r - st->data);\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n return st == NULL ? -1 : st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}', 'static int x509_object_cmp(const X509_OBJECT *const *a,\n const X509_OBJECT *const *b)\n{\n int ret;\n ret = ((*a)->type - (*b)->type);\n if (ret)\n return ret;\n switch ((*a)->type) {\n case X509_LU_X509:\n ret = X509_subject_name_cmp((*a)->data.x509, (*b)->data.x509);\n break;\n case X509_LU_CRL:\n ret = X509_CRL_cmp((*a)->data.crl, (*b)->data.crl);\n break;\n case X509_LU_NONE:\n return 0;\n }\n return ret;\n}']
34,908
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/ac3.c/#L141
void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, int start, int end, int fast_gain, int is_lfe, int dba_mode, int dba_nsegs, uint8_t *dba_offsets, uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask) { int16_t excite[50]; int bin, k; int bndstrt, bndend, begin, end1, tmp; int lowcomp, fastleak, slowleak; bndstrt = bin_to_band_tab[start]; bndend = bin_to_band_tab[end-1] + 1; if (bndstrt == 0) { lowcomp = 0; lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384); excite[0] = band_psd[0] - fast_gain - lowcomp; lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384); excite[1] = band_psd[1] - fast_gain - lowcomp; begin = 7; for (bin = 2; bin < 7; bin++) { if (!(is_lfe && bin == 6)) lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384); fastleak = band_psd[bin] - fast_gain; slowleak = band_psd[bin] - s->slow_gain; excite[bin] = fastleak - lowcomp; if (!(is_lfe && bin == 6)) { if (band_psd[bin] <= band_psd[bin+1]) { begin = bin + 1; break; } } } end1=bndend; if (end1 > 22) end1=22; for (bin = begin; bin < end1; bin++) { if (!(is_lfe && bin == 6)) lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin); fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); excite[bin] = FFMAX(fastleak - lowcomp, slowleak); } begin = 22; } else { begin = bndstrt; fastleak = (s->cpl_fast_leak << 8) + 768; slowleak = (s->cpl_slow_leak << 8) + 768; } for (bin = begin; bin < bndend; bin++) { fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); excite[bin] = FFMAX(fastleak, slowleak); } for (bin = bndstrt; bin < bndend; bin++) { tmp = s->db_per_bit - band_psd[bin]; if (tmp > 0) { excite[bin] += tmp >> 2; } mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]); } if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) { int band, seg, delta; band = 0; for (seg = 0; seg < dba_nsegs; seg++) { band += dba_offsets[seg]; if (dba_values[seg] >= 4) { delta = (dba_values[seg] - 3) << 7; } else { delta = (dba_values[seg] - 4) << 7; } for (k = 0; k < dba_lengths[seg]; k++) { mask[band] += delta; band++; } } } }
['void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd,\n int start, int end, int fast_gain, int is_lfe,\n int dba_mode, int dba_nsegs, uint8_t *dba_offsets,\n uint8_t *dba_lengths, uint8_t *dba_values,\n int16_t *mask)\n{\n int16_t excite[50];\n int bin, k;\n int bndstrt, bndend, begin, end1, tmp;\n int lowcomp, fastleak, slowleak;\n bndstrt = bin_to_band_tab[start];\n bndend = bin_to_band_tab[end-1] + 1;\n if (bndstrt == 0) {\n lowcomp = 0;\n lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384);\n excite[0] = band_psd[0] - fast_gain - lowcomp;\n lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384);\n excite[1] = band_psd[1] - fast_gain - lowcomp;\n begin = 7;\n for (bin = 2; bin < 7; bin++) {\n if (!(is_lfe && bin == 6))\n lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384);\n fastleak = band_psd[bin] - fast_gain;\n slowleak = band_psd[bin] - s->slow_gain;\n excite[bin] = fastleak - lowcomp;\n if (!(is_lfe && bin == 6)) {\n if (band_psd[bin] <= band_psd[bin+1]) {\n begin = bin + 1;\n break;\n }\n }\n }\n end1=bndend;\n if (end1 > 22) end1=22;\n for (bin = begin; bin < end1; bin++) {\n if (!(is_lfe && bin == 6))\n lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin);\n fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);\n slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);\n excite[bin] = FFMAX(fastleak - lowcomp, slowleak);\n }\n begin = 22;\n } else {\n begin = bndstrt;\n fastleak = (s->cpl_fast_leak << 8) + 768;\n slowleak = (s->cpl_slow_leak << 8) + 768;\n }\n for (bin = begin; bin < bndend; bin++) {\n fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain);\n slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain);\n excite[bin] = FFMAX(fastleak, slowleak);\n }\n for (bin = bndstrt; bin < bndend; bin++) {\n tmp = s->db_per_bit - band_psd[bin];\n if (tmp > 0) {\n excite[bin] += tmp >> 2;\n }\n mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]);\n }\n if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) {\n int band, seg, delta;\n band = 0;\n for (seg = 0; seg < dba_nsegs; seg++) {\n band += dba_offsets[seg];\n if (dba_values[seg] >= 4) {\n delta = (dba_values[seg] - 3) << 7;\n } else {\n delta = (dba_values[seg] - 4) << 7;\n }\n for (k = 0; k < dba_lengths[seg]; k++) {\n mask[band] += delta;\n band++;\n }\n }\n }\n}']
34,909
0
https://github.com/libav/libav/blob/a893655bdaa726a82424367b6456d195be12ebbc/libavformat/cutils.c/#L41
void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem) { int nb, nb_alloc; intptr_t *tab; nb = *nb_ptr; tab = *tab_ptr; if ((nb & (nb - 1)) == 0) { if (nb == 0) nb_alloc = 1; else nb_alloc = nb * 2; tab = av_realloc(tab, nb_alloc * sizeof(intptr_t)); *tab_ptr = tab; } tab[nb++] = elem; *nb_ptr = nb; }
['void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem)\n{\n int nb, nb_alloc;\n intptr_t *tab;\n nb = *nb_ptr;\n tab = *tab_ptr;\n if ((nb & (nb - 1)) == 0) {\n if (nb == 0)\n nb_alloc = 1;\n else\n nb_alloc = nb * 2;\n tab = av_realloc(tab, nb_alloc * sizeof(intptr_t));\n *tab_ptr = tab;\n }\n tab[nb++] = elem;\n *nb_ptr = nb;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if (size > (INT_MAX - 16))\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if (!ptr)\n return av_malloc(size);\n diff = ((char *)ptr)[-1];\n return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
34,910
0
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L333
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) { bn_check_top(b); if (a == b) return a; if (bn_wexpand(a, b->top) == NULL) return NULL; if (b->top > 0) memcpy(a->d, b->d, sizeof(b->d[0]) * b->top); a->top = b->top; a->neg = b->neg; bn_check_top(a); return a; }
['static int file_modmul(STANZA *s)\n{\n BIGNUM *a = getBN(s, "A");\n BIGNUM *b = getBN(s, "B");\n BIGNUM *m = getBN(s, "M");\n BIGNUM *mod_mul = getBN(s, "ModMul");\n BIGNUM *ret = BN_new();\n int st = 0;\n if (a == NULL || b == NULL || m == NULL || mod_mul == NULL || ret == NULL)\n goto err;\n if (!BN_mod_mul(ret, a, b, m, ctx)\n || !equalBN("A * B (mod M)", mod_mul, ret))\n goto err;\n if (BN_is_odd(m)) {\n BN_MONT_CTX *mont = BN_MONT_CTX_new();\n BIGNUM *a_tmp = BN_new();\n BIGNUM *b_tmp = BN_new();\n if (mont == NULL || a_tmp == NULL || b_tmp == NULL\n || !BN_MONT_CTX_set(mont, m, ctx)\n || !BN_nnmod(a_tmp, a, m, ctx)\n || !BN_nnmod(b_tmp, b, m, ctx)\n || !BN_to_montgomery(a_tmp, a_tmp, mont, ctx)\n || !BN_to_montgomery(b_tmp, b_tmp, mont, ctx)\n || !BN_mod_mul_montgomery(ret, a_tmp, b_tmp, mont, ctx)\n || !BN_from_montgomery(ret, ret, mont, ctx)\n || !equalBN("A * B (mod M) (mont)", mod_mul, ret)) {\n st = 0;\n } else {\n st = 1;\n }\n BN_MONT_CTX_free(mont);\n BN_free(a_tmp);\n BN_free(b_tmp);\n if (st == 0)\n goto err;\n }\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(m);\n BN_free(mod_mul);\n BN_free(ret);\n return st;\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_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n int retn = 0;\n#ifdef MONT_WORD\n BIGNUM *t;\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) && BN_copy(t, a))\n retn = BN_from_montgomery_word(ret, t, mont);\n BN_CTX_end(ctx);\n#else\n BIGNUM *t1, *t2;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t1 == NULL || t2 == NULL)\n goto err;\n if (!BN_copy(t1, a))\n goto err;\n BN_mask_bits(t1, mont->ri);\n if (!BN_mul(t2, t1, &mont->Ni, ctx))\n goto err;\n BN_mask_bits(t2, mont->ri);\n if (!BN_mul(t1, t2, &mont->N, ctx))\n goto err;\n if (!BN_add(t2, a, t1))\n goto err;\n if (!BN_rshift(ret, t2, mont->ri))\n goto err;\n if (BN_ucmp(ret, &(mont->N)) >= 0) {\n if (!BN_usub(ret, ret, &(mont->N)))\n goto err;\n }\n retn = 1;\n bn_check_top(ret);\n err:\n BN_CTX_end(ctx);\n#endif\n return (retn);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
34,911
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL;\n BIGNUM *m;\n BIGNUM *xr;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int rv = 0;\n m = BN_new();\n xr = BN_new();\n if (m == NULL || xr == NULL)\n goto err;\n if (!dsa->p || !dsa->q || !dsa->g) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n redo:\n if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n goto err;\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n if (!BN_mod_mul(xr, dsa->priv_key, ret->r, dsa->q, ctx))\n goto err;\n if (!BN_add(ret->s, xr, m))\n goto err;\n if (BN_cmp(ret->s, dsa->q) > 0)\n if (!BN_sub(ret->s, ret->s, dsa->q))\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n goto err;\n if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n goto redo;\n rv = 1;\n err:\n if (rv == 0) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n DSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(xr);\n BN_clear_free(kinv);\n return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n int ret = 0;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n if (k == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_priv_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(k, k, dsa->q))\n goto err;\n if (BN_num_bits(k) <= BN_num_bits(dsa->q)) {\n if (!BN_add(k, k, dsa->q))\n goto err;\n }\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_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}']
34,912
0
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/packet_locl.h/#L36
static ossl_inline void packet_forward(PACKET *pkt, size_t len) { pkt->curr += len; pkt->remaining -= len; }
['int DTLSv1_listen(SSL *s, BIO_ADDR *client)\n{\n int next, n, ret = 0, clearpkt = 0;\n unsigned char cookie[DTLS1_COOKIE_LENGTH];\n unsigned char seq[SEQ_NUM_SIZE];\n const unsigned char *data;\n unsigned char *p, *buf;\n unsigned long reclen, fragoff, fraglen, msglen;\n unsigned int rectype, versmajor, msgseq, msgtype, clientvers, cookielen;\n BIO *rbio, *wbio;\n BUF_MEM *bufm;\n BIO_ADDR *tmpclient = NULL;\n PACKET pkt, msgpkt, msgpayload, session, cookiepkt;\n if (!SSL_clear(s))\n return -1;\n ERR_clear_error();\n rbio = SSL_get_rbio(s);\n wbio = SSL_get_wbio(s);\n if (!rbio || !wbio) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_BIO_NOT_SET);\n return -1;\n }\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNSUPPORTED_SSL_VERSION);\n return -1;\n }\n if (s->init_buf == NULL) {\n if ((bufm = BUF_MEM_new()) == NULL) {\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n if (!BUF_MEM_grow(bufm, SSL3_RT_MAX_PLAIN_LENGTH)) {\n BUF_MEM_free(bufm);\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n s->init_buf = bufm;\n }\n buf = (unsigned char *)s->init_buf->data;\n do {\n clear_sys_error();\n n = BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n if (n <= 0) {\n if (BIO_should_retry(rbio)) {\n goto end;\n }\n return -1;\n }\n clearpkt = 1;\n if (!PACKET_buf_init(&pkt, buf, n)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n if (n < DTLS1_RT_HEADER_LENGTH) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_RECORD_TOO_SMALL);\n goto end;\n }\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, buf,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n if (!PACKET_get_1(&pkt, &rectype)\n || !PACKET_get_1(&pkt, &versmajor)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (rectype != SSL3_RT_HANDSHAKE) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n if (versmajor != DTLS1_VERSION_MAJOR) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_BAD_PROTOCOL_VERSION_NUMBER);\n goto end;\n }\n if (!PACKET_forward(&pkt, 1)\n || !PACKET_copy_bytes(&pkt, seq, SEQ_NUM_SIZE)\n || !PACKET_get_length_prefixed_2(&pkt, &msgpkt)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (seq[0] != 0 || seq[1] != 0) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n data = PACKET_data(&msgpkt);\n if (!PACKET_get_1(&msgpkt, &msgtype)\n || !PACKET_get_net_3(&msgpkt, &msglen)\n || !PACKET_get_net_2(&msgpkt, &msgseq)\n || !PACKET_get_net_3(&msgpkt, &fragoff)\n || !PACKET_get_net_3(&msgpkt, &fraglen)\n || !PACKET_get_sub_packet(&msgpkt, &msgpayload, fraglen)\n || PACKET_remaining(&msgpkt) != 0) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (msgtype != SSL3_MT_CLIENT_HELLO) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n if (msgseq > 2) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_INVALID_SEQUENCE_NUMBER);\n goto end;\n }\n if (fragoff != 0 || fraglen > msglen) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_FRAGMENTED_CLIENT_HELLO);\n goto end;\n }\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, data,\n fraglen + DTLS1_HM_HEADER_LENGTH, s,\n s->msg_callback_arg);\n if (!PACKET_get_net_2(&msgpayload, &clientvers)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (DTLS_VERSION_LT(clientvers, (unsigned int)s->method->version) &&\n s->method->version != DTLS_ANY_VERSION) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_WRONG_VERSION_NUMBER);\n goto end;\n }\n if (!PACKET_forward(&msgpayload, SSL3_RANDOM_SIZE)\n || !PACKET_get_length_prefixed_1(&msgpayload, &session)\n || !PACKET_get_length_prefixed_1(&msgpayload, &cookiepkt)) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (PACKET_remaining(&cookiepkt) == 0) {\n next = LISTEN_SEND_VERIFY_REQUEST;\n } else {\n if (s->ctx->app_verify_cookie_cb == NULL) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_NO_VERIFY_COOKIE_CALLBACK);\n return -1;\n }\n if (s->ctx->app_verify_cookie_cb(s, PACKET_data(&cookiepkt),\n PACKET_remaining(&cookiepkt)) ==\n 0) {\n next = LISTEN_SEND_VERIFY_REQUEST;\n } else {\n next = LISTEN_SUCCESS;\n }\n }\n if (next == LISTEN_SEND_VERIFY_REQUEST) {\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n if (s->ctx->app_gen_cookie_cb == NULL ||\n s->ctx->app_gen_cookie_cb(s, cookie, &cookielen) == 0 ||\n cookielen > 255) {\n SSLerr(SSL_F_DTLSV1_LISTEN, SSL_R_COOKIE_GEN_CALLBACK_FAILURE);\n return -1;\n }\n p = &buf[DTLS1_RT_HEADER_LENGTH];\n msglen = dtls_raw_hello_verify_request(p + DTLS1_HM_HEADER_LENGTH,\n cookie, cookielen);\n *p++ = DTLS1_MT_HELLO_VERIFY_REQUEST;\n l2n3(msglen, p);\n s2n(0, p);\n l2n3(0, p);\n l2n3(msglen, p);\n reclen = msglen + DTLS1_HM_HEADER_LENGTH;\n p = buf;\n *(p++) = SSL3_RT_HANDSHAKE;\n if (s->method->version == DTLS_ANY_VERSION) {\n *(p++) = DTLS1_VERSION >> 8;\n *(p++) = DTLS1_VERSION & 0xff;\n } else {\n *(p++) = s->version >> 8;\n *(p++) = s->version & 0xff;\n }\n memcpy(p, seq, SEQ_NUM_SIZE);\n p += SEQ_NUM_SIZE;\n s2n(reclen, p);\n reclen += DTLS1_RT_HEADER_LENGTH;\n if (s->msg_callback)\n s->msg_callback(1, 0, SSL3_RT_HEADER, buf,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n if ((tmpclient = BIO_ADDR_new()) == NULL) {\n SSLerr(SSL_F_DTLSV1_LISTEN, ERR_R_MALLOC_FAILURE);\n goto end;\n }\n if (BIO_dgram_get_peer(rbio, tmpclient) > 0) {\n (void)BIO_dgram_set_peer(wbio, tmpclient);\n }\n BIO_ADDR_free(tmpclient);\n tmpclient = NULL;\n if (BIO_write(wbio, buf, reclen) < (int)reclen) {\n if (BIO_should_retry(wbio)) {\n goto end;\n }\n return -1;\n }\n if (BIO_flush(wbio) <= 0) {\n if (BIO_should_retry(wbio)) {\n goto end;\n }\n return -1;\n }\n }\n } while (next != LISTEN_SUCCESS);\n s->d1->handshake_read_seq = 1;\n s->d1->handshake_write_seq = 1;\n s->d1->next_handshake_write_seq = 1;\n DTLS_RECORD_LAYER_set_write_sequence(&s->rlayer, seq);\n SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);\n ossl_statem_set_hello_verify_done(s);\n if (BIO_dgram_get_peer(rbio, client) <= 0)\n BIO_ADDR_clear(client);\n ret = 1;\n clearpkt = 0;\n end:\n BIO_ADDR_free(tmpclient);\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n if (clearpkt) {\n BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n }\n return ret;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}']
34,913
0
https://github.com/openssl/openssl/blob/d8028b202bfe337200a0cc89b80983ea1838cb30/crypto/lhash/lhash.c/#L123
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return (NULL); } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return (ret); }
['int ciphers_main(int argc, char **argv)\n{\n SSL_CTX *ctx = NULL;\n SSL *ssl = NULL;\n STACK_OF(SSL_CIPHER) *sk = NULL;\n const SSL_METHOD *meth = TLS_server_method();\n int ret = 1, i, verbose = 0, Verbose = 0, use_supported = 0;\n#ifndef OPENSSL_NO_SSL_TRACE\n int stdname = 0;\n#endif\n#ifndef OPENSSL_NO_PSK\n int psk = 0;\n#endif\n#ifndef OPENSSL_NO_SRP\n int srp = 0;\n#endif\n const char *p;\n char *ciphers = NULL, *prog;\n char buf[512];\n OPTION_CHOICE o;\n int min_version = 0, max_version = 0;\n prog = opt_init(argc, argv, ciphers_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(ciphers_options);\n ret = 0;\n goto end;\n case OPT_V:\n verbose = 1;\n break;\n case OPT_UPPER_V:\n verbose = Verbose = 1;\n break;\n case OPT_S:\n use_supported = 1;\n break;\n case OPT_STDNAME:\n#ifndef OPENSSL_NO_SSL_TRACE\n stdname = verbose = 1;\n#endif\n break;\n case OPT_SSL3:\n min_version = SSL3_VERSION;\n max_version = SSL3_VERSION;\n break;\n case OPT_TLS1:\n min_version = TLS1_VERSION;\n max_version = TLS1_VERSION;\n break;\n case OPT_TLS1_1:\n min_version = TLS1_1_VERSION;\n max_version = TLS1_1_VERSION;\n break;\n case OPT_TLS1_2:\n min_version = TLS1_2_VERSION;\n max_version = TLS1_2_VERSION;\n break;\n case OPT_TLS1_3:\n min_version = TLS1_3_VERSION;\n max_version = TLS1_3_VERSION;\n break;\n case OPT_PSK:\n#ifndef OPENSSL_NO_PSK\n psk = 1;\n#endif\n break;\n case OPT_SRP:\n#ifndef OPENSSL_NO_SRP\n srp = 1;\n#endif\n break;\n }\n }\n argv = opt_rest();\n argc = opt_num_rest();\n if (argc == 1)\n ciphers = *argv;\n else if (argc != 0)\n goto opthelp;\n ctx = SSL_CTX_new(meth);\n if (ctx == NULL)\n goto err;\n if (SSL_CTX_set_min_proto_version(ctx, min_version) == 0)\n goto err;\n if (SSL_CTX_set_max_proto_version(ctx, max_version) == 0)\n goto err;\n#ifndef OPENSSL_NO_PSK\n if (psk)\n SSL_CTX_set_psk_client_callback(ctx, dummy_psk);\n#endif\n#ifndef OPENSSL_NO_SRP\n if (srp)\n SSL_CTX_set_srp_client_pwd_callback(ctx, dummy_srp);\n#endif\n if (ciphers != NULL) {\n if (!SSL_CTX_set_cipher_list(ctx, ciphers)) {\n BIO_printf(bio_err, "Error in cipher list\\n");\n goto err;\n }\n }\n ssl = SSL_new(ctx);\n if (ssl == NULL)\n goto err;\n if (use_supported)\n sk = SSL_get1_supported_ciphers(ssl);\n else\n sk = SSL_get_ciphers(ssl);\n if (!verbose) {\n for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {\n const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, i);\n p = SSL_CIPHER_get_name(c);\n if (p == NULL)\n break;\n if (i != 0)\n BIO_printf(bio_out, ":");\n BIO_printf(bio_out, "%s", p);\n }\n BIO_printf(bio_out, "\\n");\n } else {\n for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) {\n const SSL_CIPHER *c;\n c = sk_SSL_CIPHER_value(sk, i);\n if (Verbose) {\n unsigned long id = SSL_CIPHER_get_id(c);\n int id0 = (int)(id >> 24);\n int id1 = (int)((id >> 16) & 0xffL);\n int id2 = (int)((id >> 8) & 0xffL);\n int id3 = (int)(id & 0xffL);\n if ((id & 0xff000000L) == 0x03000000L)\n BIO_printf(bio_out, " 0x%02X,0x%02X - ", id2, id3);\n else\n BIO_printf(bio_out, "0x%02X,0x%02X,0x%02X,0x%02X - ", id0, id1, id2, id3);\n }\n#ifndef OPENSSL_NO_SSL_TRACE\n if (stdname) {\n const char *nm = SSL_CIPHER_standard_name(c);\n if (nm == NULL)\n nm = "UNKNOWN";\n BIO_printf(bio_out, "%s - ", nm);\n }\n#endif\n BIO_puts(bio_out, SSL_CIPHER_description(c, buf, sizeof buf));\n }\n }\n ret = 0;\n goto end;\n err:\n ERR_print_errors(bio_err);\n end:\n if (use_supported)\n sk_SSL_CIPHER_free(sk);\n SSL_CTX_free(ctx);\n SSL_free(ssl);\n return (ret);\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(s);\n return NULL;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->references = 1;\n s->max_early_data = ctx->max_early_data;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len);\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n BIO_free_all(s->rbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return (1);\n } else\n return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
34,914
0
https://github.com/openssl/openssl/blob/7671342e550ed2de676b23c79d0e7f45a381c76e/crypto/pem/pem_lib.c/#L768
static int get_name(BIO *bp, char **name, unsigned int flags) { char *linebuf; int ret = 0; size_t len; linebuf = pem_malloc(LINESIZE + 1, flags); if (linebuf == NULL) { PEMerr(PEM_F_GET_NAME, ERR_R_MALLOC_FAILURE); return 0; } do { len = BIO_gets(bp, linebuf, LINESIZE); if (len <= 0) { PEMerr(PEM_F_GET_NAME, PEM_R_NO_START_LINE); goto err; } len = sanitize_line(linebuf, len, flags & ~PEM_FLAG_ONLY_B64); } while (strncmp(linebuf, beginstr, BEGINLEN) != 0 || len < TAILLEN || strncmp(linebuf + len - TAILLEN, tailstr, TAILLEN) != 0); linebuf[len - TAILLEN] = '\0'; len = len - BEGINLEN - TAILLEN + 1; *name = pem_malloc(len, flags); if (*name == NULL) { PEMerr(PEM_F_GET_NAME, ERR_R_MALLOC_FAILURE); goto err; } memcpy(*name, linebuf + BEGINLEN, len); ret = 1; err: pem_free(linebuf, flags); return ret; }
["static int get_name(BIO *bp, char **name, unsigned int flags)\n{\n char *linebuf;\n int ret = 0;\n size_t len;\n linebuf = pem_malloc(LINESIZE + 1, flags);\n if (linebuf == NULL) {\n PEMerr(PEM_F_GET_NAME, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n do {\n len = BIO_gets(bp, linebuf, LINESIZE);\n if (len <= 0) {\n PEMerr(PEM_F_GET_NAME, PEM_R_NO_START_LINE);\n goto err;\n }\n len = sanitize_line(linebuf, len, flags & ~PEM_FLAG_ONLY_B64);\n } while (strncmp(linebuf, beginstr, BEGINLEN) != 0\n || len < TAILLEN\n || strncmp(linebuf + len - TAILLEN, tailstr, TAILLEN) != 0);\n linebuf[len - TAILLEN] = '\\0';\n len = len - BEGINLEN - TAILLEN + 1;\n *name = pem_malloc(len, flags);\n if (*name == NULL) {\n PEMerr(PEM_F_GET_NAME, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(*name, linebuf + BEGINLEN, len);\n ret = 1;\nerr:\n pem_free(linebuf, flags);\n return ret;\n}", 'int BIO_gets(BIO *b, char *buf, int size)\n{\n int ret;\n size_t readbytes = 0;\n if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) {\n BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD);\n return (-2);\n }\n if (size < 0) {\n BIOerr(BIO_F_BIO_GETS, BIO_R_INVALID_ARGUMENT);\n return 0;\n }\n if (b->callback != NULL || b->callback_ex != NULL) {\n ret = (int)bio_call_callback(b, BIO_CB_GETS, buf, size, 0, 0L, 1, NULL);\n if (ret <= 0)\n return ret;\n }\n if (!b->init) {\n BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED);\n return (-2);\n }\n ret = b->method->bgets(b, buf, size);\n if (ret > 0) {\n readbytes = ret;\n ret = 1;\n }\n if (b->callback != NULL || b->callback_ex != NULL)\n ret = (int)bio_call_callback(b, BIO_CB_GETS | BIO_CB_RETURN, buf, size,\n 0, 0L, ret, &readbytes);\n if (ret > 0) {\n if (readbytes > (size_t)size)\n ret = -1;\n else\n ret = (int)readbytes;\n }\n return ret;\n}', "static int sanitize_line(char *linebuf, int len, unsigned int flags)\n{\n int i;\n if (flags & PEM_FLAG_EAY_COMPATIBLE) {\n while ((len >= 0) && (linebuf[len] <= ' '))\n len--;\n len++;\n } else if (flags & PEM_FLAG_ONLY_B64) {\n for (i = 0; i < len; ++i) {\n if (!isb64(linebuf[i]) || linebuf[i] == '\\n' || linebuf[i] == '\\r')\n break;\n }\n len = i;\n } else {\n for (i = 0; i < len; ++i) {\n if (linebuf[i] == '\\n' || linebuf[i] == '\\r')\n break;\n if (iscntrl(linebuf[i]))\n linebuf[i] = ' ';\n }\n len = i;\n }\n linebuf[len++] = '\\n';\n linebuf[len] = '\\0';\n return len;\n}"]
34,915
0
https://github.com/openssl/openssl/blob/a44a208442ecf8f576c9e364f8b46b6661c7d2de/crypto/x509v3/v3_conf.c/#L216
static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method, int ext_nid, int crit, void *ext_struc) { unsigned char *ext_der = NULL; int ext_len; ASN1_OCTET_STRING *ext_oct = NULL; X509_EXTENSION *ext; if (method->it) { ext_der = NULL; ext_len = ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it)); if (ext_len < 0) goto merr; } else { unsigned char *p; ext_len = method->i2d(ext_struc, NULL); if ((ext_der = OPENSSL_malloc(ext_len)) == NULL) goto merr; p = ext_der; method->i2d(ext_struc, &p); } if ((ext_oct = ASN1_OCTET_STRING_new()) == NULL) goto merr; ext_oct->data = ext_der; ext_der = NULL; ext_oct->length = ext_len; ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct); if (!ext) goto merr; ASN1_OCTET_STRING_free(ext_oct); return ext; merr: X509V3err(X509V3_F_DO_EXT_I2D, ERR_R_MALLOC_FAILURE); OPENSSL_free(ext_der); ASN1_OCTET_STRING_free(ext_oct); return NULL; }
['static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method,\n int ext_nid, int crit, void *ext_struc)\n{\n unsigned char *ext_der = NULL;\n int ext_len;\n ASN1_OCTET_STRING *ext_oct = NULL;\n X509_EXTENSION *ext;\n if (method->it) {\n ext_der = NULL;\n ext_len =\n ASN1_item_i2d(ext_struc, &ext_der, ASN1_ITEM_ptr(method->it));\n if (ext_len < 0)\n goto merr;\n } else {\n unsigned char *p;\n ext_len = method->i2d(ext_struc, NULL);\n if ((ext_der = OPENSSL_malloc(ext_len)) == NULL)\n goto merr;\n p = ext_der;\n method->i2d(ext_struc, &p);\n }\n if ((ext_oct = ASN1_OCTET_STRING_new()) == NULL)\n goto merr;\n ext_oct->data = ext_der;\n ext_der = NULL;\n ext_oct->length = ext_len;\n ext = X509_EXTENSION_create_by_NID(NULL, ext_nid, crit, ext_oct);\n if (!ext)\n goto merr;\n ASN1_OCTET_STRING_free(ext_oct);\n return ext;\n merr:\n X509V3err(X509V3_F_DO_EXT_I2D, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(ext_der);\n ASN1_OCTET_STRING_free(ext_oct);\n return NULL;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n 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#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}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)', 'X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid,\n int crit,\n ASN1_OCTET_STRING *data)\n{\n ASN1_OBJECT *obj;\n X509_EXTENSION *ret;\n obj = OBJ_nid2obj(nid);\n if (obj == NULL) {\n X509err(X509_F_X509_EXTENSION_CREATE_BY_NID, X509_R_UNKNOWN_NID);\n return (NULL);\n }\n ret = X509_EXTENSION_create_by_OBJ(ex, obj, crit, data);\n if (ret == NULL)\n ASN1_OBJECT_free(obj);\n return (ret);\n}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n{\n ADDED_OBJ ad, *adp;\n ASN1_OBJECT ob;\n if ((n >= 0) && (n < NUM_NID)) {\n if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {\n OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);\n return (NULL);\n }\n return ((ASN1_OBJECT *)&(nid_objs[n]));\n } else if (added == NULL)\n return (NULL);\n else {\n ad.type = ADDED_NID;\n ad.obj = &ob;\n ob.nid = n;\n adp = lh_ADDED_OBJ_retrieve(added, &ad);\n if (adp != NULL)\n return (adp->obj);\n else {\n OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);\n return (NULL);\n }\n }\n}', 'DEFINE_LHASH_OF(ADDED_OBJ)', 'void *lh_retrieve(_LHASH *lh, const void *data)\n{\n unsigned long hash;\n LHASH_NODE **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_retrieve_miss++;\n return (NULL);\n } else {\n ret = (*rn)->data;\n lh->num_retrieve++;\n }\n return (ret);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', '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}']
34,916
0
https://github.com/libav/libav/blob/9104cd5161ec7cb31361f3dabd73a8a813d4f7d0/libavcodec/sonic.c/#L809
static av_cold int sonic_decode_init(AVCodecContext *avctx) { SonicContext *s = avctx->priv_data; GetBitContext gb; int i, version; s->channels = avctx->channels; s->samplerate = avctx->sample_rate; if (!avctx->extradata) { av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n"); return -1; } init_get_bits(&gb, avctx->extradata, avctx->extradata_size); version = get_bits(&gb, 2); if (version > 1) { av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n"); return -1; } if (version == 1) { s->channels = get_bits(&gb, 2); s->samplerate = samplerate_table[get_bits(&gb, 4)]; av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n", s->channels, s->samplerate); } if (s->channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n"); return -1; } s->lossless = get_bits1(&gb); if (!s->lossless) skip_bits(&gb, 3); s->decorrelation = get_bits(&gb, 2); s->downsampling = get_bits(&gb, 2); s->num_taps = (get_bits(&gb, 5)+1)<<5; if (get_bits1(&gb)) av_log(avctx, AV_LOG_INFO, "Custom quant table\n"); s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling; s->frame_size = s->channels*s->block_align*s->downsampling; av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n", version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling); s->tap_quant = av_mallocz(4* s->num_taps); for (i = 0; i < s->num_taps; i++) s->tap_quant[i] = (int)(sqrt(i+1)); s->predictor_k = av_mallocz(4* s->num_taps); for (i = 0; i < s->channels; i++) { s->predictor_state[i] = av_mallocz(4* s->num_taps); if (!s->predictor_state[i]) return -1; } for (i = 0; i < s->channels; i++) { s->coded_samples[i] = av_mallocz(4* s->block_align); if (!s->coded_samples[i]) return -1; } s->int_samples = av_mallocz(4* s->frame_size); avctx->sample_fmt = SAMPLE_FMT_S16; return 0; }
['static av_cold int sonic_decode_init(AVCodecContext *avctx)\n{\n SonicContext *s = avctx->priv_data;\n GetBitContext gb;\n int i, version;\n s->channels = avctx->channels;\n s->samplerate = avctx->sample_rate;\n if (!avctx->extradata)\n {\n av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\\n");\n return -1;\n }\n init_get_bits(&gb, avctx->extradata, avctx->extradata_size);\n version = get_bits(&gb, 2);\n if (version > 1)\n {\n av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\\n");\n return -1;\n }\n if (version == 1)\n {\n s->channels = get_bits(&gb, 2);\n s->samplerate = samplerate_table[get_bits(&gb, 4)];\n av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\\n",\n s->channels, s->samplerate);\n }\n if (s->channels > MAX_CHANNELS)\n {\n av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\\n");\n return -1;\n }\n s->lossless = get_bits1(&gb);\n if (!s->lossless)\n skip_bits(&gb, 3);\n s->decorrelation = get_bits(&gb, 2);\n s->downsampling = get_bits(&gb, 2);\n s->num_taps = (get_bits(&gb, 5)+1)<<5;\n if (get_bits1(&gb))\n av_log(avctx, AV_LOG_INFO, "Custom quant table\\n");\n s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling;\n s->frame_size = s->channels*s->block_align*s->downsampling;\n av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\\n",\n version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);\n s->tap_quant = av_mallocz(4* s->num_taps);\n for (i = 0; i < s->num_taps; i++)\n s->tap_quant[i] = (int)(sqrt(i+1));\n s->predictor_k = av_mallocz(4* s->num_taps);\n for (i = 0; i < s->channels; i++)\n {\n s->predictor_state[i] = av_mallocz(4* s->num_taps);\n if (!s->predictor_state[i])\n return -1;\n }\n for (i = 0; i < s->channels; i++)\n {\n s->coded_samples[i] = av_mallocz(4* s->block_align);\n if (!s->coded_samples[i])\n return -1;\n }\n s->int_samples = av_mallocz(4* s->frame_size);\n avctx->sample_fmt = SAMPLE_FMT_S16;\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits(GetBitContext *s, int n){\n register int tmp;\n OPEN_READER(re, s)\n UPDATE_CACHE(re, s)\n tmp= SHOW_UBITS(re, s, n);\n LAST_SKIP_BITS(re, s, n)\n CLOSE_READER(re, s)\n return tmp;\n}', 'static av_always_inline av_const uint32_t bswap_32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\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&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n 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}']
34,917
0
https://github.com/libav/libav/blob/b5c1c16247ab7d166c84eaf4564e49a1535fdaaf/libavcodec/simple_idct.c/#L164
static inline void idct4row(int16_t *row) { int c0, c1, c2, c3, a0, a1, a2, a3; a0 = row[0]; a1 = row[1]; a2 = row[2]; a3 = row[3]; c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1)); c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1)); c1 = a1 * R1 + a3 * R2; c3 = a1 * R2 - a3 * R1; row[0]= (c0 + c1) >> R_SHIFT; row[1]= (c2 + c3) >> R_SHIFT; row[2]= (c2 - c3) >> R_SHIFT; row[3]= (c0 - c1) >> R_SHIFT; }
['void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],\n uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr)\n{\n Wmv2Context *const w = (Wmv2Context *) s;\n wmv2_add_block(w, block1[0], dest_y, s->linesize, 0);\n wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1);\n wmv2_add_block(w, block1[2], dest_y + 8 * s->linesize, s->linesize, 2);\n wmv2_add_block(w, block1[3], dest_y + 8 + 8 * s->linesize, s->linesize, 3);\n if (s->avctx->flags & AV_CODEC_FLAG_GRAY)\n return;\n wmv2_add_block(w, block1[4], dest_cb, s->uvlinesize, 4);\n wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);\n}', 'static void wmv2_add_block(Wmv2Context *w, int16_t *block1,\n uint8_t *dst, int stride, int n)\n{\n MpegEncContext *const s = &w->s;\n if (s->block_last_index[n] >= 0) {\n switch (w->abt_type_table[n]) {\n case 0:\n w->wdsp.idct_add(dst, stride, block1);\n break;\n case 1:\n ff_simple_idct84_add(dst, stride, block1);\n ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]);\n s->bdsp.clear_block(w->abt_block2[n]);\n break;\n case 2:\n ff_simple_idct48_add(dst, stride, block1);\n ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]);\n s->bdsp.clear_block(w->abt_block2[n]);\n break;\n default:\n av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\\n");\n }\n }\n}', 'void ff_simple_idct48_add(uint8_t *dest, int line_size, int16_t *block)\n{\n int i;\n for(i=0; i<8; i++) {\n idct4row(block + i*8);\n }\n for(i=0; i<4; i++){\n idctSparseColAdd_8(dest + i, line_size, block + i);\n }\n}', 'static inline void idct4row(int16_t *row)\n{\n int c0, c1, c2, c3, a0, a1, a2, a3;\n a0 = row[0];\n a1 = row[1];\n a2 = row[2];\n a3 = row[3];\n c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));\n c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));\n c1 = a1 * R1 + a3 * R2;\n c3 = a1 * R2 - a3 * R1;\n row[0]= (c0 + c1) >> R_SHIFT;\n row[1]= (c2 + c3) >> R_SHIFT;\n row[2]= (c2 - c3) >> R_SHIFT;\n row[3]= (c0 - c1) >> R_SHIFT;\n}']
34,918
0
https://github.com/openssl/openssl/blob/d9c989fe3f137580ee627c91e01245e78b0b41ff/apps/x509.c/#L1017
static int x509_certify(X509_STORE *ctx, const char *CAfile, const EVP_MD *digest, X509 *x, X509 *xca, EVP_PKEY *pkey, STACK_OF(OPENSSL_STRING) *sigopts, const char *serialfile, int create, int days, int clrext, CONF *conf, const char *section, ASN1_INTEGER *sno, int reqfile, int preserve_dates) { int ret = 0; ASN1_INTEGER *bs = NULL; X509_STORE_CTX *xsc = NULL; EVP_PKEY *upkey; upkey = X509_get0_pubkey(xca); if (upkey == NULL) { BIO_printf(bio_err, "Error obtaining CA X509 public key\n"); goto end; } EVP_PKEY_copy_parameters(upkey, pkey); xsc = X509_STORE_CTX_new(); if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) { BIO_printf(bio_err, "Error initialising X509 store\n"); goto end; } if (sno) bs = sno; else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL) goto end; X509_STORE_CTX_set_cert(xsc, x); X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_CHECK_SS_SIGNATURE); if (!reqfile && X509_verify_cert(xsc) <= 0) goto end; if (!X509_check_private_key(xca, pkey)) { BIO_printf(bio_err, "CA certificate and CA private key do not match\n"); goto end; } if (!X509_set_issuer_name(x, X509_get_subject_name(xca))) goto end; if (!X509_set_serialNumber(x, bs)) goto end; if (!preserve_dates && !set_cert_times(x, NULL, NULL, days)) goto end; if (clrext) { while (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); } if (conf != NULL) { X509V3_CTX ctx2; X509_set_version(x, 2); X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0); X509V3_set_nconf(&ctx2, conf); if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x)) goto end; } if (!do_X509_sign(x, pkey, digest, sigopts)) goto end; ret = 1; end: X509_STORE_CTX_free(xsc); if (!ret) ERR_print_errors(bio_err); if (!sno) ASN1_INTEGER_free(bs); return ret; }
['static int x509_certify(X509_STORE *ctx, const char *CAfile, const EVP_MD *digest,\n X509 *x, X509 *xca, EVP_PKEY *pkey,\n STACK_OF(OPENSSL_STRING) *sigopts,\n const char *serialfile, int create,\n int days, int clrext, CONF *conf, const char *section,\n ASN1_INTEGER *sno, int reqfile, int preserve_dates)\n{\n int ret = 0;\n ASN1_INTEGER *bs = NULL;\n X509_STORE_CTX *xsc = NULL;\n EVP_PKEY *upkey;\n upkey = X509_get0_pubkey(xca);\n if (upkey == NULL) {\n BIO_printf(bio_err, "Error obtaining CA X509 public key\\n");\n goto end;\n }\n EVP_PKEY_copy_parameters(upkey, pkey);\n xsc = X509_STORE_CTX_new();\n if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {\n BIO_printf(bio_err, "Error initialising X509 store\\n");\n goto end;\n }\n if (sno)\n bs = sno;\n else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL)\n goto end;\n X509_STORE_CTX_set_cert(xsc, x);\n X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);\n if (!reqfile && X509_verify_cert(xsc) <= 0)\n goto end;\n if (!X509_check_private_key(xca, pkey)) {\n BIO_printf(bio_err,\n "CA certificate and CA private key do not match\\n");\n goto end;\n }\n if (!X509_set_issuer_name(x, X509_get_subject_name(xca)))\n goto end;\n if (!X509_set_serialNumber(x, bs))\n goto end;\n if (!preserve_dates && !set_cert_times(x, NULL, NULL, days))\n goto end;\n if (clrext) {\n while (X509_get_ext_count(x) > 0)\n X509_delete_ext(x, 0);\n }\n if (conf != NULL) {\n X509V3_CTX ctx2;\n X509_set_version(x, 2);\n X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n X509V3_set_nconf(&ctx2, conf);\n if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x))\n goto end;\n }\n if (!do_X509_sign(x, pkey, digest, sigopts))\n goto end;\n ret = 1;\n end:\n X509_STORE_CTX_free(xsc);\n if (!ret)\n ERR_print_errors(bio_err);\n if (!sno)\n ASN1_INTEGER_free(bs);\n return ret;\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n{\n if (to->type == EVP_PKEY_NONE) {\n if (EVP_PKEY_set_type(to, from->type) == 0)\n return 0;\n } else if (to->type != from->type) {\n EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);\n goto err;\n }\n if (EVP_PKEY_missing_parameters(from)) {\n EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_MISSING_PARAMETERS);\n goto err;\n }\n if (!EVP_PKEY_missing_parameters(to)) {\n if (EVP_PKEY_cmp_parameters(to, from) == 1)\n return 1;\n EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_PARAMETERS);\n return 0;\n }\n if (from->ameth && from->ameth->param_copy)\n return from->ameth->param_copy(to, from);\n err:\n return 0;\n}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL) {\n X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)\n{\n ctx->cert = x;\n}', 'void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags)\n{\n X509_VERIFY_PARAM_set_flags(ctx->param, flags);\n}', 'int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)\n{\n param->flags |= flags;\n if (flags & X509_V_FLAG_POLICY_MASK)\n param->flags |= X509_V_FLAG_POLICY_CHECK;\n return 1;\n}', 'int X509_verify_cert(X509_STORE_CTX *ctx)\n{\n SSL_DANE *dane = ctx->dane;\n int ret;\n if (ctx->cert == NULL) {\n X509err(X509_F_X509_VERIFY_CERT, X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);\n ctx->error = X509_V_ERR_INVALID_CALL;\n return -1;\n }\n if (ctx->chain != NULL) {\n X509err(X509_F_X509_VERIFY_CERT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n ctx->error = X509_V_ERR_INVALID_CALL;\n return -1;\n }\n if (((ctx->chain = sk_X509_new_null()) == NULL) ||\n (!sk_X509_push(ctx->chain, ctx->cert))) {\n X509err(X509_F_X509_VERIFY_CERT, ERR_R_MALLOC_FAILURE);\n ctx->error = X509_V_ERR_OUT_OF_MEM;\n return -1;\n }\n X509_up_ref(ctx->cert);\n ctx->num_untrusted = 1;\n if (!check_key_level(ctx, ctx->cert) &&\n !verify_cb_cert(ctx, ctx->cert, 0, X509_V_ERR_EE_KEY_TOO_SMALL))\n return 0;\n if (DANETLS_ENABLED(dane))\n ret = dane_verify(ctx);\n else\n ret = verify_chain(ctx);\n if (ret <= 0 && ctx->error == X509_V_OK)\n ctx->error = X509_V_ERR_UNSPECIFIED;\n return ret;\n}', 'DEFINE_STACK_OF(X509)', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_sk_new_reserve(NULL, 0);\n}', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n if (st == NULL)\n return -1;\n return OPENSSL_sk_insert(st, data, st->num);\n}', 'int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)\n{\n if (st == NULL || st->num == max_nodes)\n return 0;\n if (!sk_reserve(st, 1, 0))\n return 0;\n if ((loc >= st->num) || (loc < 0)) {\n st->data[st->num] = data;\n } else {\n memmove(&st->data[loc + 1], &st->data[loc],\n sizeof(st->data[0]) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return st->num;\n}', 'void X509_STORE_CTX_free(X509_STORE_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n X509_STORE_CTX_cleanup(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
34,919
0
https://github.com/openssl/openssl/blob/00fe865dbec8fb626a63ed9f5b0be4073597c7a8/crypto/lhash/lhash.c/#L240
void *lh_delete(LHASH *lh, const void *data) { unsigned long hash; LHASH_NODE *nn,**rn; void *ret; lh->error=0; rn=getrn(lh,data,&hash); if (*rn == NULL) { lh->num_no_delete++; return(NULL); } else { nn= *rn; *rn=nn->next; ret=nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) contract(lh); return(ret); }
['int dtls1_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long l,Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tlong num1;\n\tint ret= -1;\n\tint new_state,state,skip=0;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tif (s->cert == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_NO_CERTIFICATE_SET);\n\t\treturn(-1);\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch (s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_ACCEPT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_ACCEPT:\n\t\tcase SSL_ST_OK|SSL_ST_ACCEPT:\n\t\t\ts->server=1;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_DTLS1_ACCEPT, ERR_R_INTERNAL_ERROR);\n\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_ACCEPT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tif (s->state != SSL_ST_RENEGOTIATE)\n\t\t\t\t{\n\t\t\t\tif (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }\n\t\t\t\tssl3_init_finished_mac(s);\n\t\t\t\ts->state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\t\t\ts->ctx->stats.sess_accept++;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->ctx->stats.sess_accept_renegotiate++;\n\t\t\t\ts->state=SSL3_ST_SW_HELLO_REQ_A;\n\t\t\t\t}\n if ( (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE))\n s->d1->send_cookie = 1;\n else\n s->d1->send_cookie = 0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_A:\n\t\tcase SSL3_ST_SW_HELLO_REQ_B:\n\t\t\ts->shutdown=0;\n\t\t\tret=dtls1_send_hello_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_C:\n\t\t\ts->state=SSL_ST_OK;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CLNT_HELLO_A:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_B:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_C:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_get_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->new_session = 2;\n\t\t\tif ( s->d1->send_cookie)\n\t\t\t\ts->state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A;\n\t\t\telse\n\t\t\t\ts->state = SSL3_ST_SW_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:\n\t\tcase DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:\n\t\t\tret = dtls1_send_hello_verify_request(s);\n\t\t\tif ( ret <= 0) goto end;\n\t\t\ts->d1->send_cookie = 0;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_HELLO_A:\n\t\tcase SSL3_ST_SW_SRVR_HELLO_B:\n\t\t\tret=dtls1_send_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CERT_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_A:\n\t\tcase SSL3_ST_SW_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))\n\t\t\t\t{\n\t\t\t\tret=dtls1_send_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_KEY_EXCH_A:\n\t\tcase SSL3_ST_SW_KEY_EXCH_B:\n\t\t\tl=s->s3->tmp.new_cipher->algorithms;\n\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n#ifndef OPENSSL_NO_KRB5\n\t\t\t\t&& !(l & SSL_KRB5)\n#endif\n\t\t\t\t)\n\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\telse\n\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n\t\t\tif (s->s3->tmp.use_rsa_tmp\n\t\t\t || (l & (SSL_DH|SSL_kFZA))\n\t\t\t || ((l & SSL_kRSA)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL\n\t\t\t\t || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)\n\t\t\t\t\t&& EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t)\n\t\t\t )\n\t\t\t\t{\n\t\t\t\tret=dtls1_send_server_key_exchange(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_REQ_A:\n\t\tcase SSL3_ST_SW_CERT_REQ_B:\n\t\t\tif (\n\t\t\t\t!(s->verify_mode & SSL_VERIFY_PEER) ||\n\t\t\t\t((s->session->peer != NULL) &&\n\t\t\t\t (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||\n\t\t\t\t((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&\n\t\t\t\t !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||\n (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5))\n\t\t\t\t{\n\t\t\t\tskip=1;\n\t\t\t\ts->s3->tmp.cert_request=0;\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.cert_request=1;\n\t\t\t\tret=dtls1_send_certificate_request(s);\n\t\t\t\tif (ret <= 0) goto end;\n#ifndef NETSCAPE_HANG_BUG\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n#else\n\t\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n#endif\n\t\t\t\ts->init_num=0;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_DONE_A:\n\t\tcase SSL3_ST_SW_SRVR_DONE_B:\n\t\t\tret=dtls1_send_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_A:\n\t\tcase SSL3_ST_SR_CERT_B:\n\t\t\tret = ssl3_check_client_hello(s);\n\t\t\tif (ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif (ret == 2)\n\t\t\t\ts->state = SSL3_ST_SR_CLNT_HELLO_C;\n\t\t\telse {\n\t\t\t\tret=ssl3_get_client_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\ts->init_num=0;\n\t\t\t\ts->state=SSL3_ST_SR_KEY_EXCH_A;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_KEY_EXCH_A:\n\t\tcase SSL3_ST_SR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_client_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SR_CERT_VRFY_A;\n\t\t\ts->init_num=0;\n\t\t\ts->method->ssl3_enc->cert_verify_mac(s,\n\t\t\t\t&(s->s3->finish_dgst1),\n\t\t\t\t&(s->s3->tmp.cert_verify_md[0]));\n\t\t\ts->method->ssl3_enc->cert_verify_mac(s,\n\t\t\t\t&(s->s3->finish_dgst2),\n\t\t\t\t&(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_VRFY_A:\n\t\tcase SSL3_ST_SR_CERT_VRFY_B:\n\t\t\tret=ssl3_get_cert_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_FINISHED_A:\n\t\tcase SSL3_ST_SR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,\n\t\t\t\tSSL3_ST_SR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL_ST_OK;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CHANGE_A:\n\t\tcase SSL3_ST_SW_CHANGE_B:\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{ ret= -1; goto end; }\n\t\t\tret=dtls1_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_SERVER_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdtls1_reset_seq_numbers(s, SSL3_CC_WRITE);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FINISHED_A:\n\t\tcase SSL3_ST_SW_FINISHED_B:\n\t\t\tret=dtls1_send_finished(s,\n\t\t\t\tSSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->server_finished_label,\n\t\t\t\ts->method->ssl3_enc->server_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\tif (s->hit)\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;\n\t\t\telse\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n#if 0\n\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\ts->init_buf=NULL;\n#endif\n\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\tif (s->new_session == 2)\n\t\t\t\t{\n\t\t\t\ts->new_session=0;\n\t\t\t\tssl_update_cache(s,SSL_SESS_CACHE_SERVER);\n\t\t\t\ts->ctx->stats.sess_accept_good++;\n\t\t\t\ts->handshake_func=dtls1_accept;\n\t\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\t\t}\n\t\t\tret = 1;\n\t\t\ts->d1->handshake_read_seq = 0;\n\t\t\ts->d1->handshake_write_seq = 0;\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_DTLS1_ACCEPT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_ACCEPT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_ACCEPT_EXIT,ret);\n\treturn(ret);\n\t}', 'int ssl3_get_client_hello(SSL *s)\n\t{\n\tint i,j,ok,al,ret= -1;\n\tunsigned int cookie_len;\n\tlong n;\n\tunsigned long id;\n\tunsigned char *p,*d,*q;\n\tSSL_CIPHER *c;\n#ifndef OPENSSL_NO_COMP\n\tSSL_COMP *comp=NULL;\n#endif\n\tSTACK_OF(SSL_CIPHER) *ciphers=NULL;\n\tif (s->state == SSL3_ST_SR_CLNT_HELLO_A)\n\t\t{\n\t\ts->first_packet=1;\n\t\ts->state=SSL3_ST_SR_CLNT_HELLO_B;\n\t\t}\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_SR_CLNT_HELLO_B,\n\t\tSSL3_ST_SR_CLNT_HELLO_C,\n\t\tSSL3_MT_CLIENT_HELLO,\n\t\tSSL3_RT_MAX_PLAIN_LENGTH,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\td=p=(unsigned char *)s->init_msg;\n\ts->client_version=(((int)p[0])<<8)|(int)p[1];\n\tp+=2;\n\tif (s->client_version < s->version)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_WRONG_VERSION_NUMBER);\n\t\tif ((s->client_version>>8) == SSL3_VERSION_MAJOR)\n\t\t\t{\n\t\t\ts->version = s->client_version;\n\t\t\t}\n\t\tal = SSL_AD_PROTOCOL_VERSION;\n\t\tgoto f_err;\n\t\t}\n\tmemcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);\n\tp+=SSL3_RANDOM_SIZE;\n\tj= *(p++);\n\ts->hit=0;\n\tif (j == 0 || (s->new_session && (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION)))\n\t\t{\n\t\tif (!ssl_get_new_session(s,1))\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\t{\n\t\ti=ssl_get_prev_session(s,p,j);\n\t\tif (i == 1)\n\t\t\t{\n\t\t\ts->hit=1;\n\t\t\t}\n\t\telse if (i == -1)\n\t\t\tgoto err;\n\t\telse\n\t\t\t{\n\t\t\tif (!ssl_get_new_session(s,1))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tp+=j;\n\tif (SSL_version(s) == DTLS1_VERSION)\n\t\t{\n\t\tcookie_len = *(p++);\n\t\tif ( (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) &&\n\t\t\ts->d1->send_cookie == 0)\n\t\t\t{\n\t\t\tif ( cookie_len != s->d1->cookie_len)\n\t\t\t\t{\n\t\t\t\tal = SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_COOKIE_MISMATCH);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\tif ( cookie_len > sizeof(s->d1->rcvd_cookie))\n\t\t\t{\n\t\t\tal = SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_COOKIE_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif ( (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) &&\n\t\t\tcookie_len > 0)\n\t\t\t{\n\t\t\tmemcpy(s->d1->rcvd_cookie, p, cookie_len);\n\t\t\tif ( s->ctx->app_verify_cookie_cb != NULL)\n\t\t\t\t{\n\t\t\t\tif ( s->ctx->app_verify_cookie_cb(s, s->d1->rcvd_cookie,\n\t\t\t\t\tcookie_len) == 0)\n\t\t\t\t\t{\n\t\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,\n\t\t\t\t\t\tSSL_R_COOKIE_MISMATCH);\n\t\t\t\t\tgoto f_err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if ( memcmp(s->d1->rcvd_cookie, s->d1->cookie,\n\t\t\t\t\t\t s->d1->cookie_len) != 0)\n\t\t\t\t{\n\t\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,\n\t\t\t\t\t\tSSL_R_COOKIE_MISMATCH);\n\t\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\tp += cookie_len;\n\t\t}\n\tn2s(p,i);\n\tif ((i == 0) && (j != 0))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\tif ((p+i) >= (d+n))\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tif ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))\n\t\t== NULL))\n\t\t{\n\t\tgoto err;\n\t\t}\n\tp+=i;\n\tif ((s->hit) && (i > 0))\n\t\t{\n\t\tj=0;\n\t\tid=s->session->cipher->id;\n#ifdef CIPHER_DEBUG\n\t\tprintf("client sent %d ciphers\\n",sk_num(ciphers));\n#endif\n\t\tfor (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)\n\t\t\t{\n\t\t\tc=sk_SSL_CIPHER_value(ciphers,i);\n#ifdef CIPHER_DEBUG\n\t\t\tprintf("client [%2d of %2d]:%s\\n",\n\t\t\t\ti,sk_num(ciphers),SSL_CIPHER_get_name(c));\n#endif\n\t\t\tif (c->id == id)\n\t\t\t\t{\n\t\t\t\tj=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))\n\t\t\t\t{\n\t\t\t\ts->session->cipher=sk_SSL_CIPHER_value(ciphers, 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\ti= *(p++);\n\tif ((p+i) > (d+n))\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tq=p;\n\tfor (j=0; j<i; j++)\n\t\t{\n\t\tif (p[j] == 0) break;\n\t\t}\n\tp+=i;\n\tif (j >= i)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\tif (s->version > SSL3_VERSION)\n\t\t{\n\t\tif (!ssl_parse_clienthello_tlsext(s,&p,d,n, &al))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_PARSE_TLS_EXT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\t\tif (ssl_check_tlsext(s,1) <= 0) {\n\t\t\tSSLerr(SSL_F_SSL3_ACCEPT,SSL_R_CLIENTHELLO_TLS_EXT);\n\t\t\tgoto err;\n\t\t}\n#endif\n\ts->s3->tmp.new_compression=NULL;\n#ifndef OPENSSL_NO_COMP\n\tif (!(s->options & SSL_OP_NO_COMPRESSION) && s->ctx->comp_methods)\n\t\t{\n\t\tint m,nn,o,v,done=0;\n\t\tnn=sk_SSL_COMP_num(s->ctx->comp_methods);\n\t\tfor (m=0; m<nn; m++)\n\t\t\t{\n\t\t\tcomp=sk_SSL_COMP_value(s->ctx->comp_methods,m);\n\t\t\tv=comp->id;\n\t\t\tfor (o=0; o<i; o++)\n\t\t\t\t{\n\t\t\t\tif (v == q[o])\n\t\t\t\t\t{\n\t\t\t\t\tdone=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (done) break;\n\t\t\t}\n\t\tif (done)\n\t\t\ts->s3->tmp.new_compression=comp;\n\t\telse\n\t\t\tcomp=NULL;\n\t\t}\n#endif\n\tif (!s->hit)\n\t\t{\n#ifdef OPENSSL_NO_COMP\n\t\ts->session->compress_meth=0;\n#else\n\t\ts->session->compress_meth=(comp == NULL)?0:comp->id;\n#endif\n\t\tif (s->session->ciphers != NULL)\n\t\t\tsk_SSL_CIPHER_free(s->session->ciphers);\n\t\ts->session->ciphers=ciphers;\n\t\tif (ciphers == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tciphers=NULL;\n\t\tc=ssl3_choose_cipher(s,s->session->ciphers,\n\t\t\t\t SSL_get_ciphers(s));\n\t\tif (c == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.new_cipher=c;\n\t\t}\n\telse\n\t\t{\n#ifdef REUSE_CIPHER_BUG\n\t\tSTACK_OF(SSL_CIPHER) *sk;\n\t\tSSL_CIPHER *nc=NULL;\n\t\tSSL_CIPHER *ec=NULL;\n\t\tif (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)\n\t\t\t{\n\t\t\tsk=s->session->ciphers;\n\t\t\tfor (i=0; i<sk_SSL_CIPHER_num(sk); i++)\n\t\t\t\t{\n\t\t\t\tc=sk_SSL_CIPHER_value(sk,i);\n\t\t\t\tif (c->algorithms & SSL_eNULL)\n\t\t\t\t\tnc=c;\n\t\t\t\tif (SSL_C_IS_EXPORT(c))\n\t\t\t\t\tec=c;\n\t\t\t\t}\n\t\t\tif (nc != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=nc;\n\t\t\telse if (ec != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=ec;\n\t\t\telse\n\t\t\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t\t}\n\t\telse\n#endif\n\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t}\n\tret=1;\n\tif (0)\n\t\t{\nf_err:\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t}\nerr:\n\tif (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);\n\treturn(ret);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\ts->method->ssl_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
34,920
1
https://github.com/openssl/openssl/blob/3da2e9c4ee45989a426ff513dc6c6250d1e460de/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\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 l0 = bn_sub_words(wnum.d, wnum.d, 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.d, wnum.d, tmp->d, div_n);\n (*wnump) += l0;\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}']
34,921
0
https://github.com/libav/libav/blob/ab3554e1a7c04a5ea30f9c905de92348478ef7c8/libavutil/mem.c/#L168
int av_reallocp_array(void *ptr, size_t nmemb, size_t size) { void *val; if (!size || nmemb >= INT_MAX / size) return AVERROR(ENOMEM); if (!nmemb) { av_freep(ptr); return 0; } memcpy(&val, ptr, sizeof(val)); val = av_realloc(val, nmemb * size); if (!val) { av_freep(ptr); return AVERROR(ENOMEM); } memcpy(ptr, &val, sizeof(val)); return 0; }
['int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n void *val;\n if (!size || nmemb >= INT_MAX / size)\n return AVERROR(ENOMEM);\n if (!nmemb) {\n av_freep(ptr);\n return 0;\n }\n memcpy(&val, ptr, sizeof(val));\n val = av_realloc(val, nmemb * size);\n if (!val) {\n av_freep(ptr);\n return AVERROR(ENOMEM);\n }\n memcpy(ptr, &val, sizeof(val));\n return 0;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n if (size > (INT_MAX - 16))\n return NULL;\n#if HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
34,922
0
https://github.com/openssl/openssl/blob/55442b8a5b719f54578083fae0fcc814b599cd84/crypto/bn/bn_lib.c/#L233
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; }
['BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int ret, r_neg, cmp_res;\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg != b->neg) {\n r_neg = a->neg;\n ret = BN_uadd(r, a, b);\n } else {\n cmp_res = BN_ucmp(a, b);\n if (cmp_res > 0) {\n r_neg = a->neg;\n ret = BN_usub(r, a, b);\n } else if (cmp_res < 0) {\n r_neg = !b->neg;\n ret = BN_usub(r, b, a);\n } else {\n r_neg = 0;\n BN_zero(r);\n ret = 1;\n }\n }\n r->neg = r_neg;\n bn_check_top(r);\n return ret;\n}', 'int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int max, min, dif;\n const BN_ULONG *ap, *bp;\n BN_ULONG *rp, carry, t1, t2;\n bn_check_top(a);\n bn_check_top(b);\n if (a->top < b->top) {\n const BIGNUM *tmp;\n tmp = a;\n a = b;\n b = tmp;\n }\n max = a->top;\n min = b->top;\n dif = max - min;\n if (bn_wexpand(r, max + 1) == NULL)\n return 0;\n r->top = max;\n ap = a->d;\n bp = b->d;\n rp = r->d;\n carry = bn_add_words(rp, ap, bp, min);\n rp += min;\n ap += min;\n while (dif) {\n dif--;\n t1 = *(ap++);\n t2 = (t1 + carry) & BN_MASK2;\n *(rp++) = t2;\n carry &= (t2 == 0);\n }\n *rp = carry;\n r->top += carry;\n r->neg = 0;\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
34,923
0
https://github.com/openssl/openssl/blob/0f3e6045898e9aa5d0249e61c874b1f153ae54fa/crypto/bn/bn_mul.c/#L648
int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) { int top,al,bl; BIGNUM *rr; #ifdef BN_RECURSION BIGNUM *t; int i,j,k; #endif #ifdef BN_COUNT printf("BN_mul %d * %d\n",a->top,b->top); #endif bn_check_top(a); bn_check_top(b); bn_check_top(r); al=a->top; bl=b->top; r->neg=a->neg^b->neg; if ((al == 0) || (bl == 0)) { BN_zero(r); return(1); } top=al+bl; if ((r == a) || (r == b)) rr= &(ctx->bn[ctx->tos+1]); else rr=r; #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) if (al == bl) { # ifdef BN_MUL_COMBA if (al == 8) { if (bn_wexpand(rr,16) == NULL) return(0); r->top=16; bn_mul_comba8(rr->d,a->d,b->d); goto end; } else # endif #ifdef BN_RECURSION if (al < BN_MULL_SIZE_NORMAL) #endif { if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); goto end; } # ifdef BN_RECURSION goto symetric; # endif } #endif #ifdef BN_RECURSION else if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL)) { if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); goto end; } else { i=(al-bl); if ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA)) { bn_wexpand(b,al); b->d[bl]=0; bl++; goto symetric; } else if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA)) { bn_wexpand(a,bl); a->d[al]=0; al++; goto symetric; } } #endif if (bn_wexpand(rr,top) == NULL) return(0); rr->top=top; bn_mul_normal(rr->d,a->d,al,b->d,bl); #ifdef BN_RECURSION if (0) { symetric: j=BN_num_bits_word((BN_ULONG)al); j=1<<(j-1); k=j+j; t= &(ctx->bn[ctx->tos]); if (al == j) { bn_wexpand(t,k*2); bn_wexpand(rr,k*2); bn_mul_recursive(rr->d,a->d,b->d,al,t->d); } else { bn_wexpand(a,k); bn_wexpand(b,k); bn_wexpand(t,k*4); bn_wexpand(rr,k*4); for (i=a->top; i<k; i++) a->d[i]=0; for (i=b->top; i<k; i++) b->d[i]=0; bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); } rr->top=top; } #endif #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) end: #endif bn_fix_top(rr); if (r != rr) BN_copy(r,rr); return(1); }
['int MAIN(int argc, char **argv)\n\t{\n#ifndef NO_DSA\n\tDSA *dsa_params=NULL;\n#endif\n\tint ex=1,x509=0,days=30;\n\tX509 *x509ss=NULL;\n\tX509_REQ *req=NULL;\n\tEVP_PKEY *pkey=NULL;\n\tint i,badops=0,newreq=0,newkey= -1,pkey_type=0;\n\tBIO *in=NULL,*out=NULL;\n\tint informat,outformat,verify=0,noout=0,text=0,keyform=FORMAT_PEM;\n\tint nodes=0,kludge=0;\n\tchar *infile,*outfile,*prog,*keyfile=NULL,*template=NULL,*keyout=NULL;\n\tchar *extensions = NULL;\n\tEVP_CIPHER *cipher=NULL;\n\tint modulus=0;\n\tchar *p;\n\tconst EVP_MD *md_alg=NULL,*digest=EVP_md5();\n#ifndef MONOLITH\n\tMS_STATIC char config_name[256];\n#endif\n#ifndef NO_DES\n\tcipher=EVP_des_ede3_cbc();\n#endif\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tinfile=NULL;\n\toutfile=NULL;\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tprog=argv[0];\n\targc--;\n\targv++;\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,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-new") == 0)\n\t\t\t{\n\t\t\tpkey_type=TYPE_RSA;\n\t\t\tnewreq=1;\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\ttemplate= *(++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\tkeyform=str2fmt(*(++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,"-keyout") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyout= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-newkey") == 0)\n\t\t\t{\n\t\t\tint is_numeric;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tp= *(++argv);\n\t\t\tis_numeric = p[0] >= \'0\' && p[0] <= \'9\';\n\t\t\tif (strncmp("rsa:",p,4) == 0 || is_numeric)\n\t\t\t\t{\n\t\t\t\tpkey_type=TYPE_RSA;\n\t\t\t\tif(!is_numeric)\n\t\t\t\t p+=4;\n\t\t\t\tnewkey= atoi(p);\n\t\t\t\t}\n\t\t\telse\n#ifndef NO_DSA\n\t\t\t\tif (strncmp("dsa:",p,4) == 0)\n\t\t\t\t{\n\t\t\t\tX509 *xtmp=NULL;\n\t\t\t\tEVP_PKEY *dtmp;\n\t\t\t\tpkey_type=TYPE_DSA;\n\t\t\t\tp+=4;\n\t\t\t\tif ((in=BIO_new_file(p,"r")) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tperror(p);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif ((dsa_params=PEM_read_bio_DSAparams(in,NULL,NULL)) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tERR_clear_error();\n\t\t\t\t\tBIO_reset(in);\n\t\t\t\t\tif ((xtmp=PEM_read_bio_X509(in,NULL,NULL)) == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err,"unable to load DSA parameters from file\\n");\n\t\t\t\t\t\tgoto end;\n\t\t\t\t\t\t}\n\t\t\t\t\tdtmp=X509_get_pubkey(xtmp);\n\t\t\t\t\tif (dtmp->type == EVP_PKEY_DSA)\n\t\t\t\t\t\tdsa_params=DSAparams_dup(dtmp->pkey.dsa);\n\t\t\t\t\tEVP_PKEY_free(dtmp);\n\t\t\t\t\tX509_free(xtmp);\n\t\t\t\t\tif (dsa_params == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err,"Certificate does not contain DSA parameters\\n");\n\t\t\t\t\t\tgoto end;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tBIO_free(in);\n\t\t\t\tnewkey=BN_num_bits(dsa_params->p);\n\t\t\t\tin=NULL;\n\t\t\t\t}\n\t\t\telse\n#endif\n#ifndef NO_DH\n\t\t\t\tif (strncmp("dh:",p,4) == 0)\n\t\t\t\t{\n\t\t\t\tpkey_type=TYPE_DH;\n\t\t\t\tp+=3;\n\t\t\t\t}\n\t\t\telse\n#endif\n\t\t\t\tpkey_type=TYPE_RSA;\n\t\t\tnewreq=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-modulus") == 0)\n\t\t\tmodulus=1;\n\t\telse if (strcmp(*argv,"-verify") == 0)\n\t\t\tverify=1;\n\t\telse if (strcmp(*argv,"-nodes") == 0)\n\t\t\tnodes=1;\n\t\telse if (strcmp(*argv,"-noout") == 0)\n\t\t\tnoout=1;\n\t\telse if (strcmp(*argv,"-text") == 0)\n\t\t\ttext=1;\n\t\telse if (strcmp(*argv,"-x509") == 0)\n\t\t\tx509=1;\n\t\telse if (strcmp(*argv,"-asn1-kludge") == 0)\n\t\t\tkludge=1;\n\t\telse if (strcmp(*argv,"-no-asn1-kludge") == 0)\n\t\t\tkludge=0;\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) days=30;\n\t\t\t}\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\tBIO_printf(bio_err,"%s [options] <infile >outfile\\n",prog);\n\t\tBIO_printf(bio_err,"where options are\\n");\n\t\tBIO_printf(bio_err," -inform arg input format - one of DER TXT PEM\\n");\n\t\tBIO_printf(bio_err," -outform arg output format - one of DER TXT PEM\\n");\n\t\tBIO_printf(bio_err," -in arg input file\\n");\n\t\tBIO_printf(bio_err," -out arg output file\\n");\n\t\tBIO_printf(bio_err," -text text form of request\\n");\n\t\tBIO_printf(bio_err," -noout do not output REQ\\n");\n\t\tBIO_printf(bio_err," -verify verify signature on REQ\\n");\n\t\tBIO_printf(bio_err," -modulus RSA modulus\\n");\n\t\tBIO_printf(bio_err," -nodes don\'t encrypt the output key\\n");\n\t\tBIO_printf(bio_err," -key file\tuse the private key contained in file\\n");\n\t\tBIO_printf(bio_err," -keyform arg key file format\\n");\n\t\tBIO_printf(bio_err," -keyout arg file to send the key to\\n");\n\t\tBIO_printf(bio_err," -newkey rsa:bits generate a new RSA key of \'bits\' in size\\n");\n\t\tBIO_printf(bio_err," -newkey dsa:file generate a new DSA key, parameters taken from CA in \'file\'\\n");\n\t\tBIO_printf(bio_err," -[digest] Digest to sign with (md5, sha1, md2, mdc2)\\n");\n\t\tBIO_printf(bio_err," -config file request template file.\\n");\n\t\tBIO_printf(bio_err," -new new request.\\n");\n\t\tBIO_printf(bio_err," -x509 output a x509 structure instead of a cert. req.\\n");\n\t\tBIO_printf(bio_err," -days number of days a x509 generated by -x509 is valid for.\\n");\n\t\tBIO_printf(bio_err," -asn1-kludge Output the \'request\' in a format that is wrong but some CA\'s\\n");\n\t\tBIO_printf(bio_err," have been reported as requiring\\n");\n\t\tBIO_printf(bio_err," [ It is now always turned on but can be turned off with -no-asn1-kludge ]\\n");\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n\tX509V3_add_standard_extensions();\n#ifndef MONOLITH\n\tp=getenv("OPENSSL_CONF");\n\tif (p == NULL)\n\t\tp=getenv("SSLEAY_CONF");\n\tif (p == NULL)\n\t\t{\n\t\tstrcpy(config_name,X509_get_default_cert_area());\n\t\tstrcat(config_name,"/lib/");\n\t\tstrcat(config_name,OPENSSL_CONF);\n\t\tp=config_name;\n\t\t}\n default_config_file=p;\n\tconfig=CONF_load(config,p,NULL);\n#endif\n\tif (template != NULL)\n\t\t{\n\t\tlong errline;\n\t\tBIO_printf(bio_err,"Using configuration from %s\\n",template);\n\t\treq_conf=CONF_load(NULL,template,&errline);\n\t\tif (req_conf == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"error on line %ld of %s\\n",errline,template);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\treq_conf=config;\n\t\tBIO_printf(bio_err,"Using configuration from %s\\n",\n\t\t\tdefault_config_file);\n\t\tif (req_conf == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Unable to load config info\\n");\n\t\t\t}\n\t\t}\n\tif (req_conf != NULL)\n\t\t{\n\t\tp=CONF_get_string(req_conf,NULL,"oid_file");\n\t\tif (p != NULL)\n\t\t\t{\n\t\t\tBIO *oid_bio;\n\t\t\toid_bio=BIO_new_file(p,"r");\n\t\t\tif (oid_bio == NULL)\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tOBJ_create_objects(oid_bio);\n\t\t\t\tBIO_free(oid_bio);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(!add_oid_section(req_conf)) goto end;\n\tif ((md_alg == NULL) &&\n\t\t((p=CONF_get_string(req_conf,SECTION,"default_md")) != NULL))\n\t\t{\n\t\tif ((md_alg=EVP_get_digestbyname(p)) != NULL)\n\t\t\tdigest=md_alg;\n\t\t}\n\textensions = CONF_get_string(req_conf, SECTION, V3_EXTENSIONS);\n\tif(extensions) {\n\t\tX509V3_CTX ctx;\n\t\tX509V3_set_ctx_test(&ctx);\n\t\tX509V3_set_conf_lhash(&ctx, req_conf);\n\t\tif(!X509V3_EXT_add_conf(req_conf, &ctx, extensions, NULL)) {\n\t\t\tBIO_printf(bio_err,\n\t\t\t "Error Loading extension section %s\\n", extensions);\n\t\t\tgoto end;\n\t\t}\n\t}\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL))\n\t\tgoto end;\n\tif (keyfile != NULL)\n\t\t{\n\t\tif (BIO_read_filename(in,keyfile) <= 0)\n\t\t\t{\n\t\t\tperror(keyfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (keyform == FORMAT_PEM)\n\t\t\tpkey=PEM_read_bio_PrivateKey(in,NULL,NULL);\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"bad input format specified for X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (pkey == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load Private key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (newreq && (pkey == NULL))\n\t\t{\n\t\tchar *randfile;\n\t\tchar buffer[200];\n\t\tif ((randfile=CONF_get_string(req_conf,SECTION,"RANDFILE")) == NULL)\n\t\t\trandfile=RAND_file_name(buffer,200);\n#ifdef WINDOWS\n\t\tBIO_printf(bio_err,"Loading \'screen\' into random state -");\n\t\tBIO_flush(bio_err);\n\t\tRAND_screen();\n\t\tBIO_printf(bio_err," done\\n");\n#endif\n\t\tif ((randfile == NULL) || !RAND_load_file(randfile,1024L*1024L))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load \'random state\'\\n");\n\t\t\tBIO_printf(bio_err,"What this means is that the random number generator has not been seeded\\n");\n\t\t\tBIO_printf(bio_err,"with much random data.\\n");\n\t\t\tBIO_printf(bio_err,"Consider setting the RANDFILE environment variable to point at a file that\\n");\n\t\t\tBIO_printf(bio_err,"\'random\' data can be kept in.\\n");\n\t\t\t}\n\t\tif (newkey <= 0)\n\t\t\t{\n\t\t\tnewkey=(int)CONF_get_number(req_conf,SECTION,BITS);\n\t\t\tif (newkey <= 0)\n\t\t\t\tnewkey=DEFAULT_KEY_LENGTH;\n\t\t\t}\n\t\tif (newkey < MIN_KEY_LENGTH)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"private key length is too short,\\n");\n\t\t\tBIO_printf(bio_err,"it needs to be at least %d bits, not %d\\n",MIN_KEY_LENGTH,newkey);\n\t\t\tgoto end;\n\t\t\t}\n\t\tBIO_printf(bio_err,"Generating a %d bit %s private key\\n",\n\t\t\tnewkey,(pkey_type == TYPE_RSA)?"RSA":"DSA");\n\t\tif ((pkey=EVP_PKEY_new()) == NULL) goto end;\n#ifndef NO_RSA\n\t\tif (pkey_type == TYPE_RSA)\n\t\t\t{\n\t\t\tif (!EVP_PKEY_assign_RSA(pkey,\n\t\t\t\tRSA_generate_key(newkey,0x10001,\n\t\t\t\t\treq_cb,(char *)bio_err)))\n\t\t\t\tgoto end;\n\t\t\t}\n\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\tif (pkey_type == TYPE_DSA)\n\t\t\t{\n\t\t\tif (!DSA_generate_key(dsa_params)) goto end;\n\t\t\tif (!EVP_PKEY_assign_DSA(pkey,dsa_params)) goto end;\n\t\t\tdsa_params=NULL;\n\t\t\t}\n#endif\n\t\tif ((randfile == NULL) || (RAND_write_file(randfile) == 0))\n\t\t\tBIO_printf(bio_err,"unable to write \'random state\'\\n");\n\t\tif (pkey == NULL) goto end;\n\t\tif (keyout == NULL)\n\t\t\tkeyout=CONF_get_string(req_conf,SECTION,KEYFILE);\n\t\tif (keyout == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"writing new private key to stdout\\n");\n\t\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"writing new private key to \'%s\'\\n",keyout);\n\t\t\tif (BIO_write_filename(out,keyout) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(keyout);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\tp=CONF_get_string(req_conf,SECTION,"encrypt_rsa_key");\n\t\tif (p == NULL)\n\t\t\tp=CONF_get_string(req_conf,SECTION,"encrypt_key");\n\t\tif ((p != NULL) && (strcmp(p,"no") == 0))\n\t\t\tcipher=NULL;\n\t\tif (nodes) cipher=NULL;\n\t\ti=0;\nloop:\n\t\tif (!PEM_write_bio_PrivateKey(out,pkey,cipher,\n\t\t\tNULL,0,NULL))\n\t\t\t{\n\t\t\tif ((ERR_GET_REASON(ERR_peek_error()) ==\n\t\t\t\tPEM_R_PROBLEMS_GETTING_PASSWORD) && (i < 3))\n\t\t\t\t{\n\t\t\t\tERR_clear_error();\n\t\t\t\ti++;\n\t\t\t\tgoto loop;\n\t\t\t\t}\n\t\t\tgoto end;\n\t\t\t}\n\t\tBIO_printf(bio_err,"-----\\n");\n\t\t}\n\tif (!newreq)\n\t\t{\n\t\tkludge= -1;\n\t\tif (infile == NULL)\n\t\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\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\tif\t(informat == FORMAT_ASN1)\n\t\t\treq=d2i_X509_REQ_bio(in,NULL);\n\t\telse if (informat == FORMAT_PEM)\n\t\t\treq=PEM_read_bio_X509_REQ(in,NULL,NULL);\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"bad input format specified for X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (req == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (newreq || x509)\n\t\t{\n#ifndef NO_DSA\n\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\tdigest=EVP_dss1();\n#endif\n\t\tif (pkey == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"you need to specify a private key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (req == NULL)\n\t\t\t{\n\t\t\treq=X509_REQ_new();\n\t\t\tif (req == NULL)\n\t\t\t\t{\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ti=make_REQ(req,pkey,!x509);\n\t\t\tif (kludge >= 0)\n\t\t\t\treq->req_info->req_kludge=kludge;\n\t\t\tif (!i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"problems making Certificate Request\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif (x509)\n\t\t\t{\n\t\t\tEVP_PKEY *tmppkey;\n\t\t\tX509V3_CTX ext_ctx;\n\t\t\tif ((x509ss=X509_new()) == NULL) goto end;\n\t\t\tif(!X509_set_version(x509ss, 2)) goto end;\n\t\t\tASN1_INTEGER_set(X509_get_serialNumber(x509ss),0L);\n\t\t\tX509_set_issuer_name(x509ss,\n\t\t\t\tX509_REQ_get_subject_name(req));\n\t\t\tX509_gmtime_adj(X509_get_notBefore(x509ss),0);\n\t\t\tX509_gmtime_adj(X509_get_notAfter(x509ss),\n\t\t\t\t(long)60*60*24*days);\n\t\t\tX509_set_subject_name(x509ss,\n\t\t\t\tX509_REQ_get_subject_name(req));\n\t\t\ttmppkey = X509_REQ_get_pubkey(req);\n\t\t\tX509_set_pubkey(x509ss,tmppkey);\n\t\t\tEVP_PKEY_free(tmppkey);\n\t\t\tX509V3_set_ctx(&ext_ctx, x509ss, x509ss, NULL, NULL, 0);\n\t\t\tX509V3_set_conf_lhash(&ext_ctx, req_conf);\n\t\t\tif(extensions && !X509V3_EXT_add_conf(req_conf,\n\t\t\t\t \t&ext_ctx, extensions, x509ss))\n\t\t\t {\n\t\t\t BIO_printf(bio_err,\n\t\t\t\t "Error Loading extension section %s\\n",\n\t\t\t\t extensions);\n\t\t\t goto end;\n\t\t\t }\n\t\t\tif (!(i=X509_sign(x509ss,pkey,digest)))\n\t\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!(i=X509_REQ_sign(req,pkey,digest)))\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (verify && !x509)\n\t\t{\n\t\tint tmp=0;\n\t\tif (pkey == NULL)\n\t\t\t{\n\t\t\tpkey=X509_REQ_get_pubkey(req);\n\t\t\ttmp=1;\n\t\t\tif (pkey == NULL) goto end;\n\t\t\t}\n\t\ti=X509_REQ_verify(req,pkey);\n\t\tif (tmp) {\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\tpkey=NULL;\n\t\t}\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tgoto end;\n\t\t\t}\n\t\telse if (i == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"verify failure\\n");\n\t\t\t}\n\t\telse\n\t\t\tBIO_printf(bio_err,"verify OK\\n");\n\t\t}\n\tif (noout && !text && !modulus)\n\t\t{\n\t\tex=0;\n\t\tgoto end;\n\t\t}\n\tif (outfile == NULL)\n\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\telse\n\t\t{\n\t\tif ((keyout != NULL) && (strcmp(outfile,keyout) == 0))\n\t\t\ti=(int)BIO_append_filename(out,outfile);\n\t\telse\n\t\t\ti=(int)BIO_write_filename(out,outfile);\n\t\tif (!i)\n\t\t\t{\n\t\t\tperror(outfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (text)\n\t\t{\n\t\tif (x509)\n\t\t\tX509_print(out,x509ss);\n\t\telse\n\t\t\tX509_REQ_print(out,req);\n\t\t}\n\tif (modulus)\n\t\t{\n\t\tEVP_PKEY *pubkey;\n\t\tif (x509)\n\t\t\tpubkey=X509_get_pubkey(x509ss);\n\t\telse\n\t\t\tpubkey=X509_REQ_get_pubkey(req);\n\t\tif (pubkey == NULL)\n\t\t\t{\n\t\t\tfprintf(stdout,"Modulus=unavailable\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tfprintf(stdout,"Modulus=");\n#ifndef NO_RSA\n\t\tif (pubkey->type == EVP_PKEY_RSA)\n\t\t\tBN_print(out,pubkey->pkey.rsa->n);\n\t\telse\n#endif\n\t\t\tfprintf(stdout,"Wrong Algorithm type");\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tif (!noout && !x509)\n\t\t{\n\t\tif \t(outformat == FORMAT_ASN1)\n\t\t\ti=i2d_X509_REQ_bio(out,req);\n\t\telse if (outformat == FORMAT_PEM)\n\t\t\ti=PEM_write_bio_X509_REQ(out,req);\n\t\telse\t{\n\t\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to write X509 request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!noout && x509 && (x509ss != NULL))\n\t\t{\n\t\tif \t(outformat == FORMAT_ASN1)\n\t\t\ti=i2d_X509_bio(out,x509ss);\n\t\telse if (outformat == FORMAT_PEM)\n\t\t\ti=PEM_write_bio_X509(out,x509ss);\n\t\telse\t{\n\t\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to write X509 certificate\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tex=0;\nend:\n\tif (ex)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tif ((req_conf != NULL) && (req_conf != config)) CONF_free(req_conf);\n\tBIO_free(in);\n\tBIO_free(out);\n\tEVP_PKEY_free(pkey);\n\tX509_REQ_free(req);\n\tX509_free(x509ss);\n\tX509V3_EXT_cleanup();\n\tOBJ_cleanup();\n#ifndef NO_DSA\n\tif (dsa_params != NULL) DSA_free(dsa_params);\n#endif\n\tEXIT(ex);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'int BN_num_bits(BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\ti=(a->top-1)*BN_BITS2;\n\tif (l == 0)\n\t\t{\n#if !defined(NO_STDIO) && !defined(WIN16)\n\t\tfprintf(stderr,"BAD TOP VALUE\\n");\n#endif\n\t\tabort();\n\t\t}\n\treturn(i+BN_num_bits_word(l));\n\t}', 'int DSA_generate_key(DSA *dsa)\n\t{\n\tint ok=0;\n\tunsigned int i;\n\tBN_CTX *ctx=NULL;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif (dsa->priv_key == NULL)\n\t\t{\n\t\tif ((priv_key=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tpriv_key=dsa->priv_key;\n\ti=BN_num_bits(dsa->q);\n\tfor (;;)\n\t\t{\n\t\tBN_rand(priv_key,i,1,0);\n\t\tif (BN_cmp(priv_key,dsa->q) >= 0)\n\t\t\tBN_sub(priv_key,priv_key,dsa->q);\n\t\tif (!BN_is_zero(priv_key)) break;\n\t\t}\n\tif (dsa->pub_key == NULL)\n\t\t{\n\t\tif ((pub_key=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dsa->pub_key;\n\tif (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;\n\tdsa->priv_key=priv_key;\n\tdsa->pub_key=pub_key;\n\tok=1;\nerr:\n\tif ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\treturn(ok);\n\t}', 'int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{ ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\treturn(ret);\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\taa= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_RECP_CTX_init(&recp);\n\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&val[i]);\n\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\treturn(ret);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, BIGNUM *d, BN_CTX *ctx)\n\t{\n\tBN_copy(&(recp->N),d);\n\tBN_zero(&(recp->Nr));\n\trecp->num_bits=BN_num_bits(d);\n\trecp->shift=0;\n\treturn(1);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A,*B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t{\n\t\tA[0]=B[0];\n\t\tA[1]=B[1];\n\t\tA[2]=B[2];\n\t\tA[3]=B[3];\n\t\tA[4]=B[4];\n\t\tA[5]=B[5];\n\t\tA[6]=B[6];\n\t\tA[7]=B[7];\n\t\tA+=8;\n\t\tB+=8;\n\t\t}\n\tswitch (b->top&7)\n\t\t{\n\tcase 7:\n\t\tA[6]=B[6];\n\tcase 6:\n\t\tA[5]=B[5];\n\tcase 5:\n\t\tA[4]=B[4];\n\tcase 4:\n\t\tA[3]=B[3];\n\tcase 3:\n\t\tA[2]=B[2];\n\tcase 2:\n\t\tA[1]=B[1];\n\tcase 1:\n\t\tA[0]=B[0];\n case 0:\n\t\t;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\ta= &(ctx->bn[ctx->tos++]);\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\t}\n\telse\n\t\ta=x;\n\tBN_div_recp(NULL,r,a,recp,ctx);\n\tret=1;\nerr:\n\tctx->tos--;\n\treturn(ret);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,tos,ret=0,ex;\n\tBIGNUM *a,*b,*d,*r;\n\ttos=ctx->tos;\n\ta= &(ctx->bn[ctx->tos++]);\n\tb= &(ctx->bn[ctx->tos++]);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td= &(ctx->bn[ctx->tos++]);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr= &(ctx->bn[ctx->tos++]);\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tBN_copy(r,m);\n\t\tctx->tos=tos;\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits*2;\n\tif (j > i)\n\t\t{\n\t\ti=j;\n\t\tex=0;\n\t\t}\n\telse\n\t\t{\n\t\tex=(i-j)/2;\n\t\t}\n\tj=i/2;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (!BN_rshift(a,m,j-ex)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,j+ex)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n\tj=0;\n#if 1\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tctx->tos=tos;\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}']
34,924
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_sqr.c/#L118
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 || 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}', '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 ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_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}']
34,925
0
https://github.com/libav/libav/blob/60392480181f24ebf3ab48d8ac3614705de90152/cmdutils.c/#L1588
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) { if (*spec <= '9' && *spec >= '0') return strtol(spec, NULL, 0) == st->index; else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || *spec == 't') { enum AVMediaType type; switch (*spec++) { case 'v': type = AVMEDIA_TYPE_VIDEO; break; case 'a': type = AVMEDIA_TYPE_AUDIO; break; case 's': type = AVMEDIA_TYPE_SUBTITLE; break; case 'd': type = AVMEDIA_TYPE_DATA; break; case 't': type = AVMEDIA_TYPE_ATTACHMENT; break; default: av_assert0(0); } if (type != st->codec->codec_type) return 0; if (*spec++ == ':') { int i, index = strtol(spec, NULL, 0); for (i = 0; i < s->nb_streams; i++) if (s->streams[i]->codec->codec_type == type && index-- == 0) return i == st->index; return 0; } return 1; } else if (*spec == 'p' && *(spec + 1) == ':') { int prog_id, i, j; char *endptr; spec += 2; prog_id = strtol(spec, &endptr, 0); for (i = 0; i < s->nb_programs; i++) { if (s->programs[i]->id != prog_id) continue; if (*endptr++ == ':') { int stream_idx = strtol(endptr, NULL, 0); return stream_idx >= 0 && stream_idx < s->programs[i]->nb_stream_indexes && st->index == s->programs[i]->stream_index[stream_idx]; } for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) if (st->index == s->programs[i]->stream_index[j]) return 1; } return 0; } else if (*spec == 'i' && *(spec + 1) == ':') { int stream_id; char *endptr; spec += 2; stream_id = strtol(spec, &endptr, 0); return stream_id == st->id; } else if (*spec == 'm' && *(spec + 1) == ':') { AVDictionaryEntry *tag; char *key, *val; int ret; spec += 2; val = strchr(spec, ':'); key = val ? av_strndup(spec, val - spec) : av_strdup(spec); if (!key) return AVERROR(ENOMEM); tag = av_dict_get(st->metadata, key, NULL, 0); if (tag) { if (!val || !strcmp(tag->value, val + 1)) ret = 1; else ret = 0; } else ret = 0; av_freep(&key); return ret; } else if (!*spec) return 1; av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec); return AVERROR(EINVAL); }
['int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)\n{\n if (*spec <= \'9\' && *spec >= \'0\')\n return strtol(spec, NULL, 0) == st->index;\n else if (*spec == \'v\' || *spec == \'a\' || *spec == \'s\' || *spec == \'d\' ||\n *spec == \'t\') {\n enum AVMediaType type;\n switch (*spec++) {\n case \'v\': type = AVMEDIA_TYPE_VIDEO; break;\n case \'a\': type = AVMEDIA_TYPE_AUDIO; break;\n case \'s\': type = AVMEDIA_TYPE_SUBTITLE; break;\n case \'d\': type = AVMEDIA_TYPE_DATA; break;\n case \'t\': type = AVMEDIA_TYPE_ATTACHMENT; break;\n default: av_assert0(0);\n }\n if (type != st->codec->codec_type)\n return 0;\n if (*spec++ == \':\') {\n int i, index = strtol(spec, NULL, 0);\n for (i = 0; i < s->nb_streams; i++)\n if (s->streams[i]->codec->codec_type == type && index-- == 0)\n return i == st->index;\n return 0;\n }\n return 1;\n } else if (*spec == \'p\' && *(spec + 1) == \':\') {\n int prog_id, i, j;\n char *endptr;\n spec += 2;\n prog_id = strtol(spec, &endptr, 0);\n for (i = 0; i < s->nb_programs; i++) {\n if (s->programs[i]->id != prog_id)\n continue;\n if (*endptr++ == \':\') {\n int stream_idx = strtol(endptr, NULL, 0);\n return stream_idx >= 0 &&\n stream_idx < s->programs[i]->nb_stream_indexes &&\n st->index == s->programs[i]->stream_index[stream_idx];\n }\n for (j = 0; j < s->programs[i]->nb_stream_indexes; j++)\n if (st->index == s->programs[i]->stream_index[j])\n return 1;\n }\n return 0;\n } else if (*spec == \'i\' && *(spec + 1) == \':\') {\n int stream_id;\n char *endptr;\n spec += 2;\n stream_id = strtol(spec, &endptr, 0);\n return stream_id == st->id;\n } else if (*spec == \'m\' && *(spec + 1) == \':\') {\n AVDictionaryEntry *tag;\n char *key, *val;\n int ret;\n spec += 2;\n val = strchr(spec, \':\');\n key = val ? av_strndup(spec, val - spec) : av_strdup(spec);\n if (!key)\n return AVERROR(ENOMEM);\n tag = av_dict_get(st->metadata, key, NULL, 0);\n if (tag) {\n if (!val || !strcmp(tag->value, val + 1))\n ret = 1;\n else\n ret = 0;\n } else\n ret = 0;\n av_freep(&key);\n return ret;\n } else if (!*spec)\n return 1;\n av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\\n", spec);\n return AVERROR(EINVAL);\n}', 'char *av_strndup(const char *s, size_t len)\n{\n char *ret = NULL, *end;\n if (!s)\n return NULL;\n end = memchr(s, 0, len);\n if (end)\n len = end - s;\n ret = av_realloc(NULL, len + 1);\n if (!ret)\n return NULL;\n memcpy(ret, s, len);\n ret[len] = 0;\n return ret;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if (size > (INT_MAX - 16))\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if (!ptr)\n return av_malloc(size);\n diff = ((char *)ptr)[-1];\n return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
34,926
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int aic_decode_coeffs(BitstreamContext *bc, int16_t *dst,\n int band, int slice_width, int force_chroma)\n{\n int has_skips, coeff_type, coeff_bits, skip_type, skip_bits;\n const int num_coeffs = aic_num_band_coeffs[band];\n const uint8_t *scan = aic_scan[band | force_chroma];\n int mb, idx, val;\n has_skips = bitstream_read_bit(bc);\n coeff_type = bitstream_read_bit(bc);\n coeff_bits = bitstream_read(bc, 3);\n if (has_skips) {\n skip_type = bitstream_read_bit(bc);\n skip_bits = bitstream_read(bc, 3);\n for (mb = 0; mb < slice_width; mb++) {\n idx = -1;\n do {\n GET_CODE(val, skip_type, skip_bits);\n if (val < 0)\n return AVERROR_INVALIDDATA;\n idx += val + 1;\n if (idx >= num_coeffs)\n break;\n GET_CODE(val, coeff_type, coeff_bits);\n val++;\n if (val >= 0x10000 || val < 0)\n return AVERROR_INVALIDDATA;\n dst[scan[idx]] = val;\n } while (idx < num_coeffs - 1);\n dst += num_coeffs;\n }\n } else {\n for (mb = 0; mb < slice_width; mb++) {\n for (idx = 0; idx < num_coeffs; idx++) {\n GET_CODE(val, coeff_type, coeff_bits);\n if (val >= 0x10000 || val < 0)\n return AVERROR_INVALIDDATA;\n dst[scan[idx]] = val;\n }\n dst += num_coeffs;\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}']
34,927
0
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['static ASN1_INTEGER *x509_load_serial(const char *CAfile, const char *serialfile,\n int create)\n{\n char *buf = NULL, *p;\n ASN1_INTEGER *bs = NULL;\n BIGNUM *serial = NULL;\n size_t len;\n len = ((serialfile == NULL)\n ? (strlen(CAfile) + strlen(POSTFIX) + 1)\n : (strlen(serialfile))) + 1;\n buf = app_malloc(len, "serial# buffer");\n if (serialfile == NULL) {\n OPENSSL_strlcpy(buf, CAfile, len);\n for (p = buf; *p; p++)\n if (*p == \'.\') {\n *p = \'\\0\';\n break;\n }\n OPENSSL_strlcat(buf, POSTFIX, len);\n } else\n OPENSSL_strlcpy(buf, serialfile, len);\n serial = load_serial(buf, create, NULL);\n if (serial == NULL)\n goto end;\n if (!BN_add_word(serial, 1)) {\n BIO_printf(bio_err, "add_word failure\\n");\n goto end;\n }\n if (!save_serial(buf, NULL, serial, &bs))\n goto end;\n end:\n OPENSSL_free(buf);\n BN_free(serial);\n return bs;\n}', 'BIGNUM *load_serial(const char *serialfile, int create, ASN1_INTEGER **retai)\n{\n BIO *in = NULL;\n BIGNUM *ret = NULL;\n char buf[1024];\n ASN1_INTEGER *ai = NULL;\n ai = ASN1_INTEGER_new();\n if (ai == NULL)\n goto err;\n in = BIO_new_file(serialfile, "r");\n if (in == NULL) {\n if (!create) {\n perror(serialfile);\n goto err;\n }\n ERR_clear_error();\n ret = BN_new();\n if (ret == NULL || !rand_serial(ret, ai))\n BIO_printf(bio_err, "Out of memory\\n");\n } else {\n if (!a2i_ASN1_INTEGER(in, ai, buf, 1024)) {\n BIO_printf(bio_err, "unable to load number from %s\\n",\n serialfile);\n goto err;\n }\n ret = ASN1_INTEGER_to_BN(ai, NULL);\n if (ret == NULL) {\n BIO_printf(bio_err,\n "error converting number from bin to BIGNUM\\n");\n goto err;\n }\n }\n if (ret && retai) {\n *retai = ai;\n ai = NULL;\n }\n err:\n BIO_free(in);\n ASN1_INTEGER_free(ai);\n return (ret);\n}', 'int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)\n{\n BIGNUM *btmp;\n int ret = 0;\n if (b)\n btmp = b;\n else\n btmp = BN_new();\n if (btmp == NULL)\n return 0;\n if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))\n goto error;\n if (ai && !BN_to_ASN1_INTEGER(btmp, ai))\n goto error;\n ret = 1;\n error:\n if (btmp != b)\n BN_free(btmp);\n return ret;\n}', 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n{\n BN_ULONG l;\n int i;\n bn_check_top(a);\n w &= BN_MASK2;\n if (!w)\n return 1;\n if (BN_is_zero(a))\n return BN_set_word(a, w);\n if (a->neg) {\n a->neg = 0;\n i = BN_sub_word(a, w);\n if (!BN_is_zero(a))\n a->neg = !(a->neg);\n return (i);\n }\n for (i = 0; w != 0 && i < a->top; i++) {\n a->d[i] = l = (a->d[i] + w) & BN_MASK2;\n w = (w > l) ? 1 : 0;\n }\n if (w && i == a->top) {\n if (bn_wexpand(a, a->top + 1) == NULL)\n return 0;\n a->top++;\n a->d[i] = w;\n }\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
34,928
0
https://gitlab.com/libtiff/libtiff/blob/bf3589510740d30f231bdbc340502622cbcc5984/tools/tiff2pdf.c/#L5504
tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){ tsize_t written=0; ttile_t i2=0; tsize_t streamlen=0; uint16 i=0; t2p_read_tiff_init(t2p, input); if(t2p->t2p_error!=T2P_ERR_OK){return(0);} t2p->pdf_xrefoffsets= (uint32*) _TIFFmalloc(TIFFSafeMultiply(tmsize_t,t2p->pdf_xrefcount,sizeof(uint32)) ); if(t2p->pdf_xrefoffsets==NULL){ TIFFError( TIFF2PDF_MODULE, "Can't allocate %u bytes of memory for t2p_write_pdf", (unsigned int) (t2p->pdf_xrefcount * sizeof(uint32)) ); t2p->t2p_error = T2P_ERR_ERROR; return(written); } t2p->pdf_xrefcount=0; t2p->pdf_catalog=1; t2p->pdf_info=2; t2p->pdf_pages=3; written += t2p_write_pdf_header(t2p, output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; t2p->pdf_catalog=t2p->pdf_xrefcount; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_catalog(t2p, output); written += t2p_write_pdf_obj_end(output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; t2p->pdf_info=t2p->pdf_xrefcount; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_info(t2p, input, output); written += t2p_write_pdf_obj_end(output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; t2p->pdf_pages=t2p->pdf_xrefcount; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_pages(t2p, output); written += t2p_write_pdf_obj_end(output); for(t2p->pdf_page=0;t2p->pdf_page<t2p->tiff_pagecount;t2p->pdf_page++){ t2p_read_tiff_data(t2p, input); if(t2p->t2p_error!=T2P_ERR_OK){return(0);} t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_page(t2p->pdf_xrefcount, t2p, output); written += t2p_write_pdf_obj_end(output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_dict_start(output); written += t2p_write_pdf_stream_dict(0, t2p->pdf_xrefcount+1, output); written += t2p_write_pdf_stream_dict_end(output); written += t2p_write_pdf_stream_start(output); streamlen=written; written += t2p_write_pdf_page_content_stream(t2p, output); streamlen=written-streamlen; written += t2p_write_pdf_stream_end(output); written += t2p_write_pdf_obj_end(output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_length(streamlen, output); written += t2p_write_pdf_obj_end(output); if(t2p->tiff_transferfunctioncount != 0){ t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_transfer(t2p, output); written += t2p_write_pdf_obj_end(output); for(i=0; i < t2p->tiff_transferfunctioncount; i++){ t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_dict_start(output); written += t2p_write_pdf_transfer_dict(t2p, output, i); written += t2p_write_pdf_stream_dict_end(output); written += t2p_write_pdf_stream_start(output); written += t2p_write_pdf_transfer_stream(t2p, output, i); written += t2p_write_pdf_stream_end(output); written += t2p_write_pdf_obj_end(output); } } if( (t2p->pdf_colorspace & T2P_CS_PALETTE) != 0){ t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; t2p->pdf_palettecs=t2p->pdf_xrefcount; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_dict_start(output); written += t2p_write_pdf_stream_dict(t2p->pdf_palettesize, 0, output); written += t2p_write_pdf_stream_dict_end(output); written += t2p_write_pdf_stream_start(output); written += t2p_write_pdf_xobject_palettecs_stream(t2p, output); written += t2p_write_pdf_stream_end(output); written += t2p_write_pdf_obj_end(output); } if( (t2p->pdf_colorspace & T2P_CS_ICCBASED) != 0){ t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; t2p->pdf_icccs=t2p->pdf_xrefcount; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_dict_start(output); written += t2p_write_pdf_xobject_icccs_dict(t2p, output); written += t2p_write_pdf_stream_dict_end(output); written += t2p_write_pdf_stream_start(output); written += t2p_write_pdf_xobject_icccs_stream(t2p, output); written += t2p_write_pdf_stream_end(output); written += t2p_write_pdf_obj_end(output); } if(t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount !=0){ for(i2=0;i2<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount;i2++){ t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_dict_start(output); written += t2p_write_pdf_xobject_stream_dict( i2+1, t2p, output); written += t2p_write_pdf_stream_dict_end(output); written += t2p_write_pdf_stream_start(output); streamlen=written; t2p_read_tiff_size_tile(t2p, input, i2); written += t2p_readwrite_pdf_image_tile(t2p, input, output, i2); t2p_write_advance_directory(t2p, output); if(t2p->t2p_error!=T2P_ERR_OK){return(0);} streamlen=written-streamlen; written += t2p_write_pdf_stream_end(output); written += t2p_write_pdf_obj_end(output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_length(streamlen, output); written += t2p_write_pdf_obj_end(output); } } else { t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_dict_start(output); written += t2p_write_pdf_xobject_stream_dict( 0, t2p, output); written += t2p_write_pdf_stream_dict_end(output); written += t2p_write_pdf_stream_start(output); streamlen=written; t2p_read_tiff_size(t2p, input); written += t2p_readwrite_pdf_image(t2p, input, output); t2p_write_advance_directory(t2p, output); if(t2p->t2p_error!=T2P_ERR_OK){return(0);} streamlen=written-streamlen; written += t2p_write_pdf_stream_end(output); written += t2p_write_pdf_obj_end(output); t2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written; written += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output); written += t2p_write_pdf_stream_length(streamlen, output); written += t2p_write_pdf_obj_end(output); } } t2p->pdf_startxref = written; written += t2p_write_pdf_xreftable(t2p, output); written += t2p_write_pdf_trailer(t2p, output); t2p_disable(output); return(written); }
['tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){\n\ttsize_t written=0;\n\tttile_t i2=0;\n\ttsize_t streamlen=0;\n\tuint16 i=0;\n\tt2p_read_tiff_init(t2p, input);\n\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\tt2p->pdf_xrefoffsets= (uint32*) _TIFFmalloc(TIFFSafeMultiply(tmsize_t,t2p->pdf_xrefcount,sizeof(uint32)) );\n\tif(t2p->pdf_xrefoffsets==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %u bytes of memory for t2p_write_pdf",\n\t\t\t(unsigned int) (t2p->pdf_xrefcount * sizeof(uint32)) );\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn(written);\n\t}\n\tt2p->pdf_xrefcount=0;\n\tt2p->pdf_catalog=1;\n\tt2p->pdf_info=2;\n\tt2p->pdf_pages=3;\n\twritten += t2p_write_pdf_header(t2p, output);\n\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\tt2p->pdf_catalog=t2p->pdf_xrefcount;\n\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\twritten += t2p_write_pdf_catalog(t2p, output);\n\twritten += t2p_write_pdf_obj_end(output);\n\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\tt2p->pdf_info=t2p->pdf_xrefcount;\n\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\twritten += t2p_write_pdf_info(t2p, input, output);\n\twritten += t2p_write_pdf_obj_end(output);\n\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\tt2p->pdf_pages=t2p->pdf_xrefcount;\n\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\twritten += t2p_write_pdf_pages(t2p, output);\n\twritten += t2p_write_pdf_obj_end(output);\n\tfor(t2p->pdf_page=0;t2p->pdf_page<t2p->tiff_pagecount;t2p->pdf_page++){\n\t\tt2p_read_tiff_data(t2p, input);\n\t\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\twritten += t2p_write_pdf_page(t2p->pdf_xrefcount, t2p, output);\n\t\twritten += t2p_write_pdf_obj_end(output);\n\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\twritten += t2p_write_pdf_stream_dict(0, t2p->pdf_xrefcount+1, output);\n\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\twritten += t2p_write_pdf_stream_start(output);\n\t\tstreamlen=written;\n\t\twritten += t2p_write_pdf_page_content_stream(t2p, output);\n\t\tstreamlen=written-streamlen;\n\t\twritten += t2p_write_pdf_stream_end(output);\n\t\twritten += t2p_write_pdf_obj_end(output);\n\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\twritten += t2p_write_pdf_stream_length(streamlen, output);\n\t\twritten += t2p_write_pdf_obj_end(output);\n\t\tif(t2p->tiff_transferfunctioncount != 0){\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_transfer(t2p, output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\tfor(i=0; i < t2p->tiff_transferfunctioncount; i++){\n\t\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\t\twritten += t2p_write_pdf_transfer_dict(t2p, output, i);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\t\twritten += t2p_write_pdf_transfer_stream(t2p, output, i);\n\t\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\t}\n\t\t}\n\t\tif( (t2p->pdf_colorspace & T2P_CS_PALETTE) != 0){\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\tt2p->pdf_palettecs=t2p->pdf_xrefcount;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\twritten += t2p_write_pdf_stream_dict(t2p->pdf_palettesize, 0, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\twritten += t2p_write_pdf_xobject_palettecs_stream(t2p, output);\n\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t}\n\t\tif( (t2p->pdf_colorspace & T2P_CS_ICCBASED) != 0){\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\tt2p->pdf_icccs=t2p->pdf_xrefcount;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\twritten += t2p_write_pdf_xobject_icccs_dict(t2p, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\twritten += t2p_write_pdf_xobject_icccs_stream(t2p, output);\n\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t}\n\t\tif(t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount !=0){\n\t\t\tfor(i2=0;i2<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount;i2++){\n\t\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\t\twritten += t2p_write_pdf_xobject_stream_dict(\n\t\t\t\t\ti2+1,\n\t\t\t\t\tt2p,\n\t\t\t\t\toutput);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\t\tstreamlen=written;\n\t\t\t\tt2p_read_tiff_size_tile(t2p, input, i2);\n\t\t\t\twritten += t2p_readwrite_pdf_image_tile(t2p, input, output, i2);\n\t\t\t\tt2p_write_advance_directory(t2p, output);\n\t\t\t\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\t\t\t\tstreamlen=written-streamlen;\n\t\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\t\twritten += t2p_write_pdf_stream_length(streamlen, output);\n\t\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\t}\n\t\t} else {\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\twritten += t2p_write_pdf_xobject_stream_dict(\n\t\t\t\t0,\n\t\t\t\tt2p,\n\t\t\t\toutput);\n\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\tstreamlen=written;\n\t\t\tt2p_read_tiff_size(t2p, input);\n\t\t\twritten += t2p_readwrite_pdf_image(t2p, input, output);\n\t\t\tt2p_write_advance_directory(t2p, output);\n\t\t\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\t\t\tstreamlen=written-streamlen;\n\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_length(streamlen, output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t}\n\t}\n\tt2p->pdf_startxref = written;\n\twritten += t2p_write_pdf_xreftable(t2p, output);\n\twritten += t2p_write_pdf_trailer(t2p, output);\n\tt2p_disable(output);\n\treturn(written);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n if (s == 0)\n return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}', 'tsize_t t2p_write_pdf_header(T2P* t2p, TIFF* output){\n\ttsize_t written=0;\n\tchar buffer[16];\n\tint buflen=0;\n\tbuflen = snprintf(buffer, sizeof(buffer), "%%PDF-%u.%u ",\n\t\t\t t2p->pdf_majorversion&0xff,\n\t\t\t t2p->pdf_minorversion&0xff);\n\tcheck_snprintf_ret(t2p, buflen, buffer);\n\twritten += t2pWriteFile(output, (tdata_t) buffer, buflen);\n\twritten += t2pWriteFile(output, (tdata_t)"\\n%\\342\\343\\317\\323\\n", 7);\n\treturn(written);\n}', 'static tmsize_t\nt2pWriteFile(TIFF *tif, tdata_t data, tmsize_t size)\n{\n\tthandle_t client = TIFFClientdata(tif);\n\tTIFFReadWriteProc proc = TIFFGetWriteProc(tif);\n\tif (proc)\n\t\treturn proc(client, data, size);\n\treturn -1;\n}', 'thandle_t\nTIFFClientdata(TIFF* tif)\n{\n\treturn (tif->tif_clientdata);\n}', 'TIFFReadWriteProc\nTIFFGetWriteProc(TIFF* tif)\n{\n\treturn (tif->tif_writeproc);\n}', 'tsize_t t2p_write_pdf_obj_start(uint32 number, TIFF* output){\n\ttsize_t written=0;\n\tchar buffer[32];\n\tint buflen=0;\n\tbuflen=snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)number);\n\tcheck_snprintf_ret((T2P*)NULL, buflen, buffer);\n\twritten += t2pWriteFile(output, (tdata_t) buffer, buflen );\n\twritten += t2pWriteFile(output, (tdata_t) " 0 obj\\n", 7);\n\treturn(written);\n}', 'tsize_t t2p_write_pdf_catalog(T2P* t2p, TIFF* output)\n{\n\ttsize_t written = 0;\n\tchar buffer[32];\n\tint buflen = 0;\n\twritten += t2pWriteFile(output,\n\t\t(tdata_t)"<< \\n/Type /Catalog \\n/Pages ",\n\t\t27);\n\tbuflen = snprintf(buffer, sizeof(buffer), "%lu", (unsigned long)t2p->pdf_pages);\n\tcheck_snprintf_ret(t2p, buflen, buffer);\n\twritten += t2pWriteFile(output, (tdata_t) buffer,\n\t\t\t\tTIFFmin((size_t)buflen, sizeof(buffer) - 1));\n\twritten += t2pWriteFile(output, (tdata_t) " 0 R \\n", 6);\n\tif(t2p->pdf_fitwindow){\n\t\twritten += t2pWriteFile(output,\n\t\t\t(tdata_t) "/ViewerPreferences <</FitWindow true>>\\n",\n\t\t\t39);\n\t}\n\twritten += t2pWriteFile(output, (tdata_t)">>\\n", 3);\n\treturn(written);\n}', 'tsize_t t2p_write_pdf_obj_end(TIFF* output){\n\ttsize_t written=0;\n\twritten += t2pWriteFile(output, (tdata_t) "endobj\\n", 7);\n\treturn(written);\n}']
34,929
0
https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_lib.c/#L342
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *A, *a = NULL; const BN_ULONG *B; int i; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b,BN_FLG_SECURE)) a = A = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = A = OPENSSL_zalloc(words * sizeof(*a)); if (A == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } #if 1 B = b->d; if (B != NULL) { for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) { BN_ULONG a0, a1, a2, a3; a0 = B[0]; a1 = B[1]; a2 = B[2]; a3 = B[3]; A[0] = a0; A[1] = a1; A[2] = a2; A[3] = a3; } switch (b->top & 3) { case 3: A[2] = B[2]; case 2: A[1] = B[1]; case 1: A[0] = B[0]; case 0: ; } } #else memset(A, 0, sizeof(*A) * words); memcpy(A, b->d, sizeof(b->d[0]) * b->top); #endif return (a); }
['static int generate_key(DH *dh)\n{\n int ok = 0;\n int generate_new_key = 0;\n unsigned l;\n BN_CTX *ctx;\n BN_MONT_CTX *mont = NULL;\n BIGNUM *pub_key = NULL, *priv_key = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n if (dh->priv_key == NULL) {\n priv_key = BN_secure_new();\n if (priv_key == NULL)\n goto err;\n generate_new_key = 1;\n } else\n priv_key = dh->priv_key;\n if (dh->pub_key == NULL) {\n pub_key = BN_new();\n if (pub_key == NULL)\n goto err;\n } else\n pub_key = dh->pub_key;\n if (dh->flags & DH_FLAG_CACHE_MONT_P) {\n mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,\n CRYPTO_LOCK_DH, dh->p, ctx);\n if (!mont)\n goto err;\n }\n if (generate_new_key) {\n if (dh->q) {\n do {\n if (!BN_rand_range(priv_key, dh->q))\n goto err;\n }\n while (BN_is_zero(priv_key) || BN_is_one(priv_key));\n } else {\n l = dh->length ? dh->length : BN_num_bits(dh->p) - 1;\n if (!BN_rand(priv_key, l, 0, 0))\n goto err;\n }\n }\n {\n BIGNUM *local_prk = NULL;\n BIGNUM *prk;\n if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) {\n local_prk = prk = BN_new();\n if (local_prk == NULL)\n goto err;\n BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n } else {\n prk = priv_key;\n }\n if (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) {\n BN_free(local_prk);\n goto err;\n }\n BN_free(local_prk);\n }\n dh->pub_key = pub_key;\n dh->priv_key = priv_key;\n ok = 1;\n err:\n if (ok != 1)\n DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB);\n if (pub_key != dh->pub_key)\n BN_free(pub_key);\n if (priv_key != dh->priv_key)\n BN_free(priv_key);\n BN_CTX_free(ctx);\n return (ok);\n}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(0, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits < 0 || (bits == 1 && top > 0)) {\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n if (bits == 0) {\n BN_zero(rnd);\n return 1;\n }\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (pseudorand) {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n } else {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n }\n if (pseudorand == 2) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\n}', '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, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = A = OPENSSL_zalloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
34,930
0
https://github.com/libav/libav/blob/0e7fa0bc3ba8eaea3eb623aa269806d2eca3a2c2/ffmpeg.c/#L3499
static void new_audio_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *audio_enc; enum CodecID codec_id; st = av_new_stream(oc, streamid_map[oc->nb_streams]); if (!st) { fprintf(stderr, "Could not alloc stream\n"); av_exit(1); } avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_AUDIO); bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters; audio_bitstream_filters= NULL; avcodec_thread_init(st->codec, thread_count); audio_enc = st->codec; audio_enc->codec_type = AVMEDIA_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[AVMEDIA_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER; } if (audio_stream_copy) { st->stream_copy = 1; audio_enc->channels = audio_channels; audio_enc->sample_rate = audio_sample_rate; } else { AVCodec *codec; set_context_opts(audio_enc, avcodec_opts[AVMEDIA_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, AVMEDIA_TYPE_AUDIO, 1, audio_enc->strict_std_compliance); 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, AVMEDIA_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->channels = audio_channels; audio_enc->sample_fmt = audio_sample_fmt; audio_enc->sample_rate = audio_sample_rate; audio_enc->channel_layout = channel_layout; if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels) audio_enc->channel_layout = 0; choose_sample_fmt(st, codec); choose_sample_rate(st, codec); } nb_ocodecs++; audio_enc->time_base= (AVRational){1, audio_sample_rate}; if (audio_language) { av_metadata_set2(&st->metadata, "language", audio_language, 0); av_freep(&audio_language); } 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 enum CodecID codec_id;\n st = av_new_stream(oc, streamid_map[oc->nb_streams]);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_AUDIO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;\n audio_bitstream_filters= NULL;\n avcodec_thread_init(st->codec, thread_count);\n audio_enc = st->codec;\n audio_enc->codec_type = AVMEDIA_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[AVMEDIA_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 audio_enc->sample_rate = audio_sample_rate;\n } else {\n AVCodec *codec;\n set_context_opts(audio_enc, avcodec_opts[AVMEDIA_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, AVMEDIA_TYPE_AUDIO, 1,\n audio_enc->strict_std_compliance);\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, AVMEDIA_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->channels = audio_channels;\n audio_enc->sample_fmt = audio_sample_fmt;\n audio_enc->sample_rate = audio_sample_rate;\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 choose_sample_fmt(st, codec);\n choose_sample_rate(st, codec);\n }\n nb_ocodecs++;\n audio_enc->time_base= (AVRational){1, audio_sample_rate};\n if (audio_language) {\n av_metadata_set2(&st->metadata, "language", audio_language, 0);\n av_freep(&audio_language);\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 av_log(s, AV_LOG_ERROR, "Too many streams\\n");\n return NULL;\n }\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}']
34,931
0
https://github.com/openssl/openssl/blob/74df8c4ce3c7ccb4e2809a44791756356f704b66/crypto/rand/rand_lib.c/#L137
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 = &openssl_rand_meth;\n }\n#else\n default_RAND_meth = &openssl_rand_meth;\n#endif\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
34,932
0
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int 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_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_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,\n const BIGNUM *priv, const unsigned char *message,\n size_t message_len, BN_CTX *ctx)\n{\n SHA512_CTX sha;\n unsigned char random_bytes[64];\n unsigned char digest[SHA512_DIGEST_LENGTH];\n unsigned done, todo;\n const unsigned num_k_bytes = BN_num_bytes(range) + 8;\n unsigned char private_bytes[96];\n unsigned char *k_bytes;\n int ret = 0;\n k_bytes = OPENSSL_malloc(num_k_bytes);\n if (k_bytes == NULL)\n goto err;\n todo = sizeof(priv->d[0]) * priv->top;\n if (todo > sizeof(private_bytes)) {\n BNerr(BN_F_BN_GENERATE_DSA_NONCE, BN_R_PRIVATE_KEY_TOO_LARGE);\n goto err;\n }\n memcpy(private_bytes, priv->d, todo);\n memset(private_bytes + todo, 0, sizeof(private_bytes) - todo);\n for (done = 0; done < num_k_bytes;) {\n if (RAND_bytes(random_bytes, sizeof(random_bytes)) != 1)\n goto err;\n SHA512_Init(&sha);\n SHA512_Update(&sha, &done, sizeof(done));\n SHA512_Update(&sha, private_bytes, sizeof(private_bytes));\n SHA512_Update(&sha, message, message_len);\n SHA512_Update(&sha, random_bytes, sizeof(random_bytes));\n SHA512_Final(digest, &sha);\n todo = num_k_bytes - done;\n if (todo > SHA512_DIGEST_LENGTH)\n todo = SHA512_DIGEST_LENGTH;\n memcpy(k_bytes + done, digest, todo);\n done += todo;\n }\n if (!BN_bin2bn(k_bytes, num_k_bytes, out))\n goto err;\n if (BN_mod(out, out, range, ctx) != 1)\n goto err;\n ret = 1;\n err:\n OPENSSL_free(k_bytes);\n OPENSSL_cleanse(private_bytes, sizeof(private_bytes));\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 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_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,933
0
https://github.com/libav/libav/blob/750f5034cf4d0dbe54aed917972f9c3f7a2cebbd/libavcodec/wmaprodec.c/#L622
static void decode_decorrelation_matrix(WMAProDecodeCtx *s, WMAProChannelGrp *chgroup) { int i; int offset = 0; int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS]; memset(chgroup->decorrelation_matrix, 0, s->num_channels * s->num_channels * sizeof(*chgroup->decorrelation_matrix)); for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++) rotation_offset[i] = get_bits(&s->gb, 6); for (i = 0; i < chgroup->num_channels; i++) chgroup->decorrelation_matrix[chgroup->num_channels * i + i] = get_bits1(&s->gb) ? 1.0 : -1.0; for (i = 1; i < chgroup->num_channels; i++) { int x; for (x = 0; x < i; x++) { int y; for (y = 0; y < i + 1; y++) { float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y]; float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y]; int n = rotation_offset[offset + x]; float sinv; float cosv; if (n < 32) { sinv = sin64[n]; cosv = sin64[32 - n]; } else { sinv = sin64[64 - n]; cosv = -sin64[n - 32]; } chgroup->decorrelation_matrix[y + x * chgroup->num_channels] = (v1 * sinv) - (v2 * cosv); chgroup->decorrelation_matrix[y + i * chgroup->num_channels] = (v1 * cosv) + (v2 * sinv); } } offset += i; } }
['static void decode_decorrelation_matrix(WMAProDecodeCtx *s,\n WMAProChannelGrp *chgroup)\n{\n int i;\n int offset = 0;\n int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS];\n memset(chgroup->decorrelation_matrix, 0, s->num_channels *\n s->num_channels * sizeof(*chgroup->decorrelation_matrix));\n for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++)\n rotation_offset[i] = get_bits(&s->gb, 6);\n for (i = 0; i < chgroup->num_channels; i++)\n chgroup->decorrelation_matrix[chgroup->num_channels * i + i] =\n get_bits1(&s->gb) ? 1.0 : -1.0;\n for (i = 1; i < chgroup->num_channels; i++) {\n int x;\n for (x = 0; x < i; x++) {\n int y;\n for (y = 0; y < i + 1; y++) {\n float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y];\n float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y];\n int n = rotation_offset[offset + x];\n float sinv;\n float cosv;\n if (n < 32) {\n sinv = sin64[n];\n cosv = sin64[32 - n];\n } else {\n sinv = sin64[64 - n];\n cosv = -sin64[n - 32];\n }\n chgroup->decorrelation_matrix[y + x * chgroup->num_channels] =\n (v1 * sinv) - (v2 * cosv);\n chgroup->decorrelation_matrix[y + i * chgroup->num_channels] =\n (v1 * cosv) + (v2 * sinv);\n }\n }\n offset += i;\n }\n}']
34,934
0
https://github.com/libav/libav/blob/12f0388f9cb32016ac0dacaeca631b088b29bb96/libavcodec/wmaenc.c/#L304
static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain) { int v, bsize, ch, coef_nb_bits, parse_exponents; float mdct_norm; int nb_coefs[MAX_CHANNELS]; static const int fixed_exp[25] = { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }; if (s->use_variable_block_len) { assert(0); } else { s->next_block_len_bits = s->frame_len_bits; s->prev_block_len_bits = s->frame_len_bits; s->block_len_bits = s->frame_len_bits; } s->block_len = 1 << s->block_len_bits; bsize = s->frame_len_bits - s->block_len_bits; v = s->coefs_end[bsize] - s->coefs_start; for (ch = 0; ch < s->avctx->channels; ch++) nb_coefs[ch] = v; { int n4 = s->block_len / 2; mdct_norm = 1.0 / (float) n4; if (s->version == 1) mdct_norm *= sqrt(n4); } if (s->avctx->channels == 2) put_bits(&s->pb, 1, !!s->ms_stereo); for (ch = 0; ch < s->avctx->channels; ch++) { s->channel_coded[ch] = 1; if (s->channel_coded[ch]) init_exp(s, ch, fixed_exp); } for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { WMACoef *coefs1; float *coefs, *exponents, mult; int i, n; coefs1 = s->coefs1[ch]; exponents = s->exponents[ch]; mult = pow(10, total_gain * 0.05) / s->max_exponent[ch]; mult *= mdct_norm; coefs = src_coefs[ch]; if (s->use_noise_coding && 0) { assert(0); } else { coefs += s->coefs_start; n = nb_coefs[ch]; for (i = 0; i < n; i++) { double t = *coefs++ / (exponents[i] * mult); if (t < -32768 || t > 32767) return -1; coefs1[i] = lrint(t); } } } } v = 0; for (ch = 0; ch < s->avctx->channels; ch++) { int a = s->channel_coded[ch]; put_bits(&s->pb, 1, a); v |= a; } if (!v) return 1; for (v = total_gain - 1; v >= 127; v -= 127) put_bits(&s->pb, 7, 127); put_bits(&s->pb, 7, v); coef_nb_bits = ff_wma_total_gain_to_bits(total_gain); if (s->use_noise_coding) { for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { int i, n; n = s->exponent_high_sizes[bsize]; for (i = 0; i < n; i++) { put_bits(&s->pb, 1, s->high_band_coded[ch][i] = 0); if (0) nb_coefs[ch] -= s->exponent_high_bands[bsize][i]; } } } } parse_exponents = 1; if (s->block_len_bits != s->frame_len_bits) put_bits(&s->pb, 1, parse_exponents); if (parse_exponents) { for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { encode_exp_vlc(s, ch, fixed_exp); } else { assert(0); } } } } else assert(0); for (ch = 0; ch < s->avctx->channels; ch++) { if (s->channel_coded[ch]) { int run, tindex; WMACoef *ptr, *eptr; tindex = (ch == 1 && s->ms_stereo); ptr = &s->coefs1[ch][0]; eptr = ptr + nb_coefs[ch]; run = 0; for (; ptr < eptr; ptr++) { if (*ptr) { int level = *ptr; int abs_level = FFABS(level); int code = 0; if (abs_level <= s->coef_vlcs[tindex]->max_level) if (run < s->coef_vlcs[tindex]->levels[abs_level - 1]) code = run + s->int_table[tindex][abs_level - 1]; assert(code < s->coef_vlcs[tindex]->n); put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[code], s->coef_vlcs[tindex]->huffcodes[code]); if (code == 0) { if (1 << coef_nb_bits <= abs_level) return -1; put_bits(&s->pb, coef_nb_bits, abs_level); put_bits(&s->pb, s->frame_len_bits, run); } put_bits(&s->pb, 1, level < 0); run = 0; } else run++; } if (run) put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]); } if (s->version == 1 && s->avctx->channels >= 2) avpriv_align_put_bits(&s->pb); } return 0; }
['static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],\n int total_gain)\n{\n int v, bsize, ch, coef_nb_bits, parse_exponents;\n float mdct_norm;\n int nb_coefs[MAX_CHANNELS];\n static const int fixed_exp[25] = {\n 20, 20, 20, 20, 20,\n 20, 20, 20, 20, 20,\n 20, 20, 20, 20, 20,\n 20, 20, 20, 20, 20,\n 20, 20, 20, 20, 20\n };\n if (s->use_variable_block_len) {\n assert(0);\n } else {\n s->next_block_len_bits = s->frame_len_bits;\n s->prev_block_len_bits = s->frame_len_bits;\n s->block_len_bits = s->frame_len_bits;\n }\n s->block_len = 1 << s->block_len_bits;\n bsize = s->frame_len_bits - s->block_len_bits;\n v = s->coefs_end[bsize] - s->coefs_start;\n for (ch = 0; ch < s->avctx->channels; ch++)\n nb_coefs[ch] = v;\n {\n int n4 = s->block_len / 2;\n mdct_norm = 1.0 / (float) n4;\n if (s->version == 1)\n mdct_norm *= sqrt(n4);\n }\n if (s->avctx->channels == 2)\n put_bits(&s->pb, 1, !!s->ms_stereo);\n for (ch = 0; ch < s->avctx->channels; ch++) {\n s->channel_coded[ch] = 1;\n if (s->channel_coded[ch])\n init_exp(s, ch, fixed_exp);\n }\n for (ch = 0; ch < s->avctx->channels; ch++) {\n if (s->channel_coded[ch]) {\n WMACoef *coefs1;\n float *coefs, *exponents, mult;\n int i, n;\n coefs1 = s->coefs1[ch];\n exponents = s->exponents[ch];\n mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];\n mult *= mdct_norm;\n coefs = src_coefs[ch];\n if (s->use_noise_coding && 0) {\n assert(0);\n } else {\n coefs += s->coefs_start;\n n = nb_coefs[ch];\n for (i = 0; i < n; i++) {\n double t = *coefs++ / (exponents[i] * mult);\n if (t < -32768 || t > 32767)\n return -1;\n coefs1[i] = lrint(t);\n }\n }\n }\n }\n v = 0;\n for (ch = 0; ch < s->avctx->channels; ch++) {\n int a = s->channel_coded[ch];\n put_bits(&s->pb, 1, a);\n v |= a;\n }\n if (!v)\n return 1;\n for (v = total_gain - 1; v >= 127; v -= 127)\n put_bits(&s->pb, 7, 127);\n put_bits(&s->pb, 7, v);\n coef_nb_bits = ff_wma_total_gain_to_bits(total_gain);\n if (s->use_noise_coding) {\n for (ch = 0; ch < s->avctx->channels; ch++) {\n if (s->channel_coded[ch]) {\n int i, n;\n n = s->exponent_high_sizes[bsize];\n for (i = 0; i < n; i++) {\n put_bits(&s->pb, 1, s->high_band_coded[ch][i] = 0);\n if (0)\n nb_coefs[ch] -= s->exponent_high_bands[bsize][i];\n }\n }\n }\n }\n parse_exponents = 1;\n if (s->block_len_bits != s->frame_len_bits)\n put_bits(&s->pb, 1, parse_exponents);\n if (parse_exponents) {\n for (ch = 0; ch < s->avctx->channels; ch++) {\n if (s->channel_coded[ch]) {\n if (s->use_exp_vlc) {\n encode_exp_vlc(s, ch, fixed_exp);\n } else {\n assert(0);\n }\n }\n }\n } else\n assert(0);\n for (ch = 0; ch < s->avctx->channels; ch++) {\n if (s->channel_coded[ch]) {\n int run, tindex;\n WMACoef *ptr, *eptr;\n tindex = (ch == 1 && s->ms_stereo);\n ptr = &s->coefs1[ch][0];\n eptr = ptr + nb_coefs[ch];\n run = 0;\n for (; ptr < eptr; ptr++) {\n if (*ptr) {\n int level = *ptr;\n int abs_level = FFABS(level);\n int code = 0;\n if (abs_level <= s->coef_vlcs[tindex]->max_level)\n if (run < s->coef_vlcs[tindex]->levels[abs_level - 1])\n code = run + s->int_table[tindex][abs_level - 1];\n assert(code < s->coef_vlcs[tindex]->n);\n put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[code],\n s->coef_vlcs[tindex]->huffcodes[code]);\n if (code == 0) {\n if (1 << coef_nb_bits <= abs_level)\n return -1;\n put_bits(&s->pb, coef_nb_bits, abs_level);\n put_bits(&s->pb, s->frame_len_bits, run);\n }\n put_bits(&s->pb, 1, level < 0);\n run = 0;\n } else\n run++;\n }\n if (run)\n put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1],\n s->coef_vlcs[tindex]->huffcodes[1]);\n }\n if (s->version == 1 && s->avctx->channels >= 2)\n avpriv_align_put_bits(&s->pb);\n }\n return 0;\n}']
34,935
0
https://github.com/openssl/openssl/blob/fa9bb6201e1d16ba8ccab938833d140ef81a7f73/crypto/bn/bn_sqr.c/#L167
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) { int i, j, max; const BN_ULONG *ap; BN_ULONG *rp; max = n * 2; ap = a; rp = r; rp[0] = rp[max - 1] = 0; rp++; j = n; if (--j > 0) { ap++; rp[j] = bn_mul_words(rp, ap, j, ap[-1]); rp += 2; } for (i = n - 2; i > 0; i--) { j--; ap++; rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); rp += 2; } bn_add_words(r, r, r, max); bn_sqr_words(tmp, a, n); bn_add_words(r, r, tmp, max); }
['static int rsa_ossl_private_encrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret, *res;\n int i, j, k, num = 0, r = -1;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n int local_blinding = 0;\n BIGNUM *unblind = NULL;\n BN_BLINDING *blinding = NULL;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (f == NULL || ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n switch (padding) {\n case RSA_PKCS1_PADDING:\n i = RSA_padding_add_PKCS1_type_1(buf, num, from, flen);\n break;\n case RSA_X931_PADDING:\n i = RSA_padding_add_X931(buf, num, from, flen);\n break;\n case RSA_NO_PADDING:\n i = RSA_padding_add_none(buf, num, from, flen);\n break;\n case RSA_SSLV23_PADDING:\n default:\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (i <= 0)\n goto err;\n if (BN_bin2bn(buf, num, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {\n blinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n if (blinding == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n if (blinding != NULL) {\n if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!rsa_blinding_convert(blinding, f, unblind, ctx))\n goto err;\n }\n if ((rsa->flags & RSA_FLAG_EXT_PKEY) ||\n ((rsa->p != NULL) &&\n (rsa->q != NULL) &&\n (rsa->dmp1 != NULL) && (rsa->dmq1 != NULL) && (rsa->iqmp != NULL))) {\n if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx))\n goto err;\n } else {\n BIGNUM *d = NULL, *local_d = NULL;\n if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n local_d = d = BN_new();\n if (d == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n } else {\n d = rsa->d;\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {\n BN_free(local_d);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(local_d);\n goto err;\n }\n BN_free(local_d);\n }\n if (blinding)\n if (!rsa_blinding_invert(blinding, ret, unblind, ctx))\n goto err;\n if (padding == RSA_X931_PADDING) {\n BN_sub(f, rsa->n, ret);\n if (BN_cmp(ret, f) > 0)\n res = f;\n else\n res = ret;\n } else\n res = ret;\n j = BN_num_bytes(res);\n i = BN_bn2bin(res, &(to[num - j]));\n for (k = 0; k < (num - i); k++)\n to[k] = 0;\n r = num;\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return (r);\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return (NULL);\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return (ret);\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return (ret);\n}', 'static int rsa_blinding_convert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,\n BN_CTX *ctx)\n{\n if (unblind == NULL)\n return BN_BLINDING_convert_ex(f, NULL, b, ctx);\n else {\n int ret;\n CRYPTO_w_lock(CRYPTO_LOCK_RSA_BLINDING);\n ret = BN_BLINDING_convert_ex(f, unblind, b, ctx);\n CRYPTO_w_unlock(CRYPTO_LOCK_RSA_BLINDING);\n return ret;\n }\n}', 'int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)\n{\n int ret = 1;\n bn_check_top(n);\n if ((b->A == NULL) || (b->Ai == NULL)) {\n BNerr(BN_F_BN_BLINDING_CONVERT_EX, BN_R_NOT_INITIALIZED);\n return (0);\n }\n if (b->counter == -1)\n b->counter = 0;\n else if (!BN_BLINDING_update(b, ctx))\n return (0);\n if (r != NULL) {\n if (!BN_copy(r, b->Ai))\n ret = 0;\n }\n if (!BN_mod_mul(n, n, b->A, b->mod, ctx))\n ret = 0;\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', '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}']
34,936
0
https://github.com/apache/httpd/blob/c12eef19b2c88d34c7c0b869b6389aae5173110a/server/util.c/#L797
AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line) { const char *str = *line, *strend; char *res; char quote; while (apr_isspace(*str)) ++str; if (!*str) { *line = str; return ""; } if ((quote = *str) == '"' || quote == '\'') { strend = str + 1; while (*strend && *strend != quote) { if (*strend == '\\' && strend[1] && (strend[1] == quote || strend[1] == '\\')) { strend += 2; } else { ++strend; } } res = substring_conf(p, str + 1, strend - str - 1, quote); if (*strend == quote) ++strend; } else { strend = str; while (*strend && !apr_isspace(*strend)) ++strend; res = substring_conf(p, str, strend - str, 0); } while (apr_isspace(*strend)) ++strend; *line = strend; return res; }
['static authz_status host_check_authorization(request_rec *r,\n const char *require_line,\n const void *parsed_require_line)\n{\n const char *t;\n char *w, *hash_ptr;\n const char *remotehost = NULL;\n int remotehost_is_ip;\n remotehost = ap_get_remote_host(r->connection,\n r->per_dir_config,\n REMOTE_DOUBLE_REV,\n &remotehost_is_ip);\n if ((remotehost == NULL) || remotehost_is_ip) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01753)\n "access check of \'%s\' to %s failed, reason: unable to get the "\n "remote host name", require_line, r->uri);\n }\n else {\n const char *err = NULL;\n const ap_expr_info_t *expr = parsed_require_line;\n const char *require;\n require = ap_expr_str_exec(r, expr, &err);\n if (err) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(02593)\n "authz_host authorize: require host: Can\'t "\n "evaluate require expression: %s", err);\n return AUTHZ_DENIED;\n }\n t = require;\n while ((w = ap_getword_conf(r->pool, &t)) && w[0]) {\n if ((hash_ptr = ap_strchr(w, \'#\'))) {\n if (hash_ptr == w) {\n break;\n }\n *hash_ptr = \'\\0\';\n }\n if (in_domain(w, remotehost)) {\n return AUTHZ_GRANTED;\n }\n if (hash_ptr) {\n break;\n }\n }\n }\n return AUTHZ_DENIED;\n}', 'AP_DECLARE(const char *) ap_expr_str_exec(request_rec *r,\n const ap_expr_info_t *info,\n const char **err)\n{\n return ap_expr_str_exec_re(r, info, 0, NULL, NULL, err);\n}', 'AP_DECLARE(const char *) ap_expr_str_exec_re(request_rec *r,\n const ap_expr_info_t *info,\n apr_size_t nmatch,\n ap_regmatch_t *pmatch,\n const char **source,\n const char **err)\n{\n ap_expr_eval_ctx_t ctx;\n int dont_vary, rc;\n const char *tmp_source, *vary_this;\n ap_regmatch_t tmp_pmatch[AP_MAX_REG_MATCH];\n const char *result;\n AP_DEBUG_ASSERT(info->flags & AP_EXPR_FLAG_STRING_RESULT);\n if (info->root_node->node_op == op_String) {\n *err = NULL;\n return (const char *)info->root_node->node_arg1;\n }\n tmp_source = NULL;\n vary_this = NULL;\n dont_vary = (info->flags & AP_EXPR_FLAG_DONT_VARY);\n ctx.r = r;\n ctx.c = r->connection;\n ctx.s = r->server;\n ctx.p = r->pool;\n ctx.err = err;\n ctx.info = info;\n ctx.re_nmatch = nmatch;\n ctx.re_pmatch = pmatch;\n ctx.re_source = source;\n ctx.vary_this = dont_vary ? NULL : &vary_this;\n ctx.data = NULL;\n ctx.result_string = &result;\n if (!pmatch) {\n ctx.re_nmatch = AP_MAX_REG_MATCH;\n ctx.re_pmatch = tmp_pmatch;\n ctx.re_source = &tmp_source;\n }\n rc = ap_expr_exec_ctx(&ctx);\n if (rc > 0)\n return result;\n else if (rc < 0)\n return NULL;\n else\n ap_assert(0);\n return NULL;\n}', 'AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line)\n{\n const char *str = *line, *strend;\n char *res;\n char quote;\n while (apr_isspace(*str))\n ++str;\n if (!*str) {\n *line = str;\n return "";\n }\n if ((quote = *str) == \'"\' || quote == \'\\\'\') {\n strend = str + 1;\n while (*strend && *strend != quote) {\n if (*strend == \'\\\\\' && strend[1] &&\n (strend[1] == quote || strend[1] == \'\\\\\')) {\n strend += 2;\n }\n else {\n ++strend;\n }\n }\n res = substring_conf(p, str + 1, strend - str - 1, quote);\n if (*strend == quote)\n ++strend;\n }\n else {\n strend = str;\n while (*strend && !apr_isspace(*strend))\n ++strend;\n res = substring_conf(p, str, strend - str, 0);\n }\n while (apr_isspace(*strend))\n ++strend;\n *line = strend;\n return res;\n}']
34,937
0
https://github.com/libav/libav/blob/03f8fc0897c128028111182e6276139fa00b891b/libavcodec/aacsbr.c/#L744
static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr, GetBitContext *gb, SBRData *ch_data) { int i; unsigned bs_pointer; int abs_bord_lead = 0; int abs_bord_trail = 16; int num_rel_lead, num_rel_trail; uint8_t bs_rel_bord[2][3]; ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env[1]]; ch_data->bs_num_env[0] = ch_data->bs_num_env[1]; ch_data->bs_amp_res = sbr->bs_amp_res_header; switch (ch_data->bs_frame_class = get_bits(gb, 2)) { case FIXFIX: ch_data->bs_num_env[1] = 1 << get_bits(gb, 2); num_rel_lead = ch_data->bs_num_env[1] - 1; if (ch_data->bs_num_env[1] == 1) ch_data->bs_amp_res = 0; if (ch_data->bs_num_env[1] > 4) { av_log(ac->avccontext, AV_LOG_ERROR, "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\n", ch_data->bs_num_env[1]); return -1; } bs_pointer = 0; ch_data->bs_freq_res[1] = get_bits1(gb); for (i = 1; i < ch_data->bs_num_env[1]; i++) ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1]; break; case FIXVAR: abs_bord_trail += get_bits(gb, 2); num_rel_trail = get_bits(gb, 2); num_rel_lead = 0; ch_data->bs_num_env[1] = num_rel_trail + 1; for (i = 0; i < num_rel_trail; i++) bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); for (i = 0; i < ch_data->bs_num_env[1]; i++) ch_data->bs_freq_res[ch_data->bs_num_env[1] - i] = get_bits1(gb); break; case VARFIX: abs_bord_lead = get_bits(gb, 2); num_rel_lead = get_bits(gb, 2); ch_data->bs_num_env[1] = num_rel_lead + 1; for (i = 0; i < num_rel_lead; i++) bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]); break; case VARVAR: abs_bord_lead = get_bits(gb, 2); abs_bord_trail += get_bits(gb, 2); num_rel_lead = get_bits(gb, 2); num_rel_trail = get_bits(gb, 2); ch_data->bs_num_env[1] = num_rel_lead + num_rel_trail + 1; if (ch_data->bs_num_env[1] > 5) { av_log(ac->avccontext, AV_LOG_ERROR, "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\n", ch_data->bs_num_env[1]); return -1; } for (i = 0; i < num_rel_lead; i++) bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2; for (i = 0; i < num_rel_trail; i++) bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2; bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]); get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]); break; } if (bs_pointer > ch_data->bs_num_env[1] + 1) { av_log(ac->avccontext, AV_LOG_ERROR, "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\n", bs_pointer); return -1; } ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]]; ch_data->t_env[0] = abs_bord_lead; ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail; if (ch_data->bs_frame_class == FIXFIX) { int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) / ch_data->bs_num_env[1]; for (i = 0; i < num_rel_lead; i++) ch_data->t_env[i + 1] = ch_data->t_env[i] + temp; } else if (ch_data->bs_frame_class > 1) { for (i = 0; i < num_rel_lead; i++) ch_data->t_env[i + 1] = ch_data->t_env[i] + bs_rel_bord[0][i]; } if (ch_data->bs_frame_class & 1) { for (i = ch_data->bs_num_env[1] - 1; i > num_rel_lead; i--) ch_data->t_env[i] = ch_data->t_env[i + 1] - bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i]; } ch_data->bs_num_noise = (ch_data->bs_num_env[1] > 1) + 1; ch_data->t_q[0] = ch_data->t_env[0]; if (ch_data->bs_num_noise > 1) { unsigned int idx; if (ch_data->bs_frame_class == FIXFIX) { idx = ch_data->bs_num_env[1] >> 1; } else if (ch_data->bs_frame_class & 1) { idx = ch_data->bs_num_env[1] - FFMAX(bs_pointer - 1, 1); } else { if (!bs_pointer) idx = 1; else if (bs_pointer == 1) idx = ch_data->bs_num_env[1] - 1; else idx = bs_pointer - 1; } ch_data->t_q[1] = ch_data->t_env[idx]; ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]]; } else ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]]; ch_data->e_a[0] = -(ch_data->e_a[1] != ch_data->bs_num_env[0]); ch_data->e_a[1] = -1; if ((ch_data->bs_frame_class & 1) && bs_pointer) { ch_data->e_a[1] = ch_data->bs_num_env[1] + 1 - bs_pointer; } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1)) ch_data->e_a[1] = bs_pointer - 1; return 0; }
['static int read_sbr_grid(AACContext *ac, SpectralBandReplication *sbr,\n GetBitContext *gb, SBRData *ch_data)\n{\n int i;\n unsigned bs_pointer;\n int abs_bord_lead = 0;\n int abs_bord_trail = 16;\n int num_rel_lead, num_rel_trail;\n uint8_t bs_rel_bord[2][3];\n ch_data->bs_freq_res[0] = ch_data->bs_freq_res[ch_data->bs_num_env[1]];\n ch_data->bs_num_env[0] = ch_data->bs_num_env[1];\n ch_data->bs_amp_res = sbr->bs_amp_res_header;\n switch (ch_data->bs_frame_class = get_bits(gb, 2)) {\n case FIXFIX:\n ch_data->bs_num_env[1] = 1 << get_bits(gb, 2);\n num_rel_lead = ch_data->bs_num_env[1] - 1;\n if (ch_data->bs_num_env[1] == 1)\n ch_data->bs_amp_res = 0;\n if (ch_data->bs_num_env[1] > 4) {\n av_log(ac->avccontext, AV_LOG_ERROR,\n "Invalid bitstream, too many SBR envelopes in FIXFIX type SBR frame: %d\\n",\n ch_data->bs_num_env[1]);\n return -1;\n }\n bs_pointer = 0;\n ch_data->bs_freq_res[1] = get_bits1(gb);\n for (i = 1; i < ch_data->bs_num_env[1]; i++)\n ch_data->bs_freq_res[i + 1] = ch_data->bs_freq_res[1];\n break;\n case FIXVAR:\n abs_bord_trail += get_bits(gb, 2);\n num_rel_trail = get_bits(gb, 2);\n num_rel_lead = 0;\n ch_data->bs_num_env[1] = num_rel_trail + 1;\n for (i = 0; i < num_rel_trail; i++)\n bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;\n bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);\n for (i = 0; i < ch_data->bs_num_env[1]; i++)\n ch_data->bs_freq_res[ch_data->bs_num_env[1] - i] = get_bits1(gb);\n break;\n case VARFIX:\n abs_bord_lead = get_bits(gb, 2);\n num_rel_lead = get_bits(gb, 2);\n ch_data->bs_num_env[1] = num_rel_lead + 1;\n for (i = 0; i < num_rel_lead; i++)\n bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;\n bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);\n get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]);\n break;\n case VARVAR:\n abs_bord_lead = get_bits(gb, 2);\n abs_bord_trail += get_bits(gb, 2);\n num_rel_lead = get_bits(gb, 2);\n num_rel_trail = get_bits(gb, 2);\n ch_data->bs_num_env[1] = num_rel_lead + num_rel_trail + 1;\n if (ch_data->bs_num_env[1] > 5) {\n av_log(ac->avccontext, AV_LOG_ERROR,\n "Invalid bitstream, too many SBR envelopes in VARVAR type SBR frame: %d\\n",\n ch_data->bs_num_env[1]);\n return -1;\n }\n for (i = 0; i < num_rel_lead; i++)\n bs_rel_bord[0][i] = 2 * get_bits(gb, 2) + 2;\n for (i = 0; i < num_rel_trail; i++)\n bs_rel_bord[1][i] = 2 * get_bits(gb, 2) + 2;\n bs_pointer = get_bits(gb, ceil_log2[ch_data->bs_num_env[1]]);\n get_bits1_vector(gb, ch_data->bs_freq_res + 1, ch_data->bs_num_env[1]);\n break;\n }\n if (bs_pointer > ch_data->bs_num_env[1] + 1) {\n av_log(ac->avccontext, AV_LOG_ERROR,\n "Invalid bitstream, bs_pointer points to a middle noise border outside the time borders table: %d\\n",\n bs_pointer);\n return -1;\n }\n ch_data->t_env_num_env_old = ch_data->t_env[ch_data->bs_num_env[0]];\n ch_data->t_env[0] = abs_bord_lead;\n ch_data->t_env[ch_data->bs_num_env[1]] = abs_bord_trail;\n if (ch_data->bs_frame_class == FIXFIX) {\n int temp = (abs_bord_trail + (ch_data->bs_num_env[1] >> 1)) /\n ch_data->bs_num_env[1];\n for (i = 0; i < num_rel_lead; i++)\n ch_data->t_env[i + 1] = ch_data->t_env[i] + temp;\n } else if (ch_data->bs_frame_class > 1) {\n for (i = 0; i < num_rel_lead; i++)\n ch_data->t_env[i + 1] = ch_data->t_env[i] + bs_rel_bord[0][i];\n }\n if (ch_data->bs_frame_class & 1) {\n for (i = ch_data->bs_num_env[1] - 1; i > num_rel_lead; i--)\n ch_data->t_env[i] = ch_data->t_env[i + 1] -\n bs_rel_bord[1][ch_data->bs_num_env[1] - 1 - i];\n }\n ch_data->bs_num_noise = (ch_data->bs_num_env[1] > 1) + 1;\n ch_data->t_q[0] = ch_data->t_env[0];\n if (ch_data->bs_num_noise > 1) {\n unsigned int idx;\n if (ch_data->bs_frame_class == FIXFIX) {\n idx = ch_data->bs_num_env[1] >> 1;\n } else if (ch_data->bs_frame_class & 1) {\n idx = ch_data->bs_num_env[1] - FFMAX(bs_pointer - 1, 1);\n } else {\n if (!bs_pointer)\n idx = 1;\n else if (bs_pointer == 1)\n idx = ch_data->bs_num_env[1] - 1;\n else\n idx = bs_pointer - 1;\n }\n ch_data->t_q[1] = ch_data->t_env[idx];\n ch_data->t_q[2] = ch_data->t_env[ch_data->bs_num_env[1]];\n } else\n ch_data->t_q[1] = ch_data->t_env[ch_data->bs_num_env[1]];\n ch_data->e_a[0] = -(ch_data->e_a[1] != ch_data->bs_num_env[0]);\n ch_data->e_a[1] = -1;\n if ((ch_data->bs_frame_class & 1) && bs_pointer) {\n ch_data->e_a[1] = ch_data->bs_num_env[1] + 1 - bs_pointer;\n } else if ((ch_data->bs_frame_class == 2) && (bs_pointer > 1))\n ch_data->e_a[1] = bs_pointer - 1;\n return 0;\n}']
34,938
0
https://github.com/openssl/openssl/blob/24a5f17b6a221c327d292d7236b24717d5e413a9/crypto/bn/bn_ctx.c/#L355
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int test_div(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta = BN_new();\n\tb = BN_new();\n\tc = BN_new();\n\td = BN_new();\n\te = BN_new();\n\tfor (i=0; i<num0+num1; i++)\n\t\t{\n\t\tif (i < num1)\n\t\t\t{\n\t\t\tBN_bntest_rand(a,400,0,0);\n\t\t\tBN_copy(b,a);\n\t\t\tBN_lshift(a,a,i);\n\t\t\tBN_add_word(a,i);\n\t\t\t}\n\t\telse\n\t\t\tBN_bntest_rand(b,50+3*(i-num1),0,0);\n\t\ta->neg=rand_neg();\n\t\tb->neg=rand_neg();\n\t\tBN_div(d,c,a,b,ctx);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," / ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,d);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,c);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_mul(e,d,b,ctx);\n\t\tBN_add(d,e,c);\n\t\tBN_sub(d,d,a);\n\t\tif(!BN_is_zero(d))\n\t\t {\n\t\t fprintf(stderr,"Division test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tint no_branch=0;\n\tif ((num->top > 0 && num->d[num->top - 1] == 0) ||\n\t\t(divisor->top > 0 && divisor->d[divisor->top - 1] == 0))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\tno_branch=1;\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (!no_branch && BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n\t\tgoto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (no_branch)\n\t\t{\n\t\tif (snum->top <= sdiv->top+1)\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\t\tsnum->top = sdiv->top + 2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\t\tsnum->d[snum->top] = 0;\n\t\t\tsnum->top ++;\n\t\t\t}\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-no_branch;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (!no_branch)\n\t\t{\n\t\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t\t{\n\t\t\tbn_clear_top2max(&wnum);\n\t\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t\t*resp=1;\n\t\t\t}\n\t\telse\n\t\t\tres->top--;\n\t\t}\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tif (no_branch)\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
34,939
0
https://github.com/libav/libav/blob/00ba041cb396f88f68a1bf7907e7c98ded3760ab/libavcodec/binkaudio.c/#L205
static void decode_block(BinkAudioContext *s, short *out, int use_dct) { int ch, i, j, k; float q, quant[25]; int width, coeff; GetBitContext *gb = &s->gb; if (use_dct) skip_bits(gb, 2); for (ch = 0; ch < s->channels; ch++) { FFTSample *coeffs = s->coeffs_ptr[ch]; if (s->version_b) { coeffs[0] = av_int2flt(get_bits(gb, 32)) * s->root; coeffs[1] = av_int2flt(get_bits(gb, 32)) * s->root; } else { coeffs[0] = get_float(gb) * s->root; coeffs[1] = get_float(gb) * s->root; } for (i = 0; i < s->num_bands; i++) { int value = get_bits(gb, 8); quant[i] = expf(FFMIN(value, 95) * 0.15289164787221953823f) * s->root; } k = 0; q = quant[0]; i = 2; while (i < s->frame_len) { if (s->version_b) { j = i + 16; } else if (get_bits1(gb)) { j = i + rle_length_tab[get_bits(gb, 4)] * 8; } else { j = i + 8; } j = FFMIN(j, s->frame_len); width = get_bits(gb, 4); if (width == 0) { memset(coeffs + i, 0, (j - i) * sizeof(*coeffs)); i = j; while (s->bands[k] < i) q = quant[k++]; } else { while (i < j) { if (s->bands[k] == i) q = quant[k++]; coeff = get_bits(gb, width); if (coeff) { if (get_bits1(gb)) coeffs[i] = -q * coeff; else coeffs[i] = q * coeff; } else { coeffs[i] = 0.0f; } i++; } } } if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) { coeffs[0] /= 0.5; ff_dct_calc (&s->trans.dct, coeffs); s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame_len); } else if (CONFIG_BINKAUDIO_RDFT_DECODER) ff_rdft_calc(&s->trans.rdft, coeffs); } s->fmt_conv.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, s->frame_len, s->channels); if (!s->first) { int count = s->overlap_len * s->channels; int shift = av_log2(count); for (i = 0; i < count; i++) { out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift; } } memcpy(s->previous, out + s->block_size, s->overlap_len * s->channels * sizeof(*out)); s->first = 0; }
['static void decode_block(BinkAudioContext *s, short *out, int use_dct)\n{\n int ch, i, j, k;\n float q, quant[25];\n int width, coeff;\n GetBitContext *gb = &s->gb;\n if (use_dct)\n skip_bits(gb, 2);\n for (ch = 0; ch < s->channels; ch++) {\n FFTSample *coeffs = s->coeffs_ptr[ch];\n if (s->version_b) {\n coeffs[0] = av_int2flt(get_bits(gb, 32)) * s->root;\n coeffs[1] = av_int2flt(get_bits(gb, 32)) * s->root;\n } else {\n coeffs[0] = get_float(gb) * s->root;\n coeffs[1] = get_float(gb) * s->root;\n }\n for (i = 0; i < s->num_bands; i++) {\n int value = get_bits(gb, 8);\n quant[i] = expf(FFMIN(value, 95) * 0.15289164787221953823f) * s->root;\n }\n k = 0;\n q = quant[0];\n i = 2;\n while (i < s->frame_len) {\n if (s->version_b) {\n j = i + 16;\n } else if (get_bits1(gb)) {\n j = i + rle_length_tab[get_bits(gb, 4)] * 8;\n } else {\n j = i + 8;\n }\n j = FFMIN(j, s->frame_len);\n width = get_bits(gb, 4);\n if (width == 0) {\n memset(coeffs + i, 0, (j - i) * sizeof(*coeffs));\n i = j;\n while (s->bands[k] < i)\n q = quant[k++];\n } else {\n while (i < j) {\n if (s->bands[k] == i)\n q = quant[k++];\n coeff = get_bits(gb, width);\n if (coeff) {\n if (get_bits1(gb))\n coeffs[i] = -q * coeff;\n else\n coeffs[i] = q * coeff;\n } else {\n coeffs[i] = 0.0f;\n }\n i++;\n }\n }\n }\n if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) {\n coeffs[0] /= 0.5;\n ff_dct_calc (&s->trans.dct, coeffs);\n s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame_len);\n }\n else if (CONFIG_BINKAUDIO_RDFT_DECODER)\n ff_rdft_calc(&s->trans.rdft, coeffs);\n }\n s->fmt_conv.float_to_int16_interleave(out, (const float **)s->coeffs_ptr,\n s->frame_len, s->channels);\n if (!s->first) {\n int count = s->overlap_len * s->channels;\n int shift = av_log2(count);\n for (i = 0; i < count; i++) {\n out[i] = (s->previous[i] * (count - i) + out[i] * i) >> shift;\n }\n }\n memcpy(s->previous, out + s->block_size,\n s->overlap_len * s->channels * sizeof(*out));\n s->first = 0;\n}']
34,940
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/cast/c_skey.c/#L96
void CAST_set_key(CAST_KEY *key, int len, unsigned char *data) { CAST_LONG x[16]; CAST_LONG z[16]; CAST_LONG k[32]; CAST_LONG X[4],Z[4]; CAST_LONG l,*K; int i; for (i=0; i<16; i++) x[i]=0; if (len > 16) len=16; for (i=0; i<len; i++) x[i]=data[i]; if(len <= 10) key->short_key=1; else key->short_key=0; K= &k[0]; X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL; X[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL; X[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL; X[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL; for (;;) { l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]]; CAST_exp(l,Z,z, 0); l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]]; CAST_exp(l,Z,z, 4); l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]]; CAST_exp(l,Z,z, 8); l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]]; CAST_exp(l,Z,z,12); K[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]]; K[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]]; K[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]]; K[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]]; l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]]; CAST_exp(l,X,x, 0); l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]]; CAST_exp(l,X,x, 4); l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]]; CAST_exp(l,X,x, 8); l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]]; CAST_exp(l,X,x,12); K[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]]; K[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]]; K[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]]; K[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]]; l=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]]; CAST_exp(l,Z,z, 0); l=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]]; CAST_exp(l,Z,z, 4); l=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]]; CAST_exp(l,Z,z, 8); l=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]]; CAST_exp(l,Z,z,12); K[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]]; K[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]]; K[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]]; K[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]]; l=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]]; CAST_exp(l,X,x, 0); l=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]]; CAST_exp(l,X,x, 4); l=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]]; CAST_exp(l,X,x, 8); l=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]]; CAST_exp(l,X,x,12); K[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]]; K[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]]; K[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]]; K[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]]; if (K != k) break; K+=16; } for (i=0; i<16; i++) { key->data[i*2]=k[i]; key->data[i*2+1]=((k[i+16])+16)&0x1f; } }
['void CAST_set_key(CAST_KEY *key, int len, unsigned char *data)\n\t{\n\tCAST_LONG x[16];\n\tCAST_LONG z[16];\n\tCAST_LONG k[32];\n\tCAST_LONG X[4],Z[4];\n\tCAST_LONG l,*K;\n\tint i;\n\tfor (i=0; i<16; i++) x[i]=0;\n\tif (len > 16) len=16;\n\tfor (i=0; i<len; i++)\n\t\tx[i]=data[i];\n\tif(len <= 10)\n\t key->short_key=1;\n\telse\n\t key->short_key=0;\n\tK= &k[0];\n\tX[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL;\n\tX[1]=((x[ 4]<<24)|(x[ 5]<<16)|(x[ 6]<<8)|x[ 7])&0xffffffffL;\n\tX[2]=((x[ 8]<<24)|(x[ 9]<<16)|(x[10]<<8)|x[11])&0xffffffffL;\n\tX[3]=((x[12]<<24)|(x[13]<<16)|(x[14]<<8)|x[15])&0xffffffffL;\n\tfor (;;)\n\t\t{\n\tl=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];\n\tCAST_exp(l,Z,z, 0);\n\tl=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];\n\tCAST_exp(l,Z,z, 4);\n\tl=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];\n\tCAST_exp(l,Z,z, 8);\n\tl=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];\n\tCAST_exp(l,Z,z,12);\n\tK[ 0]= S4[z[ 8]]^S5[z[ 9]]^S6[z[ 7]]^S7[z[ 6]]^S4[z[ 2]];\n\tK[ 1]= S4[z[10]]^S5[z[11]]^S6[z[ 5]]^S7[z[ 4]]^S5[z[ 6]];\n\tK[ 2]= S4[z[12]]^S5[z[13]]^S6[z[ 3]]^S7[z[ 2]]^S6[z[ 9]];\n\tK[ 3]= S4[z[14]]^S5[z[15]]^S6[z[ 1]]^S7[z[ 0]]^S7[z[12]];\n\tl=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];\n\tCAST_exp(l,X,x, 0);\n\tl=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];\n\tCAST_exp(l,X,x, 4);\n\tl=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];\n\tCAST_exp(l,X,x, 8);\n\tl=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];\n\tCAST_exp(l,X,x,12);\n\tK[ 4]= S4[x[ 3]]^S5[x[ 2]]^S6[x[12]]^S7[x[13]]^S4[x[ 8]];\n\tK[ 5]= S4[x[ 1]]^S5[x[ 0]]^S6[x[14]]^S7[x[15]]^S5[x[13]];\n\tK[ 6]= S4[x[ 7]]^S5[x[ 6]]^S6[x[ 8]]^S7[x[ 9]]^S6[x[ 3]];\n\tK[ 7]= S4[x[ 5]]^S5[x[ 4]]^S6[x[10]]^S7[x[11]]^S7[x[ 7]];\n\tl=X[0]^S4[x[13]]^S5[x[15]]^S6[x[12]]^S7[x[14]]^S6[x[ 8]];\n\tCAST_exp(l,Z,z, 0);\n\tl=X[2]^S4[z[ 0]]^S5[z[ 2]]^S6[z[ 1]]^S7[z[ 3]]^S7[x[10]];\n\tCAST_exp(l,Z,z, 4);\n\tl=X[3]^S4[z[ 7]]^S5[z[ 6]]^S6[z[ 5]]^S7[z[ 4]]^S4[x[ 9]];\n\tCAST_exp(l,Z,z, 8);\n\tl=X[1]^S4[z[10]]^S5[z[ 9]]^S6[z[11]]^S7[z[ 8]]^S5[x[11]];\n\tCAST_exp(l,Z,z,12);\n\tK[ 8]= S4[z[ 3]]^S5[z[ 2]]^S6[z[12]]^S7[z[13]]^S4[z[ 9]];\n\tK[ 9]= S4[z[ 1]]^S5[z[ 0]]^S6[z[14]]^S7[z[15]]^S5[z[12]];\n\tK[10]= S4[z[ 7]]^S5[z[ 6]]^S6[z[ 8]]^S7[z[ 9]]^S6[z[ 2]];\n\tK[11]= S4[z[ 5]]^S5[z[ 4]]^S6[z[10]]^S7[z[11]]^S7[z[ 6]];\n\tl=Z[2]^S4[z[ 5]]^S5[z[ 7]]^S6[z[ 4]]^S7[z[ 6]]^S6[z[ 0]];\n\tCAST_exp(l,X,x, 0);\n\tl=Z[0]^S4[x[ 0]]^S5[x[ 2]]^S6[x[ 1]]^S7[x[ 3]]^S7[z[ 2]];\n\tCAST_exp(l,X,x, 4);\n\tl=Z[1]^S4[x[ 7]]^S5[x[ 6]]^S6[x[ 5]]^S7[x[ 4]]^S4[z[ 1]];\n\tCAST_exp(l,X,x, 8);\n\tl=Z[3]^S4[x[10]]^S5[x[ 9]]^S6[x[11]]^S7[x[ 8]]^S5[z[ 3]];\n\tCAST_exp(l,X,x,12);\n\tK[12]= S4[x[ 8]]^S5[x[ 9]]^S6[x[ 7]]^S7[x[ 6]]^S4[x[ 3]];\n\tK[13]= S4[x[10]]^S5[x[11]]^S6[x[ 5]]^S7[x[ 4]]^S5[x[ 7]];\n\tK[14]= S4[x[12]]^S5[x[13]]^S6[x[ 3]]^S7[x[ 2]]^S6[x[ 8]];\n\tK[15]= S4[x[14]]^S5[x[15]]^S6[x[ 1]]^S7[x[ 0]]^S7[x[13]];\n\tif (K != k) break;\n\tK+=16;\n\t\t}\n\tfor (i=0; i<16; i++)\n\t\t{\n\t\tkey->data[i*2]=k[i];\n\t\tkey->data[i*2+1]=((k[i+16])+16)&0x1f;\n\t\t}\n\t}']
34,941
0
https://github.com/openssl/openssl/blob/c1e744b9125a883450c2239ec55ea606c618a5c0/apps/x509.c/#L788
static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, X509 *x, X509 *xca, EVP_PKEY *pkey, char *serialfile, int create, int days, LHASH *conf, char *section) { int ret=0; BIO *io=NULL; MS_STATIC char buf2[1024]; char *buf=NULL,*p; BIGNUM *serial=NULL; ASN1_INTEGER *bs=NULL,bs2; X509_STORE_CTX xsc; EVP_PKEY *upkey; upkey = X509_get_pubkey(xca); EVP_PKEY_copy_parameters(upkey,pkey); EVP_PKEY_free(upkey); X509_STORE_CTX_init(&xsc,ctx,x,NULL); buf=(char *)Malloc(EVP_PKEY_size(pkey)*2+ ((serialfile == NULL) ?(strlen(CAfile)+strlen(POSTFIX)+1) :(strlen(serialfile)))+1); if (buf == NULL) { BIO_printf(bio_err,"out of mem\n"); goto end; } if (serialfile == NULL) { strcpy(buf,CAfile); for (p=buf; *p; p++) if (*p == '.') { *p='\0'; break; } strcat(buf,POSTFIX); } else strcpy(buf,serialfile); serial=BN_new(); bs=ASN1_INTEGER_new(); if ((serial == NULL) || (bs == NULL)) { ERR_print_errors(bio_err); goto end; } io=BIO_new(BIO_s_file()); if (io == NULL) { ERR_print_errors(bio_err); goto end; } if (BIO_read_filename(io,buf) <= 0) { if (!create) { perror(buf); goto end; } else { ASN1_INTEGER_set(bs,0); BN_zero(serial); } } else { if (!a2i_ASN1_INTEGER(io,bs,buf2,1024)) { BIO_printf(bio_err,"unable to load serial number from %s\n",buf); ERR_print_errors(bio_err); goto end; } else { serial=BN_bin2bn(bs->data,bs->length,serial); if (serial == NULL) { BIO_printf(bio_err,"error converting bin 2 bn"); goto end; } } } if (!BN_add_word(serial,1)) { BIO_printf(bio_err,"add_word failure\n"); goto end; } bs2.data=(unsigned char *)buf2; bs2.length=BN_bn2bin(serial,bs2.data); if (BIO_write_filename(io,buf) <= 0) { BIO_printf(bio_err,"error attempting to write serial number file\n"); perror(buf); goto end; } i2a_ASN1_INTEGER(io,&bs2); BIO_puts(io,"\n"); BIO_free(io); io=NULL; if (!X509_STORE_add_cert(ctx,x)) goto end; X509_STORE_CTX_set_cert(&xsc,x); if (!reqfile && !X509_verify_cert(&xsc)) goto end; if (!X509_check_private_key(xca,pkey)) { BIO_printf(bio_err,"CA certificate and CA private key do not match\n"); goto end; } if (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end; if (!X509_set_serialNumber(x,bs)) goto end; if (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL) goto end; if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL) goto end; if(conf) { X509V3_CTX ctx2; X509_set_version(x,2); X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0); X509V3_set_conf_lhash(&ctx2, conf); if(!X509V3_EXT_add_conf(conf, &ctx2, section, x)) goto end; } if (!X509_sign(x,pkey,digest)) goto end; ret=1; end: X509_STORE_CTX_cleanup(&xsc); if (!ret) ERR_print_errors(bio_err); if (buf != NULL) Free(buf); if (bs != NULL) ASN1_INTEGER_free(bs); if (io != NULL) BIO_free(io); if (serial != NULL) BN_free(serial); return(ret); }
['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, LHASH *conf, char *section)\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\tif(conf) {\n\t\tX509V3_CTX ctx2;\n\t\tX509_set_version(x,2);\n X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n X509V3_set_conf_lhash(&ctx2, conf);\n if(!X509V3_EXT_add_conf(conf, &ctx2, section, x)) goto end;\n\t}\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}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}']
34,942
0
https://github.com/openssl/openssl/blob/b2b4dfcca6cf2230107a711f7af1cd8ee3f74229/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 }
['void CONF_modules_finish(void)\n{\n CONF_IMODULE *imod;\n while (sk_CONF_IMODULE_num(initialized_modules) > 0) {\n imod = sk_CONF_IMODULE_pop(initialized_modules);\n module_finish(imod);\n }\n sk_CONF_IMODULE_free(initialized_modules);\n initialized_modules = NULL;\n}', 'static void module_finish(CONF_IMODULE *imod)\n{\n if (!imod)\n return;\n if (imod->pmod->finish)\n imod->pmod->finish(imod);\n imod->pmod->links--;\n OPENSSL_free(imod->name);\n OPENSSL_free(imod->value);\n OPENSSL_free(imod);\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}']
34,943
0
https://github.com/openssl/openssl/blob/3ad4af89cf7380aa94d1995e05e713d59e1c469a/crypto/err/err.c/#L877
int ERR_pop_to_mark(void) { ERR_STATE *es; es = ERR_get_state(); while (es->bottom != es->top && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) { err_clear(es, es->top); es->top -= 1; if (es->top == -1) es->top = ERR_NUM_ERRORS - 1; } if (es->bottom == es->top) return 0; es->err_flags[es->top] &= ~ERR_FLAG_MARK; return 1; }
['int ERR_pop_to_mark(void)\n{\n ERR_STATE *es;\n es = ERR_get_state();\n while (es->bottom != es->top\n && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) {\n err_clear(es, es->top);\n es->top -= 1;\n if (es->top == -1)\n es->top = ERR_NUM_ERRORS - 1;\n }\n if (es->bottom == es->top)\n return 0;\n es->err_flags[es->top] &= ~ERR_FLAG_MARK;\n return 1;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n CRYPTO_THREAD_run_once(&err_init, err_do_init);\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
34,944
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/test/ssltest.c/#L472
static int verify_alpn(SSL *client, SSL *server) { const unsigned char *client_proto, *server_proto; unsigned int client_proto_len = 0, server_proto_len = 0; SSL_get0_alpn_selected(client, &client_proto, &client_proto_len); SSL_get0_alpn_selected(server, &server_proto, &server_proto_len); OPENSSL_free(alpn_selected); alpn_selected = NULL; if (client_proto_len != server_proto_len || memcmp(client_proto, server_proto, client_proto_len) != 0) { BIO_printf(bio_stdout, "ALPN selected protocols differ!\n"); goto err; } if (client_proto_len > 0 && alpn_expected == NULL) { BIO_printf(bio_stdout, "ALPN unexpectedly negotiated\n"); goto err; } if (alpn_expected != NULL && (client_proto_len != strlen(alpn_expected) || memcmp(client_proto, alpn_expected, client_proto_len) != 0)) { BIO_printf(bio_stdout, "ALPN selected protocols not equal to expected protocol: %s\n", alpn_expected); goto err; } return 0; err: BIO_printf(bio_stdout, "ALPN results: client: '"); BIO_write(bio_stdout, client_proto, client_proto_len); BIO_printf(bio_stdout, "', server: '"); BIO_write(bio_stdout, server_proto, server_proto_len); BIO_printf(bio_stdout, "'\n"); BIO_printf(bio_stdout, "ALPN configured: client: '%s', server: '%s'\n", alpn_client, alpn_server); return -1; }
['static int verify_alpn(SSL *client, SSL *server)\n{\n const unsigned char *client_proto, *server_proto;\n unsigned int client_proto_len = 0, server_proto_len = 0;\n SSL_get0_alpn_selected(client, &client_proto, &client_proto_len);\n SSL_get0_alpn_selected(server, &server_proto, &server_proto_len);\n OPENSSL_free(alpn_selected);\n alpn_selected = NULL;\n if (client_proto_len != server_proto_len ||\n memcmp(client_proto, server_proto, client_proto_len) != 0) {\n BIO_printf(bio_stdout, "ALPN selected protocols differ!\\n");\n goto err;\n }\n if (client_proto_len > 0 && alpn_expected == NULL) {\n BIO_printf(bio_stdout, "ALPN unexpectedly negotiated\\n");\n goto err;\n }\n if (alpn_expected != NULL &&\n (client_proto_len != strlen(alpn_expected) ||\n memcmp(client_proto, alpn_expected, client_proto_len) != 0)) {\n BIO_printf(bio_stdout,\n "ALPN selected protocols not equal to expected protocol: %s\\n",\n alpn_expected);\n goto err;\n }\n return 0;\n err:\n BIO_printf(bio_stdout, "ALPN results: client: \'");\n BIO_write(bio_stdout, client_proto, client_proto_len);\n BIO_printf(bio_stdout, "\', server: \'");\n BIO_write(bio_stdout, server_proto, server_proto_len);\n BIO_printf(bio_stdout, "\'\\n");\n BIO_printf(bio_stdout, "ALPN configured: client: \'%s\', server: \'%s\'\\n",\n alpn_client, alpn_server);\n return -1;\n}', 'void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,\n unsigned *len)\n{\n *data = NULL;\n if (ssl->s3)\n *data = ssl->s3->alpn_selected;\n if (*data == NULL)\n *len = 0;\n else\n *len = ssl->s3->alpn_selected_len;\n}', 'void CRYPTO_free(void *str)\n{\n if (free_debug_func != NULL)\n free_debug_func(str, 0);\n#ifdef LEVITTE_DEBUG_MEM\n fprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\\n", str);\n#endif\n free_func(str);\n if (free_debug_func != NULL)\n free_debug_func(NULL, 1);\n}']
34,945
0
https://github.com/libav/libav/blob/a893655bdaa726a82424367b6456d195be12ebbc/libavformat/oggparsespeex.c/#L71
static int speex_header(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; struct speex_params *spxp = os->private; AVStream *st = s->streams[idx]; uint8_t *p = os->buf + os->pstart; if (!spxp) { spxp = av_mallocz(sizeof(*spxp)); os->private = spxp; } if (spxp->seq > 1) return 0; if (spxp->seq == 0) { int frames_per_packet; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = AV_CODEC_ID_SPEEX; st->codec->sample_rate = AV_RL32(p + 36); st->codec->channels = AV_RL32(p + 48); spxp->packet_size = AV_RL32(p + 56); frames_per_packet = AV_RL32(p + 64); if (frames_per_packet) spxp->packet_size *= frames_per_packet; st->codec->extradata_size = os->psize; st->codec->extradata = av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(st->codec->extradata, p, st->codec->extradata_size); avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); } else ff_vorbis_comment(s, &st->metadata, p, os->psize); spxp->seq++; return 1; }
['static int speex_header(AVFormatContext *s, int idx) {\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n struct speex_params *spxp = os->private;\n AVStream *st = s->streams[idx];\n uint8_t *p = os->buf + os->pstart;\n if (!spxp) {\n spxp = av_mallocz(sizeof(*spxp));\n os->private = spxp;\n }\n if (spxp->seq > 1)\n return 0;\n if (spxp->seq == 0) {\n int frames_per_packet;\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codec->codec_id = AV_CODEC_ID_SPEEX;\n st->codec->sample_rate = AV_RL32(p + 36);\n st->codec->channels = AV_RL32(p + 48);\n spxp->packet_size = AV_RL32(p + 56);\n frames_per_packet = AV_RL32(p + 64);\n if (frames_per_packet)\n spxp->packet_size *= frames_per_packet;\n st->codec->extradata_size = os->psize;\n st->codec->extradata = av_malloc(st->codec->extradata_size\n + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(st->codec->extradata, p, st->codec->extradata_size);\n avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);\n } else\n ff_vorbis_comment(s, &st->metadata, p, os->psize);\n spxp->seq++;\n return 1;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if (size > (INT_MAX - 32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size + 32);\n if (!ptr)\n return ptr;\n diff = ((-(long)ptr - 1) & 31) + 1;\n ptr = (char *)ptr + diff;\n ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr, 32, size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32, size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
34,946
0
https://github.com/openssl/openssl/blob/313fce7b61ecaf5879cf84b256bdd0964134836e/crypto/bn/bn_ctx.c/#L440
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while(num--) { bn_check_top(p->current->vals + offset); if(!offset) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p,\n\tconst BIGNUM *q, BN_CTX *ctx)\n{\n\tBIGNUM *ret = NULL, *r0, *r1, *r2;\n\tif (d == NULL || p == NULL || q == NULL)\n\t\treturn NULL;\n\tBN_CTX_start(ctx);\n\tr0 = BN_CTX_get(ctx);\n\tr1 = BN_CTX_get(ctx);\n\tr2 = BN_CTX_get(ctx);\n\tif (r2 == NULL)\n\t\tgoto err;\n\tif (!BN_sub(r1, p, BN_value_one())) goto err;\n\tif (!BN_sub(r2, q, BN_value_one())) goto err;\n\tif (!BN_mul(r0, r1, r2, ctx)) goto err;\n\tret = BN_mod_inverse(NULL, d, r0, ctx);\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', '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,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n\t{\n\tBIGNUM *ret;\n\tCTXDBG_ENTRY("BN_CTX_get", ctx);\n\tif(ctx->err_stack || ctx->too_many) return NULL;\n\tif((ret = BN_POOL_get(&ctx->pool)) == NULL)\n\t\t{\n\t\tctx->too_many = 1;\n\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\treturn NULL;\n\t\t}\n\tBN_zero(ret);\n\tctx->used++;\n\tCTXDBG_RET(ctx, ret);\n\treturn ret;\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n\t{\n\tunsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n\tp->used -= num;\n\twhile(num--)\n\t\t{\n\t\tbn_check_top(p->current->vals + offset);\n\t\tif(!offset)\n\t\t\t{\n\t\t\toffset = BN_CTX_POOL_SIZE - 1;\n\t\t\tp->current = p->current->prev;\n\t\t\t}\n\t\telse\n\t\t\toffset--;\n\t\t}\n\t}']
34,947
0
https://github.com/libav/libav/blob/18b59956e0e94017f1b519bb42c7c937b2f9f8a4/libavcodec/wmaenc.c/#L61
static int encode_init(AVCodecContext * avctx){ WMACodecContext *s = avctx->priv_data; int i, flags1, flags2; uint8_t *extradata; s->avctx = avctx; if(avctx->channels > MAX_CHANNELS) { av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer", avctx->channels, MAX_CHANNELS); return AVERROR(EINVAL); } if (avctx->sample_rate > 48000) { av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz", avctx->sample_rate); return AVERROR(EINVAL); } if(avctx->bit_rate < 24*1000) { av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\n", avctx->bit_rate); return AVERROR(EINVAL); } flags1 = 0; flags2 = 1; if (avctx->codec->id == CODEC_ID_WMAV1) { extradata= av_malloc(4); avctx->extradata_size= 4; AV_WL16(extradata, flags1); AV_WL16(extradata+2, flags2); } else if (avctx->codec->id == CODEC_ID_WMAV2) { extradata= av_mallocz(10); avctx->extradata_size= 10; AV_WL32(extradata, flags1); AV_WL16(extradata+4, flags2); }else assert(0); avctx->extradata= extradata; s->use_exp_vlc = flags2 & 0x0001; s->use_bit_reservoir = flags2 & 0x0002; s->use_variable_block_len = flags2 & 0x0004; if (avctx->channels == 2) s->ms_stereo = 1; ff_wma_init(avctx, flags2); for(i = 0; i < s->nb_block_sizes; i++) ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0); s->block_align = avctx->bit_rate * (int64_t)s->frame_len / (avctx->sample_rate * 8); s->block_align = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE); avctx->block_align = s->block_align; avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate / s->frame_len; avctx->frame_size = avctx->delay = s->frame_len; #if FF_API_OLD_ENCODE_AUDIO avctx->coded_frame = &s->frame; avcodec_get_frame_defaults(avctx->coded_frame); #endif return 0; }
['static int encode_init(AVCodecContext * avctx){\n WMACodecContext *s = avctx->priv_data;\n int i, flags1, flags2;\n uint8_t *extradata;\n s->avctx = avctx;\n if(avctx->channels > MAX_CHANNELS) {\n av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer",\n avctx->channels, MAX_CHANNELS);\n return AVERROR(EINVAL);\n }\n if (avctx->sample_rate > 48000) {\n av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz",\n avctx->sample_rate);\n return AVERROR(EINVAL);\n }\n if(avctx->bit_rate < 24*1000) {\n av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\\n",\n avctx->bit_rate);\n return AVERROR(EINVAL);\n }\n flags1 = 0;\n flags2 = 1;\n if (avctx->codec->id == CODEC_ID_WMAV1) {\n extradata= av_malloc(4);\n avctx->extradata_size= 4;\n AV_WL16(extradata, flags1);\n AV_WL16(extradata+2, flags2);\n } else if (avctx->codec->id == CODEC_ID_WMAV2) {\n extradata= av_mallocz(10);\n avctx->extradata_size= 10;\n AV_WL32(extradata, flags1);\n AV_WL16(extradata+4, flags2);\n }else\n assert(0);\n avctx->extradata= extradata;\n s->use_exp_vlc = flags2 & 0x0001;\n s->use_bit_reservoir = flags2 & 0x0002;\n s->use_variable_block_len = flags2 & 0x0004;\n if (avctx->channels == 2)\n s->ms_stereo = 1;\n ff_wma_init(avctx, flags2);\n for(i = 0; i < s->nb_block_sizes; i++)\n ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0);\n s->block_align = avctx->bit_rate * (int64_t)s->frame_len /\n (avctx->sample_rate * 8);\n s->block_align = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE);\n avctx->block_align = s->block_align;\n avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate /\n s->frame_len;\n avctx->frame_size = avctx->delay = s->frame_len;\n#if FF_API_OLD_ENCODE_AUDIO\n avctx->coded_frame = &s->frame;\n avcodec_get_frame_defaults(avctx->coded_frame);\n#endif\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}']
34,948
0
https://github.com/openssl/openssl/blob/49cd47eaababc8c57871b929080fc1357e2ad7b8/crypto/rand/rand_lib.c/#L849
int RAND_status(void) { const RAND_METHOD *meth = RAND_get_rand_method(); if (meth->status != NULL) return meth->status(); return 0; }
['int RAND_status(void)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth->status != NULL)\n return meth->status();\n return 0;\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}']
34,949
0
https://github.com/openssl/openssl/blob/3d81ec5b92e1141762eb72caf2aeb9b2cd019a78/crypto/constant_time_locl.h/#L154
static inline unsigned int constant_time_ge(unsigned int a, unsigned int b) { unsigned int ge; ge = ~((a ^ b) | (a - b)); ge |= a & ~b; return constant_time_msb(ge); }
['int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,\n\t const unsigned char *from, int flen, int num)\n\t{\n\tint i;\n\tunsigned char *em = NULL;\n\tunsigned int good, found_zero_byte;\n\tint zero_index = 0, msg_index, mlen = -1;\n if (tlen < 0 || flen < 0)\n\t\treturn -1;\n\tif (flen > num)\n\t\tgoto err;\n\tif (num < 11)\n\t\tgoto err;\n\tem = OPENSSL_malloc(num);\n\tif (em == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, ERR_R_MALLOC_FAILURE);\n\t\treturn -1;\n\t\t}\n\tmemset(em, 0, num);\n\tmemcpy(em + num - flen, from, flen);\n\tgood = constant_time_is_zero(em[0]);\n\tgood &= constant_time_eq(em[1], 2);\n\tfound_zero_byte = 0;\n\tfor (i = 2; i < num; i++)\n\t\t{\n\t\tunsigned int equals0 = constant_time_is_zero(em[i]);\n\t\tzero_index = constant_time_select_int(~found_zero_byte & equals0, i, zero_index);\n\t\tfound_zero_byte |= equals0;\n\t\t}\n\tgood &= constant_time_ge((unsigned int)(zero_index), 2 + 8);\n\tmsg_index = zero_index + 1;\n\tmlen = num - msg_index;\n\tgood &= constant_time_ge((unsigned int)(tlen), (unsigned int)(mlen));\n\tif (!good)\n\t\t{\n\t\tmlen = -1;\n\t\tgoto err;\n\t\t}\n\tmemcpy(to, em + msg_index, mlen);\nerr:\n\tif (em != NULL)\n\t\tOPENSSL_free(em);\n\tif (mlen == -1)\n\t\tRSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, RSA_R_PKCS_DECODING_ERROR);\n\treturn mlen;\n\t}', 'static inline unsigned int constant_time_ge(unsigned int a, unsigned int b)\n\t{\n\tunsigned int ge;\n\tge = ~((a ^ b) | (a - b));\n\tge |= a & ~b;\n\treturn constant_time_msb(ge);\n\t}']
34,950
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/x509/x509_vfy.c/#L637
static int check_chain_extensions(X509_STORE_CTX *ctx) { int i, ok = 0, must_be_ca, plen = 0; X509 *x; int (*cb) (int xok, X509_STORE_CTX *xctx); int proxy_path_length = 0; int purpose; int allow_proxy_certs; cb = ctx->verify_cb; must_be_ca = -1; if (ctx->parent) { allow_proxy_certs = 0; purpose = X509_PURPOSE_CRL_SIGN; } else { allow_proxy_certs = ! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS); if (getenv("OPENSSL_ALLOW_PROXY_CERTS")) allow_proxy_certs = 1; purpose = ctx->param->purpose; } for (i = 0; i < ctx->last_untrusted; i++) { int ret; x = sk_X509_value(ctx->chain, i); if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && (x->ex_flags & EXFLAG_CRITICAL)) { ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION; ctx->error_depth = i; ctx->current_cert = x; ok = cb(0, ctx); if (!ok) goto end; } if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) { ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED; ctx->error_depth = i; ctx->current_cert = x; ok = cb(0, ctx); if (!ok) goto end; } ret = X509_check_ca(x); switch (must_be_ca) { case -1: if ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && (ret != 1) && (ret != 0)) { ret = 0; ctx->error = X509_V_ERR_INVALID_CA; } else ret = 1; break; case 0: if (ret != 0) { ret = 0; ctx->error = X509_V_ERR_INVALID_NON_CA; } else ret = 1; break; default: if ((ret == 0) || ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && (ret != 1))) { ret = 0; ctx->error = X509_V_ERR_INVALID_CA; } else ret = 1; break; } if (ret == 0) { ctx->error_depth = i; ctx->current_cert = x; ok = cb(0, ctx); if (!ok) goto end; } if (ctx->param->purpose > 0) { ret = X509_check_purpose(x, purpose, must_be_ca > 0); if ((ret == 0) || ((ctx->param->flags & X509_V_FLAG_X509_STRICT) && (ret != 1))) { ctx->error = X509_V_ERR_INVALID_PURPOSE; ctx->error_depth = i; ctx->current_cert = x; ok = cb(0, ctx); if (!ok) goto end; } } if ((i > 1) && !(x->ex_flags & EXFLAG_SI) && (x->ex_pathlen != -1) && (plen > (x->ex_pathlen + proxy_path_length + 1))) { ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED; ctx->error_depth = i; ctx->current_cert = x; ok = cb(0, ctx); if (!ok) goto end; } if (!(x->ex_flags & EXFLAG_SI)) plen++; if (x->ex_flags & EXFLAG_PROXY) { if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) { ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED; ctx->error_depth = i; ctx->current_cert = x; ok = cb(0, ctx); if (!ok) goto end; } proxy_path_length++; must_be_ca = 0; } else must_be_ca = 1; } ok = 1; end: return ok; }
['static int check_chain_extensions(X509_STORE_CTX *ctx)\n{\n int i, ok = 0, must_be_ca, plen = 0;\n X509 *x;\n int (*cb) (int xok, X509_STORE_CTX *xctx);\n int proxy_path_length = 0;\n int purpose;\n int allow_proxy_certs;\n cb = ctx->verify_cb;\n must_be_ca = -1;\n if (ctx->parent) {\n allow_proxy_certs = 0;\n purpose = X509_PURPOSE_CRL_SIGN;\n } else {\n allow_proxy_certs =\n ! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);\n if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))\n allow_proxy_certs = 1;\n purpose = ctx->param->purpose;\n }\n for (i = 0; i < ctx->last_untrusted; i++) {\n int ret;\n x = sk_X509_value(ctx->chain, i);\n if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)\n && (x->ex_flags & EXFLAG_CRITICAL)) {\n ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) {\n ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n ret = X509_check_ca(x);\n switch (must_be_ca) {\n case -1:\n if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1) && (ret != 0)) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_CA;\n } else\n ret = 1;\n break;\n case 0:\n if (ret != 0) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_NON_CA;\n } else\n ret = 1;\n break;\n default:\n if ((ret == 0)\n || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1))) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_CA;\n } else\n ret = 1;\n break;\n }\n if (ret == 0) {\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (ctx->param->purpose > 0) {\n ret = X509_check_purpose(x, purpose, must_be_ca > 0);\n if ((ret == 0)\n || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1))) {\n ctx->error = X509_V_ERR_INVALID_PURPOSE;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n }\n if ((i > 1) && !(x->ex_flags & EXFLAG_SI)\n && (x->ex_pathlen != -1)\n && (plen > (x->ex_pathlen + proxy_path_length + 1))) {\n ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (!(x->ex_flags & EXFLAG_SI))\n plen++;\n if (x->ex_flags & EXFLAG_PROXY) {\n if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) {\n ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n proxy_path_length++;\n must_be_ca = 0;\n } else\n must_be_ca = 1;\n }\n ok = 1;\n end:\n return ok;\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}', 'int X509_check_ca(X509 *x)\n{\n if (!(x->ex_flags & EXFLAG_SET)) {\n CRYPTO_w_lock(CRYPTO_LOCK_X509);\n x509v3_cache_extensions(x);\n CRYPTO_w_unlock(CRYPTO_LOCK_X509);\n }\n return check_ca(x);\n}']
34,951
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/error_resilience.c/#L397
static void guess_mv(MpegEncContext *s){ uint8_t fixed[s->mb_stride * s->mb_height]; #define MV_FROZEN 3 #define MV_CHANGED 2 #define MV_UNCHANGED 1 const int mb_stride = s->mb_stride; const int mb_width = s->mb_width; const int mb_height= s->mb_height; int i, depth, num_avail; int mb_x, mb_y; num_avail=0; for(i=0; i<s->mb_num; i++){ const int mb_xy= s->mb_index2xy[ i ]; int f=0; int error= s->error_status_table[mb_xy]; if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; if(!(error&MV_ERROR)) f=MV_FROZEN; fixed[mb_xy]= f; if(f==MV_FROZEN) num_avail++; } if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){ for(mb_y=0; mb_y<s->mb_height; mb_y++){ for(mb_x=0; mb_x<s->mb_width; mb_x++){ const int mb_xy= mb_x + mb_y*s->mb_stride; if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue; if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue; s->mv_dir = MV_DIR_FORWARD; s->mb_intra=0; s->mv_type = MV_TYPE_16X16; s->mb_skipped=0; s->dsp.clear_blocks(s->block[0]); s->mb_x= mb_x; s->mb_y= mb_y; s->mv[0][0][0]= 0; s->mv[0][0][1]= 0; decode_mb(s); } } return; } for(depth=0;; depth++){ int changed, pass, none_left; none_left=1; changed=1; for(pass=0; (changed || pass<2) && pass<10; pass++){ int mb_x, mb_y; int score_sum=0; changed=0; for(mb_y=0; mb_y<s->mb_height; mb_y++){ for(mb_x=0; mb_x<s->mb_width; mb_x++){ const int mb_xy= mb_x + mb_y*s->mb_stride; int mv_predictor[8][2]={{0}}; int pred_count=0; int j; int best_score=256*256*256*64; int best_pred=0; const int mot_stride= s->b8_stride; const int mot_index= mb_x*2 + mb_y*2*mot_stride; int prev_x= s->current_picture.motion_val[0][mot_index][0]; int prev_y= s->current_picture.motion_val[0][mot_index][1]; if((mb_x^mb_y^pass)&1) continue; if(fixed[mb_xy]==MV_FROZEN) continue; assert(!IS_INTRA(s->current_picture.mb_type[mb_xy])); assert(s->last_picture_ptr && s->last_picture_ptr->data[0]); j=0; if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1; if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1; if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1; if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1; if(j==0) continue; j=0; if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1; if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1; if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1; if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1; if(j==0 && pass>1) continue; none_left=0; if(mb_x>0 && fixed[mb_xy-1]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1]; pred_count++; } if(mb_x+1<mb_width && fixed[mb_xy+1]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1]; pred_count++; } if(mb_y>0 && fixed[mb_xy-mb_stride]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1]; pred_count++; } if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){ mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1]; pred_count++; } if(pred_count==0) continue; if(pred_count>1){ int sum_x=0, sum_y=0; int max_x, max_y, min_x, min_y; for(j=0; j<pred_count; j++){ sum_x+= mv_predictor[j][0]; sum_y+= mv_predictor[j][1]; } mv_predictor[pred_count][0] = sum_x/j; mv_predictor[pred_count][1] = sum_y/j; if(pred_count>=3){ min_y= min_x= 99999; max_y= max_x=-99999; }else{ min_x=min_y=max_x=max_y=0; } for(j=0; j<pred_count; j++){ max_x= FFMAX(max_x, mv_predictor[j][0]); max_y= FFMAX(max_y, mv_predictor[j][1]); min_x= FFMIN(min_x, mv_predictor[j][0]); min_y= FFMIN(min_y, mv_predictor[j][1]); } mv_predictor[pred_count+1][0] = sum_x - max_x - min_x; mv_predictor[pred_count+1][1] = sum_y - max_y - min_y; if(pred_count==4){ mv_predictor[pred_count+1][0] /= 2; mv_predictor[pred_count+1][1] /= 2; } pred_count+=2; } pred_count++; mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0]; mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1]; pred_count++; s->mv_dir = MV_DIR_FORWARD; s->mb_intra=0; s->mv_type = MV_TYPE_16X16; s->mb_skipped=0; s->dsp.clear_blocks(s->block[0]); s->mb_x= mb_x; s->mb_y= mb_y; for(j=0; j<pred_count; j++){ int score=0; uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0]; s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1]; decode_mb(s); if(mb_x>0 && fixed[mb_xy-1]){ int k; for(k=0; k<16; k++) score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]); } if(mb_x+1<mb_width && fixed[mb_xy+1]){ int k; for(k=0; k<16; k++) score += FFABS(src[k*s->linesize+15]-src[k*s->linesize+16]); } if(mb_y>0 && fixed[mb_xy-mb_stride]){ int k; for(k=0; k<16; k++) score += FFABS(src[k-s->linesize ]-src[k ]); } if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){ int k; for(k=0; k<16; k++) score += FFABS(src[k+s->linesize*15]-src[k+s->linesize*16]); } if(score <= best_score){ best_score= score; best_pred= j; } } score_sum+= best_score; s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0]; s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1]; decode_mb(s); if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){ fixed[mb_xy]=MV_CHANGED; changed++; }else fixed[mb_xy]=MV_UNCHANGED; } } } if(none_left) return; for(i=0; i<s->mb_num; i++){ int mb_xy= s->mb_index2xy[i]; if(fixed[mb_xy]) fixed[mb_xy]=MV_FROZEN; } } }
['static void guess_mv(MpegEncContext *s){\n uint8_t fixed[s->mb_stride * s->mb_height];\n#define MV_FROZEN 3\n#define MV_CHANGED 2\n#define MV_UNCHANGED 1\n const int mb_stride = s->mb_stride;\n const int mb_width = s->mb_width;\n const int mb_height= s->mb_height;\n int i, depth, num_avail;\n int mb_x, mb_y;\n num_avail=0;\n for(i=0; i<s->mb_num; i++){\n const int mb_xy= s->mb_index2xy[ i ];\n int f=0;\n int error= s->error_status_table[mb_xy];\n if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN;\n if(!(error&MV_ERROR)) f=MV_FROZEN;\n fixed[mb_xy]= f;\n if(f==MV_FROZEN)\n num_avail++;\n }\n if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n const int mb_xy= mb_x + mb_y*s->mb_stride;\n if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;\n if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;\n s->mv_dir = MV_DIR_FORWARD;\n s->mb_intra=0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_skipped=0;\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x= mb_x;\n s->mb_y= mb_y;\n s->mv[0][0][0]= 0;\n s->mv[0][0][1]= 0;\n decode_mb(s);\n }\n }\n return;\n }\n for(depth=0;; depth++){\n int changed, pass, none_left;\n none_left=1;\n changed=1;\n for(pass=0; (changed || pass<2) && pass<10; pass++){\n int mb_x, mb_y;\nint score_sum=0;\n changed=0;\n for(mb_y=0; mb_y<s->mb_height; mb_y++){\n for(mb_x=0; mb_x<s->mb_width; mb_x++){\n const int mb_xy= mb_x + mb_y*s->mb_stride;\n int mv_predictor[8][2]={{0}};\n int pred_count=0;\n int j;\n int best_score=256*256*256*64;\n int best_pred=0;\n const int mot_stride= s->b8_stride;\n const int mot_index= mb_x*2 + mb_y*2*mot_stride;\n int prev_x= s->current_picture.motion_val[0][mot_index][0];\n int prev_y= s->current_picture.motion_val[0][mot_index][1];\n if((mb_x^mb_y^pass)&1) continue;\n if(fixed[mb_xy]==MV_FROZEN) continue;\n assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));\n assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);\n j=0;\n if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;\n if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;\n if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;\n if(j==0) continue;\n j=0;\n if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;\n if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;\n if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;\n if(j==0 && pass>1) continue;\n none_left=0;\n if(mb_x>0 && fixed[mb_xy-1]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1];\n pred_count++;\n }\n if(mb_x+1<mb_width && fixed[mb_xy+1]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1];\n pred_count++;\n }\n if(mb_y>0 && fixed[mb_xy-mb_stride]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1];\n pred_count++;\n }\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];\n pred_count++;\n }\n if(pred_count==0) continue;\n if(pred_count>1){\n int sum_x=0, sum_y=0;\n int max_x, max_y, min_x, min_y;\n for(j=0; j<pred_count; j++){\n sum_x+= mv_predictor[j][0];\n sum_y+= mv_predictor[j][1];\n }\n mv_predictor[pred_count][0] = sum_x/j;\n mv_predictor[pred_count][1] = sum_y/j;\n if(pred_count>=3){\n min_y= min_x= 99999;\n max_y= max_x=-99999;\n }else{\n min_x=min_y=max_x=max_y=0;\n }\n for(j=0; j<pred_count; j++){\n max_x= FFMAX(max_x, mv_predictor[j][0]);\n max_y= FFMAX(max_y, mv_predictor[j][1]);\n min_x= FFMIN(min_x, mv_predictor[j][0]);\n min_y= FFMIN(min_y, mv_predictor[j][1]);\n }\n mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;\n mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;\n if(pred_count==4){\n mv_predictor[pred_count+1][0] /= 2;\n mv_predictor[pred_count+1][1] /= 2;\n }\n pred_count+=2;\n }\n pred_count++;\n mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];\n mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];\n pred_count++;\n s->mv_dir = MV_DIR_FORWARD;\n s->mb_intra=0;\n s->mv_type = MV_TYPE_16X16;\n s->mb_skipped=0;\n s->dsp.clear_blocks(s->block[0]);\n s->mb_x= mb_x;\n s->mb_y= mb_y;\n for(j=0; j<pred_count; j++){\n int score=0;\n uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;\n s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];\n s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];\n decode_mb(s);\n if(mb_x>0 && fixed[mb_xy-1]){\n int k;\n for(k=0; k<16; k++)\n score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);\n }\n if(mb_x+1<mb_width && fixed[mb_xy+1]){\n int k;\n for(k=0; k<16; k++)\n score += FFABS(src[k*s->linesize+15]-src[k*s->linesize+16]);\n }\n if(mb_y>0 && fixed[mb_xy-mb_stride]){\n int k;\n for(k=0; k<16; k++)\n score += FFABS(src[k-s->linesize ]-src[k ]);\n }\n if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){\n int k;\n for(k=0; k<16; k++)\n score += FFABS(src[k+s->linesize*15]-src[k+s->linesize*16]);\n }\n if(score <= best_score){\n best_score= score;\n best_pred= j;\n }\n }\nscore_sum+= best_score;\n s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];\n s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];\n decode_mb(s);\n if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){\n fixed[mb_xy]=MV_CHANGED;\n changed++;\n }else\n fixed[mb_xy]=MV_UNCHANGED;\n }\n }\n }\n if(none_left)\n return;\n for(i=0; i<s->mb_num; i++){\n int mb_xy= s->mb_index2xy[i];\n if(fixed[mb_xy])\n fixed[mb_xy]=MV_FROZEN;\n }\n }\n}']
34,952
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,\n const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n BN_CTX *ctx_new = NULL;\n if (!group || !r || !a || !b) {\n ECerr(EC_F_EC_GFP_NIST_FIELD_MUL, ERR_R_PASSED_NULL_PARAMETER);\n goto err;\n }\n if (!ctx)\n if ((ctx_new = ctx = BN_CTX_new()) == NULL)\n goto err;\n if (!BN_mul(r, a, b, ctx))\n goto err;\n if (!group->field_mod_func(r, r, group->field, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_free(ctx_new);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,953
0
https://github.com/libav/libav/blob/4d6d70292e91a7ef027824d731b6b6570ceabf2f/libavcodec/atrac.c/#L140
void ff_atrac_iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp) { int i, j; float *p1, *p3; memcpy(temp, delayBuf, 46*sizeof(float)); p3 = temp + 46; for(i=0; i<nIn; i+=2){ p3[2*i+0] = inlo[i ] + inhi[i ]; p3[2*i+1] = inlo[i ] - inhi[i ]; p3[2*i+2] = inlo[i+1] + inhi[i+1]; p3[2*i+3] = inlo[i+1] - inhi[i+1]; } p1 = temp; for (j = nIn; j != 0; j--) { float s1 = 0.0; float s2 = 0.0; for (i = 0; i < 48; i += 2) { s1 += p1[i] * qmf_window[i]; s2 += p1[i+1] * qmf_window[i+1]; } pOut[0] = s2; pOut[1] = s1; p1 += 2; pOut += 2; } memcpy(delayBuf, temp + nIn*2, 46*sizeof(float)); }
['static void at1_subband_synthesis(AT1Ctx *q, AT1SUCtx* su, float *pOut)\n{\n float temp[256];\n float iqmf_temp[512 + 46];\n ff_atrac_iqmf(q->bands[0], q->bands[1], 128, temp, su->fst_qmf_delay, iqmf_temp);\n memcpy( su->last_qmf_delay, &su->last_qmf_delay[256], sizeof(float) * 23);\n memcpy(&su->last_qmf_delay[23], q->bands[2], sizeof(float) * 256);\n ff_atrac_iqmf(temp, su->last_qmf_delay, 256, pOut, su->snd_qmf_delay, iqmf_temp);\n}', 'void ff_atrac_iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp)\n{\n int i, j;\n float *p1, *p3;\n memcpy(temp, delayBuf, 46*sizeof(float));\n p3 = temp + 46;\n for(i=0; i<nIn; i+=2){\n p3[2*i+0] = inlo[i ] + inhi[i ];\n p3[2*i+1] = inlo[i ] - inhi[i ];\n p3[2*i+2] = inlo[i+1] + inhi[i+1];\n p3[2*i+3] = inlo[i+1] - inhi[i+1];\n }\n p1 = temp;\n for (j = nIn; j != 0; j--) {\n float s1 = 0.0;\n float s2 = 0.0;\n for (i = 0; i < 48; i += 2) {\n s1 += p1[i] * qmf_window[i];\n s2 += p1[i+1] * qmf_window[i+1];\n }\n pOut[0] = s2;\n pOut[1] = s1;\n p1 += 2;\n pOut += 2;\n }\n memcpy(delayBuf, temp + nIn*2, 46*sizeof(float));\n}']
34,954
0
https://github.com/openssl/openssl/blob/3ba25ee86a3758cc659c954b59718d8397030768/crypto/x509/x509_vfy.c/#L811
int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, int purpose, int trust) { int idx; if (!purpose) purpose = def_purpose; if (purpose) { X509_PURPOSE *ptmp; idx = X509_PURPOSE_get_by_id(purpose); if (idx == -1) { X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, X509_R_UNKNOWN_PURPOSE_ID); return 0; } ptmp = X509_PURPOSE_get0(idx); if (ptmp->trust == X509_TRUST_DEFAULT) { idx = X509_PURPOSE_get_by_id(def_purpose); if (idx == -1) { X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, X509_R_UNKNOWN_PURPOSE_ID); return 0; } ptmp = X509_PURPOSE_get0(idx); } if (!trust) trust = ptmp->trust; } if (trust) { idx = X509_TRUST_get_by_id(trust); if (idx == -1) { X509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT, X509_R_UNKNOWN_TRUST_ID); return 0; } } if (purpose) ctx->purpose = purpose; if (trust) ctx->trust = trust; return 1; }
['int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,\n\t\t\t\tint purpose, int trust)\n{\n\tint idx;\n\tif (!purpose) purpose = def_purpose;\n\tif (purpose)\n\t\t{\n\t\tX509_PURPOSE *ptmp;\n\t\tidx = X509_PURPOSE_get_by_id(purpose);\n\t\tif (idx == -1)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,\n\t\t\t\t\t\tX509_R_UNKNOWN_PURPOSE_ID);\n\t\t\treturn 0;\n\t\t\t}\n\t\tptmp = X509_PURPOSE_get0(idx);\n\t\tif (ptmp->trust == X509_TRUST_DEFAULT)\n\t\t\t{\n\t\t\tidx = X509_PURPOSE_get_by_id(def_purpose);\n\t\t\tif (idx == -1)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,\n\t\t\t\t\t\tX509_R_UNKNOWN_PURPOSE_ID);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\tptmp = X509_PURPOSE_get0(idx);\n\t\t\t}\n\t\tif (!trust) trust = ptmp->trust;\n\t\t}\n\tif (trust)\n\t\t{\n\t\tidx = X509_TRUST_get_by_id(trust);\n\t\tif (idx == -1)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_STORE_CTX_PURPOSE_INHERIT,\n\t\t\t\t\t\tX509_R_UNKNOWN_TRUST_ID);\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\tif (purpose) ctx->purpose = purpose;\n\tif (trust) ctx->trust = trust;\n\treturn 1;\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n\tX509_PURPOSE tmp;\n\tint idx;\n\tif((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n\t\treturn purpose - X509_PURPOSE_MIN;\n\ttmp.purpose = purpose;\n\tif(!xptable) return -1;\n\tidx = sk_X509_PURPOSE_find(xptable, &tmp);\n\tif(idx == -1) return -1;\n\treturn idx + X509_PURPOSE_COUNT;\n}', 'X509_PURPOSE * X509_PURPOSE_get0(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_PURPOSE_COUNT) return xstandard + idx;\n\treturn sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']
34,955
0
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/flac.c/#L47
static int64_t get_utf8(BitstreamContext *bc) { int64_t val; GET_UTF8(val, bitstream_read(bc, 8), return -1;) return val; }
['static int64_t get_utf8(BitstreamContext *bc)\n{\n int64_t val;\n GET_UTF8(val, bitstream_read(bc, 8), return -1;)\n return val;\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}']
34,956
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,\n const BIGNUM *v)\n{\n BIGNUM *kv = NULL, *gb = NULL;\n BIGNUM *B = NULL, *k = NULL;\n BN_CTX *bn_ctx;\n if (b == NULL || N == NULL || g == NULL || v == NULL ||\n (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((kv = BN_new()) == NULL ||\n (gb = BN_new()) == NULL || (B = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(gb, g, b, N, bn_ctx)\n || (k = srp_Calc_k(N, g)) == NULL\n || !BN_mod_mul(kv, v, k, N, bn_ctx)\n || !BN_mod_add(B, gb, kv, N, bn_ctx)) {\n BN_free(B);\n B = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(kv);\n BN_clear_free(gb);\n BN_free(k);\n return B;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
34,957
0
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[],\n BN_CTX *ctx)\n{\n int ret = 0, count = 0, j;\n BIGNUM *a, *z, *rho, *w, *w2, *tmp;\n bn_check_top(a_);\n if (!p[0]) {\n BN_zero(r);\n return 1;\n }\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n z = BN_CTX_get(ctx);\n w = BN_CTX_get(ctx);\n if (w == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(a, a_, p))\n goto err;\n if (BN_is_zero(a)) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n if (p[0] & 0x1) {\n if (!BN_copy(z, a))\n goto err;\n for (j = 1; j <= (p[0] - 1) / 2; j++) {\n if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))\n goto err;\n if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))\n goto err;\n if (!BN_GF2m_add(z, z, a))\n goto err;\n }\n } else {\n rho = BN_CTX_get(ctx);\n w2 = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n do {\n if (!BN_priv_rand(rho, p[0], BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto err;\n if (!BN_GF2m_mod_arr(rho, rho, p))\n goto err;\n BN_zero(z);\n if (!BN_copy(w, rho))\n goto err;\n for (j = 1; j <= p[0] - 1; j++) {\n if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))\n goto err;\n if (!BN_GF2m_mod_sqr_arr(w2, w, p, ctx))\n goto err;\n if (!BN_GF2m_mod_mul_arr(tmp, w2, a, p, ctx))\n goto err;\n if (!BN_GF2m_add(z, z, tmp))\n goto err;\n if (!BN_GF2m_add(w, w2, rho))\n goto err;\n }\n count++;\n } while (BN_is_zero(w) && (count < MAX_ITERATIONS));\n if (BN_is_zero(w)) {\n BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR, BN_R_TOO_MANY_ITERATIONS);\n goto err;\n }\n }\n if (!BN_GF2m_mod_sqr_arr(w, z, p, ctx))\n goto err;\n if (!BN_GF2m_add(w, z, w))\n goto err;\n if (BN_GF2m_cmp(w, a)) {\n BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR, BN_R_NO_SOLUTION);\n goto err;\n }\n if (!BN_copy(r, z))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("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_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *s;\n bn_check_top(a);\n BN_CTX_start(ctx);\n if ((s = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!bn_wexpand(s, 2 * a->top))\n goto err;\n for (i = a->top - 1; i >= 0; i--) {\n s->d[2 * i + 1] = SQR1(a->d[i]);\n s->d[2 * i] = SQR0(a->d[i]);\n }\n s->top = 2 * a->top;\n bn_correct_top(s);\n if (!BN_GF2m_mod_arr(r, s, p))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', '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}']
34,958
0
https://github.com/openssl/openssl/blob/e3713c365c2657236439fea00822a43aa396d112/crypto/mem.c/#L303
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 }
['int crl2pkcs7_main(int argc, char **argv)\n{\n BIO *in = NULL, *out = NULL;\n PKCS7 *p7 = NULL;\n PKCS7_SIGNED *p7s = NULL;\n STACK_OF(OPENSSL_STRING) *certflst = NULL;\n STACK_OF(X509) *cert_stack = NULL;\n STACK_OF(X509_CRL) *crl_stack = NULL;\n X509_CRL *crl = NULL;\n char *infile = NULL, *outfile = NULL, *prog, *certfile;\n int i = 0, informat = FORMAT_PEM, outformat = FORMAT_PEM, ret = 1, nocrl =\n 0;\n OPTION_CHOICE o;\n prog = opt_init(argc, argv, crl2pkcs7_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(crl2pkcs7_options);\n ret = 0;\n goto end;\n case OPT_INFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))\n goto opthelp;\n break;\n case OPT_OUTFORM:\n if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n goto opthelp;\n break;\n case OPT_IN:\n infile = opt_arg();\n break;\n case OPT_OUT:\n outfile = opt_arg();\n break;\n case OPT_NOCRL:\n nocrl = 1;\n break;\n case OPT_CERTFILE:\n if ((certflst == NULL)\n && (certflst = sk_OPENSSL_STRING_new_null()) == NULL)\n goto end;\n if (!sk_OPENSSL_STRING_push(certflst, opt_arg()))\n goto end;\n break;\n }\n }\n argc = opt_num_rest();\n if (argc != 0)\n goto opthelp;\n if (!nocrl) {\n in = bio_open_default(infile, \'r\', informat);\n if (in == NULL)\n goto end;\n if (informat == FORMAT_ASN1)\n crl = d2i_X509_CRL_bio(in, NULL);\n else if (informat == FORMAT_PEM)\n crl = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);\n if (crl == NULL) {\n BIO_printf(bio_err, "unable to load CRL\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n if ((p7 = PKCS7_new()) == NULL)\n goto end;\n if ((p7s = PKCS7_SIGNED_new()) == NULL)\n goto end;\n p7->type = OBJ_nid2obj(NID_pkcs7_signed);\n p7->d.sign = p7s;\n p7s->contents->type = OBJ_nid2obj(NID_pkcs7_data);\n if (!ASN1_INTEGER_set(p7s->version, 1))\n goto end;\n if ((crl_stack = sk_X509_CRL_new_null()) == NULL)\n goto end;\n p7s->crl = crl_stack;\n if (crl != NULL) {\n sk_X509_CRL_push(crl_stack, crl);\n crl = NULL;\n }\n if ((cert_stack = sk_X509_new_null()) == NULL)\n goto end;\n p7s->cert = cert_stack;\n if (certflst != NULL)\n for (i = 0; i < sk_OPENSSL_STRING_num(certflst); i++) {\n certfile = sk_OPENSSL_STRING_value(certflst, i);\n if (add_certs_from_file(cert_stack, certfile) < 0) {\n BIO_printf(bio_err, "error loading certificates\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n }\n out = bio_open_default(outfile, \'w\', outformat);\n if (out == NULL)\n goto end;\n if (outformat == FORMAT_ASN1)\n i = i2d_PKCS7_bio(out, p7);\n else if (outformat == FORMAT_PEM)\n i = PEM_write_bio_PKCS7(out, p7);\n if (!i) {\n BIO_printf(bio_err, "unable to write pkcs7 object\\n");\n ERR_print_errors(bio_err);\n goto end;\n }\n ret = 0;\n end:\n sk_OPENSSL_STRING_free(certflst);\n BIO_free(in);\n BIO_free_all(out);\n PKCS7_free(p7);\n X509_CRL_free(crl);\n return (ret);\n}', 'DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n if (st == NULL)\n return -1;\n return OPENSSL_sk_insert(st, data, st->num);\n}', 'int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)\n{\n if (st == NULL || st->num == max_nodes)\n return 0;\n if (!sk_reserve(st, 1, 0))\n return 0;\n if ((loc >= st->num) || (loc < 0)) {\n st->data[st->num] = data;\n } else {\n memmove(&st->data[loc + 1], &st->data[loc],\n sizeof(st->data[0]) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return st->num;\n}', '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 st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc);\n if (st->data == NULL)\n return 0;\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 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); (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}']
34,959
0
https://github.com/openssl/openssl/blob/ba4f1331e3e96a83144adf5f100b8b5f8f29a2c9/ssl/ssl_rsa.c/#L374
int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) { int rv; if (x == NULL) { SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE, ERR_R_PASSED_NULL_PARAMETER); return (0); } rv = ssl_security_cert(NULL, ctx, x, 0, 1); if (rv != 1) { SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE, rv); return 0; } return (ssl_set_cert(ctx->cert, x)); }
['int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)\n{\n int rv;\n if (x == NULL) {\n SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE, ERR_R_PASSED_NULL_PARAMETER);\n return (0);\n }\n rv = ssl_security_cert(NULL, ctx, x, 0, 1);\n if (rv != 1) {\n SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE, rv);\n return 0;\n }\n return (ssl_set_cert(ctx->cert, x));\n}']
34,960
0
https://github.com/libav/libav/blob/5150dd532b142d7032854a362228dd40142a8e94/libavcodec/mpegaudiodec.c/#L716
static void dct32(INTFLOAT *out, const INTFLOAT *tab) { INTFLOAT tmp0, tmp1; INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 , val8 , val9 , val10, val11, val12, val13, val14, val15, val16, val17, val18, val19, val20, val21, val22, val23, val24, val25, val26, val27, val28, val29, val30, val31; BF0( 0, 31, COS0_0 , 1); BF0(15, 16, COS0_15, 5); BF( 0, 15, COS1_0 , 1); BF(16, 31,-COS1_0 , 1); BF0( 7, 24, COS0_7 , 1); BF0( 8, 23, COS0_8 , 1); BF( 7, 8, COS1_7 , 4); BF(23, 24,-COS1_7 , 4); BF( 0, 7, COS2_0 , 1); BF( 8, 15,-COS2_0 , 1); BF(16, 23, COS2_0 , 1); BF(24, 31,-COS2_0 , 1); BF0( 3, 28, COS0_3 , 1); BF0(12, 19, COS0_12, 2); BF( 3, 12, COS1_3 , 1); BF(19, 28,-COS1_3 , 1); BF0( 4, 27, COS0_4 , 1); BF0(11, 20, COS0_11, 2); BF( 4, 11, COS1_4 , 1); BF(20, 27,-COS1_4 , 1); BF( 3, 4, COS2_3 , 3); BF(11, 12,-COS2_3 , 3); BF(19, 20, COS2_3 , 3); BF(27, 28,-COS2_3 , 3); BF( 0, 3, COS3_0 , 1); BF( 4, 7,-COS3_0 , 1); BF( 8, 11, COS3_0 , 1); BF(12, 15,-COS3_0 , 1); BF(16, 19, COS3_0 , 1); BF(20, 23,-COS3_0 , 1); BF(24, 27, COS3_0 , 1); BF(28, 31,-COS3_0 , 1); BF0( 1, 30, COS0_1 , 1); BF0(14, 17, COS0_14, 3); BF( 1, 14, COS1_1 , 1); BF(17, 30,-COS1_1 , 1); BF0( 6, 25, COS0_6 , 1); BF0( 9, 22, COS0_9 , 1); BF( 6, 9, COS1_6 , 2); BF(22, 25,-COS1_6 , 2); BF( 1, 6, COS2_1 , 1); BF( 9, 14,-COS2_1 , 1); BF(17, 22, COS2_1 , 1); BF(25, 30,-COS2_1 , 1); BF0( 2, 29, COS0_2 , 1); BF0(13, 18, COS0_13, 3); BF( 2, 13, COS1_2 , 1); BF(18, 29,-COS1_2 , 1); BF0( 5, 26, COS0_5 , 1); BF0(10, 21, COS0_10, 1); BF( 5, 10, COS1_5 , 2); BF(21, 26,-COS1_5 , 2); BF( 2, 5, COS2_2 , 1); BF(10, 13,-COS2_2 , 1); BF(18, 21, COS2_2 , 1); BF(26, 29,-COS2_2 , 1); BF( 1, 2, COS3_1 , 2); BF( 5, 6,-COS3_1 , 2); BF( 9, 10, COS3_1 , 2); BF(13, 14,-COS3_1 , 2); BF(17, 18, COS3_1 , 2); BF(21, 22,-COS3_1 , 2); BF(25, 26, COS3_1 , 2); BF(29, 30,-COS3_1 , 2); BF1( 0, 1, 2, 3); BF2( 4, 5, 6, 7); BF1( 8, 9, 10, 11); BF2(12, 13, 14, 15); BF1(16, 17, 18, 19); BF2(20, 21, 22, 23); BF1(24, 25, 26, 27); BF2(28, 29, 30, 31); ADD( 8, 12); ADD(12, 10); ADD(10, 14); ADD(14, 9); ADD( 9, 13); ADD(13, 11); ADD(11, 15); out[ 0] = val0; out[16] = val1; out[ 8] = val2; out[24] = val3; out[ 4] = val4; out[20] = val5; out[12] = val6; out[28] = val7; out[ 2] = val8; out[18] = val9; out[10] = val10; out[26] = val11; out[ 6] = val12; out[22] = val13; out[14] = val14; out[30] = val15; ADD(24, 28); ADD(28, 26); ADD(26, 30); ADD(30, 25); ADD(25, 29); ADD(29, 27); ADD(27, 31); out[ 1] = val16 + val24; out[17] = val17 + val25; out[ 9] = val18 + val26; out[25] = val19 + val27; out[ 5] = val20 + val28; out[21] = val21 + val29; out[13] = val22 + val30; out[29] = val23 + val31; out[ 3] = val24 + val20; out[19] = val25 + val21; out[11] = val26 + val22; out[27] = val27 + val23; out[ 7] = val28 + val18; out[23] = val29 + val19; out[15] = val30 + val17; out[31] = val31; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void dct32(INTFLOAT *out, const INTFLOAT *tab)\n{\n INTFLOAT tmp0, tmp1;\n INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,\n val8 , val9 , val10, val11, val12, val13, val14, val15,\n val16, val17, val18, val19, val20, val21, val22, val23,\n val24, val25, val26, val27, val28, val29, val30, val31;\n BF0( 0, 31, COS0_0 , 1);\n BF0(15, 16, COS0_15, 5);\n BF( 0, 15, COS1_0 , 1);\n BF(16, 31,-COS1_0 , 1);\n BF0( 7, 24, COS0_7 , 1);\n BF0( 8, 23, COS0_8 , 1);\n BF( 7, 8, COS1_7 , 4);\n BF(23, 24,-COS1_7 , 4);\n BF( 0, 7, COS2_0 , 1);\n BF( 8, 15,-COS2_0 , 1);\n BF(16, 23, COS2_0 , 1);\n BF(24, 31,-COS2_0 , 1);\n BF0( 3, 28, COS0_3 , 1);\n BF0(12, 19, COS0_12, 2);\n BF( 3, 12, COS1_3 , 1);\n BF(19, 28,-COS1_3 , 1);\n BF0( 4, 27, COS0_4 , 1);\n BF0(11, 20, COS0_11, 2);\n BF( 4, 11, COS1_4 , 1);\n BF(20, 27,-COS1_4 , 1);\n BF( 3, 4, COS2_3 , 3);\n BF(11, 12,-COS2_3 , 3);\n BF(19, 20, COS2_3 , 3);\n BF(27, 28,-COS2_3 , 3);\n BF( 0, 3, COS3_0 , 1);\n BF( 4, 7,-COS3_0 , 1);\n BF( 8, 11, COS3_0 , 1);\n BF(12, 15,-COS3_0 , 1);\n BF(16, 19, COS3_0 , 1);\n BF(20, 23,-COS3_0 , 1);\n BF(24, 27, COS3_0 , 1);\n BF(28, 31,-COS3_0 , 1);\n BF0( 1, 30, COS0_1 , 1);\n BF0(14, 17, COS0_14, 3);\n BF( 1, 14, COS1_1 , 1);\n BF(17, 30,-COS1_1 , 1);\n BF0( 6, 25, COS0_6 , 1);\n BF0( 9, 22, COS0_9 , 1);\n BF( 6, 9, COS1_6 , 2);\n BF(22, 25,-COS1_6 , 2);\n BF( 1, 6, COS2_1 , 1);\n BF( 9, 14,-COS2_1 , 1);\n BF(17, 22, COS2_1 , 1);\n BF(25, 30,-COS2_1 , 1);\n BF0( 2, 29, COS0_2 , 1);\n BF0(13, 18, COS0_13, 3);\n BF( 2, 13, COS1_2 , 1);\n BF(18, 29,-COS1_2 , 1);\n BF0( 5, 26, COS0_5 , 1);\n BF0(10, 21, COS0_10, 1);\n BF( 5, 10, COS1_5 , 2);\n BF(21, 26,-COS1_5 , 2);\n BF( 2, 5, COS2_2 , 1);\n BF(10, 13,-COS2_2 , 1);\n BF(18, 21, COS2_2 , 1);\n BF(26, 29,-COS2_2 , 1);\n BF( 1, 2, COS3_1 , 2);\n BF( 5, 6,-COS3_1 , 2);\n BF( 9, 10, COS3_1 , 2);\n BF(13, 14,-COS3_1 , 2);\n BF(17, 18, COS3_1 , 2);\n BF(21, 22,-COS3_1 , 2);\n BF(25, 26, COS3_1 , 2);\n BF(29, 30,-COS3_1 , 2);\n BF1( 0, 1, 2, 3);\n BF2( 4, 5, 6, 7);\n BF1( 8, 9, 10, 11);\n BF2(12, 13, 14, 15);\n BF1(16, 17, 18, 19);\n BF2(20, 21, 22, 23);\n BF1(24, 25, 26, 27);\n BF2(28, 29, 30, 31);\n ADD( 8, 12);\n ADD(12, 10);\n ADD(10, 14);\n ADD(14, 9);\n ADD( 9, 13);\n ADD(13, 11);\n ADD(11, 15);\n out[ 0] = val0;\n out[16] = val1;\n out[ 8] = val2;\n out[24] = val3;\n out[ 4] = val4;\n out[20] = val5;\n out[12] = val6;\n out[28] = val7;\n out[ 2] = val8;\n out[18] = val9;\n out[10] = val10;\n out[26] = val11;\n out[ 6] = val12;\n out[22] = val13;\n out[14] = val14;\n out[30] = val15;\n ADD(24, 28);\n ADD(28, 26);\n ADD(26, 30);\n ADD(30, 25);\n ADD(25, 29);\n ADD(29, 27);\n ADD(27, 31);\n out[ 1] = val16 + val24;\n out[17] = val17 + val25;\n out[ 9] = val18 + val26;\n out[25] = val19 + val27;\n out[ 5] = val20 + val28;\n out[21] = val21 + val29;\n out[13] = val22 + val30;\n out[29] = val23 + val31;\n out[ 3] = val24 + val20;\n out[19] = val25 + val21;\n out[11] = val26 + val22;\n out[27] = val27 + val23;\n out[ 7] = val28 + val18;\n out[23] = val29 + val19;\n out[15] = val30 + val17;\n out[31] = val31;\n}']
34,961
0
https://github.com/openssl/openssl/blob/7d3932e8cf736ae9f81bc23662801ae79dbd45b5/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point,\n\tBIGNUM *x, BIGNUM *y, BN_CTX *ctx)\n\t{\n\tBN_CTX *new_ctx = NULL;\n\tBIGNUM *Z, *Z_1, *Z_2, *Z_3;\n\tconst BIGNUM *Z_;\n\tint ret = 0;\n\tif (EC_POINT_is_at_infinity(group, point))\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY);\n\t\treturn 0;\n\t\t}\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\treturn 0;\n\t\t}\n\tBN_CTX_start(ctx);\n\tZ = BN_CTX_get(ctx);\n\tZ_1 = BN_CTX_get(ctx);\n\tZ_2 = BN_CTX_get(ctx);\n\tZ_3 = BN_CTX_get(ctx);\n\tif (Z_3 == NULL) goto err;\n\tif (group->meth->field_decode)\n\t\t{\n\t\tif (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;\n\t\tZ_ = Z;\n\t\t}\n\telse\n\t\t{\n\t\tZ_ = &point->Z;\n\t\t}\n\tif (BN_is_one(Z_))\n\t\t{\n\t\tif (group->meth->field_decode)\n\t\t\t{\n\t\t\tif (x != NULL)\n\t\t\t\t{\n\t\t\t\tif (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;\n\t\t\t\t}\n\t\t\tif (y != NULL)\n\t\t\t\t{\n\t\t\t\tif (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (x != NULL)\n\t\t\t\t{\n\t\t\t\tif (!BN_copy(x, &point->X)) goto err;\n\t\t\t\t}\n\t\t\tif (y != NULL)\n\t\t\t\t{\n\t\t\t\tif (!BN_copy(y, &point->Y)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (group->meth->field_encode == 0)\n\t\t\t{\n\t\t\tif (!group->meth->field_sqr(group, Z_2, Z_1, ctx)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_mod_sqr(Z_2, Z_1, &group->field, ctx)) goto err;\n\t\t\t}\n\t\tif (x != NULL)\n\t\t\t{\n\t\t\tif (!group->meth->field_mul(group, x, &point->X, Z_2, ctx)) goto err;\n\t\t\t}\n\t\tif (y != NULL)\n\t\t\t{\n\t\t\tif (group->meth->field_encode == 0)\n\t\t\t\t{\n\t\t\t\tif (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;\n\t\t\t\t}\n\t\t\tif (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx)) goto err;\n\t\t\t}\n\t\t}\n\tret = 1;\n err:\n\tBN_CTX_end(ctx);\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tif (ret)\n\t\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_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 (dv)\n\t\tbn_check_top(dv);\n\tif (rm)\n\t\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\tif (rm)\n\t\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}']
34,962
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_sqr.c/#L118
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_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(n);\n if (r == NULL && (r = b->Ai) == NULL) {\n BNerr(BN_F_BN_BLINDING_INVERT_EX, BN_R_NOT_INITIALIZED);\n return 0;\n }\n if (b->m_ctx != NULL) {\n if (n->dmax >= r->top) {\n size_t i, rtop = r->top, ntop = n->top;\n BN_ULONG mask;\n for (i = 0; i < rtop; i++) {\n mask = (BN_ULONG)0 - ((i - ntop) >> (8 * sizeof(i) - 1));\n n->d[i] &= mask;\n }\n mask = (BN_ULONG)0 - ((rtop - ntop) >> (8 * sizeof(ntop) - 1));\n n->top = (int)(rtop & ~mask) | (ntop & mask);\n n->flags |= (BN_FLG_FIXED_TOP & ~mask);\n }\n ret = BN_mod_mul_montgomery(n, n, r, b->m_ctx, ctx);\n } else {\n ret = BN_mod_mul(n, n, r, b->mod, ctx);\n }\n bn_check_top(n);\n return ret;\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n int ret = bn_mul_mont_fixed_top(r, a, b, mont, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
34,963
0
https://github.com/openssl/openssl/blob/ad0e439604abf22dcf9e9b7ffd0618c7f3489e02/crypto/pem/pem_all.c/#L267
EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb, void *u) { EVP_PKEY *pktmp; pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u); return pkey_get_eckey(pktmp, key); }
['EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb,\n\t\t\t\t\t\t\tvoid *u)\n{\n\tEVP_PKEY *pktmp;\n\tpktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);\n\treturn pkey_get_eckey(pktmp, key);\n}', 'EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)\n\t{\n\tchar *nm=NULL;\n\tconst unsigned char *p=NULL;\n\tunsigned char *data=NULL;\n\tlong len;\n\tint slen;\n\tEVP_PKEY *ret=NULL;\n\tif (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))\n\t\treturn NULL;\n\tp = data;\n\tif (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {\n\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\tp8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);\n\t\tif(!p8inf) goto p8err;\n\t\tret = EVP_PKCS82PKEY(p8inf);\n\t\tif(x) {\n\t\t\tif(*x) EVP_PKEY_free((EVP_PKEY *)*x);\n\t\t\t*x = ret;\n\t\t}\n\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t} else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {\n\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\tX509_SIG *p8;\n\t\tint klen;\n\t\tchar psbuf[PEM_BUFSIZE];\n\t\tp8 = d2i_X509_SIG(NULL, &p, len);\n\t\tif(!p8) goto p8err;\n\t\tif (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);\n\t\telse klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);\n\t\tif (klen <= 0) {\n\t\t\tPEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,\n\t\t\t\t\tPEM_R_BAD_PASSWORD_READ);\n\t\t\tX509_SIG_free(p8);\n\t\t\tgoto err;\n\t\t}\n\t\tp8inf = PKCS8_decrypt(p8, psbuf, klen);\n\t\tX509_SIG_free(p8);\n\t\tif(!p8inf) goto p8err;\n\t\tret = EVP_PKCS82PKEY(p8inf);\n\t\tif(x) {\n\t\t\tif(*x) EVP_PKEY_free((EVP_PKEY *)*x);\n\t\t\t*x = ret;\n\t\t}\n\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t} else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0)\n\t\t{\n\t\tconst EVP_PKEY_ASN1_METHOD *ameth;\n\t\tameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);\n\t\tif (!ameth || !ameth->old_priv_decode)\n\t\t\tgoto p8err;\n\t\tret=d2i_PrivateKey(ameth->pkey_id,x,&p,len);\n\t\t}\np8err:\n\tif (ret == NULL)\n\t\tPEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB);\nerr:\n\tOPENSSL_free(nm);\n\tOPENSSL_free(data);\n\treturn(ret);\n\t}', 'int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,\n\t pem_password_cb *cb, void *u)\n\t{\n\tEVP_CIPHER_INFO cipher;\n\tchar *nm=NULL,*header=NULL;\n\tunsigned char *data=NULL;\n\tlong len;\n\tint ret = 0;\n\tfor (;;)\n\t\t{\n\t\tif (!PEM_read_bio(bp,&nm,&header,&data,&len)) {\n\t\t\tif(ERR_GET_REASON(ERR_peek_error()) ==\n\t\t\t\tPEM_R_NO_START_LINE)\n\t\t\t\tERR_add_error_data(2, "Expecting: ", name);\n\t\t\treturn 0;\n\t\t}\n\t\tif(check_pem(nm, name)) break;\n\t\tOPENSSL_free(nm);\n\t\tOPENSSL_free(header);\n\t\tOPENSSL_free(data);\n\t\t}\n\tif (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;\n\tif (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;\n\t*pdata = data;\n\t*plen = len;\n\tif (pnm)\n\t\t*pnm = nm;\n\tret = 1;\nerr:\n\tif (!ret || !pnm) OPENSSL_free(nm);\n\tOPENSSL_free(header);\n\tif (!ret) OPENSSL_free(data);\n\treturn ret;\n\t}', 'int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,\n\t long *len)\n\t{\n\tEVP_ENCODE_CTX ctx;\n\tint end=0,i,k,bl=0,hl=0,nohead=0;\n\tchar buf[256];\n\tBUF_MEM *nameB;\n\tBUF_MEM *headerB;\n\tBUF_MEM *dataB,*tmpB;\n\tnameB=BUF_MEM_new();\n\theaderB=BUF_MEM_new();\n\tdataB=BUF_MEM_new();\n\tif ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))\n\t\t{\n\t\tBUF_MEM_free(nameB);\n\t\tBUF_MEM_free(headerB);\n\t\tBUF_MEM_free(dataB);\n\t\tPEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tbuf[254]=\'\\0\';\n\tfor (;;)\n\t\t{\n\t\ti=BIO_gets(bp,buf,254);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);\n\t\t\tgoto err;\n\t\t\t}\n\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\tif (strncmp(buf,"-----BEGIN ",11) == 0)\n\t\t\t{\n\t\t\ti=strlen(&(buf[11]));\n\t\t\tif (strncmp(&(buf[11+i-6]),"-----\\n",6) != 0)\n\t\t\t\tcontinue;\n\t\t\tif (!BUF_MEM_grow(nameB,i+9))\n\t\t\t\t{\n\t\t\t\tPEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tmemcpy(nameB->data,&(buf[11]),i-6);\n\t\t\tnameB->data[i-6]=\'\\0\';\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\thl=0;\n\tif (!BUF_MEM_grow(headerB,256))\n\t\t{ PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }\n\theaderB->data[0]=\'\\0\';\n\tfor (;;)\n\t\t{\n\t\ti=BIO_gets(bp,buf,254);\n\t\tif (i <= 0) break;\n\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\tif (buf[0] == \'\\n\') break;\n\t\tif (!BUF_MEM_grow(headerB,hl+i+9))\n\t\t\t{ PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }\n\t\tif (strncmp(buf,"-----END ",9) == 0)\n\t\t\t{\n\t\t\tnohead=1;\n\t\t\tbreak;\n\t\t\t}\n\t\tmemcpy(&(headerB->data[hl]),buf,i);\n\t\theaderB->data[hl+i]=\'\\0\';\n\t\thl+=i;\n\t\t}\n\tbl=0;\n\tif (!BUF_MEM_grow(dataB,1024))\n\t\t{ PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }\n\tdataB->data[0]=\'\\0\';\n\tif (!nohead)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\ti=BIO_gets(bp,buf,254);\n\t\t\tif (i <= 0) break;\n\t\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\t\tif (i != 65) end=1;\n\t\t\tif (strncmp(buf,"-----END ",9) == 0)\n\t\t\t\tbreak;\n\t\t\tif (i > 65) break;\n\t\t\tif (!BUF_MEM_grow_clean(dataB,i+bl+9))\n\t\t\t\t{\n\t\t\t\tPEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tmemcpy(&(dataB->data[bl]),buf,i);\n\t\t\tdataB->data[bl+i]=\'\\0\';\n\t\t\tbl+=i;\n\t\t\tif (end)\n\t\t\t\t{\n\t\t\t\tbuf[0]=\'\\0\';\n\t\t\t\ti=BIO_gets(bp,buf,254);\n\t\t\t\tif (i <= 0) break;\n\t\t\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\t\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ttmpB=headerB;\n\t\theaderB=dataB;\n\t\tdataB=tmpB;\n\t\tbl=hl;\n\t\t}\n\ti=strlen(nameB->data);\n\tif (\t(strncmp(buf,"-----END ",9) != 0) ||\n\t\t(strncmp(nameB->data,&(buf[9]),i) != 0) ||\n\t\t(strncmp(&(buf[9+i]),"-----\\n",6) != 0))\n\t\t{\n\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);\n\t\tgoto err;\n\t\t}\n\tEVP_DecodeInit(&ctx);\n\ti=EVP_DecodeUpdate(&ctx,\n\t\t(unsigned char *)dataB->data,&bl,\n\t\t(unsigned char *)dataB->data,bl);\n\tif (i < 0)\n\t\t{\n\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);\n\t\tgoto err;\n\t\t}\n\ti=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);\n\tif (i < 0)\n\t\t{\n\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);\n\t\tgoto err;\n\t\t}\n\tbl+=k;\n\tif (bl == 0) goto err;\n\t*name=nameB->data;\n\t*header=headerB->data;\n\t*data=(unsigned char *)dataB->data;\n\t*len=bl;\n\tOPENSSL_free(nameB);\n\tOPENSSL_free(headerB);\n\tOPENSSL_free(dataB);\n\treturn(1);\nerr:\n\tBUF_MEM_free(nameB);\n\tBUF_MEM_free(headerB);\n\tBUF_MEM_free(dataB);\n\treturn(0);\n\t}', 'BUF_MEM *BUF_MEM_new(void)\n\t{\n\tBUF_MEM *ret;\n\tret=OPENSSL_malloc(sizeof(BUF_MEM));\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->max=0;\n\tret->data=NULL;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void BUF_MEM_free(BUF_MEM *a)\n\t{\n\tif(a == NULL)\n\t return;\n\tif (a->data != NULL)\n\t\t{\n\t\tmemset(a->data,0,(unsigned int)a->max);\n\t\tOPENSSL_free(a->data);\n\t\t}\n\tOPENSSL_free(a);\n\t}', 'unsigned long ERR_peek_error(void)\n\t{ return(get_error_values(0,0,NULL,NULL,NULL,NULL)); }']
34,964
0
https://github.com/openssl/openssl/blob/2238119751bb95efc1dfafabf0e70e86f71fc6f6/apps/x509.c/#L1011
static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, X509 *x, X509 *xca, EVP_PKEY *pkey, STACK_OF(OPENSSL_STRING) *sigopts, char *serialfile, int create, int days, int clrext, CONF *conf, char *section, ASN1_INTEGER *sno, int reqfile) { int ret = 0; ASN1_INTEGER *bs = NULL; X509_STORE_CTX *xsc = NULL; EVP_PKEY *upkey; upkey = X509_get0_pubkey(xca); if (upkey == NULL) { BIO_printf(bio_err, "Error obtaining CA X509 public key\n"); goto end; } EVP_PKEY_copy_parameters(upkey, pkey); xsc = X509_STORE_CTX_new(); if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) { BIO_printf(bio_err, "Error initialising X509 store\n"); goto end; } if (sno) bs = sno; else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL) goto end; X509_STORE_CTX_set_cert(xsc, x); X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_CHECK_SS_SIGNATURE); if (!reqfile && X509_verify_cert(xsc) <= 0) goto end; if (!X509_check_private_key(xca, pkey)) { BIO_printf(bio_err, "CA certificate and CA private key do not match\n"); goto end; } if (!X509_set_issuer_name(x, X509_get_subject_name(xca))) goto end; if (!X509_set_serialNumber(x, bs)) goto end; if (X509_gmtime_adj(X509_get_notBefore(x), 0L) == NULL) goto end; if (X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL) == NULL) goto end; if (clrext) { while (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0); } if (conf) { X509V3_CTX ctx2; X509_set_version(x, 2); X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0); X509V3_set_nconf(&ctx2, conf); if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x)) goto end; } if (!do_X509_sign(x, pkey, digest, sigopts)) goto end; ret = 1; end: X509_STORE_CTX_free(xsc); if (!ret) ERR_print_errors(bio_err); if (!sno) ASN1_INTEGER_free(bs); return ret; }
['static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n X509 *x, X509 *xca, EVP_PKEY *pkey,\n STACK_OF(OPENSSL_STRING) *sigopts,\n char *serialfile, int create,\n int days, int clrext, CONF *conf, char *section,\n ASN1_INTEGER *sno, int reqfile)\n{\n int ret = 0;\n ASN1_INTEGER *bs = NULL;\n X509_STORE_CTX *xsc = NULL;\n EVP_PKEY *upkey;\n upkey = X509_get0_pubkey(xca);\n if (upkey == NULL) {\n BIO_printf(bio_err, "Error obtaining CA X509 public key\\n");\n goto end;\n }\n EVP_PKEY_copy_parameters(upkey, pkey);\n xsc = X509_STORE_CTX_new();\n if (xsc == NULL || !X509_STORE_CTX_init(xsc, ctx, x, NULL)) {\n BIO_printf(bio_err, "Error initialising X509 store\\n");\n goto end;\n }\n if (sno)\n bs = sno;\n else if ((bs = x509_load_serial(CAfile, serialfile, create)) == NULL)\n goto end;\n X509_STORE_CTX_set_cert(xsc, x);\n X509_STORE_CTX_set_flags(xsc, X509_V_FLAG_CHECK_SS_SIGNATURE);\n if (!reqfile && X509_verify_cert(xsc) <= 0)\n goto end;\n if (!X509_check_private_key(xca, pkey)) {\n BIO_printf(bio_err,\n "CA certificate and CA private key do not match\\n");\n goto end;\n }\n if (!X509_set_issuer_name(x, X509_get_subject_name(xca)))\n goto end;\n if (!X509_set_serialNumber(x, bs))\n goto end;\n if (X509_gmtime_adj(X509_get_notBefore(x), 0L) == NULL)\n goto end;\n if (X509_time_adj_ex(X509_get_notAfter(x), days, 0, NULL) == NULL)\n goto end;\n if (clrext) {\n while (X509_get_ext_count(x) > 0)\n X509_delete_ext(x, 0);\n }\n if (conf) {\n X509V3_CTX ctx2;\n X509_set_version(x, 2);\n X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n X509V3_set_nconf(&ctx2, conf);\n if (!X509V3_EXT_add_nconf(conf, &ctx2, section, x))\n goto end;\n }\n if (!do_X509_sign(x, pkey, digest, sigopts))\n goto end;\n ret = 1;\n end:\n X509_STORE_CTX_free(xsc);\n if (!ret)\n ERR_print_errors(bio_err);\n if (!sno)\n ASN1_INTEGER_free(bs);\n return ret;\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n{\n if (to->type == EVP_PKEY_NONE) {\n if (EVP_PKEY_set_type(to, from->type) == 0)\n return 0;\n } else if (to->type != from->type) {\n EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_KEY_TYPES);\n goto err;\n }\n if (EVP_PKEY_missing_parameters(from)) {\n EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_MISSING_PARAMETERS);\n goto err;\n }\n if (!EVP_PKEY_missing_parameters(to)) {\n if (EVP_PKEY_cmp_parameters(to, from) == 1)\n return 1;\n EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_PARAMETERS);\n return 0;\n }\n if (from->ameth && from->ameth->param_copy)\n return from->ameth->param_copy(to, from);\n err:\n return 0;\n}', 'X509_STORE_CTX *X509_STORE_CTX_new(void)\n{\n X509_STORE_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL) {\n X509err(X509_F_X509_STORE_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)\n{\n ctx->cert = x;\n}', 'void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags)\n{\n X509_VERIFY_PARAM_set_flags(ctx->param, flags);\n}', 'int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)\n{\n param->flags |= flags;\n if (flags & X509_V_FLAG_POLICY_MASK)\n param->flags |= X509_V_FLAG_POLICY_CHECK;\n return 1;\n}', 'void X509_STORE_CTX_free(X509_STORE_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n X509_STORE_CTX_cleanup(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
34,965
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L340
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', '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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
34,966
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/asn1/asn1_lib.c/#L107
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, long omax) { int i,ret; long l; unsigned char *p= *pp; int tag,xclass,inf; long max=omax; if (!max) goto err; ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMATIVE_TAG; if (i == V_ASN1_PRIMATIVE_TAG) { p++; if (--max == 0) goto err; l=0; while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; } l<<=7L; l|= *(p++)&0x7f; tag=(int)l; } else { tag=i; p++; if (--max == 0) goto err; } *ptag=tag; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; #if 0 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), (int)(omax+ *pp)); #endif #if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); ret|=0x80; } #endif *pp=p; return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); }
['int MAIN(int argc, char **argv)\n{\n char *infile=NULL, *outfile=NULL, *keyname = NULL;\n char *certfile=NULL;\n BIO *in=NULL, *out = NULL, *inkey = NULL, *certsin = NULL;\n char **args;\n char *name = NULL;\n PKCS12 *p12 = NULL;\n char pass[50], macpass[50];\n int export_cert = 0;\n int options = 0;\n int chain = 0;\n int badarg = 0;\n int iter = _ITER_;\n int maciter = 1;\n int twopass = 0;\n int keytype = 0;\n int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;\n int ret = 1;\n int macver = 1;\n STACK *canames = NULL;\n apps_startup();\n enc = EVP_des_ede3_cbc();\n if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);\n args = argv + 1;\n while (*args) {\n\tif (*args[0] == \'-\') {\n\t\tif (!strcmp (*args, "-nokeys")) options |= NOKEYS;\n\t\telse if (!strcmp (*args, "-keyex")) keytype = KEY_EX;\n\t\telse if (!strcmp (*args, "-keysig")) keytype = KEY_SIG;\n\t\telse if (!strcmp (*args, "-nocerts")) options |= NOCERTS;\n\t\telse if (!strcmp (*args, "-clcerts")) options |= CLCERTS;\n\t\telse if (!strcmp (*args, "-cacerts")) options |= CACERTS;\n\t\telse if (!strcmp (*args, "-noout")) options |= (NOKEYS|NOCERTS);\n\t\telse if (!strcmp (*args, "-info")) options |= INFO;\n\t\telse if (!strcmp (*args, "-chain")) chain = 1;\n\t\telse if (!strcmp (*args, "-twopass")) twopass = 1;\n\t\telse if (!strcmp (*args, "-nomacver")) macver = 0;\n\t\telse if (!strcmp (*args, "-descert"))\n \t\t\tcert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;\n\t\telse if (!strcmp (*args, "-export")) export_cert = 1;\n\t\telse if (!strcmp (*args, "-des")) enc=EVP_des_cbc();\n#ifndef NO_IDEA\n\t\telse if (!strcmp (*args, "-idea")) enc=EVP_idea_cbc();\n#endif\n\t\telse if (!strcmp (*args, "-des3")) enc = EVP_des_ede3_cbc();\n\t\telse if (!strcmp (*args, "-noiter")) iter = 1;\n\t\telse if (!strcmp (*args, "-maciter")) maciter = _ITER_;\n\t\telse if (!strcmp (*args, "-nodes")) enc=NULL;\n\t\telse if (!strcmp (*args, "-inkey")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tkeyname = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-certfile")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tcertfile = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-name")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tname = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-caname")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tif (!canames) canames = sk_new(NULL);\n\t\t\tsk_push(canames, *args);\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-in")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\tinfile = *args;\n\t\t } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-out")) {\n\t\t if (args[1]) {\n\t\t\targs++;\n\t\t\toutfile = *args;\n\t\t } else badarg = 1;\n\t\t} else badarg = 1;\n\t} else badarg = 1;\n\targs++;\n }\n if (badarg) {\n\tBIO_printf (bio_err, "Usage: pkcs12 [options]\\n");\n\tBIO_printf (bio_err, "where options are\\n");\n\tBIO_printf (bio_err, "-export output PKCS12 file\\n");\n\tBIO_printf (bio_err, "-chain add certificate chain\\n");\n\tBIO_printf (bio_err, "-inkey file private key if not infile\\n");\n\tBIO_printf (bio_err, "-certfile f add all certs in f\\n");\n\tBIO_printf (bio_err, "-name \\"name\\" use name as friendly name\\n");\n\tBIO_printf (bio_err, "-caname \\"nm\\" use nm as CA friendly name (can be used more than once).\\n");\n\tBIO_printf (bio_err, "-in infile input filename\\n");\n\tBIO_printf (bio_err, "-out outfile output filename\\n");\n\tBIO_printf (bio_err, "-noout don\'t output anything, just verify.\\n");\n\tBIO_printf (bio_err, "-nomacver don\'t verify MAC.\\n");\n\tBIO_printf (bio_err, "-nocerts don\'t output certificates.\\n");\n\tBIO_printf (bio_err, "-clcerts only output client certificates.\\n");\n\tBIO_printf (bio_err, "-cacerts only output CA certificates.\\n");\n\tBIO_printf (bio_err, "-nokeys don\'t output private keys.\\n");\n\tBIO_printf (bio_err, "-info give info about PKCS#12 structure.\\n");\n\tBIO_printf (bio_err, "-des encrypt private keys with DES\\n");\n\tBIO_printf (bio_err, "-des3 encrypt private keys with triple DES (default)\\n");\n#ifndef NO_IDEA\n\tBIO_printf (bio_err, "-idea encrypt private keys with idea\\n");\n#endif\n\tBIO_printf (bio_err, "-nodes don\'t encrypt private keys\\n");\n\tBIO_printf (bio_err, "-noiter don\'t use encryption iteration\\n");\n\tBIO_printf (bio_err, "-maciter use MAC iteration\\n");\n\tBIO_printf (bio_err, "-twopass separate MAC, encryption passwords\\n");\n\tBIO_printf (bio_err, "-descert encrypt PKCS#12 certificates with triple DES (default RC2-40)\\n");\n\tBIO_printf (bio_err, "-keyex set MS key exchange type\\n");\n\tBIO_printf (bio_err, "-keysig set MS key signature type\\n");\n \tgoto end;\n }\n ERR_load_crypto_strings();\n in = BIO_new (BIO_s_file());\n out = BIO_new (BIO_s_file());\n if (!infile) BIO_set_fp (in, stdin, BIO_NOCLOSE);\n else {\n if (BIO_read_filename (in, infile) <= 0) {\n\t perror (infile);\n\t goto end;\n\t}\n }\n if (certfile) {\n \tcertsin = BIO_new (BIO_s_file());\n if (BIO_read_filename (certsin, certfile) <= 0) {\n\t perror (certfile);\n\t goto end;\n\t}\n }\n if (keyname) {\n \tinkey = BIO_new (BIO_s_file());\n if (BIO_read_filename (inkey, keyname) <= 0) {\n\t perror (keyname);\n\t goto end;\n\t}\n }\n if (!outfile) BIO_set_fp (out, stdout, BIO_NOCLOSE);\n else {\n if (BIO_write_filename (out, outfile) <= 0) {\n\t perror (outfile);\n\t goto end;\n\t}\n }\n if (twopass) {\n\tif(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert)) {\n \t BIO_printf (bio_err, "Can\'t read Password\\n");\n \t goto end;\n \t}\n }\nif (export_cert) {\n\tEVP_PKEY *key;\n\tSTACK *bags, *safes;\n\tPKCS12_SAFEBAG *bag;\n\tPKCS8_PRIV_KEY_INFO *p8;\n\tPKCS7 *authsafe;\n\tX509 *cert, *ucert = NULL;\n\tSTACK *certs;\n\tchar *catmp;\n\tint i, pmatch = 0;\n\tunsigned char keyid[EVP_MAX_MD_SIZE];\n\tint keyidlen;\n\tkey = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL);\n\tif (!inkey) BIO_reset(in);\n\tif (!key) {\n\t\tBIO_printf (bio_err, "Error loading private key\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tcerts = sk_new(NULL);\n\tif(!cert_load(in, certs)) {\n\t\tBIO_printf(bio_err, "Error loading certificates from input\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tbags = sk_new (NULL);\n\tif (certsin) {\n\t\tif(!cert_load(certsin, certs)) {\n\t\t\tBIO_printf(bio_err, "Error loading certificates from certfile\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t \tBIO_free(certsin);\n \t}\n\tfor(i = 0; i < sk_num(certs); i++) {\n\t\t\tcert = (X509 *)sk_value(certs, i);\n\t\t\tif(X509_check_private_key(cert, key)) {\n\t\t\t\tucert = cert;\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\tif(!ucert) {\n\t\tBIO_printf(bio_err, "No certificate matches private key\\n");\n\t\tgoto end;\n\t}\n\tif (chain) {\n \tint vret;\n\t\tSTACK *chain2;\n\t\tvret = get_cert_chain (ucert, &chain2);\n\t\tif (vret) {\n\t\t\tBIO_printf (bio_err, "Error %s getting chain.\\n",\n\t\t\t\t\tX509_verify_cert_error_string(vret));\n\t\t\tgoto end;\n\t\t}\n\t\tfor (i = 1; i < sk_num (chain2) ; i++)\n\t\t\t\t sk_push(certs, sk_value (chain2, i));\n\t\tsk_free(chain2);\n \t}\n\tfor(i = 0; i < sk_num(certs); i++) {\n\t\tcert = (X509 *)sk_value(certs, i);\n\t\tbag = M_PKCS12_x5092certbag(cert);\n\t\tif(cert == ucert) {\n\t\t\tif(name) PKCS12_add_friendlyname(bag, name, -1);\n\t\t\tX509_digest(cert, EVP_sha1(), keyid, &keyidlen);\n\t\t\tPKCS12_add_localkeyid(bag, keyid, keyidlen);\n\t\t\tpmatch = 1;\n\t\t} else if((catmp = sk_shift(canames)))\n\t\t\t\tPKCS12_add_friendlyname(bag, catmp, -1);\n\t\tsk_push(bags, (char *)bag);\n\t}\n\tif (canames) sk_free(canames);\n\tif(EVP_read_pw_string (pass, 50, "Enter Export Password:", 1)) {\n\t BIO_printf (bio_err, "Can\'t read Password\\n");\n\t goto end;\n }\n\tif (!twopass) strcpy(macpass, pass);\n\tauthsafe = PKCS12_pack_p7encdata (cert_pbe, pass, -1, NULL, 0,\n\t\t\t\t\t\t\t\t iter, bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tif (!authsafe) {\n\t\tERR_print_errors (bio_err);\n\t\tgoto end;\n\t}\n\tsafes = sk_new (NULL);\n\tsk_push (safes, (char *)authsafe);\n\tp8 = EVP_PKEY2PKCS8 (key);\n\tEVP_PKEY_free(key);\n\tif(keytype) PKCS8_add_keyusage(p8, keytype);\n\tbag = PKCS12_MAKE_SHKEYBAG (NID_pbe_WithSHA1And3_Key_TripleDES_CBC,\n\t\t\tpass, -1, NULL, 0, iter, p8);\n\tPKCS8_PRIV_KEY_INFO_free(p8);\n if (name) PKCS12_add_friendlyname (bag, name, -1);\n\tPKCS12_add_localkeyid (bag, keyid, keyidlen);\n\tbags = sk_new(NULL);\n\tsk_push (bags, (char *)bag);\n\tauthsafe = PKCS12_pack_p7data (bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tsk_push (safes, (char *)authsafe);\n\tp12 = PKCS12_init (NID_pkcs7_data);\n\tM_PKCS12_pack_authsafes (p12, safes);\n\tsk_pop_free(safes, PKCS7_free);\n\tPKCS12_set_mac (p12, macpass, -1, NULL, 0, maciter, NULL);\n\ti2d_PKCS12_bio (out, p12);\n\tPKCS12_free(p12);\n\tret = 0;\n\tgoto end;\n}\n if (!(p12 = d2i_PKCS12_bio (in, NULL))) {\n\tERR_print_errors(bio_err);\n\tgoto end;\n }\n if(EVP_read_pw_string (pass, 50, "Enter Import Password:", 0)) {\n\tBIO_printf (bio_err, "Can\'t read Password\\n");\n\tgoto end;\n }\n if (!twopass) strcpy(macpass, pass);\n if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);\n if(macver) {\n\tif (!PKCS12_verify_mac (p12, macpass, -1)) {\n\t BIO_printf (bio_err, "Mac verify errror: invalid password?\\n");\n\t ERR_print_errors (bio_err);\n\t goto end;\n\t} else BIO_printf (bio_err, "MAC verified OK\\n");\n }\n if (!dump_certs_keys_p12 (out, p12, pass, -1, options)) {\n\tBIO_printf(bio_err, "Error outputting keys and certificates\\n");\n\tERR_print_errors (bio_err);\n\tgoto end;\n }\n PKCS12_free(p12);\n ret = 0;\n end:\n EXIT(ret);\n}', 'int X509_check_private_key(X509 *x, EVP_PKEY *k)\n\t{\n\tEVP_PKEY *xk=NULL;\n\tint ok=0;\n\txk=X509_get_pubkey(x);\n\tif (xk->type != k->type)\n\t {\n\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);\n\t goto err;\n\t }\n\tswitch (k->type)\n\t\t{\n#ifndef NO_RSA\n\tcase EVP_PKEY_RSA:\n\t\tif (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0\n\t\t || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)\n\t\t {\n\t\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t goto err;\n\t\t }\n\t\tbreak;\n#endif\n#ifndef NO_DSA\n\tcase EVP_PKEY_DSA:\n\t\tif (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)\n\t\t {\n\t\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t goto err;\n\t\t }\n\t\tbreak;\n#endif\n#ifndef NO_DH\n\tcase EVP_PKEY_DH:\n\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);\n\t\tgoto err;\n#endif\n\tdefault:\n\t SSLerr(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);\n\t\tgoto err;\n\t\t}\n\tok=1;\nerr:\n\tEVP_PKEY_free(xk);\n\treturn(ok);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,\n\t long length)\n\t{\n\tASN1_INTEGER *ret=NULL;\n\tunsigned char *p,*to,*s;\n\tlong len;\n\tint inf,tag,xclass;\n\tint i;\n\tif ((a == NULL) || ((*a) == NULL))\n\t\t{\n\t\tif ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);\n\t\tret->type=V_ASN1_INTEGER;\n\t\t}\n\telse\n\t\tret=(*a);\n\tp= *pp;\n\tinf=ASN1_get_object(&p,&len,&tag,&xclass,length);\n\tif (inf & 0x80)\n\t\t{\n\t\ti=ASN1_R_BAD_OBJECT_HEADER;\n\t\tgoto err;\n\t\t}\n\tif (tag != V_ASN1_INTEGER)\n\t\t{\n\t\ti=ASN1_R_EXPECTING_AN_INTEGER;\n\t\tgoto err;\n\t\t}\n\ts=(unsigned char *)Malloc((int)len+1);\n\tif (s == NULL)\n\t\t{\n\t\ti=ERR_R_MALLOC_FAILURE;\n\t\tgoto err;\n\t\t}\n\tto=s;\n\tif (*p & 0x80)\n\t\t{\n\t\tret->type=V_ASN1_NEG_INTEGER;\n\t\tif (*p == 0xff)\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tfor (i=(int)len; i>0; i--)\n\t\t\t*(to++)= (*(p++)^0xFF)+1;\n\t\t}\n\telse\n\t\t{\n\t\tret->type=V_ASN1_INTEGER;\n\t\tif ((*p == 0) && (len != 1))\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tmemcpy(s,p,(int)len);\n\t\tp+=len;\n\t\t}\n\tif (ret->data != NULL) Free((char *)ret->data);\n\tret->data=s;\n\tret->length=(int)len;\n\tif (a != NULL) (*a)=ret;\n\t*pp=p;\n\treturn(ret);\nerr:\n\tASN1err(ASN1_F_D2I_ASN1_INTEGER,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\tASN1_INTEGER_free(ret);\n\treturn(NULL);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMATIVE_TAG;\n\tif (i == V_ASN1_PRIMATIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
34,967
0
https://github.com/openssl/openssl/blob/ff281ee8369350d88e8b57af139614f5683e1e8c/test/handshake_helper.c/#L323
static int do_not_call_session_ticket_cb(SSL *s, unsigned char *key_name, unsigned char *iv, EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc) { HANDSHAKE_EX_DATA *ex_data = (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx)); ex_data->session_ticket_do_not_call = 1; return 0; }
['static int do_not_call_session_ticket_cb(SSL *s, unsigned char *key_name,\n unsigned char *iv,\n EVP_CIPHER_CTX *ctx,\n HMAC_CTX *hctx, int enc)\n{\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n ex_data->session_ticket_do_not_call = 1;\n return 0;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}']
34,968
0
https://github.com/libav/libav/blob/58ef4ecff834f47f5a4c2a6bd4385b1999a30930/libavcodec/h264.c/#L2978
static int decode_slice_header(H264Context *h, H264Context *h0){ MpegEncContext * const s = &h->s; MpegEncContext * const s0 = &h0->s; unsigned int first_mb_in_slice; unsigned int pps_id; int num_ref_idx_active_override_flag; unsigned int slice_type, tmp, i, j; int default_ref_list_done = 0; int last_pic_structure; s->dropable= h->nal_ref_idc == 0; if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){ s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; }else{ s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; } first_mb_in_slice= get_ue_golomb(&s->gb); if(first_mb_in_slice == 0){ if(h0->current_slice && FIELD_PICTURE){ field_end(h, 1); } h0->current_slice = 0; if (!s0->first_field) s->current_picture_ptr= NULL; } slice_type= get_ue_golomb_31(&s->gb); if(slice_type > 9){ av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); return -1; } if(slice_type > 4){ slice_type -= 5; h->slice_type_fixed=1; }else h->slice_type_fixed=0; slice_type= golomb_to_pict_type[ slice_type ]; if (slice_type == AV_PICTURE_TYPE_I || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) { default_ref_list_done = 1; } h->slice_type= slice_type; h->slice_type_nos= slice_type & 3; s->pict_type= h->slice_type; pps_id= get_ue_golomb(&s->gb); if(pps_id>=MAX_PPS_COUNT){ av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); return -1; } if(!h0->pps_buffers[pps_id]) { av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\n", pps_id); return -1; } h->pps= *h0->pps_buffers[pps_id]; if(!h0->sps_buffers[h->pps.sps_id]) { av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\n", h->pps.sps_id); return -1; } h->sps = *h0->sps_buffers[h->pps.sps_id]; s->avctx->profile = ff_h264_get_profile(&h->sps); s->avctx->level = h->sps.level_idc; s->avctx->refs = h->sps.ref_frame_count; if(h == h0 && h->dequant_coeff_pps != pps_id){ h->dequant_coeff_pps = pps_id; init_dequant_tables(h); } s->mb_width= h->sps.mb_width; s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); h->b_stride= s->mb_width*4; s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1); if(h->sps.frame_mbs_only_flag) s->height= 16*s->mb_height - (2>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1); else s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1); if (s->context_initialized && ( s->width != s->avctx->width || s->height != s->avctx->height || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) { if(h != h0) { av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0); return -1; } free_tables(h, 0); flush_dpb(s->avctx); MPV_common_end(s); } if (!s->context_initialized) { if (h != h0) { av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n"); return -1; } avcodec_set_dimensions(s->avctx, s->width, s->height); s->avctx->sample_aspect_ratio= h->sps.sar; av_assert0(s->avctx->sample_aspect_ratio.den); h->s.avctx->coded_width = 16*s->mb_width; h->s.avctx->coded_height = 16*s->mb_height; if(h->sps.video_signal_type_present_flag){ s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; if(h->sps.colour_description_present_flag){ s->avctx->color_primaries = h->sps.color_primaries; s->avctx->color_trc = h->sps.color_trc; s->avctx->colorspace = h->sps.colorspace; } } if(h->sps.timing_info_present_flag){ int64_t den= h->sps.time_scale; if(h->x264_build < 44U) den *= 2; av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, h->sps.num_units_in_tick, den, 1<<30); } switch (h->sps.bit_depth_luma) { case 9 : s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P9 : PIX_FMT_YUV420P9; break; case 10 : s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV420P10; break; default: if (CHROMA444){ s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P; }else{ s->avctx->pix_fmt = s->avctx->get_format(s->avctx, s->avctx->codec->pix_fmts ? s->avctx->codec->pix_fmts : s->avctx->color_range == AVCOL_RANGE_JPEG ? hwaccel_pixfmt_list_h264_jpeg_420 : ff_hwaccel_pixfmt_list_420); } } s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt); if (MPV_common_init(s) < 0) { av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\n"); return -1; } s->first_field = 0; h->prev_interlaced_frame = 1; init_scan_tables(h); ff_h264_alloc_tables(h); if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) { if (context_init(h) < 0) { av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n"); return -1; } } else { for(i = 1; i < s->avctx->thread_count; i++) { H264Context *c; c = h->thread_context[i] = av_malloc(sizeof(H264Context)); memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); c->h264dsp = h->h264dsp; c->sps = h->sps; c->pps = h->pps; c->pixel_shift = h->pixel_shift; init_scan_tables(c); clone_tables(c, h, i); } for(i = 0; i < s->avctx->thread_count; i++) if (context_init(h->thread_context[i]) < 0) { av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n"); return -1; } } } h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); h->mb_mbaff = 0; h->mb_aff_frame = 0; last_pic_structure = s0->picture_structure; if(h->sps.frame_mbs_only_flag){ s->picture_structure= PICT_FRAME; }else{ if(get_bits1(&s->gb)) { s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); } else { s->picture_structure= PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME; if(h0->current_slice == 0){ if(h->frame_num != h->prev_frame_num) { int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num; if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num; if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) { unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1; if (unwrap_prev_frame_num < 0) unwrap_prev_frame_num += max_frame_num; h->prev_frame_num = unwrap_prev_frame_num; } } while(h->frame_num != h->prev_frame_num && h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){ Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); if (ff_h264_frame_start(h) < 0) return -1; h->prev_frame_num++; h->prev_frame_num %= 1<<h->sps.log2_max_frame_num; s->current_picture_ptr->frame_num= h->prev_frame_num; ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0); ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1); ff_generate_sliding_window_mmcos(h); ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); if (h->short_ref_count) { if (prev) { av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize, (const uint8_t**)prev->f.data, prev->f.linesize, s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16); h->short_ref[0]->poc = prev->poc+2; } h->short_ref[0]->frame_num = h->prev_frame_num; } } if (s0->first_field) { assert(s0->current_picture_ptr); assert(s0->current_picture_ptr->f.data[0]); assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF); if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { s0->current_picture_ptr = NULL; s0->first_field = FIELD_PICTURE; } else { if (h->nal_ref_idc && s0->current_picture_ptr->f.reference && s0->current_picture_ptr->frame_num != h->frame_num) { s0->first_field = 1; s0->current_picture_ptr = NULL; } else { s0->first_field = 0; } } } else { assert(!s0->current_picture_ptr); s0->first_field = FIELD_PICTURE; } if(!FIELD_PICTURE || s0->first_field) { if (ff_h264_frame_start(h) < 0) { s0->first_field = 0; return -1; } } else { ff_release_unused_pictures(s, 0); } } if(h != h0) clone_slice(h, h0); s->current_picture_ptr->frame_num= h->frame_num; assert(s->mb_num == s->mb_width * s->mb_height); if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num || first_mb_in_slice >= s->mb_num){ av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return -1; } s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width; s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE; if (s->picture_structure == PICT_BOTTOM_FIELD) s->resync_mb_y = s->mb_y = s->mb_y + 1; assert(s->mb_y < s->mb_height); if(s->picture_structure==PICT_FRAME){ h->curr_pic_num= h->frame_num; h->max_pic_num= 1<< h->sps.log2_max_frame_num; }else{ h->curr_pic_num= 2*h->frame_num + 1; h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); } if(h->nal_unit_type == NAL_IDR_SLICE){ get_ue_golomb(&s->gb); } if(h->sps.poc_type==0){ h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb); if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){ h->delta_poc_bottom= get_se_golomb(&s->gb); } } if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){ h->delta_poc[0]= get_se_golomb(&s->gb); if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME) h->delta_poc[1]= get_se_golomb(&s->gb); } init_poc(h); if(h->pps.redundant_pic_cnt_present){ h->redundant_pic_count= get_ue_golomb(&s->gb); } h->ref_count[0]= h->pps.ref_count[0]; h->ref_count[1]= h->pps.ref_count[1]; if(h->slice_type_nos != AV_PICTURE_TYPE_I){ if(h->slice_type_nos == AV_PICTURE_TYPE_B){ h->direct_spatial_mv_pred= get_bits1(&s->gb); } num_ref_idx_active_override_flag= get_bits1(&s->gb); if(num_ref_idx_active_override_flag){ h->ref_count[0]= get_ue_golomb(&s->gb) + 1; if(h->slice_type_nos==AV_PICTURE_TYPE_B) h->ref_count[1]= get_ue_golomb(&s->gb) + 1; if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){ av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); h->ref_count[0]= h->ref_count[1]= 1; return -1; } } if(h->slice_type_nos == AV_PICTURE_TYPE_B) h->list_count= 2; else h->list_count= 1; }else h->list_count= 0; if(!default_ref_list_done){ ff_h264_fill_default_ref_list(h); } if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0) return -1; if(h->slice_type_nos!=AV_PICTURE_TYPE_I){ s->last_picture_ptr= &h->ref_list[0][0]; ff_copy_picture(&s->last_picture, s->last_picture_ptr); } if(h->slice_type_nos==AV_PICTURE_TYPE_B){ s->next_picture_ptr= &h->ref_list[1][0]; ff_copy_picture(&s->next_picture, s->next_picture_ptr); } if( (h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P ) || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) ) pred_weight_table(h); else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){ implicit_weight_table(h, -1); }else { h->use_weight = 0; for (i = 0; i < 2; i++) { h->luma_weight_flag[i] = 0; h->chroma_weight_flag[i] = 0; } } if(h->nal_ref_idc) ff_h264_decode_ref_pic_marking(h0, &s->gb); if(FRAME_MBAFF){ ff_h264_fill_mbaff_ref_list(h); if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){ implicit_weight_table(h, 0); implicit_weight_table(h, 1); } } if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred) ff_h264_direct_dist_scale_factor(h); ff_h264_direct_ref_list_init(h); if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){ tmp = get_ue_golomb_31(&s->gb); if(tmp > 2){ av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); return -1; } h->cabac_init_idc= tmp; } h->last_qscale_diff = 0; tmp = h->pps.init_qp + get_se_golomb(&s->gb); if(tmp>51+6*(h->sps.bit_depth_luma-8)){ av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); return -1; } s->qscale= tmp; h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); if(h->slice_type == AV_PICTURE_TYPE_SP){ get_bits1(&s->gb); } if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){ get_se_golomb(&s->gb); } h->deblocking_filter = 1; h->slice_alpha_c0_offset = 52; h->slice_beta_offset = 52; if( h->pps.deblocking_filter_parameters_present ) { tmp= get_ue_golomb_31(&s->gb); if(tmp > 2){ av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); return -1; } h->deblocking_filter= tmp; if(h->deblocking_filter < 2) h->deblocking_filter^= 1; if( h->deblocking_filter ) { h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1; h->slice_beta_offset += get_se_golomb(&s->gb) << 1; if( h->slice_alpha_c0_offset > 104U || h->slice_beta_offset > 104U){ av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\n", h->slice_alpha_c0_offset, h->slice_beta_offset); return -1; } } } if( s->avctx->skip_loop_filter >= AVDISCARD_ALL ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I) ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B) ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) h->deblocking_filter= 0; if(h->deblocking_filter == 1 && h0->max_contexts > 1) { if(s->avctx->flags2 & CODEC_FLAG2_FAST) { h->deblocking_filter = 2; } else { h0->max_contexts = 1; if(!h0->single_decode_warning) { av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n"); h0->single_decode_warning = 1; } if (h != h0) { av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n"); return 1; } } } h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]) + 6 * (h->sps.bit_depth_luma - 8); #if 0 if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) slice_group_change_cycle= get_bits(&s->gb, ?); #endif h0->last_slice_type = slice_type; h->slice_num = ++h0->current_slice; if(h->slice_num >= MAX_SLICES){ av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n"); } for(j=0; j<2; j++){ int id_list[16]; int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j]; for(i=0; i<16; i++){ id_list[i]= 60; if (h->ref_list[j][i].f.data[0]) { int k; uint8_t *base = h->ref_list[j][i].f.base[0]; for(k=0; k<h->short_ref_count; k++) if (h->short_ref[k]->f.base[0] == base) { id_list[i]= k; break; } for(k=0; k<h->long_ref_count; k++) if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) { id_list[i]= h->short_ref_count + k; break; } } } ref2frm[0]= ref2frm[1]= -1; for(i=0; i<16; i++) ref2frm[i+2]= 4*id_list[i] + (h->ref_list[j][i].f.reference & 3); ref2frm[18+0]= ref2frm[18+1]= -1; for(i=16; i<48; i++) ref2frm[i+4]= 4*id_list[(i-16)>>1] + (h->ref_list[j][i].f.reference & 3); } h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16; h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width; if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", h->slice_num, (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"), first_mb_in_slice, av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", pps_id, h->frame_num, s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], h->ref_count[0], h->ref_count[1], s->qscale, h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26, h->use_weight, h->use_weight==1 && h->use_weight_chroma ? "c" : "", h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "" ); } return 0; }
['static int decode_slice_header(H264Context *h, H264Context *h0){\n MpegEncContext * const s = &h->s;\n MpegEncContext * const s0 = &h0->s;\n unsigned int first_mb_in_slice;\n unsigned int pps_id;\n int num_ref_idx_active_override_flag;\n unsigned int slice_type, tmp, i, j;\n int default_ref_list_done = 0;\n int last_pic_structure;\n s->dropable= h->nal_ref_idc == 0;\n if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){\n s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;\n }else{\n s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;\n }\n first_mb_in_slice= get_ue_golomb(&s->gb);\n if(first_mb_in_slice == 0){\n if(h0->current_slice && FIELD_PICTURE){\n field_end(h, 1);\n }\n h0->current_slice = 0;\n if (!s0->first_field)\n s->current_picture_ptr= NULL;\n }\n slice_type= get_ue_golomb_31(&s->gb);\n if(slice_type > 9){\n av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\\n", h->slice_type, s->mb_x, s->mb_y);\n return -1;\n }\n if(slice_type > 4){\n slice_type -= 5;\n h->slice_type_fixed=1;\n }else\n h->slice_type_fixed=0;\n slice_type= golomb_to_pict_type[ slice_type ];\n if (slice_type == AV_PICTURE_TYPE_I\n || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {\n default_ref_list_done = 1;\n }\n h->slice_type= slice_type;\n h->slice_type_nos= slice_type & 3;\n s->pict_type= h->slice_type;\n pps_id= get_ue_golomb(&s->gb);\n if(pps_id>=MAX_PPS_COUNT){\n av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n return -1;\n }\n if(!h0->pps_buffers[pps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\\n", pps_id);\n return -1;\n }\n h->pps= *h0->pps_buffers[pps_id];\n if(!h0->sps_buffers[h->pps.sps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\\n", h->pps.sps_id);\n return -1;\n }\n h->sps = *h0->sps_buffers[h->pps.sps_id];\n s->avctx->profile = ff_h264_get_profile(&h->sps);\n s->avctx->level = h->sps.level_idc;\n s->avctx->refs = h->sps.ref_frame_count;\n if(h == h0 && h->dequant_coeff_pps != pps_id){\n h->dequant_coeff_pps = pps_id;\n init_dequant_tables(h);\n }\n s->mb_width= h->sps.mb_width;\n s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n h->b_stride= s->mb_width*4;\n s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);\n if(h->sps.frame_mbs_only_flag)\n s->height= 16*s->mb_height - (2>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);\n else\n s->height= 16*s->mb_height - (4>>CHROMA444)*FFMIN(h->sps.crop_bottom, (8<<CHROMA444)-1);\n if (s->context_initialized\n && ( s->width != s->avctx->width || s->height != s->avctx->height\n || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {\n if(h != h0) {\n av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);\n return -1;\n }\n free_tables(h, 0);\n flush_dpb(s->avctx);\n MPV_common_end(s);\n }\n if (!s->context_initialized) {\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\\n");\n return -1;\n }\n avcodec_set_dimensions(s->avctx, s->width, s->height);\n s->avctx->sample_aspect_ratio= h->sps.sar;\n av_assert0(s->avctx->sample_aspect_ratio.den);\n h->s.avctx->coded_width = 16*s->mb_width;\n h->s.avctx->coded_height = 16*s->mb_height;\n if(h->sps.video_signal_type_present_flag){\n s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;\n if(h->sps.colour_description_present_flag){\n s->avctx->color_primaries = h->sps.color_primaries;\n s->avctx->color_trc = h->sps.color_trc;\n s->avctx->colorspace = h->sps.colorspace;\n }\n }\n if(h->sps.timing_info_present_flag){\n int64_t den= h->sps.time_scale;\n if(h->x264_build < 44U)\n den *= 2;\n av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n h->sps.num_units_in_tick, den, 1<<30);\n }\n switch (h->sps.bit_depth_luma) {\n case 9 :\n s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P9 : PIX_FMT_YUV420P9;\n break;\n case 10 :\n s->avctx->pix_fmt = CHROMA444 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV420P10;\n break;\n default:\n if (CHROMA444){\n s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;\n }else{\n s->avctx->pix_fmt = s->avctx->get_format(s->avctx,\n s->avctx->codec->pix_fmts ?\n s->avctx->codec->pix_fmts :\n s->avctx->color_range == AVCOL_RANGE_JPEG ?\n hwaccel_pixfmt_list_h264_jpeg_420 :\n ff_hwaccel_pixfmt_list_420);\n }\n }\n s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt);\n if (MPV_common_init(s) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\\n");\n return -1;\n }\n s->first_field = 0;\n h->prev_interlaced_frame = 1;\n init_scan_tables(h);\n ff_h264_alloc_tables(h);\n if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {\n if (context_init(h) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n } else {\n for(i = 1; i < s->avctx->thread_count; i++) {\n H264Context *c;\n c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n c->h264dsp = h->h264dsp;\n c->sps = h->sps;\n c->pps = h->pps;\n c->pixel_shift = h->pixel_shift;\n init_scan_tables(c);\n clone_tables(c, h, i);\n }\n for(i = 0; i < s->avctx->thread_count; i++)\n if (context_init(h->thread_context[i]) < 0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n return -1;\n }\n }\n }\n h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);\n h->mb_mbaff = 0;\n h->mb_aff_frame = 0;\n last_pic_structure = s0->picture_structure;\n if(h->sps.frame_mbs_only_flag){\n s->picture_structure= PICT_FRAME;\n }else{\n if(get_bits1(&s->gb)) {\n s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);\n } else {\n s->picture_structure= PICT_FRAME;\n h->mb_aff_frame = h->sps.mb_aff;\n }\n }\n h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME;\n if(h0->current_slice == 0){\n if(h->frame_num != h->prev_frame_num) {\n int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;\n if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;\n if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n if (unwrap_prev_frame_num < 0)\n unwrap_prev_frame_num += max_frame_num;\n h->prev_frame_num = unwrap_prev_frame_num;\n }\n }\n while(h->frame_num != h->prev_frame_num &&\n h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){\n Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n", h->frame_num, h->prev_frame_num);\n if (ff_h264_frame_start(h) < 0)\n return -1;\n h->prev_frame_num++;\n h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;\n s->current_picture_ptr->frame_num= h->prev_frame_num;\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);\n ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);\n ff_generate_sliding_window_mmcos(h);\n ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n if (h->short_ref_count) {\n if (prev) {\n av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,\n (const uint8_t**)prev->f.data, prev->f.linesize,\n s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16);\n h->short_ref[0]->poc = prev->poc+2;\n }\n h->short_ref[0]->frame_num = h->prev_frame_num;\n }\n }\n if (s0->first_field) {\n assert(s0->current_picture_ptr);\n assert(s0->current_picture_ptr->f.data[0]);\n assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);\n if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n s0->current_picture_ptr = NULL;\n s0->first_field = FIELD_PICTURE;\n } else {\n if (h->nal_ref_idc &&\n s0->current_picture_ptr->f.reference &&\n s0->current_picture_ptr->frame_num != h->frame_num) {\n s0->first_field = 1;\n s0->current_picture_ptr = NULL;\n } else {\n s0->first_field = 0;\n }\n }\n } else {\n assert(!s0->current_picture_ptr);\n s0->first_field = FIELD_PICTURE;\n }\n if(!FIELD_PICTURE || s0->first_field) {\n if (ff_h264_frame_start(h) < 0) {\n s0->first_field = 0;\n return -1;\n }\n } else {\n ff_release_unused_pictures(s, 0);\n }\n }\n if(h != h0)\n clone_slice(h, h0);\n s->current_picture_ptr->frame_num= h->frame_num;\n assert(s->mb_num == s->mb_width * s->mb_height);\n if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n first_mb_in_slice >= s->mb_num){\n av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n return -1;\n }\n s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n if (s->picture_structure == PICT_BOTTOM_FIELD)\n s->resync_mb_y = s->mb_y = s->mb_y + 1;\n assert(s->mb_y < s->mb_height);\n if(s->picture_structure==PICT_FRAME){\n h->curr_pic_num= h->frame_num;\n h->max_pic_num= 1<< h->sps.log2_max_frame_num;\n }else{\n h->curr_pic_num= 2*h->frame_num + 1;\n h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);\n }\n if(h->nal_unit_type == NAL_IDR_SLICE){\n get_ue_golomb(&s->gb);\n }\n if(h->sps.poc_type==0){\n h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){\n h->delta_poc_bottom= get_se_golomb(&s->gb);\n }\n }\n if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){\n h->delta_poc[0]= get_se_golomb(&s->gb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)\n h->delta_poc[1]= get_se_golomb(&s->gb);\n }\n init_poc(h);\n if(h->pps.redundant_pic_cnt_present){\n h->redundant_pic_count= get_ue_golomb(&s->gb);\n }\n h->ref_count[0]= h->pps.ref_count[0];\n h->ref_count[1]= h->pps.ref_count[1];\n if(h->slice_type_nos != AV_PICTURE_TYPE_I){\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n h->direct_spatial_mv_pred= get_bits1(&s->gb);\n }\n num_ref_idx_active_override_flag= get_bits1(&s->gb);\n if(num_ref_idx_active_override_flag){\n h->ref_count[0]= get_ue_golomb(&s->gb) + 1;\n if(h->slice_type_nos==AV_PICTURE_TYPE_B)\n h->ref_count[1]= get_ue_golomb(&s->gb) + 1;\n if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){\n av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n h->ref_count[0]= h->ref_count[1]= 1;\n return -1;\n }\n }\n if(h->slice_type_nos == AV_PICTURE_TYPE_B)\n h->list_count= 2;\n else\n h->list_count= 1;\n }else\n h->list_count= 0;\n if(!default_ref_list_done){\n ff_h264_fill_default_ref_list(h);\n }\n if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0)\n return -1;\n if(h->slice_type_nos!=AV_PICTURE_TYPE_I){\n s->last_picture_ptr= &h->ref_list[0][0];\n ff_copy_picture(&s->last_picture, s->last_picture_ptr);\n }\n if(h->slice_type_nos==AV_PICTURE_TYPE_B){\n s->next_picture_ptr= &h->ref_list[1][0];\n ff_copy_picture(&s->next_picture, s->next_picture_ptr);\n }\n if( (h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P )\n || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) )\n pred_weight_table(h);\n else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n implicit_weight_table(h, -1);\n }else {\n h->use_weight = 0;\n for (i = 0; i < 2; i++) {\n h->luma_weight_flag[i] = 0;\n h->chroma_weight_flag[i] = 0;\n }\n }\n if(h->nal_ref_idc)\n ff_h264_decode_ref_pic_marking(h0, &s->gb);\n if(FRAME_MBAFF){\n ff_h264_fill_mbaff_ref_list(h);\n if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n implicit_weight_table(h, 0);\n implicit_weight_table(h, 1);\n }\n }\n if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n ff_h264_direct_dist_scale_factor(h);\n ff_h264_direct_ref_list_init(h);\n if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){\n tmp = get_ue_golomb_31(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n return -1;\n }\n h->cabac_init_idc= tmp;\n }\n h->last_qscale_diff = 0;\n tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n if(tmp>51+6*(h->sps.bit_depth_luma-8)){\n av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n return -1;\n }\n s->qscale= tmp;\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n if(h->slice_type == AV_PICTURE_TYPE_SP){\n get_bits1(&s->gb);\n }\n if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){\n get_se_golomb(&s->gb);\n }\n h->deblocking_filter = 1;\n h->slice_alpha_c0_offset = 52;\n h->slice_beta_offset = 52;\n if( h->pps.deblocking_filter_parameters_present ) {\n tmp= get_ue_golomb_31(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\\n", tmp);\n return -1;\n }\n h->deblocking_filter= tmp;\n if(h->deblocking_filter < 2)\n h->deblocking_filter^= 1;\n if( h->deblocking_filter ) {\n h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;\n h->slice_beta_offset += get_se_golomb(&s->gb) << 1;\n if( h->slice_alpha_c0_offset > 104U\n || h->slice_beta_offset > 104U){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\\n", h->slice_alpha_c0_offset, h->slice_beta_offset);\n return -1;\n }\n }\n }\n if( s->avctx->skip_loop_filter >= AVDISCARD_ALL\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))\n h->deblocking_filter= 0;\n if(h->deblocking_filter == 1 && h0->max_contexts > 1) {\n if(s->avctx->flags2 & CODEC_FLAG2_FAST) {\n h->deblocking_filter = 2;\n } else {\n h0->max_contexts = 1;\n if(!h0->single_decode_warning) {\n av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n h0->single_decode_warning = 1;\n }\n if (h != h0) {\n av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\\n");\n return 1;\n }\n }\n }\n h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset)\n - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])\n + 6 * (h->sps.bit_depth_luma - 8);\n#if 0\n if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)\n slice_group_change_cycle= get_bits(&s->gb, ?);\n#endif\n h0->last_slice_type = slice_type;\n h->slice_num = ++h0->current_slice;\n if(h->slice_num >= MAX_SLICES){\n av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\\n");\n }\n for(j=0; j<2; j++){\n int id_list[16];\n int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];\n for(i=0; i<16; i++){\n id_list[i]= 60;\n if (h->ref_list[j][i].f.data[0]) {\n int k;\n uint8_t *base = h->ref_list[j][i].f.base[0];\n for(k=0; k<h->short_ref_count; k++)\n if (h->short_ref[k]->f.base[0] == base) {\n id_list[i]= k;\n break;\n }\n for(k=0; k<h->long_ref_count; k++)\n if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {\n id_list[i]= h->short_ref_count + k;\n break;\n }\n }\n }\n ref2frm[0]=\n ref2frm[1]= -1;\n for(i=0; i<16; i++)\n ref2frm[i+2]= 4*id_list[i]\n + (h->ref_list[j][i].f.reference & 3);\n ref2frm[18+0]=\n ref2frm[18+1]= -1;\n for(i=16; i<48; i++)\n ref2frm[i+4]= 4*id_list[(i-16)>>1]\n + (h->ref_list[j][i].f.reference & 3);\n }\n h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16;\n h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n if(s->avctx->debug&FF_DEBUG_PICT_INFO){\n av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n h->slice_num,\n (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),\n first_mb_in_slice,\n av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n pps_id, h->frame_num,\n s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],\n h->ref_count[0], h->ref_count[1],\n s->qscale,\n h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26,\n h->use_weight,\n h->use_weight==1 && h->use_weight_chroma ? "c" : "",\n h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""\n );\n }\n return 0;\n}']
34,969
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_mul.c/#L728
void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) { BN_ULONG *rr; #ifdef BN_COUNT printf(" bn_mul_normal %d * %d\n",na,nb); #endif if (na < nb) { int itmp; BN_ULONG *ltmp; itmp=na; na=nb; nb=itmp; ltmp=a; a=b; b=ltmp; } rr= &(r[na]); rr[0]=bn_mul_words(r,a,na,b[0]); for (;;) { if (--nb <= 0) return; rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); if (--nb <= 0) return; rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); if (--nb <= 0) return; rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); if (--nb <= 0) return; rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); rr+=4; r+=4; b+=4; } }
['int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;\n\tint start=1;\n\tBIGNUM *d;\n\tBIGNUM val[TABLE_SIZE];\n\td= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul(r,r,r,m,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul(r,r,r,m,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint r=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tt= &(ctx->bn[ctx->tos++]);\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_mod(ret,t,m,ctx)) goto err;\n\tr=1;\nerr:\n\tctx->tos--;\n\treturn(r);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n\t{\n\tBN_ULONG *rr;\n#ifdef BN_COUNT\nprintf(" bn_mul_normal %d * %d\\n",na,nb);\n#endif\n\tif (na < nb)\n\t\t{\n\t\tint itmp;\n\t\tBN_ULONG *ltmp;\n\t\titmp=na; na=nb; nb=itmp;\n\t\tltmp=a; a=b; b=ltmp;\n\t\t}\n\trr= &(r[na]);\n\trr[0]=bn_mul_words(r,a,na,b[0]);\n\tfor (;;)\n\t\t{\n\t\tif (--nb <= 0) return;\n\t\trr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);\n\t\tif (--nb <= 0) return;\n\t\trr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);\n\t\tif (--nb <= 0) return;\n\t\trr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);\n\t\tif (--nb <= 0) return;\n\t\trr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);\n\t\trr+=4;\n\t\tr+=4;\n\t\tb+=4;\n\t\t}\n\t}']
34,970
0
https://github.com/openssl/openssl/blob/c922ebe23247ff9ee07310fa30647623c0547cd9/crypto/lhash/lhash.c/#L123
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return (NULL); } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return (ret); }
['static int tls_construct_encrypted_extensions(SSL *s, WPACKET *pkt)\n{\n int al;\n if (!tls_construct_extensions(s, pkt, EXT_TLS1_3_ENCRYPTED_EXTENSIONS\n | EXT_TLS1_3_CERTIFICATE, &al)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n SSLerr(SSL_F_TLS_CONSTRUCT_ENCRYPTED_EXTENSIONS, ERR_R_INTERNAL_ERROR);\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n return 0;\n }\n return 1;\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n desc = s->method->ssl3_enc->alert_value(desc);\n if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n desc = SSL_AD_HANDSHAKE_FAILURE;\n if (desc < 0)\n return -1;\n if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n SSL_CTX_remove_session(s->session_ctx, s->session);\n s->s3->alert_dispatch = 1;\n s->s3->send_alert[0] = level;\n s->s3->send_alert[1] = desc;\n if (!RECORD_LAYER_write_pending(&s->rlayer)) {\n return s->method->ssl_dispatch_alert(s);\n }\n return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_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}']
34,971
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/objects/obj_dat.c/#L260
int OBJ_add_object(ASN1_OBJECT *obj) { ASN1_OBJECT *o; ADDED_OBJ *ao[4],*aop; int i; if (added == NULL) if (!init_added()) return(0); if ((o=OBJ_dup(obj)) == NULL) goto err; ao[ADDED_DATA]=NULL; ao[ADDED_SNAME]=NULL; ao[ADDED_LNAME]=NULL; ao[ADDED_NID]=NULL; ao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); if ((o->length != 0) && (obj->data != NULL)) ao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); if (o->sn != NULL) ao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); if (o->ln != NULL) ao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ)); for (i=ADDED_DATA; i<=ADDED_NID; i++) { if (ao[i] != NULL) { ao[i]->type=i; ao[i]->obj=o; aop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]); if (aop != NULL) Free(aop); } } o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| ASN1_OBJECT_FLAG_DYNAMIC_DATA); return(o->nid); err: for (i=ADDED_DATA; i<=ADDED_NID; i++) if (ao[i] != NULL) Free(ao[i]); if (o != NULL) Free(o); return(NID_undef); }
['int OBJ_add_object(ASN1_OBJECT *obj)\n\t{\n\tASN1_OBJECT *o;\n\tADDED_OBJ *ao[4],*aop;\n\tint i;\n\tif (added == NULL)\n\t\tif (!init_added()) return(0);\n\tif ((o=OBJ_dup(obj)) == NULL) goto err;\n\tao[ADDED_DATA]=NULL;\n\tao[ADDED_SNAME]=NULL;\n\tao[ADDED_LNAME]=NULL;\n\tao[ADDED_NID]=NULL;\n\tao[ADDED_NID]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));\n\tif ((o->length != 0) && (obj->data != NULL))\n\t\tao[ADDED_DATA]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));\n\tif (o->sn != NULL)\n\t\tao[ADDED_SNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));\n\tif (o->ln != NULL)\n\t\tao[ADDED_LNAME]=(ADDED_OBJ *)Malloc(sizeof(ADDED_OBJ));\n\tfor (i=ADDED_DATA; i<=ADDED_NID; i++)\n\t\t{\n\t\tif (ao[i] != NULL)\n\t\t\t{\n\t\t\tao[i]->type=i;\n\t\t\tao[i]->obj=o;\n\t\t\taop=(ADDED_OBJ *)lh_insert(added,(char *)ao[i]);\n\t\t\tif (aop != NULL)\n\t\t\t\tFree(aop);\n\t\t\t}\n\t\t}\n\to->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|\n\t\t\tASN1_OBJECT_FLAG_DYNAMIC_DATA);\n\treturn(o->nid);\nerr:\n\tfor (i=ADDED_DATA; i<=ADDED_NID; i++)\n\t\tif (ao[i] != NULL) Free(ao[i]);\n\tif (o != NULL) Free(o);\n\treturn(NID_undef);\n\t}']
34,972
0
https://github.com/openssl/openssl/blob/02ab618c97eb5c383153f1835017533efc2f7422/crypto/asn1/asn1_lib.c/#L101
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, long omax) { int i,ret; long l; unsigned char *p= *pp; int tag,xclass,inf; long max=omax; if (!max) goto err; ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMITIVE_TAG; if (i == V_ASN1_PRIMITIVE_TAG) { p++; if (--max == 0) goto err; l=0; while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; } l<<=7L; l|= *(p++)&0x7f; tag=(int)l; } else { tag=i; p++; if (--max == 0) goto err; } *ptag=tag; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; #if 0 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), (int)(omax+ *pp)); #endif #if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); ret|=0x80; } #endif *pp=p; return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); }
['static int 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, LHASH *conf, char *section)\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\tif(conf) {\n\t\tX509V3_CTX ctx2;\n\t\tX509_set_version(x,2);\n X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n X509V3_set_conf_lhash(&ctx2, conf);\n if(!X509V3_EXT_add_conf(conf, &ctx2, section, x)) goto end;\n\t}\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}', 'int X509_verify_cert(X509_STORE_CTX *ctx)\n\t{\n\tX509 *x,*xtmp,*chain_ss=NULL;\n\tX509_NAME *xn;\n\tX509_OBJECT obj;\n\tint depth,i,ok=0;\n\tint num;\n\tint (*cb)();\n\tSTACK_OF(X509) *sktmp=NULL;\n\tif (ctx->cert == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);\n\t\treturn(-1);\n\t\t}\n\tcb=ctx->ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tif (ctx->chain == NULL)\n\t\t{\n\t\tif (\t((ctx->chain=sk_X509_new_null()) == NULL) ||\n\t\t\t(!sk_X509_push(ctx->chain,ctx->cert)))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto end;\n\t\t\t}\n\t\tCRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);\n\t\tctx->last_untrusted=1;\n\t\t}\n\tif (ctx->untrusted != NULL\n\t && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\tgoto end;\n\t\t}\n\tnum=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,num-1);\n\tdepth=ctx->depth;\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)\n\t\t\tbreak;\n\t\tif (ctx->untrusted != NULL)\n\t\t\t{\n\t\t\txtmp=X509_find_by_subject(sktmp,xn);\n\t\t\tif (xtmp != NULL)\n\t\t\t\t{\n\t\t\t\tif (!sk_X509_push(ctx->chain,xtmp))\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tCRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);\n\t\t\t\tsk_X509_delete_ptr(sktmp,xtmp);\n\t\t\t\tctx->last_untrusted++;\n\t\t\t\tx=xtmp;\n\t\t\t\tnum++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\tbreak;\n\t\t}\n\ti=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,i-1);\n\tif (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x))\n\t\t== 0)\n\t\t{\n\t\tif (sk_X509_num(ctx->chain) == 1)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\tctx->error_depth=i-1;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tchain_ss=sk_X509_pop(ctx->chain);\n\t\t\tctx->last_untrusted--;\n\t\t\tnum--;\n\t\t\tx=sk_X509_value(ctx->chain,num-1);\n\t\t\t}\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)\n\t\t\tbreak;\n\t\tok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);\n\t\tif (ok != X509_LU_X509)\n\t\t\t{\n\t\t\tif (ok == X509_LU_RETRY)\n\t\t\t\t{\n\t\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);\n\t\t\t\treturn(ok);\n\t\t\t\t}\n\t\t\telse if (ok != X509_LU_FAIL)\n\t\t\t\t{\n\t\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\t\treturn(ok);\n\t\t\t\t}\n\t\t\tbreak;\n\t\t\t}\n\t\tx=obj.data.x509;\n\t\tif (!sk_X509_push(ctx->chain,obj.data.x509))\n\t\t\t{\n\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(0);\n\t\t\t}\n\t\tnum++;\n\t\t}\n\txn=X509_get_issuer_name(x);\n\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0)\n\t\t{\n\t\tif ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0))\n\t\t\t{\n\t\t\tif (ctx->last_untrusted >= num)\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;\n\t\t\telse\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsk_X509_push(ctx->chain,chain_ss);\n\t\t\tnum++;\n\t\t\tctx->last_untrusted=num;\n\t\t\tctx->current_cert=chain_ss;\n\t\t\tctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;\n\t\t\tchain_ss=NULL;\n\t\t\t}\n\t\tctx->error_depth=num-1;\n\t\tok=cb(0,ctx);\n\t\tif (!ok) goto end;\n\t\t}\n\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\tif (ctx->ctx->verify != NULL)\n\t\tok=ctx->ctx->verify(ctx);\n\telse\n\t\tok=internal_verify(ctx);\n\tif (0)\n\t\t{\nend:\n\t\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\t\t}\n\tif (sktmp != NULL) sk_X509_free(sktmp);\n\tif (chain_ss != NULL) X509_free(chain_ss);\n\treturn(ok);\n\t}', 'void X509_OBJECT_free_contents(X509_OBJECT *a)\n\t{\n\tswitch (a->type)\n\t\t{\n\tcase X509_LU_X509:\n\t\tX509_free(a->data.x509);\n\t\tbreak;\n\tcase X509_LU_CRL:\n\t\tX509_CRL_free(a->data.crl);\n\t\tbreak;\n\t\t}\n\t}', 'int X509_check_private_key(X509 *x, EVP_PKEY *k)\n\t{\n\tEVP_PKEY *xk=NULL;\n\tint ok=0;\n\txk=X509_get_pubkey(x);\n\tif (xk->type != k->type)\n\t {\n\t X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);\n\t goto err;\n\t }\n\tswitch (k->type)\n\t\t{\n#ifndef NO_RSA\n\tcase EVP_PKEY_RSA:\n\t\tif (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0\n\t\t || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)\n\t\t {\n\t\t X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t goto err;\n\t\t }\n\t\tbreak;\n#endif\n#ifndef NO_DSA\n\tcase EVP_PKEY_DSA:\n\t\tif (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)\n\t\t {\n\t\t X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t goto err;\n\t\t }\n\t\tbreak;\n#endif\n#ifndef NO_DH\n\tcase EVP_PKEY_DH:\n\t X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);\n\t\tgoto err;\n#endif\n\tdefault:\n\t X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);\n\t\tgoto err;\n\t\t}\n\tok=1;\nerr:\n\tEVP_PKEY_free(xk);\n\treturn(ok);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tM_ASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) M_ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
34,973
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static void truespeech_read_frame(TSContext *dec, const uint8_t *input)\n{\n BitstreamContext bc;\n dec->bdsp.bswap_buf((uint32_t *) dec->buffer, (const uint32_t *) input, 8);\n bitstream_init8(&bc, dec->buffer, 32);\n dec->vector[7] = ts_codebook[7][bitstream_read(&bc, 3)];\n dec->vector[6] = ts_codebook[6][bitstream_read(&bc, 3)];\n dec->vector[5] = ts_codebook[5][bitstream_read(&bc, 3)];\n dec->vector[4] = ts_codebook[4][bitstream_read(&bc, 4)];\n dec->vector[3] = ts_codebook[3][bitstream_read(&bc, 4)];\n dec->vector[2] = ts_codebook[2][bitstream_read(&bc, 4)];\n dec->vector[1] = ts_codebook[1][bitstream_read(&bc, 5)];\n dec->vector[0] = ts_codebook[0][bitstream_read(&bc, 5)];\n dec->flag = bitstream_read_bit(&bc);\n dec->offset1[0] = bitstream_read(&bc, 4) << 4;\n dec->offset2[3] = bitstream_read(&bc, 7);\n dec->offset2[2] = bitstream_read(&bc, 7);\n dec->offset2[1] = bitstream_read(&bc, 7);\n dec->offset2[0] = bitstream_read(&bc, 7);\n dec->offset1[1] = bitstream_read(&bc, 4);\n dec->pulseval[1] = bitstream_read(&bc, 14);\n dec->pulseval[0] = bitstream_read(&bc, 14);\n dec->offset1[1] |= bitstream_read(&bc, 4) << 4;\n dec->pulseval[3] = bitstream_read(&bc, 14);\n dec->pulseval[2] = bitstream_read(&bc, 14);\n dec->offset1[0] |= bitstream_read_bit(&bc);\n dec->pulsepos[0] = bitstream_read(&bc, 27);\n dec->pulseoff[0] = bitstream_read(&bc, 4);\n dec->offset1[0] |= bitstream_read_bit(&bc) << 1;\n dec->pulsepos[1] = bitstream_read(&bc, 27);\n dec->pulseoff[1] = bitstream_read(&bc, 4);\n dec->offset1[0] |= bitstream_read_bit(&bc) << 2;\n dec->pulsepos[2] = bitstream_read(&bc, 27);\n dec->pulseoff[2] = bitstream_read(&bc, 4);\n dec->offset1[0] |= bitstream_read_bit(&bc) << 3;\n dec->pulsepos[3] = bitstream_read(&bc, 27);\n dec->pulseoff[3] = bitstream_read(&bc, 4);\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}']
34,974
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_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n 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_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}']
34,975
0
https://github.com/nginx/nginx/blob/29b5a1378460c746a9e9eec7110df31e845b31b2/src/core/ngx_hash.c/#L391
ngx_int_t ngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts) { u_char *elts; size_t len; u_short *test; ngx_uint_t i, n, key, size, start, bucket_size; ngx_hash_elt_t *elt, **buckets; for (n = 0; n < nelts; n++) { if (names[n].key.len >= 255) { ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, "the \"%V\" value to hash is to long: %uz bytes, " "the maximum length can be 255 bytes only", &names[n].key, names[n].key.len); return NGX_ERROR; } if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *)) { ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, "could not build the %s, you should " "increase %s_bucket_size: %i", hinit->name, hinit->name, hinit->bucket_size); return NGX_ERROR; } } test = ngx_alloc(hinit->max_size * sizeof(u_short), hinit->pool->log); if (test == NULL) { return NGX_ERROR; } bucket_size = hinit->bucket_size - sizeof(void *); start = nelts / (bucket_size / (2 * sizeof(void *))); start = start ? start : 1; if (hinit->max_size > 10000 && hinit->max_size / nelts < 100) { start = hinit->max_size - 1000; } for (size = start; size < hinit->max_size; size++) { ngx_memzero(test, size * sizeof(u_short)); for (n = 0; n < nelts; n++) { if (names[n].key.data == NULL) { continue; } key = names[n].key_hash % size; test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n])); #if 0 ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, "%ui: %ui %ui \"%V\"", size, key, test[key], &names[n].key); #endif if (test[key] > (u_short) bucket_size) { goto next; } } goto found; next: continue; } ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0, "could not build the %s, you should increase " "either %s_max_size: %i or %s_bucket_size: %i", hinit->name, hinit->name, hinit->max_size, hinit->name, hinit->bucket_size); ngx_free(test); return NGX_ERROR; found: for (i = 0; i < size; i++) { test[i] = sizeof(void *); } for (n = 0; n < nelts; n++) { if (names[n].key.data == NULL) { continue; } key = names[n].key_hash % size; test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n])); } len = 0; for (i = 0; i < size; i++) { if (test[i] == sizeof(void *)) { continue; } test[i] = (u_short) (ngx_align(test[i], ngx_cacheline_size)); len += test[i]; } if (hinit->hash == NULL) { hinit->hash = ngx_pcalloc(hinit->pool, sizeof(ngx_hash_wildcard_t) + size * sizeof(ngx_hash_elt_t *)); if (hinit->hash == NULL) { ngx_free(test); return NGX_ERROR; } buckets = (ngx_hash_elt_t **) ((u_char *) hinit->hash + sizeof(ngx_hash_wildcard_t)); } else { buckets = ngx_pcalloc(hinit->pool, size * sizeof(ngx_hash_elt_t *)); if (buckets == NULL) { ngx_free(test); return NGX_ERROR; } } elts = ngx_palloc(hinit->pool, len + ngx_cacheline_size); if (elts == NULL) { ngx_free(test); return NGX_ERROR; } elts = ngx_align_ptr(elts, ngx_cacheline_size); for (i = 0; i < size; i++) { if (test[i] == sizeof(void *)) { continue; } buckets[i] = (ngx_hash_elt_t *) elts; elts += test[i]; } for (i = 0; i < size; i++) { test[i] = 0; } for (n = 0; n < nelts; n++) { if (names[n].key.data == NULL) { continue; } key = names[n].key_hash % size; elt = (ngx_hash_elt_t *) ((u_char *) buckets[key] + test[key]); elt->value = names[n].value; elt->len = (u_char) names[n].key.len; ngx_strlow(elt->name, names[n].key.data, names[n].key.len); test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n])); } for (i = 0; i < size; i++) { if (buckets[i] == NULL) { continue; } elt = (ngx_hash_elt_t *) ((u_char *) buckets[i] + test[i]); elt->value = NULL; } ngx_free(test); hinit->hash->buckets = buckets; hinit->hash->size = size; #if 0 for (i = 0; i < size; i++) { ngx_str_t val; ngx_uint_t key; elt = buckets[i]; if (elt == NULL) { ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, "%ui: NULL", i); continue; } while (elt->value) { val.len = elt->len; val.data = &elt->name[0]; key = hinit->key(val.data, val.len); ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0, "%ui: %p \"%V\" %ui", i, elt, &val, key); elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len, sizeof(void *)); } } #endif return NGX_OK; }
['static char *\nngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)\n{\n ngx_http_fastcgi_loc_conf_t *prev = parent;\n ngx_http_fastcgi_loc_conf_t *conf = child;\n u_char *p;\n size_t size;\n uintptr_t *code;\n ngx_str_t *h;\n ngx_uint_t i;\n ngx_keyval_t *src;\n ngx_hash_init_t hash;\n ngx_http_script_compile_t sc;\n ngx_http_script_copy_code_t *copy;\n if (conf->upstream.store != 0) {\n ngx_conf_merge_value(conf->upstream.store,\n prev->upstream.store, 0);\n if (conf->upstream.store_lengths == NULL) {\n conf->upstream.store_lengths = prev->upstream.store_lengths;\n conf->upstream.store_values = prev->upstream.store_values;\n }\n }\n ngx_conf_merge_uint_value(conf->upstream.store_access,\n prev->upstream.store_access, 0600);\n ngx_conf_merge_value(conf->upstream.buffering,\n prev->upstream.buffering, 1);\n ngx_conf_merge_value(conf->upstream.ignore_client_abort,\n prev->upstream.ignore_client_abort, 0);\n ngx_conf_merge_msec_value(conf->upstream.connect_timeout,\n prev->upstream.connect_timeout, 60000);\n ngx_conf_merge_msec_value(conf->upstream.send_timeout,\n prev->upstream.send_timeout, 60000);\n ngx_conf_merge_msec_value(conf->upstream.read_timeout,\n prev->upstream.read_timeout, 60000);\n ngx_conf_merge_size_value(conf->upstream.send_lowat,\n prev->upstream.send_lowat, 0);\n ngx_conf_merge_size_value(conf->upstream.buffer_size,\n prev->upstream.buffer_size,\n (size_t) ngx_pagesize);\n ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,\n 8, ngx_pagesize);\n if (conf->upstream.bufs.num < 2) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "there must be at least 2 \\"fastcgi_buffers\\"");\n return NGX_CONF_ERROR;\n }\n size = conf->upstream.buffer_size;\n if (size < conf->upstream.bufs.size) {\n size = conf->upstream.bufs.size;\n }\n ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,\n prev->upstream.busy_buffers_size_conf,\n NGX_CONF_UNSET_SIZE);\n if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {\n conf->upstream.busy_buffers_size = 2 * size;\n } else {\n conf->upstream.busy_buffers_size =\n conf->upstream.busy_buffers_size_conf;\n }\n if (conf->upstream.busy_buffers_size < size) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"fastcgi_busy_buffers_size\\" must be equal or bigger than "\n "maximum of the value of \\"fastcgi_buffer_size\\" and "\n "one of the \\"fastcgi_buffers\\"");\n return NGX_CONF_ERROR;\n }\n if (conf->upstream.busy_buffers_size\n > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)\n {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"fastcgi_busy_buffers_size\\" must be less than "\n "the size of all \\"fastcgi_buffers\\" minus one buffer");\n return NGX_CONF_ERROR;\n }\n ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,\n prev->upstream.temp_file_write_size_conf,\n NGX_CONF_UNSET_SIZE);\n if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {\n conf->upstream.temp_file_write_size = 2 * size;\n } else {\n conf->upstream.temp_file_write_size =\n conf->upstream.temp_file_write_size_conf;\n }\n if (conf->upstream.temp_file_write_size < size) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"fastcgi_temp_file_write_size\\" must be equal or bigger than "\n "maximum of the value of \\"fastcgi_buffer_size\\" and "\n "one of the \\"fastcgi_buffers\\"");\n return NGX_CONF_ERROR;\n }\n ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,\n prev->upstream.max_temp_file_size_conf,\n NGX_CONF_UNSET_SIZE);\n if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {\n conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;\n } else {\n conf->upstream.max_temp_file_size =\n conf->upstream.max_temp_file_size_conf;\n }\n if (conf->upstream.max_temp_file_size != 0\n && conf->upstream.max_temp_file_size < size)\n {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"fastcgi_max_temp_file_size\\" must be equal to zero to disable "\n "the temporary files usage or must be equal or bigger than "\n "maximum of the value of \\"fastcgi_buffer_size\\" and "\n "one of the \\"fastcgi_buffers\\"");\n return NGX_CONF_ERROR;\n }\n ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers,\n prev->upstream.ignore_headers,\n NGX_CONF_BITMASK_SET);\n ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,\n prev->upstream.next_upstream,\n (NGX_CONF_BITMASK_SET\n |NGX_HTTP_UPSTREAM_FT_ERROR\n |NGX_HTTP_UPSTREAM_FT_TIMEOUT));\n if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {\n conf->upstream.next_upstream = NGX_CONF_BITMASK_SET\n |NGX_HTTP_UPSTREAM_FT_OFF;\n }\n if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path,\n prev->upstream.temp_path,\n &ngx_http_fastcgi_temp_path)\n != NGX_OK)\n {\n return NGX_CONF_ERROR;\n }\n#if (NGX_HTTP_CACHE)\n ngx_conf_merge_ptr_value(conf->upstream.cache,\n prev->upstream.cache, NULL);\n if (conf->upstream.cache && conf->upstream.cache->data == NULL) {\n ngx_shm_zone_t *shm_zone;\n shm_zone = conf->upstream.cache;\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"fastcgi_cache\\" zone \\"%V\\" is unknown",\n &shm_zone->shm.name);\n return NGX_CONF_ERROR;\n }\n ngx_conf_merge_uint_value(conf->upstream.cache_min_uses,\n prev->upstream.cache_min_uses, 1);\n ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale,\n prev->upstream.cache_use_stale,\n (NGX_CONF_BITMASK_SET\n |NGX_HTTP_UPSTREAM_FT_OFF));\n if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) {\n conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET\n |NGX_HTTP_UPSTREAM_FT_OFF;\n }\n if (conf->upstream.cache_methods == 0) {\n conf->upstream.cache_methods = prev->upstream.cache_methods;\n }\n conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;\n ngx_conf_merge_ptr_value(conf->upstream.cache_valid,\n prev->upstream.cache_valid, NULL);\n if (conf->cache_key.value.data == NULL) {\n conf->cache_key = prev->cache_key;\n }\n#endif\n ngx_conf_merge_value(conf->upstream.pass_request_headers,\n prev->upstream.pass_request_headers, 1);\n ngx_conf_merge_value(conf->upstream.pass_request_body,\n prev->upstream.pass_request_body, 1);\n ngx_conf_merge_value(conf->upstream.intercept_errors,\n prev->upstream.intercept_errors, 0);\n ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL);\n ngx_conf_merge_str_value(conf->index, prev->index, "");\n hash.max_size = 512;\n hash.bucket_size = ngx_align(64, ngx_cacheline_size);\n hash.name = "fastcgi_hide_headers_hash";\n#if (NGX_HTTP_CACHE)\n h = conf->upstream.cache ? ngx_http_fastcgi_hide_cache_headers:\n ngx_http_fastcgi_hide_headers;\n#else\n h = ngx_http_fastcgi_hide_headers;\n#endif\n if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,\n &prev->upstream, h, &hash)\n != NGX_OK)\n {\n return NGX_CONF_ERROR;\n }\n if (conf->upstream.upstream == NULL) {\n conf->upstream.upstream = prev->upstream.upstream;\n }\n if (conf->fastcgi_lengths == NULL) {\n conf->fastcgi_lengths = prev->fastcgi_lengths;\n conf->fastcgi_values = prev->fastcgi_values;\n }\n#if (NGX_PCRE)\n if (conf->split_regex == NULL) {\n conf->split_regex = prev->split_regex;\n conf->split_name = prev->split_name;\n }\n#endif\n if (conf->params_source == NULL) {\n conf->flushes = prev->flushes;\n conf->params_len = prev->params_len;\n conf->params = prev->params;\n conf->params_source = prev->params_source;\n if (conf->params_source == NULL) {\n return NGX_CONF_OK;\n }\n }\n conf->params_len = ngx_array_create(cf->pool, 64, 1);\n if (conf->params_len == NULL) {\n return NGX_CONF_ERROR;\n }\n conf->params = ngx_array_create(cf->pool, 512, 1);\n if (conf->params == NULL) {\n return NGX_CONF_ERROR;\n }\n src = conf->params_source->elts;\n for (i = 0; i < conf->params_source->nelts; i++) {\n if (ngx_http_script_variables_count(&src[i].value) == 0) {\n copy = ngx_array_push_n(conf->params_len,\n sizeof(ngx_http_script_copy_code_t));\n if (copy == NULL) {\n return NGX_CONF_ERROR;\n }\n copy->code = (ngx_http_script_code_pt)\n ngx_http_script_copy_len_code;\n copy->len = src[i].key.len;\n copy = ngx_array_push_n(conf->params_len,\n sizeof(ngx_http_script_copy_code_t));\n if (copy == NULL) {\n return NGX_CONF_ERROR;\n }\n copy->code = (ngx_http_script_code_pt)\n ngx_http_script_copy_len_code;\n copy->len = src[i].value.len;\n size = (sizeof(ngx_http_script_copy_code_t)\n + src[i].key.len + src[i].value.len\n + sizeof(uintptr_t) - 1)\n & ~(sizeof(uintptr_t) - 1);\n copy = ngx_array_push_n(conf->params, size);\n if (copy == NULL) {\n return NGX_CONF_ERROR;\n }\n copy->code = ngx_http_script_copy_code;\n copy->len = src[i].key.len + src[i].value.len;\n p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);\n p = ngx_cpymem(p, src[i].key.data, src[i].key.len);\n ngx_memcpy(p, src[i].value.data, src[i].value.len);\n } else {\n copy = ngx_array_push_n(conf->params_len,\n sizeof(ngx_http_script_copy_code_t));\n if (copy == NULL) {\n return NGX_CONF_ERROR;\n }\n copy->code = (ngx_http_script_code_pt)\n ngx_http_script_copy_len_code;\n copy->len = src[i].key.len;\n size = (sizeof(ngx_http_script_copy_code_t)\n + src[i].key.len + sizeof(uintptr_t) - 1)\n & ~(sizeof(uintptr_t) - 1);\n copy = ngx_array_push_n(conf->params, size);\n if (copy == NULL) {\n return NGX_CONF_ERROR;\n }\n copy->code = ngx_http_script_copy_code;\n copy->len = src[i].key.len;\n p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);\n ngx_memcpy(p, src[i].key.data, src[i].key.len);\n ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));\n sc.cf = cf;\n sc.source = &src[i].value;\n sc.flushes = &conf->flushes;\n sc.lengths = &conf->params_len;\n sc.values = &conf->params;\n if (ngx_http_script_compile(&sc) != NGX_OK) {\n return NGX_CONF_ERROR;\n }\n }\n code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));\n if (code == NULL) {\n return NGX_CONF_ERROR;\n }\n *code = (uintptr_t) NULL;\n code = ngx_array_push_n(conf->params, sizeof(uintptr_t));\n if (code == NULL) {\n return NGX_CONF_ERROR;\n }\n *code = (uintptr_t) NULL;\n }\n code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));\n if (code == NULL) {\n return NGX_CONF_ERROR;\n }\n *code = (uintptr_t) NULL;\n return NGX_CONF_OK;\n}', 'ngx_int_t\nngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,\n ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,\n ngx_str_t *default_hide_headers, ngx_hash_init_t *hash)\n{\n ngx_str_t *h;\n ngx_uint_t i, j;\n ngx_array_t hide_headers;\n ngx_hash_key_t *hk;\n if (conf->hide_headers == NGX_CONF_UNSET_PTR\n && conf->pass_headers == NGX_CONF_UNSET_PTR)\n {\n conf->hide_headers_hash = prev->hide_headers_hash;\n if (conf->hide_headers_hash.buckets\n#if (NGX_HTTP_CACHE)\n && ((conf->cache == NULL) == (prev->cache == NULL))\n#endif\n )\n {\n return NGX_OK;\n }\n conf->hide_headers = prev->hide_headers;\n conf->pass_headers = prev->pass_headers;\n } else {\n if (conf->hide_headers == NGX_CONF_UNSET_PTR) {\n conf->hide_headers = prev->hide_headers;\n }\n if (conf->pass_headers == NGX_CONF_UNSET_PTR) {\n conf->pass_headers = prev->pass_headers;\n }\n }\n if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n for (h = default_hide_headers; h->len; h++) {\n hk = ngx_array_push(&hide_headers);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key = *h;\n hk->key_hash = ngx_hash_key_lc(h->data, h->len);\n hk->value = (void *) 1;\n }\n if (conf->hide_headers != NGX_CONF_UNSET_PTR) {\n h = conf->hide_headers->elts;\n for (i = 0; i < conf->hide_headers->nelts; i++) {\n hk = hide_headers.elts;\n for (j = 0; j < hide_headers.nelts; j++) {\n if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) {\n goto exist;\n }\n }\n hk = ngx_array_push(&hide_headers);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key = h[i];\n hk->key_hash = ngx_hash_key_lc(h[i].data, h[i].len);\n hk->value = (void *) 1;\n exist:\n continue;\n }\n }\n if (conf->pass_headers != NGX_CONF_UNSET_PTR) {\n h = conf->pass_headers->elts;\n hk = hide_headers.elts;\n for (i = 0; i < conf->pass_headers->nelts; i++) {\n for (j = 0; j < hide_headers.nelts; j++) {\n if (hk[j].key.data == NULL) {\n continue;\n }\n if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) {\n hk[j].key.data = NULL;\n break;\n }\n }\n }\n }\n hash->hash = &conf->hide_headers_hash;\n hash->key = ngx_hash_key_lc;\n hash->pool = cf->pool;\n hash->temp_pool = NULL;\n return ngx_hash_init(hash, hide_headers.elts, hide_headers.nelts);\n}', 'ngx_int_t\nngx_hash_init(ngx_hash_init_t *hinit, ngx_hash_key_t *names, ngx_uint_t nelts)\n{\n u_char *elts;\n size_t len;\n u_short *test;\n ngx_uint_t i, n, key, size, start, bucket_size;\n ngx_hash_elt_t *elt, **buckets;\n for (n = 0; n < nelts; n++) {\n if (names[n].key.len >= 255) {\n ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,\n "the \\"%V\\" value to hash is to long: %uz bytes, "\n "the maximum length can be 255 bytes only",\n &names[n].key, names[n].key.len);\n return NGX_ERROR;\n }\n if (hinit->bucket_size < NGX_HASH_ELT_SIZE(&names[n]) + sizeof(void *))\n {\n ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,\n "could not build the %s, you should "\n "increase %s_bucket_size: %i",\n hinit->name, hinit->name, hinit->bucket_size);\n return NGX_ERROR;\n }\n }\n test = ngx_alloc(hinit->max_size * sizeof(u_short), hinit->pool->log);\n if (test == NULL) {\n return NGX_ERROR;\n }\n bucket_size = hinit->bucket_size - sizeof(void *);\n start = nelts / (bucket_size / (2 * sizeof(void *)));\n start = start ? start : 1;\n if (hinit->max_size > 10000 && hinit->max_size / nelts < 100) {\n start = hinit->max_size - 1000;\n }\n for (size = start; size < hinit->max_size; size++) {\n ngx_memzero(test, size * sizeof(u_short));\n for (n = 0; n < nelts; n++) {\n if (names[n].key.data == NULL) {\n continue;\n }\n key = names[n].key_hash % size;\n test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));\n#if 0\n ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0,\n "%ui: %ui %ui \\"%V\\"",\n size, key, test[key], &names[n].key);\n#endif\n if (test[key] > (u_short) bucket_size) {\n goto next;\n }\n }\n goto found;\n next:\n continue;\n }\n ngx_log_error(NGX_LOG_EMERG, hinit->pool->log, 0,\n "could not build the %s, you should increase "\n "either %s_max_size: %i or %s_bucket_size: %i",\n hinit->name, hinit->name, hinit->max_size,\n hinit->name, hinit->bucket_size);\n ngx_free(test);\n return NGX_ERROR;\nfound:\n for (i = 0; i < size; i++) {\n test[i] = sizeof(void *);\n }\n for (n = 0; n < nelts; n++) {\n if (names[n].key.data == NULL) {\n continue;\n }\n key = names[n].key_hash % size;\n test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));\n }\n len = 0;\n for (i = 0; i < size; i++) {\n if (test[i] == sizeof(void *)) {\n continue;\n }\n test[i] = (u_short) (ngx_align(test[i], ngx_cacheline_size));\n len += test[i];\n }\n if (hinit->hash == NULL) {\n hinit->hash = ngx_pcalloc(hinit->pool, sizeof(ngx_hash_wildcard_t)\n + size * sizeof(ngx_hash_elt_t *));\n if (hinit->hash == NULL) {\n ngx_free(test);\n return NGX_ERROR;\n }\n buckets = (ngx_hash_elt_t **)\n ((u_char *) hinit->hash + sizeof(ngx_hash_wildcard_t));\n } else {\n buckets = ngx_pcalloc(hinit->pool, size * sizeof(ngx_hash_elt_t *));\n if (buckets == NULL) {\n ngx_free(test);\n return NGX_ERROR;\n }\n }\n elts = ngx_palloc(hinit->pool, len + ngx_cacheline_size);\n if (elts == NULL) {\n ngx_free(test);\n return NGX_ERROR;\n }\n elts = ngx_align_ptr(elts, ngx_cacheline_size);\n for (i = 0; i < size; i++) {\n if (test[i] == sizeof(void *)) {\n continue;\n }\n buckets[i] = (ngx_hash_elt_t *) elts;\n elts += test[i];\n }\n for (i = 0; i < size; i++) {\n test[i] = 0;\n }\n for (n = 0; n < nelts; n++) {\n if (names[n].key.data == NULL) {\n continue;\n }\n key = names[n].key_hash % size;\n elt = (ngx_hash_elt_t *) ((u_char *) buckets[key] + test[key]);\n elt->value = names[n].value;\n elt->len = (u_char) names[n].key.len;\n ngx_strlow(elt->name, names[n].key.data, names[n].key.len);\n test[key] = (u_short) (test[key] + NGX_HASH_ELT_SIZE(&names[n]));\n }\n for (i = 0; i < size; i++) {\n if (buckets[i] == NULL) {\n continue;\n }\n elt = (ngx_hash_elt_t *) ((u_char *) buckets[i] + test[i]);\n elt->value = NULL;\n }\n ngx_free(test);\n hinit->hash->buckets = buckets;\n hinit->hash->size = size;\n#if 0\n for (i = 0; i < size; i++) {\n ngx_str_t val;\n ngx_uint_t key;\n elt = buckets[i];\n if (elt == NULL) {\n ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0,\n "%ui: NULL", i);\n continue;\n }\n while (elt->value) {\n val.len = elt->len;\n val.data = &elt->name[0];\n key = hinit->key(val.data, val.len);\n ngx_log_error(NGX_LOG_ALERT, hinit->pool->log, 0,\n "%ui: %p \\"%V\\" %ui", i, elt, &val, key);\n elt = (ngx_hash_elt_t *) ngx_align_ptr(&elt->name[0] + elt->len,\n sizeof(void *));\n }\n }\n#endif\n return NGX_OK;\n}', 'void *\nngx_pcalloc(ngx_pool_t *pool, size_t size)\n{\n void *p;\n p = ngx_palloc(pool, size);\n if (p) {\n ngx_memzero(p, size);\n }\n return p;\n}', 'void *\nngx_palloc(ngx_pool_t *pool, size_t size)\n{\n u_char *m;\n ngx_pool_t *p;\n if (size <= pool->max) {\n p = pool->current;\n do {\n m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT);\n if ((size_t) (p->d.end - m) >= size) {\n p->d.last = m + size;\n return m;\n }\n p = p->d.next;\n } while (p);\n return ngx_palloc_block(pool, size);\n }\n return ngx_palloc_large(pool, size);\n}']
34,976
0
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/http/ngx_http_upstream_round_robin.c/#L161
ngx_int_t ngx_http_upstream_init_round_robin(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us) { ngx_url_t u; ngx_uint_t i, j, n; ngx_http_upstream_server_t *server; ngx_http_upstream_rr_peers_t *peers, *backup; us->peer.init = ngx_http_upstream_init_round_robin_peer; if (us->servers) { server = us->servers->elts; n = 0; for (i = 0; i < us->servers->nelts; i++) { if (server[i].backup) { continue; } n += server[i].naddrs; } peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t) + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1)); if (peers == NULL) { return NGX_ERROR; } peers->single = (n == 1); peers->number = n; peers->name = &us->host; n = 0; for (i = 0; i < us->servers->nelts; i++) { for (j = 0; j < server[i].naddrs; j++) { if (server[i].backup) { continue; } peers->peer[n].sockaddr = server[i].addrs[j].sockaddr; peers->peer[n].socklen = server[i].addrs[j].socklen; peers->peer[n].name = server[i].addrs[j].name; peers->peer[n].max_fails = server[i].max_fails; peers->peer[n].fail_timeout = server[i].fail_timeout; peers->peer[n].down = server[i].down; peers->peer[n].weight = server[i].down ? 0 : server[i].weight; peers->peer[n].current_weight = peers->peer[n].weight; n++; } } us->peer.data = peers; ngx_sort(&peers->peer[0], (size_t) n, sizeof(ngx_http_upstream_rr_peer_t), ngx_http_upstream_cmp_servers); n = 0; for (i = 0; i < us->servers->nelts; i++) { if (!server[i].backup) { continue; } n += server[i].naddrs; } if (n == 0) { return NGX_OK; } backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t) + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1)); if (backup == NULL) { return NGX_ERROR; } peers->single = 0; backup->single = 0; backup->number = n; backup->name = &us->host; n = 0; for (i = 0; i < us->servers->nelts; i++) { for (j = 0; j < server[i].naddrs; j++) { if (!server[i].backup) { continue; } backup->peer[n].sockaddr = server[i].addrs[j].sockaddr; backup->peer[n].socklen = server[i].addrs[j].socklen; backup->peer[n].name = server[i].addrs[j].name; backup->peer[n].weight = server[i].weight; backup->peer[n].current_weight = server[i].weight; backup->peer[n].max_fails = server[i].max_fails; backup->peer[n].fail_timeout = server[i].fail_timeout; backup->peer[n].down = server[i].down; n++; } } peers->next = backup; ngx_sort(&backup->peer[0], (size_t) n, sizeof(ngx_http_upstream_rr_peer_t), ngx_http_upstream_cmp_servers); return NGX_OK; } if (us->port == 0 && us->default_port == 0) { ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "no port in upstream \"%V\" in %s:%ui", &us->host, us->file_name, us->line); return NGX_ERROR; } ngx_memzero(&u, sizeof(ngx_url_t)); u.host = us->host; u.port = (in_port_t) (us->port ? us->port : us->default_port); if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) { if (u.err) { ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "%s in upstream \"%V\" in %s:%ui", u.err, &us->host, us->file_name, us->line); } return NGX_ERROR; } n = u.naddrs; peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t) + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1)); if (peers == NULL) { return NGX_ERROR; } peers->single = (n == 1); peers->number = n; peers->name = &us->host; for (i = 0; i < u.naddrs; i++) { peers->peer[i].sockaddr = u.addrs[i].sockaddr; peers->peer[i].socklen = u.addrs[i].socklen; peers->peer[i].name = u.addrs[i].name; peers->peer[i].weight = 1; peers->peer[i].current_weight = 1; peers->peer[i].max_fails = 1; peers->peer[i].fail_timeout = 10; } us->peer.data = peers; return NGX_OK; }
['ngx_int_t\nngx_http_upstream_init_round_robin(ngx_conf_t *cf,\n ngx_http_upstream_srv_conf_t *us)\n{\n ngx_url_t u;\n ngx_uint_t i, j, n;\n ngx_http_upstream_server_t *server;\n ngx_http_upstream_rr_peers_t *peers, *backup;\n us->peer.init = ngx_http_upstream_init_round_robin_peer;\n if (us->servers) {\n server = us->servers->elts;\n n = 0;\n for (i = 0; i < us->servers->nelts; i++) {\n if (server[i].backup) {\n continue;\n }\n n += server[i].naddrs;\n }\n peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)\n + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));\n if (peers == NULL) {\n return NGX_ERROR;\n }\n peers->single = (n == 1);\n peers->number = n;\n peers->name = &us->host;\n n = 0;\n for (i = 0; i < us->servers->nelts; i++) {\n for (j = 0; j < server[i].naddrs; j++) {\n if (server[i].backup) {\n continue;\n }\n peers->peer[n].sockaddr = server[i].addrs[j].sockaddr;\n peers->peer[n].socklen = server[i].addrs[j].socklen;\n peers->peer[n].name = server[i].addrs[j].name;\n peers->peer[n].max_fails = server[i].max_fails;\n peers->peer[n].fail_timeout = server[i].fail_timeout;\n peers->peer[n].down = server[i].down;\n peers->peer[n].weight = server[i].down ? 0 : server[i].weight;\n peers->peer[n].current_weight = peers->peer[n].weight;\n n++;\n }\n }\n us->peer.data = peers;\n ngx_sort(&peers->peer[0], (size_t) n,\n sizeof(ngx_http_upstream_rr_peer_t),\n ngx_http_upstream_cmp_servers);\n n = 0;\n for (i = 0; i < us->servers->nelts; i++) {\n if (!server[i].backup) {\n continue;\n }\n n += server[i].naddrs;\n }\n if (n == 0) {\n return NGX_OK;\n }\n backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)\n + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));\n if (backup == NULL) {\n return NGX_ERROR;\n }\n peers->single = 0;\n backup->single = 0;\n backup->number = n;\n backup->name = &us->host;\n n = 0;\n for (i = 0; i < us->servers->nelts; i++) {\n for (j = 0; j < server[i].naddrs; j++) {\n if (!server[i].backup) {\n continue;\n }\n backup->peer[n].sockaddr = server[i].addrs[j].sockaddr;\n backup->peer[n].socklen = server[i].addrs[j].socklen;\n backup->peer[n].name = server[i].addrs[j].name;\n backup->peer[n].weight = server[i].weight;\n backup->peer[n].current_weight = server[i].weight;\n backup->peer[n].max_fails = server[i].max_fails;\n backup->peer[n].fail_timeout = server[i].fail_timeout;\n backup->peer[n].down = server[i].down;\n n++;\n }\n }\n peers->next = backup;\n ngx_sort(&backup->peer[0], (size_t) n,\n sizeof(ngx_http_upstream_rr_peer_t),\n ngx_http_upstream_cmp_servers);\n return NGX_OK;\n }\n if (us->port == 0 && us->default_port == 0) {\n ngx_log_error(NGX_LOG_EMERG, cf->log, 0,\n "no port in upstream \\"%V\\" in %s:%ui",\n &us->host, us->file_name, us->line);\n return NGX_ERROR;\n }\n ngx_memzero(&u, sizeof(ngx_url_t));\n u.host = us->host;\n u.port = (in_port_t) (us->port ? us->port : us->default_port);\n if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {\n if (u.err) {\n ngx_log_error(NGX_LOG_EMERG, cf->log, 0,\n "%s in upstream \\"%V\\" in %s:%ui",\n u.err, &us->host, us->file_name, us->line);\n }\n return NGX_ERROR;\n }\n n = u.naddrs;\n peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t)\n + sizeof(ngx_http_upstream_rr_peer_t) * (n - 1));\n if (peers == NULL) {\n return NGX_ERROR;\n }\n peers->single = (n == 1);\n peers->number = n;\n peers->name = &us->host;\n for (i = 0; i < u.naddrs; i++) {\n peers->peer[i].sockaddr = u.addrs[i].sockaddr;\n peers->peer[i].socklen = u.addrs[i].socklen;\n peers->peer[i].name = u.addrs[i].name;\n peers->peer[i].weight = 1;\n peers->peer[i].current_weight = 1;\n peers->peer[i].max_fails = 1;\n peers->peer[i].fail_timeout = 10;\n }\n us->peer.data = peers;\n return NGX_OK;\n}', 'ngx_int_t\nngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *p, *host;\n size_t len;\n in_port_t port;\n in_addr_t in_addr;\n ngx_uint_t i;\n struct hostent *h;\n struct sockaddr_in *sin;\n host = ngx_alloc(u->host.len + 1, pool->log);\n if (host == NULL) {\n return NGX_ERROR;\n }\n (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);\n port = htons(u->port);\n in_addr = inet_addr((char *) host);\n if (in_addr == INADDR_NONE) {\n h = gethostbyname((char *) host);\n ngx_free(host);\n if (h == NULL || h->h_addr_list[0] == NULL) {\n u->err = "host not found";\n return NGX_ERROR;\n }\n if (u->one_addr == 0) {\n for (i = 0; h->h_addr_list[i] != NULL; i++) { }\n } else {\n i = 1;\n }\n u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_peer_addr_t));\n if (u->addrs == NULL) {\n return NGX_ERROR;\n }\n u->naddrs = i;\n for (i = 0; h->h_addr_list[i] != NULL; i++) {\n sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));\n if (sin == NULL) {\n return NGX_ERROR;\n }\n sin->sin_family = AF_INET;\n sin->sin_port = port;\n sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);\n u->addrs[i].sockaddr = (struct sockaddr *) sin;\n u->addrs[i].socklen = sizeof(struct sockaddr_in);\n len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1;\n p = ngx_pnalloc(pool, len);\n if (p == NULL) {\n return NGX_ERROR;\n }\n len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1);\n u->addrs[i].name.len = len;\n u->addrs[i].name.data = p;\n }\n } else {\n ngx_free(host);\n u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));\n if (u->addrs == NULL) {\n return NGX_ERROR;\n }\n sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));\n if (sin == NULL) {\n return NGX_ERROR;\n }\n u->naddrs = 1;\n sin->sin_family = AF_INET;\n sin->sin_port = port;\n sin->sin_addr.s_addr = in_addr;\n u->addrs[0].sockaddr = (struct sockaddr *) sin;\n u->addrs[0].socklen = sizeof(struct sockaddr_in);\n p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1);\n if (p == NULL) {\n return NGX_ERROR;\n }\n u->addrs[0].name.len = ngx_sprintf(p, "%V:%d",\n &u->host, ntohs(port)) - p;\n u->addrs[0].name.data = p;\n }\n return NGX_OK;\n}']
34,977
0
https://github.com/libav/libav/blob/fc322d6a70189da24dbd445c710bb214eb031ce7/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 read_channel_params(MLPDecodeContext *m, unsigned int substr,\n BitstreamContext *bc, unsigned int ch)\n{\n SubStream *s = &m->substream[substr];\n ChannelParams *cp = &s->channel_params[ch];\n FilterParams *fir = &cp->filter_params[FIR];\n FilterParams *iir = &cp->filter_params[IIR];\n int ret;\n if (s->param_presence_flags & PARAM_FIR)\n if (bitstream_read_bit(bc))\n if ((ret = read_filter_params(m, bc, substr, ch, FIR)) < 0)\n return ret;\n if (s->param_presence_flags & PARAM_IIR)\n if (bitstream_read_bit(bc))\n if ((ret = read_filter_params(m, bc, substr, ch, IIR)) < 0)\n return ret;\n if (fir->order + iir->order > 8) {\n av_log(m->avctx, AV_LOG_ERROR, "Total filter orders too high.\\n");\n return AVERROR_INVALIDDATA;\n }\n if (fir->order && iir->order &&\n fir->shift != iir->shift) {\n av_log(m->avctx, AV_LOG_ERROR,\n "FIR and IIR filters must use the same precision.\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!fir->order && iir->order)\n fir->shift = iir->shift;\n if (s->param_presence_flags & PARAM_HUFFOFFSET)\n if (bitstream_read_bit(bc))\n cp->huff_offset = bitstream_read_signed(bc, 15);\n cp->codebook = bitstream_read(bc, 2);\n cp->huff_lsbs = bitstream_read(bc, 5);\n if (cp->huff_lsbs > 24) {\n av_log(m->avctx, AV_LOG_ERROR, "Invalid huff_lsbs.\\n");\n return AVERROR_INVALIDDATA;\n }\n cp->sign_huff_offset = calculate_sign_huff(m, substr, ch);\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}']
34,978
0
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/crypto/bn/bn_shift.c/#L113
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_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_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 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}']
34,979
0
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_md5.c/#L48
void ngx_md5_update(ngx_md5_t *ctx, const void *data, size_t size) { size_t used, free; used = (size_t) (ctx->bytes & 0x3f); ctx->bytes += size; if (used) { free = 64 - used; if (size < free) { ngx_memcpy(&ctx->buffer[used], data, size); return; } ngx_memcpy(&ctx->buffer[used], data, free); data = (u_char *) data + free; size -= free; (void) ngx_md5_body(ctx, ctx->buffer, 64); } if (size >= 64) { data = ngx_md5_body(ctx, data, size & ~(size_t) 0x3f); size &= 0x3f; } ngx_memcpy(ctx->buffer, data, size); }
['void\nngx_http_file_cache_create_key(ngx_http_request_t *r)\n{\n size_t len;\n ngx_str_t *key;\n ngx_uint_t i;\n ngx_md5_t md5;\n ngx_http_cache_t *c;\n c = r->cache;\n len = 0;\n ngx_crc32_init(c->crc32);\n ngx_md5_init(&md5);\n key = c->keys.elts;\n for (i = 0; i < c->keys.nelts; i++) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http cache key: \\"%V\\"", &key[i]);\n len += key[i].len;\n ngx_crc32_update(&c->crc32, key[i].data, key[i].len);\n ngx_md5_update(&md5, key[i].data, key[i].len);\n }\n c->header_start = sizeof(ngx_http_file_cache_header_t)\n + sizeof(ngx_http_file_cache_key) + len + 1;\n ngx_crc32_final(c->crc32);\n ngx_md5_final(c->key, &md5);\n ngx_memcpy(c->main, c->key, NGX_HTTP_CACHE_KEY_LEN);\n}', 'void\nngx_md5_init(ngx_md5_t *ctx)\n{\n ctx->a = 0x67452301;\n ctx->b = 0xefcdab89;\n ctx->c = 0x98badcfe;\n ctx->d = 0x10325476;\n ctx->bytes = 0;\n}', 'void\nngx_md5_update(ngx_md5_t *ctx, const void *data, size_t size)\n{\n size_t used, free;\n used = (size_t) (ctx->bytes & 0x3f);\n ctx->bytes += size;\n if (used) {\n free = 64 - used;\n if (size < free) {\n ngx_memcpy(&ctx->buffer[used], data, size);\n return;\n }\n ngx_memcpy(&ctx->buffer[used], data, free);\n data = (u_char *) data + free;\n size -= free;\n (void) ngx_md5_body(ctx, ctx->buffer, 64);\n }\n if (size >= 64) {\n data = ngx_md5_body(ctx, data, size & ~(size_t) 0x3f);\n size &= 0x3f;\n }\n ngx_memcpy(ctx->buffer, data, size);\n}']
34,980
0
https://github.com/openssl/openssl/blob/a21285b3636a8356f01027416b0cd43b016f58ca/crypto/bn/bn_lib.c/#L232
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return NULL; } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return NULL; } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int bn_probable_prime_dh(BIGNUM *rnd, int bits,\n const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *t1;\n BN_CTX_start(ctx);\n if ((t1 = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_rand(rnd, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n goto err;\n if (!BN_mod(t1, rnd, add, ctx))\n goto err;\n if (!BN_sub(rnd, rnd, t1))\n goto err;\n if (rem == NULL) {\n if (!BN_add_word(rnd, 1))\n goto err;\n } else {\n if (!BN_add(rnd, rnd, rem))\n goto err;\n }\n loop:\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(rnd, (BN_ULONG)primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod <= 1) {\n if (!BN_add(rnd, rnd, add))\n goto err;\n goto loop;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(rnd);\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 a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
34,981
0
https://github.com/openssl/openssl/blob/49cd47eaababc8c57871b929080fc1357e2ad7b8/crypto/err/err.c/#L480
static unsigned long get_error_values(int inc, int top, const char **file, int *line, const char **data, int *flags) { int i = 0; ERR_STATE *es; unsigned long ret; es = ERR_get_state(); if (es == NULL) return 0; if (inc && top) { if (file) *file = ""; if (line) *line = 0; if (data) *data = ""; if (flags) *flags = 0; return ERR_R_INTERNAL_ERROR; } if (es->bottom == es->top) return 0; if (top) i = es->top; else i = (es->bottom + 1) % ERR_NUM_ERRORS; ret = es->err_buffer[i]; if (inc) { es->bottom = i; es->err_buffer[i] = 0; } if (file != NULL && line != NULL) { if (es->err_file[i] == NULL) { *file = "NA"; *line = 0; } else { *file = es->err_file[i]; *line = es->err_line[i]; } } if (data == NULL) { if (inc) { err_clear_data(es, i); } } else { if (es->err_data[i] == NULL) { *data = ""; if (flags != NULL) *flags = 0; } else { *data = es->err_data[i]; if (flags != NULL) *flags = es->err_data_flags[i]; } } return ret; }
['static unsigned long get_error_values(int inc, int top, const char **file,\n int *line, const char **data,\n int *flags)\n{\n int i = 0;\n ERR_STATE *es;\n unsigned long ret;\n es = ERR_get_state();\n if (es == NULL)\n return 0;\n if (inc && top) {\n if (file)\n *file = "";\n if (line)\n *line = 0;\n if (data)\n *data = "";\n if (flags)\n *flags = 0;\n return ERR_R_INTERNAL_ERROR;\n }\n if (es->bottom == es->top)\n return 0;\n if (top)\n i = es->top;\n else\n i = (es->bottom + 1) % ERR_NUM_ERRORS;\n ret = es->err_buffer[i];\n if (inc) {\n es->bottom = i;\n es->err_buffer[i] = 0;\n }\n if (file != NULL && line != NULL) {\n if (es->err_file[i] == NULL) {\n *file = "NA";\n *line = 0;\n } else {\n *file = es->err_file[i];\n *line = es->err_line[i];\n }\n }\n if (data == NULL) {\n if (inc) {\n err_clear_data(es, i);\n }\n } else {\n if (es->err_data[i] == NULL) {\n *data = "";\n if (flags != NULL)\n *flags = 0;\n } else {\n *data = es->err_data[i];\n if (flags != NULL)\n *flags = es->err_data_flags[i];\n }\n }\n return ret;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n if (!OPENSSL_init_crypto(0, NULL))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)\n || !CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}']
34,982
0
https://github.com/openssl/openssl/blob/85bcf27cccd8f5f569886479ad96a0c33444404c/crypto/lhash/lhash.c/#L281
static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) { int i; LHASH_NODE *a,*n; if (lh == NULL) return; for (i=lh->num_nodes-1; i>=0; i--) { a=lh->b[i]; while (a != NULL) { n=a->next; if(use_arg) func_arg(a->data,arg); else func(a->data); a=n; } } }
['static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)\n\t{\n\tSSL **sslp,*ssl;\n\tBIO_SSL *bs;\n\tBIO *dbio,*bio;\n\tlong ret=1;\n\tbs=(BIO_SSL *)b->ptr;\n\tssl=bs->ssl;\n\tif ((ssl == NULL) && (cmd != BIO_C_SET_SSL))\n\t\treturn(0);\n\tswitch (cmd)\n\t\t{\n\tcase BIO_CTRL_RESET:\n\t\tSSL_shutdown(ssl);\n\t\tif (ssl->handshake_func == ssl->method->ssl_connect)\n\t\t\tSSL_set_connect_state(ssl);\n\t\telse if (ssl->handshake_func == ssl->method->ssl_accept)\n\t\t\tSSL_set_accept_state(ssl);\n\t\tSSL_clear(ssl);\n\t\tif (b->next_bio != NULL)\n\t\t\tret=BIO_ctrl(b->next_bio,cmd,num,ptr);\n\t\telse if (ssl->rbio != NULL)\n\t\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\telse\n\t\t\tret=1;\n\t\tbreak;\n\tcase BIO_CTRL_INFO:\n\t\tret=0;\n\t\tbreak;\n\tcase BIO_C_SSL_MODE:\n\t\tif (num)\n\t\t\tSSL_set_connect_state(ssl);\n\t\telse\n\t\t\tSSL_set_accept_state(ssl);\n\t\tbreak;\n\tcase BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:\n\t\tret=bs->renegotiate_timeout;\n\t\tif (num < 60) num=5;\n\t\tbs->renegotiate_timeout=(unsigned long)num;\n\t\tbs->last_time=(unsigned long)time(NULL);\n\t\tbreak;\n\tcase BIO_C_SET_SSL_RENEGOTIATE_BYTES:\n\t\tret=bs->renegotiate_count;\n\t\tif ((long)num >=512)\n\t\t\tbs->renegotiate_count=(unsigned long)num;\n\t\tbreak;\n\tcase BIO_C_GET_SSL_NUM_RENEGOTIATES:\n\t\tret=bs->num_renegotiates;\n\t\tbreak;\n\tcase BIO_C_SET_SSL:\n\t\tif (ssl != NULL)\n\t\t\t{\n\t\t\tssl_free(b);\n\t\t\tif (!ssl_new(b))\n\t\t\t\treturn 0;\n\t\t\t}\n\t\tb->shutdown=(int)num;\n\t\tssl=(SSL *)ptr;\n\t\t((BIO_SSL *)b->ptr)->ssl=ssl;\n\t\tbio=SSL_get_rbio(ssl);\n\t\tif (bio != NULL)\n\t\t\t{\n\t\t\tif (b->next_bio != NULL)\n\t\t\t\tBIO_push(bio,b->next_bio);\n\t\t\tb->next_bio=bio;\n\t\t\tCRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);\n\t\t\t}\n\t\tb->init=1;\n\t\tbreak;\n\tcase BIO_C_GET_SSL:\n\t\tif (ptr != NULL)\n\t\t\t{\n\t\t\tsslp=(SSL **)ptr;\n\t\t\t*sslp=ssl;\n\t\t\t}\n\t\telse\n\t\t\tret=0;\n\t\tbreak;\n\tcase BIO_CTRL_GET_CLOSE:\n\t\tret=b->shutdown;\n\t\tbreak;\n\tcase BIO_CTRL_SET_CLOSE:\n\t\tb->shutdown=(int)num;\n\t\tbreak;\n\tcase BIO_CTRL_WPENDING:\n\t\tret=BIO_ctrl(ssl->wbio,cmd,num,ptr);\n\t\tbreak;\n\tcase BIO_CTRL_PENDING:\n\t\tret=SSL_pending(ssl);\n\t\tif (ret == 0)\n\t\t\tret=BIO_pending(ssl->rbio);\n\t\tbreak;\n\tcase BIO_CTRL_FLUSH:\n\t\tBIO_clear_retry_flags(b);\n\t\tret=BIO_ctrl(ssl->wbio,cmd,num,ptr);\n\t\tBIO_copy_next_retry(b);\n\t\tbreak;\n\tcase BIO_CTRL_PUSH:\n\t\tif ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))\n\t\t\t{\n\t\t\tSSL_set_bio(ssl,b->next_bio,b->next_bio);\n\t\t\tCRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);\n\t\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_POP:\n\t\tif (b == ptr)\n\t\t\t{\n\t\t\tif (ssl->rbio != ssl->wbio)\n\t\t\t\tBIO_free_all(ssl->wbio);\n\t\t\tif (b->next_bio != NULL)\n\t\t\t\tCRYPTO_add(&b->next_bio->references,-1,CRYPTO_LOCK_BIO);\n\t\t\tssl->wbio=NULL;\n\t\t\tssl->rbio=NULL;\n\t\t\t}\n\t\tbreak;\n\tcase BIO_C_DO_STATE_MACHINE:\n\t\tBIO_clear_retry_flags(b);\n\t\tb->retry_reason=0;\n\t\tret=(int)SSL_do_handshake(ssl);\n\t\tswitch (SSL_get_error(ssl,(int)ret))\n\t\t\t{\n\t\tcase SSL_ERROR_WANT_READ:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tbreak;\n\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tbreak;\n\t\tcase SSL_ERROR_WANT_CONNECT:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tb->retry_reason=b->next_bio->retry_reason;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_DUP:\n\t\tdbio=(BIO *)ptr;\n\t\tif (((BIO_SSL *)dbio->ptr)->ssl != NULL)\n\t\t\tSSL_free(((BIO_SSL *)dbio->ptr)->ssl);\n\t\t((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);\n\t\t((BIO_SSL *)dbio->ptr)->renegotiate_count=\n\t\t\t((BIO_SSL *)b->ptr)->renegotiate_count;\n\t\t((BIO_SSL *)dbio->ptr)->byte_count=\n\t\t\t((BIO_SSL *)b->ptr)->byte_count;\n\t\t((BIO_SSL *)dbio->ptr)->renegotiate_timeout=\n\t\t\t((BIO_SSL *)b->ptr)->renegotiate_timeout;\n\t\t((BIO_SSL *)dbio->ptr)->last_time=\n\t\t\t((BIO_SSL *)b->ptr)->last_time;\n\t\tret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);\n\t\tbreak;\n\tcase BIO_C_GET_FD:\n\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\tbreak;\n\tcase BIO_CTRL_SET_CALLBACK:\n\t\t{\n#if 0\n\t\tSSLerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\tret = -1;\n#else\n\t\tret=0;\n#endif\n\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_GET_CALLBACK:\n\t\t{\n\t\tvoid (**fptr)(const SSL *xssl,int type,int val);\n\t\tfptr=(void (**)(const SSL *xssl,int type,int val))ptr;\n\t\t*fptr=SSL_get_info_callback(ssl);\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\tbreak;\n\t\t}\n\treturn(ret);\n\t}', 'void SSL_free(SSL *s)\n\t{\n\tint i;\n\tif(s == NULL)\n\t return;\n\ti=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);\n#ifdef REF_PRINT\n\tREF_PRINT("SSL",s);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"SSL_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tif (s->param)\n\t\tX509_VERIFY_PARAM_free(s->param);\n\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n\tif (s->bbio != NULL)\n\t\t{\n\t\tif (s->bbio == s->wbio)\n\t\t\t{\n\t\t\ts->wbio=BIO_pop(s->wbio);\n\t\t\t}\n\t\tBIO_free(s->bbio);\n\t\ts->bbio=NULL;\n\t\t}\n\tif (s->rbio != NULL)\n\t\tBIO_free_all(s->rbio);\n\tif ((s->wbio != NULL) && (s->wbio != s->rbio))\n\t\tBIO_free_all(s->wbio);\n\tif (s->init_buf != NULL) BUF_MEM_free(s->init_buf);\n\tif (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);\n\tif (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);\n\tif (s->session != NULL)\n\t\t{\n\t\tssl_clear_bad_session(s);\n\t\tSSL_SESSION_free(s->session);\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tssl_clear_hash_ctx(&s->read_hash);\n\tssl_clear_hash_ctx(&s->write_hash);\n\tif (s->cert != NULL) ssl_cert_free(s->cert);\n#ifndef OPENSSL_NO_TLSEXT\n\tif (s->tlsext_hostname)\n\t\tOPENSSL_free(s->tlsext_hostname);\n\tif (s->initial_ctx) SSL_CTX_free(s->initial_ctx);\n#ifndef OPENSSL_NO_EC\n\tif (s->tlsext_ecpointformatlist) OPENSSL_free(s->tlsext_ecpointformatlist);\n\tif (s->tlsext_ellipticcurvelist) OPENSSL_free(s->tlsext_ellipticcurvelist);\n#endif\n\tif (s->tlsext_opaque_prf_input) OPENSSL_free(s->tlsext_opaque_prf_input);\n\tif (s->tlsext_ocsp_exts)\n\t\tsk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,\n\t\t\t\t\t\tX509_EXTENSION_free);\n\tif (s->tlsext_ocsp_ids)\n\t\tsk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n\tif (s->tlsext_ocsp_resp)\n\t\tOPENSSL_free(s->tlsext_ocsp_resp);\n\tif (s->alpn_client_proto_list)\n\t\tOPENSSL_free(s->alpn_client_proto_list);\n#endif\n\tif (s->client_CA != NULL)\n\t\tsk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);\n\tif (s->method != NULL) s->method->ssl_free(s);\n\tif (s->ctx) SSL_CTX_free(s->ctx);\n#ifndef\tOPENSSL_NO_KRB5\n\tif (s->kssl_ctx != NULL)\n\t\tkssl_ctx_free(s->kssl_ctx);\n#endif\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n\tif (s->next_proto_negotiated)\n\t\tOPENSSL_free(s->next_proto_negotiated);\n#endif\n if (s->srtp_profiles)\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n\tOPENSSL_free(s);\n\t}', 'SSL *SSL_dup(SSL *s)\n\t{\n\tSTACK_OF(X509_NAME) *sk;\n\tX509_NAME *xn;\n\tSSL *ret;\n\tint i;\n\tif ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)\n\t return(NULL);\n\tret->version = s->version;\n\tret->type = s->type;\n\tret->method = s->method;\n\tif (s->session != NULL)\n\t\t{\n\t\tSSL_copy_session_id(ret,s);\n\t\t}\n\telse\n\t\t{\n\t\tret->method->ssl_free(ret);\n\t\tret->method = s->method;\n\t\tret->method->ssl_new(ret);\n\t\tif (s->cert != NULL)\n\t\t\t{\n\t\t\tif (ret->cert != NULL)\n\t\t\t\t{\n\t\t\t\tssl_cert_free(ret->cert);\n\t\t\t\t}\n\t\t\tret->cert = ssl_cert_dup(s->cert);\n\t\t\tif (ret->cert == NULL)\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tSSL_set_session_id_context(ret,\n\t\t\ts->sid_ctx, s->sid_ctx_length);\n\t\t}\n\tret->options=s->options;\n\tret->mode=s->mode;\n\tSSL_set_max_cert_list(ret,SSL_get_max_cert_list(s));\n\tSSL_set_read_ahead(ret,SSL_get_read_ahead(s));\n\tret->msg_callback = s->msg_callback;\n\tret->msg_callback_arg = s->msg_callback_arg;\n\tSSL_set_verify(ret,SSL_get_verify_mode(s),\n\t\tSSL_get_verify_callback(s));\n\tSSL_set_verify_depth(ret,SSL_get_verify_depth(s));\n\tret->generate_session_id = s->generate_session_id;\n\tSSL_set_info_callback(ret,SSL_get_info_callback(s));\n\tret->debug=s->debug;\n\tif (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL, &ret->ex_data, &s->ex_data))\n\t\tgoto err;\n\tif (s->rbio != NULL)\n\t\t{\n\t\tif (!BIO_dup_state(s->rbio,(char *)&ret->rbio))\n\t\t\tgoto err;\n\t\t}\n\tif (s->wbio != NULL)\n\t\t{\n\t\tif (s->wbio != s->rbio)\n\t\t\t{\n\t\t\tif (!BIO_dup_state(s->wbio,(char *)&ret->wbio))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\telse\n\t\t\tret->wbio=ret->rbio;\n\t\t}\n\tret->rwstate = s->rwstate;\n\tret->in_handshake = s->in_handshake;\n\tret->handshake_func = s->handshake_func;\n\tret->server = s->server;\n\tret->renegotiate = s->renegotiate;\n\tret->new_session = s->new_session;\n\tret->quiet_shutdown = s->quiet_shutdown;\n\tret->shutdown=s->shutdown;\n\tret->state=s->state;\n\tret->rstate=s->rstate;\n\tret->init_num = 0;\n\tret->hit=s->hit;\n\tX509_VERIFY_PARAM_inherit(ret->param, s->param);\n\tif (s->cipher_list != NULL)\n\t\t{\n\t\tif ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)\n\t\t\tgoto err;\n\t\t}\n\tif (s->cipher_list_by_id != NULL)\n\t\tif ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))\n\t\t\t== NULL)\n\t\t\tgoto err;\n\tif (s->client_CA != NULL)\n\t\t{\n\t\tif ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;\n\t\tret->client_CA=sk;\n\t\tfor (i=0; i<sk_X509_NAME_num(sk); i++)\n\t\t\t{\n\t\t\txn=sk_X509_NAME_value(sk,i);\n\t\t\tif (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)\n\t\t\t\t{\n\t\t\t\tX509_NAME_free(xn);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (0)\n\t\t{\nerr:\n\t\tif (ret != NULL) SSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->max_cert_list=ctx->max_cert_list;\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->read_ahead=ctx->read_ahead;\n\ts->msg_callback=ctx->msg_callback;\n\ts->msg_callback_arg=ctx->msg_callback_arg;\n\ts->verify_mode=ctx->verify_mode;\n\ts->not_resumable_session_cb=ctx->not_resumable_session_cb;\n#if 0\n\ts->verify_depth=ctx->verify_depth;\n#endif\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tOPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->param = X509_VERIFY_PARAM_new();\n\tif (!s->param)\n\t\tgoto err;\n\tX509_VERIFY_PARAM_inherit(s->param, ctx->param);\n#if 0\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n#endif\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->max_send_fragment = ctx->max_send_fragment;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n#ifndef OPENSSL_NO_TLSEXT\n\ts->tlsext_debug_cb = 0;\n\ts->tlsext_debug_arg = NULL;\n\ts->tlsext_ticket_expected = 0;\n\ts->tlsext_status_type = -1;\n\ts->tlsext_status_expected = 0;\n\ts->tlsext_ocsp_ids = NULL;\n\ts->tlsext_ocsp_exts = NULL;\n\ts->tlsext_ocsp_resp = NULL;\n\ts->tlsext_ocsp_resplen = -1;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->initial_ctx=ctx;\n#ifndef OPENSSL_NO_EC\n\tif (ctx->tlsext_ecpointformatlist)\n\t\t{\n\t\ts->tlsext_ecpointformatlist =\n\t\t\tBUF_memdup(ctx->tlsext_ecpointformatlist,\n\t\t\t\t\tctx->tlsext_ecpointformatlist_length);\n\t\tif (!s->tlsext_ecpointformatlist)\n\t\t\tgoto err;\n\t\ts->tlsext_ecpointformatlist_length =\n\t\t\t\t\tctx->tlsext_ecpointformatlist_length;\n\t\t}\n\tif (ctx->tlsext_ellipticcurvelist)\n\t\t{\n\t\ts->tlsext_ellipticcurvelist =\n\t\t\tBUF_memdup(ctx->tlsext_ellipticcurvelist,\n\t\t\t\t\tctx->tlsext_ellipticcurvelist_length);\n\t\tif (!s->tlsext_ellipticcurvelist)\n\t\t\tgoto err;\n\t\ts->tlsext_ellipticcurvelist_length =\n\t\t\t\t\tctx->tlsext_ellipticcurvelist_length;\n\t\t}\n#endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\ts->next_proto_negotiated = NULL;\n# endif\n\tif (s->ctx->alpn_client_proto_list)\n\t\t{\n\t\ts->alpn_client_proto_list =\n\t\t\tOPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n\t\tif (s->alpn_client_proto_list == NULL)\n\t\t\tgoto err;\n\t\tmemcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n\t\t s->ctx->alpn_client_proto_list_len);\n\t\ts->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n\t\t}\n#endif\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n#ifndef OPENSSL_NO_PSK\n\ts->psk_client_callback=ctx->psk_client_callback;\n\ts->psk_server_callback=ctx->psk_server_callback;\n#endif\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\tSSL_free(s);\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'void SSL_CTX_free(SSL_CTX *a)\n\t{\n\tint i;\n\tif (a == NULL) return;\n\ti=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);\n#ifdef REF_PRINT\n\tREF_PRINT("SSL_CTX",a);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"SSL_CTX_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tif (a->param)\n\t\tX509_VERIFY_PARAM_free(a->param);\n\tif (a->sessions != NULL)\n\t\tSSL_CTX_flush_sessions(a,0);\n\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n\tif (a->sessions != NULL)\n\t\tlh_SSL_SESSION_free(a->sessions);\n\tif (a->cert_store != NULL)\n\t\tX509_STORE_free(a->cert_store);\n\tif (a->cipher_list != NULL)\n\t\tsk_SSL_CIPHER_free(a->cipher_list);\n\tif (a->cipher_list_by_id != NULL)\n\t\tsk_SSL_CIPHER_free(a->cipher_list_by_id);\n\tif (a->cert != NULL)\n\t\tssl_cert_free(a->cert);\n\tif (a->client_CA != NULL)\n\t\tsk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);\n\tif (a->extra_certs != NULL)\n\t\tsk_X509_pop_free(a->extra_certs,X509_free);\n#if 0\n\tif (a->comp_methods != NULL)\n\t\tsk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);\n#else\n\ta->comp_methods = NULL;\n#endif\n if (a->srtp_profiles)\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#ifndef OPENSSL_NO_PSK\n\tif (a->psk_identity_hint)\n\t\tOPENSSL_free(a->psk_identity_hint);\n#endif\n#ifndef OPENSSL_NO_SRP\n\tSSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n\tif (a->client_cert_engine)\n\t\tENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_BUF_FREELISTS\n\tif (a->wbuf_freelist)\n\t\tssl_buf_freelist_free(a->wbuf_freelist);\n\tif (a->rbuf_freelist)\n\t\tssl_buf_freelist_free(a->rbuf_freelist);\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n# ifndef OPENSSL_NO_EC\n\tif (a->tlsext_ecpointformatlist)\n\t\tOPENSSL_free(a->tlsext_ecpointformatlist);\n\tif (a->tlsext_ellipticcurvelist)\n\t\tOPENSSL_free(a->tlsext_ellipticcurvelist);\n# endif\n\tif (a->alpn_client_proto_list != NULL)\n\t\tOPENSSL_free(a->alpn_client_proto_list);\n#endif\n\tOPENSSL_free(a);\n\t}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n\t{\n\tunsigned long i;\n\tTIMEOUT_PARAM tp;\n\ttp.ctx=s;\n\ttp.cache=s->sessions;\n\tif (tp.cache == NULL) return;\n\ttp.time=t;\n\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\ti=CHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load;\n\tCHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=0;\n\tlh_SSL_SESSION_doall_arg(tp.cache, LHASH_DOALL_ARG_FN(timeout),\n\t\t\t\t TIMEOUT_PARAM, &tp);\n\tCHECKED_LHASH_OF(SSL_SESSION, tp.cache)->down_load=i;\n\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t}', 'void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n\t{\n\tdoall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n\t}', 'static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n\t\t\t LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tif (lh == NULL)\n\t\treturn;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tif(use_arg)\n\t\t\t\tfunc_arg(a->data,arg);\n\t\t\telse\n\t\t\t\tfunc(a->data);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
34,983
0
https://github.com/libav/libav/blob/5718e3487ba3b26aba341070be0b6b0b4de45ea3/libavformat/rtpdec_qdm2.c/#L207
static int qdm2_restore_block(PayloadContext *qdm, AVStream *st, AVPacket *pkt) { int to_copy, n, res, include_csum; uint8_t *p, *csum_pos = NULL; assert(qdm->cache > 0); for (n = 0; n < 0x80; n++) if (qdm->len[n] > 0) break; assert(n < 0x80); if ((res = av_new_packet(pkt, qdm->block_size)) < 0) return res; memset(pkt->data, 0, pkt->size); pkt->stream_index = st->index; p = pkt->data; if (qdm->len[n] > 0xff) { *p++ = qdm->block_type | 0x80; AV_WB16(p, qdm->len[n]); p += 2; } else { *p++ = qdm->block_type; *p++ = qdm->len[n]; } if ((include_csum = (qdm->block_type == 2 || qdm->block_type == 4))) { csum_pos = p; p += 2; } to_copy = FFMIN(qdm->len[n], pkt->size - (p - pkt->data)); memcpy(p, qdm->buf[n], to_copy); qdm->len[n] = 0; if (include_csum) { unsigned int total = 0; uint8_t *q; for (q = pkt->data; q < &pkt->data[qdm->block_size]; q++) total += *q; AV_WB16(csum_pos, (uint16_t) total); } return 0; }
['static int qdm2_restore_block(PayloadContext *qdm, AVStream *st, AVPacket *pkt)\n{\n int to_copy, n, res, include_csum;\n uint8_t *p, *csum_pos = NULL;\n assert(qdm->cache > 0);\n for (n = 0; n < 0x80; n++)\n if (qdm->len[n] > 0)\n break;\n assert(n < 0x80);\n if ((res = av_new_packet(pkt, qdm->block_size)) < 0)\n return res;\n memset(pkt->data, 0, pkt->size);\n pkt->stream_index = st->index;\n p = pkt->data;\n if (qdm->len[n] > 0xff) {\n *p++ = qdm->block_type | 0x80;\n AV_WB16(p, qdm->len[n]);\n p += 2;\n } else {\n *p++ = qdm->block_type;\n *p++ = qdm->len[n];\n }\n if ((include_csum = (qdm->block_type == 2 || qdm->block_type == 4))) {\n csum_pos = p;\n p += 2;\n }\n to_copy = FFMIN(qdm->len[n], pkt->size - (p - pkt->data));\n memcpy(p, qdm->buf[n], to_copy);\n qdm->len[n] = 0;\n if (include_csum) {\n unsigned int total = 0;\n uint8_t *q;\n for (q = pkt->data; q < &pkt->data[qdm->block_size]; q++)\n total += *q;\n AV_WB16(csum_pos, (uint16_t) total);\n }\n return 0;\n}']
34,984
0
https://github.com/openssl/openssl/blob/02703c74a4c10f3848cdd5e7ff5196ab45c7e67e/engines/e_sureware.c/#L709
static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype) { EVP_PKEY *res = NULL; #ifndef OPENSSL_NO_RSA RSA *rsatmp = NULL; #endif #ifndef OPENSSL_NO_DSA DSA *dsatmp=NULL; #endif char msg[64]="sureware_load_public"; int ret=0; if(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey) { SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_NOT_INITIALISED); goto err; } switch (keytype) { #ifndef OPENSSL_NO_RSA case 1: rsatmp = RSA_new_method(e); RSA_set_ex_data(rsatmp,rsaHndidx,hptr); rsatmp->flags |= RSA_FLAG_EXT_PKEY; rsatmp->e = BN_new(); rsatmp->n = BN_new(); bn_expand2(rsatmp->e, el/sizeof(BN_ULONG)); bn_expand2(rsatmp->n, el/sizeof(BN_ULONG)); if (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))|| !rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG))) goto err; ret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el, (unsigned long *)rsatmp->n->d, (unsigned long *)rsatmp->e->d); surewarehk_error_handling(msg,SUREWARE_F_SUREWARE_LOAD_PUBLIC,ret); if (ret!=1) { SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); goto err; } rsatmp->e->top=el/sizeof(BN_ULONG); bn_fix_top(rsatmp->e); rsatmp->n->top=el/sizeof(BN_ULONG); bn_fix_top(rsatmp->n); res = EVP_PKEY_new(); EVP_PKEY_assign_RSA(res, rsatmp); break; #endif #ifndef OPENSSL_NO_DSA case 2: dsatmp = DSA_new_method(e); DSA_set_ex_data(dsatmp,dsaHndidx,hptr); dsatmp->pub_key = BN_new(); dsatmp->p = BN_new(); dsatmp->q = BN_new(); dsatmp->g = BN_new(); bn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG)); bn_expand2(dsatmp->p, el/sizeof(BN_ULONG)); bn_expand2(dsatmp->q, 20/sizeof(BN_ULONG)); bn_expand2(dsatmp->g, el/sizeof(BN_ULONG)); if (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))|| !dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) || !dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) || !dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG))) goto err; ret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el, (unsigned long *)dsatmp->pub_key->d, (unsigned long *)dsatmp->p->d, (unsigned long *)dsatmp->q->d, (unsigned long *)dsatmp->g->d); surewarehk_error_handling(msg,SUREWARE_F_SUREWARE_LOAD_PUBLIC,ret); if (ret!=1) { SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PUBLIC_KEY); goto err; } dsatmp->pub_key->top=el/sizeof(BN_ULONG); bn_fix_top(dsatmp->pub_key); dsatmp->p->top=el/sizeof(BN_ULONG); bn_fix_top(dsatmp->p); dsatmp->q->top=20/sizeof(BN_ULONG); bn_fix_top(dsatmp->q); dsatmp->g->top=el/sizeof(BN_ULONG); bn_fix_top(dsatmp->g); res = EVP_PKEY_new(); EVP_PKEY_assign_DSA(res, dsatmp); break; #endif default: SUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PRIVATE_KEY); goto err; } return res; err: if (res) EVP_PKEY_free(res); #ifndef OPENSSL_NO_RSA if (rsatmp) RSA_free(rsatmp); #endif #ifndef OPENSSL_NO_DSA if (dsatmp) DSA_free(dsatmp); #endif return NULL; }
['static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype)\n{\n\tEVP_PKEY *res = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsatmp = NULL;\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsatmp=NULL;\n#endif\n\tchar msg[64]="sureware_load_public";\n\tint ret=0;\n\tif(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey)\n\t{\n\t\tSUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_NOT_INITIALISED);\n\t\tgoto err;\n\t}\n\tswitch (keytype)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tcase 1:\n\t\trsatmp = RSA_new_method(e);\n\t\tRSA_set_ex_data(rsatmp,rsaHndidx,hptr);\n\t\trsatmp->flags |= RSA_FLAG_EXT_PKEY;\n\t\trsatmp->e = BN_new();\n\t\trsatmp->n = BN_new();\n\t\tbn_expand2(rsatmp->e, el/sizeof(BN_ULONG));\n\t\tbn_expand2(rsatmp->n, el/sizeof(BN_ULONG));\n\t\tif (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))||\n\t\t\t!rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG)))\n\t\t\tgoto err;\n\t\tret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el,\n\t\t\t\t\t\t (unsigned long *)rsatmp->n->d,\n\t\t\t\t\t\t (unsigned long *)rsatmp->e->d);\n\t\tsurewarehk_error_handling(msg,SUREWARE_F_SUREWARE_LOAD_PUBLIC,ret);\n\t\tif (ret!=1)\n\t\t{\n\t\t\tSUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);\n\t\t\tgoto err;\n\t\t}\n\t\trsatmp->e->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(rsatmp->e);\n\t\trsatmp->n->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(rsatmp->n);\n\t\tres = EVP_PKEY_new();\n\t\tEVP_PKEY_assign_RSA(res, rsatmp);\n\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_DSA\n\tcase 2:\n\t\tdsatmp = DSA_new_method(e);\n\t\tDSA_set_ex_data(dsatmp,dsaHndidx,hptr);\n\t\tdsatmp->pub_key = BN_new();\n\t\tdsatmp->p = BN_new();\n\t\tdsatmp->q = BN_new();\n\t\tdsatmp->g = BN_new();\n\t\tbn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG));\n\t\tbn_expand2(dsatmp->p, el/sizeof(BN_ULONG));\n\t\tbn_expand2(dsatmp->q, 20/sizeof(BN_ULONG));\n\t\tbn_expand2(dsatmp->g, el/sizeof(BN_ULONG));\n\t\tif (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))||\n\t\t\t!dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) ||\n\t\t\t!dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) ||\n\t\t\t!dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG)))\n\t\t\tgoto err;\n\t\tret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el,\n\t\t\t\t\t\t (unsigned long *)dsatmp->pub_key->d,\n\t\t\t\t\t\t (unsigned long *)dsatmp->p->d,\n\t\t\t\t\t\t (unsigned long *)dsatmp->q->d,\n\t\t\t\t\t\t (unsigned long *)dsatmp->g->d);\n\t\tsurewarehk_error_handling(msg,SUREWARE_F_SUREWARE_LOAD_PUBLIC,ret);\n\t\tif (ret!=1)\n\t\t{\n\t\t\tSUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);\n\t\t\tgoto err;\n\t\t}\n\t\tdsatmp->pub_key->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->pub_key);\n\t\tdsatmp->p->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->p);\n\t\tdsatmp->q->top=20/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->q);\n\t\tdsatmp->g->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->g);\n\t\tres = EVP_PKEY_new();\n\t\tEVP_PKEY_assign_DSA(res, dsatmp);\n\t\tbreak;\n#endif\n\tdefault:\n\t\tSUREWAREerr(SUREWARE_F_SUREWARE_LOAD_PUBLIC,ENGINE_R_FAILED_LOADING_PRIVATE_KEY);\n\t\tgoto err;\n\t}\n\treturn res;\n err:\n\tif (res)\n\t\tEVP_PKEY_free(res);\n#ifndef OPENSSL_NO_RSA\n\tif (rsatmp)\n\t\tRSA_free(rsatmp);\n#endif\n#ifndef OPENSSL_NO_DSA\n\tif (dsatmp)\n\t\tDSA_free(dsatmp);\n#endif\n\treturn NULL;\n}', 'DSA *DSA_new_method(ENGINE *engine)\n\t{\n\tDSA *ret;\n\tret=(DSA *)OPENSSL_malloc(sizeof(DSA));\n\tif (ret == NULL)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->meth = DSA_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tDSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_DSA();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_DSA(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tDSAerr(DSA_F_DSA_NEW_METHOD,\n\t\t\t\tERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n#endif\n\tret->pad=0;\n\tret->version=0;\n\tret->write_params=1;\n\tret->p=NULL;\n\tret->q=NULL;\n\tret->g=NULL;\n\tret->pub_key=NULL;\n\tret->priv_key=NULL;\n\tret->kinv=NULL;\n\tret->r=NULL;\n\tret->method_mont_p=NULL;\n\tret->references=1;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n#ifndef OPENSSL_NO_ENGINE\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n#endif\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']
34,985
0
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L904
PUT_HEVC_QPEL_HV(2, 1)
['QPEL(64)', 'PUT_HEVC_QPEL_HV(2, 1)']
34,986
0
https://github.com/openssl/openssl/blob/3ad4af89cf7380aa94d1995e05e713d59e1c469a/crypto/dsa/dsa_lib.c/#L159
DSA *DSA_new_method(ENGINE *engine) { DSA *ret; ret = OPENSSL_zalloc(sizeof(*ret)); if (ret == NULL) { DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE); return NULL; } ret->meth = DSA_get_default_method(); #ifndef OPENSSL_NO_ENGINE if (engine) { if (!ENGINE_init(engine)) { DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); OPENSSL_free(ret); return NULL; } ret->engine = engine; } else ret->engine = ENGINE_get_default_DSA(); if (ret->engine) { ret->meth = ENGINE_get_DSA(ret->engine); if (ret->meth == NULL) { DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); ENGINE_finish(ret->engine); OPENSSL_free(ret); return NULL; } } #endif ret->references = 1; ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); ret->lock = CRYPTO_THREAD_lock_new(); if (ret->lock == NULL) { #ifndef OPENSSL_NO_ENGINE ENGINE_finish(ret->engine); #endif CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); OPENSSL_free(ret); return NULL; } if ((ret->meth->init != NULL) && !ret->meth->init(ret)) { DSA_free(ret); ret = NULL; } return ret; }
['DSA *DSA_new_method(ENGINE *engine)\n{\n DSA *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n ret->meth = DSA_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n if (engine) {\n if (!ENGINE_init(engine)) {\n DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n OPENSSL_free(ret);\n return NULL;\n }\n ret->engine = engine;\n } else\n ret->engine = ENGINE_get_default_DSA();\n if (ret->engine) {\n ret->meth = ENGINE_get_DSA(ret->engine);\n if (ret->meth == NULL) {\n DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n ENGINE_finish(ret->engine);\n OPENSSL_free(ret);\n return NULL;\n }\n }\n#endif\n ret->references = 1;\n ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;\n CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);\n ret->lock = CRYPTO_THREAD_lock_new();\n if (ret->lock == NULL) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(ret->engine);\n#endif\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);\n OPENSSL_free(ret);\n return NULL;\n }\n if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {\n DSA_free(ret);\n ret = NULL;\n }\n return ret;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'const DSA_METHOD *DSA_get_default_method(void)\n{\n if (!default_DSA_method)\n default_DSA_method = DSA_OpenSSL();\n return default_DSA_method;\n}', 'ENGINE *ENGINE_get_default_DSA(void)\n{\n return engine_table_select(&dsa_table, dummy_nid);\n}', 'ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)\n#else\nENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,\n int l)\n#endif\n{\n ENGINE *ret = NULL;\n ENGINE_PILE tmplate, *fnd = NULL;\n int initres, loop = 0;\n if (!(*table)) {\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "\n "registered!\\n", f, l, nid);\n#endif\n return NULL;\n }\n ERR_set_mark();\n CRYPTO_THREAD_write_lock(global_engine_lock);\n if (!int_table_check(table, 0))\n goto end;\n tmplate.nid = nid;\n fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);\n if (!fnd)\n goto end;\n if (fnd->funct && engine_unlocked_init(fnd->funct)) {\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n "ENGINE \'%s\' cached\\n", f, l, nid, fnd->funct->id);\n#endif\n ret = fnd->funct;\n goto end;\n }\n if (fnd->uptodate) {\n ret = fnd->funct;\n goto end;\n }\n trynext:\n ret = sk_ENGINE_value(fnd->sk, loop++);\n if (!ret) {\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "\n "registered implementations would initialise\\n", f, l, nid);\n#endif\n goto end;\n }\n if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))\n initres = engine_unlocked_init(ret);\n else\n initres = 0;\n if (initres) {\n if ((fnd->funct != ret) && engine_unlocked_init(ret)) {\n if (fnd->funct)\n engine_unlocked_finish(fnd->funct, 0);\n fnd->funct = ret;\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "\n "setting default to \'%s\'\\n", f, l, nid, ret->id);\n#endif\n }\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n "newly initialised \'%s\'\\n", f, l, nid, ret->id);\n#endif\n goto end;\n }\n goto trynext;\n end:\n if (fnd)\n fnd->uptodate = 1;\n#ifdef ENGINE_TABLE_DEBUG\n if (ret)\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n "ENGINE \'%s\'\\n", f, l, nid, ret->id);\n else\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n "\'no matching ENGINE\'\\n", f, l, nid);\n#endif\n CRYPTO_THREAD_unlock(global_engine_lock);\n ERR_pop_to_mark();\n return ret;\n}', 'int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)\n{\n int mx, i;\n void *ptr;\n EX_CALLBACK **storage = NULL;\n EX_CALLBACK *stack[10];\n EX_CALLBACKS *ip = get_and_lock(class_index);\n if (ip == NULL)\n return 0;\n ad->sk = NULL;\n mx = sk_EX_CALLBACK_num(ip->meth);\n if (mx > 0) {\n if (mx < (int)OSSL_NELEM(stack))\n storage = stack;\n else\n storage = OPENSSL_malloc(sizeof(*storage) * mx);\n if (storage != NULL)\n for (i = 0; i < mx; i++)\n storage[i] = sk_EX_CALLBACK_value(ip->meth, i);\n }\n CRYPTO_THREAD_unlock(ex_data_lock);\n if (mx > 0 && storage == NULL) {\n CRYPTOerr(CRYPTO_F_CRYPTO_NEW_EX_DATA, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n for (i = 0; i < mx; i++) {\n if (storage[i] && storage[i]->new_func) {\n ptr = CRYPTO_get_ex_data(ad, i);\n storage[i]->new_func(obj, ptr, ad, i,\n storage[i]->argl, storage[i]->argp);\n }\n }\n if (storage != stack)\n OPENSSL_free(storage);\n return 1;\n}', 'static EX_CALLBACKS *get_and_lock(int class_index)\n{\n EX_CALLBACKS *ip;\n if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {\n CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);\n return NULL;\n }\n CRYPTO_THREAD_run_once(&ex_data_init, do_ex_data_init);\n if (ex_data_lock == NULL) {\n return NULL;\n }\n ip = &ex_data[class_index];\n CRYPTO_THREAD_write_lock(ex_data_lock);\n return ip;\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}', 'CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)\n{\n CRYPTO_RWLOCK *lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t));\n if (lock == NULL)\n return NULL;\n if (pthread_rwlock_init(lock, NULL) != 0) {\n OPENSSL_free(lock);\n return NULL;\n }\n return lock;\n}']
34,987
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_lib.c/#L377
BIGNUM *bn_expand2(BIGNUM *b, int words) { BN_ULONG *A,*B,*a; int i,j; bn_check_top(b); if (words > b->max) { bn_check_top(b); if (BN_get_flags(b,BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return(NULL); } a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); if (A == NULL) { BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); return(NULL); } memset(A,0x5c,sizeof(BN_ULONG)*(words+1)); #if 1 B=b->d; if (B != NULL) { for (i=b->top&(~7); i>0; i-=8) { A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3]; A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7]; A+=8; B+=8; } switch (b->top&7) { case 7: A[6]=B[6]; case 6: A[5]=B[5]; case 5: A[4]=B[4]; case 4: A[3]=B[3]; case 3: A[2]=B[2]; case 2: A[1]=B[1]; case 1: A[0]=B[0]; case 0: ; } Free(b->d); } b->d=a; b->max=words; B= &(b->d[b->top]); j=(b->max - b->top) & ~7; for (i=0; i<j; i+=8) { B[0]=0; B[1]=0; B[2]=0; B[3]=0; B[4]=0; B[5]=0; B[6]=0; B[7]=0; B+=8; } j=(b->max - b->top) & 7; for (i=0; i<j; i++) { B[0]=0; B++; } #else memcpy(a->d,b->d,sizeof(b->d[0])*b->top); #endif } return(b); }
['int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\taa= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_RECP_CTX_init(&recp);\n\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&val[i]);\n\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\treturn(ret);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, BIGNUM *d, BN_CTX *ctx)\n\t{\n\tBN_copy(&(recp->N),d);\n\tBN_zero(&(recp->Nr));\n\trecp->num_bits=BN_num_bits(d);\n\trecp->shift=0;\n\treturn(1);\n\t}', '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}', 'int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\ta= &(ctx->bn[ctx->tos++]);\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\t}\n\telse\n\t\ta=x;\n\tBN_div_recp(NULL,r,a,recp,ctx);\n\tret=1;\nerr:\n\tctx->tos--;\n\treturn(ret);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,tos,ret=0,ex;\n\tBIGNUM *a,*b,*d,*r;\n\ttos=ctx->tos;\n\ta= &(ctx->bn[ctx->tos++]);\n\tb= &(ctx->bn[ctx->tos++]);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td= &(ctx->bn[ctx->tos++]);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr= &(ctx->bn[ctx->tos++]);\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tBN_copy(r,m);\n\t\tctx->tos=tos;\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits*2;\n\tif (j > i)\n\t\t{\n\t\ti=j;\n\t\tex=0;\n\t\t}\n\telse\n\t\t{\n\t\tex=(i-j)/2;\n\t\t}\n\tj=i/2;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (!BN_rshift(a,m,j-ex)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,j+ex)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n\tj=0;\n#if 1\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tctx->tos=tos;\n\treturn(ret);\n\t}', 'int BN_reciprocal(BIGNUM *r, BIGNUM *m, int len, BN_CTX *ctx)\n\t{\n\tint ret= -1;\n\tBIGNUM t;\n\tBN_init(&t);\n\tBN_zero(&t);\n\tif (!BN_set_bit(&t,len)) goto err;\n\tif (!BN_div(r,NULL,&t,m,ctx)) goto err;\n\tret=len;\nerr:\n\tBN_free(&t);\n\treturn(ret);\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', '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}']
34,988
0
https://github.com/openssl/openssl/blob/a8ae0891d4bfd18f224777aed1fbb172504421f1/apps/apps.c/#L1505
X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath) { X509_STORE *store; X509_LOOKUP *lookup; if (!(store = X509_STORE_new())) goto end; lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file()); if (lookup == NULL) goto end; if (CAfile) { if (!X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM)) { BIO_printf(bp, "Error loading file %s\n", CAfile); goto end; } } else X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT); lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir()); if (lookup == NULL) goto end; if (CApath) { if (!X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM)) { BIO_printf(bp, "Error loading directory %s\n", CApath); goto end; } } else X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); ERR_clear_error(); return store; end: X509_STORE_free(store); return NULL; }
['X509_STORE *setup_verify(BIO *bp, char *CAfile, char *CApath)\n{\n X509_STORE *store;\n X509_LOOKUP *lookup;\n if (!(store = X509_STORE_new()))\n goto end;\n lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());\n if (lookup == NULL)\n goto end;\n if (CAfile) {\n if (!X509_LOOKUP_load_file(lookup, CAfile, X509_FILETYPE_PEM)) {\n BIO_printf(bp, "Error loading file %s\\n", CAfile);\n goto end;\n }\n } else\n X509_LOOKUP_load_file(lookup, NULL, X509_FILETYPE_DEFAULT);\n lookup = X509_STORE_add_lookup(store, X509_LOOKUP_hash_dir());\n if (lookup == NULL)\n goto end;\n if (CApath) {\n if (!X509_LOOKUP_add_dir(lookup, CApath, X509_FILETYPE_PEM)) {\n BIO_printf(bp, "Error loading directory %s\\n", CApath);\n goto end;\n }\n } else\n X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT);\n ERR_clear_error();\n return store;\n end:\n X509_STORE_free(store);\n return NULL;\n}']
34,989
0
https://gitlab.com/libtiff/libtiff/blob/3334704ebcec6a8011fc5ef5d0904d6297a0b9ff/libtiff/tif_dirread.c/#L5184
static int TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover) { static const char module[] = "TIFFFetchNormalTag"; enum TIFFReadDirEntryErr err; uint32 fii; const TIFFField* fip = NULL; TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); if( fii == FAILED_FII ) { TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag", "No definition found for tag %d", dp->tdir_tag); return 0; } fip=tif->tif_fields[fii]; assert(fip != NULL); assert(fip->set_field_type!=TIFF_SETGET_OTHER); assert(fip->set_field_type!=TIFF_SETGET_INT); err=TIFFReadDirEntryErrOk; switch (fip->set_field_type) { case TIFF_SETGET_UNDEFINED: break; case TIFF_SETGET_ASCII: { uint8* data; assert(fip->field_passcount==0); err=TIFFReadDirEntryByteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { uint32 mb = 0; int n; if (data != NULL) { uint8* ma = data; while (mb<(uint32)dp->tdir_count) { if (*ma==0) break; ma++; mb++; } } if (mb+1<(uint32)dp->tdir_count) TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name); else if (mb+1>(uint32)dp->tdir_count) { uint8* o; TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte",fip->field_name); if ((uint32)dp->tdir_count+1!=dp->tdir_count+1) o=NULL; else o=_TIFFmalloc((uint32)dp->tdir_count+1); if (o==NULL) { if (data!=NULL) _TIFFfree(data); return(0); } _TIFFmemcpy(o,data,(uint32)dp->tdir_count); o[(uint32)dp->tdir_count]=0; if (data!=0) _TIFFfree(data); data=o; } n=TIFFSetField(tif,dp->tdir_tag,data); if (data!=0) _TIFFfree(data); if (!n) return(0); } } break; case TIFF_SETGET_UINT8: { uint8 data=0; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryByte(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_UINT16: { uint16 data; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryShort(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_UINT32: { uint32 data; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryLong(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_UINT64: { uint64 data; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryLong8(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_FLOAT: { float data; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryFloat(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_DOUBLE: { double data; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryDouble(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_IFD8: { uint64 data; assert(fip->field_readcount==1); assert(fip->field_passcount==0); err=TIFFReadDirEntryIfd8(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { if (!TIFFSetField(tif,dp->tdir_tag,data)) return(0); } } break; case TIFF_SETGET_UINT16_PAIR: { uint16* data; assert(fip->field_readcount==2); assert(fip->field_passcount==0); if (dp->tdir_count!=2) { TIFFWarningExt(tif->tif_clientdata,module, "incorrect count for field \"%s\", expected 2, got %d", fip->field_name,(int)dp->tdir_count); return(0); } err=TIFFReadDirEntryShortArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; assert(data); m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]); _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C0_UINT8: { uint8* data; assert(fip->field_readcount>=1); assert(fip->field_passcount==0); if (dp->tdir_count!=(uint64)fip->field_readcount) { TIFFWarningExt(tif->tif_clientdata,module, "incorrect count for field \"%s\", expected %d, got %d", fip->field_name,(int) fip->field_readcount, (int)dp->tdir_count); return 0; } else { err=TIFFReadDirEntryByteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C0_UINT16: { uint16* data; assert(fip->field_readcount>=1); assert(fip->field_passcount==0); if (dp->tdir_count!=(uint64)fip->field_readcount) ; else { err=TIFFReadDirEntryShortArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C0_UINT32: { uint32* data; assert(fip->field_readcount>=1); assert(fip->field_passcount==0); if (dp->tdir_count!=(uint64)fip->field_readcount) ; else { err=TIFFReadDirEntryLongArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C0_FLOAT: { float* data; assert(fip->field_readcount>=1); assert(fip->field_passcount==0); if (dp->tdir_count!=(uint64)fip->field_readcount) ; else { err=TIFFReadDirEntryFloatArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_ASCII: { uint8* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryByteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) { TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name); data[dp->tdir_count-1] = '\0'; } m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_UINT8: { uint8* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryByteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_UINT16: { uint16* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryShortArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_UINT32: { uint32* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryLongArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_UINT64: { uint64* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryLong8Array(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_FLOAT: { float* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryFloatArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_DOUBLE: { double* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryDoubleArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C16_IFD8: { uint64* data; assert(fip->field_readcount==TIFF_VARIABLE); assert(fip->field_passcount==1); if (dp->tdir_count>0xFFFF) err=TIFFReadDirEntryErrCount; else { err=TIFFReadDirEntryIfd8Array(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } } break; case TIFF_SETGET_C32_ASCII: { uint8* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryByteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' ) { TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name); data[dp->tdir_count-1] = '\0'; } m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_UINT8: { uint8* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryByteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_SINT8: { int8* data = NULL; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntrySbyteArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_UINT16: { uint16* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryShortArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_SINT16: { int16* data = NULL; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntrySshortArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_UINT32: { uint32* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryLongArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_SINT32: { int32* data = NULL; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntrySlongArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_UINT64: { uint64* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryLong8Array(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_SINT64: { int64* data = NULL; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntrySlong8Array(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_FLOAT: { float* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryFloatArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_DOUBLE: { double* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryDoubleArray(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; case TIFF_SETGET_C32_IFD8: { uint64* data; assert(fip->field_readcount==TIFF_VARIABLE2); assert(fip->field_passcount==1); err=TIFFReadDirEntryIfd8Array(tif,dp,&data); if (err==TIFFReadDirEntryErrOk) { int m; m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data); if (data!=0) _TIFFfree(data); if (!m) return(0); } } break; default: assert(0); break; } if (err!=TIFFReadDirEntryErrOk) { TIFFReadDirEntryOutputErr(tif,err,module,fip->field_name,recover); return(0); } return(1); }
['static int\nTIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)\n{\n\tstatic const char module[] = "TIFFFetchNormalTag";\n\tenum TIFFReadDirEntryErr err;\n\tuint32 fii;\n\tconst TIFFField* fip = NULL;\n\tTIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii);\n if( fii == FAILED_FII )\n {\n TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag",\n "No definition found for tag %d",\n dp->tdir_tag);\n return 0;\n }\n\tfip=tif->tif_fields[fii];\n\tassert(fip != NULL);\n\tassert(fip->set_field_type!=TIFF_SETGET_OTHER);\n\tassert(fip->set_field_type!=TIFF_SETGET_INT);\n\terr=TIFFReadDirEntryErrOk;\n\tswitch (fip->set_field_type)\n\t{\n\t\tcase TIFF_SETGET_UNDEFINED:\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_ASCII:\n\t\t\t{\n\t\t\t\tuint8* data;\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryByteArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tuint32 mb = 0;\n\t\t\t\t\tint n;\n\t\t\t\t\tif (data != NULL)\n\t\t\t\t\t{\n\t\t\t\t\t uint8* ma = data;\n\t\t\t\t\t while (mb<(uint32)dp->tdir_count)\n\t\t\t\t\t {\n\t\t\t\t\t if (*ma==0)\n\t\t\t\t\t break;\n\t\t\t\t\t ma++;\n\t\t\t\t\t mb++;\n\t\t\t\t\t }\n\t\t\t\t\t}\n\t\t\t\t\tif (mb+1<(uint32)dp->tdir_count)\n\t\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \\"%s\\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name);\n\t\t\t\t\telse if (mb+1>(uint32)dp->tdir_count)\n\t\t\t\t\t{\n\t\t\t\t\t\tuint8* o;\n\t\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \\"%s\\" does not end in null byte",fip->field_name);\n\t\t\t\t\t\tif ((uint32)dp->tdir_count+1!=dp->tdir_count+1)\n\t\t\t\t\t\t\to=NULL;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\to=_TIFFmalloc((uint32)dp->tdir_count+1);\n\t\t\t\t\t\tif (o==NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (data!=NULL)\n\t\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t_TIFFmemcpy(o,data,(uint32)dp->tdir_count);\n\t\t\t\t\t\to[(uint32)dp->tdir_count]=0;\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tdata=o;\n\t\t\t\t\t}\n\t\t\t\t\tn=TIFFSetField(tif,dp->tdir_tag,data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!n)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_UINT8:\n\t\t\t{\n\t\t\t\tuint8 data=0;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryByte(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_UINT16:\n\t\t\t{\n\t\t\t\tuint16 data;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryShort(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_UINT32:\n\t\t\t{\n\t\t\t\tuint32 data;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryLong(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_UINT64:\n\t\t\t{\n\t\t\t\tuint64 data;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryLong8(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_FLOAT:\n\t\t\t{\n\t\t\t\tfloat data;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryFloat(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_DOUBLE:\n\t\t\t{\n\t\t\t\tdouble data;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryDouble(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_IFD8:\n\t\t\t{\n\t\t\t\tuint64 data;\n\t\t\t\tassert(fip->field_readcount==1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\terr=TIFFReadDirEntryIfd8(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFSetField(tif,dp->tdir_tag,data))\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_UINT16_PAIR:\n\t\t\t{\n\t\t\t\tuint16* data;\n\t\t\t\tassert(fip->field_readcount==2);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\tif (dp->tdir_count!=2) {\n\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t\t\t "incorrect count for field \\"%s\\", expected 2, got %d",\n\t\t\t\t\t\t fip->field_name,(int)dp->tdir_count);\n\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n assert(data);\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]);\n\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C0_UINT8:\n\t\t\t{\n\t\t\t\tuint8* data;\n\t\t\t\tassert(fip->field_readcount>=1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\tif (dp->tdir_count!=(uint64)fip->field_readcount) {\n\t\t\t\t\tTIFFWarningExt(tif->tif_clientdata,module,\n\t\t\t\t\t\t "incorrect count for field \\"%s\\", expected %d, got %d",\n\t\t\t\t\t\t fip->field_name,(int) fip->field_readcount, (int)dp->tdir_count);\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryByteArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C0_UINT16:\n\t\t\t{\n\t\t\t\tuint16* data;\n\t\t\t\tassert(fip->field_readcount>=1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\tif (dp->tdir_count!=(uint64)fip->field_readcount)\n ;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C0_UINT32:\n\t\t\t{\n\t\t\t\tuint32* data;\n\t\t\t\tassert(fip->field_readcount>=1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\tif (dp->tdir_count!=(uint64)fip->field_readcount)\n ;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryLongArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C0_FLOAT:\n\t\t\t{\n\t\t\t\tfloat* data;\n\t\t\t\tassert(fip->field_readcount>=1);\n\t\t\t\tassert(fip->field_passcount==0);\n\t\t\t\tif (dp->tdir_count!=(uint64)fip->field_readcount)\n ;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryFloatArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_ASCII:\n\t\t\t{\n\t\t\t\tuint8* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryByteArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tif( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != \'\\0\' )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \\"%s\\" does not end in null byte. Forcing it to be null",fip->field_name);\n\t\t\t\t\t\t data[dp->tdir_count-1] = \'\\0\';\n\t\t\t\t\t\t}\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_UINT8:\n\t\t\t{\n\t\t\t\tuint8* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryByteArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_UINT16:\n\t\t\t{\n\t\t\t\tuint16* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_UINT32:\n\t\t\t{\n\t\t\t\tuint32* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryLongArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_UINT64:\n\t\t\t{\n\t\t\t\tuint64* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryLong8Array(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_FLOAT:\n\t\t\t{\n\t\t\t\tfloat* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryFloatArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_DOUBLE:\n\t\t\t{\n\t\t\t\tdouble* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryDoubleArray(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C16_IFD8:\n\t\t\t{\n\t\t\t\tuint64* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\tif (dp->tdir_count>0xFFFF)\n\t\t\t\t\terr=TIFFReadDirEntryErrCount;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryIfd8Array(tif,dp,&data);\n\t\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\tint m;\n\t\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);\n\t\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\t\tif (!m)\n\t\t\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_ASCII:\n\t\t\t{\n\t\t\t\tuint8* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryByteArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tif( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != \'\\0\' )\n\t\t\t\t\t{\n\t\t\t\t\t TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \\"%s\\" does not end in null byte. Forcing it to be null",fip->field_name);\n data[dp->tdir_count-1] = \'\\0\';\n\t\t\t\t\t}\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_UINT8:\n\t\t\t{\n\t\t\t\tuint8* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryByteArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_SINT8:\n\t\t\t{\n\t\t\t\tint8* data = NULL;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntrySbyteArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_UINT16:\n\t\t\t{\n\t\t\t\tuint16* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryShortArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_SINT16:\n\t\t\t{\n\t\t\t\tint16* data = NULL;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntrySshortArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_UINT32:\n\t\t\t{\n\t\t\t\tuint32* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryLongArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_SINT32:\n\t\t\t{\n\t\t\t\tint32* data = NULL;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntrySlongArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_UINT64:\n\t\t\t{\n\t\t\t\tuint64* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryLong8Array(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_SINT64:\n\t\t\t{\n\t\t\t\tint64* data = NULL;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntrySlong8Array(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_FLOAT:\n\t\t\t{\n\t\t\t\tfloat* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryFloatArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_DOUBLE:\n\t\t\t{\n\t\t\t\tdouble* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryDoubleArray(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SETGET_C32_IFD8:\n\t\t\t{\n\t\t\t\tuint64* data;\n\t\t\t\tassert(fip->field_readcount==TIFF_VARIABLE2);\n\t\t\t\tassert(fip->field_passcount==1);\n\t\t\t\terr=TIFFReadDirEntryIfd8Array(tif,dp,&data);\n\t\t\t\tif (err==TIFFReadDirEntryErrOk)\n\t\t\t\t{\n\t\t\t\t\tint m;\n\t\t\t\t\tm=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);\n\t\t\t\t\tif (data!=0)\n\t\t\t\t\t\t_TIFFfree(data);\n\t\t\t\t\tif (!m)\n\t\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tassert(0);\n\t\t\tbreak;\n\t}\n\tif (err!=TIFFReadDirEntryErrOk)\n\t{\n\t\tTIFFReadDirEntryOutputErr(tif,err,module,fip->field_name,recover);\n\t\treturn(0);\n\t}\n\treturn(1);\n}', 'static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF* tif, TIFFDirEntry* direntry, uint16** value)\n{\n\tenum TIFFReadDirEntryErr err;\n\tuint32 count;\n\tvoid* origdata;\n\tuint16* data;\n\tswitch (direntry->tdir_type)\n\t{\n\t\tcase TIFF_BYTE:\n\t\tcase TIFF_SBYTE:\n\t\tcase TIFF_SHORT:\n\t\tcase TIFF_SSHORT:\n\t\tcase TIFF_LONG:\n\t\tcase TIFF_SLONG:\n\t\tcase TIFF_LONG8:\n\t\tcase TIFF_SLONG8:\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn(TIFFReadDirEntryErrType);\n\t}\n\terr=TIFFReadDirEntryArray(tif,direntry,&count,2,&origdata);\n\tif ((err!=TIFFReadDirEntryErrOk)||(origdata==0))\n\t{\n\t\t*value=0;\n\t\treturn(err);\n\t}\n\tswitch (direntry->tdir_type)\n\t{\n\t\tcase TIFF_SHORT:\n\t\t\t*value=(uint16*)origdata;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabArrayOfShort(*value,count);\n\t\t\treturn(TIFFReadDirEntryErrOk);\n\t\tcase TIFF_SSHORT:\n\t\t\t{\n\t\t\t\tint16* m;\n\t\t\t\tuint32 n;\n\t\t\t\tm=(int16*)origdata;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t{\n\t\t\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\t\t\tTIFFSwabShort((uint16*)m);\n\t\t\t\t\terr=TIFFReadDirEntryCheckRangeShortSshort(*m);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t{\n\t\t\t\t\t\t_TIFFfree(origdata);\n\t\t\t\t\t\treturn(err);\n\t\t\t\t\t}\n\t\t\t\t\tm++;\n\t\t\t\t}\n\t\t\t\t*value=(uint16*)origdata;\n\t\t\t\treturn(TIFFReadDirEntryErrOk);\n\t\t\t}\n\t}\n\tdata=(uint16*)_TIFFmalloc(count*2);\n\tif (data==0)\n\t{\n\t\t_TIFFfree(origdata);\n\t\treturn(TIFFReadDirEntryErrAlloc);\n\t}\n\tswitch (direntry->tdir_type)\n\t{\n\t\tcase TIFF_BYTE:\n\t\t\t{\n\t\t\t\tuint8* ma;\n\t\t\t\tuint16* mb;\n\t\t\t\tuint32 n;\n\t\t\t\tma=(uint8*)origdata;\n\t\t\t\tmb=data;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t\t*mb++=(uint16)(*ma++);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SBYTE:\n\t\t\t{\n\t\t\t\tint8* ma;\n\t\t\t\tuint16* mb;\n\t\t\t\tuint32 n;\n\t\t\t\tma=(int8*)origdata;\n\t\t\t\tmb=data;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t{\n\t\t\t\t\terr=TIFFReadDirEntryCheckRangeShortSbyte(*ma);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t*mb++=(uint16)(*ma++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_LONG:\n\t\t\t{\n\t\t\t\tuint32* ma;\n\t\t\t\tuint16* mb;\n\t\t\t\tuint32 n;\n\t\t\t\tma=(uint32*)origdata;\n\t\t\t\tmb=data;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t{\n\t\t\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\t\t\tTIFFSwabLong(ma);\n\t\t\t\t\terr=TIFFReadDirEntryCheckRangeShortLong(*ma);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t*mb++=(uint16)(*ma++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SLONG:\n\t\t\t{\n\t\t\t\tint32* ma;\n\t\t\t\tuint16* mb;\n\t\t\t\tuint32 n;\n\t\t\t\tma=(int32*)origdata;\n\t\t\t\tmb=data;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t{\n\t\t\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\t\t\tTIFFSwabLong((uint32*)ma);\n\t\t\t\t\terr=TIFFReadDirEntryCheckRangeShortSlong(*ma);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t*mb++=(uint16)(*ma++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_LONG8:\n\t\t\t{\n\t\t\t\tuint64* ma;\n\t\t\t\tuint16* mb;\n\t\t\t\tuint32 n;\n\t\t\t\tma=(uint64*)origdata;\n\t\t\t\tmb=data;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t{\n\t\t\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\t\t\tTIFFSwabLong8(ma);\n\t\t\t\t\terr=TIFFReadDirEntryCheckRangeShortLong8(*ma);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t*mb++=(uint16)(*ma++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase TIFF_SLONG8:\n\t\t\t{\n\t\t\t\tint64* ma;\n\t\t\t\tuint16* mb;\n\t\t\t\tuint32 n;\n\t\t\t\tma=(int64*)origdata;\n\t\t\t\tmb=data;\n\t\t\t\tfor (n=0; n<count; n++)\n\t\t\t\t{\n\t\t\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\t\t\tTIFFSwabLong8((uint64*)ma);\n\t\t\t\t\terr=TIFFReadDirEntryCheckRangeShortSlong8(*ma);\n\t\t\t\t\tif (err!=TIFFReadDirEntryErrOk)\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t*mb++=(uint16)(*ma++);\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t}\n\t_TIFFfree(origdata);\n\tif (err!=TIFFReadDirEntryErrOk)\n\t{\n\t\t_TIFFfree(data);\n\t\treturn(err);\n\t}\n\t*value=data;\n\treturn(TIFFReadDirEntryErrOk);\n}']
34,990
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/bn/bn_ctx.c/#L401
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)\n{\n int ret = 0;\n if ((b->A == NULL) || (b->Ai == NULL)) {\n BNerr(BN_F_BN_BLINDING_UPDATE, BN_R_NOT_INITIALIZED);\n goto err;\n }\n if (b->counter == -1)\n b->counter = 0;\n if (++b->counter == BN_BLINDING_COUNTER && b->e != NULL &&\n !(b->flags & BN_BLINDING_NO_RECREATE)) {\n if (!BN_BLINDING_create_param(b, NULL, NULL, ctx, NULL, NULL))\n goto err;\n } else if (!(b->flags & BN_BLINDING_NO_UPDATE)) {\n if (!BN_mod_mul(b->A, b->A, b->A, b->mod, ctx))\n goto err;\n if (!BN_mod_mul(b->Ai, b->Ai, b->Ai, b->mod, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (b->counter == BN_BLINDING_COUNTER)\n b->counter = 0;\n return (ret);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, 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_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
34,991
0
https://github.com/libav/libav/blob/b8b207e8963f35a76c6981d7a74d6c08a53abab9/libavcodec/ralf.c/#L97
static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems) { uint8_t lens[MAX_ELEMS]; uint16_t codes[MAX_ELEMS]; int counts[17], prefixes[18]; int i, cur_len; int max_bits = 0; GetBitContext gb; init_get_bits(&gb, data, elems * 4); for (i = 0; i <= 16; i++) counts[i] = 0; for (i = 0; i < elems; i++) { cur_len = get_bits(&gb, 4) + 1; counts[cur_len]++; max_bits = FFMAX(max_bits, cur_len); lens[i] = cur_len; } prefixes[1] = 0; for (i = 1; i <= 16; i++) prefixes[i + 1] = (prefixes[i] + counts[i]) << 1; for (i = 0; i < elems; i++) codes[i] = prefixes[lens[i]]++; return ff_init_vlc_sparse(vlc, FFMIN(max_bits, 9), elems, lens, 1, 1, codes, 2, 2, NULL, 0, 0, 0); }
['static int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)\n{\n uint8_t lens[MAX_ELEMS];\n uint16_t codes[MAX_ELEMS];\n int counts[17], prefixes[18];\n int i, cur_len;\n int max_bits = 0;\n GetBitContext gb;\n init_get_bits(&gb, data, elems * 4);\n for (i = 0; i <= 16; i++)\n counts[i] = 0;\n for (i = 0; i < elems; i++) {\n cur_len = get_bits(&gb, 4) + 1;\n counts[cur_len]++;\n max_bits = FFMAX(max_bits, cur_len);\n lens[i] = cur_len;\n }\n prefixes[1] = 0;\n for (i = 1; i <= 16; i++)\n prefixes[i + 1] = (prefixes[i] + counts[i]) << 1;\n for (i = 0; i < elems; i++)\n codes[i] = prefixes[lens[i]]++;\n return ff_init_vlc_sparse(vlc, FFMIN(max_bits, 9), elems,\n lens, 1, 1, codes, 2, 2, NULL, 0, 0, 0);\n}']
34,992
0
https://github.com/libav/libav/blob/51ca3cb604a7585a7cff35d4b954794508955c19/libavformat/mpegts.c/#L750
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size) { GetBitContext gb; int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0; int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0; int dts_flag = -1, cts_flag = -1; int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE; init_get_bits(&gb, buf, buf_size * 8); if (sl->use_au_start) au_start_flag = get_bits1(&gb); if (sl->use_au_end) au_end_flag = get_bits1(&gb); if (!sl->use_au_start && !sl->use_au_end) au_start_flag = au_end_flag = 1; if (sl->ocr_len > 0) ocr_flag = get_bits1(&gb); if (sl->use_idle) idle_flag = get_bits1(&gb); if (sl->use_padding) padding_flag = get_bits1(&gb); if (padding_flag) padding_bits = get_bits(&gb, 3); if (!idle_flag && (!padding_flag || padding_bits != 0)) { if (sl->packet_seq_num_len) skip_bits_long(&gb, sl->packet_seq_num_len); if (sl->degr_prior_len) if (get_bits1(&gb)) skip_bits(&gb, sl->degr_prior_len); if (ocr_flag) skip_bits_long(&gb, sl->ocr_len); if (au_start_flag) { if (sl->use_rand_acc_pt) get_bits1(&gb); if (sl->au_seq_num_len > 0) skip_bits_long(&gb, sl->au_seq_num_len); if (sl->use_timestamps) { dts_flag = get_bits1(&gb); cts_flag = get_bits1(&gb); } } if (sl->inst_bitrate_len) inst_bitrate_flag = get_bits1(&gb); if (dts_flag == 1) dts = get_bits64(&gb, sl->timestamp_len); if (cts_flag == 1) cts = get_bits64(&gb, sl->timestamp_len); if (sl->au_len > 0) skip_bits_long(&gb, sl->au_len); if (inst_bitrate_flag) skip_bits_long(&gb, sl->inst_bitrate_len); } if (dts != AV_NOPTS_VALUE) pes->dts = dts; if (cts != AV_NOPTS_VALUE) pes->pts = cts; if (sl->timestamp_len && sl->timestamp_res) avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res); return (get_bits_count(&gb) + 7) >> 3; }
['static int read_sl_header(PESContext *pes, SLConfigDescr *sl,\n const uint8_t *buf, int buf_size)\n{\n GetBitContext gb;\n int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;\n int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;\n int dts_flag = -1, cts_flag = -1;\n int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;\n init_get_bits(&gb, buf, buf_size * 8);\n if (sl->use_au_start)\n au_start_flag = get_bits1(&gb);\n if (sl->use_au_end)\n au_end_flag = get_bits1(&gb);\n if (!sl->use_au_start && !sl->use_au_end)\n au_start_flag = au_end_flag = 1;\n if (sl->ocr_len > 0)\n ocr_flag = get_bits1(&gb);\n if (sl->use_idle)\n idle_flag = get_bits1(&gb);\n if (sl->use_padding)\n padding_flag = get_bits1(&gb);\n if (padding_flag)\n padding_bits = get_bits(&gb, 3);\n if (!idle_flag && (!padding_flag || padding_bits != 0)) {\n if (sl->packet_seq_num_len)\n skip_bits_long(&gb, sl->packet_seq_num_len);\n if (sl->degr_prior_len)\n if (get_bits1(&gb))\n skip_bits(&gb, sl->degr_prior_len);\n if (ocr_flag)\n skip_bits_long(&gb, sl->ocr_len);\n if (au_start_flag) {\n if (sl->use_rand_acc_pt)\n get_bits1(&gb);\n if (sl->au_seq_num_len > 0)\n skip_bits_long(&gb, sl->au_seq_num_len);\n if (sl->use_timestamps) {\n dts_flag = get_bits1(&gb);\n cts_flag = get_bits1(&gb);\n }\n }\n if (sl->inst_bitrate_len)\n inst_bitrate_flag = get_bits1(&gb);\n if (dts_flag == 1)\n dts = get_bits64(&gb, sl->timestamp_len);\n if (cts_flag == 1)\n cts = get_bits64(&gb, sl->timestamp_len);\n if (sl->au_len > 0)\n skip_bits_long(&gb, sl->au_len);\n if (inst_bitrate_flag)\n skip_bits_long(&gb, sl->inst_bitrate_len);\n }\n if (dts != AV_NOPTS_VALUE)\n pes->dts = dts;\n if (cts != AV_NOPTS_VALUE)\n pes->pts = cts;\n if (sl->timestamp_len && sl->timestamp_res)\n avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);\n return (get_bits_count(&gb) + 7) >> 3;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
34,993
0
https://github.com/openssl/openssl/blob/4f230524924fae962aaad8fd8bf57f35a0057daa/crypto/pkcs7/pk7_doit.c/#L311
BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) { int i,j; BIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL; unsigned char *tmp=NULL; X509_ALGOR *xa; ASN1_OCTET_STRING *data_body=NULL; const EVP_MD *evp_md; const EVP_CIPHER *evp_cipher=NULL; EVP_CIPHER_CTX *evp_ctx=NULL; X509_ALGOR *enc_alg=NULL; STACK_OF(X509_ALGOR) *md_sk=NULL; STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; X509_ALGOR *xalg=NULL; PKCS7_RECIP_INFO *ri=NULL; char is_rc2 = 0; #if 0 X509_STORE_CTX s_ctx; #endif i=OBJ_obj2nid(p7->type); p7->state=PKCS7_S_HEADER; switch (i) { case NID_pkcs7_signed: data_body=p7->d.sign->contents->d.data; md_sk=p7->d.sign->md_algs; break; case NID_pkcs7_signedAndEnveloped: rsk=p7->d.signed_and_enveloped->recipientinfo; md_sk=p7->d.signed_and_enveloped->md_algs; data_body=p7->d.signed_and_enveloped->enc_data->enc_data; enc_alg=p7->d.signed_and_enveloped->enc_data->algorithm; evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm))); if (evp_cipher == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); goto err; } xalg=p7->d.signed_and_enveloped->enc_data->algorithm; break; case NID_pkcs7_enveloped: rsk=p7->d.enveloped->recipientinfo; enc_alg=p7->d.enveloped->enc_data->algorithm; data_body=p7->d.enveloped->enc_data->enc_data; evp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm))); if (evp_cipher == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE); goto err; } xalg=p7->d.enveloped->enc_data->algorithm; break; default: PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); goto err; } if(EVP_CIPHER_nid(evp_cipher) == NID_rc2_cbc) is_rc2 = 1; if (md_sk != NULL) { for (i=0; i<sk_X509_ALGOR_num(md_sk); i++) { xa=sk_X509_ALGOR_value(md_sk,i); if ((btmp=BIO_new(BIO_f_md())) == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB); goto err; } j=OBJ_obj2nid(xa->algorithm); evp_md=EVP_get_digestbyname(OBJ_nid2sn(j)); if (evp_md == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE); goto err; } BIO_set_md(btmp,evp_md); if (out == NULL) out=btmp; else BIO_push(out,btmp); btmp=NULL; } } if (evp_cipher != NULL) { #if 0 unsigned char key[EVP_MAX_KEY_LENGTH]; unsigned char iv[EVP_MAX_IV_LENGTH]; unsigned char *p; int keylen,ivlen; int max; X509_OBJECT ret; #endif int jj; if ((etmp=BIO_new(BIO_f_cipher())) == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB); goto err; } for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) { ri=sk_PKCS7_RECIP_INFO_value(rsk,i); if(!X509_NAME_cmp(ri->issuer_and_serial->issuer, pcert->cert_info->issuer) && !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber, ri->issuer_and_serial->serial)) break; ri=NULL; } if (ri == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE); return(NULL); } jj=EVP_PKEY_size(pkey); tmp=(unsigned char *)Malloc(jj+10); if (tmp == NULL) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE); goto err; } jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key), M_ASN1_STRING_length(ri->enc_key), pkey); if (jj <= 0) { PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB); goto err; } evp_ctx=NULL; BIO_get_cipher_ctx(etmp,&evp_ctx); EVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0); if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0) return(NULL); if (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) { if(is_rc2) RC2_set_key(&(evp_ctx->c.rc2_ks),jj, tmp, EVP_CIPHER_CTX_key_length(evp_ctx)*8); else { PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH); goto err; } } else EVP_CipherInit(evp_ctx,NULL,tmp,NULL,0); memset(tmp,0,jj); if (out == NULL) out=etmp; else BIO_push(out,etmp); etmp=NULL; } #if 1 if (p7->detached || (in_bio != NULL)) { bio=in_bio; } else { #if 0 bio=BIO_new(BIO_s_mem()); BIO_set_mem_eof_return(bio,0); if (data_body->length > 0) BIO_write(bio,(char *)data_body->data,data_body->length); #else if (data_body->length > 0) bio = BIO_new_mem_buf(data_body->data,data_body->length); else { bio=BIO_new(BIO_s_mem()); BIO_set_mem_eof_return(bio,0); } #endif } BIO_push(out,bio); bio=NULL; #endif if (0) { err: if (out != NULL) BIO_free_all(out); if (btmp != NULL) BIO_free_all(btmp); if (etmp != NULL) BIO_free_all(etmp); if (bio != NULL) BIO_free_all(bio); out=NULL; } if (tmp != NULL) Free(tmp); return(out); }
['BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)\n\t{\n\tint i,j;\n\tBIO *out=NULL,*btmp=NULL,*etmp=NULL,*bio=NULL;\n\tunsigned char *tmp=NULL;\n\tX509_ALGOR *xa;\n\tASN1_OCTET_STRING *data_body=NULL;\n\tconst EVP_MD *evp_md;\n\tconst EVP_CIPHER *evp_cipher=NULL;\n\tEVP_CIPHER_CTX *evp_ctx=NULL;\n\tX509_ALGOR *enc_alg=NULL;\n\tSTACK_OF(X509_ALGOR) *md_sk=NULL;\n\tSTACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;\n\tX509_ALGOR *xalg=NULL;\n\tPKCS7_RECIP_INFO *ri=NULL;\n\tchar is_rc2 = 0;\n#if 0\n\tX509_STORE_CTX s_ctx;\n#endif\n\ti=OBJ_obj2nid(p7->type);\n\tp7->state=PKCS7_S_HEADER;\n\tswitch (i)\n\t\t{\n\tcase NID_pkcs7_signed:\n\t\tdata_body=p7->d.sign->contents->d.data;\n\t\tmd_sk=p7->d.sign->md_algs;\n\t\tbreak;\n\tcase NID_pkcs7_signedAndEnveloped:\n\t\trsk=p7->d.signed_and_enveloped->recipientinfo;\n\t\tmd_sk=p7->d.signed_and_enveloped->md_algs;\n\t\tdata_body=p7->d.signed_and_enveloped->enc_data->enc_data;\n\t\tenc_alg=p7->d.signed_and_enveloped->enc_data->algorithm;\n\t\tevp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));\n\t\tif (evp_cipher == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);\n\t\t\tgoto err;\n\t\t\t}\n\t\txalg=p7->d.signed_and_enveloped->enc_data->algorithm;\n\t\tbreak;\n\tcase NID_pkcs7_enveloped:\n\t\trsk=p7->d.enveloped->recipientinfo;\n\t\tenc_alg=p7->d.enveloped->enc_data->algorithm;\n\t\tdata_body=p7->d.enveloped->enc_data->enc_data;\n\t\tevp_cipher=EVP_get_cipherbyname(OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm)));\n\t\tif (evp_cipher == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CIPHER_TYPE);\n\t\t\tgoto err;\n\t\t\t}\n\t\txalg=p7->d.enveloped->enc_data->algorithm;\n\t\tbreak;\n\tdefault:\n\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);\n\t goto err;\n\t\t}\n\tif(EVP_CIPHER_nid(evp_cipher) == NID_rc2_cbc) is_rc2 = 1;\n\tif (md_sk != NULL)\n\t\t{\n\t\tfor (i=0; i<sk_X509_ALGOR_num(md_sk); i++)\n\t\t\t{\n\t\t\txa=sk_X509_ALGOR_value(md_sk,i);\n\t\t\tif ((btmp=BIO_new(BIO_f_md())) == NULL)\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tj=OBJ_obj2nid(xa->algorithm);\n\t\t\tevp_md=EVP_get_digestbyname(OBJ_nid2sn(j));\n\t\t\tif (evp_md == NULL)\n\t\t\t\t{\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,PKCS7_R_UNKNOWN_DIGEST_TYPE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tBIO_set_md(btmp,evp_md);\n\t\t\tif (out == NULL)\n\t\t\t\tout=btmp;\n\t\t\telse\n\t\t\t\tBIO_push(out,btmp);\n\t\t\tbtmp=NULL;\n\t\t\t}\n\t\t}\n\tif (evp_cipher != NULL)\n\t\t{\n#if 0\n\t\tunsigned char key[EVP_MAX_KEY_LENGTH];\n\t\tunsigned char iv[EVP_MAX_IV_LENGTH];\n\t\tunsigned char *p;\n\t\tint keylen,ivlen;\n\t\tint max;\n\t\tX509_OBJECT ret;\n#endif\n\t\tint jj;\n\t\tif ((etmp=BIO_new(BIO_f_cipher())) == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_BIO_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tfor (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {\n\t\t\tri=sk_PKCS7_RECIP_INFO_value(rsk,i);\n\t\t\tif(!X509_NAME_cmp(ri->issuer_and_serial->issuer,\n\t\t\t\t\tpcert->cert_info->issuer) &&\n\t\t\t !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,\n\t\t\t\t\tri->issuer_and_serial->serial)) break;\n\t\t\tri=NULL;\n\t\t}\n\t\tif (ri == NULL) {\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,\n\t\t\t\t PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);\n\t\t\treturn(NULL);\n\t\t}\n\t\tjj=EVP_PKEY_size(pkey);\n\t\ttmp=(unsigned char *)Malloc(jj+10);\n\t\tif (tmp == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tjj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),\n\t\t\tM_ASN1_STRING_length(ri->enc_key), pkey);\n\t\tif (jj <= 0)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tevp_ctx=NULL;\n\t\tBIO_get_cipher_ctx(etmp,&evp_ctx);\n\t\tEVP_CipherInit(evp_ctx,evp_cipher,NULL,NULL,0);\n\t\tif (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)\n\t\t\treturn(NULL);\n\t\tif (jj != EVP_CIPHER_CTX_key_length(evp_ctx)) {\n\t\t\tif(is_rc2) RC2_set_key(&(evp_ctx->c.rc2_ks),jj, tmp,\n\t\t\t\t\tEVP_CIPHER_CTX_key_length(evp_ctx)*8);\n\t\t\telse {\n\t\t\t\tPKCS7err(PKCS7_F_PKCS7_DATADECODE,\n\t\t\t\t\tPKCS7_R_DECRYPTED_KEY_IS_WRONG_LENGTH);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t} else EVP_CipherInit(evp_ctx,NULL,tmp,NULL,0);\n\t\tmemset(tmp,0,jj);\n\t\tif (out == NULL)\n\t\t\tout=etmp;\n\t\telse\n\t\t\tBIO_push(out,etmp);\n\t\tetmp=NULL;\n\t\t}\n#if 1\n\tif (p7->detached || (in_bio != NULL))\n\t\t{\n\t\tbio=in_bio;\n\t\t}\n\telse\n\t\t{\n#if 0\n\t\tbio=BIO_new(BIO_s_mem());\n\t\tBIO_set_mem_eof_return(bio,0);\n\t\tif (data_body->length > 0)\n\t\t\tBIO_write(bio,(char *)data_body->data,data_body->length);\n#else\n\t\tif (data_body->length > 0)\n\t\t bio = BIO_new_mem_buf(data_body->data,data_body->length);\n\t\telse {\n\t\t\tbio=BIO_new(BIO_s_mem());\n\t\t\tBIO_set_mem_eof_return(bio,0);\n\t\t}\n#endif\n\t\t}\n\tBIO_push(out,bio);\n\tbio=NULL;\n#endif\n\tif (0)\n\t\t{\nerr:\n\t\tif (out != NULL) BIO_free_all(out);\n\t\tif (btmp != NULL) BIO_free_all(btmp);\n\t\tif (etmp != NULL) BIO_free_all(etmp);\n\t\tif (bio != NULL) BIO_free_all(bio);\n\t\tout=NULL;\n\t\t}\n\tif (tmp != NULL)\n\t\tFree(tmp);\n\treturn(out);\n\t}', 'int OBJ_obj2nid(ASN1_OBJECT *a)\n\t{\n\tASN1_OBJECT **op;\n\tADDED_OBJ ad,*adp;\n\tif (a == NULL)\n\t\treturn(NID_undef);\n\tif (a->nid != 0)\n\t\treturn(a->nid);\n\tif (added != NULL)\n\t\t{\n\t\tad.type=ADDED_DATA;\n\t\tad.obj=a;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);\n\t\tif (adp != NULL) return (adp->obj->nid);\n\t\t}\n\top=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,\n\t\tsizeof(ASN1_OBJECT *),(int (*)())obj_cmp);\n\tif (op == NULL)\n\t\treturn(NID_undef);\n\treturn((*op)->nid);\n\t}']
34,994
0
https://github.com/openssl/openssl/blob/3208ff58ca59d143b49dd2f1c05fbc33cf35e64f/apps/speed.c/#L1820
static int do_multi(int multi) { int n; int fd[2]; int *fds; static char sep[]=":"; fds=malloc(multi*sizeof *fds); for(n=0 ; n < multi ; ++n) { pipe(fd); if(fork()) { close(fd[1]); fds[n]=fd[0]; } else { close(fd[0]); close(1); dup(fd[1]); close(fd[1]); mr=1; usertime=0; return 0; } printf("Forked child %d\n",n); } for(n=0 ; n < multi ; ++n) { FILE *f; char buf[1024]; char *p; f=fdopen(fds[n],"r"); while(fgets(buf,sizeof buf,f)) { p=strchr(buf,'\n'); if(p) *p='\0'; if(buf[0] != '+') { fprintf(stderr,"Don't understand line '%s' from child %d\n", buf,n); continue; } printf("Got: %s from %d\n",buf,n); if(!strncmp(buf,"+F:",3)) { int alg; int j; p=buf+3; alg=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); for(j=0 ; j < SIZE_NUM ; ++j) results[alg][j]+=atof(sstrsep(&p,sep)); } else if(!strncmp(buf,"+F2:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); else rsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); else rsa_results[k][1]=d; } else if(!strncmp(buf,"+F2:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); else rsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); else rsa_results[k][1]=d; } else if(!strncmp(buf,"+F3:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); else dsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); else dsa_results[k][1]=d; } else if(!strncmp(buf,"+H:",3)) { } else fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); } } return 1; }
['static int do_multi(int multi)\n\t{\n\tint n;\n\tint fd[2];\n\tint *fds;\n\tstatic char sep[]=":";\n\tfds=malloc(multi*sizeof *fds);\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tpipe(fd);\n\t\tif(fork())\n\t\t\t{\n\t\t\tclose(fd[1]);\n\t\t\tfds[n]=fd[0];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tclose(fd[0]);\n\t\t\tclose(1);\n\t\t\tdup(fd[1]);\n\t\t\tclose(fd[1]);\n\t\t\tmr=1;\n\t\t\tusertime=0;\n\t\t\treturn 0;\n\t\t\t}\n\t\tprintf("Forked child %d\\n",n);\n\t\t}\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tFILE *f;\n\t\tchar buf[1024];\n\t\tchar *p;\n\t\tf=fdopen(fds[n],"r");\n\t\twhile(fgets(buf,sizeof buf,f))\n\t\t\t{\n\t\t\tp=strchr(buf,\'\\n\');\n\t\t\tif(p)\n\t\t\t\t*p=\'\\0\';\n\t\t\tif(buf[0] != \'+\')\n\t\t\t\t{\n\t\t\t\tfprintf(stderr,"Don\'t understand line \'%s\' from child %d\\n",\n\t\t\t\t\t\tbuf,n);\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tprintf("Got: %s from %d\\n",buf,n);\n\t\t\tif(!strncmp(buf,"+F:",3))\n\t\t\t\t{\n\t\t\t\tint alg;\n\t\t\t\tint j;\n\t\t\t\tp=buf+3;\n\t\t\t\talg=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\tfor(j=0 ; j < SIZE_NUM ; ++j)\n\t\t\t\t\tresults[alg][j]+=atof(sstrsep(&p,sep));\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F3:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+H:",3))\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tfprintf(stderr,"Unknown type \'%s\' from child %d\\n",buf,n);\n\t\t\t}\n\t\t}\n\treturn 1;\n\t}']
34,995
0
https://github.com/libav/libav/blob/447a5b1996805e9e91acc5cb459ea1a047db12a1/ffmpeg.c/#L3646
static void opt_output_file(const char *filename) { AVFormatContext *oc; int err, use_video, use_audio, use_subtitle; int input_has_video, input_has_audio, input_has_subtitle; AVFormatParameters params, *ap = &params; AVOutputFormat *file_oformat; if (!strcmp(filename, "-")) filename = "pipe:"; oc = avformat_alloc_context(); if (!oc) { print_error(filename, AVERROR(ENOMEM)); av_exit(1); } if (last_asked_format) { file_oformat = av_guess_format(last_asked_format, NULL, NULL); if (!file_oformat) { fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format); av_exit(1); } last_asked_format = NULL; } else { file_oformat = av_guess_format(NULL, filename, NULL); if (!file_oformat) { fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); av_exit(1); } } oc->oformat = file_oformat; av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && av_strstart(filename, "http:", NULL)) { int err = read_ffserver_streams(oc, filename); if (err < 0) { print_error(filename, err); av_exit(1); } } else { use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; if (nb_input_files > 0) { check_audio_video_sub_inputs(&input_has_video, &input_has_audio, &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; if (!input_has_subtitle) use_subtitle = 0; } if (audio_disable) { use_audio = 0; } if (video_disable) { use_video = 0; } if (subtitle_disable) { use_subtitle = 0; } if (use_video) { new_video_stream(oc); } if (use_audio) { new_audio_stream(oc); } if (use_subtitle) { new_subtitle_stream(oc); } oc->timestamp = rec_timestamp; for(; metadata_count>0; metadata_count--){ av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key, metadata[metadata_count-1].value, 0); } av_metadata_conv(oc, oc->oformat->metadata_conv, NULL); } output_files[nb_output_files++] = oc; if (oc->oformat->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(oc->filename)) { print_error(oc->filename, AVERROR_NUMEXPECTED); av_exit(1); } } if (!(oc->oformat->flags & AVFMT_NOFILE)) { if (!file_overwrite && (strchr(filename, ':') == NULL || filename[1] == ':' || av_strstart(filename, "file:", NULL))) { if (url_exist(filename)) { if (!using_stdin) { fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename); fflush(stderr); if (!read_yesno()) { fprintf(stderr, "Not overwriting - exiting\n"); av_exit(1); } } else { fprintf(stderr,"File '%s' already exists. Exiting.\n", filename); av_exit(1); } } } if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) { print_error(filename, err); av_exit(1); } } memset(ap, 0, sizeof(*ap)); if (av_set_parameters(oc, ap) < 0) { fprintf(stderr, "%s: Invalid encoding parameters\n", oc->filename); av_exit(1); } oc->preload= (int)(mux_preload*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->loop_output = loop_output; oc->flags |= AVFMT_FLAG_NONBLOCK; set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM); }
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = &params;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n av_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n av_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n av_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) {\n use_audio = 0;\n }\n if (video_disable) {\n use_video = 0;\n }\n if (subtitle_disable) {\n use_subtitle = 0;\n }\n if (use_video) {\n new_video_stream(oc);\n }\n if (use_audio) {\n new_audio_stream(oc);\n }\n if (use_subtitle) {\n new_subtitle_stream(oc);\n }\n oc->timestamp = rec_timestamp;\n for(; metadata_count>0; metadata_count--){\n av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key,\n metadata[metadata_count-1].value, 0);\n }\n av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n av_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n av_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n av_exit(1);\n }\n }\n }\n if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n av_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n char errbuf[128];\n const char *errbuf_ptr = errbuf;\n if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n errbuf_ptr = strerror(AVUNERROR(err));\n fprintf(stderr, "%s: %s\\n", filename, errbuf_ptr);\n}', 'int av_strerror(int errnum, char *errbuf, size_t errbuf_size)\n{\n int ret = 0;\n const char *errstr = NULL;\n switch (errnum) {\n case AVERROR_EOF: errstr = "End of file"; break;\n case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input"; break;\n case AVERROR_NUMEXPECTED: errstr = "Number syntax expected in filename"; break;\n case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break;\n }\n if (errstr) {\n av_strlcpy(errbuf, errstr, errbuf_size);\n } else {\n#if HAVE_STRERROR_R\n ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);\n#else\n ret = -1;\n#endif\n if (ret < 0)\n snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);\n }\n return ret;\n}']
34,996
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L340
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (offset == 0) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_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 void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
34,997
0
https://github.com/libav/libav/blob/aff8810172f35e1a4e5d1aa180591760add2b6e6/libavcodec/ffv1.c/#L475
static inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){ PlaneContext * const p= &s->plane[plane_index]; RangeCoder * const c= &s->c; int x; int run_index= s->run_index; int run_count=0; int run_mode=0; if(s->ac){ if(c->bytestream_end - c->bytestream < w*20){ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; } }else{ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < w*4){ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return -1; } } for(x=0; x<w; x++){ int diff, context; context= get_context(p, sample[0]+x, sample[1]+x, sample[2]+x); diff= sample[0][x] - predict(sample[0]+x, sample[1]+x); if(context < 0){ context = -context; diff= -diff; } diff= fold(diff, bits); if(s->ac){ put_symbol_inline(c, p->state[context], diff, 1); }else{ if(context == 0) run_mode=1; if(run_mode){ if(diff){ while(run_count >= 1<<ff_log2_run[run_index]){ run_count -= 1<<ff_log2_run[run_index]; run_index++; put_bits(&s->pb, 1, 1); } put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count); if(run_index) run_index--; run_count=0; run_mode=0; if(diff>0) diff--; }else{ run_count++; } } if(run_mode == 0) put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits); } } if(run_mode){ while(run_count >= 1<<ff_log2_run[run_index]){ run_count -= 1<<ff_log2_run[run_index]; run_index++; put_bits(&s->pb, 1, 1); } if(run_count) put_bits(&s->pb, 1, 1); } s->run_index= run_index; return 0; }
['static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){\n int x, y, p, i;\n const int ring_size= s->avctx->context_model ? 3 : 2;\n int_fast16_t *sample[3][3];\n s->run_index=0;\n memset(s->sample_buffer, 0, ring_size*3*(w+6)*sizeof(*s->sample_buffer));\n for(y=0; y<h; y++){\n for(i=0; i<ring_size; i++)\n for(p=0; p<3; p++)\n sample[p][i]= s->sample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;\n for(x=0; x<w; x++){\n int v= src[x + stride*y];\n int b= v&0xFF;\n int g= (v>>8)&0xFF;\n int r= (v>>16)&0xFF;\n b -= g;\n r -= g;\n g += (b + r)>>2;\n b += 0x100;\n r += 0x100;\n sample[0][0][x]= g;\n sample[1][0][x]= b;\n sample[2][0][x]= r;\n }\n for(p=0; p<3; p++){\n sample[p][0][-1]= sample[p][1][0 ];\n sample[p][1][ w]= sample[p][1][w-1];\n encode_line(s, w, sample[p], FFMIN(p, 1), 9);\n }\n }\n}', 'static inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){\n PlaneContext * const p= &s->plane[plane_index];\n RangeCoder * const c= &s->c;\n int x;\n int run_index= s->run_index;\n int run_count=0;\n int run_mode=0;\n if(s->ac){\n if(c->bytestream_end - c->bytestream < w*20){\n av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\\n");\n return -1;\n }\n }else{\n if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < w*4){\n av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\\n");\n return -1;\n }\n }\n for(x=0; x<w; x++){\n int diff, context;\n context= get_context(p, sample[0]+x, sample[1]+x, sample[2]+x);\n diff= sample[0][x] - predict(sample[0]+x, sample[1]+x);\n if(context < 0){\n context = -context;\n diff= -diff;\n }\n diff= fold(diff, bits);\n if(s->ac){\n put_symbol_inline(c, p->state[context], diff, 1);\n }else{\n if(context == 0) run_mode=1;\n if(run_mode){\n if(diff){\n while(run_count >= 1<<ff_log2_run[run_index]){\n run_count -= 1<<ff_log2_run[run_index];\n run_index++;\n put_bits(&s->pb, 1, 1);\n }\n put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);\n if(run_index) run_index--;\n run_count=0;\n run_mode=0;\n if(diff>0) diff--;\n }else{\n run_count++;\n }\n }\n if(run_mode == 0)\n put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);\n }\n }\n if(run_mode){\n while(run_count >= 1<<ff_log2_run[run_index]){\n run_count -= 1<<ff_log2_run[run_index];\n run_index++;\n put_bits(&s->pb, 1, 1);\n }\n if(run_count)\n put_bits(&s->pb, 1, 1);\n }\n s->run_index= run_index;\n return 0;\n}']
34,998
0
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/crypto/bn/bn_shift.c/#L110
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } r->neg = a->neg; nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x,\n BIGNUM *a, BIGNUM *u)\n{\n BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL\n || a == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((tmp = BN_new()) == NULL ||\n (tmp2 = BN_new()) == NULL ||\n (tmp3 = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, g, x, N, bn_ctx))\n goto err;\n if ((k = srp_Calc_k(N, g)) == NULL)\n goto err;\n if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))\n goto err;\n if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))\n goto err;\n if (!BN_mul(tmp3, u, x, bn_ctx))\n goto err;\n if (!BN_add(tmp2, a, tmp3))\n goto err;\n K = BN_new();\n if (K != NULL && !BN_mod_exp(K, tmp, tmp2, N, bn_ctx)) {\n BN_free(K);\n K = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n BN_clear_free(tmp2);\n BN_clear_free(tmp3);\n BN_free(k);\n return K;\n}', 'int BN_mod_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_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 res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n r->neg = a->neg;\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
34,999
0
https://github.com/libav/libav/blob/cc20fbcd39c7b60602edae4f7deb092ecfd3c975/libavcodec/vp9dsp.c/#L1615
static av_always_inline void loop_filter(uint8_t *dst, ptrdiff_t stride, int E, int I, int H, ptrdiff_t stridea, ptrdiff_t strideb, int wd) { int i; for (i = 0; i < 8; i++, dst += stridea) { int p7, p6, p5, p4; int p3 = dst[strideb * -4], p2 = dst[strideb * -3]; int p1 = dst[strideb * -2], p0 = dst[strideb * -1]; int q0 = dst[strideb * +0], q1 = dst[strideb * +1]; int q2 = dst[strideb * +2], q3 = dst[strideb * +3]; int q4, q5, q6, q7; int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I && FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I && FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I && FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E; int flat8out, flat8in; if (!fm) continue; if (wd >= 16) { p7 = dst[strideb * -8]; p6 = dst[strideb * -7]; p5 = dst[strideb * -6]; p4 = dst[strideb * -5]; q4 = dst[strideb * +4]; q5 = dst[strideb * +5]; q6 = dst[strideb * +6]; q7 = dst[strideb * +7]; flat8out = FFABS(p7 - p0) <= 1 && FFABS(p6 - p0) <= 1 && FFABS(p5 - p0) <= 1 && FFABS(p4 - p0) <= 1 && FFABS(q4 - q0) <= 1 && FFABS(q5 - q0) <= 1 && FFABS(q6 - q0) <= 1 && FFABS(q7 - q0) <= 1; } if (wd >= 8) flat8in = FFABS(p3 - p0) <= 1 && FFABS(p2 - p0) <= 1 && FFABS(p1 - p0) <= 1 && FFABS(q1 - q0) <= 1 && FFABS(q2 - q0) <= 1 && FFABS(q3 - q0) <= 1; if (wd >= 16 && flat8out && flat8in) { dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 + p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4; dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 + p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4; dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 + p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4; dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 + p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4; dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4; dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4; dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4; dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4; dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4; dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4; dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4; dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4; dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 + q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4; dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 + q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4; } else if (wd >= 8 && flat8in) { dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3; dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3; dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3; dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3; dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3; dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3; } else { int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H; if (hev) { int f = av_clip_int8(3 * (q0 - p0) + av_clip_int8(p1 - q1)); int f1 = FFMIN(f + 4, 127) >> 3; int f2 = FFMIN(f + 3, 127) >> 3; dst[strideb * -1] = av_clip_uint8(p0 + f2); dst[strideb * +0] = av_clip_uint8(q0 - f1); } else { int f = av_clip_int8(3 * (q0 - p0)); int f1 = FFMIN(f + 4, 127) >> 3; int f2 = FFMIN(f + 3, 127) >> 3; dst[strideb * -1] = av_clip_uint8(p0 + f2); dst[strideb * +0] = av_clip_uint8(q0 - f1); f = (f1 + 1) >> 1; dst[strideb * -2] = av_clip_uint8(p1 + f); dst[strideb * +1] = av_clip_uint8(q1 - f); } } } }
['static av_always_inline void loop_filter(uint8_t *dst, ptrdiff_t stride,\n int E, int I, int H,\n ptrdiff_t stridea, ptrdiff_t strideb,\n int wd)\n{\n int i;\n for (i = 0; i < 8; i++, dst += stridea) {\n int p7, p6, p5, p4;\n int p3 = dst[strideb * -4], p2 = dst[strideb * -3];\n int p1 = dst[strideb * -2], p0 = dst[strideb * -1];\n int q0 = dst[strideb * +0], q1 = dst[strideb * +1];\n int q2 = dst[strideb * +2], q3 = dst[strideb * +3];\n int q4, q5, q6, q7;\n int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I &&\n FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I &&\n FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I &&\n FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E;\n int flat8out, flat8in;\n if (!fm)\n continue;\n if (wd >= 16) {\n p7 = dst[strideb * -8];\n p6 = dst[strideb * -7];\n p5 = dst[strideb * -6];\n p4 = dst[strideb * -5];\n q4 = dst[strideb * +4];\n q5 = dst[strideb * +5];\n q6 = dst[strideb * +6];\n q7 = dst[strideb * +7];\n flat8out = FFABS(p7 - p0) <= 1 && FFABS(p6 - p0) <= 1 &&\n FFABS(p5 - p0) <= 1 && FFABS(p4 - p0) <= 1 &&\n FFABS(q4 - q0) <= 1 && FFABS(q5 - q0) <= 1 &&\n FFABS(q6 - q0) <= 1 && FFABS(q7 - q0) <= 1;\n }\n if (wd >= 8)\n flat8in = FFABS(p3 - p0) <= 1 && FFABS(p2 - p0) <= 1 &&\n FFABS(p1 - p0) <= 1 && FFABS(q1 - q0) <= 1 &&\n FFABS(q2 - q0) <= 1 && FFABS(q3 - q0) <= 1;\n if (wd >= 16 && flat8out && flat8in) {\n dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 +\n p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;\n dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 +\n p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;\n dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 +\n p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;\n dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 +\n p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;\n dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 +\n p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;\n dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 +\n p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;\n dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 +\n q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;\n dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 +\n q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4;\n dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 +\n q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4;\n dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 +\n q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 +\n q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 +\n q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 +\n q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 +\n q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;\n } else if (wd >= 8 && flat8in) {\n dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;\n dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;\n dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;\n dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;\n dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;\n dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;\n } else {\n int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H;\n if (hev) {\n int f = av_clip_int8(3 * (q0 - p0) + av_clip_int8(p1 - q1));\n int f1 = FFMIN(f + 4, 127) >> 3;\n int f2 = FFMIN(f + 3, 127) >> 3;\n dst[strideb * -1] = av_clip_uint8(p0 + f2);\n dst[strideb * +0] = av_clip_uint8(q0 - f1);\n } else {\n int f = av_clip_int8(3 * (q0 - p0));\n int f1 = FFMIN(f + 4, 127) >> 3;\n int f2 = FFMIN(f + 3, 127) >> 3;\n dst[strideb * -1] = av_clip_uint8(p0 + f2);\n dst[strideb * +0] = av_clip_uint8(q0 - f1);\n f = (f1 + 1) >> 1;\n dst[strideb * -2] = av_clip_uint8(p1 + f);\n dst[strideb * +1] = av_clip_uint8(q1 - f);\n }\n }\n }\n}']
35,000
0
https://github.com/libav/libav/blob/225e84e74544062706c0159ec0737b0e1d40915f/libavformat/hls.c/#L495
static int save_avio_options(AVFormatContext *s) { HLSContext *c = s->priv_data; const char *opts[] = { "headers", "user_agent", NULL }, **opt = opts; uint8_t *buf; int ret = 0; while (*opt) { if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) { ret = av_dict_set(&c->avio_opts, *opt, buf, AV_DICT_DONT_STRDUP_VAL); if (ret < 0) return ret; } opt++; } return ret; }
['static int save_avio_options(AVFormatContext *s)\n{\n HLSContext *c = s->priv_data;\n const char *opts[] = { "headers", "user_agent", NULL }, **opt = opts;\n uint8_t *buf;\n int ret = 0;\n while (*opt) {\n if (av_opt_get(s->pb, *opt, AV_OPT_SEARCH_CHILDREN, &buf) >= 0) {\n ret = av_dict_set(&c->avio_opts, *opt, buf,\n AV_DICT_DONT_STRDUP_VAL);\n if (ret < 0)\n return ret;\n }\n opt++;\n }\n return ret;\n}', 'int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)\n{\n void *dst, *target_obj;\n const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);\n uint8_t *bin, buf[128];\n int len, i, ret;\n if (!o || !target_obj)\n return AVERROR_OPTION_NOT_FOUND;\n dst = (uint8_t*)target_obj + o->offset;\n buf[0] = 0;\n switch (o->type) {\n case AV_OPT_TYPE_FLAGS: ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);break;\n case AV_OPT_TYPE_INT: ret = snprintf(buf, sizeof(buf), "%d" , *(int *)dst);break;\n case AV_OPT_TYPE_INT64: ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;\n case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break;\n case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break;\n case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;\n case AV_OPT_TYPE_STRING:\n if (*(uint8_t**)dst)\n *out_val = av_strdup(*(uint8_t**)dst);\n else\n *out_val = av_strdup("");\n return *out_val ? 0 : AVERROR(ENOMEM);\n case AV_OPT_TYPE_BINARY:\n len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));\n if ((uint64_t)len*2 + 1 > INT_MAX)\n return AVERROR(EINVAL);\n if (!(*out_val = av_malloc(len*2 + 1)))\n return AVERROR(ENOMEM);\n bin = *(uint8_t**)dst;\n for (i = 0; i < len; i++)\n snprintf(*out_val + i*2, 3, "%02X", bin[i]);\n return 0;\n default:\n return AVERROR(EINVAL);\n }\n if (ret >= sizeof(buf))\n return AVERROR(EINVAL);\n *out_val = av_strdup(buf);\n return *out_val ? 0 : AVERROR(ENOMEM);\n}', 'char *av_strdup(const char *s)\n{\n char *ptr = NULL;\n if (s) {\n int len = strlen(s) + 1;\n ptr = av_realloc(NULL, len);\n if (ptr)\n memcpy(ptr, s, len);\n }\n return ptr;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if (size > (INT_MAX - 16))\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if (!ptr)\n return av_malloc(size);\n diff = ((char *)ptr)[-1];\n return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}', 'int av_dict_set(AVDictionary **pm, const char *key, const char *value,\n int flags)\n{\n AVDictionary *m = *pm;\n AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags);\n char *oldval = NULL;\n int allocated = !!m;\n if (!m)\n m = *pm = av_mallocz(sizeof(*m));\n if (!m)\n return AVERROR(ENOMEM);\n if (tag) {\n if (flags & AV_DICT_DONT_OVERWRITE) {\n if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);\n if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);\n return 0;\n }\n if (flags & AV_DICT_APPEND)\n oldval = tag->value;\n else\n av_free(tag->value);\n av_free(tag->key);\n *tag = m->elems[--m->count];\n } else {\n int ret = av_reallocp_array(&m->elems,\n m->count + 1, sizeof(*m->elems));\n if (ret < 0) {\n if (allocated)\n av_freep(pm);\n return ret;\n }\n }\n if (value) {\n if (flags & AV_DICT_DONT_STRDUP_KEY)\n m->elems[m->count].key = key;\n else\n m->elems[m->count].key = av_strdup(key);\n if (flags & AV_DICT_DONT_STRDUP_VAL) {\n m->elems[m->count].value = value;\n } else if (oldval && flags & AV_DICT_APPEND) {\n int len = strlen(oldval) + strlen(value) + 1;\n if (!(oldval = av_realloc(oldval, len)))\n return AVERROR(ENOMEM);\n av_strlcat(oldval, value, len);\n m->elems[m->count].value = oldval;\n } else\n m->elems[m->count].value = av_strdup(value);\n m->count++;\n }\n if (!m->count) {\n av_free(m->elems);\n av_freep(pm);\n }\n return 0;\n}', 'int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n void *val;\n if (!size || nmemb >= INT_MAX / size)\n return AVERROR(ENOMEM);\n if (!nmemb) {\n av_freep(ptr);\n return 0;\n }\n memcpy(&val, ptr, sizeof(val));\n val = av_realloc(val, nmemb * size);\n if (!val) {\n av_freep(ptr);\n return AVERROR(ENOMEM);\n }\n memcpy(ptr, &val, sizeof(val));\n return 0;\n}']