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
36,101
0
https://github.com/openssl/openssl/blob/38f5c30b311f0e736081e0b64b22e917b651536a/ssl/packet.c/#L49
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes) { assert(pkt->subs != NULL && len != 0); if (pkt->subs == NULL || len == 0) return 0; if (pkt->maxsize - pkt->written < len) return 0; if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) { size_t newlen; size_t reflen; reflen = (len > pkt->buf->length) ? len : pkt->buf->length; if (reflen > SIZE_MAX / 2) { newlen = SIZE_MAX; } else { newlen = reflen * 2; if (newlen < DEFAULT_BUF_SIZE) newlen = DEFAULT_BUF_SIZE; } if (BUF_MEM_grow(pkt->buf, newlen) == 0) return 0; } if (allocbytes != NULL) *allocbytes = WPACKET_get_curr(pkt); return 1; }
['int tls_construct_stoc_ec_pt_formats(SSL *s, WPACKET *pkt, unsigned int context,\n X509 *x, size_t chainidx, int *al)\n{\n unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth;\n int using_ecc = ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))\n && (s->session->ext.ecpointformats != NULL);\n const unsigned char *plist;\n size_t plistlen;\n if (!using_ecc)\n return 1;\n tls1_get_formatlist(s, &plist, &plistlen);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u8(pkt, plist, plistlen)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_STOC_EC_PT_FORMATS, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n return 1;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n assert(size <= sizeof(unsigned int));\n if (size > sizeof(unsigned int)\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,\n size_t lenbytes)\n{\n if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)\n || !WPACKET_memcpy(pkt, src, len)\n || !WPACKET_close(pkt))\n return 0;\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n assert(pkt->subs != NULL && len != 0);\n if (pkt->subs == NULL || len == 0)\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
36,102
0
https://github.com/libav/libav/blob/ec2ac9271c91633e5d88551867a7f03bb81852f1/libavcodec/h264.c/#L348
static void await_references(H264Context *h){ MpegEncContext * const s = &h->s; const int mb_xy= h->mb_xy; const int mb_type = s->current_picture.f.mb_type[mb_xy]; int refs[2][48]; int nrefs[2] = {0}; int ref, list; memset(refs, -1, sizeof(refs)); if(IS_16X16(mb_type)){ get_lowest_part_y(h, refs, 0, 16, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); }else if(IS_16X8(mb_type)){ get_lowest_part_y(h, refs, 0, 8, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, 8, 8, 8, IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); }else if(IS_8X16(mb_type)){ get_lowest_part_y(h, refs, 0, 16, 0, IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, 4, 16, 0, IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); }else{ int i; assert(IS_8X8(mb_type)); for(i=0; i<4; i++){ const int sub_mb_type= h->sub_mb_type[i]; const int n= 4*i; int y_offset= (i&2)<<2; if(IS_SUB_8X8(sub_mb_type)){ get_lowest_part_y(h, refs, n , 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); }else if(IS_SUB_8X4(sub_mb_type)){ get_lowest_part_y(h, refs, n , 4, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, n+2, 4, y_offset+4, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); }else if(IS_SUB_4X8(sub_mb_type)){ get_lowest_part_y(h, refs, n , 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); get_lowest_part_y(h, refs, n+1, 8, y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); }else{ int j; assert(IS_SUB_4X4(sub_mb_type)); for(j=0; j<4; j++){ int sub_y_offset= y_offset + 2*(j&2); get_lowest_part_y(h, refs, n+j, 4, sub_y_offset, IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); } } } } for(list=h->list_count-1; list>=0; list--){ for(ref=0; ref<48 && nrefs[list]; ref++){ int row = refs[list][ref]; if(row >= 0){ Picture *ref_pic = &h->ref_list[list][ref]; int ref_field = ref_pic->f.reference - 1; int ref_field_picture = ref_pic->field_picture; int pic_height = 16*s->mb_height >> ref_field_picture; row <<= MB_MBAFF; nrefs[list]--; if(!FIELD_PICTURE && ref_field_picture){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1); ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0); }else if(FIELD_PICTURE && !ref_field_picture){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0); }else if(FIELD_PICTURE){ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field); }else{ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0); } } } } }
['static int decode_slice(struct AVCodecContext *avctx, void *arg){\n H264Context *h = *(void**)arg;\n MpegEncContext * const s = &h->s;\n const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;\n int lf_x_start = s->mb_x;\n s->mb_skip_run= -1;\n h->is_complex = FRAME_MBAFF || s->picture_structure != PICT_FRAME || s->codec_id != CODEC_ID_H264 ||\n (CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY));\n if( h->pps.cabac ) {\n align_get_bits( &s->gb );\n ff_init_cabac_states( &h->cabac);\n ff_init_cabac_decoder( &h->cabac,\n s->gb.buffer + get_bits_count(&s->gb)/8,\n (get_bits_left(&s->gb) + 7)/8);\n ff_h264_init_cabac_states(h);\n for(;;){\n int ret = ff_h264_decode_mb_cabac(h);\n int eos;\n if(ret>=0) ff_h264_hl_decode_mb(h);\n if( ret >= 0 && FRAME_MBAFF ) {\n s->mb_y++;\n ret = ff_h264_decode_mb_cabac(h);\n if(ret>=0) ff_h264_hl_decode_mb(h);\n s->mb_y--;\n }\n eos = get_cabac_terminate( &h->cabac );\n if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n if (s->mb_x >= lf_x_start) loop_filter(h, lf_x_start, s->mb_x + 1);\n return 0;\n }\n if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) {\n av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n if( ++s->mb_x >= s->mb_width ) {\n loop_filter(h, lf_x_start, s->mb_x);\n s->mb_x = lf_x_start = 0;\n decode_finish_row(h);\n ++s->mb_y;\n if(FIELD_OR_MBAFF_PICTURE) {\n ++s->mb_y;\n if(FRAME_MBAFF && s->mb_y < s->mb_height)\n predict_field_decoding_flag(h);\n }\n }\n if( eos || s->mb_y >= s->mb_height ) {\n tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);\n return 0;\n }\n }\n } else {\n for(;;){\n int ret = ff_h264_decode_mb_cavlc(h);\n if(ret>=0) ff_h264_hl_decode_mb(h);\n if(ret>=0 && FRAME_MBAFF){\n s->mb_y++;\n ret = ff_h264_decode_mb_cavlc(h);\n if(ret>=0) ff_h264_hl_decode_mb(h);\n s->mb_y--;\n }\n if(ret<0){\n av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\\n", s->mb_x, s->mb_y);\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n if(++s->mb_x >= s->mb_width){\n loop_filter(h, lf_x_start, s->mb_x);\n s->mb_x = lf_x_start = 0;\n decode_finish_row(h);\n ++s->mb_y;\n if(FIELD_OR_MBAFF_PICTURE) {\n ++s->mb_y;\n if(FRAME_MBAFF && s->mb_y < s->mb_height)\n predict_field_decoding_flag(h);\n }\n if(s->mb_y >= s->mb_height){\n tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return 0;\n }else{\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n return -1;\n }\n }\n }\n if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){\n tprintf(s->avctx, "slice end %d %d\\n", get_bits_count(&s->gb), s->gb.size_in_bits);\n if(get_bits_count(&s->gb) == s->gb.size_in_bits ){\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);\n if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x);\n return 0;\n }else{\n ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);\n return -1;\n }\n }\n }\n }\n}', 'int ff_h264_decode_mb_cabac(H264Context *h) {\n MpegEncContext * const s = &h->s;\n int mb_xy;\n int mb_type, partition_count, cbp = 0;\n int dct8x8_allowed= h->pps.transform_8x8_mode;\n int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\n mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;\n tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n if( h->slice_type_nos != AV_PICTURE_TYPE_I ) {\n int skip;\n if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )\n skip = h->next_mb_skipped;\n else\n skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );\n if( skip ) {\n if( FRAME_MBAFF && (s->mb_y&1)==0 ){\n s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP;\n h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );\n if(!h->next_mb_skipped)\n h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n }\n decode_mb_skip(h);\n h->cbp_table[mb_xy] = 0;\n h->chroma_pred_mode_table[mb_xy] = 0;\n h->last_qscale_diff = 0;\n return 0;\n }\n }\n if(FRAME_MBAFF){\n if( (s->mb_y&1) == 0 )\n h->mb_mbaff =\n h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n }\n h->prev_mb_skipped = 0;\n fill_decode_neighbors(h, -(MB_FIELD));\n if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n int ctx = 0;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_B);\n if( !IS_DIRECT( h->left_type[LTOP]-1 ) )\n ctx++;\n if( !IS_DIRECT( h->top_type-1 ) )\n ctx++;\n if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){\n mb_type= 0;\n }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {\n mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n }else{\n int bits;\n bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;\n bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;\n bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;\n bits+= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n if( bits < 8 ){\n mb_type= bits + 3;\n }else if( bits == 13 ){\n mb_type= decode_cabac_intra_mb_type(h, 32, 0);\n goto decode_intra_mb;\n }else if( bits == 14 ){\n mb_type= 11;\n }else if( bits == 15 ){\n mb_type= 22;\n }else{\n bits= ( bits<<1 ) + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n mb_type= bits - 4;\n }\n }\n partition_count= b_mb_type_info[mb_type].partition_count;\n mb_type= b_mb_type_info[mb_type].type;\n } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) {\n if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {\n if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {\n mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );\n } else {\n mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );\n }\n partition_count= p_mb_type_info[mb_type].partition_count;\n mb_type= p_mb_type_info[mb_type].type;\n } else {\n mb_type= decode_cabac_intra_mb_type(h, 17, 0);\n goto decode_intra_mb;\n }\n } else {\n mb_type= decode_cabac_intra_mb_type(h, 3, 1);\n if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\ndecode_intra_mb:\n partition_count = 0;\n cbp= i_mb_type_info[mb_type].cbp;\n h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n mb_type= i_mb_type_info[mb_type].type;\n }\n if(MB_FIELD)\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[ mb_xy ]= h->slice_num;\n if(IS_INTRA_PCM(mb_type)) {\n static const uint16_t mb_sizes[4] = {256,384,512,768};\n const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;\n const uint8_t *ptr;\n ptr= h->cabac.bytestream;\n if(h->cabac.low&0x1) ptr--;\n if(CABAC_BITS==16){\n if(h->cabac.low&0x1FF) ptr--;\n }\n memcpy(h->mb, ptr, mb_size); ptr+=mb_size;\n ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n h->cbp_table[mb_xy] = 0xf7ef;\n h->chroma_pred_mode_table[mb_xy] = 0;\n s->current_picture.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 h->last_qscale_diff = 0;\n return 0;\n }\n if(MB_MBAFF){\n h->ref_count[0] <<= 1;\n h->ref_count[1] <<= 1;\n }\n fill_decode_caches(h, mb_type);\n if( IS_INTRA( mb_type ) ) {\n int i, pred_mode;\n if( IS_INTRA4x4( mb_type ) ) {\n if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {\n mb_type |= MB_TYPE_8x8DCT;\n for( i = 0; i < 16; i+=4 ) {\n int pred = pred_intra_mode( h, i );\n int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n }\n } else {\n for( i = 0; i < 16; i++ ) {\n int pred = pred_intra_mode( h, i );\n h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n }\n }\n write_back_intra_pred_mode(h);\n if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;\n } else {\n h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode );\n if( h->intra16x16_pred_mode < 0 ) return -1;\n }\n if(decode_chroma){\n h->chroma_pred_mode_table[mb_xy] =\n pred_mode = decode_cabac_mb_chroma_pre_mode( h );\n pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode );\n if( pred_mode < 0 ) return -1;\n h->chroma_pred_mode= pred_mode;\n } else {\n h->chroma_pred_mode= DC_128_PRED8x8;\n }\n } else if( partition_count == 4 ) {\n int i, j, sub_partition_count[4], list, ref[2][4];\n if( h->slice_type_nos == AV_PICTURE_TYPE_B ) {\n for( i = 0; i < 4; i++ ) {\n h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );\n sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |\n h->sub_mb_type[2] | h->sub_mb_type[3]) ) {\n ff_h264_pred_direct_motion(h, &mb_type);\n h->ref_cache[0][scan8[4]] =\n h->ref_cache[1][scan8[4]] =\n h->ref_cache[0][scan8[12]] =\n h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n for( i = 0; i < 4; i++ )\n fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );\n }\n } else {\n for( i = 0; i < 4; i++ ) {\n h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );\n sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n }\n for( list = 0; list < h->list_count; list++ ) {\n for( i = 0; i < 4; i++ ) {\n if(IS_DIRECT(h->sub_mb_type[i])) continue;\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n if( h->ref_count[list] > 1 ){\n ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );\n if(ref[list][i] >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], h->ref_count[list]);\n return -1;\n }\n }else\n ref[list][i] = 0;\n } else {\n ref[list][i] = -1;\n }\n h->ref_cache[list][ scan8[4*i]+1 ]=\n h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h);\n for(list=0; list<h->list_count; list++){\n for(i=0; i<4; i++){\n h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];\n if(IS_DIRECT(h->sub_mb_type[i])){\n fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 2);\n continue;\n }\n if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){\n const int sub_mb_type= h->sub_mb_type[i];\n const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n for(j=0; j<sub_partition_count[i]; j++){\n int mpx, mpy;\n int mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, index)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n if(IS_SUB_8X8(sub_mb_type)){\n mv_cache[ 1 ][0]=\n mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n mv_cache[ 1 ][1]=\n mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n mvd_cache[ 1 ][0]=\n mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n mvd_cache[ 1 ][1]=\n mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n mvd_cache[ 1 ][0]= mpx;\n mvd_cache[ 1 ][1]= mpy;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n mvd_cache[ 8 ][0]= mpx;\n mvd_cache[ 8 ][1]= mpy;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n mvd_cache[ 0 ][0]= mpx;\n mvd_cache[ 0 ][1]= mpy;\n }\n }else{\n fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\n }\n }\n }\n } else if( IS_DIRECT(mb_type) ) {\n ff_h264_pred_direct_motion(h, &mb_type);\n fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 2);\n fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n } else {\n int list, i;\n if(IS_16X16(mb_type)){\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref(h, list, 0);\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int mx,my,mpx,mpy;\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 0)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }\n }\n }\n else if(IS_16X8(mb_type)){\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref( h, list, 8*i );\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int mx,my,mpx,mpy;\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 8*i)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 2);\n fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n }\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref( h, list, 4*i );\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int mx,my,mpx,mpy;\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 4*i)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 2);\n fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n }\n }\n }\n }\n }\n if( IS_INTER( mb_type ) ) {\n h->chroma_pred_mode_table[mb_xy] = 0;\n write_back_motion( h, mb_type );\n }\n if( !IS_INTRA16x16( mb_type ) ) {\n cbp = decode_cabac_mb_cbp_luma( h );\n if(decode_chroma)\n cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;\n }\n h->cbp_table[mb_xy] = h->cbp = cbp;\n if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );\n }\n if (CHROMA444 && IS_8x8DCT(mb_type)){\n int i;\n uint8_t *nnz_cache = h->non_zero_count_cache;\n for (i = 0; i < 2; i++){\n if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n }\n }\n if (h->top_type && !IS_8x8DCT(h->top_type)){\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n }\n s->current_picture.f.mb_type[mb_xy] = mb_type;\n if( cbp || IS_INTRA16x16( mb_type ) ) {\n const uint8_t *scan, *scan8x8;\n const uint32_t *qmul;\n if(IS_INTERLACED(mb_type)){\n scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n scan= s->qscale ? h->field_scan : h->field_scan_q0;\n }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n }\n if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){\n int val = 1;\n int ctx= 2;\n const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n ctx= 3;\n val++;\n if(val > 2*max_qp){\n av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", s->mb_x, s->mb_y);\n return -1;\n }\n }\n if( val&0x01 )\n val= (val + 1)>>1 ;\n else\n val= -((val + 1)>>1);\n h->last_qscale_diff = val;\n s->qscale += val;\n if(((unsigned)s->qscale) > max_qp){\n if(s->qscale<0) s->qscale+= max_qp+1;\n else s->qscale-= max_qp+1;\n }\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n }else\n h->last_qscale_diff=0;\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n if(CHROMA444){\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n } else {\n if( cbp&0x30 ){\n int c;\n for( c = 0; c < 2; c++ ) {\n decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4);\n }\n }\n if( cbp&0x20 ) {\n int c, i;\n for( c = 0; c < 2; c++ ) {\n qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n for( i = 0; i < 4; i++ ) {\n const int index = 16 + 16 * c + i;\n decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n h->last_qscale_diff = 0;\n }\n s->current_picture.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}', 'void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){\n if(h->direct_spatial_mv_pred){\n pred_spatial_direct_motion(h, mb_type);\n }else{\n pred_temp_direct_motion(h, mb_type);\n }\n}', 'void ff_h264_hl_decode_mb(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;\n if (CHROMA444) {\n if(is_complex || h->pixel_shift)\n hl_decode_mb_444_complex(h);\n else\n hl_decode_mb_444_simple(h);\n } else if (is_complex) {\n hl_decode_mb_complex(h);\n } else if (h->pixel_shift) {\n hl_decode_mb_simple_16(h);\n } else\n hl_decode_mb_simple_8(h);\n}', 'static void av_noinline hl_decode_mb_444_complex(H264Context *h){\n hl_decode_mb_444_internal(h, 0, h->pixel_shift);\n}', 'static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simple, int pixel_shift){\n MpegEncContext * const s = &h->s;\n const int mb_x= s->mb_x;\n const int mb_y= s->mb_y;\n const int mb_xy= h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n uint8_t *dest[3];\n int linesize;\n int i, j, p;\n int *block_offset = &h->block_offset[0];\n const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);\n const int plane_count = (simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) ? 3 : 1;\n for (p = 0; p < plane_count; p++)\n {\n dest[p] = s->current_picture.f.data[p] + ((mb_x << pixel_shift) + mb_y * s->linesize) * 16;\n s->dsp.prefetch(dest[p] + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4);\n }\n h->list_counts[mb_xy]= h->list_count;\n if (!simple && MB_FIELD) {\n linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2;\n block_offset = &h->block_offset[48];\n if(mb_y&1)\n for (p = 0; p < 3; p++)\n dest[p] -= s->linesize*15;\n if(FRAME_MBAFF) {\n int list;\n for(list=0; list<h->list_count; list++){\n if(!USES_LIST(mb_type, list))\n continue;\n if(IS_16X16(mb_type)){\n int8_t *ref = &h->ref_cache[list][scan8[0]];\n fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1);\n }else{\n for(i=0; i<16; i+=4){\n int ref = h->ref_cache[list][scan8[i]];\n if(ref >= 0)\n fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1);\n }\n }\n }\n }\n } else {\n linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize;\n }\n if (!simple && IS_INTRA_PCM(mb_type)) {\n if (pixel_shift) {\n const int bit_depth = h->sps.bit_depth_luma;\n GetBitContext gb;\n init_get_bits(&gb, (uint8_t*)h->mb, 768*bit_depth);\n for (p = 0; p < plane_count; p++) {\n for (i = 0; i < 16; i++) {\n uint16_t *tmp = (uint16_t*)(dest[p] + i*linesize);\n for (j = 0; j < 16; j++)\n tmp[j] = get_bits(&gb, bit_depth);\n }\n }\n } else {\n for (p = 0; p < plane_count; p++) {\n for (i = 0; i < 16; i++) {\n memcpy(dest[p] + i*linesize, h->mb + p*128 + i*8, 16);\n }\n }\n }\n } else {\n if(IS_INTRA(mb_type)){\n if(h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 1, 1, simple, pixel_shift);\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_predict_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n if(h->deblocking_filter)\n xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift);\n }else{\n hl_motion(h, dest[0], dest[1], dest[2],\n s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n h->h264dsp.weight_h264_pixels_tab,\n h->h264dsp.biweight_h264_pixels_tab, pixel_shift, 1);\n }\n for (p = 0; p < plane_count; p++)\n hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n }\n if(h->cbp || IS_INTRA(mb_type))\n {\n s->dsp.clear_blocks(h->mb);\n s->dsp.clear_blocks(h->mb+(24*16<<pixel_shift));\n }\n}', 'static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,\n qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),\n qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),\n h264_weight_func *weight_op, h264_biweight_func *weight_avg,\n int pixel_shift, int chroma444){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n assert(IS_INTER(mb_type));\n if(HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n await_references(h);\n prefetch_motion(h, 0, pixel_shift, chroma444);\n if(IS_16X16(mb_type)){\n mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],\n weight_op, weight_avg,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_16X8(mb_type)){\n mc_part(h, 0, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n &weight_op[1], &weight_avg[1],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, 8, 0, 4, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,\n qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n &weight_op[1], &weight_avg[1],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma444);\n }else if(IS_8X16(mb_type)){\n mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[2], &weight_avg[2],\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[2], &weight_avg[2],\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n pixel_shift, chroma444);\n }else{\n int i;\n assert(IS_8X8(mb_type));\n for(i=0; i<4; i++){\n const int sub_mb_type= h->sub_mb_type[i];\n const int n= 4*i;\n int x_offset= (i&1)<<2;\n int y_offset= (i&2)<<1;\n if(IS_SUB_8X8(sub_mb_type)){\n mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n &weight_op[3], &weight_avg[3],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_SUB_8X4(sub_mb_type)){\n mc_part(h, n , 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[4], &weight_avg[4],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, n+2, 0, 2, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,\n qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n &weight_op[4], &weight_avg[4],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else if(IS_SUB_4X8(sub_mb_type)){\n mc_part(h, n , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[5], &weight_avg[5],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[5], &weight_avg[5],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }else{\n int j;\n assert(IS_SUB_4X4(sub_mb_type));\n for(j=0; j<4; j++){\n int sub_x_offset= x_offset + 2*(j&1);\n int sub_y_offset= y_offset + (j&2);\n mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,\n qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n &weight_op[6], &weight_avg[6],\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n pixel_shift, chroma444);\n }\n }\n }\n }\n prefetch_motion(h, 1, pixel_shift, chroma444);\n}', 'static void await_references(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n const int mb_type = s->current_picture.f.mb_type[mb_xy];\n int refs[2][48];\n int nrefs[2] = {0};\n int ref, list;\n memset(refs, -1, sizeof(refs));\n if(IS_16X16(mb_type)){\n get_lowest_part_y(h, refs, 0, 16, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n }else if(IS_16X8(mb_type)){\n get_lowest_part_y(h, refs, 0, 8, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, 8, 8, 8,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n }else if(IS_8X16(mb_type)){\n get_lowest_part_y(h, refs, 0, 16, 0,\n IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, 4, 16, 0,\n IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n }else{\n int i;\n assert(IS_8X8(mb_type));\n for(i=0; i<4; i++){\n const int sub_mb_type= h->sub_mb_type[i];\n const int n= 4*i;\n int y_offset= (i&2)<<2;\n if(IS_SUB_8X8(sub_mb_type)){\n get_lowest_part_y(h, refs, n , 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }else if(IS_SUB_8X4(sub_mb_type)){\n get_lowest_part_y(h, refs, n , 4, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, n+2, 4, y_offset+4,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }else if(IS_SUB_4X8(sub_mb_type)){\n get_lowest_part_y(h, refs, n , 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n get_lowest_part_y(h, refs, n+1, 8, y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }else{\n int j;\n assert(IS_SUB_4X4(sub_mb_type));\n for(j=0; j<4; j++){\n int sub_y_offset= y_offset + 2*(j&2);\n get_lowest_part_y(h, refs, n+j, 4, sub_y_offset,\n IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n }\n }\n }\n }\n for(list=h->list_count-1; list>=0; list--){\n for(ref=0; ref<48 && nrefs[list]; ref++){\n int row = refs[list][ref];\n if(row >= 0){\n Picture *ref_pic = &h->ref_list[list][ref];\n int ref_field = ref_pic->f.reference - 1;\n int ref_field_picture = ref_pic->field_picture;\n int pic_height = 16*s->mb_height >> ref_field_picture;\n row <<= MB_MBAFF;\n nrefs[list]--;\n if(!FIELD_PICTURE && ref_field_picture){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0);\n }else if(FIELD_PICTURE && !ref_field_picture){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0);\n }else if(FIELD_PICTURE){\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);\n }else{\n ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);\n }\n }\n }\n }\n}']
36,103
0
https://github.com/nginx/nginx/blob/a0caa70c98fcda923970c9edcf8caad60cb8e40a/src/http/modules/ngx_http_geo_module.c/#L352
static char * ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { char *rv; size_t len; ngx_str_t *value, name; ngx_uint_t i; ngx_conf_t save; ngx_pool_t *pool; ngx_array_t *a; ngx_http_variable_t *var; ngx_http_geo_ctx_t *geo; ngx_http_geo_conf_ctx_t ctx; value = cf->args->elts; geo = ngx_palloc(cf->pool, sizeof(ngx_http_geo_ctx_t)); if (geo == NULL) { return NGX_CONF_ERROR; } name = value[1]; if (name.data[0] != '$') { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid variable name \"%V\"", &name); return NGX_CONF_ERROR; } name.len--; name.data++; if (cf->args->nelts == 3) { geo->index = ngx_http_get_variable_index(cf, &name); if (geo->index == NGX_ERROR) { return NGX_CONF_ERROR; } name = value[2]; if (name.data[0] != '$') { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid variable name \"%V\"", &name); return NGX_CONF_ERROR; } name.len--; name.data++; } else { geo->index = -1; } var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); if (var == NULL) { return NGX_CONF_ERROR; } pool = ngx_create_pool(16384, cf->log); if (pool == NULL) { return NGX_CONF_ERROR; } ngx_memzero(&ctx, sizeof(ngx_http_geo_conf_ctx_t)); ctx.temp_pool = ngx_create_pool(16384, cf->log); if (ctx.temp_pool == NULL) { return NGX_CONF_ERROR; } ngx_rbtree_init(&ctx.rbtree, &ctx.sentinel, ngx_str_rbtree_insert_value); ctx.pool = cf->pool; ctx.data_size = sizeof(ngx_http_geo_header_t) + sizeof(ngx_http_variable_value_t) + 0x10000 * sizeof(ngx_http_geo_range_t *); ctx.allow_binary_include = 1; save = *cf; cf->pool = pool; cf->ctx = &ctx; cf->handler = ngx_http_geo; cf->handler_conf = conf; rv = ngx_conf_parse(cf, NULL); *cf = save; geo->proxies = ctx.proxies; geo->proxy_recursive = ctx.proxy_recursive; if (ctx.ranges) { if (ctx.high.low && !ctx.binary_include) { for (i = 0; i < 0x10000; i++) { a = (ngx_array_t *) ctx.high.low[i]; if (a == NULL || a->nelts == 0) { continue; } len = a->nelts * sizeof(ngx_http_geo_range_t); ctx.high.low[i] = ngx_palloc(cf->pool, len + sizeof(void *)); if (ctx.high.low[i] == NULL) { return NGX_CONF_ERROR; } ngx_memcpy(ctx.high.low[i], a->elts, len); ctx.high.low[i][a->nelts].value = NULL; ctx.data_size += len + sizeof(void *); } if (ctx.allow_binary_include && !ctx.outside_entries && ctx.entries > 100000 && ctx.includes == 1) { ngx_http_geo_create_binary_base(&ctx); } } if (ctx.high.default_value == NULL) { ctx.high.default_value = &ngx_http_variable_null_value; } geo->u.high = ctx.high; var->get_handler = ngx_http_geo_range_variable; var->data = (uintptr_t) geo; ngx_destroy_pool(ctx.temp_pool); ngx_destroy_pool(pool); } else { if (ctx.tree == NULL) { ctx.tree = ngx_radix_tree_create(cf->pool, -1); if (ctx.tree == NULL) { return NGX_CONF_ERROR; } } geo->u.tree = ctx.tree; var->get_handler = ngx_http_geo_cidr_variable; var->data = (uintptr_t) geo; ngx_destroy_pool(ctx.temp_pool); ngx_destroy_pool(pool); if (ngx_radix32tree_find(ctx.tree, 0) != NGX_RADIX_NO_VALUE) { return rv; } if (ngx_radix32tree_insert(ctx.tree, 0, 0, (uintptr_t) &ngx_http_variable_null_value) == NGX_ERROR) { return NGX_CONF_ERROR; } } return rv; }
['static char *\nngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n char *rv;\n size_t len;\n ngx_str_t *value, name;\n ngx_uint_t i;\n ngx_conf_t save;\n ngx_pool_t *pool;\n ngx_array_t *a;\n ngx_http_variable_t *var;\n ngx_http_geo_ctx_t *geo;\n ngx_http_geo_conf_ctx_t ctx;\n value = cf->args->elts;\n geo = ngx_palloc(cf->pool, sizeof(ngx_http_geo_ctx_t));\n if (geo == NULL) {\n return NGX_CONF_ERROR;\n }\n name = value[1];\n if (name.data[0] != \'$\') {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"%V\\"", &name);\n return NGX_CONF_ERROR;\n }\n name.len--;\n name.data++;\n if (cf->args->nelts == 3) {\n geo->index = ngx_http_get_variable_index(cf, &name);\n if (geo->index == NGX_ERROR) {\n return NGX_CONF_ERROR;\n }\n name = value[2];\n if (name.data[0] != \'$\') {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"%V\\"", &name);\n return NGX_CONF_ERROR;\n }\n name.len--;\n name.data++;\n } else {\n geo->index = -1;\n }\n var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);\n if (var == NULL) {\n return NGX_CONF_ERROR;\n }\n pool = ngx_create_pool(16384, cf->log);\n if (pool == NULL) {\n return NGX_CONF_ERROR;\n }\n ngx_memzero(&ctx, sizeof(ngx_http_geo_conf_ctx_t));\n ctx.temp_pool = ngx_create_pool(16384, cf->log);\n if (ctx.temp_pool == NULL) {\n return NGX_CONF_ERROR;\n }\n ngx_rbtree_init(&ctx.rbtree, &ctx.sentinel, ngx_str_rbtree_insert_value);\n ctx.pool = cf->pool;\n ctx.data_size = sizeof(ngx_http_geo_header_t)\n + sizeof(ngx_http_variable_value_t)\n + 0x10000 * sizeof(ngx_http_geo_range_t *);\n ctx.allow_binary_include = 1;\n save = *cf;\n cf->pool = pool;\n cf->ctx = &ctx;\n cf->handler = ngx_http_geo;\n cf->handler_conf = conf;\n rv = ngx_conf_parse(cf, NULL);\n *cf = save;\n geo->proxies = ctx.proxies;\n geo->proxy_recursive = ctx.proxy_recursive;\n if (ctx.ranges) {\n if (ctx.high.low && !ctx.binary_include) {\n for (i = 0; i < 0x10000; i++) {\n a = (ngx_array_t *) ctx.high.low[i];\n if (a == NULL || a->nelts == 0) {\n continue;\n }\n len = a->nelts * sizeof(ngx_http_geo_range_t);\n ctx.high.low[i] = ngx_palloc(cf->pool, len + sizeof(void *));\n if (ctx.high.low[i] == NULL) {\n return NGX_CONF_ERROR;\n }\n ngx_memcpy(ctx.high.low[i], a->elts, len);\n ctx.high.low[i][a->nelts].value = NULL;\n ctx.data_size += len + sizeof(void *);\n }\n if (ctx.allow_binary_include\n && !ctx.outside_entries\n && ctx.entries > 100000\n && ctx.includes == 1)\n {\n ngx_http_geo_create_binary_base(&ctx);\n }\n }\n if (ctx.high.default_value == NULL) {\n ctx.high.default_value = &ngx_http_variable_null_value;\n }\n geo->u.high = ctx.high;\n var->get_handler = ngx_http_geo_range_variable;\n var->data = (uintptr_t) geo;\n ngx_destroy_pool(ctx.temp_pool);\n ngx_destroy_pool(pool);\n } else {\n if (ctx.tree == NULL) {\n ctx.tree = ngx_radix_tree_create(cf->pool, -1);\n if (ctx.tree == NULL) {\n return NGX_CONF_ERROR;\n }\n }\n geo->u.tree = ctx.tree;\n var->get_handler = ngx_http_geo_cidr_variable;\n var->data = (uintptr_t) geo;\n ngx_destroy_pool(ctx.temp_pool);\n ngx_destroy_pool(pool);\n if (ngx_radix32tree_find(ctx.tree, 0) != NGX_RADIX_NO_VALUE) {\n return rv;\n }\n if (ngx_radix32tree_insert(ctx.tree, 0, 0,\n (uintptr_t) &ngx_http_variable_null_value)\n == NGX_ERROR)\n {\n return NGX_CONF_ERROR;\n }\n }\n return rv;\n}', 'ngx_int_t\nngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)\n{\n ngx_uint_t i;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n if (name->len == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"$\\"");\n return NGX_ERROR;\n }\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n v = cmcf->variables.elts;\n if (v == NULL) {\n if (ngx_array_init(&cmcf->variables, cf->pool, 4,\n sizeof(ngx_http_variable_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n } else {\n for (i = 0; i < cmcf->variables.nelts; i++) {\n if (name->len != v[i].name.len\n || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)\n {\n continue;\n }\n return i;\n }\n }\n v = ngx_array_push(&cmcf->variables);\n if (v == NULL) {\n return NGX_ERROR;\n }\n v->name.len = name->len;\n v->name.data = ngx_pnalloc(cf->pool, name->len);\n if (v->name.data == NULL) {\n return NGX_ERROR;\n }\n ngx_strlow(v->name.data, name->data, name->len);\n v->set_handler = NULL;\n v->get_handler = NULL;\n v->data = 0;\n v->flags = 0;\n v->index = cmcf->variables.nelts - 1;\n return v->index;\n}']
36,104
0
https://gitlab.com/libtiff/libtiff/blob/6dac309a9701d15ac52d895d566ddae2ed49db9b/libtiff/tif_tile.c/#L55
uint32 TIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s) { TIFFDirectory *td = &tif->tif_dir; uint32 dx = td->td_tilewidth; uint32 dy = td->td_tilelength; uint32 dz = td->td_tiledepth; uint32 tile = 1; if (td->td_imagedepth == 1) z = 0; if (dx == (uint32) -1) dx = td->td_imagewidth; if (dy == (uint32) -1) dy = td->td_imagelength; if (dz == (uint32) -1) dz = td->td_imagedepth; if (dx != 0 && dy != 0 && dz != 0) { uint32 xpt = TIFFhowmany_32(td->td_imagewidth, dx); uint32 ypt = TIFFhowmany_32(td->td_imagelength, dy); uint32 zpt = TIFFhowmany_32(td->td_imagedepth, dz); if (td->td_planarconfig == PLANARCONFIG_SEPARATE) tile = (xpt*ypt*zpt)*s + (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx; else tile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx; } return (tile); }
['static int\ngtTileSeparate(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)\n{\n\tTIFF* tif = img->tif;\n\ttileSeparateRoutine put = img->put.separate;\n\tuint32 col, row, y, rowstoread;\n\ttmsize_t pos;\n\tuint32 tw, th;\n\tunsigned char* buf = NULL;\n\tunsigned char* p0 = NULL;\n\tunsigned char* p1 = NULL;\n\tunsigned char* p2 = NULL;\n\tunsigned char* pa = NULL;\n\ttmsize_t tilesize;\n\ttmsize_t bufsize;\n\tint32 fromskew, toskew;\n\tint alpha = img->alpha;\n\tuint32 nrow;\n\tint ret = 1, flip;\n uint16 colorchannels;\n\tuint32 this_tw, tocol;\n\tint32 this_toskew, leftmost_toskew;\n\tint32 leftmost_fromskew;\n\tuint32 leftmost_tw;\n\ttilesize = TIFFTileSize(tif);\n\tbufsize = TIFFSafeMultiply(tmsize_t,alpha?4:3,tilesize);\n\tif (bufsize == 0) {\n\t\tTIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "Integer overflow in %s", "gtTileSeparate");\n\t\treturn (0);\n\t}\n\tTIFFGetField(tif, TIFFTAG_TILEWIDTH, &tw);\n\tTIFFGetField(tif, TIFFTAG_TILELENGTH, &th);\n\tflip = setorientation(img);\n\tif (flip & FLIP_VERTICALLY) {\n\t\ty = h - 1;\n\t\ttoskew = -(int32)(tw + w);\n\t}\n\telse {\n\t\ty = 0;\n\t\ttoskew = -(int32)(tw - w);\n\t}\n switch( img->photometric )\n {\n case PHOTOMETRIC_MINISWHITE:\n case PHOTOMETRIC_MINISBLACK:\n case PHOTOMETRIC_PALETTE:\n colorchannels = 1;\n break;\n default:\n colorchannels = 3;\n break;\n }\n\tleftmost_fromskew = img->col_offset % tw;\n\tleftmost_tw = tw - leftmost_fromskew;\n\tleftmost_toskew = toskew + leftmost_fromskew;\n\tfor (row = 0; ret != 0 && row < h; row += nrow)\n\t{\n\t\trowstoread = th - (row + img->row_offset) % th;\n\t\tnrow = (row + rowstoread > h ? h - row : rowstoread);\n\t\tfromskew = leftmost_fromskew;\n\t\tthis_tw = leftmost_tw;\n\t\tthis_toskew = leftmost_toskew;\n\t\ttocol = 0;\n\t\tcol = img->col_offset;\n\t\twhile (tocol < w)\n\t\t{\n if( buf == NULL )\n {\n if (_TIFFReadTileAndAllocBuffer(\n tif, (void**) &buf, bufsize, col,\n row+img->row_offset,0,0)==(tmsize_t)(-1)\n && (buf == NULL || img->stoponerr))\n {\n ret = 0;\n break;\n }\n p0 = buf;\n if( colorchannels == 1 )\n {\n p2 = p1 = p0;\n pa = (alpha?(p0+3*tilesize):NULL);\n }\n else\n {\n p1 = p0 + tilesize;\n p2 = p1 + tilesize;\n pa = (alpha?(p2+tilesize):NULL);\n }\n }\n\t\t\telse if (TIFFReadTile(tif, p0, col,\n\t\t\t row+img->row_offset,0,0)==(tmsize_t)(-1) && img->stoponerr)\n\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (colorchannels > 1\n && TIFFReadTile(tif, p1, col,\n row+img->row_offset,0,1) == (tmsize_t)(-1)\n && img->stoponerr)\n\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (colorchannels > 1\n && TIFFReadTile(tif, p2, col,\n row+img->row_offset,0,2) == (tmsize_t)(-1)\n && img->stoponerr)\n\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (alpha\n && TIFFReadTile(tif,pa,col,\n row+img->row_offset,0,colorchannels) == (tmsize_t)(-1)\n && img->stoponerr)\n {\n ret = 0;\n break;\n\t\t\t}\n\t\t\tpos = ((row+img->row_offset) % th) * TIFFTileRowSize(tif) + \\\n\t\t\t ((tmsize_t) fromskew * img->samplesperpixel);\n\t\t\tif (tocol + this_tw > w)\n\t\t\t{\n\t\t\t\tfromskew = tw - (w - tocol);\n\t\t\t\tthis_tw = tw - fromskew;\n\t\t\t\tthis_toskew = toskew + fromskew;\n\t\t\t}\n\t\t\t(*put)(img, raster+y*w+tocol, tocol, y, this_tw, nrow, fromskew, this_toskew, \\\n\t\t\t\tp0 + pos, p1 + pos, p2 + pos, (alpha?(pa+pos):NULL));\n\t\t\ttocol += this_tw;\n\t\t\tcol += this_tw;\n\t\t\tfromskew = 0;\n\t\t\tthis_tw = tw;\n\t\t\tthis_toskew = toskew;\n\t\t}\n\t\ty += ((flip & FLIP_VERTICALLY) ?-(int32) nrow : (int32) nrow);\n\t}\n\tif (flip & FLIP_HORIZONTALLY) {\n\t\tuint32 line;\n\t\tfor (line = 0; line < h; line++) {\n\t\t\tuint32 *left = raster + (line * w);\n\t\t\tuint32 *right = left + w - 1;\n\t\t\twhile ( left < right ) {\n\t\t\t\tuint32 temp = *left;\n\t\t\t\t*left = *right;\n\t\t\t\t*right = temp;\n\t\t\t\tleft++;\n\t\t\t\tright--;\n\t\t\t}\n\t\t}\n\t}\n\t_TIFFfree(buf);\n\treturn (ret);\n}', 'tmsize_t\n_TIFFReadTileAndAllocBuffer(TIFF* tif,\n void **buf, tmsize_t bufsizetoalloc,\n uint32 x, uint32 y, uint32 z, uint16 s)\n{\n if (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))\n return ((tmsize_t)(-1));\n return (_TIFFReadEncodedTileAndAllocBuffer(tif,\n TIFFComputeTile(tif, x, y, z, s),\n buf, bufsizetoalloc,\n (tmsize_t)(-1)));\n}', 'int\nTIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (x >= td->td_imagewidth) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Col out of range, max %lu",\n\t\t\t (unsigned long) x,\n\t\t\t (unsigned long) (td->td_imagewidth - 1));\n\t\treturn (0);\n\t}\n\tif (y >= td->td_imagelength) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Row out of range, max %lu",\n\t\t\t (unsigned long) y,\n\t\t\t (unsigned long) (td->td_imagelength - 1));\n\t\treturn (0);\n\t}\n\tif (z >= td->td_imagedepth) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Depth out of range, max %lu",\n\t\t\t (unsigned long) z,\n\t\t\t (unsigned long) (td->td_imagedepth - 1));\n\t\treturn (0);\n\t}\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE &&\n\t s >= td->td_samplesperpixel) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Sample out of range, max %lu",\n\t\t\t (unsigned long) s,\n\t\t\t (unsigned long) (td->td_samplesperpixel - 1));\n\t\treturn (0);\n\t}\n\treturn (1);\n}', 'uint32\nTIFFComputeTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 tile = 1;\n\tif (td->td_imagedepth == 1)\n\t\tz = 0;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tif (dx != 0 && dy != 0 && dz != 0) {\n\t\tuint32 xpt = TIFFhowmany_32(td->td_imagewidth, dx);\n\t\tuint32 ypt = TIFFhowmany_32(td->td_imagelength, dy);\n\t\tuint32 zpt = TIFFhowmany_32(td->td_imagedepth, dz);\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\t\ttile = (xpt*ypt*zpt)*s +\n\t\t\t (xpt*ypt)*(z/dz) +\n\t\t\t xpt*(y/dy) +\n\t\t\t x/dx;\n\t\telse\n\t\t\ttile = (xpt*ypt)*(z/dz) + xpt*(y/dy) + x/dx;\n\t}\n\treturn (tile);\n}']
36,105
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L727
static int l2s_dia_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,i,d; int dia_size= c->dia_size&0xFF; const int dec= dia_size & (dia_size-1); static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1}, { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}}; cmpf= s->dsp.me_cmp[size]; chroma_cmpf= s->dsp.me_cmp[size+1]; for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){ do{ x= best[0]; y= best[1]; for(i=0; i<8; i++){ CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size); } }while(best[0] != x || best[1] != y); } x= best[0]; y= best[1]; CHECK_CLIPPED_MV(x+1, y); CHECK_CLIPPED_MV(x, y+1); CHECK_CLIPPED_MV(x-1, y); CHECK_CLIPPED_MV(x, y-1); return dmin; }
['static int l2s_dia_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,i,d;\n int dia_size= c->dia_size&0xFF;\n const int dec= dia_size & (dia_size-1);\n static const int hex[8][2]={{-2, 0}, {-1,-1}, { 0,-2}, { 1,-1},\n { 2, 0}, { 1, 1}, { 0, 2}, {-1, 1}};\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n for(; dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){\n do{\n x= best[0];\n y= best[1];\n for(i=0; i<8; i++){\n CHECK_CLIPPED_MV(x+hex[i][0]*dia_size, y+hex[i][1]*dia_size);\n }\n }while(best[0] != x || best[1] != y);\n }\n x= best[0];\n y= best[1];\n CHECK_CLIPPED_MV(x+1, y);\n CHECK_CLIPPED_MV(x, y+1);\n CHECK_CLIPPED_MV(x-1, y);\n CHECK_CLIPPED_MV(x, y-1);\n return dmin;\n}']
36,106
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; }
['int ff_wma_run_level_decode(AVCodecContext *avctx, BitstreamContext *bc,\n VLC *vlc, const float *level_table,\n const uint16_t *run_table, int version,\n WMACoef *ptr, int offset, int num_coefs,\n int block_len, int frame_len_bits,\n int coef_nb_bits)\n{\n int code, level, sign;\n const uint32_t *ilvl = (const uint32_t *) level_table;\n uint32_t *iptr = (uint32_t *) ptr;\n const unsigned int coef_mask = block_len - 1;\n for (; offset < num_coefs; offset++) {\n code = bitstream_read_vlc(bc, vlc->table, VLCBITS, VLCMAX);\n if (code > 1) {\n offset += run_table[code];\n sign = bitstream_read_bit(bc) - 1;\n iptr[offset & coef_mask] = ilvl[code] ^ sign << 31;\n } else if (code == 1) {\n break;\n } else {\n if (!version) {\n level = bitstream_read(bc, coef_nb_bits);\n offset += bitstream_read(bc, frame_len_bits);\n } else {\n level = ff_wma_get_large_val(bc);\n if (bitstream_read_bit(bc)) {\n if (bitstream_read_bit(bc)) {\n if (bitstream_read_bit(bc)) {\n av_log(avctx, AV_LOG_ERROR,\n "broken escape sequence\\n");\n return -1;\n } else\n offset += bitstream_read(bc, frame_len_bits) + 4;\n } else\n offset += bitstream_read(bc, 2) + 1;\n }\n }\n sign = bitstream_read_bit(bc) - 1;\n ptr[offset & coef_mask] = (level ^ sign) - sign;\n }\n }\n if (offset > num_coefs) {\n av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\\n");\n return -1;\n }\n return 0;\n}', 'unsigned int ff_wma_get_large_val(BitstreamContext *bc)\n{\n int n_bits = 8;\n if (bitstream_read_bit(bc)) {\n n_bits += 8;\n if (bitstream_read_bit(bc)) {\n n_bits += 8;\n if (bitstream_read_bit(bc))\n n_bits += 7;\n }\n }\n return bitstream_read(bc, n_bits);\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n if (!bc->bits_left)\n refill_64(bc);\n return get_val(bc, 1);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
36,107
0
https://github.com/openssl/openssl/blob/d8028b202bfe337200a0cc89b80983ea1838cb30/crypto/lhash/lhash.c/#L123
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data) { unsigned long hash; OPENSSL_LH_NODE *nn, **rn; void *ret; lh->error = 0; rn = getrn(lh, data, &hash); if (*rn == NULL) { lh->num_no_delete++; return (NULL); } else { nn = *rn; *rn = nn->next; ret = nn->data; OPENSSL_free(nn); lh->num_delete++; } lh->num_items--; if ((lh->num_nodes > MIN_NODES) && (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))) contract(lh); return (ret); }
['static SUB_STATE_RETURN read_state_machine(SSL *s)\n{\n OSSL_STATEM *st = &s->statem;\n int ret, mt;\n size_t len = 0;\n int (*transition) (SSL *s, int mt);\n PACKET pkt;\n MSG_PROCESS_RETURN(*process_message) (SSL *s, PACKET *pkt);\n WORK_STATE(*post_process_message) (SSL *s, WORK_STATE wst);\n size_t (*max_message_size) (SSL *s);\n void (*cb) (const SSL *ssl, int type, int val) = NULL;\n cb = get_callback(s);\n if (s->server) {\n transition = ossl_statem_server_read_transition;\n process_message = ossl_statem_server_process_message;\n max_message_size = ossl_statem_server_max_message_size;\n post_process_message = ossl_statem_server_post_process_message;\n } else {\n transition = ossl_statem_client_read_transition;\n process_message = ossl_statem_client_process_message;\n max_message_size = ossl_statem_client_max_message_size;\n post_process_message = ossl_statem_client_post_process_message;\n }\n if (st->read_state_first_init) {\n s->first_packet = 1;\n st->read_state_first_init = 0;\n }\n while (1) {\n switch (st->read_state) {\n case READ_STATE_HEADER:\n if (SSL_IS_DTLS(s)) {\n ret = dtls_get_message(s, &mt, &len);\n } else {\n ret = tls_get_message_header(s, &mt);\n }\n if (ret == 0) {\n return SUB_STATE_ERROR;\n }\n if (cb != NULL) {\n if (s->server)\n cb(s, SSL_CB_ACCEPT_LOOP, 1);\n else\n cb(s, SSL_CB_CONNECT_LOOP, 1);\n }\n if (!transition(s, mt)) {\n ossl_statem_set_error(s);\n return SUB_STATE_ERROR;\n }\n if (s->s3->tmp.message_size > max_message_size(s)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);\n SSLerr(SSL_F_READ_STATE_MACHINE, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n return SUB_STATE_ERROR;\n }\n if (!SSL_IS_DTLS(s)\n && s->s3->tmp.message_size > 0\n && !grow_init_buf(s, s->s3->tmp.message_size\n + SSL3_HM_HEADER_LENGTH)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_BUF_LIB);\n return SUB_STATE_ERROR;\n }\n st->read_state = READ_STATE_BODY;\n case READ_STATE_BODY:\n if (!SSL_IS_DTLS(s)) {\n ret = tls_get_message_body(s, &len);\n if (ret == 0) {\n return SUB_STATE_ERROR;\n }\n }\n s->first_packet = 0;\n if (!PACKET_buf_init(&pkt, s->init_msg, len)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n return SUB_STATE_ERROR;\n }\n ret = process_message(s, &pkt);\n s->init_num = 0;\n switch (ret) {\n case MSG_PROCESS_ERROR:\n return SUB_STATE_ERROR;\n case MSG_PROCESS_FINISHED_READING:\n if (SSL_IS_DTLS(s)) {\n dtls1_stop_timer(s);\n }\n return SUB_STATE_FINISHED;\n case MSG_PROCESS_CONTINUE_PROCESSING:\n st->read_state = READ_STATE_POST_PROCESS;\n st->read_state_work = WORK_MORE_A;\n break;\n default:\n st->read_state = READ_STATE_HEADER;\n break;\n }\n break;\n case READ_STATE_POST_PROCESS:\n st->read_state_work = post_process_message(s, st->read_state_work);\n switch (st->read_state_work) {\n case WORK_ERROR:\n case WORK_MORE_A:\n case WORK_MORE_B:\n case WORK_MORE_C:\n return SUB_STATE_ERROR;\n case WORK_FINISHED_CONTINUE:\n st->read_state = READ_STATE_HEADER;\n break;\n case WORK_FINISHED_STOP:\n if (SSL_IS_DTLS(s)) {\n dtls1_stop_timer(s);\n }\n return SUB_STATE_FINISHED;\n }\n break;\n default:\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n ossl_statem_set_error(s);\n return SUB_STATE_ERROR;\n }\n }\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n if (SSL_TREAT_AS_TLS13(s))\n desc = tls13_alert_code(desc);\n else\n desc = s->method->ssl3_enc->alert_value(desc);\n if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n desc = SSL_AD_HANDSHAKE_FAILURE;\n if (desc < 0)\n return -1;\n if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n SSL_CTX_remove_session(s->session_ctx, s->session);\n s->s3->alert_dispatch = 1;\n s->s3->send_alert[0] = level;\n s->s3->send_alert[1] = desc;\n if (!RECORD_LAYER_write_pending(&s->rlayer)) {\n return s->method->ssl_dispatch_alert(s);\n }\n return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
36,108
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L762
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}']
36,109
0
https://github.com/openssl/openssl/blob/46ef873f0b3c04b6415cddac5d4a7b27b53cc482/crypto/bio/b_print.c/#L744
static void doapr_outch( char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen, int c) { assert(*sbuffer != NULL || buffer != NULL); if (buffer) { while (*currlen >= *maxlen) { if (*buffer == NULL) { if (*maxlen == 0) *maxlen = 1024; *buffer = OPENSSL_malloc(*maxlen); if (*currlen > 0) { assert(*sbuffer != NULL); memcpy(*buffer, *sbuffer, *currlen); } *sbuffer = NULL; } else { *maxlen += 1024; *buffer = OPENSSL_realloc(*buffer, *maxlen); } } assert(*sbuffer != NULL || *buffer != NULL); } if (*currlen < *maxlen) { if (*sbuffer) (*sbuffer)[(*currlen)++] = (char)c; else (*buffer)[(*currlen)++] = (char)c; } return; }
['static void\ndoapr_outch(\n char **sbuffer,\n char **buffer,\n size_t *currlen,\n size_t *maxlen,\n int c)\n{\n assert(*sbuffer != NULL || buffer != NULL);\n if (buffer) {\n\twhile (*currlen >= *maxlen) {\n\t if (*buffer == NULL) {\n\t\tif (*maxlen == 0)\n\t\t *maxlen = 1024;\n\t\t*buffer = OPENSSL_malloc(*maxlen);\n\t\tif (*currlen > 0) {\n\t\t assert(*sbuffer != NULL);\n\t\t memcpy(*buffer, *sbuffer, *currlen);\n\t\t}\n\t\t*sbuffer = NULL;\n\t } else {\n\t\t*maxlen += 1024;\n\t\t*buffer = OPENSSL_realloc(*buffer, *maxlen);\n\t }\n\t}\n\tassert(*sbuffer != NULL || *buffer != NULL);\n }\n if (*currlen < *maxlen) {\n\tif (*sbuffer)\n\t (*sbuffer)[(*currlen)++] = (char)c;\n\telse\n\t (*buffer)[(*currlen)++] = (char)c;\n }\n return;\n}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}']
36,110
0
https://github.com/openssl/openssl/blob/440bce8f813fa661437ce52378c3df38e2fd073b/ssl/s3_enc.c/#L519
int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, size_t len, size_t *secret_size) { static const unsigned char *salt[3] = { #ifndef CHARSET_EBCDIC (const unsigned char *)"A", (const unsigned char *)"BB", (const unsigned char *)"CCC", #else (const unsigned char *)"\x41", (const unsigned char *)"\x42\x42", (const unsigned char *)"\x43\x43\x43", #endif }; unsigned char buf[EVP_MAX_MD_SIZE]; EVP_MD_CTX *ctx = EVP_MD_CTX_new(); int i, ret = 1; unsigned int n; size_t ret_secret_size = 0; if (ctx == NULL) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_MALLOC_FAILURE); return 0; } for (i = 0; i < 3; i++) { if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0 || EVP_DigestUpdate(ctx, salt[i], strlen((const char *)salt[i])) <= 0 || EVP_DigestUpdate(ctx, p, len) <= 0 || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]), SSL3_RANDOM_SIZE) <= 0 || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]), SSL3_RANDOM_SIZE) <= 0 || EVP_DigestFinal_ex(ctx, buf, &n) <= 0 || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0 || EVP_DigestUpdate(ctx, p, len) <= 0 || EVP_DigestUpdate(ctx, buf, n) <= 0 || EVP_DigestFinal_ex(ctx, out, &n) <= 0) { SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR); ret = 0; break; } out += n; ret_secret_size += n; } EVP_MD_CTX_free(ctx); OPENSSL_cleanse(buf, sizeof(buf)); if (ret) *secret_size = ret_secret_size; return ret; }
['int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,\n size_t len, size_t *secret_size)\n{\n static const unsigned char *salt[3] = {\n#ifndef CHARSET_EBCDIC\n (const unsigned char *)"A",\n (const unsigned char *)"BB",\n (const unsigned char *)"CCC",\n#else\n (const unsigned char *)"\\x41",\n (const unsigned char *)"\\x42\\x42",\n (const unsigned char *)"\\x43\\x43\\x43",\n#endif\n };\n unsigned char buf[EVP_MAX_MD_SIZE];\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n int i, ret = 1;\n unsigned int n;\n size_t ret_secret_size = 0;\n if (ctx == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,\n ERR_R_MALLOC_FAILURE);\n return 0;\n }\n for (i = 0; i < 3; i++) {\n if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0\n || EVP_DigestUpdate(ctx, salt[i],\n strlen((const char *)salt[i])) <= 0\n || EVP_DigestUpdate(ctx, p, len) <= 0\n || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_DigestFinal_ex(ctx, buf, &n) <= 0\n || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0\n || EVP_DigestUpdate(ctx, p, len) <= 0\n || EVP_DigestUpdate(ctx, buf, n) <= 0\n || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);\n ret = 0;\n break;\n }\n out += n;\n ret_secret_size += n;\n }\n EVP_MD_CTX_free(ctx);\n OPENSSL_cleanse(buf, sizeof(buf));\n if (ret)\n *secret_size = ret_secret_size;\n return ret;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n 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}', 'void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,\n int line)\n{\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
36,111
0
https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int on2avc_decode_band_scales(On2AVCContext *c, BitstreamContext *bc)\n{\n int w, w2, b, scale, first = 1;\n int band_off = 0;\n for (w = 0; w < c->num_windows; w++) {\n if (!c->grouping[w]) {\n memcpy(c->band_scales + band_off,\n c->band_scales + band_off - c->num_bands,\n c->num_bands * sizeof(*c->band_scales));\n band_off += c->num_bands;\n continue;\n }\n for (b = 0; b < c->num_bands; b++) {\n if (!c->band_type[band_off]) {\n int all_zero = 1;\n for (w2 = w + 1; w2 < c->num_windows; w2++) {\n if (c->grouping[w2])\n break;\n if (c->band_type[w2 * c->num_bands + b]) {\n all_zero = 0;\n break;\n }\n }\n if (all_zero) {\n c->band_scales[band_off++] = 0;\n continue;\n }\n }\n if (first) {\n scale = bitstream_read(bc, 7);\n first = 0;\n } else {\n scale += bitstream_read_vlc(bc, c->scale_diff.table, 9, 3) - 60;\n }\n if (scale < 0 || scale > 127) {\n av_log(c->avctx, AV_LOG_ERROR, "Invalid scale value %d\\n",\n scale);\n return AVERROR_INVALIDDATA;\n }\n c->band_scales[band_off++] = c->scale_tab[scale];\n }\n }\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
36,112
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/motion_est.c/#L176
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ MotionEstContext * const c= &s->me; const int stride= c->stride; const int uvstride= c->uvstride; const int qpel= flags&FLAG_QPEL; const int chroma= flags&FLAG_CHROMA; const int dxy= subx + (suby<<(1+qpel)); const int hx= subx + (x<<(1+qpel)); const int hy= suby + (y<<(1+qpel)); uint8_t * const * const ref= c->ref[ref_index]; uint8_t * const * const src= c->src[src_index]; int d; if(flags&FLAG_DIRECT){ assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)); if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){ const int time_pp= s->pp_time; const int time_pb= s->pb_time; const int mask= 2*qpel+1; if(s->mv_type==MV_TYPE_8X8){ int i; for(i=0; i<4; i++){ int fx = c->direct_basis_mv[i][0] + hx; int fy = c->direct_basis_mv[i][1] + hy; int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4)); int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4)); int fxy= (fx&mask) + ((fy&mask)<<(qpel+1)); int bxy= (bx&mask) + ((by&mask)<<(qpel+1)); uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1); if(qpel){ c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride); c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride); }else{ c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8); c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8); } } }else{ int fx = c->direct_basis_mv[0][0] + hx; int fy = c->direct_basis_mv[0][1] + hy; int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp); int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp); int fxy= (fx&mask) + ((fy&mask)<<(qpel+1)); int bxy= (bx&mask) + ((by&mask)<<(qpel+1)); if(qpel){ c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride); c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride); c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride); c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride); c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride); c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride); c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride); c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride); }else{ assert((fx>>1) + 16*s->mb_x >= -16); assert((fy>>1) + 16*s->mb_y >= -16); assert((fx>>1) + 16*s->mb_x <= s->width); assert((fy>>1) + 16*s->mb_y <= s->height); assert((bx>>1) + 16*s->mb_x >= -16); assert((by>>1) + 16*s->mb_y >= -16); assert((bx>>1) + 16*s->mb_x <= s->width); assert((by>>1) + 16*s->mb_y <= s->height); c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16); c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16); } } d = cmp_func(s, c->temp, src[0], stride, 16); }else d= 256*256*256*32; }else{ int uvdxy; if(dxy){ if(qpel){ c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride); if(chroma){ int cx= hx/2; int cy= hy/2; cx= (cx>>1)|(cx&1); cy= (cy>>1)|(cy&1); uvdxy= (cx&1) + 2*(cy&1); } }else{ c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h); if(chroma) uvdxy= dxy | (x&1) | (2*(y&1)); } d = cmp_func(s, c->temp, src[0], stride, h); }else{ d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h); if(chroma) uvdxy= (x&1) + 2*(y&1); } if(chroma){ uint8_t * const uvtemp= c->temp + 16*stride; c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1); c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1); d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1); d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1); } } #if 0 if(full_pel){ const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1); score_map[index]= d; } d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor; #endif return d; }
['static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)\n{\n MotionEstContext * const c= &s->me;\n int P[10][2];\n const int mot_stride = s->mb_stride;\n const int mot_xy = mb_y*mot_stride + mb_x;\n const int shift= 1+s->quarter_sample;\n int dmin, i;\n const int time_pp= s->pp_time;\n const int time_pb= s->pb_time;\n int mx, my, xmin, xmax, ymin, ymax;\n int16_t (*mv_table)[2]= s->b_direct_mv_table;\n c->current_mv_penalty= c->mv_penalty[1] + MAX_MV;\n ymin= xmin=(-32)>>shift;\n ymax= xmax= 31>>shift;\n if(IS_8X8(s->next_picture.mb_type[mot_xy])){\n s->mv_type= MV_TYPE_8X8;\n }else{\n s->mv_type= MV_TYPE_16X16;\n }\n for(i=0; i<4; i++){\n int index= s->block_index[i];\n int min, max;\n c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];\n c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];\n c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));\n c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));\n max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;\n min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;\n max+= 16*mb_x + 1;\n min+= 16*mb_x - 1;\n xmax= FFMIN(xmax, s->width - max);\n xmin= FFMAX(xmin, - 16 - min);\n max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;\n min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;\n max+= 16*mb_y + 1;\n min+= 16*mb_y - 1;\n ymax= FFMIN(ymax, s->height - max);\n ymin= FFMAX(ymin, - 16 - min);\n if(s->mv_type == MV_TYPE_16X16) break;\n }\n assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);\n if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){\n s->b_direct_mv_table[mot_xy][0]= 0;\n s->b_direct_mv_table[mot_xy][1]= 0;\n return 256*256*256*64;\n }\n c->xmin= xmin;\n c->ymin= ymin;\n c->xmax= xmax;\n c->ymax= ymax;\n c->flags |= FLAG_DIRECT;\n c->sub_flags |= FLAG_DIRECT;\n c->pred_x=0;\n c->pred_y=0;\n P_LEFT[0] = av_clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);\n P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);\n if (!s->first_slice_line) {\n P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift);\n P_TOP[1] = av_clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift);\n P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift);\n P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift);\n P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n }\n dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16);\n if(c->sub_flags&FLAG_QPEL)\n dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n else\n dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);\n if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip)\n dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1);\n get_limits(s, 16*mb_x, 16*mb_y);\n mv_table[mot_xy][0]= mx;\n mv_table[mot_xy][1]= my;\n c->flags &= ~FLAG_DIRECT;\n c->sub_flags &= ~FLAG_DIRECT;\n return dmin;\n}', 'inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,\n int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],\n int ref_mv_scale, int size, int h)\n{\n MotionEstContext * const c= &s->me;\n if(c->flags==0 && h==16 && size==0){\n return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);\n }else{\n return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);\n }\n}', 'static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,\n int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],\n int ref_mv_scale, int flags, int size, int h)\n{\n MotionEstContext * const c= &s->me;\n int best[2]={0, 0};\n int d;\n int dmin;\n int map_generation;\n int penalty_factor;\n const int ref_mv_stride= s->mb_stride;\n const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride;\n me_cmp_func cmpf, chroma_cmpf;\n LOAD_COMMON\n LOAD_COMMON2\n if(c->pre_pass){\n penalty_factor= c->pre_penalty_factor;\n cmpf= s->dsp.me_pre_cmp[size];\n chroma_cmpf= s->dsp.me_pre_cmp[size+1];\n }else{\n penalty_factor= c->penalty_factor;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n }\n map_generation= update_map_generation(c);\n assert(cmpf);\n dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\n map[0]= map_generation;\n score_map[0]= dmin;\n if((s->pict_type == FF_B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)\n dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;\n if (s->first_slice_line) {\n CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n }else{\n if(dmin<((h*h*s->avctx->mv0_threshold)>>8)\n && ( P_LEFT[0] |P_LEFT[1]\n |P_TOP[0] |P_TOP[1]\n |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){\n *mx_ptr= 0;\n *my_ptr= 0;\n c->skip=1;\n return dmin;\n }\n CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)\n CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)\n CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)\n }\n if(dmin>h*h*4){\n if(c->pre_pass){\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)\n if(!s->first_slice_line)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)\n }else{\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)\n if(s->mb_y+1<s->end_mb_y)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)\n }\n }\n if(c->avctx->last_predictor_count){\n const int count= c->avctx->last_predictor_count;\n const int xstart= FFMAX(0, s->mb_x - count);\n const int ystart= FFMAX(0, s->mb_y - count);\n const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);\n const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);\n int mb_y;\n for(mb_y=ystart; mb_y<yend; mb_y++){\n int mb_x;\n for(mb_x=xstart; mb_x<xend; mb_x++){\n const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;\n int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;\n int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;\n if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;\n CHECK_MV(mx,my)\n }\n }\n }\n dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n *mx_ptr= best[0];\n *my_ptr= best[1];\n return dmin;\n}', 'static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags){\n MotionEstContext * const c= &s->me;\n if(c->dia_size==-1)\n return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size<-1)\n return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size<2)\n return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>1024)\n return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>768)\n return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>512)\n return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);\n else if(c->dia_size>256)\n return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else\n return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n}', 'static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags)\n{\n MotionEstContext * const c= &s->me;\n me_cmp_func cmpf, chroma_cmpf;\n int dia_size;\n LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n for(dia_size=1; dia_size<=4; dia_size++){\n int dir;\n const int x= best[0];\n const int y= best[1];\n if(dia_size&(dia_size-1)) continue;\n if( x + dia_size > xmax\n || x - dia_size < xmin\n || y + dia_size > ymax\n || y - dia_size < ymin)\n continue;\n for(dir= 0; dir<dia_size; dir+=2){\n int d;\n CHECK_MV(x + dir , y + dia_size - dir);\n CHECK_MV(x + dia_size - dir, y - dir );\n CHECK_MV(x - dir , y - dia_size + dir);\n CHECK_MV(x - dia_size + dir, y + dir );\n }\n if(x!=best[0] || y!=best[1])\n dia_size=0;\n#if 0\n{\nint dx, dy, i;\nstatic int stats[8*8];\ndx= FFABS(x-best[0]);\ndy= FFABS(y-best[1]);\nif(dy>dx){\n dx^=dy; dy^=dx; dx^=dy;\n}\nstats[dy*8 + dx] ++;\nif(256*256*256*64 % (stats[0]+1)==0){\n for(i=0; i<64; i++){\n if((i&7)==0) printf("\\n");\n printf("%8d ", stats[i]);\n }\n printf("\\n");\n}\n}\n#endif\n }\n return dmin;\n}', 'static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n const int size, const int h, int ref_index, int src_index,\n me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n MotionEstContext * const c= &s->me;\n const int stride= c->stride;\n const int uvstride= c->uvstride;\n const int qpel= flags&FLAG_QPEL;\n const int chroma= flags&FLAG_CHROMA;\n const int dxy= subx + (suby<<(1+qpel));\n const int hx= subx + (x<<(1+qpel));\n const int hy= suby + (y<<(1+qpel));\n uint8_t * const * const ref= c->ref[ref_index];\n uint8_t * const * const src= c->src[src_index];\n int d;\n if(flags&FLAG_DIRECT){\n assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));\n if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){\n const int time_pp= s->pp_time;\n const int time_pb= s->pb_time;\n const int mask= 2*qpel+1;\n if(s->mv_type==MV_TYPE_8X8){\n int i;\n for(i=0; i<4; i++){\n int fx = c->direct_basis_mv[i][0] + hx;\n int fy = c->direct_basis_mv[i][1] + hy;\n int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));\n int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));\n int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);\n if(qpel){\n c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);\n c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);\n }else{\n c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);\n c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);\n }\n }\n }else{\n int fx = c->direct_basis_mv[0][0] + hx;\n int fy = c->direct_basis_mv[0][1] + hy;\n int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\n int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\n int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n if(qpel){\n c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);\n c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);\n c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);\n c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);\n c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);\n c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);\n c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);\n c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);\n }else{\n assert((fx>>1) + 16*s->mb_x >= -16);\n assert((fy>>1) + 16*s->mb_y >= -16);\n assert((fx>>1) + 16*s->mb_x <= s->width);\n assert((fy>>1) + 16*s->mb_y <= s->height);\n assert((bx>>1) + 16*s->mb_x >= -16);\n assert((by>>1) + 16*s->mb_y >= -16);\n assert((bx>>1) + 16*s->mb_x <= s->width);\n assert((by>>1) + 16*s->mb_y <= s->height);\n c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);\n c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);\n }\n }\n d = cmp_func(s, c->temp, src[0], stride, 16);\n }else\n d= 256*256*256*32;\n }else{\n int uvdxy;\n if(dxy){\n if(qpel){\n c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride);\n if(chroma){\n int cx= hx/2;\n int cy= hy/2;\n cx= (cx>>1)|(cx&1);\n cy= (cy>>1)|(cy&1);\n uvdxy= (cx&1) + 2*(cy&1);\n }\n }else{\n c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);\n if(chroma)\n uvdxy= dxy | (x&1) | (2*(y&1));\n }\n d = cmp_func(s, c->temp, src[0], stride, h);\n }else{\n d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);\n if(chroma)\n uvdxy= (x&1) + 2*(y&1);\n }\n if(chroma){\n uint8_t * const uvtemp= c->temp + 16*stride;\n c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);\n c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);\n d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);\n d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);\n }\n }\n#if 0\n if(full_pel){\n const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\n score_map[index]= d;\n }\n d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;\n#endif\n return d;\n}']
36,113
0
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/asn1/a_bitstr.c/#L180
ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len) { ASN1_BIT_STRING *ret = NULL; const unsigned char *p; unsigned char *s; int i; if (len < 1) { i = ASN1_R_STRING_TOO_SHORT; goto err; } if ((a == NULL) || ((*a) == NULL)) { if ((ret = ASN1_BIT_STRING_new()) == NULL) return (NULL); } else ret = (*a); p = *pp; i = *(p++); if (i > 7) { i = ASN1_R_INVALID_BIT_STRING_BITS_LEFT; goto err; } ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); if (len-- > 1) { s = OPENSSL_malloc((int)len); if (s == NULL) { i = ERR_R_MALLOC_FAILURE; goto err; } memcpy(s, p, (int)len); s[len - 1] &= (0xff << i); p += len; } else s = NULL; ret->length = (int)len; OPENSSL_free(ret->data); ret->data = s; ret->type = V_ASN1_BIT_STRING; if (a != NULL) (*a) = ret; *pp = p; return (ret); err: ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i); if ((a == NULL) || (*a != ret)) ASN1_BIT_STRING_free(ret); return (NULL); }
['ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,\n const unsigned char **pp, long len)\n{\n ASN1_BIT_STRING *ret = NULL;\n const unsigned char *p;\n unsigned char *s;\n int i;\n if (len < 1) {\n i = ASN1_R_STRING_TOO_SHORT;\n goto err;\n }\n if ((a == NULL) || ((*a) == NULL)) {\n if ((ret = ASN1_BIT_STRING_new()) == NULL)\n return (NULL);\n } else\n ret = (*a);\n p = *pp;\n i = *(p++);\n if (i > 7) {\n i = ASN1_R_INVALID_BIT_STRING_BITS_LEFT;\n goto err;\n }\n ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);\n ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i);\n if (len-- > 1) {\n s = OPENSSL_malloc((int)len);\n if (s == NULL) {\n i = ERR_R_MALLOC_FAILURE;\n goto err;\n }\n memcpy(s, p, (int)len);\n s[len - 1] &= (0xff << i);\n p += len;\n } else\n s = NULL;\n ret->length = (int)len;\n OPENSSL_free(ret->data);\n ret->data = s;\n ret->type = V_ASN1_BIT_STRING;\n if (a != NULL)\n (*a) = ret;\n *pp = p;\n return (ret);\n err:\n ASN1err(ASN1_F_C2I_ASN1_BIT_STRING, i);\n if ((a == NULL) || (*a != ret))\n ASN1_BIT_STRING_free(ret);\n return (NULL);\n}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n ASN1_STRING *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->type = type;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'void ASN1_STRING_free(ASN1_STRING *a)\n{\n if (a == NULL)\n return;\n if (!(a->flags & ASN1_STRING_FLAG_NDEF))\n OPENSSL_free(a->data);\n if (!(a->flags & ASN1_STRING_FLAG_EMBED))\n OPENSSL_free(a);\n}']
36,114
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavformat/utils.c/#L2944
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) { const char *p; char tag[128], *q; p = info; if (*p == '?') p++; for(;;) { q = tag; while (*p != '\0' && *p != '=' && *p != '&') { if ((q - tag) < sizeof(tag) - 1) *q++ = *p; p++; } *q = '\0'; q = arg; if (*p == '=') { p++; while (*p != '&' && *p != '\0') { if ((q - arg) < arg_size - 1) { if (*p == '+') *q++ = ' '; else *q++ = *p; } p++; } *q = '\0'; } if (!strcmp(tag, tag1)) return 1; if (*p != '&') break; p++; } return 0; }
['static int http_prepare_data(HTTPContext *c)\n{\n int i, len, ret;\n AVFormatContext *ctx;\n av_freep(&c->pb_buffer);\n switch(c->state) {\n case HTTPSTATE_SEND_DATA_HEADER:\n memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx));\n av_strlcpy(c->fmt_ctx.author, c->stream->author,\n sizeof(c->fmt_ctx.author));\n av_strlcpy(c->fmt_ctx.comment, c->stream->comment,\n sizeof(c->fmt_ctx.comment));\n av_strlcpy(c->fmt_ctx.copyright, c->stream->copyright,\n sizeof(c->fmt_ctx.copyright));\n av_strlcpy(c->fmt_ctx.title, c->stream->title,\n sizeof(c->fmt_ctx.title));\n for(i=0;i<c->stream->nb_streams;i++) {\n AVStream *st;\n AVStream *src;\n st = av_mallocz(sizeof(AVStream));\n c->fmt_ctx.streams[i] = st;\n if (!c->stream->feed ||\n c->stream->feed == c->stream)\n src = c->stream->streams[i];\n else\n src = c->stream->feed->streams[c->stream->feed_streams[i]];\n *st = *src;\n st->priv_data = 0;\n st->codec->frame_number = 0;\n }\n c->fmt_ctx.oformat = c->stream->fmt;\n c->fmt_ctx.nb_streams = c->stream->nb_streams;\n c->got_key_frame = 0;\n if (url_open_dyn_buf(&c->fmt_ctx.pb) < 0) {\n return -1;\n }\n c->fmt_ctx.pb->is_streamed = 1;\n c->fmt_ctx.preload = (int)(0.5*AV_TIME_BASE);\n c->fmt_ctx.max_delay = (int)(0.7*AV_TIME_BASE);\n av_set_parameters(&c->fmt_ctx, NULL);\n if (av_write_header(&c->fmt_ctx) < 0) {\n http_log("Error writing output header\\n");\n return -1;\n }\n len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer);\n c->buffer_ptr = c->pb_buffer;\n c->buffer_end = c->pb_buffer + len;\n c->state = HTTPSTATE_SEND_DATA;\n c->last_packet_sent = 0;\n break;\n case HTTPSTATE_SEND_DATA:\n if (c->stream->feed)\n ffm_set_write_index(c->fmt_in,\n c->stream->feed->feed_write_index,\n c->stream->feed->feed_size);\n if (c->stream->max_time &&\n c->stream->max_time + c->start_time - cur_time < 0)\n c->state = HTTPSTATE_SEND_DATA_TRAILER;\n else {\n AVPacket pkt;\n redo:\n if (av_read_frame(c->fmt_in, &pkt) < 0) {\n if (c->stream->feed && c->stream->feed->feed_opened) {\n c->state = HTTPSTATE_WAIT_FEED;\n return 1;\n } else {\n if (c->stream->loop) {\n av_close_input_file(c->fmt_in);\n c->fmt_in = NULL;\n if (open_input_stream(c, "") < 0)\n goto no_loop;\n goto redo;\n } else {\n no_loop:\n c->state = HTTPSTATE_SEND_DATA_TRAILER;\n }\n }\n } else {\n int source_index = pkt.stream_index;\n if (c->first_pts == AV_NOPTS_VALUE) {\n c->first_pts = av_rescale_q(pkt.dts, c->fmt_in->streams[pkt.stream_index]->time_base, AV_TIME_BASE_Q);\n c->start_time = cur_time;\n }\n if (c->stream->feed) {\n if (c->switch_pending) {\n c->switch_pending = 0;\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->switch_feed_streams[i] == pkt.stream_index)\n if (pkt.flags & PKT_FLAG_KEY)\n do_switch_stream(c, i);\n if (c->switch_feed_streams[i] >= 0)\n c->switch_pending = 1;\n }\n }\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->feed_streams[i] == pkt.stream_index) {\n AVStream *st = c->fmt_in->streams[source_index];\n pkt.stream_index = i;\n if (pkt.flags & PKT_FLAG_KEY &&\n (st->codec->codec_type == CODEC_TYPE_VIDEO ||\n c->stream->nb_streams == 1))\n c->got_key_frame = 1;\n if (!c->stream->send_on_key || c->got_key_frame)\n goto send_it;\n }\n }\n } else {\n AVCodecContext *codec;\n AVStream *ist, *ost;\n send_it:\n ist = c->fmt_in->streams[source_index];\n if (c->is_packetized) {\n c->cur_pts = av_rescale_q(pkt.dts, ist->time_base, AV_TIME_BASE_Q);\n if (ist->start_time != AV_NOPTS_VALUE)\n c->cur_pts -= av_rescale_q(ist->start_time, ist->time_base, AV_TIME_BASE_Q);\n c->cur_frame_duration = av_rescale_q(pkt.duration, ist->time_base, AV_TIME_BASE_Q);\n#if 0\n printf("index=%d pts=%0.3f duration=%0.6f\\n",\n pkt.stream_index,\n (double)c->cur_pts /\n AV_TIME_BASE,\n (double)c->cur_frame_duration /\n AV_TIME_BASE);\n#endif\n c->packet_stream_index = pkt.stream_index;\n ctx = c->rtp_ctx[c->packet_stream_index];\n if(!ctx) {\n av_free_packet(&pkt);\n break;\n }\n codec = ctx->streams[0]->codec;\n pkt.stream_index = 0;\n } else {\n ctx = &c->fmt_ctx;\n codec = ctx->streams[pkt.stream_index]->codec;\n }\n if (c->is_packetized) {\n int max_packet_size;\n if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP)\n max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;\n else\n max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]);\n ret = url_open_dyn_packet_buf(&ctx->pb, max_packet_size);\n } else {\n ret = url_open_dyn_buf(&ctx->pb);\n }\n if (ret < 0) {\n return -1;\n }\n ost = ctx->streams[pkt.stream_index];\n ctx->pb->is_streamed = 1;\n if (pkt.dts != AV_NOPTS_VALUE)\n pkt.dts = av_rescale_q(pkt.dts, ist->time_base, ost->time_base);\n if (pkt.pts != AV_NOPTS_VALUE)\n pkt.pts = av_rescale_q(pkt.pts, ist->time_base, ost->time_base);\n pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);\n if (av_write_frame(ctx, &pkt) < 0) {\n http_log("Error writing frame to output\\n");\n c->state = HTTPSTATE_SEND_DATA_TRAILER;\n }\n len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n c->cur_frame_bytes = len;\n c->buffer_ptr = c->pb_buffer;\n c->buffer_end = c->pb_buffer + len;\n codec->frame_number++;\n if (len == 0) {\n av_free_packet(&pkt);\n goto redo;\n }\n }\n av_free_packet(&pkt);\n }\n }\n break;\n default:\n case HTTPSTATE_SEND_DATA_TRAILER:\n if (c->last_packet_sent || c->is_packetized)\n return -1;\n ctx = &c->fmt_ctx;\n if (url_open_dyn_buf(&ctx->pb) < 0) {\n return -1;\n }\n c->fmt_ctx.pb->is_streamed = 1;\n av_write_trailer(ctx);\n len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n c->buffer_ptr = c->pb_buffer;\n c->buffer_end = c->pb_buffer + len;\n c->last_packet_sent = 1;\n break;\n }\n return 0;\n}', 'static int open_input_stream(HTTPContext *c, const char *info)\n{\n char buf[128];\n char input_filename[1024];\n AVFormatContext *s;\n int buf_size, i, ret;\n int64_t stream_pos;\n if (c->stream->feed) {\n strcpy(input_filename, c->stream->feed->feed_filename);\n buf_size = FFM_PACKET_SIZE;\n if (find_info_tag(buf, sizeof(buf), "date", info)) {\n stream_pos = parse_date(buf, 0);\n if (stream_pos == INT64_MIN)\n return -1;\n } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {\n int prebuffer = strtol(buf, 0, 10);\n stream_pos = av_gettime() - prebuffer * (int64_t)1000000;\n } else\n stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000;\n } else {\n strcpy(input_filename, c->stream->feed_filename);\n buf_size = 0;\n if (find_info_tag(buf, sizeof(buf), "date", info)) {\n stream_pos = parse_date(buf, 1);\n if (stream_pos == INT64_MIN)\n return -1;\n } else\n stream_pos = 0;\n }\n if (input_filename[0] == \'\\0\')\n return -1;\n#if 0\n { time_t when = stream_pos / 1000000;\n http_log("Stream pos = %"PRId64", time=%s", stream_pos, ctime(&when));\n }\n#endif\n if ((ret = av_open_input_file(&s, input_filename, c->stream->ifmt,\n buf_size, c->stream->ap_in)) < 0) {\n http_log("could not open %s: %d\\n", input_filename, ret);\n return -1;\n }\n s->flags |= AVFMT_FLAG_GENPTS;\n c->fmt_in = s;\n av_find_stream_info(c->fmt_in);\n for(i=0;i<s->nb_streams;i++)\n open_parser(s, i);\n c->pts_stream_index = 0;\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->pts_stream_index == 0 &&\n c->stream->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {\n c->pts_stream_index = i;\n }\n }\n#if 1\n if (c->fmt_in->iformat->read_seek)\n av_seek_frame(c->fmt_in, -1, stream_pos, 0);\n#endif\n c->start_time = cur_time;\n c->first_pts = AV_NOPTS_VALUE;\n return 0;\n}', "int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)\n{\n const char *p;\n char tag[128], *q;\n p = info;\n if (*p == '?')\n p++;\n for(;;) {\n q = tag;\n while (*p != '\\0' && *p != '=' && *p != '&') {\n if ((q - tag) < sizeof(tag) - 1)\n *q++ = *p;\n p++;\n }\n *q = '\\0';\n q = arg;\n if (*p == '=') {\n p++;\n while (*p != '&' && *p != '\\0') {\n if ((q - arg) < arg_size - 1) {\n if (*p == '+')\n *q++ = ' ';\n else\n *q++ = *p;\n }\n p++;\n }\n *q = '\\0';\n }\n if (!strcmp(tag, tag1))\n return 1;\n if (*p != '&')\n break;\n p++;\n }\n return 0;\n}"]
36,115
0
https://github.com/libav/libav/blob/5228bcd8705523cee43e351e1a113e12aefcf837/libavcodec/h264pred.c/#L112
static void pred4x4_vertical_vp8_c(uint8_t *src, const uint8_t *topright, int stride){ const int lt= src[-1-1*stride]; LOAD_TOP_EDGE LOAD_TOP_RIGHT_EDGE uint32_t v = PACK4UINT8((lt + 2*t0 + t1 + 2) >> 2, (t0 + 2*t1 + t2 + 2) >> 2, (t1 + 2*t2 + t3 + 2) >> 2, (t2 + 2*t3 + t4 + 2) >> 2); AV_WN32A(src+0*stride, v); AV_WN32A(src+1*stride, v); AV_WN32A(src+2*stride, v); AV_WN32A(src+3*stride, v); }
['static void pred4x4_vertical_vp8_c(uint8_t *src, const uint8_t *topright, int stride){\n const int lt= src[-1-1*stride];\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n uint32_t v = PACK4UINT8((lt + 2*t0 + t1 + 2) >> 2,\n (t0 + 2*t1 + t2 + 2) >> 2,\n (t1 + 2*t2 + t3 + 2) >> 2,\n (t2 + 2*t3 + t4 + 2) >> 2);\n AV_WN32A(src+0*stride, v);\n AV_WN32A(src+1*stride, v);\n AV_WN32A(src+2*stride, v);\n AV_WN32A(src+3*stride, v);\n}']
36,116
0
https://github.com/libav/libav/blob/7ed63ca2e7817e837facd29b01d25a1a69087916/libavcodec/h264_loopfilter.c/#L151
static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { int i; int index_a = qp + h->slice_alpha_c0_offset; int alpha = alpha_table[index_a]; int beta = beta_table[qp + h->slice_beta_offset]; for( i = 0; i < 8; i++, pix += stride) { const int bS_index = (i >> 1) * bsi; if( bS[bS_index] == 0 ) { continue; } if( bS[bS_index] < 4 ) { const int tc0 = tc0_table[index_a][bS[bS_index]]; const int p0 = pix[-1]; const int p1 = pix[-2]; const int p2 = pix[-3]; const int q0 = pix[0]; const int q1 = pix[1]; const int q2 = pix[2]; if( FFABS( p0 - q0 ) < alpha && FFABS( p1 - p0 ) < beta && FFABS( q1 - q0 ) < beta ) { int tc = tc0; int i_delta; if( FFABS( p2 - p0 ) < beta ) { if(tc0) pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); tc++; } if( FFABS( q2 - q0 ) < beta ) { if(tc0) pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); tc++; } i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); pix[-1] = av_clip_uint8( p0 + i_delta ); pix[0] = av_clip_uint8( q0 - i_delta ); tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); } }else{ const int p0 = pix[-1]; const int p1 = pix[-2]; const int p2 = pix[-3]; const int q0 = pix[0]; const int q1 = pix[1]; const int q2 = pix[2]; if( FFABS( p0 - q0 ) < alpha && FFABS( p1 - p0 ) < beta && FFABS( q1 - q0 ) < beta ) { if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ if( FFABS( p2 - p0 ) < beta) { const int p3 = pix[-4]; pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; } else { pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; } if( FFABS( q2 - q0 ) < beta) { const int q3 = pix[3]; pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; } else { pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; } }else{ pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; } tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); } } } }
['void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {\n MpegEncContext * const s = &h->s;\n const int mb_xy= mb_x + mb_y*s->mb_stride;\n const int mb_type = s->current_picture.mb_type[mb_xy];\n const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;\n int first_vertical_edge_done = 0;\n av_unused int dir;\n if (FRAME_MBAFF\n && IS_INTERLACED(mb_type^h->left_type[0])\n && h->left_type[0]) {\n DECLARE_ALIGNED_8(int16_t, bS)[8];\n int qp[2];\n int bqp[2];\n int rqp[2];\n int mb_qp, mbn0_qp, mbn1_qp;\n int i;\n first_vertical_edge_done = 1;\n if( IS_INTRA(mb_type) ) {\n AV_WN64A(&bS[0], 0x0004000400040004ULL);\n AV_WN64A(&bS[4], 0x0004000400040004ULL);\n } else {\n static const uint8_t offset[2][2][8]={\n {\n {7+8*0, 7+8*0, 7+8*0, 7+8*0, 7+8*1, 7+8*1, 7+8*1, 7+8*1},\n {7+8*2, 7+8*2, 7+8*2, 7+8*2, 7+8*3, 7+8*3, 7+8*3, 7+8*3},\n },{\n {7+8*0, 7+8*1, 7+8*2, 7+8*3, 7+8*0, 7+8*1, 7+8*2, 7+8*3},\n {7+8*0, 7+8*1, 7+8*2, 7+8*3, 7+8*0, 7+8*1, 7+8*2, 7+8*3},\n }\n };\n const uint8_t *off= offset[MB_FIELD][mb_y&1];\n for( i = 0; i < 8; i++ ) {\n int j= MB_FIELD ? i>>2 : i&1;\n int mbn_xy = h->left_mb_xy[j];\n int mbn_type= h->left_type[j];\n if( IS_INTRA( mbn_type ) )\n bS[i] = 4;\n else{\n bS[i] = 1 + !!(h->non_zero_count_cache[12+8*(i>>1)] |\n ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ?\n (h->cbp_table[mbn_xy] & ((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2))\n :\n h->non_zero_count[mbn_xy][ off[i] ]));\n }\n }\n }\n mb_qp = s->current_picture.qscale_table[mb_xy];\n mbn0_qp = s->current_picture.qscale_table[h->left_mb_xy[0]];\n mbn1_qp = s->current_picture.qscale_table[h->left_mb_xy[1]];\n qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;\n bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) +\n get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1;\n rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) +\n get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1;\n qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;\n bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) +\n get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1;\n rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) +\n get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1;\n tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);\n { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\\n"); }\n if(MB_FIELD){\n filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0] );\n filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1] );\n filter_mb_mbaff_edgecv( h, img_cb, uvlinesize, bS , 1, bqp[0] );\n filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1] );\n filter_mb_mbaff_edgecv( h, img_cr, uvlinesize, bS , 1, rqp[0] );\n filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1] );\n }else{\n filter_mb_mbaff_edgev ( h, img_y , 2* linesize, bS , 2, qp [0] );\n filter_mb_mbaff_edgev ( h, img_y + linesize, 2* linesize, bS+1, 2, qp [1] );\n filter_mb_mbaff_edgecv( h, img_cb, 2*uvlinesize, bS , 2, bqp[0] );\n filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1] );\n filter_mb_mbaff_edgecv( h, img_cr, 2*uvlinesize, bS , 2, rqp[0] );\n filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1] );\n }\n }\n#if CONFIG_SMALL\n for( dir = 0; dir < 2; dir++ )\n filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, dir);\n#else\n filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, 0);\n filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, 1);\n#endif\n}', 'static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) {\n int i;\n int index_a = qp + h->slice_alpha_c0_offset;\n int alpha = alpha_table[index_a];\n int beta = beta_table[qp + h->slice_beta_offset];\n for( i = 0; i < 8; i++, pix += stride) {\n const int bS_index = (i >> 1) * bsi;\n if( bS[bS_index] == 0 ) {\n continue;\n }\n if( bS[bS_index] < 4 ) {\n const int tc0 = tc0_table[index_a][bS[bS_index]];\n const int p0 = pix[-1];\n const int p1 = pix[-2];\n const int p2 = pix[-3];\n const int q0 = pix[0];\n const int q1 = pix[1];\n const int q2 = pix[2];\n if( FFABS( p0 - q0 ) < alpha &&\n FFABS( p1 - p0 ) < beta &&\n FFABS( q1 - q0 ) < beta ) {\n int tc = tc0;\n int i_delta;\n if( FFABS( p2 - p0 ) < beta ) {\n if(tc0)\n pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 );\n tc++;\n }\n if( FFABS( q2 - q0 ) < beta ) {\n if(tc0)\n pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 );\n tc++;\n }\n i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc );\n pix[-1] = av_clip_uint8( p0 + i_delta );\n pix[0] = av_clip_uint8( q0 - i_delta );\n tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1);\n }\n }else{\n const int p0 = pix[-1];\n const int p1 = pix[-2];\n const int p2 = pix[-3];\n const int q0 = pix[0];\n const int q1 = pix[1];\n const int q2 = pix[2];\n if( FFABS( p0 - q0 ) < alpha &&\n FFABS( p1 - p0 ) < beta &&\n FFABS( q1 - q0 ) < beta ) {\n if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){\n if( FFABS( p2 - p0 ) < beta)\n {\n const int p3 = pix[-4];\n pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3;\n pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2;\n pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3;\n } else {\n pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;\n }\n if( FFABS( q2 - q0 ) < beta)\n {\n const int q3 = pix[3];\n pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3;\n pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2;\n pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3;\n } else {\n pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;\n }\n }else{\n pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2;\n pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2;\n }\n tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]);\n }\n }\n }\n}']
36,117
0
https://github.com/libav/libav/blob/df84d7d9bdf6b8e6896c711880f130b72738c828/libavcodec/mpegaudiodec.c/#L885
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr, int32_t sb_samples[SBLIMIT]) { register MPA_INT *synth_buf; register const MPA_INT *w, *w2, *p; int j, offset; OUT_INT *samples2; #if FRAC_BITS <= 15 int32_t tmp[32]; int sum, sum2; #else int64_t sum, sum2; #endif offset = *synth_buf_offset; synth_buf = synth_buf_ptr + offset; #if FRAC_BITS <= 15 dct32(tmp, sb_samples); for(j=0;j<32;j++) { synth_buf[j] = av_clip_int16(tmp[j]); } #else dct32(synth_buf, sb_samples); #endif memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT)); samples2 = samples + 31 * incr; w = window; w2 = window + 31; sum = *dither_state; p = synth_buf + 16; SUM8(MACS, sum, w, p); p = synth_buf + 48; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); samples += incr; w++; for(j=1;j<16;j++) { sum2 = 0; p = synth_buf + 16 + j; SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); p = synth_buf + 48 - j; SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); *samples = round_sample(&sum); samples += incr; sum += sum2; *samples2 = round_sample(&sum); samples2 -= incr; w++; w2--; } p = synth_buf + 32; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); *dither_state= sum; offset = (offset - 32) & 511; *synth_buf_offset = offset; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n int32_t sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}']
36,118
0
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/crypto/x509/x509_vfy.c/#L1203
static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer, int *pcrl_score) { X509 *crl_issuer = NULL; X509_NAME *cnm = X509_CRL_get_issuer(crl); int cidx = ctx->error_depth; int i; if (cidx != sk_X509_num(ctx->chain) - 1) cidx++; crl_issuer = sk_X509_value(ctx->chain, cidx); if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { if (*pcrl_score & CRL_SCORE_ISSUER_NAME) { *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT; *pissuer = crl_issuer; return; } } for (cidx++; cidx < sk_X509_num(ctx->chain); cidx++) { crl_issuer = sk_X509_value(ctx->chain, cidx); if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) continue; if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH; *pissuer = crl_issuer; return; } } if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT)) return; for (i = 0; i < sk_X509_num(ctx->untrusted); i++) { crl_issuer = sk_X509_value(ctx->untrusted, i); if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) continue; if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { *pissuer = crl_issuer; *pcrl_score |= CRL_SCORE_AKID; return; } } }
['static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,\n X509 **pissuer, int *pcrl_score)\n{\n X509 *crl_issuer = NULL;\n X509_NAME *cnm = X509_CRL_get_issuer(crl);\n int cidx = ctx->error_depth;\n int i;\n if (cidx != sk_X509_num(ctx->chain) - 1)\n cidx++;\n crl_issuer = sk_X509_value(ctx->chain, cidx);\n if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {\n if (*pcrl_score & CRL_SCORE_ISSUER_NAME) {\n *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT;\n *pissuer = crl_issuer;\n return;\n }\n }\n for (cidx++; cidx < sk_X509_num(ctx->chain); cidx++) {\n crl_issuer = sk_X509_value(ctx->chain, cidx);\n if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))\n continue;\n if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {\n *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH;\n *pissuer = crl_issuer;\n return;\n }\n }\n if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT))\n return;\n for (i = 0; i < sk_X509_num(ctx->untrusted); i++) {\n crl_issuer = sk_X509_value(ctx->untrusted, i);\n if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))\n continue;\n if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {\n *pissuer = crl_issuer;\n *pcrl_score |= CRL_SCORE_AKID;\n return;\n }\n }\n}', 'X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl)\n{\n return crl->crl.issuer;\n}', 'DEFINE_STACK_OF(X509)', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}', 'int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid)\n{\n if (!akid)\n return X509_V_OK;\n if (akid->keyid && issuer->skid &&\n ASN1_OCTET_STRING_cmp(akid->keyid, issuer->skid))\n return X509_V_ERR_AKID_SKID_MISMATCH;\n if (akid->serial &&\n ASN1_INTEGER_cmp(X509_get_serialNumber(issuer), akid->serial))\n return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;\n if (akid->issuer) {\n GENERAL_NAMES *gens;\n GENERAL_NAME *gen;\n X509_NAME *nm = NULL;\n int i;\n gens = akid->issuer;\n for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {\n gen = sk_GENERAL_NAME_value(gens, i);\n if (gen->type == GEN_DIRNAME) {\n nm = gen->d.dirn;\n break;\n }\n }\n if (nm && X509_NAME_cmp(nm, X509_get_issuer_name(issuer)))\n return X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH;\n }\n return X509_V_OK;\n}', 'X509_NAME *X509_get_subject_name(const X509 *a)\n{\n return (a->cert_info.subject);\n}']
36,119
0
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/conf/conf.c/#L490
static int str_copy(LHASH *conf, char *section, char **pto, char *from) { int q,r,rr=0,to=0,len=0; char *s,*e,*rp,*p,*rrp,*np,*cp,v; BUF_MEM *buf; if ((buf=BUF_MEM_new()) == NULL) return(0); len=strlen(from)+1; if (!BUF_MEM_grow(buf,len)) goto err; for (;;) { if (IS_QUOTE(*from)) { q= *from; from++; while ((*from != '\0') && (*from != q)) { if (*from == '\\') { from++; if (*from == '\0') break; } buf->data[to++]= *(from++); } } else if (*from == '\\') { from++; v= *(from++); if (v == '\0') break; else if (v == 'r') v='\r'; else if (v == 'n') v='\n'; else if (v == 'b') v='\b'; else if (v == 't') v='\t'; buf->data[to++]= v; } else if (*from == '\0') break; else if (*from == '$') { rrp=NULL; s= &(from[1]); if (*s == '{') q='}'; else if (*s == '(') q=')'; else q=0; if (q) s++; cp=section; e=np=s; while (IS_ALPHA_NUMERIC(*e)) e++; if ((e[0] == ':') && (e[1] == ':')) { cp=np; rrp=e; rr= *e; *rrp='\0'; e+=2; np=e; while (IS_ALPHA_NUMERIC(*e)) e++; } r= *e; *e='\0'; rp=e; if (q) { if (r != q) { CONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE); goto err; } e++; } p=CONF_get_string(conf,cp,np); if (rrp != NULL) *rrp=rr; *rp=r; if (p == NULL) { CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); goto err; } BUF_MEM_grow(buf,(strlen(p)+len-(e-from))); while (*p) buf->data[to++]= *(p++); from=e; } else buf->data[to++]= *(from++); } buf->data[to]='\0'; if (*pto != NULL) Free(*pto); *pto=buf->data; Free(buf); return(1); err: if (buf != NULL) BUF_MEM_free(buf); return(0); }
["static int str_copy(LHASH *conf, char *section, char **pto, char *from)\n\t{\n\tint q,r,rr=0,to=0,len=0;\n\tchar *s,*e,*rp,*p,*rrp,*np,*cp,v;\n\tBUF_MEM *buf;\n\tif ((buf=BUF_MEM_new()) == NULL) return(0);\n\tlen=strlen(from)+1;\n\tif (!BUF_MEM_grow(buf,len)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (IS_QUOTE(*from))\n\t\t\t{\n\t\t\tq= *from;\n\t\t\tfrom++;\n\t\t\twhile ((*from != '\\0') && (*from != q))\n\t\t\t\t{\n\t\t\t\tif (*from == '\\\\')\n\t\t\t\t\t{\n\t\t\t\t\tfrom++;\n\t\t\t\t\tif (*from == '\\0') break;\n\t\t\t\t\t}\n\t\t\t\tbuf->data[to++]= *(from++);\n\t\t\t\t}\n\t\t\t}\n\t\telse if (*from == '\\\\')\n\t\t\t{\n\t\t\tfrom++;\n\t\t\tv= *(from++);\n\t\t\tif (v == '\\0') break;\n\t\t\telse if (v == 'r') v='\\r';\n\t\t\telse if (v == 'n') v='\\n';\n\t\t\telse if (v == 'b') v='\\b';\n\t\t\telse if (v == 't') v='\\t';\n\t\t\tbuf->data[to++]= v;\n\t\t\t}\n\t\telse if (*from == '\\0')\n\t\t\tbreak;\n\t\telse if (*from == '$')\n\t\t\t{\n\t\t\trrp=NULL;\n\t\t\ts= &(from[1]);\n\t\t\tif (*s == '{')\n\t\t\t\tq='}';\n\t\t\telse if (*s == '(')\n\t\t\t\tq=')';\n\t\t\telse q=0;\n\t\t\tif (q) s++;\n\t\t\tcp=section;\n\t\t\te=np=s;\n\t\t\twhile (IS_ALPHA_NUMERIC(*e))\n\t\t\t\te++;\n\t\t\tif ((e[0] == ':') && (e[1] == ':'))\n\t\t\t\t{\n\t\t\t\tcp=np;\n\t\t\t\trrp=e;\n\t\t\t\trr= *e;\n\t\t\t\t*rrp='\\0';\n\t\t\t\te+=2;\n\t\t\t\tnp=e;\n\t\t\t\twhile (IS_ALPHA_NUMERIC(*e))\n\t\t\t\t\te++;\n\t\t\t\t}\n\t\t\tr= *e;\n\t\t\t*e='\\0';\n\t\t\trp=e;\n\t\t\tif (q)\n\t\t\t\t{\n\t\t\t\tif (r != q)\n\t\t\t\t\t{\n\t\t\t\t\tCONFerr(CONF_F_STR_COPY,CONF_R_NO_CLOSE_BRACE);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\te++;\n\t\t\t\t}\n\t\t\tp=CONF_get_string(conf,cp,np);\n\t\t\tif (rrp != NULL) *rrp=rr;\n\t\t\t*rp=r;\n\t\t\tif (p == NULL)\n\t\t\t\t{\n\t\t\t\tCONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tBUF_MEM_grow(buf,(strlen(p)+len-(e-from)));\n\t\t\twhile (*p)\n\t\t\t\tbuf->data[to++]= *(p++);\n\t\t\tfrom=e;\n\t\t\t}\n\t\telse\n\t\t\tbuf->data[to++]= *(from++);\n\t\t}\n\tbuf->data[to]='\\0';\n\tif (*pto != NULL) Free(*pto);\n\t*pto=buf->data;\n\tFree(buf);\n\treturn(1);\nerr:\n\tif (buf != NULL) BUF_MEM_free(buf);\n\treturn(0);\n\t}", 'BUF_MEM *BUF_MEM_new(void)\n\t{\n\tBUF_MEM *ret;\n\tret=Malloc(sizeof(BUF_MEM));\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->max=0;\n\tret->data=NULL;\n\treturn(ret);\n\t}', 'int BUF_MEM_grow(BUF_MEM *str, int len)\n\t{\n\tchar *ret;\n\tunsigned int n;\n\tif (str->length >= len)\n\t\t{\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=Malloc(n);\n\telse\n\t\tret=Realloc(str->data,n);\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);\n\t\tlen=0;\n\t\t}\n\telse\n\t\t{\n\t\tstr->data=ret;\n\t\tstr->length=len;\n\t\tstr->max=n;\n\t\t}\n\treturn(len);\n\t}']
36,120
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L139
static inline uint64_t get_val(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1); bc->bits >>= n; #else uint64_t ret = bc->bits >> (64 - n); bc->bits <<= n; #endif bc->bits_left -= n; return ret; }
['static int decode_mv_component(BitstreamContext *bc, int v)\n{\n int mv_diff = bitstream_read_vlc(bc, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);\n if (mv_diff < 0)\n return v;\n mv_diff = mvmap[mv_diff];\n if (mv_diff && !bitstream_read_bit(bc))\n mv_diff = -mv_diff;\n v += mv_diff;\n if (v <= -16)\n v += 32;\n else if (v >= 16)\n v -= 32;\n return v;\n}', 'static inline int bitstream_read_vlc(BitstreamContext *bc, VLC_TYPE (*table)[2],\n int bits, int max_depth)\n{\n int nb_bits;\n unsigned idx = bitstream_peek(bc, bits);\n int code = table[idx][0];\n int n = table[idx][1];\n if (max_depth > 1 && n < 0) {\n skip_remaining(bc, bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n if (max_depth > 2 && n < 0) {\n skip_remaining(bc, nb_bits);\n code = set_idx(bc, code, &n, &nb_bits, table);\n }\n }\n skip_remaining(bc, n);\n return code;\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n if (!bc->bits_left)\n refill_64(bc);\n return get_val(bc, 1);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
36,121
0
https://github.com/openssl/openssl/blob/3b1fb1a0226e29c9d7c79ff7fbde21ef9cac4deb/crypto/x509/x509_vfy.c/#L659
static int check_name_constraints(X509_STORE_CTX *ctx) { X509 *x; int i, j, rv; for (i = sk_X509_num(ctx->chain) - 1; i >= 0; i--) { x = sk_X509_value(ctx->chain, i); if (i && (x->ex_flags & EXFLAG_SI)) continue; for (j = sk_X509_num(ctx->chain) - 1; j > i; j--) { NAME_CONSTRAINTS *nc = sk_X509_value(ctx->chain, j)->nc; if (nc) { rv = NAME_CONSTRAINTS_check(x, nc); if (rv != X509_V_OK) { ctx->error = rv; ctx->error_depth = i; ctx->current_cert = x; if (!ctx->verify_cb(0,ctx)) return 0; } } } } return 1; }
['static int check_name_constraints(X509_STORE_CTX *ctx)\n\t{\n\tX509 *x;\n\tint i, j, rv;\n\tfor (i = sk_X509_num(ctx->chain) - 1; i >= 0; i--)\n\t\t{\n\t\tx = sk_X509_value(ctx->chain, i);\n\t\tif (i && (x->ex_flags & EXFLAG_SI))\n\t\t\tcontinue;\n\t\tfor (j = sk_X509_num(ctx->chain) - 1; j > i; j--)\n\t\t\t{\n\t\t\tNAME_CONSTRAINTS *nc = sk_X509_value(ctx->chain, j)->nc;\n\t\t\tif (nc)\n\t\t\t\t{\n\t\t\t\trv = NAME_CONSTRAINTS_check(x, nc);\n\t\t\t\tif (rv != X509_V_OK)\n\t\t\t\t\t{\n\t\t\t\t\tctx->error = rv;\n\t\t\t\t\tctx->error_depth = i;\n\t\t\t\t\tctx->current_cert = x;\n\t\t\t\t\tif (!ctx->verify_cb(0,ctx))\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn 1;\n\t}', 'int sk_num(const _STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}']
36,122
0
https://github.com/openssl/openssl/blob/9e84a42db497e06a38f804b5acd09b6aa4f87db3/crypto/x509/x509_vfy.c/#L2836
static int build_chain(X509_STORE_CTX *ctx) { SSL_DANE *dane = ctx->dane; int num = sk_X509_num(ctx->chain); X509 *cert = sk_X509_value(ctx->chain, num - 1); int ss = cert_self_signed(cert); STACK_OF(X509) *sktmp = NULL; unsigned int search; int may_trusted = 0; int may_alternate = 0; int trust = X509_TRUST_UNTRUSTED; int alt_untrusted = 0; int depth; int ok = 0; int i; if (!ossl_assert(num == 1 && ctx->num_untrusted == num)) { X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR); ctx->error = X509_V_ERR_UNSPECIFIED; return 0; } #define S_DOUNTRUSTED (1 << 0) #define S_DOTRUSTED (1 << 1) #define S_DOALTERNATE (1 << 2) search = (ctx->untrusted != NULL) ? S_DOUNTRUSTED : 0; if (DANETLS_HAS_PKIX(dane) || !DANETLS_HAS_DANE(dane)) { if (search == 0 || ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST) search |= S_DOTRUSTED; else if (!(ctx->param->flags & X509_V_FLAG_NO_ALT_CHAINS)) may_alternate = 1; may_trusted = 1; } if (ctx->untrusted && (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) { X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE); ctx->error = X509_V_ERR_OUT_OF_MEM; return 0; } if (DANETLS_ENABLED(dane) && dane->certs != NULL) { if (sktmp == NULL && (sktmp = sk_X509_new_null()) == NULL) { X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE); ctx->error = X509_V_ERR_OUT_OF_MEM; return 0; } for (i = 0; i < sk_X509_num(dane->certs); ++i) { if (!sk_X509_push(sktmp, sk_X509_value(dane->certs, i))) { sk_X509_free(sktmp); X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE); ctx->error = X509_V_ERR_OUT_OF_MEM; return 0; } } } if (ctx->param->depth > INT_MAX/2) ctx->param->depth = INT_MAX/2; depth = ctx->param->depth + 1; while (search != 0) { X509 *x; X509 *xtmp = NULL; if ((search & S_DOTRUSTED) != 0) { i = num = sk_X509_num(ctx->chain); if ((search & S_DOALTERNATE) != 0) { i = alt_untrusted; } x = sk_X509_value(ctx->chain, i-1); ok = (depth < num) ? 0 : get_issuer(&xtmp, ctx, x); if (ok < 0) { trust = X509_TRUST_REJECTED; ctx->error = X509_V_ERR_STORE_LOOKUP; search = 0; continue; } if (ok > 0) { if ((search & S_DOALTERNATE) != 0) { if (!ossl_assert(num > i && i > 0 && ss == 0)) { X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR); X509_free(xtmp); trust = X509_TRUST_REJECTED; ctx->error = X509_V_ERR_UNSPECIFIED; search = 0; continue; } search &= ~S_DOALTERNATE; for (; num > i; --num) X509_free(sk_X509_pop(ctx->chain)); ctx->num_untrusted = num; if (DANETLS_ENABLED(dane) && dane->mdpth >= ctx->num_untrusted) { dane->mdpth = -1; X509_free(dane->mcert); dane->mcert = NULL; } if (DANETLS_ENABLED(dane) && dane->pdpth >= ctx->num_untrusted) dane->pdpth = -1; } if (ss == 0) { if (!sk_X509_push(ctx->chain, x = xtmp)) { X509_free(xtmp); X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE); trust = X509_TRUST_REJECTED; ctx->error = X509_V_ERR_OUT_OF_MEM; search = 0; continue; } ss = cert_self_signed(x); } else if (num == ctx->num_untrusted) { if (X509_cmp(x, xtmp) != 0) { X509_free(xtmp); ok = 0; } else { X509_free(x); ctx->num_untrusted = --num; (void) sk_X509_set(ctx->chain, num, x = xtmp); } } if (ok) { if (!ossl_assert(ctx->num_untrusted <= num)) { X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR); trust = X509_TRUST_REJECTED; ctx->error = X509_V_ERR_UNSPECIFIED; search = 0; continue; } search &= ~S_DOUNTRUSTED; switch (trust = check_trust(ctx, num)) { case X509_TRUST_TRUSTED: case X509_TRUST_REJECTED: search = 0; continue; } if (ss == 0) continue; } } if ((search & S_DOUNTRUSTED) == 0) { if ((search & S_DOALTERNATE) != 0 && --alt_untrusted > 0) continue; if (!may_alternate || (search & S_DOALTERNATE) != 0 || ctx->num_untrusted < 2) break; search |= S_DOALTERNATE; alt_untrusted = ctx->num_untrusted - 1; ss = 0; } } if ((search & S_DOUNTRUSTED) != 0) { num = sk_X509_num(ctx->chain); if (!ossl_assert(num == ctx->num_untrusted)) { X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR); trust = X509_TRUST_REJECTED; ctx->error = X509_V_ERR_UNSPECIFIED; search = 0; continue; } x = sk_X509_value(ctx->chain, num-1); xtmp = (ss || depth < num) ? NULL : find_issuer(ctx, sktmp, x); if (xtmp == NULL) { search &= ~S_DOUNTRUSTED; if (may_trusted) search |= S_DOTRUSTED; continue; } (void) sk_X509_delete_ptr(sktmp, xtmp); if (!sk_X509_push(ctx->chain, xtmp)) { X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE); trust = X509_TRUST_REJECTED; ctx->error = X509_V_ERR_OUT_OF_MEM; search = 0; continue; } X509_up_ref(x = xtmp); ++ctx->num_untrusted; ss = cert_self_signed(xtmp); switch (trust = check_dane_issuer(ctx, ctx->num_untrusted - 1)) { case X509_TRUST_TRUSTED: case X509_TRUST_REJECTED: search = 0; continue; } } } sk_X509_free(sktmp); num = sk_X509_num(ctx->chain); if (num <= depth) { if (trust == X509_TRUST_UNTRUSTED && DANETLS_HAS_DANE_TA(dane)) trust = check_dane_pkeys(ctx); if (trust == X509_TRUST_UNTRUSTED && num == ctx->num_untrusted) trust = check_trust(ctx, num); } switch (trust) { case X509_TRUST_TRUSTED: return 1; case X509_TRUST_REJECTED: return 0; case X509_TRUST_UNTRUSTED: default: num = sk_X509_num(ctx->chain); if (num > depth) return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_CERT_CHAIN_TOO_LONG); if (DANETLS_ENABLED(dane) && (!DANETLS_HAS_PKIX(dane) || dane->pdpth >= 0)) return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_DANE_NO_MATCH); if (ss && sk_X509_num(ctx->chain) == 1) return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT); if (ss) return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN); if (ctx->num_untrusted < num) return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT); return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY); } }
['static int build_chain(X509_STORE_CTX *ctx)\n{\n SSL_DANE *dane = ctx->dane;\n int num = sk_X509_num(ctx->chain);\n X509 *cert = sk_X509_value(ctx->chain, num - 1);\n int ss = cert_self_signed(cert);\n STACK_OF(X509) *sktmp = NULL;\n unsigned int search;\n int may_trusted = 0;\n int may_alternate = 0;\n int trust = X509_TRUST_UNTRUSTED;\n int alt_untrusted = 0;\n int depth;\n int ok = 0;\n int i;\n if (!ossl_assert(num == 1 && ctx->num_untrusted == num)) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR);\n ctx->error = X509_V_ERR_UNSPECIFIED;\n return 0;\n }\n#define S_DOUNTRUSTED (1 << 0)\n#define S_DOTRUSTED (1 << 1)\n#define S_DOALTERNATE (1 << 2)\n search = (ctx->untrusted != NULL) ? S_DOUNTRUSTED : 0;\n if (DANETLS_HAS_PKIX(dane) || !DANETLS_HAS_DANE(dane)) {\n if (search == 0 || ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST)\n search |= S_DOTRUSTED;\n else if (!(ctx->param->flags & X509_V_FLAG_NO_ALT_CHAINS))\n may_alternate = 1;\n may_trusted = 1;\n }\n if (ctx->untrusted && (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE);\n ctx->error = X509_V_ERR_OUT_OF_MEM;\n return 0;\n }\n if (DANETLS_ENABLED(dane) && dane->certs != NULL) {\n if (sktmp == NULL && (sktmp = sk_X509_new_null()) == NULL) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE);\n ctx->error = X509_V_ERR_OUT_OF_MEM;\n return 0;\n }\n for (i = 0; i < sk_X509_num(dane->certs); ++i) {\n if (!sk_X509_push(sktmp, sk_X509_value(dane->certs, i))) {\n sk_X509_free(sktmp);\n X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE);\n ctx->error = X509_V_ERR_OUT_OF_MEM;\n return 0;\n }\n }\n }\n if (ctx->param->depth > INT_MAX/2)\n ctx->param->depth = INT_MAX/2;\n depth = ctx->param->depth + 1;\n while (search != 0) {\n X509 *x;\n X509 *xtmp = NULL;\n if ((search & S_DOTRUSTED) != 0) {\n i = num = sk_X509_num(ctx->chain);\n if ((search & S_DOALTERNATE) != 0) {\n i = alt_untrusted;\n }\n x = sk_X509_value(ctx->chain, i-1);\n ok = (depth < num) ? 0 : get_issuer(&xtmp, ctx, x);\n if (ok < 0) {\n trust = X509_TRUST_REJECTED;\n ctx->error = X509_V_ERR_STORE_LOOKUP;\n search = 0;\n continue;\n }\n if (ok > 0) {\n if ((search & S_DOALTERNATE) != 0) {\n if (!ossl_assert(num > i && i > 0 && ss == 0)) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR);\n X509_free(xtmp);\n trust = X509_TRUST_REJECTED;\n ctx->error = X509_V_ERR_UNSPECIFIED;\n search = 0;\n continue;\n }\n search &= ~S_DOALTERNATE;\n for (; num > i; --num)\n X509_free(sk_X509_pop(ctx->chain));\n ctx->num_untrusted = num;\n if (DANETLS_ENABLED(dane) &&\n dane->mdpth >= ctx->num_untrusted) {\n dane->mdpth = -1;\n X509_free(dane->mcert);\n dane->mcert = NULL;\n }\n if (DANETLS_ENABLED(dane) &&\n dane->pdpth >= ctx->num_untrusted)\n dane->pdpth = -1;\n }\n if (ss == 0) {\n if (!sk_X509_push(ctx->chain, x = xtmp)) {\n X509_free(xtmp);\n X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE);\n trust = X509_TRUST_REJECTED;\n ctx->error = X509_V_ERR_OUT_OF_MEM;\n search = 0;\n continue;\n }\n ss = cert_self_signed(x);\n } else if (num == ctx->num_untrusted) {\n if (X509_cmp(x, xtmp) != 0) {\n X509_free(xtmp);\n ok = 0;\n } else {\n X509_free(x);\n ctx->num_untrusted = --num;\n (void) sk_X509_set(ctx->chain, num, x = xtmp);\n }\n }\n if (ok) {\n if (!ossl_assert(ctx->num_untrusted <= num)) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR);\n trust = X509_TRUST_REJECTED;\n ctx->error = X509_V_ERR_UNSPECIFIED;\n search = 0;\n continue;\n }\n search &= ~S_DOUNTRUSTED;\n switch (trust = check_trust(ctx, num)) {\n case X509_TRUST_TRUSTED:\n case X509_TRUST_REJECTED:\n search = 0;\n continue;\n }\n if (ss == 0)\n continue;\n }\n }\n if ((search & S_DOUNTRUSTED) == 0) {\n if ((search & S_DOALTERNATE) != 0 && --alt_untrusted > 0)\n continue;\n if (!may_alternate || (search & S_DOALTERNATE) != 0 ||\n ctx->num_untrusted < 2)\n break;\n search |= S_DOALTERNATE;\n alt_untrusted = ctx->num_untrusted - 1;\n ss = 0;\n }\n }\n if ((search & S_DOUNTRUSTED) != 0) {\n num = sk_X509_num(ctx->chain);\n if (!ossl_assert(num == ctx->num_untrusted)) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_INTERNAL_ERROR);\n trust = X509_TRUST_REJECTED;\n ctx->error = X509_V_ERR_UNSPECIFIED;\n search = 0;\n continue;\n }\n x = sk_X509_value(ctx->chain, num-1);\n xtmp = (ss || depth < num) ? NULL : find_issuer(ctx, sktmp, x);\n if (xtmp == NULL) {\n search &= ~S_DOUNTRUSTED;\n if (may_trusted)\n search |= S_DOTRUSTED;\n continue;\n }\n (void) sk_X509_delete_ptr(sktmp, xtmp);\n if (!sk_X509_push(ctx->chain, xtmp)) {\n X509err(X509_F_BUILD_CHAIN, ERR_R_MALLOC_FAILURE);\n trust = X509_TRUST_REJECTED;\n ctx->error = X509_V_ERR_OUT_OF_MEM;\n search = 0;\n continue;\n }\n X509_up_ref(x = xtmp);\n ++ctx->num_untrusted;\n ss = cert_self_signed(xtmp);\n switch (trust = check_dane_issuer(ctx, ctx->num_untrusted - 1)) {\n case X509_TRUST_TRUSTED:\n case X509_TRUST_REJECTED:\n search = 0;\n continue;\n }\n }\n }\n sk_X509_free(sktmp);\n num = sk_X509_num(ctx->chain);\n if (num <= depth) {\n if (trust == X509_TRUST_UNTRUSTED && DANETLS_HAS_DANE_TA(dane))\n trust = check_dane_pkeys(ctx);\n if (trust == X509_TRUST_UNTRUSTED && num == ctx->num_untrusted)\n trust = check_trust(ctx, num);\n }\n switch (trust) {\n case X509_TRUST_TRUSTED:\n return 1;\n case X509_TRUST_REJECTED:\n return 0;\n case X509_TRUST_UNTRUSTED:\n default:\n num = sk_X509_num(ctx->chain);\n if (num > depth)\n return verify_cb_cert(ctx, NULL, num-1,\n X509_V_ERR_CERT_CHAIN_TOO_LONG);\n if (DANETLS_ENABLED(dane) &&\n (!DANETLS_HAS_PKIX(dane) || dane->pdpth >= 0))\n return verify_cb_cert(ctx, NULL, num-1, X509_V_ERR_DANE_NO_MATCH);\n if (ss && sk_X509_num(ctx->chain) == 1)\n return verify_cb_cert(ctx, NULL, num-1,\n X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT);\n if (ss)\n return verify_cb_cert(ctx, NULL, num-1,\n X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN);\n if (ctx->num_untrusted < num)\n return verify_cb_cert(ctx, NULL, num-1,\n X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT);\n return verify_cb_cert(ctx, NULL, num-1,\n X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY);\n }\n}', 'DEFINE_STACK_OF(X509)', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}', 'static int cert_self_signed(X509 *x)\n{\n X509_check_purpose(x, -1, 0);\n if (x->ex_flags & EXFLAG_SS)\n return 1;\n else\n return 0;\n}']
36,123
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/mpegaudiodec.c/#L904
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr, int32_t sb_samples[SBLIMIT]) { int32_t tmp[32]; register MPA_INT *synth_buf; register const MPA_INT *w, *w2, *p; int j, offset, v; OUT_INT *samples2; #if FRAC_BITS <= 15 int sum, sum2; #else int64_t sum, sum2; #endif dct32(tmp, sb_samples); offset = *synth_buf_offset; synth_buf = synth_buf_ptr + offset; for(j=0;j<32;j++) { v = tmp[j]; #if FRAC_BITS <= 15 v = av_clip_int16(v); #endif synth_buf[j] = v; } memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT)); samples2 = samples + 31 * incr; w = window; w2 = window + 31; sum = *dither_state; p = synth_buf + 16; SUM8(MACS, sum, w, p); p = synth_buf + 48; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); samples += incr; w++; for(j=1;j<16;j++) { sum2 = 0; p = synth_buf + 16 + j; SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); p = synth_buf + 48 - j; SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); *samples = round_sample(&sum); samples += incr; sum += sum2; *samples2 = round_sample(&sum); samples2 -= incr; w++; w2--; } p = synth_buf + 32; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); *dither_state= sum; offset = (offset - 32) & 511; *synth_buf_offset = offset; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n mpa_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n int32_t sb_samples[SBLIMIT])\n{\n int32_t tmp[32];\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset, v;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n dct32(tmp, sb_samples);\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n for(j=0;j<32;j++) {\n v = tmp[j];\n#if FRAC_BITS <= 15\n v = av_clip_int16(v);\n#endif\n synth_buf[j] = v;\n }\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}']
36,124
0
https://github.com/openssl/openssl/blob/e334d78b87517652cc34825aff7b6fc7be9a1e83/crypto/lhash/lhash.c/#L359
static void contract(LHASH *lh) { LHASH_NODE **n,*n1,*np; np=lh->b[lh->p+lh->pmax-1]; lh->b[lh->p+lh->pmax-1]=NULL; if (lh->p == 0) { n=(LHASH_NODE **)Realloc((char *)lh->b, (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); if (n == NULL) { lh->error++; return; } lh->num_contract_reallocs++; lh->num_alloc_nodes/=2; lh->pmax/=2; lh->p=lh->pmax-1; lh->b=n; } else lh->p--; lh->num_nodes--; lh->num_contracts++; n1=lh->b[(int)lh->p]; if (n1 == NULL) lh->b[(int)lh->p]=np; else { while (n1->next != NULL) n1=n1->next; n1->next=np; } }
['static int ssl3_get_certificate_request(SSL *s)\n\t{\n\tint ok,ret=0;\n\tunsigned long n,nc,l;\n\tunsigned int llen,ctype_num,i;\n\tX509_NAME *xn=NULL;\n\tunsigned char *p,*d,*q;\n\tSTACK_OF(X509_NAME) *ca_sk=NULL;\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_CR_CERT_REQ_A,\n\t\tSSL3_ST_CR_CERT_REQ_B,\n\t\t-1,\n#if defined(MSDOS) && !defined(WIN32)\n\t\t1024*30,\n#else\n\t\t1024*100,\n#endif\n\t\t&ok);\n\tif (!ok) return((int)n);\n\ts->s3->tmp.cert_req=0;\n\tif (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tif (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (s->version > SSL3_VERSION)\n\t\t{\n\t\tl=s->s3->tmp.new_cipher->algorithms;\n\t\tif (l & SSL_aNULL)\n\t\t\t{\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\td=p=(unsigned char *)s->init_buf->data;\n\tif ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tctype_num= *(p++);\n\tif (ctype_num > SSL3_CT_NUMBER)\n\t\tctype_num=SSL3_CT_NUMBER;\n\tfor (i=0; i<ctype_num; i++)\n\t\ts->s3->tmp.ctype[i]= p[i];\n\tp+=ctype_num;\n\tn2s(p,llen);\n#if 0\n{\nFILE *out;\nout=fopen("/tmp/vsign.der","w");\nfwrite(p,1,llen,out);\nfclose(out);\n}\n#endif\n\tif ((llen+ctype_num+2+1) != n)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);\n\t\tgoto err;\n\t\t}\n\tfor (nc=0; nc<llen; )\n\t\t{\n\t\tn2s(p,l);\n\t\tif ((l+nc+2) > llen)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))\n\t\t\t\tgoto cont;\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tq=p;\n\t\tif ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)\n\t\t\t{\n\t\t\tif (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)\n\t\t\t\tgoto cont;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (q != (p+l))\n\t\t\t{\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!sk_X509_NAME_push(ca_sk,xn))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=l;\n\t\tnc+=l+2;\n\t\t}\n\tif (0)\n\t\t{\ncont:\n\t\tERR_clear_error();\n\t\t}\n\ts->s3->tmp.cert_req=1;\n\ts->s3->tmp.ctype_num=ctype_num;\n\tif (s->s3->tmp.ca_names != NULL)\n\t\tsk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);\n\ts->s3->tmp.ca_names=ca_sk;\n\tca_sk=NULL;\n\tret=1;\nerr:\n\tif (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);\n\treturn(ret);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t 4-s->init_num);\n\t\tif (i < (4-s->init_num))\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\tif (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);\n\t\tif (i != (int)n)\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\t}\n\t*ok=1;\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)Realloc((char *)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}']
36,125
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L322
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 pkey_ec_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)\n{\n EC_KEY *ec = NULL;\n EC_PKEY_CTX *dctx = ctx->data;\n int ret = 0;\n if (dctx->gen_group == NULL) {\n ECerr(EC_F_PKEY_EC_PARAMGEN, EC_R_NO_PARAMETERS_SET);\n return 0;\n }\n ec = EC_KEY_new();\n if (ec == NULL)\n return 0;\n ret = EC_KEY_set_group(ec, dctx->gen_group);\n if (ret)\n EVP_PKEY_assign_EC_KEY(pkey, ec);\n else\n EC_KEY_free(ec);\n return ret;\n}', 'int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)\n{\n if (key->meth->set_group != NULL && key->meth->set_group(key, group) == 0)\n return 0;\n EC_GROUP_free(key->group);\n key->group = EC_GROUP_dup(group);\n return (key->group == NULL) ? 0 : 1;\n}', 'EC_GROUP *EC_GROUP_dup(const EC_GROUP *a)\n{\n EC_GROUP *t = NULL;\n int ok = 0;\n if (a == NULL)\n return NULL;\n if ((t = EC_GROUP_new(a->meth)) == NULL)\n return NULL;\n if (!EC_GROUP_copy(t, a))\n goto err;\n ok = 1;\n err:\n if (!ok) {\n EC_GROUP_free(t);\n return NULL;\n }\n return t;\n}', 'int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)\n{\n if (dest->meth->group_copy == 0) {\n ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (dest->meth != src->meth) {\n ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (dest == src)\n return 1;\n dest->pre_comp_type = src->pre_comp_type;\n switch (src->pre_comp_type) {\n case PCT_none:\n dest->pre_comp.ec = NULL;\n break;\n case PCT_nistz256:\n#ifdef ECP_NISTZ256_ASM\n dest->pre_comp.nistz256 = EC_nistz256_pre_comp_dup(src->pre_comp.nistz256);\n#endif\n break;\n#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128\n case PCT_nistp224:\n dest->pre_comp.nistp224 = EC_nistp224_pre_comp_dup(src->pre_comp.nistp224);\n break;\n case PCT_nistp256:\n dest->pre_comp.nistp256 = EC_nistp256_pre_comp_dup(src->pre_comp.nistp256);\n break;\n case PCT_nistp521:\n dest->pre_comp.nistp521 = EC_nistp521_pre_comp_dup(src->pre_comp.nistp521);\n break;\n#else\n case PCT_nistp224:\n case PCT_nistp256:\n case PCT_nistp521:\n break;\n#endif\n case PCT_ec:\n dest->pre_comp.ec = EC_ec_pre_comp_dup(src->pre_comp.ec);\n break;\n }\n if (src->mont_data != NULL) {\n if (dest->mont_data == NULL) {\n dest->mont_data = BN_MONT_CTX_new();\n if (dest->mont_data == NULL)\n return 0;\n }\n if (!BN_MONT_CTX_copy(dest->mont_data, src->mont_data))\n return 0;\n } else {\n BN_MONT_CTX_free(dest->mont_data);\n dest->mont_data = NULL;\n }\n if (src->generator != NULL) {\n if (dest->generator == NULL) {\n dest->generator = EC_POINT_new(dest);\n if (dest->generator == NULL)\n return 0;\n }\n if (!EC_POINT_copy(dest->generator, src->generator))\n return 0;\n } else {\n EC_POINT_clear_free(dest->generator);\n dest->generator = NULL;\n }\n if ((src->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {\n if (!BN_copy(dest->order, src->order))\n return 0;\n if (!BN_copy(dest->cofactor, src->cofactor))\n return 0;\n }\n dest->curve_name = src->curve_name;\n dest->asn1_flag = src->asn1_flag;\n dest->asn1_form = src->asn1_form;\n if (src->seed) {\n OPENSSL_free(dest->seed);\n dest->seed = OPENSSL_malloc(src->seed_len);\n if (dest->seed == NULL)\n return 0;\n if (!memcpy(dest->seed, src->seed, src->seed_len))\n return 0;\n dest->seed_len = src->seed_len;\n } else {\n OPENSSL_free(dest->seed);\n dest->seed = NULL;\n dest->seed_len = 0;\n }\n return dest->meth->group_copy(dest, src);\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}']
36,126
0
https://github.com/libav/libav/blob/493f54ada083b4d6c8f14f02607224fe258c211c/ffmpeg.c/#L3237
static void new_audio_stream(AVFormatContext *oc) { AVStream *st; AVCodecContext *audio_enc; enum CodecID codec_id; st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); av_exit(1); } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO); bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters; audio_bitstream_filters= NULL; avcodec_thread_init(st->codec, thread_count); audio_enc = st->codec; audio_enc->codec_type = CODEC_TYPE_AUDIO; if(audio_codec_tag) audio_enc->codec_tag= audio_codec_tag; if (oc->oformat->flags & AVFMT_GLOBALHEADER) { audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER; avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER; } if (audio_stream_copy) { st->stream_copy = 1; audio_enc->channels = audio_channels; } else { AVCodec *codec; set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); if (audio_codec_name) { codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1); codec = avcodec_find_encoder_by_name(audio_codec_name); output_codecs[nb_ocodecs] = codec; } else { codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO); codec = avcodec_find_encoder(codec_id); } audio_enc->codec_id = codec_id; if (audio_qscale > QSCALE_NONE) { audio_enc->flags |= CODEC_FLAG_QSCALE; audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale; } audio_enc->channels = audio_channels; audio_enc->sample_fmt = audio_sample_fmt; audio_enc->channel_layout = channel_layout; if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels) audio_enc->channel_layout = 0; if(codec && codec->sample_fmts){ const enum SampleFormat *p= codec->sample_fmts; for(; *p!=-1; p++){ if(*p == audio_enc->sample_fmt) break; } if(*p == -1) audio_enc->sample_fmt = codec->sample_fmts[0]; } } nb_ocodecs++; audio_enc->sample_rate = audio_sample_rate; audio_enc->time_base= (AVRational){1, audio_sample_rate}; if (audio_language) { av_metadata_set(&st->metadata, "language", audio_language); av_freep(&audio_language); } audio_disable = 0; av_freep(&audio_codec_name); audio_stream_copy = 0; }
['static void new_audio_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *audio_enc;\n enum CodecID codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;\n audio_bitstream_filters= NULL;\n avcodec_thread_init(st->codec, thread_count);\n audio_enc = st->codec;\n audio_enc->codec_type = CODEC_TYPE_AUDIO;\n if(audio_codec_tag)\n audio_enc->codec_tag= audio_codec_tag;\n if (oc->oformat->flags & AVFMT_GLOBALHEADER) {\n audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if (audio_stream_copy) {\n st->stream_copy = 1;\n audio_enc->channels = audio_channels;\n } else {\n AVCodec *codec;\n set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (audio_codec_name) {\n codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);\n codec = avcodec_find_encoder_by_name(audio_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);\n codec = avcodec_find_encoder(codec_id);\n }\n audio_enc->codec_id = codec_id;\n if (audio_qscale > QSCALE_NONE) {\n audio_enc->flags |= CODEC_FLAG_QSCALE;\n audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;\n }\n audio_enc->channels = audio_channels;\n audio_enc->sample_fmt = audio_sample_fmt;\n audio_enc->channel_layout = channel_layout;\n if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)\n audio_enc->channel_layout = 0;\n if(codec && codec->sample_fmts){\n const enum SampleFormat *p= codec->sample_fmts;\n for(; *p!=-1; p++){\n if(*p == audio_enc->sample_fmt)\n break;\n }\n if(*p == -1)\n audio_enc->sample_fmt = codec->sample_fmts[0];\n }\n }\n nb_ocodecs++;\n audio_enc->sample_rate = audio_sample_rate;\n audio_enc->time_base= (AVRational){1, audio_sample_rate};\n if (audio_language) {\n av_metadata_set(&st->metadata, "language", audio_language);\n av_freep(&audio_language);\n }\n audio_disable = 0;\n av_freep(&audio_codec_name);\n audio_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n st->probe_packets = MAX_PROBE_PACKETS;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}']
36,127
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 int do_i2b(unsigned char **out, EVP_PKEY *pk, int ispub)\n\t{\n\tunsigned char *p;\n\tunsigned int bitlen, magic = 0, keyalg;\n\tint outlen, noinc = 0;\n\tif (pk->type == EVP_PKEY_DSA)\n\t\t{\n\t\tbitlen = check_bitlen_dsa(pk->pkey.dsa, ispub, &magic);\n\t\tkeyalg = MS_KEYALG_DSS_SIGN;\n\t\t}\n\telse if (pk->type == EVP_PKEY_RSA)\n\t\t{\n\t\tbitlen = check_bitlen_rsa(pk->pkey.rsa, ispub, &magic);\n\t\tkeyalg = MS_KEYALG_RSA_KEYX;\n\t\t}\n\telse\n\t\treturn -1;\n\tif (bitlen == 0)\n\t\treturn -1;\n\toutlen = 16 + blob_length(bitlen,\n\t\t\tkeyalg == MS_KEYALG_DSS_SIGN ? 1 : 0, ispub);\n\tif (out == NULL)\n\t\treturn outlen;\n\tif (*out)\n\t\tp = *out;\n\telse\n\t\t{\n\t\tp = OPENSSL_malloc(outlen);\n\t\tif (!p)\n\t\t\treturn -1;\n\t\t*out = p;\n\t\tnoinc = 1;\n\t\t}\n\tif (ispub)\n\t\t*p++ = MS_PUBLICKEYBLOB;\n\telse\n\t\t*p++ = MS_PRIVATEKEYBLOB;\n\t*p++ = 0x2;\n\t*p++ = 0;\n\t*p++ = 0;\n\twrite_ledword(&p, keyalg);\n\twrite_ledword(&p, magic);\n\twrite_ledword(&p, bitlen);\n\tif (keyalg == MS_KEYALG_DSS_SIGN)\n\t\twrite_dsa(&p, pk->pkey.dsa, ispub);\n\telse\n\t\twrite_rsa(&p, pk->pkey.rsa, ispub);\n\tif (!noinc)\n\t\t*out += outlen;\n\treturn outlen;\n\t}', 'static void write_rsa(unsigned char **out, RSA *rsa, int ispub)\n\t{\n\tint nbyte, hnbyte;\n\tnbyte = BN_num_bytes(rsa->n);\n\thnbyte = (BN_num_bits(rsa->n) + 15) >> 4;\n\twrite_lebn(out, rsa->e, 4);\n\twrite_lebn(out, rsa->n, -1);\n\tif (ispub)\n\t\treturn;\n\twrite_lebn(out, rsa->p, hnbyte);\n\twrite_lebn(out, rsa->q, hnbyte);\n\twrite_lebn(out, rsa->dmp1, hnbyte);\n\twrite_lebn(out, rsa->dmq1, hnbyte);\n\twrite_lebn(out, rsa->iqmp, hnbyte);\n\twrite_lebn(out, rsa->d, nbyte);\n\t}', 'static void write_lebn(unsigned char **out, const BIGNUM *bn, int len)\n\t{\n\tint nb, i;\n\tunsigned char *p = *out, *q, c;\n\tnb = BN_num_bytes(bn);\n\tBN_bn2bin(bn, p);\n\tq = p + nb - 1;\n\tfor (i = 0; i < nb/2; i++)\n\t\t{\n\t\tc = *p;\n\t\t*p++ = *q;\n\t\t*q-- = c;\n\t\t}\n\t*out += nb;\n\tif (len > 0)\n\t\t{\n\t\tlen -= nb;\n\t\tif (len > 0)\n\t\t\t{\n\t\t\tmemset(*out, 0, len);\n\t\t\t*out += len;\n\t\t\t}\n\t\t}\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']
36,128
0
https://github.com/libav/libav/blob/acf91215c74a91eb3b86af01dcb1d3c78d0e2310/libavformat/movenc.c/#L3198
static void enable_tracks(AVFormatContext *s) { MOVMuxContext *mov = s->priv_data; int i; int enabled[AVMEDIA_TYPE_NB]; int first[AVMEDIA_TYPE_NB]; for (i = 0; i < AVMEDIA_TYPE_NB; i++) { enabled[i] = 0; first[i] = -1; } for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN || st->codec->codec_type >= AVMEDIA_TYPE_NB) continue; if (first[st->codec->codec_type] < 0) first[st->codec->codec_type] = i; if (st->disposition & AV_DISPOSITION_DEFAULT) { mov->tracks[i].flags |= MOV_TRACK_ENABLED; enabled[st->codec->codec_type]++; } } for (i = 0; i < AVMEDIA_TYPE_NB; i++) { switch (i) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: case AVMEDIA_TYPE_SUBTITLE: if (enabled[i] > 1) mov->per_stream_grouping = 1; if (!enabled[i] && first[i] >= 0) mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED; break; } } }
['static void enable_tracks(AVFormatContext *s)\n{\n MOVMuxContext *mov = s->priv_data;\n int i;\n int enabled[AVMEDIA_TYPE_NB];\n int first[AVMEDIA_TYPE_NB];\n for (i = 0; i < AVMEDIA_TYPE_NB; i++) {\n enabled[i] = 0;\n first[i] = -1;\n }\n for (i = 0; i < s->nb_streams; i++) {\n AVStream *st = s->streams[i];\n if (st->codec->codec_type <= AVMEDIA_TYPE_UNKNOWN ||\n st->codec->codec_type >= AVMEDIA_TYPE_NB)\n continue;\n if (first[st->codec->codec_type] < 0)\n first[st->codec->codec_type] = i;\n if (st->disposition & AV_DISPOSITION_DEFAULT) {\n mov->tracks[i].flags |= MOV_TRACK_ENABLED;\n enabled[st->codec->codec_type]++;\n }\n }\n for (i = 0; i < AVMEDIA_TYPE_NB; i++) {\n switch (i) {\n case AVMEDIA_TYPE_VIDEO:\n case AVMEDIA_TYPE_AUDIO:\n case AVMEDIA_TYPE_SUBTITLE:\n if (enabled[i] > 1)\n mov->per_stream_grouping = 1;\n if (!enabled[i] && first[i] >= 0)\n mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;\n break;\n }\n }\n}']
36,129
0
https://github.com/nginx/nginx/blob/d81db904550f719907df5922f7d8c384dd349cdc/src/http/ngx_http_core_module.c/#L2587
ngx_int_t ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t *uri, ngx_str_t *args) { ngx_http_core_srv_conf_t *cscf; r->uri_changes--; if (r->uri_changes == 0) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "rewrite or internal redirection cycle " "while internally redirecting to \"%V\"", uri); r->main->count++; ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); return NGX_DONE; } r->uri = *uri; if (args) { r->args = *args; } else { ngx_str_null(&r->args); } ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "internal redirect: \"%V?%V\"", uri, &r->args); ngx_http_set_exten(r); ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module); cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); r->loc_conf = cscf->ctx->loc_conf; ngx_http_update_location_config(r); #if (NGX_HTTP_CACHE) r->cache = NULL; #endif r->internal = 1; r->valid_unparsed_uri = 0; r->add_uri_to_alias = 0; r->main->count++; ngx_http_handler(r); return NGX_DONE; }
['static void\nngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ssize_t n;\n ngx_int_t rc;\n ngx_time_t *tp;\n ngx_connection_t *c;\n c = u->peer.connection;\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream process header");\n c->log->action = "reading response header from upstream";\n if (c->read->timedout) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);\n return;\n }\n if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n if (u->buffer.start == NULL) {\n u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);\n if (u->buffer.start == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->buffer.pos = u->buffer.start;\n u->buffer.last = u->buffer.start;\n u->buffer.end = u->buffer.start + u->conf->buffer_size;\n u->buffer.temporary = 1;\n u->buffer.tag = u->output.tag;\n if (ngx_list_init(&u->headers_in.headers, r->pool, 8,\n sizeof(ngx_table_elt_t))\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n#if (NGX_HTTP_CACHE)\n if (r->cache) {\n u->buffer.pos += r->cache->header_start;\n u->buffer.last = u->buffer.pos;\n }\n#endif\n }\n for ( ;; ) {\n n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);\n if (n == NGX_AGAIN) {\n#if 0\n ngx_add_timer(rev, u->read_timeout);\n#endif\n if (ngx_handle_read_event(c->read, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\n if (n == 0) {\n ngx_log_error(NGX_LOG_ERR, c->log, 0,\n "upstream prematurely closed connection");\n }\n if (n == NGX_ERROR || n == 0) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n u->buffer.last += n;\n#if 0\n u->valid_header_in = 0;\n u->peer.cached = 0;\n#endif\n rc = u->process_header(r);\n if (rc == NGX_AGAIN) {\n if (u->buffer.last == u->buffer.end) {\n ngx_log_error(NGX_LOG_ERR, c->log, 0,\n "upstream sent too big header");\n ngx_http_upstream_next(r, u,\n NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n return;\n }\n continue;\n }\n break;\n }\n if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n return;\n }\n if (rc == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n tp = ngx_timeofday();\n u->state->header_sec = tp->sec - u->state->response_sec;\n u->state->header_msec = tp->msec - u->state->response_msec;\n if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {\n if (ngx_http_upstream_test_next(r, u) == NGX_OK) {\n return;\n }\n if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) {\n return;\n }\n }\n if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {\n return;\n }\n if (!r->subrequest_in_memory) {\n ngx_http_upstream_send_response(r, u);\n return;\n }\n if (u->input_filter == NULL) {\n u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;\n u->input_filter = ngx_http_upstream_non_buffered_filter;\n u->input_filter_ctx = r;\n }\n if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n n = u->buffer.last - u->buffer.pos;\n if (n) {\n u->buffer.last = u->buffer.pos;\n u->state->response_length += n;\n if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n }\n if (u->length == 0) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n u->read_event_handler = ngx_http_upstream_process_body_in_memory;\n ngx_http_upstream_process_body_in_memory(r, u);\n}', "static ngx_int_t\nngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_str_t uri, args;\n ngx_uint_t i, flags;\n ngx_list_part_t *part;\n ngx_table_elt_t *h;\n ngx_http_upstream_header_t *hh;\n ngx_http_upstream_main_conf_t *umcf;\n umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n if (u->headers_in.x_accel_redirect\n && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT))\n {\n ngx_http_upstream_finalize_request(r, u, NGX_DECLINED);\n part = &u->headers_in.headers.part;\n h = part->elts;\n for (i = 0; ; i++) {\n if (i >= part->nelts) {\n if (part->next == NULL) {\n break;\n }\n part = part->next;\n h = part->elts;\n i = 0;\n }\n hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,\n h[i].lowcase_key, h[i].key.len);\n if (hh && hh->redirect) {\n if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {\n ngx_http_finalize_request(r,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n }\n }\n uri = u->headers_in.x_accel_redirect->value;\n if (uri.data[0] == '@') {\n ngx_http_named_location(r, &uri);\n } else {\n ngx_str_null(&args);\n flags = NGX_HTTP_LOG_UNSAFE;\n if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);\n return NGX_DONE;\n }\n if (r->method != NGX_HTTP_HEAD) {\n r->method = NGX_HTTP_GET;\n }\n ngx_http_internal_redirect(r, &uri, &args);\n }\n ngx_http_finalize_request(r, NGX_DONE);\n return NGX_DONE;\n }\n part = &u->headers_in.headers.part;\n h = part->elts;\n for (i = 0; ; i++) {\n if (i >= part->nelts) {\n if (part->next == NULL) {\n break;\n }\n part = part->next;\n h = part->elts;\n i = 0;\n }\n if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,\n h[i].lowcase_key, h[i].key.len))\n {\n continue;\n }\n hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,\n h[i].lowcase_key, h[i].key.len);\n if (hh) {\n if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n continue;\n }\n if (ngx_http_upstream_copy_header_line(r, &h[i], 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n }\n if (r->headers_out.server && r->headers_out.server->value.data == NULL) {\n r->headers_out.server->hash = 0;\n }\n if (r->headers_out.date && r->headers_out.date->value.data == NULL) {\n r->headers_out.date->hash = 0;\n }\n r->headers_out.status = u->headers_in.status_n;\n r->headers_out.status_line = u->headers_in.status_line;\n r->headers_out.content_length_n = u->headers_in.content_length_n;\n r->disable_not_modified = !u->cacheable;\n if (u->conf->force_ranges) {\n r->allow_ranges = 1;\n r->single_range = 1;\n#if (NGX_HTTP_CACHE)\n if (r->cached) {\n r->single_range = 0;\n }\n#endif\n }\n u->length = -1;\n return NGX_OK;\n}", 'static void\nngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,\n ngx_http_upstream_t *u)\n{\n size_t size;\n ssize_t n;\n ngx_buf_t *b;\n ngx_event_t *rev;\n ngx_connection_t *c;\n c = u->peer.connection;\n rev = c->read;\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream process body on memory");\n if (rev->timedout) {\n ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);\n return;\n }\n b = &u->buffer;\n for ( ;; ) {\n size = b->end - b->last;\n if (size == 0) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "upstream buffer is too small to read response");\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n n = c->recv(c, b->last, size);\n if (n == NGX_AGAIN) {\n break;\n }\n if (n == 0 || n == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, n);\n return;\n }\n u->state->response_length += n;\n if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n if (!rev->ready) {\n break;\n }\n }\n if (u->length == 0) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (ngx_handle_read_event(rev, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n if (rev->active) {\n ngx_add_timer(rev, u->conf->read_timeout);\n } else if (rev->timer_set) {\n ngx_del_timer(rev);\n }\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n ngx_http_upstream_t *u, ngx_int_t rc)\n{\n ngx_uint_t flush;\n ngx_time_t *tp;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "finalize http upstream request: %i", rc);\n if (u->cleanup == NULL) {\n ngx_http_finalize_request(r, NGX_DONE);\n return;\n }\n *u->cleanup = NULL;\n u->cleanup = NULL;\n if (u->resolved && u->resolved->ctx) {\n ngx_resolve_name_done(u->resolved->ctx);\n u->resolved->ctx = NULL;\n }\n if (u->state && u->state->response_sec) {\n tp = ngx_timeofday();\n u->state->response_sec = tp->sec - u->state->response_sec;\n u->state->response_msec = tp->msec - u->state->response_msec;\n if (u->pipe && u->pipe->read_length) {\n u->state->response_length = u->pipe->read_length;\n }\n }\n u->finalize_request(r, rc);\n if (u->peer.free && u->peer.sockaddr) {\n u->peer.free(&u->peer, u->peer.data, 0);\n u->peer.sockaddr = NULL;\n }\n if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n if (u->peer.connection->ssl) {\n u->peer.connection->ssl->no_wait_shutdown = 1;\n (void) ngx_ssl_shutdown(u->peer.connection);\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "close http upstream connection: %d",\n u->peer.connection->fd);\n if (u->peer.connection->pool) {\n ngx_destroy_pool(u->peer.connection->pool);\n }\n ngx_close_connection(u->peer.connection);\n }\n u->peer.connection = NULL;\n if (u->pipe && u->pipe->temp_file) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream temp fd: %d",\n u->pipe->temp_file->file.fd);\n }\n if (u->store && u->pipe && u->pipe->temp_file\n && u->pipe->temp_file->file.fd != NGX_INVALID_FILE)\n {\n if (ngx_delete_file(u->pipe->temp_file->file.name.data)\n == NGX_FILE_ERROR)\n {\n ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,\n ngx_delete_file_n " \\"%s\\" failed",\n u->pipe->temp_file->file.name.data);\n }\n }\n#if (NGX_HTTP_CACHE)\n if (r->cache) {\n if (u->cacheable) {\n if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n time_t valid;\n valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n if (valid) {\n r->cache->valid_sec = ngx_time() + valid;\n r->cache->error = rc;\n }\n }\n }\n ngx_http_file_cache_free(r->cache, u->pipe->temp_file);\n }\n#endif\n if (r->subrequest_in_memory\n && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE)\n {\n u->buffer.last = u->buffer.pos;\n }\n if (rc == NGX_DECLINED) {\n return;\n }\n r->connection->log->action = "sending to client";\n if (!u->header_sent\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)\n {\n ngx_http_finalize_request(r, rc);\n return;\n }\n flush = 0;\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {\n rc = NGX_ERROR;\n flush = 1;\n }\n if (r->header_only) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n if (rc == 0) {\n rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n } else if (flush) {\n r->keepalive = 0;\n rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);\n }\n ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n r->main->subrequests++;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'static ngx_int_t\nngx_http_post_action(ngx_http_request_t *r)\n{\n ngx_http_core_loc_conf_t *clcf;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->post_action.data == NULL) {\n return NGX_DECLINED;\n }\n if (r->post_action && r->uri_changes == 0) {\n return NGX_DECLINED;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "post action: \\"%V\\"", &clcf->post_action);\n r->main->count--;\n r->http_version = NGX_HTTP_VERSION_9;\n r->header_only = 1;\n r->post_action = 1;\n r->read_event_handler = ngx_http_block_reading;\n if (clcf->post_action.data[0] == \'/\') {\n ngx_http_internal_redirect(r, &clcf->post_action, NULL);\n } else {\n ngx_http_named_location(r, &clcf->post_action);\n }\n return NGX_OK;\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internally redirecting to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n ngx_str_null(&r->args);\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->valid_unparsed_uri = 0;\n r->add_uri_to_alias = 0;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}']
36,130
0
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,\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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,131
0
https://github.com/openssl/openssl/blob/b8a3f39b890304757058deb730c855b72c14947b/crypto/ec/curve448/scalar.c/#L223
void curve448_scalar_halve(curve448_scalar_t out, const curve448_scalar_t a) { c448_word_t mask = 0 - (a->limb[0] & 1); c448_dword_t chain = 0; unsigned int i; for (i = 0; i < C448_SCALAR_LIMBS; i++) { chain = (chain + a->limb[i]) + (sc_p->limb[i] & mask); out->limb[i] = (c448_word_t)chain; chain >>= C448_WORD_BITS; } for (i = 0; i < C448_SCALAR_LIMBS - 1; i++) out->limb[i] = out->limb[i] >> 1 | out->limb[i + 1] << (WBITS - 1); out->limb[i] = out->limb[i] >> 1 | (c448_word_t)(chain << (WBITS - 1)); }
['void x448_derive_public_key(uint8_t out[X_PUBLIC_BYTES],\n const uint8_t scalar[X_PRIVATE_BYTES])\n{\n uint8_t scalar2[X_PRIVATE_BYTES];\n curve448_scalar_t the_scalar;\n curve448_point_t p;\n unsigned int i;\n memcpy(scalar2, scalar, sizeof(scalar2));\n scalar2[0] &= -(uint8_t)COFACTOR;\n scalar2[X_PRIVATE_BYTES - 1] &= ~((0u - 1u) << ((X_PRIVATE_BITS + 7) % 8));\n scalar2[X_PRIVATE_BYTES - 1] |= 1 << ((X_PRIVATE_BITS + 7) % 8);\n curve448_scalar_decode_long(the_scalar, scalar2, sizeof(scalar2));\n for (i = 1; i < X448_ENCODE_RATIO; i <<= 1)\n curve448_scalar_halve(the_scalar, the_scalar);\n curve448_precomputed_scalarmul(p, curve448_precomputed_base, the_scalar);\n curve448_point_mul_by_ratio_and_encode_like_x448(out, p);\n curve448_point_destroy(p);\n}', 'void curve448_scalar_decode_long(curve448_scalar_t s,\n const unsigned char *ser, size_t ser_len)\n{\n size_t i;\n curve448_scalar_t t1, t2;\n if (ser_len == 0) {\n curve448_scalar_copy(s, curve448_scalar_zero);\n return;\n }\n i = ser_len - (ser_len % C448_SCALAR_BYTES);\n if (i == ser_len)\n i -= C448_SCALAR_BYTES;\n scalar_decode_short(t1, &ser[i], ser_len - i);\n if (ser_len == sizeof(curve448_scalar_t)) {\n assert(i == 0);\n curve448_scalar_mul(s, t1, curve448_scalar_one);\n curve448_scalar_destroy(t1);\n return;\n }\n while (i) {\n i -= C448_SCALAR_BYTES;\n sc_montmul(t1, t1, sc_r2);\n (void)curve448_scalar_decode(t2, ser + i);\n curve448_scalar_add(t1, t1, t2);\n }\n curve448_scalar_copy(s, t1);\n curve448_scalar_destroy(t1);\n curve448_scalar_destroy(t2);\n}', 'void curve448_scalar_halve(curve448_scalar_t out, const curve448_scalar_t a)\n{\n c448_word_t mask = 0 - (a->limb[0] & 1);\n c448_dword_t chain = 0;\n unsigned int i;\n for (i = 0; i < C448_SCALAR_LIMBS; i++) {\n chain = (chain + a->limb[i]) + (sc_p->limb[i] & mask);\n out->limb[i] = (c448_word_t)chain;\n chain >>= C448_WORD_BITS;\n }\n for (i = 0; i < C448_SCALAR_LIMBS - 1; i++)\n out->limb[i] = out->limb[i] >> 1 | out->limb[i + 1] << (WBITS - 1);\n out->limb[i] = out->limb[i] >> 1 | (c448_word_t)(chain << (WBITS - 1));\n}']
36,132
0
https://github.com/openssl/openssl/blob/00a357ab203b4153eee970ffb33f0f22ef59f734/apps/ca.c/#L2954
char *make_revocation_str(int rev_type, char *rev_arg) { char *reason = NULL, *other = NULL, *str; ASN1_OBJECT *otmp; ASN1_UTCTIME *revtm = NULL; int i; switch (rev_type) { case REV_NONE: break; case REV_CRL_REASON: for (i = 0; i < 8; i++) { if (!strcasecmp(rev_arg, crl_reasons[i])) { reason = crl_reasons[i]; break; } } if (reason == NULL) { BIO_printf(bio_err, "Unknown CRL reason %s\n", rev_arg); return NULL; } break; case REV_HOLD: otmp = OBJ_txt2obj(rev_arg, 0); ASN1_OBJECT_free(otmp); if (otmp == NULL) { BIO_printf(bio_err, "Invalid object identifier %s\n", rev_arg); return NULL; } reason = "holdInstruction"; other = rev_arg; break; case REV_KEY_COMPROMISE: case REV_CA_COMPROMISE: if (!ASN1_GENERALIZEDTIME_set_string(NULL, rev_arg)) { BIO_printf(bio_err, "Invalid time format %s. Need YYYYMMDDHHMMSSZ\n", rev_arg); return NULL; } other = rev_arg; if (rev_type == REV_KEY_COMPROMISE) reason = "keyTime"; else reason = "CAkeyTime"; break; } revtm = X509_gmtime_adj(NULL, 0); i = revtm->length + 1; if (reason) i += strlen(reason) + 1; if (other) i += strlen(other) + 1; str = OPENSSL_malloc(i); if (!str) return NULL; strcpy(str, (char *)revtm->data); if (reason) { strcat(str, ","); strcat(str, reason); } if (other) { strcat(str, ","); strcat(str, other); } ASN1_UTCTIME_free(revtm); return str; }
['char *make_revocation_str(int rev_type, char *rev_arg)\n\t{\n\tchar *reason = NULL, *other = NULL, *str;\n\tASN1_OBJECT *otmp;\n\tASN1_UTCTIME *revtm = NULL;\n\tint i;\n\tswitch (rev_type)\n\t\t{\n\tcase REV_NONE:\n\t\tbreak;\n\tcase REV_CRL_REASON:\n\t\tfor (i = 0; i < 8; i++)\n\t\t\t{\n\t\t\tif (!strcasecmp(rev_arg, crl_reasons[i]))\n\t\t\t\t{\n\t\t\t\treason = crl_reasons[i];\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (reason == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Unknown CRL reason %s\\n", rev_arg);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tbreak;\n\tcase REV_HOLD:\n\t\totmp = OBJ_txt2obj(rev_arg, 0);\n\t\tASN1_OBJECT_free(otmp);\n\t\tif (otmp == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Invalid object identifier %s\\n", rev_arg);\n\t\t\treturn NULL;\n\t\t\t}\n\t\treason = "holdInstruction";\n\t\tother = rev_arg;\n\t\tbreak;\n\tcase REV_KEY_COMPROMISE:\n\tcase REV_CA_COMPROMISE:\n\t\tif (!ASN1_GENERALIZEDTIME_set_string(NULL, rev_arg))\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Invalid time format %s. Need YYYYMMDDHHMMSSZ\\n", rev_arg);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tother = rev_arg;\n\t\tif (rev_type == REV_KEY_COMPROMISE)\n\t\t\treason = "keyTime";\n\t\telse\n\t\t\treason = "CAkeyTime";\n\t\tbreak;\n\t\t}\n\trevtm = X509_gmtime_adj(NULL, 0);\n\ti = revtm->length + 1;\n\tif (reason) i += strlen(reason) + 1;\n\tif (other) i += strlen(other) + 1;\n\tstr = OPENSSL_malloc(i);\n\tif (!str) return NULL;\n\tstrcpy(str, (char *)revtm->data);\n\tif (reason)\n\t\t{\n\t\tstrcat(str, ",");\n\t\tstrcat(str, reason);\n\t\t}\n\tif (other)\n\t\t{\n\t\tstrcat(str, ",");\n\t\tstrcat(str, other);\n\t\t}\n\tASN1_UTCTIME_free(revtm);\n\treturn str;\n\t}', 'int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)\n\t{\n\tASN1_GENERALIZEDTIME t;\n\tt.type=V_ASN1_GENERALIZEDTIME;\n\tt.length=strlen(str);\n\tt.data=(unsigned char *)str;\n\tif (ASN1_GENERALIZEDTIME_check(&t))\n\t\t{\n\t\tif (s != NULL)\n\t\t\t{\n\t\t\tASN1_STRING_set((ASN1_STRING *)s,\n\t\t\t\t(unsigned char *)str,t.length);\n\t\t\ts->type=V_ASN1_GENERALIZEDTIME;\n\t\t\t}\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj)\n{\n\treturn X509_time_adj(s, adj, NULL);\n}', 'ASN1_TIME *X509_time_adj(ASN1_TIME *s, long adj, time_t *in_tm)\n\t{\n\ttime_t t;\n\tint type = -1;\n\tif (in_tm) t = *in_tm;\n\telse time(&t);\n\tt+=adj;\n\tif (s) type = s->type;\n\tif (type == V_ASN1_UTCTIME) return ASN1_UTCTIME_set(s,t);\n\tif (type == V_ASN1_GENERALIZEDTIME) return ASN1_GENERALIZEDTIME_set(s, t);\n\treturn ASN1_TIME_set(s, t);\n\t}', 'ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)\n\t{\n\tstruct tm *ts;\n\tstruct tm data;\n\tts=OPENSSL_gmtime(&t,&data);\n\tif (ts == NULL)\n\t\treturn NULL;\n\tif((ts->tm_year >= 50) && (ts->tm_year < 150))\n\t\t\t\t\treturn ASN1_UTCTIME_set(s, t);\n\treturn ASN1_GENERALIZEDTIME_set(s,t);\n\t}']
36,133
0
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
u_char * ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) { u_char *p, zero, *last; int d; float f, scale; size_t len, slen; int64_t i64; uint64_t ui64; ngx_msec_t ms; ngx_uint_t width, sign, hex, max_width, frac_width, i; ngx_str_t *v; ngx_variable_value_t *vv; if (max == 0) { return buf; } last = buf + max; while (*fmt && buf < last) { if (*fmt == '%') { i64 = 0; ui64 = 0; zero = (u_char) ((*++fmt == '0') ? '0' : ' '); width = 0; sign = 1; hex = 0; max_width = 0; frac_width = 0; slen = (size_t) -1; while (*fmt >= '0' && *fmt <= '9') { width = width * 10 + *fmt++ - '0'; } for ( ;; ) { switch (*fmt) { case 'u': sign = 0; fmt++; continue; case 'm': max_width = 1; fmt++; continue; case 'X': hex = 2; sign = 0; fmt++; continue; case 'x': hex = 1; sign = 0; fmt++; continue; case '.': fmt++; while (*fmt >= '0' && *fmt <= '9') { frac_width = frac_width * 10 + *fmt++ - '0'; } break; case '*': slen = va_arg(args, size_t); fmt++; continue; default: break; } break; } switch (*fmt) { case 'V': v = va_arg(args, ngx_str_t *); len = v->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, v->data, len); fmt++; continue; case 'v': vv = va_arg(args, ngx_variable_value_t *); len = vv->len; len = (buf + len < last) ? len : (size_t) (last - buf); buf = ngx_cpymem(buf, vv->data, len); fmt++; continue; case 's': p = va_arg(args, u_char *); if (slen == (size_t) -1) { while (*p && buf < last) { *buf++ = *p++; } } else { len = (buf + slen < last) ? slen : (size_t) (last - buf); buf = ngx_cpymem(buf, p, len); } fmt++; continue; case 'O': i64 = (int64_t) va_arg(args, off_t); sign = 1; break; case 'P': i64 = (int64_t) va_arg(args, ngx_pid_t); sign = 1; break; case 'T': i64 = (int64_t) va_arg(args, time_t); sign = 1; break; case 'M': ms = (ngx_msec_t) va_arg(args, ngx_msec_t); if ((ngx_msec_int_t) ms == -1) { sign = 1; i64 = -1; } else { sign = 0; ui64 = (uint64_t) ms; } break; case 'z': if (sign) { i64 = (int64_t) va_arg(args, ssize_t); } else { ui64 = (uint64_t) va_arg(args, size_t); } break; case 'i': if (sign) { i64 = (int64_t) va_arg(args, ngx_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_uint_t); } if (max_width) { width = NGX_INT_T_LEN; } break; case 'd': if (sign) { i64 = (int64_t) va_arg(args, int); } else { ui64 = (uint64_t) va_arg(args, u_int); } break; case 'l': if (sign) { i64 = (int64_t) va_arg(args, long); } else { ui64 = (uint64_t) va_arg(args, u_long); } break; case 'D': if (sign) { i64 = (int64_t) va_arg(args, int32_t); } else { ui64 = (uint64_t) va_arg(args, uint32_t); } break; case 'L': if (sign) { i64 = va_arg(args, int64_t); } else { ui64 = va_arg(args, uint64_t); } break; case 'A': if (sign) { i64 = (int64_t) va_arg(args, ngx_atomic_int_t); } else { ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t); } if (max_width) { width = NGX_ATOMIC_T_LEN; } break; case 'f': f = (float) va_arg(args, double); if (f < 0) { *buf++ = '-'; f = -f; } ui64 = (int64_t) f; buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width); if (frac_width) { if (buf < last) { *buf++ = '.'; } scale = 1.0; for (i = 0; i < frac_width; i++) { scale *= 10.0; } ui64 = (uint64_t) ((f - (int64_t) ui64) * scale); buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width); } fmt++; continue; #if !(NGX_WIN32) case 'r': i64 = (int64_t) va_arg(args, rlim_t); sign = 1; break; #endif case 'p': ui64 = (uintptr_t) va_arg(args, void *); hex = 2; sign = 0; zero = '0'; width = NGX_PTR_SIZE * 2; break; case 'c': d = va_arg(args, int); *buf++ = (u_char) (d & 0xff); fmt++; continue; case 'Z': *buf++ = '\0'; fmt++; continue; case 'N': #if (NGX_WIN32) *buf++ = CR; #endif *buf++ = LF; fmt++; continue; case '%': *buf++ = '%'; fmt++; continue; default: *buf++ = *fmt++; continue; } if (sign) { if (i64 < 0) { *buf++ = '-'; ui64 = (uint64_t) -i64; } else { ui64 = (uint64_t) i64; } } buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width); fmt++; } else { *buf++ = *fmt++; } } return buf; }
['static time_t\nngx_http_file_cache_manager(void *data)\n{\n ngx_http_file_cache_t *cache = data;\n off_t size;\n time_t next;\n ngx_tree_ctx_t tree;\n if (*cache->cold) {\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,\n "http file cache manager update");\n tree.init_handler = NULL;\n tree.file_handler = ngx_http_file_cache_manage_file;\n tree.pre_tree_handler = ngx_http_file_cache_noop;\n tree.post_tree_handler = ngx_http_file_cache_noop;\n tree.spec_handler = ngx_http_file_cache_delete_file;\n tree.data = cache;\n tree.alloc = 0;\n tree.log = ngx_cycle->log;\n cache->last = ngx_current_msec;\n cache->files = 0;\n if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) {\n return 10;\n }\n *cache->cold = 0;\n ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,\n "http file cache: %V %.3fM, bsize: %uz",\n &cache->path->name,\n ((double) *cache->size * cache->bsize) / (1024 * 1024),\n cache->bsize);\n }\n next = ngx_http_file_cache_expire(cache);\n cache->last = ngx_current_msec;\n cache->files = 0;\n for ( ;; ) {\n ngx_shmtx_lock(&cache->shpool->mutex);\n size = *cache->size;\n ngx_shmtx_unlock(&cache->shpool->mutex);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,\n "http file cache size: %O", size);\n if (size < cache->max_size) {\n return next;\n }\n next = ngx_http_file_cache_forced_expire(cache);\n if (ngx_http_file_cache_manager_sleep(cache) != NGX_OK) {\n return next;\n }\n }\n}', 'ngx_int_t\nngx_walk_tree(ngx_tree_ctx_t *ctx, ngx_str_t *tree)\n{\n void *data, *prev;\n u_char *p, *name;\n size_t len;\n ngx_int_t rc;\n ngx_err_t err;\n ngx_str_t file, buf;\n ngx_dir_t dir;\n buf.len = 0;\n buf.data = NULL;\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,\n "walk tree \\"%V\\"", tree);\n if (ngx_open_dir(tree, &dir) == NGX_ERROR) {\n ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,\n ngx_open_dir_n " \\"%s\\" failed", tree->data);\n return NGX_ERROR;\n }\n prev = ctx->data;\n if (ctx->alloc) {\n data = ngx_alloc(ctx->alloc, ctx->log);\n if (data == NULL) {\n goto failed;\n }\n if (ctx->init_handler(data, prev) == NGX_ABORT) {\n goto failed;\n }\n ctx->data = data;\n } else {\n data = NULL;\n }\n for ( ;; ) {\n ngx_set_errno(0);\n if (ngx_read_dir(&dir) == NGX_ERROR) {\n err = ngx_errno;\n if (err == NGX_ENOMOREFILES) {\n rc = NGX_OK;\n } else {\n ngx_log_error(NGX_LOG_CRIT, ctx->log, err,\n ngx_read_dir_n " \\"%s\\" failed", tree->data);\n rc = NGX_ERROR;\n }\n goto done;\n }\n len = ngx_de_namelen(&dir);\n name = ngx_de_name(&dir);\n ngx_log_debug2(NGX_LOG_DEBUG_CORE, ctx->log, 0,\n "tree name %uz:\\"%s\\"", len, name);\n if (len == 1 && name[0] == \'.\') {\n continue;\n }\n if (len == 2 && name[0] == \'.\' && name[1] == \'.\') {\n continue;\n }\n file.len = tree->len + 1 + len;\n if (file.len + NGX_DIR_MASK_LEN > buf.len) {\n if (buf.len) {\n ngx_free(buf.data);\n }\n buf.len = tree->len + 1 + len + NGX_DIR_MASK_LEN;\n buf.data = ngx_alloc(buf.len + 1, ctx->log);\n if (buf.data == NULL) {\n goto failed;\n }\n }\n p = ngx_cpymem(buf.data, tree->data, tree->len);\n *p++ = \'/\';\n ngx_memcpy(p, name, len + 1);\n file.data = buf.data;\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,\n "tree path \\"%s\\"", file.data);\n if (!dir.valid_info) {\n if (ngx_de_info(file.data, &dir) == NGX_FILE_ERROR) {\n ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,\n ngx_de_info_n " \\"%s\\" failed", file.data);\n continue;\n }\n }\n if (ngx_de_is_file(&dir)) {\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,\n "tree file \\"%s\\"", file.data);\n ctx->size = ngx_de_size(&dir);\n ctx->access = ngx_de_access(&dir);\n ctx->mtime = ngx_de_mtime(&dir);\n if (ctx->file_handler(ctx, &file) == NGX_ABORT) {\n goto failed;\n }\n } else if (ngx_de_is_dir(&dir)) {\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,\n "tree enter dir \\"%s\\"", file.data);\n ctx->access = ngx_de_access(&dir);\n ctx->mtime = ngx_de_mtime(&dir);\n if (ctx->pre_tree_handler(ctx, &file) == NGX_ABORT) {\n goto failed;\n }\n if (ngx_walk_tree(ctx, &file) == NGX_ABORT) {\n goto failed;\n }\n ctx->access = ngx_de_access(&dir);\n ctx->mtime = ngx_de_mtime(&dir);\n if (ctx->post_tree_handler(ctx, &file) == NGX_ABORT) {\n goto failed;\n }\n } else {\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, ctx->log, 0,\n "tree special \\"%s\\"", file.data);\n if (ctx->spec_handler(ctx, &file) == NGX_ABORT) {\n goto failed;\n }\n }\n }\nfailed:\n rc = NGX_ABORT;\ndone:\n if (buf.len) {\n ngx_free(buf.data);\n }\n if (data) {\n ngx_free(data);\n ctx->data = prev;\n }\n if (ngx_close_dir(&dir) == NGX_ERROR) {\n ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,\n ngx_close_dir_n " \\"%s\\" failed", tree->data);\n }\n return rc;\n}', 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
36,134
0
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/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); }
['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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int max;\n int add = 0, neg = 0;\n const BIGNUM *tmp;\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg) {\n if (b->neg) {\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 const BIGNUM *tmp;\n bn_check_top(a);\n bn_check_top(b);\n if (a->top < b->top) {\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 bp += min;\n if (carry) {\n while (dif) {\n dif--;\n t1 = *(ap++);\n t2 = (t1 + 1) & BN_MASK2;\n *(rp++) = t2;\n if (t2) {\n carry = 0;\n break;\n }\n }\n if (carry) {\n *rp = 1;\n r->top++;\n }\n }\n if (dif && rp != ap)\n while (dif--)\n *(rp++) = *(ap++);\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, *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}']
36,135
0
https://github.com/openssl/openssl/blob/0350ef69add8758dd180e73cbc7c1961bf64e503/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b,\n BIGNUM *N)\n{\n BIGNUM *tmp = NULL, *S = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || A == NULL || v == NULL || b == NULL || N == NULL)\n return NULL;\n if ((bn_ctx = BN_CTX_new()) == NULL ||\n (tmp = BN_new()) == NULL || (S = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, v, u, N, bn_ctx))\n goto err;\n if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))\n goto err;\n if (!BN_mod_exp(S, tmp, b, N, bn_ctx))\n goto err;\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n return S;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n ret = BN_one(r);\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!aa || !val[0])\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,136
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n int i, bits, ret = 0;\n BIGNUM *v, *rr;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_EXP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n BN_CTX_start(ctx);\n if ((r == a) || (r == p))\n rr = BN_CTX_get(ctx);\n else\n rr = r;\n v = BN_CTX_get(ctx);\n if (rr == NULL || v == NULL)\n goto err;\n if (BN_copy(v, a) == NULL)\n goto err;\n bits = BN_num_bits(p);\n if (BN_is_odd(p)) {\n if (BN_copy(rr, a) == NULL)\n goto err;\n } else {\n if (!BN_one(rr))\n goto err;\n }\n for (i = 1; i < bits; i++) {\n if (!BN_sqr(v, v, ctx))\n goto err;\n if (BN_is_bit_set(p, i)) {\n if (!BN_mul(rr, rr, v, ctx))\n goto err;\n }\n }\n ret = 1;\n err:\n if (r != rr)\n BN_copy(r, rr);\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_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,137
0
https://github.com/openssl/openssl/blob/313fce7b61ecaf5879cf84b256bdd0964134836e/crypto/bn/bn_ctx.c/#L353
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\treturn BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\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\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif (!d || !r || !val[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_nnmod(val[0],a,m,ctx))\n\t\t\tgoto err;\n\t\taa= val[0];\n\t\t}\n\telse\n\t\taa=a;\n\tif (BN_is_zero(aa))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val[i],val[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!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\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
36,138
0
https://github.com/openssl/openssl/blob/a3a2ff4cd9ada10effaa514af90c7638ab0e9824/ssl/s3_clnt.c/#L2290
static int ssl3_check_cert_and_algorithm(SSL *s) { int i,idx; long algs; EVP_PKEY *pkey=NULL; SESS_CERT *sc; #ifndef OPENSSL_NO_RSA RSA *rsa; #endif #ifndef OPENSSL_NO_DH DH *dh; #endif sc=s->session->sess_cert; if (sc == NULL) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR); goto err; } algs=s->s3->tmp.new_cipher->algorithms; if (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5)) return(1); #ifndef OPENSSL_NO_RSA rsa=s->session->sess_cert->peer_rsa_tmp; #endif #ifndef OPENSSL_NO_DH dh=s->session->sess_cert->peer_dh_tmp; #endif idx=sc->peer_cert_type; #ifndef OPENSSL_NO_ECDH if (idx == SSL_PKEY_ECC) { if (check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509, s->s3->tmp.new_cipher) == 0) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_BAD_ECC_CERT); goto f_err; } else { return 1; } } #endif pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509); i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey); EVP_PKEY_free(pkey); if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN)) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT); goto f_err; } #ifndef OPENSSL_NO_DSA else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN)) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT); goto f_err; } #endif #ifndef OPENSSL_NO_RSA if ((algs & SSL_kRSA) && !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL))) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT); goto f_err; } #endif #ifndef OPENSSL_NO_DH if ((algs & SSL_kEDH) && !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL))) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY); goto f_err; } else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA)) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT); goto f_err; } #ifndef OPENSSL_NO_DSA else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA)) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT); goto f_err; } #endif #endif if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP)) { #ifndef OPENSSL_NO_RSA if (algs & SSL_kRSA) { if (rsa == NULL || RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY); goto f_err; } } else #endif #ifndef OPENSSL_NO_DH if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) { if (dh == NULL || DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)) { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY); goto f_err; } } else #endif { SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE); goto f_err; } } return(1); f_err: ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE); err: return(0); }
['static int ssl3_check_cert_and_algorithm(SSL *s)\n\t{\n\tint i,idx;\n\tlong algs;\n\tEVP_PKEY *pkey=NULL;\n\tSESS_CERT *sc;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh;\n#endif\n\tsc=s->session->sess_cert;\n\tif (sc == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,ERR_R_INTERNAL_ERROR);\n\t\tgoto err;\n\t\t}\n\talgs=s->s3->tmp.new_cipher->algorithms;\n\tif (algs & (SSL_aDH|SSL_aNULL|SSL_aKRB5))\n\t\treturn(1);\n#ifndef OPENSSL_NO_RSA\n\trsa=s->session->sess_cert->peer_rsa_tmp;\n#endif\n#ifndef OPENSSL_NO_DH\n\tdh=s->session->sess_cert->peer_dh_tmp;\n#endif\n\tidx=sc->peer_cert_type;\n#ifndef OPENSSL_NO_ECDH\n\tif (idx == SSL_PKEY_ECC)\n\t\t{\n\t\tif (check_srvr_ecc_cert_and_alg(sc->peer_pkeys[idx].x509,\n\t\t s->s3->tmp.new_cipher) == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_BAD_ECC_CERT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\treturn 1;\n\t\t\t}\n\t\t}\n#endif\n\tpkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);\n\ti=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);\n\tEVP_PKEY_free(pkey);\n\tif ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);\n\t\tgoto f_err;\n\t\t}\n#ifndef OPENSSL_NO_DSA\n\telse if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);\n\t\tgoto f_err;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RSA\n\tif ((algs & SSL_kRSA) &&\n\t\t!(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);\n\t\tgoto f_err;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DH\n\tif ((algs & SSL_kEDH) &&\n\t\t!(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);\n\t\tgoto f_err;\n\t\t}\n\telse if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);\n\t\tgoto f_err;\n\t\t}\n#ifndef OPENSSL_NO_DSA\n\telse if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);\n\t\tgoto f_err;\n\t\t}\n#endif\n#endif\n\tif (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))\n\t\t{\n#ifndef OPENSSL_NO_RSA\n\t\tif (algs & SSL_kRSA)\n\t\t\t{\n\t\t\tif (rsa == NULL\n\t\t\t || RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DH\n\t\t\tif (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t\t {\n\t\t\t if (dh == NULL\n\t\t\t\t|| DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);\nerr:\n\treturn(0);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\tconst unsigned char *cp;\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t\t{\n\t\tCRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\t\treturn(key->pkey);\n\t\t}\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tif ((ret = EVP_PKEY_new()) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tret->type = EVP_PKEY_type(type);\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\ta=key->algor;\n#endif\n\tif (0)\n\t\t;\n#ifndef OPENSSL_NO_DSA\n\telse if (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tif ((ret->pkey.dsa = DSA_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tcp=p=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_EC\n\telse if (ret->type == EVP_PKEY_EC)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tif ((ret->pkey.eckey= EC_KEY_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tcp = p = a->parameter->value.sequence->data;\n\t\t\tj = a->parameter->value.sequence->length;\n\t\t\tif (!d2i_ECParameters(&ret->pkey.eckey, &cp, (long)j))\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))\n\t\t\t{\n\t\t\tEC_KEY *eckey;\n\t\t\tif (ret->pkey.eckey == NULL)\n\t\t\t\tret->pkey.eckey = EC_KEY_new();\n\t\t\teckey = ret->pkey.eckey;\n\t\t\tif (eckey->group)\n\t\t\t\tEC_GROUP_free(eckey->group);\n\t\t\tif ((eckey->group = EC_GROUP_new_by_nid(\n OBJ_obj2nid(a->parameter->value.object))) == NULL)\n\t\t\t\tgoto err;\n\t\t\tEC_GROUP_set_asn1_flag(eckey->group,\n\t\t\t\t\t\tOPENSSL_EC_NAMED_CURVE);\n\t\t\t}\n\t\tret->save_parameters = 1;\n\t\t}\n#endif\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret = d2i_PublicKey(type, &ret, &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\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}', 'EVP_PKEY *EVP_PKEY_new(void)\n\t{\n\tEVP_PKEY *ret;\n\tret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));\n\tif (ret == NULL)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->type=EVP_PKEY_NONE;\n\tret->references=1;\n\tret->pkey.ptr=NULL;\n\tret->attributes=NULL;\n\tret->save_parameters=1;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num < 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']
36,139
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/dnxhdenc.c/#L187
static int dnxhd_init_rc(DNXHDEncContext *ctx) { CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry)); if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry)); ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; ctx->qscale = 1; ctx->lambda = 2<<LAMBDA_FRAC_BITS; return 0; fail: return -1; }
['static int dnxhd_encode_init(AVCodecContext *avctx)\n{\n DNXHDEncContext *ctx = avctx->priv_data;\n int i, index;\n ctx->cid = ff_dnxhd_find_cid(avctx);\n if (!ctx->cid || avctx->pix_fmt != PIX_FMT_YUV422P) {\n av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\\n");\n return -1;\n }\n av_log(avctx, AV_LOG_DEBUG, "cid %d\\n", ctx->cid);\n index = ff_dnxhd_get_cid_table(ctx->cid);\n ctx->cid_table = &ff_dnxhd_cid_table[index];\n ctx->m.avctx = avctx;\n ctx->m.mb_intra = 1;\n ctx->m.h263_aic = 1;\n dsputil_init(&ctx->m.dsp, avctx);\n ff_dct_common_init(&ctx->m);\n if (!ctx->m.dct_quantize)\n ctx->m.dct_quantize = dct_quantize_c;\n ctx->m.mb_height = (avctx->height + 15) / 16;\n ctx->m.mb_width = (avctx->width + 15) / 16;\n if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) {\n ctx->interlaced = 1;\n ctx->m.mb_height /= 2;\n }\n ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width;\n if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS)\n ctx->m.intra_quant_bias = avctx->intra_quant_bias;\n if (dnxhd_init_qmat(ctx, ctx->m.intra_quant_bias, 0) < 0)\n return -1;\n if (dnxhd_init_vlc(ctx) < 0)\n return -1;\n if (dnxhd_init_rc(ctx) < 0)\n return -1;\n CHECKED_ALLOCZ(ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t));\n CHECKED_ALLOCZ(ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t));\n CHECKED_ALLOCZ(ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t));\n ctx->frame.key_frame = 1;\n ctx->frame.pict_type = FF_I_TYPE;\n ctx->m.avctx->coded_frame = &ctx->frame;\n if (avctx->thread_count > MAX_THREADS || (avctx->thread_count > ctx->m.mb_height)) {\n av_log(avctx, AV_LOG_ERROR, "too many threads\\n");\n return -1;\n }\n ctx->thread[0] = ctx;\n for (i = 1; i < avctx->thread_count; i++) {\n ctx->thread[i] = av_malloc(sizeof(DNXHDEncContext));\n memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext));\n }\n for (i = 0; i < avctx->thread_count; i++) {\n ctx->thread[i]->m.start_mb_y = (ctx->m.mb_height*(i ) + avctx->thread_count/2) / avctx->thread_count;\n ctx->thread[i]->m.end_mb_y = (ctx->m.mb_height*(i+1) + avctx->thread_count/2) / avctx->thread_count;\n }\n return 0;\n fail:\n return -1;\n}', 'void dsputil_init(DSPContext* c, AVCodecContext *avctx)\n{\n int i;\n ff_check_alignment();\n#ifdef CONFIG_ENCODERS\n if(avctx->dct_algo==FF_DCT_FASTINT) {\n c->fdct = fdct_ifast;\n c->fdct248 = fdct_ifast248;\n }\n else if(avctx->dct_algo==FF_DCT_FAAN) {\n c->fdct = ff_faandct;\n c->fdct248 = ff_faandct248;\n }\n else {\n c->fdct = ff_jpeg_fdct_islow;\n c->fdct248 = ff_fdct248_islow;\n }\n#endif\n if(avctx->lowres==1){\n if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !ENABLE_H264_DECODER){\n c->idct_put= ff_jref_idct4_put;\n c->idct_add= ff_jref_idct4_add;\n }else{\n c->idct_put= ff_h264_lowres_idct_put_c;\n c->idct_add= ff_h264_lowres_idct_add_c;\n }\n c->idct = j_rev_dct4;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }else if(avctx->lowres==2){\n c->idct_put= ff_jref_idct2_put;\n c->idct_add= ff_jref_idct2_add;\n c->idct = j_rev_dct2;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }else if(avctx->lowres==3){\n c->idct_put= ff_jref_idct1_put;\n c->idct_add= ff_jref_idct1_add;\n c->idct = j_rev_dct1;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }else{\n if(avctx->idct_algo==FF_IDCT_INT){\n c->idct_put= ff_jref_idct_put;\n c->idct_add= ff_jref_idct_add;\n c->idct = j_rev_dct;\n c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;\n }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER || ENABLE_THEORA_DECODER ) &&\n avctx->idct_algo==FF_IDCT_VP3){\n c->idct_put= ff_vp3_idct_put_c;\n c->idct_add= ff_vp3_idct_add_c;\n c->idct = ff_vp3_idct_c;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }else if(avctx->idct_algo==FF_IDCT_WMV2){\n c->idct_put= ff_wmv2_idct_put_c;\n c->idct_add= ff_wmv2_idct_add_c;\n c->idct = ff_wmv2_idct_c;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }else if(avctx->idct_algo==FF_IDCT_FAAN){\n c->idct_put= ff_faanidct_put;\n c->idct_add= ff_faanidct_add;\n c->idct = ff_faanidct;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }else{\n c->idct_put= ff_simple_idct_put;\n c->idct_add= ff_simple_idct_add;\n c->idct = ff_simple_idct;\n c->idct_permutation_type= FF_NO_IDCT_PERM;\n }\n }\n if (ENABLE_H264_DECODER) {\n c->h264_idct_add= ff_h264_idct_add_c;\n c->h264_idct8_add= ff_h264_idct8_add_c;\n c->h264_idct_dc_add= ff_h264_idct_dc_add_c;\n c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c;\n }\n c->get_pixels = get_pixels_c;\n c->diff_pixels = diff_pixels_c;\n c->put_pixels_clamped = put_pixels_clamped_c;\n c->put_signed_pixels_clamped = put_signed_pixels_clamped_c;\n c->add_pixels_clamped = add_pixels_clamped_c;\n c->add_pixels8 = add_pixels8_c;\n c->add_pixels4 = add_pixels4_c;\n c->sum_abs_dctelem = sum_abs_dctelem_c;\n c->gmc1 = gmc1_c;\n c->gmc = ff_gmc_c;\n c->clear_blocks = clear_blocks_c;\n c->pix_sum = pix_sum_c;\n c->pix_norm1 = pix_norm1_c;\n c->pix_abs[0][0] = pix_abs16_c;\n c->pix_abs[0][1] = pix_abs16_x2_c;\n c->pix_abs[0][2] = pix_abs16_y2_c;\n c->pix_abs[0][3] = pix_abs16_xy2_c;\n c->pix_abs[1][0] = pix_abs8_c;\n c->pix_abs[1][1] = pix_abs8_x2_c;\n c->pix_abs[1][2] = pix_abs8_y2_c;\n c->pix_abs[1][3] = pix_abs8_xy2_c;\n#define dspfunc(PFX, IDX, NUM) \\\n c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \\\n c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \\\n c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \\\n c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c\n dspfunc(put, 0, 16);\n dspfunc(put_no_rnd, 0, 16);\n dspfunc(put, 1, 8);\n dspfunc(put_no_rnd, 1, 8);\n dspfunc(put, 2, 4);\n dspfunc(put, 3, 2);\n dspfunc(avg, 0, 16);\n dspfunc(avg_no_rnd, 0, 16);\n dspfunc(avg, 1, 8);\n dspfunc(avg_no_rnd, 1, 8);\n dspfunc(avg, 2, 4);\n dspfunc(avg, 3, 2);\n#undef dspfunc\n c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c;\n c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c;\n c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c;\n c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c;\n c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c;\n c->put_tpel_pixels_tab[ 4] = put_tpel_pixels_mc01_c;\n c->put_tpel_pixels_tab[ 5] = put_tpel_pixels_mc11_c;\n c->put_tpel_pixels_tab[ 6] = put_tpel_pixels_mc21_c;\n c->put_tpel_pixels_tab[ 8] = put_tpel_pixels_mc02_c;\n c->put_tpel_pixels_tab[ 9] = put_tpel_pixels_mc12_c;\n c->put_tpel_pixels_tab[10] = put_tpel_pixels_mc22_c;\n c->avg_tpel_pixels_tab[ 0] = avg_tpel_pixels_mc00_c;\n c->avg_tpel_pixels_tab[ 1] = avg_tpel_pixels_mc10_c;\n c->avg_tpel_pixels_tab[ 2] = avg_tpel_pixels_mc20_c;\n c->avg_tpel_pixels_tab[ 4] = avg_tpel_pixels_mc01_c;\n c->avg_tpel_pixels_tab[ 5] = avg_tpel_pixels_mc11_c;\n c->avg_tpel_pixels_tab[ 6] = avg_tpel_pixels_mc21_c;\n c->avg_tpel_pixels_tab[ 8] = avg_tpel_pixels_mc02_c;\n c->avg_tpel_pixels_tab[ 9] = avg_tpel_pixels_mc12_c;\n c->avg_tpel_pixels_tab[10] = avg_tpel_pixels_mc22_c;\n#define dspfunc(PFX, IDX, NUM) \\\n c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_c; \\\n c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_c; \\\n c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_c; \\\n c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_c; \\\n c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_c; \\\n c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_c; \\\n c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_c; \\\n c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_c; \\\n c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_c; \\\n c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_c; \\\n c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \\\n c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \\\n c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \\\n c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \\\n c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \\\n c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c\n dspfunc(put_qpel, 0, 16);\n dspfunc(put_no_rnd_qpel, 0, 16);\n dspfunc(avg_qpel, 0, 16);\n dspfunc(put_qpel, 1, 8);\n dspfunc(put_no_rnd_qpel, 1, 8);\n dspfunc(avg_qpel, 1, 8);\n dspfunc(put_h264_qpel, 0, 16);\n dspfunc(put_h264_qpel, 1, 8);\n dspfunc(put_h264_qpel, 2, 4);\n dspfunc(put_h264_qpel, 3, 2);\n dspfunc(avg_h264_qpel, 0, 16);\n dspfunc(avg_h264_qpel, 1, 8);\n dspfunc(avg_h264_qpel, 2, 4);\n#undef dspfunc\n c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c;\n c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c;\n c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c;\n c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c;\n c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c;\n c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c;\n c->put_no_rnd_h264_chroma_pixels_tab[0]= put_no_rnd_h264_chroma_mc8_c;\n c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c;\n c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c;\n c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c;\n c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c;\n c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c;\n c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c;\n c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c;\n c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c;\n c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c;\n c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c;\n c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c;\n c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c;\n c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c;\n c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c;\n c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c;\n c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c;\n c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c;\n c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c;\n c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c;\n c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c;\n c->draw_edges = draw_edges_c;\n#ifdef CONFIG_CAVS_DECODER\n ff_cavsdsp_init(c,avctx);\n#endif\n#if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)\n ff_vc1dsp_init(c,avctx);\n#endif\n#if defined(CONFIG_WMV2_DECODER) || defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER)\n ff_intrax8dsp_init(c,avctx);\n#endif\n#if defined(CONFIG_H264_ENCODER)\n ff_h264dspenc_init(c,avctx);\n#endif\n c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c;\n c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c;\n c->put_mspel_pixels_tab[2]= put_mspel8_mc20_c;\n c->put_mspel_pixels_tab[3]= put_mspel8_mc30_c;\n c->put_mspel_pixels_tab[4]= put_mspel8_mc02_c;\n c->put_mspel_pixels_tab[5]= put_mspel8_mc12_c;\n c->put_mspel_pixels_tab[6]= put_mspel8_mc22_c;\n c->put_mspel_pixels_tab[7]= put_mspel8_mc32_c;\n#define SET_CMP_FUNC(name) \\\n c->name[0]= name ## 16_c;\\\n c->name[1]= name ## 8x8_c;\n SET_CMP_FUNC(hadamard8_diff)\n c->hadamard8_diff[4]= hadamard8_intra16_c;\n SET_CMP_FUNC(dct_sad)\n SET_CMP_FUNC(dct_max)\n#ifdef CONFIG_GPL\n SET_CMP_FUNC(dct264_sad)\n#endif\n c->sad[0]= pix_abs16_c;\n c->sad[1]= pix_abs8_c;\n c->sse[0]= sse16_c;\n c->sse[1]= sse8_c;\n c->sse[2]= sse4_c;\n SET_CMP_FUNC(quant_psnr)\n SET_CMP_FUNC(rd)\n SET_CMP_FUNC(bit)\n c->vsad[0]= vsad16_c;\n c->vsad[4]= vsad_intra16_c;\n c->vsse[0]= vsse16_c;\n c->vsse[4]= vsse_intra16_c;\n c->nsse[0]= nsse16_c;\n c->nsse[1]= nsse8_c;\n#ifdef CONFIG_SNOW_ENCODER\n c->w53[0]= w53_16_c;\n c->w53[1]= w53_8_c;\n c->w97[0]= w97_16_c;\n c->w97[1]= w97_8_c;\n#endif\n c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c;\n c->add_bytes= add_bytes_c;\n c->add_bytes_l2= add_bytes_l2_c;\n c->diff_bytes= diff_bytes_c;\n c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c;\n c->bswap_buf= bswap_buf;\n#ifdef CONFIG_PNG_DECODER\n c->add_png_paeth_prediction= ff_add_png_paeth_prediction;\n#endif\n c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c;\n c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c;\n c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c;\n c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c;\n c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c;\n c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c;\n c->h264_loop_filter_strength= NULL;\n if (ENABLE_ANY_H263) {\n c->h263_h_loop_filter= h263_h_loop_filter_c;\n c->h263_v_loop_filter= h263_v_loop_filter_c;\n }\n c->h261_loop_filter= h261_loop_filter_c;\n c->try_8x8basis= try_8x8basis_c;\n c->add_8x8basis= add_8x8basis_c;\n#ifdef CONFIG_SNOW_DECODER\n c->vertical_compose97i = ff_snow_vertical_compose97i;\n c->horizontal_compose97i = ff_snow_horizontal_compose97i;\n c->inner_add_yblock = ff_snow_inner_add_yblock;\n#endif\n#ifdef CONFIG_VORBIS_DECODER\n c->vorbis_inverse_coupling = vorbis_inverse_coupling;\n#endif\n#ifdef CONFIG_FLAC_ENCODER\n c->flac_compute_autocorr = ff_flac_compute_autocorr;\n#endif\n c->vector_fmul = vector_fmul_c;\n c->vector_fmul_reverse = vector_fmul_reverse_c;\n c->vector_fmul_add_add = ff_vector_fmul_add_add_c;\n c->vector_fmul_window = ff_vector_fmul_window_c;\n c->float_to_int16 = ff_float_to_int16_c;\n c->float_to_int16_interleave = ff_float_to_int16_interleave_c;\n c->add_int16 = add_int16_c;\n c->sub_int16 = sub_int16_c;\n c->scalarproduct_int16 = scalarproduct_int16_c;\n c->shrink[0]= ff_img_copy_plane;\n c->shrink[1]= ff_shrink22;\n c->shrink[2]= ff_shrink44;\n c->shrink[3]= ff_shrink88;\n c->prefetch= just_return;\n memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab));\n memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab));\n if (ENABLE_MMX) dsputil_init_mmx (c, avctx);\n if (ENABLE_ARMV4L) dsputil_init_armv4l(c, avctx);\n if (ENABLE_MLIB) dsputil_init_mlib (c, avctx);\n if (ENABLE_VIS) dsputil_init_vis (c, avctx);\n if (ENABLE_ALPHA) dsputil_init_alpha (c, avctx);\n if (ENABLE_POWERPC) dsputil_init_ppc (c, avctx);\n if (ENABLE_MMI) dsputil_init_mmi (c, avctx);\n if (ENABLE_SH4) dsputil_init_sh4 (c, avctx);\n if (ENABLE_BFIN) dsputil_init_bfin (c, avctx);\n for(i=0; i<64; i++){\n if(!c->put_2tap_qpel_pixels_tab[0][i])\n c->put_2tap_qpel_pixels_tab[0][i]= c->put_h264_qpel_pixels_tab[0][i];\n if(!c->avg_2tap_qpel_pixels_tab[0][i])\n c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i];\n }\n switch(c->idct_permutation_type){\n case FF_NO_IDCT_PERM:\n for(i=0; i<64; i++)\n c->idct_permutation[i]= i;\n break;\n case FF_LIBMPEG2_IDCT_PERM:\n for(i=0; i<64; i++)\n c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2);\n break;\n case FF_SIMPLE_IDCT_PERM:\n for(i=0; i<64; i++)\n c->idct_permutation[i]= simple_mmx_permutation[i];\n break;\n case FF_TRANSPOSE_IDCT_PERM:\n for(i=0; i<64; i++)\n c->idct_permutation[i]= ((i&7)<<3) | (i>>3);\n break;\n case FF_PARTTRANS_IDCT_PERM:\n for(i=0; i<64; i++)\n c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3);\n break;\n case FF_SSE2_IDCT_PERM:\n for(i=0; i<64; i++)\n c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7];\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\\n");\n }\n}', 'int ff_dct_common_init(MpegEncContext *s)\n{\n s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;\n s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;\n s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;\n s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;\n s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;\n if(s->flags & CODEC_FLAG_BITEXACT)\n s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;\n s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;\n#if defined(HAVE_MMX)\n MPV_common_init_mmx(s);\n#elif defined(ARCH_ALPHA)\n MPV_common_init_axp(s);\n#elif defined(CONFIG_MLIB)\n MPV_common_init_mlib(s);\n#elif defined(HAVE_MMI)\n MPV_common_init_mmi(s);\n#elif defined(ARCH_ARMV4L)\n MPV_common_init_armv4l(s);\n#elif defined(HAVE_ALTIVEC)\n MPV_common_init_altivec(s);\n#elif defined(ARCH_BFIN)\n MPV_common_init_bfin(s);\n#endif\n if(s->alternate_scan){\n ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);\n ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);\n }else{\n ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);\n ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);\n }\n ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);\n ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);\n return 0;\n}', 'void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){\n int i;\n int end;\n st->scantable= src_scantable;\n for(i=0; i<64; i++){\n int j;\n j = src_scantable[i];\n st->permutated[i] = permutation[j];\n#ifdef ARCH_POWERPC\n st->inverse[j] = i;\n#endif\n }\n end=-1;\n for(i=0; i<64; i++){\n int j;\n j = st->permutated[i];\n if(j>end) end=j;\n st->raster_end[i]= end;\n }\n}', 'static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)\n{\n uint16_t weight_matrix[64] = {1,};\n int qscale, i;\n CHECKED_ALLOCZ(ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int));\n CHECKED_ALLOCZ(ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int));\n CHECKED_ALLOCZ(ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t));\n CHECKED_ALLOCZ(ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t));\n for (i = 1; i < 64; i++) {\n int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];\n weight_matrix[j] = ctx->cid_table->luma_weight[i];\n }\n ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix,\n ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);\n for (i = 1; i < 64; i++) {\n int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]];\n weight_matrix[j] = ctx->cid_table->chroma_weight[i];\n }\n ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix,\n ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1);\n for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) {\n for (i = 0; i < 64; i++) {\n ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2;\n ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2;\n ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2;\n }\n }\n return 0;\n fail:\n return -1;\n}', 'static int dnxhd_init_vlc(DNXHDEncContext *ctx)\n{\n int i, j, level, run;\n int max_level = 1<<(ctx->cid_table->bit_depth+2);\n CHECKED_ALLOCZ(ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes));\n CHECKED_ALLOCZ(ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits));\n CHECKED_ALLOCZ(ctx->run_codes, 63*2);\n CHECKED_ALLOCZ(ctx->run_bits, 63);\n ctx->vlc_codes += max_level*2;\n ctx->vlc_bits += max_level*2;\n for (level = -max_level; level < max_level; level++) {\n for (run = 0; run < 2; run++) {\n int index = (level<<1)|run;\n int sign, offset = 0, alevel = level;\n MASK_ABS(sign, alevel);\n if (alevel > 64) {\n offset = (alevel-1)>>6;\n alevel -= offset<<6;\n }\n for (j = 0; j < 257; j++) {\n if (ctx->cid_table->ac_level[j] == alevel &&\n (!offset || (ctx->cid_table->ac_index_flag[j] && offset)) &&\n (!run || (ctx->cid_table->ac_run_flag [j] && run))) {\n assert(!ctx->vlc_codes[index]);\n if (alevel) {\n ctx->vlc_codes[index] = (ctx->cid_table->ac_codes[j]<<1)|(sign&1);\n ctx->vlc_bits [index] = ctx->cid_table->ac_bits[j]+1;\n } else {\n ctx->vlc_codes[index] = ctx->cid_table->ac_codes[j];\n ctx->vlc_bits [index] = ctx->cid_table->ac_bits [j];\n }\n break;\n }\n }\n assert(!alevel || j < 257);\n if (offset) {\n ctx->vlc_codes[index] = (ctx->vlc_codes[index]<<ctx->cid_table->index_bits)|offset;\n ctx->vlc_bits [index]+= ctx->cid_table->index_bits;\n }\n }\n }\n for (i = 0; i < 62; i++) {\n int run = ctx->cid_table->run[i];\n assert(run < 63);\n ctx->run_codes[run] = ctx->cid_table->run_codes[i];\n ctx->run_bits [run] = ctx->cid_table->run_bits[i];\n }\n return 0;\n fail:\n return -1;\n}', 'static int dnxhd_init_rc(DNXHDEncContext *ctx)\n{\n CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry));\n if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD)\n CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry));\n ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8;\n ctx->qscale = 1;\n ctx->lambda = 2<<LAMBDA_FRAC_BITS;\n return 0;\n fail:\n return -1;\n}']
36,140
0
https://github.com/openssl/openssl/blob/05eec39505ba8af6f3c1558a26c565987707cd37/ssl/ssl_lib.c/#L3983
EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md) { ssl_clear_hash_ctx(hash); *hash = EVP_MD_CTX_new(); if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) { EVP_MD_CTX_free(*hash); *hash = NULL; return NULL; } return *hash; }
['EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md)\n{\n ssl_clear_hash_ctx(hash);\n *hash = EVP_MD_CTX_new();\n if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {\n EVP_MD_CTX_free(*hash);\n *hash = NULL;\n return NULL;\n }\n return *hash;\n}', 'void ssl_clear_hash_ctx(EVP_MD_CTX **hash)\n{\n EVP_MD_CTX_free(*hash);\n *hash = NULL;\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}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
36,141
0
https://github.com/libav/libav/blob/366ba2dee1f2b17825b42e2164d3b9879f0271b1/libavcodec/h264_slice.c/#L1580
static av_always_inline void fill_filter_caches_inter(const H264Context *h, H264SliceContext *sl, int mb_type, int top_xy, int left_xy[LEFT_MBS], int top_type, int left_type[LEFT_MBS], int mb_xy, int list) { int b_stride = h->b_stride; int16_t(*mv_dst)[2] = &sl->mv_cache[list][scan8[0]]; int8_t *ref_cache = &sl->ref_cache[list][scan8[0]]; if (IS_INTER(mb_type) || IS_DIRECT(mb_type)) { if (USES_LIST(top_type, list)) { const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; const int b8_xy = 4 * top_xy + 2; int (*ref2frm)[64] = h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2); AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]); ref_cache[0 - 1 * 8] = ref_cache[1 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 0]]; ref_cache[2 - 1 * 8] = ref_cache[3 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 1]]; } else { AV_ZERO128(mv_dst - 1 * 8); AV_WN32A(&ref_cache[0 - 1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); } if (!IS_INTERLACED(mb_type ^ left_type[LTOP])) { 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; int (*ref2frm)[64] = h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2); AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]); AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]); AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]); AV_COPY32(mv_dst - 1 + 24, h->cur_pic.motion_val[list][b_xy + b_stride * 3]); ref_cache[-1 + 0] = ref_cache[-1 + 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 2 * 0]]; ref_cache[-1 + 16] = ref_cache[-1 + 24] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 2 * 1]]; } else { AV_ZERO32(mv_dst - 1 + 0); AV_ZERO32(mv_dst - 1 + 8); AV_ZERO32(mv_dst - 1 + 16); AV_ZERO32(mv_dst - 1 + 24); ref_cache[-1 + 0] = ref_cache[-1 + 8] = ref_cache[-1 + 16] = ref_cache[-1 + 24] = LIST_NOT_USED; } } } if (!USES_LIST(mb_type, list)) { fill_rectangle(mv_dst, 4, 4, 8, pack16to32(0, 0), 4); AV_WN32A(&ref_cache[0 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); AV_WN32A(&ref_cache[1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); AV_WN32A(&ref_cache[2 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); AV_WN32A(&ref_cache[3 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); return; } { int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy]; int (*ref2frm)[64] = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2); uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101; uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101; AV_WN32A(&ref_cache[0 * 8], ref01); AV_WN32A(&ref_cache[1 * 8], ref01); AV_WN32A(&ref_cache[2 * 8], ref23); AV_WN32A(&ref_cache[3 * 8], ref23); } { int16_t(*mv_src)[2] = &h->cur_pic.motion_val[list][4 * sl->mb_x + 4 * sl->mb_y * b_stride]; AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride); AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride); AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride); AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride); } }
['static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type)\n{\n const int mb_xy = sl->mb_xy;\n int top_xy, left_xy[LEFT_MBS];\n int top_type, left_type[LEFT_MBS];\n uint8_t *nnz;\n uint8_t *nnz_cache;\n top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;\n if (FRAME_MBAFF(h)) {\n const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if (sl->mb_y & 1) {\n if (left_mb_field_flag != curr_mb_field_flag)\n left_xy[LTOP] -= h->mb_stride;\n } else {\n if (curr_mb_field_flag)\n top_xy += h->mb_stride &\n (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);\n if (left_mb_field_flag != curr_mb_field_flag)\n left_xy[LBOT] += h->mb_stride;\n }\n }\n sl->top_mb_xy = top_xy;\n sl->left_mb_xy[LTOP] = left_xy[LTOP];\n sl->left_mb_xy[LBOT] = left_xy[LBOT];\n {\n int qp_thresh = sl->qp_thresh;\n int qp = h->cur_pic.qscale_table[mb_xy];\n if (qp <= qp_thresh &&\n (left_xy[LTOP] < 0 ||\n ((qp + h->cur_pic.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) &&\n (top_xy < 0 ||\n ((qp + h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) {\n if (!FRAME_MBAFF(h))\n return 1;\n if ((left_xy[LTOP] < 0 ||\n ((qp + h->cur_pic.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) &&\n (top_xy < h->mb_stride ||\n ((qp + h->cur_pic.qscale_table[top_xy - h->mb_stride] + 1) >> 1) <= qp_thresh))\n return 1;\n }\n }\n top_type = h->cur_pic.mb_type[top_xy];\n left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];\n left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];\n if (sl->deblocking_filter == 2) {\n if (h->slice_table[top_xy] != sl->slice_num)\n top_type = 0;\n if (h->slice_table[left_xy[LBOT]] != sl->slice_num)\n left_type[LTOP] = left_type[LBOT] = 0;\n } else {\n if (h->slice_table[top_xy] == 0xFFFF)\n top_type = 0;\n if (h->slice_table[left_xy[LBOT]] == 0xFFFF)\n left_type[LTOP] = left_type[LBOT] = 0;\n }\n sl->top_type = top_type;\n sl->left_type[LTOP] = left_type[LTOP];\n sl->left_type[LBOT] = left_type[LBOT];\n if (IS_INTRA(mb_type))\n return 0;\n fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,\n top_type, left_type, mb_xy, 0);\n if (sl->list_count == 2)\n fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy,\n top_type, left_type, mb_xy, 1);\n nnz = h->non_zero_count[mb_xy];\n nnz_cache = sl->non_zero_count_cache;\n AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]);\n AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]);\n AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]);\n AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]);\n sl->cbp = h->cbp_table[mb_xy];\n if (top_type) {\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]);\n }\n if (left_type[LTOP]) {\n nnz = h->non_zero_count[left_xy[LTOP]];\n nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4];\n nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4];\n nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4];\n nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4];\n }\n if (!CABAC(h) && h->ps.pps->transform_8x8_mode) {\n if (IS_8x8DCT(top_type)) {\n nnz_cache[4 + 8 * 0] =\n nnz_cache[5 + 8 * 0] = (h->cbp_table[top_xy] & 0x4000) >> 12;\n nnz_cache[6 + 8 * 0] =\n nnz_cache[7 + 8 * 0] = (h->cbp_table[top_xy] & 0x8000) >> 12;\n }\n if (IS_8x8DCT(left_type[LTOP])) {\n nnz_cache[3 + 8 * 1] =\n nnz_cache[3 + 8 * 2] = (h->cbp_table[left_xy[LTOP]] & 0x2000) >> 12;\n }\n if (IS_8x8DCT(left_type[LBOT])) {\n nnz_cache[3 + 8 * 3] =\n nnz_cache[3 + 8 * 4] = (h->cbp_table[left_xy[LBOT]] & 0x8000) >> 12;\n }\n if (IS_8x8DCT(mb_type)) {\n nnz_cache[scan8[0]] =\n nnz_cache[scan8[1]] =\n nnz_cache[scan8[2]] =\n nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12;\n nnz_cache[scan8[0 + 4]] =\n nnz_cache[scan8[1 + 4]] =\n nnz_cache[scan8[2 + 4]] =\n nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12;\n nnz_cache[scan8[0 + 8]] =\n nnz_cache[scan8[1 + 8]] =\n nnz_cache[scan8[2 + 8]] =\n nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12;\n nnz_cache[scan8[0 + 12]] =\n nnz_cache[scan8[1 + 12]] =\n nnz_cache[scan8[2 + 12]] =\n nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12;\n }\n }\n return 0;\n}', 'static av_always_inline void fill_filter_caches_inter(const H264Context *h,\n H264SliceContext *sl,\n int mb_type, int top_xy,\n int left_xy[LEFT_MBS],\n int top_type,\n int left_type[LEFT_MBS],\n int mb_xy, int list)\n{\n int b_stride = h->b_stride;\n int16_t(*mv_dst)[2] = &sl->mv_cache[list][scan8[0]];\n int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];\n if (IS_INTER(mb_type) || IS_DIRECT(mb_type)) {\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;\n const int b8_xy = 4 * top_xy + 2;\n int (*ref2frm)[64] = h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2);\n AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]);\n ref_cache[0 - 1 * 8] =\n ref_cache[1 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 0]];\n ref_cache[2 - 1 * 8] =\n ref_cache[3 - 1 * 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 1]];\n } else {\n AV_ZERO128(mv_dst - 1 * 8);\n AV_WN32A(&ref_cache[0 - 1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u);\n }\n if (!IS_INTERLACED(mb_type ^ left_type[LTOP])) {\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 int (*ref2frm)[64] = h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2);\n AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]);\n AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]);\n AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]);\n AV_COPY32(mv_dst - 1 + 24, h->cur_pic.motion_val[list][b_xy + b_stride * 3]);\n ref_cache[-1 + 0] =\n ref_cache[-1 + 8] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 2 * 0]];\n ref_cache[-1 + 16] =\n ref_cache[-1 + 24] = ref2frm[list][h->cur_pic.ref_index[list][b8_xy + 2 * 1]];\n } else {\n AV_ZERO32(mv_dst - 1 + 0);\n AV_ZERO32(mv_dst - 1 + 8);\n AV_ZERO32(mv_dst - 1 + 16);\n AV_ZERO32(mv_dst - 1 + 24);\n ref_cache[-1 + 0] =\n ref_cache[-1 + 8] =\n ref_cache[-1 + 16] =\n ref_cache[-1 + 24] = LIST_NOT_USED;\n }\n }\n }\n if (!USES_LIST(mb_type, list)) {\n fill_rectangle(mv_dst, 4, 4, 8, pack16to32(0, 0), 4);\n AV_WN32A(&ref_cache[0 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u);\n AV_WN32A(&ref_cache[1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u);\n AV_WN32A(&ref_cache[2 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u);\n AV_WN32A(&ref_cache[3 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u);\n return;\n }\n {\n int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy];\n int (*ref2frm)[64] = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][0] + (MB_MBAFF(sl) ? 20 : 2);\n uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]], ref2frm[list][ref[1]]) & 0x00FF00FF) * 0x0101;\n uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]], ref2frm[list][ref[3]]) & 0x00FF00FF) * 0x0101;\n AV_WN32A(&ref_cache[0 * 8], ref01);\n AV_WN32A(&ref_cache[1 * 8], ref01);\n AV_WN32A(&ref_cache[2 * 8], ref23);\n AV_WN32A(&ref_cache[3 * 8], ref23);\n }\n {\n int16_t(*mv_src)[2] = &h->cur_pic.motion_val[list][4 * sl->mb_x + 4 * sl->mb_y * b_stride];\n AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride);\n AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride);\n AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride);\n AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride);\n }\n}']
36,142
0
https://github.com/libav/libav/blob/1e76a1da0534f3a7cdaf7811059beaff874e0504/libavcodec/vp3.c/#L764
static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) { int j, k, sb_x, sb_y; int coding_mode; int motion_x[4]; int motion_y[4]; int last_motion_x = 0; int last_motion_y = 0; int prior_last_motion_x = 0; int prior_last_motion_y = 0; int current_macroblock; int current_fragment; Vp3Fragment *frag; if (s->keyframe) return 0; coding_mode = get_bits1(gb); for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) { for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) { for (j = 0; j < 4; j++) { int mb_x = 2*sb_x + (j>>1); int mb_y = 2*sb_y + (((j>>1)+j)&1); current_macroblock = mb_y * s->macroblock_width + mb_x; if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height || (s->macroblock_coding[current_macroblock] == MODE_COPY)) continue; switch (s->macroblock_coding[current_macroblock]) { case MODE_INTER_PLUS_MV: case MODE_GOLDEN_MV: if (coding_mode == 0) { motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; } else { motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)]; motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; } if (s->macroblock_coding[current_macroblock] == MODE_INTER_PLUS_MV) { prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[0]; last_motion_y = motion_y[0]; } break; case MODE_INTER_FOURMV: prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; for (k = 0; k < 4; k++) { current_fragment = BLOCK_Y*s->fragment_width[0] + BLOCK_X; if (s->all_fragments[current_fragment].coding_method != MODE_COPY) { if (coding_mode == 0) { motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; } else { motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)]; motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)]; } last_motion_x = motion_x[k]; last_motion_y = motion_y[k]; } else { motion_x[k] = 0; motion_y[k] = 0; } } break; case MODE_INTER_LAST_MV: motion_x[0] = last_motion_x; motion_y[0] = last_motion_y; break; case MODE_INTER_PRIOR_LAST: motion_x[0] = prior_last_motion_x; motion_y[0] = prior_last_motion_y; prior_last_motion_x = last_motion_x; prior_last_motion_y = last_motion_y; last_motion_x = motion_x[0]; last_motion_y = motion_y[0]; break; default: motion_x[0] = 0; motion_y[0] = 0; break; } for (k = 0; k < 4; k++) { current_fragment = BLOCK_Y*s->fragment_width[0] + BLOCK_X; if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { s->all_fragments[current_fragment].motion_x = motion_x[k]; s->all_fragments[current_fragment].motion_y = motion_y[k]; } else { s->all_fragments[current_fragment].motion_x = motion_x[0]; s->all_fragments[current_fragment].motion_y = motion_y[0]; } } #define SET_CHROMA_MV(mx, my) \ frag[s->fragment_start[1]].motion_x = mx; \ frag[s->fragment_start[1]].motion_y = my; \ frag[s->fragment_start[2]].motion_x = mx; \ frag[s->fragment_start[2]].motion_y = my if (s->chroma_y_shift) { if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] + motion_x[2] + motion_x[3], 2); motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] + motion_y[2] + motion_y[3], 2); } motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1); motion_y[0] = (motion_y[0]>>1) | (motion_y[0]&1); frag = s->all_fragments + mb_y*s->fragment_width[1] + mb_x; SET_CHROMA_MV(motion_x[0], motion_y[0]); } else if (s->chroma_x_shift) { if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1); motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1); motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1); motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1); } else { motion_x[1] = motion_x[0]; motion_y[1] = motion_y[0]; } motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1); motion_x[1] = (motion_x[1]>>1) | (motion_x[1]&1); frag = s->all_fragments + 2*mb_y*s->fragment_width[1] + mb_x; for (k = 0; k < 2; k++) { SET_CHROMA_MV(motion_x[k], motion_y[k]); frag += s->fragment_width[1]; } } else { for (k = 0; k < 4; k++) { frag = s->all_fragments + BLOCK_Y*s->fragment_width[1] + BLOCK_X; if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) { SET_CHROMA_MV(motion_x[k], motion_y[k]); } else { SET_CHROMA_MV(motion_x[0], motion_y[0]); } } } } } } return 0; }
['static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb)\n{\n int j, k, sb_x, sb_y;\n int coding_mode;\n int motion_x[4];\n int motion_y[4];\n int last_motion_x = 0;\n int last_motion_y = 0;\n int prior_last_motion_x = 0;\n int prior_last_motion_y = 0;\n int current_macroblock;\n int current_fragment;\n Vp3Fragment *frag;\n if (s->keyframe)\n return 0;\n coding_mode = get_bits1(gb);\n for (sb_y = 0; sb_y < s->y_superblock_height; sb_y++) {\n for (sb_x = 0; sb_x < s->y_superblock_width; sb_x++) {\n for (j = 0; j < 4; j++) {\n int mb_x = 2*sb_x + (j>>1);\n int mb_y = 2*sb_y + (((j>>1)+j)&1);\n current_macroblock = mb_y * s->macroblock_width + mb_x;\n if (mb_x >= s->macroblock_width || mb_y >= s->macroblock_height ||\n (s->macroblock_coding[current_macroblock] == MODE_COPY))\n continue;\n switch (s->macroblock_coding[current_macroblock]) {\n case MODE_INTER_PLUS_MV:\n case MODE_GOLDEN_MV:\n if (coding_mode == 0) {\n motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n } else {\n motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)];\n motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)];\n }\n if (s->macroblock_coding[current_macroblock] ==\n MODE_INTER_PLUS_MV) {\n prior_last_motion_x = last_motion_x;\n prior_last_motion_y = last_motion_y;\n last_motion_x = motion_x[0];\n last_motion_y = motion_y[0];\n }\n break;\n case MODE_INTER_FOURMV:\n prior_last_motion_x = last_motion_x;\n prior_last_motion_y = last_motion_y;\n for (k = 0; k < 4; k++) {\n current_fragment = BLOCK_Y*s->fragment_width[0] + BLOCK_X;\n if (s->all_fragments[current_fragment].coding_method != MODE_COPY) {\n if (coding_mode == 0) {\n motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)];\n } else {\n motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)];\n motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)];\n }\n last_motion_x = motion_x[k];\n last_motion_y = motion_y[k];\n } else {\n motion_x[k] = 0;\n motion_y[k] = 0;\n }\n }\n break;\n case MODE_INTER_LAST_MV:\n motion_x[0] = last_motion_x;\n motion_y[0] = last_motion_y;\n break;\n case MODE_INTER_PRIOR_LAST:\n motion_x[0] = prior_last_motion_x;\n motion_y[0] = prior_last_motion_y;\n prior_last_motion_x = last_motion_x;\n prior_last_motion_y = last_motion_y;\n last_motion_x = motion_x[0];\n last_motion_y = motion_y[0];\n break;\n default:\n motion_x[0] = 0;\n motion_y[0] = 0;\n break;\n }\n for (k = 0; k < 4; k++) {\n current_fragment =\n BLOCK_Y*s->fragment_width[0] + BLOCK_X;\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n s->all_fragments[current_fragment].motion_x = motion_x[k];\n s->all_fragments[current_fragment].motion_y = motion_y[k];\n } else {\n s->all_fragments[current_fragment].motion_x = motion_x[0];\n s->all_fragments[current_fragment].motion_y = motion_y[0];\n }\n }\n#define SET_CHROMA_MV(mx, my) \\\n frag[s->fragment_start[1]].motion_x = mx; \\\n frag[s->fragment_start[1]].motion_y = my; \\\n frag[s->fragment_start[2]].motion_x = mx; \\\n frag[s->fragment_start[2]].motion_y = my\n if (s->chroma_y_shift) {\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n motion_x[0] = RSHIFT(motion_x[0] + motion_x[1] + motion_x[2] + motion_x[3], 2);\n motion_y[0] = RSHIFT(motion_y[0] + motion_y[1] + motion_y[2] + motion_y[3], 2);\n }\n motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1);\n motion_y[0] = (motion_y[0]>>1) | (motion_y[0]&1);\n frag = s->all_fragments + mb_y*s->fragment_width[1] + mb_x;\n SET_CHROMA_MV(motion_x[0], motion_y[0]);\n } else if (s->chroma_x_shift) {\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n motion_x[0] = RSHIFT(motion_x[0] + motion_x[1], 1);\n motion_y[0] = RSHIFT(motion_y[0] + motion_y[1], 1);\n motion_x[1] = RSHIFT(motion_x[2] + motion_x[3], 1);\n motion_y[1] = RSHIFT(motion_y[2] + motion_y[3], 1);\n } else {\n motion_x[1] = motion_x[0];\n motion_y[1] = motion_y[0];\n }\n motion_x[0] = (motion_x[0]>>1) | (motion_x[0]&1);\n motion_x[1] = (motion_x[1]>>1) | (motion_x[1]&1);\n frag = s->all_fragments + 2*mb_y*s->fragment_width[1] + mb_x;\n for (k = 0; k < 2; k++) {\n SET_CHROMA_MV(motion_x[k], motion_y[k]);\n frag += s->fragment_width[1];\n }\n } else {\n for (k = 0; k < 4; k++) {\n frag = s->all_fragments + BLOCK_Y*s->fragment_width[1] + BLOCK_X;\n if (s->macroblock_coding[current_macroblock] == MODE_INTER_FOURMV) {\n SET_CHROMA_MV(motion_x[k], motion_y[k]);\n } else {\n SET_CHROMA_MV(motion_x[0], motion_y[0]);\n }\n }\n }\n }\n }\n }\n return 0;\n}']
36,143
0
https://github.com/libav/libav/blob/1e8b9738fa70e20967ddb542d2f9d5552fc51ec6/libavcodec/h264_mvpred.h/#L571
static void fill_decode_caches(H264Context *h, int mb_type) { int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; const uint8_t *left_block = h->left_block; int i; uint8_t *nnz; uint8_t *nnz_cache; topleft_xy = h->topleft_mb_xy; top_xy = h->top_mb_xy; topright_xy = h->topright_mb_xy; left_xy[LTOP] = h->left_mb_xy[LTOP]; left_xy[LBOT] = h->left_mb_xy[LBOT]; topleft_type = h->topleft_type; top_type = h->top_type; topright_type = h->topright_type; left_type[LTOP] = h->left_type[LTOP]; left_type[LBOT] = h->left_type[LBOT]; if (!IS_SKIP(mb_type)) { if (IS_INTRA(mb_type)) { int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; h->topleft_samples_available = h->top_samples_available = h->left_samples_available = 0xFFFF; h->topright_samples_available = 0xEEEA; if (!(top_type & type_mask)) { h->topleft_samples_available = 0xB3FF; h->top_samples_available = 0x33FF; h->topright_samples_available = 0x26EA; } if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) { if (IS_INTERLACED(mb_type)) { if (!(left_type[LTOP] & type_mask)) { h->topleft_samples_available &= 0xDFFF; h->left_samples_available &= 0x5FFF; } if (!(left_type[LBOT] & type_mask)) { h->topleft_samples_available &= 0xFF5F; h->left_samples_available &= 0xFF5F; } } else { int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride]; assert(left_xy[LTOP] == left_xy[LBOT]); if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) { h->topleft_samples_available &= 0xDF5F; h->left_samples_available &= 0x5F5F; } } } else { if (!(left_type[LTOP] & type_mask)) { h->topleft_samples_available &= 0xDF5F; h->left_samples_available &= 0x5F5F; } } if (!(topleft_type & type_mask)) h->topleft_samples_available &= 0x7FFF; if (!(topright_type & type_mask)) h->topright_samples_available &= 0xFBFF; if (IS_INTRA4x4(mb_type)) { if (IS_INTRA4x4(top_type)) { AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); } else { h->intra4x4_pred_mode_cache[4 + 8 * 0] = h->intra4x4_pred_mode_cache[5 + 8 * 0] = h->intra4x4_pred_mode_cache[6 + 8 * 0] = h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask); } for (i = 0; i < 2; i++) { if (IS_INTRA4x4(left_type[LEFT(i)])) { int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]]; h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]]; h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]]; } else { h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask); } } } } nnz_cache = h->non_zero_count_cache; if (top_type) { nnz = h->non_zero_count[top_xy]; AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]); if (!h->chroma_y_shift) { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]); } else { AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]); AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]); } } else { uint32_t top_empty = CABAC(h) && !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(h)) { nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4]; nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4]; nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4]; nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4]; } else if (CHROMA422(h)) { nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4]; nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4]; nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4]; nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4]; } else { nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]]; nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]]; } } else { nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 64; } } if (CABAC(h)) { if (top_type) h->top_cbp = h->cbp_table[top_xy]; else h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; if (left_type[LTOP]) { h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) | ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) | (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2); } else { h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; } } } if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) { int list; int b_stride = h->b_stride; for (list = 0; list < h->list_count; list++) { int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; int8_t *ref = h->cur_pic.ref_index[list]; int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; int16_t(*mv)[2] = h->cur_pic.motion_val[list]; if (!USES_LIST(mb_type, list)) continue; assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); if (USES_LIST(top_type, list)) { const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]); ref_cache[0 - 1 * 8] = ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2]; ref_cache[2 - 1 * 8] = ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3]; } else { AV_ZERO128(mv_cache[0 - 1 * 8]); AV_WN32A(&ref_cache[0 - 1 * 8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u); } if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) { for (i = 0; i < 2; i++) { int cache_idx = -1 + i * 2 * 8; if (USES_LIST(left_type[LEFT(i)], list)) { const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3; const int b8_xy = 4 * left_xy[LEFT(i)] + 1; AV_COPY32(mv_cache[cache_idx], mv[b_xy + b_stride * left_block[0 + i * 2]]); AV_COPY32(mv_cache[cache_idx + 8], mv[b_xy + b_stride * left_block[1 + i * 2]]); ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)]; ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)]; } else { AV_ZERO32(mv_cache[cache_idx]); AV_ZERO32(mv_cache[cache_idx + 8]); ref_cache[cache_idx] = ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } } else { if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; const int b8_xy = 4 * left_xy[LTOP] + 1; AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]); ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)]; } else { AV_ZERO32(mv_cache[-1]); ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if (USES_LIST(topright_type, list)) { const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride; AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]); ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2]; } else { AV_ZERO32(mv_cache[4 - 1 * 8]); ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } if (ref_cache[4 - 1 * 8] < 0) { if (USES_LIST(topleft_type, list)) { const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2 * b_stride); const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2); AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]); ref_cache[-1 - 1 * 8] = ref[b8_xy]; } else { AV_ZERO32(mv_cache[-1 - 1 * 8]); ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; } } if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h)) 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(h)) { if (USES_LIST(top_type, list)) { const int b_xy = h->mb2br_xy[top_xy]; AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]); } else { AV_ZERO64(mvd_cache[0 - 1 * 8]); } if (USES_LIST(left_type[LTOP], list)) { const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6; AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]); AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]); } else { AV_ZERO16(mvd_cache[-1 + 0 * 8]); AV_ZERO16(mvd_cache[-1 + 1 * 8]); } if (USES_LIST(left_type[LBOT], list)) { const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6; AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]); AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]); } else { AV_ZERO16(mvd_cache[-1 + 2 * 8]); AV_ZERO16(mvd_cache[-1 + 3 * 8]); } AV_ZERO16(mvd_cache[2 + 8 * 0]); AV_ZERO16(mvd_cache[2 + 8 * 2]); if (h->slice_type_nos == AV_PICTURE_TYPE_B) { uint8_t *direct_cache = &h->direct_cache[scan8[0]]; uint8_t *direct_table = h->direct_table; fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1); if (IS_DIRECT(top_type)) { AV_WN32A(&direct_cache[-1 * 8], 0x01010101u * (MB_TYPE_DIRECT2 >> 1)); } else if (IS_8X8(top_type)) { int b8_xy = 4 * top_xy; direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2]; direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3]; } else { AV_WN32A(&direct_cache[-1 * 8], 0x01010101 * (MB_TYPE_16x16 >> 1)); } if (IS_DIRECT(left_type[LTOP])) direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1; else if (IS_8X8(left_type[LTOP])) direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)]; else direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1; if (IS_DIRECT(left_type[LBOT])) direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1; else if (IS_8X8(left_type[LBOT])) direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)]; else direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1; } } } #define MAP_MVS \ MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \ MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \ MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \ MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \ MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \ MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \ MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT]) if (FRAME_MBAFF(h)) { if (MB_FIELD(h)) { #define MAP_F2F(idx, mb_type) \ if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \ h->ref_cache[list][idx] <<= 1; \ h->mv_cache[list][idx][1] /= 2; \ h->mvd_cache[list][idx][1] >>= 1; \ } MAP_MVS } else { #undef MAP_F2F #define MAP_F2F(idx, mb_type) \ if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \ h->ref_cache[list][idx] >>= 1; \ h->mv_cache[list][idx][1] <<= 1; \ h->mvd_cache[list][idx][1] <<= 1; \ } MAP_MVS #undef MAP_F2F } } } } h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]); }
['static void av_unused decode_mb_skip(H264Context *h)\n{\n const int mb_xy = h->mb_xy;\n int mb_type = 0;\n memset(h->non_zero_count[mb_xy], 0, 48);\n if (MB_FIELD(h))\n mb_type |= MB_TYPE_INTERLACED;\n if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\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 } else {\n mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;\n fill_decode_neighbors(h, mb_type);\n pred_pskip_motion(h);\n }\n write_back_motion(h, mb_type);\n h->cur_pic.mb_type[mb_xy] = mb_type;\n h->cur_pic.qscale_table[mb_xy] = h->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{\n const int mb_xy = h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n static const uint8_t left_block_options[4][32] = {\n { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },\n { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },\n { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },\n { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }\n };\n h->topleft_partition = -1;\n top_xy = mb_xy - (h->mb_stride << MB_FIELD(h));\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(h)) {\n const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if (h->mb_y & 1) {\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += h->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += h->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n } else {\n if (curr_mb_field_flag) {\n topleft_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);\n topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);\n top_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[LBOT] += h->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy = topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = h->cur_pic.mb_type[topleft_xy];\n h->top_type = h->cur_pic.mb_type[top_xy];\n h->topright_type = h->cur_pic.mb_type[topright_xy];\n h->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];\n h->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];\n if (FMO) {\n if (h->slice_table[topleft_xy] != h->slice_num)\n h->topleft_type = 0;\n if (h->slice_table[top_xy] != h->slice_num)\n h->top_type = 0;\n if (h->slice_table[left_xy[LTOP]] != h->slice_num)\n h->left_type[LTOP] = h->left_type[LBOT] = 0;\n } else {\n if (h->slice_table[topleft_xy] != h->slice_num) {\n h->topleft_type = 0;\n if (h->slice_table[top_xy] != h->slice_num)\n h->top_type = 0;\n if (h->slice_table[left_xy[LTOP]] != h->slice_num)\n h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if (h->slice_table[topright_xy] != h->slice_num)\n h->topright_type = 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type)\n{\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t *left_block = h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP] = h->left_type[LTOP];\n left_type[LBOT] = h->left_type[LBOT];\n if (!IS_SKIP(mb_type)) {\n if (IS_INTRA(mb_type)) {\n int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available =\n h->top_samples_available =\n h->left_samples_available = 0xFFFF;\n h->topright_samples_available = 0xEEEA;\n if (!(top_type & type_mask)) {\n h->topleft_samples_available = 0xB3FF;\n h->top_samples_available = 0x33FF;\n h->topright_samples_available = 0x26EA;\n }\n if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {\n if (IS_INTERLACED(mb_type)) {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDFFF;\n h->left_samples_available &= 0x5FFF;\n }\n if (!(left_type[LBOT] & type_mask)) {\n h->topleft_samples_available &= 0xFF5F;\n h->left_samples_available &= 0xFF5F;\n }\n } else {\n int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n } else {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n if (!(topleft_type & type_mask))\n h->topleft_samples_available &= 0x7FFF;\n if (!(topright_type & type_mask))\n h->topright_samples_available &= 0xFBFF;\n if (IS_INTRA4x4(mb_type)) {\n if (IS_INTRA4x4(top_type)) {\n AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n } else {\n h->intra4x4_pred_mode_cache[4 + 8 * 0] =\n h->intra4x4_pred_mode_cache[5 + 8 * 0] =\n h->intra4x4_pred_mode_cache[6 + 8 * 0] =\n h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);\n }\n for (i = 0; i < 2; i++) {\n if (IS_INTRA4x4(left_type[LEFT(i)])) {\n int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];\n } else {\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if (top_type) {\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);\n if (!h->chroma_y_shift) {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);\n } else {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);\n }\n } else {\n uint32_t top_empty = CABAC(h) && !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(h)) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];\n } else if (CHROMA422(h)) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];\n } else {\n nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];\n nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];\n }\n } else {\n nnz_cache[3 + 8 * 1 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 2 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if (CABAC(h)) {\n if (top_type)\n h->top_cbp = h->cbp_table[top_xy];\n else\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |\n ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |\n (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {\n int list;\n int b_stride = h->b_stride;\n for (list = 0; list < h->list_count; list++) {\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = h->cur_pic.ref_index[list];\n int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t(*mv)[2] = h->cur_pic.motion_val[list];\n if (!USES_LIST(mb_type, list))\n continue;\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;\n AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);\n ref_cache[0 - 1 * 8] =\n ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];\n ref_cache[2 - 1 * 8] =\n ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];\n } else {\n AV_ZERO128(mv_cache[0 - 1 * 8]);\n AV_WN32A(&ref_cache[0 - 1 * 8],\n ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);\n }\n if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {\n for (i = 0; i < 2; i++) {\n int cache_idx = -1 + i * 2 * 8;\n if (USES_LIST(left_type[LEFT(i)], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy = 4 * left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx],\n mv[b_xy + b_stride * left_block[0 + i * 2]]);\n AV_COPY32(mv_cache[cache_idx + 8],\n mv[b_xy + b_stride * left_block[1 + i * 2]]);\n ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];\n ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];\n } else {\n AV_ZERO32(mv_cache[cache_idx]);\n AV_ZERO32(mv_cache[cache_idx + 8]);\n ref_cache[cache_idx] =\n ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n } else {\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy = 4 * left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);\n ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];\n } else {\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if (USES_LIST(topright_type, list)) {\n const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;\n AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);\n ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];\n } else {\n AV_ZERO32(mv_cache[4 - 1 * 8]);\n ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n if (ref_cache[4 - 1 * 8] < 0) {\n if (USES_LIST(topleft_type, list)) {\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +\n (h->topleft_partition & 2 * b_stride);\n const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);\n ref_cache[-1 - 1 * 8] = ref[b8_xy];\n } else {\n AV_ZERO32(mv_cache[-1 - 1 * 8]);\n ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h))\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(h)) {\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);\n } else {\n AV_ZERO64(mvd_cache[0 - 1 * 8]);\n }\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 0 * 8]);\n AV_ZERO16(mvd_cache[-1 + 1 * 8]);\n }\n if (USES_LIST(left_type[LBOT], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 2 * 8]);\n AV_ZERO16(mvd_cache[-1 + 3 * 8]);\n }\n AV_ZERO16(mvd_cache[2 + 8 * 0]);\n AV_ZERO16(mvd_cache[2 + 8 * 2]);\n if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);\n if (IS_DIRECT(top_type)) {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101u * (MB_TYPE_DIRECT2 >> 1));\n } else if (IS_8X8(top_type)) {\n int b8_xy = 4 * top_xy;\n direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];\n direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];\n } else {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101 * (MB_TYPE_16x16 >> 1));\n }\n if (IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];\n else\n direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;\n if (IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];\n else\n direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;\n }\n }\n }\n#define MAP_MVS \\\n MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \\\n MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \\\n MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \\\n MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])\n if (FRAME_MBAFF(h)) {\n if (MB_FIELD(h)) {\n#define MAP_F2F(idx, mb_type) \\\n if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] <<= 1; \\\n h->mv_cache[list][idx][1] /= 2; \\\n h->mvd_cache[list][idx][1] >>= 1; \\\n }\n MAP_MVS\n } else {\n#undef MAP_F2F\n#define MAP_F2F(idx, mb_type) \\\n if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] >>= 1; \\\n h->mv_cache[list][idx][1] <<= 1; \\\n h->mvd_cache[list][idx][1] <<= 1; \\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
36,144
0
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L951
void bn_correct_top(BIGNUM *a) { BN_ULONG *ftl; int tmp_top = a->top; if (tmp_top > 0) { for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) { ftl--; if (*ftl != 0) break; } a->top = tmp_top; } if (a->top == 0) a->neg = 0; bn_pollute(a); }
['static int test_negzero(void)\n{\n BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL;\n BIGNUM *numerator = NULL, *denominator = NULL;\n int consttime, st = 0;\n if (!TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_ptr(c = BN_new())\n || !TEST_ptr(d = BN_new()))\n goto err;\n if (!TEST_true(BN_set_word(a, 1)))\n goto err;\n BN_set_negative(a, 1);\n BN_zero(b);\n if (!TEST_true(BN_mul(c, a, b, ctx)))\n goto err;\n if (!TEST_BN_eq_zero(c)\n || !TEST_BN_ge_zero(c))\n goto err;\n for (consttime = 0; consttime < 2; consttime++) {\n if (!TEST_ptr(numerator = BN_new())\n || !TEST_ptr(denominator = BN_new()))\n goto err;\n if (consttime) {\n BN_set_flags(numerator, BN_FLG_CONSTTIME);\n BN_set_flags(denominator, BN_FLG_CONSTTIME);\n }\n if (!TEST_true(BN_set_word(numerator, 1))\n || !TEST_true(BN_set_word(denominator, 2)))\n goto err;\n BN_set_negative(numerator, 1);\n if (!TEST_true(BN_div(a, b, numerator, denominator, ctx))\n || !TEST_BN_eq_zero(a)\n || !TEST_BN_ge_zero(a))\n goto err;\n if (!TEST_true(BN_set_word(denominator, 1))\n || !TEST_true(BN_div(a, b, numerator, denominator, ctx))\n || !TEST_BN_eq_zero(b)\n || !TEST_BN_ge_zero(b))\n goto err;\n BN_free(numerator);\n BN_free(denominator);\n numerator = denominator = NULL;\n }\n BN_zero(a);\n BN_set_negative(a, 1);\n if (BN_is_negative(a))\n goto err;\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n BN_free(numerator);\n BN_free(denominator);\n return st;\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_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_correct_top(BIGNUM *a)\n{\n BN_ULONG *ftl;\n int tmp_top = a->top;\n if (tmp_top > 0) {\n for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {\n ftl--;\n if (*ftl != 0)\n break;\n }\n a->top = tmp_top;\n }\n if (a->top == 0)\n a->neg = 0;\n bn_pollute(a);\n}']
36,145
0
https://github.com/openssl/openssl/blob/49cd47eaababc8c57871b929080fc1357e2ad7b8/ssl/tls13_enc.c/#L702
int tls13_export_keying_material(SSL *s, unsigned char *out, size_t olen, const char *label, size_t llen, const unsigned char *context, size_t contextlen, int use_context) { unsigned char exportsecret[EVP_MAX_MD_SIZE]; static const unsigned char exporterlabel[] = "exporter"; unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE]; const EVP_MD *md = ssl_handshake_md(s); EVP_MD_CTX *ctx = EVP_MD_CTX_new(); unsigned int hashsize, datalen; int ret = 0; if (ctx == NULL || !ossl_statem_export_allowed(s)) goto err; if (!use_context) contextlen = 0; if (EVP_DigestInit_ex(ctx, md, NULL) <= 0 || EVP_DigestUpdate(ctx, context, contextlen) <= 0 || EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0 || EVP_DigestInit_ex(ctx, md, NULL) <= 0 || EVP_DigestFinal_ex(ctx, data, &datalen) <= 0 || !tls13_hkdf_expand(s, md, s->exporter_master_secret, (const unsigned char *)label, llen, data, datalen, exportsecret, hashsize) || !tls13_hkdf_expand(s, md, exportsecret, exporterlabel, sizeof(exporterlabel) - 1, hash, hashsize, out, olen)) goto err; ret = 1; err: EVP_MD_CTX_free(ctx); return ret; }
['int tls13_export_keying_material(SSL *s, unsigned char *out, size_t olen,\n const char *label, size_t llen,\n const unsigned char *context,\n size_t contextlen, int use_context)\n{\n unsigned char exportsecret[EVP_MAX_MD_SIZE];\n static const unsigned char exporterlabel[] = "exporter";\n unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];\n const EVP_MD *md = ssl_handshake_md(s);\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n unsigned int hashsize, datalen;\n int ret = 0;\n if (ctx == NULL || !ossl_statem_export_allowed(s))\n goto err;\n if (!use_context)\n contextlen = 0;\n if (EVP_DigestInit_ex(ctx, md, NULL) <= 0\n || EVP_DigestUpdate(ctx, context, contextlen) <= 0\n || EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0\n || EVP_DigestInit_ex(ctx, md, NULL) <= 0\n || EVP_DigestFinal_ex(ctx, data, &datalen) <= 0\n || !tls13_hkdf_expand(s, md, s->exporter_master_secret,\n (const unsigned char *)label, llen,\n data, datalen, exportsecret, hashsize)\n || !tls13_hkdf_expand(s, md, exportsecret, exporterlabel,\n sizeof(exporterlabel) - 1, hash, hashsize,\n out, olen))\n goto err;\n ret = 1;\n err:\n EVP_MD_CTX_free(ctx);\n return ret;\n}', 'const EVP_MD *ssl_handshake_md(SSL *s)\n{\n return EVP_sha256();\n}', 'const EVP_MD *EVP_sha256(void)\n{\n return &sha256_md;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int ossl_statem_export_allowed(SSL *s)\n{\n return 1;\n}', 'int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)\n{\n return ctx->update(ctx, data, count);\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
36,146
0
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/wmaenc.c/#L237
static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain){ int v, bsize, ch, coef_nb_bits, parse_exponents; float mdct_norm; int nb_coefs[MAX_CHANNELS]; static const int fixed_exp[25]={20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20}; if (s->use_variable_block_len) { assert(0); }else{ s->next_block_len_bits = s->frame_len_bits; s->prev_block_len_bits = s->frame_len_bits; s->block_len_bits = s->frame_len_bits; } s->block_len = 1 << s->block_len_bits; bsize = s->frame_len_bits - s->block_len_bits; v = s->coefs_end[bsize] - s->coefs_start; for(ch = 0; ch < s->nb_channels; ch++) nb_coefs[ch] = v; { int n4 = s->block_len / 2; mdct_norm = 1.0 / (float)n4; if (s->version == 1) { mdct_norm *= sqrt(n4); } } if (s->nb_channels == 2) { put_bits(&s->pb, 1, s->ms_stereo= 1); } for(ch = 0; ch < s->nb_channels; ch++) { if ((s->channel_coded[ch]= 1)) { init_exp(s, ch, fixed_exp); } } for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int16_t *coefs1; float *coefs, *exponents, mult; int i, n; coefs1 = s->coefs1[ch]; exponents = s->exponents[ch]; mult = pow(10, total_gain * 0.05) / s->max_exponent[ch]; mult *= mdct_norm; coefs = src_coefs[ch]; if (s->use_noise_coding && 0) { assert(0); } else { coefs += s->coefs_start; n = nb_coefs[ch]; for(i = 0;i < n; i++){ double t= *coefs++ / (exponents[i] * mult); if(t<-32768 || t>32767) return -1; coefs1[i] = lrint(t); } } } } v = 0; for(ch = 0; ch < s->nb_channels; ch++) { int a = s->channel_coded[ch]; put_bits(&s->pb, 1, a); v |= a; } if (!v) return 1; for(v= total_gain-1; v>=127; v-= 127) put_bits(&s->pb, 7, 127); put_bits(&s->pb, 7, v); coef_nb_bits= ff_wma_total_gain_to_bits(total_gain); if (s->use_noise_coding) { for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int i, n; n = s->exponent_high_sizes[bsize]; for(i=0;i<n;i++) { put_bits(&s->pb, 1, s->high_band_coded[ch][i]= 0); if (0) nb_coefs[ch] -= s->exponent_high_bands[bsize][i]; } } } } parse_exponents = 1; if (s->block_len_bits != s->frame_len_bits) { put_bits(&s->pb, 1, parse_exponents); } if (parse_exponents) { for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { encode_exp_vlc(s, ch, fixed_exp); } else { assert(0); } } } } else { assert(0); } for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int run, tindex; int16_t *ptr, *eptr; tindex = (ch == 1 && s->ms_stereo); ptr = &s->coefs1[ch][0]; eptr = ptr + nb_coefs[ch]; run=0; for(;ptr < eptr; ptr++){ if(*ptr){ int level= *ptr; int abs_level= FFABS(level); int code= 0; if(abs_level <= s->coef_vlcs[tindex]->max_level){ if(run < s->coef_vlcs[tindex]->levels[abs_level-1]) code= run + s->int_table[tindex][abs_level-1]; } assert(code < s->coef_vlcs[tindex]->n); put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[code], s->coef_vlcs[tindex]->huffcodes[code]); if(code == 0){ if(1<<coef_nb_bits <= abs_level) return -1; put_bits(&s->pb, coef_nb_bits, abs_level); put_bits(&s->pb, s->frame_len_bits, run); } put_bits(&s->pb, 1, level < 0); run=0; }else{ run++; } } if(run) put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]); } if (s->version == 1 && s->nb_channels >= 2) { align_put_bits(&s->pb); } } return 0; }
['static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], int total_gain){\n int v, bsize, ch, coef_nb_bits, parse_exponents;\n float mdct_norm;\n int nb_coefs[MAX_CHANNELS];\n static const int fixed_exp[25]={20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20};\n if (s->use_variable_block_len) {\n assert(0);\n }else{\n s->next_block_len_bits = s->frame_len_bits;\n s->prev_block_len_bits = s->frame_len_bits;\n s->block_len_bits = s->frame_len_bits;\n }\n s->block_len = 1 << s->block_len_bits;\n bsize = s->frame_len_bits - s->block_len_bits;\n v = s->coefs_end[bsize] - s->coefs_start;\n for(ch = 0; ch < s->nb_channels; ch++)\n nb_coefs[ch] = v;\n {\n int n4 = s->block_len / 2;\n mdct_norm = 1.0 / (float)n4;\n if (s->version == 1) {\n mdct_norm *= sqrt(n4);\n }\n }\n if (s->nb_channels == 2) {\n put_bits(&s->pb, 1, s->ms_stereo= 1);\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if ((s->channel_coded[ch]= 1)) {\n init_exp(s, ch, fixed_exp);\n }\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int16_t *coefs1;\n float *coefs, *exponents, mult;\n int i, n;\n coefs1 = s->coefs1[ch];\n exponents = s->exponents[ch];\n mult = pow(10, total_gain * 0.05) / s->max_exponent[ch];\n mult *= mdct_norm;\n coefs = src_coefs[ch];\n if (s->use_noise_coding && 0) {\n assert(0);\n } else {\n coefs += s->coefs_start;\n n = nb_coefs[ch];\n for(i = 0;i < n; i++){\n double t= *coefs++ / (exponents[i] * mult);\n if(t<-32768 || t>32767)\n return -1;\n coefs1[i] = lrint(t);\n }\n }\n }\n }\n v = 0;\n for(ch = 0; ch < s->nb_channels; ch++) {\n int a = s->channel_coded[ch];\n put_bits(&s->pb, 1, a);\n v |= a;\n }\n if (!v)\n return 1;\n for(v= total_gain-1; v>=127; v-= 127)\n put_bits(&s->pb, 7, 127);\n put_bits(&s->pb, 7, v);\n coef_nb_bits= ff_wma_total_gain_to_bits(total_gain);\n if (s->use_noise_coding) {\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int i, n;\n n = s->exponent_high_sizes[bsize];\n for(i=0;i<n;i++) {\n put_bits(&s->pb, 1, s->high_band_coded[ch][i]= 0);\n if (0)\n nb_coefs[ch] -= s->exponent_high_bands[bsize][i];\n }\n }\n }\n }\n parse_exponents = 1;\n if (s->block_len_bits != s->frame_len_bits) {\n put_bits(&s->pb, 1, parse_exponents);\n }\n if (parse_exponents) {\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n if (s->use_exp_vlc) {\n encode_exp_vlc(s, ch, fixed_exp);\n } else {\n assert(0);\n }\n }\n }\n } else {\n assert(0);\n }\n for(ch = 0; ch < s->nb_channels; ch++) {\n if (s->channel_coded[ch]) {\n int run, tindex;\n int16_t *ptr, *eptr;\n tindex = (ch == 1 && s->ms_stereo);\n ptr = &s->coefs1[ch][0];\n eptr = ptr + nb_coefs[ch];\n run=0;\n for(;ptr < eptr; ptr++){\n if(*ptr){\n int level= *ptr;\n int abs_level= FFABS(level);\n int code= 0;\n if(abs_level <= s->coef_vlcs[tindex]->max_level){\n if(run < s->coef_vlcs[tindex]->levels[abs_level-1])\n code= run + s->int_table[tindex][abs_level-1];\n }\n assert(code < s->coef_vlcs[tindex]->n);\n put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[code], s->coef_vlcs[tindex]->huffcodes[code]);\n if(code == 0){\n if(1<<coef_nb_bits <= abs_level)\n return -1;\n put_bits(&s->pb, coef_nb_bits, abs_level);\n put_bits(&s->pb, s->frame_len_bits, run);\n }\n put_bits(&s->pb, 1, level < 0);\n run=0;\n }else{\n run++;\n }\n }\n if(run)\n put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]);\n }\n if (s->version == 1 && s->nb_channels >= 2) {\n align_put_bits(&s->pb);\n }\n }\n return 0;\n}']
36,147
0
https://github.com/libav/libav/blob/5e1840622ce6e41c57d9c407604863d3f3dcc3ae/libavcodec/h264_loopfilter.c/#L371
static av_always_inline void h264_filter_mb_fast_internal(const H264Context *h, H264SliceContext *sl, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int pixel_shift) { int chroma = !(CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY)); int chroma444 = CHROMA444(h); int chroma422 = CHROMA422(h); int mb_xy = sl->mb_xy; int left_type = sl->left_type[LTOP]; int top_type = sl->top_type; int qp_bd_offset = 6 * (h->ps.sps->bit_depth_luma - 8); int a = 52 + sl->slice_alpha_c0_offset - qp_bd_offset; int b = 52 + sl->slice_beta_offset - qp_bd_offset; int mb_type = h->cur_pic.mb_type[mb_xy]; int qp = h->cur_pic.qscale_table[mb_xy]; int qp0 = h->cur_pic.qscale_table[mb_xy - 1]; int qp1 = h->cur_pic.qscale_table[sl->top_mb_xy]; int qpc = get_chroma_qp(h->ps.pps, 0, qp); int qpc0 = get_chroma_qp(h->ps.pps, 0, qp0); int qpc1 = get_chroma_qp(h->ps.pps, 0, qp1); qp0 = (qp + qp0 + 1) >> 1; qp1 = (qp + qp1 + 1) >> 1; qpc0 = (qpc + qpc0 + 1) >> 1; qpc1 = (qpc + qpc1 + 1) >> 1; if( IS_INTRA(mb_type) ) { static const int16_t bS4[4] = {4,4,4,4}; static const int16_t bS3[4] = {3,3,3,3}; const int16_t *bSH = FIELD_PICTURE(h) ? bS3 : bS4; if(left_type) filter_mb_edgev( &img_y[4*0<<pixel_shift], linesize, bS4, qp0, a, b, h, 1); if( IS_8x8DCT(mb_type) ) { filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0); if(top_type){ filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1); } filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0); } else { filter_mb_edgev( &img_y[4*1<<pixel_shift], linesize, bS3, qp, a, b, h, 0); filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0); filter_mb_edgev( &img_y[4*3<<pixel_shift], linesize, bS3, qp, a, b, h, 0); if(top_type){ filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1); } filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, a, b, h, 0); filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0); filter_mb_edgeh( &img_y[4*3*linesize], linesize, bS3, qp, a, b, h, 0); } if(chroma){ if(chroma444){ if(left_type){ filter_mb_edgev( &img_cb[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1); filter_mb_edgev( &img_cr[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1); } if( IS_8x8DCT(mb_type) ) { filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); if(top_type){ filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 ); filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 ); } filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0); } else { filter_mb_edgev( &img_cb[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgev( &img_cr[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgev( &img_cb[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgev( &img_cr[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0); if(top_type){ filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1); filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1); } filter_mb_edgeh( &img_cb[4*1*linesize], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgeh( &img_cr[4*1*linesize], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgeh( &img_cb[4*3*linesize], linesize, bS3, qpc, a, b, h, 0); filter_mb_edgeh( &img_cr[4*3*linesize], linesize, bS3, qpc, a, b, h, 0); } }else if(chroma422){ if(left_type){ filter_mb_edgecv(&img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1); filter_mb_edgecv(&img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1); } filter_mb_edgecv(&img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgecv(&img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0); if(top_type){ filter_mb_edgech(&img_cb[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1); filter_mb_edgech(&img_cr[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1); } filter_mb_edgech(&img_cb[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgech(&img_cr[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgech(&img_cb[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgech(&img_cr[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgech(&img_cb[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgech(&img_cr[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); }else{ if(left_type){ filter_mb_edgecv( &img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1); filter_mb_edgecv( &img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1); } filter_mb_edgecv( &img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgecv( &img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0); if(top_type){ filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1); filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1); } filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0); } } return; } else { LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]); int edges; if( IS_8x8DCT(mb_type) && (sl->cbp&7) == 7 && !chroma444 ) { edges = 4; AV_WN64A(bS[0][0], 0x0002000200020002ULL); AV_WN64A(bS[0][2], 0x0002000200020002ULL); AV_WN64A(bS[1][0], 0x0002000200020002ULL); AV_WN64A(bS[1][2], 0x0002000200020002ULL); } else { int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4); int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1); int step = 1+(mb_type>>24); edges = 4 - 3*((mb_type>>3) & !(sl->cbp & 15)); h->h264dsp.h264_loop_filter_strength(bS, sl->non_zero_count_cache, sl->ref_cache, sl->mv_cache, sl->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE(h)); } if( IS_INTRA(left_type) ) AV_WN64A(bS[0][0], 0x0004000400040004ULL); if( IS_INTRA(top_type) ) AV_WN64A(bS[1][0], FIELD_PICTURE(h) ? 0x0003000300030003ULL : 0x0004000400040004ULL); #define FILTER(hv,dir,edge,intra)\ if(AV_RN64A(bS[dir][edge])) { \ filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qp : qp##dir, a, b, h, intra );\ if(chroma){\ if(chroma444){\ filter_mb_edge##hv( &img_cb[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\ filter_mb_edge##hv( &img_cr[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\ } else if(!(edge&1)) {\ filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\ filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\ }\ }\ } if(left_type) FILTER(v,0,0,1); if( edges == 1 ) { if(top_type) FILTER(h,1,0,1); } else if( IS_8x8DCT(mb_type) ) { FILTER(v,0,2,0); if(top_type) FILTER(h,1,0,1); FILTER(h,1,2,0); } else { FILTER(v,0,1,0); FILTER(v,0,2,0); FILTER(v,0,3,0); if(top_type) FILTER(h,1,0,1); FILTER(h,1,1,0); FILTER(h,1,2,0); FILTER(h,1,3,0); } #undef FILTER } }
['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;\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 if (avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)\n decode_postinit(h, 1);\n ff_h264_field_end(h, &h->slice_ctx[0], 0);\n *got_frame = 0;\n if (h->next_output_pic && ((avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) ||\n h->next_output_pic->recovered)) {\n if (!h->next_output_pic->recovered)\n h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT;\n ret = output_frame(h, pict, h->next_output_pic->f);\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 unsigned context_count = 0;\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 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 H264SliceContext *sl = &h->slice_ctx[context_count];\n int 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 sl->gb = nal->gb;\n if ((err = ff_h264_decode_slice_header(h, sl, nal)))\n break;\n if (sl->redundant_pic_count > 0)\n break;\n if (h->current_slice == 1) {\n if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS))\n decode_postinit(h, i >= nals_needed);\n }\n if ((avctx->skip_frame < AVDISCARD_NONREF || nal->ref_idc) &&\n (avctx->skip_frame < AVDISCARD_BIDIR ||\n sl->slice_type_nos != AV_PICTURE_TYPE_B) &&\n (avctx->skip_frame < AVDISCARD_NONKEY ||\n h->cur_pic_ptr->f->key_frame) &&\n avctx->skip_frame < AVDISCARD_ALL) {\n if (avctx->hwaccel) {\n ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n if (ret < 0)\n return ret;\n } else\n context_count++;\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 (context_count == h->nb_slice_ctx) {\n ret = ff_h264_execute_decode_slices(h, context_count);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n context_count = 0;\n }\n if (err < 0) {\n av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n sl->ref_count[0] = sl->ref_count[1] = sl->list_count = 0;\n }\n }\n if (context_count) {\n ret = ff_h264_execute_decode_slices(h, context_count);\n if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n goto end;\n }\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 pkt->nb_nals = 0;\n while (length >= 4) {\n H2645NAL *nal;\n int extract_length = 0;\n int skip_trailing_zeros = 1;\n if (is_nalff) {\n int i;\n for (i = 0; i < nal_length_size; i++)\n extract_length = (extract_length << 8) | buf[i];\n buf += nal_length_size;\n length -= nal_length_size;\n if (extract_length > length) {\n av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit size.\\n");\n return AVERROR_INVALIDDATA;\n }\n } else {\n if (buf[2] == 0) {\n length--;\n buf++;\n continue;\n }\n if (buf[0] != 0 || buf[1] != 0 || buf[2] != 1)\n return AVERROR_INVALIDDATA;\n buf += 3;\n length -= 3;\n extract_length = length;\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_execute_decode_slices(H264Context *h, unsigned context_count)\n{\n AVCodecContext *const avctx = h->avctx;\n H264SliceContext *sl;\n int i, j;\n if (h->avctx->hwaccel)\n return 0;\n if (context_count == 1) {\n int ret;\n h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height;\n h->postpone_filter = 0;\n ret = decode_slice(avctx, &h->slice_ctx[0]);\n h->mb_y = h->slice_ctx[0].mb_y;\n return ret;\n } else {\n for (i = 0; i < context_count; i++) {\n int next_slice_idx = h->mb_width * h->mb_height;\n int slice_idx;\n sl = &h->slice_ctx[i];\n sl->er.error_count = 0;\n slice_idx = sl->mb_y * h->mb_width + sl->mb_x;\n for (j = 0; j < context_count; j++) {\n H264SliceContext *sl2 = &h->slice_ctx[j];\n int slice_idx2 = sl2->mb_y * h->mb_width + sl2->mb_x;\n if (i == j || slice_idx2 < slice_idx)\n continue;\n next_slice_idx = FFMIN(next_slice_idx, slice_idx2);\n }\n sl->next_slice_idx = next_slice_idx;\n }\n avctx->execute(avctx, decode_slice, h->slice_ctx,\n NULL, context_count, sizeof(h->slice_ctx[0]));\n sl = &h->slice_ctx[context_count - 1];\n h->mb_y = sl->mb_y;\n for (i = 1; i < context_count; i++)\n h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;\n if (h->postpone_filter) {\n h->postpone_filter = 0;\n for (i = 0; i < context_count; i++) {\n int y_end, x_end;\n sl = &h->slice_ctx[i];\n y_end = FFMIN(sl->mb_y + 1, h->mb_height);\n x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;\n for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {\n sl->mb_y = j;\n loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,\n j == y_end - 1 ? x_end : h->mb_width);\n }\n }\n }\n }\n return 0;\n}', 'static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)\n{\n uint8_t *dest_y, *dest_cb, *dest_cr;\n int linesize, uvlinesize, mb_x, mb_y;\n const int end_mb_y = sl->mb_y + FRAME_MBAFF(h);\n const int old_slice_type = sl->slice_type;\n const int pixel_shift = h->pixel_shift;\n const int block_h = 16 >> h->chroma_y_shift;\n if (h->postpone_filter)\n return;\n if (sl->deblocking_filter) {\n for (mb_x = start_x; mb_x < end_x; mb_x++)\n for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {\n int mb_xy, mb_type;\n mb_xy = sl->mb_xy = mb_x + mb_y * h->mb_stride;\n mb_type = h->cur_pic.mb_type[mb_xy];\n if (FRAME_MBAFF(h))\n sl->mb_mbaff =\n sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type);\n sl->mb_x = mb_x;\n sl->mb_y = mb_y;\n dest_y = h->cur_pic.f->data[0] +\n ((mb_x << pixel_shift) + mb_y * sl->linesize) * 16;\n dest_cb = h->cur_pic.f->data[1] +\n (mb_x << pixel_shift) * (8 << CHROMA444(h)) +\n mb_y * sl->uvlinesize * block_h;\n dest_cr = h->cur_pic.f->data[2] +\n (mb_x << pixel_shift) * (8 << CHROMA444(h)) +\n mb_y * sl->uvlinesize * block_h;\n if (MB_FIELD(sl)) {\n linesize = sl->mb_linesize = sl->linesize * 2;\n uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2;\n if (mb_y & 1) {\n dest_y -= sl->linesize * 15;\n dest_cb -= sl->uvlinesize * (block_h - 1);\n dest_cr -= sl->uvlinesize * (block_h - 1);\n }\n } else {\n linesize = sl->mb_linesize = sl->linesize;\n uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;\n }\n backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n uvlinesize, 0);\n if (fill_filter_caches(h, sl, mb_type))\n continue;\n sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]);\n sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mb_xy]);\n if (FRAME_MBAFF(h)) {\n ff_h264_filter_mb(h, sl, mb_x, mb_y, dest_y, dest_cb, dest_cr,\n linesize, uvlinesize);\n } else {\n ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb,\n dest_cr, linesize, uvlinesize);\n }\n }\n }\n sl->slice_type = old_slice_type;\n sl->mb_x = end_x;\n sl->mb_y = end_mb_y - FRAME_MBAFF(h);\n sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);\n sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);\n}', 'void ff_h264_filter_mb_fast(const H264Context *h, H264SliceContext *sl,\n int mb_x, int mb_y, uint8_t *img_y,\n uint8_t *img_cb, uint8_t *img_cr,\n unsigned int linesize, unsigned int uvlinesize)\n{\n assert(!FRAME_MBAFF(h));\n if(!h->h264dsp.h264_loop_filter_strength || h->ps.pps->chroma_qp_diff) {\n ff_h264_filter_mb(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);\n return;\n }\n#if CONFIG_SMALL\n h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift);\n#else\n if(h->pixel_shift){\n h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1);\n }else{\n h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0);\n }\n#endif\n}', 'static av_always_inline void h264_filter_mb_fast_internal(const H264Context *h,\n H264SliceContext *sl,\n int mb_x, int mb_y,\n uint8_t *img_y,\n uint8_t *img_cb,\n uint8_t *img_cr,\n unsigned int linesize,\n unsigned int uvlinesize,\n int pixel_shift)\n{\n int chroma = !(CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY));\n int chroma444 = CHROMA444(h);\n int chroma422 = CHROMA422(h);\n int mb_xy = sl->mb_xy;\n int left_type = sl->left_type[LTOP];\n int top_type = sl->top_type;\n int qp_bd_offset = 6 * (h->ps.sps->bit_depth_luma - 8);\n int a = 52 + sl->slice_alpha_c0_offset - qp_bd_offset;\n int b = 52 + sl->slice_beta_offset - qp_bd_offset;\n int mb_type = h->cur_pic.mb_type[mb_xy];\n int qp = h->cur_pic.qscale_table[mb_xy];\n int qp0 = h->cur_pic.qscale_table[mb_xy - 1];\n int qp1 = h->cur_pic.qscale_table[sl->top_mb_xy];\n int qpc = get_chroma_qp(h->ps.pps, 0, qp);\n int qpc0 = get_chroma_qp(h->ps.pps, 0, qp0);\n int qpc1 = get_chroma_qp(h->ps.pps, 0, qp1);\n qp0 = (qp + qp0 + 1) >> 1;\n qp1 = (qp + qp1 + 1) >> 1;\n qpc0 = (qpc + qpc0 + 1) >> 1;\n qpc1 = (qpc + qpc1 + 1) >> 1;\n if( IS_INTRA(mb_type) ) {\n static const int16_t bS4[4] = {4,4,4,4};\n static const int16_t bS3[4] = {3,3,3,3};\n const int16_t *bSH = FIELD_PICTURE(h) ? bS3 : bS4;\n if(left_type)\n filter_mb_edgev( &img_y[4*0<<pixel_shift], linesize, bS4, qp0, a, b, h, 1);\n if( IS_8x8DCT(mb_type) ) {\n filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);\n }\n filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);\n } else {\n filter_mb_edgev( &img_y[4*1<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgev( &img_y[4*2<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgev( &img_y[4*3<<pixel_shift], linesize, bS3, qp, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_y[4*0*linesize], linesize, bSH, qp1, a, b, h, 1);\n }\n filter_mb_edgeh( &img_y[4*1*linesize], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgeh( &img_y[4*2*linesize], linesize, bS3, qp, a, b, h, 0);\n filter_mb_edgeh( &img_y[4*3*linesize], linesize, bS3, qp, a, b, h, 0);\n }\n if(chroma){\n if(chroma444){\n if(left_type){\n filter_mb_edgev( &img_cb[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);\n filter_mb_edgev( &img_cr[4*0<<pixel_shift], linesize, bS4, qpc0, a, b, h, 1);\n }\n if( IS_8x8DCT(mb_type) ) {\n filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );\n filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1 );\n }\n filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n } else {\n filter_mb_edgev( &img_cb[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*1<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cb[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*2<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cb[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgev( &img_cr[4*3<<pixel_shift], linesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgeh( &img_cb[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);\n filter_mb_edgeh( &img_cr[4*0*linesize], linesize, bSH, qpc1, a, b, h, 1);\n }\n filter_mb_edgeh( &img_cb[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*1*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cb[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*2*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cb[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgeh( &img_cr[4*3*linesize], linesize, bS3, qpc, a, b, h, 0);\n }\n }else if(chroma422){\n if(left_type){\n filter_mb_edgecv(&img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n filter_mb_edgecv(&img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n }\n filter_mb_edgecv(&img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgecv(&img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgech(&img_cb[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n filter_mb_edgech(&img_cr[4*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n }\n filter_mb_edgech(&img_cb[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cr[4*1*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cb[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cr[4*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cb[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech(&img_cr[4*3*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n }else{\n if(left_type){\n filter_mb_edgecv( &img_cb[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n filter_mb_edgecv( &img_cr[2*0<<pixel_shift], uvlinesize, bS4, qpc0, a, b, h, 1);\n }\n filter_mb_edgecv( &img_cb[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgecv( &img_cr[2*2<<pixel_shift], uvlinesize, bS3, qpc, a, b, h, 0);\n if(top_type){\n filter_mb_edgech( &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n filter_mb_edgech( &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1, a, b, h, 1);\n }\n filter_mb_edgech( &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n filter_mb_edgech( &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc, a, b, h, 0);\n }\n }\n return;\n } else {\n LOCAL_ALIGNED_8(int16_t, bS, [2], [4][4]);\n int edges;\n if( IS_8x8DCT(mb_type) && (sl->cbp&7) == 7 && !chroma444 ) {\n edges = 4;\n AV_WN64A(bS[0][0], 0x0002000200020002ULL);\n AV_WN64A(bS[0][2], 0x0002000200020002ULL);\n AV_WN64A(bS[1][0], 0x0002000200020002ULL);\n AV_WN64A(bS[1][2], 0x0002000200020002ULL);\n } else {\n int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4);\n int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1);\n int step = 1+(mb_type>>24);\n edges = 4 - 3*((mb_type>>3) & !(sl->cbp & 15));\n h->h264dsp.h264_loop_filter_strength(bS, sl->non_zero_count_cache, sl->ref_cache, sl->mv_cache,\n sl->list_count==2, edges, step, mask_edge0, mask_edge1, FIELD_PICTURE(h));\n }\n if( IS_INTRA(left_type) )\n AV_WN64A(bS[0][0], 0x0004000400040004ULL);\n if( IS_INTRA(top_type) )\n AV_WN64A(bS[1][0], FIELD_PICTURE(h) ? 0x0003000300030003ULL : 0x0004000400040004ULL);\n#define FILTER(hv,dir,edge,intra)\\\n if(AV_RN64A(bS[dir][edge])) { \\\n filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qp : qp##dir, a, b, h, intra );\\\n if(chroma){\\\n if(chroma444){\\\n filter_mb_edge##hv( &img_cb[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n filter_mb_edge##hv( &img_cr[4*edge*(dir?linesize:1<<pixel_shift)], linesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n } else if(!(edge&1)) {\\\n filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1<<pixel_shift)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, a, b, h, intra );\\\n }\\\n }\\\n }\n if(left_type)\n FILTER(v,0,0,1);\n if( edges == 1 ) {\n if(top_type)\n FILTER(h,1,0,1);\n } else if( IS_8x8DCT(mb_type) ) {\n FILTER(v,0,2,0);\n if(top_type)\n FILTER(h,1,0,1);\n FILTER(h,1,2,0);\n } else {\n FILTER(v,0,1,0);\n FILTER(v,0,2,0);\n FILTER(v,0,3,0);\n if(top_type)\n FILTER(h,1,0,1);\n FILTER(h,1,1,0);\n FILTER(h,1,2,0);\n FILTER(h,1,3,0);\n }\n#undef FILTER\n }\n}']
36,148
0
https://github.com/openssl/openssl/blob/02ab618c97eb5c383153f1835017533efc2f7422/crypto/asn1/asn1_lib.c/#L101
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, long omax) { int i,ret; long l; unsigned char *p= *pp; int tag,xclass,inf; long max=omax; if (!max) goto err; ret=(*p&V_ASN1_CONSTRUCTED); xclass=(*p&V_ASN1_PRIVATE); i= *p&V_ASN1_PRIMITIVE_TAG; if (i == V_ASN1_PRIMITIVE_TAG) { p++; if (--max == 0) goto err; l=0; while (*p&0x80) { l<<=7L; l|= *(p++)&0x7f; if (--max == 0) goto err; } l<<=7L; l|= *(p++)&0x7f; tag=(int)l; } else { tag=i; p++; if (--max == 0) goto err; } *ptag=tag; *pclass=xclass; if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; #if 0 fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), (int)(omax+ *pp)); #endif #if 0 if ((p+ *plength) > (omax+ *pp)) { ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); ret|=0x80; } #endif *pp=p; return(ret|inf); err: ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); return(0x80); }
['int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,\n\t PKCS7 *p7, PKCS7_SIGNER_INFO *si)\n\t{\n\tPKCS7_ISSUER_AND_SERIAL *ias;\n\tint ret=0,i;\n\tSTACK_OF(X509) *cert;\n\tX509 *x509;\n\tif (PKCS7_type_is_signed(p7))\n\t\t{\n\t\tcert=p7->d.sign->cert;\n\t\t}\n\telse if (PKCS7_type_is_signedAndEnveloped(p7))\n\t\t{\n\t\tcert=p7->d.signed_and_enveloped->cert;\n\t\t}\n\telse\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);\n\t\tgoto err;\n\t\t}\n\tias=si->issuer_and_serial;\n\tx509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);\n\tif (x509 == NULL)\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);\n\t\tgoto err;\n\t\t}\n\tX509_STORE_CTX_init(ctx,cert_store,x509,cert);\n\ti=X509_verify_cert(ctx);\n\tif (i <= 0)\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);\n\t\tgoto err;\n\t\t}\n\tX509_STORE_CTX_cleanup(ctx);\n\treturn PKCS7_signatureVerify(bio, p7, si, x509);\n\terr:\n\treturn ret;\n\t}', 'int X509_verify_cert(X509_STORE_CTX *ctx)\n\t{\n\tX509 *x,*xtmp,*chain_ss=NULL;\n\tX509_NAME *xn;\n\tX509_OBJECT obj;\n\tint depth,i,ok=0;\n\tint num;\n\tint (*cb)();\n\tSTACK_OF(X509) *sktmp=NULL;\n\tif (ctx->cert == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);\n\t\treturn(-1);\n\t\t}\n\tcb=ctx->ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tif (ctx->chain == NULL)\n\t\t{\n\t\tif (\t((ctx->chain=sk_X509_new_null()) == NULL) ||\n\t\t\t(!sk_X509_push(ctx->chain,ctx->cert)))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto end;\n\t\t\t}\n\t\tCRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);\n\t\tctx->last_untrusted=1;\n\t\t}\n\tif (ctx->untrusted != NULL\n\t && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\tgoto end;\n\t\t}\n\tnum=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,num-1);\n\tdepth=ctx->depth;\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)\n\t\t\tbreak;\n\t\tif (ctx->untrusted != NULL)\n\t\t\t{\n\t\t\txtmp=X509_find_by_subject(sktmp,xn);\n\t\t\tif (xtmp != NULL)\n\t\t\t\t{\n\t\t\t\tif (!sk_X509_push(ctx->chain,xtmp))\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tCRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);\n\t\t\t\tsk_X509_delete_ptr(sktmp,xtmp);\n\t\t\t\tctx->last_untrusted++;\n\t\t\t\tx=xtmp;\n\t\t\t\tnum++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\tbreak;\n\t\t}\n\ti=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,i-1);\n\tif (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x))\n\t\t== 0)\n\t\t{\n\t\tif (sk_X509_num(ctx->chain) == 1)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\tctx->error_depth=i-1;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tchain_ss=sk_X509_pop(ctx->chain);\n\t\t\tctx->last_untrusted--;\n\t\t\tnum--;\n\t\t\tx=sk_X509_value(ctx->chain,num-1);\n\t\t\t}\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)\n\t\t\tbreak;\n\t\tok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);\n\t\tif (ok != X509_LU_X509)\n\t\t\t{\n\t\t\tif (ok == X509_LU_RETRY)\n\t\t\t\t{\n\t\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);\n\t\t\t\treturn(ok);\n\t\t\t\t}\n\t\t\telse if (ok != X509_LU_FAIL)\n\t\t\t\t{\n\t\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\t\treturn(ok);\n\t\t\t\t}\n\t\t\tbreak;\n\t\t\t}\n\t\tx=obj.data.x509;\n\t\tif (!sk_X509_push(ctx->chain,obj.data.x509))\n\t\t\t{\n\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(0);\n\t\t\t}\n\t\tnum++;\n\t\t}\n\txn=X509_get_issuer_name(x);\n\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0)\n\t\t{\n\t\tif ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0))\n\t\t\t{\n\t\t\tif (ctx->last_untrusted >= num)\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;\n\t\t\telse\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsk_X509_push(ctx->chain,chain_ss);\n\t\t\tnum++;\n\t\t\tctx->last_untrusted=num;\n\t\t\tctx->current_cert=chain_ss;\n\t\t\tctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;\n\t\t\tchain_ss=NULL;\n\t\t\t}\n\t\tctx->error_depth=num-1;\n\t\tok=cb(0,ctx);\n\t\tif (!ok) goto end;\n\t\t}\n\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\tif (ctx->ctx->verify != NULL)\n\t\tok=ctx->ctx->verify(ctx);\n\telse\n\t\tok=internal_verify(ctx);\n\tif (0)\n\t\t{\nend:\n\t\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\t\t}\n\tif (sktmp != NULL) sk_X509_free(sktmp);\n\tif (chain_ss != NULL) X509_free(chain_ss);\n\treturn(ok);\n\t}', 'void X509_OBJECT_free_contents(X509_OBJECT *a)\n\t{\n\tswitch (a->type)\n\t\t{\n\tcase X509_LU_X509:\n\t\tX509_free(a->data.x509);\n\t\tbreak;\n\tcase X509_LU_CRL:\n\t\tX509_CRL_free(a->data.crl);\n\t\tbreak;\n\t\t}\n\t}', 'int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,\n\t\t\t\t\t\t\t\tX509 *x509)\n\t{\n\tASN1_OCTET_STRING *os;\n\tEVP_MD_CTX mdc_tmp,*mdc;\n\tunsigned char *pp,*p;\n\tint ret=0,i;\n\tint md_type;\n\tSTACK_OF(X509_ATTRIBUTE) *sk;\n\tBIO *btmp;\n\tEVP_PKEY *pkey;\n\tif (!PKCS7_type_is_signed(p7) &&\n\t\t\t\t!PKCS7_type_is_signedAndEnveloped(p7)) {\n\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\tPKCS7_R_WRONG_PKCS7_TYPE);\n\t\tgoto err;\n\t}\n\tmd_type=OBJ_obj2nid(si->digest_alg->algorithm);\n\tbtmp=bio;\n\tfor (;;)\n\t\t{\n\t\tif ((btmp == NULL) ||\n\t\t\t((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\tPKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\tBIO_get_md_ctx(btmp,&mdc);\n\t\tif (mdc == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\t\tPKCS7_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type)\n\t\t\tbreak;\n\t\tbtmp=btmp->next_bio;\n\t\t}\n\tmemcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));\n\tsk=si->auth_attr;\n\tif ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))\n\t\t{\n\t\tunsigned char md_dat[EVP_MAX_MD_SIZE];\n unsigned int md_len;\n\t\tASN1_OCTET_STRING *message_digest;\n\t\tEVP_DigestFinal(&mdc_tmp,md_dat,&md_len);\n\t\tmessage_digest=PKCS7_digest_from_attributes(sk);\n\t\tif (!message_digest)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\tPKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif ((message_digest->length != (int)md_len) ||\n\t\t\t(memcmp(message_digest->data,md_dat,md_len)))\n\t\t\t{\n#if 0\n{\nint ii;\nfor (ii=0; ii<message_digest->length; ii++)\n\tprintf("%02X",message_digest->data[ii]); printf(" sent\\n");\nfor (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\\n");\n}\n#endif\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\t\tPKCS7_R_DIGEST_FAILURE);\n\t\t\tret= -1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tEVP_VerifyInit(&mdc_tmp,EVP_get_digestbynid(md_type));\n\t\ti=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE,\n\t\t\tV_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);\n\t\tpp=Malloc(i);\n\t\tp=pp;\n\t\ti2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE,\n\t\t\tV_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);\n\t\tEVP_VerifyUpdate(&mdc_tmp,pp,i);\n\t\tFree(pp);\n\t\t}\n\tos=si->enc_digest;\n\tpkey = X509_get_pubkey(x509);\n\tif(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();\n\ti=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);\n\tEVP_PKEY_free(pkey);\n\tif (i <= 0)\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\tPKCS7_R_SIGNATURE_FAILURE);\n\t\tret= -1;\n\t\tgoto err;\n\t\t}\n\telse\n\t\tret=1;\nerr:\n\treturn(ret);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tM_ASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) M_ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
36,149
0
https://github.com/libav/libav/blob/c5254755c0154dcc7bb1191a84e6e7cf0106343b/libavformat/rtsp.c/#L1826
static int sdp_read_header(AVFormatContext *s) { RTSPState *rt = s->priv_data; RTSPStream *rtsp_st; int size, i, err; char *content; char url[1024]; if (!ff_network_init()) return AVERROR(EIO); content = av_malloc(SDP_MAX_SIZE); size = avio_read(s->pb, content, SDP_MAX_SIZE - 1); if (size <= 0) { av_free(content); return AVERROR_INVALIDDATA; } content[size] ='\0'; err = ff_sdp_parse(s, content); av_free(content); if (err) goto fail; for (i = 0; i < rt->nb_rtsp_streams; i++) { char namebuf[50]; rtsp_st = rt->rtsp_streams[i]; getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip), namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, rtsp_st->sdp_port, "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port, rtsp_st->sdp_ttl, rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0); if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, &s->interrupt_callback, NULL) < 0) { err = AVERROR_INVALIDDATA; goto fail; } if ((err = rtsp_open_transport_ctx(s, rtsp_st))) goto fail; } return 0; fail: ff_rtsp_close_streams(s); ff_network_close(); return err; }
['static int sdp_read_header(AVFormatContext *s)\n{\n RTSPState *rt = s->priv_data;\n RTSPStream *rtsp_st;\n int size, i, err;\n char *content;\n char url[1024];\n if (!ff_network_init())\n return AVERROR(EIO);\n content = av_malloc(SDP_MAX_SIZE);\n size = avio_read(s->pb, content, SDP_MAX_SIZE - 1);\n if (size <= 0) {\n av_free(content);\n return AVERROR_INVALIDDATA;\n }\n content[size] =\'\\0\';\n err = ff_sdp_parse(s, content);\n av_free(content);\n if (err) goto fail;\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n char namebuf[50];\n rtsp_st = rt->rtsp_streams[i];\n getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),\n namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);\n ff_url_join(url, sizeof(url), "rtp", NULL,\n namebuf, rtsp_st->sdp_port,\n "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port,\n rtsp_st->sdp_ttl,\n rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0);\n if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,\n &s->interrupt_callback, NULL) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n if ((err = rtsp_open_transport_ctx(s, rtsp_st)))\n goto fail;\n }\n return 0;\nfail:\n ff_rtsp_close_streams(s);\n ff_network_close();\n return err;\n}', 'int ff_network_init(void)\n{\n#if HAVE_WINSOCK2_H\n WSADATA wsaData;\n#endif\n if (!ff_network_inited_globally)\n av_log(NULL, AV_LOG_WARNING, "Using network protocols without global "\n "network initialization. Please use "\n "avformat_network_init(), this will "\n "become mandatory later.\\n");\n#if HAVE_WINSOCK2_H\n if (WSAStartup(MAKEWORD(1,1), &wsaData))\n return 0;\n#endif\n return 1;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\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}']
36,150
0
https://github.com/openssl/openssl/blob/cf56663fb71ce279eb8ea603faf0a3c98cc7bc47/apps/dgst.c/#L372
int MAIN(int argc, char **argv) { ENGINE *e = NULL; unsigned char *buf=NULL; int i,err=0; const EVP_MD *md=NULL,*m; BIO *in=NULL,*inp; BIO *bmd=NULL; BIO *out = NULL; const char *name; #define PROG_NAME_SIZE 39 char pname[PROG_NAME_SIZE+1]; int separator=0; int debug=0; int keyform=FORMAT_PEM; const char *outfile = NULL, *keyfile = NULL; const char *sigfile = NULL, *randfile = NULL; int out_bin = -1, want_pub = 0, do_verify = 0; EVP_PKEY *sigkey = NULL; unsigned char *sigbuf = NULL; int siglen = 0; #ifndef OPENSSL_NO_ENGINE char *engine=NULL; #endif apps_startup(); if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL) { BIO_printf(bio_err,"out of memory\n"); goto end; } if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; program_name(argv[0],pname,sizeof pname); md=EVP_get_digestbyname(pname); argc--; argv++; while (argc > 0) { if ((*argv)[0] != '-') break; if (strcmp(*argv,"-c") == 0) separator=1; else if (strcmp(*argv,"-rand") == 0) { if (--argc < 1) break; randfile=*(++argv); } else if (strcmp(*argv,"-out") == 0) { if (--argc < 1) break; outfile=*(++argv); } else if (strcmp(*argv,"-sign") == 0) { if (--argc < 1) break; keyfile=*(++argv); } else if (strcmp(*argv,"-verify") == 0) { if (--argc < 1) break; keyfile=*(++argv); want_pub = 1; do_verify = 1; } else if (strcmp(*argv,"-prverify") == 0) { if (--argc < 1) break; keyfile=*(++argv); do_verify = 1; } else if (strcmp(*argv,"-signature") == 0) { if (--argc < 1) break; sigfile=*(++argv); } else if (strcmp(*argv,"-keyform") == 0) { if (--argc < 1) break; keyform=str2fmt(*(++argv)); } #ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv,"-engine") == 0) { if (--argc < 1) break; engine= *(++argv); } #endif else if (strcmp(*argv,"-hex") == 0) out_bin = 0; else if (strcmp(*argv,"-binary") == 0) out_bin = 1; else if (strcmp(*argv,"-d") == 0) debug=1; else if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL) md=m; else break; argc--; argv++; } if (md == NULL) md=EVP_md5(); if(do_verify && !sigfile) { BIO_printf(bio_err, "No signature to verify: use the -signature option\n"); err = 1; goto end; } if ((argc > 0) && (argv[0][0] == '-')) { BIO_printf(bio_err,"unknown option '%s'\n",*argv); BIO_printf(bio_err,"options are\n"); BIO_printf(bio_err,"-c to output the digest with separating colons\n"); BIO_printf(bio_err,"-d to output debug info\n"); BIO_printf(bio_err,"-hex output as hex dump\n"); BIO_printf(bio_err,"-binary output in binary form\n"); BIO_printf(bio_err,"-sign file sign digest using private key in file\n"); BIO_printf(bio_err,"-verify file verify a signature using public key in file\n"); BIO_printf(bio_err,"-prverify file verify a signature using private key in file\n"); BIO_printf(bio_err,"-keyform arg key file format (PEM or ENGINE)\n"); BIO_printf(bio_err,"-signature file signature to verify\n"); BIO_printf(bio_err,"-binary output in binary form\n"); #ifndef OPENSSL_NO_ENGINE BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n"); #endif BIO_printf(bio_err,"-%3s to use the %s message digest algorithm (default)\n", LN_md5,LN_md5); BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n", LN_md4,LN_md4); BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n", LN_md2,LN_md2); BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n", LN_sha1,LN_sha1); BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n", LN_sha,LN_sha); BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n", LN_mdc2,LN_mdc2); BIO_printf(bio_err,"-%3s to use the %s message digest algorithm\n", LN_ripemd160,LN_ripemd160); err=1; goto end; } #ifndef OPENSSL_NO_ENGINE e = setup_engine(bio_err, engine, 0); #endif in=BIO_new(BIO_s_file()); bmd=BIO_new(BIO_f_md()); if (debug) { BIO_set_callback(in,BIO_debug_callback); BIO_set_callback_arg(in,bio_err); } if ((in == NULL) || (bmd == NULL)) { ERR_print_errors(bio_err); goto end; } if(out_bin == -1) { if(keyfile) out_bin = 1; else out_bin = 0; } if(randfile) app_RAND_load_file(randfile, bio_err, 0); if(outfile) { if(out_bin) out = BIO_new_file(outfile, "wb"); else out = BIO_new_file(outfile, "w"); } else { out = BIO_new_fp(stdout, BIO_NOCLOSE); #ifdef OPENSSL_SYS_VMS { BIO *tmpbio = BIO_new(BIO_f_linebuffer()); out = BIO_push(tmpbio, out); } #endif } if(!out) { BIO_printf(bio_err, "Error opening output file %s\n", outfile ? outfile : "(stdout)"); ERR_print_errors(bio_err); goto end; } if(keyfile) { if (want_pub) sigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL, e, "key file"); else sigkey = load_key(bio_err, keyfile, keyform, 0, NULL, e, "key file"); if (!sigkey) { goto end; } } if(sigfile && sigkey) { BIO *sigbio; sigbio = BIO_new_file(sigfile, "rb"); siglen = EVP_PKEY_size(sigkey); sigbuf = OPENSSL_malloc(siglen); if(!sigbio) { BIO_printf(bio_err, "Error opening signature file %s\n", sigfile); ERR_print_errors(bio_err); goto end; } siglen = BIO_read(sigbio, sigbuf, siglen); BIO_free(sigbio); if(siglen <= 0) { BIO_printf(bio_err, "Error reading signature file %s\n", sigfile); ERR_print_errors(bio_err); goto end; } } BIO_set_md(bmd,md); inp=BIO_push(bmd,in); if (argc == 0) { BIO_set_fp(in,stdin,BIO_NOCLOSE); err=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf, siglen,"","(stdin)"); } else { name=OBJ_nid2sn(md->type); for (i=0; i<argc; i++) { char *tmp,*tofree=NULL; int r; if (BIO_read_filename(in,argv[i]) <= 0) { perror(argv[i]); err++; continue; } if(!out_bin) { tmp=tofree=OPENSSL_malloc(strlen(name)+strlen(argv[i])+5); sprintf(tmp,"%s(%s)= ",name,argv[i]); } else tmp=""; r=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf, siglen,tmp,argv[i]); if(r) err=r; if(tofree) OPENSSL_free(tofree); (void)BIO_reset(bmd); } } end: if (buf != NULL) { OPENSSL_cleanse(buf,BUFSIZE); OPENSSL_free(buf); } if (in != NULL) BIO_free(in); BIO_free_all(out); EVP_PKEY_free(sigkey); if(sigbuf) OPENSSL_free(sigbuf); if (bmd != NULL) BIO_free(bmd); apps_shutdown(); OPENSSL_EXIT(err); }
['int MAIN(int argc, char **argv)\n\t{\n\tENGINE *e = NULL;\n\tunsigned char *buf=NULL;\n\tint i,err=0;\n\tconst EVP_MD *md=NULL,*m;\n\tBIO *in=NULL,*inp;\n\tBIO *bmd=NULL;\n\tBIO *out = NULL;\n\tconst char *name;\n#define PROG_NAME_SIZE 39\n\tchar pname[PROG_NAME_SIZE+1];\n\tint separator=0;\n\tint debug=0;\n\tint keyform=FORMAT_PEM;\n\tconst char *outfile = NULL, *keyfile = NULL;\n\tconst char *sigfile = NULL, *randfile = NULL;\n\tint out_bin = -1, want_pub = 0, do_verify = 0;\n\tEVP_PKEY *sigkey = NULL;\n\tunsigned char *sigbuf = NULL;\n\tint siglen = 0;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine=NULL;\n#endif\n\tapps_startup();\n\tif ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\tprogram_name(argv[0],pname,sizeof pname);\n\tmd=EVP_get_digestbyname(pname);\n\targc--;\n\targv++;\n\twhile (argc > 0)\n\t\t{\n\t\tif ((*argv)[0] != \'-\') break;\n\t\tif (strcmp(*argv,"-c") == 0)\n\t\t\tseparator=1;\n\t\telse if (strcmp(*argv,"-rand") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\trandfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\toutfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-sign") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-verify") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyfile=*(++argv);\n\t\t\twant_pub = 1;\n\t\t\tdo_verify = 1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-prverify") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyfile=*(++argv);\n\t\t\tdo_verify = 1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-signature") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tsigfile=*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tkeyform=str2fmt(*(++argv));\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if (strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) break;\n\t\t\tengine= *(++argv);\n\t\t\t}\n#endif\n\t\telse if (strcmp(*argv,"-hex") == 0)\n\t\t\tout_bin = 0;\n\t\telse if (strcmp(*argv,"-binary") == 0)\n\t\t\tout_bin = 1;\n\t\telse if (strcmp(*argv,"-d") == 0)\n\t\t\tdebug=1;\n\t\telse if ((m=EVP_get_digestbyname(&((*argv)[1]))) != NULL)\n\t\t\tmd=m;\n\t\telse\n\t\t\tbreak;\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (md == NULL)\n\t\tmd=EVP_md5();\n\tif(do_verify && !sigfile) {\n\t\tBIO_printf(bio_err, "No signature to verify: use the -signature option\\n");\n\t\terr = 1;\n\t\tgoto end;\n\t}\n\tif ((argc > 0) && (argv[0][0] == \'-\'))\n\t\t{\n\t\tBIO_printf(bio_err,"unknown option \'%s\'\\n",*argv);\n\t\tBIO_printf(bio_err,"options are\\n");\n\t\tBIO_printf(bio_err,"-c to output the digest with separating colons\\n");\n\t\tBIO_printf(bio_err,"-d to output debug info\\n");\n\t\tBIO_printf(bio_err,"-hex output as hex dump\\n");\n\t\tBIO_printf(bio_err,"-binary output in binary form\\n");\n\t\tBIO_printf(bio_err,"-sign file sign digest using private key in file\\n");\n\t\tBIO_printf(bio_err,"-verify file verify a signature using public key in file\\n");\n\t\tBIO_printf(bio_err,"-prverify file verify a signature using private key in file\\n");\n\t\tBIO_printf(bio_err,"-keyform arg key file format (PEM or ENGINE)\\n");\n\t\tBIO_printf(bio_err,"-signature file signature to verify\\n");\n\t\tBIO_printf(bio_err,"-binary output in binary form\\n");\n#ifndef OPENSSL_NO_ENGINE\n\t\tBIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\\n");\n#endif\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm (default)\\n",\n\t\t\tLN_md5,LN_md5);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_md4,LN_md4);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_md2,LN_md2);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_sha1,LN_sha1);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_sha,LN_sha);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_mdc2,LN_mdc2);\n\t\tBIO_printf(bio_err,"-%3s to use the %s message digest algorithm\\n",\n\t\t\tLN_ripemd160,LN_ripemd160);\n\t\terr=1;\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_ENGINE\n e = setup_engine(bio_err, engine, 0);\n#endif\n\tin=BIO_new(BIO_s_file());\n\tbmd=BIO_new(BIO_f_md());\n\tif (debug)\n\t\t{\n\t\tBIO_set_callback(in,BIO_debug_callback);\n\t\tBIO_set_callback_arg(in,bio_err);\n\t\t}\n\tif ((in == NULL) || (bmd == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif(out_bin == -1) {\n\t\tif(keyfile) out_bin = 1;\n\t\telse out_bin = 0;\n\t}\n\tif(randfile)\n\t\tapp_RAND_load_file(randfile, bio_err, 0);\n\tif(outfile) {\n\t\tif(out_bin)\n\t\t\tout = BIO_new_file(outfile, "wb");\n\t\telse out = BIO_new_file(outfile, "w");\n\t} else {\n\t\tout = BIO_new_fp(stdout, BIO_NOCLOSE);\n#ifdef OPENSSL_SYS_VMS\n\t\t{\n\t\tBIO *tmpbio = BIO_new(BIO_f_linebuffer());\n\t\tout = BIO_push(tmpbio, out);\n\t\t}\n#endif\n\t}\n\tif(!out) {\n\t\tBIO_printf(bio_err, "Error opening output file %s\\n",\n\t\t\t\t\toutfile ? outfile : "(stdout)");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tif(keyfile)\n\t\t{\n\t\tif (want_pub)\n\t\t\tsigkey = load_pubkey(bio_err, keyfile, keyform, 0, NULL,\n\t\t\t\te, "key file");\n\t\telse\n\t\t\tsigkey = load_key(bio_err, keyfile, keyform, 0, NULL,\n\t\t\t\te, "key file");\n\t\tif (!sigkey)\n\t\t\t{\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif(sigfile && sigkey) {\n\t\tBIO *sigbio;\n\t\tsigbio = BIO_new_file(sigfile, "rb");\n\t\tsiglen = EVP_PKEY_size(sigkey);\n\t\tsigbuf = OPENSSL_malloc(siglen);\n\t\tif(!sigbio) {\n\t\t\tBIO_printf(bio_err, "Error opening signature file %s\\n",\n\t\t\t\t\t\t\t\tsigfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t\tsiglen = BIO_read(sigbio, sigbuf, siglen);\n\t\tBIO_free(sigbio);\n\t\tif(siglen <= 0) {\n\t\t\tBIO_printf(bio_err, "Error reading signature file %s\\n",\n\t\t\t\t\t\t\t\tsigfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t}\n\tBIO_set_md(bmd,md);\n\tinp=BIO_push(bmd,in);\n\tif (argc == 0)\n\t\t{\n\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\t\terr=do_fp(out, buf,inp,separator, out_bin, sigkey, sigbuf,\n\t\t\t siglen,"","(stdin)");\n\t\t}\n\telse\n\t\t{\n\t\tname=OBJ_nid2sn(md->type);\n\t\tfor (i=0; i<argc; i++)\n\t\t\t{\n\t\t\tchar *tmp,*tofree=NULL;\n\t\t\tint r;\n\t\t\tif (BIO_read_filename(in,argv[i]) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(argv[i]);\n\t\t\t\terr++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tif(!out_bin)\n\t\t\t\t{\n\t\t\t\ttmp=tofree=OPENSSL_malloc(strlen(name)+strlen(argv[i])+5);\n\t\t\t\tsprintf(tmp,"%s(%s)= ",name,argv[i]);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ttmp="";\n\t\t\tr=do_fp(out,buf,inp,separator,out_bin,sigkey,sigbuf,\n\t\t\t\tsiglen,tmp,argv[i]);\n\t\t\tif(r)\n\t\t\t err=r;\n\t\t\tif(tofree)\n\t\t\t\tOPENSSL_free(tofree);\n\t\t\t(void)BIO_reset(bmd);\n\t\t\t}\n\t\t}\nend:\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,BUFSIZE);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tif (in != NULL) BIO_free(in);\n\tBIO_free_all(out);\n\tEVP_PKEY_free(sigkey);\n\tif(sigbuf) OPENSSL_free(sigbuf);\n\tif (bmd != NULL) BIO_free(bmd);\n\tapps_shutdown();\n\tOPENSSL_EXIT(err);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'int BIO_printf (BIO *bio, const char *format, ...)\n\t{\n\tva_list args;\n\tint ret;\n\tva_start(args, format);\n\tret = BIO_vprintf(bio, format, args);\n\tva_end(args);\n\treturn(ret);\n\t}', 'void BIO_free_all(BIO *bio)\n\t{\n\tBIO *b;\n\tint ref;\n\twhile (bio != NULL)\n\t\t{\n\t\tb=bio;\n\t\tref=b->references;\n\t\tbio=bio->next_bio;\n\t\tBIO_free(b);\n\t\tif (ref > 1) break;\n\t\t}\n\t}']
36,151
0
https://github.com/openssl/openssl/blob/0bde1089f895718db2fe2637fda4a0c2ed6df904/crypto/lhash/lhash.c/#L282
void lh_doall_arg(LHASH *lh, void (*func)(), void *arg) { int i; LHASH_NODE *a,*n; for (i=lh->num_nodes-1; i>=0; i--) { a=lh->b[i]; while (a != NULL) { n=a->next; func(a->data,arg); a=n; } } }
['void ssl_update_cache(SSL *s,int mode)\n\t{\n\tint i;\n\tif (s->session->session_id_length == 0) return;\n\tif ((s->ctx->session_cache_mode & mode)\n\t\t&& (!s->hit)\n\t\t&& SSL_CTX_add_session(s->ctx,s->session)\n\t\t&& (s->ctx->new_session_cb != NULL))\n\t\t{\n\t\tCRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);\n\t\tif (!s->ctx->new_session_cb(s,s->session))\n\t\t\tSSL_SESSION_free(s->session);\n\t\t}\n\ti=s->ctx->session_cache_mode;\n\tif ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&\n\t\t((i & mode) == mode))\n\t\t{\n\t\tif ( (((mode & SSL_SESS_CACHE_CLIENT)\n\t\t\t?s->ctx->stats.sess_connect_good\n\t\t\t:s->ctx->stats.sess_accept_good) & 0xff) == 0xff)\n\t\t\t{\n\t\t\tSSL_CTX_flush_sessions(s->ctx,time(NULL));\n\t\t\t}\n\t\t}\n\t}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n\t{\n\tunsigned long i;\n\tTIMEOUT_PARAM tp;\n\ttp.ctx=s;\n\ttp.cache=s->sessions;\n\tif (tp.cache == NULL) return;\n\ttp.time=t;\n\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\ti=tp.cache->down_load;\n\ttp.cache->down_load=0;\n\tlh_doall_arg(tp.cache,(void (*)())timeout,&tp);\n\ttp.cache->down_load=i;\n\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t}', 'void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)\n\t{\n\tint i;\n\tLHASH_NODE *a,*n;\n\tfor (i=lh->num_nodes-1; i>=0; i--)\n\t\t{\n\t\ta=lh->b[i];\n\t\twhile (a != NULL)\n\t\t\t{\n\t\t\tn=a->next;\n\t\t\tfunc(a->data,arg);\n\t\t\ta=n;\n\t\t\t}\n\t\t}\n\t}']
36,152
1
https://github.com/libav/libav/blob/63e8d9760f23a4edf81e9ae58c4f6d3baa6ff4dd/libavcodec/mpegaudiodec.c/#L669
static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr) { register const MPA_INT *w, *w2, *p; int j; OUT_INT *samples2; #if CONFIG_FLOAT float sum, sum2; #elif FRAC_BITS <= 15 int sum, sum2; #else int64_t sum, sum2; #endif memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf)); samples2 = samples + 31 * incr; w = window; w2 = window + 31; sum = *dither_state; p = synth_buf + 16; SUM8(MACS, sum, w, p); p = synth_buf + 48; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); samples += incr; w++; for(j=1;j<16;j++) { sum2 = 0; p = synth_buf + 16 + j; SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); p = synth_buf + 48 - j; SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); *samples = round_sample(&sum); samples += incr; sum += sum2; *samples2 = round_sample(&sum); samples2 -= incr; w++; w2--; } p = synth_buf + 32; SUM8(MLSS, sum, w + 32, p); *samples = round_sample(&sum); *dither_state= sum; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int j;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}']
36,153
0
https://github.com/libav/libav/blob/fd7f59639c43f0ab6b83ad2c1ceccafc553d7845/libavformat/oggparsespeex.c/#L49
static int speex_header(AVFormatContext *s, int idx) { struct ogg *ogg = s->priv_data; struct ogg_stream *os = ogg->streams + idx; AVStream *st = s->streams[idx]; uint8_t *p = os->buf + os->pstart; if (os->psize < 80) return 1; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_SPEEX; st->codec->sample_rate = AV_RL32(p + 36); st->codec->channels = AV_RL32(p + 48); st->codec->extradata_size = os->psize; st->codec->extradata = av_malloc(st->codec->extradata_size); memcpy(st->codec->extradata, p, st->codec->extradata_size); st->time_base.num = 1; st->time_base.den = st->codec->sample_rate; return 0; }
['static int speex_header(AVFormatContext *s, int idx) {\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n AVStream *st = s->streams[idx];\n uint8_t *p = os->buf + os->pstart;\n if (os->psize < 80)\n return 1;\n st->codec->codec_type = CODEC_TYPE_AUDIO;\n st->codec->codec_id = CODEC_ID_SPEEX;\n st->codec->sample_rate = AV_RL32(p + 36);\n st->codec->channels = AV_RL32(p + 48);\n st->codec->extradata_size = os->psize;\n st->codec->extradata = av_malloc(st->codec->extradata_size);\n memcpy(st->codec->extradata, p, st->codec->extradata_size);\n st->time_base.num = 1;\n st->time_base.den = st->codec->sample_rate;\n return 0;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\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_POSIX_MEMALIGN)\n posix_memalign(&ptr,16,size);\n#elif defined (HAVE_MEMALIGN)\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
36,154
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L246
static inline void bitstream_skip(BitstreamContext *bc, unsigned n) { if (n <= bc->bits_left) skip_remaining(bc, n); else { n -= bc->bits_left; skip_remaining(bc, bc->bits_left); if (n >= 64) { unsigned skip = n / 8; n -= skip * 8; bc->ptr += skip; } refill_64(bc); if (n) skip_remaining(bc, n); } }
['static inline int get_ue_code(BitstreamContext *bc, int order)\n{\n if (order) {\n int ret = get_ue_golomb(bc) << order;\n return ret + bitstream_read(bc, order);\n }\n return get_ue_golomb(bc);\n}', 'static inline int get_ue_golomb(BitstreamContext *bc)\n{\n unsigned int buf;\n buf = bitstream_peek(bc, 32);\n if (buf >= (1 << 27)) {\n buf >>= 32 - 9;\n bitstream_skip(bc, ff_golomb_vlc_len[buf]);\n return ff_ue_golomb_vlc_code[buf];\n } else {\n int log = 2 * av_log2(buf) - 31;\n buf >>= log;\n buf--;\n bitstream_skip(bc, 32 - log);\n return buf;\n }\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}']
36,155
0
https://github.com/libav/libav/blob/c8b4a3999bc7f3732a537cdec6475918a65d6e78/libavfilter/avfilter.c/#L91
void avfilter_unref_buffer(AVFilterBufferRef *ref) { if (!ref) return; if (!(--ref->buf->refcount)) ref->buf->free(ref->buf); if (ref->extended_data != ref->data) av_freep(&ref->extended_data); av_free(ref->video); av_free(ref->audio); av_free(ref); }
['static void end_frame(AVFilterLink *inlink)\n{\n GradFunContext *gf = inlink->dst->priv;\n AVFilterBufferRef *inpic = inlink->cur_buf;\n AVFilterLink *outlink = inlink->dst->outputs[0];\n AVFilterBufferRef *outpic = outlink->out_buf;\n int p;\n for (p = 0; p < 4 && inpic->data[p]; p++) {\n int w = inlink->w;\n int h = inlink->h;\n int r = gf->radius;\n if (p) {\n w = gf->chroma_w;\n h = gf->chroma_h;\n r = gf->chroma_r;\n }\n if (FFMIN(w, h) > 2 * r)\n filter(gf, outpic->data[p], inpic->data[p], w, h, outpic->linesize[p], inpic->linesize[p], r);\n else if (outpic->data[p] != inpic->data[p])\n av_image_copy_plane(outpic->data[p], outpic->linesize[p], inpic->data[p], inpic->linesize[p], w, h);\n }\n avfilter_draw_slice(outlink, 0, inlink->h, 1);\n avfilter_end_frame(outlink);\n avfilter_unref_buffer(inpic);\n if (outpic != inpic)\n avfilter_unref_buffer(outpic);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n if (!ref)\n return;\n if (!(--ref->buf->refcount))\n ref->buf->free(ref->buf);\n if (ref->extended_data != ref->data)\n av_freep(&ref->extended_data);\n av_free(ref->video);\n av_free(ref->audio);\n av_free(ref);\n}']
36,156
0
https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/mpegaudiodec.c/#L701
static void dct32(INTFLOAT *out, const INTFLOAT *tab) { INTFLOAT tmp0, tmp1; INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 , val8 , val9 , val10, val11, val12, val13, val14, val15, val16, val17, val18, val19, val20, val21, val22, val23, val24, val25, val26, val27, val28, val29, val30, val31; BF0( 0, 31, COS0_0 , 1); BF0(15, 16, COS0_15, 5); BF( 0, 15, COS1_0 , 1); BF(16, 31,-COS1_0 , 1); BF0( 7, 24, COS0_7 , 1); BF0( 8, 23, COS0_8 , 1); BF( 7, 8, COS1_7 , 4); BF(23, 24,-COS1_7 , 4); BF( 0, 7, COS2_0 , 1); BF( 8, 15,-COS2_0 , 1); BF(16, 23, COS2_0 , 1); BF(24, 31,-COS2_0 , 1); BF0( 3, 28, COS0_3 , 1); BF0(12, 19, COS0_12, 2); BF( 3, 12, COS1_3 , 1); BF(19, 28,-COS1_3 , 1); BF0( 4, 27, COS0_4 , 1); BF0(11, 20, COS0_11, 2); BF( 4, 11, COS1_4 , 1); BF(20, 27,-COS1_4 , 1); BF( 3, 4, COS2_3 , 3); BF(11, 12,-COS2_3 , 3); BF(19, 20, COS2_3 , 3); BF(27, 28,-COS2_3 , 3); BF( 0, 3, COS3_0 , 1); BF( 4, 7,-COS3_0 , 1); BF( 8, 11, COS3_0 , 1); BF(12, 15,-COS3_0 , 1); BF(16, 19, COS3_0 , 1); BF(20, 23,-COS3_0 , 1); BF(24, 27, COS3_0 , 1); BF(28, 31,-COS3_0 , 1); BF0( 1, 30, COS0_1 , 1); BF0(14, 17, COS0_14, 3); BF( 1, 14, COS1_1 , 1); BF(17, 30,-COS1_1 , 1); BF0( 6, 25, COS0_6 , 1); BF0( 9, 22, COS0_9 , 1); BF( 6, 9, COS1_6 , 2); BF(22, 25,-COS1_6 , 2); BF( 1, 6, COS2_1 , 1); BF( 9, 14,-COS2_1 , 1); BF(17, 22, COS2_1 , 1); BF(25, 30,-COS2_1 , 1); BF0( 2, 29, COS0_2 , 1); BF0(13, 18, COS0_13, 3); BF( 2, 13, COS1_2 , 1); BF(18, 29,-COS1_2 , 1); BF0( 5, 26, COS0_5 , 1); BF0(10, 21, COS0_10, 1); BF( 5, 10, COS1_5 , 2); BF(21, 26,-COS1_5 , 2); BF( 2, 5, COS2_2 , 1); BF(10, 13,-COS2_2 , 1); BF(18, 21, COS2_2 , 1); BF(26, 29,-COS2_2 , 1); BF( 1, 2, COS3_1 , 2); BF( 5, 6,-COS3_1 , 2); BF( 9, 10, COS3_1 , 2); BF(13, 14,-COS3_1 , 2); BF(17, 18, COS3_1 , 2); BF(21, 22,-COS3_1 , 2); BF(25, 26, COS3_1 , 2); BF(29, 30,-COS3_1 , 2); BF1( 0, 1, 2, 3); BF2( 4, 5, 6, 7); BF1( 8, 9, 10, 11); BF2(12, 13, 14, 15); BF1(16, 17, 18, 19); BF2(20, 21, 22, 23); BF1(24, 25, 26, 27); BF2(28, 29, 30, 31); ADD( 8, 12); ADD(12, 10); ADD(10, 14); ADD(14, 9); ADD( 9, 13); ADD(13, 11); ADD(11, 15); out[ 0] = val0; out[16] = val1; out[ 8] = val2; out[24] = val3; out[ 4] = val4; out[20] = val5; out[12] = val6; out[28] = val7; out[ 2] = val8; out[18] = val9; out[10] = val10; out[26] = val11; out[ 6] = val12; out[22] = val13; out[14] = val14; out[30] = val15; ADD(24, 28); ADD(28, 26); ADD(26, 30); ADD(30, 25); ADD(25, 29); ADD(29, 27); ADD(27, 31); out[ 1] = val16 + val24; out[17] = val17 + val25; out[ 9] = val18 + val26; out[25] = val19 + val27; out[ 5] = val20 + val28; out[21] = val21 + val29; out[13] = val22 + val30; out[29] = val23 + val31; out[ 3] = val24 + val20; out[19] = val25 + val21; out[11] = val26 + val22; out[27] = val27 + val23; out[ 7] = val28 + val18; out[23] = val29 + val19; out[15] = val30 + val17; out[31] = val31; }
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void 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 dct32(INTFLOAT *out, const INTFLOAT *tab)\n{\n INTFLOAT tmp0, tmp1;\n INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,\n val8 , val9 , val10, val11, val12, val13, val14, val15,\n val16, val17, val18, val19, val20, val21, val22, val23,\n val24, val25, val26, val27, val28, val29, val30, val31;\n BF0( 0, 31, COS0_0 , 1);\n BF0(15, 16, COS0_15, 5);\n BF( 0, 15, COS1_0 , 1);\n BF(16, 31,-COS1_0 , 1);\n BF0( 7, 24, COS0_7 , 1);\n BF0( 8, 23, COS0_8 , 1);\n BF( 7, 8, COS1_7 , 4);\n BF(23, 24,-COS1_7 , 4);\n BF( 0, 7, COS2_0 , 1);\n BF( 8, 15,-COS2_0 , 1);\n BF(16, 23, COS2_0 , 1);\n BF(24, 31,-COS2_0 , 1);\n BF0( 3, 28, COS0_3 , 1);\n BF0(12, 19, COS0_12, 2);\n BF( 3, 12, COS1_3 , 1);\n BF(19, 28,-COS1_3 , 1);\n BF0( 4, 27, COS0_4 , 1);\n BF0(11, 20, COS0_11, 2);\n BF( 4, 11, COS1_4 , 1);\n BF(20, 27,-COS1_4 , 1);\n BF( 3, 4, COS2_3 , 3);\n BF(11, 12,-COS2_3 , 3);\n BF(19, 20, COS2_3 , 3);\n BF(27, 28,-COS2_3 , 3);\n BF( 0, 3, COS3_0 , 1);\n BF( 4, 7,-COS3_0 , 1);\n BF( 8, 11, COS3_0 , 1);\n BF(12, 15,-COS3_0 , 1);\n BF(16, 19, COS3_0 , 1);\n BF(20, 23,-COS3_0 , 1);\n BF(24, 27, COS3_0 , 1);\n BF(28, 31,-COS3_0 , 1);\n BF0( 1, 30, COS0_1 , 1);\n BF0(14, 17, COS0_14, 3);\n BF( 1, 14, COS1_1 , 1);\n BF(17, 30,-COS1_1 , 1);\n BF0( 6, 25, COS0_6 , 1);\n BF0( 9, 22, COS0_9 , 1);\n BF( 6, 9, COS1_6 , 2);\n BF(22, 25,-COS1_6 , 2);\n BF( 1, 6, COS2_1 , 1);\n BF( 9, 14,-COS2_1 , 1);\n BF(17, 22, COS2_1 , 1);\n BF(25, 30,-COS2_1 , 1);\n BF0( 2, 29, COS0_2 , 1);\n BF0(13, 18, COS0_13, 3);\n BF( 2, 13, COS1_2 , 1);\n BF(18, 29,-COS1_2 , 1);\n BF0( 5, 26, COS0_5 , 1);\n BF0(10, 21, COS0_10, 1);\n BF( 5, 10, COS1_5 , 2);\n BF(21, 26,-COS1_5 , 2);\n BF( 2, 5, COS2_2 , 1);\n BF(10, 13,-COS2_2 , 1);\n BF(18, 21, COS2_2 , 1);\n BF(26, 29,-COS2_2 , 1);\n BF( 1, 2, COS3_1 , 2);\n BF( 5, 6,-COS3_1 , 2);\n BF( 9, 10, COS3_1 , 2);\n BF(13, 14,-COS3_1 , 2);\n BF(17, 18, COS3_1 , 2);\n BF(21, 22,-COS3_1 , 2);\n BF(25, 26, COS3_1 , 2);\n BF(29, 30,-COS3_1 , 2);\n BF1( 0, 1, 2, 3);\n BF2( 4, 5, 6, 7);\n BF1( 8, 9, 10, 11);\n BF2(12, 13, 14, 15);\n BF1(16, 17, 18, 19);\n BF2(20, 21, 22, 23);\n BF1(24, 25, 26, 27);\n BF2(28, 29, 30, 31);\n ADD( 8, 12);\n ADD(12, 10);\n ADD(10, 14);\n ADD(14, 9);\n ADD( 9, 13);\n ADD(13, 11);\n ADD(11, 15);\n out[ 0] = val0;\n out[16] = val1;\n out[ 8] = val2;\n out[24] = val3;\n out[ 4] = val4;\n out[20] = val5;\n out[12] = val6;\n out[28] = val7;\n out[ 2] = val8;\n out[18] = val9;\n out[10] = val10;\n out[26] = val11;\n out[ 6] = val12;\n out[22] = val13;\n out[14] = val14;\n out[30] = val15;\n ADD(24, 28);\n ADD(28, 26);\n ADD(26, 30);\n ADD(30, 25);\n ADD(25, 29);\n ADD(29, 27);\n ADD(27, 31);\n out[ 1] = val16 + val24;\n out[17] = val17 + val25;\n out[ 9] = val18 + val26;\n out[25] = val19 + val27;\n out[ 5] = val20 + val28;\n out[21] = val21 + val29;\n out[13] = val22 + val30;\n out[29] = val23 + val31;\n out[ 3] = val24 + val20;\n out[19] = val25 + val21;\n out[11] = val26 + val22;\n out[27] = val27 + val23;\n out[ 7] = val28 + val18;\n out[23] = val29 + val19;\n out[15] = val30 + val17;\n out[31] = val31;\n}']
36,157
0
https://github.com/openssl/openssl/blob/49cd47eaababc8c57871b929080fc1357e2ad7b8/crypto/x509/x509_cmp.c/#L224
unsigned long X509_NAME_hash_old(X509_NAME *x) { EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); unsigned long ret = 0; unsigned char md[16]; if (md_ctx == NULL) return ret; i2d_X509_NAME(x, NULL); EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL) && EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length) && EVP_DigestFinal_ex(md_ctx, md, NULL)) ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) | ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L) ) & 0xffffffffL; EVP_MD_CTX_free(md_ctx); return ret; }
['unsigned long X509_NAME_hash_old(X509_NAME *x)\n{\n EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n unsigned long ret = 0;\n unsigned char md[16];\n if (md_ctx == NULL)\n return ret;\n i2d_X509_NAME(x, NULL);\n EVP_MD_CTX_set_flags(md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);\n if (EVP_DigestInit_ex(md_ctx, EVP_md5(), NULL)\n && EVP_DigestUpdate(md_ctx, x->bytes->data, x->bytes->length)\n && EVP_DigestFinal_ex(md_ctx, md, NULL))\n ret = (((unsigned long)md[0]) | ((unsigned long)md[1] << 8L) |\n ((unsigned long)md[2] << 16L) | ((unsigned long)md[3] << 24L)\n ) & 0xffffffffL;\n EVP_MD_CTX_free(md_ctx);\n return ret;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n 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}', 'IMPLEMENT_ASN1_FUNCTIONS(X509_NAME)', 'int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)\n{\n return asn1_item_flags_i2d(val, out, it, 0);\n}', 'static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,\n const ASN1_ITEM *it, int flags)\n{\n if (out && !*out) {\n unsigned char *p, *buf;\n int len;\n len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);\n if (len <= 0)\n return len;\n buf = OPENSSL_malloc(len);\n if (buf == NULL)\n return -1;\n p = buf;\n ASN1_item_ex_i2d(&val, &p, it, -1, flags);\n *out = buf;\n return len;\n }\n return ASN1_item_ex_i2d(&val, out, it, -1, flags);\n}', 'void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)\n{\n ctx->flags |= flags;\n}', 'const EVP_MD *EVP_md5(void)\n{\n return &md5_md;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
36,158
0
https://github.com/libav/libav/blob/641c7afe3c17334b81e3e2eef88f1751eb68f89f/libavcodec/rv34.c/#L239
static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc) { int coeffs[4]; coeffs[0] = modulo_three_table[code][0]; coeffs[1] = modulo_three_table[code][1]; coeffs[2] = modulo_three_table[code][2]; coeffs[3] = modulo_three_table[code][3]; decode_coeff(dst , coeffs[0], 3, gb, vlc); if(is_block2){ decode_coeff(dst+8, coeffs[1], 2, gb, vlc); decode_coeff(dst+1, coeffs[2], 2, gb, vlc); }else{ decode_coeff(dst+1, coeffs[1], 2, gb, vlc); decode_coeff(dst+8, coeffs[2], 2, gb, vlc); } decode_coeff(dst+9, coeffs[3], 2, gb, vlc); }
['static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types)\n{\n MpegEncContext *s = &r->s;\n GetBitContext *gb = &s->gb;\n int cbp, cbp2;\n int i, blknum, blkoff;\n DCTELEM block16[64];\n int luma_dc_quant;\n int dist;\n int mb_pos = s->mb_x + s->mb_y * s->mb_stride;\n memset(r->avail_cache, 0, sizeof(r->avail_cache));\n fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4);\n dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width;\n if(s->mb_x && dist)\n r->avail_cache[5] =\n r->avail_cache[9] = s->current_picture_ptr->f.mb_type[mb_pos - 1];\n if(dist >= s->mb_width)\n r->avail_cache[2] =\n r->avail_cache[3] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride];\n if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1)\n r->avail_cache[4] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride + 1];\n if(s->mb_x && dist > s->mb_width)\n r->avail_cache[1] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride - 1];\n s->qscale = r->si.quant;\n cbp = cbp2 = rv34_decode_mb_header(r, intra_types);\n r->cbp_luma [mb_pos] = cbp;\n r->cbp_chroma[mb_pos] = cbp >> 16;\n if(s->pict_type == AV_PICTURE_TYPE_I)\n r->deblock_coefs[mb_pos] = 0xFFFF;\n else\n r->deblock_coefs[mb_pos] = rv34_set_deblock_coef(r) | r->cbp_luma[mb_pos];\n s->current_picture_ptr->f.qscale_table[mb_pos] = s->qscale;\n if(cbp == -1)\n return -1;\n luma_dc_quant = r->block_type == RV34_MB_P_MIX16x16 ? r->luma_dc_quant_p[s->qscale] : r->luma_dc_quant_i[s->qscale];\n if(r->is16){\n memset(block16, 0, sizeof(block16));\n rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0);\n rv34_dequant4x4_16x16(block16, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]);\n r->rdsp.rv34_inv_transform_tab[1](block16);\n }\n for(i = 0; i < 16; i++, cbp >>= 1){\n if(!r->is16 && !(cbp & 1)) continue;\n blknum = ((i & 2) >> 1) + ((i & 8) >> 2);\n blkoff = ((i & 1) << 2) + ((i & 4) << 3);\n if(cbp & 1)\n rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->luma_vlc, 0);\n rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[s->qscale],rv34_qscale_tab[s->qscale]);\n if(r->is16)\n s->block[blknum][blkoff] = block16[(i & 3) | ((i & 0xC) << 1)];\n r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff);\n }\n if(r->block_type == RV34_MB_P_MIX16x16)\n r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1);\n for(; i < 24; i++, cbp >>= 1){\n if(!(cbp & 1)) continue;\n blknum = ((i & 4) >> 2) + 4;\n blkoff = ((i & 1) << 2) + ((i & 2) << 4);\n rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->chroma_vlc, 1);\n rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]);\n r->rdsp.rv34_inv_transform_tab[0](s->block[blknum] + blkoff);\n }\n if (IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos]))\n rv34_output_macroblock(r, intra_types, cbp2, r->is16);\n else\n rv34_apply_differences(r, cbp2);\n return 0;\n}', 'static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){\n uint8_t *p= (uint8_t*)vp;\n assert(size==1 || size==2 || size==4);\n assert(w<=4);\n w *= size;\n stride *= size;\n assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);\n assert((stride&(w-1))==0);\n if(w==2){\n const uint16_t v= size==4 ? val : val*0x0101;\n *(uint16_t*)(p + 0*stride)= v;\n if(h==1) return;\n *(uint16_t*)(p + 1*stride)= v;\n if(h==2) return;\n *(uint16_t*)(p + 2*stride)= v;\n *(uint16_t*)(p + 3*stride)= v;\n }else if(w==4){\n const uint32_t v= size==4 ? val : size==2 ? val*0x00010001 : val*0x01010101;\n *(uint32_t*)(p + 0*stride)= v;\n if(h==1) return;\n *(uint32_t*)(p + 1*stride)= v;\n if(h==2) return;\n *(uint32_t*)(p + 2*stride)= v;\n *(uint32_t*)(p + 3*stride)= v;\n }else if(w==8){\n#if HAVE_FAST_64BIT\n const uint64_t v= size==2 ? val*0x0001000100010001ULL : val*0x0100000001ULL;\n *(uint64_t*)(p + 0*stride)= v;\n if(h==1) return;\n *(uint64_t*)(p + 1*stride)= v;\n if(h==2) return;\n *(uint64_t*)(p + 2*stride)= v;\n *(uint64_t*)(p + 3*stride)= v;\n }else if(w==16){\n const uint64_t v= val*0x0100000001ULL;\n *(uint64_t*)(p + 0+0*stride)= v;\n *(uint64_t*)(p + 8+0*stride)= v;\n *(uint64_t*)(p + 0+1*stride)= v;\n *(uint64_t*)(p + 8+1*stride)= v;\n if(h==2) return;\n *(uint64_t*)(p + 0+2*stride)= v;\n *(uint64_t*)(p + 8+2*stride)= v;\n *(uint64_t*)(p + 0+3*stride)= v;\n *(uint64_t*)(p + 8+3*stride)= v;\n#else\n const uint32_t v= size==2 ? val*0x00010001 : val;\n *(uint32_t*)(p + 0+0*stride)= v;\n *(uint32_t*)(p + 4+0*stride)= v;\n if(h==1) return;\n *(uint32_t*)(p + 0+1*stride)= v;\n *(uint32_t*)(p + 4+1*stride)= v;\n if(h==2) return;\n *(uint32_t*)(p + 0+2*stride)= v;\n *(uint32_t*)(p + 4+2*stride)= v;\n *(uint32_t*)(p + 0+3*stride)= v;\n *(uint32_t*)(p + 4+3*stride)= v;\n }else if(w==16){\n *(uint32_t*)(p + 0+0*stride)= val;\n *(uint32_t*)(p + 4+0*stride)= val;\n *(uint32_t*)(p + 8+0*stride)= val;\n *(uint32_t*)(p +12+0*stride)= val;\n *(uint32_t*)(p + 0+1*stride)= val;\n *(uint32_t*)(p + 4+1*stride)= val;\n *(uint32_t*)(p + 8+1*stride)= val;\n *(uint32_t*)(p +12+1*stride)= val;\n if(h==2) return;\n *(uint32_t*)(p + 0+2*stride)= val;\n *(uint32_t*)(p + 4+2*stride)= val;\n *(uint32_t*)(p + 8+2*stride)= val;\n *(uint32_t*)(p +12+2*stride)= val;\n *(uint32_t*)(p + 0+3*stride)= val;\n *(uint32_t*)(p + 4+3*stride)= val;\n *(uint32_t*)(p + 8+3*stride)= val;\n *(uint32_t*)(p +12+3*stride)= val;\n#endif\n }else\n assert(0);\n assert(h==4);\n}', 'static inline void rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc)\n{\n int code, pattern;\n code = get_vlc2(gb, rvlc->first_pattern[fc].table, 9, 2);\n pattern = code & 0x7;\n code >>= 3;\n decode_subblock(dst, code, 0, gb, &rvlc->coefficient);\n if(pattern & 4){\n code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2);\n decode_subblock(dst + 2, code, 0, gb, &rvlc->coefficient);\n }\n if(pattern & 2){\n code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2);\n decode_subblock(dst + 8*2, code, 1, gb, &rvlc->coefficient);\n }\n if(pattern & 1){\n code = get_vlc2(gb, rvlc->third_pattern[sc].table, 9, 2);\n decode_subblock(dst + 8*2+2, code, 0, gb, &rvlc->coefficient);\n }\n}', 'static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],\n int bits, int max_depth)\n{\n int code;\n OPEN_READER(re, s);\n UPDATE_CACHE(re, s);\n GET_VLC(code, re, s, table, bits, max_depth);\n CLOSE_READER(re, s);\n return code;\n}', 'static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc)\n{\n int coeffs[4];\n coeffs[0] = modulo_three_table[code][0];\n coeffs[1] = modulo_three_table[code][1];\n coeffs[2] = modulo_three_table[code][2];\n coeffs[3] = modulo_three_table[code][3];\n decode_coeff(dst , coeffs[0], 3, gb, vlc);\n if(is_block2){\n decode_coeff(dst+8, coeffs[1], 2, gb, vlc);\n decode_coeff(dst+1, coeffs[2], 2, gb, vlc);\n }else{\n decode_coeff(dst+1, coeffs[1], 2, gb, vlc);\n decode_coeff(dst+8, coeffs[2], 2, gb, vlc);\n }\n decode_coeff(dst+9, coeffs[3], 2, gb, vlc);\n}']
36,159
0
https://github.com/libav/libav/blob/f73467192558cadff476c98c73767ec04e7212c3/ffserver.c/#L3956
static void load_module(const char *filename) { void *dll; void (*init_func)(void); dll = dlopen(filename, RTLD_NOW); if (!dll) { fprintf(stderr, "Could not load module '%s' - %s\n", filename, dlerror()); return; } init_func = dlsym(dll, "ffserver_module_init"); if (!init_func) { fprintf(stderr, "%s: init function 'ffserver_module_init()' not found\n", filename); dlclose(dll); } init_func(); }
['static void load_module(const char *filename)\n{\n void *dll;\n void (*init_func)(void);\n dll = dlopen(filename, RTLD_NOW);\n if (!dll) {\n fprintf(stderr, "Could not load module \'%s\' - %s\\n",\n filename, dlerror());\n return;\n }\n init_func = dlsym(dll, "ffserver_module_init");\n if (!init_func) {\n fprintf(stderr,\n "%s: init function \'ffserver_module_init()\' not found\\n",\n filename);\n dlclose(dll);\n }\n init_func();\n}']
36,160
0
https://gitlab.com/libtiff/libtiff/blob/b69a1998bedfabc32cd541408bffdef05bd01e45/tools/tiffcp.c/#L1062
DECLAREcpFunc(cpContig2SeparateByRow) { tsize_t scanlinesizein = TIFFScanlineSize(in); tsize_t scanlinesizeout = TIFFScanlineSize(out); tdata_t inbuf; tdata_t outbuf; register uint8 *inp, *outp; register uint32 n; uint32 row; tsample_t s; inbuf = _TIFFmalloc(scanlinesizein); outbuf = _TIFFmalloc(scanlinesizeout); if (!inbuf || !outbuf) return 0; _TIFFmemset(inbuf, 0, scanlinesizein); _TIFFmemset(outbuf, 0, scanlinesizeout); for (s = 0; s < spp; s++) { for (row = 0; row < imagelength; row++) { if (TIFFReadScanline(in, inbuf, row, 0) < 0 && !ignore) { TIFFError(TIFFFileName(in), "Error, can't read scanline %lu", (unsigned long) row); goto bad; } inp = ((uint8*)inbuf) + s; outp = (uint8*)outbuf; for (n = imagewidth; n-- > 0;) { *outp++ = *inp; inp += spp; } if (TIFFWriteScanline(out, outbuf, row, s) < 0) { TIFFError(TIFFFileName(out), "Error, can't write scanline %lu", (unsigned long) row); goto bad; } } } if (inbuf) _TIFFfree(inbuf); if (outbuf) _TIFFfree(outbuf); return 1; bad: if (inbuf) _TIFFfree(inbuf); if (outbuf) _TIFFfree(outbuf); return 0; }
['DECLAREcpFunc(cpContig2SeparateByRow)\n{\n\ttsize_t scanlinesizein = TIFFScanlineSize(in);\n\ttsize_t scanlinesizeout = TIFFScanlineSize(out);\n\ttdata_t inbuf;\n\ttdata_t outbuf;\n\tregister uint8 *inp, *outp;\n\tregister uint32 n;\n\tuint32 row;\n\ttsample_t s;\n\tinbuf = _TIFFmalloc(scanlinesizein);\n\toutbuf = _TIFFmalloc(scanlinesizeout);\n\tif (!inbuf || !outbuf)\n\t\treturn 0;\n\t_TIFFmemset(inbuf, 0, scanlinesizein);\n\t_TIFFmemset(outbuf, 0, scanlinesizeout);\n\tfor (s = 0; s < spp; s++) {\n\t\tfor (row = 0; row < imagelength; row++) {\n\t\t\tif (TIFFReadScanline(in, inbuf, row, 0) < 0\n\t\t\t && !ignore) {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t "Error, can\'t read scanline %lu",\n\t\t\t\t (unsigned long) row);\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tinp = ((uint8*)inbuf) + s;\n\t\t\toutp = (uint8*)outbuf;\n\t\t\tfor (n = imagewidth; n-- > 0;) {\n\t\t\t\t*outp++ = *inp;\n\t\t\t\tinp += spp;\n\t\t\t}\n\t\t\tif (TIFFWriteScanline(out, outbuf, row, s) < 0) {\n\t\t\t\tTIFFError(TIFFFileName(out),\n\t\t\t\t "Error, can\'t write scanline %lu",\n\t\t\t\t (unsigned long) row);\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\t}\n\t}\n\tif (inbuf) _TIFFfree(inbuf);\n\tif (outbuf) _TIFFfree(outbuf);\n\treturn 1;\nbad:\n\tif (inbuf) _TIFFfree(inbuf);\n\tif (outbuf) _TIFFfree(outbuf);\n\treturn 0;\n}', 'tmsize_t\nTIFFScanlineSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFScanlineSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFScanlineSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer arithmetic overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n\treturn (malloc((size_t) s));\n}']
36,161
0
https://github.com/libav/libav/blob/a1c1c7801918c46da5525cfddb99f3467c522b02/libavcodec/rv40.c/#L554
static void rv40_loop_filter(RV34DecContext *r, int row) { MpegEncContext *s = &r->s; int mb_pos, mb_x; int i, j, k; uint8_t *Y, *C; int alpha, beta, betaY, betaC; int q; int mbtype[4]; int mb_strong[4]; int clip[4]; int cbp[4]; int uvcbp[4][2]; int mvmasks[4]; mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int mbtype = s->current_picture_ptr->mb_type[mb_pos]; if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) r->cbp_luma [mb_pos] = 0xFFFF; if(IS_INTRA(mbtype)) r->cbp_chroma[mb_pos] = 0xFF; } mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int y_h_deblock, y_v_deblock; int c_v_deblock[2], c_h_deblock[2]; int clip_left; int avail[4]; int y_to_deblock, c_to_deblock[2]; q = s->current_picture_ptr->qscale_table[mb_pos]; alpha = rv40_alpha_tab[q]; beta = rv40_beta_tab [q]; betaY = betaC = beta * 3; if(s->width * s->height <= 176*144) betaY += beta; avail[0] = 1; avail[1] = row; avail[2] = mb_x; avail[3] = row < s->mb_height - 1; for(i = 0; i < 4; i++){ if(avail[i]){ int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; mvmasks[i] = r->deblock_coefs[pos]; mbtype [i] = s->current_picture_ptr->mb_type[pos]; cbp [i] = r->cbp_luma[pos]; uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; uvcbp[i][1] = r->cbp_chroma[pos] >> 4; }else{ mvmasks[i] = 0; mbtype [i] = mbtype[0]; cbp [i] = 0; uvcbp[i][0] = uvcbp[i][1] = 0; } mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]); clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q]; } y_to_deblock = cbp[POS_CUR] | (cbp[POS_BOTTOM] << 16) | mvmasks[POS_CUR] | (mvmasks[POS_BOTTOM] << 16); y_h_deblock = y_to_deblock | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW) | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12); y_v_deblock = y_to_deblock | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL) | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3); if(!mb_x) y_v_deblock &= ~MASK_Y_LEFT_COL; if(!row) y_h_deblock &= ~MASK_Y_TOP_ROW; if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])) y_h_deblock &= ~(MASK_Y_TOP_ROW << 16); for(i = 0; i < 2; i++){ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i]; c_v_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL) | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1); c_h_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2) | (uvcbp[POS_CUR][i] << 2); if(!mb_x) c_v_deblock[i] &= ~MASK_C_LEFT_COL; if(!row) c_h_deblock[i] &= ~MASK_C_TOP_ROW; if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]) c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4); } for(j = 0; j < 16; j += 4){ Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize; for(i = 0; i < 4; i++, Y += 4){ int ij = i + j; int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; int dither = j ? ij : i*4; if(y_h_deblock & (MASK_BOTTOM << ij)){ rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither, y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, clip_cur, alpha, beta, betaY, 0, 0); } if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; else clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 0); } if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ rv40_h_loop_filter(Y, s->linesize, dither, clip_cur, (cbp[POS_TOP] | mvmasks[POS_TOP]) & (MASK_TOP << i) ? clip[POS_TOP] : 0, alpha, beta, betaY, 0, 1); } if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 1); } } } for(k = 0; k < 2; k++){ for(j = 0; j < 2; j++){ C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; for(i = 0; i < 2; i++, C += 4){ int ij = i + j*2; int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8, clip_bot, clip_cur, alpha, beta, betaC, 1, 0); } if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; else clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 0); } if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; rv40_h_loop_filter(C, s->uvlinesize, i*8, clip_cur, clip_top, alpha, beta, betaC, 1, 1); } if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 1); } } } } } }
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = cbp[POS_CUR]\n | (cbp[POS_BOTTOM] << 16)\n | mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur,\n alpha, beta, betaY, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_h_loop_filter(Y, s->linesize, dither,\n clip_cur,\n (cbp[POS_TOP] | mvmasks[POS_TOP]) & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_h_loop_filter(C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1);\n }\n }\n }\n }\n }\n}']
36,162
0
https://github.com/openssl/openssl/blob/85bcf27cccd8f5f569886479ad96a0c33444404c/crypto/bn/bn_gf2m.c/#L600
int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) { BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp; int ret = 0; bn_check_top(a); bn_check_top(p); BN_CTX_start(ctx); if ((b = BN_CTX_get(ctx))==NULL) goto err; if ((c = BN_CTX_get(ctx))==NULL) goto err; if ((u = BN_CTX_get(ctx))==NULL) goto err; if ((v = BN_CTX_get(ctx))==NULL) goto err; if (!BN_GF2m_mod(u, a, p)) goto err; if (BN_is_zero(u)) goto err; if (!BN_copy(v, p)) goto err; #if 0 if (!BN_one(b)) goto err; while (1) { while (!BN_is_odd(u)) { if (BN_is_zero(u)) goto err; if (!BN_rshift1(u, u)) goto err; if (BN_is_odd(b)) { if (!BN_GF2m_add(b, b, p)) goto err; } if (!BN_rshift1(b, b)) goto err; } if (BN_abs_is_word(u, 1)) break; if (BN_num_bits(u) < BN_num_bits(v)) { tmp = u; u = v; v = tmp; tmp = b; b = c; c = tmp; } if (!BN_GF2m_add(u, u, v)) goto err; if (!BN_GF2m_add(b, b, c)) goto err; } #else { int i, ubits = BN_num_bits(u), vbits = BN_num_bits(v), top = p->top; BN_ULONG *udp,*bdp,*vdp,*cdp; bn_wexpand(u,top); udp = u->d; for (i=u->top;i<top;i++) udp[i] = 0; u->top = top; bn_wexpand(b,top); bdp = b->d; bdp[0] = 1; for (i=1;i<top;i++) bdp[i] = 0; b->top = top; bn_wexpand(c,top); cdp = c->d; for (i=0;i<top;i++) cdp[i] = 0; c->top = top; vdp = v->d; while (1) { while (ubits && !(udp[0]&1)) { BN_ULONG u0,u1,b0,b1,mask; u0 = udp[0]; b0 = bdp[0]; mask = (BN_ULONG)0-(b0&1); b0 ^= p->d[0]&mask; for (i=0;i<top-1;i++) { u1 = udp[i+1]; udp[i] = ((u0>>1)|(u1<<(BN_BITS2-1)))&BN_MASK2; u0 = u1; b1 = bdp[i+1]^(p->d[i+1]&mask); bdp[i] = ((b0>>1)|(b1<<(BN_BITS2-1)))&BN_MASK2; b0 = b1; } udp[i] = u0>>1; bdp[i] = b0>>1; ubits--; } if (ubits<=BN_BITS2 && udp[0]==1) break; if (ubits<vbits) { i = ubits; ubits = vbits; vbits = i; tmp = u; u = v; v = tmp; tmp = b; b = c; c = tmp; udp = vdp; vdp = v->d; bdp = cdp; cdp = c->d; } for(i=0;i<top;i++) { udp[i] ^= vdp[i]; bdp[i] ^= cdp[i]; } if (ubits==vbits) { BN_ULONG ul; int utop = (ubits-1)/BN_BITS2; while ((ul=udp[utop])==0 && utop) utop--; ubits = utop*BN_BITS2 + BN_num_bits_word(ul); } } bn_correct_top(b); } #endif if (!BN_copy(r, b)) goto err; bn_check_top(r); ret = 1; err: #ifdef BN_DEBUG bn_correct_top(c); bn_correct_top(u); bn_correct_top(v); #endif BN_CTX_end(ctx); return ret; }
['int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tBIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;\n\tint ret = 0;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tBN_CTX_start(ctx);\n\tif ((b = BN_CTX_get(ctx))==NULL) goto err;\n\tif ((c = BN_CTX_get(ctx))==NULL) goto err;\n\tif ((u = BN_CTX_get(ctx))==NULL) goto err;\n\tif ((v = BN_CTX_get(ctx))==NULL) goto err;\n\tif (!BN_GF2m_mod(u, a, p)) goto err;\n\tif (BN_is_zero(u)) goto err;\n\tif (!BN_copy(v, p)) goto err;\n#if 0\n\tif (!BN_one(b)) goto err;\n\twhile (1)\n\t\t{\n\t\twhile (!BN_is_odd(u))\n\t\t\t{\n\t\t\tif (BN_is_zero(u)) goto err;\n\t\t\tif (!BN_rshift1(u, u)) goto err;\n\t\t\tif (BN_is_odd(b))\n\t\t\t\t{\n\t\t\t\tif (!BN_GF2m_add(b, b, p)) goto err;\n\t\t\t\t}\n\t\t\tif (!BN_rshift1(b, b)) goto err;\n\t\t\t}\n\t\tif (BN_abs_is_word(u, 1)) break;\n\t\tif (BN_num_bits(u) < BN_num_bits(v))\n\t\t\t{\n\t\t\ttmp = u; u = v; v = tmp;\n\t\t\ttmp = b; b = c; c = tmp;\n\t\t\t}\n\t\tif (!BN_GF2m_add(u, u, v)) goto err;\n\t\tif (!BN_GF2m_add(b, b, c)) goto err;\n\t\t}\n#else\n\t{\n\tint i,\tubits = BN_num_bits(u),\n\t\tvbits = BN_num_bits(v),\n\t\ttop = p->top;\n\tBN_ULONG *udp,*bdp,*vdp,*cdp;\n\tbn_wexpand(u,top);\tudp = u->d;\n\t\t\t\tfor (i=u->top;i<top;i++) udp[i] = 0;\n\t\t\t\tu->top = top;\n\tbn_wexpand(b,top);\tbdp = b->d;\n\t\t\t\tbdp[0] = 1;\n\t\t\t\tfor (i=1;i<top;i++) bdp[i] = 0;\n\t\t\t\tb->top = top;\n\tbn_wexpand(c,top);\tcdp = c->d;\n\t\t\t\tfor (i=0;i<top;i++) cdp[i] = 0;\n\t\t\t\tc->top = top;\n\tvdp = v->d;\n\twhile (1)\n\t\t{\n\t\twhile (ubits && !(udp[0]&1))\n\t\t\t{\n\t\t\tBN_ULONG u0,u1,b0,b1,mask;\n\t\t\tu0 = udp[0];\n\t\t\tb0 = bdp[0];\n\t\t\tmask = (BN_ULONG)0-(b0&1);\n\t\t\tb0 ^= p->d[0]&mask;\n\t\t\tfor (i=0;i<top-1;i++)\n\t\t\t\t{\n\t\t\t\tu1 = udp[i+1];\n\t\t\t\tudp[i] = ((u0>>1)|(u1<<(BN_BITS2-1)))&BN_MASK2;\n\t\t\t\tu0 = u1;\n\t\t\t\tb1 = bdp[i+1]^(p->d[i+1]&mask);\n\t\t\t\tbdp[i] = ((b0>>1)|(b1<<(BN_BITS2-1)))&BN_MASK2;\n\t\t\t\tb0 = b1;\n\t\t\t\t}\n\t\t\tudp[i] = u0>>1;\n\t\t\tbdp[i] = b0>>1;\n\t\t\tubits--;\n\t\t\t}\n\t\tif (ubits<=BN_BITS2 && udp[0]==1) break;\n\t\tif (ubits<vbits)\n\t\t\t{\n\t\t\ti = ubits; ubits = vbits; vbits = i;\n\t\t\ttmp = u; u = v; v = tmp;\n\t\t\ttmp = b; b = c; c = tmp;\n\t\t\tudp = vdp; vdp = v->d;\n\t\t\tbdp = cdp; cdp = c->d;\n\t\t\t}\n\t\tfor(i=0;i<top;i++)\n\t\t\t{\n\t\t\tudp[i] ^= vdp[i];\n\t\t\tbdp[i] ^= cdp[i];\n\t\t\t}\n\t\tif (ubits==vbits)\n\t\t\t{\n\t\t\tBN_ULONG ul;\n\t\t\tint utop = (ubits-1)/BN_BITS2;\n\t\t\twhile ((ul=udp[utop])==0 && utop) utop--;\n\t\t\tubits = utop*BN_BITS2 + BN_num_bits_word(ul);\n\t\t\t}\n\t\t}\n\tbn_correct_top(b);\n\t}\n#endif\n\tif (!BN_copy(r, b)) goto err;\n\tbn_check_top(r);\n\tret = 1;\nerr:\n#ifdef BN_DEBUG\n bn_correct_top(c);\n bn_correct_top(u);\n bn_correct_top(v);\n#endif\n \tBN_CTX_end(ctx);\n\treturn ret;\n\t}']
36,163
0
https://github.com/openssl/openssl/blob/5ea564f154ebe8bda2a0e091a312e2058edf437f/crypto/bn/bn_shift.c/#L112
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a, *b, *order, *tmp_1, *tmp_2;\n const BIGNUM *p = group->field;\n BN_CTX *new_ctx = NULL;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL) {\n ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT,\n ERR_R_MALLOC_FAILURE);\n goto err;\n }\n }\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n tmp_1 = BN_CTX_get(ctx);\n tmp_2 = BN_CTX_get(ctx);\n order = BN_CTX_get(ctx);\n if (order == NULL)\n goto err;\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, a, group->a, ctx))\n goto err;\n if (!group->meth->field_decode(group, b, group->b, ctx))\n goto err;\n } else {\n if (!BN_copy(a, group->a))\n goto err;\n if (!BN_copy(b, group->b))\n goto err;\n }\n if (BN_is_zero(a)) {\n if (BN_is_zero(b))\n goto err;\n } else if (!BN_is_zero(b)) {\n if (!BN_mod_sqr(tmp_1, a, p, ctx))\n goto err;\n if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx))\n goto err;\n if (!BN_lshift(tmp_1, tmp_2, 2))\n goto err;\n if (!BN_mod_sqr(tmp_2, b, p, ctx))\n goto err;\n if (!BN_mul_word(tmp_2, 27))\n goto err;\n if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx))\n goto err;\n if (BN_is_zero(a))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_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 memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'int BN_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}']
36,164
0
https://github.com/openssl/openssl/blob/85bcf27cccd8f5f569886479ad96a0c33444404c/crypto/bn/bn_mul.c/#L100
BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int cl, int dl) { BN_ULONG c, t; assert(cl >= 0); c = bn_sub_words(r, a, b, cl); if (dl == 0) return c; r += cl; a += cl; b += cl; if (dl < 0) { for (;;) { t = b[0]; r[0] = (0-t-c)&BN_MASK2; if (t != 0) c=1; if (++dl >= 0) break; t = b[1]; r[1] = (0-t-c)&BN_MASK2; if (t != 0) c=1; if (++dl >= 0) break; t = b[2]; r[2] = (0-t-c)&BN_MASK2; if (t != 0) c=1; if (++dl >= 0) break; t = b[3]; r[3] = (0-t-c)&BN_MASK2; if (t != 0) c=1; if (++dl >= 0) break; b += 4; r += 4; } } else { int save_dl = dl; while(c) { t = a[0]; r[0] = (t-c)&BN_MASK2; if (t != 0) c=0; if (--dl <= 0) break; t = a[1]; r[1] = (t-c)&BN_MASK2; if (t != 0) c=0; if (--dl <= 0) break; t = a[2]; r[2] = (t-c)&BN_MASK2; if (t != 0) c=0; if (--dl <= 0) break; t = a[3]; r[3] = (t-c)&BN_MASK2; if (t != 0) c=0; if (--dl <= 0) break; save_dl = dl; a += 4; r += 4; } if (dl > 0) { if (save_dl > dl) { switch (save_dl - dl) { case 1: r[1] = a[1]; if (--dl <= 0) break; case 2: r[2] = a[2]; if (--dl <= 0) break; case 3: r[3] = a[3]; if (--dl <= 0) break; } a += 4; r += 4; } } if (dl > 0) { for(;;) { r[0] = a[0]; if (--dl <= 0) break; r[1] = a[1]; if (--dl <= 0) break; r[2] = a[2]; if (--dl <= 0) break; r[3] = a[3]; if (--dl <= 0) break; a += 4; r += 4; } } } return c; }
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n\tconst BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n\tBN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2;\n\tint r_is_one=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *a_mod_m;\n\tBIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a1);\n\tbn_check_top(p1);\n\tbn_check_top(a2);\n\tbn_check_top(p2);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP2_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits1=BN_num_bits(p1);\n\tbits2=BN_num_bits(p2);\n\tif ((bits1 == 0) && (bits2 == 0))\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tbits=(bits1 > bits2)?bits1:bits2;\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval1[0] = BN_CTX_get(ctx);\n\tval2[0] = BN_CTX_get(ctx);\n\tif(!d || !r || !val1[0] || !val2[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow1 = BN_window_bits_for_exponent_size(bits1);\n\twindow2 = BN_window_bits_for_exponent_size(bits2);\n\tif (a1->neg || BN_ucmp(a1,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(val1[0],a1,m,ctx))\n\t\t\tgoto err;\n\t\ta_mod_m = val1[0];\n\t\t}\n\telse\n\t\ta_mod_m = a1;\n\tif (BN_is_zero(a_mod_m))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val1[0],a_mod_m,mont,ctx)) goto err;\n\tif (window1 > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val1[0],val1[0],mont,ctx)) goto err;\n\t\tj=1<<(window1-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val1[i],val1[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (a2->neg || BN_ucmp(a2,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(val2[0],a2,m,ctx))\n\t\t\tgoto err;\n\t\ta_mod_m = val2[0];\n\t\t}\n\telse\n\t\ta_mod_m = a2;\n\tif (BN_is_zero(a_mod_m))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val2[0],a_mod_m,mont,ctx)) goto err;\n\tif (window2 > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val2[0],val2[0],mont,ctx)) goto err;\n\t\tj=1<<(window2-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val2[i],val2[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tr_is_one=1;\n\twvalue1=0;\n\twvalue2=0;\n\twpos1=0;\n\twpos2=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (b=bits-1; b>=0; b--)\n\t\t{\n\t\tif (!r_is_one)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (!wvalue1)\n\t\t\tif (BN_is_bit_set(p1, b))\n\t\t\t\t{\n\t\t\t\ti = b-window1+1;\n\t\t\t\twhile (!BN_is_bit_set(p1, i))\n\t\t\t\t\ti++;\n\t\t\t\twpos1 = i;\n\t\t\t\twvalue1 = 1;\n\t\t\t\tfor (i = b-1; i >= wpos1; i--)\n\t\t\t\t\t{\n\t\t\t\t\twvalue1 <<= 1;\n\t\t\t\t\tif (BN_is_bit_set(p1, i))\n\t\t\t\t\t\twvalue1++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tif (!wvalue2)\n\t\t\tif (BN_is_bit_set(p2, b))\n\t\t\t\t{\n\t\t\t\ti = b-window2+1;\n\t\t\t\twhile (!BN_is_bit_set(p2, i))\n\t\t\t\t\ti++;\n\t\t\t\twpos2 = i;\n\t\t\t\twvalue2 = 1;\n\t\t\t\tfor (i = b-1; i >= wpos2; i--)\n\t\t\t\t\t{\n\t\t\t\t\twvalue2 <<= 1;\n\t\t\t\t\tif (BN_is_bit_set(p2, i))\n\t\t\t\t\t\twvalue2++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tif (wvalue1 && b == wpos1)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,val1[wvalue1>>1],mont,ctx))\n\t\t\t\tgoto err;\n\t\t\twvalue1 = 0;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\tif (wvalue2 && b == wpos2)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,val2[wvalue2>>1],mont,ctx))\n\t\t\t\tgoto err;\n\t\t\twvalue2 = 0;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx))\n\t\tgoto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'const BIGNUM *BN_value_one(void)\n\t{\n\tstatic const BN_ULONG data_one=1L;\n\tstatic const BIGNUM const_one={(BN_ULONG *)&data_one,1,1,0,BN_FLG_STATIC_DATA};\n\treturn(&const_one);\n\t}', 'int BN_to_montgomery(BIGNUM *r,const BIGNUM *a,\tBN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\treturn BN_mod_mul_montgomery(r,a,&(mont->RR),mont,ctx);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n\tint num = mont->N.top;\n\tif (num>1 && a->top==num && b->top==num)\n\t\t{\n\t\tif (bn_wexpand(r,num) == NULL) return(0);\n\t\tif (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))\n\t\t\t{\n\t\t\tr->neg = a->neg^b->neg;\n\t\t\tr->top = num;\n\t\t\tbn_correct_top(r);\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n#ifdef MONT_WORD\n\tif (!BN_from_montgomery_word(r,tmp,mont)) goto err;\n#else\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n#endif\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (t == NULL)\n\t\t\t\tgoto err;\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n\t int tna, int tnb, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tint c1,c2,neg;\n\tBN_ULONG ln,lo,*p;\n\tif (n < 8)\n\t\t{\n\t\tbn_mul_normal(r,a,n+tna,b,n+tnb);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_part_words(a,&(a[n]),tna,n-tna);\n\tc2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n);\n\tneg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tbreak;\n\tcase -3:\n\tcase -2:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\tcase 2:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\tcase 4:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tbreak;\n\t\t}\n# if 0\n\tif (n == 4)\n\t\t{\n\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba4(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# endif\n\tif (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]),tna,&(b[n]),tnb);\n\t\tmemset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb));\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,0,0,p);\n\t\tbn_mul_recursive(r,a,b,n,0,0,p);\n\t\ti=n/2;\n\t\tif (tna > tnb)\n\t\t\tj = tna - i;\n\t\telse\n\t\t\tj = tnb - i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\ti,tna-i,tnb-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\ti,tna-i,tnb-i,p);\n\t\t\t\tmemset(&(r[n2+tna+tnb]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tna-tnb));\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 (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n\t\t\t\t&& tnb < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\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 < tna || i < tnb)\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\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tna || i == tnb)\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,tna-i,tnb-i,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\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}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tint n,i;\n\tn = cl-1;\n\tif (dl < 0)\n\t\t{\n\t\tfor (i=dl; i<0; i++)\n\t\t\t{\n\t\t\tif (b[n-i] != 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif (dl > 0)\n\t\t{\n\t\tfor (i=dl; i>0; i--)\n\t\t\t{\n\t\t\tif (a[n+i] != 0)\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\treturn bn_cmp_words(a,b,cl);\n\t}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n\tconst BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tBN_ULONG c, t;\n\tassert(cl >= 0);\n\tc = bn_sub_words(r, a, b, cl);\n\tif (dl == 0)\n\t\treturn c;\n\tr += cl;\n\ta += cl;\n\tb += cl;\n\tif (dl < 0)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt = b[0];\n\t\t\tr[0] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[1];\n\t\t\tr[1] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[2];\n\t\t\tr[2] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[3];\n\t\t\tr[3] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tb += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tint save_dl = dl;\n\t\twhile(c)\n\t\t\t{\n\t\t\tt = a[0];\n\t\t\tr[0] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[1];\n\t\t\tr[1] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[2];\n\t\t\tr[2] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[3];\n\t\t\tr[3] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tsave_dl = dl;\n\t\t\ta += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n\t\t\tif (save_dl > dl)\n\t\t\t\t{\n\t\t\t\tswitch (save_dl - dl)\n\t\t\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tr[1] = a[1];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 2:\n\t\t\t\t\tr[2] = a[2];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 3:\n\t\t\t\t\tr[3] = a[3];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\t\t}\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n\t\t\tfor(;;)\n\t\t\t\t{\n\t\t\t\tr[0] = a[0];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[1] = a[1];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[2] = a[2];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[3] = a[3];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn c;\n\t}']
36,165
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L237
static inline void skip_remaining(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE bc->bits >>= n; #else bc->bits <<= n; #endif bc->bits_left -= n; }
['static int read_header(ShortenContext *s)\n{\n int i, ret;\n int maxnlpc = 0;\n if (bitstream_read(&s->bc, 32) != AV_RB32("ajkg")) {\n av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic \'ajkg\'\\n");\n return AVERROR_INVALIDDATA;\n }\n s->lpcqoffset = 0;\n s->blocksize = DEFAULT_BLOCK_SIZE;\n s->nmean = -1;\n s->version = bitstream_read(&s->bc, 8);\n s->internal_ftype = get_uint(s, TYPESIZE);\n s->channels = get_uint(s, CHANSIZE);\n if (!s->channels) {\n av_log(s->avctx, AV_LOG_ERROR, "No channels reported\\n");\n return AVERROR_INVALIDDATA;\n }\n if (s->channels > MAX_CHANNELS) {\n av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\\n", s->channels);\n s->channels = 0;\n return AVERROR_INVALIDDATA;\n }\n s->avctx->channels = s->channels;\n if (s->version > 0) {\n int skip_bytes;\n unsigned blocksize;\n blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));\n if (!blocksize || blocksize > MAX_BLOCKSIZE) {\n av_log(s->avctx, AV_LOG_ERROR,\n "invalid or unsupported block size: %d\\n",\n blocksize);\n return AVERROR(EINVAL);\n }\n s->blocksize = blocksize;\n maxnlpc = get_uint(s, LPCQSIZE);\n s->nmean = get_uint(s, 0);\n skip_bytes = get_uint(s, NSKIPSIZE);\n for (i = 0; i < skip_bytes; i++)\n bitstream_skip(&s->bc, 8);\n }\n s->nwrap = FFMAX(NWRAP, maxnlpc);\n if ((ret = allocate_buffers(s)) < 0)\n return ret;\n if ((ret = init_offset(s)) < 0)\n return ret;\n if (s->version > 1)\n s->lpcqoffset = V2LPCQOFFSET;\n if (get_ur_golomb_shorten(&s->bc, FNSIZE) != FN_VERBATIM) {\n av_log(s->avctx, AV_LOG_ERROR,\n "missing verbatim section at beginning of stream\\n");\n return AVERROR_INVALIDDATA;\n }\n s->header_size = get_ur_golomb_shorten(&s->bc, VERBATIM_CKSIZE_SIZE);\n if (s->header_size >= OUT_BUFFER_SIZE ||\n s->header_size < CANONICAL_HEADER_SIZE) {\n av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\\n",\n s->header_size);\n return AVERROR_INVALIDDATA;\n }\n for (i = 0; i < s->header_size; i++)\n s->header[i] = (char)get_ur_golomb_shorten(&s->bc, VERBATIM_BYTE_SIZE);\n if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)\n return ret;\n s->cur_chan = 0;\n s->bitshift = 0;\n s->got_header = 1;\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline unsigned int get_uint(ShortenContext *s, int k)\n{\n if (s->version != 0)\n k = get_ur_golomb_shorten(&s->bc, ULONGSIZE);\n return get_ur_golomb_shorten(&s->bc, k);\n}', 'static inline unsigned int get_ur_golomb_shorten(BitstreamContext *bc, int k)\n{\n return get_ur_golomb_jpegls(bc, k, INT_MAX, 0);\n}', 'static inline int get_ur_golomb_jpegls(BitstreamContext *bc, int k, int limit,\n int esc_len)\n{\n unsigned int buf;\n int log;\n buf = bitstream_peek(bc, 32);\n log = av_log2(buf);\n if (log - k >= 1 && 32 - log < limit) {\n buf >>= log - k;\n buf += (30 - log) << k;\n bitstream_skip(bc, 32 + k - log);\n return buf;\n } else {\n int i;\n for (i = 0; i < limit && bitstream_peek(bc, 1) == 0 && bitstream_bits_left(bc) > 0; i++)\n bitstream_skip(bc, 1);\n bitstream_skip(bc, 1);\n if (i < limit - 1) {\n if (k) {\n buf = bitstream_read(bc, k);\n } else {\n buf = 0;\n }\n return buf + (i << k);\n } else if (i == limit - 1) {\n buf = bitstream_read(bc, esc_len);\n return buf + 1;\n } else\n return -1;\n }\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
36,166
0
https://github.com/openssl/openssl/blob/38d1b3cc0271008b8bd130a2c4b442775b028a08/crypto/bn/bn_shift.c/#L110
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['static EVP_PKEY *b2i_dss(const unsigned char **in,\n unsigned int bitlen, int ispub)\n{\n const unsigned char *p = *in;\n EVP_PKEY *ret = NULL;\n DSA *dsa = NULL;\n BN_CTX *ctx = NULL;\n unsigned int nbyte;\n BIGNUM *pbn = NULL, *qbn = NULL, *gbn = NULL, *priv_key = NULL;\n BIGNUM *pub_key = NULL;\n nbyte = (bitlen + 7) >> 3;\n dsa = DSA_new();\n ret = EVP_PKEY_new();\n if (dsa == NULL || ret == NULL)\n goto memerr;\n if (!read_lebn(&p, nbyte, &pbn))\n goto memerr;\n if (!read_lebn(&p, 20, &qbn))\n goto memerr;\n if (!read_lebn(&p, nbyte, &gbn))\n goto memerr;\n if (ispub) {\n if (!read_lebn(&p, nbyte, &pub_key))\n goto memerr;\n } else {\n if (!read_lebn(&p, 20, &priv_key))\n goto memerr;\n pub_key = BN_new();\n if (pub_key == NULL)\n goto memerr;\n if ((ctx = BN_CTX_new()) == NULL)\n goto memerr;\n if (!BN_mod_exp(pub_key, gbn, priv_key, pbn, ctx))\n goto memerr;\n BN_CTX_free(ctx);\n }\n if (!DSA_set0_pqg(dsa, pbn, qbn, gbn))\n goto memerr;\n pbn = qbn = gbn = NULL;\n if (!DSA_set0_key(dsa, pub_key, priv_key))\n goto memerr;\n EVP_PKEY_set1_DSA(ret, dsa);\n DSA_free(dsa);\n *in = p;\n return ret;\n memerr:\n PEMerr(PEM_F_B2I_DSS, ERR_R_MALLOC_FAILURE);\n DSA_free(dsa);\n BN_free(pbn);\n BN_free(qbn);\n BN_free(gbn);\n BN_free(pub_key);\n BN_free(priv_key);\n EVP_PKEY_free(ret);\n BN_CTX_free(ctx);\n return NULL;\n}', 'static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r)\n{\n *r = BN_lebin2bn(*in, nbyte, NULL);\n if (*r == NULL)\n return 0;\n *in += nbyte;\n return 1;\n}', 'BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return (NULL);\n bn_check_top(ret);\n s += len;\n for ( ; len > 0 && s[-1] == 0; s--, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n s--;\n l = (l << 8L) | *s;\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!d || !r || !val[0])\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
36,167
1
https://github.com/openssl/openssl/blob/3aecef76973dbea037ec4e1ceba7ec1bd3fb683a/crypto/objects/obj_dat.c/#L467
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) { int i,idx=0,n=0,len,nid; unsigned long l; unsigned char *p; const char *s; char tbuf[32]; if (buf_len <= 0) return(0); if ((a == NULL) || (a->data == NULL)) { buf[0]='\0'; return(0); } if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) { len=a->length; p=a->data; idx=0; l=0; while (idx < a->length) { l|=(p[idx]&0x7f); if (!(p[idx] & 0x80)) break; l<<=7L; idx++; } idx++; i=(int)(l/40); if (i > 2) i=2; l-=(long)(i*40); sprintf(tbuf,"%d.%lu",i,l); i=strlen(tbuf); strncpy(buf,tbuf,buf_len); buf_len-=i; buf+=i; n+=i; l=0; for (; idx<len; idx++) { l|=p[idx]&0x7f; if (!(p[idx] & 0x80)) { sprintf(tbuf,".%lu",l); i=strlen(tbuf); if (buf_len > 0) strncpy(buf,tbuf,buf_len); buf_len-=i; buf+=i; n+=i; l=0; } l<<=7L; } } else { s=OBJ_nid2ln(nid); if (s == NULL) s=OBJ_nid2sn(nid); strncpy(buf,s,buf_len); n=strlen(s); } buf[buf_len-1]='\0'; return(n); }
['int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent)\n{\n\tchar oidstr[80], first;\n\tint i;\n\tif(!aux) return 1;\n\tif(aux->trust) {\n\t\tfirst = 1;\n\t\tBIO_printf(out, "%*sTrusted Uses:\\n%*s",\n\t\t\t\t\t\tindent, "", indent + 2, "");\n\t\tfor(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) {\n\t\t\tif(!first) BIO_puts(out, ", ");\n\t\t\telse first = 0;\n\t\t\tOBJ_obj2txt(oidstr, 80,\n\t\t\t\tsk_ASN1_OBJECT_value(aux->trust, i), 0);\n\t\t\tBIO_puts(out, oidstr);\n\t\t}\n\t\tBIO_puts(out, "\\n");\n\t} else BIO_printf(out, "%*sNo Trusted Uses.\\n", indent, "");\n\tif(aux->reject) {\n\t\tfirst = 1;\n\t\tBIO_printf(out, "%*sRejected Uses:\\n%*s",\n\t\t\t\t\t\tindent, "", indent + 2, "");\n\t\tfor(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) {\n\t\t\tif(!first) BIO_puts(out, ", ");\n\t\t\telse first = 0;\n\t\t\tOBJ_obj2txt(oidstr, 80,\n\t\t\t\tsk_ASN1_OBJECT_value(aux->reject, i), 0);\n\t\t\tBIO_puts(out, oidstr);\n\t\t}\n\t\tBIO_puts(out, "\\n");\n\t} else BIO_printf(out, "%*sNo Rejected Uses.\\n", indent, "");\n\tif(aux->alias) BIO_printf(out, "%*sAlias: %s\\n", indent, "",\n\t\t\t\t\t\t\taux->alias->data);\n\tif(aux->keyid) {\n\t\tBIO_printf(out, "%*sKey Id: ", indent, "");\n\t\tfor(i = 0; i < aux->keyid->length; i++)\n\t\t\tBIO_printf(out, "%s%02X",\n\t\t\t\ti ? ":" : "",\n\t\t\t\taux->keyid->data[i]);\n\t\tBIO_write(out,"\\n",1);\n\t}\n\treturn 1;\n}', 'int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n\tint i,idx=0,n=0,len,nid;\n\tunsigned long l;\n\tunsigned char *p;\n\tconst char *s;\n\tchar tbuf[32];\n\tif (buf_len <= 0) return(0);\n\tif ((a == NULL) || (a->data == NULL)) {\n\t\tbuf[0]=\'\\0\';\n\t\treturn(0);\n\t}\n\tif (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {\n\t\tlen=a->length;\n\t\tp=a->data;\n\t\tidx=0;\n\t\tl=0;\n\t\twhile (idx < a->length) {\n\t\t\tl|=(p[idx]&0x7f);\n\t\t\tif (!(p[idx] & 0x80)) break;\n\t\t\tl<<=7L;\n\t\t\tidx++;\n\t\t}\n\t\tidx++;\n\t\ti=(int)(l/40);\n\t\tif (i > 2) i=2;\n\t\tl-=(long)(i*40);\n\t\tsprintf(tbuf,"%d.%lu",i,l);\n\t\ti=strlen(tbuf);\n\t\tstrncpy(buf,tbuf,buf_len);\n\t\tbuf_len-=i;\n\t\tbuf+=i;\n\t\tn+=i;\n\t\tl=0;\n\t\tfor (; idx<len; idx++) {\n\t\t\tl|=p[idx]&0x7f;\n\t\t\tif (!(p[idx] & 0x80)) {\n\t\t\t\tsprintf(tbuf,".%lu",l);\n\t\t\t\ti=strlen(tbuf);\n\t\t\t\tif (buf_len > 0)\n\t\t\t\t\tstrncpy(buf,tbuf,buf_len);\n\t\t\t\tbuf_len-=i;\n\t\t\t\tbuf+=i;\n\t\t\t\tn+=i;\n\t\t\t\tl=0;\n\t\t\t}\n\t\t\tl<<=7L;\n\t\t}\n\t} else {\n\t\ts=OBJ_nid2ln(nid);\n\t\tif (s == NULL)\n\t\t\ts=OBJ_nid2sn(nid);\n\t\tstrncpy(buf,s,buf_len);\n\t\tn=strlen(s);\n\t}\n\tbuf[buf_len-1]=\'\\0\';\n\treturn(n);\n}']
36,168
0
https://github.com/openssl/openssl/blob/b2e54eb834e2d5a79d03f12a818d68f82c0e3d13/crypto/err/err.c/#L757
int ERR_pop_to_mark(void) { ERR_STATE *es; es = ERR_get_state(); while (es->bottom != es->top && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) { err_clear(es, es->top); es->top -= 1; if (es->top == -1) es->top = ERR_NUM_ERRORS - 1; } if (es->bottom == es->top) return 0; es->err_flags[es->top] &= ~ERR_FLAG_MARK; return 1; }
['int ERR_pop_to_mark(void)\n{\n ERR_STATE *es;\n es = ERR_get_state();\n while (es->bottom != es->top\n && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) {\n err_clear(es, es->top);\n es->top -= 1;\n if (es->top == -1)\n es->top = ERR_NUM_ERRORS - 1;\n }\n if (es->bottom == es->top)\n return 0;\n es->err_flags[es->top] &= ~ERR_FLAG_MARK;\n return 1;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
36,169
0
https://github.com/libav/libav/blob/67ce33162aa93bee1a5f9e8d6f00060329fa67da/libavcodec/ffv1.c/#L501
static void write_quant_table(RangeCoder *c, int16_t *quant_table){ int last=0; int i; uint8_t state[CONTEXT_SIZE]; memset(state, 128, sizeof(state)); for(i=1; i<128 ; i++){ if(quant_table[i] != quant_table[i-1]){ put_symbol(c, state, i-last-1, 0); last= i; } } put_symbol(c, state, i-last-1, 0); }
['static void write_header(FFV1Context *f){\n uint8_t state[CONTEXT_SIZE];\n int i;\n RangeCoder * const c= &f->c;\n memset(state, 128, sizeof(state));\n put_symbol(c, state, f->version, 0);\n put_symbol(c, state, f->avctx->coder_type, 0);\n put_symbol(c, state, f->colorspace, 0);\n put_rac(c, state, 1);\n put_symbol(c, state, f->chroma_h_shift, 0);\n put_symbol(c, state, f->chroma_v_shift, 0);\n put_rac(c, state, 0);\n for(i=0; i<5; i++)\n write_quant_table(c, f->quant_table[i]);\n}', 'static void write_quant_table(RangeCoder *c, int16_t *quant_table){\n int last=0;\n int i;\n uint8_t state[CONTEXT_SIZE];\n memset(state, 128, sizeof(state));\n for(i=1; i<128 ; i++){\n if(quant_table[i] != quant_table[i-1]){\n put_symbol(c, state, i-last-1, 0);\n last= i;\n }\n }\n put_symbol(c, state, i-last-1, 0);\n}']
36,170
0
https://github.com/openssl/openssl/blob/9829b5ab52cb5f1891fc48262503b7eec32351b3/crypto/pem/pvkfmt.c/#L761
static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel, pem_password_cb *cb, void *u) { int outlen = 24, pklen; unsigned char *p, *salt = NULL; EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new(); if (enclevel) outlen += PVK_SALTLEN; pklen = do_i2b(NULL, pk, 0); if (pklen < 0) return -1; outlen += pklen; if (!out) return outlen; if (*out) p = *out; else { p = OPENSSL_malloc(outlen); if (p == NULL) { PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE); return -1; } *out = p; } write_ledword(&p, MS_PVKMAGIC); write_ledword(&p, 0); if (EVP_PKEY_id(pk) == EVP_PKEY_DSA) write_ledword(&p, MS_KEYTYPE_SIGN); else write_ledword(&p, MS_KEYTYPE_KEYX); write_ledword(&p, enclevel ? 1 : 0); write_ledword(&p, enclevel ? PVK_SALTLEN : 0); write_ledword(&p, pklen); if (enclevel) { if (RAND_bytes(p, PVK_SALTLEN) <= 0) goto error; salt = p; p += PVK_SALTLEN; } do_i2b(&p, pk, 0); if (enclevel == 0) return outlen; else { char psbuf[PEM_BUFSIZE]; unsigned char keybuf[20]; int enctmplen, inlen; if (cb) inlen = cb(psbuf, PEM_BUFSIZE, 1, u); else inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u); if (inlen <= 0) { PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ); goto error; } if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN, (unsigned char *)psbuf, inlen)) goto error; if (enclevel == 1) memset(keybuf + 5, 0, 11); p = salt + PVK_SALTLEN + 8; if (!EVP_EncryptInit_ex(cctx, EVP_rc4(), NULL, keybuf, NULL)) goto error; OPENSSL_cleanse(keybuf, 20); if (!EVP_DecryptUpdate(cctx, p, &enctmplen, p, pklen - 8)) goto error; if (!EVP_DecryptFinal_ex(cctx, p + enctmplen, &enctmplen)) goto error; } EVP_CIPHER_CTX_free(cctx); return outlen; error: EVP_CIPHER_CTX_free(cctx); return -1; }
['static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,\n pem_password_cb *cb, void *u)\n{\n int outlen = 24, pklen;\n unsigned char *p, *salt = NULL;\n EVP_CIPHER_CTX *cctx = EVP_CIPHER_CTX_new();\n if (enclevel)\n outlen += PVK_SALTLEN;\n pklen = do_i2b(NULL, pk, 0);\n if (pklen < 0)\n return -1;\n outlen += pklen;\n if (!out)\n return outlen;\n if (*out)\n p = *out;\n else {\n p = OPENSSL_malloc(outlen);\n if (p == NULL) {\n PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n *out = p;\n }\n write_ledword(&p, MS_PVKMAGIC);\n write_ledword(&p, 0);\n if (EVP_PKEY_id(pk) == EVP_PKEY_DSA)\n write_ledword(&p, MS_KEYTYPE_SIGN);\n else\n write_ledword(&p, MS_KEYTYPE_KEYX);\n write_ledword(&p, enclevel ? 1 : 0);\n write_ledword(&p, enclevel ? PVK_SALTLEN : 0);\n write_ledword(&p, pklen);\n if (enclevel) {\n if (RAND_bytes(p, PVK_SALTLEN) <= 0)\n goto error;\n salt = p;\n p += PVK_SALTLEN;\n }\n do_i2b(&p, pk, 0);\n if (enclevel == 0)\n return outlen;\n else {\n char psbuf[PEM_BUFSIZE];\n unsigned char keybuf[20];\n int enctmplen, inlen;\n if (cb)\n inlen = cb(psbuf, PEM_BUFSIZE, 1, u);\n else\n inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u);\n if (inlen <= 0) {\n PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ);\n goto error;\n }\n if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,\n (unsigned char *)psbuf, inlen))\n goto error;\n if (enclevel == 1)\n memset(keybuf + 5, 0, 11);\n p = salt + PVK_SALTLEN + 8;\n if (!EVP_EncryptInit_ex(cctx, EVP_rc4(), NULL, keybuf, NULL))\n goto error;\n OPENSSL_cleanse(keybuf, 20);\n if (!EVP_DecryptUpdate(cctx, p, &enctmplen, p, pklen - 8))\n goto error;\n if (!EVP_DecryptFinal_ex(cctx, p + enctmplen, &enctmplen))\n goto error;\n }\n EVP_CIPHER_CTX_free(cctx);\n return outlen;\n error:\n EVP_CIPHER_CTX_free(cctx);\n return -1;\n}', 'EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_CIPHER_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}']
36,171
0
https://github.com/openssl/openssl/blob/84c15db551ce1d167b901a3bde2b21880b084384/crypto/bn/bn_mont.c/#L193
int BN_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont, BN_CTX *ctx) { #ifdef BN_RECURSION_MONT if (mont->use_word) #endif { BIGNUM *n,*r; BN_ULONG *ap,*np,*rp,n0,v,*nrp; int al,nl,max,i,x,ri; int retn=0; r= &(ctx->bn[ctx->tos]); if (!BN_copy(r,a)) goto err1; n= &(mont->N); ap=a->d; al=ri=mont->ri/BN_BITS2; nl=n->top; if ((al == 0) || (nl == 0)) { r->top=0; return(1); } max=(nl+al+1); if (bn_wexpand(r,max) == NULL) goto err1; if (bn_wexpand(ret,max) == NULL) goto err1; r->neg=a->neg^n->neg; np=n->d; rp=r->d; nrp= &(r->d[nl]); #if 1 for (i=r->top; i<max; i++) r->d[i]=0; #else memset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG)); #endif r->top=max; n0=mont->n0; #ifdef BN_COUNT printf("word BN_from_montgomery %d * %d\n",nl,nl); #endif for (i=0; i<nl; i++) { v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2); nrp++; rp++; if (((nrp[-1]+=v)&BN_MASK2) >= v) continue; else { if (((++nrp[0])&BN_MASK2) != 0) continue; if (((++nrp[1])&BN_MASK2) != 0) continue; for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ; } } bn_fix_top(r); #if 0 BN_rshift(ret,r,mont->ri); #else x=ri; rp=ret->d; ap= &(r->d[x]); if (r->top < x) al=0; else al=r->top-x; ret->top=al; al-=4; for (i=0; i<al; i+=4) { BN_ULONG t1,t2,t3,t4; t1=ap[i+0]; t2=ap[i+1]; t3=ap[i+2]; t4=ap[i+3]; rp[i+0]=t1; rp[i+1]=t2; rp[i+2]=t3; rp[i+3]=t4; } al+=4; for (; i<al; i++) rp[i]=ap[i]; #endif if (BN_ucmp(ret, &(mont->N)) >= 0) { BN_usub(ret,ret,&(mont->N)); } retn=1; err1: return(retn); } #ifdef BN_RECURSION_MONT else { BIGNUM *t1,*t2,*t3; int j,i; #ifdef BN_COUNT printf("number BN_from_montgomery\n"); #endif t1= &(ctx->bn[ctx->tos]); t2= &(ctx->bn[ctx->tos+1]); t3= &(ctx->bn[ctx->tos+2]); i=mont->Ni.top; bn_wexpand(ret,i); bn_wexpand(t1,i*4); bn_wexpand(t2,i*2); bn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d); BN_zero(t3); BN_set_bit(t3,mont->N.top*BN_BITS2); bn_sub_words(t3->d,t3->d,a->d,i); bn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d); if (a->top > i) { j=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i)); if (j) bn_sub_words(ret->d,ret->d,mont->N.d,i); } ret->top=i; bn_fix_top(ret); if (a->d[0]) BN_add_word(ret,1); else { for (i=1; i<mont->N.top-1; i++) { if (a->d[i]) { BN_add_word(ret,1); break; } } } if (BN_ucmp(ret,&(mont->N)) >= 0) BN_usub(ret,ret,&(mont->N)); return(1); } #endif }
['int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,\n\t BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;\n\tint start=1,ts=0,x,y;\n\tBIGNUM *d,*aa1,*aa2,*r;\n\tBIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a1);\n\tbn_check_top(p1);\n\tbn_check_top(a2);\n\tbn_check_top(p2);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits1=BN_num_bits(p1);\n\tbits2=BN_num_bits(p2);\n\tif ((bits1 == 0) && (bits2 == 0))\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tbits=(bits1 > bits2)?bits1:bits2;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&(val[0][0]));\n\tBN_init(&(val[1][1]));\n\tBN_init(&(val[0][1]));\n\tBN_init(&(val[1][0]));\n\tts=1;\n\tif (BN_ucmp(a1,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[1][0]),a1,m,ctx);\n\t\taa1= &(val[1][0]);\n\t\t}\n\telse\n\t\taa1=a1;\n\tif (BN_ucmp(a2,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0][1]),a2,m,ctx);\n\t\taa2= &(val[0][1]);\n\t\t}\n\telse\n\t\taa2=a2;\n\tif (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;\n\tif (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(&(val[1][1]),\n\t\t&(val[1][0]),&(val[0][1]),mont,ctx))\n\t\tgoto err;\n#if 0\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits > 250)\n\t\twindow=5;\n\telse if (bits >= 120)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n#else\n\twindow=EXP2_TABLE_BITS;\n#endif\n\tk=1<<window;\n\tfor (x=0; x<k; x++)\n\t\t{\n\t\tif (x >= 2)\n\t\t\t{\n\t\t\tBN_init(&(val[x][0]));\n\t\t\tBN_init(&(val[x][1]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][0]),\n\t\t\t\t&(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][1]),\n\t\t\t\t&(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;\n\t\t\t}\n\t\tfor (y=2; y<k; y++)\n\t\t\t{\n\t\t\tBN_init(&(val[x][y]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][y]),\n\t\t\t\t&(val[x][y-1]),&(val[0][1]),mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tts=k;\n\tstart=1;\n\txvalue=0;\n\tyvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\txvalue=BN_is_bit_set(p1,wstart);\n\t\tyvalue=BN_is_bit_set(p2,wstart);\n\t\tif (!(xvalue || yvalue))\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\twstart--;\n\t\t\tif (wstart < 0) break;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\txvalue+=xvalue;\n\t\t\txvalue|=BN_is_bit_set(p1,wstart-i);\n\t\t\tyvalue+=yvalue;\n\t\t\tyvalue|=BN_is_bit_set(p2,wstart-i);\n\t\t\t}\n\t\tif (!start)\n\t\t\tfor (j=0; j<i; j++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (xvalue || yvalue)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),\n\t\t\t\tmont,ctx)) goto err;\n\t\t\t}\n\t\twstart-=i;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\t{\n\t\tfor (j=0; j<ts; j++)\n\t\t\t{\n\t\t\tBN_clear_free(&(val[i][j]));\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, 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_from_montgomery(BIGNUM *ret, BIGNUM *a, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n#ifdef BN_RECURSION_MONT\n\tif (mont->use_word)\n#endif\n\t\t{\n\t\tBIGNUM *n,*r;\n\t\tBN_ULONG *ap,*np,*rp,n0,v,*nrp;\n\t\tint al,nl,max,i,x,ri;\n\t\tint retn=0;\n\t\tr= &(ctx->bn[ctx->tos]);\n\t\tif (!BN_copy(r,a)) goto err1;\n\t\tn= &(mont->N);\n\t\tap=a->d;\n\t\tal=ri=mont->ri/BN_BITS2;\n\t\tnl=n->top;\n\t\tif ((al == 0) || (nl == 0)) { r->top=0; return(1); }\n\t\tmax=(nl+al+1);\n\t\tif (bn_wexpand(r,max) == NULL) goto err1;\n\t\tif (bn_wexpand(ret,max) == NULL) goto err1;\n\t\tr->neg=a->neg^n->neg;\n\t\tnp=n->d;\n\t\trp=r->d;\n\t\tnrp= &(r->d[nl]);\n#if 1\n\t\tfor (i=r->top; i<max; i++)\n\t\t\tr->d[i]=0;\n#else\n\t\tmemset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));\n#endif\n\t\tr->top=max;\n\t\tn0=mont->n0;\n#ifdef BN_COUNT\nprintf("word BN_from_montgomery %d * %d\\n",nl,nl);\n#endif\n\t\tfor (i=0; i<nl; i++)\n\t\t\t{\n\t\t\tv=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);\n\t\t\tnrp++;\n\t\t\trp++;\n\t\t\tif (((nrp[-1]+=v)&BN_MASK2) >= v)\n\t\t\t\tcontinue;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (((++nrp[0])&BN_MASK2) != 0) continue;\n\t\t\t\tif (((++nrp[1])&BN_MASK2) != 0) continue;\n\t\t\t\tfor (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;\n\t\t\t\t}\n\t\t\t}\n\t\tbn_fix_top(r);\n#if 0\n\t\tBN_rshift(ret,r,mont->ri);\n#else\n\t\tx=ri;\n\t\trp=ret->d;\n\t\tap= &(r->d[x]);\n\t\tif (r->top < x)\n\t\t\tal=0;\n\t\telse\n\t\t\tal=r->top-x;\n\t\tret->top=al;\n\t\tal-=4;\n\t\tfor (i=0; i<al; i+=4)\n\t\t\t{\n\t\t\tBN_ULONG t1,t2,t3,t4;\n\t\t\tt1=ap[i+0];\n\t\t\tt2=ap[i+1];\n\t\t\tt3=ap[i+2];\n\t\t\tt4=ap[i+3];\n\t\t\trp[i+0]=t1;\n\t\t\trp[i+1]=t2;\n\t\t\trp[i+2]=t3;\n\t\t\trp[i+3]=t4;\n\t\t\t}\n\t\tal+=4;\n\t\tfor (; i<al; i++)\n\t\t\trp[i]=ap[i];\n#endif\n\t\tif (BN_ucmp(ret, &(mont->N)) >= 0)\n\t\t\t{\n\t\t\tBN_usub(ret,ret,&(mont->N));\n\t\t\t}\n\t\tretn=1;\nerr1:\n\t\treturn(retn);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tBIGNUM *t1,*t2,*t3;\n\t\tint j,i;\n#ifdef BN_COUNT\nprintf("number BN_from_montgomery\\n");\n#endif\n\t\tt1= &(ctx->bn[ctx->tos]);\n\t\tt2= &(ctx->bn[ctx->tos+1]);\n\t\tt3= &(ctx->bn[ctx->tos+2]);\n\t\ti=mont->Ni.top;\n\t\tbn_wexpand(ret,i);\n\t\tbn_wexpand(t1,i*4);\n\t\tbn_wexpand(t2,i*2);\n\t\tbn_mul_low_recursive(t2->d,a->d,mont->Ni.d,i,t1->d);\n\t\tBN_zero(t3);\n\t\tBN_set_bit(t3,mont->N.top*BN_BITS2);\n\t\tbn_sub_words(t3->d,t3->d,a->d,i);\n\t\tbn_mul_high(ret->d,t2->d,mont->N.d,t3->d,i,t1->d);\n\t\tif (a->top > i)\n\t\t\t{\n\t\t\tj=(int)(bn_add_words(ret->d,ret->d,&(a->d[i]),i));\n\t\t\tif (j)\n\t\t\t\tbn_sub_words(ret->d,ret->d,mont->N.d,i);\n\t\t\t}\n\t\tret->top=i;\n\t\tbn_fix_top(ret);\n\t\tif (a->d[0])\n\t\t\tBN_add_word(ret,1);\n\t\telse\n\t\t\t{\n\t\t\tfor (i=1; i<mont->N.top-1; i++)\n\t\t\t\t{\n\t\t\t\tif (a->d[i])\n\t\t\t\t\t{\n\t\t\t\t\tBN_add_word(ret,1);\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif (BN_ucmp(ret,&(mont->N)) >= 0)\n\t\t\tBN_usub(ret,ret,&(mont->N));\n\t\treturn(1);\n\t\t}\n#endif\n\t}']
36,172
0
https://github.com/libav/libav/blob/ab492ca2ab105aeb24d955f3f03756bdb3139ee1/libavcodec/golomb.h/#L275
static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){ unsigned int buf; int log; OPEN_READER(re, gb); UPDATE_CACHE(re, gb); buf=GET_CACHE(re, gb); log= av_log2(buf); if(log > 31-limit){ buf >>= log - k; buf += (30-log)<<k; LAST_SKIP_BITS(re, gb, 32 + k - log); CLOSE_READER(re, gb); return buf; }else{ LAST_SKIP_BITS(re, gb, limit); UPDATE_CACHE(re, gb); buf = SHOW_UBITS(re, gb, esc_len); LAST_SKIP_BITS(re, gb, esc_len); CLOSE_READER(re, gb); return buf + limit - 1; } }
['static inline int get_ur_golomb(GetBitContext *gb, int k, int limit, int esc_len){\n unsigned int buf;\n int log;\n OPEN_READER(re, gb);\n UPDATE_CACHE(re, gb);\n buf=GET_CACHE(re, gb);\n log= av_log2(buf);\n if(log > 31-limit){\n buf >>= log - k;\n buf += (30-log)<<k;\n LAST_SKIP_BITS(re, gb, 32 + k - log);\n CLOSE_READER(re, gb);\n return buf;\n }else{\n LAST_SKIP_BITS(re, gb, limit);\n UPDATE_CACHE(re, gb);\n buf = SHOW_UBITS(re, gb, esc_len);\n LAST_SKIP_BITS(re, gb, esc_len);\n CLOSE_READER(re, gb);\n return buf + limit - 1;\n }\n}']
36,173
0
https://github.com/libav/libav/blob/0bf511d579c7b21f1244eec688abf571ca1235bd/libavfilter/vf_gradfun.c/#L171
static int config_input(AVFilterLink *inlink) { GradFunContext *gf = inlink->dst->priv; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); int hsub = desc->log2_chroma_w; int vsub = desc->log2_chroma_h; gf->buf = av_mallocz((FFALIGN(inlink->w, 16) * (gf->radius + 1) / 2 + 32) * sizeof(uint16_t)); if (!gf->buf) return AVERROR(ENOMEM); gf->chroma_w = -((-inlink->w) >> hsub); gf->chroma_h = -((-inlink->h) >> vsub); gf->chroma_r = av_clip(((((gf->radius >> hsub) + (gf->radius >> vsub)) / 2 ) + 1) & ~1, 4, 32); return 0; }
['static int config_input(AVFilterLink *inlink)\n{\n GradFunContext *gf = inlink->dst->priv;\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);\n int hsub = desc->log2_chroma_w;\n int vsub = desc->log2_chroma_h;\n gf->buf = av_mallocz((FFALIGN(inlink->w, 16) * (gf->radius + 1) / 2 + 32) * sizeof(uint16_t));\n if (!gf->buf)\n return AVERROR(ENOMEM);\n gf->chroma_w = -((-inlink->w) >> hsub);\n gf->chroma_h = -((-inlink->h) >> vsub);\n gf->chroma_r = av_clip(((((gf->radius >> hsub) + (gf->radius >> vsub)) / 2 ) + 1) & ~1, 4, 32);\n return 0;\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}']
36,174
0
https://github.com/nginx/nginx/blob/d79cbf15e6ba119767d2a035047ff67c19465961/src/os/unix/ngx_readv_chain.c/#L70
ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) { u_char *prev; ssize_t n, size; ngx_err_t err; ngx_array_t vec; ngx_event_t *rev; struct iovec *iov, iovs[NGX_IOVS_PREALLOCATE]; rev = c->read; #if (NGX_HAVE_KQUEUE) if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, "readv: eof:%d, avail:%d, err:%d", rev->pending_eof, rev->available, rev->kq_errno); if (rev->available == 0) { if (rev->pending_eof) { rev->ready = 0; rev->eof = 1; ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno, "kevent() reported about an closed connection"); if (rev->kq_errno) { rev->error = 1; ngx_set_socket_errno(rev->kq_errno); return NGX_ERROR; } return 0; } else { return NGX_AGAIN; } } } #endif prev = NULL; iov = NULL; size = 0; vec.elts = iovs; vec.nelts = 0; vec.size = sizeof(struct iovec); vec.nalloc = NGX_IOVS_PREALLOCATE; vec.pool = c->pool; while (chain) { if (prev == chain->buf->last) { iov->iov_len += chain->buf->end - chain->buf->last; } else { if (vec.nelts >= IOV_MAX) { break; } iov = ngx_array_push(&vec); if (iov == NULL) { return NGX_ERROR; } iov->iov_base = (void *) chain->buf->last; iov->iov_len = chain->buf->end - chain->buf->last; } size += chain->buf->end - chain->buf->last; prev = chain->buf->end; chain = chain->next; } ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, "readv: %d, last:%d", vec.nelts, iov->iov_len); do { n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts); if (n >= 0) { #if (NGX_HAVE_KQUEUE) if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { rev->available -= n; if (rev->available <= 0) { if (!rev->pending_eof) { rev->ready = 0; } if (rev->available < 0) { rev->available = 0; } } if (n == 0) { #if 0 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "readv() returned 0 while kevent() reported " "%d available bytes", rev->available); #endif rev->ready = 0; rev->eof = 1; rev->available = 0; } return n; } #endif if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) { rev->ready = 0; } if (n == 0) { rev->eof = 1; } return n; } err = ngx_socket_errno; if (err == NGX_EAGAIN || err == NGX_EINTR) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, "readv() not ready"); n = NGX_AGAIN; } else { n = ngx_connection_error(c, err, "readv() failed"); break; } } while (err == NGX_EINTR); rev->ready = 0; if (n == NGX_ERROR) { c->read->error = 1; } return n; }
['ssize_t\nngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)\n{\n u_char *prev;\n ssize_t n, size;\n ngx_err_t err;\n ngx_array_t vec;\n ngx_event_t *rev;\n struct iovec *iov, iovs[NGX_IOVS_PREALLOCATE];\n rev = c->read;\n#if (NGX_HAVE_KQUEUE)\n if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {\n ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,\n "readv: eof:%d, avail:%d, err:%d",\n rev->pending_eof, rev->available, rev->kq_errno);\n if (rev->available == 0) {\n if (rev->pending_eof) {\n rev->ready = 0;\n rev->eof = 1;\n ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,\n "kevent() reported about an closed connection");\n if (rev->kq_errno) {\n rev->error = 1;\n ngx_set_socket_errno(rev->kq_errno);\n return NGX_ERROR;\n }\n return 0;\n } else {\n return NGX_AGAIN;\n }\n }\n }\n#endif\n prev = NULL;\n iov = NULL;\n size = 0;\n vec.elts = iovs;\n vec.nelts = 0;\n vec.size = sizeof(struct iovec);\n vec.nalloc = NGX_IOVS_PREALLOCATE;\n vec.pool = c->pool;\n while (chain) {\n if (prev == chain->buf->last) {\n iov->iov_len += chain->buf->end - chain->buf->last;\n } else {\n if (vec.nelts >= IOV_MAX) {\n break;\n }\n iov = ngx_array_push(&vec);\n if (iov == NULL) {\n return NGX_ERROR;\n }\n iov->iov_base = (void *) chain->buf->last;\n iov->iov_len = chain->buf->end - chain->buf->last;\n }\n size += chain->buf->end - chain->buf->last;\n prev = chain->buf->end;\n chain = chain->next;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,\n "readv: %d, last:%d", vec.nelts, iov->iov_len);\n do {\n n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);\n if (n >= 0) {\n#if (NGX_HAVE_KQUEUE)\n if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {\n rev->available -= n;\n if (rev->available <= 0) {\n if (!rev->pending_eof) {\n rev->ready = 0;\n }\n if (rev->available < 0) {\n rev->available = 0;\n }\n }\n if (n == 0) {\n#if 0\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "readv() returned 0 while kevent() reported "\n "%d available bytes", rev->available);\n#endif\n rev->ready = 0;\n rev->eof = 1;\n rev->available = 0;\n }\n return n;\n }\n#endif\n if (n < size && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) {\n rev->ready = 0;\n }\n if (n == 0) {\n rev->eof = 1;\n }\n return n;\n }\n err = ngx_socket_errno;\n if (err == NGX_EAGAIN || err == NGX_EINTR) {\n ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,\n "readv() not ready");\n n = NGX_AGAIN;\n } else {\n n = ngx_connection_error(c, err, "readv() failed");\n break;\n }\n } while (err == NGX_EINTR);\n rev->ready = 0;\n if (n == NGX_ERROR) {\n c->read->error = 1;\n }\n return n;\n}']
36,175
0
https://github.com/openssl/openssl/blob/98e665493818493e9a2bb4fce30127aca052f47a/crypto/lhash/lhash.c/#L240
void *lh_delete(LHASH *lh, const void *data) { unsigned long hash; LHASH_NODE *nn,**rn; const 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((void *)ret); }
['int main(int argc, char *argv[])\n\t{\n\tchar *CApath=NULL,*CAfile=NULL;\n\tint badop=0;\n\tint bio_pair=0;\n\tint force=0;\n\tint tls1=0,ssl2=0,ssl3=0,ret=1;\n\tint client_auth=0;\n\tint server_auth=0,i;\n\tchar *server_cert=TEST_SERVER_CERT;\n\tchar *server_key=NULL;\n\tchar *client_cert=TEST_CLIENT_CERT;\n\tchar *client_key=NULL;\n\tSSL_CTX *s_ctx=NULL;\n\tSSL_CTX *c_ctx=NULL;\n\tSSL_METHOD *meth=NULL;\n\tSSL *c_ssl,*s_ssl;\n\tint number=1,reuse=0;\n\tlong bytes=1L;\n#ifndef OPENSSL_NO_DH\n\tDH *dh;\n\tint dhe1024 = 0, dhe1024dsa = 0;\n#endif\n\tint no_dhe = 0;\n\tint print_time = 0;\n\tclock_t s_time = 0, c_time = 0;\n\tint comp = 0;\n\tCOMP_METHOD *cm = NULL;\n\tverbose = 0;\n\tdebug = 0;\n\tcipher = 0;\n\tCRYPTO_set_locking_callback(lock_dbg_cb);\n\tif (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))\n\t\t{\n\t\tCRYPTO_malloc_debug_init();\n\t\tCRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);\n\t\t}\n\telse\n\t\t{\n\t\tCRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);\n\t\t}\n\tCRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);\n\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tbio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif\t(strcmp(*argv,"-server_auth") == 0)\n\t\t\tserver_auth=1;\n\t\telse if\t(strcmp(*argv,"-client_auth") == 0)\n\t\t\tclient_auth=1;\n\t\telse if\t(strcmp(*argv,"-v") == 0)\n\t\t\tverbose=1;\n\t\telse if\t(strcmp(*argv,"-d") == 0)\n\t\t\tdebug=1;\n\t\telse if\t(strcmp(*argv,"-reuse") == 0)\n\t\t\treuse=1;\n#ifndef OPENSSL_NO_DH\n\t\telse if\t(strcmp(*argv,"-dhe1024") == 0)\n\t\t\tdhe1024=1;\n\t\telse if\t(strcmp(*argv,"-dhe1024dsa") == 0)\n\t\t\tdhe1024dsa=1;\n#endif\n\t\telse if\t(strcmp(*argv,"-no_dhe") == 0)\n\t\t\tno_dhe=1;\n\t\telse if\t(strcmp(*argv,"-ssl2") == 0)\n\t\t\tssl2=1;\n\t\telse if\t(strcmp(*argv,"-tls1") == 0)\n\t\t\ttls1=1;\n\t\telse if\t(strcmp(*argv,"-ssl3") == 0)\n\t\t\tssl3=1;\n\t\telse if\t(strncmp(*argv,"-num",4) == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tnumber= atoi(*(++argv));\n\t\t\tif (number == 0) number=1;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-bytes") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tbytes= atol(*(++argv));\n\t\t\tif (bytes == 0L) bytes=1L;\n\t\t\ti=strlen(argv[0]);\n\t\t\tif (argv[0][i-1] == \'k\') bytes*=1024L;\n\t\t\tif (argv[0][i-1] == \'m\') bytes*=1024L*1024L;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tserver_cert= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-s_cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tserver_cert= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tserver_key= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-s_key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tserver_key= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-c_cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tclient_cert= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-c_key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tclient_key= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-cipher") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcipher= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CApath") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCApath= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CAfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-bio_pair") == 0)\n\t\t\t{\n\t\t\tbio_pair = 1;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-f") == 0)\n\t\t\t{\n\t\t\tforce = 1;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-time") == 0)\n\t\t\t{\n\t\t\tprint_time = 1;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-zlib") == 0)\n\t\t\t{\n\t\t\tcomp = COMP_ZLIB;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-rle") == 0)\n\t\t\t{\n\t\t\tcomp = COMP_RLE;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tfprintf(stderr,"unknown option %s\\n",*argv);\n\t\t\tbadop=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badop)\n\t\t{\nbad:\n\t\tsv_usage();\n\t\tgoto end;\n\t\t}\n\tif (!ssl2 && !ssl3 && !tls1 && number > 1 && !reuse && !force)\n\t\t{\n\t\tfprintf(stderr, "This case cannot work. Use -f to perform "\n\t\t\t"the test anyway (and\\n-d to see what happens), "\n\t\t\t"or add one of -ssl2, -ssl3, -tls1, -reuse\\n"\n\t\t\t"to avoid protocol mismatch.\\n");\n\t\texit(1);\n\t\t}\n\tif (print_time)\n\t\t{\n\t\tif (!bio_pair)\n\t\t\t{\n\t\t\tfprintf(stderr, "Using BIO pair (-bio_pair)\\n");\n\t\t\tbio_pair = 1;\n\t\t\t}\n\t\tif (number < 50 && !force)\n\t\t\tfprintf(stderr, "Warning: For accurate timings, use more connections (e.g. -num 1000)\\n");\n\t\t}\n\tSSL_library_init();\n\tSSL_load_error_strings();\n\tif (comp == COMP_ZLIB) cm = COMP_zlib();\n\tif (comp == COMP_RLE) cm = COMP_rle();\n\tif (cm != NULL)\n\t\t{\n\t\tif (cm->type != NID_undef)\n\t\t\tSSL_COMP_add_compression_method(comp, cm);\n\t\telse\n\t\t\t{\n\t\t\tfprintf(stderr,\n\t\t\t\t"Warning: %s compression not supported\\n",\n\t\t\t\t(comp == COMP_RLE ? "rle" :\n\t\t\t\t\t(comp == COMP_ZLIB ? "zlib" :\n\t\t\t\t\t\t"unknown")));\n\t\t\tERR_print_errors_fp(stderr);\n\t\t\t}\n\t\t}\n#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)\n\tif (ssl2)\n\t\tmeth=SSLv2_method();\n\telse\n\tif (tls1)\n\t\tmeth=TLSv1_method();\n\telse\n\tif (ssl3)\n\t\tmeth=SSLv3_method();\n\telse\n\t\tmeth=SSLv23_method();\n#else\n#ifdef OPENSSL_NO_SSL2\n\tmeth=SSLv3_method();\n#else\n\tmeth=SSLv2_method();\n#endif\n#endif\n\tc_ctx=SSL_CTX_new(meth);\n\ts_ctx=SSL_CTX_new(meth);\n\tif ((c_ctx == NULL) || (s_ctx == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (cipher != NULL)\n\t\t{\n\t\tSSL_CTX_set_cipher_list(c_ctx,cipher);\n\t\tSSL_CTX_set_cipher_list(s_ctx,cipher);\n\t\t}\n#ifndef OPENSSL_NO_DH\n\tif (!no_dhe)\n\t\t{\n\t\tif (dhe1024dsa)\n\t\t\t{\n\t\t\tSSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE);\n\t\t\tdh=get_dh1024dsa();\n\t\t\t}\n\t\telse if (dhe1024)\n\t\t\tdh=get_dh1024();\n\t\telse\n\t\t\tdh=get_dh512();\n\t\tSSL_CTX_set_tmp_dh(s_ctx,dh);\n\t\tDH_free(dh);\n\t\t}\n#else\n\t(void)no_dhe;\n#endif\n#ifndef OPENSSL_NO_RSA\n\tSSL_CTX_set_tmp_rsa_callback(s_ctx,tmp_rsa_cb);\n#endif\n\tif (!SSL_CTX_use_certificate_file(s_ctx,server_cert,SSL_FILETYPE_PEM))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\telse if (!SSL_CTX_use_PrivateKey_file(s_ctx,\n\t\t(server_key?server_key:server_cert), SSL_FILETYPE_PEM))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (client_auth)\n\t\t{\n\t\tSSL_CTX_use_certificate_file(c_ctx,client_cert,\n\t\t\tSSL_FILETYPE_PEM);\n\t\tSSL_CTX_use_PrivateKey_file(c_ctx,\n\t\t\t(client_key?client_key:client_cert),\n\t\t\tSSL_FILETYPE_PEM);\n\t\t}\n\tif (\t(!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||\n\t\t(!SSL_CTX_set_default_verify_paths(s_ctx)) ||\n\t\t(!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||\n\t\t(!SSL_CTX_set_default_verify_paths(c_ctx)))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tif (client_auth)\n\t\t{\n\t\tBIO_printf(bio_err,"client authentication\\n");\n\t\tSSL_CTX_set_verify(s_ctx,\n\t\t\tSSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,\n\t\t\tverify_callback);\n\t\t}\n\tif (server_auth)\n\t\t{\n\t\tBIO_printf(bio_err,"server authentication\\n");\n\t\tSSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,\n\t\t\tverify_callback);\n\t\t}\n\t{\n\t\tint session_id_context = 0;\n\t\tSSL_CTX_set_session_id_context(s_ctx, (void *)&session_id_context, sizeof session_id_context);\n\t}\n\tc_ssl=SSL_new(c_ctx);\n\ts_ssl=SSL_new(s_ctx);\n#ifndef OPENSSL_NO_KRB5\n\tif (c_ssl && c_ssl->kssl_ctx)\n {\n char\tlocalhost[257];\n\t\tif (gethostname(localhost, 256) == 0)\n {\n\t\t\tkssl_ctx_setstring(c_ssl->kssl_ctx, KSSL_SERVER,\n localhost);\n\t\t\t}\n\t\t}\n#endif\n\tfor (i=0; i<number; i++)\n\t\t{\n\t\tif (!reuse) SSL_set_session(c_ssl,NULL);\n\t\tif (bio_pair)\n\t\t\tret=doit_biopair(s_ssl,c_ssl,bytes,&s_time,&c_time);\n\t\telse\n\t\t\tret=doit(s_ssl,c_ssl,bytes);\n\t\t}\n\tif (!verbose)\n\t\t{\n\t\tprint_details(c_ssl, "");\n\t\t}\n\tif ((number > 1) || (bytes > 1L))\n\t\tBIO_printf(bio_stdout, "%d handshakes of %ld bytes done\\n",number,bytes);\n\tif (print_time)\n\t\t{\n#ifdef CLOCKS_PER_SEC\n\t\tBIO_printf(bio_stdout, "Approximate total server time: %6.2f s\\n"\n\t\t\t"Approximate total client time: %6.2f s\\n",\n\t\t\t(double)s_time/CLOCKS_PER_SEC,\n\t\t\t(double)c_time/CLOCKS_PER_SEC);\n#else\n\t\tBIO_printf(bio_stdout,\n\t\t\t"Approximate total server time: %6.2f units\\n"\n\t\t\t"Approximate total client time: %6.2f units\\n",\n\t\t\t(double)s_time,\n\t\t\t(double)c_time);\n#endif\n\t\t}\n\tSSL_free(s_ssl);\n\tSSL_free(c_ssl);\nend:\n\tif (s_ctx != NULL) SSL_CTX_free(s_ctx);\n\tif (c_ctx != NULL) SSL_CTX_free(c_ctx);\n\tif (bio_stdout != NULL) BIO_free(bio_stdout);\n#ifndef OPENSSL_NO_RSA\n\tfree_tmp_rsa();\n#endif\n\tENGINE_cleanup();\n\tCRYPTO_cleanup_all_ex_data();\n\tERR_free_strings();\n\tERR_remove_state(0);\n\tEVP_cleanup();\n\tCRYPTO_mem_leaks(bio_err);\n\tif (bio_err != NULL) BIO_free(bio_err);\n\tEXIT(ret);\n\t}', 'SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)\n\t{\n\tSSL_CTX *ret=NULL;\n\tif (meth == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);\n\t\treturn(NULL);\n\t\t}\n\tif (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n\t\tgoto err;\n\t\t}\n\tret=(SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));\n\tif (ret == NULL)\n\t\tgoto err;\n\tmemset(ret,0,sizeof(SSL_CTX));\n\tret->method=meth;\n\tret->cert_store=NULL;\n\tret->session_cache_mode=SSL_SESS_CACHE_SERVER;\n\tret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n\tret->session_cache_head=NULL;\n\tret->session_cache_tail=NULL;\n\tret->session_timeout=meth->get_timeout();\n\tret->new_session_cb=0;\n\tret->remove_session_cb=0;\n\tret->get_session_cb=0;\n\tret->generate_session_id=0;\n\tmemset((char *)&ret->stats,0,sizeof(ret->stats));\n\tret->references=1;\n\tret->quiet_shutdown=0;\n\tret->info_callback=0;\n\tret->app_verify_callback=0;\n\tret->app_verify_arg=NULL;\n\tret->max_cert_list=SSL_MAX_CERT_LIST_DEFAULT;\n\tret->read_ahead=0;\n\tret->msg_callback=0;\n\tret->msg_callback_arg=NULL;\n\tret->verify_mode=SSL_VERIFY_NONE;\n\tret->verify_depth=-1;\n\tret->sid_ctx_length=0;\n\tret->default_verify_callback=NULL;\n\tif ((ret->cert=ssl_cert_new()) == NULL)\n\t\tgoto err;\n\tret->default_passwd_callback=0;\n\tret->default_passwd_callback_userdata=NULL;\n\tret->client_cert_cb=0;\n\tret->sessions=lh_new(LHASH_HASH_FN(SSL_SESSION_hash),\n\t\t\tLHASH_COMP_FN(SSL_SESSION_cmp));\n\tif (ret->sessions == NULL) goto err;\n\tret->cert_store=X509_STORE_new();\n\tif (ret->cert_store == NULL) goto err;\n\tssl_create_cipher_list(ret->method,\n\t\t&ret->cipher_list,&ret->cipher_list_by_id,\n\t\tSSL_DEFAULT_CIPHER_LIST);\n\tif (ret->cipher_list == NULL\n\t || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)\n\t\tgoto err;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);\n\tret->extra_certs=NULL;\n\tret->comp_methods=SSL_COMP_get_compression_methods();\n\treturn(ret);\nerr:\n\tSSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);\nerr2:\n\tif (ret != NULL) SSL_CTX_free(ret);\n\treturn(NULL);\n\t}', 'LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n\t{\n\tLHASH *ret;\n\tint i;\n\tif ((ret=(LHASH *)OPENSSL_malloc(sizeof(LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=(LHASH_NODE **)OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);\n\tret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tOPENSSL_free(ret);\nerr0:\n\treturn(NULL);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->max_cert_list=ctx->max_cert_list;\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->read_ahead=ctx->read_ahead;\n\ts->msg_callback=ctx->msg_callback;\n\ts->msg_callback_arg=ctx->msg_callback_arg;\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_depth=ctx->verify_depth;\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tOPENSSL_free(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tint state;\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#else\n\tif (s->new_session)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR);\n\t\treturn 0;\n\t\t}\n#endif\n\tstate=s->state;\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n#if 0\n\ts->read_ahead=s->ctx->read_ahead;\n#endif\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->first_packet=0;\n#if 1\n\tif ((s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn((void *)ret);\n\t}']
36,176
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_ctx.c/#L437
static void BN_POOL_release(BN_POOL *p, unsigned int num) { unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; p->used -= num; while (num--) { bn_check_top(p->current->vals + offset); if (!offset) { offset = BN_CTX_POOL_SIZE - 1; p->current = p->current->prev; } else offset--; } }
['int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *yy, const BIGNUM *xx,\n const int p[], BN_CTX *ctx)\n{\n BIGNUM *field;\n int ret = 0;\n bn_check_top(yy);\n bn_check_top(xx);\n BN_CTX_start(ctx);\n if ((field = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_GF2m_arr2poly(p, field))\n goto err;\n ret = BN_GF2m_mod_div(r, yy, xx, field, ctx);\n bn_check_top(r);\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (!offset) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
36,177
0
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L237
static inline void skip_remaining(BitstreamContext *bc, unsigned n) { #ifdef BITSTREAM_READER_LE bc->bits >>= n; #else bc->bits <<= n; #endif bc->bits_left -= n; }
['static int theora_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 TheoraParams *thp = os->private;\n int cds = st->codecpar->extradata_size + os->psize + 2;\n int err;\n uint8_t *cdp;\n if (!(os->buf[os->pstart] & 0x80))\n return 0;\n if (!thp) {\n thp = av_mallocz(sizeof(*thp));\n if (!thp)\n return AVERROR(ENOMEM);\n os->private = thp;\n }\n switch (os->buf[os->pstart]) {\n case 0x80: {\n BitstreamContext bc;\n AVRational timebase;\n bitstream_init8(&bc, os->buf + os->pstart, os->psize);\n bitstream_skip(&bc, 7 * 8);\n thp->version = bitstream_read(&bc, 24);\n if (thp->version < 0x030100) {\n av_log(s, AV_LOG_ERROR,\n "Too old or unsupported Theora (%x)\\n", thp->version);\n return AVERROR(ENOSYS);\n }\n st->codecpar->width = bitstream_read(&bc, 16) << 4;\n st->codecpar->height = bitstream_read(&bc, 16) << 4;\n if (thp->version >= 0x030400)\n bitstream_skip(&bc, 100);\n if (thp->version >= 0x030200) {\n int width = bitstream_read(&bc, 24);\n int height = bitstream_read(&bc, 24);\n if (width <= st->codecpar->width && width > st->codecpar->width - 16 &&\n height <= st->codecpar->height && height > st->codecpar->height - 16) {\n st->codecpar->width = width;\n st->codecpar->height = height;\n }\n bitstream_skip(&bc, 16);\n }\n timebase.den = bitstream_read(&bc, 32);\n timebase.num = bitstream_read(&bc, 32);\n if (!(timebase.num > 0 && timebase.den > 0)) {\n av_log(s, AV_LOG_WARNING, "Invalid time base in theora stream, assuming 25 FPS\\n");\n timebase.num = 1;\n timebase.den = 25;\n }\n avpriv_set_pts_info(st, 64, timebase.num, timebase.den);\n st->sample_aspect_ratio.num = bitstream_read(&bc, 24);\n st->sample_aspect_ratio.den = bitstream_read(&bc, 24);\n if (thp->version >= 0x030200)\n bitstream_skip(&bc, 38);\n if (thp->version >= 0x304000)\n bitstream_skip(&bc, 2);\n thp->gpshift = bitstream_read(&bc, 5);\n thp->gpmask = (1 << thp->gpshift) - 1;\n st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;\n st->codecpar->codec_id = AV_CODEC_ID_THEORA;\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n }\n break;\n case 0x81:\n ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 7, os->psize - 7);\n case 0x82:\n if (!thp->version)\n return AVERROR_INVALIDDATA;\n break;\n default:\n return AVERROR_INVALIDDATA;\n }\n if ((err = av_reallocp(&st->codecpar->extradata,\n cds + AV_INPUT_BUFFER_PADDING_SIZE)) < 0) {\n st->codecpar->extradata_size = 0;\n return err;\n }\n cdp = st->codecpar->extradata + st->codecpar->extradata_size;\n *cdp++ = os->psize >> 8;\n *cdp++ = os->psize & 0xff;\n memcpy(cdp, os->buf + os->pstart, os->psize);\n st->codecpar->extradata_size = cds;\n return 1;\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n unsigned byte_size)\n{\n if (byte_size > INT_MAX / 8)\n return AVERROR_INVALIDDATA;\n return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
36,178
0
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/test/evp_test.c/#L1556
static int encode_test_init(struct evp_test *t, const char *encoding) { struct encode_data *edata = OPENSSL_zalloc(sizeof(*edata)); if (strcmp(encoding, "canonical") == 0) { edata->encoding = BASE64_CANONICAL_ENCODING; } else if (strcmp(encoding, "valid") == 0) { edata->encoding = BASE64_VALID_ENCODING; } else if (strcmp(encoding, "invalid") == 0) { edata->encoding = BASE64_INVALID_ENCODING; t->expected_err = OPENSSL_strdup("DECODE_ERROR"); if (t->expected_err == NULL) return 0; } else { fprintf(stderr, "Bad encoding: %s. Should be one of " "{canonical, valid, invalid}\n", encoding); return 0; } t->data = edata; return 1; }
['static int encode_test_init(struct evp_test *t, const char *encoding)\n{\n struct encode_data *edata = OPENSSL_zalloc(sizeof(*edata));\n if (strcmp(encoding, "canonical") == 0) {\n edata->encoding = BASE64_CANONICAL_ENCODING;\n } else if (strcmp(encoding, "valid") == 0) {\n edata->encoding = BASE64_VALID_ENCODING;\n } else if (strcmp(encoding, "invalid") == 0) {\n edata->encoding = BASE64_INVALID_ENCODING;\n t->expected_err = OPENSSL_strdup("DECODE_ERROR");\n if (t->expected_err == NULL)\n return 0;\n } else {\n fprintf(stderr, "Bad encoding: %s. Should be one of "\n "{canonical, valid, invalid}\\n", encoding);\n return 0;\n }\n t->data = edata;\n return 1;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}']
36,179
0
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)\n{\n BN_CTX *ctx = NULL;\n BN_MONT_CTX *mont = NULL;\n BIGNUM *tmp;\n int ret = -1;\n int check_result;\n if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {\n DHerr(DH_F_COMPUTE_KEY, DH_R_MODULUS_TOO_LARGE);\n goto err;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n if (dh->priv_key == NULL) {\n DHerr(DH_F_COMPUTE_KEY, DH_R_NO_PRIVATE_VALUE);\n goto err;\n }\n if (dh->flags & DH_FLAG_CACHE_MONT_P) {\n mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,\n dh->lock, dh->p, ctx);\n BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME);\n if (!mont)\n goto err;\n }\n if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result) {\n DHerr(DH_F_COMPUTE_KEY, DH_R_INVALID_PUBKEY);\n goto err;\n }\n if (!dh->\n meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key, dh->p, ctx, mont)) {\n DHerr(DH_F_COMPUTE_KEY, ERR_R_BN_LIB);\n goto err;\n }\n ret = BN_bn2bin(tmp, key);\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,\n const BIGNUM *mod, BN_CTX *ctx)\n{\n BN_MONT_CTX *ret;\n CRYPTO_THREAD_read_lock(lock);\n ret = *pmont;\n CRYPTO_THREAD_unlock(lock);\n if (ret)\n return ret;\n ret = BN_MONT_CTX_new();\n if (ret == NULL)\n return NULL;\n if (!BN_MONT_CTX_set(ret, mod, ctx)) {\n BN_MONT_CTX_free(ret);\n return NULL;\n }\n CRYPTO_THREAD_write_lock(lock);\n if (*pmont) {\n BN_MONT_CTX_free(ret);\n ret = *pmont;\n } else\n *pmont = ret;\n CRYPTO_THREAD_unlock(lock);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,180
0
https://github.com/libav/libav/blob/c41b9842ceac42bedfd74a7ba2d02add82f818a9/libavcodec/rv40.c/#L472
static void rv40_loop_filter(RV34DecContext *r, int row) { MpegEncContext *s = &r->s; int mb_pos, mb_x; int i, j, k; uint8_t *Y, *C; int alpha, beta, betaY, betaC; int q; int mbtype[4]; int mb_strong[4]; int clip[4]; int cbp[4]; int uvcbp[4][2]; int mvmasks[4]; mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos]; if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF; if(IS_INTRA(mbtype)) r->cbp_chroma[mb_pos] = 0xFF; } mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int y_h_deblock, y_v_deblock; int c_v_deblock[2], c_h_deblock[2]; int clip_left; int avail[4]; int y_to_deblock, c_to_deblock[2]; q = s->current_picture_ptr->f.qscale_table[mb_pos]; alpha = rv40_alpha_tab[q]; beta = rv40_beta_tab [q]; betaY = betaC = beta * 3; if(s->width * s->height <= 176*144) betaY += beta; avail[0] = 1; avail[1] = row; avail[2] = mb_x; avail[3] = row < s->mb_height - 1; for(i = 0; i < 4; i++){ if(avail[i]){ int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; mvmasks[i] = r->deblock_coefs[pos]; mbtype [i] = s->current_picture_ptr->f.mb_type[pos]; cbp [i] = r->cbp_luma[pos]; uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; uvcbp[i][1] = r->cbp_chroma[pos] >> 4; }else{ mvmasks[i] = 0; mbtype [i] = mbtype[0]; cbp [i] = 0; uvcbp[i][0] = uvcbp[i][1] = 0; } mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]); clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q]; } y_to_deblock = mvmasks[POS_CUR] | (mvmasks[POS_BOTTOM] << 16); y_h_deblock = y_to_deblock | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW) | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12); y_v_deblock = y_to_deblock | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL) | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3); if(!mb_x) y_v_deblock &= ~MASK_Y_LEFT_COL; if(!row) y_h_deblock &= ~MASK_Y_TOP_ROW; if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])) y_h_deblock &= ~(MASK_Y_TOP_ROW << 16); for(i = 0; i < 2; i++){ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i]; c_v_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL) | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1); c_h_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2) | (uvcbp[POS_CUR][i] << 2); if(!mb_x) c_v_deblock[i] &= ~MASK_C_LEFT_COL; if(!row) c_h_deblock[i] &= ~MASK_C_TOP_ROW; if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]) c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4); } for(j = 0; j < 16; j += 4){ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize; for(i = 0; i < 4; i++, Y += 4){ int ij = i + j; int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; int dither = j ? ij : i*4; if(y_h_deblock & (MASK_BOTTOM << ij)){ rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize, s->linesize, dither, y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, clip_cur, alpha, beta, betaY, 0, 0, 0); } if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; else clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 0, 1); } if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, clip_cur, mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0, alpha, beta, betaY, 0, 1, 0); } if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 1, 1); } } } for(k = 0; k < 2; k++){ for(j = 0; j < 2; j++){ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; for(i = 0; i < 2; i++, C += 4){ int ij = i + j*2; int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8, clip_bot, clip_cur, alpha, beta, betaC, 1, 0, 0); } if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; else clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 0, 1); } if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8, clip_cur, clip_top, alpha, beta, betaC, 1, 1, 0); } if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 1, 1); } } } } } }
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->f.qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->f.mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,\n s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur, alpha, beta, betaY,\n 0, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0, 1);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0, 1);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1, 0);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1, 1);\n }\n }\n }\n }\n }\n}']
36,181
0
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int bn_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_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
36,182
0
https://github.com/libav/libav/blob/66a71d989fdca27749bf4a965d0c0b2fe6d7b473/libavcodec/aacsbr.c/#L185
static void sbr_make_f_tablelim(SpectralBandReplication *sbr) { int k; if (sbr->bs_limiter_bands > 0) { static const float bands_warped[3] = { 1.32715174233856803909f, 1.18509277094158210129f, 1.11987160404675912501f }; const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1]; int16_t patch_borders[7]; uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim; patch_borders[0] = sbr->kx[1]; for (k = 1; k <= sbr->num_patches; k++) patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1]; memcpy(sbr->f_tablelim, sbr->f_tablelow, (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0])); if (sbr->num_patches > 1) memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1, (sbr->num_patches - 1) * sizeof(patch_borders[0])); qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0], sizeof(sbr->f_tablelim[0]), qsort_comparison_function_int16); sbr->n_lim = sbr->n[0] + sbr->num_patches - 1; while (out < sbr->f_tablelim + sbr->n_lim) { if (*in >= *out * lim_bands_per_octave_warped) { *++out = *in++; } else if (*in == *out || !in_table_int16(patch_borders, sbr->num_patches, *in)) { in++; sbr->n_lim--; } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) { *out = *in++; sbr->n_lim--; } else { *++out = *in++; } } } else { sbr->f_tablelim[0] = sbr->f_tablelow[0]; sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]]; sbr->n_lim = 1; } }
['static int aac_decode_frame_int(AVCodecContext *avctx, void *data,\n int *data_size, GetBitContext *gb)\n{\n AACContext *ac = avctx->priv_data;\n ChannelElement *che = NULL, *che_prev = NULL;\n enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;\n int err, elem_id, data_size_tmp;\n int samples = 0, multiplier;\n if (show_bits(gb, 12) == 0xfff) {\n if (parse_adts_frame_header(ac, gb) < 0) {\n av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\\n");\n return -1;\n }\n if (ac->m4ac.sampling_index > 12) {\n av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\\n", ac->m4ac.sampling_index);\n return -1;\n }\n }\n ac->tags_mapped = 0;\n while ((elem_type = get_bits(gb, 3)) != TYPE_END) {\n elem_id = get_bits(gb, 4);\n if (elem_type < TYPE_DSE) {\n if (!(che=get_che(ac, elem_type, elem_id))) {\n av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\\n",\n elem_type, elem_id);\n return -1;\n }\n samples = 1024;\n }\n switch (elem_type) {\n case TYPE_SCE:\n err = decode_ics(ac, &che->ch[0], gb, 0, 0);\n break;\n case TYPE_CPE:\n err = decode_cpe(ac, gb, che);\n break;\n case TYPE_CCE:\n err = decode_cce(ac, gb, che);\n break;\n case TYPE_LFE:\n err = decode_ics(ac, &che->ch[0], gb, 0, 0);\n break;\n case TYPE_DSE:\n err = skip_data_stream_element(ac, gb);\n break;\n case TYPE_PCE: {\n enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];\n memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));\n if ((err = decode_pce(ac, new_che_pos, gb)))\n break;\n if (ac->output_configured > OC_TRIAL_PCE)\n av_log(avctx, AV_LOG_ERROR,\n "Not evaluating a further program_config_element as this construct is dubious at best.\\n");\n else\n err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE);\n break;\n }\n case TYPE_FIL:\n if (elem_id == 15)\n elem_id += get_bits(gb, 8) - 1;\n if (get_bits_left(gb) < 8 * elem_id) {\n av_log(avctx, AV_LOG_ERROR, overread_err);\n return -1;\n }\n while (elem_id > 0)\n elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev);\n err = 0;\n break;\n default:\n err = -1;\n break;\n }\n che_prev = che;\n elem_type_prev = elem_type;\n if (err)\n return err;\n if (get_bits_left(gb) < 3) {\n av_log(avctx, AV_LOG_ERROR, overread_err);\n return -1;\n }\n }\n spectral_to_sample(ac);\n multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;\n samples <<= multiplier;\n if (ac->output_configured < OC_LOCKED) {\n avctx->sample_rate = ac->m4ac.sample_rate << multiplier;\n avctx->frame_size = samples;\n }\n data_size_tmp = samples * avctx->channels * sizeof(int16_t);\n if (*data_size < data_size_tmp) {\n av_log(avctx, AV_LOG_ERROR,\n "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\\n",\n *data_size, data_size_tmp);\n return -1;\n }\n *data_size = data_size_tmp;\n if (samples)\n ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels);\n if (ac->output_configured)\n ac->output_configured = OC_LOCKED;\n return 0;\n}', 'static ChannelElement *get_che(AACContext *ac, int type, int elem_id)\n{\n if (!ac->m4ac.chan_config) {\n return ac->tag_che_map[type][elem_id];\n }\n switch (ac->m4ac.chan_config) {\n case 7:\n if (ac->tags_mapped == 3 && type == TYPE_CPE) {\n ac->tags_mapped++;\n return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];\n }\n case 6:\n if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {\n ac->tags_mapped++;\n return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];\n }\n case 5:\n if (ac->tags_mapped == 2 && type == TYPE_CPE) {\n ac->tags_mapped++;\n return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];\n }\n case 4:\n if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {\n ac->tags_mapped++;\n return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];\n }\n case 3:\n case 2:\n if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {\n ac->tags_mapped++;\n return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];\n } else if (ac->m4ac.chan_config == 2) {\n return NULL;\n }\n case 1:\n if (!ac->tags_mapped && type == TYPE_SCE) {\n ac->tags_mapped++;\n return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];\n }\n default:\n return NULL;\n }\n}', 'static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt,\n ChannelElement *che, enum RawDataBlockType elem_type)\n{\n int crc_flag = 0;\n int res = cnt;\n switch (get_bits(gb, 4)) {\n case EXT_SBR_DATA_CRC:\n crc_flag++;\n case EXT_SBR_DATA:\n if (!che) {\n av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\\n");\n return res;\n } else if (!ac->m4ac.sbr) {\n av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\\n");\n skip_bits_long(gb, 8 * cnt - 4);\n return res;\n } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) {\n av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\\n");\n skip_bits_long(gb, 8 * cnt - 4);\n return res;\n } else if (ac->m4ac.ps == -1 && ac->output_configured < OC_LOCKED && ac->avctx->channels == 1) {\n ac->m4ac.sbr = 1;\n ac->m4ac.ps = 1;\n output_configure(ac, ac->che_pos, ac->che_pos, ac->m4ac.chan_config, ac->output_configured);\n } else {\n ac->m4ac.sbr = 1;\n }\n res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_type);\n break;\n case EXT_DYNAMIC_RANGE:\n res = decode_dynamic_range(&ac->che_drc, gb, cnt);\n break;\n case EXT_FILL:\n case EXT_FILL_DATA:\n case EXT_DATA_ELEMENT:\n default:\n skip_bits_long(gb, 8 * cnt - 4);\n break;\n };\n return res;\n}', 'int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,\n GetBitContext *gb_host, int crc, int cnt, int id_aac)\n{\n unsigned int num_sbr_bits = 0, num_align_bits;\n unsigned bytes_read;\n GetBitContext gbc = *gb_host, *gb = &gbc;\n skip_bits_long(gb_host, cnt*8 - 4);\n sbr->reset = 0;\n if (!sbr->sample_rate)\n sbr->sample_rate = 2 * ac->m4ac.sample_rate;\n if (!ac->m4ac.ext_sample_rate)\n ac->m4ac.ext_sample_rate = 2 * ac->m4ac.sample_rate;\n if (crc) {\n skip_bits(gb, 10);\n num_sbr_bits += 10;\n }\n sbr->kx[0] = sbr->kx[1];\n sbr->m[0] = sbr->m[1];\n num_sbr_bits++;\n if (get_bits1(gb))\n num_sbr_bits += read_sbr_header(sbr, gb);\n if (sbr->reset)\n sbr_reset(ac, sbr);\n if (sbr->start)\n num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac);\n num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7;\n bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3);\n if (bytes_read > cnt) {\n av_log(ac->avctx, AV_LOG_ERROR,\n "Expected to read %d SBR bytes actually read %d.\\n", cnt, bytes_read);\n }\n return cnt;\n}', 'static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb)\n{\n unsigned int cnt = get_bits_count(gb);\n uint8_t bs_header_extra_1;\n uint8_t bs_header_extra_2;\n int old_bs_limiter_bands = sbr->bs_limiter_bands;\n SpectrumParameters old_spectrum_params;\n sbr->start = 1;\n memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters));\n sbr->bs_amp_res_header = get_bits1(gb);\n sbr->spectrum_params.bs_start_freq = get_bits(gb, 4);\n sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4);\n sbr->spectrum_params.bs_xover_band = get_bits(gb, 3);\n skip_bits(gb, 2);\n bs_header_extra_1 = get_bits1(gb);\n bs_header_extra_2 = get_bits1(gb);\n if (bs_header_extra_1) {\n sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2);\n sbr->spectrum_params.bs_alter_scale = get_bits1(gb);\n sbr->spectrum_params.bs_noise_bands = get_bits(gb, 2);\n } else {\n sbr->spectrum_params.bs_freq_scale = 2;\n sbr->spectrum_params.bs_alter_scale = 1;\n sbr->spectrum_params.bs_noise_bands = 2;\n }\n if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)))\n sbr->reset = 1;\n if (bs_header_extra_2) {\n sbr->bs_limiter_bands = get_bits(gb, 2);\n sbr->bs_limiter_gains = get_bits(gb, 2);\n sbr->bs_interpol_freq = get_bits1(gb);\n sbr->bs_smoothing_mode = get_bits1(gb);\n } else {\n sbr->bs_limiter_bands = 2;\n sbr->bs_limiter_gains = 2;\n sbr->bs_interpol_freq = 1;\n sbr->bs_smoothing_mode = 1;\n }\n if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset)\n sbr_make_f_tablelim(sbr);\n return get_bits_count(gb) - cnt;\n}', 'static void sbr_make_f_tablelim(SpectralBandReplication *sbr)\n{\n int k;\n if (sbr->bs_limiter_bands > 0) {\n static const float bands_warped[3] = { 1.32715174233856803909f,\n 1.18509277094158210129f,\n 1.11987160404675912501f };\n const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1];\n int16_t patch_borders[7];\n uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim;\n patch_borders[0] = sbr->kx[1];\n for (k = 1; k <= sbr->num_patches; k++)\n patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1];\n memcpy(sbr->f_tablelim, sbr->f_tablelow,\n (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0]));\n if (sbr->num_patches > 1)\n memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1,\n (sbr->num_patches - 1) * sizeof(patch_borders[0]));\n qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0],\n sizeof(sbr->f_tablelim[0]),\n qsort_comparison_function_int16);\n sbr->n_lim = sbr->n[0] + sbr->num_patches - 1;\n while (out < sbr->f_tablelim + sbr->n_lim) {\n if (*in >= *out * lim_bands_per_octave_warped) {\n *++out = *in++;\n } else if (*in == *out ||\n !in_table_int16(patch_borders, sbr->num_patches, *in)) {\n in++;\n sbr->n_lim--;\n } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) {\n *out = *in++;\n sbr->n_lim--;\n } else {\n *++out = *in++;\n }\n }\n } else {\n sbr->f_tablelim[0] = sbr->f_tablelow[0];\n sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]];\n sbr->n_lim = 1;\n }\n}']
36,183
0
https://github.com/libav/libav/blob/a158446b2842143a1ea0a284952571435c9ad3c4/libavcodec/wmv2enc.c/#L48
static int encode_ext_header(Wmv2Context *w){ MpegEncContext * const s= &w->s; PutBitContext pb; int code; init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size); put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047)); put_bits(&pb, 1, w->mspel_bit=1); put_bits(&pb, 1, s->loop_filter); put_bits(&pb, 1, w->abt_flag=1); put_bits(&pb, 1, w->j_type_bit=1); put_bits(&pb, 1, w->top_left_mv_flag=0); put_bits(&pb, 1, w->per_mb_rl_bit=1); put_bits(&pb, 3, code=1); flush_put_bits(&pb); s->slice_height = s->mb_height / code; return 0; }
['static int encode_ext_header(Wmv2Context *w){\n MpegEncContext * const s= &w->s;\n PutBitContext pb;\n int code;\n init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size);\n put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num);\n put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047));\n put_bits(&pb, 1, w->mspel_bit=1);\n put_bits(&pb, 1, s->loop_filter);\n put_bits(&pb, 1, w->abt_flag=1);\n put_bits(&pb, 1, w->j_type_bit=1);\n put_bits(&pb, 1, w->top_left_mv_flag=0);\n put_bits(&pb, 1, w->per_mb_rl_bit=1);\n put_bits(&pb, 3, code=1);\n flush_put_bits(&pb);\n s->slice_height = s->mb_height / code;\n return 0;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)\n{\n if(buffer_size < 0) {\n buffer_size = 0;\n buffer = NULL;\n }\n s->size_in_bits= 8*buffer_size;\n s->buf = buffer;\n s->buf_end = s->buf + buffer_size;\n#ifdef ALT_BITSTREAM_WRITER\n s->index=0;\n ((uint32_t*)(s->buf))[0]=0;\n#else\n s->buf_ptr = s->buf;\n s->bit_left=32;\n s->bit_buf=0;\n#endif\n}', 'static inline void put_bits(PutBitContext *s, int n, unsigned int value)\n#ifndef ALT_BITSTREAM_WRITER\n{\n unsigned int bit_buf;\n int bit_left;\n assert(n <= 31 && value < (1U << n));\n bit_buf = s->bit_buf;\n bit_left = s->bit_left;\n#ifdef BITSTREAM_WRITER_LE\n bit_buf |= value << (32 - bit_left);\n if (n >= bit_left) {\n#if !HAVE_FAST_UNALIGNED\n if (3 & (intptr_t) s->buf_ptr) {\n AV_WL32(s->buf_ptr, bit_buf);\n } else\n#endif\n *(uint32_t *)s->buf_ptr = le2me_32(bit_buf);\n s->buf_ptr+=4;\n bit_buf = (bit_left==32)?0:value >> bit_left;\n bit_left+=32;\n }\n bit_left-=n;\n#else\n if (n < bit_left) {\n bit_buf = (bit_buf<<n) | value;\n bit_left-=n;\n } else {\n bit_buf<<=bit_left;\n bit_buf |= value >> (n - bit_left);\n#if !HAVE_FAST_UNALIGNED\n if (3 & (intptr_t) s->buf_ptr) {\n AV_WB32(s->buf_ptr, bit_buf);\n } else\n#endif\n *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);\n s->buf_ptr+=4;\n bit_left+=32 - n;\n bit_buf = value;\n }\n#endif\n s->bit_buf = bit_buf;\n s->bit_left = bit_left;\n}', 'static inline void flush_put_bits(PutBitContext *s)\n{\n#ifdef ALT_BITSTREAM_WRITER\n align_put_bits(s);\n#else\n#ifndef BITSTREAM_WRITER_LE\n s->bit_buf<<= s->bit_left;\n#endif\n while (s->bit_left < 32) {\n#ifdef BITSTREAM_WRITER_LE\n *s->buf_ptr++=s->bit_buf;\n s->bit_buf>>=8;\n#else\n *s->buf_ptr++=s->bit_buf >> 24;\n s->bit_buf<<=8;\n#endif\n s->bit_left+=8;\n }\n s->bit_left=32;\n s->bit_buf=0;\n#endif\n}']
36,184
0
https://github.com/openssl/openssl/blob/3a160f1dc6c312495d65fdfabd8f86c0071975c2/apps/apps.c/#L1406
char *make_config_name() { const char *t=X509_get_default_cert_area(); size_t len; char *p; len=strlen(t)+strlen(OPENSSL_CONF)+2; p=OPENSSL_malloc(len); BUF_strlcpy(p,t,len); #ifndef OPENSSL_SYS_VMS BUF_strlcat(p,"/",len); #endif BUF_strlcat(p,OPENSSL_CONF,len); return p; }
['char *make_config_name()\n\t{\n\tconst char *t=X509_get_default_cert_area();\n\tsize_t len;\n\tchar *p;\n\tlen=strlen(t)+strlen(OPENSSL_CONF)+2;\n\tp=OPENSSL_malloc(len);\n\tBUF_strlcpy(p,t,len);\n#ifndef OPENSSL_SYS_VMS\n\tBUF_strlcat(p,"/",len);\n#endif\n\tBUF_strlcat(p,OPENSSL_CONF,len);\n\treturn p;\n\t}', 'const char *X509_get_default_cert_area(void)\n\t{ return(X509_CERT_AREA); }', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'size_t BUF_strlcat(char *dst, const char *src, size_t size)\n\t{\n\tsize_t l = 0;\n\tfor(; size > 0 && *dst; size--, dst++)\n\t\tl++;\n\treturn l + BUF_strlcpy(dst, src, size);\n\t}']
36,185
0
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_ctx.c/#L273
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['static int ecp_nistz256_points_mul(const EC_GROUP *group,\n EC_POINT *r,\n const BIGNUM *scalar,\n size_t num,\n const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n int i = 0, ret = 0, no_precomp_for_generator = 0, p_is_infinity = 0;\n size_t j;\n unsigned char p_str[33] = { 0 };\n const PRECOMP256_ROW *preComputedTable = NULL;\n const NISTZ256_PRE_COMP *pre_comp = NULL;\n const EC_POINT *generator = NULL;\n BN_CTX *new_ctx = NULL;\n const BIGNUM **new_scalars = NULL;\n const EC_POINT **new_points = NULL;\n unsigned int idx = 0;\n const unsigned int window_size = 7;\n const unsigned int mask = (1 << (window_size + 1)) - 1;\n unsigned int wvalue;\n ALIGN32 union {\n P256_POINT p;\n P256_POINT_AFFINE a;\n } t, p;\n BIGNUM *tmp_scalar;\n if ((num + 1) == 0 || (num + 1) > OPENSSL_MALLOC_MAX_NELEMS(void *)) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n if (group->meth != r->meth) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if ((scalar == NULL) && (num == 0))\n return EC_POINT_set_to_infinity(group, r);\n for (j = 0; j < num; j++) {\n if (group->meth != points[j]->meth) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n }\n BN_CTX_start(ctx);\n if (scalar) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.nistz256;\n if (pre_comp) {\n EC_POINT *pre_comp_generator = EC_POINT_new(group);\n if (pre_comp_generator == NULL)\n goto err;\n if (!ecp_nistz256_set_from_affine(pre_comp_generator,\n group, pre_comp->precomp[0],\n ctx)) {\n EC_POINT_free(pre_comp_generator);\n goto err;\n }\n if (0 == EC_POINT_cmp(group, generator, pre_comp_generator, ctx))\n preComputedTable = (const PRECOMP256_ROW *)pre_comp->precomp;\n EC_POINT_free(pre_comp_generator);\n }\n if (preComputedTable == NULL && ecp_nistz256_is_affine_G(generator)) {\n preComputedTable = ecp_nistz256_precomputed;\n }\n if (preComputedTable) {\n if ((BN_num_bits(scalar) > 256)\n || BN_is_negative(scalar)) {\n if ((tmp_scalar = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_nnmod(tmp_scalar, scalar, group->order, ctx)) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_BN_LIB);\n goto err;\n }\n scalar = tmp_scalar;\n }\n for (i = 0; i < bn_get_top(scalar) * BN_BYTES; i += BN_BYTES) {\n BN_ULONG d = bn_get_words(scalar)[i / BN_BYTES];\n p_str[i + 0] = (unsigned char)d;\n p_str[i + 1] = (unsigned char)(d >> 8);\n p_str[i + 2] = (unsigned char)(d >> 16);\n p_str[i + 3] = (unsigned char)(d >>= 24);\n if (BN_BYTES == 8) {\n d >>= 8;\n p_str[i + 4] = (unsigned char)d;\n p_str[i + 5] = (unsigned char)(d >> 8);\n p_str[i + 6] = (unsigned char)(d >> 16);\n p_str[i + 7] = (unsigned char)(d >> 24);\n }\n }\n for (; i < 33; i++)\n p_str[i] = 0;\n#if defined(ECP_NISTZ256_AVX2)\n if (ecp_nistz_avx2_eligible()) {\n ecp_nistz256_avx2_mul_g(&p.p, p_str, preComputedTable);\n } else\n#endif\n {\n BN_ULONG infty;\n wvalue = (p_str[0] << 1) & mask;\n idx += window_size;\n wvalue = _booth_recode_w7(wvalue);\n ecp_nistz256_gather_w7(&p.a, preComputedTable[0],\n wvalue >> 1);\n ecp_nistz256_neg(p.p.Z, p.p.Y);\n copy_conditional(p.p.Y, p.p.Z, wvalue & 1);\n infty = (p.p.X[0] | p.p.X[1] | p.p.X[2] | p.p.X[3] |\n p.p.Y[0] | p.p.Y[1] | p.p.Y[2] | p.p.Y[3]);\n if (P256_LIMBS == 8)\n infty |= (p.p.X[4] | p.p.X[5] | p.p.X[6] | p.p.X[7] |\n p.p.Y[4] | p.p.Y[5] | p.p.Y[6] | p.p.Y[7]);\n infty = 0 - is_zero(infty);\n infty = ~infty;\n p.p.Z[0] = ONE[0] & infty;\n p.p.Z[1] = ONE[1] & infty;\n p.p.Z[2] = ONE[2] & infty;\n p.p.Z[3] = ONE[3] & infty;\n if (P256_LIMBS == 8) {\n p.p.Z[4] = ONE[4] & infty;\n p.p.Z[5] = ONE[5] & infty;\n p.p.Z[6] = ONE[6] & infty;\n p.p.Z[7] = ONE[7] & infty;\n }\n for (i = 1; i < 37; i++) {\n unsigned int off = (idx - 1) / 8;\n wvalue = p_str[off] | p_str[off + 1] << 8;\n wvalue = (wvalue >> ((idx - 1) % 8)) & mask;\n idx += window_size;\n wvalue = _booth_recode_w7(wvalue);\n ecp_nistz256_gather_w7(&t.a,\n preComputedTable[i], wvalue >> 1);\n ecp_nistz256_neg(t.p.Z, t.a.Y);\n copy_conditional(t.a.Y, t.p.Z, wvalue & 1);\n ecp_nistz256_point_add_affine(&p.p, &p.p, &t.a);\n }\n }\n } else {\n p_is_infinity = 1;\n no_precomp_for_generator = 1;\n }\n } else\n p_is_infinity = 1;\n if (no_precomp_for_generator) {\n new_scalars = OPENSSL_malloc((num + 1) * sizeof(BIGNUM *));\n if (new_scalars == NULL) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n new_points = OPENSSL_malloc((num + 1) * sizeof(EC_POINT *));\n if (new_points == NULL) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(new_scalars, scalars, num * sizeof(BIGNUM *));\n new_scalars[num] = scalar;\n memcpy(new_points, points, num * sizeof(EC_POINT *));\n new_points[num] = generator;\n scalars = new_scalars;\n points = new_points;\n num++;\n }\n if (num) {\n P256_POINT *out = &t.p;\n if (p_is_infinity)\n out = &p.p;\n if (!ecp_nistz256_windowed_mul(group, out, scalars, points, num, ctx))\n goto err;\n if (!p_is_infinity)\n ecp_nistz256_point_add(&p.p, &p.p, out);\n }\n if (!bn_set_words(r->X, p.p.X, P256_LIMBS) ||\n !bn_set_words(r->Y, p.p.Y, P256_LIMBS) ||\n !bn_set_words(r->Z, p.p.Z, P256_LIMBS)) {\n goto err;\n }\n r->Z_is_one = is_one(r->Z) & 1;\n ret = 1;\nerr:\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n OPENSSL_free(new_points);\n OPENSSL_free(new_scalars);\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}', '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}']
36,186
0
https://github.com/openssl/openssl/blob/d4f63f1c39c3908cd81fda07448144bafb9aba4a/test/evp_test.c/#L493
static int cipher_test_init(EVP_TEST *t, const char *alg) { const EVP_CIPHER *cipher; CIPHER_DATA *cdat; int m; if ((cipher = EVP_get_cipherbyname(alg)) == NULL) { if (OBJ_sn2nid(alg) != NID_undef || OBJ_ln2nid(alg) != NID_undef) { t->skip = 1; return 1; } return 0; } cdat = OPENSSL_zalloc(sizeof(*cdat)); cdat->cipher = cipher; cdat->enc = -1; m = EVP_CIPHER_mode(cipher); if (m == EVP_CIPH_GCM_MODE || m == EVP_CIPH_OCB_MODE || m == EVP_CIPH_SIV_MODE || m == EVP_CIPH_CCM_MODE) cdat->aead = m; else if (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER) cdat->aead = -1; else cdat->aead = 0; t->data = cdat; return 1; }
['static int cipher_test_init(EVP_TEST *t, const char *alg)\n{\n const EVP_CIPHER *cipher;\n CIPHER_DATA *cdat;\n int m;\n if ((cipher = EVP_get_cipherbyname(alg)) == NULL) {\n if (OBJ_sn2nid(alg) != NID_undef || OBJ_ln2nid(alg) != NID_undef) {\n t->skip = 1;\n return 1;\n }\n return 0;\n }\n cdat = OPENSSL_zalloc(sizeof(*cdat));\n cdat->cipher = cipher;\n cdat->enc = -1;\n m = EVP_CIPHER_mode(cipher);\n if (m == EVP_CIPH_GCM_MODE\n || m == EVP_CIPH_OCB_MODE\n || m == EVP_CIPH_SIV_MODE\n || m == EVP_CIPH_CCM_MODE)\n cdat->aead = m;\n else if (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_AEAD_CIPHER)\n cdat->aead = -1;\n else\n cdat->aead = 0;\n t->data = cdat;\n return 1;\n}', 'const EVP_CIPHER *EVP_get_cipherbyname(const char *name)\n{\n const EVP_CIPHER *cp;\n if (!OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS, NULL))\n return NULL;\n cp = (const EVP_CIPHER *)OBJ_NAME_get(name, OBJ_NAME_TYPE_CIPHER_METH);\n return cp;\n}', 'const char *OBJ_NAME_get(const char *name, int type)\n{\n OBJ_NAME on, *ret;\n int num = 0, alias;\n const char *value = NULL;\n if (name == NULL)\n return NULL;\n if (!OBJ_NAME_init())\n return NULL;\n CRYPTO_THREAD_read_lock(obj_lock);\n alias = type & OBJ_NAME_ALIAS;\n type &= ~OBJ_NAME_ALIAS;\n on.name = name;\n on.type = type;\n for (;;) {\n ret = lh_OBJ_NAME_retrieve(names_lh, &on);\n if (ret == NULL)\n break;\n if ((ret->alias) && !alias) {\n if (++num > 10)\n break;\n on.name = ret->data;\n } else {\n value = ret->data;\n break;\n }\n }\n CRYPTO_THREAD_unlock(obj_lock);\n return value;\n}', 'int OBJ_NAME_init(void)\n{\n return RUN_ONCE(&init, o_names_init);\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_rdlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_lock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', 'void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE **rn;\n void *ret;\n tsan_store((TSAN_QUALIFIER int *)&lh->error, 0);\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n tsan_counter(&lh->num_retrieve_miss);\n return NULL;\n } else {\n ret = (*rn)->data;\n tsan_counter(&lh->num_retrieve);\n }\n return ret;\n}', 'int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_unlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_unlock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#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}']
36,187
0
https://github.com/openssl/openssl/blob/985de8634000df9b33b8ac4519fa10a99e43b314/crypto/x509/x509_lu.c/#L298
int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, X509_OBJECT *ret) { X509_STORE *ctx=vs->ctx; X509_LOOKUP *lu; X509_OBJECT stmp,*tmp; int i,j; tmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name); if (tmp == NULL || type == X509_LU_CRL) { for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++) { lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i); j=X509_LOOKUP_by_subject(lu,type,name,&stmp); if (j < 0) { vs->current_method=j; return j; } else if (j) { tmp= &stmp; break; } } vs->current_method=0; if (tmp == NULL) return 0; } ret->type=tmp->type; ret->data.ptr=tmp->data.ptr; X509_OBJECT_up_ref_count(ret); return 1; }
['int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,\n\t X509_OBJECT *ret)\n\t{\n\tX509_STORE *ctx=vs->ctx;\n\tX509_LOOKUP *lu;\n\tX509_OBJECT stmp,*tmp;\n\tint i,j;\n\ttmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name);\n\tif (tmp == NULL || type == X509_LU_CRL)\n\t\t{\n\t\tfor (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)\n\t\t\t{\n\t\t\tlu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);\n\t\t\tj=X509_LOOKUP_by_subject(lu,type,name,&stmp);\n\t\t\tif (j < 0)\n\t\t\t\t{\n\t\t\t\tvs->current_method=j;\n\t\t\t\treturn j;\n\t\t\t\t}\n\t\t\telse if (j)\n\t\t\t\t{\n\t\t\t\ttmp= &stmp;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tvs->current_method=0;\n\t\tif (tmp == NULL)\n\t\t\treturn 0;\n\t\t}\n\tret->type=tmp->type;\n\tret->data.ptr=tmp->data.ptr;\n\tX509_OBJECT_up_ref_count(ret);\n\treturn 1;\n\t}', 'X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type,\n\t X509_NAME *name)\n{\n\tint idx;\n\tidx = X509_OBJECT_idx_by_subject(h, type, name);\n\tif (idx==-1) return NULL;\n\treturn sk_X509_OBJECT_value(h, idx);\n}', 'int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,\n\t X509_NAME *name)\n\t{\n\treturn x509_object_idx_cnt(h, type, name, NULL);\n\t}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}', 'int sk_num(const _STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,\n\t X509_OBJECT *ret)\n\t{\n\tif ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))\n\t\treturn X509_LU_FAIL;\n\tif (ctx->skip) return 0;\n\treturn ctx->method->get_by_subject(ctx,type,name,ret);\n\t}']
36,188
1
https://github.com/openssl/openssl/blob/3da2e9c4ee45989a426ff513dc6c6250d1e460de/crypto/bn/bn_shift.c/#L112
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return 0; r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return 1; }
['BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)\n{\n#ifndef BN_LLONG\n BN_ULONG ret = 0;\n#else\n BN_ULLONG ret = 0;\n#endif\n int i;\n if (w == 0)\n return (BN_ULONG)-1;\n#ifndef BN_LLONG\n if (w > ((BN_ULONG)1 << BN_BITS4)) {\n BIGNUM *tmp = BN_dup(a);\n if (tmp == NULL)\n return (BN_ULONG)-1;\n ret = BN_div_word(tmp, w);\n BN_free(tmp);\n return ret;\n }\n#endif\n bn_check_top(a);\n w &= BN_MASK2;\n for (i = a->top - 1; i >= 0; i--) {\n#ifndef BN_LLONG\n ret = ((ret << BN_BITS4) | ((a->d[i] >> BN_BITS4) & BN_MASK2l)) % w;\n ret = ((ret << BN_BITS4) | (a->d[i] & BN_MASK2l)) % w;\n#else\n ret = (BN_ULLONG) (((ret << (BN_ULLONG) BN_BITS2) | a->d[i]) %\n (BN_ULLONG) w);\n#endif\n }\n return (BN_ULONG)ret;\n}', 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n BIGNUM *t;\n if (a == NULL)\n return NULL;\n bn_check_top(a);\n t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n if (t == NULL)\n return NULL;\n if (!BN_copy(t, a)) {\n BN_free(t);\n return NULL;\n }\n bn_check_top(t);\n return t;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)\n{\n BN_ULONG ret = 0;\n int i, j;\n bn_check_top(a);\n w &= BN_MASK2;\n if (!w)\n return (BN_ULONG)-1;\n if (a->top == 0)\n return 0;\n j = BN_BITS2 - BN_num_bits_word(w);\n w <<= j;\n if (!BN_lshift(a, a, j))\n return (BN_ULONG)-1;\n for (i = a->top - 1; i >= 0; i--) {\n BN_ULONG l, d;\n l = a->d[i];\n d = bn_div_words(ret, l, w);\n ret = (l - ((d * w) & BN_MASK2)) & BN_MASK2;\n a->d[i] = d;\n }\n if ((a->top > 0) && (a->d[a->top - 1] == 0))\n a->top--;\n ret >>= j;\n if (!a->top)\n a->neg = 0;\n bn_check_top(a);\n return ret;\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}']
36,189
0
https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/crypto/bn/bn_shift.c/#L112
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) { int i, nw, lb, rb; BN_ULONG *t, *f; BN_ULONG l; bn_check_top(r); bn_check_top(a); if (n < 0) { BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT); return 0; } nw = n / BN_BITS2; if (bn_wexpand(r, a->top + nw + 1) == NULL) return (0); r->neg = a->neg; lb = n % BN_BITS2; rb = BN_BITS2 - lb; f = a->d; t = r->d; t[a->top + nw] = 0; if (lb == 0) for (i = a->top - 1; i >= 0; i--) t[nw + i] = f[i]; else for (i = a->top - 1; i >= 0; i--) { l = f[i]; t[nw + i + 1] |= (l >> rb) & BN_MASK2; t[nw + i] = (l << lb) & BN_MASK2; } memset(t, 0, sizeof(*t) * nw); r->top = a->top + nw + 1; bn_correct_top(r); bn_check_top(r); return (1); }
['int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_add(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int a_neg = a->neg, ret;\n bn_check_top(a);\n bn_check_top(b);\n if (a_neg ^ b->neg) {\n if (a_neg) {\n const BIGNUM *tmp;\n tmp = a;\n a = b;\n b = tmp;\n }\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 return 1;\n }\n ret = BN_uadd(r, a, b);\n r->neg = a_neg;\n bn_check_top(r);\n return ret;\n}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int max, min, dif;\n BN_ULONG t1, t2, borrow, *rp;\n const BN_ULONG *ap, *bp;\n bn_check_top(a);\n bn_check_top(b);\n max = a->top;\n min = b->top;\n dif = max - min;\n if (dif < 0) {\n BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);\n return 0;\n }\n if (bn_wexpand(r, max) == NULL)\n return 0;\n ap = a->d;\n bp = b->d;\n rp = r->d;\n borrow = bn_sub_words(rp, ap, bp, min);\n ap += min;\n rp += min;\n while (dif) {\n dif--;\n t1 = *(ap++);\n t2 = (t1 - borrow) & BN_MASK2;\n *(rp++) = t2;\n borrow &= (t1 == 0);\n }\n r->top = max;\n r->neg = 0;\n bn_correct_top(r);\n return 1;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n 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}']
36,190
0
https://github.com/openssl/openssl/blob/a4af39ac4482355ffdd61fb61231a0c79b96997b/crypto/pkcs12/p12_npas.c/#L136
static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) { STACK *asafes, *newsafes, *bags; int i, bagnid, pbe_nid, pbe_iter, pbe_saltlen; PKCS7 *p7, *p7new; ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL; unsigned char mac[EVP_MAX_MD_SIZE]; unsigned int maclen; if (!(asafes = M_PKCS12_unpack_authsafes(p12))) return 0; if(!(newsafes = sk_new(NULL))) return 0; for (i = 0; i < sk_num (asafes); i++) { p7 = (PKCS7 *) sk_value(asafes, i); bagnid = OBJ_obj2nid(p7->type); if (bagnid == NID_pkcs7_data) { bags = M_PKCS12_unpack_p7data(p7); } else if (bagnid == NID_pkcs7_encrypted) { bags = M_PKCS12_unpack_p7encdata(p7, oldpass, -1); alg_get(p7->d.encrypted->enc_data->algorithm, &pbe_nid, &pbe_iter, &pbe_saltlen); } else continue; if (!bags) { sk_pop_free(asafes, PKCS7_free); return 0; } if (!newpass_bags(bags, oldpass, newpass)) { sk_pop_free(bags, PKCS12_SAFEBAG_free); sk_pop_free(asafes, PKCS7_free); return 0; } if (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags); else p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL, pbe_saltlen, pbe_iter, bags); sk_pop_free(bags, PKCS12_SAFEBAG_free); if(!p7new) { sk_pop_free(asafes, PKCS7_free); return 0; } sk_push(newsafes, (char *)p7new); } sk_pop_free(asafes, PKCS7_free); p12_data_tmp = p12->authsafes->d.data; if(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr; if(!M_PKCS12_pack_authsafes(p12, newsafes)) goto saferr; if(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr; if(!(macnew = ASN1_OCTET_STRING_new())) goto saferr; if(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr; ASN1_OCTET_STRING_free(p12->mac->dinfo->digest); p12->mac->dinfo->digest = macnew; ASN1_OCTET_STRING_free(p12_data_tmp); return 1; saferr: ASN1_OCTET_STRING_free(p12->authsafes->d.data); ASN1_OCTET_STRING_free(macnew); p12->authsafes->d.data = p12_data_tmp; return 0; }
['static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass)\n{\n\tSTACK *asafes, *newsafes, *bags;\n\tint i, bagnid, pbe_nid, pbe_iter, pbe_saltlen;\n\tPKCS7 *p7, *p7new;\n\tASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL;\n\tunsigned char mac[EVP_MAX_MD_SIZE];\n\tunsigned int maclen;\n\tif (!(asafes = M_PKCS12_unpack_authsafes(p12))) return 0;\n\tif(!(newsafes = sk_new(NULL))) return 0;\n\tfor (i = 0; i < sk_num (asafes); i++) {\n\t\tp7 = (PKCS7 *) sk_value(asafes, i);\n\t\tbagnid = OBJ_obj2nid(p7->type);\n\t\tif (bagnid == NID_pkcs7_data) {\n\t\t\tbags = M_PKCS12_unpack_p7data(p7);\n\t\t} else if (bagnid == NID_pkcs7_encrypted) {\n\t\t\tbags = M_PKCS12_unpack_p7encdata(p7, oldpass, -1);\n\t\t\talg_get(p7->d.encrypted->enc_data->algorithm,\n\t\t\t\t&pbe_nid, &pbe_iter, &pbe_saltlen);\n\t\t} else continue;\n\t\tif (!bags) {\n\t\t\tsk_pop_free(asafes, PKCS7_free);\n\t\t\treturn 0;\n\t\t}\n\t \tif (!newpass_bags(bags, oldpass, newpass)) {\n\t\t\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\t\t\tsk_pop_free(asafes, PKCS7_free);\n\t\t\treturn 0;\n\t\t}\n\t\tif (bagnid == NID_pkcs7_data) p7new = PKCS12_pack_p7data(bags);\n\t\telse p7new = PKCS12_pack_p7encdata(pbe_nid, newpass, -1, NULL,\n\t\t\t\t\t\t pbe_saltlen, pbe_iter, bags);\n\t\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\t\tif(!p7new) {\n\t\t\tsk_pop_free(asafes, PKCS7_free);\n\t\t\treturn 0;\n\t\t}\n\t\tsk_push(newsafes, (char *)p7new);\n\t}\n\tsk_pop_free(asafes, PKCS7_free);\n\tp12_data_tmp = p12->authsafes->d.data;\n\tif(!(p12->authsafes->d.data = ASN1_OCTET_STRING_new())) goto saferr;\n\tif(!M_PKCS12_pack_authsafes(p12, newsafes)) goto saferr;\n\tif(!PKCS12_gen_mac(p12, newpass, -1, mac, &maclen)) goto saferr;\n\tif(!(macnew = ASN1_OCTET_STRING_new())) goto saferr;\n\tif(!ASN1_OCTET_STRING_set(macnew, mac, maclen)) goto saferr;\n\tASN1_OCTET_STRING_free(p12->mac->dinfo->digest);\n\tp12->mac->dinfo->digest = macnew;\n\tASN1_OCTET_STRING_free(p12_data_tmp);\n\treturn 1;\n\tsaferr:\n\tASN1_OCTET_STRING_free(p12->authsafes->d.data);\n\tASN1_OCTET_STRING_free(macnew);\n\tp12->authsafes->d.data = p12_data_tmp;\n\treturn 0;\n}']
36,191
0
https://github.com/openssl/openssl/blob/54d00677f305375eee65a0c9edb5f0980c5f020f/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 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 (!group->meth->field_inv(group, Z_1, Z_, 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_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int 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}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
36,192
0
https://github.com/libav/libav/blob/fd7f59639c43f0ab6b83ad2c1ceccafc553d7845/libavcodec/vorbis_enc.c/#L169
static void ready_codebook(vorbis_enc_codebook * cb) { int i; ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); if (!cb->lookup) cb->pow2 = cb->dimentions = NULL; else { int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); for (i = 0; i < cb->nentries; i++) { float last = 0; int j; int div = 1; for (j = 0; j < cb->ndimentions; j++) { int off; if (cb->lookup == 1) off = (i / div) % vals; else off = i * cb->ndimentions + j; cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta; if (cb->seq_p) last = cb->dimentions[i * cb->ndimentions + j]; cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j]*cb->dimentions[i * cb->ndimentions + j]; div *= vals; } cb->pow2[i] /= 2.; } } }
['static void ready_codebook(vorbis_enc_codebook * cb) {\n int i;\n ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries);\n if (!cb->lookup)\n cb->pow2 = cb->dimentions = NULL;\n else {\n int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries);\n cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions);\n cb->pow2 = av_mallocz(sizeof(float) * cb->nentries);\n for (i = 0; i < cb->nentries; i++) {\n float last = 0;\n int j;\n int div = 1;\n for (j = 0; j < cb->ndimentions; j++) {\n int off;\n if (cb->lookup == 1)\n off = (i / div) % vals;\n else\n off = i * cb->ndimentions + j;\n cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta;\n if (cb->seq_p)\n last = cb->dimentions[i * cb->ndimentions + j];\n cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j]*cb->dimentions[i * cb->ndimentions + j];\n div *= vals;\n }\n cb->pow2[i] /= 2.;\n }\n }\n}', 'static int cb_lookup_vals(int lookup, int dimentions, int entries) {\n if (lookup == 1) return ff_vorbis_nth_root(entries, dimentions);\n else if (lookup == 2) return dimentions * entries;\n return 0;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\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_POSIX_MEMALIGN)\n posix_memalign(&ptr,16,size);\n#elif defined (HAVE_MEMALIGN)\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}']
36,193
0
https://github.com/openssl/openssl/blob/61f5b6f33807306d09bccbc2dcad474d1d04ca40/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); }
['DSA *get_dsa512()\n\t{\n\tDSA *dsa;\n\tif ((dsa=DSA_new()) == NULL) return(NULL);\n\tdsa->p=BN_bin2bn(dsa512_p,sizeof(dsa512_p),NULL);\n\tdsa->q=BN_bin2bn(dsa512_q,sizeof(dsa512_q),NULL);\n\tdsa->g=BN_bin2bn(dsa512_g,sizeof(dsa512_g),NULL);\n\tif ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))\n\t\treturn(NULL);\n\treturn(dsa);\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}']
36,194
0
https://github.com/openssl/openssl/blob/d858c87653257185ead1c5baf3d84cd7276dd912/crypto/rsa/rsa_pk1.c/#L131
int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen, const unsigned char *from, int flen, int num) { int i, j; const unsigned char *p; p = from; if (num < 11) return -1; if (num == flen) { if ((*p++) != 0x00) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_INVALID_PADDING); return -1; } flen--; } if ((num != (flen + 1)) || (*(p++) != 0x01)) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_BLOCK_TYPE_IS_NOT_01); return (-1); } j = flen - 1; for (i = 0; i < j; i++) { if (*p != 0xff) { if (*p == 0) { p++; break; } else { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_BAD_FIXED_HEADER_DECRYPT); return (-1); } } p++; } if (i == j) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_NULL_BEFORE_BLOCK_MISSING); return (-1); } if (i < 8) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_BAD_PAD_BYTE_COUNT); return (-1); } i++; j -= i; if (j > tlen) { RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_DATA_TOO_LARGE); return (-1); } memcpy(to, p, (unsigned int)j); return (j); }
['static int rsa_ossl_public_decrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret;\n int i, num = 0, r = -1;\n unsigned char *p;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n if (BN_ucmp(rsa->n, rsa->e) <= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {\n if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n }\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (f == NULL || ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (flen > num) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_DATA_GREATER_THAN_MOD_LEN);\n goto err;\n }\n if (BN_bin2bn(from, flen, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))\n goto err;\n if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n if ((padding == RSA_X931_PADDING) && ((bn_get_words(ret)[0] & 0xf) != 12))\n if (!BN_sub(ret, rsa->n, ret))\n goto err;\n p = buf;\n i = BN_bn2bin(ret, p);\n switch (padding) {\n case RSA_PKCS1_PADDING:\n r = RSA_padding_check_PKCS1_type_1(to, num, buf, i, num);\n break;\n case RSA_X931_PADDING:\n r = RSA_padding_check_X931(to, num, buf, i, num);\n break;\n case RSA_NO_PADDING:\n r = RSA_padding_check_none(to, num, buf, i, num);\n break;\n default:\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (r < 0)\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED);\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return (r);\n}', '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}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int RSA_padding_check_PKCS1_type_1(unsigned char *to, int tlen,\n const unsigned char *from, int flen,\n int num)\n{\n int i, j;\n const unsigned char *p;\n p = from;\n if (num < 11)\n return -1;\n if (num == flen) {\n if ((*p++) != 0x00) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n RSA_R_INVALID_PADDING);\n return -1;\n }\n flen--;\n }\n if ((num != (flen + 1)) || (*(p++) != 0x01)) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n RSA_R_BLOCK_TYPE_IS_NOT_01);\n return (-1);\n }\n j = flen - 1;\n for (i = 0; i < j; i++) {\n if (*p != 0xff) {\n if (*p == 0) {\n p++;\n break;\n } else {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n RSA_R_BAD_FIXED_HEADER_DECRYPT);\n return (-1);\n }\n }\n p++;\n }\n if (i == j) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n RSA_R_NULL_BEFORE_BLOCK_MISSING);\n return (-1);\n }\n if (i < 8) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1,\n RSA_R_BAD_PAD_BYTE_COUNT);\n return (-1);\n }\n i++;\n j -= i;\n if (j > tlen) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_1, RSA_R_DATA_TOO_LARGE);\n return (-1);\n }\n memcpy(to, p, (unsigned int)j);\n return (j);\n}']
36,195
0
https://github.com/openssl/openssl/blob/47ddf355b46eae8c846e411f44531e928e04adf5/crypto/x509v3/v3_purp.c/#L121
int X509_check_purpose(X509 *x, int id, int ca) { int idx; const X509_PURPOSE *pt; if(!(x->ex_flags & EXFLAG_SET)) { CRYPTO_w_lock(CRYPTO_LOCK_X509); x509v3_cache_extensions(x); CRYPTO_w_unlock(CRYPTO_LOCK_X509); } if(id == -1) return 1; idx = X509_PURPOSE_get_by_id(id); if(idx == -1) return -1; pt = X509_PURPOSE_get0(idx); return pt->check_purpose(pt, x, ca); }
['int X509_check_purpose(X509 *x, int id, int ca)\n{\n\tint idx;\n\tconst X509_PURPOSE *pt;\n\tif(!(x->ex_flags & EXFLAG_SET)) {\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_X509);\n\t\tx509v3_cache_extensions(x);\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_X509);\n\t}\n\tif(id == -1) return 1;\n\tidx = X509_PURPOSE_get_by_id(id);\n\tif(idx == -1) return -1;\n\tpt = X509_PURPOSE_get0(idx);\n\treturn pt->check_purpose(pt, x, ca);\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tint i = -type - 1;\n\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t= CRYPTO_get_dynlock_value(i);\n\t\tif (pointer)\n\t\t\t{\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\t}\n\t\tCRYPTO_destroy_dynlockid(i);\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'static void x509v3_cache_extensions(X509 *x)\n{\n\tBASIC_CONSTRAINTS *bs;\n\tASN1_BIT_STRING *usage;\n\tASN1_BIT_STRING *ns;\n\tEXTENDED_KEY_USAGE *extusage;\n\tint i;\n\tif(x->ex_flags & EXFLAG_SET) return;\n#ifndef OPENSSL_NO_SHA\n\tX509_digest(x, EVP_sha1(), x->sha1_hash, NULL);\n#endif\n\tif(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))\n\t\t\t x->ex_flags |= EXFLAG_SS;\n\tif(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;\n\tif((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {\n\t\tif(bs->ca) x->ex_flags |= EXFLAG_CA;\n\t\tif(bs->pathlen) {\n\t\t\tif((bs->pathlen->type == V_ASN1_NEG_INTEGER)\n\t\t\t\t\t\t|| !bs->ca) {\n\t\t\t\tx->ex_flags |= EXFLAG_INVALID;\n\t\t\t\tx->ex_pathlen = 0;\n\t\t\t} else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);\n\t\t} else x->ex_pathlen = -1;\n\t\tBASIC_CONSTRAINTS_free(bs);\n\t\tx->ex_flags |= EXFLAG_BCONS;\n\t}\n\tif((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {\n\t\tif(usage->length > 0) {\n\t\t\tx->ex_kusage = usage->data[0];\n\t\t\tif(usage->length > 1)\n\t\t\t\tx->ex_kusage |= usage->data[1] << 8;\n\t\t} else x->ex_kusage = 0;\n\t\tx->ex_flags |= EXFLAG_KUSAGE;\n\t\tASN1_BIT_STRING_free(usage);\n\t}\n\tx->ex_xkusage = 0;\n\tif((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {\n\t\tx->ex_flags |= EXFLAG_XKUSAGE;\n\t\tfor(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {\n\t\t\tswitch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {\n\t\t\t\tcase NID_server_auth:\n\t\t\t\tx->ex_xkusage |= XKU_SSL_SERVER;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_client_auth:\n\t\t\t\tx->ex_xkusage |= XKU_SSL_CLIENT;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_email_protect:\n\t\t\t\tx->ex_xkusage |= XKU_SMIME;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_code_sign:\n\t\t\t\tx->ex_xkusage |= XKU_CODE_SIGN;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_ms_sgc:\n\t\t\t\tcase NID_ns_sgc:\n\t\t\t\tx->ex_xkusage |= XKU_SGC;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_OCSP_sign:\n\t\t\t\tx->ex_xkusage |= XKU_OCSP_SIGN;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_time_stamp:\n\t\t\t\tx->ex_xkusage |= XKU_TIMESTAMP;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);\n\t}\n\tif((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {\n\t\tif(ns->length > 0) x->ex_nscert = ns->data[0];\n\t\telse x->ex_nscert = 0;\n\t\tx->ex_flags |= EXFLAG_NSCERT;\n\t\tASN1_BIT_STRING_free(ns);\n\t}\n\tx->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);\n\tx->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);\n\tx->ex_flags |= EXFLAG_SET;\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n\tX509_PURPOSE tmp;\n\tint idx;\n\tif((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n\t\treturn purpose - X509_PURPOSE_MIN;\n\ttmp.purpose = purpose;\n\tif(!xptable) return -1;\n\tidx = sk_X509_PURPOSE_find(xptable, &tmp);\n\tif(idx == -1) return -1;\n\treturn idx + X509_PURPOSE_COUNT;\n}', 'X509_PURPOSE * X509_PURPOSE_get0(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_PURPOSE_COUNT) return xstandard + idx;\n\treturn sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']
36,196
0
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/h264.c/#L4066
static int decode_slice_header(H264Context *h, H264Context *h0){ MpegEncContext * const s = &h->s; MpegEncContext * const s0 = &h0->s; unsigned int first_mb_in_slice; unsigned int pps_id; int num_ref_idx_active_override_flag; static const uint8_t slice_type_map[5]= {FF_P_TYPE, FF_B_TYPE, FF_I_TYPE, FF_SP_TYPE, FF_SI_TYPE}; unsigned int slice_type, tmp, i, j; int default_ref_list_done = 0; int last_pic_structure; s->dropable= h->nal_ref_idc == 0; if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc){ s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; }else{ s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab; s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; } first_mb_in_slice= get_ue_golomb(&s->gb); if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){ h0->current_slice = 0; if (!s0->first_field) s->current_picture_ptr= NULL; } slice_type= get_ue_golomb(&s->gb); if(slice_type > 9){ av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); return -1; } if(slice_type > 4){ slice_type -= 5; h->slice_type_fixed=1; }else h->slice_type_fixed=0; slice_type= slice_type_map[ slice_type ]; if (slice_type == FF_I_TYPE || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) { default_ref_list_done = 1; } h->slice_type= slice_type; h->slice_type_nos= slice_type & 3; s->pict_type= h->slice_type; if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) { av_log(h->s.avctx, AV_LOG_ERROR, "B picture before any references, skipping\n"); return -1; } pps_id= get_ue_golomb(&s->gb); if(pps_id>=MAX_PPS_COUNT){ av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); return -1; } if(!h0->pps_buffers[pps_id]) { av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS referenced\n"); return -1; } h->pps= *h0->pps_buffers[pps_id]; if(!h0->sps_buffers[h->pps.sps_id]) { av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS referenced\n"); return -1; } h->sps = *h0->sps_buffers[h->pps.sps_id]; if(h == h0 && h->dequant_coeff_pps != pps_id){ h->dequant_coeff_pps = pps_id; init_dequant_tables(h); } s->mb_width= h->sps.mb_width; s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); h->b_stride= s->mb_width*4; h->b8_stride= s->mb_width*2; s->width = 16*s->mb_width - 2*FFMIN(h->sps.crop_right, 7); if(h->sps.frame_mbs_only_flag) s->height= 16*s->mb_height - 2*FFMIN(h->sps.crop_bottom, 7); else s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 3); if (s->context_initialized && ( s->width != s->avctx->width || s->height != s->avctx->height)) { if(h != h0) return -1; free_tables(h); MPV_common_end(s); } if (!s->context_initialized) { if(h != h0) return -1; if (MPV_common_init(s) < 0) return -1; s->first_field = 0; init_scan_tables(h); alloc_tables(h); for(i = 1; i < s->avctx->thread_count; i++) { H264Context *c; c = h->thread_context[i] = av_malloc(sizeof(H264Context)); memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); c->sps = h->sps; c->pps = h->pps; init_scan_tables(c); clone_tables(c, h); } for(i = 0; i < s->avctx->thread_count; i++) if(context_init(h->thread_context[i]) < 0) return -1; s->avctx->width = s->width; s->avctx->height = s->height; s->avctx->sample_aspect_ratio= h->sps.sar; if(!s->avctx->sample_aspect_ratio.den) s->avctx->sample_aspect_ratio.den = 1; if(h->sps.timing_info_present_flag){ s->avctx->time_base= (AVRational){h->sps.num_units_in_tick * 2, h->sps.time_scale}; if(h->x264_build > 0 && h->x264_build < 44) s->avctx->time_base.den *= 2; av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, s->avctx->time_base.num, s->avctx->time_base.den, 1<<30); } } h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); h->mb_mbaff = 0; h->mb_aff_frame = 0; last_pic_structure = s0->picture_structure; if(h->sps.frame_mbs_only_flag){ s->picture_structure= PICT_FRAME; }else{ if(get_bits1(&s->gb)) { s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); } else { s->picture_structure= PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } if(h0->current_slice == 0){ while(h->frame_num != h->prev_frame_num && h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){ av_log(NULL, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); frame_start(h); h->prev_frame_num++; h->prev_frame_num %= 1<<h->sps.log2_max_frame_num; s->current_picture_ptr->frame_num= h->prev_frame_num; execute_ref_pic_marking(h, NULL, 0); } if (s0->first_field) { assert(s0->current_picture_ptr); assert(s0->current_picture_ptr->data[0]); assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF); if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { s0->current_picture_ptr = NULL; s0->first_field = FIELD_PICTURE; } else { if (h->nal_ref_idc && s0->current_picture_ptr->reference && s0->current_picture_ptr->frame_num != h->frame_num) { s0->first_field = 1; s0->current_picture_ptr = NULL; } else { s0->first_field = 0; } } } else { assert(!s0->current_picture_ptr); s0->first_field = FIELD_PICTURE; } if((!FIELD_PICTURE || s0->first_field) && frame_start(h) < 0) { s0->first_field = 0; return -1; } } if(h != h0) clone_slice(h, h0); s->current_picture_ptr->frame_num= h->frame_num; assert(s->mb_num == s->mb_width * s->mb_height); if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num || first_mb_in_slice >= s->mb_num){ av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return -1; } s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width; s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE; if (s->picture_structure == PICT_BOTTOM_FIELD) s->resync_mb_y = s->mb_y = s->mb_y + 1; assert(s->mb_y < s->mb_height); if(s->picture_structure==PICT_FRAME){ h->curr_pic_num= h->frame_num; h->max_pic_num= 1<< h->sps.log2_max_frame_num; }else{ h->curr_pic_num= 2*h->frame_num + 1; h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); } if(h->nal_unit_type == NAL_IDR_SLICE){ get_ue_golomb(&s->gb); } if(h->sps.poc_type==0){ h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb); if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){ h->delta_poc_bottom= get_se_golomb(&s->gb); } } if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){ h->delta_poc[0]= get_se_golomb(&s->gb); if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME) h->delta_poc[1]= get_se_golomb(&s->gb); } init_poc(h); if(h->pps.redundant_pic_cnt_present){ h->redundant_pic_count= get_ue_golomb(&s->gb); } h->ref_count[0]= h->pps.ref_count[0]; h->ref_count[1]= h->pps.ref_count[1]; if(h->slice_type_nos != FF_I_TYPE){ if(h->slice_type_nos == FF_B_TYPE){ h->direct_spatial_mv_pred= get_bits1(&s->gb); } num_ref_idx_active_override_flag= get_bits1(&s->gb); if(num_ref_idx_active_override_flag){ h->ref_count[0]= get_ue_golomb(&s->gb) + 1; if(h->slice_type_nos==FF_B_TYPE) h->ref_count[1]= get_ue_golomb(&s->gb) + 1; if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){ av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); h->ref_count[0]= h->ref_count[1]= 1; return -1; } } if(h->slice_type_nos == FF_B_TYPE) h->list_count= 2; else h->list_count= 1; }else h->list_count= 0; if(!default_ref_list_done){ fill_default_ref_list(h); } if(h->slice_type_nos!=FF_I_TYPE && decode_ref_pic_list_reordering(h) < 0) return -1; if( (h->pps.weighted_pred && h->slice_type_nos == FF_P_TYPE ) || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) ) pred_weight_table(h); else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE) implicit_weight_table(h); else h->use_weight = 0; if(h->nal_ref_idc) decode_ref_pic_marking(h0, &s->gb); if(FRAME_MBAFF) fill_mbaff_ref_list(h); if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){ tmp = get_ue_golomb(&s->gb); if(tmp > 2){ av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); return -1; } h->cabac_init_idc= tmp; } h->last_qscale_diff = 0; tmp = h->pps.init_qp + get_se_golomb(&s->gb); if(tmp>51){ av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); return -1; } s->qscale= tmp; h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); if(h->slice_type == FF_SP_TYPE){ get_bits1(&s->gb); } if(h->slice_type==FF_SP_TYPE || h->slice_type == FF_SI_TYPE){ get_se_golomb(&s->gb); } h->deblocking_filter = 1; h->slice_alpha_c0_offset = 0; h->slice_beta_offset = 0; if( h->pps.deblocking_filter_parameters_present ) { tmp= get_ue_golomb(&s->gb); if(tmp > 2){ av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\n", tmp); return -1; } h->deblocking_filter= tmp; if(h->deblocking_filter < 2) h->deblocking_filter^= 1; if( h->deblocking_filter ) { h->slice_alpha_c0_offset = get_se_golomb(&s->gb) << 1; h->slice_beta_offset = get_se_golomb(&s->gb) << 1; } } if( s->avctx->skip_loop_filter >= AVDISCARD_ALL ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != FF_I_TYPE) ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == FF_B_TYPE) ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) h->deblocking_filter= 0; if(h->deblocking_filter == 1 && h0->max_contexts > 1) { if(s->avctx->flags2 & CODEC_FLAG2_FAST) { h->deblocking_filter = 2; } else { h0->max_contexts = 1; if(!h0->single_decode_warning) { av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n"); h0->single_decode_warning = 1; } if(h != h0) return 1; } } #if 0 if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) slice_group_change_cycle= get_bits(&s->gb, ?); #endif h0->last_slice_type = slice_type; h->slice_num = ++h0->current_slice; for(j=0; j<2; j++){ int *ref2frm= h->ref2frm[h->slice_num&15][j]; ref2frm[0]= ref2frm[1]= -1; for(i=0; i<48; i++) ref2frm[i+2]= 4*h->ref_list[j][i].frame_num +(h->ref_list[j][i].reference&3); } h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width; if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", h->slice_num, (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"), first_mb_in_slice, av_get_pict_type_char(h->slice_type), pps_id, h->frame_num, s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], h->ref_count[0], h->ref_count[1], s->qscale, h->deblocking_filter, h->slice_alpha_c0_offset/2, h->slice_beta_offset/2, h->use_weight, h->use_weight==1 && h->use_weight_chroma ? "c" : "", h->slice_type == FF_B_TYPE ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "" ); } return 0; }
['static int decode_slice_header(H264Context *h, H264Context *h0){\n MpegEncContext * const s = &h->s;\n MpegEncContext * const s0 = &h0->s;\n unsigned int first_mb_in_slice;\n unsigned int pps_id;\n int num_ref_idx_active_override_flag;\n static const uint8_t slice_type_map[5]= {FF_P_TYPE, FF_B_TYPE, FF_I_TYPE, FF_SP_TYPE, FF_SI_TYPE};\n unsigned int slice_type, tmp, i, j;\n int default_ref_list_done = 0;\n int last_pic_structure;\n s->dropable= h->nal_ref_idc == 0;\n if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc){\n s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;\n }else{\n s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;\n s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;\n }\n first_mb_in_slice= get_ue_golomb(&s->gb);\n if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){\n h0->current_slice = 0;\n if (!s0->first_field)\n s->current_picture_ptr= NULL;\n }\n slice_type= get_ue_golomb(&s->gb);\n if(slice_type > 9){\n av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\\n", h->slice_type, s->mb_x, s->mb_y);\n return -1;\n }\n if(slice_type > 4){\n slice_type -= 5;\n h->slice_type_fixed=1;\n }else\n h->slice_type_fixed=0;\n slice_type= slice_type_map[ slice_type ];\n if (slice_type == FF_I_TYPE\n || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {\n default_ref_list_done = 1;\n }\n h->slice_type= slice_type;\n h->slice_type_nos= slice_type & 3;\n s->pict_type= h->slice_type;\n if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) {\n av_log(h->s.avctx, AV_LOG_ERROR,\n "B picture before any references, skipping\\n");\n return -1;\n }\n pps_id= get_ue_golomb(&s->gb);\n if(pps_id>=MAX_PPS_COUNT){\n av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n return -1;\n }\n if(!h0->pps_buffers[pps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS referenced\\n");\n return -1;\n }\n h->pps= *h0->pps_buffers[pps_id];\n if(!h0->sps_buffers[h->pps.sps_id]) {\n av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS referenced\\n");\n return -1;\n }\n h->sps = *h0->sps_buffers[h->pps.sps_id];\n if(h == h0 && h->dequant_coeff_pps != pps_id){\n h->dequant_coeff_pps = pps_id;\n init_dequant_tables(h);\n }\n s->mb_width= h->sps.mb_width;\n s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n h->b_stride= s->mb_width*4;\n h->b8_stride= s->mb_width*2;\n s->width = 16*s->mb_width - 2*FFMIN(h->sps.crop_right, 7);\n if(h->sps.frame_mbs_only_flag)\n s->height= 16*s->mb_height - 2*FFMIN(h->sps.crop_bottom, 7);\n else\n s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 3);\n if (s->context_initialized\n && ( s->width != s->avctx->width || s->height != s->avctx->height)) {\n if(h != h0)\n return -1;\n free_tables(h);\n MPV_common_end(s);\n }\n if (!s->context_initialized) {\n if(h != h0)\n return -1;\n if (MPV_common_init(s) < 0)\n return -1;\n s->first_field = 0;\n init_scan_tables(h);\n alloc_tables(h);\n for(i = 1; i < s->avctx->thread_count; i++) {\n H264Context *c;\n c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n c->sps = h->sps;\n c->pps = h->pps;\n init_scan_tables(c);\n clone_tables(c, h);\n }\n for(i = 0; i < s->avctx->thread_count; i++)\n if(context_init(h->thread_context[i]) < 0)\n return -1;\n s->avctx->width = s->width;\n s->avctx->height = s->height;\n s->avctx->sample_aspect_ratio= h->sps.sar;\n if(!s->avctx->sample_aspect_ratio.den)\n s->avctx->sample_aspect_ratio.den = 1;\n if(h->sps.timing_info_present_flag){\n s->avctx->time_base= (AVRational){h->sps.num_units_in_tick * 2, h->sps.time_scale};\n if(h->x264_build > 0 && h->x264_build < 44)\n s->avctx->time_base.den *= 2;\n av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n s->avctx->time_base.num, s->avctx->time_base.den, 1<<30);\n }\n }\n h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);\n h->mb_mbaff = 0;\n h->mb_aff_frame = 0;\n last_pic_structure = s0->picture_structure;\n if(h->sps.frame_mbs_only_flag){\n s->picture_structure= PICT_FRAME;\n }else{\n if(get_bits1(&s->gb)) {\n s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);\n } else {\n s->picture_structure= PICT_FRAME;\n h->mb_aff_frame = h->sps.mb_aff;\n }\n }\n if(h0->current_slice == 0){\n while(h->frame_num != h->prev_frame_num &&\n h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){\n av_log(NULL, AV_LOG_DEBUG, "Frame num gap %d %d\\n", h->frame_num, h->prev_frame_num);\n frame_start(h);\n h->prev_frame_num++;\n h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;\n s->current_picture_ptr->frame_num= h->prev_frame_num;\n execute_ref_pic_marking(h, NULL, 0);\n }\n if (s0->first_field) {\n assert(s0->current_picture_ptr);\n assert(s0->current_picture_ptr->data[0]);\n assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF);\n if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n s0->current_picture_ptr = NULL;\n s0->first_field = FIELD_PICTURE;\n } else {\n if (h->nal_ref_idc &&\n s0->current_picture_ptr->reference &&\n s0->current_picture_ptr->frame_num != h->frame_num) {\n s0->first_field = 1;\n s0->current_picture_ptr = NULL;\n } else {\n s0->first_field = 0;\n }\n }\n } else {\n assert(!s0->current_picture_ptr);\n s0->first_field = FIELD_PICTURE;\n }\n if((!FIELD_PICTURE || s0->first_field) && frame_start(h) < 0) {\n s0->first_field = 0;\n return -1;\n }\n }\n if(h != h0)\n clone_slice(h, h0);\n s->current_picture_ptr->frame_num= h->frame_num;\n assert(s->mb_num == s->mb_width * s->mb_height);\n if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n first_mb_in_slice >= s->mb_num){\n av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n return -1;\n }\n s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n if (s->picture_structure == PICT_BOTTOM_FIELD)\n s->resync_mb_y = s->mb_y = s->mb_y + 1;\n assert(s->mb_y < s->mb_height);\n if(s->picture_structure==PICT_FRAME){\n h->curr_pic_num= h->frame_num;\n h->max_pic_num= 1<< h->sps.log2_max_frame_num;\n }else{\n h->curr_pic_num= 2*h->frame_num + 1;\n h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);\n }\n if(h->nal_unit_type == NAL_IDR_SLICE){\n get_ue_golomb(&s->gb);\n }\n if(h->sps.poc_type==0){\n h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){\n h->delta_poc_bottom= get_se_golomb(&s->gb);\n }\n }\n if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){\n h->delta_poc[0]= get_se_golomb(&s->gb);\n if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)\n h->delta_poc[1]= get_se_golomb(&s->gb);\n }\n init_poc(h);\n if(h->pps.redundant_pic_cnt_present){\n h->redundant_pic_count= get_ue_golomb(&s->gb);\n }\n h->ref_count[0]= h->pps.ref_count[0];\n h->ref_count[1]= h->pps.ref_count[1];\n if(h->slice_type_nos != FF_I_TYPE){\n if(h->slice_type_nos == FF_B_TYPE){\n h->direct_spatial_mv_pred= get_bits1(&s->gb);\n }\n num_ref_idx_active_override_flag= get_bits1(&s->gb);\n if(num_ref_idx_active_override_flag){\n h->ref_count[0]= get_ue_golomb(&s->gb) + 1;\n if(h->slice_type_nos==FF_B_TYPE)\n h->ref_count[1]= get_ue_golomb(&s->gb) + 1;\n if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){\n av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n h->ref_count[0]= h->ref_count[1]= 1;\n return -1;\n }\n }\n if(h->slice_type_nos == FF_B_TYPE)\n h->list_count= 2;\n else\n h->list_count= 1;\n }else\n h->list_count= 0;\n if(!default_ref_list_done){\n fill_default_ref_list(h);\n }\n if(h->slice_type_nos!=FF_I_TYPE && decode_ref_pic_list_reordering(h) < 0)\n return -1;\n if( (h->pps.weighted_pred && h->slice_type_nos == FF_P_TYPE )\n || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) )\n pred_weight_table(h);\n else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE)\n implicit_weight_table(h);\n else\n h->use_weight = 0;\n if(h->nal_ref_idc)\n decode_ref_pic_marking(h0, &s->gb);\n if(FRAME_MBAFF)\n fill_mbaff_ref_list(h);\n if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){\n tmp = get_ue_golomb(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n return -1;\n }\n h->cabac_init_idc= tmp;\n }\n h->last_qscale_diff = 0;\n tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n if(tmp>51){\n av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n return -1;\n }\n s->qscale= tmp;\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n if(h->slice_type == FF_SP_TYPE){\n get_bits1(&s->gb);\n }\n if(h->slice_type==FF_SP_TYPE || h->slice_type == FF_SI_TYPE){\n get_se_golomb(&s->gb);\n }\n h->deblocking_filter = 1;\n h->slice_alpha_c0_offset = 0;\n h->slice_beta_offset = 0;\n if( h->pps.deblocking_filter_parameters_present ) {\n tmp= get_ue_golomb(&s->gb);\n if(tmp > 2){\n av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\\n", tmp);\n return -1;\n }\n h->deblocking_filter= tmp;\n if(h->deblocking_filter < 2)\n h->deblocking_filter^= 1;\n if( h->deblocking_filter ) {\n h->slice_alpha_c0_offset = get_se_golomb(&s->gb) << 1;\n h->slice_beta_offset = get_se_golomb(&s->gb) << 1;\n }\n }\n if( s->avctx->skip_loop_filter >= AVDISCARD_ALL\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != FF_I_TYPE)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == FF_B_TYPE)\n ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))\n h->deblocking_filter= 0;\n if(h->deblocking_filter == 1 && h0->max_contexts > 1) {\n if(s->avctx->flags2 & CODEC_FLAG2_FAST) {\n h->deblocking_filter = 2;\n } else {\n h0->max_contexts = 1;\n if(!h0->single_decode_warning) {\n av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n h0->single_decode_warning = 1;\n }\n if(h != h0)\n return 1;\n }\n }\n#if 0\n if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)\n slice_group_change_cycle= get_bits(&s->gb, ?);\n#endif\n h0->last_slice_type = slice_type;\n h->slice_num = ++h0->current_slice;\n for(j=0; j<2; j++){\n int *ref2frm= h->ref2frm[h->slice_num&15][j];\n ref2frm[0]=\n ref2frm[1]= -1;\n for(i=0; i<48; i++)\n ref2frm[i+2]= 4*h->ref_list[j][i].frame_num\n +(h->ref_list[j][i].reference&3);\n }\n h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;\n h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n if(s->avctx->debug&FF_DEBUG_PICT_INFO){\n av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n h->slice_num,\n (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),\n first_mb_in_slice,\n av_get_pict_type_char(h->slice_type),\n pps_id, h->frame_num,\n s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],\n h->ref_count[0], h->ref_count[1],\n s->qscale,\n h->deblocking_filter, h->slice_alpha_c0_offset/2, h->slice_beta_offset/2,\n h->use_weight,\n h->use_weight==1 && h->use_weight_chroma ? "c" : "",\n h->slice_type == FF_B_TYPE ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""\n );\n }\n return 0;\n}']
36,197
0
https://github.com/openssl/openssl/blob/f38edcab594b4934bd9625ef889934b2dfb5d1f0/crypto/bn/bn_sqr.c/#L114
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) { int i, j, max; const BN_ULONG *ap; BN_ULONG *rp; max = n * 2; ap = a; rp = r; rp[0] = rp[max - 1] = 0; rp++; j = n; if (--j > 0) { ap++; rp[j] = bn_mul_words(rp, ap, j, ap[-1]); rp += 2; } for (i = n - 2; i > 0; i--) { j--; ap++; rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]); rp += 2; } bn_add_words(r, r, r, max); bn_sqr_words(tmp, a, n); bn_add_words(r, r, tmp, max); }
['static int prime_field_tests(void)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *p = NULL, *a = NULL, *b = NULL, *scalar3 = NULL;\n EC_GROUP *group = NULL, *tmp = NULL;\n EC_GROUP *P_160 = NULL, *P_192 = NULL, *P_224 = NULL,\n *P_256 = NULL, *P_384 = NULL, *P_521 = NULL;\n EC_POINT *P = NULL, *Q = NULL, *R = NULL;\n BIGNUM *x = NULL, *y = NULL, *z = NULL, *yplusone = NULL;\n const EC_POINT *points[4];\n const BIGNUM *scalars[4];\n unsigned char buf[100];\n size_t len, r = 0;\n int k;\n if (!TEST_ptr(ctx = BN_CTX_new())\n || !TEST_ptr(p = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_true(BN_hex2bn(&p, "17"))\n || !TEST_true(BN_hex2bn(&a, "1"))\n || !TEST_true(BN_hex2bn(&b, "1"))\n || !TEST_ptr(group = EC_GROUP_new(EC_GFp_mont_method()))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_ptr(tmp = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(tmp, group)))\n goto err;\n EC_GROUP_free(group);\n group = tmp;\n tmp = NULL;\n if (!TEST_true(EC_GROUP_get_curve(group, p, a, b, ctx)))\n goto err;\n TEST_info("Curve defined by Weierstrass equation");\n TEST_note(" y^2 = x^3 + a*x + b (mod p)");\n test_output_bignum("a", a);\n test_output_bignum("b", b);\n test_output_bignum("p", p);\n buf[0] = 0;\n if (!TEST_ptr(P = EC_POINT_new(group))\n || !TEST_ptr(Q = EC_POINT_new(group))\n || !TEST_ptr(R = EC_POINT_new(group))\n || !TEST_true(EC_POINT_set_to_infinity(group, P))\n || !TEST_true(EC_POINT_is_at_infinity(group, P))\n || !TEST_true(EC_POINT_oct2point(group, Q, buf, 1, ctx))\n || !TEST_true(EC_POINT_add(group, P, P, Q, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, P))\n || !TEST_ptr(x = BN_new())\n || !TEST_ptr(y = BN_new())\n || !TEST_ptr(z = BN_new())\n || !TEST_ptr(yplusone = BN_new())\n || !TEST_true(BN_hex2bn(&x, "D"))\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, Q, x, 1, ctx)))\n goto err;\n if (!TEST_int_gt(EC_POINT_is_on_curve(group, Q, ctx), 0)) {\n if (!TEST_true(EC_POINT_get_affine_coordinates(group, Q, x, y, ctx)))\n goto err;\n TEST_info("Point is not on curve");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n goto err;\n }\n TEST_note("A cyclic subgroup:");\n k = 100;\n do {\n if (!TEST_int_ne(k--, 0))\n goto err;\n if (EC_POINT_is_at_infinity(group, P)) {\n TEST_note(" point at infinity");\n } else {\n if (!TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y,\n ctx)))\n goto err;\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n }\n if (!TEST_true(EC_POINT_copy(R, P))\n || !TEST_true(EC_POINT_add(group, P, P, Q, ctx)))\n goto err;\n } while (!EC_POINT_is_at_infinity(group, P));\n if (!TEST_true(EC_POINT_add(group, P, Q, R, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n goto err;\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf,\n sizeof(buf), ctx);\n if (!TEST_size_t_ne(len, 0)\n || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n goto err;\n test_output_memory("Generator as octet string, compressed form:",\n buf, len);\n len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED,\n buf, sizeof(buf), ctx);\n if (!TEST_size_t_ne(len, 0)\n || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n goto err;\n test_output_memory("Generator as octet string, uncompressed form:",\n buf, len);\n len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID,\n buf, sizeof(buf), ctx);\n if (!TEST_size_t_ne(len, 0)\n || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n goto err;\n test_output_memory("Generator as octet string, hybrid form:",\n buf, len);\n if (!TEST_true(EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z,\n ctx)))\n goto err;\n TEST_info("A representation of the inverse of that generator in");\n TEST_note("Jacobian projective coordinates");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n test_output_bignum("z", z);\n if (!TEST_true(EC_POINT_invert(group, P, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))\n || !TEST_true(BN_hex2bn(&p, "FFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF"))\n || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n || !TEST_true(BN_hex2bn(&a, "FFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC"))\n || !TEST_true(BN_hex2bn(&b, "1C97BEFC"\n "54BD7A8B65ACF89F81D4D4ADC565FA45"))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_true(BN_hex2bn(&x, "4A96B568"\n "8EF573284664698968C38BB913CBFC82"))\n || !TEST_true(BN_hex2bn(&y, "23a62855"\n "3168947d59dcc912042351377ac5fb32"))\n || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n ctx))\n || !TEST_true(EC_POINT_set_affine_coordinates(group, P, x, y, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(BN_hex2bn(&z, "0100000000"\n "000000000001F4C8F927AED3CA752257"))\n || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n goto err;\n TEST_info("SEC2 curve secp160r1 -- Generator");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n if (!TEST_true(BN_hex2bn(&z, "23a62855"\n "3168947d59dcc912042351377ac5fb32"))\n || !TEST_BN_eq(y, z)\n || !TEST_int_eq(EC_GROUP_get_degree(group), 160)\n || !group_order_tests(group)\n || !TEST_ptr(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(P_160, group))\n || !TEST_true(BN_hex2bn(&p, "FFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"))\n || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n || !TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC"))\n || !TEST_true(BN_hex2bn(&b, "64210519E59C80E7"\n "0FA7E9AB72243049FEB8DEECC146B9B1"))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_true(BN_hex2bn(&x, "188DA80EB03090F6"\n "7CBF20EB43A18800F4FF0AFD82FF1012"))\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 1, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(BN_hex2bn(&z, "FFFFFFFFFFFFFFFF"\n "FFFFFFFF99DEF836146BC9B1B4D22831"))\n || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n goto err;\n TEST_info("NIST curve P-192 -- Generator");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n if (!TEST_true(BN_hex2bn(&z, "07192B95FFC8DA78"\n "631011ED6B24CDD573F977A11E794811"))\n || !TEST_BN_eq(y, z)\n || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n ctx))\n || !TEST_int_eq(EC_GROUP_get_degree(group), 192)\n || !group_order_tests(group)\n || !TEST_ptr(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(P_192, group))\n || !TEST_true(BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFF000000000000000000000001"))\n || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n || !TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE"))\n || !TEST_true(BN_hex2bn(&b, "B4050A850C04B3ABF5413256"\n "5044B0B7D7BFD8BA270B39432355FFB4"))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_true(BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B9"\n "4A03C1D356C21122343280D6115C1D21"))\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 0, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFF16A2E0B8F03E13DD29455C5C2A3D"))\n || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n goto err;\n TEST_info("NIST curve P-224 -- Generator");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n if (!TEST_true(BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6"\n "CD4375A05A07476444D5819985007E34"))\n || !TEST_BN_eq(y, z)\n || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n ctx))\n || !TEST_int_eq(EC_GROUP_get_degree(group), 224)\n || !group_order_tests(group)\n || !TEST_ptr(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(P_224, group))\n || !TEST_true(BN_hex2bn(&p, "FFFFFFFF000000010000000000000000"\n "00000000FFFFFFFFFFFFFFFFFFFFFFFF"))\n || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n || !TEST_true(BN_hex2bn(&a, "FFFFFFFF000000010000000000000000"\n "00000000FFFFFFFFFFFFFFFFFFFFFFFC"))\n || !TEST_true(BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC"\n "651D06B0CC53B0F63BCE3C3E27D2604B"))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_true(BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F2"\n "77037D812DEB33A0F4A13945D898C296"))\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 1, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFF"\n "BCE6FAADA7179E84F3B9CAC2FC632551"))\n || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n goto err;\n TEST_info("NIST curve P-256 -- Generator");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n if (!TEST_true(BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"\n "2BCE33576B315ECECBB6406837BF51F5"))\n || !TEST_BN_eq(y, z)\n || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n ctx))\n || !TEST_int_eq(EC_GROUP_get_degree(group), 256)\n || !group_order_tests(group)\n || !TEST_ptr(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(P_256, group))\n || !TEST_true(BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"\n "FFFFFFFF0000000000000000FFFFFFFF"))\n || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n || !TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"\n "FFFFFFFF0000000000000000FFFFFFFC"))\n || !TEST_true(BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19"\n "181D9C6EFE8141120314088F5013875A"\n "C656398D8A2ED19D2A85C8EDD3EC2AEF"))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_true(BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD74"\n "6E1D3B628BA79B9859F741E082542A38"\n "5502F25DBF55296C3A545E3872760AB7"))\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 1, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFC7634D81F4372DDF"\n "581A0DB248B0A77AECEC196ACCC52973"))\n || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n goto err;\n TEST_info("NIST curve P-384 -- Generator");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n if (!TEST_true(BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29"\n "F8F41DBD289A147CE9DA3113B5F0B8C0"\n "0A60B1CE1D7E819D7A431D7C90EA0E5F"))\n || !TEST_BN_eq(y, z)\n || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n ctx))\n || !TEST_int_eq(EC_GROUP_get_degree(group), 384)\n || !group_order_tests(group)\n || !TEST_ptr(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(P_384, group))\n || !TEST_true(BN_hex2bn(&p, "1FF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"))\n || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n || !TEST_true(BN_hex2bn(&a, "1FF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC"))\n || !TEST_true(BN_hex2bn(&b, "051"\n "953EB9618E1C9A1F929A21A0B68540EE"\n "A2DA725B99B315F3B8B489918EF109E1"\n "56193951EC7E937B1652C0BD3BB1BF07"\n "3573DF883D2C34F1EF451FD46B503F00"))\n || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n || !TEST_true(BN_hex2bn(&x, "C6"\n "858E06B70404E9CD9E3ECB662395B442"\n "9C648139053FB521F828AF606B4D3DBA"\n "A14B5E77EFE75928FE1DC127A2FFA8DE"\n "3348B3C1856A429BF97E7E31C2E5BD66"))\n || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 0, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(BN_hex2bn(&z, "1FF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA"\n "51868783BF2F966B7FCC0148F709A5D0"\n "3BB5C9B8899C47AEBB6FB71E91386409"))\n || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n goto err;\n TEST_info("NIST curve P-521 -- Generator");\n test_output_bignum("x", x);\n test_output_bignum("y", y);\n if (!TEST_true(BN_hex2bn(&z, "118"\n "39296A789A3BC0045C8A5FB42C7D1BD9"\n "98F54449579B446817AFBD17273E662C"\n "97EE72995EF42640C550B9013FAD0761"\n "353C7086A272C24088BE94769FD16650"))\n || !TEST_BN_eq(y, z)\n || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n ctx))\n || !TEST_int_eq(EC_GROUP_get_degree(group), 521)\n || !group_order_tests(group)\n || !TEST_ptr(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))\n || !TEST_true(EC_GROUP_copy(P_521, group))\n || !TEST_true(EC_POINT_set_affine_coordinates(group, P, x, y, ctx))\n || !TEST_true(EC_POINT_copy(Q, P))\n || !TEST_false(EC_POINT_is_at_infinity(group, Q))\n || !TEST_true(EC_POINT_dbl(group, P, P, ctx))\n || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n || !TEST_true(EC_POINT_invert(group, Q, ctx))\n || !TEST_true(EC_POINT_add(group, R, P, Q, ctx))\n || !TEST_true(EC_POINT_add(group, R, R, Q, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, R))\n || !TEST_false(EC_POINT_is_at_infinity(group, Q)))\n goto err;\n points[0] = Q;\n points[1] = Q;\n points[2] = Q;\n points[3] = Q;\n if (!TEST_true(EC_GROUP_get_order(group, z, ctx))\n || !TEST_true(BN_add(y, z, BN_value_one()))\n || !TEST_BN_even(y)\n || !TEST_true(BN_rshift1(y, y)))\n goto err;\n scalars[0] = y;\n scalars[1] = y;\n TEST_note("combined multiplication ...");\n if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))\n || !TEST_int_eq(0, EC_POINT_cmp(group, R, Q, ctx))\n || !TEST_true(BN_rand(y, BN_num_bits(y), 0, 0))\n || !TEST_true(BN_add(z, z, y)))\n goto err;\n BN_set_negative(z, 1);\n scalars[0] = y;\n scalars[1] = z;\n if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, P))\n || !TEST_true(BN_rand(x, BN_num_bits(y) - 1, 0, 0))\n || !TEST_true(BN_add(z, x, y)))\n goto err;\n BN_set_negative(z, 1);\n scalars[0] = x;\n scalars[1] = y;\n scalars[2] = z;\n if (!TEST_ptr(scalar3 = BN_new()))\n goto err;\n BN_zero(scalar3);\n scalars[3] = scalar3;\n if (!TEST_true(EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx))\n || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n goto err;\n TEST_note(" ok\\n");\n r = 1;\nerr:\n BN_CTX_free(ctx);\n BN_free(p);\n BN_free(a);\n BN_free(b);\n EC_GROUP_free(group);\n EC_GROUP_free(tmp);\n EC_POINT_free(P);\n EC_POINT_free(Q);\n EC_POINT_free(R);\n BN_free(x);\n BN_free(y);\n BN_free(z);\n BN_free(yplusone);\n BN_free(scalar3);\n EC_GROUP_free(P_160);\n EC_GROUP_free(P_192);\n EC_GROUP_free(P_224);\n EC_GROUP_free(P_256);\n EC_GROUP_free(P_384);\n EC_GROUP_free(P_521);\n return r;\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n BIGNUM *ret = NULL;\n BN_ULONG l = 0;\n int neg = 0, h, m, i, j, k, c;\n int num;\n if (a == NULL || *a == '\\0')\n return 0;\n if (*a == '-') {\n neg = 1;\n a++;\n }\n for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)\n continue;\n if (i == 0 || i > INT_MAX / 4)\n goto err;\n num = i + neg;\n if (bn == NULL)\n return num;\n if (*bn == NULL) {\n if ((ret = BN_new()) == NULL)\n return 0;\n } else {\n ret = *bn;\n BN_zero(ret);\n }\n if (bn_expand(ret, i * 4) == NULL)\n goto err;\n j = i;\n m = 0;\n h = 0;\n while (j > 0) {\n m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;\n l = 0;\n for (;;) {\n c = a[j - m];\n k = OPENSSL_hexchar2int(c);\n if (k < 0)\n k = 0;\n l = (l << 4) | k;\n if (--m <= 0) {\n ret->d[h++] = l;\n break;\n }\n }\n j -= BN_BYTES * 2;\n }\n ret->top = h;\n bn_correct_top(ret);\n *bn = ret;\n bn_check_top(ret);\n if (ret->top != 0)\n ret->neg = neg;\n return num;\n err:\n if (*bn == NULL)\n BN_free(ret);\n return 0;\n}", 'int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,\n const BIGNUM *x, int y_bit, BN_CTX *ctx)\n{\n if (group->meth->point_set_compressed_coordinates == NULL\n && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES,\n ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (!ec_point_is_compat(point, group)) {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES,\n EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {\n if (group->meth->field_type == NID_X9_62_prime_field)\n return ec_GFp_simple_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n else\n#ifdef OPENSSL_NO_EC2M\n {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES,\n EC_R_GF2M_NOT_SUPPORTED);\n return 0;\n }\n#else\n return ec_GF2m_simple_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n#endif\n }\n return group->meth->point_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n}', 'int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
36,198
0
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/ssl/s3_cbc.c/#L600
void ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char *md_out, size_t *md_out_size, const unsigned char header[13], const unsigned char *data, size_t data_plus_mac_size, size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret, unsigned mac_secret_length, char is_sslv3) { union { double align; unsigned char c[sizeof(LARGEST_DIGEST_CTX)]; } md_state; void (*md_final_raw) (void *ctx, unsigned char *md_out); void (*md_transform) (void *ctx, const unsigned char *block); unsigned md_size, md_block_size = 64; unsigned sslv3_pad_length = 40, header_length, variance_blocks, len, max_mac_bytes, num_blocks, num_starting_blocks, k, mac_end_offset, c, index_a, index_b; unsigned int bits; unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES]; unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE]; unsigned char first_block[MAX_HASH_BLOCK_SIZE]; unsigned char mac_out[EVP_MAX_MD_SIZE]; unsigned i, j, md_out_size_u; EVP_MD_CTX md_ctx; unsigned md_length_size = 8; char length_is_big_endian = 1; int ret; OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024); switch (EVP_MD_CTX_type(ctx)) { case NID_md5: MD5_Init((MD5_CTX *)md_state.c); md_final_raw = tls1_md5_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))MD5_Transform; md_size = 16; sslv3_pad_length = 48; length_is_big_endian = 0; break; case NID_sha1: SHA1_Init((SHA_CTX *)md_state.c); md_final_raw = tls1_sha1_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA1_Transform; md_size = 20; break; #ifndef OPENSSL_NO_SHA256 case NID_sha224: SHA224_Init((SHA256_CTX *)md_state.c); md_final_raw = tls1_sha256_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA256_Transform; md_size = 224 / 8; break; case NID_sha256: SHA256_Init((SHA256_CTX *)md_state.c); md_final_raw = tls1_sha256_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA256_Transform; md_size = 32; break; #endif #ifndef OPENSSL_NO_SHA512 case NID_sha384: SHA384_Init((SHA512_CTX *)md_state.c); md_final_raw = tls1_sha512_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA512_Transform; md_size = 384 / 8; md_block_size = 128; md_length_size = 16; break; case NID_sha512: SHA512_Init((SHA512_CTX *)md_state.c); md_final_raw = tls1_sha512_final_raw; md_transform = (void (*)(void *ctx, const unsigned char *block))SHA512_Transform; md_size = 64; md_block_size = 128; md_length_size = 16; break; #endif default: OPENSSL_assert(0); if (md_out_size) *md_out_size = -1; return; } OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES); OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE); OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE); header_length = 13; if (is_sslv3) { header_length = mac_secret_length + sslv3_pad_length + 8 + 1 + 2 ; } variance_blocks = is_sslv3 ? 2 : 6; len = data_plus_mac_plus_padding_size + header_length; max_mac_bytes = len - md_size - 1; num_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size; num_starting_blocks = 0; k = 0; mac_end_offset = data_plus_mac_size + header_length - md_size; c = mac_end_offset % md_block_size; index_a = mac_end_offset / md_block_size; index_b = (mac_end_offset + md_length_size) / md_block_size; if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) { num_starting_blocks = num_blocks - variance_blocks; k = md_block_size * num_starting_blocks; } bits = 8 * mac_end_offset; if (!is_sslv3) { bits += 8 * md_block_size; memset(hmac_pad, 0, md_block_size); OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad)); memcpy(hmac_pad, mac_secret, mac_secret_length); for (i = 0; i < md_block_size; i++) hmac_pad[i] ^= 0x36; md_transform(md_state.c, hmac_pad); } if (length_is_big_endian) { memset(length_bytes, 0, md_length_size - 4); length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24); length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16); length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8); length_bytes[md_length_size - 1] = (unsigned char)bits; } else { memset(length_bytes, 0, md_length_size); length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24); length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16); length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8); length_bytes[md_length_size - 8] = (unsigned char)bits; } if (k > 0) { if (is_sslv3) { unsigned overhang = header_length - md_block_size; md_transform(md_state.c, header); memcpy(first_block, header + md_block_size, overhang); memcpy(first_block + overhang, data, md_block_size - overhang); md_transform(md_state.c, first_block); for (i = 1; i < k / md_block_size - 1; i++) md_transform(md_state.c, data + md_block_size * i - overhang); } else { memcpy(first_block, header, 13); memcpy(first_block + 13, data, md_block_size - 13); md_transform(md_state.c, first_block); for (i = 1; i < k / md_block_size; i++) md_transform(md_state.c, data + md_block_size * i - 13); } } memset(mac_out, 0, sizeof(mac_out)); for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks; i++) { unsigned char block[MAX_HASH_BLOCK_SIZE]; unsigned char is_block_a = constant_time_eq_8(i, index_a); unsigned char is_block_b = constant_time_eq_8(i, index_b); for (j = 0; j < md_block_size; j++) { unsigned char b = 0, is_past_c, is_past_cp1; if (k < header_length) b = header[k]; else if (k < data_plus_mac_plus_padding_size + header_length) b = data[k - header_length]; k++; is_past_c = is_block_a & constant_time_ge_8(j, c); is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1); b = constant_time_select_8(is_past_c, 0x80, b); b = b & ~is_past_cp1; b &= ~is_block_b | is_block_a; if (j >= md_block_size - md_length_size) { b = constant_time_select_8(is_block_b, length_bytes[j - (md_block_size - md_length_size)], b); } block[j] = b; } md_transform(md_state.c, block); md_final_raw(md_state.c, block); for (j = 0; j < md_size; j++) mac_out[j] |= block[j] & is_block_b; } EVP_MD_CTX_init(&md_ctx); EVP_DigestInit_ex(&md_ctx, ctx->digest, NULL ); if (is_sslv3) { memset(hmac_pad, 0x5c, sslv3_pad_length); EVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length); EVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length); EVP_DigestUpdate(&md_ctx, mac_out, md_size); } else { for (i = 0; i < md_block_size; i++) hmac_pad[i] ^= 0x6a; EVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size); EVP_DigestUpdate(&md_ctx, mac_out, md_size); } ret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u); if (ret && md_out_size) *md_out_size = md_out_size_u; EVP_MD_CTX_cleanup(&md_ctx); }
['void ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,\n unsigned char *md_out,\n size_t *md_out_size,\n const unsigned char header[13],\n const unsigned char *data,\n size_t data_plus_mac_size,\n size_t data_plus_mac_plus_padding_size,\n const unsigned char *mac_secret,\n unsigned mac_secret_length, char is_sslv3)\n{\n union {\n double align;\n unsigned char c[sizeof(LARGEST_DIGEST_CTX)];\n } md_state;\n void (*md_final_raw) (void *ctx, unsigned char *md_out);\n void (*md_transform) (void *ctx, const unsigned char *block);\n unsigned md_size, md_block_size = 64;\n unsigned sslv3_pad_length = 40, header_length, variance_blocks,\n len, max_mac_bytes, num_blocks,\n num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n unsigned int bits;\n unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n unsigned char first_block[MAX_HASH_BLOCK_SIZE];\n unsigned char mac_out[EVP_MAX_MD_SIZE];\n unsigned i, j, md_out_size_u;\n EVP_MD_CTX md_ctx;\n unsigned md_length_size = 8;\n char length_is_big_endian = 1;\n int ret;\n OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024);\n switch (EVP_MD_CTX_type(ctx)) {\n case NID_md5:\n MD5_Init((MD5_CTX *)md_state.c);\n md_final_raw = tls1_md5_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))MD5_Transform;\n md_size = 16;\n sslv3_pad_length = 48;\n length_is_big_endian = 0;\n break;\n case NID_sha1:\n SHA1_Init((SHA_CTX *)md_state.c);\n md_final_raw = tls1_sha1_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA1_Transform;\n md_size = 20;\n break;\n#ifndef OPENSSL_NO_SHA256\n case NID_sha224:\n SHA224_Init((SHA256_CTX *)md_state.c);\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 224 / 8;\n break;\n case NID_sha256:\n SHA256_Init((SHA256_CTX *)md_state.c);\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 32;\n break;\n#endif\n#ifndef OPENSSL_NO_SHA512\n case NID_sha384:\n SHA384_Init((SHA512_CTX *)md_state.c);\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 384 / 8;\n md_block_size = 128;\n md_length_size = 16;\n break;\n case NID_sha512:\n SHA512_Init((SHA512_CTX *)md_state.c);\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 64;\n md_block_size = 128;\n md_length_size = 16;\n break;\n#endif\n default:\n OPENSSL_assert(0);\n if (md_out_size)\n *md_out_size = -1;\n return;\n }\n OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);\n OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);\n OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n header_length = 13;\n if (is_sslv3) {\n header_length = mac_secret_length + sslv3_pad_length + 8 +\n 1 +\n 2 ;\n }\n variance_blocks = is_sslv3 ? 2 : 6;\n len = data_plus_mac_plus_padding_size + header_length;\n max_mac_bytes = len - md_size - 1;\n num_blocks =\n (max_mac_bytes + 1 + md_length_size + md_block_size -\n 1) / md_block_size;\n num_starting_blocks = 0;\n k = 0;\n mac_end_offset = data_plus_mac_size + header_length - md_size;\n c = mac_end_offset % md_block_size;\n index_a = mac_end_offset / md_block_size;\n index_b = (mac_end_offset + md_length_size) / md_block_size;\n if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {\n num_starting_blocks = num_blocks - variance_blocks;\n k = md_block_size * num_starting_blocks;\n }\n bits = 8 * mac_end_offset;\n if (!is_sslv3) {\n bits += 8 * md_block_size;\n memset(hmac_pad, 0, md_block_size);\n OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));\n memcpy(hmac_pad, mac_secret, mac_secret_length);\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x36;\n md_transform(md_state.c, hmac_pad);\n }\n if (length_is_big_endian) {\n memset(length_bytes, 0, md_length_size - 4);\n length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 1] = (unsigned char)bits;\n } else {\n memset(length_bytes, 0, md_length_size);\n length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 8] = (unsigned char)bits;\n }\n if (k > 0) {\n if (is_sslv3) {\n unsigned overhang = header_length - md_block_size;\n md_transform(md_state.c, header);\n memcpy(first_block, header + md_block_size, overhang);\n memcpy(first_block + overhang, data, md_block_size - overhang);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size - 1; i++)\n md_transform(md_state.c, data + md_block_size * i - overhang);\n } else {\n memcpy(first_block, header, 13);\n memcpy(first_block + 13, data, md_block_size - 13);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size; i++)\n md_transform(md_state.c, data + md_block_size * i - 13);\n }\n }\n memset(mac_out, 0, sizeof(mac_out));\n for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;\n i++) {\n unsigned char block[MAX_HASH_BLOCK_SIZE];\n unsigned char is_block_a = constant_time_eq_8(i, index_a);\n unsigned char is_block_b = constant_time_eq_8(i, index_b);\n for (j = 0; j < md_block_size; j++) {\n unsigned char b = 0, is_past_c, is_past_cp1;\n if (k < header_length)\n b = header[k];\n else if (k < data_plus_mac_plus_padding_size + header_length)\n b = data[k - header_length];\n k++;\n is_past_c = is_block_a & constant_time_ge_8(j, c);\n is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1);\n b = constant_time_select_8(is_past_c, 0x80, b);\n b = b & ~is_past_cp1;\n b &= ~is_block_b | is_block_a;\n if (j >= md_block_size - md_length_size) {\n b = constant_time_select_8(is_block_b,\n length_bytes[j -\n (md_block_size -\n md_length_size)], b);\n }\n block[j] = b;\n }\n md_transform(md_state.c, block);\n md_final_raw(md_state.c, block);\n for (j = 0; j < md_size; j++)\n mac_out[j] |= block[j] & is_block_b;\n }\n EVP_MD_CTX_init(&md_ctx);\n EVP_DigestInit_ex(&md_ctx, ctx->digest, NULL );\n if (is_sslv3) {\n memset(hmac_pad, 0x5c, sslv3_pad_length);\n EVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length);\n EVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length);\n EVP_DigestUpdate(&md_ctx, mac_out, md_size);\n } else {\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x6a;\n EVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size);\n EVP_DigestUpdate(&md_ctx, mac_out, md_size);\n }\n ret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u);\n if (ret && md_out_size)\n *md_out_size = md_out_size_u;\n EVP_MD_CTX_cleanup(&md_ctx);\n}']
36,199
0
https://github.com/nginx/nginx/blob/f11a9cbdd0f5806131e4308d2ce98a2a97ca4007/src/core/ngx_inet.c/#L1408
ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1, struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port) { struct sockaddr_in *sin1, *sin2; #if (NGX_HAVE_INET6) struct sockaddr_in6 *sin61, *sin62; #endif #if (NGX_HAVE_UNIX_DOMAIN) size_t len; struct sockaddr_un *saun1, *saun2; #endif if (sa1->sa_family != sa2->sa_family) { return NGX_DECLINED; } switch (sa1->sa_family) { #if (NGX_HAVE_INET6) case AF_INET6: sin61 = (struct sockaddr_in6 *) sa1; sin62 = (struct sockaddr_in6 *) sa2; if (cmp_port && sin61->sin6_port != sin62->sin6_port) { return NGX_DECLINED; } if (ngx_memcmp(&sin61->sin6_addr, &sin62->sin6_addr, 16) != 0) { return NGX_DECLINED; } break; #endif #if (NGX_HAVE_UNIX_DOMAIN) case AF_UNIX: saun1 = (struct sockaddr_un *) sa1; saun2 = (struct sockaddr_un *) sa2; if (slen1 < slen2) { len = slen1 - offsetof(struct sockaddr_un, sun_path); } else { len = slen2 - offsetof(struct sockaddr_un, sun_path); } if (len > sizeof(saun1->sun_path)) { len = sizeof(saun1->sun_path); } if (ngx_memcmp(&saun1->sun_path, &saun2->sun_path, len) != 0) { return NGX_DECLINED; } break; #endif default: sin1 = (struct sockaddr_in *) sa1; sin2 = (struct sockaddr_in *) sa2; if (cmp_port && sin1->sin_port != sin2->sin_port) { return NGX_DECLINED; } if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) { return NGX_DECLINED; } break; } return NGX_OK; }
['static ngx_connection_t *\nngx_lookup_udp_connection(ngx_listening_t *ls, struct sockaddr *sockaddr,\n socklen_t socklen, struct sockaddr *local_sockaddr, socklen_t local_socklen)\n{\n uint32_t hash;\n ngx_int_t rc;\n ngx_connection_t *c;\n ngx_rbtree_node_t *node, *sentinel;\n ngx_udp_connection_t *udp;\n#if (NGX_HAVE_UNIX_DOMAIN)\n if (sockaddr->sa_family == AF_UNIX) {\n struct sockaddr_un *saun = (struct sockaddr_un *) sockaddr;\n if (socklen <= (socklen_t) offsetof(struct sockaddr_un, sun_path)\n || saun->sun_path[0] == \'\\0\')\n {\n ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,\n "unbound unix socket");\n return NULL;\n }\n }\n#endif\n node = ls->rbtree.root;\n sentinel = ls->rbtree.sentinel;\n ngx_crc32_init(hash);\n ngx_crc32_update(&hash, (u_char *) sockaddr, socklen);\n if (ls->wildcard) {\n ngx_crc32_update(&hash, (u_char *) local_sockaddr, local_socklen);\n }\n ngx_crc32_final(hash);\n while (node != sentinel) {\n if (hash < node->key) {\n node = node->left;\n continue;\n }\n if (hash > node->key) {\n node = node->right;\n continue;\n }\n udp = (ngx_udp_connection_t *) node;\n c = udp->connection;\n rc = ngx_cmp_sockaddr(sockaddr, socklen,\n c->sockaddr, c->socklen, 1);\n if (rc == 0 && ls->wildcard) {\n rc = ngx_cmp_sockaddr(local_sockaddr, local_socklen,\n c->local_sockaddr, c->local_socklen, 1);\n }\n if (rc == 0) {\n return c;\n }\n node = (rc < 0) ? node->left : node->right;\n }\n return NULL;\n}', 'ngx_int_t\nngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1,\n struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port)\n{\n struct sockaddr_in *sin1, *sin2;\n#if (NGX_HAVE_INET6)\n struct sockaddr_in6 *sin61, *sin62;\n#endif\n#if (NGX_HAVE_UNIX_DOMAIN)\n size_t len;\n struct sockaddr_un *saun1, *saun2;\n#endif\n if (sa1->sa_family != sa2->sa_family) {\n return NGX_DECLINED;\n }\n switch (sa1->sa_family) {\n#if (NGX_HAVE_INET6)\n case AF_INET6:\n sin61 = (struct sockaddr_in6 *) sa1;\n sin62 = (struct sockaddr_in6 *) sa2;\n if (cmp_port && sin61->sin6_port != sin62->sin6_port) {\n return NGX_DECLINED;\n }\n if (ngx_memcmp(&sin61->sin6_addr, &sin62->sin6_addr, 16) != 0) {\n return NGX_DECLINED;\n }\n break;\n#endif\n#if (NGX_HAVE_UNIX_DOMAIN)\n case AF_UNIX:\n saun1 = (struct sockaddr_un *) sa1;\n saun2 = (struct sockaddr_un *) sa2;\n if (slen1 < slen2) {\n len = slen1 - offsetof(struct sockaddr_un, sun_path);\n } else {\n len = slen2 - offsetof(struct sockaddr_un, sun_path);\n }\n if (len > sizeof(saun1->sun_path)) {\n len = sizeof(saun1->sun_path);\n }\n if (ngx_memcmp(&saun1->sun_path, &saun2->sun_path, len) != 0) {\n return NGX_DECLINED;\n }\n break;\n#endif\n default:\n sin1 = (struct sockaddr_in *) sa1;\n sin2 = (struct sockaddr_in *) sa2;\n if (cmp_port && sin1->sin_port != sin2->sin_port) {\n return NGX_DECLINED;\n }\n if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) {\n return NGX_DECLINED;\n }\n break;\n }\n return NGX_OK;\n}']
36,200
0
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_asm.c/#L551
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 BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\taa= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_RECP_CTX_init(&recp);\n\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&val[i]);\n\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\treturn(ret);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, BIGNUM *d, BN_CTX *ctx)\n\t{\n\tBN_copy(&(recp->N),d);\n\tBN_zero(&(recp->Nr));\n\trecp->num_bits=BN_num_bits(d);\n\trecp->shift=0;\n\treturn(1);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\ta= &(ctx->bn[ctx->tos++]);\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\t}\n\telse\n\t\ta=x;\n\tBN_div_recp(NULL,r,a,recp,ctx);\n\tret=1;\nerr:\n\tctx->tos--;\n\treturn(ret);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,tos,ret=0,ex;\n\tBIGNUM *a,*b,*d,*r;\n\ttos=ctx->tos;\n\ta= &(ctx->bn[ctx->tos++]);\n\tb= &(ctx->bn[ctx->tos++]);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td= &(ctx->bn[ctx->tos++]);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr= &(ctx->bn[ctx->tos++]);\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tBN_copy(r,m);\n\t\tctx->tos=tos;\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits*2;\n\tif (j > i)\n\t\t{\n\t\ti=j;\n\t\tex=0;\n\t\t}\n\telse\n\t\t{\n\t\tex=(i-j)/2;\n\t\t}\n\tj=i/2;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (!BN_rshift(a,m,j-ex)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,j+ex)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n\tj=0;\n#if 1\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tctx->tos=tos;\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', '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}']