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
601
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/rsa/rsa_eay.c/#L402
static int RSA_eay_public_decrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding) { BIGNUM f,ret; int i,num=0,r= -1; unsigned char *p; unsigned char *buf=NULL; BN_CTX *ctx=NULL; BN_init(&f); BN_init(&ret); ctx=BN_CTX_new(); if (ctx == NULL) goto err; num=BN_num_bytes(rsa->n); buf=(unsigned char *)Malloc(num); if (buf == NULL) { RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE); goto err; } if (flen > num) { RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN); goto err; } if (BN_bin2bn(from,flen,&f) == NULL) goto err; if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC)) { if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL) if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx)) goto err; } if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx, rsa->_method_mod_n)) goto err; p=buf; i=BN_bn2bin(&ret,p); switch (padding) { case RSA_PKCS1_PADDING: r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num); break; case RSA_NO_PADDING: r=RSA_padding_check_none(to,num,buf,i,num); break; default: RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE); goto err; } if (r < 0) RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED); err: if (ctx != NULL) BN_CTX_free(ctx); BN_clear_free(&f); BN_clear_free(&ret); if (buf != NULL) { memset(buf,0,num); Free(buf); } return(r); }
['static int RSA_eay_public_decrypt(int flen, unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM f,ret;\n\tint i,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tBN_init(&f);\n\tBN_init(&ret);\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tbuf=(unsigned char *)Malloc(num);\n\tif (buf == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (flen > num)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,flen,&f) == NULL) goto err;\n\tif ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))\n\t\t{\n\t\tif ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))\n\t\t\t goto err;\n\t\t}\n\tif (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tp=buf;\n\ti=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,i,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&f);\n\tBN_clear_free(&ret);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tFree(buf);\n\t\t}\n\treturn(r);\n\t}', 'void BN_init(BIGNUM *a)\n\t{\n\tmemset(a,0,sizeof(BIGNUM));\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\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}']
602
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/parser.c/#L201
int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe){ if(s && s->parser->split){ if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){ int i= s->parser->split(avctx, buf, buf_size); buf += i; buf_size -= i; } } *poutbuf= (uint8_t *) buf; *poutbuf_size= buf_size; if(avctx->extradata){ if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) ){ int size= buf_size + avctx->extradata_size; *poutbuf_size= size; *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); return 1; } } return 0; }
['int av_parser_change(AVCodecParserContext *s,\n AVCodecContext *avctx,\n uint8_t **poutbuf, int *poutbuf_size,\n const uint8_t *buf, int buf_size, int keyframe){\n if(s && s->parser->split){\n if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){\n int i= s->parser->split(avctx, buf, buf_size);\n buf += i;\n buf_size -= i;\n }\n }\n *poutbuf= (uint8_t *) buf;\n *poutbuf_size= buf_size;\n if(avctx->extradata){\n if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))\n ){\n int size= buf_size + avctx->extradata_size;\n *poutbuf_size= size;\n *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);\n memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);\n return 1;\n }\n }\n return 0;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr;\n#ifdef CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#ifdef CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif defined (HAVE_MEMALIGN)\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
603
0
https://github.com/libav/libav/blob/f97cb4515626228620d7317191c4c32f14eb1a1b/libavcodec/error_resilience.c/#L473
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, mot_step, mot_stride; set_mv_strides(s, &mot_step, &mot_stride); 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.f.mb_type[mb_xy])) f = MV_FROZEN; if (!(error & ER_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.f.mb_type[mb_xy])) continue; if (!(s->error_status_table[mb_xy] & ER_MV_ERROR)) continue; s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD; 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, 0); } } 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 ref[8] = { 0 }; int pred_count = 0; int j; int best_score = 256 * 256 * 256 * 64; int best_pred = 0; const int mot_index = (mb_x + mb_y * mot_stride) * mot_step; int prev_x, prev_y, prev_ref; if ((mb_x ^ mb_y ^ pass) & 1) continue; if (fixed[mb_xy] == MV_FROZEN) continue; assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy])); assert(s->last_picture_ptr && s->last_picture_ptr->f.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.f.motion_val[0][mot_index - mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index - mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy - 1)]; pred_count++; } if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index + mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index + mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy + 1)]; pred_count++; } if (mb_y > 0 && fixed[mb_xy - mb_stride]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)]; pred_count++; } if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) { mv_predictor[pred_count][0] = s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0]; mv_predictor[pred_count][1] = s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1]; ref[pred_count] = s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)]; pred_count++; } if (pred_count == 0) continue; if (pred_count > 1) { int sum_x = 0, sum_y = 0, sum_r = 0; int max_x, max_y, min_x, min_y, max_r, min_r; for (j = 0; j < pred_count; j++) { sum_x += mv_predictor[j][0]; sum_y += mv_predictor[j][1]; sum_r += ref[j]; if (j && ref[j] != ref[j - 1]) goto skip_mean_and_median; } mv_predictor[pred_count][0] = sum_x / j; mv_predictor[pred_count][1] = sum_y / j; ref[pred_count] = sum_r / j; if (pred_count >= 3) { min_y = min_x = min_r = 99999; max_y = max_x = max_r = -99999; } else { min_x = min_y = max_x = max_y = min_r = max_r = 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]); max_r = FFMAX(max_r, ref[j]); min_x = FFMIN(min_x, mv_predictor[j][0]); min_y = FFMIN(min_y, mv_predictor[j][1]); min_r = FFMIN(min_r, ref[j]); } mv_predictor[pred_count + 1][0] = sum_x - max_x - min_x; mv_predictor[pred_count + 1][1] = sum_y - max_y - min_y; ref[pred_count + 1] = sum_r - max_r - min_r; if (pred_count == 4) { mv_predictor[pred_count + 1][0] /= 2; mv_predictor[pred_count + 1][1] /= 2; ref[pred_count + 1] /= 2; } pred_count += 2; } skip_mean_and_median: pred_count++; if (!fixed[mb_xy]) { if (s->avctx->codec_id == CODEC_ID_H264) { } else { ff_thread_await_progress((AVFrame *) s->last_picture_ptr, mb_y, 0); } if (!s->last_picture.f.motion_val[0] || !s->last_picture.f.ref_index[0]) goto skip_last_mv; prev_x = s->last_picture.f.motion_val[0][mot_index][0]; prev_y = s->last_picture.f.motion_val[0][mot_index][1]; prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy]; } else { prev_x = s->current_picture.f.motion_val[0][mot_index][0]; prev_y = s->current_picture.f.motion_val[0][mot_index][1]; prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy]; } mv_predictor[pred_count][0] = prev_x; mv_predictor[pred_count][1] = prev_y; ref[pred_count] = prev_ref; pred_count++; skip_last_mv: 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.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; s->current_picture.f.motion_val[0][mot_index][0] = s->mv[0][0][0] = mv_predictor[j][0]; s->current_picture.f.motion_val[0][mot_index][1] = s->mv[0][0][1] = mv_predictor[j][1]; if (ref[j] < 0) continue; decode_mb(s, ref[j]); 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->mv[0][0][0] = mv_predictor[best_pred][0]; s->mv[0][0][1] = mv_predictor[best_pred][1]; for (i = 0; i < mot_step; i++) for (j = 0; j < mot_step; j++) { s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0]; s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1]; } decode_mb(s, ref[best_pred]); 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{\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, mot_step, mot_stride;\n set_mv_strides(s, &mot_step, &mot_stride);\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.f.mb_type[mb_xy]))\n f = MV_FROZEN;\n if (!(error & ER_MV_ERROR))\n 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)) ||\n 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.f.mb_type[mb_xy]))\n continue;\n if (!(s->error_status_table[mb_xy] & ER_MV_ERROR))\n continue;\n s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD\n : MV_DIR_BACKWARD;\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, 0);\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;\n int 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 ref[8] = { 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_index = (mb_x + mb_y * mot_stride) * mot_step;\n int prev_x, prev_y, prev_ref;\n if ((mb_x ^ mb_y ^ pass) & 1)\n continue;\n if (fixed[mb_xy] == MV_FROZEN)\n continue;\n assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy]));\n assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]);\n j = 0;\n if (mb_x > 0 && fixed[mb_xy - 1] == MV_FROZEN)\n j = 1;\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1] == MV_FROZEN)\n j = 1;\n if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_FROZEN)\n j = 1;\n if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_FROZEN)\n j = 1;\n if (j == 0)\n continue;\n j = 0;\n if (mb_x > 0 && fixed[mb_xy - 1 ] == MV_CHANGED)\n j = 1;\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1 ] == MV_CHANGED)\n j = 1;\n if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_CHANGED)\n j = 1;\n if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_CHANGED)\n j = 1;\n if (j == 0 && pass > 1)\n continue;\n none_left = 0;\n if (mb_x > 0 && fixed[mb_xy - 1]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index - mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index - mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy - 1)];\n pred_count++;\n }\n if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index + mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index + mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy + 1)];\n pred_count++;\n }\n if (mb_y > 0 && fixed[mb_xy - mb_stride]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)];\n pred_count++;\n }\n if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) {\n mv_predictor[pred_count][0] =\n s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0];\n mv_predictor[pred_count][1] =\n s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1];\n ref[pred_count] =\n s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)];\n pred_count++;\n }\n if (pred_count == 0)\n continue;\n if (pred_count > 1) {\n int sum_x = 0, sum_y = 0, sum_r = 0;\n int max_x, max_y, min_x, min_y, max_r, min_r;\n for (j = 0; j < pred_count; j++) {\n sum_x += mv_predictor[j][0];\n sum_y += mv_predictor[j][1];\n sum_r += ref[j];\n if (j && ref[j] != ref[j - 1])\n goto skip_mean_and_median;\n }\n mv_predictor[pred_count][0] = sum_x / j;\n mv_predictor[pred_count][1] = sum_y / j;\n ref[pred_count] = sum_r / j;\n if (pred_count >= 3) {\n min_y = min_x = min_r = 99999;\n max_y = max_x = max_r = -99999;\n } else {\n min_x = min_y = max_x = max_y = min_r = max_r = 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 max_r = FFMAX(max_r, ref[j]);\n min_x = FFMIN(min_x, mv_predictor[j][0]);\n min_y = FFMIN(min_y, mv_predictor[j][1]);\n min_r = FFMIN(min_r, ref[j]);\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 ref[pred_count + 1] = sum_r - max_r - min_r;\n if (pred_count == 4) {\n mv_predictor[pred_count + 1][0] /= 2;\n mv_predictor[pred_count + 1][1] /= 2;\n ref[pred_count + 1] /= 2;\n }\n pred_count += 2;\n }\nskip_mean_and_median:\n pred_count++;\n if (!fixed[mb_xy]) {\n if (s->avctx->codec_id == CODEC_ID_H264) {\n } else {\n ff_thread_await_progress((AVFrame *) s->last_picture_ptr,\n mb_y, 0);\n }\n if (!s->last_picture.f.motion_val[0] ||\n !s->last_picture.f.ref_index[0])\n goto skip_last_mv;\n prev_x = s->last_picture.f.motion_val[0][mot_index][0];\n prev_y = s->last_picture.f.motion_val[0][mot_index][1];\n prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy];\n } else {\n prev_x = s->current_picture.f.motion_val[0][mot_index][0];\n prev_y = s->current_picture.f.motion_val[0][mot_index][1];\n prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy];\n }\n mv_predictor[pred_count][0] = prev_x;\n mv_predictor[pred_count][1] = prev_y;\n ref[pred_count] = prev_ref;\n pred_count++;\nskip_last_mv:\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.f.data[0] +\n mb_x * 16 + mb_y * 16 * s->linesize;\n s->current_picture.f.motion_val[0][mot_index][0] =\n s->mv[0][0][0] = mv_predictor[j][0];\n s->current_picture.f.motion_val[0][mot_index][1] =\n s->mv[0][0][1] = mv_predictor[j][1];\n if (ref[j] < 0)\n continue;\n decode_mb(s, ref[j]);\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] -\n 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] -\n 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] -\n src[k + s->linesize * 16]);\n }\n if (score <= best_score) {\n best_score = score;\n best_pred = j;\n }\n }\n score_sum += best_score;\n s->mv[0][0][0] = mv_predictor[best_pred][0];\n s->mv[0][0][1] = mv_predictor[best_pred][1];\n for (i = 0; i < mot_step; i++)\n for (j = 0; j < mot_step; j++) {\n s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];\n s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];\n }\n decode_mb(s, ref[best_pred]);\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}']
604
0
https://github.com/libav/libav/blob/7c020e1ad37d27c9d5db4d714401f09c80e3cc44/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}']
605
0
https://github.com/openssl/openssl/blob/e7d961e994620dd5dee6d80794a07fb9de1bab66/ssl/packet.c/#L48
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { if (!ossl_assert(pkt->subs != NULL && len != 0)) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) { size_t newlen; size_t reflen; reflen = (len > pkt->buf->length) ? len : pkt->buf->length; if (reflen > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = reflen * 2; if (newlen < DEFAULT_BUF_SIZE) newlen = DEFAULT_BUF_SIZE; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } if (allocbytes != NULL) *allocbytes = WPACKET_get_curr(pkt); return 1; }
['EXT_RETURN tls_construct_stoc_status_request(SSL *s, WPACKET *pkt,\n unsigned int context, X509 *x,\n size_t chainidx)\n{\n if (!s->ext.status_expected)\n return EXT_RETURN_NOT_SENT;\n if (SSL_IS_TLS13(s) && chainidx != 0)\n return EXT_RETURN_NOT_SENT;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_STOC_STATUS_REQUEST, ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n if (SSL_IS_TLS13(s) && !tls_construct_cert_status_body(s, pkt)) {\n return EXT_RETURN_FAIL;\n }\n if (!WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_STOC_STATUS_REQUEST, ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n return EXT_RETURN_SENT;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n if (!ossl_assert(size <= sizeof(unsigned int))\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
606
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/flac.c/#L371
static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order) { int i, j; int coeff_prec, qlevel; int coeffs[pred_order]; int32_t *decoded = s->decoded[channel]; for (i = 0; i < pred_order; i++) { decoded[i] = get_sbits(&s->gb, s->curr_bps); } coeff_prec = get_bits(&s->gb, 4) + 1; if (coeff_prec == 16) { av_log(s->avctx, AV_LOG_DEBUG, "invalid coeff precision\n"); return -1; } qlevel = get_sbits(&s->gb, 5); if(qlevel < 0){ av_log(s->avctx, AV_LOG_DEBUG, "qlevel %d not supported, maybe buggy stream\n", qlevel); return -1; } for (i = 0; i < pred_order; i++) { coeffs[i] = get_sbits(&s->gb, coeff_prec); } if (decode_residuals(s, channel, pred_order) < 0) return -1; if (s->bps > 16) { int64_t sum; for (i = pred_order; i < s->blocksize; i++) { sum = 0; for (j = 0; j < pred_order; j++) sum += (int64_t)coeffs[j] * decoded[i-j-1]; decoded[i] += sum >> qlevel; } } else { for (i = pred_order; i < s->blocksize-1; i += 2) { int c; int d = decoded[i-pred_order]; int s0 = 0, s1 = 0; for (j = pred_order-1; j > 0; j--) { c = coeffs[j]; s0 += c*d; d = decoded[i-j]; s1 += c*d; } c = coeffs[0]; s0 += c*d; d = decoded[i] += s0 >> qlevel; s1 += c*d; decoded[i+1] += s1 >> qlevel; } if (i < s->blocksize) { int sum = 0; for (j = 0; j < pred_order; j++) sum += coeffs[j] * decoded[i-j-1]; decoded[i] += sum >> qlevel; } } return 0; }
['static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)\n{\n int i, j;\n int coeff_prec, qlevel;\n int coeffs[pred_order];\n int32_t *decoded = s->decoded[channel];\n for (i = 0; i < pred_order; i++)\n {\n decoded[i] = get_sbits(&s->gb, s->curr_bps);\n }\n coeff_prec = get_bits(&s->gb, 4) + 1;\n if (coeff_prec == 16)\n {\n av_log(s->avctx, AV_LOG_DEBUG, "invalid coeff precision\\n");\n return -1;\n }\n qlevel = get_sbits(&s->gb, 5);\n if(qlevel < 0){\n av_log(s->avctx, AV_LOG_DEBUG, "qlevel %d not supported, maybe buggy stream\\n", qlevel);\n return -1;\n }\n for (i = 0; i < pred_order; i++)\n {\n coeffs[i] = get_sbits(&s->gb, coeff_prec);\n }\n if (decode_residuals(s, channel, pred_order) < 0)\n return -1;\n if (s->bps > 16) {\n int64_t sum;\n for (i = pred_order; i < s->blocksize; i++)\n {\n sum = 0;\n for (j = 0; j < pred_order; j++)\n sum += (int64_t)coeffs[j] * decoded[i-j-1];\n decoded[i] += sum >> qlevel;\n }\n } else {\n for (i = pred_order; i < s->blocksize-1; i += 2)\n {\n int c;\n int d = decoded[i-pred_order];\n int s0 = 0, s1 = 0;\n for (j = pred_order-1; j > 0; j--)\n {\n c = coeffs[j];\n s0 += c*d;\n d = decoded[i-j];\n s1 += c*d;\n }\n c = coeffs[0];\n s0 += c*d;\n d = decoded[i] += s0 >> qlevel;\n s1 += c*d;\n decoded[i+1] += s1 >> qlevel;\n }\n if (i < s->blocksize)\n {\n int sum = 0;\n for (j = 0; j < pred_order; j++)\n sum += coeffs[j] * decoded[i-j-1];\n decoded[i] += sum >> qlevel;\n }\n }\n return 0;\n}']
607
1
https://github.com/libav/libav/blob/ce58ead40dd16f272ec1f127f04f69df67c7cd35/libavcodec/vp8dsp.c/#L210
static av_always_inline int normal_limit(uint8_t *p, ptrdiff_t stride, int E, int I) { LOAD_PIXELS return simple_limit(p, stride, E) && FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I && FFABS(p1 - p0) <= I && FFABS(q3 - q2) <= I && FFABS(q2 - q1) <= I && FFABS(q1 - q0) <= I; }
['static av_always_inline int normal_limit(uint8_t *p, ptrdiff_t stride,\n int E, int I)\n{\n LOAD_PIXELS\n return simple_limit(p, stride, E) &&\n FFABS(p3 - p2) <= I &&\n FFABS(p2 - p1) <= I &&\n FFABS(p1 - p0) <= I &&\n FFABS(q3 - q2) <= I &&\n FFABS(q2 - q1) <= I &&\n FFABS(q1 - q0) <= I;\n}']
608
0
https://github.com/openssl/openssl/blob/38d1b3cc0271008b8bd130a2c4b442775b028a08/crypto/bn/bn_shift.c/#L110
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,\n const EC_POINT *point,\n BIGNUM *x, BIGNUM *y,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *Z, *Z_1, *Z_2, *Z_3;\n const BIGNUM *Z_;\n int ret = 0;\n if (EC_POINT_is_at_infinity(group, point)) {\n ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES,\n EC_R_POINT_AT_INFINITY);\n return 0;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n Z = BN_CTX_get(ctx);\n Z_1 = BN_CTX_get(ctx);\n Z_2 = BN_CTX_get(ctx);\n Z_3 = BN_CTX_get(ctx);\n if (Z_3 == NULL)\n goto err;\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, Z, point->Z, ctx))\n goto err;\n Z_ = Z;\n } else {\n Z_ = point->Z;\n }\n if (BN_is_one(Z_)) {\n if (group->meth->field_decode) {\n if (x != NULL) {\n if (!group->meth->field_decode(group, x, point->X, ctx))\n goto err;\n }\n if (y != NULL) {\n if (!group->meth->field_decode(group, y, point->Y, ctx))\n goto err;\n }\n } else {\n if (x != NULL) {\n if (!BN_copy(x, point->X))\n goto err;\n }\n if (y != NULL) {\n if (!BN_copy(y, point->Y))\n goto err;\n }\n }\n } else {\n if (!BN_mod_inverse(Z_1, Z_, group->field, ctx)) {\n ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (group->meth->field_encode == 0) {\n if (!group->meth->field_sqr(group, Z_2, Z_1, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(Z_2, Z_1, group->field, ctx))\n goto err;\n }\n if (x != NULL) {\n if (!group->meth->field_mul(group, x, point->X, Z_2, ctx))\n goto err;\n }\n if (y != NULL) {\n if (group->meth->field_encode == 0) {\n if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx))\n goto err;\n } else {\n if (!BN_mod_mul(Z_3, Z_2, Z_1, group->field, ctx))\n goto err;\n }\n if (!group->meth->field_mul(group, y, point->Y, Z_3, ctx))\n goto err;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
609
0
https://github.com/libav/libav/blob/897d5c3a4296f3da80b8699d1487328ca2de8e55/libavcodec/mpegvideo_enc.c/#L1417
static void frame_end(MpegEncContext *s) { int i; if (s->unrestricted_mv && s->current_picture.reference && !s->intra_only) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); int hshift = desc->log2_chroma_w; int vshift = desc->log2_chroma_h; s->mpvencdsp.draw_edges(s->current_picture.f->data[0], s->linesize, s->h_edge_pos, s->v_edge_pos, EDGE_WIDTH, EDGE_WIDTH, EDGE_TOP | EDGE_BOTTOM); s->mpvencdsp.draw_edges(s->current_picture.f->data[1], s->uvlinesize, s->h_edge_pos >> hshift, s->v_edge_pos >> vshift, EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, EDGE_TOP | EDGE_BOTTOM); s->mpvencdsp.draw_edges(s->current_picture.f->data[2], s->uvlinesize, s->h_edge_pos >> hshift, s->v_edge_pos >> vshift, EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, EDGE_TOP | EDGE_BOTTOM); } emms_c(); s->last_pict_type = s->pict_type; s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality; if (s->pict_type!= AV_PICTURE_TYPE_B) s->last_non_b_pict_type = s->pict_type; if (s->encoding) { for (i = 0; i < MAX_PICTURE_COUNT; i++) { if (!s->picture[i].reference) ff_mpeg_unref_picture(s, &s->picture[i]); } } s->avctx->coded_frame = s->current_picture_ptr->f; }
['static void frame_end(MpegEncContext *s)\n{\n int i;\n if (s->unrestricted_mv &&\n s->current_picture.reference &&\n !s->intra_only) {\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);\n int hshift = desc->log2_chroma_w;\n int vshift = desc->log2_chroma_h;\n s->mpvencdsp.draw_edges(s->current_picture.f->data[0], s->linesize,\n s->h_edge_pos, s->v_edge_pos,\n EDGE_WIDTH, EDGE_WIDTH,\n EDGE_TOP | EDGE_BOTTOM);\n s->mpvencdsp.draw_edges(s->current_picture.f->data[1], s->uvlinesize,\n s->h_edge_pos >> hshift,\n s->v_edge_pos >> vshift,\n EDGE_WIDTH >> hshift,\n EDGE_WIDTH >> vshift,\n EDGE_TOP | EDGE_BOTTOM);\n s->mpvencdsp.draw_edges(s->current_picture.f->data[2], s->uvlinesize,\n s->h_edge_pos >> hshift,\n s->v_edge_pos >> vshift,\n EDGE_WIDTH >> hshift,\n EDGE_WIDTH >> vshift,\n EDGE_TOP | EDGE_BOTTOM);\n }\n emms_c();\n s->last_pict_type = s->pict_type;\n s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality;\n if (s->pict_type!= AV_PICTURE_TYPE_B)\n s->last_non_b_pict_type = s->pict_type;\n if (s->encoding) {\n for (i = 0; i < MAX_PICTURE_COUNT; i++) {\n if (!s->picture[i].reference)\n ff_mpeg_unref_picture(s, &s->picture[i]);\n }\n }\n s->avctx->coded_frame = s->current_picture_ptr->f;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
610
0
https://github.com/openssl/openssl/blob/3ba25ee86a3758cc659c954b59718d8397030768/crypto/asn1/t_x509.c/#L388
int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm) { char *v; int gmt=0; int i; int y=0,M=0,d=0,h=0,m=0,s=0; i=tm->length; v=(char *)tm->data; if (i < 12) goto err; if (v[i-1] == 'Z') gmt=1; for (i=0; i<12; i++) if ((v[i] > '9') || (v[i] < '0')) goto err; y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0'); M= (v[4]-'0')*10+(v[5]-'0'); if ((M > 12) || (M < 1)) goto err; d= (v[6]-'0')*10+(v[7]-'0'); h= (v[8]-'0')*10+(v[9]-'0'); m= (v[10]-'0')*10+(v[11]-'0'); if ( (v[12] >= '0') && (v[12] <= '9') && (v[13] >= '0') && (v[13] <= '9')) s= (v[12]-'0')*10+(v[13]-'0'); if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0) return(0); else return(1); err: BIO_write(bp,"Bad time value",14); return(0); }
['static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)\n{\n\tOCSP_CRLID *a = in;\n\tif (a->crlUrl)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;\n\t\tif (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\tif (a->crlNum)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;\n\t\tif (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\tif (a->crlTime)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;\n\t\tif (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\treturn 1;\n\terr:\n\treturn 0;\n}', "int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)\n\t{\n\tint i,n;\n\tchar buf[80],*p;;\n\tif (v == NULL) return(0);\n\tn=0;\n\tp=(char *)v->data;\n\tfor (i=0; i<v->length; i++)\n\t\t{\n\t\tif ((p[i] > '~') || ((p[i] < ' ') &&\n\t\t\t(p[i] != '\\n') && (p[i] != '\\r')))\n\t\t\tbuf[n]='.';\n\t\telse\n\t\t\tbuf[n]=p[i];\n\t\tn++;\n\t\tif (n >= 80)\n\t\t\t{\n\t\t\tif (BIO_write(bp,buf,n) <= 0)\n\t\t\t\treturn(0);\n\t\t\tn=0;\n\t\t\t}\n\t\t}\n\tif (n > 0)\n\t\tif (BIO_write(bp,buf,n) <= 0)\n\t\t\treturn(0);\n\treturn(1);\n\t}", 'int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)\n\t{\n\tchar *v;\n\tint gmt=0;\n\tint i;\n\tint y=0,M=0,d=0,h=0,m=0,s=0;\n\ti=tm->length;\n\tv=(char *)tm->data;\n\tif (i < 12) goto err;\n\tif (v[i-1] == \'Z\') gmt=1;\n\tfor (i=0; i<12; i++)\n\t\tif ((v[i] > \'9\') || (v[i] < \'0\')) goto err;\n\ty= (v[0]-\'0\')*1000+(v[1]-\'0\')*100 + (v[2]-\'0\')*10+(v[3]-\'0\');\n\tM= (v[4]-\'0\')*10+(v[5]-\'0\');\n\tif ((M > 12) || (M < 1)) goto err;\n\td= (v[6]-\'0\')*10+(v[7]-\'0\');\n\th= (v[8]-\'0\')*10+(v[9]-\'0\');\n\tm= (v[10]-\'0\')*10+(v[11]-\'0\');\n\tif (\t(v[12] >= \'0\') && (v[12] <= \'9\') &&\n\t\t(v[13] >= \'0\') && (v[13] <= \'9\'))\n\t\ts= (v[12]-\'0\')*10+(v[13]-\'0\');\n\tif (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",\n\t\tmon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)\n\t\treturn(0);\n\telse\n\t\treturn(1);\nerr:\n\tBIO_write(bp,"Bad time value",14);\n\treturn(0);\n\t}']
611
0
https://gitlab.com/libtiff/libtiff/blob/3adc33842b7533066daea2516741832edc44d5fd/libtiff/tif_read.c/#L948
static int TIFFStartTile(TIFF* tif, uint32 tile) { TIFFDirectory *td = &tif->tif_dir; if ((tif->tif_flags & TIFF_CODERSETUP) == 0) { if (!(*tif->tif_setupdecode)(tif)) return (0); tif->tif_flags |= TIFF_CODERSETUP; } tif->tif_curtile = tile; tif->tif_row = (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) * td->td_tilelength; tif->tif_col = (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) * td->td_tilewidth; tif->tif_flags &= ~TIFF_BUF4WRITE; if (tif->tif_flags&TIFF_NOREADRAW) { tif->tif_rawcp = NULL; tif->tif_rawcc = 0; } else { tif->tif_rawcp = tif->tif_rawdata; tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile]; } return ((*tif->tif_predecode)(tif, (uint16)(tile/td->td_stripsperimage))); }
['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(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\tt2p->pdf_xrefcount * sizeof(uint32) );\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\tstreamlen=written;\n\t\t\t\twritten += t2p_write_pdf_transfer_stream(t2p, output, i);\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}\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\tstreamlen=written;\n\t\t\twritten += t2p_write_pdf_xobject_palettecs_stream(t2p, output);\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}\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\tstreamlen=written;\n\t\t\twritten += t2p_write_pdf_xobject_icccs_stream(t2p, output);\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}\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 t2p_read_tiff_init(T2P* t2p, TIFF* input){\n\ttdir_t directorycount=0;\n\ttdir_t i=0;\n\tuint16 pagen=0;\n\tuint16 paged=0;\n\tuint16 xuint16=0;\n\tdirectorycount=TIFFNumberOfDirectories(input);\n\tt2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(directorycount * sizeof(T2P_PAGE));\n\tif(t2p->tiff_pages==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %lu bytes of memory for tiff_pages array, %s",\n\t\t\t(unsigned long) directorycount * sizeof(T2P_PAGE),\n\t\t\tTIFFFileName(input));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\t_TIFFmemset( t2p->tiff_pages, 0x00, directorycount * sizeof(T2P_PAGE));\n\tt2p->tiff_tiles = (T2P_TILES*) _TIFFmalloc(directorycount * sizeof(T2P_TILES));\n\tif(t2p->tiff_tiles==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %lu bytes of memory for tiff_tiles array, %s",\n\t\t\t(unsigned long) directorycount * sizeof(T2P_TILES),\n\t\t\tTIFFFileName(input));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\t_TIFFmemset( t2p->tiff_tiles, 0x00, directorycount * sizeof(T2P_TILES));\n\tfor(i=0;i<directorycount;i++){\n\t\tuint32 subfiletype = 0;\n\t\tif(!TIFFSetDirectory(input, i)){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"Can\'t set directory %u of input file %s",\n\t\t\t\ti,\n\t\t\t\tTIFFFileName(input));\n\t\t\treturn;\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)){\n\t\t\tif((pagen>paged) && (paged != 0)){\n\t\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number =\n\t\t\t\t\tpaged;\n\t\t\t} else {\n\t\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number =\n\t\t\t\t\tpagen;\n\t\t\t}\n\t\t\tgoto ispage2;\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_SUBFILETYPE, &subfiletype)){\n\t\t\tif ( ((subfiletype & FILETYPE_PAGE) != 0)\n || (subfiletype == 0)){\n\t\t\t\tgoto ispage;\n\t\t\t} else {\n\t\t\t\tgoto isnotpage;\n\t\t\t}\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_OSUBFILETYPE, &subfiletype)){\n\t\t\tif ((subfiletype == OFILETYPE_IMAGE)\n\t\t\t\t|| (subfiletype == OFILETYPE_PAGE)\n\t\t\t\t|| (subfiletype == 0) ){\n\t\t\t\tgoto ispage;\n\t\t\t} else {\n\t\t\t\tgoto isnotpage;\n\t\t\t}\n\t\t}\n\t\tispage:\n\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number=t2p->tiff_pagecount;\n\t\tispage2:\n\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_directory=i;\n\t\tif(TIFFIsTiled(input)){\n\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_tilecount =\n\t\t\t\tTIFFNumberOfTiles(input);\n\t\t}\n\t\tt2p->tiff_pagecount++;\n\t\tisnotpage:\n\t\t(void)0;\n\t}\n\tqsort((void*) t2p->tiff_pages, t2p->tiff_pagecount,\n sizeof(T2P_PAGE), t2p_cmp_t2p_page);\n\tfor(i=0;i<t2p->tiff_pagecount;i++){\n\t\tt2p->pdf_xrefcount += 5;\n\t\tTIFFSetDirectory(input, t2p->tiff_pages[i].page_directory );\n\t\tif((TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &xuint16)\n && (xuint16==PHOTOMETRIC_PALETTE))\n\t\t || TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)) {\n\t\t\tt2p->tiff_pages[i].page_extra++;\n\t\t\tt2p->pdf_xrefcount++;\n\t\t}\n#ifdef ZIP_SUPPORT\n\t\tif (TIFFGetField(input, TIFFTAG_COMPRESSION, &xuint16)) {\n if( (xuint16== COMPRESSION_DEFLATE ||\n xuint16== COMPRESSION_ADOBE_DEFLATE) &&\n ((t2p->tiff_pages[i].page_tilecount != 0)\n || TIFFNumberOfStrips(input)==1) &&\n (t2p->pdf_nopassthrough==0)\t){\n if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}\n }\n }\n#endif\n\t\tif (TIFFGetField(input, TIFFTAG_TRANSFERFUNCTION,\n &(t2p->tiff_transferfunction[0]),\n &(t2p->tiff_transferfunction[1]),\n &(t2p->tiff_transferfunction[2]))) {\n\t\t\tif(t2p->tiff_transferfunction[1] !=\n\t\t\t t2p->tiff_transferfunction[0]) {\n\t\t\t\tt2p->tiff_transferfunctioncount = 3;\n\t\t\t\tt2p->tiff_pages[i].page_extra += 4;\n\t\t\t\tt2p->pdf_xrefcount += 4;\n\t\t\t} else {\n\t\t\t\tt2p->tiff_transferfunctioncount = 1;\n\t\t\t\tt2p->tiff_pages[i].page_extra += 2;\n\t\t\t\tt2p->pdf_xrefcount += 2;\n\t\t\t}\n\t\t\tif(t2p->pdf_minorversion < 2)\n\t\t\t\tt2p->pdf_minorversion = 2;\n } else {\n\t\t\tt2p->tiff_transferfunctioncount=0;\n\t\t}\n\t\tif( TIFFGetField(\n\t\t\tinput,\n\t\t\tTIFFTAG_ICCPROFILE,\n\t\t\t&(t2p->tiff_iccprofilelength),\n\t\t\t&(t2p->tiff_iccprofile)) != 0){\n\t\t\tt2p->tiff_pages[i].page_extra++;\n\t\t\tt2p->pdf_xrefcount++;\n\t\t\tif(t2p->pdf_minorversion<3){t2p->pdf_minorversion=3;}\n\t\t}\n\t\tt2p->tiff_tiles[i].tiles_tilecount=\n\t\t\tt2p->tiff_pages[i].page_tilecount;\n\t\tif( (TIFFGetField(input, TIFFTAG_PLANARCONFIG, &xuint16) != 0)\n\t\t\t&& (xuint16 == PLANARCONFIG_SEPARATE ) ){\n\t\t\t\tTIFFGetField(input, TIFFTAG_SAMPLESPERPIXEL, &xuint16);\n\t\t\t\tt2p->tiff_tiles[i].tiles_tilecount/= xuint16;\n\t\t}\n\t\tif( t2p->tiff_tiles[i].tiles_tilecount > 0){\n\t\t\tt2p->pdf_xrefcount +=\n\t\t\t\t(t2p->tiff_tiles[i].tiles_tilecount -1)*2;\n\t\t\tTIFFGetField(input,\n\t\t\t\tTIFFTAG_TILEWIDTH,\n\t\t\t\t&( t2p->tiff_tiles[i].tiles_tilewidth) );\n\t\t\tTIFFGetField(input,\n\t\t\t\tTIFFTAG_TILELENGTH,\n\t\t\t\t&( t2p->tiff_tiles[i].tiles_tilelength) );\n\t\t\tt2p->tiff_tiles[i].tiles_tiles =\n\t\t\t(T2P_TILE*) _TIFFmalloc(\n\t\t\t\tt2p->tiff_tiles[i].tiles_tilecount\n\t\t\t\t* sizeof(T2P_TILE) );\n\t\t\tif( t2p->tiff_tiles[i].tiles_tiles == NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory for t2p_read_tiff_init, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_tiles[i].tiles_tilecount * sizeof(T2P_TILE),\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\treturn;\n}', 'void t2p_read_tiff_data(T2P* t2p, TIFF* input){\n\tint i=0;\n\tuint16* r;\n\tuint16* g;\n\tuint16* b;\n\tuint16* a;\n\tuint16 xuint16;\n\tuint16* xuint16p;\n\tfloat* xfloatp;\n\tt2p->pdf_transcode = T2P_TRANSCODE_ENCODE;\n\tt2p->pdf_sample = T2P_SAMPLE_NOTHING;\n t2p->pdf_switchdecode = t2p->pdf_colorspace_invert;\n\tTIFFSetDirectory(input, t2p->tiff_pages[t2p->pdf_page].page_directory);\n\tTIFFGetField(input, TIFFTAG_IMAGEWIDTH, &(t2p->tiff_width));\n\tif(t2p->tiff_width == 0){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with zero width",\n\t\t\tTIFFFileName(input)\t);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\tTIFFGetField(input, TIFFTAG_IMAGELENGTH, &(t2p->tiff_length));\n\tif(t2p->tiff_length == 0){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with zero length",\n\t\t\tTIFFFileName(input)\t);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n if(TIFFGetField(input, TIFFTAG_COMPRESSION, &(t2p->tiff_compression)) == 0){\n TIFFError(\n TIFF2PDF_MODULE,\n "No support for %s with no compression tag",\n TIFFFileName(input) );\n t2p->t2p_error = T2P_ERR_ERROR;\n return;\n }\n if( TIFFIsCODECConfigured(t2p->tiff_compression) == 0){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with compression type %u: not configured",\n\t\t\tTIFFFileName(input),\n\t\t\tt2p->tiff_compression\n\t\t\t);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\tTIFFGetFieldDefaulted(input, TIFFTAG_BITSPERSAMPLE, &(t2p->tiff_bitspersample));\n\tswitch(t2p->tiff_bitspersample){\n\t\tcase 1:\n\t\tcase 2:\n\t\tcase 4:\n\t\tcase 8:\n\t\t\tbreak;\n\t\tcase 0:\n\t\t\tTIFFWarning(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"Image %s has 0 bits per sample, assuming 1",\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->tiff_bitspersample=1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with %u bits per sample",\n\t\t\t\tTIFFFileName(input),\n\t\t\t\tt2p->tiff_bitspersample);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn;\n\t}\n\tTIFFGetFieldDefaulted(input, TIFFTAG_SAMPLESPERPIXEL, &(t2p->tiff_samplesperpixel));\n\tif(t2p->tiff_samplesperpixel>4){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with %u samples per pixel",\n\t\t\tTIFFFileName(input),\n\t\t\tt2p->tiff_samplesperpixel);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\tif(t2p->tiff_samplesperpixel==0){\n\t\tTIFFWarning(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Image %s has 0 samples per pixel, assuming 1",\n\t\t\tTIFFFileName(input));\n\t\tt2p->tiff_samplesperpixel=1;\n\t}\n\tif(TIFFGetField(input, TIFFTAG_SAMPLEFORMAT, &xuint16) != 0 ){\n\t\tswitch(xuint16){\n\t\t\tcase 0:\n\t\t\tcase 1:\n\t\t\tcase 4:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for %s with sample format %u",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\txuint16);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tTIFFGetFieldDefaulted(input, TIFFTAG_FILLORDER, &(t2p->tiff_fillorder));\n if(TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &(t2p->tiff_photometric)) == 0){\n TIFFError(\n TIFF2PDF_MODULE,\n "No support for %s with no photometric interpretation tag",\n TIFFFileName(input) );\n t2p->t2p_error = T2P_ERR_ERROR;\n return;\n }\n\tswitch(t2p->tiff_photometric){\n\t\tcase PHOTOMETRIC_MINISWHITE:\n\t\tcase PHOTOMETRIC_MINISBLACK:\n\t\t\tif (t2p->tiff_bitspersample==1){\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_BILEVEL;\n\t\t\t\tif(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){\n\t\t\t\t\tt2p->pdf_switchdecode ^= 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_GRAY;\n\t\t\t\tif(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){\n\t\t\t\t\tt2p->pdf_switchdecode ^= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_RGB:\n\t\t\tt2p->pdf_colorspace=T2P_CS_RGB;\n\t\t\tif(t2p->tiff_samplesperpixel == 3){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)){\n\t\t\t\tif(xuint16==1)\n\t\t\t\t\tgoto photometric_palette;\n\t\t\t}\n\t\t\tif(t2p->tiff_samplesperpixel > 3) {\n\t\t\t\tif(t2p->tiff_samplesperpixel == 4) {\n\t\t\t\t\tt2p->pdf_colorspace = T2P_CS_RGB;\n\t\t\t\t\tif(TIFFGetField(input,\n\t\t\t\t\t\t\tTIFFTAG_EXTRASAMPLES,\n\t\t\t\t\t\t\t&xuint16, &xuint16p)\n\t\t\t\t\t && xuint16 == 1) {\n\t\t\t\t\t\tif(xuint16p[0] == EXTRASAMPLE_ASSOCALPHA){\n\t\t\t\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_RGBAA_TO_RGB;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(xuint16p[0] == EXTRASAMPLE_UNASSALPHA){\n\t\t\t\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_RGBA_TO_RGB;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tTIFFWarning(\n\t\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t\t"RGB image %s has 4 samples per pixel, assuming RGBA",\n\t\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tt2p->pdf_colorspace=T2P_CS_CMYK;\n\t\t\t\t\tt2p->pdf_switchdecode ^= 1;\n\t\t\t\t\tTIFFWarning(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"RGB image %s has 4 samples per pixel, assuming inverse CMYK",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tTIFFError(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"No support for RGB image %s with %u samples per pixel",\n\t\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\t\tt2p->tiff_samplesperpixel);\n\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for RGB image %s with %u samples per pixel",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\tt2p->tiff_samplesperpixel);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tcase PHOTOMETRIC_PALETTE:\n\t\t\tphotometric_palette:\n\t\t\tif(t2p->tiff_samplesperpixel!=1){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for palettized image %s with not one sample per pixel",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tt2p->pdf_colorspace=T2P_CS_RGB | T2P_CS_PALETTE;\n\t\t\tt2p->pdf_palettesize=0x0001<<t2p->tiff_bitspersample;\n\t\t\tif(!TIFFGetField(input, TIFFTAG_COLORMAP, &r, &g, &b)){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Palettized image %s has no color map",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(t2p->pdf_palette != NULL){\n\t\t\t\t_TIFFfree(t2p->pdf_palette);\n\t\t\t\tt2p->pdf_palette=NULL;\n\t\t\t}\n\t\t\tt2p->pdf_palette = (unsigned char*)\n\t\t\t\t_TIFFmalloc(t2p->pdf_palettesize*3);\n\t\t\tif(t2p->pdf_palette==NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %u bytes of memory for t2p_read_tiff_image, %s",\n\t\t\t\t\tt2p->pdf_palettesize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(i=0;i<t2p->pdf_palettesize;i++){\n\t\t\t\tt2p->pdf_palette[(i*3)] = (unsigned char) (r[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*3)+1]= (unsigned char) (g[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*3)+2]= (unsigned char) (b[i]>>8);\n\t\t\t}\n\t\t\tt2p->pdf_palettesize *= 3;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_SEPARATED:\n\t\t\tif(TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)){\n\t\t\t\tif(xuint16==1){\n\t\t\t\t\t\tgoto photometric_palette_cmyk;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif( TIFFGetField(input, TIFFTAG_INKSET, &xuint16) ){\n\t\t\t\tif(xuint16 != INKSET_CMYK){\n\t\t\t\t\tTIFFError(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"No support for %s because its inkset is not CMYK",\n\t\t\t\t\t\tTIFFFileName(input) );\n\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(t2p->tiff_samplesperpixel==4){\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_CMYK;\n\t\t\t} else {\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for %s because it has %u samples per pixel",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\tt2p->tiff_samplesperpixel);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbreak;\n\t\t\tphotometric_palette_cmyk:\n\t\t\tif(t2p->tiff_samplesperpixel!=1){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for palettized CMYK image %s with not one sample per pixel",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tt2p->pdf_colorspace=T2P_CS_CMYK | T2P_CS_PALETTE;\n\t\t\tt2p->pdf_palettesize=0x0001<<t2p->tiff_bitspersample;\n\t\t\tif(!TIFFGetField(input, TIFFTAG_COLORMAP, &r, &g, &b, &a)){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Palettized image %s has no color map",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(t2p->pdf_palette != NULL){\n\t\t\t\t_TIFFfree(t2p->pdf_palette);\n\t\t\t\tt2p->pdf_palette=NULL;\n\t\t\t}\n\t\t\tt2p->pdf_palette = (unsigned char*)\n\t\t\t\t_TIFFmalloc(t2p->pdf_palettesize*4);\n\t\t\tif(t2p->pdf_palette==NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %u bytes of memory for t2p_read_tiff_image, %s",\n\t\t\t\t\tt2p->pdf_palettesize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(i=0;i<t2p->pdf_palettesize;i++){\n\t\t\t\tt2p->pdf_palette[(i*4)] = (unsigned char) (r[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*4)+1]= (unsigned char) (g[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*4)+2]= (unsigned char) (b[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*4)+3]= (unsigned char) (a[i]>>8);\n\t\t\t}\n\t\t\tt2p->pdf_palettesize *= 4;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_YCBCR:\n\t\t\tt2p->pdf_colorspace=T2P_CS_RGB;\n\t\t\tif(t2p->tiff_samplesperpixel==1){\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_GRAY;\n\t\t\t\tt2p->tiff_photometric=PHOTOMETRIC_MINISBLACK;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt2p->pdf_sample=T2P_SAMPLE_YCBCR_TO_RGB;\n#ifdef JPEG_SUPPORT\n\t\t\tif(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){\n\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_NOTHING;\n\t\t\t}\n#endif\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_CIELAB:\n\t\t\tt2p->pdf_labrange[0]= -127;\n\t\t\tt2p->pdf_labrange[1]= 127;\n\t\t\tt2p->pdf_labrange[2]= -127;\n\t\t\tt2p->pdf_labrange[3]= 127;\n\t\t\tt2p->pdf_sample=T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED;\n\t\t\tt2p->pdf_colorspace=T2P_CS_LAB;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_ICCLAB:\n\t\t\tt2p->pdf_labrange[0]= 0;\n\t\t\tt2p->pdf_labrange[1]= 255;\n\t\t\tt2p->pdf_labrange[2]= 0;\n\t\t\tt2p->pdf_labrange[3]= 255;\n\t\t\tt2p->pdf_colorspace=T2P_CS_LAB;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_ITULAB:\n\t\t\tt2p->pdf_labrange[0]=-85;\n\t\t\tt2p->pdf_labrange[1]=85;\n\t\t\tt2p->pdf_labrange[2]=-75;\n\t\t\tt2p->pdf_labrange[3]=124;\n\t\t\tt2p->pdf_sample=T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED;\n\t\t\tt2p->pdf_colorspace=T2P_CS_LAB;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_LOGL:\n\t\tcase PHOTOMETRIC_LOGLUV:\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with photometric interpretation LogL/LogLuv",\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn;\n\t\tdefault:\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with photometric interpretation %u",\n\t\t\t\tTIFFFileName(input),\n\t\t\t\tt2p->tiff_photometric);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn;\n\t}\n\tif(TIFFGetField(input, TIFFTAG_PLANARCONFIG, &(t2p->tiff_planar))){\n\t\tswitch(t2p->tiff_planar){\n\t\t\tcase 0:\n\t\t\t\tTIFFWarning(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Image %s has planar configuration 0, assuming 1",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->tiff_planar=PLANARCONFIG_CONTIG;\n\t\t\tcase PLANARCONFIG_CONTIG:\n\t\t\t\tbreak;\n\t\t\tcase PLANARCONFIG_SEPARATE:\n\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG;\n\t\t\t\tif(t2p->tiff_bitspersample!=8){\n\t\t\t\t\tTIFFError(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"No support for %s with separated planar configuration and %u bits per sample",\n\t\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\t\tt2p->tiff_bitspersample);\n\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for %s with planar configuration %u",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\tt2p->tiff_planar);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t}\n\t}\n TIFFGetFieldDefaulted(input, TIFFTAG_ORIENTATION,\n &(t2p->tiff_orientation));\n if(t2p->tiff_orientation>8){\n TIFFWarning(TIFF2PDF_MODULE,\n "Image %s has orientation %u, assuming 0",\n TIFFFileName(input), t2p->tiff_orientation);\n t2p->tiff_orientation=0;\n }\n if(TIFFGetField(input, TIFFTAG_XRESOLUTION, &(t2p->tiff_xres) ) == 0){\n t2p->tiff_xres=0.0;\n }\n if(TIFFGetField(input, TIFFTAG_YRESOLUTION, &(t2p->tiff_yres) ) == 0){\n t2p->tiff_yres=0.0;\n }\n\tTIFFGetFieldDefaulted(input, TIFFTAG_RESOLUTIONUNIT,\n\t\t\t &(t2p->tiff_resunit));\n\tif(t2p->tiff_resunit == RESUNIT_CENTIMETER) {\n\t\tt2p->tiff_xres *= 2.54F;\n\t\tt2p->tiff_yres *= 2.54F;\n\t} else if (t2p->tiff_resunit != RESUNIT_INCH\n\t\t && t2p->pdf_centimeters != 0) {\n\t\tt2p->tiff_xres *= 2.54F;\n\t\tt2p->tiff_yres *= 2.54F;\n\t}\n\tt2p_compose_pdf_page(t2p);\n\tt2p->pdf_transcode = T2P_TRANSCODE_ENCODE;\n\tif(t2p->pdf_nopassthrough==0){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->tiff_compression==COMPRESSION_CCITTFAX4\n\t\t\t){\n\t\t\tif(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){\n\t\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\t\tt2p->pdf_compression=T2P_COMPRESS_G4;\n\t\t\t}\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->tiff_compression== COMPRESSION_ADOBE_DEFLATE\n\t\t\t|| t2p->tiff_compression==COMPRESSION_DEFLATE){\n\t\t\tif(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){\n\t\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\t\tt2p->pdf_compression=T2P_COMPRESS_ZIP;\n\t\t\t}\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression==COMPRESSION_OJPEG){\n\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\tt2p->pdf_compression=T2P_COMPRESS_JPEG;\n\t\t\tt2p_process_ojpeg_tables(t2p, input);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression==COMPRESSION_JPEG){\n\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\tt2p->pdf_compression=T2P_COMPRESS_JPEG;\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_transcode!=T2P_TRANSCODE_RAW){\n\t\tt2p->pdf_compression = t2p->pdf_defaultcompression;\n\t}\n#ifdef JPEG_SUPPORT\n\tif(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){\n\t\tif(t2p->pdf_colorspace & T2P_CS_PALETTE){\n\t\t\tt2p->pdf_sample|=T2P_SAMPLE_REALIZE_PALETTE;\n\t\t\tt2p->pdf_colorspace ^= T2P_CS_PALETTE;\n\t\t\tt2p->tiff_pages[t2p->pdf_page].page_extra--;\n\t\t}\n\t}\n\tif(t2p->tiff_compression==COMPRESSION_JPEG){\n\t\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with JPEG compression and separated planar configuration",\n\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn;\n\t\t}\n\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\tif(t2p->tiff_compression==COMPRESSION_OJPEG){\n\t\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with OJPEG compression and separated planar configuration",\n\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn;\n\t\t}\n\t}\n#endif\n\tif(t2p->pdf_sample & T2P_SAMPLE_REALIZE_PALETTE){\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\tt2p->tiff_samplesperpixel=4;\n\t\t\tt2p->tiff_photometric=PHOTOMETRIC_SEPARATED;\n\t\t} else {\n\t\t\tt2p->tiff_samplesperpixel=3;\n\t\t\tt2p->tiff_photometric=PHOTOMETRIC_RGB;\n\t\t}\n\t}\n\tif (TIFFGetField(input, TIFFTAG_TRANSFERFUNCTION,\n\t\t\t &(t2p->tiff_transferfunction[0]),\n\t\t\t &(t2p->tiff_transferfunction[1]),\n\t\t\t &(t2p->tiff_transferfunction[2]))) {\n\t\tif(t2p->tiff_transferfunction[1] !=\n\t\t t2p->tiff_transferfunction[0]) {\n\t\t\tt2p->tiff_transferfunctioncount=3;\n\t\t} else {\n\t\t\tt2p->tiff_transferfunctioncount=1;\n\t\t}\n\t} else {\n\t\tt2p->tiff_transferfunctioncount=0;\n\t}\n\tif(TIFFGetField(input, TIFFTAG_WHITEPOINT, &xfloatp)!=0){\n\t\tt2p->tiff_whitechromaticities[0]=xfloatp[0];\n\t\tt2p->tiff_whitechromaticities[1]=xfloatp[1];\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\tt2p->pdf_colorspace |= T2P_CS_CALGRAY;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_RGB){\n\t\t\tt2p->pdf_colorspace |= T2P_CS_CALRGB;\n\t\t}\n\t}\n\tif(TIFFGetField(input, TIFFTAG_PRIMARYCHROMATICITIES, &xfloatp)!=0){\n\t\tt2p->tiff_primarychromaticities[0]=xfloatp[0];\n\t\tt2p->tiff_primarychromaticities[1]=xfloatp[1];\n\t\tt2p->tiff_primarychromaticities[2]=xfloatp[2];\n\t\tt2p->tiff_primarychromaticities[3]=xfloatp[3];\n\t\tt2p->tiff_primarychromaticities[4]=xfloatp[4];\n\t\tt2p->tiff_primarychromaticities[5]=xfloatp[5];\n\t\tif(t2p->pdf_colorspace & T2P_CS_RGB){\n\t\t\tt2p->pdf_colorspace |= T2P_CS_CALRGB;\n\t\t}\n\t}\n\tif(t2p->pdf_colorspace & T2P_CS_LAB){\n\t\tif(TIFFGetField(input, TIFFTAG_WHITEPOINT, &xfloatp) != 0){\n\t\t\tt2p->tiff_whitechromaticities[0]=xfloatp[0];\n\t\t\tt2p->tiff_whitechromaticities[1]=xfloatp[1];\n\t\t} else {\n\t\t\tt2p->tiff_whitechromaticities[0]=0.3457F;\n\t\t\tt2p->tiff_whitechromaticities[1]=0.3585F;\n\t\t}\n\t}\n\tif(TIFFGetField(input,\n\t\tTIFFTAG_ICCPROFILE,\n\t\t&(t2p->tiff_iccprofilelength),\n\t\t&(t2p->tiff_iccprofile))!=0){\n\t\tt2p->pdf_colorspace |= T2P_CS_ICCBASED;\n\t} else {\n\t\tt2p->tiff_iccprofilelength=0;\n\t\tt2p->tiff_iccprofile=NULL;\n\t}\n#ifdef CCITT_SUPPORT\n\tif( t2p->tiff_bitspersample==1 &&\n\t\tt2p->tiff_samplesperpixel==1){\n\t\tt2p->pdf_compression = T2P_COMPRESS_G4;\n\t}\n#endif\n\treturn;\n}', 'int\nTIFFSetDirectory(TIFF* tif, uint16 dirn)\n{\n\tuint64 nextdir;\n\tuint16 n;\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\telse\n\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\tfor (n = dirn; n > 0 && nextdir != 0; n--)\n\t\tif (!TIFFAdvanceDirectory(tif, &nextdir, NULL))\n\t\t\treturn (0);\n\ttif->tif_nextdiroff = nextdir;\n\ttif->tif_curdir = (dirn - n) - 1;\n\ttif->tif_dirnumber = 0;\n\treturn (TIFFReadDirectory(tif));\n}', 'void t2p_read_tiff_size_tile(T2P* t2p, TIFF* input, ttile_t tile){\n\tuint64* tbc = NULL;\n\tuint16 edge=0;\n#ifdef JPEG_SUPPORT\n\tunsigned char* jpt;\n#endif\n\tedge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tedge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tif(t2p->pdf_transcode==T2P_TRANSCODE_RAW){\n\t\tif(edge\n#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)\n\t\t&& !(t2p->pdf_compression==T2P_COMPRESS_JPEG)\n#endif\n\t\t){\n\t\t\tt2p->tiff_datasize=TIFFTileSize(input);\n\t\t\treturn;\n\t\t} else {\n\t\t\tTIFFGetField(input, TIFFTAG_TILEBYTECOUNTS, &tbc);\n\t\t\tt2p->tiff_datasize=(tmsize_t)tbc[tile];\n#ifdef OJPEG_SUPPORT\n\t\t\tif(t2p->tiff_compression==COMPRESSION_OJPEG){\n\t\t\t\tt2p->tiff_datasize+=2048;\n\t\t\t\treturn;\n\t\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\t\tif(t2p->tiff_compression==COMPRESSION_JPEG) {\n\t\t\t\tuint32 count = 0;\n\t\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt)!=0){\n\t\t\t\t\tif(count > 4){\n\t\t\t\t\t\tt2p->tiff_datasize += count;\n\t\t\t\t\t\tt2p->tiff_datasize -= 4;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n#endif\n\t\t\treturn;\n\t\t}\n\t}\n\tt2p->tiff_datasize=TIFFTileSize(input);\n\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\tt2p->tiff_datasize*= t2p->tiff_samplesperpixel;\n\t}\n\treturn;\n}', 'tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){\n\tuint16 edge=0;\n\ttsize_t written=0;\n\tunsigned char* buffer=NULL;\n\ttsize_t bufferoffset=0;\n\tunsigned char* samplebuffer=NULL;\n\ttsize_t samplebufferoffset=0;\n\ttsize_t read=0;\n\tuint16 i=0;\n\tttile_t tilecount=0;\n\ttsize_t tilesize=0;\n\tttile_t septilecount=0;\n\ttsize_t septilesize=0;\n#ifdef JPEG_SUPPORT\n\tunsigned char* jpt;\n\tfloat* xfloatp;\n\tuint32 xuint32=0;\n#endif\n\tedge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tedge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tif( (t2p->pdf_transcode == T2P_TRANSCODE_RAW) && ((edge == 0)\n#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)\n\t\t|| (t2p->pdf_compression == T2P_COMPRESS_JPEG)\n#endif\n\t)\n\t){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(! t2p->pdf_ojpegdata){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"No support for OJPEG image %s with "\n "bad tables",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tbuffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\t_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);\n\t\t\tif(edge!=0){\n\t\t\t\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[7]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength >> 8) & 0xff;\n\t\t\t\t\tbuffer[8]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength ) & 0xff;\n\t\t\t\t}\n\t\t\t\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[9]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth >> 8) & 0xff;\n\t\t\t\t\tbuffer[10]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth ) & 0xff;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbufferoffset=t2p->pdf_ojpegdatalength;\n\t\t\tbufferoffset+=TIFFReadRawTile(input,\n\t\t\t\t\ttile,\n\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t-1);\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xff;\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xd9;\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG){\n\t\t\tunsigned char table_end[2];\n\t\t\tuint32 count = 0;\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\tt2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {\n\t\t\t\tif (count > 0) {\n\t\t\t\t\t_TIFFmemcpy(buffer, jpt, count);\n\t\t\t\t\tbufferoffset += count - 2;\n\t\t\t\t\ttable_end[0] = buffer[bufferoffset-2];\n\t\t\t\t\ttable_end[1] = buffer[bufferoffset-1];\n\t\t\t\t}\n\t\t\t\tif (count > 0) {\n\t\t\t\t\txuint32 = bufferoffset;\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset-2]),\n\t\t\t\t\t\t-1);\n\t\t\t\t\t\tbuffer[xuint32-2]=table_end[0];\n\t\t\t\t\t\tbuffer[xuint32-1]=table_end[1];\n\t\t\t\t} else {\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t\t-1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_sample==T2P_SAMPLE_NOTHING){\n\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\tif(buffer==NULL){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Can\'t allocate %lu bytes of memory for "\n "t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tread = TIFFReadEncodedTile(\n\t\t\tinput,\n\t\t\ttile,\n\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\tt2p->tiff_datasize);\n\t\tif(read==-1){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\ttile,\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t} else {\n\t\tif(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){\n\t\t\tseptilesize=TIFFTileSize(input);\n\t\t\tseptilecount=TIFFNumberOfTiles(input);\n\t\t\ttilesize=septilesize*t2p->tiff_samplesperpixel;\n\t\t\ttilecount=septilecount/t2p->tiff_samplesperpixel;\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(samplebuffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebufferoffset=0;\n\t\t\tfor(i=0;i<t2p->tiff_samplesperpixel;i++){\n\t\t\t\tread =\n\t\t\t\t\tTIFFReadEncodedTile(input,\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\t(tdata_t) &(samplebuffer[samplebufferoffset]),\n\t\t\t\t\t\tseptilesize);\n\t\t\t\tif(read==-1){\n\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t_TIFFfree(samplebuffer);\n\t\t\t\t\t\t_TIFFfree(buffer);\n\t\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t\tsamplebufferoffset+=read;\n\t\t\t}\n\t\t\tt2p_sample_planar_separate_to_contig(\n\t\t\t\tt2p,\n\t\t\t\t&(buffer[bufferoffset]),\n\t\t\t\tsamplebuffer,\n\t\t\t\tsamplebufferoffset);\n\t\t\tbufferoffset+=samplebufferoffset;\n\t\t\t_TIFFfree(samplebuffer);\n\t\t}\n\t\tif(buffer==NULL){\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tread = TIFFReadEncodedTile(\n\t\t\t\tinput,\n\t\t\t\ttile,\n\t\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\t\tt2p->tiff_datasize);\n\t\t\tif(read==-1){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\ttile,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t_TIFFfree(buffer);\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgba_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBAA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgbaa_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"No support for YCbCr to RGB in tile for %s",\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED){\n\t\t\tt2p->tiff_datasize=t2p_sample_lab_signed_to_unsigned(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t}\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) != 0){\n\t\tt2p_tile_collapse_left(\n\t\t\tbuffer,\n\t\t\tTIFFTileRowSize(input),\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t}\n\tt2p_disable(output);\n\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric);\n\tTIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample);\n\tTIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel);\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);\n\t}\n\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t}\n\tTIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);\n\tTIFFSetField(output, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);\n\tswitch(t2p->pdf_compression){\n\tcase T2P_COMPRESS_NONE:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\t\tbreak;\n#ifdef CCITT_SUPPORT\n\tcase T2P_COMPRESS_G4:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);\n\t\tbreak;\n#endif\n#ifdef JPEG_SUPPORT\n\tcase T2P_COMPRESS_JPEG:\n\t\tif (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) {\n\t\t\tuint16 hor = 0, ver = 0;\n\t\t\tif (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) {\n\t\t\t\tif (hor != 0 && ver != 0) {\n\t\t\t\t\tTIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){\n\t\t\t\tTIFFSetField(output, TIFFTAG_REFERENCEBLACKWHITE, xfloatp);\n\t\t\t}\n\t\t}\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n\t\tTIFFSetField(output, TIFFTAG_JPEGTABLESMODE, 0);\n\t\tif(t2p->pdf_colorspace & (T2P_CS_RGB | T2P_CS_LAB)){\n\t\t\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n\t\t\tif(t2p->tiff_photometric != PHOTOMETRIC_YCBCR){\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n\t\t\t} else {\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_JPEGQUALITY,\n\t\t\t\tt2p->pdf_defaultcompressionquality);\n\t\t}\n\t\tbreak;\n#endif\n#ifdef ZIP_SUPPORT\n\tcase T2P_COMPRESS_ZIP:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);\n\t\tif(t2p->pdf_defaultcompressionquality%100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_PREDICTOR,\n\t\t\t\tt2p->pdf_defaultcompressionquality % 100);\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality/100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_ZIPQUALITY,\n\t\t\t\t(t2p->pdf_defaultcompressionquality / 100));\n\t\t}\n\t\tbreak;\n#endif\n\tdefault:\n\t\tbreak;\n\t}\n\tt2p_enable(output);\n\tt2p->outputwritten = 0;\n\tbufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer,\n\t\t\t\t\t TIFFStripSize(output));\n\tif (buffer != NULL) {\n\t\t_TIFFfree(buffer);\n\t\tbuffer = NULL;\n\t}\n\tif (bufferoffset == -1) {\n\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t "Error writing encoded tile to output PDF %s",\n\t\t\t TIFFFileName(output));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn(0);\n\t}\n\twritten = t2p->outputwritten;\n\treturn(written);\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}']
612
0
https://github.com/openssl/openssl/blob/d4b009d5f88875ac0e3ac0b2b9689ed16a4c88dc/crypto/lhash/lhash.c/#L249
static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) { int i; LHASH_NODE *a, *n; if (lh == NULL) return; for (i = lh->num_nodes - 1; i >= 0; i--) { a = lh->b[i]; while (a != NULL) { n = a->next; if (use_arg) func_arg(a->data, arg); else func(a->data); a = n; } } }
['const EVP_PKEY_ASN1_METHOD *ENGINE_pkey_asn1_find_str(ENGINE **pe,\n const char *str,\n int len)\n{\n ENGINE_FIND_STR fstr;\n fstr.e = NULL;\n fstr.ameth = NULL;\n fstr.str = str;\n fstr.len = len;\n CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr);\n if (fstr.e) {\n fstr.e->struct_ref++;\n engine_ref_debug(fstr.e, 0, 1)\n }\n *pe = fstr.e;\n CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n return fstr.ameth;\n}', 'void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb,\n void *arg)\n{\n ENGINE_PILE_DOALL dall;\n dall.cb = cb;\n dall.arg = arg;\n if (table)\n lh_ENGINE_PILE_doall_ENGINE_PILE_DOALL(&table->piles, int_dall, &dall);\n}', 'IMPLEMENT_LHASH_DOALL_ARG_CONST(ENGINE_PILE, ENGINE_PILE_DOALL)', 'void lh_doall_arg(_LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)\n{\n doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)0, func, arg);\n}', 'static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n{\n int i;\n LHASH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
613
0
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_lib.c/#L377
BIGNUM *bn_expand2(BIGNUM *b, int words) { BN_ULONG *A,*B,*a; int i,j; bn_check_top(b); if (words > b->max) { bn_check_top(b); if (BN_get_flags(b,BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return(NULL); } a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1)); if (A == NULL) { BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE); return(NULL); } memset(A,0x5c,sizeof(BN_ULONG)*(words+1)); #if 1 B=b->d; if (B != NULL) { for (i=b->top&(~7); i>0; i-=8) { A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3]; A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7]; A+=8; B+=8; } switch (b->top&7) { case 7: A[6]=B[6]; case 6: A[5]=B[5]; case 5: A[4]=B[4]; case 4: A[3]=B[3]; case 3: A[2]=B[2]; case 2: A[1]=B[1]; case 1: A[0]=B[0]; case 0: ; } Free(b->d); } b->d=a; b->max=words; B= &(b->d[b->top]); j=(b->max - b->top) & ~7; for (i=0; i<j; i+=8) { B[0]=0; B[1]=0; B[2]=0; B[3]=0; B[4]=0; B[5]=0; B[6]=0; B[7]=0; B+=8; } j=(b->max - b->top) & 7; for (i=0; i<j; i++) { B[0]=0; B++; } #else memcpy(a->d,b->d,sizeof(b->d[0])*b->top); #endif } return(b); }
['int test_mod(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c;\n\tint i;\n\tint j;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\tBN_rand(a,1024,0,0);\n\tfor (i=0; i<20; i++)\n\t\t{\n\t\tBN_rand(b,450+i*10,0,0);\n\t\ta->neg=rand_neg();\n\t\tb->neg=rand_neg();\n\t\tif (bp == NULL)\n\t\t\tfor (j=0; j<100; j++)\n\t\t\t\tBN_mod(c,a,b,ctx);\n\t\tBN_mod(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,c);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tif (ret == NULL) ret=BN_new();\n\tif (ret == NULL) return(NULL);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\tif (bn_expand(ret,(int)(n+2)*8) == NULL)\n\t\treturn(NULL);\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tret->top=i;\n\twhile (n-- > 0)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_fix_top(ret);\n\treturn(ret);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*B,*a;\n\tint i,j;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\nmemset(A,0x5c,sizeof(BN_ULONG)*(words+1));\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tB= &(b->d[b->top]);\n\t\tj=(b->max - b->top) & ~7;\n\t\tfor (i=0; i<j; i+=8)\n\t\t\t{\n\t\t\tB[0]=0; B[1]=0; B[2]=0; B[3]=0;\n\t\t\tB[4]=0; B[5]=0; B[6]=0; B[7]=0;\n\t\t\tB+=8;\n\t\t\t}\n\t\tj=(b->max - b->top) & 7;\n\t\tfor (i=0; i<j; i++)\n\t\t\t{\n\t\t\tB[0]=0;\n\t\t\tB++;\n\t\t\t}\n#else\n\t\t\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\t\t}\n\treturn(b);\n\t}']
614
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/lhash/lhash.c/#L233
void *lh_delete(_LHASH *lh, const void *data) { unsigned long hash; LHASH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return (NULL); } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return (ret); }
['void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,\n const char *file, int line, int before_p)\n{\n MEM m, *mp;\n#ifdef LEVITTE_DEBUG_MEM\n fprintf(stderr,\n "LEVITTE_DEBUG_MEM: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \\"%s\\", line = %d, before_p = %d)\\n",\n addr1, addr2, num, file, line, before_p);\n#endif\n switch (before_p) {\n case 0:\n break;\n case 1:\n if (addr2 == NULL)\n break;\n if (addr1 == NULL) {\n CRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);\n break;\n }\n if (is_MemCheck_on()) {\n MemCheck_off();\n m.addr = addr1;\n mp = lh_MEM_delete(mh, &m);\n if (mp != NULL) {\n#ifdef LEVITTE_DEBUG_MEM\n fprintf(stderr,\n "LEVITTE_DEBUG_MEM: [%5ld] * 0x%p (%d) -> 0x%p (%d)\\n",\n mp->order, mp->addr, mp->num, addr2, num);\n#endif\n mp->addr = addr2;\n mp->num = num;\n (void)lh_MEM_insert(mh, mp);\n }\n MemCheck_on();\n }\n break;\n }\n return;\n}', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n unsigned long hash;\n LHASH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
615
0
https://github.com/openssl/openssl/blob/c10d1bc81cb047cbd53f8cc430632b6a4a70252d/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 digest_test_run(struct evp_test *t)\n{\n struct digest_data *mdata = t->data;\n size_t i;\n const char *err = "INTERNAL_ERROR";\n EVP_MD_CTX *mctx;\n unsigned char md[EVP_MAX_MD_SIZE];\n unsigned int md_len;\n mctx = EVP_MD_CTX_new();\n if (!mctx)\n goto err;\n err = "DIGESTINIT_ERROR";\n if (!EVP_DigestInit_ex(mctx, mdata->digest, NULL))\n goto err;\n err = "DIGESTUPDATE_ERROR";\n for (i = 0; i < mdata->nrpt; i++) {\n if (!EVP_DigestUpdate(mctx, mdata->input, mdata->input_len))\n goto err;\n }\n err = "DIGESTFINAL_ERROR";\n if (!EVP_DigestFinal(mctx, md, &md_len))\n goto err;\n err = "DIGEST_LENGTH_MISMATCH";\n if (md_len != mdata->output_len)\n goto err;\n err = "DIGEST_MISMATCH";\n if (check_output(t, mdata->output, md, md_len))\n goto err;\n err = NULL;\n err:\n EVP_MD_CTX_free(mctx);\n t->err = err;\n return 1;\n}', 'int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)\n{\n EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n#ifndef OPENSSL_NO_ENGINE\n if (ctx->engine && ctx->digest && (!type ||\n (type\n && (type->type ==\n ctx->digest->type))))\n goto skip_to_init;\n if (type) {\n if (ctx->engine)\n ENGINE_finish(ctx->engine);\n if (impl) {\n if (!ENGINE_init(impl)) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n return 0;\n }\n } else\n impl = ENGINE_get_digest_engine(type->type);\n if (impl) {\n const EVP_MD *d = ENGINE_get_digest(impl, type->type);\n if (!d) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n ENGINE_finish(impl);\n return 0;\n }\n type = d;\n ctx->engine = impl;\n } else\n ctx->engine = NULL;\n } else {\n if (!ctx->digest) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);\n return 0;\n }\n type = ctx->digest;\n }\n#endif\n if (ctx->digest != type) {\n if (ctx->digest && ctx->digest->ctx_size)\n OPENSSL_free(ctx->md_data);\n ctx->digest = type;\n if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {\n ctx->update = type->update;\n ctx->md_data = OPENSSL_malloc(type->ctx_size);\n if (ctx->md_data == NULL) {\n EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n }\n#ifndef OPENSSL_NO_ENGINE\n skip_to_init:\n#endif\n if (ctx->pctx) {\n int r;\n r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,\n EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);\n if (r <= 0 && (r != -2))\n return 0;\n }\n if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)\n return 1;\n return ctx->digest->init(ctx);\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
616
0
https://github.com/openssl/openssl/blob/85bcf27cccd8f5f569886479ad96a0c33444404c/crypto/bn/bn_ctx.c/#L354
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)\n\t{\n\tBIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;\n\tBIGNUM local_r0,local_d,local_p;\n\tBIGNUM *pr0,*d,*p;\n\tint bitsp,bitsq,ok= -1,n=0;\n\tBN_CTX *ctx=NULL;\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tBN_CTX_start(ctx);\n\tr0 = BN_CTX_get(ctx);\n\tr1 = BN_CTX_get(ctx);\n\tr2 = BN_CTX_get(ctx);\n\tr3 = BN_CTX_get(ctx);\n\tif (r3 == NULL) goto err;\n\tbitsp=(bits+1)/2;\n\tbitsq=bits-bitsp;\n\tif(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err;\n\tif(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err;\n\tif(!rsa->e && ((rsa->e=BN_new()) == NULL)) goto err;\n\tif(!rsa->p && ((rsa->p=BN_new()) == NULL)) goto err;\n\tif(!rsa->q && ((rsa->q=BN_new()) == NULL)) goto err;\n\tif(!rsa->dmp1 && ((rsa->dmp1=BN_new()) == NULL)) goto err;\n\tif(!rsa->dmq1 && ((rsa->dmq1=BN_new()) == NULL)) goto err;\n\tif(!rsa->iqmp && ((rsa->iqmp=BN_new()) == NULL)) goto err;\n\tBN_copy(rsa->e, e_value);\n\tfor (;;)\n\t\t{\n\t\tif(!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb))\n\t\t\tgoto err;\n\t\tif (!BN_sub(r2,rsa->p,BN_value_one())) goto err;\n\t\tif (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;\n\t\tif (BN_is_one(r1)) break;\n\t\tif(!BN_GENCB_call(cb, 2, n++))\n\t\t\tgoto err;\n\t\t}\n\tif(!BN_GENCB_call(cb, 3, 0))\n\t\tgoto err;\n\tfor (;;)\n\t\t{\n\t\tunsigned int degenerate = 0;\n\t\tdo\n\t\t\t{\n\t\t\tif(!BN_generate_prime_ex(rsa->q, bitsq, 0, NULL, NULL, cb))\n\t\t\t\tgoto err;\n\t\t\t} while((BN_cmp(rsa->p, rsa->q) == 0) && (++degenerate < 3));\n\t\tif(degenerate == 3)\n\t\t\t{\n\t\t\tok = 0;\n\t\t\tRSAerr(RSA_F_RSA_BUILTIN_KEYGEN,RSA_R_KEY_SIZE_TOO_SMALL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_sub(r2,rsa->q,BN_value_one())) goto err;\n\t\tif (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;\n\t\tif (BN_is_one(r1))\n\t\t\tbreak;\n\t\tif(!BN_GENCB_call(cb, 2, n++))\n\t\t\tgoto err;\n\t\t}\n\tif(!BN_GENCB_call(cb, 3, 1))\n\t\tgoto err;\n\tif (BN_cmp(rsa->p,rsa->q) < 0)\n\t\t{\n\t\ttmp=rsa->p;\n\t\trsa->p=rsa->q;\n\t\trsa->q=tmp;\n\t\t}\n\tif (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;\n\tif (!BN_sub(r1,rsa->p,BN_value_one())) goto err;\n\tif (!BN_sub(r2,rsa->q,BN_value_one())) goto err;\n\tif (!BN_mul(r0,r1,r2,ctx)) goto err;\n\tif (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))\n\t\t{\n\t\t pr0 = &local_r0;\n\t\t BN_with_flags(pr0, r0, BN_FLG_CONSTTIME);\n\t\t}\n\telse\n\t pr0 = r0;\n\tif (!BN_mod_inverse(rsa->d,rsa->e,pr0,ctx)) goto err;\n\tif (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))\n\t\t{\n\t\td = &local_d;\n\t\tBN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n\t\t}\n\telse\n\t\td = rsa->d;\n\tif (!BN_mod(rsa->dmp1,d,r1,ctx)) goto err;\n\tif (!BN_mod(rsa->dmq1,d,r2,ctx)) goto err;\n\tif (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))\n\t\t{\n\t\tp = &local_p;\n\t\tBN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n\t\t}\n\telse\n\t\tp = rsa->p;\n\tif (!BN_mod_inverse(rsa->iqmp,rsa->q,p,ctx)) goto err;\n\tok=1;\nerr:\n\tif (ok == -1)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_BUILTIN_KEYGEN,ERR_LIB_BN);\n\t\tok=0;\n\t\t}\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\treturn ok;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*t;\n\tint ret=0;\n\tbn_check_top(in_a);\n\tbn_check_top(in_b);\n\tBN_CTX_start(ctx);\n\ta = BN_CTX_get(ctx);\n\tb = BN_CTX_get(ctx);\n\tif (a == NULL || b == NULL) goto err;\n\tif (BN_copy(a,in_a) == NULL) goto err;\n\tif (BN_copy(b,in_b) == NULL) goto err;\n\ta->neg = 0;\n\tb->neg = 0;\n\tif (BN_cmp(a,b) < 0) { t=a; a=b; b=t; }\n\tt=euclid(a,b);\n\tif (t == NULL) goto err;\n\tif (BN_copy(r,t) == NULL) goto err;\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
617
0
https://github.com/libav/libav/blob/97ae370078e5ee8e78269fe4d7b4f457e82bd758/libavformat/rmdec.c/#L848
int ff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *ast, AVPacket *pkt) { RMDemuxContext *rm = s->priv_data; assert (rm->audio_pkt_cnt > 0); if (ast->deint_id == DEINT_ID_VBRF || ast->deint_id == DEINT_ID_VBRS) av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]); else { av_new_packet(pkt, st->codec->block_align); memcpy(pkt->data, ast->pkt.data + st->codec->block_align * (ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt), st->codec->block_align); } rm->audio_pkt_cnt--; if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) { ast->audiotimestamp = AV_NOPTS_VALUE; pkt->flags = AV_PKT_FLAG_KEY; } else pkt->flags = 0; pkt->stream_index = st->index; return rm->audio_pkt_cnt; }
['int\nff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb,\n AVStream *st, RMStream *ast, AVPacket *pkt)\n{\n RMDemuxContext *rm = s->priv_data;\n assert (rm->audio_pkt_cnt > 0);\n if (ast->deint_id == DEINT_ID_VBRF ||\n ast->deint_id == DEINT_ID_VBRS)\n av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]);\n else {\n av_new_packet(pkt, st->codec->block_align);\n memcpy(pkt->data, ast->pkt.data + st->codec->block_align *\n (ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),\n st->codec->block_align);\n }\n rm->audio_pkt_cnt--;\n if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) {\n ast->audiotimestamp = AV_NOPTS_VALUE;\n pkt->flags = AV_PKT_FLAG_KEY;\n } else\n pkt->flags = 0;\n pkt->stream_index = st->index;\n return rm->audio_pkt_cnt;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n uint8_t *data = NULL;\n if ((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (data) {\n memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n } else\n size = 0;\n av_init_packet(pkt);\n pkt->data = data;\n pkt->size = size;\n pkt->destruct = av_destruct_packet;\n if (!data)\n return AVERROR(ENOMEM);\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n assert(size);\n if (size > (INT_MAX-32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void av_init_packet(AVPacket *pkt)\n{\n pkt->pts = AV_NOPTS_VALUE;\n pkt->dts = AV_NOPTS_VALUE;\n pkt->pos = -1;\n pkt->duration = 0;\n pkt->convergence_duration = 0;\n pkt->flags = 0;\n pkt->stream_index = 0;\n pkt->destruct = NULL;\n pkt->side_data = NULL;\n pkt->side_data_elems = 0;\n}']
618
0
https://github.com/nginx/nginx/blob/ddb7cd1c410a7166d8e28092d714f782ed1d69b3/src/core/ngx_resolver.c/#L2002
static ngx_int_t ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src, u_char *last) { char *err; u_char *p, *dst; ssize_t len; ngx_uint_t i, n; p = src; len = -1; for (i = 0; i < 128; i++) { n = *p++; if (n == 0) { goto done; } if (n & 0xc0) { n = ((n & 0x3f) << 8) + *p; p = &buf[n]; } else { len += 1 + n; p = &p[n]; } if (p >= last) { err = "name is out of response"; goto invalid; } } err = "compression pointers loop"; invalid: ngx_log_error(r->log_level, r->log, 0, err); return NGX_ERROR; done: if (name == NULL) { return NGX_OK; } if (len == -1) { name->len = 0; name->data = NULL; return NGX_OK; } dst = ngx_resolver_alloc(r, len); if (dst == NULL) { return NGX_ERROR; } name->data = dst; n = *src++; for ( ;; ) { if (n & 0xc0) { n = ((n & 0x3f) << 8) + *src; src = &buf[n]; n = *src++; } else { ngx_memcpy(dst, src, n); dst += n; src += n; n = *src++; if (n != 0) { *dst++ = '.'; } } if (n == 0) { name->len = dst - name->data; return NGX_OK; } } }
['static ngx_int_t\nngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,\n u_char *last)\n{\n char *err;\n u_char *p, *dst;\n ssize_t len;\n ngx_uint_t i, n;\n p = src;\n len = -1;\n for (i = 0; i < 128; i++) {\n n = *p++;\n if (n == 0) {\n goto done;\n }\n if (n & 0xc0) {\n n = ((n & 0x3f) << 8) + *p;\n p = &buf[n];\n } else {\n len += 1 + n;\n p = &p[n];\n }\n if (p >= last) {\n err = "name is out of response";\n goto invalid;\n }\n }\n err = "compression pointers loop";\ninvalid:\n ngx_log_error(r->log_level, r->log, 0, err);\n return NGX_ERROR;\ndone:\n if (name == NULL) {\n return NGX_OK;\n }\n if (len == -1) {\n name->len = 0;\n name->data = NULL;\n return NGX_OK;\n }\n dst = ngx_resolver_alloc(r, len);\n if (dst == NULL) {\n return NGX_ERROR;\n }\n name->data = dst;\n n = *src++;\n for ( ;; ) {\n if (n & 0xc0) {\n n = ((n & 0x3f) << 8) + *src;\n src = &buf[n];\n n = *src++;\n } else {\n ngx_memcpy(dst, src, n);\n dst += n;\n src += n;\n n = *src++;\n if (n != 0) {\n *dst++ = \'.\';\n }\n }\n if (n == 0) {\n name->len = dst - name->data;\n return NGX_OK;\n }\n }\n}']
619
0
https://github.com/libav/libav/blob/64ba831da99c5526b21d510397b449742e92961e/libavutil/mathematics.c/#L136
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){ int64_t c= (a-b) & (mod-1); if(c > (mod>>1)) c-= mod; return c; }
['int av_read_frame(AVFormatContext *s, AVPacket *pkt)\n{\n const int genpts = s->flags & AVFMT_FLAG_GENPTS;\n int eof = 0;\n if (!genpts)\n return s->packet_buffer\n ? read_from_packet_buffer(&s->packet_buffer,\n &s->packet_buffer_end, pkt)\n : read_frame_internal(s, pkt);\n for (;;) {\n int ret;\n AVPacketList *pktl = s->packet_buffer;\n if (pktl) {\n AVPacket *next_pkt = &pktl->pkt;\n if (next_pkt->dts != AV_NOPTS_VALUE) {\n int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits;\n while (pktl && next_pkt->pts == AV_NOPTS_VALUE) {\n if (pktl->pkt.stream_index == next_pkt->stream_index &&\n (av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0) &&\n av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) {\n next_pkt->pts = pktl->pkt.dts;\n }\n pktl = pktl->next;\n }\n pktl = s->packet_buffer;\n }\n if (!(next_pkt->pts == AV_NOPTS_VALUE &&\n next_pkt->dts != AV_NOPTS_VALUE && !eof))\n return read_from_packet_buffer(&s->packet_buffer,\n &s->packet_buffer_end, pkt);\n }\n ret = read_frame_internal(s, pkt);\n if (ret < 0) {\n if (pktl && ret != AVERROR(EAGAIN)) {\n eof = 1;\n continue;\n } else\n return ret;\n }\n if (av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt,\n &s->packet_buffer_end)) < 0)\n return AVERROR(ENOMEM);\n }\n}', 'int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){\n int64_t c= (a-b) & (mod-1);\n if(c > (mod>>1))\n c-= mod;\n return c;\n}']
620
1
https://github.com/openssl/openssl/blob/8e826a339f8cda20a4311fa88a1de782972cf40d/crypto/bn/bn_lib.c/#L333
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) { bn_check_top(b); if (a == b) return a; if (bn_wexpand(a, b->top) == NULL) return NULL; if (b->top > 0) memcpy(a->d, b->d, sizeof(b->d[0]) * b->top); if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0) BN_set_flags(a, BN_FLG_CONSTTIME); a->top = b->top; a->neg = b->neg; bn_check_top(a); return a; }
['static int test_mod_exp(int round)\n{\n BN_CTX *ctx;\n unsigned char c;\n int ret = 0;\n BIGNUM *r_mont = NULL;\n BIGNUM *r_mont_const = NULL;\n BIGNUM *r_recp = NULL;\n BIGNUM *r_simple = NULL;\n BIGNUM *a = NULL;\n BIGNUM *b = NULL;\n BIGNUM *m = NULL;\n if (!TEST_ptr(ctx = BN_CTX_new()))\n goto err;\n if (!TEST_ptr(r_mont = BN_new())\n || !TEST_ptr(r_mont_const = BN_new())\n || !TEST_ptr(r_recp = BN_new())\n || !TEST_ptr(r_simple = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_ptr(m = BN_new()))\n goto err;\n RAND_bytes(&c, 1);\n c = (c % BN_BITS) - BN_BITS2;\n BN_rand(a, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY);\n RAND_bytes(&c, 1);\n c = (c % BN_BITS) - BN_BITS2;\n BN_rand(b, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY);\n RAND_bytes(&c, 1);\n c = (c % BN_BITS) - BN_BITS2;\n BN_rand(m, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD);\n if (!TEST_true(BN_mod(a, a, m, ctx))\n || !TEST_true(BN_mod(b, b, m, ctx))\n || !TEST_true(BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL))\n || !TEST_true(BN_mod_exp_recp(r_recp, a, b, m, ctx))\n || !TEST_true(BN_mod_exp_simple(r_simple, a, b, m, ctx))\n || !TEST_true(BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL)))\n goto err;\n if (!TEST_BN_eq(r_simple, r_mont)\n || !TEST_BN_eq(r_simple, r_recp)\n || !TEST_BN_eq(r_simple, r_mont_const)) {\n if (BN_cmp(r_simple, r_mont) != 0)\n TEST_info("simple and mont results differ");\n if (BN_cmp(r_simple, r_mont_const) != 0)\n TEST_info("simple and mont const time results differ");\n if (BN_cmp(r_simple, r_recp) != 0)\n TEST_info("simple and recp results differ");\n BN_print_var(a);\n BN_print_var(b);\n BN_print_var(m);\n BN_print_var(r_simple);\n BN_print_var(r_recp);\n BN_print_var(r_mont);\n BN_print_var(r_mont_const);\n goto err;\n }\n ret = 1;\n err:\n BN_free(r_mont);\n BN_free(r_mont_const);\n BN_free(r_recp);\n BN_free(r_simple);\n BN_free(a);\n BN_free(b);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_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_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (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}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(a, BN_FLG_CONSTTIME);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
621
0
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250
int BN_num_bits(const BIGNUM *a) { int i = a->top - 1; bn_check_top(a); if (BN_is_zero(a)) return 0; return ((i*BN_BITS2) + BN_num_bits_word(a->d[i])); }
['static void hashbn(SHA_CTX *sha, const BIGNUM *bn)\n {\n size_t l = BN_num_bytes(bn);\n unsigned char *bin = OPENSSL_malloc(l);\n hashlength(sha, l);\n BN_bn2bin(bn, bin);\n SHA1_Update(sha, bin, l);\n OPENSSL_free(bin);\n }', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tbn_check_top(a);\n\tn=i=BN_num_bytes(a);\n\twhile (i--)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}']
622
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/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; } }
['EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)\n{\n\tEVP_PKEY *pkey;\n\tRSA *rsa;\n\tDSA *dsa;\n\tASN1_INTEGER *dsapriv;\n\tX509_ALGOR *a;\n\tSTACK *ndsa;\n\tBN_CTX *ctx;\n\tunsigned char *p;\n\tint plen, pkeylen;\n\tchar obj_tmp[80];\n\tswitch (p8->broken) {\n\t\tcase PKCS8_OK:\n\t\tp = p8->pkey->value.octet_string->data;\n\t\tpkeylen = p8->pkey->value.octet_string->length;\n\t\tbreak;\n\t\tcase PKCS8_NO_OCTET:\n\t\tp = p8->pkey->value.sequence->data;\n\t\tpkeylen = p8->pkey->value.sequence->length;\n\t\tbreak;\n\t\tdefault:\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);\n\t\treturn NULL;\n\t\tbreak;\n\t}\n\tif (!(pkey = EVP_PKEY_new())) {\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\ta = p8->pkeyalg;\n\tswitch (OBJ_obj2nid(a->algorithm))\n\t{\n\t\tcase NID_rsaEncryption:\n\t\tif (!(rsa = d2i_RSAPrivateKey (NULL, &p, pkeylen))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\treturn NULL;\n\t\t}\n\t\tEVP_PKEY_assign_RSA (pkey, rsa);\n\t\tbreak;\n\t\tcase NID_dsa:\n\t\tif(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) {\n\t\t if(!(ndsa = ASN1_seq_unpack(p, pkeylen,\n\t\t\t\t\t(char *(*)())d2i_ASN1_INTEGER,\n\t\t\t\t\t\t\t ASN1_STRING_free))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\treturn NULL;\n\t\t }\n\t\t if(sk_num(ndsa) != 2 ) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tsk_pop_free(ndsa, ASN1_STRING_free);\n\t\t\treturn NULL;\n\t\t }\n\t\t dsapriv = (ASN1_INTEGER *) sk_pop(ndsa);\n\t\t sk_pop_free(ndsa, ASN1_STRING_free);\n\t\t} else if (!(dsapriv=d2i_ASN1_INTEGER (NULL, &p, pkeylen))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (a->parameter->type != V_ASN1_SEQUENCE) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_NO_DSA_PARAMETERS);\n\t\t\treturn NULL;\n\t\t}\n\t\tp = a->parameter->value.sequence->data;\n\t\tplen = a->parameter->value.sequence->length;\n\t\tif (!(dsa = d2i_DSAparams (NULL, &p, plen))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (!(dsa->priv_key = ASN1_INTEGER_to_BN(dsapriv, NULL))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);\n\t\t\tDSA_free (dsa);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (!(dsa->pub_key = BN_new())) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\t\tDSA_free (dsa);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (!(ctx = BN_CTX_new())) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\t\tDSA_free (dsa);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (!BN_mod_exp(dsa->pub_key, dsa->g,\n\t\t\t\t\t\t dsa->priv_key, dsa->p, ctx)) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);\n\t\t\tBN_CTX_free (ctx);\n\t\t\tDSA_free (dsa);\n\t\t\treturn NULL;\n\t\t}\n\t\tEVP_PKEY_assign_DSA (pkey, dsa);\n\t\tBN_CTX_free (ctx);\n\t\tbreak;\n\t\tdefault:\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\tif (!a->algorithm) strcpy (obj_tmp, "NULL");\n\t\telse i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);\n\t\tERR_add_error_data(2, "TYPE=", obj_tmp);\n\t\tEVP_PKEY_free (pkey);\n\t\treturn NULL;\n\t}\n\treturn pkey;\n}', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->max=0;\n\tret->d=NULL;\n\treturn(ret);\n\t}', 'int BN_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_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,\n\t BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*aa,*r;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\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\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#if 1\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n#endif\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]);\n\tts=1;\n\tif (BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0]),a,m,ctx);\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\tif (bits <= 20)\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_montgomery(&(val[i]),&(val[i-1]),d,mont,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 if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) 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\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\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_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,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\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\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, BIGNUM *m, 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, 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}', '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}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,\n\t int n, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_part_recursive %d * %d\\n",tn+n,tn+n);\n#endif\n\tif (n < 8)\n\t\t{\n\t\ti=tn+n;\n\t\tbn_mul_normal(r,a,i,b,i);\n\t\treturn;\n\t\t}\n\tbn_sub_words(t, a, &(a[n]),n);\n\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n if (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\ti=n/2;\n\t\tj=tn-i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\tj,i,p);\n\t\t\t\tmemset(&(r[n2+tn*2]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tn*2));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ttn-i,i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\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}']
623
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavformat/rtpproto.c/#L230
static int rtp_read(URLContext *h, uint8_t *buf, int size) { RTPContext *s = h->priv_data; struct sockaddr_in from; socklen_t from_len; int len, fd_max, n; fd_set rfds; #if 0 for(;;) { from_len = sizeof(from); len = recvfrom (s->rtp_fd, buf, size, 0, (struct sockaddr *)&from, &from_len); if (len < 0) { if (ff_neterrno() == FF_NETERROR(EAGAIN) || ff_neterrno() == FF_NETERROR(EINTR)) continue; return AVERROR(EIO); } break; } #else for(;;) { FD_ZERO(&rfds); fd_max = s->rtp_fd; FD_SET(s->rtp_fd, &rfds); if (s->rtcp_fd > fd_max) fd_max = s->rtcp_fd; FD_SET(s->rtcp_fd, &rfds); n = select(fd_max + 1, &rfds, NULL, NULL, NULL); if (n > 0) { if (FD_ISSET(s->rtcp_fd, &rfds)) { from_len = sizeof(from); len = recvfrom (s->rtcp_fd, buf, size, 0, (struct sockaddr *)&from, &from_len); if (len < 0) { if (ff_neterrno() == FF_NETERROR(EAGAIN) || ff_neterrno() == FF_NETERROR(EINTR)) continue; return AVERROR(EIO); } break; } if (FD_ISSET(s->rtp_fd, &rfds)) { from_len = sizeof(from); len = recvfrom (s->rtp_fd, buf, size, 0, (struct sockaddr *)&from, &from_len); if (len < 0) { if (ff_neterrno() == FF_NETERROR(EAGAIN) || ff_neterrno() == FF_NETERROR(EINTR)) continue; return AVERROR(EIO); } break; } } } #endif return len; }
['static int rtp_read(URLContext *h, uint8_t *buf, int size)\n{\n RTPContext *s = h->priv_data;\n struct sockaddr_in from;\n socklen_t from_len;\n int len, fd_max, n;\n fd_set rfds;\n#if 0\n for(;;) {\n from_len = sizeof(from);\n len = recvfrom (s->rtp_fd, buf, size, 0,\n (struct sockaddr *)&from, &from_len);\n if (len < 0) {\n if (ff_neterrno() == FF_NETERROR(EAGAIN) ||\n ff_neterrno() == FF_NETERROR(EINTR))\n continue;\n return AVERROR(EIO);\n }\n break;\n }\n#else\n for(;;) {\n FD_ZERO(&rfds);\n fd_max = s->rtp_fd;\n FD_SET(s->rtp_fd, &rfds);\n if (s->rtcp_fd > fd_max)\n fd_max = s->rtcp_fd;\n FD_SET(s->rtcp_fd, &rfds);\n n = select(fd_max + 1, &rfds, NULL, NULL, NULL);\n if (n > 0) {\n if (FD_ISSET(s->rtcp_fd, &rfds)) {\n from_len = sizeof(from);\n len = recvfrom (s->rtcp_fd, buf, size, 0,\n (struct sockaddr *)&from, &from_len);\n if (len < 0) {\n if (ff_neterrno() == FF_NETERROR(EAGAIN) ||\n ff_neterrno() == FF_NETERROR(EINTR))\n continue;\n return AVERROR(EIO);\n }\n break;\n }\n if (FD_ISSET(s->rtp_fd, &rfds)) {\n from_len = sizeof(from);\n len = recvfrom (s->rtp_fd, buf, size, 0,\n (struct sockaddr *)&from, &from_len);\n if (len < 0) {\n if (ff_neterrno() == FF_NETERROR(EAGAIN) ||\n ff_neterrno() == FF_NETERROR(EINTR))\n continue;\n return AVERROR(EIO);\n }\n break;\n }\n }\n }\n#endif\n return len;\n}']
624
0
https://github.com/nginx/nginx/blob/4fe0a09942f8aed90f84c77969847980e9aadd98/src/core/ngx_string.c/#L922
ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value, cutoff, cutlim; if (n == 0) { return NGX_ERROR; } cutoff = NGX_MAX_INT_T_VALUE / 10; cutlim = NGX_MAX_INT_T_VALUE % 10; for (value = 0; n--; line++) { if (*line < '0' || *line > '9') { return NGX_ERROR; } if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { return NGX_ERROR; } value = value * 10 + (*line - '0'); } return value; }
['static char *\nngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_upstream_srv_conf_t *uscf;\n ngx_http_upstream_keepalive_srv_conf_t *kcf = conf;\n ngx_int_t n;\n ngx_str_t *value;\n uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);\n if (kcf->original_init_upstream) {\n return "is duplicate";\n }\n kcf->original_init_upstream = uscf->peer.init_upstream\n ? uscf->peer.init_upstream\n : ngx_http_upstream_init_round_robin;\n uscf->peer.init_upstream = ngx_http_upstream_init_keepalive;\n value = cf->args->elts;\n n = ngx_atoi(value[1].data, value[1].len);\n if (n == NGX_ERROR || n == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid value \\"%V\\" in \\"%V\\" directive",\n &value[1], &cmd->name);\n return NGX_CONF_ERROR;\n }\n kcf->max_cached = n;\n return NGX_CONF_OK;\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_INT_T_VALUE / 10;\n cutlim = NGX_MAX_INT_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
625
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/err/err.c/#L326
static unsigned long get_error_values(int inc, 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->bottom == es->top) return(0); i=(es->bottom+1)%ERR_NUM_ERRORS; ret=es->err_buffer[i]; if (inc) { es->bottom=i; es->err_buffer[i]=0; } if ((file != NULL) && (line != NULL)) { if (es->err_file[i] == NULL) { *file="NA"; if (line != NULL) *line=0; } else { *file=es->err_file[i]; if (line != NULL) *line=es->err_line[i]; } } if (data != NULL) { if (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, const char **file, int *line,\n\t const char **data, int *flags)\n\t{\n\tint i=0;\n\tERR_STATE *es;\n\tunsigned long ret;\n\tes=ERR_get_state();\n\tif (es->bottom == es->top) return(0);\n\ti=(es->bottom+1)%ERR_NUM_ERRORS;\n\tret=es->err_buffer[i];\n\tif (inc)\n\t\t{\n\t\tes->bottom=i;\n\t\tes->err_buffer[i]=0;\n\t\t}\n\tif ((file != NULL) && (line != NULL))\n\t\t{\n\t\tif (es->err_file[i] == NULL)\n\t\t\t{\n\t\t\t*file="NA";\n\t\t\tif (line != NULL) *line=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\t*file=es->err_file[i];\n\t\t\tif (line != NULL) *line=es->err_line[i];\n\t\t\t}\n\t\t}\n\tif (data != NULL)\n\t\t{\n\t\tif (es->err_data[i] == NULL)\n\t\t\t{\n\t\t\t*data="";\n\t\t\tif (flags != NULL) *flags=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\t*data=es->err_data[i];\n\t\t\tif (flags != NULL) *flags=es->err_data_flags[i];\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}']
626
0
https://github.com/openssl/openssl/blob/5850cc75ea0c1581a9034390f1ca77cadc596238/crypto/bn/bn_ctx.c/#L328
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p,\n const BIGNUM *q, BN_CTX *ctx)\n{\n BIGNUM *ret = NULL, *r0, *r1, *r2;\n if (d == NULL || p == NULL || q == NULL)\n return NULL;\n BN_CTX_start(ctx);\n r0 = BN_CTX_get(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n if (r2 == NULL)\n goto err;\n if (!BN_sub(r1, p, BN_value_one()))\n goto err;\n if (!BN_sub(r2, q, BN_value_one()))\n goto err;\n if (!BN_mul(r0, r1, r2, ctx))\n goto err;\n ret = BN_mod_inverse(NULL, d, r0, ctx);\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 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}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048))) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM local_A, local_B;\n BIGNUM *pA, *pB;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n pB = &local_B;\n local_B.flags = 0;\n BN_with_flags(pB, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, pB, A, ctx))\n goto err;\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n pA = &local_A;\n local_A.flags = 0;\n BN_with_flags(pA, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, pA, B, ctx))\n goto err;\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
627
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L352
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *A, *a = NULL; const BN_ULONG *B; int i; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b,BN_FLG_SECURE)) a = A = OPENSSL_secure_malloc(words * sizeof(*a)); else a = A = OPENSSL_malloc(words * sizeof(*a)); if (A == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } #ifdef PURIFY memset(a, 0, sizeof(*a) * words); #endif #if 1 B = b->d; if (B != NULL) { for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) { BN_ULONG a0, a1, a2, a3; a0 = B[0]; a1 = B[1]; a2 = B[2]; a3 = B[3]; A[0] = a0; A[1] = a1; A[2] = a2; A[3] = a3; } switch (b->top & 3) { case 3: A[2] = B[2]; case 2: A[1] = B[1]; case 1: A[0] = B[0]; case 0: ; } } #else memset(A, 0, sizeof(*A) * words); memcpy(A, b->d, sizeof(b->d[0]) * b->top); #endif return (a); }
['int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n const EC_POINT *b, BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t;\n int ret = 0;\n if (EC_POINT_is_at_infinity(group, a)) {\n if (!EC_POINT_copy(r, b))\n return 0;\n return 1;\n }\n if (EC_POINT_is_at_infinity(group, b)) {\n if (!EC_POINT_copy(r, a))\n return 0;\n return 1;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n x0 = BN_CTX_get(ctx);\n y0 = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n y1 = BN_CTX_get(ctx);\n x2 = BN_CTX_get(ctx);\n y2 = BN_CTX_get(ctx);\n s = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (a->Z_is_one) {\n if (!BN_copy(x0, a->X))\n goto err;\n if (!BN_copy(y0, a->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx))\n goto err;\n }\n if (b->Z_is_one) {\n if (!BN_copy(x1, b->X))\n goto err;\n if (!BN_copy(y1, b->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx))\n goto err;\n }\n if (BN_GF2m_cmp(x0, x1)) {\n if (!BN_GF2m_add(t, x0, x1))\n goto err;\n if (!BN_GF2m_add(s, y0, y1))\n goto err;\n if (!group->meth->field_div(group, s, s, t, ctx))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, t))\n goto err;\n } else {\n if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1)) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n ret = 1;\n goto err;\n }\n if (!group->meth->field_div(group, s, y1, x1, ctx))\n goto err;\n if (!BN_GF2m_add(s, s, x1))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n }\n if (!BN_GF2m_add(y2, x1, x2))\n goto err;\n if (!group->meth->field_mul(group, y2, y2, s, ctx))\n goto err;\n if (!BN_GF2m_add(y2, y2, x2))\n goto err;\n if (!BN_GF2m_add(y2, y2, y1))\n goto err;\n if (!EC_POINT_set_affine_coordinates_GF2m(group, r, x2, y2, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_malloc(words * sizeof(*a));\n else\n a = A = OPENSSL_malloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#ifdef PURIFY\n memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
628
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; }
['BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,\n const BIGNUM *x, const BIGNUM *a, const 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_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *d, *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (d == NULL || r == NULL || t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'static BIGNUM *srp_Calc_k(const BIGNUM *N, const BIGNUM *g)\n{\n return srp_Calc_xy(N, g, N);\n}', 'static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N)\n{\n unsigned char digest[SHA_DIGEST_LENGTH];\n unsigned char *tmp = NULL;\n int numN = BN_num_bytes(N);\n BIGNUM *res = NULL;\n if (x != N && BN_ucmp(x, N) >= 0)\n return NULL;\n if (y != N && BN_ucmp(y, N) >= 0)\n return NULL;\n if ((tmp = OPENSSL_malloc(numN * 2)) == NULL)\n goto err;\n if (BN_bn2binpad(x, tmp, numN) < 0\n || BN_bn2binpad(y, tmp + numN, numN) < 0\n || !EVP_Digest(tmp, numN * 2, digest, NULL, EVP_sha1(), NULL))\n goto err;\n res = BN_bin2bn(digest, sizeof(digest), NULL);\n err:\n OPENSSL_free(tmp);\n return res;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int BN_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_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_sub(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!aa || !val[0])\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', '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}']
629
0
https://github.com/openssl/openssl/blob/05ec6a25f80ac8edfb7d7cb764d2dd68156a6965/crypto/bn/bn_lib.c/#L289
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); }
['int test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_)\n{\n BIGNUM *a, *b, *c, *d;\n int i;\n b = BN_new();\n c = BN_new();\n d = BN_new();\n BN_one(c);\n if (a_)\n a = a_;\n else {\n a = BN_new();\n BN_bntest_rand(a, 200, 0, 0);\n a->neg = rand_neg();\n }\n for (i = 0; i < num0; i++) {\n BN_lshift(b, a, i + 1);\n BN_add(c, c, c);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " * ");\n BN_print(bp, c);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, b);\n BIO_puts(bp, "\\n");\n }\n BN_mul(d, a, c, ctx);\n BN_sub(d, d, b);\n if (!BN_is_zero(d)) {\n fprintf(stderr, "Left shift test failed!\\n");\n fprintf(stderr, "a=");\n BN_print_fp(stderr, a);\n fprintf(stderr, "\\nb=");\n BN_print_fp(stderr, b);\n fprintf(stderr, "\\nc=");\n BN_print_fp(stderr, c);\n fprintf(stderr, "\\nd=");\n BN_print_fp(stderr, d);\n fprintf(stderr, "\\n");\n return 0;\n }\n }\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n return (1);\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(2, 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 (RAND_bytes(buf, bytes) <= 0)\n goto err;\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}', '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}']
630
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L454
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) { int i; BN_ULONG *A; const BN_ULONG *B; bn_check_top(b); if (a == b) return (a); if (bn_wexpand(a, b->top) == NULL) return (NULL); #if 1 A = a->d; B = b->d; 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 memcpy(a->d, b->d, sizeof(b->d[0]) * b->top); #endif a->top = b->top; a->neg = b->neg; bn_check_top(a); return (a); }
['int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n const EC_POINT *b, BN_CTX *ctx)\n{\n int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,\n const BIGNUM *, BN_CTX *);\n int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);\n const BIGNUM *p;\n BN_CTX *new_ctx = NULL;\n BIGNUM *n0, *n1, *n2, *n3, *n4, *n5, *n6;\n int ret = 0;\n if (a == b)\n return EC_POINT_dbl(group, r, a, ctx);\n if (EC_POINT_is_at_infinity(group, a))\n return EC_POINT_copy(r, b);\n if (EC_POINT_is_at_infinity(group, b))\n return EC_POINT_copy(r, a);\n field_mul = group->meth->field_mul;\n field_sqr = group->meth->field_sqr;\n p = group->field;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n n0 = BN_CTX_get(ctx);\n n1 = BN_CTX_get(ctx);\n n2 = BN_CTX_get(ctx);\n n3 = BN_CTX_get(ctx);\n n4 = BN_CTX_get(ctx);\n n5 = BN_CTX_get(ctx);\n n6 = BN_CTX_get(ctx);\n if (n6 == NULL)\n goto end;\n if (b->Z_is_one) {\n if (!BN_copy(n1, a->X))\n goto end;\n if (!BN_copy(n2, a->Y))\n goto end;\n } else {\n if (!field_sqr(group, n0, b->Z, ctx))\n goto end;\n if (!field_mul(group, n1, a->X, n0, ctx))\n goto end;\n if (!field_mul(group, n0, n0, b->Z, ctx))\n goto end;\n if (!field_mul(group, n2, a->Y, n0, ctx))\n goto end;\n }\n if (a->Z_is_one) {\n if (!BN_copy(n3, b->X))\n goto end;\n if (!BN_copy(n4, b->Y))\n goto end;\n } else {\n if (!field_sqr(group, n0, a->Z, ctx))\n goto end;\n if (!field_mul(group, n3, b->X, n0, ctx))\n goto end;\n if (!field_mul(group, n0, n0, a->Z, ctx))\n goto end;\n if (!field_mul(group, n4, b->Y, n0, ctx))\n goto end;\n }\n if (!BN_mod_sub_quick(n5, n1, n3, p))\n goto end;\n if (!BN_mod_sub_quick(n6, n2, n4, p))\n goto end;\n if (BN_is_zero(n5)) {\n if (BN_is_zero(n6)) {\n BN_CTX_end(ctx);\n ret = EC_POINT_dbl(group, r, a, ctx);\n ctx = NULL;\n goto end;\n } else {\n BN_zero(r->Z);\n r->Z_is_one = 0;\n ret = 1;\n goto end;\n }\n }\n if (!BN_mod_add_quick(n1, n1, n3, p))\n goto end;\n if (!BN_mod_add_quick(n2, n2, n4, p))\n goto end;\n if (a->Z_is_one && b->Z_is_one) {\n if (!BN_copy(r->Z, n5))\n goto end;\n } else {\n if (a->Z_is_one) {\n if (!BN_copy(n0, b->Z))\n goto end;\n } else if (b->Z_is_one) {\n if (!BN_copy(n0, a->Z))\n goto end;\n } else {\n if (!field_mul(group, n0, a->Z, b->Z, ctx))\n goto end;\n }\n if (!field_mul(group, r->Z, n0, n5, ctx))\n goto end;\n }\n r->Z_is_one = 0;\n if (!field_sqr(group, n0, n6, ctx))\n goto end;\n if (!field_sqr(group, n4, n5, ctx))\n goto end;\n if (!field_mul(group, n3, n1, n4, ctx))\n goto end;\n if (!BN_mod_sub_quick(r->X, n0, n3, p))\n goto end;\n if (!BN_mod_lshift1_quick(n0, r->X, p))\n goto end;\n if (!BN_mod_sub_quick(n0, n3, n0, p))\n goto end;\n if (!field_mul(group, n0, n0, n6, ctx))\n goto end;\n if (!field_mul(group, n5, n4, n5, ctx))\n goto end;\n if (!field_mul(group, n1, n2, n5, ctx))\n goto end;\n if (!BN_mod_sub_quick(n0, n0, n1, p))\n goto end;\n if (BN_is_odd(n0))\n if (!BN_add(n0, n0, p))\n goto end;\n if (!BN_rshift1(r->Y, n0))\n goto end;\n ret = 1;\n end:\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
631
0
https://github.com/libav/libav/blob/e8e5dde779fca80d86e00baea26d1baca333f4c0/libavformat/aviobuf.c/#L622
GET_STR16(le, get_le16)
['static void parse_legacy_attrib(AVFormatContext *s, ByteIOContext *pb)\n{\n ff_asf_guid guid;\n int length, type;\n while(!url_feof(pb)) {\n char key[1024];\n ff_get_guid(pb, &guid);\n type = get_le32(pb);\n length = get_le32(pb);\n if (!length)\n break;\n if (ff_guidcmp(&guid, metadata_guid)) {\n av_log(s, AV_LOG_WARNING, "unknown guid "PRI_GUID", expected metadata_guid; "\n "remaining metadata entries ignored\\n", ARG_GUID(guid));\n break;\n }\n avio_get_str16le(pb, INT_MAX, key, sizeof(key));\n get_tag(s, pb, key, type, length);\n }\n ff_metadata_conv(&s->metadata, NULL, ff_asf_metadata_conv);\n}', 'GET_STR16(le, get_le16)']
632
0
https://github.com/libav/libav/blob/63380b5e54f64abdde4a8b6bce0d60f1fa4a22a1/libavcodec/vorbis_dec.c/#L1572
static int vorbis_parse_audio_packet(vorbis_context *vc) { GetBitContext *gb = &vc->gb; uint_fast8_t previous_window = vc->previous_window; uint_fast8_t mode_number; uint_fast8_t blockflag; uint_fast16_t blocksize; int_fast32_t i,j; uint_fast8_t no_residue[vc->audio_channels]; uint_fast8_t do_not_decode[vc->audio_channels]; vorbis_mapping *mapping; float *ch_res_ptr = vc->channel_residues; float *ch_floor_ptr = vc->channel_floors; uint_fast8_t res_chan[vc->audio_channels]; uint_fast8_t res_num = 0; int_fast16_t retlen = 0; float fadd_bias = vc->add_bias; if (get_bits1(gb)) { av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); return -1; } if (vc->mode_count == 1) { mode_number = 0; } else { mode_number = get_bits(gb, ilog(vc->mode_count-1)); } if (mode_number >= vc->mode_count) { av_log(vc->avccontext, AV_LOG_ERROR, "mode number %d out of range.\n", mode_number); return -1; } vc->mode_number = mode_number; mapping = &vc->mappings[vc->modes[mode_number].mapping]; AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); blockflag = vc->modes[mode_number].blockflag; blocksize = vc->blocksize[blockflag]; if (blockflag) skip_bits(gb, 2); memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); for (i = 0; i < vc->audio_channels; ++i) { vorbis_floor *floor; if (mapping->submaps > 1) { floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]]; } else { floor = &vc->floors[mapping->submap_floor[0]]; } no_residue[i] = floor->decode(vc, &floor->data, ch_floor_ptr); ch_floor_ptr += blocksize / 2; } for (i = mapping->coupling_steps - 1; i >= 0; --i) { if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) { no_residue[mapping->magnitude[i]] = 0; no_residue[mapping->angle[i]] = 0; } } for (i = 0; i < mapping->submaps; ++i) { vorbis_residue *residue; uint_fast8_t ch = 0; for (j = 0; j < vc->audio_channels; ++j) { if ((mapping->submaps == 1) || (i == mapping->mux[j])) { res_chan[j] = res_num; if (no_residue[j]) { do_not_decode[ch] = 1; } else { do_not_decode[ch] = 0; } ++ch; ++res_num; } } residue = &vc->residues[mapping->submap_residue[i]]; vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2); ch_res_ptr += ch * blocksize / 2; } for (i = mapping->coupling_steps - 1; i >= 0; --i) { float *mag, *ang; mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2; ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2; vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2); } for (j = vc->audio_channels-1;j >= 0; j--) { ch_floor_ptr = vc->channel_floors + j * blocksize / 2; ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2; vc->dsp.vector_fmul(ch_floor_ptr, ch_res_ptr, blocksize / 2); ff_imdct_half(&vc->mdct[blockflag], ch_res_ptr, ch_floor_ptr); } retlen = (blocksize + vc->blocksize[previous_window]) / 4; for (j = 0; j < vc->audio_channels; j++) { uint_fast16_t bs0 = vc->blocksize[0]; uint_fast16_t bs1 = vc->blocksize[1]; float *residue = vc->channel_residues + res_chan[j] * blocksize / 2; float *saved = vc->saved + j * bs1 / 4; float *ret = vc->channel_floors + j * retlen; float *buf = residue; const float *win = vc->win[blockflag & previous_window]; if (blockflag == previous_window) { vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, blocksize / 4); } else if (blockflag > previous_window) { vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, bs0 / 4); copy_normalize(ret+bs0/2, buf+bs0/4, (bs1-bs0)/4, vc->exp_bias, fadd_bias); } else { copy_normalize(ret, saved, (bs1 - bs0) / 4, vc->exp_bias, fadd_bias); vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, fadd_bias, bs0 / 4); } memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float)); } vc->previous_window = blockflag; return retlen; }
['static int vorbis_parse_audio_packet(vorbis_context *vc)\n{\n GetBitContext *gb = &vc->gb;\n uint_fast8_t previous_window = vc->previous_window;\n uint_fast8_t mode_number;\n uint_fast8_t blockflag;\n uint_fast16_t blocksize;\n int_fast32_t i,j;\n uint_fast8_t no_residue[vc->audio_channels];\n uint_fast8_t do_not_decode[vc->audio_channels];\n vorbis_mapping *mapping;\n float *ch_res_ptr = vc->channel_residues;\n float *ch_floor_ptr = vc->channel_floors;\n uint_fast8_t res_chan[vc->audio_channels];\n uint_fast8_t res_num = 0;\n int_fast16_t retlen = 0;\n float fadd_bias = vc->add_bias;\n if (get_bits1(gb)) {\n av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\\n");\n return -1;\n }\n if (vc->mode_count == 1) {\n mode_number = 0;\n } else {\n mode_number = get_bits(gb, ilog(vc->mode_count-1));\n }\n if (mode_number >= vc->mode_count) {\n av_log(vc->avccontext, AV_LOG_ERROR, "mode number %d out of range.\\n", mode_number);\n return -1;\n }\n vc->mode_number = mode_number;\n mapping = &vc->mappings[vc->modes[mode_number].mapping];\n AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \\n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);\n blockflag = vc->modes[mode_number].blockflag;\n blocksize = vc->blocksize[blockflag];\n if (blockflag)\n skip_bits(gb, 2);\n memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2);\n memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2);\n for (i = 0; i < vc->audio_channels; ++i) {\n vorbis_floor *floor;\n if (mapping->submaps > 1) {\n floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]];\n } else {\n floor = &vc->floors[mapping->submap_floor[0]];\n }\n no_residue[i] = floor->decode(vc, &floor->data, ch_floor_ptr);\n ch_floor_ptr += blocksize / 2;\n }\n for (i = mapping->coupling_steps - 1; i >= 0; --i) {\n if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {\n no_residue[mapping->magnitude[i]] = 0;\n no_residue[mapping->angle[i]] = 0;\n }\n }\n for (i = 0; i < mapping->submaps; ++i) {\n vorbis_residue *residue;\n uint_fast8_t ch = 0;\n for (j = 0; j < vc->audio_channels; ++j) {\n if ((mapping->submaps == 1) || (i == mapping->mux[j])) {\n res_chan[j] = res_num;\n if (no_residue[j]) {\n do_not_decode[ch] = 1;\n } else {\n do_not_decode[ch] = 0;\n }\n ++ch;\n ++res_num;\n }\n }\n residue = &vc->residues[mapping->submap_residue[i]];\n vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2);\n ch_res_ptr += ch * blocksize / 2;\n }\n for (i = mapping->coupling_steps - 1; i >= 0; --i) {\n float *mag, *ang;\n mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2;\n ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2;\n vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);\n }\n for (j = vc->audio_channels-1;j >= 0; j--) {\n ch_floor_ptr = vc->channel_floors + j * blocksize / 2;\n ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2;\n vc->dsp.vector_fmul(ch_floor_ptr, ch_res_ptr, blocksize / 2);\n ff_imdct_half(&vc->mdct[blockflag], ch_res_ptr, ch_floor_ptr);\n }\n retlen = (blocksize + vc->blocksize[previous_window]) / 4;\n for (j = 0; j < vc->audio_channels; j++) {\n uint_fast16_t bs0 = vc->blocksize[0];\n uint_fast16_t bs1 = vc->blocksize[1];\n float *residue = vc->channel_residues + res_chan[j] * blocksize / 2;\n float *saved = vc->saved + j * bs1 / 4;\n float *ret = vc->channel_floors + j * retlen;\n float *buf = residue;\n const float *win = vc->win[blockflag & previous_window];\n if (blockflag == previous_window) {\n vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, blocksize / 4);\n } else if (blockflag > previous_window) {\n vc->dsp.vector_fmul_window(ret, saved, buf, win, fadd_bias, bs0 / 4);\n copy_normalize(ret+bs0/2, buf+bs0/4, (bs1-bs0)/4, vc->exp_bias, fadd_bias);\n } else {\n copy_normalize(ret, saved, (bs1 - bs0) / 4, vc->exp_bias, fadd_bias);\n vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, fadd_bias, bs0 / 4);\n }\n memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float));\n }\n vc->previous_window = blockflag;\n return retlen;\n}']
633
0
https://github.com/libav/libav/blob/c5254755c0154dcc7bb1191a84e6e7cf0106343b/libavutil/imgutils.c/#L251
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum PixelFormat pix_fmt, int width, int height) { const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; if (desc->flags & PIX_FMT_HWACCEL) return; if (desc->flags & PIX_FMT_PAL) { av_image_copy_plane(dst_data[0], dst_linesizes[0], src_data[0], src_linesizes[0], width, height); memcpy(dst_data[1], src_data[1], 4*256); } else { int i, planes_nb = 0; for (i = 0; i < desc->nb_components; i++) planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1); for (i = 0; i < planes_nb; i++) { int h = height; int bwidth = av_image_get_linesize(pix_fmt, width, i); if (i == 1 || i == 2) { h= -((-height)>>desc->log2_chroma_h); } av_image_copy_plane(dst_data[i], dst_linesizes[i], src_data[i], src_linesizes[i], bwidth, h); } } }
['int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,\n int64_t pts, AVRational pixel_aspect)\n{\n BufferSourceContext *c = buffer_filter->priv;\n if (c->buf) {\n av_log(buffer_filter, AV_LOG_ERROR,\n "Buffering several frames is not supported. "\n "Please consume all available frames before adding a new one.\\n"\n );\n }\n CHECK_PARAM_CHANGE(buffer_filter, c, frame->width, frame->height, frame->format);\n c->buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE,\n c->w, c->h);\n av_image_copy(c->buf->data, c->buf->linesize, frame->data, frame->linesize,\n c->pix_fmt, c->w, c->h);\n avfilter_copy_frame_props(c->buf, frame);\n c->buf->pts = pts;\n c->buf->video->pixel_aspect = pixel_aspect;\n return 0;\n}', 'void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4],\n const uint8_t *src_data[4], const int src_linesizes[4],\n enum PixelFormat pix_fmt, int width, int height)\n{\n const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];\n if (desc->flags & PIX_FMT_HWACCEL)\n return;\n if (desc->flags & PIX_FMT_PAL) {\n av_image_copy_plane(dst_data[0], dst_linesizes[0],\n src_data[0], src_linesizes[0],\n width, height);\n memcpy(dst_data[1], src_data[1], 4*256);\n } else {\n int i, planes_nb = 0;\n for (i = 0; i < desc->nb_components; i++)\n planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1);\n for (i = 0; i < planes_nb; i++) {\n int h = height;\n int bwidth = av_image_get_linesize(pix_fmt, width, i);\n if (i == 1 || i == 2) {\n h= -((-height)>>desc->log2_chroma_h);\n }\n av_image_copy_plane(dst_data[i], dst_linesizes[i],\n src_data[i], src_linesizes[i],\n bwidth, h);\n }\n }\n}']
634
0
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/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_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_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!BN_copy(&(recp->N), d))\n return 0;\n BN_zero(&(recp->Nr));\n recp->num_bits = BN_num_bits(d);\n recp->shift = 0;\n return 1;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
635
0
https://github.com/libav/libav/blob/6cecd63005b29a1dc3a5104e6ac85fd112705122/libavcodec/8bps.c/#L126
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; EightBpsContext * const c = avctx->priv_data; const unsigned char *encoded = buf; unsigned char *pixptr, *pixptr_end; unsigned int height = avctx->height; unsigned int dlen, p, row; const unsigned char *lp, *dp; unsigned char count; unsigned int px_inc; unsigned int planes = c->planes; unsigned char *planemap = c->planemap; if(c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); c->pic.reference = 0; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; if(avctx->get_buffer(avctx, &c->pic) < 0){ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } dp = encoded + planes * (height << 1); if (planes == 4) planes--; px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGB32); for (p = 0; p < planes; p++) { lp = encoded + p * (height << 1); for(row = 0; row < height; row++) { pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p]; pixptr_end = pixptr + c->pic.linesize[0]; dlen = be2me_16(*(const unsigned short *)(lp+row*2)); while(dlen > 0) { if(dp + 1 >= buf+buf_size) return -1; if ((count = *dp++) <= 127) { count++; dlen -= count + 1; if (pixptr + count * px_inc > pixptr_end) break; if(dp + count > buf+buf_size) return -1; while(count--) { *pixptr = *dp++; pixptr += px_inc; } } else { count = 257 - count; if (pixptr + count * px_inc > pixptr_end) break; while(count--) { *pixptr = *dp; pixptr += px_inc; } dp++; dlen -= 2; } } } } if (avctx->palctrl) { memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE); if (avctx->palctrl->palette_changed) { c->pic.palette_has_changed = 1; avctx->palctrl->palette_changed = 0; } else c->pic.palette_has_changed = 0; } *data_size = sizeof(AVFrame); *(AVFrame*)data = c->pic; return buf_size; }
['static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n EightBpsContext * const c = avctx->priv_data;\n const unsigned char *encoded = buf;\n unsigned char *pixptr, *pixptr_end;\n unsigned int height = avctx->height;\n unsigned int dlen, p, row;\n const unsigned char *lp, *dp;\n unsigned char count;\n unsigned int px_inc;\n unsigned int planes = c->planes;\n unsigned char *planemap = c->planemap;\n if(c->pic.data[0])\n avctx->release_buffer(avctx, &c->pic);\n c->pic.reference = 0;\n c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;\n if(avctx->get_buffer(avctx, &c->pic) < 0){\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return -1;\n }\n dp = encoded + planes * (height << 1);\n if (planes == 4)\n planes--;\n px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGB32);\n for (p = 0; p < planes; p++) {\n lp = encoded + p * (height << 1);\n for(row = 0; row < height; row++) {\n pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p];\n pixptr_end = pixptr + c->pic.linesize[0];\n dlen = be2me_16(*(const unsigned short *)(lp+row*2));\n while(dlen > 0) {\n if(dp + 1 >= buf+buf_size) return -1;\n if ((count = *dp++) <= 127) {\n count++;\n dlen -= count + 1;\n if (pixptr + count * px_inc > pixptr_end)\n break;\n if(dp + count > buf+buf_size) return -1;\n while(count--) {\n *pixptr = *dp++;\n pixptr += px_inc;\n }\n } else {\n count = 257 - count;\n if (pixptr + count * px_inc > pixptr_end)\n break;\n while(count--) {\n *pixptr = *dp;\n pixptr += px_inc;\n }\n dp++;\n dlen -= 2;\n }\n }\n }\n }\n if (avctx->palctrl) {\n memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);\n if (avctx->palctrl->palette_changed) {\n c->pic.palette_has_changed = 1;\n avctx->palctrl->palette_changed = 0;\n } else\n c->pic.palette_has_changed = 0;\n }\n *data_size = sizeof(AVFrame);\n *(AVFrame*)data = c->pic;\n return buf_size;\n}']
636
0
https://github.com/openssl/openssl/blob/176f31ddec84a51d35871dc021a013df9f3cbccd/apps/speed.c/#L2440
static int do_multi(int multi) { int n; int fd[2]; int *fds; static char sep[]=":"; fds=malloc(multi*sizeof *fds); for(n=0 ; n < multi ; ++n) { pipe(fd); if(fork()) { close(fd[1]); fds[n]=fd[0]; } else { close(fd[0]); close(1); dup(fd[1]); close(fd[1]); mr=1; usertime=0; return 0; } printf("Forked child %d\n",n); } for(n=0 ; n < multi ; ++n) { FILE *f; char buf[1024]; char *p; f=fdopen(fds[n],"r"); while(fgets(buf,sizeof buf,f)) { p=strchr(buf,'\n'); if(p) *p='\0'; if(buf[0] != '+') { fprintf(stderr,"Don't understand line '%s' from child %d\n", buf,n); continue; } printf("Got: %s from %d\n",buf,n); if(!strncmp(buf,"+F:",3)) { int alg; int j; p=buf+3; alg=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); for(j=0 ; j < SIZE_NUM ; ++j) results[alg][j]+=atof(sstrsep(&p,sep)); } else if(!strncmp(buf,"+F2:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); else rsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); else rsa_results[k][1]=d; } else if(!strncmp(buf,"+F2:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d); else rsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d); else rsa_results[k][1]=d; } else if(!strncmp(buf,"+F3:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d); else dsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d); else dsa_results[k][1]=d; } #ifndef OPENSSL_NO_ECDSA else if(!strncmp(buf,"+F4:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) ecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d); else ecdsa_results[k][0]=d; d=atof(sstrsep(&p,sep)); if(n) ecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d); else ecdsa_results[k][1]=d; } #endif #ifndef OPENSSL_NO_ECDH else if(!strncmp(buf,"+F5:",4)) { int k; double d; p=buf+4; k=atoi(sstrsep(&p,sep)); sstrsep(&p,sep); d=atof(sstrsep(&p,sep)); if(n) ecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d); else ecdh_results[k][0]=d; } #endif else if(!strncmp(buf,"+H:",3)) { } else fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n); } } return 1; }
['static int do_multi(int multi)\n\t{\n\tint n;\n\tint fd[2];\n\tint *fds;\n\tstatic char sep[]=":";\n\tfds=malloc(multi*sizeof *fds);\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tpipe(fd);\n\t\tif(fork())\n\t\t\t{\n\t\t\tclose(fd[1]);\n\t\t\tfds[n]=fd[0];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tclose(fd[0]);\n\t\t\tclose(1);\n\t\t\tdup(fd[1]);\n\t\t\tclose(fd[1]);\n\t\t\tmr=1;\n\t\t\tusertime=0;\n\t\t\treturn 0;\n\t\t\t}\n\t\tprintf("Forked child %d\\n",n);\n\t\t}\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tFILE *f;\n\t\tchar buf[1024];\n\t\tchar *p;\n\t\tf=fdopen(fds[n],"r");\n\t\twhile(fgets(buf,sizeof buf,f))\n\t\t\t{\n\t\t\tp=strchr(buf,\'\\n\');\n\t\t\tif(p)\n\t\t\t\t*p=\'\\0\';\n\t\t\tif(buf[0] != \'+\')\n\t\t\t\t{\n\t\t\t\tfprintf(stderr,"Don\'t understand line \'%s\' from child %d\\n",\n\t\t\t\t\t\tbuf,n);\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tprintf("Got: %s from %d\\n",buf,n);\n\t\t\tif(!strncmp(buf,"+F:",3))\n\t\t\t\t{\n\t\t\t\tint alg;\n\t\t\t\tint j;\n\t\t\t\tp=buf+3;\n\t\t\t\talg=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\tfor(j=0 ; j < SIZE_NUM ; ++j)\n\t\t\t\t\tresults[alg][j]+=atof(sstrsep(&p,sep));\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F3:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][1]=d;\n\t\t\t\t}\n#ifndef OPENSSL_NO_ECDSA\n\t\t\telse if(!strncmp(buf,"+F4:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][1]=d;\n\t\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\telse if(!strncmp(buf,"+F5:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdh_results[k][0]=d;\n\t\t\t\t}\n#endif\n\t\t\telse if(!strncmp(buf,"+H:",3))\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tfprintf(stderr,"Unknown type \'%s\' from child %d\\n",buf,n);\n\t\t\t}\n\t\t}\n\treturn 1;\n\t}']
637
0
https://github.com/openssl/openssl/blob/0bde1089f895718db2fe2637fda4a0c2ed6df904/crypto/lhash/lhash.c/#L240
void *lh_delete(LHASH *lh, void *data) { unsigned long hash; LHASH_NODE *nn,**rn; void *ret; lh->error=0; rn=getrn(lh,data,&hash); if (*rn == NULL) { lh->num_no_delete++; return(NULL); } else { nn= *rn; *rn=nn->next; ret=nn->data; Free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) contract(lh); return(ret); }
['int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)\n\t{\n\tint ret=0;\n\tBIO *in=NULL;\n\tint i,count=0;\n\tX509 *x=NULL;\n\tif (file == NULL) return(1);\n\tin=BIO_new(BIO_s_file_internal());\n\tif ((in == NULL) || (BIO_read_filename(in,file) <= 0))\n\t\t{\n\t\tX509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_SYS_LIB);\n\t\tgoto err;\n\t\t}\n\tif (type == X509_FILETYPE_PEM)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tx=PEM_read_bio_X509_AUX(in,NULL,NULL,NULL);\n\t\t\tif (x == NULL)\n\t\t\t\t{\n\t\t\t\tif ((ERR_GET_REASON(ERR_peek_error()) ==\n\t\t\t\t\tPEM_R_NO_START_LINE) && (count > 0))\n\t\t\t\t\t{\n\t\t\t\t\tERR_clear_error();\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_LOAD_CERT_FILE,\n\t\t\t\t\t\tERR_R_PEM_LIB);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\ti=X509_STORE_add_cert(ctx->store_ctx,x);\n\t\t\tif (!i) goto err;\n\t\t\tcount++;\n\t\t\tX509_free(x);\n\t\t\tx=NULL;\n\t\t\t}\n\t\tret=count;\n\t\t}\n\telse if (type == X509_FILETYPE_ASN1)\n\t\t{\n\t\tx=d2i_X509_bio(in,NULL);\n\t\tif (x == NULL)\n\t\t\t{\n\t\t\tX509err(X509_F_X509_LOAD_CERT_FILE,ERR_R_ASN1_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ti=X509_STORE_add_cert(ctx->store_ctx,x);\n\t\tif (!i) goto err;\n\t\tret=i;\n\t\t}\n\telse\n\t\t{\n\t\tX509err(X509_F_X509_LOAD_CERT_FILE,X509_R_BAD_X509_FILETYPE);\n\t\tgoto err;\n\t\t}\nerr:\n\tif (x != NULL) X509_free(x);\n\tif (in != NULL) BIO_free(in);\n\treturn(ret);\n\t}', 'int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)\n\t{\n\tX509_OBJECT *obj,*r;\n\tint ret=1;\n\tif (x == NULL) return(0);\n\tobj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));\n\tif (obj == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tobj->type=X509_LU_X509;\n\tobj->data.x509=x;\n\tCRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n\tX509_OBJECT_up_ref_count(obj);\n\tr=(X509_OBJECT *)lh_insert(ctx->certs,obj);\n\tif (r != NULL)\n\t\t{\n\t\tlh_delete(ctx->certs,obj);\n\t\tX509_OBJECT_free_contents(obj);\n\t\tFree(obj);\n\t\tlh_insert(ctx->certs,r);\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);\n\t\tret=0;\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\n\treturn(ret);\n\t}', 'void *lh_insert(LHASH *lh, void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\tif (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))\n\t\texpand(lh);\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tif ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn(NULL);\n\t\t\t}\n\t\tnn->data=data;\n\t\tnn->next=NULL;\n#ifndef NO_HASH_COMP\n\t\tnn->hash=hash;\n#endif\n\t\t*rn=nn;\n\t\tret=NULL;\n\t\tlh->num_insert++;\n\t\tlh->num_items++;\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\t(*rn)->data=data;\n\t\tlh->num_replace++;\n\t\t}\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
638
0
https://github.com/openssl/openssl/blob/d4b009d5f88875ac0e3ac0b2b9689ed16a4c88dc/crypto/lhash/lhash.c/#L209
void *lh_delete(_LHASH *lh, const void *data) { unsigned long hash; LHASH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return (NULL); } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return (ret); }
['int ssl_get_prev_session(SSL *s, const PACKET *ext, const PACKET *session_id)\n{\n SSL_SESSION *ret = NULL;\n int fatal = 0;\n int try_session_cache = 1;\n int r;\n size_t len = PACKET_remaining(session_id);\n if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)\n goto err;\n if (len == 0)\n try_session_cache = 0;\n r = tls_check_serverhello_tlsext_early(s, ext, session_id, &ret);\n switch (r) {\n case -1:\n fatal = 1;\n goto err;\n case 0:\n case 1:\n break;\n case 2:\n case 3:\n try_session_cache = 0;\n break;\n default:\n abort();\n }\n if (try_session_cache &&\n ret == NULL &&\n !(s->session_ctx->session_cache_mode &\n SSL_SESS_CACHE_NO_INTERNAL_LOOKUP)) {\n SSL_SESSION data;\n size_t local_len;\n data.ssl_version = s->version;\n if (!PACKET_copy_all(session_id, data.session_id,\n sizeof(data.session_id),\n &local_len)) {\n goto err;\n }\n data.session_id_length = local_len;\n CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);\n ret = lh_SSL_SESSION_retrieve(s->session_ctx->sessions, &data);\n if (ret != NULL) {\n CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_SSL_SESSION);\n }\n CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);\n if (ret == NULL)\n s->session_ctx->stats.sess_miss++;\n }\n if (try_session_cache &&\n ret == NULL && s->session_ctx->get_session_cb != NULL) {\n int copy = 1;\n unsigned char *sid = NULL;\n size_t sid_len;\n if (!PACKET_memdup(session_id, &sid, &sid_len))\n goto err;\n ret = s->session_ctx->get_session_cb(s, sid, sid_len, &copy);\n OPENSSL_free(sid);\n if (ret != NULL) {\n s->session_ctx->stats.sess_cb_hit++;\n if (copy)\n CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_SSL_SESSION);\n if (!\n (s->session_ctx->session_cache_mode &\n SSL_SESS_CACHE_NO_INTERNAL_STORE)) {\n if (SSL_CTX_add_session(s->session_ctx, ret))\n goto err;\n }\n }\n }\n if (ret == NULL)\n goto err;\n if (ret->sid_ctx_length != s->sid_ctx_length\n || memcmp(ret->sid_ctx, s->sid_ctx, ret->sid_ctx_length)) {\n goto err;\n }\n if ((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) {\n SSLerr(SSL_F_SSL_GET_PREV_SESSION,\n SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);\n fatal = 1;\n goto err;\n }\n if (ret->cipher == NULL) {\n unsigned char buf[5], *p;\n unsigned long l;\n p = buf;\n l = ret->cipher_id;\n l2n(l, p);\n if ((ret->ssl_version >> 8) >= SSL3_VERSION_MAJOR)\n ret->cipher = ssl_get_cipher_by_char(s, &(buf[2]));\n else\n ret->cipher = ssl_get_cipher_by_char(s, &(buf[1]));\n if (ret->cipher == NULL)\n goto err;\n }\n if (ret->timeout < (long)(time(NULL) - ret->time)) {\n s->session_ctx->stats.sess_timeout++;\n if (try_session_cache) {\n SSL_CTX_remove_session(s->session_ctx, ret);\n }\n goto err;\n }\n if (ret->flags & SSL_SESS_FLAG_EXTMS) {\n if (!(s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS)) {\n SSLerr(SSL_F_SSL_GET_PREV_SESSION, SSL_R_INCONSISTENT_EXTMS);\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);\n fatal = 1;\n goto err;\n }\n } else if (s->s3->flags & TLS1_FLAGS_RECEIVED_EXTMS) {\n goto err;\n }\n s->session_ctx->stats.sess_hit++;\n SSL_SESSION_free(s->session);\n s->session = ret;\n s->verify_result = s->session->verify_result;\n return 1;\n err:\n if (ret != NULL) {\n SSL_SESSION_free(ret);\n if (!try_session_cache) {\n s->tlsext_ticket_expected = 1;\n }\n }\n if (fatal)\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_w_lock(CRYPTO_LOCK_SSL_CTX);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n if (lck)\n CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n if (ret) {\n r->not_resumable = 1;\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, r);\n SSL_SESSION_free(r);\n }\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n unsigned long hash;\n LHASH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
639
0
https://github.com/libav/libav/blob/58ef4ecff834f47f5a4c2a6bd4385b1999a30930/libavcodec/h264.h/#L935
static void fill_decode_caches(H264Context *h, int mb_type){ MpegEncContext * const s = &h->s; int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; const uint8_t * left_block= h->left_block; int i; uint8_t *nnz; uint8_t *nnz_cache; topleft_xy = h->topleft_mb_xy; top_xy = h->top_mb_xy; topright_xy = h->topright_mb_xy; left_xy[LTOP] = h->left_mb_xy[LTOP]; left_xy[LBOT] = h->left_mb_xy[LBOT]; topleft_type = h->topleft_type; top_type = h->top_type; topright_type = h->topright_type; left_type[LTOP]= h->left_type[LTOP]; left_type[LBOT]= h->left_type[LBOT]; if(!IS_SKIP(mb_type)){ if(IS_INTRA(mb_type)){ int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available= h->top_samples_available= h->left_samples_available= 0xFFFF; h->topright_samples_available= 0xEEEA; if(!(top_type & type_mask)){ h->topleft_samples_available= 0xB3FF; h->top_samples_available= 0x33FF; h->topright_samples_available= 0x26EA; } if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){ if(IS_INTERLACED(mb_type)){ if(!(left_type[LTOP] & type_mask)){ h->topleft_samples_available&= 0xDFFF; h->left_samples_available&= 0x5FFF; } if(!(left_type[LBOT] & type_mask)){ h->topleft_samples_available&= 0xFF5F; h->left_samples_available&= 0xFF5F; } }else{ int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride]; assert(left_xy[LTOP] == left_xy[LBOT]); if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } }else{ if(!(left_type[LTOP] & type_mask)){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } if(!(topleft_type & type_mask)) h->topleft_samples_available&= 0x7FFF; if(!(topright_type & type_mask)) h->topright_samples_available&= 0xFBFF; if(IS_INTRA4x4(mb_type)){ if(IS_INTRA4x4(top_type)){ AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); }else{ h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask); } for(i=0; i<2; i++){ if(IS_INTRA4x4(left_type[LEFT(i)])){ int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]]; h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]]; h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]]; }else{ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask); } } } } nnz_cache = h->non_zero_count_cache; if(top_type){ nnz = h->non_zero_count[top_xy]; AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]); if(CHROMA444){ AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]); AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]); }else{ AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]); AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]); } }else{ uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040; AV_WN32A(&nnz_cache[4+8* 0], top_empty); AV_WN32A(&nnz_cache[4+8* 5], top_empty); AV_WN32A(&nnz_cache[4+8*10], top_empty); } for (i=0; i<2; i++) { if(left_type[LEFT(i)]){ nnz = h->non_zero_count[left_xy[LEFT(i)]]; nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]]; nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]]; if(CHROMA444){ nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4]; nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4]; nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4]; nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4]; }else{ nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]]; nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]]; } }else{ nnz_cache[3+8* 1 + 2*8*i]= nnz_cache[3+8* 2 + 2*8*i]= nnz_cache[3+8* 6 + 2*8*i]= nnz_cache[3+8* 7 + 2*8*i]= nnz_cache[3+8*11 + 2*8*i]= nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64; } } if( CABAC ) { if(top_type) { h->top_cbp = h->cbp_table[top_xy]; } else { h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } if (left_type[LTOP]) { h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2) | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2); } else { h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } } } if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ int list; int b_stride = h->b_stride; for(list=0; list<h->list_count; list++){ int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; int8_t *ref = s->current_picture.f.ref_index[list]; int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; int16_t (*mv)[2] = s->current_picture.f.motion_val[list]; if(!USES_LIST(mb_type, list)){ continue; } assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride; AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]); ref_cache[0 - 1*8]= ref_cache[1 - 1*8]= ref[4*top_xy + 2]; ref_cache[2 - 1*8]= ref_cache[3 - 1*8]= ref[4*top_xy + 3]; }else{ AV_ZERO128(mv_cache[0 - 1*8]); AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101); } if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){ for(i=0; i<2; i++){ int cache_idx = -1 + i*2*8; if(USES_LIST(left_type[LEFT(i)], list)){ const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3; const int b8_xy= 4*left_xy[LEFT(i)] + 1; AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]); AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]); ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)]; ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)]; }else{ AV_ZERO32(mv_cache[cache_idx ]); AV_ZERO32(mv_cache[cache_idx+8]); ref_cache[cache_idx ]= ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } }else{ if(USES_LIST(left_type[LTOP], list)){ const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3; const int b8_xy= 4*left_xy[LTOP] + 1; AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]); ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)]; }else{ AV_ZERO32(mv_cache[-1]); ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if(USES_LIST(topright_type, list)){ const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride; AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]); ref_cache[4 - 1*8]= ref[4*topright_xy + 2]; }else{ AV_ZERO32(mv_cache[4 - 1*8]); ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if(ref_cache[4 - 1*8] < 0){ if(USES_LIST(topleft_type, list)){ const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride); const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2); AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]); ref_cache[-1 - 1*8]= ref[b8_xy]; }else{ AV_ZERO32(mv_cache[-1 - 1*8]); ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF) continue; if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){ uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]]; uint8_t (*mvd)[2] = h->mvd_table[list]; ref_cache[2+8*0] = ref_cache[2+8*2] = PART_NOT_AVAILABLE; AV_ZERO32(mv_cache[2+8*0]); AV_ZERO32(mv_cache[2+8*2]); if( CABAC ) { if(USES_LIST(top_type, list)){ const int b_xy= h->mb2br_xy[top_xy]; AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]); }else{ AV_ZERO64(mvd_cache[0 - 1*8]); } if(USES_LIST(left_type[LTOP], list)){ const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6; AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]); AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]); }else{ AV_ZERO16(mvd_cache[-1 + 0*8]); AV_ZERO16(mvd_cache[-1 + 1*8]); } if(USES_LIST(left_type[LBOT], list)){ const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6; AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]); AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]); }else{ AV_ZERO16(mvd_cache[-1 + 2*8]); AV_ZERO16(mvd_cache[-1 + 3*8]); } AV_ZERO16(mvd_cache[2+8*0]); AV_ZERO16(mvd_cache[2+8*2]); if(h->slice_type_nos == AV_PICTURE_TYPE_B){ uint8_t *direct_cache = &h->direct_cache[scan8[0]]; uint8_t *direct_table = h->direct_table; fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1); if(IS_DIRECT(top_type)){ AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1)); }else if(IS_8X8(top_type)){ int b8_xy = 4*top_xy; direct_cache[0 - 1*8]= direct_table[b8_xy + 2]; direct_cache[2 - 1*8]= direct_table[b8_xy + 3]; }else{ AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1)); } if(IS_DIRECT(left_type[LTOP])) direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[LTOP])) direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)]; else direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1; if(IS_DIRECT(left_type[LBOT])) direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[LBOT])) direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)]; else direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1; } } } if(FRAME_MBAFF){ #define MAP_MVS\ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\ MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\ MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\ MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT]) if(MB_FIELD){ #define MAP_F2F(idx, mb_type)\ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] <<= 1;\ h->mv_cache[list][idx][1] /= 2;\ h->mvd_cache[list][idx][1] >>=1;\ } MAP_MVS #undef MAP_F2F }else{ #define MAP_F2F(idx, mb_type)\ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] >>= 1;\ h->mv_cache[list][idx][1] <<= 1;\ h->mvd_cache[list][idx][1] <<= 1;\ } MAP_MVS #undef MAP_F2F } } } } h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]); }
['int ff_h264_decode_mb_cavlc(H264Context *h){\n MpegEncContext * const s = &h->s;\n int mb_xy;\n int partition_count;\n unsigned int mb_type, cbp;\n int dct8x8_allowed= h->pps.transform_8x8_mode;\n int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\n mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;\n tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n cbp = 0;\n if(h->slice_type_nos != AV_PICTURE_TYPE_I){\n if(s->mb_skip_run==-1)\n s->mb_skip_run= get_ue_golomb(&s->gb);\n if (s->mb_skip_run--) {\n if(FRAME_MBAFF && (s->mb_y&1) == 0){\n if(s->mb_skip_run==0)\n h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);\n }\n decode_mb_skip(h);\n return 0;\n }\n }\n if(FRAME_MBAFF){\n if( (s->mb_y&1) == 0 )\n h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb);\n }\n h->prev_mb_skipped= 0;\n mb_type= get_ue_golomb(&s->gb);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n if(mb_type < 23){\n partition_count= b_mb_type_info[mb_type].partition_count;\n mb_type= b_mb_type_info[mb_type].type;\n }else{\n mb_type -= 23;\n goto decode_intra_mb;\n }\n }else if(h->slice_type_nos == AV_PICTURE_TYPE_P){\n if(mb_type < 5){\n partition_count= p_mb_type_info[mb_type].partition_count;\n mb_type= p_mb_type_info[mb_type].type;\n }else{\n mb_type -= 5;\n goto decode_intra_mb;\n }\n }else{\n assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\n if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\ndecode_intra_mb:\n if(mb_type > 25){\n av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\\n", mb_type, av_get_picture_type_char(h->slice_type), s->mb_x, s->mb_y);\n return -1;\n }\n partition_count=0;\n cbp= i_mb_type_info[mb_type].cbp;\n h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n mb_type= i_mb_type_info[mb_type].type;\n }\n if(MB_FIELD)\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[ mb_xy ]= h->slice_num;\n if(IS_INTRA_PCM(mb_type)){\n unsigned int x;\n static const uint16_t mb_sizes[4] = {256,384,512,768};\n const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;\n align_get_bits(&s->gb);\n for(x=0; x < mb_size; x++){\n ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8);\n }\n s->current_picture.f.qscale_table[mb_xy] = 0;\n memset(h->non_zero_count[mb_xy], 16, 48);\n s->current_picture.f.mb_type[mb_xy] = mb_type;\n return 0;\n }\n if(MB_MBAFF){\n h->ref_count[0] <<= 1;\n h->ref_count[1] <<= 1;\n }\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n if(IS_INTRA(mb_type)){\n int pred_mode;\n if(IS_INTRA4x4(mb_type)){\n int i;\n int di = 1;\n if(dct8x8_allowed && get_bits1(&s->gb)){\n mb_type |= MB_TYPE_8x8DCT;\n di = 4;\n }\n for(i=0; i<16; i+=di){\n int mode= pred_intra_mode(h, i);\n if(!get_bits1(&s->gb)){\n const int rem_mode= get_bits(&s->gb, 3);\n mode = rem_mode + (rem_mode >= mode);\n }\n if(di==4)\n fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n else\n h->intra4x4_pred_mode_cache[ scan8[i] ] = mode;\n }\n write_back_intra_pred_mode(h);\n if( ff_h264_check_intra4x4_pred_mode(h) < 0)\n return -1;\n }else{\n h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode);\n if(h->intra16x16_pred_mode < 0)\n return -1;\n }\n if(decode_chroma){\n pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb));\n if(pred_mode < 0)\n return -1;\n h->chroma_pred_mode= pred_mode;\n } else {\n h->chroma_pred_mode = DC_128_PRED8x8;\n }\n }else if(partition_count==4){\n int i, j, sub_partition_count[4], list, ref[2][4];\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n for(i=0; i<4; i++){\n h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);\n if(h->sub_mb_type[i] >=13){\n av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\\n", h->sub_mb_type[i], s->mb_x, s->mb_y);\n return -1;\n }\n sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n if( IS_DIRECT(h->sub_mb_type[0]|h->sub_mb_type[1]|h->sub_mb_type[2]|h->sub_mb_type[3])) {\n ff_h264_pred_direct_motion(h, &mb_type);\n h->ref_cache[0][scan8[4]] =\n h->ref_cache[1][scan8[4]] =\n h->ref_cache[0][scan8[12]] =\n h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n }\n }else{\n assert(h->slice_type_nos == AV_PICTURE_TYPE_P);\n for(i=0; i<4; i++){\n h->sub_mb_type[i]= get_ue_golomb_31(&s->gb);\n if(h->sub_mb_type[i] >=4){\n av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\\n", h->sub_mb_type[i], s->mb_x, s->mb_y);\n return -1;\n }\n sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n }\n for(list=0; list<h->list_count; list++){\n int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list];\n for(i=0; i<4; i++){\n if(IS_DIRECT(h->sub_mb_type[i])) continue;\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n unsigned int tmp;\n if(ref_count == 1){\n tmp= 0;\n }else if(ref_count == 2){\n tmp= get_bits1(&s->gb)^1;\n }else{\n tmp= get_ue_golomb_31(&s->gb);\n if(tmp>=ref_count){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", tmp);\n return -1;\n }\n }\n ref[list][i]= tmp;\n }else{\n ref[list][i] = -1;\n }\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h);\n for(list=0; list<h->list_count; list++){\n for(i=0; i<4; i++){\n if(IS_DIRECT(h->sub_mb_type[i])) {\n h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ];\n continue;\n }\n h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]=\n h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n const int sub_mb_type= h->sub_mb_type[i];\n const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n for(j=0; j<sub_partition_count[i]; j++){\n int mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n if(IS_SUB_8X8(sub_mb_type)){\n mv_cache[ 1 ][0]=\n mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n mv_cache[ 1 ][1]=\n mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n }\n }else{\n uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];\n p[0] = p[1]=\n p[8] = p[9]= 0;\n }\n }\n }\n }else if(IS_DIRECT(mb_type)){\n ff_h264_pred_direct_motion(h, &mb_type);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n }else{\n int list, mx, my, i;\n if(IS_16X16(mb_type)){\n for(list=0; list<h->list_count; list++){\n unsigned int val;\n if(IS_DIR(mb_type, 0, list)){\n if(h->ref_count[list]==1){\n val= 0;\n }else if(h->ref_count[list]==2){\n val= get_bits1(&s->gb)^1;\n }else{\n val= get_ue_golomb_31(&s->gb);\n if(val >= h->ref_count[list]){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }\n }\n }\n else if(IS_16X8(mb_type)){\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n if(h->ref_count[list] == 1){\n val= 0;\n }else if(h->ref_count[list] == 2){\n val= get_bits1(&s->gb)^1;\n }else{\n val= get_ue_golomb_31(&s->gb);\n if(val >= h->ref_count[list]){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, val, 4);\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n if(h->ref_count[list]==1){\n val= 0;\n }else if(h->ref_count[list]==2){\n val= get_bits1(&s->gb)^1;\n }else{\n val= get_ue_golomb_31(&s->gb);\n if(val >= h->ref_count[list]){\n av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\\n", val);\n return -1;\n }\n }\n }else\n val= LIST_NOT_USED&0xFF;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n unsigned int val;\n if(IS_DIR(mb_type, i, list)){\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n mx += get_se_golomb(&s->gb);\n my += get_se_golomb(&s->gb);\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n val= pack16to32(mx,my);\n }else\n val=0;\n fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, val, 4);\n }\n }\n }\n }\n if(IS_INTER(mb_type))\n write_back_motion(h, mb_type);\n if(!IS_INTRA16x16(mb_type)){\n cbp= get_ue_golomb(&s->gb);\n if(decode_chroma){\n if(cbp > 47){\n av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, s->mb_x, s->mb_y);\n return -1;\n }\n if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp];\n else cbp= golomb_to_inter_cbp [cbp];\n }else{\n if(cbp > 15){\n av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\\n", cbp, s->mb_x, s->mb_y);\n return -1;\n }\n if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp];\n else cbp= golomb_to_inter_cbp_gray[cbp];\n }\n }\n if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){\n mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb);\n }\n h->cbp=\n h->cbp_table[mb_xy]= cbp;\n s->current_picture.f.mb_type[mb_xy] = mb_type;\n if(cbp || IS_INTRA16x16(mb_type)){\n int i4x4, chroma_idx;\n int dquant;\n int ret;\n GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr;\n const uint8_t *scan, *scan8x8;\n const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n if(IS_INTERLACED(mb_type)){\n scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0;\n scan= s->qscale ? h->field_scan : h->field_scan_q0;\n }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n }\n dquant= get_se_golomb(&s->gb);\n s->qscale += dquant;\n if(((unsigned)s->qscale) > max_qp){\n if(s->qscale<0) s->qscale+= max_qp+1;\n else s->qscale-= max_qp+1;\n if(((unsigned)s->qscale) > max_qp){\n av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\\n", dquant, s->mb_x, s->mb_y);\n return -1;\n }\n }\n h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale);\n if( (ret = decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ){\n return -1;\n }\n h->cbp_table[mb_xy] |= ret << 12;\n if(CHROMA444){\n if( decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ){\n return -1;\n }\n if( decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ){\n return -1;\n }\n } else {\n if(cbp&0x30){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++)\n if( decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift), CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){\n return -1;\n }\n }\n if(cbp&0x20){\n for(chroma_idx=0; chroma_idx<2; chroma_idx++){\n const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]];\n for(i4x4=0; i4x4<4; i4x4++){\n const int index= 16 + 16*chroma_idx + i4x4;\n if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, scan + 1, qmul, 15) < 0){\n return -1;\n }\n }\n }\n }else{\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n }else{\n fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n s->current_picture.f.qscale_table[mb_xy] = s->qscale;\n write_back_non_zero_count(h);\n if(MB_MBAFF){\n h->ref_count[0] >>= 1;\n h->ref_count[1] >>= 1;\n }\n return 0;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n static const uint8_t left_block_options[4][32]={\n {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},\n {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},\n {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},\n {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1);\n topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1);\n top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy ] >> 7) & 1) - 1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = s->current_picture.f.mb_type[topleft_xy];\n h->top_type = s->current_picture.f.mb_type[top_xy];\n h->topright_type = s->current_picture.f.mb_type[topright_xy];\n h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];\n h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];\n if(FMO){\n if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }else{\n if(h->slice_table[topleft_xy ] != h->slice_num){\n h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t * left_block= h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP]= h->left_type[LTOP];\n left_type[LBOT]= h->left_type[LBOT];\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[LBOT] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n }else{\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[LEFT(i)])){\n int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];\n }else{\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if(top_type){\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);\n if(CHROMA444){\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);\n }else{\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);\n }\n }else{\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n for (i=0; i<2; i++) {\n if(left_type[LEFT(i)]){\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];\n nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];\n if(CHROMA444){\n nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];\n nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];\n nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];\n nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];\n }else{\n nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];\n nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];\n }\n }else{\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else {\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)\n | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)\n | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n int b_stride = h->b_stride;\n for(list=0; list<h->list_count; list++){\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = s->current_picture.f.ref_index[list];\n int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t (*mv)[2] = s->current_picture.f.motion_val[list];\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;\n AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);\n ref_cache[0 - 1*8]=\n ref_cache[1 - 1*8]= ref[4*top_xy + 2];\n ref_cache[2 - 1*8]=\n ref_cache[3 - 1*8]= ref[4*top_xy + 3];\n }else{\n AV_ZERO128(mv_cache[0 - 1*8]);\n AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){\n for(i=0; i<2; i++){\n int cache_idx = -1 + i*2*8;\n if(USES_LIST(left_type[LEFT(i)], list)){\n const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy= 4*left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);\n AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);\n ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];\n ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];\n }else{\n AV_ZERO32(mv_cache[cache_idx ]);\n AV_ZERO32(mv_cache[cache_idx+8]);\n ref_cache[cache_idx ]=\n ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n }else{\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy= 4*left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);\n ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];\n }else{\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;\n AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);\n ref_cache[4 - 1*8]= ref[4*topright_xy + 2];\n }else{\n AV_ZERO32(mv_cache[4 - 1*8]);\n ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(ref_cache[4 - 1*8] < 0){\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);\n const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);\n ref_cache[-1 - 1*8]= ref[b8_xy];\n }else{\n AV_ZERO32(mv_cache[-1 - 1*8]);\n ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){\n uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t (*mvd)[2] = h->mvd_table[list];\n ref_cache[2+8*0] =\n ref_cache[2+8*2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2+8*0]);\n AV_ZERO32(mv_cache[2+8*2]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);\n }else{\n AV_ZERO64(mvd_cache[0 - 1*8]);\n }\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 0*8]);\n AV_ZERO16(mvd_cache[-1 + 1*8]);\n }\n if(USES_LIST(left_type[LBOT], list)){\n const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 2*8]);\n AV_ZERO16(mvd_cache[-1 + 3*8]);\n }\n AV_ZERO16(mvd_cache[2+8*0]);\n AV_ZERO16(mvd_cache[2+8*2]);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = 4*top_xy;\n direct_cache[0 - 1*8]= direct_table[b8_xy + 2];\n direct_cache[2 - 1*8]= direct_table[b8_xy + 3];\n }else{\n AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];\n else\n direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];\n else\n direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] >>=1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
640
0
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n BIGNUM *i, *j, *k, *l, *m;\n BN_CTX *ctx;\n int ret = 1;\n if (key->p == NULL || key->q == NULL || key->n == NULL\n || key->e == NULL || key->d == NULL) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n return 0;\n }\n i = BN_new();\n j = BN_new();\n k = BN_new();\n l = BN_new();\n m = BN_new();\n ctx = BN_CTX_new();\n if (i == NULL || j == NULL || k == NULL || l == NULL\n || m == NULL || ctx == NULL) {\n ret = -1;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (BN_is_one(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (!BN_is_odd(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n }\n if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n }\n if (!BN_mul(i, key->p, key->q, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->n) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n }\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_sub(j, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_div(k, NULL, l, m, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_is_one(i)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n }\n if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmp1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_sub(i, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmq1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->iqmp) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n }\n }\n err:\n BN_free(i);\n BN_free(j);\n BN_free(k);\n BN_free(l);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_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# 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 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}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int max;\n int add = 0, neg = 0;\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg) {\n if (b->neg) {\n const BIGNUM *tmp;\n tmp = a;\n a = b;\n b = tmp;\n } else {\n add = 1;\n neg = 1;\n }\n } else {\n if (b->neg) {\n add = 1;\n neg = 0;\n }\n }\n if (add) {\n if (!BN_uadd(r, a, b))\n return 0;\n r->neg = neg;\n return 1;\n }\n max = (a->top > b->top) ? a->top : b->top;\n if (bn_wexpand(r, max) == NULL)\n return 0;\n if (BN_ucmp(a, b) < 0) {\n if (!BN_usub(r, b, a))\n return 0;\n r->neg = 1;\n } else {\n if (!BN_usub(r, a, b))\n return 0;\n r->neg = 0;\n }\n bn_check_top(r);\n return 1;\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}', '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}']
641
0
https://github.com/libav/libav/blob/25b6837f7cacd691b19cbc12b9dad1ce84a318a1/libavcodec/vp8dsp.c/#L121
static void vp7_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride) { int i, a1, b1, c1, d1; int16_t tmp[16]; for (i = 0; i < 4; i++) { a1 = (block[i * 4 + 0] + block[i * 4 + 2]) * 23170; b1 = (block[i * 4 + 0] - block[i * 4 + 2]) * 23170; c1 = block[i * 4 + 1] * 12540 - block[i * 4 + 3] * 30274; d1 = block[i * 4 + 1] * 30274 + block[i * 4 + 3] * 12540; block[i * 4 + 0] = 0; block[i * 4 + 1] = 0; block[i * 4 + 2] = 0; block[i * 4 + 3] = 0; tmp[i * 4 + 0] = (a1 + d1) >> 14; tmp[i * 4 + 3] = (a1 - d1) >> 14; tmp[i * 4 + 1] = (b1 + c1) >> 14; tmp[i * 4 + 2] = (b1 - c1) >> 14; } for (i = 0; i < 4; i++) { a1 = (tmp[i + 0] + tmp[i + 8]) * 23170; b1 = (tmp[i + 0] - tmp[i + 8]) * 23170; c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274; d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540; dst[0 * stride + i] = av_clip_uint8(dst[0 * stride + i] + ((a1 + d1 + 0x20000) >> 18)); dst[3 * stride + i] = av_clip_uint8(dst[3 * stride + i] + ((a1 - d1 + 0x20000) >> 18)); dst[1 * stride + i] = av_clip_uint8(dst[1 * stride + i] + ((b1 + c1 + 0x20000) >> 18)); dst[2 * stride + i] = av_clip_uint8(dst[2 * stride + i] + ((b1 - c1 + 0x20000) >> 18)); } }
['static void vp7_idct_add_c(uint8_t *dst, int16_t block[16], ptrdiff_t stride)\n{\n int i, a1, b1, c1, d1;\n int16_t tmp[16];\n for (i = 0; i < 4; i++) {\n a1 = (block[i * 4 + 0] + block[i * 4 + 2]) * 23170;\n b1 = (block[i * 4 + 0] - block[i * 4 + 2]) * 23170;\n c1 = block[i * 4 + 1] * 12540 - block[i * 4 + 3] * 30274;\n d1 = block[i * 4 + 1] * 30274 + block[i * 4 + 3] * 12540;\n block[i * 4 + 0] = 0;\n block[i * 4 + 1] = 0;\n block[i * 4 + 2] = 0;\n block[i * 4 + 3] = 0;\n tmp[i * 4 + 0] = (a1 + d1) >> 14;\n tmp[i * 4 + 3] = (a1 - d1) >> 14;\n tmp[i * 4 + 1] = (b1 + c1) >> 14;\n tmp[i * 4 + 2] = (b1 - c1) >> 14;\n }\n for (i = 0; i < 4; i++) {\n a1 = (tmp[i + 0] + tmp[i + 8]) * 23170;\n b1 = (tmp[i + 0] - tmp[i + 8]) * 23170;\n c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;\n d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;\n dst[0 * stride + i] = av_clip_uint8(dst[0 * stride + i] +\n ((a1 + d1 + 0x20000) >> 18));\n dst[3 * stride + i] = av_clip_uint8(dst[3 * stride + i] +\n ((a1 - d1 + 0x20000) >> 18));\n dst[1 * stride + i] = av_clip_uint8(dst[1 * stride + i] +\n ((b1 + c1 + 0x20000) >> 18));\n dst[2 * stride + i] = av_clip_uint8(dst[2 * stride + i] +\n ((b1 - c1 + 0x20000) >> 18));\n }\n}']
642
0
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int i;\n int ret = -2;\n int err = 0;\n BIGNUM *A, *B, *tmp;\n static const int tab[8] = { 0, 1, 0, -1, 0, -1, 0, 1 };\n bn_check_top(a);\n bn_check_top(b);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n if (B == NULL)\n goto end;\n err = !BN_copy(A, a);\n if (err)\n goto end;\n err = !BN_copy(B, b);\n if (err)\n goto end;\n if (BN_is_zero(B)) {\n ret = BN_abs_is_word(A, 1);\n goto end;\n }\n if (!BN_is_odd(A) && !BN_is_odd(B)) {\n ret = 0;\n goto end;\n }\n i = 0;\n while (!BN_is_bit_set(B, i))\n i++;\n err = !BN_rshift(B, B, i);\n if (err)\n goto end;\n if (i & 1) {\n ret = tab[BN_lsw(A) & 7];\n } else {\n ret = 1;\n }\n if (B->neg) {\n B->neg = 0;\n if (A->neg)\n ret = -ret;\n }\n while (1) {\n if (BN_is_zero(A)) {\n ret = BN_is_one(B) ? ret : 0;\n goto end;\n }\n i = 0;\n while (!BN_is_bit_set(A, i))\n i++;\n err = !BN_rshift(A, A, i);\n if (err)\n goto end;\n if (i & 1) {\n ret = ret * tab[BN_lsw(B) & 7];\n }\n if ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)\n ret = -ret;\n err = !BN_nnmod(B, B, A, ctx);\n if (err)\n goto end;\n tmp = A;\n A = B;\n B = tmp;\n tmp->neg = 0;\n }\n end:\n BN_CTX_end(ctx);\n if (err)\n return -2;\n else\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
643
0
https://github.com/openssl/openssl/blob/8fa6a40be2935ca109a28cc43d28cd27051ada01/crypto/lhash/lhash.c/#L365
static void contract(LHASH *lh) { LHASH_NODE **n,*n1,*np; np=lh->b[lh->p+lh->pmax-1]; lh->b[lh->p+lh->pmax-1]=NULL; if (lh->p == 0) { n=(LHASH_NODE **)OPENSSL_realloc(lh->b, (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); if (n == NULL) { lh->error++; return; } lh->num_contract_reallocs++; lh->num_alloc_nodes/=2; lh->pmax/=2; lh->p=lh->pmax-1; lh->b=n; } else lh->p--; lh->num_nodes--; lh->num_contracts++; n1=lh->b[(int)lh->p]; if (n1 == NULL) lh->b[(int)lh->p]=np; else { while (n1->next != NULL) n1=n1->next; n1->next=np; } }
['void CRYPTO_dbg_free(void *addr, int before_p)\n\t{\n\tMEM m,*mp;\n\tswitch(before_p)\n\t\t{\n\tcase 0:\n\t\tif (addr == NULL)\n\t\t\tbreak;\n\t\tif (is_MemCheck_on() && (mh != NULL))\n\t\t\t{\n\t\t\tMemCheck_off();\n\t\t\tm.addr=addr;\n\t\t\tmp=(MEM *)lh_delete(mh,(char *)&m);\n\t\t\tif (mp != NULL)\n\t\t\t\t{\n#ifdef LEVITTE_DEBUG_MEM\n\t\t\tfprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] - 0x%p (%d)\\n",\n\t\t\t\tmp->order, mp->addr, mp->num);\n#endif\n\t\t\t\tif (mp->app_info != NULL)\n\t\t\t\t\tapp_info_free(mp->app_info);\n\t\t\t\tOPENSSL_free(mp);\n\t\t\t\t}\n\t\t\tMemCheck_on();\n\t\t\t}\n\t\tbreak;\n\tcase 1:\n\t\tbreak;\n\t\t}\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
644
0
https://github.com/openssl/openssl/blob/972c87dfc7e765bd28a4964519c362f0d3a58ca4/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_exp_simple(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 *d;\n BIGNUM *val[TABLE_SIZE];\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_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\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(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\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(d, val[0], val[0], m, 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(val[i], val[i - 1], d, m, 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(r, r, r, m, 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(r, r, r, m, ctx))\n goto err;\n }\n if (!BN_mod_mul(r, r, val[wvalue >> 1], m, 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_check_top(r);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_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}']
645
0
https://gitlab.com/libtiff/libtiff/blob/537cd1da1856d734a353511e063f755d77aae927/tools/tiff2pdf.c/#L1936
void t2p_read_tiff_size(T2P* t2p, TIFF* input){ uint64* sbc=NULL; #if defined(JPEG_SUPPORT) || defined (OJPEG_SUPPORT) unsigned char* jpt=NULL; tstrip_t i=0; tstrip_t stripcount=0; #endif uint64 k = 0; if(t2p->pdf_transcode == T2P_TRANSCODE_RAW){ #ifdef CCITT_SUPPORT if(t2p->pdf_compression == T2P_COMPRESS_G4 ){ TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc); if (sbc[0] != (uint64)(tmsize_t)sbc[0]) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } t2p->tiff_datasize=(tmsize_t)sbc[0]; return; } #endif #ifdef ZIP_SUPPORT if(t2p->pdf_compression == T2P_COMPRESS_ZIP){ TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc); if (sbc[0] != (uint64)(tmsize_t)sbc[0]) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } t2p->tiff_datasize=(tmsize_t)sbc[0]; return; } #endif #ifdef OJPEG_SUPPORT if(t2p->tiff_compression == COMPRESSION_OJPEG){ if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){ TIFFError(TIFF2PDF_MODULE, "Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS", TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; } stripcount=TIFFNumberOfStrips(input); for(i=0;i<stripcount;i++){ k = checkAdd64(k, sbc[i], t2p); } if(TIFFGetField(input, TIFFTAG_JPEGIFOFFSET, &(t2p->tiff_dataoffset))){ if(t2p->tiff_dataoffset != 0){ if(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){ if((uint64)t2p->tiff_datasize < k) { TIFFWarning(TIFF2PDF_MODULE, "Input file %s has short JPEG interchange file byte count", TIFFFileName(input)); t2p->pdf_ojpegiflength=t2p->tiff_datasize; k = checkAdd64(k, t2p->tiff_datasize, t2p); k = checkAdd64(k, 6, t2p); k = checkAdd64(k, stripcount, t2p); k = checkAdd64(k, stripcount, t2p); t2p->tiff_datasize = (tsize_t) k; if ((uint64) t2p->tiff_datasize != k) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } return; } return; }else { TIFFError(TIFF2PDF_MODULE, "Input file %s missing field: TIFFTAG_JPEGIFBYTECOUNT", TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; } } } k = checkAdd64(k, stripcount, t2p); k = checkAdd64(k, stripcount, t2p); k = checkAdd64(k, 2048, t2p); t2p->tiff_datasize = (tsize_t) k; if ((uint64) t2p->tiff_datasize != k) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } return; } #endif #ifdef JPEG_SUPPORT if(t2p->tiff_compression == COMPRESSION_JPEG) { uint32 count = 0; if(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){ if(count > 4){ k += count; k -= 2; } } else { k = 2; } stripcount=TIFFNumberOfStrips(input); if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){ TIFFError(TIFF2PDF_MODULE, "Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS", TIFFFileName(input)); t2p->t2p_error = T2P_ERR_ERROR; return; } for(i=0;i<stripcount;i++){ k = checkAdd64(k, sbc[i], t2p); k -=2; k +=2; } k = checkAdd64(k, 2, t2p); k = checkAdd64(k, 6, t2p); t2p->tiff_datasize = (tsize_t) k; if ((uint64) t2p->tiff_datasize != k) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } return; } #endif (void) 0; } k = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p); if(t2p->tiff_planar==PLANARCONFIG_SEPARATE){ k = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p); } if (k == 0) { t2p->t2p_error = T2P_ERR_ERROR; } t2p->tiff_datasize = (tsize_t) k; if ((uint64) t2p->tiff_datasize != k) { TIFFError(TIFF2PDF_MODULE, "Integer overflow"); t2p->t2p_error = T2P_ERR_ERROR; } return; }
['void t2p_read_tiff_size(T2P* t2p, TIFF* input){\n\tuint64* sbc=NULL;\n#if defined(JPEG_SUPPORT) || defined (OJPEG_SUPPORT)\n\tunsigned char* jpt=NULL;\n\ttstrip_t i=0;\n\ttstrip_t stripcount=0;\n#endif\n uint64 k = 0;\n\tif(t2p->pdf_transcode == T2P_TRANSCODE_RAW){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4 ){\n\t\t\tTIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);\n if (sbc[0] != (uint64)(tmsize_t)sbc[0]) {\n TIFFError(TIFF2PDF_MODULE, "Integer overflow");\n t2p->t2p_error = T2P_ERR_ERROR;\n }\n\t\t\tt2p->tiff_datasize=(tmsize_t)sbc[0];\n\t\t\treturn;\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tTIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);\n if (sbc[0] != (uint64)(tmsize_t)sbc[0]) {\n TIFFError(TIFF2PDF_MODULE, "Integer overflow");\n t2p->t2p_error = T2P_ERR_ERROR;\n }\n\t\t\tt2p->tiff_datasize=(tmsize_t)sbc[0];\n\t\t\treturn;\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstripcount=TIFFNumberOfStrips(input);\n\t\t\tfor(i=0;i<stripcount;i++){\n\t\t\t\tk = checkAdd64(k, sbc[i], t2p);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGIFOFFSET, &(t2p->tiff_dataoffset))){\n\t\t\t\tif(t2p->tiff_dataoffset != 0){\n\t\t\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGIFBYTECOUNT, &(t2p->tiff_datasize))!=0){\n\t\t\t\t\t\tif((uint64)t2p->tiff_datasize < k) {\n\t\t\t\t\t\t\tTIFFWarning(TIFF2PDF_MODULE,\n\t\t\t\t\t\t\t\t"Input file %s has short JPEG interchange file byte count",\n\t\t\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t\tt2p->pdf_ojpegiflength=t2p->tiff_datasize;\n\t\t\t\t\t\t\tk = checkAdd64(k, t2p->tiff_datasize, t2p);\n\t\t\t\t\t\t\tk = checkAdd64(k, 6, t2p);\n\t\t\t\t\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\t\t\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\t\t\t\t\tt2p->tiff_datasize = (tsize_t) k;\n\t\t\t\t\t\t\tif ((uint64) t2p->tiff_datasize != k) {\n\t\t\t\t\t\t\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\t\t\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}else {\n\t\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t\t"Input file %s missing field: TIFFTAG_JPEGIFBYTECOUNT",\n\t\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\tk = checkAdd64(k, stripcount, t2p);\n\t\t\tk = checkAdd64(k, 2048, t2p);\n\t\t\tt2p->tiff_datasize = (tsize_t) k;\n\t\t\tif ((uint64) t2p->tiff_datasize != k) {\n\t\t\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG) {\n\t\t\tuint32 count = 0;\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0 ){\n\t\t\t\tif(count > 4){\n\t\t\t\t\tk += count;\n\t\t\t\t\tk -= 2;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tk = 2;\n\t\t\t}\n\t\t\tstripcount=TIFFNumberOfStrips(input);\n\t\t\tif(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(i=0;i<stripcount;i++){\n\t\t\t\tk = checkAdd64(k, sbc[i], t2p);\n\t\t\t\tk -=2;\n\t\t\t\tk +=2;\n\t\t\t}\n\t\t\tk = checkAdd64(k, 2, t2p);\n\t\t\tk = checkAdd64(k, 6, t2p);\n\t\t\tt2p->tiff_datasize = (tsize_t) k;\n\t\t\tif ((uint64) t2p->tiff_datasize != k) {\n\t\t\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n#endif\n\t\t(void) 0;\n\t}\n\tk = checkMultiply64(TIFFScanlineSize(input), t2p->tiff_length, t2p);\n\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\tk = checkMultiply64(k, t2p->tiff_samplesperpixel, t2p);\n\t}\n\tif (k == 0) {\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t}\n\tt2p->tiff_datasize = (tsize_t) k;\n\tif ((uint64) t2p->tiff_datasize != k) {\n\t\tTIFFError(TIFF2PDF_MODULE, "Integer overflow");\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t}\n\treturn;\n}', 'int\nTIFFGetField(TIFF* tif, uint32 tag, ...)\n{\n\tint status;\n\tva_list ap;\n\tva_start(ap, tag);\n\tstatus = TIFFVGetField(tif, tag, ap);\n\tva_end(ap);\n\treturn (status);\n}', 'uint32\nTIFFNumberOfStrips(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 nstrips;\n\tnstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :\n\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tnstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,\n\t\t "TIFFNumberOfStrips");\n\treturn (nstrips);\n}', 'uint32\n_TIFFMultiply32(TIFF* tif, uint32 first, uint32 second, const char* where)\n{\n\tuint32 bytes = first * second;\n\tif (second && bytes / second != first) {\n\t\tTIFFErrorExt(tif->tif_clientdata, where, "Integer overflow in %s", where);\n\t\tbytes = 0;\n\t}\n\treturn bytes;\n}']
646
0
https://github.com/libav/libav/blob/41874d0a5df35732367f0c675eac914c23d65aee/libavcodec/celp_filters.c/#L146
void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs, const float* in, int buffer_length, int filter_length) { int i,n; #if 0 for (n = 0; n < buffer_length; n++) { out[n] = in[n]; for (i = 1; i <= filter_length; i++) out[n] -= filter_coeffs[i-1] * out[n-i]; } #else float out0, out1, out2, out3; float old_out0, old_out1, old_out2, old_out3; float a,b,c; a = filter_coeffs[0]; b = filter_coeffs[1]; c = filter_coeffs[2]; b -= filter_coeffs[0] * filter_coeffs[0]; c -= filter_coeffs[1] * filter_coeffs[0]; c -= filter_coeffs[0] * b; old_out0 = out[-4]; old_out1 = out[-3]; old_out2 = out[-2]; old_out3 = out[-1]; for (n = 0; n <= buffer_length - 4; n+=4) { float tmp0,tmp1,tmp2,tmp3; float val; out0 = in[0]; out1 = in[1]; out2 = in[2]; out3 = in[3]; out0 -= filter_coeffs[2] * old_out1; out1 -= filter_coeffs[2] * old_out2; out2 -= filter_coeffs[2] * old_out3; out0 -= filter_coeffs[1] * old_out2; out1 -= filter_coeffs[1] * old_out3; out0 -= filter_coeffs[0] * old_out3; val = filter_coeffs[3]; out0 -= val * old_out0; out1 -= val * old_out1; out2 -= val * old_out2; out3 -= val * old_out3; old_out3 = out[-5]; for (i = 5; i <= filter_length; i += 2) { val = filter_coeffs[i-1]; out0 -= val * old_out3; out1 -= val * old_out0; out2 -= val * old_out1; out3 -= val * old_out2; old_out2 = out[-i-1]; val = filter_coeffs[i]; out0 -= val * old_out2; out1 -= val * old_out3; out2 -= val * old_out0; out3 -= val * old_out1; FFSWAP(float, old_out0, old_out2); old_out1 = old_out3; old_out3 = out[-i-2]; } tmp0 = out0; tmp1 = out1; tmp2 = out2; tmp3 = out3; out3 -= a * tmp2; out2 -= a * tmp1; out1 -= a * tmp0; out3 -= b * tmp1; out2 -= b * tmp0; out3 -= c * tmp0; out[0] = out0; out[1] = out1; out[2] = out2; out[3] = out3; old_out0 = out0; old_out1 = out1; old_out2 = out2; old_out3 = out3; out += 4; in += 4; } out -= n; in -= n; for (; n < buffer_length; n++) { out[n] = in[n]; for (i = 1; i <= filter_length; i++) out[n] -= filter_coeffs[i-1] * out[n-i]; } #endif }
['static void ra144_encode_subblock(RA144Context *ractx,\n const int16_t *sblock_data,\n const int16_t *lpc_coefs, unsigned int rms,\n PutBitContext *pb)\n{\n float data[BLOCKSIZE], work[LPC_ORDER + BLOCKSIZE];\n float coefs[LPC_ORDER];\n float zero[BLOCKSIZE], cba[BLOCKSIZE], cb1[BLOCKSIZE], cb2[BLOCKSIZE];\n int16_t cba_vect[BLOCKSIZE];\n int cba_idx, cb1_idx, cb2_idx, gain;\n int i, n, m[3];\n float g[3];\n float error, best_error;\n for (i = 0; i < LPC_ORDER; i++) {\n work[i] = ractx->curr_sblock[BLOCKSIZE + i];\n coefs[i] = lpc_coefs[i] * (1/4096.0);\n }\n memset(data, 0, sizeof(data));\n ff_celp_lp_synthesis_filterf(work + LPC_ORDER, coefs, data, BLOCKSIZE,\n LPC_ORDER);\n for (i = 0; i < BLOCKSIZE; i++) {\n zero[i] = work[LPC_ORDER + i];\n data[i] = sblock_data[i] - zero[i];\n }\n memset(work, 0, LPC_ORDER * sizeof(*work));\n cba_idx = adaptive_cb_search(ractx->adapt_cb, work + LPC_ORDER, coefs,\n data);\n if (cba_idx) {\n memcpy(cba, work + LPC_ORDER, sizeof(cba));\n ff_copy_and_dup(cba_vect, ractx->adapt_cb, cba_idx + BLOCKSIZE / 2 - 1);\n m[0] = (ff_irms(cba_vect) * rms) >> 12;\n }\n fixed_cb_search(work + LPC_ORDER, coefs, data, cba_idx, &cb1_idx, &cb2_idx);\n for (i = 0; i < BLOCKSIZE; i++) {\n cb1[i] = ff_cb1_vects[cb1_idx][i];\n cb2[i] = ff_cb2_vects[cb2_idx][i];\n }\n ff_celp_lp_synthesis_filterf(work + LPC_ORDER, coefs, cb1, BLOCKSIZE,\n LPC_ORDER);\n memcpy(cb1, work + LPC_ORDER, sizeof(cb1));\n m[1] = (ff_cb1_base[cb1_idx] * rms) >> 8;\n ff_celp_lp_synthesis_filterf(work + LPC_ORDER, coefs, cb2, BLOCKSIZE,\n LPC_ORDER);\n memcpy(cb2, work + LPC_ORDER, sizeof(cb2));\n m[2] = (ff_cb2_base[cb2_idx] * rms) >> 8;\n best_error = FLT_MAX;\n gain = 0;\n for (n = 0; n < 256; n++) {\n g[1] = ((ff_gain_val_tab[n][1] * m[1]) >> ff_gain_exp_tab[n]) *\n (1/4096.0);\n g[2] = ((ff_gain_val_tab[n][2] * m[2]) >> ff_gain_exp_tab[n]) *\n (1/4096.0);\n error = 0;\n if (cba_idx) {\n g[0] = ((ff_gain_val_tab[n][0] * m[0]) >> ff_gain_exp_tab[n]) *\n (1/4096.0);\n for (i = 0; i < BLOCKSIZE; i++) {\n data[i] = zero[i] + g[0] * cba[i] + g[1] * cb1[i] +\n g[2] * cb2[i];\n error += (data[i] - sblock_data[i]) *\n (data[i] - sblock_data[i]);\n }\n } else {\n for (i = 0; i < BLOCKSIZE; i++) {\n data[i] = zero[i] + g[1] * cb1[i] + g[2] * cb2[i];\n error += (data[i] - sblock_data[i]) *\n (data[i] - sblock_data[i]);\n }\n }\n if (error < best_error) {\n best_error = error;\n gain = n;\n }\n }\n put_bits(pb, 7, cba_idx);\n put_bits(pb, 8, gain);\n put_bits(pb, 7, cb1_idx);\n put_bits(pb, 7, cb2_idx);\n ff_subblock_synthesis(ractx, lpc_coefs, cba_idx, cb1_idx, cb2_idx, rms,\n gain);\n}', 'void ff_celp_lp_synthesis_filterf(float *out, const float *filter_coeffs,\n const float* in, int buffer_length,\n int filter_length)\n{\n int i,n;\n#if 0\n for (n = 0; n < buffer_length; n++) {\n out[n] = in[n];\n for (i = 1; i <= filter_length; i++)\n out[n] -= filter_coeffs[i-1] * out[n-i];\n }\n#else\n float out0, out1, out2, out3;\n float old_out0, old_out1, old_out2, old_out3;\n float a,b,c;\n a = filter_coeffs[0];\n b = filter_coeffs[1];\n c = filter_coeffs[2];\n b -= filter_coeffs[0] * filter_coeffs[0];\n c -= filter_coeffs[1] * filter_coeffs[0];\n c -= filter_coeffs[0] * b;\n old_out0 = out[-4];\n old_out1 = out[-3];\n old_out2 = out[-2];\n old_out3 = out[-1];\n for (n = 0; n <= buffer_length - 4; n+=4) {\n float tmp0,tmp1,tmp2,tmp3;\n float val;\n out0 = in[0];\n out1 = in[1];\n out2 = in[2];\n out3 = in[3];\n out0 -= filter_coeffs[2] * old_out1;\n out1 -= filter_coeffs[2] * old_out2;\n out2 -= filter_coeffs[2] * old_out3;\n out0 -= filter_coeffs[1] * old_out2;\n out1 -= filter_coeffs[1] * old_out3;\n out0 -= filter_coeffs[0] * old_out3;\n val = filter_coeffs[3];\n out0 -= val * old_out0;\n out1 -= val * old_out1;\n out2 -= val * old_out2;\n out3 -= val * old_out3;\n old_out3 = out[-5];\n for (i = 5; i <= filter_length; i += 2) {\n val = filter_coeffs[i-1];\n out0 -= val * old_out3;\n out1 -= val * old_out0;\n out2 -= val * old_out1;\n out3 -= val * old_out2;\n old_out2 = out[-i-1];\n val = filter_coeffs[i];\n out0 -= val * old_out2;\n out1 -= val * old_out3;\n out2 -= val * old_out0;\n out3 -= val * old_out1;\n FFSWAP(float, old_out0, old_out2);\n old_out1 = old_out3;\n old_out3 = out[-i-2];\n }\n tmp0 = out0;\n tmp1 = out1;\n tmp2 = out2;\n tmp3 = out3;\n out3 -= a * tmp2;\n out2 -= a * tmp1;\n out1 -= a * tmp0;\n out3 -= b * tmp1;\n out2 -= b * tmp0;\n out3 -= c * tmp0;\n out[0] = out0;\n out[1] = out1;\n out[2] = out2;\n out[3] = out3;\n old_out0 = out0;\n old_out1 = out1;\n old_out2 = out2;\n old_out3 = out3;\n out += 4;\n in += 4;\n }\n out -= n;\n in -= n;\n for (; n < buffer_length; n++) {\n out[n] = in[n];\n for (i = 1; i <= filter_length; i++)\n out[n] -= filter_coeffs[i-1] * out[n-i];\n }\n#endif\n}']
647
0
https://github.com/openssl/openssl/blob/abdb0c7b4ec73d6e94d4d8a0d6ee027e3b8db428/ssl/statem/statem_srvr.c/#L1877
int tls_construct_server_key_exchange(SSL *s) { #ifndef OPENSSL_NO_DH EVP_PKEY *pkdh = NULL; int j; #endif #ifndef OPENSSL_NO_EC unsigned char *encodedPoint = NULL; int encodedlen = 0; int curve_id = 0; #endif EVP_PKEY *pkey; const EVP_MD *md = NULL; unsigned char *p, *d; int al, i; unsigned long type; int n; const BIGNUM *r[4]; int nr[4], kn; BUF_MEM *buf; EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); if (md_ctx == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE); al = SSL_AD_INTERNAL_ERROR; goto f_err; } type = s->s3->tmp.new_cipher->algorithm_mkey; buf = s->init_buf; r[0] = r[1] = r[2] = r[3] = NULL; n = 0; #ifndef OPENSSL_NO_PSK if (type & SSL_PSK) { n += 2; if (s->cert->psk_identity_hint) n += strlen(s->cert->psk_identity_hint); } if (type & (SSL_kPSK | SSL_kRSAPSK)) { } else #endif #ifndef OPENSSL_NO_DH if (type & (SSL_kDHE | SSL_kDHEPSK)) { CERT *cert = s->cert; EVP_PKEY *pkdhp = NULL; DH *dh; if (s->cert->dh_tmp_auto) { DH *dhp = ssl_get_auto_dh(s); pkdh = EVP_PKEY_new(); if (pkdh == NULL || dhp == NULL) { DH_free(dhp); al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } EVP_PKEY_assign_DH(pkdh, dhp); pkdhp = pkdh; } else { pkdhp = cert->dh_tmp; } if ((pkdhp == NULL) && (s->cert->dh_tmp_cb != NULL)) { DH *dhp = s->cert->dh_tmp_cb(s, 0, 1024); pkdh = ssl_dh_to_pkey(dhp); if (pkdh == NULL) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } pkdhp = pkdh; } if (pkdhp == NULL) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, SSL_R_MISSING_TMP_DH_KEY); goto f_err; } if (!ssl_security(s, SSL_SECOP_TMP_DH, EVP_PKEY_security_bits(pkdhp), 0, pkdhp)) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, SSL_R_DH_KEY_TOO_SMALL); goto f_err; } if (s->s3->tmp.pkey != NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto err; } s->s3->tmp.pkey = ssl_generate_pkey(pkdhp, NID_undef); if (s->s3->tmp.pkey == NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EVP_LIB); goto err; } dh = EVP_PKEY_get0_DH(s->s3->tmp.pkey); EVP_PKEY_free(pkdh); pkdh = NULL; DH_get0_pqg(dh, &r[0], NULL, &r[1]); DH_get0_key(dh, &r[2], NULL); } else #endif #ifndef OPENSSL_NO_EC if (type & (SSL_kECDHE | SSL_kECDHEPSK)) { int nid; if (s->s3->tmp.pkey != NULL) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto err; } nid = tls1_shared_curve(s, -2); curve_id = tls1_ec_nid2curve_id(nid); if (curve_id == 0) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE); goto err; } s->s3->tmp.pkey = ssl_generate_pkey(NULL, nid); if (s->s3->tmp.pkey == NULL) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EVP_LIB); goto f_err; } encodedlen = EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(s->s3->tmp.pkey), POINT_CONVERSION_UNCOMPRESSED, &encodedPoint, NULL); if (encodedlen == 0) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EC_LIB); goto err; } n += 4 + encodedlen; r[0] = NULL; r[1] = NULL; r[2] = NULL; r[3] = NULL; } else #endif #ifndef OPENSSL_NO_SRP if (type & SSL_kSRP) { if ((s->srp_ctx.N == NULL) || (s->srp_ctx.g == NULL) || (s->srp_ctx.s == NULL) || (s->srp_ctx.B == NULL)) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, SSL_R_MISSING_SRP_PARAM); goto err; } r[0] = s->srp_ctx.N; r[1] = s->srp_ctx.g; r[2] = s->srp_ctx.s; r[3] = s->srp_ctx.B; } else #endif { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); goto f_err; } for (i = 0; i < 4 && r[i] != NULL; i++) { nr[i] = BN_num_bytes(r[i]); #ifndef OPENSSL_NO_SRP if ((i == 2) && (type & SSL_kSRP)) n += 1 + nr[i]; else #endif #ifndef OPENSSL_NO_DH if ((i == 2) && (type & (SSL_kDHE | SSL_kDHEPSK))) n += 2 + nr[0]; else #endif n += 2 + nr[i]; } if (!(s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL|SSL_aSRP)) && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_PSK)) { if ((pkey = ssl_get_sign_pkey(s, s->s3->tmp.new_cipher, &md)) == NULL) { al = SSL_AD_DECODE_ERROR; goto f_err; } kn = EVP_PKEY_size(pkey); if (SSL_USE_SIGALGS(s)) kn += 2; kn += 2; } else { pkey = NULL; kn = 0; } if (!BUF_MEM_grow_clean(buf, n + SSL_HM_HEADER_LENGTH(s) + kn)) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_LIB_BUF); goto err; } d = p = ssl_handshake_start(s); #ifndef OPENSSL_NO_PSK if (type & SSL_PSK) { if (s->cert->psk_identity_hint) { size_t len = strlen(s->cert->psk_identity_hint); if (len > PSK_MAX_IDENTITY_LEN) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto err; } s2n(len, p); memcpy(p, s->cert->psk_identity_hint, len); p += len; } else { s2n(0, p); } } #endif for (i = 0; i < 4 && r[i] != NULL; i++) { #ifndef OPENSSL_NO_SRP if ((i == 2) && (type & SSL_kSRP)) { *p = nr[i]; p++; } else #endif #ifndef OPENSSL_NO_DH if ((i == 2) && (type & (SSL_kDHE | SSL_kDHEPSK))) { s2n(nr[0], p); for (j = 0; j < (nr[0] - nr[2]); ++j) { *p = 0; ++p; } } else #endif s2n(nr[i], p); BN_bn2bin(r[i], p); p += nr[i]; } #ifndef OPENSSL_NO_EC if (type & (SSL_kECDHE | SSL_kECDHEPSK)) { *p = NAMED_CURVE_TYPE; p += 1; *p = 0; p += 1; *p = curve_id; p += 1; *p = encodedlen; p += 1; memcpy(p, encodedPoint, encodedlen); OPENSSL_free(encodedPoint); encodedPoint = NULL; p += encodedlen; } #endif if (pkey != NULL) { if (md) { if (SSL_USE_SIGALGS(s)) { if (!tls12_get_sigandhash(p, pkey, md)) { al = SSL_AD_INTERNAL_ERROR; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } p += 2; } #ifdef SSL_DEBUG fprintf(stderr, "Using hash %s\n", EVP_MD_name(md)); #endif if (EVP_SignInit_ex(md_ctx, md, NULL) <= 0 || EVP_SignUpdate(md_ctx, &(s->s3->client_random[0]), SSL3_RANDOM_SIZE) <= 0 || EVP_SignUpdate(md_ctx, &(s->s3->server_random[0]), SSL3_RANDOM_SIZE) <= 0 || EVP_SignUpdate(md_ctx, d, n) <= 0 || EVP_SignFinal(md_ctx, &(p[2]), (unsigned int *)&i, pkey) <= 0) { SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_LIB_EVP); al = SSL_AD_INTERNAL_ERROR; goto f_err; } s2n(i, p); n += i + 2; if (SSL_USE_SIGALGS(s)) n += 2; } else { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, SSL_R_UNKNOWN_PKEY_TYPE); goto f_err; } } if (!ssl_set_handshake_header(s, SSL3_MT_SERVER_KEY_EXCHANGE, n)) { al = SSL_AD_HANDSHAKE_FAILURE; SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR); goto f_err; } EVP_MD_CTX_free(md_ctx); return 1; f_err: ssl3_send_alert(s, SSL3_AL_FATAL, al); err: #ifndef OPENSSL_NO_DH EVP_PKEY_free(pkdh); #endif #ifndef OPENSSL_NO_EC OPENSSL_free(encodedPoint); #endif EVP_MD_CTX_free(md_ctx); ossl_statem_set_error(s); return 0; }
['int tls_construct_server_key_exchange(SSL *s)\n{\n#ifndef OPENSSL_NO_DH\n EVP_PKEY *pkdh = NULL;\n int j;\n#endif\n#ifndef OPENSSL_NO_EC\n unsigned char *encodedPoint = NULL;\n int encodedlen = 0;\n int curve_id = 0;\n#endif\n EVP_PKEY *pkey;\n const EVP_MD *md = NULL;\n unsigned char *p, *d;\n int al, i;\n unsigned long type;\n int n;\n const BIGNUM *r[4];\n int nr[4], kn;\n BUF_MEM *buf;\n EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n if (md_ctx == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_MALLOC_FAILURE);\n al = SSL_AD_INTERNAL_ERROR;\n goto f_err;\n }\n type = s->s3->tmp.new_cipher->algorithm_mkey;\n buf = s->init_buf;\n r[0] = r[1] = r[2] = r[3] = NULL;\n n = 0;\n#ifndef OPENSSL_NO_PSK\n if (type & SSL_PSK) {\n n += 2;\n if (s->cert->psk_identity_hint)\n n += strlen(s->cert->psk_identity_hint);\n }\n if (type & (SSL_kPSK | SSL_kRSAPSK)) {\n } else\n#endif\n#ifndef OPENSSL_NO_DH\n if (type & (SSL_kDHE | SSL_kDHEPSK)) {\n CERT *cert = s->cert;\n EVP_PKEY *pkdhp = NULL;\n DH *dh;\n if (s->cert->dh_tmp_auto) {\n DH *dhp = ssl_get_auto_dh(s);\n pkdh = EVP_PKEY_new();\n if (pkdh == NULL || dhp == NULL) {\n DH_free(dhp);\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n EVP_PKEY_assign_DH(pkdh, dhp);\n pkdhp = pkdh;\n } else {\n pkdhp = cert->dh_tmp;\n }\n if ((pkdhp == NULL) && (s->cert->dh_tmp_cb != NULL)) {\n DH *dhp = s->cert->dh_tmp_cb(s, 0, 1024);\n pkdh = ssl_dh_to_pkey(dhp);\n if (pkdh == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n pkdhp = pkdh;\n }\n if (pkdhp == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_DH_KEY);\n goto f_err;\n }\n if (!ssl_security(s, SSL_SECOP_TMP_DH,\n EVP_PKEY_security_bits(pkdhp), 0, pkdhp)) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n SSL_R_DH_KEY_TOO_SMALL);\n goto f_err;\n }\n if (s->s3->tmp.pkey != NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n s->s3->tmp.pkey = ssl_generate_pkey(pkdhp, NID_undef);\n if (s->s3->tmp.pkey == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EVP_LIB);\n goto err;\n }\n dh = EVP_PKEY_get0_DH(s->s3->tmp.pkey);\n EVP_PKEY_free(pkdh);\n pkdh = NULL;\n DH_get0_pqg(dh, &r[0], NULL, &r[1]);\n DH_get0_key(dh, &r[2], NULL);\n } else\n#endif\n#ifndef OPENSSL_NO_EC\n if (type & (SSL_kECDHE | SSL_kECDHEPSK)) {\n int nid;\n if (s->s3->tmp.pkey != NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n nid = tls1_shared_curve(s, -2);\n curve_id = tls1_ec_nid2curve_id(nid);\n if (curve_id == 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);\n goto err;\n }\n s->s3->tmp.pkey = ssl_generate_pkey(NULL, nid);\n if (s->s3->tmp.pkey == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EVP_LIB);\n goto f_err;\n }\n encodedlen = EC_KEY_key2buf(EVP_PKEY_get0_EC_KEY(s->s3->tmp.pkey),\n POINT_CONVERSION_UNCOMPRESSED,\n &encodedPoint, NULL);\n if (encodedlen == 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EC_LIB);\n goto err;\n }\n n += 4 + encodedlen;\n r[0] = NULL;\n r[1] = NULL;\n r[2] = NULL;\n r[3] = NULL;\n } else\n#endif\n#ifndef OPENSSL_NO_SRP\n if (type & SSL_kSRP) {\n if ((s->srp_ctx.N == NULL) ||\n (s->srp_ctx.g == NULL) ||\n (s->srp_ctx.s == NULL) || (s->srp_ctx.B == NULL)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n SSL_R_MISSING_SRP_PARAM);\n goto err;\n }\n r[0] = s->srp_ctx.N;\n r[1] = s->srp_ctx.g;\n r[2] = s->srp_ctx.s;\n r[3] = s->srp_ctx.B;\n } else\n#endif\n {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);\n goto f_err;\n }\n for (i = 0; i < 4 && r[i] != NULL; i++) {\n nr[i] = BN_num_bytes(r[i]);\n#ifndef OPENSSL_NO_SRP\n if ((i == 2) && (type & SSL_kSRP))\n n += 1 + nr[i];\n else\n#endif\n#ifndef OPENSSL_NO_DH\n if ((i == 2) && (type & (SSL_kDHE | SSL_kDHEPSK)))\n n += 2 + nr[0];\n else\n#endif\n n += 2 + nr[i];\n }\n if (!(s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL|SSL_aSRP))\n && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_PSK)) {\n if ((pkey = ssl_get_sign_pkey(s, s->s3->tmp.new_cipher, &md))\n == NULL) {\n al = SSL_AD_DECODE_ERROR;\n goto f_err;\n }\n kn = EVP_PKEY_size(pkey);\n if (SSL_USE_SIGALGS(s))\n kn += 2;\n kn += 2;\n } else {\n pkey = NULL;\n kn = 0;\n }\n if (!BUF_MEM_grow_clean(buf, n + SSL_HM_HEADER_LENGTH(s) + kn)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_LIB_BUF);\n goto err;\n }\n d = p = ssl_handshake_start(s);\n#ifndef OPENSSL_NO_PSK\n if (type & SSL_PSK) {\n if (s->cert->psk_identity_hint) {\n size_t len = strlen(s->cert->psk_identity_hint);\n if (len > PSK_MAX_IDENTITY_LEN) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n s2n(len, p);\n memcpy(p, s->cert->psk_identity_hint, len);\n p += len;\n } else {\n s2n(0, p);\n }\n }\n#endif\n for (i = 0; i < 4 && r[i] != NULL; i++) {\n#ifndef OPENSSL_NO_SRP\n if ((i == 2) && (type & SSL_kSRP)) {\n *p = nr[i];\n p++;\n } else\n#endif\n#ifndef OPENSSL_NO_DH\n if ((i == 2) && (type & (SSL_kDHE | SSL_kDHEPSK))) {\n s2n(nr[0], p);\n for (j = 0; j < (nr[0] - nr[2]); ++j) {\n *p = 0;\n ++p;\n }\n } else\n#endif\n s2n(nr[i], p);\n BN_bn2bin(r[i], p);\n p += nr[i];\n }\n#ifndef OPENSSL_NO_EC\n if (type & (SSL_kECDHE | SSL_kECDHEPSK)) {\n *p = NAMED_CURVE_TYPE;\n p += 1;\n *p = 0;\n p += 1;\n *p = curve_id;\n p += 1;\n *p = encodedlen;\n p += 1;\n memcpy(p, encodedPoint, encodedlen);\n OPENSSL_free(encodedPoint);\n encodedPoint = NULL;\n p += encodedlen;\n }\n#endif\n if (pkey != NULL) {\n if (md) {\n if (SSL_USE_SIGALGS(s)) {\n if (!tls12_get_sigandhash(p, pkey, md)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n p += 2;\n }\n#ifdef SSL_DEBUG\n fprintf(stderr, "Using hash %s\\n", EVP_MD_name(md));\n#endif\n if (EVP_SignInit_ex(md_ctx, md, NULL) <= 0\n || EVP_SignUpdate(md_ctx, &(s->s3->client_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_SignUpdate(md_ctx, &(s->s3->server_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_SignUpdate(md_ctx, d, n) <= 0\n || EVP_SignFinal(md_ctx, &(p[2]),\n (unsigned int *)&i, pkey) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_LIB_EVP);\n al = SSL_AD_INTERNAL_ERROR;\n goto f_err;\n }\n s2n(i, p);\n n += i + 2;\n if (SSL_USE_SIGALGS(s))\n n += 2;\n } else {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE,\n SSL_R_UNKNOWN_PKEY_TYPE);\n goto f_err;\n }\n }\n if (!ssl_set_handshake_header(s, SSL3_MT_SERVER_KEY_EXCHANGE, n)) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n EVP_MD_CTX_free(md_ctx);\n return 1;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n#ifndef OPENSSL_NO_DH\n EVP_PKEY_free(pkdh);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(encodedPoint);\n#endif\n EVP_MD_CTX_free(md_ctx);\n ossl_statem_set_error(s);\n return 0;\n}']
648
0
https://github.com/openssl/openssl/blob/d6ee8f3dc4414cd97bd63b801f8644f0ff8a1f17/crypto/bio/b_print.c/#L353
static int _dopr(char **sbuffer, char **buffer, size_t *maxlen, size_t *retlen, int *truncated, const char *format, va_list args) { char ch; int64_t value; LDOUBLE fvalue; char *strvalue; int min; int max; int state; int flags; int cflags; size_t currlen; state = DP_S_DEFAULT; flags = currlen = cflags = min = 0; max = -1; ch = *format++; while (state != DP_S_DONE) { if (ch == '\0' || (buffer == NULL && currlen >= *maxlen)) state = DP_S_DONE; switch (state) { case DP_S_DEFAULT: if (ch == '%') state = DP_S_FLAGS; else if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch)) return 0; ch = *format++; break; case DP_S_FLAGS: switch (ch) { case '-': flags |= DP_F_MINUS; ch = *format++; break; case '+': flags |= DP_F_PLUS; ch = *format++; break; case ' ': flags |= DP_F_SPACE; ch = *format++; break; case '#': flags |= DP_F_NUM; ch = *format++; break; case '0': flags |= DP_F_ZERO; ch = *format++; break; default: state = DP_S_MIN; break; } break; case DP_S_MIN: if (ossl_isdigit(ch)) { min = 10 * min + char_to_int(ch); ch = *format++; } else if (ch == '*') { min = va_arg(args, int); ch = *format++; state = DP_S_DOT; } else state = DP_S_DOT; break; case DP_S_DOT: if (ch == '.') { state = DP_S_MAX; ch = *format++; } else state = DP_S_MOD; break; case DP_S_MAX: if (ossl_isdigit(ch)) { if (max < 0) max = 0; max = 10 * max + char_to_int(ch); ch = *format++; } else if (ch == '*') { max = va_arg(args, int); ch = *format++; state = DP_S_MOD; } else state = DP_S_MOD; break; case DP_S_MOD: switch (ch) { case 'h': cflags = DP_C_SHORT; ch = *format++; break; case 'l': if (*format == 'l') { cflags = DP_C_LLONG; format++; } else cflags = DP_C_LONG; ch = *format++; break; case 'q': case 'j': cflags = DP_C_LLONG; ch = *format++; break; case 'L': cflags = DP_C_LDOUBLE; ch = *format++; break; case 'z': cflags = DP_C_SIZE; ch = *format++; break; default: break; } state = DP_S_CONV; break; case DP_S_CONV: switch (ch) { case 'd': case 'i': switch (cflags) { case DP_C_SHORT: value = (short int)va_arg(args, int); break; case DP_C_LONG: value = va_arg(args, long int); break; case DP_C_LLONG: value = va_arg(args, int64_t); break; case DP_C_SIZE: value = va_arg(args, ossl_ssize_t); break; default: value = va_arg(args, int); break; } if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min, max, flags)) return 0; break; case 'X': flags |= DP_F_UP; case 'x': case 'o': case 'u': flags |= DP_F_UNSIGNED; switch (cflags) { case DP_C_SHORT: value = (unsigned short int)va_arg(args, unsigned int); break; case DP_C_LONG: value = va_arg(args, unsigned long int); break; case DP_C_LLONG: value = va_arg(args, uint64_t); break; case DP_C_SIZE: value = va_arg(args, size_t); break; default: value = va_arg(args, unsigned int); break; } if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, ch == 'o' ? 8 : (ch == 'u' ? 10 : 16), min, max, flags)) return 0; break; case 'f': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); else fvalue = va_arg(args, double); if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, flags, F_FORMAT)) return 0; break; case 'E': flags |= DP_F_UP; case 'e': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); else fvalue = va_arg(args, double); if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, flags, E_FORMAT)) return 0; break; case 'G': flags |= DP_F_UP; case 'g': if (cflags == DP_C_LDOUBLE) fvalue = va_arg(args, LDOUBLE); else fvalue = va_arg(args, double); if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max, flags, G_FORMAT)) return 0; break; case 'c': if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, va_arg(args, int))) return 0; break; case 's': strvalue = va_arg(args, char *); if (max < 0) { if (buffer) max = INT_MAX; else max = *maxlen; } if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue, flags, min, max)) return 0; break; case 'p': value = (size_t)va_arg(args, void *); if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 16, min, max, flags | DP_F_NUM)) return 0; break; case 'n': { int *num; num = va_arg(args, int *); *num = currlen; } break; case '%': if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch)) return 0; break; case 'w': ch = *format++; break; default: break; } ch = *format++; state = DP_S_DEFAULT; flags = cflags = min = 0; max = -1; break; case DP_S_DONE: break; default: break; } } if (buffer == NULL) { *truncated = (currlen > *maxlen - 1); if (*truncated) currlen = *maxlen - 1; } if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0')) return 0; *retlen = currlen - 1; return 1; }
['long BIO_debug_callback(BIO *bio, int cmd, const char *argp,\n int argi, long argl, long ret)\n{\n BIO *b;\n char buf[256];\n char *p;\n long r = 1;\n int len, left;\n if (BIO_CB_RETURN & cmd)\n r = ret;\n len = BIO_snprintf(buf, sizeof(buf), "BIO[%p]: ", (void *)bio);\n if (len < 0)\n len = 0;\n p = buf + len;\n left = sizeof(buf) - len;\n switch (cmd) {\n case BIO_CB_FREE:\n BIO_snprintf(p, left, "Free - %s\\n", bio->method->name);\n break;\n case BIO_CB_READ:\n if (bio->method->type & BIO_TYPE_DESCRIPTOR)\n BIO_snprintf(p, left, "read(%d,%lu) - %s fd=%d\\n",\n bio->num, (unsigned long)argi,\n bio->method->name, bio->num);\n else\n BIO_snprintf(p, left, "read(%d,%lu) - %s\\n",\n bio->num, (unsigned long)argi, bio->method->name);\n break;\n case BIO_CB_WRITE:\n if (bio->method->type & BIO_TYPE_DESCRIPTOR)\n BIO_snprintf(p, left, "write(%d,%lu) - %s fd=%d\\n",\n bio->num, (unsigned long)argi,\n bio->method->name, bio->num);\n else\n BIO_snprintf(p, left, "write(%d,%lu) - %s\\n",\n bio->num, (unsigned long)argi, bio->method->name);\n break;\n case BIO_CB_PUTS:\n BIO_snprintf(p, left, "puts() - %s\\n", bio->method->name);\n break;\n case BIO_CB_GETS:\n BIO_snprintf(p, left, "gets(%lu) - %s\\n", (unsigned long)argi,\n bio->method->name);\n break;\n case BIO_CB_CTRL:\n BIO_snprintf(p, left, "ctrl(%lu) - %s\\n", (unsigned long)argi,\n bio->method->name);\n break;\n case BIO_CB_RETURN | BIO_CB_READ:\n BIO_snprintf(p, left, "read return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_WRITE:\n BIO_snprintf(p, left, "write return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_GETS:\n BIO_snprintf(p, left, "gets return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_PUTS:\n BIO_snprintf(p, left, "puts return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_CTRL:\n BIO_snprintf(p, left, "ctrl return %ld\\n", ret);\n break;\n default:\n BIO_snprintf(p, left, "bio callback - unknown type (%d)\\n", cmd);\n break;\n }\n b = (BIO *)bio->cb_arg;\n if (b != NULL)\n BIO_write(b, buf, strlen(buf));\n#if !defined(OPENSSL_NO_STDIO)\n else\n fputs(buf, stderr);\n#endif\n return r;\n}', 'int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n{\n va_list args;\n int ret;\n va_start(args, format);\n ret = BIO_vsnprintf(buf, n, format, args);\n va_end(args);\n return ret;\n}', 'int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n{\n size_t retlen;\n int truncated;\n if (!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))\n return -1;\n if (truncated)\n return -1;\n else\n return (retlen <= INT_MAX) ? (int)retlen : -1;\n}', "static int\n_dopr(char **sbuffer,\n char **buffer,\n size_t *maxlen,\n size_t *retlen, int *truncated, const char *format, va_list args)\n{\n char ch;\n int64_t value;\n LDOUBLE fvalue;\n char *strvalue;\n int min;\n int max;\n int state;\n int flags;\n int cflags;\n size_t currlen;\n state = DP_S_DEFAULT;\n flags = currlen = cflags = min = 0;\n max = -1;\n ch = *format++;\n while (state != DP_S_DONE) {\n if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n state = DP_S_DONE;\n switch (state) {\n case DP_S_DEFAULT:\n if (ch == '%')\n state = DP_S_FLAGS;\n else\n if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n return 0;\n ch = *format++;\n break;\n case DP_S_FLAGS:\n switch (ch) {\n case '-':\n flags |= DP_F_MINUS;\n ch = *format++;\n break;\n case '+':\n flags |= DP_F_PLUS;\n ch = *format++;\n break;\n case ' ':\n flags |= DP_F_SPACE;\n ch = *format++;\n break;\n case '#':\n flags |= DP_F_NUM;\n ch = *format++;\n break;\n case '0':\n flags |= DP_F_ZERO;\n ch = *format++;\n break;\n default:\n state = DP_S_MIN;\n break;\n }\n break;\n case DP_S_MIN:\n if (ossl_isdigit(ch)) {\n min = 10 * min + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n min = va_arg(args, int);\n ch = *format++;\n state = DP_S_DOT;\n } else\n state = DP_S_DOT;\n break;\n case DP_S_DOT:\n if (ch == '.') {\n state = DP_S_MAX;\n ch = *format++;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MAX:\n if (ossl_isdigit(ch)) {\n if (max < 0)\n max = 0;\n max = 10 * max + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n max = va_arg(args, int);\n ch = *format++;\n state = DP_S_MOD;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MOD:\n switch (ch) {\n case 'h':\n cflags = DP_C_SHORT;\n ch = *format++;\n break;\n case 'l':\n if (*format == 'l') {\n cflags = DP_C_LLONG;\n format++;\n } else\n cflags = DP_C_LONG;\n ch = *format++;\n break;\n case 'q':\n case 'j':\n cflags = DP_C_LLONG;\n ch = *format++;\n break;\n case 'L':\n cflags = DP_C_LDOUBLE;\n ch = *format++;\n break;\n case 'z':\n cflags = DP_C_SIZE;\n ch = *format++;\n break;\n default:\n break;\n }\n state = DP_S_CONV;\n break;\n case DP_S_CONV:\n switch (ch) {\n case 'd':\n case 'i':\n switch (cflags) {\n case DP_C_SHORT:\n value = (short int)va_arg(args, int);\n break;\n case DP_C_LONG:\n value = va_arg(args, long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, int64_t);\n break;\n case DP_C_SIZE:\n value = va_arg(args, ossl_ssize_t);\n break;\n default:\n value = va_arg(args, int);\n break;\n }\n if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,\n max, flags))\n return 0;\n break;\n case 'X':\n flags |= DP_F_UP;\n case 'x':\n case 'o':\n case 'u':\n flags |= DP_F_UNSIGNED;\n switch (cflags) {\n case DP_C_SHORT:\n value = (unsigned short int)va_arg(args, unsigned int);\n break;\n case DP_C_LONG:\n value = va_arg(args, unsigned long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, uint64_t);\n break;\n case DP_C_SIZE:\n value = va_arg(args, size_t);\n break;\n default:\n value = va_arg(args, unsigned int);\n break;\n }\n if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,\n ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n min, max, flags))\n return 0;\n break;\n case 'f':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags, F_FORMAT))\n return 0;\n break;\n case 'E':\n flags |= DP_F_UP;\n case 'e':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags, E_FORMAT))\n return 0;\n break;\n case 'G':\n flags |= DP_F_UP;\n case 'g':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags, G_FORMAT))\n return 0;\n break;\n case 'c':\n if (!doapr_outch(sbuffer, buffer, &currlen, maxlen,\n va_arg(args, int)))\n return 0;\n break;\n case 's':\n strvalue = va_arg(args, char *);\n if (max < 0) {\n if (buffer)\n max = INT_MAX;\n else\n max = *maxlen;\n }\n if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n flags, min, max))\n return 0;\n break;\n case 'p':\n value = (size_t)va_arg(args, void *);\n if (!fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 16, min, max, flags | DP_F_NUM))\n return 0;\n break;\n case 'n':\n {\n int *num;\n num = va_arg(args, int *);\n *num = currlen;\n }\n break;\n case '%':\n if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n return 0;\n break;\n case 'w':\n ch = *format++;\n break;\n default:\n break;\n }\n ch = *format++;\n state = DP_S_DEFAULT;\n flags = cflags = min = 0;\n max = -1;\n break;\n case DP_S_DONE:\n break;\n default:\n break;\n }\n }\n if (buffer == NULL) {\n *truncated = (currlen > *maxlen - 1);\n if (*truncated)\n currlen = *maxlen - 1;\n }\n if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0'))\n return 0;\n *retlen = currlen - 1;\n return 1;\n}"]
649
0
https://github.com/openssl/openssl/blob/ba4341316ce762f917f973bb4ac604062fb11724/crypto/async/async.c/#L39
static async_ctx *async_ctx_new(void) { async_ctx *nctx; if (!ossl_init_thread_start(NULL, NULL, async_delete_thread_state)) return NULL; nctx = OPENSSL_malloc(sizeof(*nctx)); if (nctx == NULL) { ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE); goto err; } async_fibre_init_dispatcher(&nctx->dispatcher); nctx->currjob = NULL; nctx->blocked = 0; if (!CRYPTO_THREAD_set_local(&ctxkey, nctx)) goto err; return nctx; err: OPENSSL_free(nctx); return NULL; }
['static async_ctx *async_ctx_new(void)\n{\n async_ctx *nctx;\n if (!ossl_init_thread_start(NULL, NULL, async_delete_thread_state))\n return NULL;\n nctx = OPENSSL_malloc(sizeof(*nctx));\n if (nctx == NULL) {\n ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n async_fibre_init_dispatcher(&nctx->dispatcher);\n nctx->currjob = NULL;\n nctx->blocked = 0;\n if (!CRYPTO_THREAD_set_local(&ctxkey, nctx))\n goto err;\n return nctx;\nerr:\n OPENSSL_free(nctx);\n return NULL;\n}']
650
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/conf/conf_mod.c/#L352
static int module_init(CONF_MODULE *pmod, char *name, char *value, const CONF *cnf) { int ret = 1; int init_called = 0; CONF_IMODULE *imod = NULL; imod = OPENSSL_malloc(sizeof(*imod)); if (imod == NULL) goto err; imod->pmod = pmod; imod->name = OPENSSL_strdup(name); imod->value = OPENSSL_strdup(value); imod->usr_data = NULL; if (!imod->name || !imod->value) goto memerr; if (pmod->init) { ret = pmod->init(imod, cnf); init_called = 1; if (ret <= 0) goto err; } if (initialized_modules == NULL) { initialized_modules = sk_CONF_IMODULE_new_null(); if (!initialized_modules) { CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); goto err; } } if (!sk_CONF_IMODULE_push(initialized_modules, imod)) { CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE); goto err; } pmod->links++; return ret; err: if (pmod->finish && init_called) pmod->finish(imod); memerr: if (imod) { OPENSSL_free(imod->name); OPENSSL_free(imod->value); OPENSSL_free(imod); } return -1; }
['static int module_init(CONF_MODULE *pmod, char *name, char *value,\n const CONF *cnf)\n{\n int ret = 1;\n int init_called = 0;\n CONF_IMODULE *imod = NULL;\n imod = OPENSSL_malloc(sizeof(*imod));\n if (imod == NULL)\n goto err;\n imod->pmod = pmod;\n imod->name = OPENSSL_strdup(name);\n imod->value = OPENSSL_strdup(value);\n imod->usr_data = NULL;\n if (!imod->name || !imod->value)\n goto memerr;\n if (pmod->init) {\n ret = pmod->init(imod, cnf);\n init_called = 1;\n if (ret <= 0)\n goto err;\n }\n if (initialized_modules == NULL) {\n initialized_modules = sk_CONF_IMODULE_new_null();\n if (!initialized_modules) {\n CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n }\n if (!sk_CONF_IMODULE_push(initialized_modules, imod)) {\n CONFerr(CONF_F_MODULE_INIT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n pmod->links++;\n return ret;\n err:\n if (pmod->finish && init_called)\n pmod->finish(imod);\n memerr:\n if (imod) {\n OPENSSL_free(imod->name);\n OPENSSL_free(imod->value);\n OPENSSL_free(imod);\n }\n return -1;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'char *CRYPTO_strdup(const char *str, const char* file, int line)\n{\n char *ret;\n if (str == NULL)\n return NULL;\n ret = CRYPTO_malloc(strlen(str) + 1, file, line);\n if (ret != NULL)\n strcpy(ret, str);\n return ret;\n}']
651
1
https://github.com/apache/httpd/blob/6ae08b2207bc7812b8e8196fbb5fbd81609606cc/modules/slotmem/mod_slotmem_shm.c/#L195
static apr_status_t restore_slotmem(sharedslotdesc_t *desc, const char *storename, apr_size_t size, apr_pool_t *pool) { apr_file_t *fp; apr_status_t rv = APR_ENOTIMPL; void *ptr = (char *)desc + AP_SLOTMEM_OFFSET; apr_size_t dsize = size - AP_SLOTMEM_OFFSET; apr_size_t nbytes = dsize; unsigned char digest[APR_MD5_DIGESTSIZE]; unsigned char digest2[APR_MD5_DIGESTSIZE]; char desc_buf[AP_SLOTMEM_OFFSET]; ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02335) "restoring %s", storename); if (storename) { rv = apr_file_open(&fp, storename, APR_READ | APR_WRITE, APR_OS_DEFAULT, pool); if (rv == APR_SUCCESS) { rv = apr_file_read(fp, ptr, &nbytes); if ((rv == APR_SUCCESS || rv == APR_EOF) && nbytes == dsize) { rv = APR_SUCCESS; if (apr_file_eof(fp) != APR_EOF) { apr_size_t ds = APR_MD5_DIGESTSIZE; rv = apr_file_read(fp, digest, &ds); if ((rv == APR_SUCCESS || rv == APR_EOF) && ds == APR_MD5_DIGESTSIZE) { apr_md5(digest2, ptr, nbytes); if (memcmp(digest, digest2, APR_MD5_DIGESTSIZE)) { rv = APR_EMISMATCH; } else if (apr_file_eof(fp) != APR_EOF) { nbytes = sizeof(desc_buf); rv = apr_file_read(fp, desc_buf, &nbytes); if ((rv == APR_SUCCESS || rv == APR_EOF) && nbytes == sizeof(desc_buf)) { if (memcmp(desc, desc_buf, nbytes)) { rv = APR_EMISMATCH; } else { rv = APR_SUCCESS; } } else if (rv == APR_SUCCESS || rv == APR_EOF) { rv = APR_INCOMPLETE; } } else { rv = APR_EOF; } } else if (rv == APR_SUCCESS || rv == APR_EOF) { rv = APR_INCOMPLETE; } } else { rv = APR_EOF; } if (rv == APR_EMISMATCH) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02551) "persisted slotmem md5/desc mismatch"); } else if (rv == APR_EOF) { ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(02552) "persisted slotmem at EOF... bypassing md5/desc match check " "(old persist file?)"); rv = APR_SUCCESS; } } else if (rv == APR_SUCCESS || rv == APR_EOF) { rv = APR_INCOMPLETE; } if (rv == APR_INCOMPLETE) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02553) "persisted slotmem read had unexpected size"); } apr_file_close(fp); } } return rv; }
['static apr_status_t slotmem_create(ap_slotmem_instance_t **new,\n const char *name, apr_size_t item_size,\n unsigned int item_num,\n ap_slotmem_type_t type, apr_pool_t *pool)\n{\n int fbased = 1;\n int restored = 0;\n char *ptr;\n sharedslotdesc_t *desc;\n ap_slotmem_instance_t *res;\n ap_slotmem_instance_t *next = globallistmem;\n const char *fname, *pname = NULL;\n apr_shm_t *shm;\n apr_size_t basesize = (item_size * item_num);\n apr_size_t size = AP_SLOTMEM_OFFSET + AP_UNSIGNEDINT_OFFSET +\n (item_num * sizeof(char)) + basesize;\n int persist = (type & AP_SLOTMEM_TYPE_PERSIST) != 0;\n int generation = 0;\n apr_status_t rv;\n apr_pool_t *p;\n *new = NULL;\n ap_mpm_query(AP_MPMQ_GENERATION, &generation);\n if (slotmem_filenames(pool, name, &fname, persist ? &pname : NULL)) {\n if (next) {\n ap_slotmem_instance_t *prev = NULL;\n for (;;) {\n if (strcmp(next->name, name) == 0) {\n *new = next;\n if (!check_slotmem(next, size, item_size, item_num)) {\n apr_shm_destroy(next->shm);\n apr_shm_remove(next->fname, pool);\n fname = apr_psprintf(pool, "%s.%u", fname,\n (apr_uint32_t)generation);\n persist = 0;\n next = next->next;\n if (prev) {\n prev->next = next;\n }\n else {\n globallistmem = next;\n }\n if (next) {\n continue;\n }\n next = prev;\n break;\n }\n ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02603)\n "create found %s in global list", next->fname);\n return APR_SUCCESS;\n }\n if (!next->next) {\n break;\n }\n prev = next;\n next = next->next;\n }\n }\n ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02602)\n "create didn\'t find %s in global list", name);\n }\n else {\n fbased = 0;\n fname = "none";\n }\n ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02300)\n "create %s: %"APR_SIZE_T_FMT"/%u", name, item_size, item_num);\n {\n if (fbased) {\n if (is_child_process()) {\n rv = slotmem_attach_shm(&shm, &fname, generation, gpool);\n }\n else {\n apr_shm_remove(fname, pool);\n rv = apr_shm_create(&shm, size, fname, gpool);\n }\n }\n else {\n rv = apr_shm_create(&shm, size, NULL, pool);\n }\n ap_log_error(APLOG_MARK, rv == APR_SUCCESS ? APLOG_DEBUG : APLOG_ERR,\n rv, ap_server_conf, APLOGNO(02611)\n "create: apr_shm_%s(%s) %s",\n fbased && is_child_process() ? "attach" : "create",\n fname, rv == APR_SUCCESS ? "succeeded" : "failed");\n if (rv != APR_SUCCESS) {\n return rv;\n }\n desc = (sharedslotdesc_t *)apr_shm_baseaddr_get(shm);\n memset(desc, 0, size);\n desc->size = item_size;\n desc->num = item_num;\n desc->type = type;\n if (persist) {\n rv = restore_slotmem(desc, pname, size, pool);\n if (rv == APR_SUCCESS) {\n restored = 1;\n }\n else {\n ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf,\n APLOGNO(02554) "could not restore %s", fname);\n memset((char *)desc + AP_SLOTMEM_OFFSET, 0,\n size - AP_SLOTMEM_OFFSET);\n }\n }\n }\n p = fbased ? gpool : pool;\n ptr = (char *)desc + AP_SLOTMEM_OFFSET;\n res = *new;\n if (res == NULL) {\n res = apr_pcalloc(p, sizeof(ap_slotmem_instance_t));\n res->name = apr_pstrdup(p, name);\n res->pname = apr_pstrdup(p, pname);\n *new = res;\n }\n res->fname = apr_pstrdup(p, fname);\n res->fbased = fbased;\n res->shm = shm;\n res->persist = (void *)ptr;\n res->num_free = (unsigned int *)ptr;\n ptr += AP_UNSIGNEDINT_OFFSET;\n if (!restored) {\n *res->num_free = item_num;\n }\n res->base = (void *)ptr;\n res->desc = desc;\n res->pool = pool;\n res->next = NULL;\n res->inuse = ptr + basesize;\n if (fbased) {\n if (globallistmem == NULL) {\n globallistmem = res;\n }\n else {\n next->next = res;\n }\n }\n return APR_SUCCESS;\n}', 'static apr_status_t restore_slotmem(sharedslotdesc_t *desc,\n const char *storename, apr_size_t size,\n apr_pool_t *pool)\n{\n apr_file_t *fp;\n apr_status_t rv = APR_ENOTIMPL;\n void *ptr = (char *)desc + AP_SLOTMEM_OFFSET;\n apr_size_t dsize = size - AP_SLOTMEM_OFFSET;\n apr_size_t nbytes = dsize;\n unsigned char digest[APR_MD5_DIGESTSIZE];\n unsigned char digest2[APR_MD5_DIGESTSIZE];\n char desc_buf[AP_SLOTMEM_OFFSET];\n ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02335)\n "restoring %s", storename);\n if (storename) {\n rv = apr_file_open(&fp, storename, APR_READ | APR_WRITE, APR_OS_DEFAULT,\n pool);\n if (rv == APR_SUCCESS) {\n rv = apr_file_read(fp, ptr, &nbytes);\n if ((rv == APR_SUCCESS || rv == APR_EOF) && nbytes == dsize) {\n rv = APR_SUCCESS;\n if (apr_file_eof(fp) != APR_EOF) {\n apr_size_t ds = APR_MD5_DIGESTSIZE;\n rv = apr_file_read(fp, digest, &ds);\n if ((rv == APR_SUCCESS || rv == APR_EOF)\n && ds == APR_MD5_DIGESTSIZE) {\n apr_md5(digest2, ptr, nbytes);\n if (memcmp(digest, digest2, APR_MD5_DIGESTSIZE)) {\n rv = APR_EMISMATCH;\n }\n else if (apr_file_eof(fp) != APR_EOF) {\n nbytes = sizeof(desc_buf);\n rv = apr_file_read(fp, desc_buf, &nbytes);\n if ((rv == APR_SUCCESS || rv == APR_EOF)\n && nbytes == sizeof(desc_buf)) {\n if (memcmp(desc, desc_buf, nbytes)) {\n rv = APR_EMISMATCH;\n }\n else {\n rv = APR_SUCCESS;\n }\n }\n else if (rv == APR_SUCCESS || rv == APR_EOF) {\n rv = APR_INCOMPLETE;\n }\n }\n else {\n rv = APR_EOF;\n }\n }\n else if (rv == APR_SUCCESS || rv == APR_EOF) {\n rv = APR_INCOMPLETE;\n }\n }\n else {\n rv = APR_EOF;\n }\n if (rv == APR_EMISMATCH) {\n ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02551)\n "persisted slotmem md5/desc mismatch");\n }\n else if (rv == APR_EOF) {\n ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, APLOGNO(02552)\n "persisted slotmem at EOF... bypassing md5/desc match check "\n "(old persist file?)");\n rv = APR_SUCCESS;\n }\n }\n else if (rv == APR_SUCCESS || rv == APR_EOF) {\n rv = APR_INCOMPLETE;\n }\n if (rv == APR_INCOMPLETE) {\n ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, APLOGNO(02553)\n "persisted slotmem read had unexpected size");\n }\n apr_file_close(fp);\n }\n }\n return rv;\n}']
652
0
https://github.com/openssl/openssl/blob/11d01d371f67a9cacfeccb1078669c595d65002f/crypto/buffer/buffer.c/#L135
int BUF_MEM_grow_clean(BUF_MEM *str, size_t len) { char *ret; size_t n; if (str->length >= len) { memset(&str->data[len],0,str->length-len); str->length=len; return(len); } if (str->max >= len) { memset(&str->data[str->length],0,len-str->length); str->length=len; return(len); } n=(len+3)/3*4; if (str->data == NULL) ret=OPENSSL_malloc(n); else ret=OPENSSL_realloc_clean(str->data,str->max,n); if (ret == NULL) { BUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE); len=0; } else { str->data=ret; str->max=n; memset(&str->data[str->length],0,len-str->length); str->length=len; } return(len); }
['int dtls1_connect(SSL *s)\n\t{\n\tBUF_MEM *buf=NULL;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tlong num1;\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tint ret= -1;\n\tint new_state,state,skip=0;;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch(s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\t\ts->state=SSL_ST_CONNECT;\n\t\t\ts->ctx->stats.sess_connect_renegotiate++;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_CONNECT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_CONNECT:\n\t\tcase SSL_ST_OK|SSL_ST_CONNECT:\n\t\t\ts->server=0;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version & 0xff00 ) != (DTLS1_VERSION & 0xff00))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_DTLS1_CONNECT, ERR_R_INTERNAL_ERROR);\n\t\t\t\tret = -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_CONNECT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\tbuf=NULL;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s)) { ret= -1; goto end; }\n\t\t\tif (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }\n\t\t\ts->state=SSL3_ST_CW_CLNT_HELLO_A;\n\t\t\ts->ctx->stats.sess_connect++;\n\t\t\ts->init_num=0;\n\t\t\tmemset(s->s3->client_random,0,sizeof(s->s3->client_random));\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CLNT_HELLO_A:\n\t\tcase SSL3_ST_CW_CLNT_HELLO_B:\n\t\t\ts->shutdown=0;\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tret=dtls1_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif ( s->d1->send_cookie)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_FLUSH;\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_SRVR_HELLO_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CR_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tif (s->bbio != s->wbio)\n\t\t\t\ts->wbio=BIO_push(s->bbio,s->wbio);\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_HELLO_A:\n\t\tcase SSL3_ST_CR_SRVR_HELLO_B:\n\t\t\tret=ssl3_get_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (s->hit)\n\t\t\t\t\ts->state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:\n\t\tcase DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:\n\t\t\tret = dtls1_get_hello_verify(s);\n\t\t\tif ( ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif ( s->d1->send_cookie)\n\t\t\t\ts->state=SSL3_ST_CW_CLNT_HELLO_A;\n\t\t\telse\n\t\t\t\ts->state = SSL3_ST_CR_CERT_A;\n\t\t\ts->init_num = 0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_A:\n\t\tcase SSL3_ST_CR_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL))\n\t\t\t\t{\n\t\t\t\tret=ssl3_get_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_CR_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_KEY_EXCH_A:\n\t\tcase SSL3_ST_CR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!ssl3_check_cert_and_algorithm(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_REQ_A:\n\t\tcase SSL3_ST_CR_CERT_REQ_B:\n\t\t\tret=ssl3_get_certificate_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_SRVR_DONE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_DONE_A:\n\t\tcase SSL3_ST_CR_SRVR_DONE_B:\n\t\t\tret=ssl3_get_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req)\n\t\t\t\ts->state=SSL3_ST_CW_CERT_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_A:\n\t\tcase SSL3_ST_CW_CERT_B:\n\t\tcase SSL3_ST_CW_CERT_C:\n\t\tcase SSL3_ST_CW_CERT_D:\n\t\t\tret=dtls1_send_client_certificate(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_KEY_EXCH_A:\n\t\tcase SSL3_ST_CW_KEY_EXCH_B:\n\t\t\tret=dtls1_send_client_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req == 1)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CERT_VRFY_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\t\ts->s3->change_cipher_spec=0;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_VRFY_A:\n\t\tcase SSL3_ST_CW_CERT_VRFY_B:\n\t\t\tret=dtls1_send_client_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\ts->s3->change_cipher_spec=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CHANGE_A:\n\t\tcase SSL3_ST_CW_CHANGE_B:\n\t\t\tret=dtls1_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n#ifdef OPENSSL_NO_COMP\n\t\t\ts->session->compress_meth=0;\n#else\n\t\t\tif (s->s3->tmp.new_compression == NULL)\n\t\t\t\ts->session->compress_meth=0;\n\t\t\telse\n\t\t\t\ts->session->compress_meth=\n\t\t\t\t\ts->s3->tmp.new_compression->id;\n#endif\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_CLIENT_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdtls1_reset_seq_numbers(s, SSL3_CC_WRITE);\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_FINISHED_A:\n\t\tcase SSL3_ST_CW_FINISHED_B:\n\t\t\tret=dtls1_send_finished(s,\n\t\t\t\tSSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->client_finished_label,\n\t\t\t\ts->method->ssl3_enc->client_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FLUSH;\n\t\t\ts->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;\n\t\t\tif (s->hit)\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\t\tif (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)\n\t\t\t\t\t{\n\t\t\t\t\ts->state=SSL_ST_OK;\n\t\t\t\t\ts->s3->flags|=SSL3_FLAGS_POP_BUFFER;\n\t\t\t\t\ts->s3->delay_buf_pop_ret=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tmemset (s->s3->client_random,0,sizeof(s->s3->client_random));\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_FINISHED_A:\n\t\tcase SSL3_ST_CR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,\n\t\t\t\tSSL3_ST_CR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\telse\n\t\t\t\ts->state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n#if 0\n\t\t\tif (s->init_buf != NULL)\n\t\t\t\t{\n\t\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\t\ts->init_buf=NULL;\n\t\t\t\t}\n#endif\n\t\t\tif (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))\n\t\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\ts->new_session=0;\n\t\t\tssl_update_cache(s,SSL_SESS_CACHE_CLIENT);\n\t\t\tif (s->hit) s->ctx->stats.sess_hit++;\n\t\t\tret=1;\n\t\t\ts->handshake_func=dtls1_connect;\n\t\t\ts->ctx->stats.sess_connect_good++;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\ts->d1->handshake_read_seq = 0;\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_DTLS1_CONNECT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_CONNECT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (buf != NULL)\n\t\tBUF_MEM_free(buf);\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_CONNECT_EXIT,ret);\n\treturn(ret);\n\t}', 'int dtls1_send_client_certificate(SSL *s)\n\t{\n\tX509 *x509=NULL;\n\tEVP_PKEY *pkey=NULL;\n\tint i;\n\tunsigned long l;\n\tif (s->state ==\tSSL3_ST_CW_CERT_A)\n\t\t{\n\t\tif ((s->cert == NULL) ||\n\t\t\t(s->cert->key->x509 == NULL) ||\n\t\t\t(s->cert->key->privatekey == NULL))\n\t\t\ts->state=SSL3_ST_CW_CERT_B;\n\t\telse\n\t\t\ts->state=SSL3_ST_CW_CERT_C;\n\t\t}\n\tif (s->state == SSL3_ST_CW_CERT_B)\n\t\t{\n\t\ti=0;\n\t\tif (s->ctx->client_cert_cb != NULL)\n\t\t\ti=s->ctx->client_cert_cb(s,&(x509),&(pkey));\n\t\tif (i < 0)\n\t\t\t{\n\t\t\ts->rwstate=SSL_X509_LOOKUP;\n\t\t\treturn(-1);\n\t\t\t}\n\t\ts->rwstate=SSL_NOTHING;\n\t\tif ((i == 1) && (pkey != NULL) && (x509 != NULL))\n\t\t\t{\n\t\t\ts->state=SSL3_ST_CW_CERT_B;\n\t\t\tif (\t!SSL_use_certificate(s,x509) ||\n\t\t\t\t!SSL_use_PrivateKey(s,pkey))\n\t\t\t\ti=0;\n\t\t\t}\n\t\telse if (i == 1)\n\t\t\t{\n\t\t\ti=0;\n\t\t\tSSLerr(SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);\n\t\t\t}\n\t\tif (x509 != NULL) X509_free(x509);\n\t\tif (pkey != NULL) EVP_PKEY_free(pkey);\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tif (s->version == SSL3_VERSION)\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.cert_req=0;\n\t\t\t\tssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);\n\t\t\t\treturn(1);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.cert_req=2;\n\t\t\t\t}\n\t\t\t}\n\t\ts->state=SSL3_ST_CW_CERT_C;\n\t\t}\n\tif (s->state == SSL3_ST_CW_CERT_C)\n\t\t{\n\t\ts->state=SSL3_ST_CW_CERT_D;\n\t\tl=dtls1_output_cert_chain(s,\n\t\t\t(s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);\n\t\ts->init_num=(int)l;\n\t\ts->init_off=0;\n\t\tdtls1_buffer_message(s, 0);\n\t\t}\n\treturn(dtls1_do_write(s,SSL3_RT_HANDSHAKE));\n\t}', 'unsigned long dtls1_output_cert_chain(SSL *s, X509 *x)\n\t{\n\tunsigned char *p;\n\tint n,i;\n\tunsigned long l= 3 + DTLS1_HM_HEADER_LENGTH;\n\tBUF_MEM *buf;\n\tX509_STORE_CTX xs_ctx;\n\tX509_OBJECT obj;\n\tbuf=s->init_buf;\n\tif (!BUF_MEM_grow_clean(buf,10))\n\t\t{\n\t\tSSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);\n\t\treturn(0);\n\t\t}\n\tif (x != NULL)\n\t\t{\n\t\tif(!X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB);\n\t\t\treturn(0);\n\t\t\t}\n\t\tfor (;;)\n\t\t\t{\n\t\t\tn=i2d_X509(x,NULL);\n\t\t\tif (!BUF_MEM_grow_clean(buf,(n+l+3)))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);\n\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\tp=(unsigned char *)&(buf->data[l]);\n\t\t\tl2n3(n,p);\n\t\t\ti2d_X509(x,&p);\n\t\t\tl+=n+3;\n\t\t\tif (X509_NAME_cmp(X509_get_subject_name(x),\n\t\t\t\tX509_get_issuer_name(x)) == 0) break;\n\t\t\ti=X509_STORE_get_by_subject(&xs_ctx,X509_LU_X509,\n\t\t\t\tX509_get_issuer_name(x),&obj);\n\t\t\tif (i <= 0) break;\n\t\t\tx=obj.data.x509;\n\t\t\tX509_free(x);\n\t\t\t}\n\t\tX509_STORE_CTX_cleanup(&xs_ctx);\n\t\t}\n\tif (s->ctx->extra_certs != NULL)\n\tfor (i=0; i<sk_X509_num(s->ctx->extra_certs); i++)\n\t\t{\n\t\tx=sk_X509_value(s->ctx->extra_certs,i);\n\t\tn=i2d_X509(x,NULL);\n\t\tif (!BUF_MEM_grow_clean(buf,(n+l+3)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_DTLS1_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB);\n\t\t\treturn(0);\n\t\t\t}\n\t\tp=(unsigned char *)&(buf->data[l]);\n\t\tl2n3(n,p);\n\t\ti2d_X509(x,&p);\n\t\tl+=n+3;\n\t\t}\n\tl-= (3 + DTLS1_HM_HEADER_LENGTH);\n\tp=(unsigned char *)&(buf->data[DTLS1_HM_HEADER_LENGTH]);\n\tl2n3(l,p);\n\tl+=3;\n\tp=(unsigned char *)&(buf->data[0]);\n\tp = dtls1_set_message_header(s, p, SSL3_MT_CERTIFICATE, l, 0, l);\n\tl+=DTLS1_HM_HEADER_LENGTH;\n\treturn(l);\n\t}', 'int BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n\t{\n\tchar *ret;\n\tsize_t n;\n\tif (str->length >= len)\n\t\t{\n\t\tmemset(&str->data[len],0,str->length-len);\n\t\tstr->length=len;\n\t\treturn(len);\n\t\t}\n\tif (str->max >= len)\n\t\t{\n\t\tmemset(&str->data[str->length],0,len-str->length);\n\t\tstr->length=len;\n\t\treturn(len);\n\t\t}\n\tn=(len+3)/3*4;\n\tif (str->data == NULL)\n\t\tret=OPENSSL_malloc(n);\n\telse\n\t\tret=OPENSSL_realloc_clean(str->data,str->max,n);\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE);\n\t\tlen=0;\n\t\t}\n\telse\n\t\t{\n\t\tstr->data=ret;\n\t\tstr->max=n;\n\t\tmemset(&str->data[str->length],0,len-str->length);\n\t\tstr->length=len;\n\t\t}\n\treturn(len);\n\t}']
653
0
https://github.com/libav/libav/blob/ae3822bca16f1cdb2460a35b16f8ef636a04314e/libavcodec/imgconvert.c/#L460
static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap, int width, int height) { uint8_t *src_m1, *src_0, *src_p1, *src_p2; int y; uint8_t *buf; buf = av_malloc(width); src_m1 = src1; memcpy(buf,src_m1,width); src_0=&src_m1[src_wrap]; src_p1=&src_0[src_wrap]; src_p2=&src_p1[src_wrap]; for(y=0;y<(height-2);y+=2) { deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width); src_m1 = src_p1; src_0 = src_p2; src_p1 += 2*src_wrap; src_p2 += 2*src_wrap; } deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width); av_free(buf); }
['static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,\n int width, int height)\n{\n uint8_t *src_m1, *src_0, *src_p1, *src_p2;\n int y;\n uint8_t *buf;\n buf = av_malloc(width);\n src_m1 = src1;\n memcpy(buf,src_m1,width);\n src_0=&src_m1[src_wrap];\n src_p1=&src_0[src_wrap];\n src_p2=&src_p1[src_wrap];\n for(y=0;y<(height-2);y+=2) {\n deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);\n src_m1 = src_p1;\n src_0 = src_p2;\n src_p1 += 2*src_wrap;\n src_p2 += 2*src_wrap;\n }\n deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);\n av_free(buf);\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}']
654
0
https://github.com/libav/libav/blob/1232a1647ab27e024a3baf4d01d40c8d08d6ced9/libavfilter/vf_pad.c/#L146
static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; PadContext *s = ctx->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); uint8_t rgba_color[4]; int ret, is_packed_rgba; double var_values[VARS_NB], res; char *expr; s->hsub = pix_desc->log2_chroma_w; s->vsub = pix_desc->log2_chroma_h; var_values[VAR_PI] = M_PI; var_values[VAR_PHI] = M_PHI; var_values[VAR_E] = M_E; var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; var_values[VAR_A] = (double) inlink->w / inlink->h; var_values[VAR_HSUB] = 1<<s->hsub; var_values[VAR_VSUB] = 1<<s->vsub; av_expr_parse_and_eval(&res, (expr = s->w_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx); s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; av_expr_parse_and_eval(&res, (expr = s->x_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx); s->x = var_values[VAR_X] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->y = var_values[VAR_Y] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->x = var_values[VAR_X] = res; if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) { av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n"); return AVERROR(EINVAL); } if (!s->w) s->w = inlink->w; if (!s->h) s->h = inlink->h; s->w &= ~((1 << s->hsub) - 1); s->h &= ~((1 << s->vsub) - 1); s->x &= ~((1 << s->hsub) - 1); s->y &= ~((1 << s->vsub) - 1); s->in_w = inlink->w & ~((1 << s->hsub) - 1); s->in_h = inlink->h & ~((1 << s->vsub) - 1); memcpy(rgba_color, s->color, sizeof(rgba_color)); ff_fill_line_with_color(s->line, s->line_step, s->w, s->color, inlink->format, rgba_color, &is_packed_rgba, NULL); av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n", inlink->w, inlink->h, s->w, s->h, s->x, s->y, s->color[0], s->color[1], s->color[2], s->color[3], is_packed_rgba ? "rgba" : "yuva"); if (s->x < 0 || s->y < 0 || s->w <= 0 || s->h <= 0 || (unsigned)s->x + (unsigned)inlink->w > s->w || (unsigned)s->y + (unsigned)inlink->h > s->h) { av_log(ctx, AV_LOG_ERROR, "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n", s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h); return AVERROR(EINVAL); } return 0; eval_fail: av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }
['static int config_input(AVFilterLink *inlink)\n{\n AVFilterContext *ctx = inlink->dst;\n PadContext *s = ctx->priv;\n const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format);\n uint8_t rgba_color[4];\n int ret, is_packed_rgba;\n double var_values[VARS_NB], res;\n char *expr;\n s->hsub = pix_desc->log2_chroma_w;\n s->vsub = pix_desc->log2_chroma_h;\n var_values[VAR_PI] = M_PI;\n var_values[VAR_PHI] = M_PHI;\n var_values[VAR_E] = M_E;\n var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w;\n var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;\n var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;\n var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;\n var_values[VAR_A] = (double) inlink->w / inlink->h;\n var_values[VAR_HSUB] = 1<<s->hsub;\n var_values[VAR_VSUB] = 1<<s->vsub;\n av_expr_parse_and_eval(&res, (expr = s->w_expr),\n var_names, var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx);\n s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;\n if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr),\n var_names, var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)\n goto eval_fail;\n s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res;\n if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr),\n var_names, var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)\n goto eval_fail;\n s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res;\n av_expr_parse_and_eval(&res, (expr = s->x_expr),\n var_names, var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx);\n s->x = var_values[VAR_X] = res;\n if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr),\n var_names, var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)\n goto eval_fail;\n s->y = var_values[VAR_Y] = res;\n if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr),\n var_names, var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0)\n goto eval_fail;\n s->x = var_values[VAR_X] = res;\n if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) {\n av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\\n");\n return AVERROR(EINVAL);\n }\n if (!s->w)\n s->w = inlink->w;\n if (!s->h)\n s->h = inlink->h;\n s->w &= ~((1 << s->hsub) - 1);\n s->h &= ~((1 << s->vsub) - 1);\n s->x &= ~((1 << s->hsub) - 1);\n s->y &= ~((1 << s->vsub) - 1);\n s->in_w = inlink->w & ~((1 << s->hsub) - 1);\n s->in_h = inlink->h & ~((1 << s->vsub) - 1);\n memcpy(rgba_color, s->color, sizeof(rgba_color));\n ff_fill_line_with_color(s->line, s->line_step, s->w, s->color,\n inlink->format, rgba_color, &is_packed_rgba, NULL);\n av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\\n",\n inlink->w, inlink->h, s->w, s->h, s->x, s->y,\n s->color[0], s->color[1], s->color[2], s->color[3],\n is_packed_rgba ? "rgba" : "yuva");\n if (s->x < 0 || s->y < 0 ||\n s->w <= 0 || s->h <= 0 ||\n (unsigned)s->x + (unsigned)inlink->w > s->w ||\n (unsigned)s->y + (unsigned)inlink->h > s->h) {\n av_log(ctx, AV_LOG_ERROR,\n "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\\n",\n s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h);\n return AVERROR(EINVAL);\n }\n return 0;\neval_fail:\n av_log(NULL, AV_LOG_ERROR,\n "Error when evaluating the expression \'%s\'\\n", expr);\n return ret;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
655
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/md5/md5_dgst.c/#L133
void MD5_Update(MD5_CTX *c, const void *_data, unsigned long len) { register const unsigned char *data=_data; register ULONG *p; int sw,sc; ULONG l; if (len == 0) return; l=(c->Nl+(len<<3))&0xffffffffL; if (l < c->Nl) c->Nh++; c->Nh+=(len>>29); c->Nl=l; if (c->num != 0) { p=c->data; sw=c->num>>2; sc=c->num&0x03; if ((c->num+len) >= MD5_CBLOCK) { l= p[sw]; p_c2l(data,l,sc); p[sw++]=l; for (; sw<MD5_LBLOCK; sw++) { c2l(data,l); p[sw]=l; } len-=(MD5_CBLOCK-c->num); md5_block(c,p,64); c->num=0; } else { int ew,ec; c->num+=(int)len; if ((sc+len) < 4) { l= p[sw]; p_c2l_p(data,l,sc,len); p[sw]=l; } else { ew=(c->num>>2); ec=(c->num&0x03); l= p[sw]; p_c2l(data,l,sc); p[sw++]=l; for (; sw < ew; sw++) { c2l(data,l); p[sw]=l; } if (ec) { c2l_p(data,l,ec); p[sw]=l; } } return; } } #ifdef L_ENDIAN if ((((unsigned long)data)%sizeof(ULONG)) == 0) { sw=(int)len/MD5_CBLOCK; if (sw > 0) { sw*=MD5_CBLOCK; md5_block(c,(ULONG *)data,sw); data+=sw; len-=sw; } } #endif p=c->data; while (len >= MD5_CBLOCK) { #if defined(L_ENDIAN) || defined(B_ENDIAN) if (p != (unsigned long *)data) memcpy(p,data,MD5_CBLOCK); data+=MD5_CBLOCK; #ifdef B_ENDIAN for (sw=(MD5_LBLOCK/4); sw; sw--) { Endian_Reverse32(p[0]); Endian_Reverse32(p[1]); Endian_Reverse32(p[2]); Endian_Reverse32(p[3]); p+=4; } #endif #else for (sw=(MD5_LBLOCK/4); sw; sw--) { c2l(data,l); *(p++)=l; c2l(data,l); *(p++)=l; c2l(data,l); *(p++)=l; c2l(data,l); *(p++)=l; } #endif p=c->data; md5_block(c,p,64); len-=MD5_CBLOCK; } sc=(int)len; c->num=sc; if (sc) { sw=sc>>2; #ifdef L_ENDIAN p[sw]=0; memcpy(p,data,sc); #else sc&=0x03; for ( ; sw; sw--) { c2l(data,l); *(p++)=l; } c2l_p(data,l,sc); *p=l; #endif } }
['static void ssleay_rand_seed(const void *buf, int num)\n\t{\n\tint i,j,k,st_idx,st_num;\n\tMD_CTX m;\n#ifdef NORAND\n\treturn;\n#endif\n\tCRYPTO_w_lock(CRYPTO_LOCK_RAND);\n\tst_idx=state_index;\n\tst_num=state_num;\n\tstate_index=(state_index+num);\n\tif (state_index >= STATE_SIZE)\n\t\t{\n\t\tstate_index%=STATE_SIZE;\n\t\tstate_num=STATE_SIZE;\n\t\t}\n\telse if (state_num < STATE_SIZE)\n\t\t{\n\t\tif (state_index > state_num)\n\t\t\tstate_num=state_index;\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_RAND);\n\tfor (i=0; i<num; i+=MD_DIGEST_LENGTH)\n\t\t{\n\t\tj=(num-i);\n\t\tj=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;\n\t\tMD_Init(&m);\n\t\tMD_Update(&m,md,MD_DIGEST_LENGTH);\n\t\tk=(st_idx+j)-STATE_SIZE;\n\t\tif (k > 0)\n\t\t\t{\n\t\t\tMD_Update(&m,&(state[st_idx]),j-k);\n\t\t\tMD_Update(&m,&(state[0]),k);\n\t\t\t}\n\t\telse\n\t\t\tMD_Update(&m,&(state[st_idx]),j);\n\t\tMD_Update(&m,buf,j);\n\t\tMD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));\n\t\tMD_Final(md,&m);\n\t\tmd_count[1]++;\n\t\tbuf=(const char *)buf + j;\n\t\tfor (k=0; k<j; k++)\n\t\t\t{\n\t\t\tstate[st_idx++]^=md[k];\n\t\t\tif (st_idx >= STATE_SIZE)\n\t\t\t\t{\n\t\t\t\tst_idx=0;\n\t\t\t\tst_num=STATE_SIZE;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tmemset((char *)&m,0,sizeof(m));\n\t}', 'void MD5_Update(MD5_CTX *c, const void *_data, unsigned long len)\n\t{\n\tregister const unsigned char *data=_data;\n\tregister ULONG *p;\n\tint sw,sc;\n\tULONG l;\n\tif (len == 0) return;\n\tl=(c->Nl+(len<<3))&0xffffffffL;\n\tif (l < c->Nl)\n\t\tc->Nh++;\n\tc->Nh+=(len>>29);\n\tc->Nl=l;\n\tif (c->num != 0)\n\t\t{\n\t\tp=c->data;\n\t\tsw=c->num>>2;\n\t\tsc=c->num&0x03;\n\t\tif ((c->num+len) >= MD5_CBLOCK)\n\t\t\t{\n\t\t\tl= p[sw];\n\t\t\tp_c2l(data,l,sc);\n\t\t\tp[sw++]=l;\n\t\t\tfor (; sw<MD5_LBLOCK; sw++)\n\t\t\t\t{\n\t\t\t\tc2l(data,l);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\tlen-=(MD5_CBLOCK-c->num);\n\t\t\tmd5_block(c,p,64);\n\t\t\tc->num=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint ew,ec;\n\t\t\tc->num+=(int)len;\n\t\t\tif ((sc+len) < 4)\n\t\t\t\t{\n\t\t\t\tl= p[sw];\n\t\t\t\tp_c2l_p(data,l,sc,len);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tew=(c->num>>2);\n\t\t\t\tec=(c->num&0x03);\n\t\t\t\tl= p[sw];\n\t\t\t\tp_c2l(data,l,sc);\n\t\t\t\tp[sw++]=l;\n\t\t\t\tfor (; sw < ew; sw++)\n\t\t\t\t\t{ c2l(data,l); p[sw]=l; }\n\t\t\t\tif (ec)\n\t\t\t\t\t{\n\t\t\t\t\tc2l_p(data,l,ec);\n\t\t\t\t\tp[sw]=l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\treturn;\n\t\t\t}\n\t\t}\n#ifdef L_ENDIAN\n\tif ((((unsigned long)data)%sizeof(ULONG)) == 0)\n\t\t{\n\t\tsw=(int)len/MD5_CBLOCK;\n\t\tif (sw > 0)\n\t\t\t{\n\t\t\tsw*=MD5_CBLOCK;\n\t\t\tmd5_block(c,(ULONG *)data,sw);\n\t\t\tdata+=sw;\n\t\t\tlen-=sw;\n\t\t\t}\n\t\t}\n#endif\n\tp=c->data;\n\twhile (len >= MD5_CBLOCK)\n\t\t{\n#if defined(L_ENDIAN) || defined(B_ENDIAN)\n\t\tif (p != (unsigned long *)data)\n\t\t\tmemcpy(p,data,MD5_CBLOCK);\n\t\tdata+=MD5_CBLOCK;\n#ifdef B_ENDIAN\n\t\tfor (sw=(MD5_LBLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tEndian_Reverse32(p[0]);\n\t\t\tEndian_Reverse32(p[1]);\n\t\t\tEndian_Reverse32(p[2]);\n\t\t\tEndian_Reverse32(p[3]);\n\t\t\tp+=4;\n\t\t\t}\n#endif\n#else\n\t\tfor (sw=(MD5_LBLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\tc2l(data,l); *(p++)=l;\n\t\t\t}\n#endif\n\t\tp=c->data;\n\t\tmd5_block(c,p,64);\n\t\tlen-=MD5_CBLOCK;\n\t\t}\n\tsc=(int)len;\n\tc->num=sc;\n\tif (sc)\n\t\t{\n\t\tsw=sc>>2;\n#ifdef L_ENDIAN\n\t\tp[sw]=0;\n\t\tmemcpy(p,data,sc);\n#else\n\t\tsc&=0x03;\n\t\tfor ( ; sw; sw--)\n\t\t\t{ c2l(data,l); *(p++)=l; }\n\t\tc2l_p(data,l,sc);\n\t\t*p=l;\n#endif\n\t\t}\n\t}']
656
0
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_word.c/#L154
int BN_sub_word(BIGNUM *a, BN_ULONG w) { int i; if (a->neg) { a->neg=0; i=BN_add_word(a,w); a->neg=1; return(i); } w&=BN_MASK2; if ((a->top == 1) && (a->d[0] < w)) { a->d[0]=w-a->d[0]; a->neg=1; return(1); } i=0; for (;;) { if (a->d[i] >= w) { a->d[i]-=w; break; } else { a->d[i]=(a->d[i]-w)&BN_MASK2; i++; w=1; } } if ((a->d[i] == 0) && (i == (a->top-1))) a->top--; return(1); }
["int BN_dec2bn(BIGNUM **bn, char *a)\n\t{\n\tBIGNUM *ret=NULL;\n\tBN_ULONG l=0;\n\tint neg=0,i,j;\n\tint num;\n\tif ((a == NULL) || (*a == '\\0')) return(0);\n\tif (*a == '-') { neg=1; a++; }\n\tfor (i=0; isdigit(a[i]); i++)\n\t\t;\n\tnum=i+neg;\n\tif (bn == NULL) return(num);\n\tif (*bn == NULL)\n\t\t{\n\t\tif ((ret=BN_new()) == NULL) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tret= *bn;\n\t\tBN_zero(ret);\n\t\t}\n\tif (bn_expand(ret,i*4) == NULL) goto err;\n\tj=BN_DEC_NUM-(i%BN_DEC_NUM);\n\tif (j == BN_DEC_NUM) j=0;\n\tl=0;\n\twhile (*a)\n\t\t{\n\t\tl*=10;\n\t\tl+= *a-'0';\n\t\ta++;\n\t\tif (++j == BN_DEC_NUM)\n\t\t\t{\n\t\t\tBN_mul_word(ret,BN_DEC_CONV);\n\t\t\tBN_add_word(ret,l);\n\t\t\tl=0;\n\t\t\tj=0;\n\t\t\t}\n\t\t}\n\tret->neg=neg;\n\tbn_fix_top(ret);\n\t*bn=ret;\n\treturn(num);\nerr:\n\tif (*bn == NULL) BN_free(ret);\n\treturn(0);\n\t}", 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tif (a->neg)\n\t\t{\n\t\ta->neg=0;\n\t\ti=BN_sub_word(a,w);\n\t\tif (!BN_is_zero(a))\n\t\t\ta->neg=1;\n\t\treturn(i);\n\t\t}\n\tw&=BN_MASK2;\n\tif (bn_wexpand(a,a->top+1) == NULL) return(0);\n\ti=0;\n\tfor (;;)\n\t\t{\n\t\tl=(a->d[i]+(BN_ULONG)w)&BN_MASK2;\n\t\ta->d[i]=l;\n\t\tif (w > l)\n\t\t\tw=1;\n\t\telse\n\t\t\tbreak;\n\t\ti++;\n\t\t}\n\tif (i >= a->top)\n\t\ta->top++;\n\treturn(1);\n\t}', 'int BN_sub_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i;\n\tif (a->neg)\n\t\t{\n\t\ta->neg=0;\n\t\ti=BN_add_word(a,w);\n\t\ta->neg=1;\n\t\treturn(i);\n\t\t}\n\tw&=BN_MASK2;\n\tif ((a->top == 1) && (a->d[0] < w))\n\t\t{\n\t\ta->d[0]=w-a->d[0];\n\t\ta->neg=1;\n\t\treturn(1);\n\t\t}\n\ti=0;\n\tfor (;;)\n\t\t{\n\t\tif (a->d[i] >= w)\n\t\t\t{\n\t\t\ta->d[i]-=w;\n\t\t\tbreak;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ta->d[i]=(a->d[i]-w)&BN_MASK2;\n\t\t\ti++;\n\t\t\tw=1;\n\t\t\t}\n\t\t}\n\tif ((a->d[i] == 0) && (i == (a->top-1)))\n\t\ta->top--;\n\treturn(1);\n\t}']
657
0
https://github.com/openssl/openssl/blob/507db4c5313288d55eeb8434b0111201ba363b28/crypto/evp/p5_crpt2.c/#L139
int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, const unsigned char *salt, int saltlen, int iter, const EVP_MD *digest, int keylen, unsigned char *out) { unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4]; int cplen, j, k, tkeylen, mdlen; unsigned long i = 1; HMAC_CTX *hctx_tpl = NULL, *hctx = NULL; mdlen = EVP_MD_size(digest); if (mdlen < 0) return 0; hctx_tpl = HMAC_CTX_new(); if (hctx_tpl == NULL) return 0; p = out; tkeylen = keylen; if (!pass) passlen = 0; else if (passlen == -1) passlen = strlen(pass); if (!HMAC_Init_ex(hctx_tpl, pass, passlen, digest, NULL)) { HMAC_CTX_free(hctx_tpl); return 0; } hctx = HMAC_CTX_new(); if (hctx == NULL) { HMAC_CTX_free(hctx_tpl); return 0; } while (tkeylen) { if (tkeylen > mdlen) cplen = mdlen; else cplen = tkeylen; itmp[0] = (unsigned char)((i >> 24) & 0xff); itmp[1] = (unsigned char)((i >> 16) & 0xff); itmp[2] = (unsigned char)((i >> 8) & 0xff); itmp[3] = (unsigned char)(i & 0xff); if (!HMAC_CTX_copy(hctx, hctx_tpl)) { HMAC_CTX_free(hctx); HMAC_CTX_free(hctx_tpl); return 0; } if (!HMAC_Update(hctx, salt, saltlen) || !HMAC_Update(hctx, itmp, 4) || !HMAC_Final(hctx, digtmp, NULL)) { HMAC_CTX_free(hctx); HMAC_CTX_free(hctx_tpl); return 0; } HMAC_CTX_reset(hctx); memcpy(p, digtmp, cplen); for (j = 1; j < iter; j++) { if (!HMAC_CTX_copy(hctx, hctx_tpl)) { HMAC_CTX_free(hctx); HMAC_CTX_free(hctx_tpl); return 0; } if (!HMAC_Update(hctx, digtmp, mdlen) || !HMAC_Final(hctx, digtmp, NULL)) { HMAC_CTX_free(hctx); HMAC_CTX_free(hctx_tpl); return 0; } HMAC_CTX_reset(hctx); for (k = 0; k < cplen; k++) p[k] ^= digtmp[k]; } tkeylen -= cplen; i++; p += cplen; } HMAC_CTX_free(hctx); HMAC_CTX_free(hctx_tpl); # ifdef DEBUG_PKCS5V2 fprintf(stderr, "Password:\n"); h__dump(pass, passlen); fprintf(stderr, "Salt:\n"); h__dump(salt, saltlen); fprintf(stderr, "Iteration count %d\n", iter); fprintf(stderr, "Key:\n"); h__dump(out, keylen); # endif return 1; }
['int PKCS5_v2_PBKDF2_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass,\n int passlen, ASN1_TYPE *param,\n const EVP_CIPHER *c, const EVP_MD *md, int en_de)\n{\n unsigned char *salt, key[EVP_MAX_KEY_LENGTH];\n int saltlen, iter;\n int rv = 0;\n unsigned int keylen = 0;\n int prf_nid, hmac_md_nid;\n PBKDF2PARAM *kdf = NULL;\n const EVP_MD *prfmd;\n if (EVP_CIPHER_CTX_cipher(ctx) == NULL) {\n EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_NO_CIPHER_SET);\n goto err;\n }\n keylen = EVP_CIPHER_CTX_key_length(ctx);\n OPENSSL_assert(keylen <= sizeof key);\n kdf = ASN1_TYPE_unpack_sequence(ASN1_ITEM_rptr(PBKDF2PARAM), param);\n if (kdf == NULL) {\n EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_DECODE_ERROR);\n goto err;\n }\n keylen = EVP_CIPHER_CTX_key_length(ctx);\n if (kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != (int)keylen)) {\n EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_KEYLENGTH);\n goto err;\n }\n if (kdf->prf)\n prf_nid = OBJ_obj2nid(kdf->prf->algorithm);\n else\n prf_nid = NID_hmacWithSHA1;\n if (!EVP_PBE_find(EVP_PBE_TYPE_PRF, prf_nid, NULL, &hmac_md_nid, 0)) {\n EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);\n goto err;\n }\n prfmd = EVP_get_digestbynid(hmac_md_nid);\n if (prfmd == NULL) {\n EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_PRF);\n goto err;\n }\n if (kdf->salt->type != V_ASN1_OCTET_STRING) {\n EVPerr(EVP_F_PKCS5_V2_PBKDF2_KEYIVGEN, EVP_R_UNSUPPORTED_SALT_TYPE);\n goto err;\n }\n salt = kdf->salt->value.octet_string->data;\n saltlen = kdf->salt->value.octet_string->length;\n iter = ASN1_INTEGER_get(kdf->iter);\n if (!PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, prfmd,\n keylen, key))\n goto err;\n rv = EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de);\n err:\n OPENSSL_cleanse(key, keylen);\n PBKDF2PARAM_free(kdf);\n return rv;\n}', 'long ASN1_INTEGER_get(const ASN1_INTEGER *a)\n{\n int i;\n int64_t r;\n if (a == NULL)\n return 0;\n i = ASN1_INTEGER_get_int64(&r, a);\n if (i == 0)\n return -1;\n if (r > LONG_MAX || r < LONG_MIN)\n return -1;\n return (long)r;\n}', 'int PKCS5_PBKDF2_HMAC(const char *pass, int passlen,\n const unsigned char *salt, int saltlen, int iter,\n const EVP_MD *digest, int keylen, unsigned char *out)\n{\n unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4];\n int cplen, j, k, tkeylen, mdlen;\n unsigned long i = 1;\n HMAC_CTX *hctx_tpl = NULL, *hctx = NULL;\n mdlen = EVP_MD_size(digest);\n if (mdlen < 0)\n return 0;\n hctx_tpl = HMAC_CTX_new();\n if (hctx_tpl == NULL)\n return 0;\n p = out;\n tkeylen = keylen;\n if (!pass)\n passlen = 0;\n else if (passlen == -1)\n passlen = strlen(pass);\n if (!HMAC_Init_ex(hctx_tpl, pass, passlen, digest, NULL)) {\n HMAC_CTX_free(hctx_tpl);\n return 0;\n }\n hctx = HMAC_CTX_new();\n if (hctx == NULL) {\n HMAC_CTX_free(hctx_tpl);\n return 0;\n }\n while (tkeylen) {\n if (tkeylen > mdlen)\n cplen = mdlen;\n else\n cplen = tkeylen;\n itmp[0] = (unsigned char)((i >> 24) & 0xff);\n itmp[1] = (unsigned char)((i >> 16) & 0xff);\n itmp[2] = (unsigned char)((i >> 8) & 0xff);\n itmp[3] = (unsigned char)(i & 0xff);\n if (!HMAC_CTX_copy(hctx, hctx_tpl)) {\n HMAC_CTX_free(hctx);\n HMAC_CTX_free(hctx_tpl);\n return 0;\n }\n if (!HMAC_Update(hctx, salt, saltlen)\n || !HMAC_Update(hctx, itmp, 4)\n || !HMAC_Final(hctx, digtmp, NULL)) {\n HMAC_CTX_free(hctx);\n HMAC_CTX_free(hctx_tpl);\n return 0;\n }\n HMAC_CTX_reset(hctx);\n memcpy(p, digtmp, cplen);\n for (j = 1; j < iter; j++) {\n if (!HMAC_CTX_copy(hctx, hctx_tpl)) {\n HMAC_CTX_free(hctx);\n HMAC_CTX_free(hctx_tpl);\n return 0;\n }\n if (!HMAC_Update(hctx, digtmp, mdlen)\n || !HMAC_Final(hctx, digtmp, NULL)) {\n HMAC_CTX_free(hctx);\n HMAC_CTX_free(hctx_tpl);\n return 0;\n }\n HMAC_CTX_reset(hctx);\n for (k = 0; k < cplen; k++)\n p[k] ^= digtmp[k];\n }\n tkeylen -= cplen;\n i++;\n p += cplen;\n }\n HMAC_CTX_free(hctx);\n HMAC_CTX_free(hctx_tpl);\n# ifdef DEBUG_PKCS5V2\n fprintf(stderr, "Password:\\n");\n h__dump(pass, passlen);\n fprintf(stderr, "Salt:\\n");\n h__dump(salt, saltlen);\n fprintf(stderr, "Iteration count %d\\n", iter);\n fprintf(stderr, "Key:\\n");\n h__dump(out, keylen);\n# endif\n return 1;\n}']
658
0
https://github.com/openssl/openssl/blob/de3955f66225e42bfae710c50b51c98aa4616ac1/crypto/ocsp/ocsp_ht.c/#L80
OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline) { OCSP_REQ_CTX *rctx = OPENSSL_zalloc(sizeof(*rctx)); if (rctx == NULL) return NULL; rctx->state = OHS_ERROR; rctx->max_resp_len = OCSP_MAX_RESP_LENGTH; rctx->mem = BIO_new(BIO_s_mem()); rctx->io = io; if (maxline > 0) rctx->iobuflen = maxline; else rctx->iobuflen = OCSP_MAX_LINE_LEN; rctx->iobuf = OPENSSL_malloc(rctx->iobuflen); if (rctx->iobuf == NULL || rctx->mem == NULL) { OCSP_REQ_CTX_free(rctx); return NULL; } return rctx; }
['OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline)\n{\n OCSP_REQ_CTX *rctx = OPENSSL_zalloc(sizeof(*rctx));\n if (rctx == NULL)\n return NULL;\n rctx->state = OHS_ERROR;\n rctx->max_resp_len = OCSP_MAX_RESP_LENGTH;\n rctx->mem = BIO_new(BIO_s_mem());\n rctx->io = io;\n if (maxline > 0)\n rctx->iobuflen = maxline;\n else\n rctx->iobuflen = OCSP_MAX_LINE_LEN;\n rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);\n if (rctx->iobuf == NULL || rctx->mem == NULL) {\n OCSP_REQ_CTX_free(rctx);\n return NULL;\n }\n return rctx;\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#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'const BIO_METHOD *BIO_s_mem(void)\n{\n return &mem_method;\n}', 'void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx)\n{\n if (!rctx)\n return;\n BIO_free(rctx->mem);\n OPENSSL_free(rctx->iobuf);\n OPENSSL_free(rctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
659
0
https://github.com/libav/libav/blob/7ff018c1cb43a5fe5ee2049d325cdd785852067a/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static void rice_decompress(ALACContext *alac, int32_t *output_buffer,\n int nb_samples, int bps, int rice_history_mult)\n{\n int i;\n unsigned int history = alac->rice_initial_history;\n int sign_modifier = 0;\n for (i = 0; i < nb_samples; i++) {\n int k;\n unsigned int x;\n k = av_log2((history >> 9) + 3);\n k = FFMIN(k, alac->rice_limit);\n x = decode_scalar(&alac->bc, k, bps);\n x += sign_modifier;\n sign_modifier = 0;\n output_buffer[i] = (x >> 1) ^ -(x & 1);\n if (x > 0xffff)\n history = 0xffff;\n else\n history += x * rice_history_mult -\n ((history * rice_history_mult) >> 9);\n if ((history < 128) && (i + 1 < nb_samples)) {\n int block_size;\n k = 7 - av_log2(history) + ((history + 16) >> 6);\n k = FFMIN(k, alac->rice_limit);\n block_size = decode_scalar(&alac->bc, k, 16);\n if (block_size > 0) {\n if (block_size >= nb_samples - i) {\n av_log(alac->avctx, AV_LOG_ERROR,\n "invalid zero block size of %d %d %d\\n", block_size,\n nb_samples, i);\n block_size = nb_samples - i - 1;\n }\n memset(&output_buffer[i + 1], 0,\n block_size * sizeof(*output_buffer));\n i += block_size;\n }\n if (block_size <= 0xffff)\n sign_modifier = 1;\n history = 0;\n }\n }\n}', 'static inline unsigned int decode_scalar(BitstreamContext *bc, int k, int bps)\n{\n unsigned int x = get_unary_0_9(bc);\n if (x > 8) {\n x = bitstream_read(bc, bps);\n } else if (k != 1) {\n int extrabits = bitstream_peek(bc, k);\n x = (x << k) - x;\n if (extrabits > 1) {\n x += extrabits - 1;\n bitstream_skip(bc, k);\n } else\n bitstream_skip(bc, k - 1);\n }\n return x;\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}']
660
0
https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/mpegaudiodec.c/#L865
static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr) { register const MPA_INT *w, *w2, *p; int j; OUT_INT *samples2; #if CONFIG_FLOAT float sum, sum2; #elif FRAC_BITS <= 15 int sum, sum2; #else int64_t sum, sum2; #endif memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf)); samples2 = samples + 31 * incr; w = window; w2 = window + 31; sum = *dither_state; p = synth_buf + 16; SUM8(MACS, sum, w, p); p = synth_buf + 48; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); samples += incr; w++; for(j=1;j<16;j++) { sum2 = 0; p = synth_buf + 16 + j; SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); p = synth_buf + 48 - j; SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); *samples = round_sample(&sum); samples += incr; sum += sum2; *samples2 = round_sample(&sum); samples2 -= incr; w++; w2--; } p = synth_buf + 32; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); *dither_state= sum; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n#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 apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}']
661
0
https://github.com/libav/libav/blob/fd7f59639c43f0ab6b83ad2c1ceccafc553d7845/libavformat/rmdec.c/#L523
static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb, RMDemuxContext *rm, RMStream *vst, AVPacket *pkt, int len) { int hdr, seq, pic_num, len2, pos; int type; hdr = get_byte(pb); len--; type = hdr >> 6; if(type != 3){ seq = get_byte(pb); len--; } if(type != 1){ len2 = get_num(pb, &len); pos = get_num(pb, &len); pic_num = get_byte(pb); len--; } if(len<0) return -1; rm->remaining_len = len; if(type&1){ if(type == 3) len= len2; if(rm->remaining_len < len) return -1; rm->remaining_len -= len; if(av_new_packet(pkt, len + 9) < 0) return AVERROR(EIO); pkt->data[0] = 0; AV_WL32(pkt->data + 1, 1); AV_WL32(pkt->data + 5, 0); get_buffer(pb, pkt->data + 9, len); return 0; } if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){ vst->slices = ((hdr & 0x3F) << 1) + 1; vst->videobufsize = len2 + 8*vst->slices + 1; av_free_packet(&vst->pkt); if(av_new_packet(&vst->pkt, vst->videobufsize) < 0) return AVERROR(ENOMEM); vst->videobufpos = 8*vst->slices + 1; vst->cur_slice = 0; vst->curpic_num = pic_num; vst->pktpos = url_ftell(pb); } if(type == 2) len = FFMIN(len, pos); if(++vst->cur_slice > vst->slices) return 1; AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1); AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1); if(vst->videobufpos + len > vst->videobufsize) return 1; if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len) return AVERROR(EIO); vst->videobufpos += len; rm->remaining_len-= len; if(type == 2 || (vst->videobufpos) == vst->videobufsize){ vst->pkt.data[0] = vst->cur_slice-1; *pkt= vst->pkt; vst->pkt.data= NULL; vst->pkt.size= 0; if(vst->slices != vst->cur_slice) memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices, vst->videobufpos - 1 - 8*vst->slices); pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices); pkt->pts = AV_NOPTS_VALUE; pkt->pos = vst->pktpos; return 0; } return 1; }
['static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,\n RMDemuxContext *rm, RMStream *vst,\n AVPacket *pkt, int len)\n{\n int hdr, seq, pic_num, len2, pos;\n int type;\n hdr = get_byte(pb); len--;\n type = hdr >> 6;\n if(type != 3){\n seq = get_byte(pb); len--;\n }\n if(type != 1){\n len2 = get_num(pb, &len);\n pos = get_num(pb, &len);\n pic_num = get_byte(pb); len--;\n }\n if(len<0)\n return -1;\n rm->remaining_len = len;\n if(type&1){\n if(type == 3)\n len= len2;\n if(rm->remaining_len < len)\n return -1;\n rm->remaining_len -= len;\n if(av_new_packet(pkt, len + 9) < 0)\n return AVERROR(EIO);\n pkt->data[0] = 0;\n AV_WL32(pkt->data + 1, 1);\n AV_WL32(pkt->data + 5, 0);\n get_buffer(pb, pkt->data + 9, len);\n return 0;\n }\n if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){\n vst->slices = ((hdr & 0x3F) << 1) + 1;\n vst->videobufsize = len2 + 8*vst->slices + 1;\n av_free_packet(&vst->pkt);\n if(av_new_packet(&vst->pkt, vst->videobufsize) < 0)\n return AVERROR(ENOMEM);\n vst->videobufpos = 8*vst->slices + 1;\n vst->cur_slice = 0;\n vst->curpic_num = pic_num;\n vst->pktpos = url_ftell(pb);\n }\n if(type == 2)\n len = FFMIN(len, pos);\n if(++vst->cur_slice > vst->slices)\n return 1;\n AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1);\n AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);\n if(vst->videobufpos + len > vst->videobufsize)\n return 1;\n if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len)\n return AVERROR(EIO);\n vst->videobufpos += len;\n rm->remaining_len-= len;\n if(type == 2 || (vst->videobufpos) == vst->videobufsize){\n vst->pkt.data[0] = vst->cur_slice-1;\n *pkt= vst->pkt;\n vst->pkt.data= NULL;\n vst->pkt.size= 0;\n if(vst->slices != vst->cur_slice)\n memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices,\n vst->videobufpos - 1 - 8*vst->slices);\n pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices);\n pkt->pts = AV_NOPTS_VALUE;\n pkt->pos = vst->pktpos;\n return 0;\n }\n return 1;\n}']
662
0
https://github.com/openssl/openssl/blob/ddc6a5c8f5900959bdbdfee79e1625a3f7808acd/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)\n{\n BIGNUM *t;\n int i;\n if ((nbits < 1024) || (nbits & 0xff))\n return 0;\n nbits >>= 1;\n if (!BN_priv_rand(Xp, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n for (i = 0; i < 1000; i++) {\n if (!BN_priv_rand(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto err;\n BN_sub(t, Xp, Xq);\n if (BN_num_bits(t) > (nbits - 100))\n break;\n }\n BN_CTX_end(ctx);\n if (i < 1000)\n return 1;\n return 0;\n err:\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(PRIVATE, rnd, bits, top, bottom);\n}', 'static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int b, ret = 0, bit, bytes, mask;\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n b = flag == NORMAL ? RAND_bytes(buf, bytes) : RAND_priv_bytes(buf, bytes);\n if (b <= 0)\n goto err;\n if (flag == TESTING) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
663
0
https://github.com/libav/libav/blob/2a21adf924c6019b13f632802dadda3914a2c93f/libavformat/rtpdec.c/#L409
static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) { int au_headers_length, au_header_size, i; GetBitContext getbitcontext; RTPPayloadData *infos; infos = s->rtp_payload_data; if (infos == NULL) return -1; au_headers_length = AV_RB16(buf); if (au_headers_length > RTP_MAX_PACKET_LENGTH) return -1; infos->au_headers_length_bytes = (au_headers_length + 7) / 8; buf += 2; init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8); au_header_size = infos->sizelength + infos->indexlength; if (au_header_size <= 0 || (au_headers_length % au_header_size != 0)) return -1; infos->nb_au_headers = au_headers_length / au_header_size; infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); infos->au_headers[0].size = 0; infos->au_headers[0].index = 0; for (i = 0; i < infos->nb_au_headers; ++i) { infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength); infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength); } infos->nb_au_headers = 1; return 0; }
['static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf)\n{\n int au_headers_length, au_header_size, i;\n GetBitContext getbitcontext;\n RTPPayloadData *infos;\n infos = s->rtp_payload_data;\n if (infos == NULL)\n return -1;\n au_headers_length = AV_RB16(buf);\n if (au_headers_length > RTP_MAX_PACKET_LENGTH)\n return -1;\n infos->au_headers_length_bytes = (au_headers_length + 7) / 8;\n buf += 2;\n init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8);\n au_header_size = infos->sizelength + infos->indexlength;\n if (au_header_size <= 0 || (au_headers_length % au_header_size != 0))\n return -1;\n infos->nb_au_headers = au_headers_length / au_header_size;\n infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers);\n infos->au_headers[0].size = 0;\n infos->au_headers[0].index = 0;\n for (i = 0; i < infos->nb_au_headers; ++i) {\n infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength);\n infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength);\n }\n infos->nb_au_headers = 1;\n return 0;\n}', 'static av_always_inline av_const uint16_t bswap_16(uint16_t x)\n{\n x= (x>>8) | (x<<8);\n return x;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = 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}']
664
0
https://github.com/openssl/openssl/blob/260a16f33682a819414fcba6161708a5e6bdff50/crypto/lhash/lhash.c/#L157
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 early_data_skip_helper(int testtype, int idx)\n{\n SSL_CTX *cctx = NULL, *sctx = NULL;\n SSL *clientssl = NULL, *serverssl = NULL;\n int testresult = 0;\n SSL_SESSION *sess = NULL;\n unsigned char buf[20];\n size_t readbytes, written;\n if (!TEST_true(setupearly_data_test(&cctx, &sctx, &clientssl,\n &serverssl, &sess, idx)))\n goto end;\n if (testtype == 1 || testtype == 2) {\n if (!TEST_true(SSL_set1_groups_list(serverssl, "P-256")))\n goto end;\n } else if (idx == 2) {\n srvid = "Dummy Identity";\n } else {\n if (!TEST_true(SSL_SESSION_set_time(sess, (long)(time(NULL) - 20))))\n goto end;\n }\n if (testtype == 3\n && !TEST_true(SSL_set_recv_max_early_data(serverssl, 0)))\n goto end;\n if (!TEST_true(SSL_write_early_data(clientssl, MSG1, strlen(MSG1),\n &written))\n || !TEST_size_t_eq(written, strlen(MSG1)))\n goto end;\n if (!TEST_int_eq(SSL_read_early_data(serverssl, buf, sizeof(buf),\n &readbytes),\n SSL_READ_EARLY_DATA_FINISH)\n || !TEST_size_t_eq(readbytes, 0)\n || !TEST_int_eq(SSL_get_early_data_status(serverssl),\n SSL_EARLY_DATA_REJECTED))\n goto end;\n switch (testtype) {\n case 0:\n break;\n case 1:\n if (!TEST_false(SSL_write_ex(clientssl, MSG2, strlen(MSG2), &written))\n || !TEST_false(SSL_read_ex(serverssl, buf, sizeof(buf),\n &readbytes)))\n goto end;\n break;\n case 2:\n {\n BIO *wbio = SSL_get_wbio(clientssl);\n const unsigned char bad_early_data[] = {\n 0x17, 0x03, 0x03, 0x00, 0x01, 0x00\n };\n if (!TEST_false(SSL_write_ex(clientssl, MSG2, strlen(MSG2),\n &written)))\n goto end;\n if (!TEST_true(BIO_write_ex(wbio, bad_early_data,\n sizeof(bad_early_data), &written)))\n goto end;\n }\n case 3:\n if (!TEST_false(SSL_read_ex(serverssl, buf, sizeof(buf), &readbytes))\n || !TEST_int_eq(SSL_get_error(serverssl, 0), SSL_ERROR_SSL))\n goto end;\n testresult = 1;\n goto end;\n default:\n TEST_error("Invalid test type");\n goto end;\n }\n if (!TEST_true(SSL_write_ex(clientssl, MSG2, strlen(MSG2), &written))\n || !TEST_size_t_eq(written, strlen(MSG2))\n || !TEST_int_eq(SSL_get_early_data_status(clientssl),\n SSL_EARLY_DATA_REJECTED)\n || !TEST_true(SSL_read_ex(serverssl, buf, sizeof(buf), &readbytes))\n || !TEST_mem_eq(buf, readbytes, MSG2, strlen(MSG2)))\n goto end;\n testresult = 1;\n end:\n SSL_SESSION_free(clientpsk);\n SSL_SESSION_free(serverpsk);\n clientpsk = serverpsk = NULL;\n SSL_SESSION_free(sess);\n SSL_free(serverssl);\n SSL_free(clientssl);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'static int setupearly_data_test(SSL_CTX **cctx, SSL_CTX **sctx, SSL **clientssl,\n SSL **serverssl, SSL_SESSION **sess, int idx)\n{\n if (*sctx == NULL\n && !TEST_true(create_ssl_ctx_pair(TLS_server_method(),\n TLS_client_method(),\n TLS1_VERSION, 0,\n sctx, cctx, cert, privkey)))\n return 0;\n if (!TEST_true(SSL_CTX_set_max_early_data(*sctx, SSL3_RT_MAX_PLAIN_LENGTH)))\n return 0;\n if (idx == 1) {\n SSL_CTX_set_read_ahead(*cctx, 1);\n SSL_CTX_set_read_ahead(*sctx, 1);\n } else if (idx == 2) {\n SSL_CTX_set_psk_use_session_callback(*cctx, use_session_cb);\n SSL_CTX_set_psk_find_session_callback(*sctx, find_session_cb);\n use_session_cb_cnt = 0;\n find_session_cb_cnt = 0;\n srvid = pskid;\n }\n if (!TEST_true(create_ssl_objects(*sctx, *cctx, serverssl, clientssl,\n NULL, NULL)))\n return 0;\n if (idx == 1\n && !TEST_true(SSL_set_tlsext_host_name(*clientssl, "localhost")))\n return 0;\n if (idx == 2) {\n clientpsk = create_a_psk(*clientssl);\n if (!TEST_ptr(clientpsk)\n || !TEST_true(SSL_SESSION_set_max_early_data(clientpsk,\n 0x100))\n || !TEST_true(SSL_SESSION_up_ref(clientpsk))) {\n SSL_SESSION_free(clientpsk);\n clientpsk = NULL;\n return 0;\n }\n serverpsk = clientpsk;\n if (sess != NULL) {\n if (!TEST_true(SSL_SESSION_up_ref(clientpsk))) {\n SSL_SESSION_free(clientpsk);\n SSL_SESSION_free(serverpsk);\n clientpsk = serverpsk = NULL;\n return 0;\n }\n *sess = clientpsk;\n }\n return 1;\n }\n if (sess == NULL)\n return 1;\n if (!TEST_true(create_ssl_connection(*serverssl, *clientssl,\n SSL_ERROR_NONE)))\n return 0;\n *sess = SSL_get1_session(*clientssl);\n SSL_shutdown(*clientssl);\n SSL_shutdown(*serverssl);\n SSL_free(*serverssl);\n SSL_free(*clientssl);\n *serverssl = *clientssl = NULL;\n if (!TEST_true(create_ssl_objects(*sctx, *cctx, serverssl,\n clientssl, NULL, NULL))\n || !TEST_true(SSL_set_session(*clientssl, *sess)))\n return 0;\n return 1;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', '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)) != NULL) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, r);\n SSL_SESSION_list_remove(ctx, r);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n if (ret)\n SSL_SESSION_free(r);\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}']
665
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/x509/x509_att.c/#L253
X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, const ASN1_OBJECT *obj, int atrtype, const void *data, int len) { X509_ATTRIBUTE *ret; if ((attr == NULL) || (*attr == NULL)) { if ((ret = X509_ATTRIBUTE_new()) == NULL) { X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ, ERR_R_MALLOC_FAILURE); return (NULL); } } else ret = *attr; if (!X509_ATTRIBUTE_set1_object(ret, obj)) goto err; if (!X509_ATTRIBUTE_set1_data(ret, atrtype, data, len)) goto err; if ((attr != NULL) && (*attr == NULL)) *attr = ret; return (ret); err: if ((attr == NULL) || (ret != *attr)) X509_ATTRIBUTE_free(ret); return (NULL); }
['X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,\n const ASN1_OBJECT *obj,\n int atrtype, const void *data,\n int len)\n{\n X509_ATTRIBUTE *ret;\n if ((attr == NULL) || (*attr == NULL)) {\n if ((ret = X509_ATTRIBUTE_new()) == NULL) {\n X509err(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ,\n ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n } else\n ret = *attr;\n if (!X509_ATTRIBUTE_set1_object(ret, obj))\n goto err;\n if (!X509_ATTRIBUTE_set1_data(ret, atrtype, data, len))\n goto err;\n if ((attr != NULL) && (*attr == NULL))\n *attr = ret;\n return (ret);\n err:\n if ((attr == NULL) || (ret != *attr))\n X509_ATTRIBUTE_free(ret);\n return (NULL);\n}', 'int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj)\n{\n if ((attr == NULL) || (obj == NULL))\n return (0);\n ASN1_OBJECT_free(attr->object);\n attr->object = OBJ_dup(obj);\n return (1);\n}', 'ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)\n{\n ASN1_OBJECT *r;\n int i;\n char *ln = NULL, *sn = NULL;\n unsigned char *data = NULL;\n if (o == NULL)\n return (NULL);\n if (!(o->flags & ASN1_OBJECT_FLAG_DYNAMIC))\n return ((ASN1_OBJECT *)o);\n r = ASN1_OBJECT_new();\n if (r == NULL) {\n OBJerr(OBJ_F_OBJ_DUP, ERR_R_ASN1_LIB);\n return (NULL);\n }\n data = OPENSSL_malloc(o->length);\n if (data == NULL)\n goto err;\n if (o->data != NULL)\n memcpy(data, o->data, o->length);\n r->data = data;\n r->length = o->length;\n r->nid = o->nid;\n r->ln = r->sn = NULL;\n if (o->ln != NULL) {\n i = strlen(o->ln) + 1;\n ln = OPENSSL_malloc(i);\n if (ln == NULL)\n goto err;\n memcpy(ln, o->ln, i);\n r->ln = ln;\n }\n if (o->sn != NULL) {\n i = strlen(o->sn) + 1;\n sn = OPENSSL_malloc(i);\n if (sn == NULL)\n goto err;\n memcpy(sn, o->sn, i);\n r->sn = sn;\n }\n r->flags = o->flags | (ASN1_OBJECT_FLAG_DYNAMIC |\n ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |\n ASN1_OBJECT_FLAG_DYNAMIC_DATA);\n return (r);\n err:\n OBJerr(OBJ_F_OBJ_DUP, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(ln);\n OPENSSL_free(sn);\n OPENSSL_free(data);\n OPENSSL_free(r);\n return (NULL);\n}', 'ASN1_OBJECT *ASN1_OBJECT_new(void)\n{\n ASN1_OBJECT *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_OBJECT_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = ASN1_OBJECT_FLAG_DYNAMIC;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}']
666
0
https://github.com/openssl/openssl/blob/828d04afe40caaa19cff23b0ba04008a4313e30e/crypto/dso/dso_lib.c/#L206
DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags) { DSO *ret; int allocated = 0; if (dso == NULL) { ret = DSO_new_method(meth); if (ret == NULL) { DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE); goto err; } allocated = 1; if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) { DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED); goto err; } } else ret = dso; if (ret->filename != NULL) { DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED); goto err; } if (filename != NULL) if (!DSO_set_filename(ret, filename)) { DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED); goto err; } filename = ret->filename; if (filename == NULL) { DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME); goto err; } if (ret->meth->dso_load == NULL) { DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED); goto err; } if (!ret->meth->dso_load(ret)) { DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED); goto err; } return (ret); err: if (allocated) DSO_free(ret); return (NULL); }
['DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)\n{\n DSO *ret;\n int allocated = 0;\n if (dso == NULL) {\n ret = DSO_new_method(meth);\n if (ret == NULL) {\n DSOerr(DSO_F_DSO_LOAD, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n allocated = 1;\n if (DSO_ctrl(ret, DSO_CTRL_SET_FLAGS, flags, NULL) < 0) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_CTRL_FAILED);\n goto err;\n }\n } else\n ret = dso;\n if (ret->filename != NULL) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_DSO_ALREADY_LOADED);\n goto err;\n }\n if (filename != NULL)\n if (!DSO_set_filename(ret, filename)) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_SET_FILENAME_FAILED);\n goto err;\n }\n filename = ret->filename;\n if (filename == NULL) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_NO_FILENAME);\n goto err;\n }\n if (ret->meth->dso_load == NULL) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_UNSUPPORTED);\n goto err;\n }\n if (!ret->meth->dso_load(ret)) {\n DSOerr(DSO_F_DSO_LOAD, DSO_R_LOAD_FAILED);\n goto err;\n }\n return (ret);\n err:\n if (allocated)\n DSO_free(ret);\n return (NULL);\n}', 'long DSO_ctrl(DSO *dso, int cmd, long larg, void *parg)\n{\n if (dso == NULL) {\n DSOerr(DSO_F_DSO_CTRL, ERR_R_PASSED_NULL_PARAMETER);\n return (-1);\n }\n switch (cmd) {\n case DSO_CTRL_GET_FLAGS:\n return dso->flags;\n case DSO_CTRL_SET_FLAGS:\n dso->flags = (int)larg;\n return (0);\n case DSO_CTRL_OR_FLAGS:\n dso->flags |= (int)larg;\n return (0);\n default:\n break;\n }\n if ((dso->meth == NULL) || (dso->meth->dso_ctrl == NULL)) {\n DSOerr(DSO_F_DSO_CTRL, DSO_R_UNSUPPORTED);\n return (-1);\n }\n return (dso->meth->dso_ctrl(dso, cmd, larg, parg));\n}', 'int DSO_set_filename(DSO *dso, const char *filename)\n{\n char *copied;\n if ((dso == NULL) || (filename == NULL)) {\n DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_PASSED_NULL_PARAMETER);\n return (0);\n }\n if (dso->loaded_filename) {\n DSOerr(DSO_F_DSO_SET_FILENAME, DSO_R_DSO_ALREADY_LOADED);\n return (0);\n }\n copied = OPENSSL_strdup(filename);\n if (copied == NULL) {\n DSOerr(DSO_F_DSO_SET_FILENAME, ERR_R_MALLOC_FAILURE);\n return (0);\n }\n OPENSSL_free(dso->filename);\n dso->filename = copied;\n return (1);\n}', 'char *CRYPTO_strdup(const char *str, const char* file, int line)\n{\n char *ret;\n size_t size;\n if (str == NULL)\n return NULL;\n size = strlen(str) + 1;\n ret = CRYPTO_malloc(size, file, line);\n if (ret != NULL)\n memcpy(ret, str, size);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
667
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); }
['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_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n 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}']
668
0
https://github.com/openssl/openssl/blob/21e8bbf2904e5ac8709d46424e18f8ba6e813b06/crypto/asn1/t_x509.c/#L414
int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm) { char *v; int gmt=0; int i; int y=0,M=0,d=0,h=0,m=0,s=0; char *f = NULL; int f_len = 0; i=tm->length; v=(char *)tm->data; if (i < 12) goto err; if (v[i-1] == 'Z') gmt=1; for (i=0; i<12; i++) if ((v[i] > '9') || (v[i] < '0')) goto err; y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0'); M= (v[4]-'0')*10+(v[5]-'0'); if ((M > 12) || (M < 1)) goto err; d= (v[6]-'0')*10+(v[7]-'0'); h= (v[8]-'0')*10+(v[9]-'0'); m= (v[10]-'0')*10+(v[11]-'0'); if ( (v[12] >= '0') && (v[12] <= '9') && (v[13] >= '0') && (v[13] <= '9')) { s= (v[12]-'0')*10+(v[13]-'0'); if (v[14] == '.') { int l = tm->length; f = &v[14]; f_len = 1; while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9') ++f_len; } } if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s", mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0) return(0); else return(1); err: BIO_write(bp,"Bad time value",14); return(0); }
['static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)\n{\n\tOCSP_CRLID *a = in;\n\tif (a->crlUrl)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;\n\t\tif (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\tif (a->crlNum)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;\n\t\tif (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\tif (a->crlTime)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;\n\t\tif (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\treturn 1;\n\terr:\n\treturn 0;\n}', "int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)\n\t{\n\tint i,n;\n\tchar buf[80],*p;;\n\tif (v == NULL) return(0);\n\tn=0;\n\tp=(char *)v->data;\n\tfor (i=0; i<v->length; i++)\n\t\t{\n\t\tif ((p[i] > '~') || ((p[i] < ' ') &&\n\t\t\t(p[i] != '\\n') && (p[i] != '\\r')))\n\t\t\tbuf[n]='.';\n\t\telse\n\t\t\tbuf[n]=p[i];\n\t\tn++;\n\t\tif (n >= 80)\n\t\t\t{\n\t\t\tif (BIO_write(bp,buf,n) <= 0)\n\t\t\t\treturn(0);\n\t\t\tn=0;\n\t\t\t}\n\t\t}\n\tif (n > 0)\n\t\tif (BIO_write(bp,buf,n) <= 0)\n\t\t\treturn(0);\n\treturn(1);\n\t}", 'int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm)\n\t{\n\tchar *v;\n\tint gmt=0;\n\tint i;\n\tint y=0,M=0,d=0,h=0,m=0,s=0;\n\tchar *f = NULL;\n\tint f_len = 0;\n\ti=tm->length;\n\tv=(char *)tm->data;\n\tif (i < 12) goto err;\n\tif (v[i-1] == \'Z\') gmt=1;\n\tfor (i=0; i<12; i++)\n\t\tif ((v[i] > \'9\') || (v[i] < \'0\')) goto err;\n\ty= (v[0]-\'0\')*1000+(v[1]-\'0\')*100 + (v[2]-\'0\')*10+(v[3]-\'0\');\n\tM= (v[4]-\'0\')*10+(v[5]-\'0\');\n\tif ((M > 12) || (M < 1)) goto err;\n\td= (v[6]-\'0\')*10+(v[7]-\'0\');\n\th= (v[8]-\'0\')*10+(v[9]-\'0\');\n\tm= (v[10]-\'0\')*10+(v[11]-\'0\');\n\tif (\t(v[12] >= \'0\') && (v[12] <= \'9\') &&\n\t\t(v[13] >= \'0\') && (v[13] <= \'9\'))\n\t\t{\n\t\ts= (v[12]-\'0\')*10+(v[13]-\'0\');\n\t\tif (v[14] == \'.\')\n\t\t\t{\n\t\t\tint l = tm->length;\n\t\t\tf = &v[14];\n\t\t\tf_len = 1;\n\t\t\twhile (14 + f_len < l && f[f_len] >= \'0\' && f[f_len] <= \'9\')\n\t\t\t\t++f_len;\n\t\t\t}\n\t\t}\n\tif (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s",\n\t\tmon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0)\n\t\treturn(0);\n\telse\n\t\treturn(1);\nerr:\n\tBIO_write(bp,"Bad time value",14);\n\treturn(0);\n\t}']
669
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavformat/gxf.c/#L132
static int get_sindex(AVFormatContext *s, int id, int format) { int i; AVStream *st = NULL; for (i = 0; i < s->nb_streams; i++) { if (s->streams[i]->id == id) return i; } st = av_new_stream(s, id); switch (format) { case 3: case 4: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MJPEG; break; case 13: case 15: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_DVVIDEO; break; case 14: case 16: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_DVVIDEO; break; case 11: case 12: case 20: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG2VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; break; case 22: case 23: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG1VIDEO; st->need_parsing = AVSTREAM_PARSE_HEADERS; break; case 9: st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S24LE; st->codec->channels = 1; st->codec->sample_rate = 48000; st->codec->bit_rate = 3 * 1 * 48000 * 8; st->codec->block_align = 3 * 1; st->codec->bits_per_sample = 24; break; case 10: st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_PCM_S16LE; st->codec->channels = 1; st->codec->sample_rate = 48000; st->codec->bit_rate = 2 * 1 * 48000 * 8; st->codec->block_align = 2 * 1; st->codec->bits_per_sample = 16; break; case 17: st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_AC3; st->codec->channels = 2; st->codec->sample_rate = 48000; break; case 7: case 8: case 24: st->codec->codec_type = CODEC_TYPE_DATA; st->codec->codec_id = CODEC_ID_NONE; break; default: st->codec->codec_type = CODEC_TYPE_UNKNOWN; st->codec->codec_id = CODEC_ID_NONE; break; } return s->nb_streams - 1; }
['static int get_sindex(AVFormatContext *s, int id, int format) {\n int i;\n AVStream *st = NULL;\n for (i = 0; i < s->nb_streams; i++) {\n if (s->streams[i]->id == id)\n return i;\n }\n st = av_new_stream(s, id);\n switch (format) {\n case 3:\n case 4:\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_id = CODEC_ID_MJPEG;\n break;\n case 13:\n case 15:\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_id = CODEC_ID_DVVIDEO;\n break;\n case 14:\n case 16:\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_id = CODEC_ID_DVVIDEO;\n break;\n case 11:\n case 12:\n case 20:\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_id = CODEC_ID_MPEG2VIDEO;\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n break;\n case 22:\n case 23:\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_id = CODEC_ID_MPEG1VIDEO;\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n break;\n case 9:\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n st->codec->codec_id = CODEC_ID_PCM_S24LE;\n st->codec->channels = 1;\n st->codec->sample_rate = 48000;\n st->codec->bit_rate = 3 * 1 * 48000 * 8;\n st->codec->block_align = 3 * 1;\n st->codec->bits_per_sample = 24;\n break;\n case 10:\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n st->codec->codec_id = CODEC_ID_PCM_S16LE;\n st->codec->channels = 1;\n st->codec->sample_rate = 48000;\n st->codec->bit_rate = 2 * 1 * 48000 * 8;\n st->codec->block_align = 2 * 1;\n st->codec->bits_per_sample = 16;\n break;\n case 17:\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n st->codec->codec_id = CODEC_ID_AC3;\n st->codec->channels = 2;\n st->codec->sample_rate = 48000;\n break;\n case 7:\n case 8:\n case 24:\n st->codec->codec_type = CODEC_TYPE_DATA;\n st->codec->codec_id = CODEC_ID_NONE;\n break;\n default:\n st->codec->codec_type = CODEC_TYPE_UNKNOWN;\n st->codec->codec_id = CODEC_ID_NONE;\n break;\n }\n return s->nb_streams - 1;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = AV_NOPTS_VALUE;\n st->first_dts = AV_NOPTS_VALUE;\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 s->streams[s->nb_streams++] = st;\n return st;\n}']
670
0
https://github.com/libav/libav/blob/124c21d79f2124d028890022e98ea853a834a964/libavcodec/vp6.c/#L179
static void vp6_default_models_init(VP56Context *s) { VP56Model *model = s->modelp; model->vector_dct[0] = 0xA2; model->vector_dct[1] = 0xA4; model->vector_sig[0] = 0x80; model->vector_sig[1] = 0x80; memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats)); memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv)); memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv)); memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv)); memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder)); vp6_coeff_order_table_init(s); }
['static void vp6_default_models_init(VP56Context *s)\n{\n VP56Model *model = s->modelp;\n model->vector_dct[0] = 0xA2;\n model->vector_dct[1] = 0xA4;\n model->vector_sig[0] = 0x80;\n model->vector_sig[1] = 0x80;\n memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats));\n memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv));\n memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv));\n memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv));\n memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder));\n vp6_coeff_order_table_init(s);\n}']
671
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_dec2bn(BIGNUM **bn, char *a)\n\t{\n\tBIGNUM *ret=NULL;\n\tBN_ULONG l=0;\n\tint neg=0,i,j;\n\tint num;\n\tif ((a == NULL) || (*a == '\\0')) return(0);\n\tif (*a == '-') { neg=1; a++; }\n\tfor (i=0; isdigit(a[i]); i++)\n\t\t;\n\tnum=i+neg;\n\tif (bn == NULL) return(num);\n\tif (*bn == NULL)\n\t\t{\n\t\tif ((ret=BN_new()) == NULL) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tret= *bn;\n\t\tBN_zero(ret);\n\t\t}\n\tif (bn_expand(ret,i*4) == NULL) goto err;\n\tj=BN_DEC_NUM-(i%BN_DEC_NUM);\n\tif (j == BN_DEC_NUM) j=0;\n\tl=0;\n\twhile (*a)\n\t\t{\n\t\tl*=10;\n\t\tl+= *a-'0';\n\t\ta++;\n\t\tif (++j == BN_DEC_NUM)\n\t\t\t{\n\t\t\tBN_mul_word(ret,BN_DEC_CONV);\n\t\t\tBN_add_word(ret,l);\n\t\t\tl=0;\n\t\t\tj=0;\n\t\t\t}\n\t\t}\n\tret->neg=neg;\n\tbn_fix_top(ret);\n\t*bn=ret;\n\treturn(num);\nerr:\n\tif (*bn == NULL) BN_free(ret);\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}']
672
0
https://github.com/libav/libav/blob/f223ad1e000d56ef5231a3b1fc00495b538a9ed6/libavcodec/utils.c/#L786
static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); return desc->flags & PIX_FMT_HWACCEL; }
['static int is_hwaccel_pix_fmt(enum AVPixelFormat pix_fmt)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);\n return desc->flags & PIX_FMT_HWACCEL;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
673
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_asm.c/#L545
void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) { #ifdef BN_LLONG BN_ULLONG t; #else BN_ULONG bl,bh; #endif BN_ULONG t1,t2; BN_ULONG c1,c2,c3; c1=0; c2=0; c3=0; mul_add_c(a[0],b[0],c1,c2,c3); r[0]=c1; c1=0; mul_add_c(a[0],b[1],c2,c3,c1); mul_add_c(a[1],b[0],c2,c3,c1); r[1]=c2; c2=0; mul_add_c(a[2],b[0],c3,c1,c2); mul_add_c(a[1],b[1],c3,c1,c2); mul_add_c(a[0],b[2],c3,c1,c2); r[2]=c3; c3=0; mul_add_c(a[0],b[3],c1,c2,c3); mul_add_c(a[1],b[2],c1,c2,c3); mul_add_c(a[2],b[1],c1,c2,c3); mul_add_c(a[3],b[0],c1,c2,c3); r[3]=c1; c1=0; mul_add_c(a[4],b[0],c2,c3,c1); mul_add_c(a[3],b[1],c2,c3,c1); mul_add_c(a[2],b[2],c2,c3,c1); mul_add_c(a[1],b[3],c2,c3,c1); mul_add_c(a[0],b[4],c2,c3,c1); r[4]=c2; c2=0; mul_add_c(a[0],b[5],c3,c1,c2); mul_add_c(a[1],b[4],c3,c1,c2); mul_add_c(a[2],b[3],c3,c1,c2); mul_add_c(a[3],b[2],c3,c1,c2); mul_add_c(a[4],b[1],c3,c1,c2); mul_add_c(a[5],b[0],c3,c1,c2); r[5]=c3; c3=0; mul_add_c(a[6],b[0],c1,c2,c3); mul_add_c(a[5],b[1],c1,c2,c3); mul_add_c(a[4],b[2],c1,c2,c3); mul_add_c(a[3],b[3],c1,c2,c3); mul_add_c(a[2],b[4],c1,c2,c3); mul_add_c(a[1],b[5],c1,c2,c3); mul_add_c(a[0],b[6],c1,c2,c3); r[6]=c1; c1=0; mul_add_c(a[0],b[7],c2,c3,c1); mul_add_c(a[1],b[6],c2,c3,c1); mul_add_c(a[2],b[5],c2,c3,c1); mul_add_c(a[3],b[4],c2,c3,c1); mul_add_c(a[4],b[3],c2,c3,c1); mul_add_c(a[5],b[2],c2,c3,c1); mul_add_c(a[6],b[1],c2,c3,c1); mul_add_c(a[7],b[0],c2,c3,c1); r[7]=c2; c2=0; mul_add_c(a[7],b[1],c3,c1,c2); mul_add_c(a[6],b[2],c3,c1,c2); mul_add_c(a[5],b[3],c3,c1,c2); mul_add_c(a[4],b[4],c3,c1,c2); mul_add_c(a[3],b[5],c3,c1,c2); mul_add_c(a[2],b[6],c3,c1,c2); mul_add_c(a[1],b[7],c3,c1,c2); r[8]=c3; c3=0; mul_add_c(a[2],b[7],c1,c2,c3); mul_add_c(a[3],b[6],c1,c2,c3); mul_add_c(a[4],b[5],c1,c2,c3); mul_add_c(a[5],b[4],c1,c2,c3); mul_add_c(a[6],b[3],c1,c2,c3); mul_add_c(a[7],b[2],c1,c2,c3); r[9]=c1; c1=0; mul_add_c(a[7],b[3],c2,c3,c1); mul_add_c(a[6],b[4],c2,c3,c1); mul_add_c(a[5],b[5],c2,c3,c1); mul_add_c(a[4],b[6],c2,c3,c1); mul_add_c(a[3],b[7],c2,c3,c1); r[10]=c2; c2=0; mul_add_c(a[4],b[7],c3,c1,c2); mul_add_c(a[5],b[6],c3,c1,c2); mul_add_c(a[6],b[5],c3,c1,c2); mul_add_c(a[7],b[4],c3,c1,c2); r[11]=c3; c3=0; mul_add_c(a[7],b[5],c1,c2,c3); mul_add_c(a[6],b[6],c1,c2,c3); mul_add_c(a[5],b[7],c1,c2,c3); r[12]=c1; c1=0; mul_add_c(a[6],b[7],c2,c3,c1); mul_add_c(a[7],b[6],c2,c3,c1); r[13]=c2; c2=0; mul_add_c(a[7],b[7],c3,c1,c2); r[14]=c3; r[15]=c1; }
['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_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_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n\t BN_ULONG *t)\n\t{\n\tint n=n2/2,c1,c2;\n\tunsigned int neg,zero;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_recursive %d * %d\\n",n2,n2);\n#endif\n#ifdef BN_MUL_COMBA\n if (n2 == 8)\n\t\t{\n\t\tbn_mul_comba8(r,a,b);\n\t\treturn;\n\t\t}\n#endif\n\tif (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t{\n\t\tbn_mul_normal(r,a,n2,b,n2);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_words(a,&(a[n]),n);\n\tc2=bn_cmp_words(&(b[n]),b,n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\t\tbreak;\n\tcase -2:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\t\tbreak;\n\tcase 2:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\t\tbreak;\n\tcase 4:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tbreak;\n\t\t}\n#ifdef BN_MUL_COMBA\n\tif (n == 4)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,8*sizeof(BN_ULONG));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse if (n == 8)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,16*sizeof(BN_ULONG));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tif (!zero)\n\t\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\telse\n\t\t\tmemset(&(t[n2]),0,n2*sizeof(BN_ULONG));\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)\n\t{\n#ifdef BN_LLONG\n\tBN_ULLONG t;\n#else\n\tBN_ULONG bl,bh;\n#endif\n\tBN_ULONG t1,t2;\n\tBN_ULONG c1,c2,c3;\n\tc1=0;\n\tc2=0;\n\tc3=0;\n\tmul_add_c(a[0],b[0],c1,c2,c3);\n\tr[0]=c1;\n\tc1=0;\n\tmul_add_c(a[0],b[1],c2,c3,c1);\n\tmul_add_c(a[1],b[0],c2,c3,c1);\n\tr[1]=c2;\n\tc2=0;\n\tmul_add_c(a[2],b[0],c3,c1,c2);\n\tmul_add_c(a[1],b[1],c3,c1,c2);\n\tmul_add_c(a[0],b[2],c3,c1,c2);\n\tr[2]=c3;\n\tc3=0;\n\tmul_add_c(a[0],b[3],c1,c2,c3);\n\tmul_add_c(a[1],b[2],c1,c2,c3);\n\tmul_add_c(a[2],b[1],c1,c2,c3);\n\tmul_add_c(a[3],b[0],c1,c2,c3);\n\tr[3]=c1;\n\tc1=0;\n\tmul_add_c(a[4],b[0],c2,c3,c1);\n\tmul_add_c(a[3],b[1],c2,c3,c1);\n\tmul_add_c(a[2],b[2],c2,c3,c1);\n\tmul_add_c(a[1],b[3],c2,c3,c1);\n\tmul_add_c(a[0],b[4],c2,c3,c1);\n\tr[4]=c2;\n\tc2=0;\n\tmul_add_c(a[0],b[5],c3,c1,c2);\n\tmul_add_c(a[1],b[4],c3,c1,c2);\n\tmul_add_c(a[2],b[3],c3,c1,c2);\n\tmul_add_c(a[3],b[2],c3,c1,c2);\n\tmul_add_c(a[4],b[1],c3,c1,c2);\n\tmul_add_c(a[5],b[0],c3,c1,c2);\n\tr[5]=c3;\n\tc3=0;\n\tmul_add_c(a[6],b[0],c1,c2,c3);\n\tmul_add_c(a[5],b[1],c1,c2,c3);\n\tmul_add_c(a[4],b[2],c1,c2,c3);\n\tmul_add_c(a[3],b[3],c1,c2,c3);\n\tmul_add_c(a[2],b[4],c1,c2,c3);\n\tmul_add_c(a[1],b[5],c1,c2,c3);\n\tmul_add_c(a[0],b[6],c1,c2,c3);\n\tr[6]=c1;\n\tc1=0;\n\tmul_add_c(a[0],b[7],c2,c3,c1);\n\tmul_add_c(a[1],b[6],c2,c3,c1);\n\tmul_add_c(a[2],b[5],c2,c3,c1);\n\tmul_add_c(a[3],b[4],c2,c3,c1);\n\tmul_add_c(a[4],b[3],c2,c3,c1);\n\tmul_add_c(a[5],b[2],c2,c3,c1);\n\tmul_add_c(a[6],b[1],c2,c3,c1);\n\tmul_add_c(a[7],b[0],c2,c3,c1);\n\tr[7]=c2;\n\tc2=0;\n\tmul_add_c(a[7],b[1],c3,c1,c2);\n\tmul_add_c(a[6],b[2],c3,c1,c2);\n\tmul_add_c(a[5],b[3],c3,c1,c2);\n\tmul_add_c(a[4],b[4],c3,c1,c2);\n\tmul_add_c(a[3],b[5],c3,c1,c2);\n\tmul_add_c(a[2],b[6],c3,c1,c2);\n\tmul_add_c(a[1],b[7],c3,c1,c2);\n\tr[8]=c3;\n\tc3=0;\n\tmul_add_c(a[2],b[7],c1,c2,c3);\n\tmul_add_c(a[3],b[6],c1,c2,c3);\n\tmul_add_c(a[4],b[5],c1,c2,c3);\n\tmul_add_c(a[5],b[4],c1,c2,c3);\n\tmul_add_c(a[6],b[3],c1,c2,c3);\n\tmul_add_c(a[7],b[2],c1,c2,c3);\n\tr[9]=c1;\n\tc1=0;\n\tmul_add_c(a[7],b[3],c2,c3,c1);\n\tmul_add_c(a[6],b[4],c2,c3,c1);\n\tmul_add_c(a[5],b[5],c2,c3,c1);\n\tmul_add_c(a[4],b[6],c2,c3,c1);\n\tmul_add_c(a[3],b[7],c2,c3,c1);\n\tr[10]=c2;\n\tc2=0;\n\tmul_add_c(a[4],b[7],c3,c1,c2);\n\tmul_add_c(a[5],b[6],c3,c1,c2);\n\tmul_add_c(a[6],b[5],c3,c1,c2);\n\tmul_add_c(a[7],b[4],c3,c1,c2);\n\tr[11]=c3;\n\tc3=0;\n\tmul_add_c(a[7],b[5],c1,c2,c3);\n\tmul_add_c(a[6],b[6],c1,c2,c3);\n\tmul_add_c(a[5],b[7],c1,c2,c3);\n\tr[12]=c1;\n\tc1=0;\n\tmul_add_c(a[6],b[7],c2,c3,c1);\n\tmul_add_c(a[7],b[6],c2,c3,c1);\n\tr[13]=c2;\n\tc2=0;\n\tmul_add_c(a[7],b[7],c3,c1,c2);\n\tr[14]=c3;\n\tr[15]=c1;\n\t}']
674
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/ssl/s3_lib.c/#L512
int ssl3_new(SSL *s) { SSL3_CTX *s3; if ((s3=(SSL3_CTX *)Malloc(sizeof(SSL3_CTX))) == NULL) goto err; memset(s3,0,sizeof(SSL3_CTX)); s->s3=s3; s->method->ssl_clear(s); return(1); err: return(0); }
['int ssl3_new(SSL *s)\n\t{\n\tSSL3_CTX *s3;\n\tif ((s3=(SSL3_CTX *)Malloc(sizeof(SSL3_CTX))) == NULL) goto err;\n\tmemset(s3,0,sizeof(SSL3_CTX));\n\ts->s3=s3;\n\ts->method->ssl_clear(s);\n\treturn(1);\nerr:\n\treturn(0);\n\t}']
675
0
https://github.com/libav/libav/blob/8e3d8a82e6eb8ef37daecddf651fe6cdadaab7e8/libavformat/rmdec.c/#L582
static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb, RMDemuxContext *rm, RMStream *vst, AVPacket *pkt, int len, int *pseq) { int hdr, seq, pic_num, len2, pos; int type; hdr = get_byte(pb); len--; type = hdr >> 6; if(type != 3){ seq = get_byte(pb); len--; } if(type != 1){ len2 = get_num(pb, &len); pos = get_num(pb, &len); pic_num = get_byte(pb); len--; } if(len<0) return -1; rm->remaining_len = len; if(type&1){ if(type == 3) len= len2; if(rm->remaining_len < len) return -1; rm->remaining_len -= len; if(av_new_packet(pkt, len + 9) < 0) return AVERROR(EIO); pkt->data[0] = 0; AV_WL32(pkt->data + 1, 1); AV_WL32(pkt->data + 5, 0); get_buffer(pb, pkt->data + 9, len); return 0; } *pseq = seq; if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){ vst->slices = ((hdr & 0x3F) << 1) + 1; vst->videobufsize = len2 + 8*vst->slices + 1; av_free_packet(&vst->pkt); if(av_new_packet(&vst->pkt, vst->videobufsize) < 0) return AVERROR(ENOMEM); vst->videobufpos = 8*vst->slices + 1; vst->cur_slice = 0; vst->curpic_num = pic_num; vst->pktpos = url_ftell(pb); } if(type == 2) len = FFMIN(len, pos); if(++vst->cur_slice > vst->slices) return 1; AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1); AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1); if(vst->videobufpos + len > vst->videobufsize) return 1; if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len) return AVERROR(EIO); vst->videobufpos += len; rm->remaining_len-= len; if(type == 2 || (vst->videobufpos) == vst->videobufsize){ vst->pkt.data[0] = vst->cur_slice-1; *pkt= vst->pkt; vst->pkt.data= NULL; vst->pkt.size= 0; if(vst->slices != vst->cur_slice) memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices, vst->videobufpos - 1 - 8*vst->slices); pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices); pkt->pts = AV_NOPTS_VALUE; pkt->pos = vst->pktpos; return 0; } return 1; }
['static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,\n RMDemuxContext *rm, RMStream *vst,\n AVPacket *pkt, int len, int *pseq)\n{\n int hdr, seq, pic_num, len2, pos;\n int type;\n hdr = get_byte(pb); len--;\n type = hdr >> 6;\n if(type != 3){\n seq = get_byte(pb); len--;\n }\n if(type != 1){\n len2 = get_num(pb, &len);\n pos = get_num(pb, &len);\n pic_num = get_byte(pb); len--;\n }\n if(len<0)\n return -1;\n rm->remaining_len = len;\n if(type&1){\n if(type == 3)\n len= len2;\n if(rm->remaining_len < len)\n return -1;\n rm->remaining_len -= len;\n if(av_new_packet(pkt, len + 9) < 0)\n return AVERROR(EIO);\n pkt->data[0] = 0;\n AV_WL32(pkt->data + 1, 1);\n AV_WL32(pkt->data + 5, 0);\n get_buffer(pb, pkt->data + 9, len);\n return 0;\n }\n *pseq = seq;\n if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){\n vst->slices = ((hdr & 0x3F) << 1) + 1;\n vst->videobufsize = len2 + 8*vst->slices + 1;\n av_free_packet(&vst->pkt);\n if(av_new_packet(&vst->pkt, vst->videobufsize) < 0)\n return AVERROR(ENOMEM);\n vst->videobufpos = 8*vst->slices + 1;\n vst->cur_slice = 0;\n vst->curpic_num = pic_num;\n vst->pktpos = url_ftell(pb);\n }\n if(type == 2)\n len = FFMIN(len, pos);\n if(++vst->cur_slice > vst->slices)\n return 1;\n AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1);\n AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);\n if(vst->videobufpos + len > vst->videobufsize)\n return 1;\n if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len)\n return AVERROR(EIO);\n vst->videobufpos += len;\n rm->remaining_len-= len;\n if(type == 2 || (vst->videobufpos) == vst->videobufsize){\n vst->pkt.data[0] = vst->cur_slice-1;\n *pkt= vst->pkt;\n vst->pkt.data= NULL;\n vst->pkt.size= 0;\n if(vst->slices != vst->cur_slice)\n memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices,\n vst->videobufpos - 1 - 8*vst->slices);\n pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices);\n pkt->pts = AV_NOPTS_VALUE;\n pkt->pos = vst->pktpos;\n return 0;\n }\n return 1;\n}']
676
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)\n{\n BIGNUM *r1, *m1, *vrfy, *r2, *m[RSA_MAX_PRIME_NUM - 2];\n int ret = 0, i, ex_primes = 0, smooth = 0;\n RSA_PRIME_INFO *pinfo;\n BN_CTX_start(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n m1 = BN_CTX_get(ctx);\n vrfy = BN_CTX_get(ctx);\n if (vrfy == NULL)\n goto err;\n if (rsa->version == RSA_ASN1_VERSION_MULTI\n && ((ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0\n || ex_primes > RSA_MAX_PRIME_NUM - 2))\n goto err;\n if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) {\n BIGNUM *factor = BN_new();\n if (factor == NULL)\n goto err;\n if (!(BN_with_flags(factor, rsa->p, BN_FLG_CONSTTIME),\n BN_MONT_CTX_set_locked(&rsa->_method_mod_p, rsa->lock,\n factor, ctx))\n || !(BN_with_flags(factor, rsa->q, BN_FLG_CONSTTIME),\n BN_MONT_CTX_set_locked(&rsa->_method_mod_q, rsa->lock,\n factor, ctx))) {\n BN_free(factor);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(factor, pinfo->r, BN_FLG_CONSTTIME);\n if (!BN_MONT_CTX_set_locked(&pinfo->m, rsa->lock, factor, ctx)) {\n BN_free(factor);\n goto err;\n }\n }\n BN_free(factor);\n smooth = (ex_primes == 0)\n && (rsa->meth->bn_mod_exp == BN_mod_exp_mont)\n && (BN_num_bits(rsa->q) == BN_num_bits(rsa->p));\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,\n rsa->n, ctx))\n goto err;\n if (smooth) {\n if (\n !bn_from_mont_fixed_top(m1, I, rsa->_method_mod_q, ctx)\n || !bn_to_mont_fixed_top(m1, m1, rsa->_method_mod_q, ctx)\n || !BN_mod_exp_mont_consttime(m1, m1, rsa->dmq1, rsa->q, ctx,\n rsa->_method_mod_q)\n || !bn_from_mont_fixed_top(r1, I, rsa->_method_mod_p, ctx)\n || !bn_to_mont_fixed_top(r1, r1, rsa->_method_mod_p, ctx)\n || !BN_mod_exp_mont_consttime(r1, r1, rsa->dmp1, rsa->p, ctx,\n rsa->_method_mod_p)\n || !bn_mod_sub_fixed_top(r1, r1, m1, rsa->p)\n || !bn_to_mont_fixed_top(r1, r1, rsa->_method_mod_p, ctx)\n || !bn_mul_mont_fixed_top(r1, r1, rsa->iqmp, rsa->_method_mod_p,\n ctx)\n || !bn_mul_fixed_top(r0, r1, rsa->q, ctx)\n || !bn_mod_add_fixed_top(r0, r0, m1, rsa->n))\n goto err;\n goto tail;\n }\n {\n BIGNUM *c = BN_new();\n if (c == NULL)\n goto err;\n BN_with_flags(c, I, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, c, rsa->q, ctx)) {\n BN_free(c);\n goto err;\n }\n {\n BIGNUM *dmq1 = BN_new();\n if (dmq1 == NULL) {\n BN_free(c);\n goto err;\n }\n BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,\n rsa->_method_mod_q)) {\n BN_free(c);\n BN_free(dmq1);\n goto err;\n }\n BN_free(dmq1);\n }\n if (!BN_mod(r1, c, rsa->p, ctx)) {\n BN_free(c);\n goto err;\n }\n BN_free(c);\n }\n {\n BIGNUM *dmp1 = BN_new();\n if (dmp1 == NULL)\n goto err;\n BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,\n rsa->_method_mod_p)) {\n BN_free(dmp1);\n goto err;\n }\n BN_free(dmp1);\n }\n if (ex_primes > 0) {\n BIGNUM *di = BN_new(), *cc = BN_new();\n if (cc == NULL || di == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n if ((m[i] = BN_CTX_get(ctx)) == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(cc, I, BN_FLG_CONSTTIME);\n BN_with_flags(di, pinfo->d, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, cc, pinfo->r, ctx)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(m[i], r1, di, pinfo->r, ctx, pinfo->m)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n }\n BN_free(cc);\n BN_free(di);\n }\n if (!BN_sub(r0, r0, m1))\n goto err;\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->iqmp, ctx))\n goto err;\n {\n BIGNUM *pr1 = BN_new();\n if (pr1 == NULL)\n goto err;\n BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);\n if (!BN_mod(r0, pr1, rsa->p, ctx)) {\n BN_free(pr1);\n goto err;\n }\n BN_free(pr1);\n }\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->q, ctx))\n goto err;\n if (!BN_add(r0, r1, m1))\n goto err;\n if (ex_primes > 0) {\n BIGNUM *pr2 = BN_new();\n if (pr2 == NULL)\n goto err;\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n if (!BN_sub(r1, m[i], r0)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r2, r1, pinfo->t, ctx)) {\n BN_free(pr2);\n goto err;\n }\n BN_with_flags(pr2, r2, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, pr2, pinfo->r, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (BN_is_negative(r1))\n if (!BN_add(r1, r1, pinfo->r)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r1, r1, pinfo->pp, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_add(r0, r0, r1)) {\n BN_free(pr2);\n goto err;\n }\n }\n BN_free(pr2);\n }\n tail:\n if (rsa->e && rsa->n) {\n if (rsa->meth->bn_mod_exp == BN_mod_exp_mont) {\n if (!BN_mod_exp_mont(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n } else {\n bn_correct_top(r0);\n if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n }\n if (!BN_sub(vrfy, vrfy, I))\n goto err;\n if (BN_is_zero(vrfy)) {\n bn_correct_top(r0);\n ret = 1;\n goto err;\n }\n if (!BN_mod(vrfy, vrfy, rsa->n, ctx))\n goto err;\n if (BN_is_negative(vrfy))\n if (!BN_add(vrfy, vrfy, rsa->n))\n goto err;\n if (!BN_is_zero(vrfy)) {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n }\n bn_correct_top(r0);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'int bn_from_mont_fixed_top(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 }\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 (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}', '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}', 'int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);\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_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, wmask, window0;\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 = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n 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 BIGNUM *reduced = BN_CTX_get(ctx);\n if (reduced == NULL\n || !BN_nnmod(reduced, a, m, ctx)) {\n goto err;\n }\n a = reduced;\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_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&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 window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\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 window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\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 bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\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_mul_mont_fixed_top(&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_mul_mont_fixed_top(&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 window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&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_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
677
0
https://github.com/libav/libav/blob/3a7f7678eb3be1f9a28414c9908ed8d34b1b9846/libavformat/oggparseflac.c/#L66
static int flac_header (AVFormatContext * s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; GetBitContext gb; FLACStreaminfo si; int mdt; if (os->buf[os->pstart] == 0xff) return 0; init_get_bits(&gb, os->buf + os->pstart, os->psize*8); skip_bits1(&gb); mdt = get_bits(&gb, 7); if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) { uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4; skip_bits_long(&gb, 4*8); if(get_bits(&gb, 8) != 1) return -1; skip_bits_long(&gb, 8 + 16); skip_bits_long(&gb, 4*8); if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) return -1; avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start); st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_FLAC; st->codec->extradata = av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE); st->codec->extradata_size = FLAC_STREAMINFO_SIZE; avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) { ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4); } return 1; }
['static int\nflac_header (AVFormatContext * s, int idx)\n{\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n AVStream *st = s->streams[idx];\n GetBitContext gb;\n FLACStreaminfo si;\n int mdt;\n if (os->buf[os->pstart] == 0xff)\n return 0;\n init_get_bits(&gb, os->buf + os->pstart, os->psize*8);\n skip_bits1(&gb);\n mdt = get_bits(&gb, 7);\n if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {\n uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;\n skip_bits_long(&gb, 4*8);\n if(get_bits(&gb, 8) != 1)\n return -1;\n skip_bits_long(&gb, 8 + 16);\n skip_bits_long(&gb, 4*8);\n if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE)\n return -1;\n avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start);\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codec->codec_id = CODEC_ID_FLAC;\n st->codec->extradata =\n av_malloc(FLAC_STREAMINFO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE);\n st->codec->extradata_size = FLAC_STREAMINFO_SIZE;\n avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);\n } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {\n ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4);\n }\n return 1;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n s->buffer_end = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index = 0;\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3);\n s->bit_count = 32 + 8*((intptr_t)buffer & 3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline void skip_bits1(GetBitContext *s){\n skip_bits(s, 1);\n}', 'static inline void skip_bits(GetBitContext *s, int n){\n OPEN_READER(re, s);\n UPDATE_CACHE(re, s);\n LAST_SKIP_BITS(re, s, n);\n CLOSE_READER(re, s);\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n return AV_BSWAP32C(x);\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 inline void skip_bits_long(GetBitContext *s, int n){\n s->index += n;\n}', 'static inline unsigned int get_bits_long(GetBitContext *s, int n){\n if (n <= MIN_CACHE_BITS) return get_bits(s, n);\n else {\n#ifdef ALT_BITSTREAM_READER_LE\n int ret = get_bits(s, 16);\n return ret | (get_bits(s, n-16) << 16);\n#else\n int ret = get_bits(s, 16) << (n-16);\n return ret | get_bits(s, n-16);\n#endif\n }\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
678
0
https://github.com/libav/libav/blob/64ba831da99c5526b21d510397b449742e92961e/libavformat/utils.c/#L2622
void avformat_free_context(AVFormatContext *s) { int i; AVStream *st; av_opt_free(s); if (s->iformat && s->iformat->priv_class && s->priv_data) av_opt_free(s->priv_data); for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; if (st->parser) { av_parser_close(st->parser); } if (st->attached_pic.data) av_free_packet(&st->attached_pic); av_dict_free(&st->metadata); av_freep(&st->probe_data.buf); av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec->subtitle_header); av_free(st->codec); av_free(st->priv_data); av_free(st->info); av_free(st); } for (i = s->nb_programs - 1; i >= 0; i--) { av_dict_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); } av_freep(&s->programs); av_freep(&s->priv_data); while (s->nb_chapters--) { av_dict_free(&s->chapters[s->nb_chapters]->metadata); av_free(s->chapters[s->nb_chapters]); } av_freep(&s->chapters); av_dict_free(&s->metadata); av_freep(&s->streams); av_free(s); }
['static int hls_write_header(AVFormatContext *s)\n{\n HLSContext *hls = s->priv_data;\n int ret, i;\n char *p;\n const char *pattern = "%d.ts";\n int basename_size = strlen(s->filename) + strlen(pattern) + 1;\n hls->number = 0;\n hls->recording_time = hls->time * AV_TIME_BASE;\n hls->start_pts = AV_NOPTS_VALUE;\n for (i = 0; i < s->nb_streams; i++)\n hls->has_video +=\n s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO;\n if (hls->has_video > 1)\n av_log(s, AV_LOG_WARNING,\n "More than a single video stream present, "\n "expect issues decoding it.\\n");\n hls->oformat = av_guess_format("mpegts", NULL, NULL);\n if (!hls->oformat) {\n ret = AVERROR_MUXER_NOT_FOUND;\n goto fail;\n }\n hls->basename = av_malloc(basename_size);\n if (!hls->basename) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n strcpy(hls->basename, s->filename);\n p = strrchr(hls->basename, \'.\');\n if (p)\n *p = \'\\0\';\n av_strlcat(hls->basename, pattern, basename_size);\n if ((ret = hls_mux_init(s)) < 0)\n goto fail;\n if ((ret = hls_start(s)) < 0)\n goto fail;\n if ((ret = avformat_write_header(hls->avf, NULL)) < 0)\n return ret;\nfail:\n if (ret) {\n av_free(hls->basename);\n if (hls->avf)\n avformat_free_context(hls->avf);\n }\n return ret;\n}', 'AVOutputFormat *av_guess_format(const char *short_name, const char *filename,\n const char *mime_type)\n{\n AVOutputFormat *fmt = NULL, *fmt_found;\n int score_max, score;\n#if CONFIG_IMAGE2_MUXER\n if (!short_name && filename &&\n av_filename_number_test(filename) &&\n ff_guess_image2_codec(filename) != AV_CODEC_ID_NONE) {\n return av_guess_format("image2", NULL, NULL);\n }\n#endif\n fmt_found = NULL;\n score_max = 0;\n while ((fmt = av_oformat_next(fmt))) {\n score = 0;\n if (fmt->name && short_name && !av_strcasecmp(fmt->name, short_name))\n score += 100;\n if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))\n score += 10;\n if (filename && fmt->extensions &&\n av_match_ext(filename, fmt->extensions)) {\n score += 5;\n }\n if (score > score_max) {\n score_max = score;\n fmt_found = fmt;\n }\n }\n return fmt_found;\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for (i = 0; i < s->nb_streams; i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n }\n if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\n av_dict_free(&st->metadata);\n av_freep(&st->probe_data.buf);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for (i = s->nb_programs - 1; i >= 0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while (s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_free(s);\n}']
679
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L764
static int umh_search(MpegEncContext * s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags) { MotionEstContext * const c= &s->me; me_cmp_func cmpf, chroma_cmpf; LOAD_COMMON LOAD_COMMON2 int map_generation= c->map_generation; int x,y,x2,y2, i, j, d; const int dia_size= c->dia_size&0xFE; static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2}, { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2}, {-2, 3}, { 0, 4}, { 2, 3}, {-2,-3}, { 0,-4}, { 2,-3},}; cmpf= s->dsp.me_cmp[size]; chroma_cmpf= s->dsp.me_cmp[size+1]; x= best[0]; y= best[1]; for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){ CHECK_MV(x2, y); } for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){ CHECK_MV(x, y2); } x= best[0]; y= best[1]; for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){ for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){ CHECK_MV(x2, y2); } } for(j=1; j<=dia_size/4; j++){ for(i=0; i<16; i++){ CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j); } } return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2); }
['static int umh_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags)\n{\n MotionEstContext * const c= &s->me;\n me_cmp_func cmpf, chroma_cmpf;\n LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n int x,y,x2,y2, i, j, d;\n const int dia_size= c->dia_size&0xFE;\n static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},\n { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},\n {-2, 3}, { 0, 4}, { 2, 3},\n {-2,-3}, { 0,-4}, { 2,-3},};\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n x= best[0];\n y= best[1];\n for(x2=FFMAX(x-dia_size+1, xmin); x2<=FFMIN(x+dia_size-1,xmax); x2+=2){\n CHECK_MV(x2, y);\n }\n for(y2=FFMAX(y-dia_size/2+1, ymin); y2<=FFMIN(y+dia_size/2-1,ymax); y2+=2){\n CHECK_MV(x, y2);\n }\n x= best[0];\n y= best[1];\n for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){\n for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){\n CHECK_MV(x2, y2);\n }\n }\n for(j=1; j<=dia_size/4; j++){\n for(i=0; i<16; i++){\n CHECK_CLIPPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);\n }\n }\n return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, 2);\n}']
680
0
https://github.com/libav/libav/blob/bb4afa13dd3264832bc379bbfefe1db8cf4f0e40/libavcodec/parser.c/#L230
int av_parser_change(AVCodecParserContext *s, AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe){ if(s && s->parser->split){ if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){ int i= s->parser->split(avctx, buf, buf_size); buf += i; buf_size -= i; } } *poutbuf= (uint8_t *) buf; *poutbuf_size= buf_size; if(avctx->extradata){ if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) ){ int size= buf_size + avctx->extradata_size; *poutbuf_size= size; *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); return 1; } } return 0; }
['int av_parser_change(AVCodecParserContext *s,\n AVCodecContext *avctx,\n uint8_t **poutbuf, int *poutbuf_size,\n const uint8_t *buf, int buf_size, int keyframe){\n if(s && s->parser->split){\n if((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)){\n int i= s->parser->split(avctx, buf, buf_size);\n buf += i;\n buf_size -= i;\n }\n }\n *poutbuf= (uint8_t *) buf;\n *poutbuf_size= buf_size;\n if(avctx->extradata){\n if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER))\n ){\n int size= buf_size + avctx->extradata_size;\n *poutbuf_size= size;\n *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(*poutbuf, avctx->extradata, avctx->extradata_size);\n memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);\n return 1;\n }\n }\n return 0;\n}', 'void *av_malloc(FF_INTERNAL_MEM_TYPE size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
681
0
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/mem.c/#L245
void CRYPTO_free(void *str) { #ifdef CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0); free(str); CRYPTO_mem_debug_free(str, 1); } else { free(str); } #else free(str); #endif }
['unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,\n const unsigned char *d, size_t n, unsigned char *md,\n unsigned int *md_len)\n{\n HMAC_CTX *c = NULL;\n static unsigned char m[EVP_MAX_MD_SIZE];\n if (md == NULL)\n md = m;\n if ((c = HMAC_CTX_new()) == NULL)\n goto err;\n if (!HMAC_Init_ex(c, key, key_len, evp_md, NULL))\n goto err;\n if (!HMAC_Update(c, d, n))\n goto err;\n if (!HMAC_Final(c, md, md_len))\n goto err;\n HMAC_CTX_free(c);\n return md;\n err:\n HMAC_CTX_free(c);\n return NULL;\n}', 'HMAC_CTX *HMAC_CTX_new(void)\n{\n HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_zalloc(sizeof(HMAC_CTX));\n if (ctx)\n if (!HMAC_CTX_reset(ctx)) {\n HMAC_CTX_free(ctx);\n ctx = NULL;\n }\n return ctx;\n}', 'int HMAC_CTX_reset(HMAC_CTX *ctx)\n{\n hmac_ctx_cleanup(ctx);\n if (ctx->i_ctx == NULL)\n ctx->i_ctx = EVP_MD_CTX_new();\n if (ctx->i_ctx == NULL)\n goto err;\n if (ctx->o_ctx == NULL)\n ctx->o_ctx = EVP_MD_CTX_new();\n if (ctx->o_ctx == NULL)\n goto err;\n if (ctx->md_ctx == NULL)\n ctx->md_ctx = EVP_MD_CTX_new();\n if (ctx->md_ctx == NULL)\n goto err;\n ctx->md = NULL;\n return 1;\n err:\n hmac_ctx_cleanup(ctx);\n return 0;\n}', 'static void hmac_ctx_cleanup(HMAC_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx->i_ctx);\n EVP_MD_CTX_reset(ctx->o_ctx);\n EVP_MD_CTX_reset(ctx->md_ctx);\n ctx->md = NULL;\n ctx->key_length = 0;\n memset(ctx->key, 0, sizeof(HMAC_MAX_MD_CBLOCK));\n}', 'int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)\n{\n if (ctx == NULL)\n return 1;\n if (ctx->digest && ctx->digest->cleanup\n && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))\n ctx->digest->cleanup(ctx);\n if (ctx->digest && ctx->digest->ctx_size && ctx->md_data\n && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {\n OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);\n }\n EVP_PKEY_CTX_free(ctx->pctx);\n#ifndef OPENSSL_NO_ENGINE\n if (ctx->engine)\n ENGINE_finish(ctx->engine);\n#endif\n memset(ctx, 0, sizeof(*ctx));\n return 1;\n}', 'void CRYPTO_clear_free(void *str, size_t num)\n{\n if (str == NULL)\n return;\n if (num)\n OPENSSL_cleanse(str, num);\n CRYPTO_free(str);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
682
0
https://github.com/libav/libav/blob/8f935b9271052be8f97d655081b94b68b6c23bfb/libavformat/nsvdec.c/#L314
static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) { NSVContext *nsv = s->priv_data; AVIOContext *pb = s->pb; unsigned int file_size, size; int64_t duration; int strings_size; int table_entries; int table_entries_used; av_dlog(s, "%s()\n", __FUNCTION__); nsv->state = NSV_UNSYNC; size = avio_rl32(pb); if (size < 28) return -1; nsv->NSVf_end = size; file_size = (uint32_t)avio_rl32(pb); av_dlog(s, "NSV NSVf chunk_size %u\n", size); av_dlog(s, "NSV NSVf file_size %u\n", file_size); nsv->duration = duration = avio_rl32(pb); av_dlog(s, "NSV NSVf duration %"PRId64" ms\n", duration); strings_size = avio_rl32(pb); table_entries = avio_rl32(pb); table_entries_used = avio_rl32(pb); av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", strings_size, table_entries, table_entries_used); if (url_feof(pb)) return -1; av_dlog(s, "NSV got header; filepos %"PRId64"\n", url_ftell(pb)); if (strings_size > 0) { char *strings; char *p, *endp; char *token, *value; char quote; p = strings = av_mallocz(strings_size + 1); endp = strings + strings_size; avio_read(pb, strings, strings_size); while (p < endp) { while (*p == ' ') p++; if (p >= endp-2) break; token = p; p = strchr(p, '='); if (!p || p >= endp-2) break; *p++ = '\0'; quote = *p++; value = p; p = strchr(p, quote); if (!p || p >= endp) break; *p++ = '\0'; av_dlog(s, "NSV NSVf INFO: %s='%s'\n", token, value); av_metadata_set2(&s->metadata, token, value, 0); } av_free(strings); } if (url_feof(pb)) return -1; av_dlog(s, "NSV got infos; filepos %"PRId64"\n", url_ftell(pb)); if (table_entries_used > 0) { int i; nsv->index_entries = table_entries_used; if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t)) return -1; nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t)); for(i=0;i<table_entries_used;i++) nsv->nsvs_file_offset[i] = avio_rl32(pb) + size; if(table_entries > table_entries_used && avio_rl32(pb) == MKTAG('T','O','C','2')) { nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t)); for(i=0;i<table_entries_used;i++) { nsv->nsvs_timestamps[i] = avio_rl32(pb); } } } av_dlog(s, "NSV got index; filepos %"PRId64"\n", url_ftell(pb)); #ifdef DEBUG_DUMP_INDEX #define V(v) ((v<0x20 || v > 127)?'.':v) av_dlog(s, "NSV %d INDEX ENTRIES:\n", table_entries); av_dlog(s, "NSV [dataoffset][fileoffset]\n", table_entries); for (i = 0; i < table_entries; i++) { unsigned char b[8]; url_fseek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET); avio_read(pb, b, 8); av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x" "%c%c%c%c%c%c%c%c\n", nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i], b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ); } #undef V #endif url_fseek(pb, nsv->base_offset + size, SEEK_SET); if (url_feof(pb)) return -1; nsv->state = NSV_HAS_READ_NSVF; return 0; }
['static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n NSVContext *nsv = s->priv_data;\n AVIOContext *pb = s->pb;\n unsigned int file_size, size;\n int64_t duration;\n int strings_size;\n int table_entries;\n int table_entries_used;\n av_dlog(s, "%s()\\n", __FUNCTION__);\n nsv->state = NSV_UNSYNC;\n size = avio_rl32(pb);\n if (size < 28)\n return -1;\n nsv->NSVf_end = size;\n file_size = (uint32_t)avio_rl32(pb);\n av_dlog(s, "NSV NSVf chunk_size %u\\n", size);\n av_dlog(s, "NSV NSVf file_size %u\\n", file_size);\n nsv->duration = duration = avio_rl32(pb);\n av_dlog(s, "NSV NSVf duration %"PRId64" ms\\n", duration);\n strings_size = avio_rl32(pb);\n table_entries = avio_rl32(pb);\n table_entries_used = avio_rl32(pb);\n av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\\n",\n strings_size, table_entries, table_entries_used);\n if (url_feof(pb))\n return -1;\n av_dlog(s, "NSV got header; filepos %"PRId64"\\n", url_ftell(pb));\n if (strings_size > 0) {\n char *strings;\n char *p, *endp;\n char *token, *value;\n char quote;\n p = strings = av_mallocz(strings_size + 1);\n endp = strings + strings_size;\n avio_read(pb, strings, strings_size);\n while (p < endp) {\n while (*p == \' \')\n p++;\n if (p >= endp-2)\n break;\n token = p;\n p = strchr(p, \'=\');\n if (!p || p >= endp-2)\n break;\n *p++ = \'\\0\';\n quote = *p++;\n value = p;\n p = strchr(p, quote);\n if (!p || p >= endp)\n break;\n *p++ = \'\\0\';\n av_dlog(s, "NSV NSVf INFO: %s=\'%s\'\\n", token, value);\n av_metadata_set2(&s->metadata, token, value, 0);\n }\n av_free(strings);\n }\n if (url_feof(pb))\n return -1;\n av_dlog(s, "NSV got infos; filepos %"PRId64"\\n", url_ftell(pb));\n if (table_entries_used > 0) {\n int i;\n nsv->index_entries = table_entries_used;\n if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t))\n return -1;\n nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t));\n for(i=0;i<table_entries_used;i++)\n nsv->nsvs_file_offset[i] = avio_rl32(pb) + size;\n if(table_entries > table_entries_used &&\n avio_rl32(pb) == MKTAG(\'T\',\'O\',\'C\',\'2\')) {\n nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t));\n for(i=0;i<table_entries_used;i++) {\n nsv->nsvs_timestamps[i] = avio_rl32(pb);\n }\n }\n }\n av_dlog(s, "NSV got index; filepos %"PRId64"\\n", url_ftell(pb));\n#ifdef DEBUG_DUMP_INDEX\n#define V(v) ((v<0x20 || v > 127)?\'.\':v)\n av_dlog(s, "NSV %d INDEX ENTRIES:\\n", table_entries);\n av_dlog(s, "NSV [dataoffset][fileoffset]\\n", table_entries);\n for (i = 0; i < table_entries; i++) {\n unsigned char b[8];\n url_fseek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET);\n avio_read(pb, b, 8);\n av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x"\n "%c%c%c%c%c%c%c%c\\n",\n nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i],\n b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],\n V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) );\n }\n#undef V\n#endif\n url_fseek(pb, nsv->base_offset + size, SEEK_SET);\n if (url_feof(pb))\n return -1;\n nsv->state = NSV_HAS_READ_NSVF;\n return 0;\n}', 'unsigned int avio_rl32(AVIOContext *s)\n{\n unsigned int val;\n val = avio_rl16(s);\n val |= avio_rl16(s) << 16;\n return val;\n}', 'unsigned int avio_rl16(AVIOContext *s)\n{\n unsigned int val;\n val = avio_r8(s);\n val |= avio_r8(s) << 8;\n return val;\n}', 'int avio_r8(AVIOContext *s)\n{\n if (s->buf_ptr >= s->buf_end)\n fill_buffer(s);\n if (s->buf_ptr < s->buf_end)\n return *s->buf_ptr++;\n return 0;\n}', 'int url_feof(AVIOContext *s)\n{\n if(!s)\n return 0;\n return s->eof_reached;\n}', 'void *av_mallocz(FF_INTERNAL_MEM_TYPE size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(FF_INTERNAL_MEM_TYPE size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
683
0
https://github.com/openssl/openssl/blob/9dd4ac8cf17f2afd636e85ae0111d1df4104a475/crypto/ct/ct_log.c/#L201
int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file) { int ret = 0; char *enabled_logs; CTLOG_STORE_LOAD_CTX* load_ctx = ctlog_store_load_ctx_new(); load_ctx->log_store = store; load_ctx->conf = NCONF_new(NULL); if (load_ctx->conf == NULL) goto end; if (NCONF_load(load_ctx->conf, file, NULL) <= 0) { CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID); goto end; } enabled_logs = NCONF_get_string(load_ctx->conf, NULL, "enabled_logs"); if (enabled_logs == NULL) { CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID); goto end; } if (!CONF_parse_list(enabled_logs, ',', 1, ctlog_store_load_log, load_ctx) || load_ctx->invalid_log_entries > 0) { CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID); goto end; } ret = 1; end: NCONF_free(load_ctx->conf); ctlog_store_load_ctx_free(load_ctx); return ret; }
['int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file)\n{\n int ret = 0;\n char *enabled_logs;\n CTLOG_STORE_LOAD_CTX* load_ctx = ctlog_store_load_ctx_new();\n load_ctx->log_store = store;\n load_ctx->conf = NCONF_new(NULL);\n if (load_ctx->conf == NULL)\n goto end;\n if (NCONF_load(load_ctx->conf, file, NULL) <= 0) {\n CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID);\n goto end;\n }\n enabled_logs = NCONF_get_string(load_ctx->conf, NULL, "enabled_logs");\n if (enabled_logs == NULL) {\n CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID);\n goto end;\n }\n if (!CONF_parse_list(enabled_logs, \',\', 1, ctlog_store_load_log, load_ctx) ||\n load_ctx->invalid_log_entries > 0) {\n CTerr(CT_F_CTLOG_STORE_LOAD_FILE, CT_R_LOG_CONF_INVALID);\n goto end;\n }\n ret = 1;\nend:\n NCONF_free(load_ctx->conf);\n ctlog_store_load_ctx_free(load_ctx);\n return ret;\n}', 'static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new()\n{\n CTLOG_STORE_LOAD_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));\n if (ctx == NULL)\n CTerr(CT_F_CTLOG_STORE_LOAD_CTX_NEW, ERR_R_MALLOC_FAILURE);\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 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}']
684
0
https://github.com/openssl/openssl/blob/6ea3bca427b3e759939a63555821d0c4678dd79c/test/testutil/format_output.c/#L312
static void test_fail_bignum_common(const char *prefix, const char *file, int line, const char *type, const char *left, const char *right, const char *op, const BIGNUM *bn1, const BIGNUM *bn2) { const int indent = subtest_level(); const size_t bytes = bn_bytes; char b1[MAX_STRING_WIDTH + 1], b2[MAX_STRING_WIDTH + 1]; char *p, bdiff[MAX_STRING_WIDTH + 1]; size_t l1, l2, n1, n2, i, len; unsigned int cnt, diff, real_diff; unsigned char *m1 = NULL, *m2 = NULL; int lz1 = 1, lz2 = 1; unsigned char buffer[MEM_BUFFER_SIZE * 2], *bufp = buffer; test_fail_message_prefix(prefix, file, line, type, left, right, op); l1 = bn1 == NULL ? 0 : (BN_num_bytes(bn1) + (BN_is_negative(bn1) ? 1 : 0)); l2 = bn2 == NULL ? 0 : (BN_num_bytes(bn2) + (BN_is_negative(bn2) ? 1 : 0)); if (l1 == 0 && l2 == 0) { if ((bn1 == NULL) == (bn2 == NULL)) { test_bignum_header_line(); test_bignum_zero_print(bn1, ' '); } else { test_diff_header(left, right); test_bignum_header_line(); test_bignum_zero_print(bn1, '-'); test_bignum_zero_print(bn2, '+'); } goto fin; } if (l1 != l2 || bn1 == NULL || bn2 == NULL || BN_cmp(bn1, bn2) != 0) test_diff_header(left, right); test_bignum_header_line(); len = ((l1 > l2 ? l1 : l2) + bytes - 1) / bytes * bytes; if (len > MEM_BUFFER_SIZE && (bufp = OPENSSL_malloc(len * 2)) == NULL) { bufp = buffer; len = MEM_BUFFER_SIZE; test_printf_stderr("%*s# WARNING: these BIGNUMs have been truncated", indent, ""); } if (bn1 != NULL) { m1 = bufp; BN_bn2binpad(bn1, m1, len); } if (bn2 != NULL) { m2 = bufp + len; BN_bn2binpad(bn2, m2, len); } while (len > 0) { cnt = 8 * (len - bytes); n1 = convert_bn_memory(m1, bytes, b1, &lz1, bn1); n2 = convert_bn_memory(m2, bytes, b2, &lz2, bn2); diff = real_diff = 0; i = 0; p = bdiff; for (i=0; b1[i] != '\0'; i++) if (b1[i] == b2[i] || b1[i] == ' ' || b2[i] == ' ') { *p++ = ' '; diff |= b1[i] != b2[i]; } else { *p++ = '^'; real_diff = diff = 1; } *p++ = '\0'; if (!diff) { test_printf_stderr("%*s# %s:% 5d\n", indent, "", n2 > n1 ? b2 : b1, cnt); } else { if (cnt == 0 && bn1 == NULL) test_printf_stderr("%*s# -%s\n", indent, "", b1); else if (cnt == 0 || n1 > 0) test_printf_stderr("%*s# -%s:% 5d\n", indent, "", b1, cnt); if (cnt == 0 && bn2 == NULL) test_printf_stderr("%*s# +%s\n", indent, "", b2); else if (cnt == 0 || n2 > 0) test_printf_stderr("%*s# +%s:% 5d\n", indent, "", b2, cnt); if (real_diff && (cnt == 0 || (n1 > 0 && n2 > 0)) && bn1 != NULL && bn2 != NULL) test_printf_stderr("%*s# %s\n", indent, "", bdiff); } if (m1 != NULL) m1 += bytes; if (m2 != NULL) m2 += bytes; len -= bytes; } fin: test_flush_stderr(); if (bufp != buffer) OPENSSL_free(bufp); }
['static void test_fail_bignum_common(const char *prefix, const char *file,\n int line, const char *type,\n const char *left, const char *right,\n const char *op,\n const BIGNUM *bn1, const BIGNUM *bn2)\n{\n const int indent = subtest_level();\n const size_t bytes = bn_bytes;\n char b1[MAX_STRING_WIDTH + 1], b2[MAX_STRING_WIDTH + 1];\n char *p, bdiff[MAX_STRING_WIDTH + 1];\n size_t l1, l2, n1, n2, i, len;\n unsigned int cnt, diff, real_diff;\n unsigned char *m1 = NULL, *m2 = NULL;\n int lz1 = 1, lz2 = 1;\n unsigned char buffer[MEM_BUFFER_SIZE * 2], *bufp = buffer;\n test_fail_message_prefix(prefix, file, line, type, left, right, op);\n l1 = bn1 == NULL ? 0 : (BN_num_bytes(bn1) + (BN_is_negative(bn1) ? 1 : 0));\n l2 = bn2 == NULL ? 0 : (BN_num_bytes(bn2) + (BN_is_negative(bn2) ? 1 : 0));\n if (l1 == 0 && l2 == 0) {\n if ((bn1 == NULL) == (bn2 == NULL)) {\n test_bignum_header_line();\n test_bignum_zero_print(bn1, \' \');\n } else {\n test_diff_header(left, right);\n test_bignum_header_line();\n test_bignum_zero_print(bn1, \'-\');\n test_bignum_zero_print(bn2, \'+\');\n }\n goto fin;\n }\n if (l1 != l2 || bn1 == NULL || bn2 == NULL || BN_cmp(bn1, bn2) != 0)\n test_diff_header(left, right);\n test_bignum_header_line();\n len = ((l1 > l2 ? l1 : l2) + bytes - 1) / bytes * bytes;\n if (len > MEM_BUFFER_SIZE && (bufp = OPENSSL_malloc(len * 2)) == NULL) {\n bufp = buffer;\n len = MEM_BUFFER_SIZE;\n test_printf_stderr("%*s# WARNING: these BIGNUMs have been truncated",\n indent, "");\n }\n if (bn1 != NULL) {\n m1 = bufp;\n BN_bn2binpad(bn1, m1, len);\n }\n if (bn2 != NULL) {\n m2 = bufp + len;\n BN_bn2binpad(bn2, m2, len);\n }\n while (len > 0) {\n cnt = 8 * (len - bytes);\n n1 = convert_bn_memory(m1, bytes, b1, &lz1, bn1);\n n2 = convert_bn_memory(m2, bytes, b2, &lz2, bn2);\n diff = real_diff = 0;\n i = 0;\n p = bdiff;\n for (i=0; b1[i] != \'\\0\'; i++)\n if (b1[i] == b2[i] || b1[i] == \' \' || b2[i] == \' \') {\n *p++ = \' \';\n diff |= b1[i] != b2[i];\n } else {\n *p++ = \'^\';\n real_diff = diff = 1;\n }\n *p++ = \'\\0\';\n if (!diff) {\n test_printf_stderr("%*s# %s:% 5d\\n", indent, "",\n n2 > n1 ? b2 : b1, cnt);\n } else {\n if (cnt == 0 && bn1 == NULL)\n test_printf_stderr("%*s# -%s\\n", indent, "", b1);\n else if (cnt == 0 || n1 > 0)\n test_printf_stderr("%*s# -%s:% 5d\\n", indent, "", b1, cnt);\n if (cnt == 0 && bn2 == NULL)\n test_printf_stderr("%*s# +%s\\n", indent, "", b2);\n else if (cnt == 0 || n2 > 0)\n test_printf_stderr("%*s# +%s:% 5d\\n", indent, "", b2, cnt);\n if (real_diff && (cnt == 0 || (n1 > 0 && n2 > 0))\n && bn1 != NULL && bn2 != NULL)\n test_printf_stderr("%*s# %s\\n", indent, "", bdiff);\n }\n if (m1 != NULL)\n m1 += bytes;\n if (m2 != NULL)\n m2 += bytes;\n len -= bytes;\n }\nfin:\n test_flush_stderr();\n if (bufp != buffer)\n OPENSSL_free(bufp);\n}']
685
0
https://github.com/libav/libav/blob/2f99117f6ff24ce5be2abb9e014cb8b86c2aa0e0/libavcodec/h264_refs.c/#L235
static void h264_fill_mbaff_ref_list(H264SliceContext *sl) { int list, i, j; for (list = 0; list < sl->list_count; list++) { for (i = 0; i < sl->ref_count[list]; i++) { H264Ref *frame = &sl->ref_list[list][i]; H264Ref *field = &sl->ref_list[list][16 + 2 * i]; field[0] = *frame; for (j = 0; j < 3; j++) field[0].linesize[j] <<= 1; field[0].reference = PICT_TOP_FIELD; field[0].poc = field[0].parent->field_poc[0]; field[1] = field[0]; for (j = 0; j < 3; j++) field[1].data[j] += frame->parent->f->linesize[j]; field[1].reference = PICT_BOTTOM_FIELD; field[1].poc = field[1].parent->field_poc[1]; } } }
['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n H264Context *h = avctx->priv_data;\n AVFrame *pict = data;\n int buf_index = 0;\n int ret;\n const uint8_t *new_extradata;\n int new_extradata_size;\n h->flags = avctx->flags;\n h->setup_finished = 0;\n h->nb_slice_ctx_queued = 0;\nout:\n if (buf_size == 0) {\n H264Picture *out;\n int i, out_idx;\n h->cur_pic_ptr = NULL;\n out = h->delayed_pic[0];\n out_idx = 0;\n for (i = 1;\n h->delayed_pic[i] &&\n !h->delayed_pic[i]->f->key_frame &&\n !h->delayed_pic[i]->mmco_reset;\n i++)\n if (h->delayed_pic[i]->poc < out->poc) {\n out = h->delayed_pic[i];\n out_idx = i;\n }\n for (i = out_idx; h->delayed_pic[i]; i++)\n h->delayed_pic[i] = h->delayed_pic[i + 1];\n if (out) {\n ret = output_frame(h, pict, out->f);\n if (ret < 0)\n return ret;\n *got_frame = 1;\n }\n return buf_index;\n }\n new_extradata_size = 0;\n new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,\n &new_extradata_size);\n if (new_extradata_size > 0 && new_extradata) {\n ret = ff_h264_decode_extradata(new_extradata, new_extradata_size,\n &h->ps, &h->is_avc, &h->nal_length_size,\n avctx->err_recognition, avctx);\n if (ret < 0)\n return ret;\n }\n buf_index = decode_nal_units(h, buf, buf_size);\n if (buf_index < 0)\n return AVERROR_INVALIDDATA;\n if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) {\n buf_size = 0;\n goto out;\n }\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n if (avctx->skip_frame >= AVDISCARD_NONREF)\n return 0;\n av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||\n (h->mb_y >= h->mb_height && h->mb_height)) {\n ff_h264_field_end(h, &h->slice_ctx[0], 0);\n *got_frame = 0;\n if (h->output_frame->buf[0]) {\n ret = output_frame(h, pict, h->output_frame) ;\n av_frame_unref(h->output_frame);\n if (ret < 0)\n return ret;\n *got_frame = 1;\n }\n }\n assert(pict->buf[0] || !*got_frame);\n return get_consumed_bytes(buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n AVCodecContext *const avctx = h->avctx;\n int nals_needed = 0;\n int i, ret = 0;\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {\n h->current_slice = 0;\n if (!h->first_field)\n h->cur_pic_ptr = NULL;\n ff_h264_sei_uninit(&h->sei);\n }\n ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,\n h->nal_length_size, avctx->codec_id);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR,\n "Error splitting the input into NAL units.\\n");\n if (h->is_avc && !(avctx->err_recognition & AV_EF_EXPLODE)) {\n int err = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, 0, 0,\n avctx->codec_id);\n if (err >= 0) {\n av_log(avctx, AV_LOG_WARNING,\n "The stream seems to contain AVCC extradata with Annex B "\n "formatted data, which is invalid.");\n h->is_avc = 0;\n ret = 0;\n }\n }\n if (ret < 0)\n return ret;\n }\n if (avctx->active_thread_type & FF_THREAD_FRAME)\n nals_needed = get_last_needed_nal(h);\n for (i = 0; i < h->pkt.nb_nals; i++) {\n H2645NAL *nal = &h->pkt.nals[i];\n int max_slice_ctx, err;\n if (avctx->skip_frame >= AVDISCARD_NONREF &&\n nal->ref_idc == 0 && nal->type != H264_NAL_SEI)\n continue;\n h->nal_ref_idc = nal->ref_idc;\n h->nal_unit_type = nal->type;\n err = 0;\n switch (nal->type) {\n case H264_NAL_IDR_SLICE:\n idr(h);\n case H264_NAL_SLICE:\n if ((err = ff_h264_queue_decode_slice(h, nal)))\n break;\n if (avctx->active_thread_type & FF_THREAD_FRAME && !h->avctx->hwaccel &&\n i >= nals_needed && !h->setup_finished && h->cur_pic_ptr) {\n ff_thread_finish_setup(avctx);\n h->setup_finished = 1;\n }\n max_slice_ctx = avctx->hwaccel ? 1 : h->nb_slice_ctx;\n if (h->nb_slice_ctx_queued == max_slice_ctx) {\n if (avctx->hwaccel) {\n ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n h->nb_slice_ctx_queued = 0;\n } else\n ret = ff_h264_execute_decode_slices(h);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n }\n break;\n case H264_NAL_DPA:\n case H264_NAL_DPB:\n case H264_NAL_DPC:\n avpriv_request_sample(avctx, "data partitioning");\n ret = AVERROR(ENOSYS);\n goto end;\n break;\n case H264_NAL_SEI:\n ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n break;\n case H264_NAL_SPS:\n ret = ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n break;\n case H264_NAL_PPS:\n ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,\n nal->size_bits);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n break;\n case H264_NAL_AUD:\n case H264_NAL_END_SEQUENCE:\n case H264_NAL_END_STREAM:\n case H264_NAL_FILLER_DATA:\n case H264_NAL_SPS_EXT:\n case H264_NAL_AUXILIARY_SLICE:\n break;\n default:\n av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n",\n nal->type, nal->size_bits);\n }\n if (err < 0) {\n av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n }\n }\n ret = ff_h264_execute_decode_slices(h);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n ret = 0;\nend:\n if (h->cur_pic_ptr && !h->droppable) {\n ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n h->picture_structure == PICT_BOTTOM_FIELD);\n }\n return (ret < 0) ? ret : buf_size;\n}', 'int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n void *logctx, int is_nalff, int nal_length_size,\n enum AVCodecID codec_id)\n{\n int consumed, ret = 0;\n const uint8_t *next_avc = buf + (is_nalff ? 0 : length);\n pkt->nb_nals = 0;\n while (length >= 4) {\n H2645NAL *nal;\n int extract_length = 0;\n int skip_trailing_zeros = 1;\n if (buf == next_avc) {\n int i;\n for (i = 0; i < nal_length_size; i++)\n extract_length = (extract_length << 8) | buf[i];\n if (extract_length > length) {\n av_log(logctx, AV_LOG_ERROR,\n "Invalid NAL unit size (%d > %d).\\n",\n extract_length, length);\n return AVERROR_INVALIDDATA;\n }\n buf += nal_length_size;\n length -= nal_length_size;\n next_avc = buf + extract_length;\n } else {\n int buf_index = find_next_start_code(buf, next_avc);\n buf += buf_index;\n length -= buf_index;\n if (buf == next_avc)\n continue;\n if (length > 0) {\n extract_length = length;\n } else if (pkt->nb_nals == 0) {\n av_log(logctx, AV_LOG_ERROR, "No NAL unit found\\n");\n return AVERROR_INVALIDDATA;\n } else {\n break;\n }\n }\n if (pkt->nals_allocated < pkt->nb_nals + 1) {\n int new_size = pkt->nals_allocated + 1;\n H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n if (!tmp)\n return AVERROR(ENOMEM);\n pkt->nals = tmp;\n memset(pkt->nals + pkt->nals_allocated, 0,\n (new_size - pkt->nals_allocated) * sizeof(*tmp));\n pkt->nals_allocated = new_size;\n }\n nal = &pkt->nals[pkt->nb_nals++];\n consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n if (consumed < 0)\n return consumed;\n if (consumed < length - 3 &&\n buf[consumed] == 0x00 && buf[consumed + 1] == 0x00 &&\n buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n skip_trailing_zeros = 0;\n nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n if (ret < 0)\n return ret;\n if (codec_id == AV_CODEC_ID_HEVC)\n ret = hevc_parse_nal_header(nal, logctx);\n else\n ret = h264_parse_nal_header(nal, logctx);\n if (ret <= 0) {\n if (ret < 0) {\n av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\\n",\n nal->type);\n }\n pkt->nb_nals--;\n }\n buf += consumed;\n length -= consumed;\n }\n return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !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}', 'int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal)\n{\n H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued;\n int ret;\n sl->gb = nal->gb;\n ret = h264_slice_header_parse(sl, nal, &h->ps, h->avctx);\n if (ret < 0)\n return ret;\n if (sl->redundant_pic_count > 0)\n return 0;\n if (!h->setup_finished) {\n if (sl->first_mb_addr == 0) {\n if (h->nb_slice_ctx_queued) {\n H264SliceContext tmp_ctx;\n ret = ff_h264_execute_decode_slices(h);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n return ret;\n memcpy(&tmp_ctx, h->slice_ctx, sizeof(tmp_ctx));\n memcpy(h->slice_ctx, sl, sizeof(tmp_ctx));\n memcpy(sl, &tmp_ctx, sizeof(tmp_ctx));\n sl = h->slice_ctx;\n }\n if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {\n ff_h264_field_end(h, sl, 1);\n }\n h->current_slice = 0;\n if (!h->first_field) {\n if (h->cur_pic_ptr && !h->droppable) {\n ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n h->picture_structure == PICT_BOTTOM_FIELD);\n }\n h->cur_pic_ptr = NULL;\n }\n }\n if (h->current_slice == 0) {\n ret = h264_field_start(h, sl, nal);\n if (ret < 0)\n return ret;\n }\n }\n ret = h264_slice_init(h, sl, nal);\n if (ret < 0)\n return ret;\n if ((h->avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&\n (h->avctx->skip_frame < AVDISCARD_BIDIR ||\n sl->slice_type_nos != AV_PICTURE_TYPE_B) &&\n (h->avctx->skip_frame < AVDISCARD_NONKEY ||\n h->cur_pic_ptr->f->key_frame) &&\n h->avctx->skip_frame < AVDISCARD_ALL) {\n h->nb_slice_ctx_queued++;\n }\n return 0;\n}', 'static int h264_slice_header_parse(H264SliceContext *sl, const H2645NAL *nal,\n const H264ParamSets *ps, AVCodecContext *avctx)\n{\n const SPS *sps;\n const PPS *pps;\n int ret;\n unsigned int slice_type, tmp, i;\n int field_pic_flag, bottom_field_flag, picture_structure;\n sl->first_mb_addr = get_ue_golomb(&sl->gb);\n slice_type = get_ue_golomb_31(&sl->gb);\n if (slice_type > 9) {\n av_log(avctx, AV_LOG_ERROR,\n "slice type %d too large at %d\\n",\n slice_type, sl->first_mb_addr);\n return AVERROR_INVALIDDATA;\n }\n if (slice_type > 4) {\n slice_type -= 5;\n sl->slice_type_fixed = 1;\n } else\n sl->slice_type_fixed = 0;\n slice_type = ff_h264_golomb_to_pict_type[slice_type];\n sl->slice_type = slice_type;\n sl->slice_type_nos = slice_type & 3;\n if (nal->type == H264_NAL_IDR_SLICE &&\n sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n av_log(avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\\n");\n return AVERROR_INVALIDDATA;\n }\n sl->pps_id = get_ue_golomb(&sl->gb);\n if (sl->pps_id >= MAX_PPS_COUNT) {\n av_log(avctx, AV_LOG_ERROR, "pps_id %u out of range\\n", sl->pps_id);\n return AVERROR_INVALIDDATA;\n }\n if (!ps->pps_list[sl->pps_id]) {\n av_log(avctx, AV_LOG_ERROR,\n "non-existing PPS %u referenced\\n",\n sl->pps_id);\n return AVERROR_INVALIDDATA;\n }\n pps = (const PPS*)ps->pps_list[sl->pps_id]->data;\n if (!ps->sps_list[pps->sps_id]) {\n av_log(avctx, AV_LOG_ERROR,\n "non-existing SPS %u referenced\\n", pps->sps_id);\n return AVERROR_INVALIDDATA;\n }\n sps = (const SPS*)ps->sps_list[pps->sps_id]->data;\n sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);\n sl->mb_mbaff = 0;\n if (sps->frame_mbs_only_flag) {\n picture_structure = PICT_FRAME;\n } else {\n field_pic_flag = get_bits1(&sl->gb);\n if (field_pic_flag) {\n bottom_field_flag = get_bits1(&sl->gb);\n picture_structure = PICT_TOP_FIELD + bottom_field_flag;\n } else {\n picture_structure = PICT_FRAME;\n }\n }\n sl->picture_structure = picture_structure;\n sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;\n if (picture_structure == PICT_FRAME) {\n sl->curr_pic_num = sl->frame_num;\n sl->max_pic_num = 1 << sps->log2_max_frame_num;\n } else {\n sl->curr_pic_num = 2 * sl->frame_num + 1;\n sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1);\n }\n if (nal->type == H264_NAL_IDR_SLICE)\n get_ue_golomb(&sl->gb);\n if (sps->poc_type == 0) {\n sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);\n if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)\n sl->delta_poc_bottom = get_se_golomb(&sl->gb);\n }\n if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {\n sl->delta_poc[0] = get_se_golomb(&sl->gb);\n if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)\n sl->delta_poc[1] = get_se_golomb(&sl->gb);\n }\n sl->redundant_pic_count = 0;\n if (pps->redundant_pic_cnt_present)\n sl->redundant_pic_count = get_ue_golomb(&sl->gb);\n if (sl->slice_type_nos == AV_PICTURE_TYPE_B)\n sl->direct_spatial_mv_pred = get_bits1(&sl->gb);\n ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,\n &sl->gb, pps, sl->slice_type_nos,\n picture_structure);\n if (ret < 0)\n return ret;\n if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {\n ret = ff_h264_decode_ref_pic_list_reordering(sl, avctx);\n if (ret < 0) {\n sl->ref_count[1] = sl->ref_count[0] = 0;\n return ret;\n }\n }\n sl->pwt.use_weight = 0;\n for (i = 0; i < 2; i++) {\n sl->pwt.luma_weight_flag[i] = 0;\n sl->pwt.chroma_weight_flag[i] = 0;\n }\n if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||\n (pps->weighted_bipred_idc == 1 &&\n sl->slice_type_nos == AV_PICTURE_TYPE_B))\n ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,\n sl->slice_type_nos, &sl->pwt);\n sl->explicit_ref_marking = 0;\n if (nal->ref_idc) {\n ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, avctx);\n if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))\n return AVERROR_INVALIDDATA;\n }\n if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {\n tmp = get_ue_golomb_31(&sl->gb);\n if (tmp > 2) {\n av_log(avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\\n", tmp);\n return AVERROR_INVALIDDATA;\n }\n sl->cabac_init_idc = tmp;\n }\n sl->last_qscale_diff = 0;\n tmp = pps->init_qp + get_se_golomb(&sl->gb);\n if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) {\n av_log(avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n return AVERROR_INVALIDDATA;\n }\n sl->qscale = tmp;\n sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale);\n sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale);\n if (sl->slice_type == AV_PICTURE_TYPE_SP)\n get_bits1(&sl->gb);\n if (sl->slice_type == AV_PICTURE_TYPE_SP ||\n sl->slice_type == AV_PICTURE_TYPE_SI)\n get_se_golomb(&sl->gb);\n sl->deblocking_filter = 1;\n sl->slice_alpha_c0_offset = 0;\n sl->slice_beta_offset = 0;\n if (pps->deblocking_filter_parameters_present) {\n tmp = get_ue_golomb_31(&sl->gb);\n if (tmp > 2) {\n av_log(avctx, AV_LOG_ERROR,\n "deblocking_filter_idc %u out of range\\n", tmp);\n return AVERROR_INVALIDDATA;\n }\n sl->deblocking_filter = tmp;\n if (sl->deblocking_filter < 2)\n sl->deblocking_filter ^= 1;\n if (sl->deblocking_filter) {\n sl->slice_alpha_c0_offset = get_se_golomb(&sl->gb) * 2;\n sl->slice_beta_offset = get_se_golomb(&sl->gb) * 2;\n if (sl->slice_alpha_c0_offset > 12 ||\n sl->slice_alpha_c0_offset < -12 ||\n sl->slice_beta_offset > 12 ||\n sl->slice_beta_offset < -12) {\n av_log(avctx, AV_LOG_ERROR,\n "deblocking filter parameters %d %d out of range\\n",\n sl->slice_alpha_c0_offset, sl->slice_beta_offset);\n return AVERROR_INVALIDDATA;\n }\n }\n }\n return 0;\n}', 'static int h264_slice_init(H264Context *h, H264SliceContext *sl,\n const H2645NAL *nal)\n{\n int i, j, ret = 0;\n if (h->current_slice > 0) {\n if (h->ps.pps != (const PPS*)h->ps.pps_list[sl->pps_id]->data) {\n av_log(h->avctx, AV_LOG_ERROR, "PPS changed between slices\\n");\n return AVERROR_INVALIDDATA;\n }\n if (h->picture_structure != sl->picture_structure ||\n h->droppable != (nal->ref_idc == 0)) {\n av_log(h->avctx, AV_LOG_ERROR,\n "Changing field mode (%d -> %d) between slices is not allowed\\n",\n h->picture_structure, sl->picture_structure);\n return AVERROR_INVALIDDATA;\n } else if (!h->cur_pic_ptr) {\n av_log(h->avctx, AV_LOG_ERROR,\n "unset cur_pic_ptr on slice %d\\n",\n h->current_slice + 1);\n return AVERROR_INVALIDDATA;\n }\n }\n if (h->picture_idr && nal->type != H264_NAL_IDR_SLICE) {\n av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of IDR and non-IDR slices\\n");\n return AVERROR_INVALIDDATA;\n }\n assert(h->mb_num == h->mb_width * h->mb_height);\n if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||\n sl->first_mb_addr >= h->mb_num) {\n av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n return AVERROR_INVALIDDATA;\n }\n sl->resync_mb_x = sl->mb_x = sl->first_mb_addr % h->mb_width;\n sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) <<\n FIELD_OR_MBAFF_PICTURE(h);\n if (h->picture_structure == PICT_BOTTOM_FIELD)\n sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;\n assert(sl->mb_y < h->mb_height);\n ret = ff_h264_build_ref_list(h, sl);\n if (ret < 0)\n return ret;\n if (h->ps.pps->weighted_bipred_idc == 2 &&\n sl->slice_type_nos == AV_PICTURE_TYPE_B) {\n implicit_weight_table(h, sl, -1);\n if (FRAME_MBAFF(h)) {\n implicit_weight_table(h, sl, 0);\n implicit_weight_table(h, sl, 1);\n }\n }\n if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred)\n ff_h264_direct_dist_scale_factor(h, sl);\n ff_h264_direct_ref_list_init(h, sl);\n if (h->avctx->skip_loop_filter >= AVDISCARD_ALL ||\n (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY &&\n sl->slice_type_nos != AV_PICTURE_TYPE_I) ||\n (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR &&\n sl->slice_type_nos == AV_PICTURE_TYPE_B) ||\n (h->avctx->skip_loop_filter >= AVDISCARD_NONREF &&\n nal->ref_idc == 0))\n sl->deblocking_filter = 0;\n if (sl->deblocking_filter == 1 && h->nb_slice_ctx > 1) {\n if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) {\n sl->deblocking_filter = 2;\n } else {\n h->postpone_filter = 1;\n }\n }\n sl->qp_thresh = 15 -\n FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) -\n FFMAX3(0,\n h->ps.pps->chroma_qp_index_offset[0],\n h->ps.pps->chroma_qp_index_offset[1]) +\n 6 * (h->ps.sps->bit_depth_luma - 8);\n sl->slice_num = ++h->current_slice;\n if (sl->slice_num >= MAX_SLICES) {\n av_log(h->avctx, AV_LOG_ERROR,\n "Too many slices, increase MAX_SLICES and recompile\\n");\n }\n for (j = 0; j < 2; j++) {\n int id_list[16];\n int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j];\n for (i = 0; i < 16; i++) {\n id_list[i] = 60;\n if (j < sl->list_count && i < sl->ref_count[j] &&\n sl->ref_list[j][i].parent->f->buf[0]) {\n int k;\n AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer;\n for (k = 0; k < h->short_ref_count; k++)\n if (h->short_ref[k]->f->buf[0]->buffer == buf) {\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->buf[0]->buffer == buf) {\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] + (sl->ref_list[j][i].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 (sl->ref_list[j][i].reference & 3);\n }\n if (h->avctx->debug & FF_DEBUG_PICT_INFO) {\n av_log(h->avctx, AV_LOG_DEBUG,\n "slice:%d %s mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n sl->slice_num,\n (h->picture_structure == PICT_FRAME ? "F" : h->picture_structure == PICT_TOP_FIELD ? "T" : "B"),\n sl->mb_y * h->mb_width + sl->mb_x,\n av_get_picture_type_char(sl->slice_type),\n sl->slice_type_fixed ? " fix" : "",\n nal->type == H264_NAL_IDR_SLICE ? " IDR" : "",\n h->poc.frame_num,\n h->cur_pic_ptr->field_poc[0],\n h->cur_pic_ptr->field_poc[1],\n sl->ref_count[0], sl->ref_count[1],\n sl->qscale,\n sl->deblocking_filter,\n sl->slice_alpha_c0_offset, sl->slice_beta_offset,\n sl->pwt.use_weight,\n sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",\n sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");\n }\n return 0;\n}', 'int ff_h264_build_ref_list(const H264Context *h, H264SliceContext *sl)\n{\n int list, index, pic_structure;\n print_short_term(h);\n print_long_term(h);\n h264_initialise_ref_list(h, sl);\n for (list = 0; list < sl->list_count; list++) {\n int pred = sl->curr_pic_num;\n for (index = 0; index < sl->nb_ref_modifications[list]; index++) {\n unsigned int modification_of_pic_nums_idc = sl->ref_modifications[list][index].op;\n unsigned int val = sl->ref_modifications[list][index].val;\n unsigned int pic_id;\n int i;\n H264Picture *ref = NULL;\n switch (modification_of_pic_nums_idc) {\n case 0:\n case 1: {\n const unsigned int abs_diff_pic_num = val + 1;\n int frame_num;\n if (abs_diff_pic_num > sl->max_pic_num) {\n av_log(h->avctx, AV_LOG_ERROR,\n "abs_diff_pic_num overflow\\n");\n return AVERROR_INVALIDDATA;\n }\n if (modification_of_pic_nums_idc == 0)\n pred -= abs_diff_pic_num;\n else\n pred += abs_diff_pic_num;\n pred &= sl->max_pic_num - 1;\n frame_num = pic_num_extract(h, pred, &pic_structure);\n for (i = h->short_ref_count - 1; i >= 0; i--) {\n ref = h->short_ref[i];\n assert(ref->reference);\n assert(!ref->long_ref);\n if (ref->frame_num == frame_num &&\n (ref->reference & pic_structure))\n break;\n }\n if (i >= 0)\n ref->pic_id = pred;\n break;\n }\n case 2: {\n int long_idx;\n pic_id = val;\n long_idx = pic_num_extract(h, pic_id, &pic_structure);\n if (long_idx > 31) {\n av_log(h->avctx, AV_LOG_ERROR,\n "long_term_pic_idx overflow\\n");\n return AVERROR_INVALIDDATA;\n }\n ref = h->long_ref[long_idx];\n assert(!(ref && !ref->reference));\n if (ref && (ref->reference & pic_structure)) {\n ref->pic_id = pic_id;\n assert(ref->long_ref);\n i = 0;\n } else {\n i = -1;\n }\n break;\n }\n }\n if (i < 0) {\n av_log(h->avctx, AV_LOG_ERROR,\n "reference picture missing during reorder\\n");\n memset(&sl->ref_list[list][index], 0, sizeof(sl->ref_list[0][0]));\n } else {\n for (i = index; i + 1 < sl->ref_count[list]; i++) {\n if (sl->ref_list[list][i].parent &&\n ref->long_ref == sl->ref_list[list][i].parent->long_ref &&\n ref->pic_id == sl->ref_list[list][i].pic_id)\n break;\n }\n for (; i > index; i--) {\n sl->ref_list[list][i] = sl->ref_list[list][i - 1];\n }\n ref_from_h264pic(&sl->ref_list[list][index], ref);\n if (FIELD_PICTURE(h)) {\n pic_as_field(&sl->ref_list[list][index], pic_structure);\n }\n }\n }\n }\n for (list = 0; list < sl->list_count; list++) {\n for (index = 0; index < sl->ref_count[list]; index++) {\n if (!sl->ref_list[list][index].parent) {\n av_log(h->avctx, AV_LOG_ERROR, "Missing reference picture\\n");\n if (index == 0 || h->avctx->err_recognition & AV_EF_EXPLODE)\n return AVERROR_INVALIDDATA;\n else\n sl->ref_list[list][index] = sl->ref_list[list][index - 1];\n }\n }\n }\n if (FRAME_MBAFF(h))\n h264_fill_mbaff_ref_list(sl);\n return 0;\n}', 'static void h264_fill_mbaff_ref_list(H264SliceContext *sl)\n{\n int list, i, j;\n for (list = 0; list < sl->list_count; list++) {\n for (i = 0; i < sl->ref_count[list]; i++) {\n H264Ref *frame = &sl->ref_list[list][i];\n H264Ref *field = &sl->ref_list[list][16 + 2 * i];\n field[0] = *frame;\n for (j = 0; j < 3; j++)\n field[0].linesize[j] <<= 1;\n field[0].reference = PICT_TOP_FIELD;\n field[0].poc = field[0].parent->field_poc[0];\n field[1] = field[0];\n for (j = 0; j < 3; j++)\n field[1].data[j] += frame->parent->f->linesize[j];\n field[1].reference = PICT_BOTTOM_FIELD;\n field[1].poc = field[1].parent->field_poc[1];\n }\n }\n}']
686
0
https://github.com/apache/httpd/blob/478077c99b083478973d3f34301c5191e4265595/modules/proxy/mod_proxy_express.c/#L152
static int xlate_name(request_rec *r) { int i; const char *name; char *backend; apr_dbm_t *db; apr_status_t rv; apr_datum_t key, val; struct proxy_alias *ralias; proxy_dir_conf *dconf; express_server_conf *sconf; sconf = ap_get_module_config(r->server->module_config, &proxy_express_module); dconf = ap_get_module_config(r->per_dir_config, &proxy_module); if (!sconf->enabled) { return DECLINED; } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01001) "proxy_express: Enabled"); if (!sconf->dbmfile || (r->filename && strncmp(r->filename, "proxy:", 6) == 0)) { return DECLINED; } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01002) "proxy_express: Opening DBM file: %s (%s)", sconf->dbmfile, sconf->dbmtype); rv = apr_dbm_open_ex(&db, sconf->dbmtype, sconf->dbmfile, APR_DBM_READONLY, APR_OS_DEFAULT, r->pool); if (rv != APR_SUCCESS) { return DECLINED; } name = ap_get_server_name(r); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01003) "proxy_express: looking for %s", name); key.dptr = (char *)name; key.dsize = strlen(key.dptr); rv = apr_dbm_fetch(db, key, &val); if (rv == APR_SUCCESS) { backend = apr_pstrmemdup(r->pool, val.dptr, val.dsize); } apr_dbm_close(db); if (rv != APR_SUCCESS || !backend) { return DECLINED; } ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01004) "proxy_express: found %s -> %s", name, backend); r->filename = apr_pstrcat(r->pool, "proxy:", backend, r->uri, NULL); r->handler = "proxy-server"; r->proxyreq = PROXYREQ_REVERSE; ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01005) "proxy_express: rewritten as: %s", r->filename); ralias = (struct proxy_alias *)dconf->raliases->elts; for (i = 0; i < dconf->raliases->nelts; i++, ralias++) { if (strcasecmp(backend, ralias->real) == 0) { ralias = NULL; break; } } if (!ralias) { ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01006) "proxy_express: adding PPR entry"); ralias = apr_array_push(dconf->raliases); ralias->fake = "/"; ralias->real = apr_pstrdup(dconf->raliases->pool, backend); ralias->flags = 0; } return OK; }
['static int xlate_name(request_rec *r)\n{\n int i;\n const char *name;\n char *backend;\n apr_dbm_t *db;\n apr_status_t rv;\n apr_datum_t key, val;\n struct proxy_alias *ralias;\n proxy_dir_conf *dconf;\n express_server_conf *sconf;\n sconf = ap_get_module_config(r->server->module_config, &proxy_express_module);\n dconf = ap_get_module_config(r->per_dir_config, &proxy_module);\n if (!sconf->enabled) {\n return DECLINED;\n }\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01001) "proxy_express: Enabled");\n if (!sconf->dbmfile || (r->filename && strncmp(r->filename, "proxy:", 6) == 0)) {\n return DECLINED;\n }\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01002)\n "proxy_express: Opening DBM file: %s (%s)",\n sconf->dbmfile, sconf->dbmtype);\n rv = apr_dbm_open_ex(&db, sconf->dbmtype, sconf->dbmfile, APR_DBM_READONLY,\n APR_OS_DEFAULT, r->pool);\n if (rv != APR_SUCCESS) {\n return DECLINED;\n }\n name = ap_get_server_name(r);\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01003)\n "proxy_express: looking for %s", name);\n key.dptr = (char *)name;\n key.dsize = strlen(key.dptr);\n rv = apr_dbm_fetch(db, key, &val);\n if (rv == APR_SUCCESS) {\n backend = apr_pstrmemdup(r->pool, val.dptr, val.dsize);\n }\n apr_dbm_close(db);\n if (rv != APR_SUCCESS || !backend) {\n return DECLINED;\n }\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01004)\n "proxy_express: found %s -> %s", name, backend);\n r->filename = apr_pstrcat(r->pool, "proxy:", backend, r->uri, NULL);\n r->handler = "proxy-server";\n r->proxyreq = PROXYREQ_REVERSE;\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01005)\n "proxy_express: rewritten as: %s", r->filename);\n ralias = (struct proxy_alias *)dconf->raliases->elts;\n for (i = 0; i < dconf->raliases->nelts; i++, ralias++) {\n if (strcasecmp(backend, ralias->real) == 0) {\n ralias = NULL;\n break;\n }\n }\n if (!ralias) {\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01006)\n "proxy_express: adding PPR entry");\n ralias = apr_array_push(dconf->raliases);\n ralias->fake = "/";\n ralias->real = apr_pstrdup(dconf->raliases->pool, backend);\n ralias->flags = 0;\n }\n return OK;\n}']
687
0
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words) { BN_ULONG *a = NULL; bn_check_top(b); if (words > (INT_MAX / (4 * BN_BITS2))) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG); return NULL; } if (BN_get_flags(b, BN_FLG_STATIC_DATA)) { BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); return (NULL); } if (BN_get_flags(b, BN_FLG_SECURE)) a = OPENSSL_secure_zalloc(words * sizeof(*a)); else a = OPENSSL_zalloc(words * sizeof(*a)); if (a == NULL) { BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE); return (NULL); } assert(b->top <= words); if (b->top > 0) memcpy(a, b->d, sizeof(*a) * b->top); return a; }
['int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', '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}']
688
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)]; }
['int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,\n const ECDSA_SIG *sig, EC_KEY *eckey)\n{\n int ret = -1, i;\n BN_CTX *ctx;\n const BIGNUM *order;\n BIGNUM *u1, *u2, *m, *X;\n EC_POINT *point = NULL;\n const EC_GROUP *group;\n const EC_POINT *pub_key;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||\n (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_MISSING_PARAMETERS);\n return -1;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return -1;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n BN_CTX_start(ctx);\n u1 = BN_CTX_get(ctx);\n u2 = BN_CTX_get(ctx);\n m = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n if (X == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||\n BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) ||\n BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_BAD_SIGNATURE);\n ret = 0;\n goto err;\n }\n if (!ec_group_do_inverse_ord(group, u2, sig->s, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n i = BN_num_bits(order);\n if (8 * dgst_len > i)\n dgst_len = (i + 7) / 8;\n if (!BN_bin2bn(dgst, dgst_len, m)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(u1, m, u2, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (!BN_nnmod(u1, X, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n ret = (BN_ucmp(u1, sig->r) == 0);\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n EC_POINT_free(point);\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_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}', '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}']
689
1
https://github.com/libav/libav/blob/f726fc21ef76a8ba3445448066f7b2a687fbca16/libavfilter/buffersrc.c/#L384
static int query_formats(AVFilterContext *ctx) { BufferSourceContext *c = ctx->priv; AVFilterChannelLayouts *channel_layouts = NULL; AVFilterFormats *formats = NULL; AVFilterFormats *samplerates = NULL; switch (ctx->outputs[0]->type) { case AVMEDIA_TYPE_VIDEO: ff_add_format(&formats, c->pix_fmt); ff_set_common_formats(ctx, formats); break; case AVMEDIA_TYPE_AUDIO: ff_add_format(&formats, c->sample_fmt); ff_set_common_formats(ctx, formats); ff_add_format(&samplerates, c->sample_rate); ff_set_common_samplerates(ctx, samplerates); ff_add_channel_layout(&channel_layouts, c->channel_layout); ff_set_common_channel_layouts(ctx, channel_layouts); break; default: return AVERROR(EINVAL); } return 0; }
['static int query_formats(AVFilterContext *ctx)\n{\n BufferSourceContext *c = ctx->priv;\n AVFilterChannelLayouts *channel_layouts = NULL;\n AVFilterFormats *formats = NULL;\n AVFilterFormats *samplerates = NULL;\n switch (ctx->outputs[0]->type) {\n case AVMEDIA_TYPE_VIDEO:\n ff_add_format(&formats, c->pix_fmt);\n ff_set_common_formats(ctx, formats);\n break;\n case AVMEDIA_TYPE_AUDIO:\n ff_add_format(&formats, c->sample_fmt);\n ff_set_common_formats(ctx, formats);\n ff_add_format(&samplerates, c->sample_rate);\n ff_set_common_samplerates(ctx, samplerates);\n ff_add_channel_layout(&channel_layouts, c->channel_layout);\n ff_set_common_channel_layouts(ctx, channel_layouts);\n break;\n default:\n return AVERROR(EINVAL);\n }\n return 0;\n}', 'int ff_add_format(AVFilterFormats **avff, int fmt)\n{\n ADD_FORMAT(avff, fmt, int, formats, nb_formats);\n}', 'void av_freep(void *arg)\n{\n void **ptr = (void **)arg;\n av_free(*ptr);\n *ptr = NULL;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n if (ptr)\n free((char *)ptr - ((char *)ptr)[-1]);\n#elif HAVE_ALIGNED_MALLOC\n _aligned_free(ptr);\n#else\n free(ptr);\n#endif\n}']
690
0
https://github.com/nginx/nginx/blob/4fe0a09942f8aed90f84c77969847980e9aadd98/src/core/ngx_string.c/#L922
ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value, cutoff, cutlim; if (n == 0) { return NGX_ERROR; } cutoff = NGX_MAX_INT_T_VALUE / 10; cutlim = NGX_MAX_INT_T_VALUE % 10; for (value = 0; n--; line++) { if (*line < '0' || *line > '9') { return NGX_ERROR; } if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { return NGX_ERROR; } value = value * 10 + (*line - '0'); } return value; }
['static char *\nngx_http_log_open_file_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_log_loc_conf_t *llcf = conf;\n time_t inactive, valid;\n ngx_str_t *value, s;\n ngx_int_t max, min_uses;\n ngx_uint_t i;\n if (llcf->open_file_cache != NGX_CONF_UNSET_PTR) {\n return "is duplicate";\n }\n value = cf->args->elts;\n max = 0;\n inactive = 10;\n valid = 60;\n min_uses = 1;\n for (i = 1; i < cf->args->nelts; i++) {\n if (ngx_strncmp(value[i].data, "max=", 4) == 0) {\n max = ngx_atoi(value[i].data + 4, value[i].len - 4);\n if (max == NGX_ERROR) {\n goto failed;\n }\n continue;\n }\n if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) {\n s.len = value[i].len - 9;\n s.data = value[i].data + 9;\n inactive = ngx_parse_time(&s, 1);\n if (inactive == (time_t) NGX_ERROR) {\n goto failed;\n }\n continue;\n }\n if (ngx_strncmp(value[i].data, "min_uses=", 9) == 0) {\n min_uses = ngx_atoi(value[i].data + 9, value[i].len - 9);\n if (min_uses == NGX_ERROR) {\n goto failed;\n }\n continue;\n }\n if (ngx_strncmp(value[i].data, "valid=", 6) == 0) {\n s.len = value[i].len - 6;\n s.data = value[i].data + 6;\n valid = ngx_parse_time(&s, 1);\n if (valid == (time_t) NGX_ERROR) {\n goto failed;\n }\n continue;\n }\n if (ngx_strcmp(value[i].data, "off") == 0) {\n llcf->open_file_cache = NULL;\n continue;\n }\n failed:\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid \\"open_log_file_cache\\" parameter \\"%V\\"",\n &value[i]);\n return NGX_CONF_ERROR;\n }\n if (llcf->open_file_cache == NULL) {\n return NGX_CONF_OK;\n }\n if (max == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "\\"open_log_file_cache\\" must have \\"max\\" parameter");\n return NGX_CONF_ERROR;\n }\n llcf->open_file_cache = ngx_open_file_cache_init(cf->pool, max, inactive);\n if (llcf->open_file_cache) {\n llcf->open_file_cache_valid = valid;\n llcf->open_file_cache_min_uses = min_uses;\n return NGX_CONF_OK;\n }\n return NGX_CONF_ERROR;\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_INT_T_VALUE / 10;\n cutlim = NGX_MAX_INT_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
691
0
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/bn/bn_x931p.c/#L227
int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) { BIGNUM *t; int i; if ((nbits < 1024) || (nbits & 0xff)) return 0; nbits >>= 1; if (!BN_rand(Xp, nbits, 1, 0)) return 0; BN_CTX_start(ctx); t = BN_CTX_get(ctx); for (i = 0; i < 1000; i++) { if (!BN_rand(Xq, nbits, 1, 0)) return 0; BN_sub(t, Xp, Xq); if (BN_num_bits(t) > (nbits - 100)) break; } BN_CTX_end(ctx); if (i < 1000) return 1; return 0; }
['int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)\n{\n BIGNUM *t;\n int i;\n if ((nbits < 1024) || (nbits & 0xff))\n return 0;\n nbits >>= 1;\n if (!BN_rand(Xp, nbits, 1, 0))\n return 0;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n for (i = 0; i < 1000; i++) {\n if (!BN_rand(Xq, nbits, 1, 0))\n return 0;\n BN_sub(t, Xp, Xq);\n if (BN_num_bits(t) > (nbits - 100))\n break;\n }\n BN_CTX_end(ctx);\n if (i < 1000)\n return 1;\n return 0;\n}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(0, rnd, bits, top, bottom);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'BIGNUM *BN_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_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}']
692
0
https://github.com/libav/libav/blob/0e5f33f2426dae28725b14468b61cbad052da240/libavcodec/h264.h/#L898
static void fill_decode_caches(H264Context *h, int mb_type){ MpegEncContext * const s = &h->s; int topleft_xy, top_xy, topright_xy, left_xy[2]; int topleft_type, top_type, topright_type, left_type[2]; const uint8_t * left_block= h->left_block; int i; topleft_xy = h->topleft_mb_xy ; top_xy = h->top_mb_xy ; topright_xy = h->topright_mb_xy; left_xy[0] = h->left_mb_xy[0] ; left_xy[1] = h->left_mb_xy[1] ; topleft_type = h->topleft_type ; top_type = h->top_type ; topright_type= h->topright_type ; left_type[0] = h->left_type[0] ; left_type[1] = h->left_type[1] ; if(!IS_SKIP(mb_type)){ if(IS_INTRA(mb_type)){ int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available= h->top_samples_available= h->left_samples_available= 0xFFFF; h->topright_samples_available= 0xEEEA; if(!(top_type & type_mask)){ h->topleft_samples_available= 0xB3FF; h->top_samples_available= 0x33FF; h->topright_samples_available= 0x26EA; } if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){ if(IS_INTERLACED(mb_type)){ if(!(left_type[0] & type_mask)){ h->topleft_samples_available&= 0xDFFF; h->left_samples_available&= 0x5FFF; } if(!(left_type[1] & type_mask)){ h->topleft_samples_available&= 0xFF5F; h->left_samples_available&= 0xFF5F; } }else{ int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num ? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0; assert(left_xy[0] == left_xy[1]); if(!((left_typei & type_mask) && (left_type[0] & type_mask))){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } }else{ if(!(left_type[0] & type_mask)){ h->topleft_samples_available&= 0xDF5F; h->left_samples_available&= 0x5F5F; } } if(!(topleft_type & type_mask)) h->topleft_samples_available&= 0x7FFF; if(!(topright_type & type_mask)) h->topright_samples_available&= 0xFBFF; if(IS_INTRA4x4(mb_type)){ if(IS_INTRA4x4(top_type)){ h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4]; h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; }else{ int pred; if(!(top_type & type_mask)) pred= -1; else{ pred= 2; } h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode_cache[7+8*0]= pred; } for(i=0; i<2; i++){ if(IS_INTRA4x4(left_type[i])){ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; }else{ int pred; if(!(left_type[i] & type_mask)) pred= -1; else{ pred= 2; } h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; } } } } if(top_type){ AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]); h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8]; h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8]; h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8]; h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8]; }else { h->non_zero_count_cache[1+8*0]= h->non_zero_count_cache[2+8*0]= h->non_zero_count_cache[1+8*3]= h->non_zero_count_cache[2+8*3]= AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040); } for (i=0; i<2; i++) { if(left_type[i]){ h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]]; h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]]; h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]]; h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]]; }else{ h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64; } } if( CABAC ) { if(top_type) { h->top_cbp = h->cbp_table[top_xy]; } else if(IS_INTRA(mb_type)) { h->top_cbp = 0x1CF; } else { h->top_cbp = 0x00F; } if (left_type[0]) { h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0; } else if(IS_INTRA(mb_type)) { h->left_cbp = 0x1CF; } else { h->left_cbp = 0x00F; } if (left_type[0]) { h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1; } if (left_type[1]) { h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3; } } } #if 1 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ int list; for(list=0; list<h->list_count; list++){ if(!USES_LIST(mb_type, list)){ continue; } assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); h->mv_cache_clean[list]= 0; if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride; AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); h->ref_cache[list][scan8[0] + 0 - 1*8]= h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0]; h->ref_cache[list][scan8[0] + 2 - 1*8]= h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1]; }else{ AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101); } for(i=0; i<2; i++){ int cache_idx = scan8[0] - 1 + i*2*8; if(USES_LIST(left_type[i], list)){ const int b_xy= h->mb2b_xy[left_xy[i]] + 3; const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1; AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]); AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]); h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)]; h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)]; }else{ AV_ZERO32(h->mv_cache [list][cache_idx ]); AV_ZERO32(h->mv_cache [list][cache_idx+8]); h->ref_cache[list][cache_idx ]= h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if(USES_LIST(topleft_type, list)){ const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride); const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (h->topleft_partition & h->b8_stride); AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]); h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]); h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if(USES_LIST(topright_type, list)){ const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride; AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]); h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]); h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF) continue; if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) { h->ref_cache[list][scan8[5 ]+1] = h->ref_cache[list][scan8[7 ]+1] = h->ref_cache[list][scan8[13]+1] = h->ref_cache[list][scan8[4 ]] = h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; AV_ZERO32(h->mv_cache [list][scan8[5 ]+1]); AV_ZERO32(h->mv_cache [list][scan8[7 ]+1]); AV_ZERO32(h->mv_cache [list][scan8[13]+1]); AV_ZERO32(h->mv_cache [list][scan8[4 ]]); AV_ZERO32(h->mv_cache [list][scan8[12]]); if( CABAC ) { if(USES_LIST(top_type, list)){ const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; AV_COPY128(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]); }else{ AV_ZERO128(h->mvd_cache[list][scan8[0] + 0 - 1*8]); } if(USES_LIST(left_type[0], list)){ const int b_xy= h->mb2b_xy[left_xy[0]] + 3; AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy + h->b_stride*left_block[0]]); AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy + h->b_stride*left_block[1]]); }else{ AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 0*8]); AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 1*8]); } if(USES_LIST(left_type[1], list)){ const int b_xy= h->mb2b_xy[left_xy[1]] + 3; AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy + h->b_stride*left_block[2]]); AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy + h->b_stride*left_block[3]]); }else{ AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 2*8]); AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 3*8]); } AV_ZERO32(h->mvd_cache [list][scan8[5 ]+1]); AV_ZERO32(h->mvd_cache [list][scan8[7 ]+1]); AV_ZERO32(h->mvd_cache [list][scan8[13]+1]); AV_ZERO32(h->mvd_cache [list][scan8[4 ]]); AV_ZERO32(h->mvd_cache [list][scan8[12]]); if(h->slice_type_nos == FF_B_TYPE){ fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1); if(IS_DIRECT(top_type)){ AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_DIRECT2>>1)); }else if(IS_8X8(top_type)){ int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride; h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy]; h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1]; }else{ AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1)); } if(IS_DIRECT(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[0])) h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)]; else h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1; if(IS_DIRECT(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1; else if(IS_8X8(left_type[1])) h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)]; else h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1; } } } if(FRAME_MBAFF){ #define MAP_MVS\ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) if(MB_FIELD){ #define MAP_F2F(idx, mb_type)\ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] <<= 1;\ h->mv_cache[list][idx][1] /= 2;\ h->mvd_cache[list][idx][1] /= 2;\ } MAP_MVS #undef MAP_F2F }else{ #define MAP_F2F(idx, mb_type)\ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ h->ref_cache[list][idx] >>= 1;\ h->mv_cache[list][idx][1] <<= 1;\ h->mvd_cache[list][idx][1] <<= 1;\ } MAP_MVS #undef MAP_F2F } } } } #endif h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); }
['static void decode_mb_skip(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int mb_type=0;\n memset(h->non_zero_count[mb_xy], 0, 32);\n memset(h->non_zero_count_cache + 8, 0, 8*5);\n if(MB_FIELD)\n mb_type|= MB_TYPE_INTERLACED;\n if( h->slice_type_nos == FF_B_TYPE )\n {\n mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;\n if(h->direct_spatial_mv_pred){\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n }\n ff_h264_pred_direct_motion(h, &mb_type);\n mb_type|= MB_TYPE_SKIP;\n }\n else\n {\n int mx, my;\n mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n pred_pskip_motion(h, &mx, &my);\n fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);\n fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4);\n }\n write_back_motion(h, mb_type);\n s->current_picture.mb_type[mb_xy]= mb_type;\n s->current_picture.qscale_table[mb_xy]= s->qscale;\n h->slice_table[ mb_xy ]= h->slice_num;\n h->prev_mb_skipped= 1;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n static const uint8_t left_block_options[4][16]={\n {0,1,2,3,7,10,8,11,7+0*8, 7+1*8, 7+2*8, 7+3*8, 2+0*8, 2+3*8, 2+1*8, 2+2*8},\n {2,2,3,3,8,11,8,11,7+2*8, 7+2*8, 7+3*8, 7+3*8, 2+1*8, 2+2*8, 2+1*8, 2+2*8},\n {0,0,1,1,7,10,7,10,7+0*8, 7+0*8, 7+1*8, 7+1*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8},\n {0,2,0,2,7,10,7,10,7+0*8, 7+2*8, 7+0*8, 7+2*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[1] = left_xy[0] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1);\n topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1);\n top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[0] = left_xy[0];\n h->left_mb_xy[1] = left_xy[1];\n h->topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0;\n h->top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;\n h->topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0;\n h->left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n int topleft_type, top_type, topright_type, left_type[2];\n const uint8_t * left_block= h->left_block;\n int i;\n topleft_xy = h->topleft_mb_xy ;\n top_xy = h->top_mb_xy ;\n topright_xy = h->topright_mb_xy;\n left_xy[0] = h->left_mb_xy[0] ;\n left_xy[1] = h->left_mb_xy[1] ;\n topleft_type = h->topleft_type ;\n top_type = h->top_type ;\n topright_type= h->topright_type ;\n left_type[0] = h->left_type[0] ;\n left_type[1] = h->left_type[1] ;\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[1] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num\n ? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0;\n assert(left_xy[0] == left_xy[1]);\n if(!((left_typei & type_mask) && (left_type[0] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4];\n h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];\n h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];\n h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];\n }else{\n int pred;\n if(!(top_type & type_mask))\n pred= -1;\n else{\n pred= 2;\n }\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= pred;\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[i])){\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];\n }else{\n int pred;\n if(!(left_type[i] & type_mask))\n pred= -1;\n else{\n pred= 2;\n }\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;\n }\n }\n }\n }\n if(top_type){\n AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]);\n h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8];\n h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8];\n h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8];\n h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8];\n }else {\n h->non_zero_count_cache[1+8*0]=\n h->non_zero_count_cache[2+8*0]=\n h->non_zero_count_cache[1+8*3]=\n h->non_zero_count_cache[2+8*3]=\n AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040);\n }\n for (i=0; i<2; i++) {\n if(left_type[i]){\n h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]];\n h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]];\n h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]];\n h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]];\n }else{\n h->non_zero_count_cache[3+8*1 + 2*8*i]=\n h->non_zero_count_cache[3+8*2 + 2*8*i]=\n h->non_zero_count_cache[0+8*1 + 8*i]=\n h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else if(IS_INTRA(mb_type)) {\n h->top_cbp = 0x1CF;\n } else {\n h->top_cbp = 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0;\n } else if(IS_INTRA(mb_type)) {\n h->left_cbp = 0x1CF;\n } else {\n h->left_cbp = 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1;\n }\n if (left_type[1]) {\n h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3;\n }\n }\n }\n#if 1\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n for(list=0; list<h->list_count; list++){\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n h->mv_cache_clean[list]= 0;\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;\n AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);\n h->ref_cache[list][scan8[0] + 0 - 1*8]=\n h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0];\n h->ref_cache[list][scan8[0] + 2 - 1*8]=\n h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1];\n }else{\n AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);\n AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n for(i=0; i<2; i++){\n int cache_idx = scan8[0] - 1 + i*2*8;\n if(USES_LIST(left_type[i], list)){\n const int b_xy= h->mb2b_xy[left_xy[i]] + 3;\n const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1;\n AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]);\n AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]);\n h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)];\n h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)];\n }else{\n AV_ZERO32(h->mv_cache [list][cache_idx ]);\n AV_ZERO32(h->mv_cache [list][cache_idx+8]);\n h->ref_cache[list][cache_idx ]=\n h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride);\n const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (h->topleft_partition & h->b8_stride);\n AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride;\n AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) {\n h->ref_cache[list][scan8[5 ]+1] =\n h->ref_cache[list][scan8[7 ]+1] =\n h->ref_cache[list][scan8[13]+1] =\n h->ref_cache[list][scan8[4 ]] =\n h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;\n AV_ZERO32(h->mv_cache [list][scan8[5 ]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[7 ]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[13]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mv_cache [list][scan8[12]]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n AV_COPY128(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]);\n }else{\n AV_ZERO128(h->mvd_cache[list][scan8[0] + 0 - 1*8]);\n }\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2b_xy[left_xy[0]] + 3;\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy + h->b_stride*left_block[0]]);\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy + h->b_stride*left_block[1]]);\n }else{\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 0*8]);\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 1*8]);\n }\n if(USES_LIST(left_type[1], list)){\n const int b_xy= h->mb2b_xy[left_xy[1]] + 3;\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy + h->b_stride*left_block[2]]);\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy + h->b_stride*left_block[3]]);\n }else{\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 2*8]);\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 3*8]);\n }\n AV_ZERO32(h->mvd_cache [list][scan8[5 ]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[7 ]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[13]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mvd_cache [list][scan8[12]]);\n if(h->slice_type_nos == FF_B_TYPE){\n fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride;\n h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy];\n h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1];\n }else{\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)];\n else\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)];\n else\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[1])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] /= 2;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n#endif\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]);\n}']
693
0
https://github.com/libav/libav/blob/2ee054c2153c32790851cc1095c50d3a89cf2dcc/libavformat/dv.c/#L121
static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4], const DVprofile *sys) { int size, chan, i, j, d, of, smpls, freq, quant, half_ch; uint16_t lc, rc; const uint8_t* as_pack; uint8_t *pcm, ipcm; as_pack = dv_extract_pack(frame, dv_audio_source); if (!as_pack) return 0; smpls = as_pack[1] & 0x3f; freq = (as_pack[4] >> 3) & 0x07; quant = as_pack[4] & 0x07; if (quant > 1) return -1; size = (sys->audio_min_samples[freq] + smpls) * 4; half_ch = sys->difseg_size / 2; ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0; pcm = ppcm[ipcm++]; for (chan = 0; chan < sys->n_difchan; chan++) { for (i = 0; i < sys->difseg_size; i++) { frame += 6 * 80; if (quant == 1 && i == half_ch) { pcm = ppcm[ipcm++]; if (!pcm) break; } for (j = 0; j < 9; j++) { for (d = 8; d < 80; d += 2) { if (quant == 0) { of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride; if (of*2 >= size) continue; pcm[of*2] = frame[d+1]; pcm[of*2+1] = frame[d]; if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) pcm[of*2+1] = 0; } else { lc = ((uint16_t)frame[d] << 4) | ((uint16_t)frame[d+2] >> 4); rc = ((uint16_t)frame[d+1] << 4) | ((uint16_t)frame[d+2] & 0x0f); lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride; if (of*2 >= size) continue; pcm[of*2] = lc & 0xff; pcm[of*2+1] = lc >> 8; of = sys->audio_shuffle[i%half_ch+half_ch][j] + (d - 8) / 3 * sys->audio_stride; pcm[of*2] = rc & 0xff; pcm[of*2+1] = rc >> 8; ++d; } } frame += 16 * 80; } } pcm = ppcm[ipcm++]; if (!pcm) break; } return size; }
['static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n int size;\n RawDVContext *c = s->priv_data;\n size = dv_get_packet(c->dv_demux, pkt);\n if (size < 0) {\n size = c->dv_demux->sys->frame_size;\n if (get_buffer(s->pb, c->buf, size) <= 0)\n return AVERROR(EIO);\n size = dv_produce_packet(c->dv_demux, pkt, c->buf, size);\n }\n return size;\n}', 'int get_buffer(ByteIOContext *s, unsigned char *buf, int size)\n{\n int len, size1;\n size1 = size;\n while (size > 0) {\n len = s->buf_end - s->buf_ptr;\n if (len > size)\n len = size;\n if (len == 0) {\n if(size > s->buffer_size && !s->update_checksum){\n if(s->read_packet)\n len = s->read_packet(s->opaque, buf, size);\n if (len <= 0) {\n s->eof_reached = 1;\n if(len<0)\n s->error= len;\n break;\n } else {\n s->pos += len;\n size -= len;\n buf += len;\n s->buf_ptr = s->buffer;\n s->buf_end = s->buffer ;\n }\n }else{\n fill_buffer(s);\n len = s->buf_end - s->buf_ptr;\n if (len == 0)\n break;\n }\n } else {\n memcpy(buf, s->buf_ptr, len);\n buf += len;\n s->buf_ptr += len;\n size -= len;\n }\n }\n return size1 - size;\n}', 'int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,\n uint8_t* buf, int buf_size)\n{\n int size, i;\n uint8_t *ppcm[4] = {0};\n if (buf_size < DV_PROFILE_BYTES ||\n !(c->sys = dv_frame_profile(buf)) ||\n buf_size < c->sys->frame_size) {\n return -1;\n }\n size = dv_extract_audio_info(c, buf);\n for (i = 0; i < c->ach; i++) {\n c->audio_pkt[i].size = size;\n c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;\n ppcm[i] = c->audio_buf[i];\n }\n dv_extract_audio(buf, ppcm, c->sys);\n c->abytes += size;\n if (c->sys->height == 720) {\n if (buf[1] & 0x0C)\n c->audio_pkt[2].size = c->audio_pkt[3].size = 0;\n else\n c->audio_pkt[0].size = c->audio_pkt[1].size = 0;\n }\n size = dv_extract_video_info(c, buf);\n av_init_packet(pkt);\n pkt->data = buf;\n pkt->size = size;\n pkt->flags |= PKT_FLAG_KEY;\n pkt->stream_index = c->vst->id;\n pkt->pts = c->frames;\n c->frames++;\n return size;\n}', 'static inline const DVprofile* dv_frame_profile(const uint8_t* frame)\n{\n int i;\n int dsf = (frame[3] & 0x80) >> 7;\n int stype = frame[80*5 + 48 + 3] & 0x1f;\n if (dsf == 1 && stype == 0 && frame[5] & 0x07) {\n return &dv_profiles[2];\n }\n for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)\n if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)\n return &dv_profiles[i];\n return NULL;\n}', 'static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4],\n const DVprofile *sys)\n{\n int size, chan, i, j, d, of, smpls, freq, quant, half_ch;\n uint16_t lc, rc;\n const uint8_t* as_pack;\n uint8_t *pcm, ipcm;\n as_pack = dv_extract_pack(frame, dv_audio_source);\n if (!as_pack)\n return 0;\n smpls = as_pack[1] & 0x3f;\n freq = (as_pack[4] >> 3) & 0x07;\n quant = as_pack[4] & 0x07;\n if (quant > 1)\n return -1;\n size = (sys->audio_min_samples[freq] + smpls) * 4;\n half_ch = sys->difseg_size / 2;\n ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0;\n pcm = ppcm[ipcm++];\n for (chan = 0; chan < sys->n_difchan; chan++) {\n for (i = 0; i < sys->difseg_size; i++) {\n frame += 6 * 80;\n if (quant == 1 && i == half_ch) {\n pcm = ppcm[ipcm++];\n if (!pcm)\n break;\n }\n for (j = 0; j < 9; j++) {\n for (d = 8; d < 80; d += 2) {\n if (quant == 0) {\n of = sys->audio_shuffle[i][j] + (d - 8) / 2 * sys->audio_stride;\n if (of*2 >= size)\n continue;\n pcm[of*2] = frame[d+1];\n pcm[of*2+1] = frame[d];\n if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)\n pcm[of*2+1] = 0;\n } else {\n lc = ((uint16_t)frame[d] << 4) |\n ((uint16_t)frame[d+2] >> 4);\n rc = ((uint16_t)frame[d+1] << 4) |\n ((uint16_t)frame[d+2] & 0x0f);\n lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));\n rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));\n of = sys->audio_shuffle[i%half_ch][j] + (d - 8) / 3 * sys->audio_stride;\n if (of*2 >= size)\n continue;\n pcm[of*2] = lc & 0xff;\n pcm[of*2+1] = lc >> 8;\n of = sys->audio_shuffle[i%half_ch+half_ch][j] +\n (d - 8) / 3 * sys->audio_stride;\n pcm[of*2] = rc & 0xff;\n pcm[of*2+1] = rc >> 8;\n ++d;\n }\n }\n frame += 16 * 80;\n }\n }\n pcm = ppcm[ipcm++];\n if (!pcm)\n break;\n }\n return size;\n}', 'static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)\n{\n int offs;\n switch (t) {\n case dv_audio_source:\n offs = (80*6 + 80*16*3 + 3);\n break;\n case dv_audio_control:\n offs = (80*6 + 80*16*4 + 3);\n break;\n case dv_video_control:\n offs = (80*5 + 48 + 5);\n break;\n default:\n return NULL;\n }\n return frame[offs] == t ? &frame[offs] : NULL;\n}']
694
0
https://github.com/openssl/openssl/blob/4973a60cb92dc121fc09246bff3815afc0f8ab9a/crypto/srp/srp_lib.c/#L191
BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass) { unsigned char dig[SHA_DIGEST_LENGTH]; EVP_MD_CTX *ctxt; unsigned char *cs; BIGNUM *res = NULL; if ((s == NULL) || (user == NULL) || (pass == NULL)) return NULL; ctxt = EVP_MD_CTX_new(); if (ctxt == NULL) return NULL; if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL) goto err; EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL); EVP_DigestUpdate(ctxt, user, strlen(user)); EVP_DigestUpdate(ctxt, ":", 1); EVP_DigestUpdate(ctxt, pass, strlen(pass)); EVP_DigestFinal_ex(ctxt, dig, NULL); EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL); BN_bn2bin(s, cs); EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)); OPENSSL_free(cs); EVP_DigestUpdate(ctxt, dig, sizeof(dig)); EVP_DigestFinal_ex(ctxt, dig, NULL); res = BN_bin2bn(dig, sizeof(dig), NULL); err: EVP_MD_CTX_free(ctxt); return res; }
['BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)\n{\n unsigned char dig[SHA_DIGEST_LENGTH];\n EVP_MD_CTX *ctxt;\n unsigned char *cs;\n BIGNUM *res = NULL;\n if ((s == NULL) || (user == NULL) || (pass == NULL))\n return NULL;\n ctxt = EVP_MD_CTX_new();\n if (ctxt == NULL)\n return NULL;\n if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)\n goto err;\n EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);\n EVP_DigestUpdate(ctxt, user, strlen(user));\n EVP_DigestUpdate(ctxt, ":", 1);\n EVP_DigestUpdate(ctxt, pass, strlen(pass));\n EVP_DigestFinal_ex(ctxt, dig, NULL);\n EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);\n BN_bn2bin(s, cs);\n EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s));\n OPENSSL_free(cs);\n EVP_DigestUpdate(ctxt, dig, sizeof(dig));\n EVP_DigestFinal_ex(ctxt, dig, NULL);\n res = BN_bin2bn(dig, sizeof(dig), NULL);\n err:\n EVP_MD_CTX_free(ctxt);\n return res;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
695
0
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L268
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int bn_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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
696
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 kempf_restore_buf(const uint8_t *src, int len,\n uint8_t *dst, int stride,\n const uint8_t *jpeg_tile, int tile_stride,\n int width, int height,\n const uint8_t *pal, int npal, int tidx)\n{\n BitstreamContext bc;\n int i, j, nb, col;\n int align_width = FFALIGN(width, 16);\n bitstream_init8(&bc, src, len);\n if (npal <= 2) nb = 1;\n else if (npal <= 4) nb = 2;\n else if (npal <= 16) nb = 4;\n else nb = 8;\n for (j = 0; j < height; j++, dst += stride, jpeg_tile += tile_stride) {\n if (bitstream_read(&bc, 8))\n continue;\n for (i = 0; i < width; i++) {\n col = bitstream_read(&bc, nb);\n if (col != tidx)\n memcpy(dst + i * 3, pal + col * 3, 3);\n else\n memcpy(dst + i * 3, jpeg_tile + i * 3, 3);\n }\n bitstream_skip(&bc, nb * (align_width - width));\n }\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
697
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L215
static int hpel_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h) { MotionEstContext * const c= &s->me; const int mx = *mx_ptr; const int my = *my_ptr; const int penalty_factor= c->sub_penalty_factor; me_cmp_func cmp_sub, chroma_cmp_sub; int bx=2*mx, by=2*my; LOAD_COMMON int flags= c->sub_flags; cmp_sub= s->dsp.me_sub_cmp[size]; chroma_cmp_sub= s->dsp.me_sub_cmp[size+1]; if(c->skip){ *mx_ptr = 0; *my_ptr = 0; return dmin; } if(c->avctx->me_cmp != c->avctx->me_sub_cmp){ dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags); if(mx || my || size>0) dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor; } if (mx > xmin && mx < xmax && my > ymin && my < ymax) { int d= dmin; const int index= (my<<ME_MAP_SHIFT) + mx; const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor; const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)] + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor; const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)] + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor; const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor; #if 1 int key; int map_generation= c->map_generation; #ifndef NDEBUG uint32_t *map= c->map; #endif key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation; assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key); key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation; assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key); key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation; assert(map[(index+1)&(ME_MAP_SIZE-1)] == key); key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation; assert(map[(index-1)&(ME_MAP_SIZE-1)] == key); #endif if(t<=b){ CHECK_HALF_MV(0, 1, mx ,my-1) if(l<=r){ CHECK_HALF_MV(1, 1, mx-1, my-1) if(t+r<=b+l){ CHECK_HALF_MV(1, 1, mx , my-1) }else{ CHECK_HALF_MV(1, 1, mx-1, my ) } CHECK_HALF_MV(1, 0, mx-1, my ) }else{ CHECK_HALF_MV(1, 1, mx , my-1) if(t+l<=b+r){ CHECK_HALF_MV(1, 1, mx-1, my-1) }else{ CHECK_HALF_MV(1, 1, mx , my ) } CHECK_HALF_MV(1, 0, mx , my ) } }else{ if(l<=r){ if(t+l<=b+r){ CHECK_HALF_MV(1, 1, mx-1, my-1) }else{ CHECK_HALF_MV(1, 1, mx , my ) } CHECK_HALF_MV(1, 0, mx-1, my) CHECK_HALF_MV(1, 1, mx-1, my) }else{ if(t+r<=b+l){ CHECK_HALF_MV(1, 1, mx , my-1) }else{ CHECK_HALF_MV(1, 1, mx-1, my) } CHECK_HALF_MV(1, 0, mx , my) CHECK_HALF_MV(1, 1, mx , my) } CHECK_HALF_MV(0, 1, mx , my) } assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2); } *mx_ptr = bx; *my_ptr = by; return dmin; }
['static int hpel_motion_search(MpegEncContext * s,\n int *mx_ptr, int *my_ptr, int dmin,\n int src_index, int ref_index,\n int size, int h)\n{\n MotionEstContext * const c= &s->me;\n const int mx = *mx_ptr;\n const int my = *my_ptr;\n const int penalty_factor= c->sub_penalty_factor;\n me_cmp_func cmp_sub, chroma_cmp_sub;\n int bx=2*mx, by=2*my;\n LOAD_COMMON\n int flags= c->sub_flags;\n cmp_sub= s->dsp.me_sub_cmp[size];\n chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];\n if(c->skip){\n *mx_ptr = 0;\n *my_ptr = 0;\n return dmin;\n }\n if(c->avctx->me_cmp != c->avctx->me_sub_cmp){\n dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\n if(mx || my || size>0)\n dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;\n }\n if (mx > xmin && mx < xmax &&\n my > ymin && my < ymax) {\n int d= dmin;\n const int index= (my<<ME_MAP_SHIFT) + mx;\n const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]\n + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;\n const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]\n + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;\n const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]\n + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;\n const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]\n + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;\n#if 1\n int key;\n int map_generation= c->map_generation;\n#ifndef NDEBUG\n uint32_t *map= c->map;\n#endif\n key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;\n assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);\n key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;\n assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);\n key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;\n assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);\n key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;\n assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);\n#endif\n if(t<=b){\n CHECK_HALF_MV(0, 1, mx ,my-1)\n if(l<=r){\n CHECK_HALF_MV(1, 1, mx-1, my-1)\n if(t+r<=b+l){\n CHECK_HALF_MV(1, 1, mx , my-1)\n }else{\n CHECK_HALF_MV(1, 1, mx-1, my )\n }\n CHECK_HALF_MV(1, 0, mx-1, my )\n }else{\n CHECK_HALF_MV(1, 1, mx , my-1)\n if(t+l<=b+r){\n CHECK_HALF_MV(1, 1, mx-1, my-1)\n }else{\n CHECK_HALF_MV(1, 1, mx , my )\n }\n CHECK_HALF_MV(1, 0, mx , my )\n }\n }else{\n if(l<=r){\n if(t+l<=b+r){\n CHECK_HALF_MV(1, 1, mx-1, my-1)\n }else{\n CHECK_HALF_MV(1, 1, mx , my )\n }\n CHECK_HALF_MV(1, 0, mx-1, my)\n CHECK_HALF_MV(1, 1, mx-1, my)\n }else{\n if(t+r<=b+l){\n CHECK_HALF_MV(1, 1, mx , my-1)\n }else{\n CHECK_HALF_MV(1, 1, mx-1, my)\n }\n CHECK_HALF_MV(1, 0, mx , my)\n CHECK_HALF_MV(1, 1, mx , my)\n }\n CHECK_HALF_MV(0, 1, mx , my)\n }\n assert(bx >= xmin*2 && bx <= xmax*2 && by >= ymin*2 && by <= ymax*2);\n }\n *mx_ptr = bx;\n *my_ptr = by;\n return dmin;\n}']
698
0
https://github.com/openssl/openssl/blob/b6a8916102b9bf84b33ade2030079d76d9ba60f6/crypto/mem.c/#L226
void CRYPTO_free(void *str, const char *file, int line) { if (free_impl != NULL && free_impl != &CRYPTO_free) { free_impl(str, file, line); return; } #ifndef OPENSSL_NO_CRYPTO_MDEBUG if (call_malloc_debug) { CRYPTO_mem_debug_free(str, 0, file, line); free(str); CRYPTO_mem_debug_free(str, 1, file, line); } else { free(str); } #else free(str); #endif }
['int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx)\n{\n if (!HMAC_CTX_reset(dctx))\n goto err;\n if (!EVP_MD_CTX_copy_ex(dctx->i_ctx, sctx->i_ctx))\n goto err;\n if (!EVP_MD_CTX_copy_ex(dctx->o_ctx, sctx->o_ctx))\n goto err;\n if (!EVP_MD_CTX_copy_ex(dctx->md_ctx, sctx->md_ctx))\n goto err;\n memcpy(dctx->key, sctx->key, HMAC_MAX_MD_CBLOCK);\n dctx->key_length = sctx->key_length;\n dctx->md = sctx->md;\n return 1;\n err:\n hmac_ctx_cleanup(dctx);\n return 0;\n}', 'int HMAC_CTX_reset(HMAC_CTX *ctx)\n{\n hmac_ctx_cleanup(ctx);\n if (ctx->i_ctx == NULL)\n ctx->i_ctx = EVP_MD_CTX_new();\n if (ctx->i_ctx == NULL)\n goto err;\n if (ctx->o_ctx == NULL)\n ctx->o_ctx = EVP_MD_CTX_new();\n if (ctx->o_ctx == NULL)\n goto err;\n if (ctx->md_ctx == NULL)\n ctx->md_ctx = EVP_MD_CTX_new();\n if (ctx->md_ctx == NULL)\n goto err;\n ctx->md = NULL;\n return 1;\n err:\n hmac_ctx_cleanup(ctx);\n return 0;\n}', 'static void hmac_ctx_cleanup(HMAC_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx->i_ctx);\n EVP_MD_CTX_reset(ctx->o_ctx);\n EVP_MD_CTX_reset(ctx->md_ctx);\n ctx->md = NULL;\n ctx->key_length = 0;\n memset(ctx->key, 0, sizeof(HMAC_MAX_MD_CBLOCK));\n}', 'int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)\n{\n if (ctx == NULL)\n return 1;\n if (ctx->digest && ctx->digest->cleanup\n && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))\n ctx->digest->cleanup(ctx);\n if (ctx->digest && ctx->digest->ctx_size && ctx->md_data\n && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {\n OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);\n }\n EVP_PKEY_CTX_free(ctx->pctx);\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(ctx->engine);\n#endif\n memset(ctx, 0, sizeof(*ctx));\n return 1;\n}', 'void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n if (ctx->pmeth && ctx->pmeth->cleanup)\n ctx->pmeth->cleanup(ctx);\n EVP_PKEY_free(ctx->pkey);\n EVP_PKEY_free(ctx->peerkey);\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(ctx->engine);\n#endif\n OPENSSL_free(ctx);\n}', 'void EVP_PKEY_free(EVP_PKEY *x)\n{\n int i;\n if (x == NULL)\n return;\n i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);\n REF_PRINT_COUNT("EVP_PKEY", x);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n EVP_PKEY_free_it(x);\n sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);\n OPENSSL_free(x);\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}']
699
0
https://github.com/openssl/openssl/blob/8f0edcb3d28f3b8d96e10ad24e46d9e43bd1aab5/crypto/x509/x509_cmp.c/#L272
int X509_check_private_key(X509 *x, EVP_PKEY *k) { EVP_PKEY *xk=NULL; int ok=0; xk=X509_get_pubkey(x); if (xk->type != k->type) { X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH); goto err; } switch (k->type) { #ifndef OPENSSL_NO_RSA case EVP_PKEY_RSA: if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0) { X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH); goto err; } break; #endif #ifndef OPENSSL_NO_DSA case EVP_PKEY_DSA: if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0) { X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH); goto err; } break; #endif #ifndef OPENSSL_NO_DH case EVP_PKEY_DH: X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY); goto err; #endif default: X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE); goto err; } ok=1; err: EVP_PKEY_free(xk); return(ok); }
['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 OPENSSL_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 OPENSSL_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 OPENSSL_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 OPENSSL_NO_DSA\n\tconst unsigned char *cp;\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 OPENSSL_NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tcp=p=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'int OBJ_obj2nid(const ASN1_OBJECT *a)\n\t{\n\tASN1_OBJECT **op;\n\tADDED_OBJ ad,*adp;\n\tif (a == NULL)\n\t\treturn(NID_undef);\n\tif (a->nid != 0)\n\t\treturn(a->nid);\n\tif (added != NULL)\n\t\t{\n\t\tad.type=ADDED_DATA;\n\t\tad.obj=(ASN1_OBJECT *)a;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL) return (adp->obj->nid);\n\t\t}\n\top=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,\n\t\tsizeof(ASN1_OBJECT *),obj_cmp);\n\tif (op == NULL)\n\t\treturn(NID_undef);\n\treturn((*op)->nid);\n\t}', 'void *lh_retrieve(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE **rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_retrieve_miss++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\tlh->num_retrieve++;\n\t\t}\n\treturn((void *)ret);\n\t}', 'EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,\n\t long length)\n\t{\n\tEVP_PKEY *ret;\n\tif ((a == NULL) || (*a == NULL))\n\t\t{\n\t\tif ((ret=EVP_PKEY_new()) == NULL)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\telse\tret= *a;\n\tret->save_type=type;\n\tret->type=EVP_PKEY_type(type);\n\tswitch (ret->type)\n\t\t{\n#ifndef OPENSSL_NO_RSA\n\tcase EVP_PKEY_RSA:\n\t\tif ((ret->pkey.rsa=d2i_RSAPublicKey(NULL,\n\t\t\t(const unsigned char **)pp,length)) == NULL)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_DSA\n\tcase EVP_PKEY_DSA:\n\t\tif ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,\n\t\t\t(const unsigned char **)pp,length)) == NULL)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tbreak;\n#endif\n\tdefault:\n\t\tASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (a != NULL) (*a)=ret;\n\treturn(ret);\nerr:\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret);\n\treturn(NULL);\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_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}']
700
0
https://github.com/openssl/openssl/blob/cacd830f02736aeb6ee26a742c61b3df39b62195/crypto/x509v3/v3_utl.c/#L505
static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens) { STACK *ret = NULL; X509_NAME_ENTRY *ne; ASN1_IA5STRING *email; GENERAL_NAME *gen; int i; i = -1; while((i = X509_NAME_get_index_by_NID(name, NID_pkcs9_emailAddress, i)) >= 0) { ne = X509_NAME_get_entry(name, i); email = X509_NAME_ENTRY_get_data(ne); if(!append_ia5(&ret, email)) return NULL; } for(i = 0; i < sk_GENERAL_NAME_num(gens); i++) { gen = sk_GENERAL_NAME_value(gens, i); if(gen->type != GEN_EMAIL) continue; if(!append_ia5(&ret, gen->d.ia5)) return NULL; } return ret; }
['static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)\n{\n\tSTACK *ret = NULL;\n\tX509_NAME_ENTRY *ne;\n\tASN1_IA5STRING *email;\n\tGENERAL_NAME *gen;\n\tint i;\n\ti = -1;\n\twhile((i = X509_NAME_get_index_by_NID(name,\n\t\t\t\t\t NID_pkcs9_emailAddress, i)) >= 0) {\n\t\tne = X509_NAME_get_entry(name, i);\n\t\temail = X509_NAME_ENTRY_get_data(ne);\n\t\tif(!append_ia5(&ret, email)) return NULL;\n\t}\n\tfor(i = 0; i < sk_GENERAL_NAME_num(gens); i++)\n\t{\n\t\tgen = sk_GENERAL_NAME_value(gens, i);\n\t\tif(gen->type != GEN_EMAIL) continue;\n\t\tif(!append_ia5(&ret, gen->d.ia5)) return NULL;\n\t}\n\treturn ret;\n}', 'int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)\n\t{\n\tASN1_OBJECT *obj;\n\tobj=OBJ_nid2obj(nid);\n\tif (obj == NULL) return(-2);\n\treturn(X509_NAME_get_index_by_OBJ(name,obj,lastpos));\n\t}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn((ASN1_OBJECT *)&(nid_objs[n]));\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}', 'X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)\n\t{\n\tif(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc\n\t || loc < 0)\n\t\treturn(NULL);\n\telse\n\t\treturn(sk_X509_NAME_ENTRY_value(name->entries,loc));\n\t}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}', 'ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)\n\t{\n\tif (ne == NULL) return(NULL);\n\treturn(ne->value);\n\t}', 'static int append_ia5(STACK **sk, ASN1_IA5STRING *email)\n{\n\tchar *emtmp;\n\tif(email->type != V_ASN1_IA5STRING) return 1;\n\tif(!email->data || !email->length) return 1;\n\tif(!*sk) *sk = sk_new(sk_strcmp);\n\tif(!*sk) return 0;\n\tif(sk_find(*sk, (char *)email->data) != -1) return 1;\n\temtmp = BUF_strdup((char *)email->data);\n\tif(!emtmp || !sk_push(*sk, emtmp)) {\n\t\tX509_email_free(*sk);\n\t\t*sk = NULL;\n\t\treturn 0;\n\t}\n\treturn 1;\n}']