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 |
|---|---|---|---|---|
33,001 | 0 | https://github.com/libav/libav/blob/ff866063e981ea6a51036c2ffd9bb152b8219437/ffmpeg.c/#L2716 | static int opt_metadata(const char *opt, const char *arg)
{
char *mid= strchr(arg, '=');
if(!mid){
fprintf(stderr, "Missing =\n");
av_exit(1);
}
*mid++= 0;
metadata_count++;
metadata= av_realloc(metadata, sizeof(*metadata)*metadata_count);
metadata[metadata_count-1].key = av_strdup(arg);
metadata[metadata_count-1].value= av_strdup(mid);
return 0;
} | ['static int opt_metadata(const char *opt, const char *arg)\n{\n char *mid= strchr(arg, \'=\');\n if(!mid){\n fprintf(stderr, "Missing =\\n");\n av_exit(1);\n }\n *mid++= 0;\n metadata_count++;\n metadata= av_realloc(metadata, sizeof(*metadata)*metadata_count);\n metadata[metadata_count-1].key = av_strdup(arg);\n metadata[metadata_count-1].value= av_strdup(mid);\n return 0;\n}'] |
33,002 | 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_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a_, const int p[],\n BN_CTX *ctx)\n{\n int ret = 0, count = 0, j;\n BIGNUM *a, *z, *rho, *w, *w2, *tmp;\n bn_check_top(a_);\n if (!p[0]) {\n BN_zero(r);\n return 1;\n }\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n z = BN_CTX_get(ctx);\n w = BN_CTX_get(ctx);\n if (w == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(a, a_, p))\n goto err;\n if (BN_is_zero(a)) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n if (p[0] & 0x1) {\n if (!BN_copy(z, a))\n goto err;\n for (j = 1; j <= (p[0] - 1) / 2; j++) {\n if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))\n goto err;\n if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))\n goto err;\n if (!BN_GF2m_add(z, z, a))\n goto err;\n }\n } else {\n rho = BN_CTX_get(ctx);\n w2 = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n do {\n if (!BN_priv_rand(rho, p[0], BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto err;\n if (!BN_GF2m_mod_arr(rho, rho, p))\n goto err;\n BN_zero(z);\n if (!BN_copy(w, rho))\n goto err;\n for (j = 1; j <= p[0] - 1; j++) {\n if (!BN_GF2m_mod_sqr_arr(z, z, p, ctx))\n goto err;\n if (!BN_GF2m_mod_sqr_arr(w2, w, p, ctx))\n goto err;\n if (!BN_GF2m_mod_mul_arr(tmp, w2, a, p, ctx))\n goto err;\n if (!BN_GF2m_add(z, z, tmp))\n goto err;\n if (!BN_GF2m_add(w, w2, rho))\n goto err;\n }\n count++;\n } while (BN_is_zero(w) && (count < MAX_ITERATIONS));\n if (BN_is_zero(w)) {\n BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR, BN_R_TOO_MANY_ITERATIONS);\n goto err;\n }\n }\n if (!BN_GF2m_mod_sqr_arr(w, z, p, ctx))\n goto err;\n if (!BN_GF2m_add(w, z, w))\n goto err;\n if (BN_GF2m_cmp(w, a)) {\n BNerr(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR, BN_R_NO_SOLUTION);\n goto err;\n }\n if (!BN_copy(r, z))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *s;\n bn_check_top(a);\n BN_CTX_start(ctx);\n if ((s = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!bn_wexpand(s, 2 * a->top))\n goto err;\n for (i = a->top - 1; i >= 0; i--) {\n s->d[2 * i + 1] = SQR1(a->d[i]);\n s->d[2 * i] = SQR0(a->d[i]);\n }\n s->top = 2 * a->top;\n bn_correct_top(s);\n if (!BN_GF2m_mod_arr(r, s, p))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n 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}'] |
33,003 | 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 void qdm2_decode_fft_packets(QDM2Context *q)\n{\n int i, j, min, max, value, type, unknown_flag;\n BitstreamContext bc;\n if (!q->sub_packet_list_B[0].packet)\n return;\n q->fft_coefs_index = 0;\n for (i = 0; i < 5; i++)\n q->fft_coefs_min_index[i] = -1;\n for (i = 0, max = 256; i < q->sub_packets_B; i++) {\n QDM2SubPacket *packet = NULL;\n for (j = 0, min = 0; j < q->sub_packets_B; j++) {\n value = q->sub_packet_list_B[j].packet->type;\n if (value > min && value < max) {\n min = value;\n packet = q->sub_packet_list_B[j].packet;\n }\n }\n max = min;\n if (!packet)\n return;\n if (i == 0 &&\n (packet->type < 16 || packet->type >= 48 ||\n fft_subpackets[packet->type - 16]))\n return;\n bitstream_init(&bc, packet->data, packet->size * 8);\n if (packet->type >= 32 && packet->type < 48 && !fft_subpackets[packet->type - 16])\n unknown_flag = 1;\n else\n unknown_flag = 0;\n type = packet->type;\n if ((type >= 17 && type < 24) || (type >= 33 && type < 40)) {\n int duration = q->sub_sampling + 5 - (type & 15);\n if (duration >= 0 && duration < 4)\n qdm2_fft_decode_tones(q, duration, &bc, unknown_flag);\n } else if (type == 31) {\n for (j = 0; j < 4; j++)\n qdm2_fft_decode_tones(q, j, &bc, unknown_flag);\n } else if (type == 46) {\n for (j = 0; j < 6; j++)\n q->fft_level_exp[j] = bitstream_read(&bc, 6);\n for (j = 0; j < 4; j++)\n qdm2_fft_decode_tones(q, j, &bc, unknown_flag);\n }\n }\n for (i = 0, j = -1; i < 5; i++)\n if (q->fft_coefs_min_index[i] >= 0) {\n if (j >= 0)\n q->fft_coefs_max_index[j] = q->fft_coefs_min_index[i];\n j = i;\n }\n if (j >= 0)\n q->fft_coefs_max_index[j] = q->fft_coefs_index;\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}'] |
33,004 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L485 | static int qpel_motion_search(MpegEncContext * s,
int *mx_ptr, int *my_ptr, int dmin,
int src_index, int ref_index,
int size, int h)
{
MotionEstContext * const c= &s->me;
const int mx = *mx_ptr;
const int my = *my_ptr;
const int penalty_factor= c->sub_penalty_factor;
const int map_generation= c->map_generation;
const int subpel_quality= c->avctx->me_subpel_quality;
uint32_t *map= c->map;
me_cmp_func cmpf, chroma_cmpf;
me_cmp_func cmp_sub, chroma_cmp_sub;
LOAD_COMMON
int flags= c->sub_flags;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
cmp_sub= s->dsp.me_sub_cmp[size];
chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
if(c->skip){
*mx_ptr = 0;
*my_ptr = 0;
return dmin;
}
if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
if(mx || my || size>0)
dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;
}
if (mx > xmin && mx < xmax &&
my > ymin && my < ymax) {
int bx=4*mx, by=4*my;
int d= dmin;
int i, nx, ny;
const int index= (my<<ME_MAP_SHIFT) + mx;
const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];
const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];
const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];
const int c= score_map[(index )&(ME_MAP_SIZE-1)];
int best[8];
int best_pos[8][2];
memset(best, 64, sizeof(int)*8);
#if 1
if(s->me.dia_size>=2){
const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
for(ny= -3; ny <= 3; ny++){
for(nx= -3; nx <= 3; nx++){
const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;
int i;
if((nx&3)==0 && (ny&3)==0) continue;
score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
for(i=0; i<8; i++){
if(score < best[i]){
memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
best[i]= score;
best_pos[i][0]= nx + 4*mx;
best_pos[i][1]= ny + 4*my;
break;
}
}
}
}
}else{
int tl;
const int cx = 4*(r - l);
const int cx2= r + l - 2*c;
const int cy = 4*(b - t);
const int cy2= b + t - 2*c;
int cxy;
if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){
tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
}else{
tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
}
cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;
assert(16*cx2 + 4*cx + 32*c == 32*r);
assert(16*cx2 - 4*cx + 32*c == 32*l);
assert(16*cy2 + 4*cy + 32*c == 32*b);
assert(16*cy2 - 4*cy + 32*c == 32*t);
assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);
for(ny= -3; ny <= 3; ny++){
for(nx= -3; nx <= 3; nx++){
int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c;
int i;
if((nx&3)==0 && (ny&3)==0) continue;
score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
for(i=0; i<8; i++){
if(score < best[i]){
memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
best[i]= score;
best_pos[i][0]= nx + 4*mx;
best_pos[i][1]= ny + 4*my;
break;
}
}
}
}
}
for(i=0; i<subpel_quality; i++){
nx= best_pos[i][0];
ny= best_pos[i][1];
CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
}
#if 0
const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
if(tl<br){
static int stats[7][7], count;
count++;
stats[4*mx - bx + 3][4*my - by + 3]++;
if(256*256*256*64 % count ==0){
for(i=0; i<49; i++){
if((i%7)==0) printf("\n");
printf("%6d ", stats[0][i]);
}
printf("\n");
}
}
#endif
#else
CHECK_QUARTER_MV(2, 2, mx-1, my-1)
CHECK_QUARTER_MV(0, 2, mx , my-1)
CHECK_QUARTER_MV(2, 2, mx , my-1)
CHECK_QUARTER_MV(2, 0, mx , my )
CHECK_QUARTER_MV(2, 2, mx , my )
CHECK_QUARTER_MV(0, 2, mx , my )
CHECK_QUARTER_MV(2, 2, mx-1, my )
CHECK_QUARTER_MV(2, 0, mx-1, my )
nx= bx;
ny= by;
for(i=0; i<8; i++){
int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
}
#endif
#if 0
CHECK_QUARTER_MV(1, 3, mx-1, my-1)
CHECK_QUARTER_MV(1, 2, mx-1, my-1)
CHECK_QUARTER_MV(1, 1, mx-1, my-1)
CHECK_QUARTER_MV(2, 1, mx-1, my-1)
CHECK_QUARTER_MV(3, 1, mx-1, my-1)
CHECK_QUARTER_MV(0, 1, mx , my-1)
CHECK_QUARTER_MV(1, 1, mx , my-1)
CHECK_QUARTER_MV(2, 1, mx , my-1)
CHECK_QUARTER_MV(3, 1, mx , my-1)
CHECK_QUARTER_MV(3, 2, mx , my-1)
CHECK_QUARTER_MV(3, 3, mx , my-1)
CHECK_QUARTER_MV(3, 0, mx , my )
CHECK_QUARTER_MV(3, 1, mx , my )
CHECK_QUARTER_MV(3, 2, mx , my )
CHECK_QUARTER_MV(3, 3, mx , my )
CHECK_QUARTER_MV(2, 3, mx , my )
CHECK_QUARTER_MV(1, 3, mx , my )
CHECK_QUARTER_MV(0, 3, mx , my )
CHECK_QUARTER_MV(3, 3, mx-1, my )
CHECK_QUARTER_MV(2, 3, mx-1, my )
CHECK_QUARTER_MV(1, 3, mx-1, my )
CHECK_QUARTER_MV(1, 2, mx-1, my )
CHECK_QUARTER_MV(1, 1, mx-1, my )
CHECK_QUARTER_MV(1, 0, mx-1, my )
#endif
assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
*mx_ptr = bx;
*my_ptr = by;
}else{
*mx_ptr =4*mx;
*my_ptr =4*my;
}
return dmin;
} | ['static int qpel_motion_search(MpegEncContext * s,\n int *mx_ptr, int *my_ptr, int dmin,\n int src_index, int ref_index,\n int size, int h)\n{\n MotionEstContext * const c= &s->me;\n const int mx = *mx_ptr;\n const int my = *my_ptr;\n const int penalty_factor= c->sub_penalty_factor;\n const int map_generation= c->map_generation;\n const int subpel_quality= c->avctx->me_subpel_quality;\n uint32_t *map= c->map;\n me_cmp_func cmpf, chroma_cmpf;\n me_cmp_func cmp_sub, chroma_cmp_sub;\n LOAD_COMMON\n int flags= c->sub_flags;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n cmp_sub= s->dsp.me_sub_cmp[size];\n chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];\n if(c->skip){\n *mx_ptr = 0;\n *my_ptr = 0;\n return dmin;\n }\n if(c->avctx->me_cmp != c->avctx->me_sub_cmp){\n dmin= cmp(s, mx, my, 0, 0, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\n if(mx || my || size>0)\n dmin += (mv_penalty[4*mx - pred_x] + mv_penalty[4*my - pred_y])*penalty_factor;\n }\n if (mx > xmin && mx < xmax &&\n my > ymin && my < ymax) {\n int bx=4*mx, by=4*my;\n int d= dmin;\n int i, nx, ny;\n const int index= (my<<ME_MAP_SHIFT) + mx;\n const int t= score_map[(index-(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];\n const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)];\n const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)];\n const int b= score_map[(index+(1<<ME_MAP_SHIFT) )&(ME_MAP_SIZE-1)];\n const int c= score_map[(index )&(ME_MAP_SIZE-1)];\n int best[8];\n int best_pos[8][2];\n memset(best, 64, sizeof(int)*8);\n#if 1\n if(s->me.dia_size>=2){\n const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];\n const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];\n const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];\n const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];\n for(ny= -3; ny <= 3; ny++){\n for(nx= -3; nx <= 3; nx++){\n const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;\n const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;\n const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;\n int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;\n int i;\n if((nx&3)==0 && (ny&3)==0) continue;\n score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;\n for(i=0; i<8; i++){\n if(score < best[i]){\n memmove(&best[i+1], &best[i], sizeof(int)*(7-i));\n memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));\n best[i]= score;\n best_pos[i][0]= nx + 4*mx;\n best_pos[i][1]= ny + 4*my;\n break;\n }\n }\n }\n }\n }else{\n int tl;\n const int cx = 4*(r - l);\n const int cx2= r + l - 2*c;\n const int cy = 4*(b - t);\n const int cy2= b + t - 2*c;\n int cxy;\n if(map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)] == (my<<ME_MAP_MV_BITS) + mx + map_generation && 0){\n tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];\n }else{\n tl= cmp(s, mx-1, my-1, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\n }\n cxy= 2*tl + (cx + cy)/4 - (cx2 + cy2) - 2*c;\n assert(16*cx2 + 4*cx + 32*c == 32*r);\n assert(16*cx2 - 4*cx + 32*c == 32*l);\n assert(16*cy2 + 4*cy + 32*c == 32*b);\n assert(16*cy2 - 4*cy + 32*c == 32*t);\n assert(16*cxy + 16*cy2 + 16*cx2 - 4*cy - 4*cx + 32*c == 32*tl);\n for(ny= -3; ny <= 3; ny++){\n for(nx= -3; nx <= 3; nx++){\n int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c;\n int i;\n if((nx&3)==0 && (ny&3)==0) continue;\n score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;\n for(i=0; i<8; i++){\n if(score < best[i]){\n memmove(&best[i+1], &best[i], sizeof(int)*(7-i));\n memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));\n best[i]= score;\n best_pos[i][0]= nx + 4*mx;\n best_pos[i][1]= ny + 4*my;\n break;\n }\n }\n }\n }\n }\n for(i=0; i<subpel_quality; i++){\n nx= best_pos[i][0];\n ny= best_pos[i][1];\n CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)\n }\n#if 0\n const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];\n const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];\n const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];\n const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];\n if(tl<br){\n static int stats[7][7], count;\n count++;\n stats[4*mx - bx + 3][4*my - by + 3]++;\n if(256*256*256*64 % count ==0){\n for(i=0; i<49; i++){\n if((i%7)==0) printf("\\n");\n printf("%6d ", stats[0][i]);\n }\n printf("\\n");\n }\n }\n#endif\n#else\n CHECK_QUARTER_MV(2, 2, mx-1, my-1)\n CHECK_QUARTER_MV(0, 2, mx , my-1)\n CHECK_QUARTER_MV(2, 2, mx , my-1)\n CHECK_QUARTER_MV(2, 0, mx , my )\n CHECK_QUARTER_MV(2, 2, mx , my )\n CHECK_QUARTER_MV(0, 2, mx , my )\n CHECK_QUARTER_MV(2, 2, mx-1, my )\n CHECK_QUARTER_MV(2, 0, mx-1, my )\n nx= bx;\n ny= by;\n for(i=0; i<8; i++){\n int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};\n int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};\n CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)\n }\n#endif\n#if 0\n CHECK_QUARTER_MV(1, 3, mx-1, my-1)\n CHECK_QUARTER_MV(1, 2, mx-1, my-1)\n CHECK_QUARTER_MV(1, 1, mx-1, my-1)\n CHECK_QUARTER_MV(2, 1, mx-1, my-1)\n CHECK_QUARTER_MV(3, 1, mx-1, my-1)\n CHECK_QUARTER_MV(0, 1, mx , my-1)\n CHECK_QUARTER_MV(1, 1, mx , my-1)\n CHECK_QUARTER_MV(2, 1, mx , my-1)\n CHECK_QUARTER_MV(3, 1, mx , my-1)\n CHECK_QUARTER_MV(3, 2, mx , my-1)\n CHECK_QUARTER_MV(3, 3, mx , my-1)\n CHECK_QUARTER_MV(3, 0, mx , my )\n CHECK_QUARTER_MV(3, 1, mx , my )\n CHECK_QUARTER_MV(3, 2, mx , my )\n CHECK_QUARTER_MV(3, 3, mx , my )\n CHECK_QUARTER_MV(2, 3, mx , my )\n CHECK_QUARTER_MV(1, 3, mx , my )\n CHECK_QUARTER_MV(0, 3, mx , my )\n CHECK_QUARTER_MV(3, 3, mx-1, my )\n CHECK_QUARTER_MV(2, 3, mx-1, my )\n CHECK_QUARTER_MV(1, 3, mx-1, my )\n CHECK_QUARTER_MV(1, 2, mx-1, my )\n CHECK_QUARTER_MV(1, 1, mx-1, my )\n CHECK_QUARTER_MV(1, 0, mx-1, my )\n#endif\n assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);\n *mx_ptr = bx;\n *my_ptr = by;\n }else{\n *mx_ptr =4*mx;\n *my_ptr =4*my;\n }\n return dmin;\n}'] |
33,005 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_ctx.c/#L273 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)\n{\n BIGNUM *e;\n BN_CTX *ctx;\n BN_BLINDING *ret = NULL;\n if (in_ctx == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n return 0;\n } else {\n ctx = in_ctx;\n }\n BN_CTX_start(ctx);\n e = BN_CTX_get(ctx);\n if (e == NULL) {\n RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (rsa->e == NULL) {\n e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx);\n if (e == NULL) {\n RSAerr(RSA_F_RSA_SETUP_BLINDING, RSA_R_NO_PUBLIC_EXPONENT);\n goto err;\n }\n } else {\n e = rsa->e;\n }\n {\n BIGNUM *n = BN_new();\n if (n == NULL) {\n RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n BN_with_flags(n, rsa->n, BN_FLG_CONSTTIME);\n ret = BN_BLINDING_create_param(NULL, e, n, ctx, rsa->meth->bn_mod_exp,\n rsa->_method_mod_n);\n BN_free(n);\n }\n if (ret == NULL) {\n RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_BN_LIB);\n goto err;\n }\n BN_BLINDING_set_current_thread(ret);\n err:\n BN_CTX_end(ctx);\n if (ctx != in_ctx)\n BN_CTX_free(ctx);\n if (e != rsa->e)\n BN_free(e);\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}', '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}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
33,006 | 0 | https://github.com/libav/libav/blob/f52fd3f3b26f0d80e4f0b374b7695383feca5b92/avprobe.c/#L322 | static void old_print_object_footer(const char *name)
{
char *str, *p;
if (!strcmp(name, "tags"))
return;
str = p = av_strdup(name);
while (*p) {
*p = av_toupper(*p);
p++;
}
avio_printf(probe_out, "[/%s]\n", str);
av_freep(&str);
} | ['static void old_print_object_footer(const char *name)\n{\n char *str, *p;\n if (!strcmp(name, "tags"))\n return;\n str = p = av_strdup(name);\n while (*p) {\n *p = av_toupper(*p);\n p++;\n }\n avio_printf(probe_out, "[/%s]\\n", str);\n av_freep(&str);\n}', 'char *av_strdup(const char *s)\n{\n char *ptr = NULL;\n if (s) {\n int len = strlen(s) + 1;\n ptr = av_realloc(NULL, len);\n if (ptr)\n memcpy(ptr, s, len);\n }\n return ptr;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if (size > (INT_MAX - 16))\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if (!ptr)\n return av_malloc(size);\n diff = ((char *)ptr)[-1];\n return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}'] |
33,007 | 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)];
} | ['static int test_check_private_exponent(void)\n{\n int ret = 0;\n RSA *key = NULL;\n BN_CTX *ctx = NULL;\n BIGNUM *p = NULL, *q = NULL, *e = NULL, *d = NULL, *n = NULL;\n ret = TEST_ptr(key = RSA_new())\n && TEST_ptr(ctx = BN_CTX_new())\n && TEST_ptr(p = BN_new())\n && TEST_ptr(q = BN_new())\n && TEST_ptr(e = BN_new())\n && TEST_ptr(d = BN_new())\n && TEST_ptr(n = BN_new())\n && TEST_true(BN_set_word(p, 15))\n && TEST_true(BN_set_word(q, 17))\n && TEST_true(BN_set_word(e, 5))\n && TEST_true(BN_set_word(d, 157))\n && TEST_true(BN_set_word(n, 15*17))\n && TEST_true(RSA_set0_factors(key, p, q))\n && TEST_true(RSA_set0_key(key, n, e, d))\n && TEST_false(rsa_check_private_exponent(key, 8, ctx))\n && TEST_true(BN_set_word(d, 45))\n && TEST_true(rsa_check_private_exponent(key, 8, ctx))\n && TEST_false(rsa_check_private_exponent(key, 16, ctx))\n && TEST_true(BN_set_word(d, 16))\n && TEST_false(rsa_check_private_exponent(key, 8, ctx))\n && TEST_true(BN_set_word(d, 46))\n && TEST_false(rsa_check_private_exponent(key, 8, ctx));\n RSA_free(key);\n BN_CTX_free(ctx);\n return ret;\n}', 'int rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)\n{\n int ret;\n BIGNUM *r, *p1, *q1, *lcm, *p1q1, *gcd;\n if (BN_num_bits(rsa->d) <= (nbits >> 1))\n return 0;\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n p1 = BN_CTX_get(ctx);\n q1 = BN_CTX_get(ctx);\n lcm = BN_CTX_get(ctx);\n p1q1 = BN_CTX_get(ctx);\n gcd = BN_CTX_get(ctx);\n ret = (gcd != NULL\n && (rsa_get_lcm(ctx, rsa->p, rsa->q, lcm, gcd, p1, q1, p1q1) == 1)\n && (BN_cmp(rsa->d, lcm) < 0)\n && BN_mod_mul(r, rsa->e, rsa->d, lcm, ctx)\n && BN_is_one(r));\n BN_clear(p1);\n BN_clear(q1);\n BN_clear(lcm);\n BN_clear(gcd);\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 rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q,\n BIGNUM *lcm, BIGNUM *gcd, BIGNUM *p1, BIGNUM *q1,\n BIGNUM *p1q1)\n{\n return BN_sub(p1, p, BN_value_one())\n && BN_sub(q1, q, BN_value_one())\n && BN_mul(p1q1, p1, q1, ctx)\n && BN_gcd(gcd, p1, q1, ctx)\n && BN_div(lcm, NULL, p1q1, gcd, ctx);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', '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}'] |
33,008 | 0 | https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_mont.c/#L127 | static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
{
BIGNUM *n;
BN_ULONG *ap, *np, *rp, n0, v, carry;
int nl, max, i;
unsigned int rtop;
n = &(mont->N);
nl = n->top;
if (nl == 0) {
ret->top = 0;
return 1;
}
max = (2 * nl);
if (bn_wexpand(r, max) == NULL)
return 0;
r->neg ^= n->neg;
np = n->d;
rp = r->d;
for (rtop = r->top, i = 0; i < max; i++) {
v = (BN_ULONG)0 - ((i - rtop) >> (8 * sizeof(rtop) - 1));
rp[i] &= v;
}
r->top = max;
r->flags |= BN_FLG_FIXED_TOP;
n0 = mont->n0[0];
for (carry = 0, i = 0; i < nl; i++, rp++) {
v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
v = (v + carry + rp[nl]) & BN_MASK2;
carry |= (v != rp[nl]);
carry &= (v <= rp[nl]);
rp[nl] = v;
}
if (bn_wexpand(ret, nl) == NULL)
return 0;
ret->top = nl;
ret->flags |= BN_FLG_FIXED_TOP;
ret->neg = r->neg;
rp = ret->d;
ap = &(r->d[nl]);
carry -= bn_sub_words(rp, ap, np, nl);
for (i = 0; i < nl; i++) {
rp[i] = (carry & ap[i]) | (~carry & rp[i]);
ap[i] = 0;
}
return 1;
} | ['int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)\n{\n int ret = 1;\n bn_check_top(n);\n if ((b->A == NULL) || (b->Ai == NULL)) {\n BNerr(BN_F_BN_BLINDING_CONVERT_EX, BN_R_NOT_INITIALIZED);\n return 0;\n }\n if (b->counter == -1)\n b->counter = 0;\n else if (!BN_BLINDING_update(b, ctx))\n return 0;\n if (r != NULL && (BN_copy(r, b->Ai) == NULL))\n return 0;\n if (b->m_ctx != NULL)\n ret = BN_mod_mul_montgomery(n, n, b->A, b->m_ctx, ctx);\n else\n ret = BN_mod_mul(n, n, b->A, b->mod, ctx);\n return ret;\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n int ret = bn_mul_mont_fixed_top(r, a, b, mont, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n unsigned int rtop;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return 1;\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return 0;\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n for (rtop = r->top, i = 0; i < max; i++) {\n v = (BN_ULONG)0 - ((i - rtop) >> (8 * sizeof(rtop) - 1));\n rp[i] &= v;\n }\n r->top = max;\n r->flags |= BN_FLG_FIXED_TOP;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return 0;\n ret->top = nl;\n ret->flags |= BN_FLG_FIXED_TOP;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n carry -= bn_sub_words(rp, ap, np, nl);\n for (i = 0; i < nl; i++) {\n rp[i] = (carry & ap[i]) | (~carry & rp[i]);\n ap[i] = 0;\n }\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}'] |
33,009 | 0 | https://github.com/nginx/nginx/blob/ba290091cf2c369ae36c6c3845f770f85f1172e6/src/core/ngx_hash.c/#L962 | ngx_int_t
ngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, void *value,
ngx_uint_t flags)
{
size_t len;
u_char *p;
ngx_str_t *name;
ngx_uint_t i, k, n, skip, last;
ngx_array_t *keys, *hwc;
ngx_hash_key_t *hk;
last = key->len;
if (flags & NGX_HASH_WILDCARD_KEY) {
n = 0;
for (i = 0; i < key->len; i++) {
if (key->data[i] == '*') {
if (++n > 1) {
return NGX_DECLINED;
}
}
if (key->data[i] == '.' && key->data[i + 1] == '.') {
return NGX_DECLINED;
}
}
if (key->len > 1 && key->data[0] == '.') {
skip = 1;
goto wildcard;
}
if (key->len > 2) {
if (key->data[0] == '*' && key->data[1] == '.') {
skip = 2;
goto wildcard;
}
if (key->data[i - 2] == '.' && key->data[i - 1] == '*') {
skip = 0;
last -= 2;
goto wildcard;
}
}
if (n) {
return NGX_DECLINED;
}
}
k = 0;
for (i = 0; i < last; i++) {
if (!(flags & NGX_HASH_READONLY_KEY)) {
key->data[i] = ngx_tolower(key->data[i]);
}
k = ngx_hash(k, key->data[i]);
}
k %= ha->hsize;
name = ha->keys_hash[k].elts;
if (name) {
for (i = 0; i < ha->keys_hash[k].nelts; i++) {
if (last != name[i].len) {
continue;
}
if (ngx_strncmp(key->data, name[i].data, last) == 0) {
return NGX_BUSY;
}
}
} else {
if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,
sizeof(ngx_str_t))
!= NGX_OK)
{
return NGX_ERROR;
}
}
name = ngx_array_push(&ha->keys_hash[k]);
if (name == NULL) {
return NGX_ERROR;
}
*name = *key;
hk = ngx_array_push(&ha->keys);
if (hk == NULL) {
return NGX_ERROR;
}
hk->key = *key;
hk->key_hash = ngx_hash_key(key->data, last);
hk->value = value;
return NGX_OK;
wildcard:
k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip);
k %= ha->hsize;
if (skip == 1) {
name = ha->keys_hash[k].elts;
if (name) {
len = last - skip;
for (i = 0; i < ha->keys_hash[k].nelts; i++) {
if (len != name[i].len) {
continue;
}
if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) {
return NGX_BUSY;
}
}
} else {
if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,
sizeof(ngx_str_t))
!= NGX_OK)
{
return NGX_ERROR;
}
}
name = ngx_array_push(&ha->keys_hash[k]);
if (name == NULL) {
return NGX_ERROR;
}
name->len = last - 1;
name->data = ngx_pnalloc(ha->temp_pool, name->len);
if (name->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(name->data, &key->data[1], name->len);
}
if (skip) {
p = ngx_pnalloc(ha->temp_pool, last);
if (p == NULL) {
return NGX_ERROR;
}
len = 0;
n = 0;
for (i = last - 1; i; i--) {
if (key->data[i] == '.') {
ngx_memcpy(&p[n], &key->data[i + 1], len);
n += len;
p[n++] = '.';
len = 0;
continue;
}
len++;
}
if (len) {
ngx_memcpy(&p[n], &key->data[1], len);
n += len;
}
p[n] = '\0';
hwc = &ha->dns_wc_head;
keys = &ha->dns_wc_head_hash[k];
} else {
last++;
p = ngx_pnalloc(ha->temp_pool, last);
if (p == NULL) {
return NGX_ERROR;
}
ngx_cpystrn(p, key->data, last);
hwc = &ha->dns_wc_tail;
keys = &ha->dns_wc_tail_hash[k];
}
name = keys->elts;
if (name) {
len = last - skip;
for (i = 0; i < keys->nelts; i++) {
if (len != name[i].len) {
continue;
}
if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {
return NGX_BUSY;
}
}
} else {
if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)
{
return NGX_ERROR;
}
}
name = ngx_array_push(keys);
if (name == NULL) {
return NGX_ERROR;
}
name->len = last - skip;
name->data = ngx_pnalloc(ha->temp_pool, name->len);
if (name->data == NULL) {
return NGX_ERROR;
}
ngx_memcpy(name->data, key->data + skip, name->len);
hk = ngx_array_push(hwc);
if (hk == NULL) {
return NGX_ERROR;
}
hk->key.len = last - 1;
hk->key.data = p;
hk->key_hash = 0;
hk->value = value;
return NGX_OK;
} | ['static char *\nngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_rewrite_loc_conf_t *lcf = conf;\n ngx_int_t index;\n ngx_str_t *value;\n ngx_http_variable_t *v;\n ngx_http_script_var_code_t *vcode;\n ngx_http_script_var_handler_code_t *vhcode;\n value = cf->args->elts;\n if (value[1].len < 2 || value[1].data[0] != \'$\') {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"%V\\"", &value[1]);\n return NGX_CONF_ERROR;\n }\n value[1].len--;\n value[1].data++;\n v = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE);\n if (v == NULL) {\n return NGX_CONF_ERROR;\n }\n index = ngx_http_get_variable_index(cf, &value[1]);\n if (index == NGX_ERROR) {\n return NGX_CONF_ERROR;\n }\n if (v->get_handler == NULL\n && ngx_strncasecmp(value[1].data, (u_char *) "http_", 5) != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "sent_http_", 10) != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "upstream_http_", 14) != 0)\n {\n v->get_handler = ngx_http_rewrite_var;\n v->data = index;\n }\n if (ngx_http_rewrite_value(cf, lcf, &value[2]) != NGX_CONF_OK) {\n return NGX_CONF_ERROR;\n }\n if (v->set_handler) {\n vhcode = ngx_http_script_start_code(cf->pool, &lcf->codes,\n sizeof(ngx_http_script_var_handler_code_t));\n if (vhcode == NULL) {\n return NGX_CONF_ERROR;\n }\n vhcode->code = ngx_http_script_var_set_handler_code;\n vhcode->handler = v->set_handler;\n vhcode->data = v->data;\n return NGX_CONF_OK;\n }\n vcode = ngx_http_script_start_code(cf->pool, &lcf->codes,\n sizeof(ngx_http_script_var_code_t));\n if (vcode == NULL) {\n return NGX_CONF_ERROR;\n }\n vcode->code = ngx_http_script_set_var_code;\n vcode->index = (uintptr_t) index;\n return NGX_CONF_OK;\n}', 'ngx_http_variable_t *\nngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)\n{\n ngx_int_t rc;\n ngx_uint_t i;\n ngx_hash_key_t *key;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n key = cmcf->variables_keys->keys.elts;\n for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) {\n if (name->len != key[i].key.len\n || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0)\n {\n continue;\n }\n v = key[i].value;\n if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "the duplicate \\"%V\\" variable", name);\n return NULL;\n }\n return v;\n }\n v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t));\n if (v == NULL) {\n return NULL;\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 NULL;\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 = flags;\n v->index = 0;\n rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0);\n if (rc == NGX_ERROR) {\n return NULL;\n }\n if (rc == NGX_BUSY) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "conflicting variable name \\"%V\\"", name);\n return NULL;\n }\n return v;\n}', "ngx_int_t\nngx_hash_add_key(ngx_hash_keys_arrays_t *ha, ngx_str_t *key, void *value,\n ngx_uint_t flags)\n{\n size_t len;\n u_char *p;\n ngx_str_t *name;\n ngx_uint_t i, k, n, skip, last;\n ngx_array_t *keys, *hwc;\n ngx_hash_key_t *hk;\n last = key->len;\n if (flags & NGX_HASH_WILDCARD_KEY) {\n n = 0;\n for (i = 0; i < key->len; i++) {\n if (key->data[i] == '*') {\n if (++n > 1) {\n return NGX_DECLINED;\n }\n }\n if (key->data[i] == '.' && key->data[i + 1] == '.') {\n return NGX_DECLINED;\n }\n }\n if (key->len > 1 && key->data[0] == '.') {\n skip = 1;\n goto wildcard;\n }\n if (key->len > 2) {\n if (key->data[0] == '*' && key->data[1] == '.') {\n skip = 2;\n goto wildcard;\n }\n if (key->data[i - 2] == '.' && key->data[i - 1] == '*') {\n skip = 0;\n last -= 2;\n goto wildcard;\n }\n }\n if (n) {\n return NGX_DECLINED;\n }\n }\n k = 0;\n for (i = 0; i < last; i++) {\n if (!(flags & NGX_HASH_READONLY_KEY)) {\n key->data[i] = ngx_tolower(key->data[i]);\n }\n k = ngx_hash(k, key->data[i]);\n }\n k %= ha->hsize;\n name = ha->keys_hash[k].elts;\n if (name) {\n for (i = 0; i < ha->keys_hash[k].nelts; i++) {\n if (last != name[i].len) {\n continue;\n }\n if (ngx_strncmp(key->data, name[i].data, last) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,\n sizeof(ngx_str_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(&ha->keys_hash[k]);\n if (name == NULL) {\n return NGX_ERROR;\n }\n *name = *key;\n hk = ngx_array_push(&ha->keys);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key = *key;\n hk->key_hash = ngx_hash_key(key->data, last);\n hk->value = value;\n return NGX_OK;\nwildcard:\n k = ngx_hash_strlow(&key->data[skip], &key->data[skip], last - skip);\n k %= ha->hsize;\n if (skip == 1) {\n name = ha->keys_hash[k].elts;\n if (name) {\n len = last - skip;\n for (i = 0; i < ha->keys_hash[k].nelts; i++) {\n if (len != name[i].len) {\n continue;\n }\n if (ngx_strncmp(&key->data[1], name[i].data, len) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(&ha->keys_hash[k], ha->temp_pool, 4,\n sizeof(ngx_str_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(&ha->keys_hash[k]);\n if (name == NULL) {\n return NGX_ERROR;\n }\n name->len = last - 1;\n name->data = ngx_pnalloc(ha->temp_pool, name->len);\n if (name->data == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(name->data, &key->data[1], name->len);\n }\n if (skip) {\n p = ngx_pnalloc(ha->temp_pool, last);\n if (p == NULL) {\n return NGX_ERROR;\n }\n len = 0;\n n = 0;\n for (i = last - 1; i; i--) {\n if (key->data[i] == '.') {\n ngx_memcpy(&p[n], &key->data[i + 1], len);\n n += len;\n p[n++] = '.';\n len = 0;\n continue;\n }\n len++;\n }\n if (len) {\n ngx_memcpy(&p[n], &key->data[1], len);\n n += len;\n }\n p[n] = '\\0';\n hwc = &ha->dns_wc_head;\n keys = &ha->dns_wc_head_hash[k];\n } else {\n last++;\n p = ngx_pnalloc(ha->temp_pool, last);\n if (p == NULL) {\n return NGX_ERROR;\n }\n ngx_cpystrn(p, key->data, last);\n hwc = &ha->dns_wc_tail;\n keys = &ha->dns_wc_tail_hash[k];\n }\n name = keys->elts;\n if (name) {\n len = last - skip;\n for (i = 0; i < keys->nelts; i++) {\n if (len != name[i].len) {\n continue;\n }\n if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {\n return NGX_BUSY;\n }\n }\n } else {\n if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)\n {\n return NGX_ERROR;\n }\n }\n name = ngx_array_push(keys);\n if (name == NULL) {\n return NGX_ERROR;\n }\n name->len = last - skip;\n name->data = ngx_pnalloc(ha->temp_pool, name->len);\n if (name->data == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(name->data, key->data + skip, name->len);\n hk = ngx_array_push(hwc);\n if (hk == NULL) {\n return NGX_ERROR;\n }\n hk->key.len = last - 1;\n hk->key.data = p;\n hk->key_hash = 0;\n hk->value = value;\n return NGX_OK;\n}"] |
33,010 | 0 | https://github.com/libav/libav/blob/606cc8afa1cb782311f68560c8f9bad978cdcc32/libswscale/utils.c/#L187 | int sws_isSupportedInput(enum AVPixelFormat pix_fmt)
{
return (unsigned)pix_fmt < AV_PIX_FMT_NB ?
format_entries[pix_fmt].is_supported_in : 0;
} | ['int show_pix_fmts(void *optctx, const char *opt, const char *arg)\n{\n const AVPixFmtDescriptor *pix_desc = NULL;\n printf("Pixel formats:\\n"\n "I.... = Supported Input format for conversion\\n"\n ".O... = Supported Output format for conversion\\n"\n "..H.. = Hardware accelerated format\\n"\n "...P. = Paletted format\\n"\n "....B = Bitstream format\\n"\n "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\\n"\n "-----\\n");\n#if !CONFIG_SWSCALE\n# define sws_isSupportedInput(x) 0\n# define sws_isSupportedOutput(x) 0\n#endif\n while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {\n enum AVPixelFormat pix_fmt = av_pix_fmt_desc_get_id(pix_desc);\n printf("%c%c%c%c%c %-16s %d %2d\\n",\n sws_isSupportedInput (pix_fmt) ? \'I\' : \'.\',\n sws_isSupportedOutput(pix_fmt) ? \'O\' : \'.\',\n pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ? \'H\' : \'.\',\n pix_desc->flags & AV_PIX_FMT_FLAG_PAL ? \'P\' : \'.\',\n pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? \'B\' : \'.\',\n pix_desc->name,\n pix_desc->nb_components,\n av_get_bits_per_pixel(pix_desc));\n }\n return 0;\n}', 'enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)\n{\n if (desc < av_pix_fmt_descriptors ||\n desc >= av_pix_fmt_descriptors + FF_ARRAY_ELEMS(av_pix_fmt_descriptors))\n return AV_PIX_FMT_NONE;\n return desc - av_pix_fmt_descriptors;\n}', 'int sws_isSupportedInput(enum AVPixelFormat pix_fmt)\n{\n return (unsigned)pix_fmt < AV_PIX_FMT_NB ?\n format_entries[pix_fmt].is_supported_in : 0;\n}'] |
33,011 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/cavsdec.c/#L363 | static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {
int block;
enum sub_mb_t sub_type[4];
int flags;
ff_cavs_init_mb(h);
h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
switch(mb_type) {
case B_SKIP:
case B_DIRECT:
if(!(*h->col_type)) {
ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
} else
for(block=0;block<4;block++)
mv_pred_direct(h,&h->mv[mv_scan[block]],
&h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);
break;
case B_FWD_16X16:
ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
break;
case B_SYM_16X16:
ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
break;
case B_BWD_16X16:
ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);
break;
case B_8X8:
for(block=0;block<4;block++)
sub_type[block] = get_bits(&h->s.gb,2);
for(block=0;block<4;block++) {
switch(sub_type[block]) {
case B_SUB_DIRECT:
if(!(*h->col_type)) {
ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,
MV_PRED_BSKIP, BLK_8X8, 1);
ff_cavs_mv(h, mv_scan[block]+MV_BWD_OFFS,
mv_scan[block]-3+MV_BWD_OFFS,
MV_PRED_BSKIP, BLK_8X8, 0);
} else
mv_pred_direct(h,&h->mv[mv_scan[block]],
&h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);
break;
case B_SUB_FWD:
ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,
MV_PRED_MEDIAN, BLK_8X8, 1);
break;
case B_SUB_SYM:
ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,
MV_PRED_MEDIAN, BLK_8X8, 1);
mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
break;
}
}
for(block=0;block<4;block++) {
if(sub_type[block] == B_SUB_BWD)
ff_cavs_mv(h, mv_scan[block]+MV_BWD_OFFS,
mv_scan[block]+MV_BWD_OFFS-3,
MV_PRED_MEDIAN, BLK_8X8, 0);
}
break;
default:
assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));
flags = ff_cavs_partition_flags[mb_type];
if(mb_type & 1) {
if(flags & FWD0)
ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
if(flags & SYM0)
mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
if(flags & FWD1)
ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
if(flags & SYM1)
mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
if(flags & BWD0)
ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);
if(flags & BWD1)
ff_cavs_mv(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);
} else {
if(flags & FWD0)
ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
if(flags & SYM0)
mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
if(flags & FWD1)
ff_cavs_mv(h,MV_FWD_X1,MV_FWD_C2,MV_PRED_TOPRIGHT,BLK_8X16,1);
if(flags & SYM1)
mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
if(flags & BWD0)
ff_cavs_mv(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);
if(flags & BWD1)
ff_cavs_mv(h,MV_BWD_X1,MV_BWD_C2,MV_PRED_TOPRIGHT,BLK_8X16,0);
}
}
ff_cavs_inter(h, mb_type);
set_intra_mode_default(h);
if(mb_type != B_SKIP)
decode_residual_inter(h);
ff_cavs_filter(h,mb_type);
} | ['static void decode_mb_b(AVSContext *h, enum mb_t mb_type) {\n int block;\n enum sub_mb_t sub_type[4];\n int flags;\n ff_cavs_init_mb(h);\n h->mv[MV_FWD_X0] = ff_cavs_dir_mv;\n set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);\n h->mv[MV_BWD_X0] = ff_cavs_dir_mv;\n set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);\n switch(mb_type) {\n case B_SKIP:\n case B_DIRECT:\n if(!(*h->col_type)) {\n ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);\n ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);\n } else\n for(block=0;block<4;block++)\n mv_pred_direct(h,&h->mv[mv_scan[block]],\n &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]);\n break;\n case B_FWD_16X16:\n ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);\n break;\n case B_SYM_16X16:\n ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);\n mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);\n break;\n case B_BWD_16X16:\n ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);\n break;\n case B_8X8:\n for(block=0;block<4;block++)\n sub_type[block] = get_bits(&h->s.gb,2);\n for(block=0;block<4;block++) {\n switch(sub_type[block]) {\n case B_SUB_DIRECT:\n if(!(*h->col_type)) {\n ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,\n MV_PRED_BSKIP, BLK_8X8, 1);\n ff_cavs_mv(h, mv_scan[block]+MV_BWD_OFFS,\n mv_scan[block]-3+MV_BWD_OFFS,\n MV_PRED_BSKIP, BLK_8X8, 0);\n } else\n mv_pred_direct(h,&h->mv[mv_scan[block]],\n &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]);\n break;\n case B_SUB_FWD:\n ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,\n MV_PRED_MEDIAN, BLK_8X8, 1);\n break;\n case B_SUB_SYM:\n ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3,\n MV_PRED_MEDIAN, BLK_8X8, 1);\n mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);\n break;\n }\n }\n for(block=0;block<4;block++) {\n if(sub_type[block] == B_SUB_BWD)\n ff_cavs_mv(h, mv_scan[block]+MV_BWD_OFFS,\n mv_scan[block]+MV_BWD_OFFS-3,\n MV_PRED_MEDIAN, BLK_8X8, 0);\n }\n break;\n default:\n assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));\n flags = ff_cavs_partition_flags[mb_type];\n if(mb_type & 1) {\n if(flags & FWD0)\n ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);\n if(flags & SYM0)\n mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);\n if(flags & FWD1)\n ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);\n if(flags & SYM1)\n mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);\n if(flags & BWD0)\n ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);\n if(flags & BWD1)\n ff_cavs_mv(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);\n } else {\n if(flags & FWD0)\n ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);\n if(flags & SYM0)\n mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);\n if(flags & FWD1)\n ff_cavs_mv(h,MV_FWD_X1,MV_FWD_C2,MV_PRED_TOPRIGHT,BLK_8X16,1);\n if(flags & SYM1)\n mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);\n if(flags & BWD0)\n ff_cavs_mv(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);\n if(flags & BWD1)\n ff_cavs_mv(h,MV_BWD_X1,MV_BWD_C2,MV_PRED_TOPRIGHT,BLK_8X16,0);\n }\n }\n ff_cavs_inter(h, mb_type);\n set_intra_mode_default(h);\n if(mb_type != B_SKIP)\n decode_residual_inter(h);\n ff_cavs_filter(h,mb_type);\n}'] |
33,012 | 0 | https://github.com/openssl/openssl/blob/8de2910b5cbfa6169b54d1267abf654da773f00a/crypto/rsa/rsa_lib.c/#L139 | int RSA_set_method(RSA *rsa, ENGINE *engine)
{
ENGINE *mtmp;
const RSA_METHOD *meth;
mtmp = rsa->engine;
meth = ENGINE_get_RSA(mtmp);
if (!ENGINE_init(engine))
return 0;
if (meth->finish) meth->finish(rsa);
rsa->engine = engine;
meth = ENGINE_get_RSA(engine);
if (meth->init) meth->init(rsa);
ENGINE_finish(mtmp);
return 1;
} | ['int RSA_set_method(RSA *rsa, ENGINE *engine)\n{\n\tENGINE *mtmp;\n\tconst RSA_METHOD *meth;\n\tmtmp = rsa->engine;\n\tmeth = ENGINE_get_RSA(mtmp);\n\tif (!ENGINE_init(engine))\n\t\treturn 0;\n\tif (meth->finish) meth->finish(rsa);\n\trsa->engine = engine;\n\tmeth = ENGINE_get_RSA(engine);\n\tif (meth->init) meth->init(rsa);\n\tENGINE_finish(mtmp);\n\treturn 1;\n}', 'const RSA_METHOD *ENGINE_get_RSA(ENGINE *e)\n\t{\n\tif(e == NULL)\n\t\t{\n\t\tENGINEerr(ENGINE_F_ENGINE_GET_RSA,\n\t\t\tERR_R_PASSED_NULL_PARAMETER);\n\t\treturn NULL;\n\t\t}\n\treturn e->rsa_meth;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int ENGINE_init(ENGINE *e)\n\t{\n\tint to_return = 1;\n\tif(e == NULL)\n\t\t{\n\t\tENGINEerr(ENGINE_F_ENGINE_INIT,ERR_R_PASSED_NULL_PARAMETER);\n\t\treturn 0;\n\t\t}\n\tCRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n\tif((e->funct_ref == 0) && e->init)\n\t\tto_return = e->init();\n\tif(to_return)\n\t\t{\n\t\te->struct_ref++;\n\t\te->funct_ref++;\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n\treturn to_return;\n\t}', '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}'] |
33,013 | 0 | https://github.com/libav/libav/blob/4f0b80599a534dcca57be3184b89b98f82bf2a2c/libavformat/assdec.c/#L158 | static int read_packet(AVFormatContext *s, AVPacket *pkt)
{
ASSContext *ass = s->priv_data;
uint8_t *p, *end;
if(ass->event_index >= ass->event_count)
return AVERROR(EIO);
p= ass->event[ ass->event_index ];
end= strchr(p, '\n');
av_new_packet(pkt, end ? end-p+1 : strlen(p));
pkt->flags |= AV_PKT_FLAG_KEY;
pkt->pos= p - ass->event_buffer + s->streams[0]->codec->extradata_size;
pkt->pts= pkt->dts= get_pts(p);
memcpy(pkt->data, p, pkt->size);
ass->event_index++;
return 0;
} | ["static int read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n ASSContext *ass = s->priv_data;\n uint8_t *p, *end;\n if(ass->event_index >= ass->event_count)\n return AVERROR(EIO);\n p= ass->event[ ass->event_index ];\n end= strchr(p, '\\n');\n av_new_packet(pkt, end ? end-p+1 : strlen(p));\n pkt->flags |= AV_PKT_FLAG_KEY;\n pkt->pos= p - ass->event_buffer + s->streams[0]->codec->extradata_size;\n pkt->pts= pkt->dts= get_pts(p);\n memcpy(pkt->data, p, pkt->size);\n ass->event_index++;\n return 0;\n}", 'int av_new_packet(AVPacket *pkt, int size)\n{\n uint8_t *data= NULL;\n if((unsigned)size < (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (data){\n memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n }else\n size=0;\n av_init_packet(pkt);\n pkt->data = data;\n pkt->size = size;\n pkt->destruct = av_destruct_packet;\n if(!data)\n return AVERROR(ENOMEM);\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n 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}', 'void av_init_packet(AVPacket *pkt)\n{\n pkt->pts = AV_NOPTS_VALUE;\n pkt->dts = AV_NOPTS_VALUE;\n pkt->pos = -1;\n pkt->duration = 0;\n pkt->convergence_duration = 0;\n pkt->flags = 0;\n pkt->stream_index = 0;\n pkt->destruct= NULL;\n pkt->side_data = NULL;\n pkt->side_data_elems = 0;\n}', 'static int64_t get_pts(const uint8_t *p)\n{\n int hour, min, sec, hsec;\n if(sscanf(p, "%*[^,],%d:%d:%d%*c%d", &hour, &min, &sec, &hsec) != 4)\n return AV_NOPTS_VALUE;\n min+= 60*hour;\n sec+= 60*min;\n return sec*100+hsec;\n}'] |
33,014 | 0 | https://github.com/openssl/openssl/blob/f345b1f39d9b4e4c9ef07e7522e9b2a870c9ca09/crypto/bn/bn_lib.c/#L96 | int BN_num_bits_word(BN_ULONG l)
{
BN_ULONG x, mask;
int bits = (l != 0);
#if BN_BITS2 > 32
x = l >> 32;
mask = (0 - x) & BN_MASK2;
mask = (0 - (mask >> (BN_BITS2 - 1)));
bits += 32 & mask;
l ^= (x ^ l) & mask;
#endif
x = l >> 16;
mask = (0 - x) & BN_MASK2;
mask = (0 - (mask >> (BN_BITS2 - 1)));
bits += 16 & mask;
l ^= (x ^ l) & mask;
x = l >> 8;
mask = (0 - x) & BN_MASK2;
mask = (0 - (mask >> (BN_BITS2 - 1)));
bits += 8 & mask;
l ^= (x ^ l) & mask;
x = l >> 4;
mask = (0 - x) & BN_MASK2;
mask = (0 - (mask >> (BN_BITS2 - 1)));
bits += 4 & mask;
l ^= (x ^ l) & mask;
x = l >> 2;
mask = (0 - x) & BN_MASK2;
mask = (0 - (mask >> (BN_BITS2 - 1)));
bits += 2 & mask;
l ^= (x ^ l) & mask;
x = l >> 1;
mask = (0 - x) & BN_MASK2;
mask = (0 - (mask >> (BN_BITS2 - 1)));
bits += 1 & mask;
return bits;
} | ['BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,\n const BIGNUM *x, const BIGNUM *a, const BIGNUM *u)\n{\n BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL\n || a == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((tmp = BN_new()) == NULL ||\n (tmp2 = BN_new()) == NULL ||\n (tmp3 = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, g, x, N, bn_ctx))\n goto err;\n if ((k = srp_Calc_k(N, g)) == NULL)\n goto err;\n if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))\n goto err;\n if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))\n goto err;\n if (!BN_mul(tmp3, u, x, bn_ctx))\n goto err;\n if (!BN_add(tmp2, a, tmp3))\n goto err;\n K = BN_new();\n if (K != NULL && !BN_mod_exp(K, tmp, tmp2, N, bn_ctx)) {\n BN_free(K);\n K = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n BN_clear_free(tmp2);\n BN_clear_free(tmp3);\n BN_free(k);\n return K;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'static BIGNUM *srp_Calc_k(const BIGNUM *N, const BIGNUM *g)\n{\n return srp_Calc_xy(N, g, N);\n}', 'static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N)\n{\n unsigned char digest[SHA_DIGEST_LENGTH];\n unsigned char *tmp = NULL;\n int numN = BN_num_bytes(N);\n BIGNUM *res = NULL;\n if (x != N && BN_ucmp(x, N) >= 0)\n return NULL;\n if (y != N && BN_ucmp(y, N) >= 0)\n return NULL;\n if ((tmp = OPENSSL_malloc(numN * 2)) == NULL)\n goto err;\n if (BN_bn2binpad(x, tmp, numN) < 0\n || BN_bn2binpad(y, tmp + numN, numN) < 0\n || !EVP_Digest(tmp, numN * 2, digest, NULL, EVP_sha1(), NULL))\n goto err;\n res = BN_bin2bn(digest, sizeof(digest), NULL);\n err:\n OPENSSL_free(tmp);\n return res;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_sub(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top,\n unsigned char *buf, int idx,\n int window)\n{\n int i, j;\n int width = 1 << window;\n volatile BN_ULONG *table = (volatile BN_ULONG *)buf;\n if (bn_wexpand(b, top) == NULL)\n return 0;\n if (window <= 3) {\n for (i = 0; i < top; i++, table += width) {\n BN_ULONG acc = 0;\n for (j = 0; j < width; j++) {\n acc |= table[j] &\n ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));\n }\n b->d[i] = acc;\n }\n } else {\n int xstride = 1 << (window - 2);\n BN_ULONG y0, y1, y2, y3;\n i = idx >> (window - 2);\n idx &= xstride - 1;\n y0 = (BN_ULONG)0 - (constant_time_eq_int(i,0)&1);\n y1 = (BN_ULONG)0 - (constant_time_eq_int(i,1)&1);\n y2 = (BN_ULONG)0 - (constant_time_eq_int(i,2)&1);\n y3 = (BN_ULONG)0 - (constant_time_eq_int(i,3)&1);\n for (i = 0; i < top; i++, table += width) {\n BN_ULONG acc = 0;\n for (j = 0; j < xstride; j++) {\n acc |= ( (table[j + 0 * xstride] & y0) |\n (table[j + 1 * xstride] & y1) |\n (table[j + 2 * xstride] & y2) |\n (table[j + 3 * xstride] & y3) )\n & ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));\n }\n b->d[i] = acc;\n }\n }\n b->top = top;\n bn_correct_top(b);\n return 1;\n}', '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}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_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 if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_num_bits_word(BN_ULONG l)\n{\n BN_ULONG x, mask;\n int bits = (l != 0);\n#if BN_BITS2 > 32\n x = l >> 32;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 32 & mask;\n l ^= (x ^ l) & mask;\n#endif\n x = l >> 16;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 16 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 8;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 8 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 4;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 4 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 2;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 2 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 1;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 1 & mask;\n return bits;\n}'] |
33,015 | 0 | https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/x509/x509_obj.c/#L96 | char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
{
X509_NAME_ENTRY *ne;
int i;
int n, lold, l, l1, l2, num, j, type;
const char *s;
char *p;
unsigned char *q;
BUF_MEM *b = NULL;
static const char hex[17] = "0123456789ABCDEF";
int gs_doit[4];
char tmp_buf[80];
#ifdef CHARSET_EBCDIC
char ebcdic_buf[1024];
#endif
if (buf == NULL) {
if ((b = BUF_MEM_new()) == NULL)
goto err;
if (!BUF_MEM_grow(b, 200))
goto err;
b->data[0] = '\0';
len = 200;
}
if (a == NULL) {
if (b) {
buf = b->data;
OPENSSL_free(b);
}
strncpy(buf, "NO X509_NAME", len);
buf[len - 1] = '\0';
return buf;
}
len--;
l = 0;
for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
ne = sk_X509_NAME_ENTRY_value(a->entries, i);
n = OBJ_obj2nid(ne->object);
if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
s = tmp_buf;
}
l1 = strlen(s);
type = ne->value->type;
num = ne->value->length;
q = ne->value->data;
#ifdef CHARSET_EBCDIC
if (type == V_ASN1_GENERALSTRING ||
type == V_ASN1_VISIBLESTRING ||
type == V_ASN1_PRINTABLESTRING ||
type == V_ASN1_TELETEXSTRING ||
type == V_ASN1_VISIBLESTRING || type == V_ASN1_IA5STRING) {
ascii2ebcdic(ebcdic_buf, q, (num > sizeof ebcdic_buf)
? sizeof ebcdic_buf : num);
q = ebcdic_buf;
}
#endif
if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
for (j = 0; j < num; j++)
if (q[j] != 0)
gs_doit[j & 3] = 1;
if (gs_doit[0] | gs_doit[1] | gs_doit[2])
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
else {
gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
gs_doit[3] = 1;
}
} else
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
for (l2 = j = 0; j < num; j++) {
if (!gs_doit[j & 3])
continue;
l2++;
#ifndef CHARSET_EBCDIC
if ((q[j] < ' ') || (q[j] > '~'))
l2 += 3;
#else
if ((os_toascii[q[j]] < os_toascii[' ']) ||
(os_toascii[q[j]] > os_toascii['~']))
l2 += 3;
#endif
}
lold = l;
l += 1 + l1 + 1 + l2;
if (b != NULL) {
if (!BUF_MEM_grow(b, l + 1))
goto err;
p = &(b->data[lold]);
} else if (l > len) {
break;
} else
p = &(buf[lold]);
*(p++) = '/';
memcpy(p, s, (unsigned int)l1);
p += l1;
*(p++) = '=';
#ifndef CHARSET_EBCDIC
q = ne->value->data;
#endif
for (j = 0; j < num; j++) {
if (!gs_doit[j & 3])
continue;
#ifndef CHARSET_EBCDIC
n = q[j];
if ((n < ' ') || (n > '~')) {
*(p++) = '\\';
*(p++) = 'x';
*(p++) = hex[(n >> 4) & 0x0f];
*(p++) = hex[n & 0x0f];
} else
*(p++) = n;
#else
n = os_toascii[q[j]];
if ((n < os_toascii[' ']) || (n > os_toascii['~'])) {
*(p++) = '\\';
*(p++) = 'x';
*(p++) = hex[(n >> 4) & 0x0f];
*(p++) = hex[n & 0x0f];
} else
*(p++) = q[j];
#endif
}
*p = '\0';
}
if (b != NULL) {
p = b->data;
OPENSSL_free(b);
} else
p = buf;
if (i == 0)
*p = '\0';
return (p);
err:
X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
BUF_MEM_free(b);
return (NULL);
} | ['static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,\n void *exarg)\n{\n X509 *ret = (X509 *)*pval;\n switch (operation) {\n case ASN1_OP_NEW_POST:\n ret->name = NULL;\n ret->ex_flags = 0;\n ret->ex_pathlen = -1;\n ret->skid = NULL;\n ret->akid = NULL;\n#ifndef OPENSSL_NO_RFC3779\n ret->rfc3779_addr = NULL;\n ret->rfc3779_asid = NULL;\n#endif\n ret->aux = NULL;\n ret->crldp = NULL;\n CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);\n break;\n case ASN1_OP_D2I_POST:\n OPENSSL_free(ret->name);\n ret->name = X509_NAME_oneline(ret->cert_info.subject, NULL, 0);\n break;\n case ASN1_OP_FREE_POST:\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);\n X509_CERT_AUX_free(ret->aux);\n ASN1_OCTET_STRING_free(ret->skid);\n AUTHORITY_KEYID_free(ret->akid);\n CRL_DIST_POINTS_free(ret->crldp);\n policy_cache_free(ret->policy_cache);\n GENERAL_NAMES_free(ret->altname);\n NAME_CONSTRAINTS_free(ret->nc);\n#ifndef OPENSSL_NO_RFC3779\n sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);\n ASIdentifiers_free(ret->rfc3779_asid);\n#endif\n OPENSSL_free(ret->name);\n break;\n }\n return 1;\n}', 'char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)\n{\n X509_NAME_ENTRY *ne;\n int i;\n int n, lold, l, l1, l2, num, j, type;\n const char *s;\n char *p;\n unsigned char *q;\n BUF_MEM *b = NULL;\n static const char hex[17] = "0123456789ABCDEF";\n int gs_doit[4];\n char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n char ebcdic_buf[1024];\n#endif\n if (buf == NULL) {\n if ((b = BUF_MEM_new()) == NULL)\n goto err;\n if (!BUF_MEM_grow(b, 200))\n goto err;\n b->data[0] = \'\\0\';\n len = 200;\n }\n if (a == NULL) {\n if (b) {\n buf = b->data;\n OPENSSL_free(b);\n }\n strncpy(buf, "NO X509_NAME", len);\n buf[len - 1] = \'\\0\';\n return buf;\n }\n len--;\n l = 0;\n for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n n = OBJ_obj2nid(ne->object);\n if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n s = tmp_buf;\n }\n l1 = strlen(s);\n type = ne->value->type;\n num = ne->value->length;\n q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n if (type == V_ASN1_GENERALSTRING ||\n type == V_ASN1_VISIBLESTRING ||\n type == V_ASN1_PRINTABLESTRING ||\n type == V_ASN1_TELETEXSTRING ||\n type == V_ASN1_VISIBLESTRING || type == V_ASN1_IA5STRING) {\n ascii2ebcdic(ebcdic_buf, q, (num > sizeof ebcdic_buf)\n ? sizeof ebcdic_buf : num);\n q = ebcdic_buf;\n }\n#endif\n if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n for (j = 0; j < num; j++)\n if (q[j] != 0)\n gs_doit[j & 3] = 1;\n if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n else {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n gs_doit[3] = 1;\n }\n } else\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n for (l2 = j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n l2++;\n#ifndef CHARSET_EBCDIC\n if ((q[j] < \' \') || (q[j] > \'~\'))\n l2 += 3;\n#else\n if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n (os_toascii[q[j]] > os_toascii[\'~\']))\n l2 += 3;\n#endif\n }\n lold = l;\n l += 1 + l1 + 1 + l2;\n if (b != NULL) {\n if (!BUF_MEM_grow(b, l + 1))\n goto err;\n p = &(b->data[lold]);\n } else if (l > len) {\n break;\n } else\n p = &(buf[lold]);\n *(p++) = \'/\';\n memcpy(p, s, (unsigned int)l1);\n p += l1;\n *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n q = ne->value->data;\n#endif\n for (j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n#ifndef CHARSET_EBCDIC\n n = q[j];\n if ((n < \' \') || (n > \'~\')) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = n;\n#else\n n = os_toascii[q[j]];\n if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = q[j];\n#endif\n }\n *p = \'\\0\';\n }\n if (b != NULL) {\n p = b->data;\n OPENSSL_free(b);\n } else\n p = buf;\n if (i == 0)\n *p = \'\\0\';\n return (p);\n err:\n X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n BUF_MEM_free(b);\n return (NULL);\n}'] |
33,016 | 0 | https://github.com/openssl/openssl/blob/9c4fe782607d8542c5f55ef1b5c687fef1da5d75/crypto/bn/bn_ctx.c/#L353 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int ecdsa_do_verify(const unsigned char *dgst, int dgst_len,\n\t\tconst ECDSA_SIG *sig, EC_KEY *eckey)\n{\n\tint ret = -1;\n\tBN_CTX *ctx;\n\tBIGNUM *order, *u1, *u2, *m, *X;\n\tEC_POINT *point = NULL;\n\tconst EC_GROUP *group;\n\tconst EC_POINT *pub_key;\n\tif (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||\n\t (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL)\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_MISSING_PARAMETERS);\n\t\treturn -1;\n\t}\n\tctx = BN_CTX_new();\n\tif (!ctx)\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n\t\treturn -1;\n\t}\n\tBN_CTX_start(ctx);\n\torder = BN_CTX_get(ctx);\n\tu1 = BN_CTX_get(ctx);\n\tu2 = BN_CTX_get(ctx);\n\tm = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tif (!X)\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB);\n\t\tgoto err;\n\t}\n\tif (!EC_GROUP_get_order(group, order, ctx))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB);\n\t\tgoto err;\n\t}\n\tif (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||\n\t BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) ||\n\t BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0)\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ECDSA_R_BAD_SIGNATURE);\n\t\tret = 0;\n\t\tgoto err;\n\t}\n\tif (!BN_mod_inverse(u2, sig->s, order, ctx))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB);\n\t\tgoto err;\n\t}\n\tif (!BN_bin2bn(dgst, dgst_len, m))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB);\n\t\tgoto err;\n\t}\n\tif (!BN_mod_mul(u1, m, u2, order, ctx))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB);\n\t\tgoto err;\n\t}\n\tif (!BN_mod_mul(u2, sig->r, u2, order, ctx))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB);\n\t\tgoto err;\n\t}\n\tif ((point = EC_POINT_new(group)) == NULL)\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t}\n\tif (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB);\n\t\tgoto err;\n\t}\n\tif (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field)\n\t{\n\t\tif (!EC_POINT_get_affine_coordinates_GFp(group,\n\t\t\tpoint, X, NULL, ctx))\n\t\t{\n\t\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB);\n\t\t\tgoto err;\n\t\t}\n\t}\n\telse\n\t{\n\t\tif (!EC_POINT_get_affine_coordinates_GF2m(group,\n\t\t\tpoint, X, NULL, ctx))\n\t\t{\n\t\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_EC_LIB);\n\t\t\tgoto err;\n\t\t}\n\t}\n\tif (!BN_nnmod(u1, X, order, ctx))\n\t{\n\t\tECDSAerr(ECDSA_F_ECDSA_DO_VERIFY, ERR_R_BN_LIB);\n\t\tgoto err;\n\t}\n\tret = (BN_ucmp(u1, sig->r) == 0);\nerr:\n\tBN_CTX_end(ctx);\n\tBN_CTX_free(ctx);\n\tif (point)\n\t\tEC_POINT_free(point);\n\treturn ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n\tBN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint ret=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tBN_CTX_start(ctx);\n\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_nnmod(r,t,m,ctx)) goto err;\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tint ret = 0;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn 1;\n\t\t}\n\tBN_CTX_start(ctx);\n\trr=(a != r) ? r : BN_CTX_get(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tif (!rr || !tmp) goto err;\n\tmax = 2 * al;\n\tif (bn_wexpand(rr,max) == NULL) goto err;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\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\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) goto err;\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->neg=0;\n\tif(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n\t\trr->top = max - 1;\n\telse\n\t\trr->top = max;\n\tif (rr != r) BN_copy(r,rr);\n\tret = 1;\n err:\n\tbn_check_top(rr);\n\tbn_check_top(tmp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}'] |
33,017 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/lhash/lhash.c/#L373 | static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash)
{
LHASH_NODE **ret, *n1;
unsigned long hash, nn;
LHASH_COMP_FN_TYPE cf;
hash = (*(lh->hash)) (data);
lh->num_hash_calls++;
*rhash = hash;
nn = hash % lh->pmax;
if (nn < lh->p)
nn = hash % lh->num_alloc_nodes;
cf = lh->comp;
ret = &(lh->b[(int)nn]);
for (n1 = *ret; n1 != NULL; n1 = n1->next) {
lh->num_hash_comps++;
if (n1->hash != hash) {
ret = &(n1->next);
continue;
}
lh->num_comp_calls++;
if (cf(n1->data, data) == 0)
break;
ret = &(n1->next);
}
return (ret);
} | ['void *lh_insert(_LHASH *lh, void *data)\n{\n unsigned long hash;\n LHASH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n if (lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes))\n expand(lh);\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) {\n lh->error++;\n return (NULL);\n }\n nn->data = data;\n nn->next = NULL;\n nn->hash = hash;\n *rn = nn;\n ret = NULL;\n lh->num_insert++;\n lh->num_items++;\n } else {\n ret = (*rn)->data;\n (*rn)->data = data;\n lh->num_replace++;\n }\n return (ret);\n}', 'static void expand(_LHASH *lh)\n{\n LHASH_NODE **n, **n1, **n2, *np;\n unsigned int p, i, j;\n unsigned long hash, nni;\n lh->num_nodes++;\n lh->num_expands++;\n p = (int)lh->p++;\n n1 = &(lh->b[p]);\n n2 = &(lh->b[p + (int)lh->pmax]);\n *n2 = NULL;\n nni = lh->num_alloc_nodes;\n for (np = *n1; np != NULL;) {\n hash = np->hash;\n if ((hash % nni) != p) {\n *n1 = (*n1)->next;\n np->next = *n2;\n *n2 = np;\n } else\n n1 = &((*n1)->next);\n np = *n1;\n }\n if ((lh->p) >= lh->pmax) {\n j = (int)lh->num_alloc_nodes * 2;\n n = OPENSSL_realloc(lh->b, (int)(sizeof(LHASH_NODE *) * j));\n if (n == NULL) {\n lh->error++;\n lh->p = 0;\n return;\n }\n for (i = (int)lh->num_alloc_nodes; i < j; i++)\n n[i] = NULL;\n lh->pmax = lh->num_alloc_nodes;\n lh->num_alloc_nodes = j;\n lh->num_expand_reallocs++;\n lh->p = 0;\n lh->b = n;\n }\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', 'static LHASH_NODE **getrn(_LHASH *lh, const void *data, unsigned long *rhash)\n{\n LHASH_NODE **ret, *n1;\n unsigned long hash, nn;\n LHASH_COMP_FN_TYPE cf;\n hash = (*(lh->hash)) (data);\n lh->num_hash_calls++;\n *rhash = hash;\n nn = hash % lh->pmax;\n if (nn < lh->p)\n nn = hash % lh->num_alloc_nodes;\n cf = lh->comp;\n ret = &(lh->b[(int)nn]);\n for (n1 = *ret; n1 != NULL; n1 = n1->next) {\n lh->num_hash_comps++;\n if (n1->hash != hash) {\n ret = &(n1->next);\n continue;\n }\n lh->num_comp_calls++;\n if (cf(n1->data, data) == 0)\n break;\n ret = &(n1->next);\n }\n return (ret);\n}'] |
33,018 | 0 | https://github.com/openssl/openssl/blob/9f519addc09b2005fa8c6cde36e3267de02577bb/ssl/s3_cbc.c/#L421 | int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,
unsigned char *md_out,
size_t *md_out_size,
const unsigned char header[13],
const unsigned char *data,
size_t data_plus_mac_size,
size_t data_plus_mac_plus_padding_size,
const unsigned char *mac_secret,
unsigned mac_secret_length, char is_sslv3)
{
union {
double align;
unsigned char c[sizeof(LARGEST_DIGEST_CTX)];
} md_state;
void (*md_final_raw) (void *ctx, unsigned char *md_out);
void (*md_transform) (void *ctx, const unsigned char *block);
unsigned md_size, md_block_size = 64;
unsigned sslv3_pad_length = 40, header_length, variance_blocks,
len, max_mac_bytes, num_blocks,
num_starting_blocks, k, mac_end_offset, c, index_a, index_b;
unsigned int bits;
unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];
unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];
unsigned char first_block[MAX_HASH_BLOCK_SIZE];
unsigned char mac_out[EVP_MAX_MD_SIZE];
unsigned i, j, md_out_size_u;
EVP_MD_CTX *md_ctx = NULL;
unsigned md_length_size = 8;
char length_is_big_endian = 1;
int ret;
OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024);
switch (EVP_MD_CTX_type(ctx)) {
case NID_md5:
if (MD5_Init((MD5_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_md5_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))MD5_Transform;
md_size = 16;
sslv3_pad_length = 48;
length_is_big_endian = 0;
break;
case NID_sha1:
if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha1_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA1_Transform;
md_size = 20;
break;
case NID_sha224:
if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha256_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA256_Transform;
md_size = 224 / 8;
break;
case NID_sha256:
if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha256_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA256_Transform;
md_size = 32;
break;
case NID_sha384:
if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha512_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA512_Transform;
md_size = 384 / 8;
md_block_size = 128;
md_length_size = 16;
break;
case NID_sha512:
if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)
return 0;
md_final_raw = tls1_sha512_final_raw;
md_transform =
(void (*)(void *ctx, const unsigned char *block))SHA512_Transform;
md_size = 64;
md_block_size = 128;
md_length_size = 16;
break;
default:
OPENSSL_assert(0);
if (md_out_size)
*md_out_size = 0;
return 0;
}
OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);
OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);
OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);
header_length = 13;
if (is_sslv3) {
header_length = mac_secret_length + sslv3_pad_length + 8 +
1 +
2 ;
}
variance_blocks = is_sslv3 ? 2 : 6;
len = data_plus_mac_plus_padding_size + header_length;
max_mac_bytes = len - md_size - 1;
num_blocks =
(max_mac_bytes + 1 + md_length_size + md_block_size -
1) / md_block_size;
num_starting_blocks = 0;
k = 0;
mac_end_offset = data_plus_mac_size + header_length - md_size;
c = mac_end_offset % md_block_size;
index_a = mac_end_offset / md_block_size;
index_b = (mac_end_offset + md_length_size) / md_block_size;
if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {
num_starting_blocks = num_blocks - variance_blocks;
k = md_block_size * num_starting_blocks;
}
bits = 8 * mac_end_offset;
if (!is_sslv3) {
bits += 8 * md_block_size;
memset(hmac_pad, 0, md_block_size);
OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));
memcpy(hmac_pad, mac_secret, mac_secret_length);
for (i = 0; i < md_block_size; i++)
hmac_pad[i] ^= 0x36;
md_transform(md_state.c, hmac_pad);
}
if (length_is_big_endian) {
memset(length_bytes, 0, md_length_size - 4);
length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);
length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);
length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);
length_bytes[md_length_size - 1] = (unsigned char)bits;
} else {
memset(length_bytes, 0, md_length_size);
length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);
length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);
length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);
length_bytes[md_length_size - 8] = (unsigned char)bits;
}
if (k > 0) {
if (is_sslv3) {
unsigned overhang;
if (header_length <= md_block_size) {
return 0;
}
overhang = header_length - md_block_size;
md_transform(md_state.c, header);
memcpy(first_block, header + md_block_size, overhang);
memcpy(first_block + overhang, data, md_block_size - overhang);
md_transform(md_state.c, first_block);
for (i = 1; i < k / md_block_size - 1; i++)
md_transform(md_state.c, data + md_block_size * i - overhang);
} else {
memcpy(first_block, header, 13);
memcpy(first_block + 13, data, md_block_size - 13);
md_transform(md_state.c, first_block);
for (i = 1; i < k / md_block_size; i++)
md_transform(md_state.c, data + md_block_size * i - 13);
}
}
memset(mac_out, 0, sizeof(mac_out));
for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;
i++) {
unsigned char block[MAX_HASH_BLOCK_SIZE];
unsigned char is_block_a = constant_time_eq_8(i, index_a);
unsigned char is_block_b = constant_time_eq_8(i, index_b);
for (j = 0; j < md_block_size; j++) {
unsigned char b = 0, is_past_c, is_past_cp1;
if (k < header_length)
b = header[k];
else if (k < data_plus_mac_plus_padding_size + header_length)
b = data[k - header_length];
k++;
is_past_c = is_block_a & constant_time_ge_8(j, c);
is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1);
b = constant_time_select_8(is_past_c, 0x80, b);
b = b & ~is_past_cp1;
b &= ~is_block_b | is_block_a;
if (j >= md_block_size - md_length_size) {
b = constant_time_select_8(is_block_b,
length_bytes[j -
(md_block_size -
md_length_size)], b);
}
block[j] = b;
}
md_transform(md_state.c, block);
md_final_raw(md_state.c, block);
for (j = 0; j < md_size; j++)
mac_out[j] |= block[j] & is_block_b;
}
md_ctx = EVP_MD_CTX_new();
if (md_ctx == NULL)
goto err;
if (EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL ) <= 0)
goto err;
if (is_sslv3) {
memset(hmac_pad, 0x5c, sslv3_pad_length);
if (EVP_DigestUpdate(md_ctx, mac_secret, mac_secret_length) <= 0
|| EVP_DigestUpdate(md_ctx, hmac_pad, sslv3_pad_length) <= 0
|| EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)
goto err;
} else {
for (i = 0; i < md_block_size; i++)
hmac_pad[i] ^= 0x6a;
if (EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size) <= 0
|| EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)
goto err;
}
ret = EVP_DigestFinal(md_ctx, md_out, &md_out_size_u);
if (ret && md_out_size)
*md_out_size = md_out_size_u;
EVP_MD_CTX_free(md_ctx);
return 1;
err:
EVP_MD_CTX_free(md_ctx);
return 0;
} | ['int tls1_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int send)\n{\n unsigned char *seq;\n EVP_MD_CTX *hash;\n size_t md_size;\n int i;\n EVP_MD_CTX *hmac = NULL, *mac_ctx;\n unsigned char header[13];\n int stream_mac = (send ? (ssl->mac_flags & SSL_MAC_FLAG_WRITE_MAC_STREAM)\n : (ssl->mac_flags & SSL_MAC_FLAG_READ_MAC_STREAM));\n int t;\n if (send) {\n seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n hash = ssl->write_hash;\n } else {\n seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n hash = ssl->read_hash;\n }\n t = EVP_MD_CTX_size(hash);\n OPENSSL_assert(t >= 0);\n md_size = t;\n if (stream_mac) {\n mac_ctx = hash;\n } else {\n hmac = EVP_MD_CTX_new();\n if (hmac == NULL\n || !EVP_MD_CTX_copy(hmac, hash))\n return -1;\n mac_ctx = hmac;\n }\n if (SSL_IS_DTLS(ssl)) {\n unsigned char dtlsseq[8], *p = dtlsseq;\n s2n(send ? DTLS_RECORD_LAYER_get_w_epoch(&ssl->rlayer) :\n DTLS_RECORD_LAYER_get_r_epoch(&ssl->rlayer), p);\n memcpy(p, &seq[2], 6);\n memcpy(header, dtlsseq, 8);\n } else\n memcpy(header, seq, 8);\n header[8] = rec->type;\n header[9] = (unsigned char)(ssl->version >> 8);\n header[10] = (unsigned char)(ssl->version);\n header[11] = (rec->length) >> 8;\n header[12] = (rec->length) & 0xff;\n if (!send && !SSL_USE_ETM(ssl) &&\n EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n ssl3_cbc_record_digest_supported(mac_ctx)) {\n if (ssl3_cbc_digest_record(mac_ctx,\n md, &md_size,\n header, rec->input,\n rec->length + md_size, rec->orig_len,\n ssl->s3->read_mac_secret,\n ssl->s3->read_mac_secret_size, 0) <= 0) {\n EVP_MD_CTX_free(hmac);\n return -1;\n }\n } else {\n if (EVP_DigestSignUpdate(mac_ctx, header, sizeof(header)) <= 0\n || EVP_DigestSignUpdate(mac_ctx, rec->input, rec->length) <= 0\n || EVP_DigestSignFinal(mac_ctx, md, &md_size) <= 0) {\n EVP_MD_CTX_free(hmac);\n return -1;\n }\n if (!send && !SSL_USE_ETM(ssl) && FIPS_mode())\n tls_fips_digest_extra(ssl->enc_read_ctx,\n mac_ctx, rec->input,\n rec->length, rec->orig_len);\n }\n EVP_MD_CTX_free(hmac);\n#ifdef SSL_DEBUG\n fprintf(stderr, "seq=");\n {\n int z;\n for (z = 0; z < 8; z++)\n fprintf(stderr, "%02X ", seq[z]);\n fprintf(stderr, "\\n");\n }\n fprintf(stderr, "rec=");\n {\n unsigned int z;\n for (z = 0; z < rec->length; z++)\n fprintf(stderr, "%02X ", rec->data[z]);\n fprintf(stderr, "\\n");\n }\n#endif\n if (!SSL_IS_DTLS(ssl)) {\n for (i = 7; i >= 0; i--) {\n ++seq[i];\n if (seq[i] != 0)\n break;\n }\n }\n#ifdef SSL_DEBUG\n {\n unsigned int z;\n for (z = 0; z < md_size; z++)\n fprintf(stderr, "%02X ", md[z]);\n fprintf(stderr, "\\n");\n }\n#endif\n return (md_size);\n}', 'int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx,\n unsigned char *md_out,\n size_t *md_out_size,\n const unsigned char header[13],\n const unsigned char *data,\n size_t data_plus_mac_size,\n size_t data_plus_mac_plus_padding_size,\n const unsigned char *mac_secret,\n unsigned mac_secret_length, char is_sslv3)\n{\n union {\n double align;\n unsigned char c[sizeof(LARGEST_DIGEST_CTX)];\n } md_state;\n void (*md_final_raw) (void *ctx, unsigned char *md_out);\n void (*md_transform) (void *ctx, const unsigned char *block);\n unsigned md_size, md_block_size = 64;\n unsigned sslv3_pad_length = 40, header_length, variance_blocks,\n len, max_mac_bytes, num_blocks,\n num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n unsigned int bits;\n unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n unsigned char first_block[MAX_HASH_BLOCK_SIZE];\n unsigned char mac_out[EVP_MAX_MD_SIZE];\n unsigned i, j, md_out_size_u;\n EVP_MD_CTX *md_ctx = NULL;\n unsigned md_length_size = 8;\n char length_is_big_endian = 1;\n int ret;\n OPENSSL_assert(data_plus_mac_plus_padding_size < 1024 * 1024);\n switch (EVP_MD_CTX_type(ctx)) {\n case NID_md5:\n if (MD5_Init((MD5_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_md5_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))MD5_Transform;\n md_size = 16;\n sslv3_pad_length = 48;\n length_is_big_endian = 0;\n break;\n case NID_sha1:\n if (SHA1_Init((SHA_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha1_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA1_Transform;\n md_size = 20;\n break;\n case NID_sha224:\n if (SHA224_Init((SHA256_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 224 / 8;\n break;\n case NID_sha256:\n if (SHA256_Init((SHA256_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha256_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA256_Transform;\n md_size = 32;\n break;\n case NID_sha384:\n if (SHA384_Init((SHA512_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 384 / 8;\n md_block_size = 128;\n md_length_size = 16;\n break;\n case NID_sha512:\n if (SHA512_Init((SHA512_CTX *)md_state.c) <= 0)\n return 0;\n md_final_raw = tls1_sha512_final_raw;\n md_transform =\n (void (*)(void *ctx, const unsigned char *block))SHA512_Transform;\n md_size = 64;\n md_block_size = 128;\n md_length_size = 16;\n break;\n default:\n OPENSSL_assert(0);\n if (md_out_size)\n *md_out_size = 0;\n return 0;\n }\n OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);\n OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);\n OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n header_length = 13;\n if (is_sslv3) {\n header_length = mac_secret_length + sslv3_pad_length + 8 +\n 1 +\n 2 ;\n }\n variance_blocks = is_sslv3 ? 2 : 6;\n len = data_plus_mac_plus_padding_size + header_length;\n max_mac_bytes = len - md_size - 1;\n num_blocks =\n (max_mac_bytes + 1 + md_length_size + md_block_size -\n 1) / md_block_size;\n num_starting_blocks = 0;\n k = 0;\n mac_end_offset = data_plus_mac_size + header_length - md_size;\n c = mac_end_offset % md_block_size;\n index_a = mac_end_offset / md_block_size;\n index_b = (mac_end_offset + md_length_size) / md_block_size;\n if (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0)) {\n num_starting_blocks = num_blocks - variance_blocks;\n k = md_block_size * num_starting_blocks;\n }\n bits = 8 * mac_end_offset;\n if (!is_sslv3) {\n bits += 8 * md_block_size;\n memset(hmac_pad, 0, md_block_size);\n OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));\n memcpy(hmac_pad, mac_secret, mac_secret_length);\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x36;\n md_transform(md_state.c, hmac_pad);\n }\n if (length_is_big_endian) {\n memset(length_bytes, 0, md_length_size - 4);\n length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 1] = (unsigned char)bits;\n } else {\n memset(length_bytes, 0, md_length_size);\n length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);\n length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);\n length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);\n length_bytes[md_length_size - 8] = (unsigned char)bits;\n }\n if (k > 0) {\n if (is_sslv3) {\n unsigned overhang;\n if (header_length <= md_block_size) {\n return 0;\n }\n overhang = header_length - md_block_size;\n md_transform(md_state.c, header);\n memcpy(first_block, header + md_block_size, overhang);\n memcpy(first_block + overhang, data, md_block_size - overhang);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size - 1; i++)\n md_transform(md_state.c, data + md_block_size * i - overhang);\n } else {\n memcpy(first_block, header, 13);\n memcpy(first_block + 13, data, md_block_size - 13);\n md_transform(md_state.c, first_block);\n for (i = 1; i < k / md_block_size; i++)\n md_transform(md_state.c, data + md_block_size * i - 13);\n }\n }\n memset(mac_out, 0, sizeof(mac_out));\n for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks;\n i++) {\n unsigned char block[MAX_HASH_BLOCK_SIZE];\n unsigned char is_block_a = constant_time_eq_8(i, index_a);\n unsigned char is_block_b = constant_time_eq_8(i, index_b);\n for (j = 0; j < md_block_size; j++) {\n unsigned char b = 0, is_past_c, is_past_cp1;\n if (k < header_length)\n b = header[k];\n else if (k < data_plus_mac_plus_padding_size + header_length)\n b = data[k - header_length];\n k++;\n is_past_c = is_block_a & constant_time_ge_8(j, c);\n is_past_cp1 = is_block_a & constant_time_ge_8(j, c + 1);\n b = constant_time_select_8(is_past_c, 0x80, b);\n b = b & ~is_past_cp1;\n b &= ~is_block_b | is_block_a;\n if (j >= md_block_size - md_length_size) {\n b = constant_time_select_8(is_block_b,\n length_bytes[j -\n (md_block_size -\n md_length_size)], b);\n }\n block[j] = b;\n }\n md_transform(md_state.c, block);\n md_final_raw(md_state.c, block);\n for (j = 0; j < md_size; j++)\n mac_out[j] |= block[j] & is_block_b;\n }\n md_ctx = EVP_MD_CTX_new();\n if (md_ctx == NULL)\n goto err;\n if (EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL ) <= 0)\n goto err;\n if (is_sslv3) {\n memset(hmac_pad, 0x5c, sslv3_pad_length);\n if (EVP_DigestUpdate(md_ctx, mac_secret, mac_secret_length) <= 0\n || EVP_DigestUpdate(md_ctx, hmac_pad, sslv3_pad_length) <= 0\n || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)\n goto err;\n } else {\n for (i = 0; i < md_block_size; i++)\n hmac_pad[i] ^= 0x6a;\n if (EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size) <= 0\n || EVP_DigestUpdate(md_ctx, mac_out, md_size) <= 0)\n goto err;\n }\n ret = EVP_DigestFinal(md_ctx, md_out, &md_out_size_u);\n if (ret && md_out_size)\n *md_out_size = md_out_size_u;\n EVP_MD_CTX_free(md_ctx);\n return 1;\nerr:\n EVP_MD_CTX_free(md_ctx);\n return 0;\n}'] |
33,019 | 0 | https://github.com/libav/libav/blob/3b2fbe67bd63b00331db2a9b213f6d420418a312/libavcodec/opus_celt.c/#L804 | static void celt_decode_allocation(CeltContext *s, OpusRangeCoder *rc)
{
int cap[CELT_MAX_BANDS];
int boost[CELT_MAX_BANDS];
int threshold[CELT_MAX_BANDS];
int bits1[CELT_MAX_BANDS];
int bits2[CELT_MAX_BANDS];
int trim_offset[CELT_MAX_BANDS];
int skip_startband = s->startband;
int dynalloc = 6;
int alloctrim = 5;
int extrabits = 0;
int skip_bit = 0;
int intensitystereo_bit = 0;
int dualstereo_bit = 0;
int remaining, bandbits;
int low, high, total, done;
int totalbits;
int consumed;
int i, j;
consumed = opus_rc_tell(rc);
s->spread = CELT_SPREAD_NORMAL;
if (consumed + 4 <= s->framebits)
s->spread = opus_rc_getsymbol(rc, celt_model_spread);
for (i = 0; i < CELT_MAX_BANDS; i++) {
cap[i] = (celt_static_caps[s->duration][s->coded_channels - 1][i] + 64)
* celt_freq_range[i] << (s->coded_channels - 1) << s->duration >> 2;
}
totalbits = s->framebits << 3;
consumed = opus_rc_tell_frac(rc);
for (i = s->startband; i < s->endband; i++) {
int quanta, band_dynalloc;
boost[i] = 0;
quanta = celt_freq_range[i] << (s->coded_channels - 1) << s->duration;
quanta = FFMIN(quanta << 3, FFMAX(6 << 3, quanta));
band_dynalloc = dynalloc;
while (consumed + (band_dynalloc<<3) < totalbits && boost[i] < cap[i]) {
int add = opus_rc_p2model(rc, band_dynalloc);
consumed = opus_rc_tell_frac(rc);
if (!add)
break;
boost[i] += quanta;
totalbits -= quanta;
band_dynalloc = 1;
}
if (boost[i])
dynalloc = FFMAX(2, dynalloc - 1);
}
if (consumed + (6 << 3) <= totalbits)
alloctrim = opus_rc_getsymbol(rc, celt_model_alloc_trim);
totalbits = (s->framebits << 3) - opus_rc_tell_frac(rc) - 1;
s->anticollapse_bit = 0;
if (s->blocks > 1 && s->duration >= 2 &&
totalbits >= ((s->duration + 2) << 3))
s->anticollapse_bit = 1 << 3;
totalbits -= s->anticollapse_bit;
if (totalbits >= 1 << 3)
skip_bit = 1 << 3;
totalbits -= skip_bit;
if (s->coded_channels == 2) {
intensitystereo_bit = celt_log2_frac[s->endband - s->startband];
if (intensitystereo_bit <= totalbits) {
totalbits -= intensitystereo_bit;
if (totalbits >= 1 << 3) {
dualstereo_bit = 1 << 3;
totalbits -= 1 << 3;
}
} else
intensitystereo_bit = 0;
}
for (i = s->startband; i < s->endband; i++) {
int trim = alloctrim - 5 - s->duration;
int band = celt_freq_range[i] * (s->endband - i - 1);
int duration = s->duration + 3;
int scale = duration + s->coded_channels - 1;
threshold[i] = FFMAX(3 * celt_freq_range[i] << duration >> 4,
s->coded_channels << 3);
trim_offset[i] = trim * (band << scale) >> 6;
if (celt_freq_range[i] << s->duration == 1)
trim_offset[i] -= s->coded_channels << 3;
}
low = 1;
high = CELT_VECTORS - 1;
while (low <= high) {
int center = (low + high) >> 1;
done = total = 0;
for (i = s->endband - 1; i >= s->startband; i--) {
bandbits = celt_freq_range[i] * celt_static_alloc[center][i]
<< (s->coded_channels - 1) << s->duration >> 2;
if (bandbits)
bandbits = FFMAX(0, bandbits + trim_offset[i]);
bandbits += boost[i];
if (bandbits >= threshold[i] || done) {
done = 1;
total += FFMIN(bandbits, cap[i]);
} else if (bandbits >= s->coded_channels << 3)
total += s->coded_channels << 3;
}
if (total > totalbits)
high = center - 1;
else
low = center + 1;
}
high = low--;
for (i = s->startband; i < s->endband; i++) {
bits1[i] = celt_freq_range[i] * celt_static_alloc[low][i]
<< (s->coded_channels - 1) << s->duration >> 2;
bits2[i] = high >= CELT_VECTORS ? cap[i] :
celt_freq_range[i] * celt_static_alloc[high][i]
<< (s->coded_channels - 1) << s->duration >> 2;
if (bits1[i])
bits1[i] = FFMAX(0, bits1[i] + trim_offset[i]);
if (bits2[i])
bits2[i] = FFMAX(0, bits2[i] + trim_offset[i]);
if (low)
bits1[i] += boost[i];
bits2[i] += boost[i];
if (boost[i])
skip_startband = i;
bits2[i] = FFMAX(0, bits2[i] - bits1[i]);
}
low = 0;
high = 1 << CELT_ALLOC_STEPS;
for (i = 0; i < CELT_ALLOC_STEPS; i++) {
int center = (low + high) >> 1;
done = total = 0;
for (j = s->endband - 1; j >= s->startband; j--) {
bandbits = bits1[j] + (center * bits2[j] >> CELT_ALLOC_STEPS);
if (bandbits >= threshold[j] || done) {
done = 1;
total += FFMIN(bandbits, cap[j]);
} else if (bandbits >= s->coded_channels << 3)
total += s->coded_channels << 3;
}
if (total > totalbits)
high = center;
else
low = center;
}
done = total = 0;
for (i = s->endband - 1; i >= s->startband; i--) {
bandbits = bits1[i] + (low * bits2[i] >> CELT_ALLOC_STEPS);
if (bandbits >= threshold[i] || done)
done = 1;
else
bandbits = (bandbits >= s->coded_channels << 3) ?
s->coded_channels << 3 : 0;
bandbits = FFMIN(bandbits, cap[i]);
s->pulses[i] = bandbits;
total += bandbits;
}
for (s->codedbands = s->endband; ; s->codedbands--) {
int allocation;
j = s->codedbands - 1;
if (j == skip_startband) {
totalbits += skip_bit;
break;
}
remaining = totalbits - total;
bandbits = remaining / (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);
remaining -= bandbits * (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);
allocation = s->pulses[j] + bandbits * celt_freq_range[j]
+ FFMAX(0, remaining - (celt_freq_bands[j] - celt_freq_bands[s->startband]));
if (allocation >= FFMAX(threshold[j], (s->coded_channels + 1) <<3 )) {
if (opus_rc_p2model(rc, 1))
break;
total += 1 << 3;
allocation -= 1 << 3;
}
total -= s->pulses[j];
if (intensitystereo_bit) {
total -= intensitystereo_bit;
intensitystereo_bit = celt_log2_frac[j - s->startband];
total += intensitystereo_bit;
}
total += s->pulses[j] = (allocation >= s->coded_channels << 3) ?
s->coded_channels << 3 : 0;
}
s->intensitystereo = 0;
s->dualstereo = 0;
if (intensitystereo_bit)
s->intensitystereo = s->startband +
opus_rc_unimodel(rc, s->codedbands + 1 - s->startband);
if (s->intensitystereo <= s->startband)
totalbits += dualstereo_bit;
else if (dualstereo_bit)
s->dualstereo = opus_rc_p2model(rc, 1);
remaining = totalbits - total;
bandbits = remaining / (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);
remaining -= bandbits * (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);
for (i = s->startband; i < s->codedbands; i++) {
int bits = FFMIN(remaining, celt_freq_range[i]);
s->pulses[i] += bits + bandbits * celt_freq_range[i];
remaining -= bits;
}
for (i = s->startband; i < s->codedbands; i++) {
int N = celt_freq_range[i] << s->duration;
int prev_extra = extrabits;
s->pulses[i] += extrabits;
if (N > 1) {
int dof;
int temp;
int offset;
int fine_bits, max_bits;
extrabits = FFMAX(0, s->pulses[i] - cap[i]);
s->pulses[i] -= extrabits;
dof = N * s->coded_channels
+ (s->coded_channels == 2 && N > 2 && !s->dualstereo && i < s->intensitystereo);
temp = dof * (celt_log_freq_range[i] + (s->duration<<3));
offset = (temp >> 1) - dof * CELT_FINE_OFFSET;
if (N == 2)
offset += dof<<1;
if (s->pulses[i] + offset < 2 * (dof << 3))
offset += temp >> 2;
else if (s->pulses[i] + offset < 3 * (dof << 3))
offset += temp >> 3;
fine_bits = (s->pulses[i] + offset + (dof << 2)) / (dof << 3);
max_bits = FFMIN((s->pulses[i]>>3) >> (s->coded_channels - 1),
CELT_MAX_FINE_BITS);
max_bits = FFMAX(max_bits, 0);
s->fine_bits[i] = av_clip(fine_bits, 0, max_bits);
s->fine_priority[i] = (s->fine_bits[i] * (dof<<3) >= s->pulses[i] + offset);
s->pulses[i] -= s->fine_bits[i] << (s->coded_channels - 1) << 3;
} else {
extrabits = FFMAX(0, s->pulses[i] - (s->coded_channels << 3));
s->pulses[i] -= extrabits;
s->fine_bits[i] = 0;
s->fine_priority[i] = 1;
}
if (extrabits > 0) {
int fineextra = FFMIN(extrabits >> (s->coded_channels + 2),
CELT_MAX_FINE_BITS - s->fine_bits[i]);
s->fine_bits[i] += fineextra;
fineextra <<= s->coded_channels + 2;
s->fine_priority[i] = (fineextra >= extrabits - prev_extra);
extrabits -= fineextra;
}
}
s->remaining = extrabits;
for (; i < s->endband; i++) {
s->fine_bits[i] = s->pulses[i] >> (s->coded_channels - 1) >> 3;
s->pulses[i] = 0;
s->fine_priority[i] = s->fine_bits[i] < 1;
}
} | ['static void celt_decode_allocation(CeltContext *s, OpusRangeCoder *rc)\n{\n int cap[CELT_MAX_BANDS];\n int boost[CELT_MAX_BANDS];\n int threshold[CELT_MAX_BANDS];\n int bits1[CELT_MAX_BANDS];\n int bits2[CELT_MAX_BANDS];\n int trim_offset[CELT_MAX_BANDS];\n int skip_startband = s->startband;\n int dynalloc = 6;\n int alloctrim = 5;\n int extrabits = 0;\n int skip_bit = 0;\n int intensitystereo_bit = 0;\n int dualstereo_bit = 0;\n int remaining, bandbits;\n int low, high, total, done;\n int totalbits;\n int consumed;\n int i, j;\n consumed = opus_rc_tell(rc);\n s->spread = CELT_SPREAD_NORMAL;\n if (consumed + 4 <= s->framebits)\n s->spread = opus_rc_getsymbol(rc, celt_model_spread);\n for (i = 0; i < CELT_MAX_BANDS; i++) {\n cap[i] = (celt_static_caps[s->duration][s->coded_channels - 1][i] + 64)\n * celt_freq_range[i] << (s->coded_channels - 1) << s->duration >> 2;\n }\n totalbits = s->framebits << 3;\n consumed = opus_rc_tell_frac(rc);\n for (i = s->startband; i < s->endband; i++) {\n int quanta, band_dynalloc;\n boost[i] = 0;\n quanta = celt_freq_range[i] << (s->coded_channels - 1) << s->duration;\n quanta = FFMIN(quanta << 3, FFMAX(6 << 3, quanta));\n band_dynalloc = dynalloc;\n while (consumed + (band_dynalloc<<3) < totalbits && boost[i] < cap[i]) {\n int add = opus_rc_p2model(rc, band_dynalloc);\n consumed = opus_rc_tell_frac(rc);\n if (!add)\n break;\n boost[i] += quanta;\n totalbits -= quanta;\n band_dynalloc = 1;\n }\n if (boost[i])\n dynalloc = FFMAX(2, dynalloc - 1);\n }\n if (consumed + (6 << 3) <= totalbits)\n alloctrim = opus_rc_getsymbol(rc, celt_model_alloc_trim);\n totalbits = (s->framebits << 3) - opus_rc_tell_frac(rc) - 1;\n s->anticollapse_bit = 0;\n if (s->blocks > 1 && s->duration >= 2 &&\n totalbits >= ((s->duration + 2) << 3))\n s->anticollapse_bit = 1 << 3;\n totalbits -= s->anticollapse_bit;\n if (totalbits >= 1 << 3)\n skip_bit = 1 << 3;\n totalbits -= skip_bit;\n if (s->coded_channels == 2) {\n intensitystereo_bit = celt_log2_frac[s->endband - s->startband];\n if (intensitystereo_bit <= totalbits) {\n totalbits -= intensitystereo_bit;\n if (totalbits >= 1 << 3) {\n dualstereo_bit = 1 << 3;\n totalbits -= 1 << 3;\n }\n } else\n intensitystereo_bit = 0;\n }\n for (i = s->startband; i < s->endband; i++) {\n int trim = alloctrim - 5 - s->duration;\n int band = celt_freq_range[i] * (s->endband - i - 1);\n int duration = s->duration + 3;\n int scale = duration + s->coded_channels - 1;\n threshold[i] = FFMAX(3 * celt_freq_range[i] << duration >> 4,\n s->coded_channels << 3);\n trim_offset[i] = trim * (band << scale) >> 6;\n if (celt_freq_range[i] << s->duration == 1)\n trim_offset[i] -= s->coded_channels << 3;\n }\n low = 1;\n high = CELT_VECTORS - 1;\n while (low <= high) {\n int center = (low + high) >> 1;\n done = total = 0;\n for (i = s->endband - 1; i >= s->startband; i--) {\n bandbits = celt_freq_range[i] * celt_static_alloc[center][i]\n << (s->coded_channels - 1) << s->duration >> 2;\n if (bandbits)\n bandbits = FFMAX(0, bandbits + trim_offset[i]);\n bandbits += boost[i];\n if (bandbits >= threshold[i] || done) {\n done = 1;\n total += FFMIN(bandbits, cap[i]);\n } else if (bandbits >= s->coded_channels << 3)\n total += s->coded_channels << 3;\n }\n if (total > totalbits)\n high = center - 1;\n else\n low = center + 1;\n }\n high = low--;\n for (i = s->startband; i < s->endband; i++) {\n bits1[i] = celt_freq_range[i] * celt_static_alloc[low][i]\n << (s->coded_channels - 1) << s->duration >> 2;\n bits2[i] = high >= CELT_VECTORS ? cap[i] :\n celt_freq_range[i] * celt_static_alloc[high][i]\n << (s->coded_channels - 1) << s->duration >> 2;\n if (bits1[i])\n bits1[i] = FFMAX(0, bits1[i] + trim_offset[i]);\n if (bits2[i])\n bits2[i] = FFMAX(0, bits2[i] + trim_offset[i]);\n if (low)\n bits1[i] += boost[i];\n bits2[i] += boost[i];\n if (boost[i])\n skip_startband = i;\n bits2[i] = FFMAX(0, bits2[i] - bits1[i]);\n }\n low = 0;\n high = 1 << CELT_ALLOC_STEPS;\n for (i = 0; i < CELT_ALLOC_STEPS; i++) {\n int center = (low + high) >> 1;\n done = total = 0;\n for (j = s->endband - 1; j >= s->startband; j--) {\n bandbits = bits1[j] + (center * bits2[j] >> CELT_ALLOC_STEPS);\n if (bandbits >= threshold[j] || done) {\n done = 1;\n total += FFMIN(bandbits, cap[j]);\n } else if (bandbits >= s->coded_channels << 3)\n total += s->coded_channels << 3;\n }\n if (total > totalbits)\n high = center;\n else\n low = center;\n }\n done = total = 0;\n for (i = s->endband - 1; i >= s->startband; i--) {\n bandbits = bits1[i] + (low * bits2[i] >> CELT_ALLOC_STEPS);\n if (bandbits >= threshold[i] || done)\n done = 1;\n else\n bandbits = (bandbits >= s->coded_channels << 3) ?\n s->coded_channels << 3 : 0;\n bandbits = FFMIN(bandbits, cap[i]);\n s->pulses[i] = bandbits;\n total += bandbits;\n }\n for (s->codedbands = s->endband; ; s->codedbands--) {\n int allocation;\n j = s->codedbands - 1;\n if (j == skip_startband) {\n totalbits += skip_bit;\n break;\n }\n remaining = totalbits - total;\n bandbits = remaining / (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);\n remaining -= bandbits * (celt_freq_bands[j+1] - celt_freq_bands[s->startband]);\n allocation = s->pulses[j] + bandbits * celt_freq_range[j]\n + FFMAX(0, remaining - (celt_freq_bands[j] - celt_freq_bands[s->startband]));\n if (allocation >= FFMAX(threshold[j], (s->coded_channels + 1) <<3 )) {\n if (opus_rc_p2model(rc, 1))\n break;\n total += 1 << 3;\n allocation -= 1 << 3;\n }\n total -= s->pulses[j];\n if (intensitystereo_bit) {\n total -= intensitystereo_bit;\n intensitystereo_bit = celt_log2_frac[j - s->startband];\n total += intensitystereo_bit;\n }\n total += s->pulses[j] = (allocation >= s->coded_channels << 3) ?\n s->coded_channels << 3 : 0;\n }\n s->intensitystereo = 0;\n s->dualstereo = 0;\n if (intensitystereo_bit)\n s->intensitystereo = s->startband +\n opus_rc_unimodel(rc, s->codedbands + 1 - s->startband);\n if (s->intensitystereo <= s->startband)\n totalbits += dualstereo_bit;\n else if (dualstereo_bit)\n s->dualstereo = opus_rc_p2model(rc, 1);\n remaining = totalbits - total;\n bandbits = remaining / (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);\n remaining -= bandbits * (celt_freq_bands[s->codedbands] - celt_freq_bands[s->startband]);\n for (i = s->startband; i < s->codedbands; i++) {\n int bits = FFMIN(remaining, celt_freq_range[i]);\n s->pulses[i] += bits + bandbits * celt_freq_range[i];\n remaining -= bits;\n }\n for (i = s->startband; i < s->codedbands; i++) {\n int N = celt_freq_range[i] << s->duration;\n int prev_extra = extrabits;\n s->pulses[i] += extrabits;\n if (N > 1) {\n int dof;\n int temp;\n int offset;\n int fine_bits, max_bits;\n extrabits = FFMAX(0, s->pulses[i] - cap[i]);\n s->pulses[i] -= extrabits;\n dof = N * s->coded_channels\n + (s->coded_channels == 2 && N > 2 && !s->dualstereo && i < s->intensitystereo);\n temp = dof * (celt_log_freq_range[i] + (s->duration<<3));\n offset = (temp >> 1) - dof * CELT_FINE_OFFSET;\n if (N == 2)\n offset += dof<<1;\n if (s->pulses[i] + offset < 2 * (dof << 3))\n offset += temp >> 2;\n else if (s->pulses[i] + offset < 3 * (dof << 3))\n offset += temp >> 3;\n fine_bits = (s->pulses[i] + offset + (dof << 2)) / (dof << 3);\n max_bits = FFMIN((s->pulses[i]>>3) >> (s->coded_channels - 1),\n CELT_MAX_FINE_BITS);\n max_bits = FFMAX(max_bits, 0);\n s->fine_bits[i] = av_clip(fine_bits, 0, max_bits);\n s->fine_priority[i] = (s->fine_bits[i] * (dof<<3) >= s->pulses[i] + offset);\n s->pulses[i] -= s->fine_bits[i] << (s->coded_channels - 1) << 3;\n } else {\n extrabits = FFMAX(0, s->pulses[i] - (s->coded_channels << 3));\n s->pulses[i] -= extrabits;\n s->fine_bits[i] = 0;\n s->fine_priority[i] = 1;\n }\n if (extrabits > 0) {\n int fineextra = FFMIN(extrabits >> (s->coded_channels + 2),\n CELT_MAX_FINE_BITS - s->fine_bits[i]);\n s->fine_bits[i] += fineextra;\n fineextra <<= s->coded_channels + 2;\n s->fine_priority[i] = (fineextra >= extrabits - prev_extra);\n extrabits -= fineextra;\n }\n }\n s->remaining = extrabits;\n for (; i < s->endband; i++) {\n s->fine_bits[i] = s->pulses[i] >> (s->coded_channels - 1) >> 3;\n s->pulses[i] = 0;\n s->fine_priority[i] = s->fine_bits[i] < 1;\n }\n}'] |
33,020 | 0 | https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/engines/e_4758cca.c/#L587 | static int cca_rsa_priv_dec(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
long returnCode;
long reasonCode;
long lflen = flen;
long exitDataLength = 0;
unsigned char exitData[8];
long ruleArrayLength = 1;
unsigned char ruleArray[8] = "PKCS-1.2";
long dataStructureLength = 0;
unsigned char dataStructure[8];
long outputLength = RSA_size(rsa);
long keyTokenLength;
unsigned char *keyToken = (unsigned char *)RSA_get_ex_data(rsa, hndidx);
keyTokenLength = *(long *)keyToken;
keyToken += sizeof(long);
pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
&ruleArrayLength, ruleArray, &lflen, (unsigned char *)from,
&dataStructureLength, dataStructure, &keyTokenLength,
keyToken, &outputLength, to);
return (returnCode | reasonCode) ? 0 : 1;
} | ['static int cca_rsa_priv_dec(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n long returnCode;\n long reasonCode;\n long lflen = flen;\n long exitDataLength = 0;\n unsigned char exitData[8];\n long ruleArrayLength = 1;\n unsigned char ruleArray[8] = "PKCS-1.2";\n long dataStructureLength = 0;\n unsigned char dataStructure[8];\n long outputLength = RSA_size(rsa);\n long keyTokenLength;\n unsigned char *keyToken = (unsigned char *)RSA_get_ex_data(rsa, hndidx);\n keyTokenLength = *(long *)keyToken;\n keyToken += sizeof(long);\n pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,\n &ruleArrayLength, ruleArray, &lflen, (unsigned char *)from,\n &dataStructureLength, dataStructure, &keyTokenLength,\n keyToken, &outputLength, to);\n return (returnCode | reasonCode) ? 0 : 1;\n}', 'int RSA_size(const RSA *r)\n{\n return (BN_num_bytes(r->n));\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'void *RSA_get_ex_data(const RSA *r, int idx)\n{\n return (CRYPTO_get_ex_data(&r->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}', 'int sk_num(const _STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}'] |
33,021 | 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)];
} | ['BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *ret = in;\n int err = 1;\n int r;\n BIGNUM *A, *b, *q, *t, *x, *y;\n int e, i, j;\n if (!BN_is_odd(p) || BN_abs_is_word(p, 1)) {\n if (BN_abs_is_word(p, 2)) {\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_set_word(ret, BN_is_bit_set(a, 0))) {\n if (ret != in)\n BN_free(ret);\n return NULL;\n }\n bn_check_top(ret);\n return ret;\n }\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n return NULL;\n }\n if (BN_is_zero(a) || BN_is_one(a)) {\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_set_word(ret, BN_is_one(a))) {\n if (ret != in)\n BN_free(ret);\n return NULL;\n }\n bn_check_top(ret);\n return ret;\n }\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto end;\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_nnmod(A, a, p, ctx))\n goto end;\n e = 1;\n while (!BN_is_bit_set(p, e))\n e++;\n if (e == 1) {\n if (!BN_rshift(q, p, 2))\n goto end;\n q->neg = 0;\n if (!BN_add_word(q, 1))\n goto end;\n if (!BN_mod_exp(ret, A, q, p, ctx))\n goto end;\n err = 0;\n goto vrfy;\n }\n if (e == 2) {\n if (!BN_mod_lshift1_quick(t, A, p))\n goto end;\n if (!BN_rshift(q, p, 3))\n goto end;\n q->neg = 0;\n if (!BN_mod_exp(b, t, q, p, ctx))\n goto end;\n if (!BN_mod_sqr(y, b, p, ctx))\n goto end;\n if (!BN_mod_mul(t, t, y, p, ctx))\n goto end;\n if (!BN_sub_word(t, 1))\n goto end;\n if (!BN_mod_mul(x, A, b, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, t, p, ctx))\n goto end;\n if (!BN_copy(ret, x))\n goto end;\n err = 0;\n goto vrfy;\n }\n if (!BN_copy(q, p))\n goto end;\n q->neg = 0;\n i = 2;\n do {\n if (i < 22) {\n if (!BN_set_word(y, i))\n goto end;\n } else {\n if (!BN_priv_rand(y, BN_num_bits(p), 0, 0))\n goto end;\n if (BN_ucmp(y, p) >= 0) {\n if (!(p->neg ? BN_add : BN_sub) (y, y, p))\n goto end;\n }\n if (BN_is_zero(y))\n if (!BN_set_word(y, i))\n goto end;\n }\n r = BN_kronecker(y, q, ctx);\n if (r < -1)\n goto end;\n if (r == 0) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n goto end;\n }\n }\n while (r == 1 && ++i < 82);\n if (r != -1) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);\n goto end;\n }\n if (!BN_rshift(q, q, e))\n goto end;\n if (!BN_mod_exp(y, y, q, p, ctx))\n goto end;\n if (BN_is_one(y)) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n goto end;\n }\n if (!BN_rshift1(t, q))\n goto end;\n if (BN_is_zero(t)) {\n if (!BN_nnmod(t, A, p, ctx))\n goto end;\n if (BN_is_zero(t)) {\n BN_zero(ret);\n err = 0;\n goto end;\n } else if (!BN_one(x))\n goto end;\n } else {\n if (!BN_mod_exp(x, A, t, p, ctx))\n goto end;\n if (BN_is_zero(x)) {\n BN_zero(ret);\n err = 0;\n goto end;\n }\n }\n if (!BN_mod_sqr(b, x, p, ctx))\n goto end;\n if (!BN_mod_mul(b, b, A, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, A, p, ctx))\n goto end;\n while (1) {\n if (BN_is_one(b)) {\n if (!BN_copy(ret, x))\n goto end;\n err = 0;\n goto vrfy;\n }\n i = 1;\n if (!BN_mod_sqr(t, b, p, ctx))\n goto end;\n while (!BN_is_one(t)) {\n i++;\n if (i == e) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n goto end;\n }\n if (!BN_mod_mul(t, t, t, p, ctx))\n goto end;\n }\n if (!BN_copy(t, y))\n goto end;\n for (j = e - i - 1; j > 0; j--) {\n if (!BN_mod_sqr(t, t, p, ctx))\n goto end;\n }\n if (!BN_mod_mul(y, t, t, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, t, p, ctx))\n goto end;\n if (!BN_mod_mul(b, b, y, p, ctx))\n goto end;\n e = i;\n }\n vrfy:\n if (!err) {\n if (!BN_mod_sqr(x, ret, p, ctx))\n err = 1;\n if (!err && 0 != BN_cmp(x, A)) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n err = 1;\n }\n }\n end:\n if (err) {\n if (ret != in)\n BN_clear_free(ret);\n ret = NULL;\n }\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n mont->RR.d[i] = 0;\n mont->RR.top = ret;\n mont->RR.flags |= BN_FLG_FIXED_TOP;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n 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}'] |
33,022 | 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 flashsv_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame, AVPacket *avpkt)\n{\n int buf_size = avpkt->size;\n FlashSVContext *s = avctx->priv_data;\n int h_blocks, v_blocks, h_part, v_part, i, j, ret;\n BitstreamContext bc;\n if (buf_size == 0)\n return 0;\n if (buf_size < 4)\n return -1;\n bitstream_init(&bc, avpkt->data, buf_size * 8);\n s->block_width = 16 * (bitstream_read(&bc, 4) + 1);\n s->image_width = bitstream_read(&bc, 12);\n s->block_height = 16 * (bitstream_read(&bc, 4) + 1);\n s->image_height = bitstream_read(&bc, 12);\n if (s->ver == 2) {\n bitstream_skip(&bc, 6);\n if (bitstream_read_bit(&bc)) {\n avpriv_request_sample(avctx, "iframe");\n return AVERROR_PATCHWELCOME;\n }\n if (bitstream_read_bit(&bc)) {\n avpriv_request_sample(avctx, "Custom palette");\n return AVERROR_PATCHWELCOME;\n }\n }\n h_blocks = s->image_width / s->block_width;\n h_part = s->image_width % s->block_width;\n v_blocks = s->image_height / s->block_height;\n v_part = s->image_height % s->block_height;\n if (s->block_size < s->block_width * s->block_height) {\n int tmpblock_size = 3 * s->block_width * s->block_height, err;\n if ((err = av_reallocp(&s->tmpblock, tmpblock_size)) < 0) {\n s->block_size = 0;\n av_log(avctx, AV_LOG_ERROR,\n "Cannot allocate decompression buffer.\\n");\n return err;\n }\n if (s->ver == 2) {\n s->deflate_block_size = calc_deflate_block_size(tmpblock_size);\n if (s->deflate_block_size <= 0) {\n av_log(avctx, AV_LOG_ERROR,\n "Cannot determine deflate buffer size.\\n");\n return -1;\n }\n if ((err = av_reallocp(&s->deflate_block, s->deflate_block_size)) < 0) {\n s->block_size = 0;\n av_log(avctx, AV_LOG_ERROR, "Cannot allocate deflate buffer.\\n");\n return err;\n }\n }\n }\n s->block_size = s->block_width * s->block_height;\n if (avctx->width == 0 && avctx->height == 0) {\n avctx->width = s->image_width;\n avctx->height = s->image_height;\n }\n if (avctx->width != s->image_width || avctx->height != s->image_height) {\n av_log(avctx, AV_LOG_ERROR,\n "Frame width or height differs from first frame!\\n");\n av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\\n",\n avctx->height, avctx->width, s->image_height, s->image_width);\n return AVERROR_INVALIDDATA;\n }\n s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);\n if (s->is_keyframe) {\n int err;\n int nb_blocks = (v_blocks + !!v_part) *\n (h_blocks + !!h_part) * sizeof(s->blocks[0]);\n if ((err = av_reallocp(&s->keyframedata, avpkt->size)) < 0)\n return err;\n memcpy(s->keyframedata, avpkt->data, avpkt->size);\n if ((err = av_reallocp(&s->blocks, nb_blocks)) < 0)\n return err;\n memset(s->blocks, 0, nb_blocks);\n }\n ff_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\\n",\n s->image_width, s->image_height, s->block_width, s->block_height,\n h_blocks, v_blocks, h_part, v_part);\n if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\\n");\n return ret;\n }\n for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) {\n int y_pos = j * s->block_height;\n int cur_blk_height = (j < v_blocks) ? s->block_height : v_part;\n for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) {\n int x_pos = i * s->block_width;\n int cur_blk_width = (i < h_blocks) ? s->block_width : h_part;\n int has_diff = 0;\n int size = bitstream_read(&bc, 16);\n s->color_depth = 0;\n s->zlibprime_curr = 0;\n s->zlibprime_prev = 0;\n s->diff_start = 0;\n s->diff_height = cur_blk_height;\n if (8 * size > bitstream_bits_left(&bc)) {\n av_frame_unref(s->frame);\n return AVERROR_INVALIDDATA;\n }\n if (s->ver == 2 && size) {\n bitstream_skip(&bc, 3);\n s->color_depth = bitstream_read(&bc, 2);\n has_diff = bitstream_read_bit(&bc);\n s->zlibprime_curr = bitstream_read_bit(&bc);\n s->zlibprime_prev = bitstream_read_bit(&bc);\n if (s->color_depth != 0 && s->color_depth != 2) {\n av_log(avctx, AV_LOG_ERROR,\n "%dx%d invalid color depth %d\\n",\n i, j, s->color_depth);\n return AVERROR_INVALIDDATA;\n }\n if (has_diff) {\n if (!s->keyframe) {\n av_log(avctx, AV_LOG_ERROR,\n "Inter frame without keyframe\\n");\n return AVERROR_INVALIDDATA;\n }\n s->diff_start = bitstream_read(&bc, 8);\n s->diff_height = bitstream_read(&bc, 8);\n if (s->diff_start + s->diff_height > cur_blk_height) {\n av_log(avctx, AV_LOG_ERROR,\n "Block parameters invalid: %d + %d > %d\\n",\n s->diff_start, s->diff_height, cur_blk_height);\n return AVERROR_INVALIDDATA;\n }\n av_log(avctx, AV_LOG_DEBUG,\n "%dx%d diff start %d height %d\\n",\n i, j, s->diff_start, s->diff_height);\n size -= 2;\n }\n if (s->zlibprime_prev)\n av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_prev\\n", i, j);\n if (s->zlibprime_curr) {\n int col = bitstream_read(&bc, 8);\n int row = bitstream_read(&bc, 8);\n av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_curr %dx%d\\n",\n i, j, col, row);\n size -= 2;\n avpriv_request_sample(avctx, "zlibprime_curr");\n return AVERROR_PATCHWELCOME;\n }\n if (!s->blocks && (s->zlibprime_curr || s->zlibprime_prev)) {\n av_log(avctx, AV_LOG_ERROR,\n "no data available for zlib priming\\n");\n return AVERROR_INVALIDDATA;\n }\n size--;\n }\n if (has_diff) {\n int k;\n int off = (s->image_height - y_pos - 1) * s->frame->linesize[0];\n for (k = 0; k < cur_blk_height; k++) {\n int x = off - k * s->frame->linesize[0] + x_pos * 3;\n memcpy(s->frame->data[0] + x, s->keyframe + x,\n cur_blk_width * 3);\n }\n }\n if (size) {\n if (flashsv_decode_block(avctx, avpkt, &bc, size,\n cur_blk_width, cur_blk_height,\n x_pos, y_pos,\n i + j * (h_blocks + !!h_part)))\n av_log(avctx, AV_LOG_ERROR,\n "error in decompression of block %dx%d\\n", i, j);\n }\n }\n }\n if (s->is_keyframe && s->ver == 2) {\n if (!s->keyframe) {\n s->keyframe = av_malloc(s->frame->linesize[0] * avctx->height);\n if (!s->keyframe) {\n av_log(avctx, AV_LOG_ERROR, "Cannot allocate image data\\n");\n return AVERROR(ENOMEM);\n }\n }\n memcpy(s->keyframe, s->frame->data[0],\n s->frame->linesize[0] * avctx->height);\n }\n if ((ret = av_frame_ref(data, s->frame)) < 0)\n return ret;\n *got_frame = 1;\n if ((bitstream_tell(&bc) / 8) != buf_size)\n av_log(avctx, AV_LOG_ERROR, "buffer not fully consumed (%d != %d)\\n",\n buf_size, (bitstream_tell(&bc) / 8));\n return buf_size;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline 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}'] |
33,023 | 0 | https://github.com/openssl/openssl/blob/b79aa47a0c8478bea62fc2bb55f99e0be172da3d/crypto/bn/bn_add.c/#L230 | int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
int max,min,dif;
register BN_ULONG t1,t2,*ap,*bp,*rp;
int i,carry;
#if defined(IRIX_CC_BUG) && !defined(LINT)
int dummy;
#endif
bn_check_top(a);
bn_check_top(b);
max = a->top;
min = b->top;
dif = max - min;
if (dif < 0)
{
BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
return(0);
}
if (bn_wexpand(r,max) == NULL) return(0);
ap=a->d;
bp=b->d;
rp=r->d;
#if 1
carry=0;
for (i = min; i != 0; i--)
{
t1= *(ap++);
t2= *(bp++);
if (carry)
{
carry=(t1 <= t2);
t1=(t1-t2-1)&BN_MASK2;
}
else
{
carry=(t1 < t2);
t1=(t1-t2)&BN_MASK2;
}
#if defined(IRIX_CC_BUG) && !defined(LINT)
dummy=t1;
#endif
*(rp++)=t1&BN_MASK2;
}
#else
carry=bn_sub_words(rp,ap,bp,min);
ap+=min;
bp+=min;
rp+=min;
#endif
if (carry)
{
if (!dif)
return 0;
while (dif)
{
dif--;
t1 = *(ap++);
t2 = (t1-1)&BN_MASK2;
*(rp++) = t2;
if (t1)
break;
}
}
#if 0
memcpy(rp,ap,sizeof(*rp)*(max-i));
#else
if (rp != ap)
{
for (;;)
{
if (!dif--) break;
rp[0]=ap[0];
if (!dif--) break;
rp[1]=ap[1];
if (!dif--) break;
rp[2]=ap[2];
if (!dif--) break;
rp[3]=ap[3];
rp+=4;
ap+=4;
}
}
#endif
r->top=max;
r->neg=0;
bn_correct_top(r);
return(1);
} | ['int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tint retn=0;\n#ifdef MONT_WORD\n\tBIGNUM *n,*r;\n\tBN_ULONG *ap,*np,*rp,n0,v,*nrp;\n\tint al,nl,max,i,x,ri;\n\tBN_CTX_start(ctx);\n\tif ((r = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!BN_copy(r,a)) goto err;\n\tn= &(mont->N);\n\tap=a->d;\n\tal=ri=mont->ri/BN_BITS2;\n\tnl=n->top;\n\tif ((al == 0) || (nl == 0)) { r->top=0; return(1); }\n\tmax=(nl+al+1);\n\tif (bn_wexpand(r,max) == NULL) goto err;\n\tif (bn_wexpand(ret,max) == NULL) goto err;\n\tr->neg=a->neg^n->neg;\n\tnp=n->d;\n\trp=r->d;\n\tnrp= &(r->d[nl]);\n#if 1\n\tfor (i=r->top; i<max; i++)\n\t\tr->d[i]=0;\n#else\n\tmemset(&(r->d[r->top]),0,(max-r->top)*sizeof(BN_ULONG));\n#endif\n\tr->top=max;\n\tn0=mont->n0;\n#ifdef BN_COUNT\n\tfprintf(stderr,"word BN_from_montgomery %d * %d\\n",nl,nl);\n#endif\n\tfor (i=0; i<nl; i++)\n\t\t{\n#ifdef __TANDEM\n {\n long long t1;\n long long t2;\n long long t3;\n t1 = rp[0] * (n0 & 0177777);\n t2 = 037777600000l;\n t2 = n0 & t2;\n t3 = rp[0] & 0177777;\n t2 = (t3 * t2) & BN_MASK2;\n t1 = t1 + t2;\n v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);\n }\n#else\n\t\tv=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);\n#endif\n\t\tnrp++;\n\t\trp++;\n\t\tif (((nrp[-1]+=v)&BN_MASK2) >= v)\n\t\t\tcontinue;\n\t\telse\n\t\t\t{\n\t\t\tif (((++nrp[0])&BN_MASK2) != 0) continue;\n\t\t\tif (((++nrp[1])&BN_MASK2) != 0) continue;\n\t\t\tfor (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;\n\t\t\t}\n\t\t}\n\tbn_correct_top(r);\n#if 0\n\tBN_rshift(ret,r,mont->ri);\n#else\n\tret->neg = r->neg;\n\tx=ri;\n\trp=ret->d;\n\tap= &(r->d[x]);\n\tif (r->top < x)\n\t\tal=0;\n\telse\n\t\tal=r->top-x;\n\tret->top=al;\n\tal-=4;\n\tfor (i=0; i<al; i+=4)\n\t\t{\n\t\tBN_ULONG t1,t2,t3,t4;\n\t\tt1=ap[i+0];\n\t\tt2=ap[i+1];\n\t\tt3=ap[i+2];\n\t\tt4=ap[i+3];\n\t\trp[i+0]=t1;\n\t\trp[i+1]=t2;\n\t\trp[i+2]=t3;\n\t\trp[i+3]=t4;\n\t\t}\n\tal+=4;\n\tfor (; i<al; i++)\n\t\trp[i]=ap[i];\n#endif\n#else\n\tBIGNUM *t1,*t2;\n\tBN_CTX_start(ctx);\n\tt1 = BN_CTX_get(ctx);\n\tt2 = BN_CTX_get(ctx);\n\tif (t1 == NULL || t2 == NULL) goto err;\n\tif (!BN_copy(t1,a)) goto err;\n\tBN_mask_bits(t1,mont->ri);\n\tif (!BN_mul(t2,t1,&mont->Ni,ctx)) goto err;\n\tBN_mask_bits(t2,mont->ri);\n\tif (!BN_mul(t1,t2,&mont->N,ctx)) goto err;\n\tif (!BN_add(t2,a,t1)) goto err;\n\tif (!BN_rshift(ret,t2,mont->ri)) goto err;\n#endif\n\tif (BN_ucmp(ret, &(mont->N)) >= 0)\n\t\t{\n\t\tif (!BN_usub(ret,ret,&(mont->N))) goto err;\n\t\t}\n\tretn=1;\n\tbn_check_top(ret);\n err:\n\tBN_CTX_end(ctx);\n\treturn(retn);\n\t}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint max,min,dif;\n\tregister BN_ULONG t1,t2,*ap,*bp,*rp;\n\tint i,carry;\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\tint dummy;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tmax = a->top;\n\tmin = b->top;\n\tdif = max - min;\n\tif (dif < 0)\n\t\t{\n\t\tBNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);\n\t\treturn(0);\n\t\t}\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tap=a->d;\n\tbp=b->d;\n\trp=r->d;\n#if 1\n\tcarry=0;\n\tfor (i = min; i != 0; i--)\n\t\t{\n\t\tt1= *(ap++);\n\t\tt2= *(bp++);\n\t\tif (carry)\n\t\t\t{\n\t\t\tcarry=(t1 <= t2);\n\t\t\tt1=(t1-t2-1)&BN_MASK2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tcarry=(t1 < t2);\n\t\t\tt1=(t1-t2)&BN_MASK2;\n\t\t\t}\n#if defined(IRIX_CC_BUG) && !defined(LINT)\n\t\tdummy=t1;\n#endif\n\t\t*(rp++)=t1&BN_MASK2;\n\t\t}\n#else\n\tcarry=bn_sub_words(rp,ap,bp,min);\n\tap+=min;\n\tbp+=min;\n\trp+=min;\n#endif\n\tif (carry)\n\t\t{\n\t\tif (!dif)\n\t\t\treturn 0;\n\t\twhile (dif)\n\t\t\t{\n\t\t\tdif--;\n\t\t\tt1 = *(ap++);\n\t\t\tt2 = (t1-1)&BN_MASK2;\n\t\t\t*(rp++) = t2;\n\t\t\tif (t1)\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n#if 0\n\tmemcpy(rp,ap,sizeof(*rp)*(max-i));\n#else\n\tif (rp != ap)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tif (!dif--) break;\n\t\t\trp[0]=ap[0];\n\t\t\tif (!dif--) break;\n\t\t\trp[1]=ap[1];\n\t\t\tif (!dif--) break;\n\t\t\trp[2]=ap[2];\n\t\t\tif (!dif--) break;\n\t\t\trp[3]=ap[3];\n\t\t\trp+=4;\n\t\t\tap+=4;\n\t\t\t}\n\t\t}\n#endif\n\tr->top=max;\n\tr->neg=0;\n\tbn_correct_top(r);\n\treturn(1);\n\t}'] |
33,024 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_ctx.c/#L273 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value,\n BN_GENCB *cb)\n{\n BIGNUM *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *tmp;\n int bitsp, bitsq, ok = -1, n = 0;\n BN_CTX *ctx = NULL;\n if (bits < 16) {\n ok = 0;\n RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, RSA_R_KEY_SIZE_TOO_SMALL);\n goto err;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n r0 = BN_CTX_get(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n r3 = BN_CTX_get(ctx);\n if (r3 == NULL)\n goto err;\n bitsp = (bits + 1) / 2;\n bitsq = bits - bitsp;\n if (!rsa->n && ((rsa->n = BN_new()) == NULL))\n goto err;\n if (!rsa->d && ((rsa->d = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->e && ((rsa->e = BN_new()) == NULL))\n goto err;\n if (!rsa->p && ((rsa->p = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->q && ((rsa->q = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->dmp1 && ((rsa->dmp1 = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->dmq1 && ((rsa->dmq1 = BN_secure_new()) == NULL))\n goto err;\n if (!rsa->iqmp && ((rsa->iqmp = BN_secure_new()) == NULL))\n goto err;\n if (BN_copy(rsa->e, e_value) == NULL)\n goto err;\n for (;;) {\n if (!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb))\n goto err;\n if (!BN_sub(r2, rsa->p, BN_value_one()))\n goto err;\n if (!BN_gcd(r1, r2, rsa->e, ctx))\n goto err;\n if (BN_is_one(r1))\n break;\n if (!BN_GENCB_call(cb, 2, n++))\n goto err;\n }\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n for (;;) {\n do {\n if (!BN_generate_prime_ex(rsa->q, bitsq, 0, NULL, NULL, cb))\n goto err;\n } while (BN_cmp(rsa->p, rsa->q) == 0);\n if (!BN_sub(r2, rsa->q, BN_value_one()))\n goto err;\n if (!BN_gcd(r1, r2, rsa->e, ctx))\n goto err;\n if (BN_is_one(r1))\n break;\n if (!BN_GENCB_call(cb, 2, n++))\n goto err;\n }\n if (!BN_GENCB_call(cb, 3, 1))\n goto err;\n if (BN_cmp(rsa->p, rsa->q) < 0) {\n tmp = rsa->p;\n rsa->p = rsa->q;\n rsa->q = tmp;\n }\n if (!BN_mul(rsa->n, rsa->p, rsa->q, ctx))\n goto err;\n if (!BN_sub(r1, rsa->p, BN_value_one()))\n goto err;\n if (!BN_sub(r2, rsa->q, BN_value_one()))\n goto err;\n if (!BN_mul(r0, r1, r2, ctx))\n goto err;\n {\n BIGNUM *pr0 = BN_new();\n if (pr0 == NULL)\n goto err;\n BN_with_flags(pr0, r0, BN_FLG_CONSTTIME);\n if (!BN_mod_inverse(rsa->d, rsa->e, pr0, ctx)) {\n BN_free(pr0);\n goto err;\n }\n BN_free(pr0);\n }\n {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (\n !BN_mod(rsa->dmp1, d, r1, ctx)\n || !BN_mod(rsa->dmq1, d, r2, ctx)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n {\n BIGNUM *p = BN_new();\n if (p == NULL)\n goto err;\n BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n if (!BN_mod_inverse(rsa->iqmp, rsa->q, p, ctx)) {\n BN_free(p);\n goto err;\n }\n BN_free(p);\n }\n ok = 1;\n err:\n if (ok == -1) {\n RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);\n ok = 0;\n }\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n return ok;\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_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n BIGNUM *a, *b, *t;\n int ret = 0;\n bn_check_top(in_a);\n bn_check_top(in_b);\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_copy(a, in_a) == NULL)\n goto err;\n if (BN_copy(b, in_b) == NULL)\n goto err;\n a->neg = 0;\n b->neg = 0;\n if (BN_cmp(a, b) < 0) {\n t = a;\n a = b;\n b = t;\n }\n t = euclid(a, b);\n if (t == NULL)\n goto err;\n if (BN_copy(r, t) == NULL)\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\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}'] |
33,025 | 0 | https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/http/ngx_http_header_filter_module.c/#L426 | static ngx_int_t
ngx_http_header_filter(ngx_http_request_t *r)
{
u_char *p;
size_t len;
ngx_str_t host, *status_line;
ngx_buf_t *b;
ngx_uint_t status, i, port;
ngx_chain_t out;
ngx_list_part_t *part;
ngx_table_elt_t *header;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;
ngx_http_core_srv_conf_t *cscf;
u_char addr[NGX_SOCKADDR_STRLEN];
if (r->header_sent) {
return NGX_OK;
}
r->header_sent = 1;
if (r != r->main) {
return NGX_OK;
}
if (r->http_version < NGX_HTTP_VERSION_10) {
return NGX_OK;
}
if (r->method == NGX_HTTP_HEAD) {
r->header_only = 1;
}
if (r->headers_out.last_modified_time != -1) {
if (r->headers_out.status != NGX_HTTP_OK
&& r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
&& r->headers_out.status != NGX_HTTP_NOT_MODIFIED)
{
r->headers_out.last_modified_time = -1;
r->headers_out.last_modified = NULL;
}
}
len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1
+ sizeof(CRLF) - 1;
if (r->headers_out.status_line.len) {
len += r->headers_out.status_line.len;
status_line = &r->headers_out.status_line;
#if (NGX_SUPPRESS_WARN)
status = 0;
#endif
} else {
status = r->headers_out.status;
if (status >= NGX_HTTP_OK
&& status < NGX_HTTP_LAST_2XX)
{
if (status == NGX_HTTP_NO_CONTENT) {
r->header_only = 1;
ngx_str_null(&r->headers_out.content_type);
r->headers_out.last_modified_time = -1;
r->headers_out.last_modified = NULL;
r->headers_out.content_length = NULL;
r->headers_out.content_length_n = -1;
}
status -= NGX_HTTP_OK;
status_line = &ngx_http_status_lines[status];
len += ngx_http_status_lines[status].len;
} else if (status >= NGX_HTTP_MOVED_PERMANENTLY
&& status < NGX_HTTP_LAST_3XX)
{
if (status == NGX_HTTP_NOT_MODIFIED) {
r->header_only = 1;
}
status = status - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;
status_line = &ngx_http_status_lines[status];
len += ngx_http_status_lines[status].len;
} else if (status >= NGX_HTTP_BAD_REQUEST
&& status < NGX_HTTP_LAST_4XX)
{
status = status - NGX_HTTP_BAD_REQUEST
+ NGX_HTTP_OFF_4XX;
status_line = &ngx_http_status_lines[status];
len += ngx_http_status_lines[status].len;
} else if (status >= NGX_HTTP_INTERNAL_SERVER_ERROR
&& status < NGX_HTTP_LAST_5XX)
{
status = status - NGX_HTTP_INTERNAL_SERVER_ERROR
+ NGX_HTTP_OFF_5XX;
status_line = &ngx_http_status_lines[status];
len += ngx_http_status_lines[status].len;
} else {
len += NGX_INT_T_LEN + 1 ;
status_line = NULL;
}
if (status_line && status_line->len == 0) {
status = r->headers_out.status;
len += NGX_INT_T_LEN + 1 ;
status_line = NULL;
}
}
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (r->headers_out.server == NULL) {
len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1:
sizeof(ngx_http_server_string) - 1;
}
if (r->headers_out.date == NULL) {
len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
}
if (r->headers_out.content_type.len) {
len += sizeof("Content-Type: ") - 1
+ r->headers_out.content_type.len + 2;
if (r->headers_out.content_type_len == r->headers_out.content_type.len
&& r->headers_out.charset.len)
{
len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
}
}
if (r->headers_out.content_length == NULL
&& r->headers_out.content_length_n >= 0)
{
len += sizeof("Content-Length: ") - 1 + NGX_OFF_T_LEN + 2;
}
if (r->headers_out.last_modified == NULL
&& r->headers_out.last_modified_time != -1)
{
len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;
}
c = r->connection;
if (r->headers_out.location
&& r->headers_out.location->value.len
&& r->headers_out.location->value.data[0] == '/')
{
r->headers_out.location->hash = 0;
if (clcf->server_name_in_redirect) {
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
host = cscf->server_name;
} else if (r->headers_in.server.len) {
host = r->headers_in.server;
} else {
host.len = NGX_SOCKADDR_STRLEN;
host.data = addr;
if (ngx_connection_local_sockaddr(c, &host, 0) != NGX_OK) {
return NGX_ERROR;
}
}
port = ngx_inet_get_port(c->local_sockaddr);
len += sizeof("Location: https://") - 1
+ host.len
+ r->headers_out.location->value.len + 2;
if (clcf->port_in_redirect) {
#if (NGX_HTTP_SSL)
if (c->ssl)
port = (port == 443) ? 0 : port;
else
#endif
port = (port == 80) ? 0 : port;
} else {
port = 0;
}
if (port) {
len += sizeof(":65535") - 1;
}
} else {
ngx_str_null(&host);
port = 0;
}
if (r->chunked) {
len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;
}
if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
len += sizeof("Connection: upgrade" CRLF) - 1;
} else if (r->keepalive) {
len += sizeof("Connection: keep-alive" CRLF) - 1;
if (clcf->keepalive_header) {
len += sizeof("Keep-Alive: timeout=") - 1 + NGX_TIME_T_LEN + 2;
}
} else {
len += sizeof("Connection: close" CRLF) - 1;
}
#if (NGX_HTTP_GZIP)
if (r->gzip_vary) {
if (clcf->gzip_vary) {
len += sizeof("Vary: Accept-Encoding" CRLF) - 1;
} else {
r->gzip_vary = 0;
}
}
#endif
part = &r->headers_out.headers.part;
header = part->elts;
for (i = 0; ; i++) {
if (i >= part->nelts) {
if (part->next == NULL) {
break;
}
part = part->next;
header = part->elts;
i = 0;
}
if (header[i].hash == 0) {
continue;
}
len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len
+ sizeof(CRLF) - 1;
}
b = ngx_create_temp_buf(r->pool, len);
if (b == NULL) {
return NGX_ERROR;
}
b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);
if (status_line) {
b->last = ngx_copy(b->last, status_line->data, status_line->len);
} else {
b->last = ngx_sprintf(b->last, "%03ui ", status);
}
*b->last++ = CR; *b->last++ = LF;
if (r->headers_out.server == NULL) {
if (clcf->server_tokens) {
p = (u_char *) ngx_http_server_full_string;
len = sizeof(ngx_http_server_full_string) - 1;
} else {
p = (u_char *) ngx_http_server_string;
len = sizeof(ngx_http_server_string) - 1;
}
b->last = ngx_cpymem(b->last, p, len);
}
if (r->headers_out.date == NULL) {
b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1);
b->last = ngx_cpymem(b->last, ngx_cached_http_time.data,
ngx_cached_http_time.len);
*b->last++ = CR; *b->last++ = LF;
}
if (r->headers_out.content_type.len) {
b->last = ngx_cpymem(b->last, "Content-Type: ",
sizeof("Content-Type: ") - 1);
p = b->last;
b->last = ngx_copy(b->last, r->headers_out.content_type.data,
r->headers_out.content_type.len);
if (r->headers_out.content_type_len == r->headers_out.content_type.len
&& r->headers_out.charset.len)
{
b->last = ngx_cpymem(b->last, "; charset=",
sizeof("; charset=") - 1);
b->last = ngx_copy(b->last, r->headers_out.charset.data,
r->headers_out.charset.len);
r->headers_out.content_type.len = b->last - p;
r->headers_out.content_type.data = p;
}
*b->last++ = CR; *b->last++ = LF;
}
if (r->headers_out.content_length == NULL
&& r->headers_out.content_length_n >= 0)
{
b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,
r->headers_out.content_length_n);
}
if (r->headers_out.last_modified == NULL
&& r->headers_out.last_modified_time != -1)
{
b->last = ngx_cpymem(b->last, "Last-Modified: ",
sizeof("Last-Modified: ") - 1);
b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);
*b->last++ = CR; *b->last++ = LF;
}
if (host.data) {
p = b->last + sizeof("Location: ") - 1;
b->last = ngx_cpymem(b->last, "Location: http",
sizeof("Location: http") - 1);
#if (NGX_HTTP_SSL)
if (c->ssl) {
*b->last++ ='s';
}
#endif
*b->last++ = ':'; *b->last++ = '/'; *b->last++ = '/';
b->last = ngx_copy(b->last, host.data, host.len);
if (port) {
b->last = ngx_sprintf(b->last, ":%ui", port);
}
b->last = ngx_copy(b->last, r->headers_out.location->value.data,
r->headers_out.location->value.len);
r->headers_out.location->value.len = b->last - p;
r->headers_out.location->value.data = p;
ngx_str_set(&r->headers_out.location->key, "Location");
*b->last++ = CR; *b->last++ = LF;
}
if (r->chunked) {
b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF,
sizeof("Transfer-Encoding: chunked" CRLF) - 1);
}
if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
b->last = ngx_cpymem(b->last, "Connection: upgrade" CRLF,
sizeof("Connection: upgrade" CRLF) - 1);
} else if (r->keepalive) {
b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF,
sizeof("Connection: keep-alive" CRLF) - 1);
if (clcf->keepalive_header) {
b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,
clcf->keepalive_header);
}
} else {
b->last = ngx_cpymem(b->last, "Connection: close" CRLF,
sizeof("Connection: close" CRLF) - 1);
}
#if (NGX_HTTP_GZIP)
if (r->gzip_vary) {
b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,
sizeof("Vary: Accept-Encoding" CRLF) - 1);
}
#endif
part = &r->headers_out.headers.part;
header = part->elts;
for (i = 0; ; i++) {
if (i >= part->nelts) {
if (part->next == NULL) {
break;
}
part = part->next;
header = part->elts;
i = 0;
}
if (header[i].hash == 0) {
continue;
}
b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);
*b->last++ = ':'; *b->last++ = ' ';
b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len);
*b->last++ = CR; *b->last++ = LF;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"%*s", (size_t) (b->last - b->pos), b->pos);
*b->last++ = CR; *b->last++ = LF;
r->header_size = b->last - b->pos;
if (r->header_only) {
b->last_buf = 1;
}
out.buf = b;
out.next = NULL;
return ngx_http_write_filter(r, &out);
} | ['static ngx_int_t\nngx_http_header_filter(ngx_http_request_t *r)\n{\n u_char *p;\n size_t len;\n ngx_str_t host, *status_line;\n ngx_buf_t *b;\n ngx_uint_t status, i, port;\n ngx_chain_t out;\n ngx_list_part_t *part;\n ngx_table_elt_t *header;\n ngx_connection_t *c;\n ngx_http_core_loc_conf_t *clcf;\n ngx_http_core_srv_conf_t *cscf;\n u_char addr[NGX_SOCKADDR_STRLEN];\n if (r->header_sent) {\n return NGX_OK;\n }\n r->header_sent = 1;\n if (r != r->main) {\n return NGX_OK;\n }\n if (r->http_version < NGX_HTTP_VERSION_10) {\n return NGX_OK;\n }\n if (r->method == NGX_HTTP_HEAD) {\n r->header_only = 1;\n }\n if (r->headers_out.last_modified_time != -1) {\n if (r->headers_out.status != NGX_HTTP_OK\n && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT\n && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)\n {\n r->headers_out.last_modified_time = -1;\n r->headers_out.last_modified = NULL;\n }\n }\n len = sizeof("HTTP/1.x ") - 1 + sizeof(CRLF) - 1\n + sizeof(CRLF) - 1;\n if (r->headers_out.status_line.len) {\n len += r->headers_out.status_line.len;\n status_line = &r->headers_out.status_line;\n#if (NGX_SUPPRESS_WARN)\n status = 0;\n#endif\n } else {\n status = r->headers_out.status;\n if (status >= NGX_HTTP_OK\n && status < NGX_HTTP_LAST_2XX)\n {\n if (status == NGX_HTTP_NO_CONTENT) {\n r->header_only = 1;\n ngx_str_null(&r->headers_out.content_type);\n r->headers_out.last_modified_time = -1;\n r->headers_out.last_modified = NULL;\n r->headers_out.content_length = NULL;\n r->headers_out.content_length_n = -1;\n }\n status -= NGX_HTTP_OK;\n status_line = &ngx_http_status_lines[status];\n len += ngx_http_status_lines[status].len;\n } else if (status >= NGX_HTTP_MOVED_PERMANENTLY\n && status < NGX_HTTP_LAST_3XX)\n {\n if (status == NGX_HTTP_NOT_MODIFIED) {\n r->header_only = 1;\n }\n status = status - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;\n status_line = &ngx_http_status_lines[status];\n len += ngx_http_status_lines[status].len;\n } else if (status >= NGX_HTTP_BAD_REQUEST\n && status < NGX_HTTP_LAST_4XX)\n {\n status = status - NGX_HTTP_BAD_REQUEST\n + NGX_HTTP_OFF_4XX;\n status_line = &ngx_http_status_lines[status];\n len += ngx_http_status_lines[status].len;\n } else if (status >= NGX_HTTP_INTERNAL_SERVER_ERROR\n && status < NGX_HTTP_LAST_5XX)\n {\n status = status - NGX_HTTP_INTERNAL_SERVER_ERROR\n + NGX_HTTP_OFF_5XX;\n status_line = &ngx_http_status_lines[status];\n len += ngx_http_status_lines[status].len;\n } else {\n len += NGX_INT_T_LEN + 1 ;\n status_line = NULL;\n }\n if (status_line && status_line->len == 0) {\n status = r->headers_out.status;\n len += NGX_INT_T_LEN + 1 ;\n status_line = NULL;\n }\n }\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (r->headers_out.server == NULL) {\n len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1:\n sizeof(ngx_http_server_string) - 1;\n }\n if (r->headers_out.date == NULL) {\n len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;\n }\n if (r->headers_out.content_type.len) {\n len += sizeof("Content-Type: ") - 1\n + r->headers_out.content_type.len + 2;\n if (r->headers_out.content_type_len == r->headers_out.content_type.len\n && r->headers_out.charset.len)\n {\n len += sizeof("; charset=") - 1 + r->headers_out.charset.len;\n }\n }\n if (r->headers_out.content_length == NULL\n && r->headers_out.content_length_n >= 0)\n {\n len += sizeof("Content-Length: ") - 1 + NGX_OFF_T_LEN + 2;\n }\n if (r->headers_out.last_modified == NULL\n && r->headers_out.last_modified_time != -1)\n {\n len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1;\n }\n c = r->connection;\n if (r->headers_out.location\n && r->headers_out.location->value.len\n && r->headers_out.location->value.data[0] == \'/\')\n {\n r->headers_out.location->hash = 0;\n if (clcf->server_name_in_redirect) {\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n host = cscf->server_name;\n } else if (r->headers_in.server.len) {\n host = r->headers_in.server;\n } else {\n host.len = NGX_SOCKADDR_STRLEN;\n host.data = addr;\n if (ngx_connection_local_sockaddr(c, &host, 0) != NGX_OK) {\n return NGX_ERROR;\n }\n }\n port = ngx_inet_get_port(c->local_sockaddr);\n len += sizeof("Location: https://") - 1\n + host.len\n + r->headers_out.location->value.len + 2;\n if (clcf->port_in_redirect) {\n#if (NGX_HTTP_SSL)\n if (c->ssl)\n port = (port == 443) ? 0 : port;\n else\n#endif\n port = (port == 80) ? 0 : port;\n } else {\n port = 0;\n }\n if (port) {\n len += sizeof(":65535") - 1;\n }\n } else {\n ngx_str_null(&host);\n port = 0;\n }\n if (r->chunked) {\n len += sizeof("Transfer-Encoding: chunked" CRLF) - 1;\n }\n if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {\n len += sizeof("Connection: upgrade" CRLF) - 1;\n } else if (r->keepalive) {\n len += sizeof("Connection: keep-alive" CRLF) - 1;\n if (clcf->keepalive_header) {\n len += sizeof("Keep-Alive: timeout=") - 1 + NGX_TIME_T_LEN + 2;\n }\n } else {\n len += sizeof("Connection: close" CRLF) - 1;\n }\n#if (NGX_HTTP_GZIP)\n if (r->gzip_vary) {\n if (clcf->gzip_vary) {\n len += sizeof("Vary: Accept-Encoding" CRLF) - 1;\n } else {\n r->gzip_vary = 0;\n }\n }\n#endif\n part = &r->headers_out.headers.part;\n header = 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 header = part->elts;\n i = 0;\n }\n if (header[i].hash == 0) {\n continue;\n }\n len += header[i].key.len + sizeof(": ") - 1 + header[i].value.len\n + sizeof(CRLF) - 1;\n }\n b = ngx_create_temp_buf(r->pool, len);\n if (b == NULL) {\n return NGX_ERROR;\n }\n b->last = ngx_cpymem(b->last, "HTTP/1.1 ", sizeof("HTTP/1.x ") - 1);\n if (status_line) {\n b->last = ngx_copy(b->last, status_line->data, status_line->len);\n } else {\n b->last = ngx_sprintf(b->last, "%03ui ", status);\n }\n *b->last++ = CR; *b->last++ = LF;\n if (r->headers_out.server == NULL) {\n if (clcf->server_tokens) {\n p = (u_char *) ngx_http_server_full_string;\n len = sizeof(ngx_http_server_full_string) - 1;\n } else {\n p = (u_char *) ngx_http_server_string;\n len = sizeof(ngx_http_server_string) - 1;\n }\n b->last = ngx_cpymem(b->last, p, len);\n }\n if (r->headers_out.date == NULL) {\n b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1);\n b->last = ngx_cpymem(b->last, ngx_cached_http_time.data,\n ngx_cached_http_time.len);\n *b->last++ = CR; *b->last++ = LF;\n }\n if (r->headers_out.content_type.len) {\n b->last = ngx_cpymem(b->last, "Content-Type: ",\n sizeof("Content-Type: ") - 1);\n p = b->last;\n b->last = ngx_copy(b->last, r->headers_out.content_type.data,\n r->headers_out.content_type.len);\n if (r->headers_out.content_type_len == r->headers_out.content_type.len\n && r->headers_out.charset.len)\n {\n b->last = ngx_cpymem(b->last, "; charset=",\n sizeof("; charset=") - 1);\n b->last = ngx_copy(b->last, r->headers_out.charset.data,\n r->headers_out.charset.len);\n r->headers_out.content_type.len = b->last - p;\n r->headers_out.content_type.data = p;\n }\n *b->last++ = CR; *b->last++ = LF;\n }\n if (r->headers_out.content_length == NULL\n && r->headers_out.content_length_n >= 0)\n {\n b->last = ngx_sprintf(b->last, "Content-Length: %O" CRLF,\n r->headers_out.content_length_n);\n }\n if (r->headers_out.last_modified == NULL\n && r->headers_out.last_modified_time != -1)\n {\n b->last = ngx_cpymem(b->last, "Last-Modified: ",\n sizeof("Last-Modified: ") - 1);\n b->last = ngx_http_time(b->last, r->headers_out.last_modified_time);\n *b->last++ = CR; *b->last++ = LF;\n }\n if (host.data) {\n p = b->last + sizeof("Location: ") - 1;\n b->last = ngx_cpymem(b->last, "Location: http",\n sizeof("Location: http") - 1);\n#if (NGX_HTTP_SSL)\n if (c->ssl) {\n *b->last++ =\'s\';\n }\n#endif\n *b->last++ = \':\'; *b->last++ = \'/\'; *b->last++ = \'/\';\n b->last = ngx_copy(b->last, host.data, host.len);\n if (port) {\n b->last = ngx_sprintf(b->last, ":%ui", port);\n }\n b->last = ngx_copy(b->last, r->headers_out.location->value.data,\n r->headers_out.location->value.len);\n r->headers_out.location->value.len = b->last - p;\n r->headers_out.location->value.data = p;\n ngx_str_set(&r->headers_out.location->key, "Location");\n *b->last++ = CR; *b->last++ = LF;\n }\n if (r->chunked) {\n b->last = ngx_cpymem(b->last, "Transfer-Encoding: chunked" CRLF,\n sizeof("Transfer-Encoding: chunked" CRLF) - 1);\n }\n if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {\n b->last = ngx_cpymem(b->last, "Connection: upgrade" CRLF,\n sizeof("Connection: upgrade" CRLF) - 1);\n } else if (r->keepalive) {\n b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF,\n sizeof("Connection: keep-alive" CRLF) - 1);\n if (clcf->keepalive_header) {\n b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,\n clcf->keepalive_header);\n }\n } else {\n b->last = ngx_cpymem(b->last, "Connection: close" CRLF,\n sizeof("Connection: close" CRLF) - 1);\n }\n#if (NGX_HTTP_GZIP)\n if (r->gzip_vary) {\n b->last = ngx_cpymem(b->last, "Vary: Accept-Encoding" CRLF,\n sizeof("Vary: Accept-Encoding" CRLF) - 1);\n }\n#endif\n part = &r->headers_out.headers.part;\n header = 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 header = part->elts;\n i = 0;\n }\n if (header[i].hash == 0) {\n continue;\n }\n b->last = ngx_copy(b->last, header[i].key.data, header[i].key.len);\n *b->last++ = \':\'; *b->last++ = \' \';\n b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len);\n *b->last++ = CR; *b->last++ = LF;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "%*s", (size_t) (b->last - b->pos), b->pos);\n *b->last++ = CR; *b->last++ = LF;\n r->header_size = b->last - b->pos;\n if (r->header_only) {\n b->last_buf = 1;\n }\n out.buf = b;\n out.next = NULL;\n return ngx_http_write_filter(r, &out);\n}', 'ngx_buf_t *\nngx_create_temp_buf(ngx_pool_t *pool, size_t size)\n{\n ngx_buf_t *b;\n b = ngx_calloc_buf(pool);\n if (b == NULL) {\n return NULL;\n }\n b->start = ngx_palloc(pool, size);\n if (b->start == NULL) {\n return NULL;\n }\n b->pos = b->start;\n b->last = b->start;\n b->end = b->last + size;\n b->temporary = 1;\n return b;\n}', 'void *\nngx_palloc(ngx_pool_t *pool, size_t size)\n{\n#if !(NGX_DEBUG_PALLOC)\n if (size <= pool->max) {\n return ngx_palloc_small(pool, size, 1);\n }\n#endif\n return ngx_palloc_large(pool, size);\n}', 'static ngx_inline void *\nngx_palloc_small(ngx_pool_t *pool, size_t size, ngx_uint_t align)\n{\n u_char *m;\n ngx_pool_t *p;\n p = pool->current;\n do {\n m = p->d.last;\n if (align) {\n m = ngx_align_ptr(m, NGX_ALIGNMENT);\n }\n if ((size_t) (p->d.end - m) >= size) {\n p->d.last = m + size;\n return m;\n }\n p = p->d.next;\n } while (p);\n return ngx_palloc_block(pool, size);\n}'] |
33,026 | 0 | https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/crypto/x509/x509_obj.c/#L56 | char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
{
X509_NAME_ENTRY *ne;
int i;
int n, lold, l, l1, l2, num, j, type;
const char *s;
char *p;
unsigned char *q;
BUF_MEM *b = NULL;
static const char hex[17] = "0123456789ABCDEF";
int gs_doit[4];
char tmp_buf[80];
#ifdef CHARSET_EBCDIC
unsigned char ebcdic_buf[1024];
#endif
if (buf == NULL) {
if ((b = BUF_MEM_new()) == NULL)
goto err;
if (!BUF_MEM_grow(b, 200))
goto err;
b->data[0] = '\0';
len = 200;
} else if (len == 0) {
return NULL;
}
if (a == NULL) {
if (b) {
buf = b->data;
OPENSSL_free(b);
}
strncpy(buf, "NO X509_NAME", len);
buf[len - 1] = '\0';
return buf;
}
len--;
l = 0;
for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
ne = sk_X509_NAME_ENTRY_value(a->entries, i);
n = OBJ_obj2nid(ne->object);
if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
s = tmp_buf;
}
l1 = strlen(s);
type = ne->value->type;
num = ne->value->length;
if (num > NAME_ONELINE_MAX) {
X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
goto end;
}
q = ne->value->data;
#ifdef CHARSET_EBCDIC
if (type == V_ASN1_GENERALSTRING ||
type == V_ASN1_VISIBLESTRING ||
type == V_ASN1_PRINTABLESTRING ||
type == V_ASN1_TELETEXSTRING ||
type == V_ASN1_IA5STRING) {
if (num > (int)sizeof(ebcdic_buf))
num = sizeof(ebcdic_buf);
ascii2ebcdic(ebcdic_buf, q, num);
q = ebcdic_buf;
}
#endif
if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
for (j = 0; j < num; j++)
if (q[j] != 0)
gs_doit[j & 3] = 1;
if (gs_doit[0] | gs_doit[1] | gs_doit[2])
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
else {
gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
gs_doit[3] = 1;
}
} else
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
for (l2 = j = 0; j < num; j++) {
if (!gs_doit[j & 3])
continue;
l2++;
#ifndef CHARSET_EBCDIC
if ((q[j] < ' ') || (q[j] > '~'))
l2 += 3;
#else
if ((os_toascii[q[j]] < os_toascii[' ']) ||
(os_toascii[q[j]] > os_toascii['~']))
l2 += 3;
#endif
}
lold = l;
l += 1 + l1 + 1 + l2;
if (l > NAME_ONELINE_MAX) {
X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
goto end;
}
if (b != NULL) {
if (!BUF_MEM_grow(b, l + 1))
goto err;
p = &(b->data[lold]);
} else if (l > len) {
break;
} else
p = &(buf[lold]);
*(p++) = '/';
memcpy(p, s, (unsigned int)l1);
p += l1;
*(p++) = '=';
#ifndef CHARSET_EBCDIC
q = ne->value->data;
#endif
for (j = 0; j < num; j++) {
if (!gs_doit[j & 3])
continue;
#ifndef CHARSET_EBCDIC
n = q[j];
if ((n < ' ') || (n > '~')) {
*(p++) = '\\';
*(p++) = 'x';
*(p++) = hex[(n >> 4) & 0x0f];
*(p++) = hex[n & 0x0f];
} else
*(p++) = n;
#else
n = os_toascii[q[j]];
if ((n < os_toascii[' ']) || (n > os_toascii['~'])) {
*(p++) = '\\';
*(p++) = 'x';
*(p++) = hex[(n >> 4) & 0x0f];
*(p++) = hex[n & 0x0f];
} else
*(p++) = q[j];
#endif
}
*p = '\0';
}
if (b != NULL) {
p = b->data;
OPENSSL_free(b);
} else
p = buf;
if (i == 0)
*p = '\0';
return (p);
err:
X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
end:
BUF_MEM_free(b);
return (NULL);
} | ['int X509_CRL_print(BIO *out, X509_CRL *x)\n{\n STACK_OF(X509_REVOKED) *rev;\n X509_REVOKED *r;\n const X509_ALGOR *sig_alg;\n const ASN1_BIT_STRING *sig;\n long l;\n int i;\n char *p;\n BIO_printf(out, "Certificate Revocation List (CRL):\\n");\n l = X509_CRL_get_version(x);\n BIO_printf(out, "%8sVersion %lu (0x%lx)\\n", "", l + 1, l);\n X509_CRL_get0_signature(x, &sig, &sig_alg);\n X509_signature_print(out, sig_alg, NULL);\n p = X509_NAME_oneline(X509_CRL_get_issuer(x), NULL, 0);\n BIO_printf(out, "%8sIssuer: %s\\n", "", p);\n OPENSSL_free(p);\n BIO_printf(out, "%8sLast Update: ", "");\n ASN1_TIME_print(out, X509_CRL_get_lastUpdate(x));\n BIO_printf(out, "\\n%8sNext Update: ", "");\n if (X509_CRL_get_nextUpdate(x))\n ASN1_TIME_print(out, X509_CRL_get_nextUpdate(x));\n else\n BIO_printf(out, "NONE");\n BIO_printf(out, "\\n");\n X509V3_extensions_print(out, "CRL extensions",\n X509_CRL_get0_extensions(x), 0, 8);\n rev = X509_CRL_get_REVOKED(x);\n if (sk_X509_REVOKED_num(rev) > 0)\n BIO_printf(out, "Revoked Certificates:\\n");\n else\n BIO_printf(out, "No Revoked Certificates.\\n");\n for (i = 0; i < sk_X509_REVOKED_num(rev); i++) {\n r = sk_X509_REVOKED_value(rev, i);\n BIO_printf(out, " Serial Number: ");\n i2a_ASN1_INTEGER(out, X509_REVOKED_get0_serialNumber(r));\n BIO_printf(out, "\\n Revocation Date: ");\n ASN1_TIME_print(out, X509_REVOKED_get0_revocationDate(r));\n BIO_printf(out, "\\n");\n X509V3_extensions_print(out, "CRL entry extensions",\n X509_REVOKED_get0_extensions(r), 0, 8);\n }\n X509_signature_print(out, sig_alg, sig);\n return 1;\n}', 'char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)\n{\n X509_NAME_ENTRY *ne;\n int i;\n int n, lold, l, l1, l2, num, j, type;\n const char *s;\n char *p;\n unsigned char *q;\n BUF_MEM *b = NULL;\n static const char hex[17] = "0123456789ABCDEF";\n int gs_doit[4];\n char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n unsigned char ebcdic_buf[1024];\n#endif\n if (buf == NULL) {\n if ((b = BUF_MEM_new()) == NULL)\n goto err;\n if (!BUF_MEM_grow(b, 200))\n goto err;\n b->data[0] = \'\\0\';\n len = 200;\n } else if (len == 0) {\n return NULL;\n }\n if (a == NULL) {\n if (b) {\n buf = b->data;\n OPENSSL_free(b);\n }\n strncpy(buf, "NO X509_NAME", len);\n buf[len - 1] = \'\\0\';\n return buf;\n }\n len--;\n l = 0;\n for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n n = OBJ_obj2nid(ne->object);\n if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n s = tmp_buf;\n }\n l1 = strlen(s);\n type = ne->value->type;\n num = ne->value->length;\n if (num > NAME_ONELINE_MAX) {\n X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n goto end;\n }\n q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n if (type == V_ASN1_GENERALSTRING ||\n type == V_ASN1_VISIBLESTRING ||\n type == V_ASN1_PRINTABLESTRING ||\n type == V_ASN1_TELETEXSTRING ||\n type == V_ASN1_IA5STRING) {\n if (num > (int)sizeof(ebcdic_buf))\n num = sizeof(ebcdic_buf);\n ascii2ebcdic(ebcdic_buf, q, num);\n q = ebcdic_buf;\n }\n#endif\n if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n for (j = 0; j < num; j++)\n if (q[j] != 0)\n gs_doit[j & 3] = 1;\n if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n else {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n gs_doit[3] = 1;\n }\n } else\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n for (l2 = j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n l2++;\n#ifndef CHARSET_EBCDIC\n if ((q[j] < \' \') || (q[j] > \'~\'))\n l2 += 3;\n#else\n if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n (os_toascii[q[j]] > os_toascii[\'~\']))\n l2 += 3;\n#endif\n }\n lold = l;\n l += 1 + l1 + 1 + l2;\n if (l > NAME_ONELINE_MAX) {\n X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n goto end;\n }\n if (b != NULL) {\n if (!BUF_MEM_grow(b, l + 1))\n goto err;\n p = &(b->data[lold]);\n } else if (l > len) {\n break;\n } else\n p = &(buf[lold]);\n *(p++) = \'/\';\n memcpy(p, s, (unsigned int)l1);\n p += l1;\n *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n q = ne->value->data;\n#endif\n for (j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n#ifndef CHARSET_EBCDIC\n n = q[j];\n if ((n < \' \') || (n > \'~\')) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = n;\n#else\n n = os_toascii[q[j]];\n if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = q[j];\n#endif\n }\n *p = \'\\0\';\n }\n if (b != NULL) {\n p = b->data;\n OPENSSL_free(b);\n } else\n p = buf;\n if (i == 0)\n *p = \'\\0\';\n return (p);\n err:\n X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n end:\n BUF_MEM_free(b);\n return (NULL);\n}'] |
33,027 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250 | int BN_num_bits(const BIGNUM *a)
{
int i = a->top - 1;
bn_check_top(a);
if (BN_is_zero(a)) return 0;
return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
} | ['int gost2001_compute_public(EC_KEY *ec)\n\t{\n\tconst EC_GROUP *group = EC_KEY_get0_group(ec);\n\tEC_POINT *pub_key=NULL;\n\tconst BIGNUM *priv_key=NULL;\n\tBN_CTX *ctx=NULL;\n\tint ok=0;\n\tif (!group)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,GOST_R_KEY_IS_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tctx=BN_CTX_new();\n\tBN_CTX_start(ctx);\n\tif (!(priv_key=EC_KEY_get0_private_key(ec)))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tpub_key = EC_POINT_new(group);\n\tif (!EC_POINT_mul(group,pub_key,priv_key,NULL,NULL,ctx))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tif (!EC_KEY_set_public_key(ec,pub_key))\n\t\t{\n\t\tGOSTerr(GOST_F_GOST2001_COMPUTE_PUBLIC,ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tok = 256;\n\terr:\n\tBN_CTX_end(ctx);\n\tEC_POINT_free(pub_key);\n\tBN_CTX_free(ctx);\n\treturn ok;\n\t}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n\tconst EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n\t{\n\tconst EC_POINT *points[1];\n\tconst BIGNUM *scalars[1];\n\tpoints[0] = point;\n\tscalars[0] = p_scalar;\n\treturn EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);\n\t}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n\tsize_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)\n\t{\n\tif (group->meth->mul == 0)\n\t\treturn ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n\treturn group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n\t}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n\tsize_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)\n\t{\n\tBN_CTX *new_ctx = NULL;\n\tconst EC_POINT *generator = NULL;\n\tEC_POINT *tmp = NULL;\n\tsize_t totalnum;\n\tsize_t blocksize = 0, numblocks = 0;\n\tsize_t pre_points_per_block = 0;\n\tsize_t i, j;\n\tint k;\n\tint r_is_inverted = 0;\n\tint r_is_at_infinity = 1;\n\tsize_t *wsize = NULL;\n\tsigned char **wNAF = NULL;\n\tsize_t *wNAF_len = NULL;\n\tsize_t max_len = 0;\n\tsize_t num_val;\n\tEC_POINT **val = NULL;\n\tEC_POINT **v;\n\tEC_POINT ***val_sub = NULL;\n\tconst EC_PRE_COMP *pre_comp = NULL;\n\tint num_scalar = 0;\n\tint ret = 0;\n\tif (group->meth != r->meth)\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n\t\treturn 0;\n\t\t}\n\tif ((scalar == NULL) && (num == 0))\n\t\t{\n\t\treturn EC_POINT_set_to_infinity(group, r);\n\t\t}\n\tfor (i = 0; i < num; i++)\n\t\t{\n\t\tif (group->meth != points[i]->meth)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\tgoto err;\n\t\t}\n\tif (scalar != NULL)\n\t\t{\n\t\tgenerator = EC_GROUP_get0_generator(group);\n\t\tif (generator == NULL)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n\t\t\tgoto err;\n\t\t\t}\n\t\tpre_comp = EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);\n\t\tif (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0))\n\t\t\t{\n\t\t\tblocksize = pre_comp->blocksize;\n\t\t\tnumblocks = (BN_num_bits(scalar) / blocksize) + 1;\n\t\t\tif (numblocks > pre_comp->numblocks)\n\t\t\t\tnumblocks = pre_comp->numblocks;\n\t\t\tpre_points_per_block = 1u << (pre_comp->w - 1);\n\t\t\tif (pre_comp->num != (pre_comp->numblocks * pre_points_per_block))\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpre_comp = NULL;\n\t\t\tnumblocks = 1;\n\t\t\tnum_scalar = 1;\n\t\t\t}\n\t\t}\n\ttotalnum = num + numblocks;\n\twsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);\n\twNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);\n\twNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);\n\tval_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);\n\tif (!wsize || !wNAF_len || !wNAF || !val_sub)\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\twNAF[0] = NULL;\n\tnum_val = 0;\n\tfor (i = 0; i < num + num_scalar; i++)\n\t\t{\n\t\tsize_t bits;\n\t\tbits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n\t\twsize[i] = EC_window_bits_for_scalar_size(bits);\n\t\tnum_val += 1u << (wsize[i] - 1);\n\t\twNAF[i + 1] = NULL;\n\t\twNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]);\n\t\tif (wNAF[i] == NULL)\n\t\t\tgoto err;\n\t\tif (wNAF_len[i] > max_len)\n\t\t\tmax_len = wNAF_len[i];\n\t\t}\n\tif (numblocks)\n\t\t{\n\t\tif (pre_comp == NULL)\n\t\t\t{\n\t\t\tif (num_scalar != 1)\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsigned char *tmp_wNAF = NULL;\n\t\t\tsize_t tmp_len = 0;\n\t\t\tif (num_scalar != 0)\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\twsize[num] = pre_comp->w;\n\t\t\ttmp_wNAF = compute_wNAF(scalar, wsize[num], &tmp_len);\n\t\t\tif (!tmp_wNAF)\n\t\t\t\tgoto err;\n\t\t\tif (tmp_len <= max_len)\n\t\t\t\t{\n\t\t\t\tnumblocks = 1;\n\t\t\t\ttotalnum = num + 1;\n\t\t\t\twNAF[num] = tmp_wNAF;\n\t\t\t\twNAF[num + 1] = NULL;\n\t\t\t\twNAF_len[num] = tmp_len;\n\t\t\t\tif (tmp_len > max_len)\n\t\t\t\t\tmax_len = tmp_len;\n\t\t\t\tval_sub[num] = pre_comp->points;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tsigned char *pp;\n\t\t\t\tEC_POINT **tmp_points;\n\t\t\t\tif (tmp_len < numblocks * blocksize)\n\t\t\t\t\t{\n\t\t\t\t\tnumblocks = (tmp_len + blocksize - 1) / blocksize;\n\t\t\t\t\tif (numblocks > pre_comp->numblocks)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t}\n\t\t\t\t\ttotalnum = num + numblocks;\n\t\t\t\t\t}\n\t\t\t\tpp = tmp_wNAF;\n\t\t\t\ttmp_points = pre_comp->points;\n\t\t\t\tfor (i = num; i < totalnum; i++)\n\t\t\t\t\t{\n\t\t\t\t\tif (i < totalnum - 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\twNAF_len[i] = blocksize;\n\t\t\t\t\t\tif (tmp_len < blocksize)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\ttmp_len -= blocksize;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\twNAF_len[i] = tmp_len;\n\t\t\t\t\twNAF[i + 1] = NULL;\n\t\t\t\t\twNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n\t\t\t\t\tif (wNAF[i] == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n\t\t\t\t\t\tOPENSSL_free(tmp_wNAF);\n\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t}\n\t\t\t\t\tmemcpy(wNAF[i], pp, wNAF_len[i]);\n\t\t\t\t\tif (wNAF_len[i] > max_len)\n\t\t\t\t\t\tmax_len = wNAF_len[i];\n\t\t\t\t\tif (*tmp_points == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\t\t\tOPENSSL_free(tmp_wNAF);\n\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t}\n\t\t\t\t\tval_sub[i] = tmp_points;\n\t\t\t\t\ttmp_points += pre_points_per_block;\n\t\t\t\t\tpp += blocksize;\n\t\t\t\t\t}\n\t\t\t\tOPENSSL_free(tmp_wNAF);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tval = OPENSSL_malloc((num_val + 1) * sizeof val[0]);\n\tif (val == NULL)\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tval[num_val] = NULL;\n\tv = val;\n\tfor (i = 0; i < num + num_scalar; i++)\n\t\t{\n\t\tval_sub[i] = v;\n\t\tfor (j = 0; j < (1u << (wsize[i] - 1)); j++)\n\t\t\t{\n\t\t\t*v = EC_POINT_new(group);\n\t\t\tif (*v == NULL) goto err;\n\t\t\tv++;\n\t\t\t}\n\t\t}\n\tif (!(v == val + num_val))\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (!(tmp = EC_POINT_new(group)))\n\t\tgoto err;\n\tfor (i = 0; i < num + num_scalar; i++)\n\t\t{\n\t\tif (i < num)\n\t\t\t{\n\t\t\tif (!EC_POINT_copy(val_sub[i][0], points[i])) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!EC_POINT_copy(val_sub[i][0], generator)) goto err;\n\t\t\t}\n\t\tif (wsize[i] > 1)\n\t\t\t{\n\t\t\tif (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err;\n\t\t\tfor (j = 1; j < (1u << (wsize[i] - 1)); j++)\n\t\t\t\t{\n\t\t\t\tif (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#if 1\n\tif (!EC_POINTs_make_affine(group, num_val, val, ctx))\n\t\tgoto err;\n#endif\n\tr_is_at_infinity = 1;\n\tfor (k = max_len - 1; k >= 0; k--)\n\t\t{\n\t\tif (!r_is_at_infinity)\n\t\t\t{\n\t\t\tif (!EC_POINT_dbl(group, r, r, ctx)) goto err;\n\t\t\t}\n\t\tfor (i = 0; i < totalnum; i++)\n\t\t\t{\n\t\t\tif (wNAF_len[i] > (size_t)k)\n\t\t\t\t{\n\t\t\t\tint digit = wNAF[i][k];\n\t\t\t\tint is_neg;\n\t\t\t\tif (digit)\n\t\t\t\t\t{\n\t\t\t\t\tis_neg = digit < 0;\n\t\t\t\t\tif (is_neg)\n\t\t\t\t\t\tdigit = -digit;\n\t\t\t\t\tif (is_neg != r_is_inverted)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!r_is_at_infinity)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (!EC_POINT_invert(group, r, ctx)) goto err;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tr_is_inverted = !r_is_inverted;\n\t\t\t\t\t\t}\n\t\t\t\t\tif (r_is_at_infinity)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err;\n\t\t\t\t\t\tr_is_at_infinity = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!EC_POINT_add(group, r, r, val_sub[i][digit >> 1], ctx)) goto err;\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\tif (r_is_at_infinity)\n\t\t{\n\t\tif (!EC_POINT_set_to_infinity(group, r)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (r_is_inverted)\n\t\t\tif (!EC_POINT_invert(group, r, ctx)) goto err;\n\t\t}\n\tret = 1;\n err:\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\tif (tmp != NULL)\n\t\tEC_POINT_free(tmp);\n\tif (wsize != NULL)\n\t\tOPENSSL_free(wsize);\n\tif (wNAF_len != NULL)\n\t\tOPENSSL_free(wNAF_len);\n\tif (wNAF != NULL)\n\t\t{\n\t\tsigned char **w;\n\t\tfor (w = wNAF; *w != NULL; w++)\n\t\t\tOPENSSL_free(*w);\n\t\tOPENSSL_free(wNAF);\n\t\t}\n\tif (val != NULL)\n\t\t{\n\t\tfor (v = val; *v != NULL; v++)\n\t\t\tEC_POINT_clear_free(*v);\n\t\tOPENSSL_free(val);\n\t\t}\n\tif (val_sub != NULL)\n\t\t{\n\t\tOPENSSL_free(val_sub);\n\t\t}\n\treturn ret;\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}'] |
33,028 | 0 | https://github.com/openssl/openssl/blob/97d5809c2b70fdd240990b940c564bcbd77a19c6/ssl/s3_cbc.c/#L617 | 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(\n\tconst EVP_MD_CTX *ctx,\n\tunsigned char* md_out,\n\tsize_t* md_out_size,\n\tconst unsigned char header[13],\n\tconst unsigned char *data,\n\tsize_t data_plus_mac_size,\n\tsize_t data_plus_mac_plus_padding_size,\n\tconst unsigned char *mac_secret,\n\tunsigned mac_secret_length,\n\tchar is_sslv3)\n\t{\n\tunion {\tdouble align;\n\t\tunsigned char c[sizeof(LARGEST_DIGEST_CTX)]; } md_state;\n\tvoid (*md_final_raw)(void *ctx, unsigned char *md_out);\n\tvoid (*md_transform)(void *ctx, const unsigned char *block);\n\tunsigned md_size, md_block_size = 64;\n\tunsigned sslv3_pad_length = 40, header_length, variance_blocks,\n\t\t len, max_mac_bytes, num_blocks,\n\t\t num_starting_blocks, k, mac_end_offset, c, index_a, index_b;\n\tunsigned int bits;\n\tunsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];\n\tunsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];\n\tunsigned char first_block[MAX_HASH_BLOCK_SIZE];\n\tunsigned char mac_out[EVP_MAX_MD_SIZE];\n\tunsigned i, j, md_out_size_u;\n\tEVP_MD_CTX md_ctx;\n\tunsigned md_length_size = 8;\n\tchar length_is_big_endian = 1;\n\tint ret;\n\tOPENSSL_assert(data_plus_mac_plus_padding_size < 1024*1024);\n\tswitch (EVP_MD_CTX_type(ctx))\n\t\t{\n\t\tcase NID_md5:\n\t\t\tMD5_Init((MD5_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_md5_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) MD5_Transform;\n\t\t\tmd_size = 16;\n\t\t\tsslv3_pad_length = 48;\n\t\t\tlength_is_big_endian = 0;\n\t\t\tbreak;\n\t\tcase NID_sha1:\n\t\t\tSHA1_Init((SHA_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha1_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA1_Transform;\n\t\t\tmd_size = 20;\n\t\t\tbreak;\n#ifndef OPENSSL_NO_SHA256\n\t\tcase NID_sha224:\n\t\t\tSHA224_Init((SHA256_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha256_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;\n\t\t\tmd_size = 224/8;\n\t\t\tbreak;\n\t\tcase NID_sha256:\n\t\t\tSHA256_Init((SHA256_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha256_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;\n\t\t\tmd_size = 32;\n\t\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\tcase NID_sha384:\n\t\t\tSHA384_Init((SHA512_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha512_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;\n\t\t\tmd_size = 384/8;\n\t\t\tmd_block_size = 128;\n\t\t\tmd_length_size = 16;\n\t\t\tbreak;\n\t\tcase NID_sha512:\n\t\t\tSHA512_Init((SHA512_CTX*)md_state.c);\n\t\t\tmd_final_raw = tls1_sha512_final_raw;\n\t\t\tmd_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;\n\t\t\tmd_size = 64;\n\t\t\tmd_block_size = 128;\n\t\t\tmd_length_size = 16;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tOPENSSL_assert(0);\n\t\t\tif (md_out_size)\n\t\t\t\t*md_out_size = -1;\n\t\t\treturn;\n\t\t}\n\tOPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);\n\tOPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);\n\tOPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);\n\theader_length = 13;\n\tif (is_sslv3)\n\t\t{\n\t\theader_length =\n\t\t\tmac_secret_length +\n\t\t\tsslv3_pad_length +\n\t\t\t8 +\n\t\t\t1 +\n\t\t\t2 ;\n\t\t}\n\tvariance_blocks = is_sslv3 ? 2 : 6;\n\tlen = data_plus_mac_plus_padding_size + header_length;\n\tmax_mac_bytes = len - md_size - 1;\n\tnum_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size;\n\tnum_starting_blocks = 0;\n\tk = 0;\n\tmac_end_offset = data_plus_mac_size + header_length - md_size;\n\tc = mac_end_offset % md_block_size;\n\tindex_a = mac_end_offset / md_block_size;\n\tindex_b = (mac_end_offset + md_length_size) / md_block_size;\n\tif (num_blocks > variance_blocks + (is_sslv3 ? 1 : 0))\n\t\t{\n\t\tnum_starting_blocks = num_blocks - variance_blocks;\n\t\tk = md_block_size*num_starting_blocks;\n\t\t}\n\tbits = 8*mac_end_offset;\n\tif (!is_sslv3)\n\t\t{\n\t\tbits += 8*md_block_size;\n\t\tmemset(hmac_pad, 0, md_block_size);\n\t\tOPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));\n\t\tmemcpy(hmac_pad, mac_secret, mac_secret_length);\n\t\tfor (i = 0; i < md_block_size; i++)\n\t\t\thmac_pad[i] ^= 0x36;\n\t\tmd_transform(md_state.c, hmac_pad);\n\t\t}\n\tif (length_is_big_endian)\n\t\t{\n\t\tmemset(length_bytes,0,md_length_size-4);\n\t\tlength_bytes[md_length_size-4] = (unsigned char)(bits>>24);\n\t\tlength_bytes[md_length_size-3] = (unsigned char)(bits>>16);\n\t\tlength_bytes[md_length_size-2] = (unsigned char)(bits>>8);\n\t\tlength_bytes[md_length_size-1] = (unsigned char)bits;\n\t\t}\n\telse\n\t\t{\n\t\tmemset(length_bytes,0,md_length_size);\n\t\tlength_bytes[md_length_size-5] = (unsigned char)(bits>>24);\n\t\tlength_bytes[md_length_size-6] = (unsigned char)(bits>>16);\n\t\tlength_bytes[md_length_size-7] = (unsigned char)(bits>>8);\n\t\tlength_bytes[md_length_size-8] = (unsigned char)bits;\n\t\t}\n\tif (k > 0)\n\t\t{\n\t\tif (is_sslv3)\n\t\t\t{\n\t\t\tunsigned overhang = header_length-md_block_size;\n\t\t\tmd_transform(md_state.c, header);\n\t\t\tmemcpy(first_block, header + md_block_size, overhang);\n\t\t\tmemcpy(first_block + overhang, data, md_block_size-overhang);\n\t\t\tmd_transform(md_state.c, first_block);\n\t\t\tfor (i = 1; i < k/md_block_size - 1; i++)\n\t\t\t\tmd_transform(md_state.c, data + md_block_size*i - overhang);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemcpy(first_block, header, 13);\n\t\t\tmemcpy(first_block+13, data, md_block_size-13);\n\t\t\tmd_transform(md_state.c, first_block);\n\t\t\tfor (i = 1; i < k/md_block_size; i++)\n\t\t\t\tmd_transform(md_state.c, data + md_block_size*i - 13);\n\t\t\t}\n\t\t}\n\tmemset(mac_out, 0, sizeof(mac_out));\n\tfor (i = num_starting_blocks; i <= num_starting_blocks+variance_blocks; i++)\n\t\t{\n\t\tunsigned char block[MAX_HASH_BLOCK_SIZE];\n\t\tunsigned char is_block_a = constant_time_eq_8(i, index_a);\n\t\tunsigned char is_block_b = constant_time_eq_8(i, index_b);\n\t\tfor (j = 0; j < md_block_size; j++)\n\t\t\t{\n\t\t\tunsigned char b = 0, is_past_c, is_past_cp1;\n\t\t\tif (k < header_length)\n\t\t\t\tb = header[k];\n\t\t\telse if (k < data_plus_mac_plus_padding_size + header_length)\n\t\t\t\tb = data[k-header_length];\n\t\t\tk++;\n\t\t\tis_past_c = is_block_a & constant_time_ge_8(j, c);\n\t\t\tis_past_cp1 = is_block_a & constant_time_ge_8(j, c+1);\n b = constant_time_select_8(is_past_c, 0x80, b);\n\t\t\tb = b&~is_past_cp1;\n\t\t\tb &= ~is_block_b | is_block_a;\n\t\t\tif (j >= md_block_size - md_length_size)\n\t\t\t\t{\n\t\t\t\tb = constant_time_select_8(\n\t\t\t\t\tis_block_b, length_bytes[j-(md_block_size-md_length_size)], b);\n\t\t\t\t}\n\t\t\tblock[j] = b;\n\t\t\t}\n\t\tmd_transform(md_state.c, block);\n\t\tmd_final_raw(md_state.c, block);\n\t\tfor (j = 0; j < md_size; j++)\n\t\t\tmac_out[j] |= block[j]&is_block_b;\n\t\t}\n\tEVP_MD_CTX_init(&md_ctx);\n\tEVP_DigestInit_ex(&md_ctx, ctx->digest, NULL );\n\tif (is_sslv3)\n\t\t{\n\t\tmemset(hmac_pad, 0x5c, sslv3_pad_length);\n\t\tEVP_DigestUpdate(&md_ctx, mac_secret, mac_secret_length);\n\t\tEVP_DigestUpdate(&md_ctx, hmac_pad, sslv3_pad_length);\n\t\tEVP_DigestUpdate(&md_ctx, mac_out, md_size);\n\t\t}\n\telse\n\t\t{\n\t\tfor (i = 0; i < md_block_size; i++)\n\t\t\thmac_pad[i] ^= 0x6a;\n\t\tEVP_DigestUpdate(&md_ctx, hmac_pad, md_block_size);\n\t\tEVP_DigestUpdate(&md_ctx, mac_out, md_size);\n\t\t}\n\tret = EVP_DigestFinal(&md_ctx, md_out, &md_out_size_u);\n\tif (ret && md_out_size)\n\t\t*md_out_size = md_out_size_u;\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\t}'] |
33,029 | 0 | https://github.com/libav/libav/blob/5b2a29552ca09edd4646b6aa1828b32912b7ab36/libavformat/rtsp.c/#L2069 | 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);
if (s->max_delay < 0)
s->max_delay = DEFAULT_REORDERING_DELAY;
if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)
rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;
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];
if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {
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 = ff_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 if (s->max_delay < 0)\n s->max_delay = DEFAULT_REORDERING_DELAY;\n if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)\n rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;\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 if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {\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 }\n if ((err = ff_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) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size + 32);\n if (!ptr)\n return ptr;\n diff = ((-(long)ptr - 1) & 31) + 1;\n ptr = (char *)ptr + diff;\n ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr, 32, size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32, size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}'] |
33,030 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_lib.c/#L377 | BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*B,*a;
int i,j;
bn_check_top(b);
if (words > b->max)
{
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return(NULL);
}
a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
if (A == NULL)
{
BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memset(A,0x5c,sizeof(BN_ULONG)*(words+1));
#if 1
B=b->d;
if (B != NULL)
{
for (i=b->top&(~7); i>0; i-=8)
{
A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
A+=8;
B+=8;
}
switch (b->top&7)
{
case 7:
A[6]=B[6];
case 6:
A[5]=B[5];
case 5:
A[4]=B[4];
case 4:
A[3]=B[3];
case 3:
A[2]=B[2];
case 2:
A[1]=B[1];
case 1:
A[0]=B[0];
case 0:
;
}
Free(b->d);
}
b->d=a;
b->max=words;
B= &(b->d[b->top]);
j=(b->max - b->top) & ~7;
for (i=0; i<j; i+=8)
{
B[0]=0; B[1]=0; B[2]=0; B[3]=0;
B[4]=0; B[5]=0; B[6]=0; B[7]=0;
B+=8;
}
j=(b->max - b->top) & 7;
for (i=0; i<j; i++)
{
B[0]=0;
B++;
}
#else
memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
#endif
}
return(b);
} | ['int MAIN(int argc, char **argv)\n\t{\n\tchar buffer[200];\n\tDSA *dsa=NULL;\n\tint ret=1;\n\tchar *outfile=NULL;\n\tchar *inrand=NULL,*randfile,*dsaparams=NULL;\n\tBIO *out=NULL,*in=NULL;\n\tEVP_CIPHER *enc=NULL;\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\targv++;\n\targc--;\n\tfor (;;)\n\t\t{\n\t\tif (argc <= 0) break;\n\t\tif (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-rand") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinrand= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-") == 0)\n\t\t\tgoto bad;\n\t\telse if (dsaparams == NULL)\n\t\t\t{\n\t\t\tdsaparams= *argv;\n\t\t\t}\n#ifndef NO_DES\n\t\telse if (strcmp(*argv,"-des") == 0)\n\t\t\tenc=EVP_des_cbc();\n\t\telse if (strcmp(*argv,"-des3") == 0)\n\t\t\tenc=EVP_des_ede3_cbc();\n#endif\n#ifndef NO_IDEA\n\t\telse if (strcmp(*argv,"-idea") == 0)\n\t\t\tenc=EVP_idea_cbc();\n#endif\n\t\telse\n\t\t\tgoto bad;\n\t\targv++;\n\t\targc--;\n\t\t}\n\tif (dsaparams == NULL)\n\t\t{\nbad:\n\t\tBIO_printf(bio_err,"usage: gendsa [args] dsaparam-file\\n");\n\t\tBIO_printf(bio_err," -out file - output the key to \'file\'\\n");\n#ifndef NO_DES\n\t\tBIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode\\n");\n\t\tBIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)\\n");\n#endif\n#ifndef NO_IDEA\n\t\tBIO_printf(bio_err," -idea - encrypt the generated key with IDEA in cbc mode\\n");\n#endif\n\t\tBIO_printf(bio_err," -rand file:file:...\\n");\n\t\tBIO_printf(bio_err," - load the file (or the files in the directory) into\\n");\n\t\tBIO_printf(bio_err," the random number generator\\n");\n\t\tBIO_printf(bio_err," dsaparam-file\\n");\n\t\tBIO_printf(bio_err," - a DSA parameter file as generated by the dsaparam command\\n");\n\t\tgoto end;\n\t\t}\n\tin=BIO_new(BIO_s_file());\n\tif (!(BIO_read_filename(in,dsaparams)))\n\t\t{\n\t\tperror(dsaparams);\n\t\tgoto end;\n\t\t}\n\tif ((dsa=PEM_read_bio_DSAparams(in,NULL,NULL)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to load DSA parameter file\\n");\n\t\tgoto end;\n\t\t}\n\tBIO_free(in);\n\tout=BIO_new(BIO_s_file());\n\tif (out == NULL) goto end;\n\tif (outfile == NULL)\n\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\telse\n\t\t{\n\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t{\n\t\t\tperror(outfile);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\trandfile=RAND_file_name(buffer,200);\n\tif ((randfile == NULL)|| !RAND_load_file(randfile,1024L*1024L))\n\t\tBIO_printf(bio_err,"unable to load \'random state\'\\n");\n\tif (inrand == NULL)\n\t\tBIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\\n");\n\telse\n\t\t{\n\t\tBIO_printf(bio_err,"%ld semi-random bytes loaded\\n",\n\t\t\tdsa_load_rand(inrand));\n\t\t}\n\tBIO_printf(bio_err,"Generating DSA key, %d bits\\n",\n\t\t\t\t\t\t\tBN_num_bits(dsa->p));\n\tif (!DSA_generate_key(dsa)) goto end;\n\tif (randfile == NULL)\n\t\tBIO_printf(bio_err,"unable to write \'random state\'\\n");\n\telse\n\t\tRAND_write_file(randfile);\n\tif (!PEM_write_bio_DSAPrivateKey(out,dsa,enc,NULL,0,NULL))\n\t\tgoto end;\n\tret=0;\nend:\n\tif (ret != 0)\n\t\tERR_print_errors(bio_err);\n\tif (out != NULL) BIO_free(out);\n\tif (dsa != NULL) DSA_free(dsa);\n\tEXIT(ret);\n\t}', 'int BN_num_bits(BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\ti=(a->top-1)*BN_BITS2;\n\tif (l == 0)\n\t\t{\n#if !defined(NO_STDIO) && !defined(WIN16)\n\t\tfprintf(stderr,"BAD TOP VALUE\\n");\n#endif\n\t\tabort();\n\t\t}\n\treturn(i+BN_num_bits_word(l));\n\t}', 'int DSA_generate_key(DSA *dsa)\n\t{\n\tint ok=0;\n\tunsigned int i;\n\tBN_CTX *ctx=NULL;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif (dsa->priv_key == NULL)\n\t\t{\n\t\tif ((priv_key=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tpriv_key=dsa->priv_key;\n\ti=BN_num_bits(dsa->q);\n\tfor (;;)\n\t\t{\n\t\tBN_rand(priv_key,i,1,0);\n\t\tif (BN_cmp(priv_key,dsa->q) >= 0)\n\t\t\tBN_sub(priv_key,priv_key,dsa->q);\n\t\tif (!BN_is_zero(priv_key)) break;\n\t\t}\n\tif (dsa->pub_key == NULL)\n\t\t{\n\t\tif ((pub_key=BN_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dsa->pub_key;\n\tif (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err;\n\tdsa->priv_key=priv_key;\n\tdsa->pub_key=pub_key;\n\tok=1;\nerr:\n\tif ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\treturn(ok);\n\t}', 'int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{ ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\treturn(ret);\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\taa= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_RECP_CTX_init(&recp);\n\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&val[i]);\n\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\treturn(ret);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, BIGNUM *d, BN_CTX *ctx)\n\t{\n\tBN_copy(&(recp->N),d);\n\tBN_zero(&(recp->Nr));\n\trecp->num_bits=BN_num_bits(d);\n\trecp->shift=0;\n\treturn(1);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A,*B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t{\n\t\tA[0]=B[0];\n\t\tA[1]=B[1];\n\t\tA[2]=B[2];\n\t\tA[3]=B[3];\n\t\tA[4]=B[4];\n\t\tA[5]=B[5];\n\t\tA[6]=B[6];\n\t\tA[7]=B[7];\n\t\tA+=8;\n\t\tB+=8;\n\t\t}\n\tswitch (b->top&7)\n\t\t{\n\tcase 7:\n\t\tA[6]=B[6];\n\tcase 6:\n\t\tA[5]=B[5];\n\tcase 5:\n\t\tA[4]=B[4];\n\tcase 4:\n\t\tA[3]=B[3];\n\tcase 3:\n\t\tA[2]=B[2];\n\tcase 2:\n\t\tA[1]=B[1];\n\tcase 1:\n\t\tA[0]=B[0];\n case 0:\n\t\t;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'int BN_mod_mul_reciprocal(BIGNUM *r, BIGNUM *x, BIGNUM *y, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\ta= &(ctx->bn[ctx->tos++]);\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\t}\n\telse\n\t\ta=x;\n\tBN_div_recp(NULL,r,a,recp,ctx);\n\tret=1;\nerr:\n\tctx->tos--;\n\treturn(ret);\n\t}', 'int BN_div_recp(BIGNUM *dv, BIGNUM *rem, BIGNUM *m, BN_RECP_CTX *recp,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,tos,ret=0,ex;\n\tBIGNUM *a,*b,*d,*r;\n\ttos=ctx->tos;\n\ta= &(ctx->bn[ctx->tos++]);\n\tb= &(ctx->bn[ctx->tos++]);\n\tif (dv != NULL)\n\t\td=dv;\n\telse\n\t\td= &(ctx->bn[ctx->tos++]);\n\tif (rem != NULL)\n\t\tr=rem;\n\telse\n\t\tr= &(ctx->bn[ctx->tos++]);\n\tif (BN_ucmp(m,&(recp->N)) < 0)\n\t\t{\n\t\tBN_zero(d);\n\t\tBN_copy(r,m);\n\t\tctx->tos=tos;\n\t\treturn(1);\n\t\t}\n\ti=BN_num_bits(m);\n\tj=recp->num_bits*2;\n\tif (j > i)\n\t\t{\n\t\ti=j;\n\t\tex=0;\n\t\t}\n\telse\n\t\t{\n\t\tex=(i-j)/2;\n\t\t}\n\tj=i/2;\n\tif (i != recp->shift)\n\t\trecp->shift=BN_reciprocal(&(recp->Nr),&(recp->N),\n\t\t\ti,ctx);\n\tif (!BN_rshift(a,m,j-ex)) goto err;\n\tif (!BN_mul(b,a,&(recp->Nr),ctx)) goto err;\n\tif (!BN_rshift(d,b,j+ex)) goto err;\n\td->neg=0;\n\tif (!BN_mul(b,&(recp->N),d,ctx)) goto err;\n\tif (!BN_usub(r,m,b)) goto err;\n\tr->neg=0;\n\tj=0;\n#if 1\n\twhile (BN_ucmp(r,&(recp->N)) >= 0)\n\t\t{\n\t\tif (j++ > 2)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(r,r,&(recp->N))) goto err;\n\t\tif (!BN_add_word(d,1)) goto err;\n\t\t}\n#endif\n\tr->neg=BN_is_zero(r)?0:m->neg;\n\td->neg=m->neg^recp->N.neg;\n\tret=1;\nerr:\n\tctx->tos=tos;\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', '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}'] |
33,031 | 0 | https://github.com/nginx/nginx/blob/08a73b4aadebd9405ac52ec1f6eef5ca1fe8c11a/src/http/ngx_http_core_module.c/#L2547 | 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_upgrade(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n int tcp_nodelay;\n ngx_connection_t *c;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n r->keepalive = 0;\n c->log->action = "proxying upgraded connection";\n u->read_event_handler = ngx_http_upstream_upgraded_read_upstream;\n u->write_event_handler = ngx_http_upstream_upgraded_write_upstream;\n r->read_event_handler = ngx_http_upstream_upgraded_read_downstream;\n r->write_event_handler = ngx_http_upstream_upgraded_write_downstream;\n if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");\n tcp_nodelay = 1;\n if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,\n (const void *) &tcp_nodelay, sizeof(int)) == -1)\n {\n ngx_connection_error(c, ngx_socket_errno,\n "setsockopt(TCP_NODELAY) failed");\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n c->tcp_nodelay = NGX_TCP_NODELAY_SET;\n if (setsockopt(u->peer.connection->fd, IPPROTO_TCP, TCP_NODELAY,\n (const void *) &tcp_nodelay, sizeof(int)) == -1)\n {\n ngx_connection_error(u->peer.connection, ngx_socket_errno,\n "setsockopt(TCP_NODELAY) failed");\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n u->peer.connection->tcp_nodelay = NGX_TCP_NODELAY_SET;\n }\n if (ngx_http_send_special(r, NGX_HTTP_FLUSH) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (u->peer.connection->read->ready\n || u->buffer.pos != u->buffer.last)\n {\n ngx_http_upstream_process_upgraded(r, 1);\n }\n if (c->read->ready\n || r->header_in->pos != r->header_in->last)\n {\n ngx_http_upstream_process_upgraded(r, 0);\n }\n}', 'static void\nngx_http_upstream_process_upgraded(ngx_http_request_t *r,\n ngx_uint_t from_upstream)\n{\n size_t size;\n ssize_t n;\n ngx_buf_t *b;\n ngx_uint_t do_write;\n ngx_connection_t *c, *downstream, *upstream, *dst, *src;\n ngx_http_upstream_t *u;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n u = r->upstream;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream process upgraded, fu:%ui", from_upstream);\n downstream = c;\n upstream = u->peer.connection;\n if (downstream->write->timedout) {\n c->timedout = 1;\n ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT);\n return;\n }\n if (upstream->read->timedout || upstream->write->timedout) {\n ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (from_upstream) {\n src = upstream;\n dst = downstream;\n b = &u->buffer;\n } else {\n src = downstream;\n dst = upstream;\n b = &u->from_client;\n if (r->header_in->last > r->header_in->pos) {\n b = r->header_in;\n b->end = b->last;\n do_write = 1;\n }\n if (b->start == NULL) {\n b->start = ngx_palloc(r->pool, u->conf->buffer_size);\n if (b->start == NULL) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n b->pos = b->start;\n b->last = b->start;\n b->end = b->start + u->conf->buffer_size;\n b->temporary = 1;\n b->tag = u->output.tag;\n }\n }\n for ( ;; ) {\n if (do_write) {\n size = b->last - b->pos;\n if (size && dst->write->ready) {\n n = dst->send(dst, b->pos, size);\n if (n == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (n > 0) {\n b->pos += n;\n if (b->pos == b->last) {\n b->pos = b->start;\n b->last = b->start;\n }\n }\n }\n }\n size = b->end - b->last;\n if (size && src->read->ready) {\n n = src->recv(src, b->last, size);\n if (n == NGX_AGAIN || n == 0) {\n break;\n }\n if (n > 0) {\n do_write = 1;\n b->last += n;\n continue;\n }\n if (n == NGX_ERROR) {\n src->read->eof = 1;\n }\n }\n break;\n }\n if ((upstream->read->eof && u->buffer.pos == u->buffer.last)\n || (downstream->read->eof && u->from_client.pos == u->from_client.last)\n || (downstream->read->eof && upstream->read->eof))\n {\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream upgraded done");\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (ngx_handle_write_event(upstream->write, u->conf->send_lowat)\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (upstream->write->active && !upstream->write->ready) {\n ngx_add_timer(upstream->write, u->conf->send_timeout);\n } else if (upstream->write->timer_set) {\n ngx_del_timer(upstream->write);\n }\n if (ngx_handle_read_event(upstream->read, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (upstream->read->active && !upstream->read->ready) {\n ngx_add_timer(upstream->read, u->conf->read_timeout);\n } else if (upstream->read->timer_set) {\n ngx_del_timer(upstream->read);\n }\n if (ngx_handle_write_event(downstream->write, clcf->send_lowat)\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (ngx_handle_read_event(downstream->read, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n if (downstream->write->active && !downstream->write->ready) {\n ngx_add_timer(downstream->write, clcf->send_timeout);\n } else if (downstream->write->timer_set) {\n ngx_del_timer(downstream->write);\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_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) {\n *u->cleanup = NULL;\n u->cleanup = NULL;\n }\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) {\n u->state->response_length = u->pipe->read_length;\n }\n }\n u->finalize_request(r, rc);\n if (u->peer.free) {\n u->peer.free(&u->peer, u->peer.data, 0);\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 (u->header_sent\n && rc != NGX_HTTP_REQUEST_TIME_OUT\n && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))\n {\n rc = 0;\n }\n if (rc == NGX_DECLINED) {\n return;\n }\n r->connection->log->action = "sending to client";\n if (rc == 0\n && !r->header_only\n#if (NGX_HTTP_CACHE)\n && !r->cached\n#endif\n )\n {\n rc = ngx_http_send_special(r, NGX_HTTP_LAST);\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}'] |
33,032 | 0 | https://github.com/libav/libav/blob/f40f329e9219a8dd7e585345a8ea294fa66562b9/libavcodec/mpegaudiodec.c/#L870 | void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
INTFLOAT sb_samples[SBLIMIT])
{
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
int j, offset;
OUT_INT *samples2;
#if CONFIG_FLOAT
float sum, sum2;
#elif 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 && !CONFIG_FLOAT
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(*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;
offset = (offset - 32) & 511;
*synth_buf_offset = offset;
} | ['static int decode_frame_mp3on4(AVCodecContext * avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MP3On4DecodeContext *s = avctx->priv_data;\n MPADecodeContext *m;\n int fsize, len = buf_size, out_size = 0;\n uint32_t header;\n OUT_INT *out_samples = data;\n OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS];\n OUT_INT *outptr, *bp;\n int fr, j, n;\n if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT))\n return -1;\n *data_size = 0;\n if (buf_size < HEADER_SIZE)\n return -1;\n outptr = s->frames == 1 ? out_samples : decoded_buf;\n avctx->bit_rate = 0;\n for (fr = 0; fr < s->frames; fr++) {\n fsize = AV_RB16(buf) >> 4;\n fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE);\n m = s->mp3decctx[fr];\n assert (m != NULL);\n header = (AV_RB32(buf) & 0x000fffff) | s->syncword;\n if (ff_mpa_check_header(header) < 0)\n break;\n ff_mpegaudio_decode_header((MPADecodeHeader *)m, header);\n out_size += mp_decode_frame(m, outptr, buf, fsize);\n buf += fsize;\n len -= fsize;\n if(s->frames > 1) {\n n = m->avctx->frame_size*m->nb_channels;\n bp = out_samples + s->coff[fr];\n if(m->nb_channels == 1) {\n for(j = 0; j < n; j++) {\n *bp = decoded_buf[j];\n bp += avctx->channels;\n }\n } else {\n for(j = 0; j < n; j++) {\n bp[0] = decoded_buf[j++];\n bp[1] = decoded_buf[j];\n bp += avctx->channels;\n }\n }\n }\n avctx->bit_rate += m->bit_rate;\n }\n avctx->sample_rate = s->mp3decctx[0]->sample_rate;\n *data_size = out_size;\n return buf_size;\n}', 'static av_always_inline av_const uint32_t bswap_32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\n}', 'int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)\n{\n int sample_rate, frame_size, mpeg25, padding;\n int sample_rate_index, bitrate_index;\n if (header & (1<<20)) {\n s->lsf = (header & (1<<19)) ? 0 : 1;\n mpeg25 = 0;\n } else {\n s->lsf = 1;\n mpeg25 = 1;\n }\n s->layer = 4 - ((header >> 17) & 3);\n sample_rate_index = (header >> 10) & 3;\n sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);\n sample_rate_index += 3 * (s->lsf + mpeg25);\n s->sample_rate_index = sample_rate_index;\n s->error_protection = ((header >> 16) & 1) ^ 1;\n s->sample_rate = sample_rate;\n bitrate_index = (header >> 12) & 0xf;\n padding = (header >> 9) & 1;\n s->mode = (header >> 6) & 3;\n s->mode_ext = (header >> 4) & 3;\n if (s->mode == MPA_MONO)\n s->nb_channels = 1;\n else\n s->nb_channels = 2;\n if (bitrate_index != 0) {\n frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];\n s->bit_rate = frame_size * 1000;\n switch(s->layer) {\n case 1:\n frame_size = (frame_size * 12000) / sample_rate;\n frame_size = (frame_size + padding) * 4;\n break;\n case 2:\n frame_size = (frame_size * 144000) / sample_rate;\n frame_size += padding;\n break;\n default:\n case 3:\n frame_size = (frame_size * 144000) / (sample_rate << s->lsf);\n frame_size += padding;\n break;\n }\n s->frame_size = frame_size;\n } else {\n return 1;\n }\n#if defined(DEBUG)\n dprintf(NULL, "layer%d, %d Hz, %d kbits/s, ",\n s->layer, s->sample_rate, s->bit_rate);\n if (s->nb_channels == 2) {\n if (s->layer == 3) {\n if (s->mode_ext & MODE_EXT_MS_STEREO)\n dprintf(NULL, "ms-");\n if (s->mode_ext & MODE_EXT_I_STEREO)\n dprintf(NULL, "i-");\n }\n dprintf(NULL, "stereo");\n } else {\n dprintf(NULL, "mono");\n }\n dprintf(NULL, "\\n");\n#endif\n return 0;\n}', 'static int mp_decode_frame(MPADecodeContext *s,\n OUT_INT *samples, const uint8_t *buf, int buf_size)\n{\n int i, nb_frames, ch;\n OUT_INT *samples_ptr;\n init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8);\n if (s->error_protection)\n skip_bits(&s->gb, 16);\n dprintf(s->avctx, "frame %d:\\n", s->frame_count);\n switch(s->layer) {\n case 1:\n s->avctx->frame_size = 384;\n nb_frames = mp_decode_layer1(s);\n break;\n case 2:\n s->avctx->frame_size = 1152;\n nb_frames = mp_decode_layer2(s);\n break;\n case 3:\n s->avctx->frame_size = s->lsf ? 576 : 1152;\n default:\n nb_frames = mp_decode_layer3(s);\n s->last_buf_size=0;\n if(s->in_gb.buffer){\n align_get_bits(&s->gb);\n i= get_bits_left(&s->gb)>>3;\n if(i >= 0 && i <= BACKSTEP_SIZE){\n memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i);\n s->last_buf_size=i;\n }else\n av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\\n", i);\n s->gb= s->in_gb;\n s->in_gb.buffer= NULL;\n }\n align_get_bits(&s->gb);\n assert((get_bits_count(&s->gb) & 7) == 0);\n i= get_bits_left(&s->gb)>>3;\n if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){\n if(i<0)\n av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\\n", i);\n i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE);\n }\n assert(i <= buf_size - HEADER_SIZE && i>= 0);\n memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i);\n s->last_buf_size += i;\n break;\n }\n for(ch=0;ch<s->nb_channels;ch++) {\n samples_ptr = samples + ch;\n for(i=0;i<nb_frames;i++) {\n RENAME(ff_mpa_synth_filter)(s->synth_buf[ch], &(s->synth_buf_offset[ch]),\n RENAME(ff_mpa_synth_window), &s->dither_state,\n samples_ptr, s->nb_channels,\n s->sb_samples[ch][i]);\n samples_ptr += 32 * s->nb_channels;\n }\n }\n return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;\n}', 'void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}'] |
33,033 | 0 | https://github.com/openssl/openssl/blob/daea0ff8a960237e0f9a71301721824c25ad3b25/crypto/objects/obj_dat.c/#L489 | int OBJ_obj2txt(char *buf, int buf_len, 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);
}
nid=OBJ_obj2nid(a);
if ((nid == NID_undef) || no_name) {
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 OBJ_obj2txt(char *buf, int buf_len, 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\tnid=OBJ_obj2nid(a);\n\tif ((nid == NID_undef) || no_name) {\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}', 'int OBJ_obj2nid(ASN1_OBJECT *a)\n\t{\n\tASN1_OBJECT **op;\n\tADDED_OBJ ad,*adp;\n\tif (a == NULL)\n\t\treturn(NID_undef);\n\tif (a->nid != 0)\n\t\treturn(a->nid);\n\tif (added != NULL)\n\t\t{\n\t\tad.type=ADDED_DATA;\n\t\tad.obj=a;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&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}', 'const char *OBJ_nid2ln(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn(nid_objs[n].ln);\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj->ln);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2LN,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void CRYPTO_free(void *str)\n\t{\n\tif (free_debug_func != NULL)\n\t\tfree_debug_func(str, 0);\n#ifdef LEVITTE_DEBUG\n\tfprintf(stderr, "LEVITTE_DEBUG: < 0x%p\\n", str);\n#endif\n\tfree_func(str);\n\tif (free_debug_func != NULL)\n\t\tfree_debug_func(NULL, 1);\n\t}', 'const char *OBJ_nid2sn(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn(nid_objs[n].sn);\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj->sn);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2SN,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}'] |
33,034 | 0 | https://github.com/libav/libav/blob/a7da517f6a5c472f46f67dd33bb6b95ccc919923/libavutil/des.c/#L257 | static void gen_roundkeys(uint64_t K[16], uint64_t key)
{
int i;
uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle));
for (i = 0; i < 16; i++) {
CDn = key_shift_left(CDn);
if (i > 1 && i != 8 && i != 15)
CDn = key_shift_left(CDn);
K[i] = shuffle(CDn, PC2_shuffle, sizeof(PC2_shuffle));
}
} | ['int av_des_init(AVDES *d, const uint8_t *key, int key_bits, int decrypt)\n{\n if (key_bits != 64 && key_bits != 192)\n return -1;\n d->triple_des = key_bits > 64;\n gen_roundkeys(d->round_keys[0], AV_RB64(key));\n if (d->triple_des) {\n gen_roundkeys(d->round_keys[1], AV_RB64(key + 8));\n gen_roundkeys(d->round_keys[2], AV_RB64(key + 16));\n }\n return 0;\n}', 'static void gen_roundkeys(uint64_t K[16], uint64_t key)\n{\n int i;\n uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle));\n for (i = 0; i < 16; i++) {\n CDn = key_shift_left(CDn);\n if (i > 1 && i != 8 && i != 15)\n CDn = key_shift_left(CDn);\n K[i] = shuffle(CDn, PC2_shuffle, sizeof(PC2_shuffle));\n }\n}'] |
33,035 | 0 | https://github.com/libav/libav/blob/b12b16c5d35adaba0979a7c2fa76b88e48f5f839/libavcodec/mlpdec.c/#L990 | static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MLPDecodeContext *m = avctx->priv_data;
GetBitContext gb;
unsigned int length, substr;
unsigned int substream_start;
unsigned int header_size = 4;
unsigned int substr_header_size = 0;
uint8_t substream_parity_present[MAX_SUBSTREAMS];
uint16_t substream_data_len[MAX_SUBSTREAMS];
uint8_t parity_bits;
if (buf_size < 4)
return 0;
length = (AV_RB16(buf) & 0xfff) * 2;
if (length < 4 || length > buf_size)
return -1;
init_get_bits(&gb, (buf + 4), (length - 4) * 8);
m->is_major_sync_unit = 0;
if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
if (read_major_sync(m, &gb) < 0)
goto error;
m->is_major_sync_unit = 1;
header_size += 28;
}
if (!m->params_valid) {
av_log(m->avctx, AV_LOG_WARNING,
"Stream parameters not seen; skipping frame.\n");
*data_size = 0;
return length;
}
substream_start = 0;
for (substr = 0; substr < m->num_substreams; substr++) {
int extraword_present, checkdata_present, end, nonrestart_substr;
extraword_present = get_bits1(&gb);
nonrestart_substr = get_bits1(&gb);
checkdata_present = get_bits1(&gb);
skip_bits1(&gb);
end = get_bits(&gb, 12) * 2;
substr_header_size += 2;
if (extraword_present) {
if (m->avctx->codec_id == CODEC_ID_MLP) {
av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n");
goto error;
}
skip_bits(&gb, 16);
substr_header_size += 2;
}
if (!(nonrestart_substr ^ m->is_major_sync_unit)) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n");
goto error;
}
if (end + header_size + substr_header_size > length) {
av_log(m->avctx, AV_LOG_ERROR,
"Indicated length of substream %d data goes off end of "
"packet.\n", substr);
end = length - header_size - substr_header_size;
}
if (end < substream_start) {
av_log(avctx, AV_LOG_ERROR,
"Indicated end offset of substream %d data "
"is smaller than calculated start offset.\n",
substr);
goto error;
}
if (substr > m->max_decoded_substream)
continue;
substream_parity_present[substr] = checkdata_present;
substream_data_len[substr] = end - substream_start;
substream_start = end;
}
parity_bits = ff_mlp_calculate_parity(buf, 4);
parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);
if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n");
goto error;
}
buf += header_size + substr_header_size;
for (substr = 0; substr <= m->max_decoded_substream; substr++) {
SubStream *s = &m->substream[substr];
init_get_bits(&gb, buf, substream_data_len[substr] * 8);
m->matrix_changed = 0;
memset(m->filter_changed, 0, sizeof(m->filter_changed));
s->blockpos = 0;
do {
if (get_bits1(&gb)) {
if (get_bits1(&gb)) {
if (read_restart_header(m, &gb, buf, substr) < 0)
goto next_substr;
s->restart_seen = 1;
}
if (!s->restart_seen)
goto next_substr;
if (read_decoding_params(m, &gb, substr) < 0)
goto next_substr;
}
if (!s->restart_seen)
goto next_substr;
if (read_block_data(m, &gb, substr) < 0)
return -1;
if (get_bits_count(&gb) >= substream_data_len[substr] * 8)
goto substream_length_mismatch;
} while (!get_bits1(&gb));
skip_bits(&gb, (-get_bits_count(&gb)) & 15);
if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {
int shorten_by;
if (get_bits(&gb, 16) != 0xD234)
return -1;
shorten_by = get_bits(&gb, 16);
if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)
s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);
else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)
return -1;
if (substr == m->max_decoded_substream)
av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
}
if (substream_parity_present[substr]) {
uint8_t parity, checksum;
if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)
goto substream_length_mismatch;
parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);
checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);
if ((get_bits(&gb, 8) ^ parity) != 0xa9 )
av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr);
if ( get_bits(&gb, 8) != checksum)
av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n" , substr);
}
if (substream_data_len[substr] * 8 != get_bits_count(&gb))
goto substream_length_mismatch;
next_substr:
if (!s->restart_seen)
av_log(m->avctx, AV_LOG_ERROR,
"No restart header present in substream %d.\n", substr);
buf += substream_data_len[substr];
}
rematrix_channels(m, m->max_decoded_substream);
if (output_data(m, m->max_decoded_substream, data, data_size) < 0)
return -1;
return length;
substream_length_mismatch:
av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr);
return -1;
error:
m->params_valid = 0;
return -1;
} | ['static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MLPDecodeContext *m = avctx->priv_data;\n GetBitContext gb;\n unsigned int length, substr;\n unsigned int substream_start;\n unsigned int header_size = 4;\n unsigned int substr_header_size = 0;\n uint8_t substream_parity_present[MAX_SUBSTREAMS];\n uint16_t substream_data_len[MAX_SUBSTREAMS];\n uint8_t parity_bits;\n if (buf_size < 4)\n return 0;\n length = (AV_RB16(buf) & 0xfff) * 2;\n if (length < 4 || length > buf_size)\n return -1;\n init_get_bits(&gb, (buf + 4), (length - 4) * 8);\n m->is_major_sync_unit = 0;\n if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {\n if (read_major_sync(m, &gb) < 0)\n goto error;\n m->is_major_sync_unit = 1;\n header_size += 28;\n }\n if (!m->params_valid) {\n av_log(m->avctx, AV_LOG_WARNING,\n "Stream parameters not seen; skipping frame.\\n");\n *data_size = 0;\n return length;\n }\n substream_start = 0;\n for (substr = 0; substr < m->num_substreams; substr++) {\n int extraword_present, checkdata_present, end, nonrestart_substr;\n extraword_present = get_bits1(&gb);\n nonrestart_substr = get_bits1(&gb);\n checkdata_present = get_bits1(&gb);\n skip_bits1(&gb);\n end = get_bits(&gb, 12) * 2;\n substr_header_size += 2;\n if (extraword_present) {\n if (m->avctx->codec_id == CODEC_ID_MLP) {\n av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\\n");\n goto error;\n }\n skip_bits(&gb, 16);\n substr_header_size += 2;\n }\n if (!(nonrestart_substr ^ m->is_major_sync_unit)) {\n av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\\n");\n goto error;\n }\n if (end + header_size + substr_header_size > length) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Indicated length of substream %d data goes off end of "\n "packet.\\n", substr);\n end = length - header_size - substr_header_size;\n }\n if (end < substream_start) {\n av_log(avctx, AV_LOG_ERROR,\n "Indicated end offset of substream %d data "\n "is smaller than calculated start offset.\\n",\n substr);\n goto error;\n }\n if (substr > m->max_decoded_substream)\n continue;\n substream_parity_present[substr] = checkdata_present;\n substream_data_len[substr] = end - substream_start;\n substream_start = end;\n }\n parity_bits = ff_mlp_calculate_parity(buf, 4);\n parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);\n if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n goto error;\n }\n buf += header_size + substr_header_size;\n for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n SubStream *s = &m->substream[substr];\n init_get_bits(&gb, buf, substream_data_len[substr] * 8);\n m->matrix_changed = 0;\n memset(m->filter_changed, 0, sizeof(m->filter_changed));\n s->blockpos = 0;\n do {\n if (get_bits1(&gb)) {\n if (get_bits1(&gb)) {\n if (read_restart_header(m, &gb, buf, substr) < 0)\n goto next_substr;\n s->restart_seen = 1;\n }\n if (!s->restart_seen)\n goto next_substr;\n if (read_decoding_params(m, &gb, substr) < 0)\n goto next_substr;\n }\n if (!s->restart_seen)\n goto next_substr;\n if (read_block_data(m, &gb, substr) < 0)\n return -1;\n if (get_bits_count(&gb) >= substream_data_len[substr] * 8)\n goto substream_length_mismatch;\n } while (!get_bits1(&gb));\n skip_bits(&gb, (-get_bits_count(&gb)) & 15);\n if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {\n int shorten_by;\n if (get_bits(&gb, 16) != 0xD234)\n return -1;\n shorten_by = get_bits(&gb, 16);\n if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)\n s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);\n else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)\n return -1;\n if (substr == m->max_decoded_substream)\n av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n }\n if (substream_parity_present[substr]) {\n uint8_t parity, checksum;\n if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)\n goto substream_length_mismatch;\n parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);\n checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);\n if ((get_bits(&gb, 8) ^ parity) != 0xa9 )\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\\n", substr);\n if ( get_bits(&gb, 8) != checksum)\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n" , substr);\n }\n if (substream_data_len[substr] * 8 != get_bits_count(&gb))\n goto substream_length_mismatch;\nnext_substr:\n if (!s->restart_seen)\n av_log(m->avctx, AV_LOG_ERROR,\n "No restart header present in substream %d.\\n", substr);\n buf += substream_data_len[substr];\n }\n rematrix_channels(m, m->max_decoded_substream);\n if (output_data(m, m->max_decoded_substream, data, data_size) < 0)\n return -1;\n return length;\nsubstream_length_mismatch:\n av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n", substr);\n return -1;\nerror:\n m->params_valid = 0;\n return -1;\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n x= (x>>8) | (x<<8);\n return x;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int show_bits_long(GetBitContext *s, int n){\n if(n<=MIN_CACHE_BITS) return show_bits(s, n);\n else{\n GetBitContext gb= *s;\n return get_bits_long(&gb, n);\n }\n}', 'static inline unsigned int get_bits_long(GetBitContext *s, int n){\n if(n<=MIN_CACHE_BITS) return get_bits(s, n);\n else{\n#ifdef ALT_BITSTREAM_READER_LE\n int ret= get_bits(s, 16);\n return ret | (get_bits(s, n-16) << 16);\n#else\n int ret= get_bits(s, 16) << (n-16);\n return ret | get_bits(s, n-16);\n#endif\n }\n}', 'static inline unsigned int get_bits(GetBitContext *s, int n){\n register int tmp;\n OPEN_READER(re, s)\n UPDATE_CACHE(re, s)\n tmp= SHOW_UBITS(re, s, n);\n LAST_SKIP_BITS(re, s, n)\n CLOSE_READER(re, s)\n return tmp;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}'] |
33,036 | 0 | https://github.com/openssl/openssl/blob/4dfc8f1f0b3ff85adfdca3a37be5df7928092f07/apps/speed.c/#L1646 | int MAIN(int argc, char **argv)
{
#ifndef OPENSSL_NO_ENGINE
ENGINE *e = NULL;
#endif
unsigned char *buf=NULL,*buf2=NULL;
int mret=1;
long count=0,save_count=0;
int i,j,k;
#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
long rsa_count;
#endif
#ifndef OPENSSL_NO_RSA
unsigned rsa_num;
#endif
unsigned char md[EVP_MAX_MD_SIZE];
#ifndef OPENSSL_NO_MD2
unsigned char md2[MD2_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_MDC2
unsigned char mdc2[MDC2_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_MD4
unsigned char md4[MD4_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_MD5
unsigned char md5[MD5_DIGEST_LENGTH];
unsigned char hmac[MD5_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_SHA
unsigned char sha[SHA_DIGEST_LENGTH];
#ifndef OPENSSL_NO_SHA256
unsigned char sha256[SHA256_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_SHA512
unsigned char sha512[SHA512_DIGEST_LENGTH];
#endif
#endif
#ifndef OPENSSL_NO_RIPEMD
unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_RC4
RC4_KEY rc4_ks;
#endif
#ifndef OPENSSL_NO_RC5
RC5_32_KEY rc5_ks;
#endif
#ifndef OPENSSL_NO_RC2
RC2_KEY rc2_ks;
#endif
#ifndef OPENSSL_NO_IDEA
IDEA_KEY_SCHEDULE idea_ks;
#endif
#ifndef OPENSSL_NO_BF
BF_KEY bf_ks;
#endif
#ifndef OPENSSL_NO_CAST
CAST_KEY cast_ks;
#endif
static const unsigned char key16[16]=
{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
#ifndef OPENSSL_NO_AES
static const unsigned char key24[24]=
{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
static const unsigned char key32[32]=
{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
#endif
#ifndef OPENSSL_NO_CAMELLIA
static const unsigned char ckey24[24]=
{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
static const unsigned char ckey32[32]=
{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,
0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,
0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};
#endif
#ifndef OPENSSL_NO_AES
#define MAX_BLOCK_SIZE 128
#else
#define MAX_BLOCK_SIZE 64
#endif
unsigned char DES_iv[8];
unsigned char iv[MAX_BLOCK_SIZE/8];
#ifndef OPENSSL_NO_DES
DES_cblock *buf_as_des_cblock = NULL;
static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
DES_key_schedule sch;
DES_key_schedule sch2;
DES_key_schedule sch3;
#endif
#ifndef OPENSSL_NO_AES
AES_KEY aes_ks1, aes_ks2, aes_ks3;
#endif
#ifndef OPENSSL_NO_CAMELLIA
CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
#endif
#define D_MD2 0
#define D_MDC2 1
#define D_MD4 2
#define D_MD5 3
#define D_HMAC 4
#define D_SHA1 5
#define D_RMD160 6
#define D_RC4 7
#define D_CBC_DES 8
#define D_EDE3_DES 9
#define D_CBC_IDEA 10
#define D_CBC_RC2 11
#define D_CBC_RC5 12
#define D_CBC_BF 13
#define D_CBC_CAST 14
#define D_CBC_128_AES 15
#define D_CBC_192_AES 16
#define D_CBC_256_AES 17
#define D_CBC_128_CML 18
#define D_CBC_192_CML 19
#define D_CBC_256_CML 20
#define D_EVP 21
#define D_SHA256 22
#define D_SHA512 23
double d=0.0;
long c[ALGOR_NUM][SIZE_NUM];
#define R_DSA_512 0
#define R_DSA_1024 1
#define R_DSA_2048 2
#define R_RSA_512 0
#define R_RSA_1024 1
#define R_RSA_2048 2
#define R_RSA_4096 3
#define R_EC_P160 0
#define R_EC_P192 1
#define R_EC_P224 2
#define R_EC_P256 3
#define R_EC_P384 4
#define R_EC_P521 5
#define R_EC_K163 6
#define R_EC_K233 7
#define R_EC_K283 8
#define R_EC_K409 9
#define R_EC_K571 10
#define R_EC_B163 11
#define R_EC_B233 12
#define R_EC_B283 13
#define R_EC_B409 14
#define R_EC_B571 15
#ifndef OPENSSL_NO_RSA
RSA *rsa_key[RSA_NUM];
long rsa_c[RSA_NUM][2];
static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
static unsigned char *rsa_data[RSA_NUM]=
{test512,test1024,test2048,test4096};
static int rsa_data_length[RSA_NUM]={
sizeof(test512),sizeof(test1024),
sizeof(test2048),sizeof(test4096)};
#endif
#ifndef OPENSSL_NO_DSA
DSA *dsa_key[DSA_NUM];
long dsa_c[DSA_NUM][2];
static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
#endif
#ifndef OPENSSL_NO_EC
static unsigned int test_curves[EC_NUM] =
{
NID_secp160r1,
NID_X9_62_prime192v1,
NID_secp224r1,
NID_X9_62_prime256v1,
NID_secp384r1,
NID_secp521r1,
NID_sect163k1,
NID_sect233k1,
NID_sect283k1,
NID_sect409k1,
NID_sect571k1,
NID_sect163r2,
NID_sect233r1,
NID_sect283r1,
NID_sect409r1,
NID_sect571r1
};
static const char * test_curves_names[EC_NUM] =
{
"secp160r1",
"nistp192",
"nistp224",
"nistp256",
"nistp384",
"nistp521",
"nistk163",
"nistk233",
"nistk283",
"nistk409",
"nistk571",
"nistb163",
"nistb233",
"nistb283",
"nistb409",
"nistb571"
};
static int test_curves_bits[EC_NUM] =
{
160, 192, 224, 256, 384, 521,
163, 233, 283, 409, 571,
163, 233, 283, 409, 571
};
#endif
#ifndef OPENSSL_NO_ECDSA
unsigned char ecdsasig[256];
unsigned int ecdsasiglen;
EC_KEY *ecdsa[EC_NUM];
long ecdsa_c[EC_NUM][2];
#endif
#ifndef OPENSSL_NO_ECDH
EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
int secret_size_a, secret_size_b;
int ecdh_checks = 0;
int secret_idx = 0;
long ecdh_c[EC_NUM][2];
#endif
int rsa_doit[RSA_NUM];
int dsa_doit[DSA_NUM];
#ifndef OPENSSL_NO_ECDSA
int ecdsa_doit[EC_NUM];
#endif
#ifndef OPENSSL_NO_ECDH
int ecdh_doit[EC_NUM];
#endif
int doit[ALGOR_NUM];
int pr_header=0;
const EVP_CIPHER *evp_cipher=NULL;
const EVP_MD *evp_md=NULL;
int decrypt=0;
#ifdef HAVE_FORK
int multi=0;
#endif
#ifndef TIMES
usertime=-1;
#endif
apps_startup();
memset(results, 0, sizeof(results));
#ifndef OPENSSL_NO_DSA
memset(dsa_key,0,sizeof(dsa_key));
#endif
#ifndef OPENSSL_NO_ECDSA
for (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;
#endif
#ifndef OPENSSL_NO_ECDH
for (i=0; i<EC_NUM; i++)
{
ecdh_a[i] = NULL;
ecdh_b[i] = NULL;
}
#endif
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;
#ifndef OPENSSL_NO_RSA
memset(rsa_key,0,sizeof(rsa_key));
for (i=0; i<RSA_NUM; i++)
rsa_key[i]=NULL;
#endif
if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
{
BIO_printf(bio_err,"out of memory\n");
goto end;
}
#ifndef OPENSSL_NO_DES
buf_as_des_cblock = (DES_cblock *)buf;
#endif
if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
{
BIO_printf(bio_err,"out of memory\n");
goto end;
}
memset(c,0,sizeof(c));
memset(DES_iv,0,sizeof(DES_iv));
memset(iv,0,sizeof(iv));
for (i=0; i<ALGOR_NUM; i++)
doit[i]=0;
for (i=0; i<RSA_NUM; i++)
rsa_doit[i]=0;
for (i=0; i<DSA_NUM; i++)
dsa_doit[i]=0;
#ifndef OPENSSL_NO_ECDSA
for (i=0; i<EC_NUM; i++)
ecdsa_doit[i]=0;
#endif
#ifndef OPENSSL_NO_ECDH
for (i=0; i<EC_NUM; i++)
ecdh_doit[i]=0;
#endif
j=0;
argc--;
argv++;
while (argc)
{
if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
{
usertime = 0;
j--;
}
else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
{
argc--;
argv++;
if(argc == 0)
{
BIO_printf(bio_err,"no EVP given\n");
goto end;
}
evp_cipher=EVP_get_cipherbyname(*argv);
if(!evp_cipher)
{
evp_md=EVP_get_digestbyname(*argv);
}
if(!evp_cipher && !evp_md)
{
BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
goto end;
}
doit[D_EVP]=1;
}
else if (argc > 0 && !strcmp(*argv,"-decrypt"))
{
decrypt=1;
j--;
}
#ifndef OPENSSL_NO_ENGINE
else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
{
argc--;
argv++;
if(argc == 0)
{
BIO_printf(bio_err,"no engine given\n");
goto end;
}
e = setup_engine(bio_err, *argv, 0);
j--;
}
#endif
#ifdef HAVE_FORK
else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
{
argc--;
argv++;
if(argc == 0)
{
BIO_printf(bio_err,"no multi count given\n");
goto end;
}
multi=atoi(argv[0]);
if(multi <= 0)
{
BIO_printf(bio_err,"bad multi count\n");
goto end;
}
j--;
}
#endif
else if (argc > 0 && !strcmp(*argv,"-mr"))
{
mr=1;
j--;
}
else
#ifndef OPENSSL_NO_MD2
if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
else
#endif
#ifndef OPENSSL_NO_MDC2
if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
else
#endif
#ifndef OPENSSL_NO_MD4
if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
else
#endif
#ifndef OPENSSL_NO_MD5
if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
else
#endif
#ifndef OPENSSL_NO_MD5
if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
else
#endif
#ifndef OPENSSL_NO_SHA
if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
else
if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1,
doit[D_SHA256]=1,
doit[D_SHA512]=1;
else
#ifndef OPENSSL_NO_SHA256
if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
else
#endif
#ifndef OPENSSL_NO_SHA512
if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
else
#endif
#endif
#ifndef OPENSSL_NO_RIPEMD
if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
else
if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
else
if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
else
#endif
#ifndef OPENSSL_NO_RC4
if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
else
#endif
#ifndef OPENSSL_NO_DES
if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
else
#endif
#ifndef OPENSSL_NO_AES
if (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;
else if (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;
else if (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;
else
#endif
#ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;
else if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;
else if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;
else
#endif
#ifndef OPENSSL_NO_RSA
#if 0
if (strcmp(*argv,"rsaref") == 0)
{
RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
j--;
}
else
#endif
#ifndef RSA_NULL
if (strcmp(*argv,"openssl") == 0)
{
RSA_set_default_method(RSA_PKCS1_SSLeay());
j--;
}
else
#endif
#endif
if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
else
#ifndef OPENSSL_NO_RC2
if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
else
#endif
#ifndef OPENSSL_NO_RC5
if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
else
#endif
#ifndef OPENSSL_NO_IDEA
if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
else
#endif
#ifndef OPENSSL_NO_BF
if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
else
#endif
#ifndef OPENSSL_NO_CAST
if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
else
#endif
#ifndef OPENSSL_NO_DES
if (strcmp(*argv,"des") == 0)
{
doit[D_CBC_DES]=1;
doit[D_EDE3_DES]=1;
}
else
#endif
#ifndef OPENSSL_NO_AES
if (strcmp(*argv,"aes") == 0)
{
doit[D_CBC_128_AES]=1;
doit[D_CBC_192_AES]=1;
doit[D_CBC_256_AES]=1;
}
else
#endif
#ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv,"camellia") == 0)
{
doit[D_CBC_128_CML]=1;
doit[D_CBC_192_CML]=1;
doit[D_CBC_256_CML]=1;
}
else
#endif
#ifndef OPENSSL_NO_RSA
if (strcmp(*argv,"rsa") == 0)
{
rsa_doit[R_RSA_512]=1;
rsa_doit[R_RSA_1024]=1;
rsa_doit[R_RSA_2048]=1;
rsa_doit[R_RSA_4096]=1;
}
else
#endif
#ifndef OPENSSL_NO_DSA
if (strcmp(*argv,"dsa") == 0)
{
dsa_doit[R_DSA_512]=1;
dsa_doit[R_DSA_1024]=1;
dsa_doit[R_DSA_2048]=1;
}
else
#endif
#ifndef OPENSSL_NO_ECDSA
if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;
else if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;
else if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;
else if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;
else if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;
else if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;
else if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;
else if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;
else if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;
else if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;
else if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;
else if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;
else if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;
else if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;
else if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;
else if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;
else if (strcmp(*argv,"ecdsa") == 0)
{
for (i=0; i < EC_NUM; i++)
ecdsa_doit[i]=1;
}
else
#endif
#ifndef OPENSSL_NO_ECDH
if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;
else if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;
else if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;
else if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;
else if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;
else if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;
else if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;
else if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;
else if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;
else if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;
else if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;
else if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;
else if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;
else if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;
else if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;
else if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;
else if (strcmp(*argv,"ecdh") == 0)
{
for (i=0; i < EC_NUM; i++)
ecdh_doit[i]=1;
}
else
#endif
{
BIO_printf(bio_err,"Error: bad option or value\n");
BIO_printf(bio_err,"\n");
BIO_printf(bio_err,"Available values:\n");
#ifndef OPENSSL_NO_MD2
BIO_printf(bio_err,"md2 ");
#endif
#ifndef OPENSSL_NO_MDC2
BIO_printf(bio_err,"mdc2 ");
#endif
#ifndef OPENSSL_NO_MD4
BIO_printf(bio_err,"md4 ");
#endif
#ifndef OPENSSL_NO_MD5
BIO_printf(bio_err,"md5 ");
#ifndef OPENSSL_NO_HMAC
BIO_printf(bio_err,"hmac ");
#endif
#endif
#ifndef OPENSSL_NO_SHA1
BIO_printf(bio_err,"sha1 ");
#endif
#ifndef OPENSSL_NO_SHA256
BIO_printf(bio_err,"sha256 ");
#endif
#ifndef OPENSSL_NO_SHA512
BIO_printf(bio_err,"sha512 ");
#endif
#ifndef OPENSSL_NO_RIPEMD160
BIO_printf(bio_err,"rmd160");
#endif
#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
!defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
!defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
BIO_printf(bio_err,"\n");
#endif
#ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err,"idea-cbc ");
#endif
#ifndef OPENSSL_NO_RC2
BIO_printf(bio_err,"rc2-cbc ");
#endif
#ifndef OPENSSL_NO_RC5
BIO_printf(bio_err,"rc5-cbc ");
#endif
#ifndef OPENSSL_NO_BF
BIO_printf(bio_err,"bf-cbc");
#endif
#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
!defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
BIO_printf(bio_err,"\n");
#endif
#ifndef OPENSSL_NO_DES
BIO_printf(bio_err,"des-cbc des-ede3 ");
#endif
#ifndef OPENSSL_NO_AES
BIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");
#endif
#ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err,"\n");
BIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
#endif
#ifndef OPENSSL_NO_RC4
BIO_printf(bio_err,"rc4");
#endif
BIO_printf(bio_err,"\n");
#ifndef OPENSSL_NO_RSA
BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
#endif
#ifndef OPENSSL_NO_DSA
BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
#endif
#ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\n");
BIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
BIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
BIO_printf(bio_err,"ecdsa\n");
#endif
#ifndef OPENSSL_NO_ECDH
BIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\n");
BIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
BIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
BIO_printf(bio_err,"ecdh\n");
#endif
#ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err,"idea ");
#endif
#ifndef OPENSSL_NO_RC2
BIO_printf(bio_err,"rc2 ");
#endif
#ifndef OPENSSL_NO_DES
BIO_printf(bio_err,"des ");
#endif
#ifndef OPENSSL_NO_AES
BIO_printf(bio_err,"aes ");
#endif
#ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err,"camellia ");
#endif
#ifndef OPENSSL_NO_RSA
BIO_printf(bio_err,"rsa ");
#endif
#ifndef OPENSSL_NO_BF
BIO_printf(bio_err,"blowfish");
#endif
#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
!defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
!defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES) || \
!defined(OPENSSL_NO_CAMELLIA)
BIO_printf(bio_err,"\n");
#endif
BIO_printf(bio_err,"\n");
BIO_printf(bio_err,"Available options:\n");
#if defined(TIMES) || defined(USE_TOD)
BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
#endif
#ifndef OPENSSL_NO_ENGINE
BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
#endif
BIO_printf(bio_err,"-evp e use EVP e.\n");
BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
BIO_printf(bio_err,"-mr produce machine readable output.\n");
#ifdef HAVE_FORK
BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
#endif
goto end;
}
argc--;
argv++;
j++;
}
#ifdef HAVE_FORK
if(multi && do_multi(multi))
goto show_res;
#endif
if (j == 0)
{
for (i=0; i<ALGOR_NUM; i++)
{
if (i != D_EVP)
doit[i]=1;
}
for (i=0; i<RSA_NUM; i++)
rsa_doit[i]=1;
for (i=0; i<DSA_NUM; i++)
dsa_doit[i]=1;
}
for (i=0; i<ALGOR_NUM; i++)
if (doit[i]) pr_header++;
if (usertime == 0 && !mr)
BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
#ifndef OPENSSL_NO_RSA
for (i=0; i<RSA_NUM; i++)
{
const unsigned char *p;
p=rsa_data[i];
rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
if (rsa_key[i] == NULL)
{
BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
goto end;
}
#if 0
else
{
BIO_printf(bio_err,mr ? "+RK:%d:"
: "Loaded RSA key, %d bit modulus and e= 0x",
BN_num_bits(rsa_key[i]->n));
BN_print(bio_err,rsa_key[i]->e);
BIO_printf(bio_err,"\n");
}
#endif
}
#endif
#ifndef OPENSSL_NO_DSA
dsa_key[0]=get_dsa512();
dsa_key[1]=get_dsa1024();
dsa_key[2]=get_dsa2048();
#endif
#ifndef OPENSSL_NO_DES
DES_set_key_unchecked(&key,&sch);
DES_set_key_unchecked(&key2,&sch2);
DES_set_key_unchecked(&key3,&sch3);
#endif
#ifndef OPENSSL_NO_AES
AES_set_encrypt_key(key16,128,&aes_ks1);
AES_set_encrypt_key(key24,192,&aes_ks2);
AES_set_encrypt_key(key32,256,&aes_ks3);
#endif
#ifndef OPENSSL_NO_CAMELLIA
Camellia_set_key(key16,128,&camellia_ks1);
Camellia_set_key(ckey24,192,&camellia_ks2);
Camellia_set_key(ckey32,256,&camellia_ks3);
#endif
#ifndef OPENSSL_NO_IDEA
idea_set_encrypt_key(key16,&idea_ks);
#endif
#ifndef OPENSSL_NO_RC4
RC4_set_key(&rc4_ks,16,key16);
#endif
#ifndef OPENSSL_NO_RC2
RC2_set_key(&rc2_ks,16,key16,128);
#endif
#ifndef OPENSSL_NO_RC5
RC5_32_set_key(&rc5_ks,16,key16,12);
#endif
#ifndef OPENSSL_NO_BF
BF_set_key(&bf_ks,16,key16);
#endif
#ifndef OPENSSL_NO_CAST
CAST_set_key(&cast_ks,16,key16);
#endif
#ifndef OPENSSL_NO_RSA
memset(rsa_c,0,sizeof(rsa_c));
#endif
#ifndef SIGALRM
#ifndef OPENSSL_NO_DES
BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
count=10;
do {
long it;
count*=2;
Time_F(START);
for (it=count; it; it--)
DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
&sch,DES_ENCRYPT);
d=Time_F(STOP);
} while (d <3);
save_count=count;
c[D_MD2][0]=count/10;
c[D_MDC2][0]=count/10;
c[D_MD4][0]=count;
c[D_MD5][0]=count;
c[D_HMAC][0]=count;
c[D_SHA1][0]=count;
c[D_RMD160][0]=count;
c[D_RC4][0]=count*5;
c[D_CBC_DES][0]=count;
c[D_EDE3_DES][0]=count/3;
c[D_CBC_IDEA][0]=count;
c[D_CBC_RC2][0]=count;
c[D_CBC_RC5][0]=count;
c[D_CBC_BF][0]=count;
c[D_CBC_CAST][0]=count;
c[D_CBC_128_AES][0]=count;
c[D_CBC_192_AES][0]=count;
c[D_CBC_256_AES][0]=count;
c[D_CBC_128_CML][0]=count;
c[D_CBC_192_CML][0]=count;
c[D_CBC_256_CML][0]=count;
c[D_SHA256][0]=count;
c[D_SHA512][0]=count;
for (i=1; i<SIZE_NUM; i++)
{
c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
}
for (i=1; i<SIZE_NUM; i++)
{
long l0,l1;
l0=(long)lengths[i-1];
l1=(long)lengths[i];
c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
c[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;
c[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;
c[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;
c[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;
c[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;
c[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;
}
#ifndef OPENSSL_NO_RSA
rsa_c[R_RSA_512][0]=count/2000;
rsa_c[R_RSA_512][1]=count/400;
for (i=1; i<RSA_NUM; i++)
{
rsa_c[i][0]=rsa_c[i-1][0]/8;
rsa_c[i][1]=rsa_c[i-1][1]/4;
if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
rsa_doit[i]=0;
else
{
if (rsa_c[i][0] == 0)
{
rsa_c[i][0]=1;
rsa_c[i][1]=20;
}
}
}
#endif
#ifndef OPENSSL_NO_DSA
dsa_c[R_DSA_512][0]=count/1000;
dsa_c[R_DSA_512][1]=count/1000/2;
for (i=1; i<DSA_NUM; i++)
{
dsa_c[i][0]=dsa_c[i-1][0]/4;
dsa_c[i][1]=dsa_c[i-1][1]/4;
if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
dsa_doit[i]=0;
else
{
if (dsa_c[i] == 0)
{
dsa_c[i][0]=1;
dsa_c[i][1]=1;
}
}
}
#endif
#ifndef OPENSSL_NO_ECDSA
ecdsa_c[R_EC_P160][0]=count/1000;
ecdsa_c[R_EC_P160][1]=count/1000/2;
for (i=R_EC_P192; i<=R_EC_P521; i++)
{
ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i]=0;
else
{
if (ecdsa_c[i] == 0)
{
ecdsa_c[i][0]=1;
ecdsa_c[i][1]=1;
}
}
}
ecdsa_c[R_EC_K163][0]=count/1000;
ecdsa_c[R_EC_K163][1]=count/1000/2;
for (i=R_EC_K233; i<=R_EC_K571; i++)
{
ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i]=0;
else
{
if (ecdsa_c[i] == 0)
{
ecdsa_c[i][0]=1;
ecdsa_c[i][1]=1;
}
}
}
ecdsa_c[R_EC_B163][0]=count/1000;
ecdsa_c[R_EC_B163][1]=count/1000/2;
for (i=R_EC_B233; i<=R_EC_B571; i++)
{
ecdsa_c[i][0]=ecdsa_c[i-1][0]/2;
ecdsa_c[i][1]=ecdsa_c[i-1][1]/2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i]=0;
else
{
if (ecdsa_c[i] == 0)
{
ecdsa_c[i][0]=1;
ecdsa_c[i][1]=1;
}
}
}
#endif
#ifndef OPENSSL_NO_ECDH
ecdh_c[R_EC_P160][0]=count/1000;
ecdh_c[R_EC_P160][1]=count/1000;
for (i=R_EC_P192; i<=R_EC_P521; i++)
{
ecdh_c[i][0]=ecdh_c[i-1][0]/2;
ecdh_c[i][1]=ecdh_c[i-1][1]/2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i]=0;
else
{
if (ecdh_c[i] == 0)
{
ecdh_c[i][0]=1;
ecdh_c[i][1]=1;
}
}
}
ecdh_c[R_EC_K163][0]=count/1000;
ecdh_c[R_EC_K163][1]=count/1000;
for (i=R_EC_K233; i<=R_EC_K571; i++)
{
ecdh_c[i][0]=ecdh_c[i-1][0]/2;
ecdh_c[i][1]=ecdh_c[i-1][1]/2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i]=0;
else
{
if (ecdh_c[i] == 0)
{
ecdh_c[i][0]=1;
ecdh_c[i][1]=1;
}
}
}
ecdh_c[R_EC_B163][0]=count/1000;
ecdh_c[R_EC_B163][1]=count/1000;
for (i=R_EC_B233; i<=R_EC_B571; i++)
{
ecdh_c[i][0]=ecdh_c[i-1][0]/2;
ecdh_c[i][1]=ecdh_c[i-1][1]/2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i]=0;
else
{
if (ecdh_c[i] == 0)
{
ecdh_c[i][0]=1;
ecdh_c[i][1]=1;
}
}
}
#endif
#define COND(d) (count < (d))
#define COUNT(d) (d)
#else
# error "You cannot disable DES on systems without SIGALRM."
#endif
#else
#define COND(c) (run)
#define COUNT(d) (count)
#ifndef _WIN32
signal(SIGALRM,sig_done);
#endif
#endif
#ifndef OPENSSL_NO_MD2
if (doit[D_MD2])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_MD2][j]); count++)
EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
d=Time_F(STOP);
print_result(D_MD2,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_MDC2
if (doit[D_MDC2])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_MDC2][j]); count++)
EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
d=Time_F(STOP);
print_result(D_MDC2,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_MD4
if (doit[D_MD4])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_MD4][j]); count++)
EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
d=Time_F(STOP);
print_result(D_MD4,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_MD5
if (doit[D_MD5])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_MD5][j]); count++)
EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
d=Time_F(STOP);
print_result(D_MD5,j,count,d);
}
}
#endif
#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
if (doit[D_HMAC])
{
HMAC_CTX hctx;
HMAC_CTX_init(&hctx);
HMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",
16,EVP_md5(), NULL);
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_HMAC][j]); count++)
{
HMAC_Init_ex(&hctx,NULL,0,NULL,NULL);
HMAC_Update(&hctx,buf,lengths[j]);
HMAC_Final(&hctx,&(hmac[0]),NULL);
}
d=Time_F(STOP);
print_result(D_HMAC,j,count,d);
}
HMAC_CTX_cleanup(&hctx);
}
#endif
#ifndef OPENSSL_NO_SHA
if (doit[D_SHA1])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_SHA1][j]); count++)
EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
d=Time_F(STOP);
print_result(D_SHA1,j,count,d);
}
}
#ifndef OPENSSL_NO_SHA256
if (doit[D_SHA256])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_SHA256][j]); count++)
SHA256(buf,lengths[j],sha256);
d=Time_F(STOP);
print_result(D_SHA256,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_SHA512
if (doit[D_SHA512])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_SHA512][j]); count++)
SHA512(buf,lengths[j],sha512);
d=Time_F(STOP);
print_result(D_SHA512,j,count,d);
}
}
#endif
#endif
#ifndef OPENSSL_NO_RIPEMD
if (doit[D_RMD160])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_RMD160][j]); count++)
EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
d=Time_F(STOP);
print_result(D_RMD160,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_RC4
if (doit[D_RC4])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_RC4][j]); count++)
RC4(&rc4_ks,(unsigned int)lengths[j],
buf,buf);
d=Time_F(STOP);
print_result(D_RC4,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_DES
if (doit[D_CBC_DES])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
&DES_iv,DES_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_DES,j,count,d);
}
}
if (doit[D_EDE3_DES])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
DES_ede3_cbc_encrypt(buf,buf,lengths[j],
&sch,&sch2,&sch3,
&DES_iv,DES_ENCRYPT);
d=Time_F(STOP);
print_result(D_EDE3_DES,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_AES
if (doit[D_CBC_128_AES])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)
AES_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&aes_ks1,
iv,AES_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_128_AES,j,count,d);
}
}
if (doit[D_CBC_192_AES])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)
AES_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&aes_ks2,
iv,AES_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_192_AES,j,count,d);
}
}
if (doit[D_CBC_256_AES])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)
AES_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&aes_ks3,
iv,AES_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_256_AES,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_CAMELLIA
if (doit[D_CBC_128_CML])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)
Camellia_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&camellia_ks1,
iv,CAMELLIA_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_128_CML,j,count,d);
}
}
if (doit[D_CBC_192_CML])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)
Camellia_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&camellia_ks2,
iv,CAMELLIA_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_192_CML,j,count,d);
}
}
if (doit[D_CBC_256_CML])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)
Camellia_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&camellia_ks3,
iv,CAMELLIA_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_256_CML,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_IDEA
if (doit[D_CBC_IDEA])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
idea_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&idea_ks,
iv,IDEA_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_IDEA,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_RC2
if (doit[D_CBC_RC2])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
RC2_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&rc2_ks,
iv,RC2_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_RC2,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_RC5
if (doit[D_CBC_RC5])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
RC5_32_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&rc5_ks,
iv,RC5_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_RC5,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_BF
if (doit[D_CBC_BF])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
BF_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&bf_ks,
iv,BF_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_BF,j,count,d);
}
}
#endif
#ifndef OPENSSL_NO_CAST
if (doit[D_CBC_CAST])
{
for (j=0; j<SIZE_NUM; j++)
{
print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
Time_F(START);
for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
CAST_cbc_encrypt(buf,buf,
(unsigned long)lengths[j],&cast_ks,
iv,CAST_ENCRYPT);
d=Time_F(STOP);
print_result(D_CBC_CAST,j,count,d);
}
}
#endif
if (doit[D_EVP])
{
for (j=0; j<SIZE_NUM; j++)
{
if (evp_cipher)
{
EVP_CIPHER_CTX ctx;
int outl;
names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
print_message(names[D_EVP],save_count,
lengths[j]);
EVP_CIPHER_CTX_init(&ctx);
if(decrypt)
EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
else
EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
EVP_CIPHER_CTX_set_padding(&ctx, 0);
Time_F(START);
if(decrypt)
for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
else
for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
if(decrypt)
EVP_DecryptFinal_ex(&ctx,buf,&outl);
else
EVP_EncryptFinal_ex(&ctx,buf,&outl);
d=Time_F(STOP);
EVP_CIPHER_CTX_cleanup(&ctx);
}
if (evp_md)
{
names[D_EVP]=OBJ_nid2ln(evp_md->type);
print_message(names[D_EVP],save_count,
lengths[j]);
Time_F(START);
for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
d=Time_F(STOP);
}
print_result(D_EVP,j,count,d);
}
}
RAND_pseudo_bytes(buf,36);
#ifndef OPENSSL_NO_RSA
for (j=0; j<RSA_NUM; j++)
{
int ret;
if (!rsa_doit[j]) continue;
ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
if (ret == 0)
{
BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
pkey_print_message("private","rsa",
rsa_c[j][0],rsa_bits[j],
RSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(rsa_c[j][0]); count++)
{
ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
&rsa_num, rsa_key[j]);
if (ret == 0)
{
BIO_printf(bio_err,
"RSA sign failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
: "%ld %d bit private RSA's in %.2fs\n",
count,rsa_bits[j],d);
rsa_results[j][0]=d/(double)count;
rsa_count=count;
}
#if 1
ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
if (ret <= 0)
{
BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
ERR_print_errors(bio_err);
rsa_doit[j] = 0;
}
else
{
pkey_print_message("public","rsa",
rsa_c[j][1],rsa_bits[j],
RSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(rsa_c[j][1]); count++)
{
ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
rsa_num, rsa_key[j]);
if (ret == 0)
{
BIO_printf(bio_err,
"RSA verify failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
: "%ld %d bit public RSA's in %.2fs\n",
count,rsa_bits[j],d);
rsa_results[j][1]=d/(double)count;
}
#endif
if (rsa_count <= 1)
{
for (j++; j<RSA_NUM; j++)
rsa_doit[j]=0;
}
}
#endif
RAND_pseudo_bytes(buf,20);
#ifndef OPENSSL_NO_DSA
if (RAND_status() != 1)
{
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j=0; j<DSA_NUM; j++)
{
unsigned int kk;
int ret;
if (!dsa_doit[j]) continue;
ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
&kk,dsa_key[j]);
if (ret == 0)
{
BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
pkey_print_message("sign","dsa",
dsa_c[j][0],dsa_bits[j],
DSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(dsa_c[j][0]); count++)
{
ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
&kk,dsa_key[j]);
if (ret == 0)
{
BIO_printf(bio_err,
"DSA sign failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
: "%ld %d bit DSA signs in %.2fs\n",
count,dsa_bits[j],d);
dsa_results[j][0]=d/(double)count;
rsa_count=count;
}
ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
kk,dsa_key[j]);
if (ret <= 0)
{
BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
ERR_print_errors(bio_err);
dsa_doit[j] = 0;
}
else
{
pkey_print_message("verify","dsa",
dsa_c[j][1],dsa_bits[j],
DSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(dsa_c[j][1]); count++)
{
ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
kk,dsa_key[j]);
if (ret <= 0)
{
BIO_printf(bio_err,
"DSA verify failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
: "%ld %d bit DSA verify in %.2fs\n",
count,dsa_bits[j],d);
dsa_results[j][1]=d/(double)count;
}
if (rsa_count <= 1)
{
for (j++; j<DSA_NUM; j++)
dsa_doit[j]=0;
}
}
if (rnd_fake) RAND_cleanup();
#endif
#ifndef OPENSSL_NO_ECDSA
if (RAND_status() != 1)
{
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j=0; j<EC_NUM; j++)
{
int ret;
if (!ecdsa_doit[j]) continue;
ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if (ecdsa[j] == NULL)
{
BIO_printf(bio_err,"ECDSA failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
#if 1
EC_KEY_precompute_mult(ecdsa[j], NULL);
#endif
EC_KEY_generate_key(ecdsa[j]);
ret = ECDSA_sign(0, buf, 20, ecdsasig,
&ecdsasiglen, ecdsa[j]);
if (ret == 0)
{
BIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
pkey_print_message("sign","ecdsa",
ecdsa_c[j][0],
test_curves_bits[j],
ECDSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(ecdsa_c[j][0]);
count++)
{
ret=ECDSA_sign(0, buf, 20,
ecdsasig, &ecdsasiglen,
ecdsa[j]);
if (ret == 0)
{
BIO_printf(bio_err, "ECDSA sign failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\n" :
"%ld %d bit ECDSA signs in %.2fs \n",
count, test_curves_bits[j], d);
ecdsa_results[j][0]=d/(double)count;
rsa_count=count;
}
ret=ECDSA_verify(0, buf, 20, ecdsasig,
ecdsasiglen, ecdsa[j]);
if (ret != 1)
{
BIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\n");
ERR_print_errors(bio_err);
ecdsa_doit[j] = 0;
}
else
{
pkey_print_message("verify","ecdsa",
ecdsa_c[j][1],
test_curves_bits[j],
ECDSA_SECONDS);
Time_F(START);
for (count=0,run=1; COND(ecdsa_c[j][1]); count++)
{
ret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
if (ret != 1)
{
BIO_printf(bio_err, "ECDSA verify failure\n");
ERR_print_errors(bio_err);
count=1;
break;
}
}
d=Time_F(STOP);
BIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\n"
: "%ld %d bit ECDSA verify in %.2fs\n",
count, test_curves_bits[j], d);
ecdsa_results[j][1]=d/(double)count;
}
if (rsa_count <= 1)
{
for (j++; j<EC_NUM; j++)
ecdsa_doit[j]=0;
}
}
}
if (rnd_fake) RAND_cleanup();
#endif
#ifndef OPENSSL_NO_ECDH
if (RAND_status() != 1)
{
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j=0; j<EC_NUM; j++)
{
if (!ecdh_doit[j]) continue;
ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))
{
BIO_printf(bio_err,"ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
if (!EC_KEY_generate_key(ecdh_a[j]) ||
!EC_KEY_generate_key(ecdh_b[j]))
{
BIO_printf(bio_err,"ECDH key generation failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
int field_size, outlen;
void *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);
field_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
if (field_size <= 24 * 8)
{
outlen = KDF1_SHA1_len;
kdf = KDF1_SHA1;
}
else
{
outlen = (field_size+7)/8;
kdf = NULL;
}
secret_size_a = ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
secret_size_b = ECDH_compute_key(secret_b, outlen,
EC_KEY_get0_public_key(ecdh_a[j]),
ecdh_b[j], kdf);
if (secret_size_a != secret_size_b)
ecdh_checks = 0;
else
ecdh_checks = 1;
for (secret_idx = 0;
(secret_idx < secret_size_a)
&& (ecdh_checks == 1);
secret_idx++)
{
if (secret_a[secret_idx] != secret_b[secret_idx])
ecdh_checks = 0;
}
if (ecdh_checks == 0)
{
BIO_printf(bio_err,"ECDH computations don't match.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
pkey_print_message("","ecdh",
ecdh_c[j][0],
test_curves_bits[j],
ECDH_SECONDS);
Time_F(START);
for (count=0,run=1; COND(ecdh_c[j][0]); count++)
{
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
}
d=Time_F(STOP);
BIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\n" :"%ld %d-bit ECDH ops in %.2fs\n",
count, test_curves_bits[j], d);
ecdh_results[j][0]=d/(double)count;
rsa_count=count;
}
}
if (rsa_count <= 1)
{
for (j++; j<EC_NUM; j++)
ecdh_doit[j]=0;
}
}
if (rnd_fake) RAND_cleanup();
#endif
#ifdef HAVE_FORK
show_res:
#endif
if(!mr)
{
fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
printf("options:");
printf("%s ",BN_options());
#ifndef OPENSSL_NO_MD2
printf("%s ",MD2_options());
#endif
#ifndef OPENSSL_NO_RC4
printf("%s ",RC4_options());
#endif
#ifndef OPENSSL_NO_DES
printf("%s ",DES_options());
#endif
#ifndef OPENSSL_NO_AES
printf("%s ",AES_options());
#endif
#ifndef OPENSSL_NO_IDEA
printf("%s ",idea_options());
#endif
#ifndef OPENSSL_NO_BF
printf("%s ",BF_options());
#endif
fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
}
if (pr_header)
{
if(mr)
fprintf(stdout,"+H");
else
{
fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
fprintf(stdout,"type ");
}
for (j=0; j<SIZE_NUM; j++)
fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
fprintf(stdout,"\n");
}
for (k=0; k<ALGOR_NUM; k++)
{
if (!doit[k]) continue;
if(mr)
fprintf(stdout,"+F:%d:%s",k,names[k]);
else
fprintf(stdout,"%-13s",names[k]);
for (j=0; j<SIZE_NUM; j++)
{
if (results[k][j] > 10000 && !mr)
fprintf(stdout," %11.2fk",results[k][j]/1e3);
else
fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
}
fprintf(stdout,"\n");
}
#ifndef OPENSSL_NO_RSA
j=1;
for (k=0; k<RSA_NUM; k++)
{
if (!rsa_doit[k]) continue;
if (j && !mr)
{
printf("%18ssign verify sign/s verify/s\n"," ");
j=0;
}
if(mr)
fprintf(stdout,"+F2:%u:%u:%f:%f\n",
k,rsa_bits[k],rsa_results[k][0],
rsa_results[k][1]);
else
fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_DSA
j=1;
for (k=0; k<DSA_NUM; k++)
{
if (!dsa_doit[k]) continue;
if (j && !mr)
{
printf("%18ssign verify sign/s verify/s\n"," ");
j=0;
}
if(mr)
fprintf(stdout,"+F3:%u:%u:%f:%f\n",
k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
else
fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_ECDSA
j=1;
for (k=0; k<EC_NUM; k++)
{
if (!ecdsa_doit[k]) continue;
if (j && !mr)
{
printf("%30ssign verify sign/s verify/s\n"," ");
j=0;
}
if (mr)
fprintf(stdout,"+F4:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdsa_results[k][0],ecdsa_results[k][1]);
else
fprintf(stdout,
"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdsa_results[k][0],ecdsa_results[k][1],
1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_ECDH
j=1;
for (k=0; k<EC_NUM; k++)
{
if (!ecdh_doit[k]) continue;
if (j && !mr)
{
printf("%30sop op/s\n"," ");
j=0;
}
if (mr)
fprintf(stdout,"+F5:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdh_results[k][0], 1.0/ecdh_results[k][0]);
else
fprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdh_results[k][0], 1.0/ecdh_results[k][0]);
}
#endif
mret=0;
end:
ERR_print_errors(bio_err);
if (buf != NULL) OPENSSL_free(buf);
if (buf2 != NULL) OPENSSL_free(buf2);
#ifndef OPENSSL_NO_RSA
for (i=0; i<RSA_NUM; i++)
if (rsa_key[i] != NULL)
RSA_free(rsa_key[i]);
#endif
#ifndef OPENSSL_NO_DSA
for (i=0; i<DSA_NUM; i++)
if (dsa_key[i] != NULL)
DSA_free(dsa_key[i]);
#endif
#ifndef OPENSSL_NO_ECDSA
for (i=0; i<EC_NUM; i++)
if (ecdsa[i] != NULL)
EC_KEY_free(ecdsa[i]);
#endif
#ifndef OPENSSL_NO_ECDH
for (i=0; i<EC_NUM; i++)
{
if (ecdh_a[i] != NULL)
EC_KEY_free(ecdh_a[i]);
if (ecdh_b[i] != NULL)
EC_KEY_free(ecdh_b[i]);
}
#endif
apps_shutdown();
OPENSSL_EXIT(mret);
} | ['int MAIN(int argc, char **argv)\n\t{\n#ifndef OPENSSL_NO_ENGINE\n\tENGINE *e = NULL;\n#endif\n\tunsigned char *buf=NULL,*buf2=NULL;\n\tint mret=1;\n\tlong count=0,save_count=0;\n\tint i,j,k;\n#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n\tlong rsa_count;\n#endif\n#ifndef OPENSSL_NO_RSA\n\tunsigned rsa_num;\n#endif\n\tunsigned char md[EVP_MAX_MD_SIZE];\n#ifndef OPENSSL_NO_MD2\n\tunsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tunsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD4\n\tunsigned char md4[MD4_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD5\n\tunsigned char md5[MD5_DIGEST_LENGTH];\n\tunsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA\n\tunsigned char sha[SHA_DIGEST_LENGTH];\n#ifndef OPENSSL_NO_SHA256\n\tunsigned char sha256[SHA256_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA512\n\tunsigned char sha512[SHA512_DIGEST_LENGTH];\n#endif\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tunsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_KEY rc4_ks;\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_KEY rc5_ks;\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_KEY rc2_ks;\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tIDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_KEY bf_ks;\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_KEY cast_ks;\n#endif\n\tstatic const unsigned char key16[16]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n#ifndef OPENSSL_NO_AES\n\tstatic const unsigned char key24[24]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tstatic const unsigned char key32[32]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,\n\t\t 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tstatic const unsigned char ckey24[24]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tstatic const unsigned char ckey32[32]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,\n\t\t 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};\n#endif\n#ifndef OPENSSL_NO_AES\n#define MAX_BLOCK_SIZE 128\n#else\n#define MAX_BLOCK_SIZE 64\n#endif\n\tunsigned char DES_iv[8];\n\tunsigned char iv[MAX_BLOCK_SIZE/8];\n#ifndef OPENSSL_NO_DES\n\tDES_cblock *buf_as_des_cblock = NULL;\n\tstatic DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};\n\tstatic DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tDES_key_schedule sch;\n\tDES_key_schedule sch2;\n\tDES_key_schedule sch3;\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_KEY aes_ks1, aes_ks2, aes_ks3;\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tCAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n#endif\n#define\tD_MD2\t\t0\n#define\tD_MDC2\t\t1\n#define\tD_MD4\t\t2\n#define\tD_MD5\t\t3\n#define\tD_HMAC\t\t4\n#define\tD_SHA1\t\t5\n#define D_RMD160\t6\n#define\tD_RC4\t\t7\n#define\tD_CBC_DES\t8\n#define\tD_EDE3_DES\t9\n#define\tD_CBC_IDEA\t10\n#define\tD_CBC_RC2\t11\n#define\tD_CBC_RC5\t12\n#define\tD_CBC_BF\t13\n#define\tD_CBC_CAST\t14\n#define D_CBC_128_AES\t15\n#define D_CBC_192_AES\t16\n#define D_CBC_256_AES\t17\n#define D_CBC_128_CML 18\n#define D_CBC_192_CML 19\n#define D_CBC_256_CML 20\n#define D_EVP\t\t21\n#define D_SHA256\t22\n#define D_SHA512\t23\n\tdouble d=0.0;\n\tlong c[ALGOR_NUM][SIZE_NUM];\n#define\tR_DSA_512\t0\n#define\tR_DSA_1024\t1\n#define\tR_DSA_2048\t2\n#define\tR_RSA_512\t0\n#define\tR_RSA_1024\t1\n#define\tR_RSA_2048\t2\n#define\tR_RSA_4096\t3\n#define R_EC_P160 0\n#define R_EC_P192 1\n#define R_EC_P224 2\n#define R_EC_P256 3\n#define R_EC_P384 4\n#define R_EC_P521 5\n#define R_EC_K163 6\n#define R_EC_K233 7\n#define R_EC_K283 8\n#define R_EC_K409 9\n#define R_EC_K571 10\n#define R_EC_B163 11\n#define R_EC_B233 12\n#define R_EC_B283 13\n#define R_EC_B409 14\n#define R_EC_B571 15\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa_key[RSA_NUM];\n\tlong rsa_c[RSA_NUM][2];\n\tstatic unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};\n\tstatic unsigned char *rsa_data[RSA_NUM]=\n\t\t{test512,test1024,test2048,test4096};\n\tstatic int rsa_data_length[RSA_NUM]={\n\t\tsizeof(test512),sizeof(test1024),\n\t\tsizeof(test2048),sizeof(test4096)};\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsa_key[DSA_NUM];\n\tlong dsa_c[DSA_NUM][2];\n\tstatic unsigned int dsa_bits[DSA_NUM]={512,1024,2048};\n#endif\n#ifndef OPENSSL_NO_EC\n\tstatic unsigned int test_curves[EC_NUM] =\n\t{\n\tNID_secp160r1,\n\tNID_X9_62_prime192v1,\n\tNID_secp224r1,\n\tNID_X9_62_prime256v1,\n\tNID_secp384r1,\n\tNID_secp521r1,\n\tNID_sect163k1,\n\tNID_sect233k1,\n\tNID_sect283k1,\n\tNID_sect409k1,\n\tNID_sect571k1,\n\tNID_sect163r2,\n\tNID_sect233r1,\n\tNID_sect283r1,\n\tNID_sect409r1,\n\tNID_sect571r1\n\t};\n\tstatic const char * test_curves_names[EC_NUM] =\n\t{\n\t"secp160r1",\n\t"nistp192",\n\t"nistp224",\n\t"nistp256",\n\t"nistp384",\n\t"nistp521",\n\t"nistk163",\n\t"nistk233",\n\t"nistk283",\n\t"nistk409",\n\t"nistk571",\n\t"nistb163",\n\t"nistb233",\n\t"nistb283",\n\t"nistb409",\n\t"nistb571"\n\t};\n\tstatic int test_curves_bits[EC_NUM] =\n {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tunsigned char ecdsasig[256];\n\tunsigned int ecdsasiglen;\n\tEC_KEY *ecdsa[EC_NUM];\n\tlong ecdsa_c[EC_NUM][2];\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n\tunsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n\tint secret_size_a, secret_size_b;\n\tint ecdh_checks = 0;\n\tint secret_idx = 0;\n\tlong ecdh_c[EC_NUM][2];\n#endif\n\tint rsa_doit[RSA_NUM];\n\tint dsa_doit[DSA_NUM];\n#ifndef OPENSSL_NO_ECDSA\n\tint ecdsa_doit[EC_NUM];\n#endif\n#ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n#endif\n\tint doit[ALGOR_NUM];\n\tint pr_header=0;\n\tconst EVP_CIPHER *evp_cipher=NULL;\n\tconst EVP_MD *evp_md=NULL;\n\tint decrypt=0;\n#ifdef HAVE_FORK\n\tint multi=0;\n#endif\n#ifndef TIMES\n\tusertime=-1;\n#endif\n\tapps_startup();\n\tmemset(results, 0, sizeof(results));\n#ifndef OPENSSL_NO_DSA\n\tmemset(dsa_key,0,sizeof(dsa_key));\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t\t{\n\t\tecdh_a[i] = NULL;\n\t\tecdh_b[i] = NULL;\n\t\t}\n#endif\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#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_key,0,sizeof(rsa_key));\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_key[i]=NULL;\n#endif\n\tif ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_DES\n\tbuf_as_des_cblock = (DES_cblock *)buf;\n#endif\n\tif ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tmemset(c,0,sizeof(c));\n\tmemset(DES_iv,0,sizeof(DES_iv));\n\tmemset(iv,0,sizeof(iv));\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tdoit[i]=0;\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_doit[i]=0;\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tdsa_doit[i]=0;\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++)\n\t\tecdsa_doit[i]=0;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t\tecdh_doit[i]=0;\n#endif\n\tj=0;\n\targc--;\n\targv++;\n\twhile (argc)\n\t\t{\n\t\tif\t((argc > 0) && (strcmp(*argv,"-elapsed") == 0))\n\t\t\t{\n\t\t\tusertime = 0;\n\t\t\tj--;\n\t\t\t}\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-evp") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no EVP given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tevp_cipher=EVP_get_cipherbyname(*argv);\n\t\t\tif(!evp_cipher)\n\t\t\t\t{\n\t\t\t\tevp_md=EVP_get_digestbyname(*argv);\n\t\t\t\t}\n\t\t\tif(!evp_cipher && !evp_md)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"%s is an unknown cipher or digest\\n",*argv);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdoit[D_EVP]=1;\n\t\t\t}\n\t\telse if (argc > 0 && !strcmp(*argv,"-decrypt"))\n\t\t\t{\n\t\t\tdecrypt=1;\n\t\t\tj--;\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-engine") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no engine given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n e = setup_engine(bio_err, *argv, 0);\n\t\t\tj--;\n\t\t\t}\n#endif\n#ifdef HAVE_FORK\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-multi") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no multi count given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tmulti=atoi(argv[0]);\n\t\t\tif(multi <= 0)\n\t\t\t {\n\t\t\t\tBIO_printf(bio_err,"bad multi count\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tj--;\n\t\t\t}\n#endif\n\t\telse if (argc > 0 && !strcmp(*argv,"-mr"))\n\t\t\t{\n\t\t\tmr=1;\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#ifndef OPENSSL_NO_MD2\n\t\tif\t(strcmp(*argv,"md2") == 0) doit[D_MD2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tif (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tif (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SHA\n\t\t\tif (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha") == 0)\tdoit[D_SHA1]=1,\n\t\t\t\t\t\t\tdoit[D_SHA256]=1,\n\t\t\t\t\t\t\tdoit[D_SHA512]=1;\n\t\telse\n#ifndef OPENSSL_NO_SHA256\n\t\t\tif (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\t\tif (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;\n\t\telse\n#endif\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\t\t\tif (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tif (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;\n\t\telse\tif (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tif (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;\n\t\telse if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;\n\t\telse if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n#if 0\n\t\t\tif (strcmp(*argv,"rsaref") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#ifndef RSA_NULL\n\t\t\tif (strcmp(*argv,"openssl") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_method(RSA_PKCS1_SSLeay());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#endif\n\t\t if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;\n\t\telse if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;\n\t\telse if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;\n\t\telse if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;\n\t\telse if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;\n\t\telse\n#ifndef OPENSSL_NO_RC2\n\t\t if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;\n\t\telse if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;\n\t\telse if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;\n\t\telse if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAST\n\t\t if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_DES]=1;\n\t\t\tdoit[D_EDE3_DES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_128_AES]=1;\n\t\t\tdoit[D_CBC_192_AES]=1;\n\t\t\tdoit[D_CBC_256_AES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tif (strcmp(*argv,"camellia") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_128_CML]=1;\n\t\t\tdoit[D_CBC_192_CML]=1;\n\t\t\tdoit[D_CBC_256_CML]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tif (strcmp(*argv,"rsa") == 0)\n\t\t\t{\n\t\t\trsa_doit[R_RSA_512]=1;\n\t\t\trsa_doit[R_RSA_1024]=1;\n\t\t\trsa_doit[R_RSA_2048]=1;\n\t\t\trsa_doit[R_RSA_4096]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tif (strcmp(*argv,"dsa") == 0)\n\t\t\t{\n\t\t\tdsa_doit[R_DSA_512]=1;\n\t\t\tdsa_doit[R_DSA_1024]=1;\n\t\t\tdsa_doit[R_DSA_2048]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;\n\t\telse if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;\n\t\telse if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;\n\t\telse if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;\n\t\telse if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;\n\t\telse if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;\n\t\telse if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;\n\t\telse if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;\n\t\telse if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;\n\t\telse if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;\n\t\telse if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;\n\t\telse if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;\n\t\telse if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;\n\t\telse if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;\n\t\telse if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;\n\t\telse if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;\n\t\telse if (strcmp(*argv,"ecdsa") == 0)\n\t\t\t{\n\t\t\tfor (i=0; i < EC_NUM; i++)\n\t\t\t\tecdsa_doit[i]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;\n\t\telse if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;\n\t\telse if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;\n\t\telse if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;\n\t\telse if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;\n\t\telse if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;\n\t\telse if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;\n\t\telse if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;\n\t\telse if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;\n\t\telse if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;\n\t\telse if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;\n\t\telse if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;\n\t\telse if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;\n\t\telse if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;\n\t\telse if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;\n\t\telse if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;\n\t\telse if (strcmp(*argv,"ecdh") == 0)\n\t\t\t{\n\t\t\tfor (i=0; i < EC_NUM; i++)\n\t\t\t\tecdh_doit[i]=1;\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Error: bad option or value\\n");\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available values:\\n");\n#ifndef OPENSSL_NO_MD2\n\t\t\tBIO_printf(bio_err,"md2 ");\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tBIO_printf(bio_err,"mdc2 ");\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tBIO_printf(bio_err,"md4 ");\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tBIO_printf(bio_err,"md5 ");\n#ifndef OPENSSL_NO_HMAC\n\t\t\tBIO_printf(bio_err,"hmac ");\n#endif\n#endif\n#ifndef OPENSSL_NO_SHA1\n\t\t\tBIO_printf(bio_err,"sha1 ");\n#endif\n#ifndef OPENSSL_NO_SHA256\n\t\t\tBIO_printf(bio_err,"sha256 ");\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\t\tBIO_printf(bio_err,"sha512 ");\n#endif\n#ifndef OPENSSL_NO_RIPEMD160\n\t\t\tBIO_printf(bio_err,"rmd160");\n#endif\n#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t\tBIO_printf(bio_err,"rc5-cbc ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"bf-cbc");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des-cbc des-ede3 ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tBIO_printf(bio_err,"rc4");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\\n");\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tBIO_printf(bio_err,"dsa512 dsa1024 dsa2048\\n");\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t\tBIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\\n");\n\t\t\tBIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n\t\t\tBIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n\t\t\tBIO_printf(bio_err,"ecdsa\\n");\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\tBIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\\n");\n\t\t\tBIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n\t\t\tBIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n\t\t\tBIO_printf(bio_err,"ecdh\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2 ");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tBIO_printf(bio_err,"camellia ");\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"blowfish");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES) || \\\n !defined(OPENSSL_NO_CAMELLIA)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available options:\\n");\n#if defined(TIMES) || defined(USE_TOD)\n\t\t\tBIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\\n");\n#endif\n#ifndef OPENSSL_NO_ENGINE\n\t\t\tBIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"-evp e use EVP e.\\n");\n\t\t\tBIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\\n");\n\t\t\tBIO_printf(bio_err,"-mr produce machine readable output.\\n");\n#ifdef HAVE_FORK\n\t\t\tBIO_printf(bio_err,"-multi n run n benchmarks in parallel.\\n");\n#endif\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\tj++;\n\t\t}\n#ifdef HAVE_FORK\n\tif(multi && do_multi(multi))\n\t\tgoto show_res;\n#endif\n\tif (j == 0)\n\t\t{\n\t\tfor (i=0; i<ALGOR_NUM; i++)\n\t\t\t{\n\t\t\tif (i != D_EVP)\n\t\t\t\tdoit[i]=1;\n\t\t\t}\n\t\tfor (i=0; i<RSA_NUM; i++)\n\t\t\trsa_doit[i]=1;\n\t\tfor (i=0; i<DSA_NUM; i++)\n\t\t\tdsa_doit[i]=1;\n\t\t}\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tif (doit[i]) pr_header++;\n\tif (usertime == 0 && !mr)\n\t\tBIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\\n");\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\t{\n\t\tconst unsigned char *p;\n\t\tp=rsa_data[i];\n\t\trsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);\n\t\tif (rsa_key[i] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"internal error loading RSA key number %d\\n",i);\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,mr ? "+RK:%d:"\n\t\t\t\t : "Loaded RSA key, %d bit modulus and e= 0x",\n\t\t\t\t BN_num_bits(rsa_key[i]->n));\n\t\t\tBN_print(bio_err,rsa_key[i]->e);\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t}\n#endif\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_key[0]=get_dsa512();\n\tdsa_key[1]=get_dsa1024();\n\tdsa_key[2]=get_dsa2048();\n#endif\n#ifndef OPENSSL_NO_DES\n\tDES_set_key_unchecked(&key,&sch);\n\tDES_set_key_unchecked(&key2,&sch2);\n\tDES_set_key_unchecked(&key3,&sch3);\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_set_encrypt_key(key16,128,&aes_ks1);\n\tAES_set_encrypt_key(key24,192,&aes_ks2);\n\tAES_set_encrypt_key(key32,256,&aes_ks3);\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tCamellia_set_key(key16,128,&camellia_ks1);\n\tCamellia_set_key(ckey24,192,&camellia_ks2);\n\tCamellia_set_key(ckey32,256,&camellia_ks3);\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tidea_set_encrypt_key(key16,&idea_ks);\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_set_key(&rc4_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_set_key(&rc2_ks,16,key16,128);\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_set_key(&rc5_ks,16,key16,12);\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_set_key(&bf_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_set_key(&cast_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_c,0,sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n#ifndef OPENSSL_NO_DES\n\tBIO_printf(bio_err,"First we calculate the approximate speed ...\\n");\n\tcount=10;\n\tdo\t{\n\t\tlong it;\n\t\tcount*=2;\n\t\tTime_F(START);\n\t\tfor (it=count; it; it--)\n\t\t\tDES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,\n\t\t\t\t&sch,DES_ENCRYPT);\n\t\td=Time_F(STOP);\n\t\t} while (d <3);\n\tsave_count=count;\n\tc[D_MD2][0]=count/10;\n\tc[D_MDC2][0]=count/10;\n\tc[D_MD4][0]=count;\n\tc[D_MD5][0]=count;\n\tc[D_HMAC][0]=count;\n\tc[D_SHA1][0]=count;\n\tc[D_RMD160][0]=count;\n\tc[D_RC4][0]=count*5;\n\tc[D_CBC_DES][0]=count;\n\tc[D_EDE3_DES][0]=count/3;\n\tc[D_CBC_IDEA][0]=count;\n\tc[D_CBC_RC2][0]=count;\n\tc[D_CBC_RC5][0]=count;\n\tc[D_CBC_BF][0]=count;\n\tc[D_CBC_CAST][0]=count;\n\tc[D_CBC_128_AES][0]=count;\n\tc[D_CBC_192_AES][0]=count;\n\tc[D_CBC_256_AES][0]=count;\n\tc[D_CBC_128_CML][0]=count;\n\tc[D_CBC_192_CML][0]=count;\n\tc[D_CBC_256_CML][0]=count;\n\tc[D_SHA256][0]=count;\n\tc[D_SHA512][0]=count;\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tc[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];\n\t\tc[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];\n\t\tc[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];\n\t\t}\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tlong l0,l1;\n\t\tl0=(long)lengths[i-1];\n\t\tl1=(long)lengths[i];\n\t\tc[D_RC4][i]=c[D_RC4][i-1]*l0/l1;\n\t\tc[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;\n\t\tc[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;\n\t\tc[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;\n\t\tc[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;\n\t\tc[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;\n\t\tc[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;\n\t\tc[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;\n\t\tc[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;\n\t\tc[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;\n\t\tc[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;\n \t\tc[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;\n\t\tc[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;\n\t\tc[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\trsa_c[R_RSA_512][0]=count/2000;\n\trsa_c[R_RSA_512][1]=count/400;\n\tfor (i=1; i<RSA_NUM; i++)\n\t\t{\n\t\trsa_c[i][0]=rsa_c[i-1][0]/8;\n\t\trsa_c[i][1]=rsa_c[i-1][1]/4;\n\t\tif ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n\t\t\trsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (rsa_c[i][0] == 0)\n\t\t\t\t{\n\t\t\t\trsa_c[i][0]=1;\n\t\t\t\trsa_c[i][1]=20;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_c[R_DSA_512][0]=count/1000;\n\tdsa_c[R_DSA_512][1]=count/1000/2;\n\tfor (i=1; i<DSA_NUM; i++)\n\t\t{\n\t\tdsa_c[i][0]=dsa_c[i-1][0]/4;\n\t\tdsa_c[i][1]=dsa_c[i-1][1]/4;\n\t\tif ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n\t\t\tdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (dsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tdsa_c[i][0]=1;\n\t\t\t\tdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tecdsa_c[R_EC_P160][0]=count/1000;\n\tecdsa_c[R_EC_P160][1]=count/1000/2;\n\tfor (i=R_EC_P192; i<=R_EC_P521; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdsa_c[R_EC_K163][0]=count/1000;\n\tecdsa_c[R_EC_K163][1]=count/1000/2;\n\tfor (i=R_EC_K233; i<=R_EC_K571; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdsa_c[R_EC_B163][0]=count/1000;\n\tecdsa_c[R_EC_B163][1]=count/1000/2;\n\tfor (i=R_EC_B233; i<=R_EC_B571; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tecdh_c[R_EC_P160][0]=count/1000;\n\tecdh_c[R_EC_P160][1]=count/1000;\n\tfor (i=R_EC_P192; i<=R_EC_P521; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdh_c[R_EC_K163][0]=count/1000;\n\tecdh_c[R_EC_K163][1]=count/1000;\n\tfor (i=R_EC_K233; i<=R_EC_K571; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdh_c[R_EC_B163][0]=count/1000;\n\tecdh_c[R_EC_B163][1]=count/1000;\n\tfor (i=R_EC_B233; i<=R_EC_B571; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#define COND(d)\t(count < (d))\n#define COUNT(d) (d)\n#else\n# error "You cannot disable DES on systems without SIGALRM."\n#endif\n#else\n#define COND(c)\t(run)\n#define COUNT(d) (count)\n#ifndef _WIN32\n\tsignal(SIGALRM,sig_done);\n#endif\n#endif\n#ifndef OPENSSL_NO_MD2\n\tif (doit[D_MD2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD2],c[D_MD2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tif (doit[D_MDC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MDC2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MDC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD4\n\tif (doit[D_MD4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD4],c[D_MD4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD4][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD5\n\tif (doit[D_MD5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD5],c[D_MD5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD5][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n\tif (doit[D_HMAC])\n\t\t{\n\t\tHMAC_CTX hctx;\n\t\tHMAC_CTX_init(&hctx);\n\t\tHMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",\n\t\t\t16,EVP_md5(), NULL);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_HMAC][j]); count++)\n\t\t\t\t{\n\t\t\t\tHMAC_Init_ex(&hctx,NULL,0,NULL,NULL);\n\t\t\t\tHMAC_Update(&hctx,buf,lengths[j]);\n\t\t\t\tHMAC_Final(&hctx,&(hmac[0]),NULL);\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_HMAC,j,count,d);\n\t\t\t}\n\t\tHMAC_CTX_cleanup(&hctx);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA\n\tif (doit[D_SHA1])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA1][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA1,j,count,d);\n\t\t\t}\n\t\t}\n#ifndef OPENSSL_NO_SHA256\n\tif (doit[D_SHA256])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA256][j]); count++)\n\t\t\t\tSHA256(buf,lengths[j],sha256);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA256,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA512\n\tif (doit[D_SHA512])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA512][j]); count++)\n\t\t\t\tSHA512(buf,lengths[j],sha512);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA512,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tif (doit[D_RMD160])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RMD160][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RMD160,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC4\n\tif (doit[D_RC4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RC4],c[D_RC4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RC4][j]); count++)\n\t\t\t\tRC4(&rc4_ks,(unsigned int)lengths[j],\n\t\t\t\t\tbuf,buf);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RC4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DES\n\tif (doit[D_CBC_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_DES][j]); count++)\n\t\t\t\tDES_ncbc_encrypt(buf,buf,lengths[j],&sch,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_DES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_EDE3_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)\n\t\t\t\tDES_ede3_cbc_encrypt(buf,buf,lengths[j],\n\t\t\t\t\t\t &sch,&sch2,&sch3,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_EDE3_DES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_AES\n\tif (doit[D_CBC_128_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks1,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_128_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_192_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks2,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_192_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_256_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks3,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_256_AES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tif (doit[D_CBC_128_CML])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)\n\t\t\t\tCamellia_cbc_encrypt(buf,buf,\n\t\t\t\t (unsigned long)lengths[j],&camellia_ks1,\n\t\t\t\t iv,CAMELLIA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_128_CML,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_192_CML])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)\n\t\t\t\tCamellia_cbc_encrypt(buf,buf,\n\t\t\t\t (unsigned long)lengths[j],&camellia_ks2,\n\t\t\t\t iv,CAMELLIA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_192_CML,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_256_CML])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)\n\t\t\t\tCamellia_cbc_encrypt(buf,buf,\n\t\t\t\t (unsigned long)lengths[j],&camellia_ks3,\n\t\t\t\t iv,CAMELLIA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_256_CML,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tif (doit[D_CBC_IDEA])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)\n\t\t\t\tidea_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&idea_ks,\n\t\t\t\t\tiv,IDEA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_IDEA,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC2\n\tif (doit[D_CBC_RC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)\n\t\t\t\tRC2_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc2_ks,\n\t\t\t\t\tiv,RC2_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC5\n\tif (doit[D_CBC_RC5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)\n\t\t\t\tRC5_32_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc5_ks,\n\t\t\t\t\tiv,RC5_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_BF\n\tif (doit[D_CBC_BF])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_BF][j]); count++)\n\t\t\t\tBF_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&bf_ks,\n\t\t\t\t\tiv,BF_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_BF,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_CAST\n\tif (doit[D_CBC_CAST])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)\n\t\t\t\tCAST_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&cast_ks,\n\t\t\t\t\tiv,CAST_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_CAST,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n\tif (doit[D_EVP])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (evp_cipher)\n\t\t\t\t{\n\t\t\t\tEVP_CIPHER_CTX ctx;\n\t\t\t\tint outl;\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_cipher->nid);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tEVP_CIPHER_CTX_init(&ctx);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\tEVP_CIPHER_CTX_set_padding(&ctx, 0);\n\t\t\t\tTime_F(START);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\telse\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tEVP_CIPHER_CTX_cleanup(&ctx);\n\t\t\t\t}\n\t\t\tif (evp_md)\n\t\t\t\t{\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_md->type);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\tEVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\t}\n\t\t\tprint_result(D_EVP,j,count,d);\n\t\t\t}\n\t\t}\n\tRAND_pseudo_bytes(buf,36);\n#ifndef OPENSSL_NO_RSA\n\tfor (j=0; j<RSA_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!rsa_doit[j]) continue;\n\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("private","rsa",\n\t\t\t\trsa_c[j][0],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\t&rsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit private RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n#if 1\n\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("public","rsa",\n\t\t\t\trsa_c[j][1],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\trsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit public RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][1]=d/(double)count;\n\t\t\t}\n#endif\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<RSA_NUM; j++)\n\t\t\t\trsa_doit[j]=0;\n\t\t\t}\n\t\t}\n#endif\n\tRAND_pseudo_bytes(buf,20);\n#ifndef OPENSSL_NO_DSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<DSA_NUM; j++)\n\t\t{\n\t\tunsigned int kk;\n\t\tint ret;\n\t\tif (!dsa_doit[j]) continue;\n\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t&kk,dsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("sign","dsa",\n\t\t\t\tdsa_c[j][0],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\t&kk,dsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA signs in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\tkk,dsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tdsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("verify","dsa",\n\t\t\t\tdsa_c[j][1],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\tkk,dsa_key[j]);\n\t\t\t\tif (ret <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA verify in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][1]=d/(double)count;\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<DSA_NUM; j++)\n\t\t\t\tdsa_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<EC_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!ecdsa_doit[j]) continue;\n\t\tecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n\t\tif (ecdsa[j] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"ECDSA failure.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n#if 1\n\t\t\tEC_KEY_precompute_mult(ecdsa[j], NULL);\n#endif\n\t\t\tEC_KEY_generate_key(ecdsa[j]);\n\t\t\tret = ECDSA_sign(0, buf, 20, ecdsasig,\n\t\t\t\t&ecdsasiglen, ecdsa[j]);\n\t\t\tif (ret == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\trsa_count=1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tpkey_print_message("sign","ecdsa",\n\t\t\t\t\tecdsa_c[j][0],\n\t\t\t\t\ttest_curves_bits[j],\n\t\t\t\t\tECDSA_SECONDS);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(ecdsa_c[j][0]);\n\t\t\t\t\tcount++)\n\t\t\t\t\t{\n\t\t\t\t\tret=ECDSA_sign(0, buf, 20,\n\t\t\t\t\t\tecdsasig, &ecdsasiglen,\n\t\t\t\t\t\tecdsa[j]);\n\t\t\t\t\tif (ret == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err, "ECDSA sign failure\\n");\n\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\tcount=1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tBIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\\n" :\n\t\t\t\t\t"%ld %d bit ECDSA signs in %.2fs \\n",\n\t\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\tecdsa_results[j][0]=d/(double)count;\n\t\t\t\trsa_count=count;\n\t\t\t\t}\n\t\t\tret=ECDSA_verify(0, buf, 20, ecdsasig,\n\t\t\t\tecdsasiglen, ecdsa[j]);\n\t\t\tif (ret != 1)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tecdsa_doit[j] = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tpkey_print_message("verify","ecdsa",\n\t\t\t\tecdsa_c[j][1],\n\t\t\t\ttest_curves_bits[j],\n\t\t\t\tECDSA_SECONDS);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(ecdsa_c[j][1]); count++)\n\t\t\t\t\t{\n\t\t\t\t\tret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n\t\t\t\t\tif (ret != 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err, "ECDSA verify failure\\n");\n\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\tcount=1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tBIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\\n"\n\t\t\t\t\t\t: "%ld %d bit ECDSA verify in %.2fs\\n",\n\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\tecdsa_results[j][1]=d/(double)count;\n\t\t\t\t}\n\t\t\tif (rsa_count <= 1)\n\t\t\t\t{\n\t\t\t\tfor (j++; j<EC_NUM; j++)\n\t\t\t\tecdsa_doit[j]=0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<EC_NUM; j++)\n\t\t{\n\t\tif (!ecdh_doit[j]) continue;\n\t\tecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n\t\tecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n\t\tif ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"ECDH failure.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!EC_KEY_generate_key(ecdh_a[j]) ||\n\t\t\t\t!EC_KEY_generate_key(ecdh_b[j]))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDH key generation failure.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\trsa_count=1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tint field_size, outlen;\n\t\t\t\tvoid *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);\n\t\t\t\tfield_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n\t\t\t\tif (field_size <= 24 * 8)\n\t\t\t\t\t{\n\t\t\t\t\toutlen = KDF1_SHA1_len;\n\t\t\t\t\tkdf = KDF1_SHA1;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\toutlen = (field_size+7)/8;\n\t\t\t\t\tkdf = NULL;\n\t\t\t\t\t}\n\t\t\t\tsecret_size_a = ECDH_compute_key(secret_a, outlen,\n\t\t\t\t\tEC_KEY_get0_public_key(ecdh_b[j]),\n\t\t\t\t\tecdh_a[j], kdf);\n\t\t\t\tsecret_size_b = ECDH_compute_key(secret_b, outlen,\n\t\t\t\t\tEC_KEY_get0_public_key(ecdh_a[j]),\n\t\t\t\t\tecdh_b[j], kdf);\n\t\t\t\tif (secret_size_a != secret_size_b)\n\t\t\t\t\tecdh_checks = 0;\n\t\t\t\telse\n\t\t\t\t\tecdh_checks = 1;\n\t\t\t\tfor (secret_idx = 0;\n\t\t\t\t (secret_idx < secret_size_a)\n\t\t\t\t\t&& (ecdh_checks == 1);\n\t\t\t\t secret_idx++)\n\t\t\t\t\t{\n\t\t\t\t\tif (secret_a[secret_idx] != secret_b[secret_idx])\n\t\t\t\t\tecdh_checks = 0;\n\t\t\t\t\t}\n\t\t\t\tif (ecdh_checks == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"ECDH computations don\'t match.\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\trsa_count=1;\n\t\t\t\t\t}\n\t\t\t\tpkey_print_message("","ecdh",\n\t\t\t\tecdh_c[j][0],\n\t\t\t\ttest_curves_bits[j],\n\t\t\t\tECDH_SECONDS);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(ecdh_c[j][0]); count++)\n\t\t\t\t\t{\n\t\t\t\t\tECDH_compute_key(secret_a, outlen,\n\t\t\t\t\tEC_KEY_get0_public_key(ecdh_b[j]),\n\t\t\t\t\tecdh_a[j], kdf);\n\t\t\t\t\t}\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tBIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\\n" :"%ld %d-bit ECDH ops in %.2fs\\n",\n\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\tecdh_results[j][0]=d/(double)count;\n\t\t\t\trsa_count=count;\n\t\t\t\t}\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<EC_NUM; j++)\n\t\t\tecdh_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifdef HAVE_FORK\nshow_res:\n#endif\n\tif(!mr)\n\t\t{\n\t\tfprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_BUILT_ON));\n\t\tprintf("options:");\n\t\tprintf("%s ",BN_options());\n#ifndef OPENSSL_NO_MD2\n\t\tprintf("%s ",MD2_options());\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\tprintf("%s ",RC4_options());\n#endif\n#ifndef OPENSSL_NO_DES\n\t\tprintf("%s ",DES_options());\n#endif\n#ifndef OPENSSL_NO_AES\n\t\tprintf("%s ",AES_options());\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\tprintf("%s ",idea_options());\n#endif\n#ifndef OPENSSL_NO_BF\n\t\tprintf("%s ",BF_options());\n#endif\n\t\tfprintf(stdout,"\\n%s\\n",SSLeay_version(SSLEAY_CFLAGS));\n\t\t}\n\tif (pr_header)\n\t\t{\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+H");\n\t\telse\n\t\t\t{\n\t\t\tfprintf(stdout,"The \'numbers\' are in 1000s of bytes per second processed.\\n");\n\t\t\tfprintf(stdout,"type ");\n\t\t\t}\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\tfprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tfor (k=0; k<ALGOR_NUM; k++)\n\t\t{\n\t\tif (!doit[k]) continue;\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F:%d:%s",k,names[k]);\n\t\telse\n\t\t\tfprintf(stdout,"%-13s",names[k]);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (results[k][j] > 10000 && !mr)\n\t\t\t\tfprintf(stdout," %11.2fk",results[k][j]/1e3);\n\t\t\telse\n\t\t\t\tfprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);\n\t\t\t}\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\tj=1;\n\tfor (k=0; k<RSA_NUM; k++)\n\t\t{\n\t\tif (!rsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F2:%u:%u:%f:%f\\n",\n\t\t\t\tk,rsa_bits[k],rsa_results[k][0],\n\t\t\t\trsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n\t\t\t\trsa_bits[k],rsa_results[k][0],rsa_results[k][1],\n\t\t\t\t1.0/rsa_results[k][0],1.0/rsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tj=1;\n\tfor (k=0; k<DSA_NUM; k++)\n\t\t{\n\t\tif (!dsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F3:%u:%u:%f:%f\\n",\n\t\t\t\tk,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n\t\t\t\tdsa_bits[k],dsa_results[k][0],dsa_results[k][1],\n\t\t\t\t1.0/dsa_results[k][0],1.0/dsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tj=1;\n\tfor (k=0; k<EC_NUM; k++)\n\t\t{\n\t\tif (!ecdsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%30ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif (mr)\n\t\t\tfprintf(stdout,"+F4:%u:%u:%f:%f\\n",\n\t\t\t\tk, test_curves_bits[k],\n\t\t\t\tecdsa_results[k][0],ecdsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,\n\t\t\t\t"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\ttest_curves_bits[k],\n\t\t\t\ttest_curves_names[k],\n\t\t\t\tecdsa_results[k][0],ecdsa_results[k][1],\n\t\t\t\t1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tj=1;\n\tfor (k=0; k<EC_NUM; k++)\n\t\t{\n\t\tif (!ecdh_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%30sop op/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif (mr)\n\t\t\tfprintf(stdout,"+F5:%u:%u:%f:%f\\n",\n\t\t\t\tk, test_curves_bits[k],\n\t\t\t\tecdh_results[k][0], 1.0/ecdh_results[k][0]);\n\t\telse\n\t\t\tfprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n\t\t\t\ttest_curves_bits[k],\n\t\t\t\ttest_curves_names[k],\n\t\t\t\tecdh_results[k][0], 1.0/ecdh_results[k][0]);\n\t\t}\n#endif\n\tmret=0;\nend:\n\tERR_print_errors(bio_err);\n\tif (buf != NULL) OPENSSL_free(buf);\n\tif (buf2 != NULL) OPENSSL_free(buf2);\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\tif (rsa_key[i] != NULL)\n\t\t\tRSA_free(rsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_DSA\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tif (dsa_key[i] != NULL)\n\t\t\tDSA_free(dsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++)\n\t\tif (ecdsa[i] != NULL)\n\t\t\tEC_KEY_free(ecdsa[i]);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t{\n\t\tif (ecdh_a[i] != NULL)\n\t\t\tEC_KEY_free(ecdh_a[i]);\n\t\tif (ecdh_b[i] != NULL)\n\t\t\tEC_KEY_free(ecdh_b[i]);\n\t}\n#endif\n\tapps_shutdown();\n\tOPENSSL_EXIT(mret);\n\t}'] |
33,037 | 0 | https://github.com/libav/libav/blob/cb4cb7b0ea12b791dde587b1acd504dbb4ec8f41/libavcodec/hqx.c/#L137 | static inline void idct_row(int16_t *blk)
{
int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;
int t10, t11, t12, t13;
t0 = (blk[3] * 19266 + blk[5] * 12873) >> 14;
t1 = (blk[5] * 19266 - blk[3] * 12873) >> 14;
t2 = ((blk[7] * 4520 + blk[1] * 22725) >> 14) - t0;
t3 = ((blk[1] * 4520 - blk[7] * 22725) >> 14) - t1;
t4 = t0 * 2 + t2;
t5 = t1 * 2 + t3;
t6 = t2 - t3;
t7 = t3 * 2 + t6;
t8 = (t6 * 11585) >> 14;
t9 = (t7 * 11585) >> 14;
tA = (blk[2] * 8867 - blk[6] * 21407) >> 14;
tB = (blk[6] * 8867 + blk[2] * 21407) >> 14;
tC = blk[0] - blk[4];
tD = blk[4] * 2 + tC;
tE = tC - tA;
tF = tD - tB;
t10 = tF - t5;
t11 = tE - t8;
t12 = tE + tA * 2 - t9;
t13 = tF + tB * 2 - t4;
blk[0] = (t13 + t4 * 2 + 4) >> 3;
blk[1] = (t12 + t9 * 2 + 4) >> 3;
blk[2] = (t11 + t8 * 2 + 4) >> 3;
blk[3] = (t10 + t5 * 2 + 4) >> 3;
blk[4] = (t10 + 4) >> 3;
blk[5] = (t11 + 4) >> 3;
blk[6] = (t12 + 4) >> 3;
blk[7] = (t13 + 4) >> 3;
} | ['static int hqx_decode_444a(HQXContext *ctx, AVFrame *pic,\n GetBitContext *gb, int x, int y)\n{\n const int *quants;\n int flag = 0;\n int last_dc;\n int i, ret;\n int cbp;\n cbp = get_vlc2(gb, ctx->cbp_vlc.table, ctx->cbp_vlc.bits, 1);\n for (i = 0; i < 16; i++)\n memset(ctx->block[i], 0, sizeof(**ctx->block) * 64);\n for (i = 0; i < 16; i++)\n ctx->block[i][0] = -0x800;\n if (cbp) {\n if (ctx->interlaced)\n flag = get_bits1(gb);\n quants = hqx_quants[get_bits(gb, 4)];\n cbp |= cbp << 4;\n cbp |= cbp << 8;\n for (i = 0; i < 16; i++) {\n if (i == 0 || i == 4 || i == 8 || i == 12)\n last_dc = 0;\n if (cbp & (1 << i)) {\n int vlc_index = ctx->dcb - 9;\n ret = decode_block(gb, &ctx->dc_vlc[vlc_index], quants,\n ctx->dcb, ctx->block[i], &last_dc);\n if (ret < 0)\n return ret;\n }\n }\n }\n put_blocks(pic, 3, x, y, flag, ctx->block[ 0], ctx->block[ 2], hqx_quant_luma);\n put_blocks(pic, 3, x + 8, y, flag, ctx->block[ 1], ctx->block[ 3], hqx_quant_luma);\n put_blocks(pic, 0, x, y, flag, ctx->block[ 4], ctx->block[ 6], hqx_quant_luma);\n put_blocks(pic, 0, x + 8, y, flag, ctx->block[ 5], ctx->block[ 7], hqx_quant_luma);\n put_blocks(pic, 2, x, y, flag, ctx->block[ 8], ctx->block[10], hqx_quant_chroma);\n put_blocks(pic, 2, x + 8, y, flag, ctx->block[ 9], ctx->block[11], hqx_quant_chroma);\n put_blocks(pic, 1, x, y, flag, ctx->block[12], ctx->block[14], hqx_quant_chroma);\n put_blocks(pic, 1, x + 8, y, flag, ctx->block[13], ctx->block[15], hqx_quant_chroma);\n return 0;\n}', 'static inline void put_blocks(AVFrame *pic, int plane,\n int x, int y, int ilace,\n int16_t *block0, int16_t *block1,\n const uint8_t *quant)\n{\n int fields = ilace ? 2 : 1;\n int lsize = pic->linesize[plane];\n uint8_t *p = pic->data[plane] + x * 2;\n hqx_idct_put((uint16_t *)(p + y * lsize), lsize * fields, block0, quant);\n hqx_idct_put((uint16_t *)(p + (y + (ilace ? 1 : 8)) * lsize),\n lsize * fields, block1, quant);\n}', 'static void hqx_idct_put(uint16_t *dst, ptrdiff_t stride,\n int16_t *block, const uint8_t *quant)\n{\n int i, j;\n hqx_idct(block, quant);\n for (i = 0; i < 8; i++) {\n for (j = 0; j < 8; j++) {\n int v = av_clip(block[j + i * 8] + 0x800, 0, 0x1000);\n dst[j] = (v << 4) | (v >> 8);\n }\n dst += stride >> 1;\n }\n}', 'static void hqx_idct(int16_t *block, const uint8_t *quant)\n{\n int i;\n for (i = 0; i < 8; i++)\n idct_col(block + i, quant + i);\n for (i = 0; i < 8; i++)\n idct_row(block + i * 8);\n}', 'static inline void idct_row(int16_t *blk)\n{\n int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, tA, tB, tC, tD, tE, tF;\n int t10, t11, t12, t13;\n t0 = (blk[3] * 19266 + blk[5] * 12873) >> 14;\n t1 = (blk[5] * 19266 - blk[3] * 12873) >> 14;\n t2 = ((blk[7] * 4520 + blk[1] * 22725) >> 14) - t0;\n t3 = ((blk[1] * 4520 - blk[7] * 22725) >> 14) - t1;\n t4 = t0 * 2 + t2;\n t5 = t1 * 2 + t3;\n t6 = t2 - t3;\n t7 = t3 * 2 + t6;\n t8 = (t6 * 11585) >> 14;\n t9 = (t7 * 11585) >> 14;\n tA = (blk[2] * 8867 - blk[6] * 21407) >> 14;\n tB = (blk[6] * 8867 + blk[2] * 21407) >> 14;\n tC = blk[0] - blk[4];\n tD = blk[4] * 2 + tC;\n tE = tC - tA;\n tF = tD - tB;\n t10 = tF - t5;\n t11 = tE - t8;\n t12 = tE + tA * 2 - t9;\n t13 = tF + tB * 2 - t4;\n blk[0] = (t13 + t4 * 2 + 4) >> 3;\n blk[1] = (t12 + t9 * 2 + 4) >> 3;\n blk[2] = (t11 + t8 * 2 + 4) >> 3;\n blk[3] = (t10 + t5 * 2 + 4) >> 3;\n blk[4] = (t10 + 4) >> 3;\n blk[5] = (t11 + 4) >> 3;\n blk[6] = (t12 + 4) >> 3;\n blk[7] = (t13 + 4) >> 3;\n}'] |
33,038 | 0 | https://github.com/openssl/openssl/blob/72257204bd2a88773461150765dfd0e0a428ee86/ssl/ssl_ciph.c/#L1167 | static int ssl_cipher_process_rulestr(const char *rule_str,
CIPHER_ORDER **head_p,
CIPHER_ORDER **tail_p,
const SSL_CIPHER **ca_list, CERT *c)
{
uint32_t alg_mkey, alg_auth, alg_enc, alg_mac, algo_strength;
int min_tls;
const char *l, *buf;
int j, multi, found, rule, retval, ok, buflen;
uint32_t cipher_id = 0;
char ch;
retval = 1;
l = rule_str;
for (;;) {
ch = *l;
if (ch == '\0')
break;
if (ch == '-') {
rule = CIPHER_DEL;
l++;
} else if (ch == '+') {
rule = CIPHER_ORD;
l++;
} else if (ch == '!') {
rule = CIPHER_KILL;
l++;
} else if (ch == '@') {
rule = CIPHER_SPECIAL;
l++;
} else {
rule = CIPHER_ADD;
}
if (ITEM_SEP(ch)) {
l++;
continue;
}
alg_mkey = 0;
alg_auth = 0;
alg_enc = 0;
alg_mac = 0;
min_tls = 0;
algo_strength = 0;
for (;;) {
ch = *l;
buf = l;
buflen = 0;
#ifndef CHARSET_EBCDIC
while (((ch >= 'A') && (ch <= 'Z')) ||
((ch >= '0') && (ch <= '9')) ||
((ch >= 'a') && (ch <= 'z')) ||
(ch == '-') || (ch == '.') || (ch == '='))
#else
while (isalnum(ch) || (ch == '-') || (ch == '.') || (ch == '='))
#endif
{
ch = *(++l);
buflen++;
}
if (buflen == 0) {
SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, SSL_R_INVALID_COMMAND);
retval = found = 0;
l++;
break;
}
if (rule == CIPHER_SPECIAL) {
found = 0;
break;
}
if (ch == '+') {
multi = 1;
l++;
} else
multi = 0;
j = found = 0;
cipher_id = 0;
while (ca_list[j]) {
if (strncmp(buf, ca_list[j]->name, buflen) == 0
&& (ca_list[j]->name[buflen] == '\0')) {
found = 1;
break;
} else
j++;
}
if (!found)
break;
if (ca_list[j]->algorithm_mkey) {
if (alg_mkey) {
alg_mkey &= ca_list[j]->algorithm_mkey;
if (!alg_mkey) {
found = 0;
break;
}
} else
alg_mkey = ca_list[j]->algorithm_mkey;
}
if (ca_list[j]->algorithm_auth) {
if (alg_auth) {
alg_auth &= ca_list[j]->algorithm_auth;
if (!alg_auth) {
found = 0;
break;
}
} else
alg_auth = ca_list[j]->algorithm_auth;
}
if (ca_list[j]->algorithm_enc) {
if (alg_enc) {
alg_enc &= ca_list[j]->algorithm_enc;
if (!alg_enc) {
found = 0;
break;
}
} else
alg_enc = ca_list[j]->algorithm_enc;
}
if (ca_list[j]->algorithm_mac) {
if (alg_mac) {
alg_mac &= ca_list[j]->algorithm_mac;
if (!alg_mac) {
found = 0;
break;
}
} else
alg_mac = ca_list[j]->algorithm_mac;
}
if (ca_list[j]->algo_strength & SSL_STRONG_MASK) {
if (algo_strength & SSL_STRONG_MASK) {
algo_strength &=
(ca_list[j]->algo_strength & SSL_STRONG_MASK) |
~SSL_STRONG_MASK;
if (!(algo_strength & SSL_STRONG_MASK)) {
found = 0;
break;
}
} else
algo_strength = ca_list[j]->algo_strength & SSL_STRONG_MASK;
}
if (ca_list[j]->algo_strength & SSL_DEFAULT_MASK) {
if (algo_strength & SSL_DEFAULT_MASK) {
algo_strength &=
(ca_list[j]->algo_strength & SSL_DEFAULT_MASK) |
~SSL_DEFAULT_MASK;
if (!(algo_strength & SSL_DEFAULT_MASK)) {
found = 0;
break;
}
} else
algo_strength |=
ca_list[j]->algo_strength & SSL_DEFAULT_MASK;
}
if (ca_list[j]->valid) {
cipher_id = ca_list[j]->id;
} else {
if (ca_list[j]->min_tls) {
if (min_tls != 0 && min_tls != ca_list[j]->min_tls) {
found = 0;
break;
} else {
min_tls = ca_list[j]->min_tls;
}
}
}
if (!multi)
break;
}
if (rule == CIPHER_SPECIAL) {
ok = 0;
if ((buflen == 8) && strncmp(buf, "STRENGTH", 8) == 0)
ok = ssl_cipher_strength_sort(head_p, tail_p);
else if (buflen == 10 && strncmp(buf, "SECLEVEL=", 9) == 0) {
int level = buf[9] - '0';
if (level < 0 || level > 5) {
SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
SSL_R_INVALID_COMMAND);
} else {
c->sec_level = level;
ok = 1;
}
} else
SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, SSL_R_INVALID_COMMAND);
if (ok == 0)
retval = 0;
while ((*l != '\0') && !ITEM_SEP(*l))
l++;
} else if (found) {
ssl_cipher_apply_rule(cipher_id,
alg_mkey, alg_auth, alg_enc, alg_mac,
min_tls, algo_strength, rule, -1, head_p,
tail_p);
} else {
while ((*l != '\0') && !ITEM_SEP(*l))
l++;
}
if (*l == '\0')
break;
}
return (retval);
} | ['static int run_mtu_tests(void)\n{\n SSL_CTX *ctx = NULL;\n STACK_OF(SSL_CIPHER) *ciphers;\n int i, ret = 0;\n if (!TEST_ptr(ctx = SSL_CTX_new(DTLS_method())))\n goto end;\n SSL_CTX_set_psk_server_callback(ctx, srvr_psk_callback);\n SSL_CTX_set_psk_client_callback(ctx, clnt_psk_callback);\n SSL_CTX_set_security_level(ctx, 0);\n if (!TEST_true(SSL_CTX_set_cipher_list(ctx, "PSK")))\n goto end;\n ciphers = SSL_CTX_get_ciphers(ctx);\n for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {\n const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);\n const char *cipher_name = SSL_CIPHER_get_name(cipher);\n if (strncmp(cipher_name, "PSK-", 4) != 0)\n continue;\n if (!TEST_int_gt(ret = mtu_test(ctx, cipher_name, 0), 0))\n break;\n TEST_info("%s OK", cipher_name);\n if (ret == 1)\n continue;\n if (!TEST_int_gt(ret = mtu_test(ctx, cipher_name, 1), 0))\n break;\n TEST_info("%s without EtM OK", cipher_name);\n }\n end:\n SSL_CTX_free(ctx);\n bio_s_mempacket_test_free();\n return ret;\n}', 'int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)\n{\n STACK_OF(SSL_CIPHER) *sk;\n sk = ssl_create_cipher_list(ctx->method, &ctx->cipher_list,\n &ctx->cipher_list_by_id, str, ctx->cert);\n if (sk == NULL)\n return 0;\n else if (sk_SSL_CIPHER_num(sk) == 0) {\n SSLerr(SSL_F_SSL_CTX_SET_CIPHER_LIST, SSL_R_NO_CIPHER_MATCH);\n return 0;\n }\n return 1;\n}', 'STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, STACK_OF(SSL_CIPHER)\n **cipher_list, STACK_OF(SSL_CIPHER)\n **cipher_list_by_id,\n const char *rule_str, CERT *c)\n{\n int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;\n uint32_t disabled_mkey, disabled_auth, disabled_enc, disabled_mac;\n STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list;\n const char *rule_p;\n CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;\n const SSL_CIPHER **ca_list = NULL;\n if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)\n return NULL;\n#ifndef OPENSSL_NO_EC\n if (!check_suiteb_cipher_list(ssl_method, c, &rule_str))\n return NULL;\n#endif\n disabled_mkey = disabled_mkey_mask;\n disabled_auth = disabled_auth_mask;\n disabled_enc = disabled_enc_mask;\n disabled_mac = disabled_mac_mask;\n num_of_ciphers = ssl_method->num_ciphers();\n co_list = OPENSSL_malloc(sizeof(*co_list) * num_of_ciphers);\n if (co_list == NULL) {\n SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,\n disabled_mkey, disabled_auth, disabled_enc,\n disabled_mac, co_list, &head, &tail);\n ssl_cipher_apply_rule(0, SSL_kECDHE, SSL_aECDSA, 0, 0, 0, 0, CIPHER_ADD,\n -1, &head, &tail);\n ssl_cipher_apply_rule(0, SSL_kECDHE, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head,\n &tail);\n ssl_cipher_apply_rule(0, SSL_kECDHE, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head,\n &tail);\n ssl_cipher_apply_rule(0, 0, 0, SSL_AESGCM, 0, 0, 0, CIPHER_ADD, -1,\n &head, &tail);\n ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20, 0, 0, 0, CIPHER_ADD, -1,\n &head, &tail);\n ssl_cipher_apply_rule(0, 0, 0, SSL_AES ^ SSL_AESGCM, 0, 0, 0, CIPHER_ADD,\n -1, &head, &tail);\n ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);\n ssl_cipher_apply_rule(0, 0, 0, 0, SSL_MD5, 0, 0, CIPHER_ORD, -1, &head,\n &tail);\n ssl_cipher_apply_rule(0, 0, SSL_aNULL, 0, 0, 0, 0, CIPHER_ORD, -1, &head,\n &tail);\n ssl_cipher_apply_rule(0, SSL_kRSA, 0, 0, 0, 0, 0, CIPHER_ORD, -1, &head,\n &tail);\n ssl_cipher_apply_rule(0, SSL_kPSK, 0, 0, 0, 0, 0, CIPHER_ORD, -1, &head,\n &tail);\n ssl_cipher_apply_rule(0, 0, 0, SSL_RC4, 0, 0, 0, CIPHER_ORD, -1, &head,\n &tail);\n if (!ssl_cipher_strength_sort(&head, &tail)) {\n OPENSSL_free(co_list);\n return NULL;\n }\n ssl_cipher_apply_rule(0, 0, 0, 0, 0, TLS1_2_VERSION, 0, CIPHER_BUMP, -1,\n &head, &tail);\n ssl_cipher_apply_rule(0, 0, 0, 0, SSL_AEAD, 0, 0, CIPHER_BUMP, -1,\n &head, &tail);\n ssl_cipher_apply_rule(0, SSL_kDHE | SSL_kECDHE, 0, 0, 0, 0, 0,\n CIPHER_BUMP, -1, &head, &tail);\n ssl_cipher_apply_rule(0, SSL_kDHE | SSL_kECDHE, 0, 0, SSL_AEAD, 0, 0,\n CIPHER_BUMP, -1, &head, &tail);\n ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);\n num_of_group_aliases = OSSL_NELEM(cipher_aliases);\n num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;\n ca_list = OPENSSL_malloc(sizeof(*ca_list) * num_of_alias_max);\n if (ca_list == NULL) {\n OPENSSL_free(co_list);\n SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ssl_cipher_collect_aliases(ca_list, num_of_group_aliases,\n disabled_mkey, disabled_auth, disabled_enc,\n disabled_mac, head);\n ok = 1;\n rule_p = rule_str;\n if (strncmp(rule_str, "DEFAULT", 7) == 0) {\n ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,\n &head, &tail, ca_list, c);\n rule_p += 7;\n if (*rule_p == \':\')\n rule_p++;\n }\n if (ok && (strlen(rule_p) > 0))\n ok = ssl_cipher_process_rulestr(rule_p, &head, &tail, ca_list, c);\n OPENSSL_free(ca_list);\n if (!ok) {\n OPENSSL_free(co_list);\n return (NULL);\n }\n if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) {\n OPENSSL_free(co_list);\n return (NULL);\n }\n for (curr = head; curr != NULL; curr = curr->next) {\n if (curr->active) {\n if (!sk_SSL_CIPHER_push(cipherstack, curr->cipher)) {\n OPENSSL_free(co_list);\n sk_SSL_CIPHER_free(cipherstack);\n return NULL;\n }\n#ifdef CIPHER_DEBUG\n fprintf(stderr, "<%s>\\n", curr->cipher->name);\n#endif\n }\n }\n OPENSSL_free(co_list);\n tmp_cipher_list = sk_SSL_CIPHER_dup(cipherstack);\n if (tmp_cipher_list == NULL) {\n sk_SSL_CIPHER_free(cipherstack);\n return NULL;\n }\n sk_SSL_CIPHER_free(*cipher_list);\n *cipher_list = cipherstack;\n if (*cipher_list_by_id != NULL)\n sk_SSL_CIPHER_free(*cipher_list_by_id);\n *cipher_list_by_id = tmp_cipher_list;\n (void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id, ssl_cipher_ptr_id_cmp);\n sk_SSL_CIPHER_sort(*cipher_list_by_id);\n return (cipherstack);\n}', 'static int check_suiteb_cipher_list(const SSL_METHOD *meth, CERT *c,\n const char **prule_str)\n{\n unsigned int suiteb_flags = 0, suiteb_comb2 = 0;\n if (strncmp(*prule_str, "SUITEB128ONLY", 13) == 0) {\n suiteb_flags = SSL_CERT_FLAG_SUITEB_128_LOS_ONLY;\n } else if (strncmp(*prule_str, "SUITEB128C2", 11) == 0) {\n suiteb_comb2 = 1;\n suiteb_flags = SSL_CERT_FLAG_SUITEB_128_LOS;\n } else if (strncmp(*prule_str, "SUITEB128", 9) == 0) {\n suiteb_flags = SSL_CERT_FLAG_SUITEB_128_LOS;\n } else if (strncmp(*prule_str, "SUITEB192", 9) == 0) {\n suiteb_flags = SSL_CERT_FLAG_SUITEB_192_LOS;\n }\n if (suiteb_flags) {\n c->cert_flags &= ~SSL_CERT_FLAG_SUITEB_128_LOS;\n c->cert_flags |= suiteb_flags;\n } else\n suiteb_flags = c->cert_flags & SSL_CERT_FLAG_SUITEB_128_LOS;\n if (!suiteb_flags)\n return 1;\n if (!(meth->ssl3_enc->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)) {\n SSLerr(SSL_F_CHECK_SUITEB_CIPHER_LIST,\n SSL_R_AT_LEAST_TLS_1_2_NEEDED_IN_SUITEB_MODE);\n return 0;\n }\n# ifndef OPENSSL_NO_EC\n switch (suiteb_flags) {\n case SSL_CERT_FLAG_SUITEB_128_LOS:\n if (suiteb_comb2)\n *prule_str = "ECDHE-ECDSA-AES256-GCM-SHA384";\n else\n *prule_str =\n "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384";\n break;\n case SSL_CERT_FLAG_SUITEB_128_LOS_ONLY:\n *prule_str = "ECDHE-ECDSA-AES128-GCM-SHA256";\n break;\n case SSL_CERT_FLAG_SUITEB_192_LOS:\n *prule_str = "ECDHE-ECDSA-AES256-GCM-SHA384";\n break;\n }\n return 1;\n# else\n SSLerr(SSL_F_CHECK_SUITEB_CIPHER_LIST, SSL_R_ECDH_REQUIRED_FOR_SUITEB_MODE);\n return 0;\n# endif\n}', 'static int ssl_cipher_process_rulestr(const char *rule_str,\n CIPHER_ORDER **head_p,\n CIPHER_ORDER **tail_p,\n const SSL_CIPHER **ca_list, CERT *c)\n{\n uint32_t alg_mkey, alg_auth, alg_enc, alg_mac, algo_strength;\n int min_tls;\n const char *l, *buf;\n int j, multi, found, rule, retval, ok, buflen;\n uint32_t cipher_id = 0;\n char ch;\n retval = 1;\n l = rule_str;\n for (;;) {\n ch = *l;\n if (ch == \'\\0\')\n break;\n if (ch == \'-\') {\n rule = CIPHER_DEL;\n l++;\n } else if (ch == \'+\') {\n rule = CIPHER_ORD;\n l++;\n } else if (ch == \'!\') {\n rule = CIPHER_KILL;\n l++;\n } else if (ch == \'@\') {\n rule = CIPHER_SPECIAL;\n l++;\n } else {\n rule = CIPHER_ADD;\n }\n if (ITEM_SEP(ch)) {\n l++;\n continue;\n }\n alg_mkey = 0;\n alg_auth = 0;\n alg_enc = 0;\n alg_mac = 0;\n min_tls = 0;\n algo_strength = 0;\n for (;;) {\n ch = *l;\n buf = l;\n buflen = 0;\n#ifndef CHARSET_EBCDIC\n while (((ch >= \'A\') && (ch <= \'Z\')) ||\n ((ch >= \'0\') && (ch <= \'9\')) ||\n ((ch >= \'a\') && (ch <= \'z\')) ||\n (ch == \'-\') || (ch == \'.\') || (ch == \'=\'))\n#else\n while (isalnum(ch) || (ch == \'-\') || (ch == \'.\') || (ch == \'=\'))\n#endif\n {\n ch = *(++l);\n buflen++;\n }\n if (buflen == 0) {\n SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, SSL_R_INVALID_COMMAND);\n retval = found = 0;\n l++;\n break;\n }\n if (rule == CIPHER_SPECIAL) {\n found = 0;\n break;\n }\n if (ch == \'+\') {\n multi = 1;\n l++;\n } else\n multi = 0;\n j = found = 0;\n cipher_id = 0;\n while (ca_list[j]) {\n if (strncmp(buf, ca_list[j]->name, buflen) == 0\n && (ca_list[j]->name[buflen] == \'\\0\')) {\n found = 1;\n break;\n } else\n j++;\n }\n if (!found)\n break;\n if (ca_list[j]->algorithm_mkey) {\n if (alg_mkey) {\n alg_mkey &= ca_list[j]->algorithm_mkey;\n if (!alg_mkey) {\n found = 0;\n break;\n }\n } else\n alg_mkey = ca_list[j]->algorithm_mkey;\n }\n if (ca_list[j]->algorithm_auth) {\n if (alg_auth) {\n alg_auth &= ca_list[j]->algorithm_auth;\n if (!alg_auth) {\n found = 0;\n break;\n }\n } else\n alg_auth = ca_list[j]->algorithm_auth;\n }\n if (ca_list[j]->algorithm_enc) {\n if (alg_enc) {\n alg_enc &= ca_list[j]->algorithm_enc;\n if (!alg_enc) {\n found = 0;\n break;\n }\n } else\n alg_enc = ca_list[j]->algorithm_enc;\n }\n if (ca_list[j]->algorithm_mac) {\n if (alg_mac) {\n alg_mac &= ca_list[j]->algorithm_mac;\n if (!alg_mac) {\n found = 0;\n break;\n }\n } else\n alg_mac = ca_list[j]->algorithm_mac;\n }\n if (ca_list[j]->algo_strength & SSL_STRONG_MASK) {\n if (algo_strength & SSL_STRONG_MASK) {\n algo_strength &=\n (ca_list[j]->algo_strength & SSL_STRONG_MASK) |\n ~SSL_STRONG_MASK;\n if (!(algo_strength & SSL_STRONG_MASK)) {\n found = 0;\n break;\n }\n } else\n algo_strength = ca_list[j]->algo_strength & SSL_STRONG_MASK;\n }\n if (ca_list[j]->algo_strength & SSL_DEFAULT_MASK) {\n if (algo_strength & SSL_DEFAULT_MASK) {\n algo_strength &=\n (ca_list[j]->algo_strength & SSL_DEFAULT_MASK) |\n ~SSL_DEFAULT_MASK;\n if (!(algo_strength & SSL_DEFAULT_MASK)) {\n found = 0;\n break;\n }\n } else\n algo_strength |=\n ca_list[j]->algo_strength & SSL_DEFAULT_MASK;\n }\n if (ca_list[j]->valid) {\n cipher_id = ca_list[j]->id;\n } else {\n if (ca_list[j]->min_tls) {\n if (min_tls != 0 && min_tls != ca_list[j]->min_tls) {\n found = 0;\n break;\n } else {\n min_tls = ca_list[j]->min_tls;\n }\n }\n }\n if (!multi)\n break;\n }\n if (rule == CIPHER_SPECIAL) {\n ok = 0;\n if ((buflen == 8) && strncmp(buf, "STRENGTH", 8) == 0)\n ok = ssl_cipher_strength_sort(head_p, tail_p);\n else if (buflen == 10 && strncmp(buf, "SECLEVEL=", 9) == 0) {\n int level = buf[9] - \'0\';\n if (level < 0 || level > 5) {\n SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,\n SSL_R_INVALID_COMMAND);\n } else {\n c->sec_level = level;\n ok = 1;\n }\n } else\n SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR, SSL_R_INVALID_COMMAND);\n if (ok == 0)\n retval = 0;\n while ((*l != \'\\0\') && !ITEM_SEP(*l))\n l++;\n } else if (found) {\n ssl_cipher_apply_rule(cipher_id,\n alg_mkey, alg_auth, alg_enc, alg_mac,\n min_tls, algo_strength, rule, -1, head_p,\n tail_p);\n } else {\n while ((*l != \'\\0\') && !ITEM_SEP(*l))\n l++;\n }\n if (*l == \'\\0\')\n break;\n }\n return (retval);\n}'] |
33,039 | 0 | https://github.com/openssl/openssl/blob/14c6d27d63795ead1b70d97e3303731b433c0db8/apps/ca.c/#L490 | int MAIN(int argc, char **argv)
{
ENGINE *e = NULL;
char *key=NULL,*passargin=NULL;
int total=0;
int total_done=0;
int badops=0;
int ret=1;
int req=0;
int verbose=0;
int gencrl=0;
int dorevoke=0;
long crldays=0;
long crlhours=0;
long errorline= -1;
char *configfile=NULL;
char *md=NULL;
char *policy=NULL;
char *keyfile=NULL;
char *certfile=NULL;
int keyform=FORMAT_PEM;
char *infile=NULL;
char *spkac_file=NULL;
char *ss_cert_file=NULL;
EVP_PKEY *pkey=NULL;
int output_der = 0;
char *outfile=NULL;
char *outdir=NULL;
char *serialfile=NULL;
char *extensions=NULL;
char *crl_ext=NULL;
BIGNUM *serial=NULL;
char *startdate=NULL;
char *enddate=NULL;
int days=0;
int batch=0;
int notext=0;
X509 *x509=NULL;
X509 *x=NULL;
BIO *in=NULL,*out=NULL,*Sout=NULL,*Cout=NULL;
char *dbfile=NULL;
TXT_DB *db=NULL;
X509_CRL *crl=NULL;
X509_CRL_INFO *ci=NULL;
X509_REVOKED *r=NULL;
char **pp,*p,*f;
int i,j;
long l;
const EVP_MD *dgst=NULL;
STACK_OF(CONF_VALUE) *attribs=NULL;
STACK_OF(X509) *cert_sk=NULL;
BIO *hex=NULL;
#undef BSIZE
#define BSIZE 256
MS_STATIC char buf[3][BSIZE];
char *randfile=NULL;
char *engine = NULL;
#ifdef EFENCE
EF_PROTECT_FREE=1;
EF_PROTECT_BELOW=1;
EF_ALIGNMENT=0;
#endif
apps_startup();
conf = NULL;
key = NULL;
section = NULL;
preserve=0;
msie_hack=0;
if (bio_err == NULL)
if ((bio_err=BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
argc--;
argv++;
while (argc >= 1)
{
if (strcmp(*argv,"-verbose") == 0)
verbose=1;
else if (strcmp(*argv,"-config") == 0)
{
if (--argc < 1) goto bad;
configfile= *(++argv);
}
else if (strcmp(*argv,"-name") == 0)
{
if (--argc < 1) goto bad;
section= *(++argv);
}
else if (strcmp(*argv,"-startdate") == 0)
{
if (--argc < 1) goto bad;
startdate= *(++argv);
}
else if (strcmp(*argv,"-enddate") == 0)
{
if (--argc < 1) goto bad;
enddate= *(++argv);
}
else if (strcmp(*argv,"-days") == 0)
{
if (--argc < 1) goto bad;
days=atoi(*(++argv));
}
else if (strcmp(*argv,"-md") == 0)
{
if (--argc < 1) goto bad;
md= *(++argv);
}
else if (strcmp(*argv,"-policy") == 0)
{
if (--argc < 1) goto bad;
policy= *(++argv);
}
else if (strcmp(*argv,"-keyfile") == 0)
{
if (--argc < 1) goto bad;
keyfile= *(++argv);
}
else if (strcmp(*argv,"-keyform") == 0)
{
if (--argc < 1) goto bad;
keyform=str2fmt(*(++argv));
}
else if (strcmp(*argv,"-passin") == 0)
{
if (--argc < 1) goto bad;
passargin= *(++argv);
}
else if (strcmp(*argv,"-key") == 0)
{
if (--argc < 1) goto bad;
key= *(++argv);
}
else if (strcmp(*argv,"-cert") == 0)
{
if (--argc < 1) goto bad;
certfile= *(++argv);
}
else if (strcmp(*argv,"-in") == 0)
{
if (--argc < 1) goto bad;
infile= *(++argv);
req=1;
}
else if (strcmp(*argv,"-out") == 0)
{
if (--argc < 1) goto bad;
outfile= *(++argv);
}
else if (strcmp(*argv,"-outdir") == 0)
{
if (--argc < 1) goto bad;
outdir= *(++argv);
}
else if (strcmp(*argv,"-notext") == 0)
notext=1;
else if (strcmp(*argv,"-batch") == 0)
batch=1;
else if (strcmp(*argv,"-preserveDN") == 0)
preserve=1;
else if (strcmp(*argv,"-gencrl") == 0)
gencrl=1;
else if (strcmp(*argv,"-msie_hack") == 0)
msie_hack=1;
else if (strcmp(*argv,"-crldays") == 0)
{
if (--argc < 1) goto bad;
crldays= atol(*(++argv));
}
else if (strcmp(*argv,"-crlhours") == 0)
{
if (--argc < 1) goto bad;
crlhours= atol(*(++argv));
}
else if (strcmp(*argv,"-infiles") == 0)
{
argc--;
argv++;
req=1;
break;
}
else if (strcmp(*argv, "-ss_cert") == 0)
{
if (--argc < 1) goto bad;
ss_cert_file = *(++argv);
req=1;
}
else if (strcmp(*argv, "-spkac") == 0)
{
if (--argc < 1) goto bad;
spkac_file = *(++argv);
req=1;
}
else if (strcmp(*argv,"-revoke") == 0)
{
if (--argc < 1) goto bad;
infile= *(++argv);
dorevoke=1;
}
else if (strcmp(*argv,"-extensions") == 0)
{
if (--argc < 1) goto bad;
extensions= *(++argv);
}
else if (strcmp(*argv,"-crlexts") == 0)
{
if (--argc < 1) goto bad;
crl_ext= *(++argv);
}
else if (strcmp(*argv,"-engine") == 0)
{
if (--argc < 1) goto bad;
engine= *(++argv);
}
else
{
bad:
BIO_printf(bio_err,"unknown option %s\n",*argv);
badops=1;
break;
}
argc--;
argv++;
}
if (badops)
{
for (pp=ca_usage; (*pp != NULL); pp++)
BIO_printf(bio_err,*pp);
goto err;
}
ERR_load_crypto_strings();
if (engine != NULL)
{
if((e = ENGINE_by_id(engine)) == NULL)
{
BIO_printf(bio_err,"invalid engine \"%s\"\n",
engine);
goto err;
}
if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
{
BIO_printf(bio_err,"can't use that engine\n");
goto err;
}
BIO_printf(bio_err,"engine \"%s\" set.\n", engine);
ENGINE_free(e);
}
if (configfile == NULL) configfile = getenv("OPENSSL_CONF");
if (configfile == NULL) configfile = getenv("SSLEAY_CONF");
if (configfile == NULL)
{
#ifdef VMS
strncpy(buf[0],X509_get_default_cert_area(),
sizeof(buf[0])-1-sizeof(CONFIG_FILE));
#else
strncpy(buf[0],X509_get_default_cert_area(),
sizeof(buf[0])-2-sizeof(CONFIG_FILE));
strcat(buf[0],"/");
#endif
strcat(buf[0],CONFIG_FILE);
configfile=buf[0];
}
BIO_printf(bio_err,"Using configuration from %s\n",configfile);
if ((conf=CONF_load(NULL,configfile,&errorline)) == NULL)
{
if (errorline <= 0)
BIO_printf(bio_err,"error loading the config file '%s'\n",
configfile);
else
BIO_printf(bio_err,"error on line %ld of config file '%s'\n"
,errorline,configfile);
goto err;
}
if (section == NULL)
{
section=CONF_get_string(conf,BASE_SECTION,ENV_DEFAULT_CA);
if (section == NULL)
{
lookup_fail(BASE_SECTION,ENV_DEFAULT_CA);
goto err;
}
}
if (conf != NULL)
{
p=CONF_get_string(conf,NULL,"oid_file");
if (p != NULL)
{
BIO *oid_bio;
oid_bio=BIO_new_file(p,"r");
if (oid_bio == NULL)
{
ERR_clear_error();
}
else
{
OBJ_create_objects(oid_bio);
BIO_free(oid_bio);
}
}
if(!add_oid_section(bio_err,conf))
{
ERR_print_errors(bio_err);
goto err;
}
}
randfile = CONF_get_string(conf, BASE_SECTION, "RANDFILE");
app_RAND_load_file(randfile, bio_err, 0);
in=BIO_new(BIO_s_file());
out=BIO_new(BIO_s_file());
Sout=BIO_new(BIO_s_file());
Cout=BIO_new(BIO_s_file());
if ((in == NULL) || (out == NULL) || (Sout == NULL) || (Cout == NULL))
{
ERR_print_errors(bio_err);
goto err;
}
if ((keyfile == NULL) && ((keyfile=CONF_get_string(conf,
section,ENV_PRIVATE_KEY)) == NULL))
{
lookup_fail(section,ENV_PRIVATE_KEY);
goto err;
}
if(!key && !app_passwd(bio_err, passargin, NULL, &key, NULL))
{
BIO_printf(bio_err,"Error getting password\n");
goto err;
}
if (keyform == FORMAT_ENGINE)
{
if (!e)
{
BIO_printf(bio_err,"no engine specified\n");
goto err;
}
pkey = ENGINE_load_private_key(e, keyfile, key);
}
else if (keyform == FORMAT_PEM)
{
if (BIO_read_filename(in,keyfile) <= 0)
{
perror(keyfile);
BIO_printf(bio_err,"trying to load CA private key\n");
goto err;
}
pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,key);
}
else
{
BIO_printf(bio_err,"bad input format specified for key file\n");
goto err;
}
if(key) memset(key,0,strlen(key));
if (pkey == NULL)
{
BIO_printf(bio_err,"unable to load CA private key\n");
goto err;
}
if ((certfile == NULL) && ((certfile=CONF_get_string(conf,
section,ENV_CERTIFICATE)) == NULL))
{
lookup_fail(section,ENV_CERTIFICATE);
goto err;
}
if (BIO_read_filename(in,certfile) <= 0)
{
perror(certfile);
BIO_printf(bio_err,"trying to load CA certificate\n");
goto err;
}
x509=PEM_read_bio_X509(in,NULL,NULL,NULL);
if (x509 == NULL)
{
BIO_printf(bio_err,"unable to load CA certificate\n");
goto err;
}
if (!X509_check_private_key(x509,pkey))
{
BIO_printf(bio_err,"CA certificate and CA private key do not match\n");
goto err;
}
f=CONF_get_string(conf,BASE_SECTION,ENV_PRESERVE);
if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
preserve=1;
f=CONF_get_string(conf,BASE_SECTION,ENV_MSIE_HACK);
if ((f != NULL) && ((*f == 'y') || (*f == 'Y')))
msie_hack=1;
if ((outdir == NULL) && (req))
{
struct stat sb;
if ((outdir=CONF_get_string(conf,section,ENV_NEW_CERTS_DIR))
== NULL)
{
BIO_printf(bio_err,"there needs to be defined a directory for new certificate to be placed in\n");
goto err;
}
#ifndef VMS
if (access(outdir,R_OK|W_OK|X_OK) != 0)
{
BIO_printf(bio_err,"I am unable to access the %s directory\n",outdir);
perror(outdir);
goto err;
}
if (stat(outdir,&sb) != 0)
{
BIO_printf(bio_err,"unable to stat(%s)\n",outdir);
perror(outdir);
goto err;
}
#ifdef S_IFDIR
if (!(sb.st_mode & S_IFDIR))
{
BIO_printf(bio_err,"%s need to be a directory\n",outdir);
perror(outdir);
goto err;
}
#endif
#endif
}
if ((dbfile=CONF_get_string(conf,section,ENV_DATABASE)) == NULL)
{
lookup_fail(section,ENV_DATABASE);
goto err;
}
if (BIO_read_filename(in,dbfile) <= 0)
{
perror(dbfile);
BIO_printf(bio_err,"unable to open '%s'\n",dbfile);
goto err;
}
db=TXT_DB_read(in,DB_NUMBER);
if (db == NULL) goto err;
for (i=0; i<sk_num(db->data); i++)
{
pp=(char **)sk_value(db->data,i);
if ((pp[DB_type][0] != DB_TYPE_REV) &&
(pp[DB_rev_date][0] != '\0'))
{
BIO_printf(bio_err,"entry %d: not revoked yet, but has a revocation date\n",i+1);
goto err;
}
if ((pp[DB_type][0] == DB_TYPE_REV) &&
!check_time_format(pp[DB_rev_date]))
{
BIO_printf(bio_err,"entry %d: invalid revocation date\n",
i+1);
goto err;
}
if (!check_time_format(pp[DB_exp_date]))
{
BIO_printf(bio_err,"entry %d: invalid expiry date\n",i+1);
goto err;
}
p=pp[DB_serial];
j=strlen(p);
if ((j&1) || (j < 2))
{
BIO_printf(bio_err,"entry %d: bad serial number length (%d)\n",i+1,j);
goto err;
}
while (*p)
{
if (!( ((*p >= '0') && (*p <= '9')) ||
((*p >= 'A') && (*p <= 'F')) ||
((*p >= 'a') && (*p <= 'f'))) )
{
BIO_printf(bio_err,"entry %d: bad serial number characters, char pos %ld, char is '%c'\n",i+1,(long)(p-pp[DB_serial]),*p);
goto err;
}
p++;
}
}
if (verbose)
{
BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT);
#ifdef VMS
{
BIO *tmpbio = BIO_new(BIO_f_linebuffer());
out = BIO_push(tmpbio, out);
}
#endif
TXT_DB_write(out,db);
BIO_printf(bio_err,"%d entries loaded from the database\n",
db->data->num);
BIO_printf(bio_err,"generating index\n");
}
if (!TXT_DB_create_index(db,DB_serial,NULL,index_serial_hash,
index_serial_cmp))
{
BIO_printf(bio_err,"error creating serial number index:(%ld,%ld,%ld)\n",db->error,db->arg1,db->arg2);
goto err;
}
if (!TXT_DB_create_index(db,DB_name,index_name_qual,index_name_hash,
index_name_cmp))
{
BIO_printf(bio_err,"error creating name index:(%ld,%ld,%ld)\n",
db->error,db->arg1,db->arg2);
goto err;
}
if (req || gencrl)
{
if (outfile != NULL)
{
if (BIO_write_filename(Sout,outfile) <= 0)
{
perror(outfile);
goto err;
}
}
else
{
BIO_set_fp(Sout,stdout,BIO_NOCLOSE|BIO_FP_TEXT);
#ifdef VMS
{
BIO *tmpbio = BIO_new(BIO_f_linebuffer());
Sout = BIO_push(tmpbio, Sout);
}
#endif
}
}
if (req)
{
if ((md == NULL) && ((md=CONF_get_string(conf,
section,ENV_DEFAULT_MD)) == NULL))
{
lookup_fail(section,ENV_DEFAULT_MD);
goto err;
}
if ((dgst=EVP_get_digestbyname(md)) == NULL)
{
BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
goto err;
}
if (verbose)
BIO_printf(bio_err,"message digest is %s\n",
OBJ_nid2ln(dgst->type));
if ((policy == NULL) && ((policy=CONF_get_string(conf,
section,ENV_POLICY)) == NULL))
{
lookup_fail(section,ENV_POLICY);
goto err;
}
if (verbose)
BIO_printf(bio_err,"policy is %s\n",policy);
if ((serialfile=CONF_get_string(conf,section,ENV_SERIAL))
== NULL)
{
lookup_fail(section,ENV_SERIAL);
goto err;
}
if(!extensions)
extensions=CONF_get_string(conf,section,ENV_EXTENSIONS);
if(extensions) {
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
X509V3_set_conf_lhash(&ctx, conf);
if(!X509V3_EXT_add_conf(conf, &ctx, extensions, NULL)) {
BIO_printf(bio_err,
"Error Loading extension section %s\n",
extensions);
ret = 1;
goto err;
}
}
if (startdate == NULL)
{
startdate=CONF_get_string(conf,section,
ENV_DEFAULT_STARTDATE);
}
if (startdate && !ASN1_UTCTIME_set_string(NULL,startdate))
{
BIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSSZ\n");
goto err;
}
if (startdate == NULL) startdate="today";
if (enddate == NULL)
{
enddate=CONF_get_string(conf,section,
ENV_DEFAULT_ENDDATE);
}
if (enddate && !ASN1_UTCTIME_set_string(NULL,enddate))
{
BIO_printf(bio_err,"end date is invalid, it should be YYMMDDHHMMSSZ\n");
goto err;
}
if (days == 0)
{
days=(int)CONF_get_number(conf,section,
ENV_DEFAULT_DAYS);
}
if (!enddate && (days == 0))
{
BIO_printf(bio_err,"cannot lookup how many days to certify for\n");
goto err;
}
if ((serial=load_serial(serialfile)) == NULL)
{
BIO_printf(bio_err,"error while loading serial number\n");
goto err;
}
if (verbose)
{
if ((f=BN_bn2hex(serial)) == NULL) goto err;
BIO_printf(bio_err,"next serial number is %s\n",f);
OPENSSL_free(f);
}
if ((attribs=CONF_get_section(conf,policy)) == NULL)
{
BIO_printf(bio_err,"unable to find 'section' for %s\n",policy);
goto err;
}
if ((cert_sk=sk_X509_new_null()) == NULL)
{
BIO_printf(bio_err,"Memory allocation failure\n");
goto err;
}
if (spkac_file != NULL)
{
total++;
j=certify_spkac(&x,spkac_file,pkey,x509,dgst,attribs,db,
serial,startdate,enddate, days,extensions,conf,
verbose);
if (j < 0) goto err;
if (j > 0)
{
total_done++;
BIO_printf(bio_err,"\n");
if (!BN_add_word(serial,1)) goto err;
if (!sk_X509_push(cert_sk,x))
{
BIO_printf(bio_err,"Memory allocation failure\n");
goto err;
}
if (outfile)
{
output_der = 1;
batch = 1;
}
}
}
if (ss_cert_file != NULL)
{
total++;
j=certify_cert(&x,ss_cert_file,pkey,x509,dgst,attribs,
db,serial,startdate,enddate,days,batch,
extensions,conf,verbose);
if (j < 0) goto err;
if (j > 0)
{
total_done++;
BIO_printf(bio_err,"\n");
if (!BN_add_word(serial,1)) goto err;
if (!sk_X509_push(cert_sk,x))
{
BIO_printf(bio_err,"Memory allocation failure\n");
goto err;
}
}
}
if (infile != NULL)
{
total++;
j=certify(&x,infile,pkey,x509,dgst,attribs,db,
serial,startdate,enddate,days,batch,
extensions,conf,verbose);
if (j < 0) goto err;
if (j > 0)
{
total_done++;
BIO_printf(bio_err,"\n");
if (!BN_add_word(serial,1)) goto err;
if (!sk_X509_push(cert_sk,x))
{
BIO_printf(bio_err,"Memory allocation failure\n");
goto err;
}
}
}
for (i=0; i<argc; i++)
{
total++;
j=certify(&x,argv[i],pkey,x509,dgst,attribs,db,
serial,startdate,enddate,days,batch,
extensions,conf,verbose);
if (j < 0) goto err;
if (j > 0)
{
total_done++;
BIO_printf(bio_err,"\n");
if (!BN_add_word(serial,1)) goto err;
if (!sk_X509_push(cert_sk,x))
{
BIO_printf(bio_err,"Memory allocation failure\n");
goto err;
}
}
}
if (sk_X509_num(cert_sk) > 0)
{
if (!batch)
{
BIO_printf(bio_err,"\n%d out of %d certificate requests certified, commit? [y/n]",total_done,total);
(void)BIO_flush(bio_err);
buf[0][0]='\0';
fgets(buf[0],10,stdin);
if ((buf[0][0] != 'y') && (buf[0][0] != 'Y'))
{
BIO_printf(bio_err,"CERTIFICATION CANCELED\n");
ret=0;
goto err;
}
}
BIO_printf(bio_err,"Write out database with %d new entries\n",sk_X509_num(cert_sk));
strncpy(buf[0],serialfile,BSIZE-4);
#ifdef VMS
strcat(buf[0],"-new");
#else
strcat(buf[0],".new");
#endif
if (!save_serial(buf[0],serial)) goto err;
strncpy(buf[1],dbfile,BSIZE-4);
#ifdef VMS
strcat(buf[1],"-new");
#else
strcat(buf[1],".new");
#endif
if (BIO_write_filename(out,buf[1]) <= 0)
{
perror(dbfile);
BIO_printf(bio_err,"unable to open '%s'\n",dbfile);
goto err;
}
l=TXT_DB_write(out,db);
if (l <= 0) goto err;
}
if (verbose)
BIO_printf(bio_err,"writing new certificates\n");
for (i=0; i<sk_X509_num(cert_sk); i++)
{
int k;
unsigned char *n;
x=sk_X509_value(cert_sk,i);
j=x->cert_info->serialNumber->length;
p=(char *)x->cert_info->serialNumber->data;
strncpy(buf[2],outdir,BSIZE-(j*2)-6);
#ifndef VMS
strcat(buf[2],"/");
#endif
n=(unsigned char *)&(buf[2][strlen(buf[2])]);
if (j > 0)
{
for (k=0; k<j; k++)
{
sprintf((char *)n,"%02X",(unsigned char)*(p++));
n+=2;
}
}
else
{
*(n++)='0';
*(n++)='0';
}
*(n++)='.'; *(n++)='p'; *(n++)='e'; *(n++)='m';
*n='\0';
if (verbose)
BIO_printf(bio_err,"writing %s\n",buf[2]);
if (BIO_write_filename(Cout,buf[2]) <= 0)
{
perror(buf[2]);
goto err;
}
write_new_certificate(Cout,x, 0, notext);
write_new_certificate(Sout,x, output_der, notext);
}
if (sk_X509_num(cert_sk))
{
strncpy(buf[2],serialfile,BSIZE-4);
#ifdef VMS
strcat(buf[2],"-old");
#else
strcat(buf[2],".old");
#endif
BIO_free(in);
BIO_free_all(out);
in=NULL;
out=NULL;
if (rename(serialfile,buf[2]) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n",
serialfile,buf[2]);
perror("reason");
goto err;
}
if (rename(buf[0],serialfile) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n",
buf[0],serialfile);
perror("reason");
rename(buf[2],serialfile);
goto err;
}
strncpy(buf[2],dbfile,BSIZE-4);
#ifdef VMS
strcat(buf[2],"-old");
#else
strcat(buf[2],".old");
#endif
if (rename(dbfile,buf[2]) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n",
dbfile,buf[2]);
perror("reason");
goto err;
}
if (rename(buf[1],dbfile) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n",
buf[1],dbfile);
perror("reason");
rename(buf[2],dbfile);
goto err;
}
BIO_printf(bio_err,"Data Base Updated\n");
}
}
if (gencrl)
{
if(!crl_ext) crl_ext=CONF_get_string(conf,section,ENV_CRLEXT);
if(crl_ext) {
X509V3_CTX ctx;
X509V3_set_ctx_test(&ctx);
X509V3_set_conf_lhash(&ctx, conf);
if(!X509V3_EXT_add_conf(conf, &ctx, crl_ext, NULL)) {
BIO_printf(bio_err,
"Error Loading CRL extension section %s\n",
crl_ext);
ret = 1;
goto err;
}
}
if ((hex=BIO_new(BIO_s_mem())) == NULL) goto err;
if (!crldays && !crlhours)
{
crldays=CONF_get_number(conf,section,
ENV_DEFAULT_CRL_DAYS);
crlhours=CONF_get_number(conf,section,
ENV_DEFAULT_CRL_HOURS);
}
if ((crldays == 0) && (crlhours == 0))
{
BIO_printf(bio_err,"cannot lookup how long until the next CRL is issuer\n");
goto err;
}
if (verbose) BIO_printf(bio_err,"making CRL\n");
if ((crl=X509_CRL_new()) == NULL) goto err;
ci=crl->crl;
X509_NAME_free(ci->issuer);
ci->issuer=X509_NAME_dup(x509->cert_info->subject);
if (ci->issuer == NULL) goto err;
X509_gmtime_adj(ci->lastUpdate,0);
if (ci->nextUpdate == NULL)
ci->nextUpdate=ASN1_UTCTIME_new();
X509_gmtime_adj(ci->nextUpdate,(crldays*24+crlhours)*60*60);
for (i=0; i<sk_num(db->data); i++)
{
pp=(char **)sk_value(db->data,i);
if (pp[DB_type][0] == DB_TYPE_REV)
{
if ((r=X509_REVOKED_new()) == NULL) goto err;
ASN1_STRING_set((ASN1_STRING *)
r->revocationDate,
(unsigned char *)pp[DB_rev_date],
strlen(pp[DB_rev_date]));
(void)BIO_reset(hex);
if (!BIO_puts(hex,pp[DB_serial]))
goto err;
if (!a2i_ASN1_INTEGER(hex,r->serialNumber,
buf[0],BSIZE)) goto err;
sk_X509_REVOKED_push(ci->revoked,r);
}
}
sk_X509_REVOKED_sort(ci->revoked);
for (i=0; i<sk_X509_REVOKED_num(ci->revoked); i++)
{
r=sk_X509_REVOKED_value(ci->revoked,i);
r->sequence=i;
}
if (verbose) BIO_printf(bio_err,"signing CRL\n");
if (md != NULL)
{
if ((dgst=EVP_get_digestbyname(md)) == NULL)
{
BIO_printf(bio_err,"%s is an unsupported message digest type\n",md);
goto err;
}
}
else
{
#ifndef NO_DSA
if (pkey->type == EVP_PKEY_DSA)
dgst=EVP_dss1();
else
#endif
dgst=EVP_md5();
}
if(crl_ext) {
X509V3_CTX crlctx;
if (ci->version == NULL)
if ((ci->version=ASN1_INTEGER_new()) == NULL) goto err;
ASN1_INTEGER_set(ci->version,1);
X509V3_set_ctx(&crlctx, x509, NULL, NULL, crl, 0);
X509V3_set_conf_lhash(&crlctx, conf);
if(!X509V3_EXT_CRL_add_conf(conf, &crlctx,
crl_ext, crl)) goto err;
}
if (!X509_CRL_sign(crl,pkey,dgst)) goto err;
PEM_write_bio_X509_CRL(Sout,crl);
}
if (dorevoke)
{
if (infile == NULL)
{
BIO_printf(bio_err,"no input files\n");
goto err;
}
else
{
X509 *revcert;
if (BIO_read_filename(in,infile) <= 0)
{
perror(infile);
BIO_printf(bio_err,"error trying to load '%s' certificate\n",infile);
goto err;
}
revcert=PEM_read_bio_X509(in,NULL,NULL,NULL);
if (revcert == NULL)
{
BIO_printf(bio_err,"unable to load '%s' certificate\n",infile);
goto err;
}
j=do_revoke(revcert,db);
if (j <= 0) goto err;
X509_free(revcert);
strncpy(buf[0],dbfile,BSIZE-4);
strcat(buf[0],".new");
if (BIO_write_filename(out,buf[0]) <= 0)
{
perror(dbfile);
BIO_printf(bio_err,"unable to open '%s'\n",dbfile);
goto err;
}
j=TXT_DB_write(out,db);
if (j <= 0) goto err;
strncpy(buf[1],dbfile,BSIZE-4);
strcat(buf[1],".old");
if (rename(dbfile,buf[1]) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n", dbfile, buf[1]);
perror("reason");
goto err;
}
if (rename(buf[0],dbfile) < 0)
{
BIO_printf(bio_err,"unable to rename %s to %s\n", buf[0],dbfile);
perror("reason");
rename(buf[1],dbfile);
goto err;
}
BIO_printf(bio_err,"Data Base Updated\n");
}
}
ret=0;
err:
BIO_free(hex);
BIO_free_all(Cout);
BIO_free_all(Sout);
BIO_free_all(out);
BIO_free(in);
sk_X509_pop_free(cert_sk,X509_free);
if (ret) ERR_print_errors(bio_err);
app_RAND_write_file(randfile, bio_err);
BN_free(serial);
TXT_DB_free(db);
EVP_PKEY_free(pkey);
X509_free(x509);
X509_CRL_free(crl);
CONF_free(conf);
OBJ_cleanup();
EXIT(ret);
} | ['int MAIN(int argc, char **argv)\n\t{\n\tENGINE *e = NULL;\n\tchar *key=NULL,*passargin=NULL;\n\tint total=0;\n\tint total_done=0;\n\tint badops=0;\n\tint ret=1;\n\tint req=0;\n\tint verbose=0;\n\tint gencrl=0;\n\tint dorevoke=0;\n\tlong crldays=0;\n\tlong crlhours=0;\n\tlong errorline= -1;\n\tchar *configfile=NULL;\n\tchar *md=NULL;\n\tchar *policy=NULL;\n\tchar *keyfile=NULL;\n\tchar *certfile=NULL;\n\tint keyform=FORMAT_PEM;\n\tchar *infile=NULL;\n\tchar *spkac_file=NULL;\n\tchar *ss_cert_file=NULL;\n\tEVP_PKEY *pkey=NULL;\n\tint output_der = 0;\n\tchar *outfile=NULL;\n\tchar *outdir=NULL;\n\tchar *serialfile=NULL;\n\tchar *extensions=NULL;\n\tchar *crl_ext=NULL;\n\tBIGNUM *serial=NULL;\n\tchar *startdate=NULL;\n\tchar *enddate=NULL;\n\tint days=0;\n\tint batch=0;\n\tint notext=0;\n\tX509 *x509=NULL;\n\tX509 *x=NULL;\n\tBIO *in=NULL,*out=NULL,*Sout=NULL,*Cout=NULL;\n\tchar *dbfile=NULL;\n\tTXT_DB *db=NULL;\n\tX509_CRL *crl=NULL;\n\tX509_CRL_INFO *ci=NULL;\n\tX509_REVOKED *r=NULL;\n\tchar **pp,*p,*f;\n\tint i,j;\n\tlong l;\n\tconst EVP_MD *dgst=NULL;\n\tSTACK_OF(CONF_VALUE) *attribs=NULL;\n\tSTACK_OF(X509) *cert_sk=NULL;\n\tBIO *hex=NULL;\n#undef BSIZE\n#define BSIZE 256\n\tMS_STATIC char buf[3][BSIZE];\n\tchar *randfile=NULL;\n\tchar *engine = NULL;\n#ifdef EFENCE\nEF_PROTECT_FREE=1;\nEF_PROTECT_BELOW=1;\nEF_ALIGNMENT=0;\n#endif\n\tapps_startup();\n\tconf = NULL;\n\tkey = NULL;\n\tsection = NULL;\n\tpreserve=0;\n\tmsie_hack=0;\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\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif\t(strcmp(*argv,"-verbose") == 0)\n\t\t\tverbose=1;\n\t\telse if\t(strcmp(*argv,"-config") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tconfigfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-name") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsection= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-startdate") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tstartdate= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-enddate") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tenddate= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-days") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tdays=atoi(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-md") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tmd= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-policy") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpolicy= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyform=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-passin") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpassargin= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkey= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcertfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\treq=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outdir") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutdir= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-notext") == 0)\n\t\t\tnotext=1;\n\t\telse if (strcmp(*argv,"-batch") == 0)\n\t\t\tbatch=1;\n\t\telse if (strcmp(*argv,"-preserveDN") == 0)\n\t\t\tpreserve=1;\n\t\telse if (strcmp(*argv,"-gencrl") == 0)\n\t\t\tgencrl=1;\n\t\telse if (strcmp(*argv,"-msie_hack") == 0)\n\t\t\tmsie_hack=1;\n\t\telse if (strcmp(*argv,"-crldays") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcrldays= atol(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-crlhours") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcrlhours= atol(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-infiles") == 0)\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\treq=1;\n\t\t\tbreak;\n\t\t\t}\n\t\telse if (strcmp(*argv, "-ss_cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tss_cert_file = *(++argv);\n\t\t\treq=1;\n\t\t\t}\n\t\telse if (strcmp(*argv, "-spkac") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tspkac_file = *(++argv);\n\t\t\treq=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-revoke") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\tdorevoke=1;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-extensions") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\textensions= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-crlexts") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcrl_ext= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tengine= *(++argv);\n\t\t\t}\n\t\telse\n\t\t\t{\nbad:\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\n\t\tfor (pp=ca_usage; (*pp != NULL); pp++)\n\t\t\tBIO_printf(bio_err,*pp);\n\t\tgoto err;\n\t\t}\n\tERR_load_crypto_strings();\n\tif (engine != NULL)\n\t\t{\n\t\tif((e = ENGINE_by_id(engine)) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"invalid engine \\"%s\\"\\n",\n\t\t\t\tengine);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif(!ENGINE_set_default(e, ENGINE_METHOD_ALL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"can\'t use that engine\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tBIO_printf(bio_err,"engine \\"%s\\" set.\\n", engine);\n\t\tENGINE_free(e);\n\t\t}\n\tif (configfile == NULL) configfile = getenv("OPENSSL_CONF");\n\tif (configfile == NULL) configfile = getenv("SSLEAY_CONF");\n\tif (configfile == NULL)\n\t\t{\n#ifdef VMS\n\t\tstrncpy(buf[0],X509_get_default_cert_area(),\n\t\t\tsizeof(buf[0])-1-sizeof(CONFIG_FILE));\n#else\n\t\tstrncpy(buf[0],X509_get_default_cert_area(),\n\t\t\tsizeof(buf[0])-2-sizeof(CONFIG_FILE));\n\t\tstrcat(buf[0],"/");\n#endif\n\t\tstrcat(buf[0],CONFIG_FILE);\n\t\tconfigfile=buf[0];\n\t\t}\n\tBIO_printf(bio_err,"Using configuration from %s\\n",configfile);\n\tif ((conf=CONF_load(NULL,configfile,&errorline)) == NULL)\n\t\t{\n\t\tif (errorline <= 0)\n\t\t\tBIO_printf(bio_err,"error loading the config file \'%s\'\\n",\n\t\t\t\tconfigfile);\n\t\telse\n\t\t\tBIO_printf(bio_err,"error on line %ld of config file \'%s\'\\n"\n\t\t\t\t,errorline,configfile);\n\t\tgoto err;\n\t\t}\n\tif (section == NULL)\n\t\t{\n\t\tsection=CONF_get_string(conf,BASE_SECTION,ENV_DEFAULT_CA);\n\t\tif (section == NULL)\n\t\t\t{\n\t\t\tlookup_fail(BASE_SECTION,ENV_DEFAULT_CA);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (conf != NULL)\n\t\t{\n\t\tp=CONF_get_string(conf,NULL,"oid_file");\n\t\tif (p != NULL)\n\t\t\t{\n\t\t\tBIO *oid_bio;\n\t\t\toid_bio=BIO_new_file(p,"r");\n\t\t\tif (oid_bio == NULL)\n\t\t\t\t{\n\t\t\t\tERR_clear_error();\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tOBJ_create_objects(oid_bio);\n\t\t\t\tBIO_free(oid_bio);\n\t\t\t\t}\n\t\t\t}\n\t\tif(!add_oid_section(bio_err,conf))\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\trandfile = CONF_get_string(conf, BASE_SECTION, "RANDFILE");\n\tapp_RAND_load_file(randfile, bio_err, 0);\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tSout=BIO_new(BIO_s_file());\n\tCout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL) || (Sout == NULL) || (Cout == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto err;\n\t\t}\n\tif ((keyfile == NULL) && ((keyfile=CONF_get_string(conf,\n\t\tsection,ENV_PRIVATE_KEY)) == NULL))\n\t\t{\n\t\tlookup_fail(section,ENV_PRIVATE_KEY);\n\t\tgoto err;\n\t\t}\n\tif(!key && !app_passwd(bio_err, passargin, NULL, &key, NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"Error getting password\\n");\n\t\tgoto err;\n\t\t}\n\tif (keyform == FORMAT_ENGINE)\n\t\t{\n\t\tif (!e)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"no engine specified\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tpkey = ENGINE_load_private_key(e, keyfile, key);\n\t\t}\n\telse if (keyform == FORMAT_PEM)\n\t\t{\n\t\tif (BIO_read_filename(in,keyfile) <= 0)\n\t\t\t{\n\t\t\tperror(keyfile);\n\t\t\tBIO_printf(bio_err,"trying to load CA private key\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tpkey=PEM_read_bio_PrivateKey(in,NULL,NULL,key);\n\t\t}\n\telse\n\t\t{\n\t\tBIO_printf(bio_err,"bad input format specified for key file\\n");\n\t\tgoto err;\n\t\t}\n\tif(key) memset(key,0,strlen(key));\n\tif (pkey == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to load CA private key\\n");\n\t\tgoto err;\n\t\t}\n\tif ((certfile == NULL) && ((certfile=CONF_get_string(conf,\n\t\tsection,ENV_CERTIFICATE)) == NULL))\n\t\t{\n\t\tlookup_fail(section,ENV_CERTIFICATE);\n\t\tgoto err;\n\t\t}\n if (BIO_read_filename(in,certfile) <= 0)\n\t\t{\n\t\tperror(certfile);\n\t\tBIO_printf(bio_err,"trying to load CA certificate\\n");\n\t\tgoto err;\n\t\t}\n\tx509=PEM_read_bio_X509(in,NULL,NULL,NULL);\n\tif (x509 == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"unable to load CA certificate\\n");\n\t\tgoto err;\n\t\t}\n\tif (!X509_check_private_key(x509,pkey))\n\t\t{\n\t\tBIO_printf(bio_err,"CA certificate and CA private key do not match\\n");\n\t\tgoto err;\n\t\t}\n\tf=CONF_get_string(conf,BASE_SECTION,ENV_PRESERVE);\n\tif ((f != NULL) && ((*f == \'y\') || (*f == \'Y\')))\n\t\tpreserve=1;\n\tf=CONF_get_string(conf,BASE_SECTION,ENV_MSIE_HACK);\n\tif ((f != NULL) && ((*f == \'y\') || (*f == \'Y\')))\n\t\tmsie_hack=1;\n\tif ((outdir == NULL) && (req))\n\t\t{\n\t\tstruct stat sb;\n\t\tif ((outdir=CONF_get_string(conf,section,ENV_NEW_CERTS_DIR))\n\t\t\t== NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"there needs to be defined a directory for new certificate to be placed in\\n");\n\t\t\tgoto err;\n\t\t\t}\n#ifndef VMS\n\t\tif (access(outdir,R_OK|W_OK|X_OK) != 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"I am unable to access the %s directory\\n",outdir);\n\t\t\tperror(outdir);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (stat(outdir,&sb) != 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to stat(%s)\\n",outdir);\n\t\t\tperror(outdir);\n\t\t\tgoto err;\n\t\t\t}\n#ifdef S_IFDIR\n\t\tif (!(sb.st_mode & S_IFDIR))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"%s need to be a directory\\n",outdir);\n\t\t\tperror(outdir);\n\t\t\tgoto err;\n\t\t\t}\n#endif\n#endif\n\t\t}\n\tif ((dbfile=CONF_get_string(conf,section,ENV_DATABASE)) == NULL)\n\t\t{\n\t\tlookup_fail(section,ENV_DATABASE);\n\t\tgoto err;\n\t\t}\n\tif (BIO_read_filename(in,dbfile) <= 0)\n\t\t{\n\t\tperror(dbfile);\n\t\tBIO_printf(bio_err,"unable to open \'%s\'\\n",dbfile);\n\t\tgoto err;\n\t\t}\n\tdb=TXT_DB_read(in,DB_NUMBER);\n\tif (db == NULL) goto err;\n\tfor (i=0; i<sk_num(db->data); i++)\n\t\t{\n\t\tpp=(char **)sk_value(db->data,i);\n\t\tif ((pp[DB_type][0] != DB_TYPE_REV) &&\n\t\t\t(pp[DB_rev_date][0] != \'\\0\'))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"entry %d: not revoked yet, but has a revocation date\\n",i+1);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif ((pp[DB_type][0] == DB_TYPE_REV) &&\n\t\t\t!check_time_format(pp[DB_rev_date]))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"entry %d: invalid revocation date\\n",\n\t\t\t\ti+1);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!check_time_format(pp[DB_exp_date]))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"entry %d: invalid expiry date\\n",i+1);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp=pp[DB_serial];\n\t\tj=strlen(p);\n\t\tif ((j&1) || (j < 2))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"entry %d: bad serial number length (%d)\\n",i+1,j);\n\t\t\tgoto err;\n\t\t\t}\n\t\twhile (*p)\n\t\t\t{\n\t\t\tif (!(\t((*p >= \'0\') && (*p <= \'9\')) ||\n\t\t\t\t((*p >= \'A\') && (*p <= \'F\')) ||\n\t\t\t\t((*p >= \'a\') && (*p <= \'f\'))) )\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"entry %d: bad serial number characters, char pos %ld, char is \'%c\'\\n",i+1,(long)(p-pp[DB_serial]),*p);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tp++;\n\t\t\t}\n\t\t}\n\tif (verbose)\n\t\t{\n\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT);\n#ifdef 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\tTXT_DB_write(out,db);\n\t\tBIO_printf(bio_err,"%d entries loaded from the database\\n",\n\t\t\tdb->data->num);\n\t\tBIO_printf(bio_err,"generating index\\n");\n\t\t}\n\tif (!TXT_DB_create_index(db,DB_serial,NULL,index_serial_hash,\n\t\tindex_serial_cmp))\n\t\t{\n\t\tBIO_printf(bio_err,"error creating serial number index:(%ld,%ld,%ld)\\n",db->error,db->arg1,db->arg2);\n\t\tgoto err;\n\t\t}\n\tif (!TXT_DB_create_index(db,DB_name,index_name_qual,index_name_hash,\n\t\tindex_name_cmp))\n\t\t{\n\t\tBIO_printf(bio_err,"error creating name index:(%ld,%ld,%ld)\\n",\n\t\t\tdb->error,db->arg1,db->arg2);\n\t\tgoto err;\n\t\t}\n\tif (req || gencrl)\n\t\t{\n\t\tif (outfile != NULL)\n\t\t\t{\n\t\t\tif (BIO_write_filename(Sout,outfile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(outfile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_set_fp(Sout,stdout,BIO_NOCLOSE|BIO_FP_TEXT);\n#ifdef VMS\n\t\t\t{\n\t\t\tBIO *tmpbio = BIO_new(BIO_f_linebuffer());\n\t\t\tSout = BIO_push(tmpbio, Sout);\n\t\t\t}\n#endif\n\t\t\t}\n\t\t}\n\tif (req)\n\t\t{\n\t\tif ((md == NULL) && ((md=CONF_get_string(conf,\n\t\t\tsection,ENV_DEFAULT_MD)) == NULL))\n\t\t\t{\n\t\t\tlookup_fail(section,ENV_DEFAULT_MD);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif ((dgst=EVP_get_digestbyname(md)) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"%s is an unsupported message digest type\\n",md);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (verbose)\n\t\t\tBIO_printf(bio_err,"message digest is %s\\n",\n\t\t\t\tOBJ_nid2ln(dgst->type));\n\t\tif ((policy == NULL) && ((policy=CONF_get_string(conf,\n\t\t\tsection,ENV_POLICY)) == NULL))\n\t\t\t{\n\t\t\tlookup_fail(section,ENV_POLICY);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (verbose)\n\t\t\tBIO_printf(bio_err,"policy is %s\\n",policy);\n\t\tif ((serialfile=CONF_get_string(conf,section,ENV_SERIAL))\n\t\t\t== NULL)\n\t\t\t{\n\t\t\tlookup_fail(section,ENV_SERIAL);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif(!extensions)\n\t\t\textensions=CONF_get_string(conf,section,ENV_EXTENSIONS);\n\t\tif(extensions) {\n\t\t\tX509V3_CTX ctx;\n\t\t\tX509V3_set_ctx_test(&ctx);\n\t\t\tX509V3_set_conf_lhash(&ctx, conf);\n\t\t\tif(!X509V3_EXT_add_conf(conf, &ctx, extensions, NULL)) {\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t "Error Loading extension section %s\\n",\n\t\t\t\t\t\t\t\t extensions);\n\t\t\t\tret = 1;\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\t\tif (startdate == NULL)\n\t\t\t{\n\t\t\tstartdate=CONF_get_string(conf,section,\n\t\t\t\tENV_DEFAULT_STARTDATE);\n\t\t\t}\n\t\tif (startdate && !ASN1_UTCTIME_set_string(NULL,startdate))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"start date is invalid, it should be YYMMDDHHMMSSZ\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (startdate == NULL) startdate="today";\n\t\tif (enddate == NULL)\n\t\t\t{\n\t\t\tenddate=CONF_get_string(conf,section,\n\t\t\t\tENV_DEFAULT_ENDDATE);\n\t\t\t}\n\t\tif (enddate && !ASN1_UTCTIME_set_string(NULL,enddate))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"end date is invalid, it should be YYMMDDHHMMSSZ\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (days == 0)\n\t\t\t{\n\t\t\tdays=(int)CONF_get_number(conf,section,\n\t\t\t\tENV_DEFAULT_DAYS);\n\t\t\t}\n\t\tif (!enddate && (days == 0))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"cannot lookup how many days to certify for\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif ((serial=load_serial(serialfile)) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"error while loading serial number\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (verbose)\n\t\t\t{\n\t\t\tif ((f=BN_bn2hex(serial)) == NULL) goto err;\n\t\t\tBIO_printf(bio_err,"next serial number is %s\\n",f);\n\t\t\tOPENSSL_free(f);\n\t\t\t}\n\t\tif ((attribs=CONF_get_section(conf,policy)) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to find \'section\' for %s\\n",policy);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif ((cert_sk=sk_X509_new_null()) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Memory allocation failure\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (spkac_file != NULL)\n\t\t\t{\n\t\t\ttotal++;\n\t\t\tj=certify_spkac(&x,spkac_file,pkey,x509,dgst,attribs,db,\n\t\t\t\tserial,startdate,enddate, days,extensions,conf,\n\t\t\t\tverbose);\n\t\t\tif (j < 0) goto err;\n\t\t\tif (j > 0)\n\t\t\t\t{\n\t\t\t\ttotal_done++;\n\t\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t\tif (!BN_add_word(serial,1)) goto err;\n\t\t\t\tif (!sk_X509_push(cert_sk,x))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Memory allocation failure\\n");\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif (outfile)\n\t\t\t\t\t{\n\t\t\t\t\toutput_der = 1;\n\t\t\t\t\tbatch = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif (ss_cert_file != NULL)\n\t\t\t{\n\t\t\ttotal++;\n\t\t\tj=certify_cert(&x,ss_cert_file,pkey,x509,dgst,attribs,\n\t\t\t\tdb,serial,startdate,enddate,days,batch,\n\t\t\t\textensions,conf,verbose);\n\t\t\tif (j < 0) goto err;\n\t\t\tif (j > 0)\n\t\t\t\t{\n\t\t\t\ttotal_done++;\n\t\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t\tif (!BN_add_word(serial,1)) goto err;\n\t\t\t\tif (!sk_X509_push(cert_sk,x))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Memory allocation failure\\n");\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif (infile != NULL)\n\t\t\t{\n\t\t\ttotal++;\n\t\t\tj=certify(&x,infile,pkey,x509,dgst,attribs,db,\n\t\t\t\tserial,startdate,enddate,days,batch,\n\t\t\t\textensions,conf,verbose);\n\t\t\tif (j < 0) goto err;\n\t\t\tif (j > 0)\n\t\t\t\t{\n\t\t\t\ttotal_done++;\n\t\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t\tif (!BN_add_word(serial,1)) goto err;\n\t\t\t\tif (!sk_X509_push(cert_sk,x))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Memory allocation failure\\n");\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tfor (i=0; i<argc; i++)\n\t\t\t{\n\t\t\ttotal++;\n\t\t\tj=certify(&x,argv[i],pkey,x509,dgst,attribs,db,\n\t\t\t\tserial,startdate,enddate,days,batch,\n\t\t\t\textensions,conf,verbose);\n\t\t\tif (j < 0) goto err;\n\t\t\tif (j > 0)\n\t\t\t\t{\n\t\t\t\ttotal_done++;\n\t\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t\tif (!BN_add_word(serial,1)) goto err;\n\t\t\t\tif (!sk_X509_push(cert_sk,x))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Memory allocation failure\\n");\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif (sk_X509_num(cert_sk) > 0)\n\t\t\t{\n\t\t\tif (!batch)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"\\n%d out of %d certificate requests certified, commit? [y/n]",total_done,total);\n\t\t\t\t(void)BIO_flush(bio_err);\n\t\t\t\tbuf[0][0]=\'\\0\';\n\t\t\t\tfgets(buf[0],10,stdin);\n\t\t\t\tif ((buf[0][0] != \'y\') && (buf[0][0] != \'Y\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"CERTIFICATION CANCELED\\n");\n\t\t\t\t\tret=0;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tBIO_printf(bio_err,"Write out database with %d new entries\\n",sk_X509_num(cert_sk));\n\t\t\tstrncpy(buf[0],serialfile,BSIZE-4);\n#ifdef VMS\n\t\t\tstrcat(buf[0],"-new");\n#else\n\t\t\tstrcat(buf[0],".new");\n#endif\n\t\t\tif (!save_serial(buf[0],serial)) goto err;\n\t\t\tstrncpy(buf[1],dbfile,BSIZE-4);\n#ifdef VMS\n\t\t\tstrcat(buf[1],"-new");\n#else\n\t\t\tstrcat(buf[1],".new");\n#endif\n\t\t\tif (BIO_write_filename(out,buf[1]) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(dbfile);\n\t\t\t\tBIO_printf(bio_err,"unable to open \'%s\'\\n",dbfile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tl=TXT_DB_write(out,db);\n\t\t\tif (l <= 0) goto err;\n\t\t\t}\n\t\tif (verbose)\n\t\t\tBIO_printf(bio_err,"writing new certificates\\n");\n\t\tfor (i=0; i<sk_X509_num(cert_sk); i++)\n\t\t\t{\n\t\t\tint k;\n\t\t\tunsigned char *n;\n\t\t\tx=sk_X509_value(cert_sk,i);\n\t\t\tj=x->cert_info->serialNumber->length;\n\t\t\tp=(char *)x->cert_info->serialNumber->data;\n\t\t\tstrncpy(buf[2],outdir,BSIZE-(j*2)-6);\n#ifndef VMS\n\t\t\tstrcat(buf[2],"/");\n#endif\n\t\t\tn=(unsigned char *)&(buf[2][strlen(buf[2])]);\n\t\t\tif (j > 0)\n\t\t\t\t{\n\t\t\t\tfor (k=0; k<j; k++)\n\t\t\t\t\t{\n\t\t\t\t\tsprintf((char *)n,"%02X",(unsigned char)*(p++));\n\t\t\t\t\tn+=2;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\t*(n++)=\'0\';\n\t\t\t\t*(n++)=\'0\';\n\t\t\t\t}\n\t\t\t*(n++)=\'.\'; *(n++)=\'p\'; *(n++)=\'e\'; *(n++)=\'m\';\n\t\t\t*n=\'\\0\';\n\t\t\tif (verbose)\n\t\t\t\tBIO_printf(bio_err,"writing %s\\n",buf[2]);\n\t\t\tif (BIO_write_filename(Cout,buf[2]) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(buf[2]);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\twrite_new_certificate(Cout,x, 0, notext);\n\t\t\twrite_new_certificate(Sout,x, output_der, notext);\n\t\t\t}\n\t\tif (sk_X509_num(cert_sk))\n\t\t\t{\n\t\t\tstrncpy(buf[2],serialfile,BSIZE-4);\n#ifdef VMS\n\t\t\tstrcat(buf[2],"-old");\n#else\n\t\t\tstrcat(buf[2],".old");\n#endif\n\t\t\tBIO_free(in);\n\t\t\tBIO_free_all(out);\n\t\t\tin=NULL;\n\t\t\tout=NULL;\n\t\t\tif (rename(serialfile,buf[2]) < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to rename %s to %s\\n",\n\t\t\t\t\tserialfile,buf[2]);\n\t\t\t\tperror("reason");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (rename(buf[0],serialfile) < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to rename %s to %s\\n",\n\t\t\t\t\tbuf[0],serialfile);\n\t\t\t\tperror("reason");\n\t\t\t\trename(buf[2],serialfile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tstrncpy(buf[2],dbfile,BSIZE-4);\n#ifdef VMS\n\t\t\tstrcat(buf[2],"-old");\n#else\n\t\t\tstrcat(buf[2],".old");\n#endif\n\t\t\tif (rename(dbfile,buf[2]) < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to rename %s to %s\\n",\n\t\t\t\t\tdbfile,buf[2]);\n\t\t\t\tperror("reason");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (rename(buf[1],dbfile) < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to rename %s to %s\\n",\n\t\t\t\t\tbuf[1],dbfile);\n\t\t\t\tperror("reason");\n\t\t\t\trename(buf[2],dbfile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tBIO_printf(bio_err,"Data Base Updated\\n");\n\t\t\t}\n\t\t}\n\tif (gencrl)\n\t\t{\n\t\tif(!crl_ext) crl_ext=CONF_get_string(conf,section,ENV_CRLEXT);\n\t\tif(crl_ext) {\n\t\t\tX509V3_CTX ctx;\n\t\t\tX509V3_set_ctx_test(&ctx);\n\t\t\tX509V3_set_conf_lhash(&ctx, conf);\n\t\t\tif(!X509V3_EXT_add_conf(conf, &ctx, crl_ext, NULL)) {\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t "Error Loading CRL extension section %s\\n",\n\t\t\t\t\t\t\t\t crl_ext);\n\t\t\t\tret = 1;\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\t\tif ((hex=BIO_new(BIO_s_mem())) == NULL) goto err;\n\t\tif (!crldays && !crlhours)\n\t\t\t{\n\t\t\tcrldays=CONF_get_number(conf,section,\n\t\t\t\tENV_DEFAULT_CRL_DAYS);\n\t\t\tcrlhours=CONF_get_number(conf,section,\n\t\t\t\tENV_DEFAULT_CRL_HOURS);\n\t\t\t}\n\t\tif ((crldays == 0) && (crlhours == 0))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"cannot lookup how long until the next CRL is issuer\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (verbose) BIO_printf(bio_err,"making CRL\\n");\n\t\tif ((crl=X509_CRL_new()) == NULL) goto err;\n\t\tci=crl->crl;\n\t\tX509_NAME_free(ci->issuer);\n\t\tci->issuer=X509_NAME_dup(x509->cert_info->subject);\n\t\tif (ci->issuer == NULL) goto err;\n\t\tX509_gmtime_adj(ci->lastUpdate,0);\n\t\tif (ci->nextUpdate == NULL)\n\t\t\tci->nextUpdate=ASN1_UTCTIME_new();\n\t\tX509_gmtime_adj(ci->nextUpdate,(crldays*24+crlhours)*60*60);\n\t\tfor (i=0; i<sk_num(db->data); i++)\n\t\t\t{\n\t\t\tpp=(char **)sk_value(db->data,i);\n\t\t\tif (pp[DB_type][0] == DB_TYPE_REV)\n\t\t\t\t{\n\t\t\t\tif ((r=X509_REVOKED_new()) == NULL) goto err;\n\t\t\t\tASN1_STRING_set((ASN1_STRING *)\n\t\t\t\t\tr->revocationDate,\n\t\t\t\t\t(unsigned char *)pp[DB_rev_date],\n\t\t\t\t\tstrlen(pp[DB_rev_date]));\n\t\t\t\t(void)BIO_reset(hex);\n\t\t\t\tif (!BIO_puts(hex,pp[DB_serial]))\n\t\t\t\t\tgoto err;\n\t\t\t\tif (!a2i_ASN1_INTEGER(hex,r->serialNumber,\n\t\t\t\t\tbuf[0],BSIZE)) goto err;\n\t\t\t\tsk_X509_REVOKED_push(ci->revoked,r);\n\t\t\t\t}\n\t\t\t}\n\t\tsk_X509_REVOKED_sort(ci->revoked);\n\t\tfor (i=0; i<sk_X509_REVOKED_num(ci->revoked); i++)\n\t\t\t{\n\t\t\tr=sk_X509_REVOKED_value(ci->revoked,i);\n\t\t\tr->sequence=i;\n\t\t\t}\n\t\tif (verbose) BIO_printf(bio_err,"signing CRL\\n");\n\t\tif (md != NULL)\n\t\t\t{\n\t\t\tif ((dgst=EVP_get_digestbyname(md)) == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"%s is an unsupported message digest type\\n",md);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t {\n#ifndef NO_DSA\n\t\t if (pkey->type == EVP_PKEY_DSA)\n\t\t\tdgst=EVP_dss1();\n\t\t else\n#endif\n\t\t\tdgst=EVP_md5();\n\t\t }\n\t\tif(crl_ext) {\n\t\t X509V3_CTX crlctx;\n\t\t if (ci->version == NULL)\n\t\t if ((ci->version=ASN1_INTEGER_new()) == NULL) goto err;\n\t\t ASN1_INTEGER_set(ci->version,1);\n\t\t X509V3_set_ctx(&crlctx, x509, NULL, NULL, crl, 0);\n\t\t X509V3_set_conf_lhash(&crlctx, conf);\n\t\t if(!X509V3_EXT_CRL_add_conf(conf, &crlctx,\n\t\t\t\t\t\t crl_ext, crl)) goto err;\n\t\t}\n\t\tif (!X509_CRL_sign(crl,pkey,dgst)) goto err;\n\t\tPEM_write_bio_X509_CRL(Sout,crl);\n\t\t}\n\tif (dorevoke)\n\t\t{\n\t\tif (infile == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"no input files\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tX509 *revcert;\n\t\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(infile);\n\t\t\t\tBIO_printf(bio_err,"error trying to load \'%s\' certificate\\n",infile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\trevcert=PEM_read_bio_X509(in,NULL,NULL,NULL);\n\t\t\tif (revcert == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to load \'%s\' certificate\\n",infile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tj=do_revoke(revcert,db);\n\t\t\tif (j <= 0) goto err;\n\t\t\tX509_free(revcert);\n\t\t\tstrncpy(buf[0],dbfile,BSIZE-4);\n\t\t\tstrcat(buf[0],".new");\n\t\t\tif (BIO_write_filename(out,buf[0]) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(dbfile);\n\t\t\t\tBIO_printf(bio_err,"unable to open \'%s\'\\n",dbfile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tj=TXT_DB_write(out,db);\n\t\t\tif (j <= 0) goto err;\n\t\t\tstrncpy(buf[1],dbfile,BSIZE-4);\n\t\t\tstrcat(buf[1],".old");\n\t\t\tif (rename(dbfile,buf[1]) < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to rename %s to %s\\n", dbfile, buf[1]);\n\t\t\t\tperror("reason");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (rename(buf[0],dbfile) < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to rename %s to %s\\n", buf[0],dbfile);\n\t\t\t\tperror("reason");\n\t\t\t\trename(buf[1],dbfile);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tBIO_printf(bio_err,"Data Base Updated\\n");\n\t\t\t}\n\t\t}\n\tret=0;\nerr:\n\tBIO_free(hex);\n\tBIO_free_all(Cout);\n\tBIO_free_all(Sout);\n\tBIO_free_all(out);\n\tBIO_free(in);\n\tsk_X509_pop_free(cert_sk,X509_free);\n\tif (ret) ERR_print_errors(bio_err);\n\tapp_RAND_write_file(randfile, bio_err);\n\tBN_free(serial);\n\tTXT_DB_free(db);\n\tEVP_PKEY_free(pkey);\n\tX509_free(x509);\n\tX509_CRL_free(crl);\n\tCONF_free(conf);\n\tOBJ_cleanup();\n\tEXIT(ret);\n\t}', 'const char *X509_get_default_cert_area(void)\n\t{ return(X509_CERT_AREA); }'] |
33,040 | 0 | https://github.com/libav/libav/blob/f62c025a5ee898cdaed8f48d2c0ddfd89ac65f16/libavcodec/aaccoder.c/#L777 | static void search_for_quantizers_twoloop(AVCodecContext *avctx,
AACEncContext *s,
SingleChannelElement *sce,
const float lambda)
{
int start = 0, i, w, w2, g;
int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels;
float dists[128], uplims[128];
float maxvals[128];
int fflag, minscaler;
int its = 0;
int allz = 0;
float minthr = INFINITY;
memset(dists, 0, sizeof(dists));
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
for (g = 0; g < sce->ics.num_swb; g++) {
int nz = 0;
float uplim = 0.0f;
for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];
uplim += band->threshold;
if (band->energy <= band->threshold || band->threshold == 0.0f) {
sce->zeroes[(w+w2)*16+g] = 1;
continue;
}
nz = 1;
}
uplims[w*16+g] = uplim *512;
sce->zeroes[w*16+g] = !nz;
if (nz)
minthr = FFMIN(minthr, uplim);
allz = FFMAX(allz, nz);
}
}
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
for (g = 0; g < sce->ics.num_swb; g++) {
if (sce->zeroes[w*16+g]) {
sce->sf_idx[w*16+g] = SCALE_ONE_POS;
continue;
}
sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);
}
}
if (!allz)
return;
abs_pow34_v(s->scoefs, sce->coeffs, 1024);
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
start = w*128;
for (g = 0; g < sce->ics.num_swb; g++) {
const float *scaled = s->scoefs + start;
maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);
start += sce->ics.swb_sizes[g];
}
}
do {
int tbits, qstep;
minscaler = sce->sf_idx[0];
qstep = its ? 1 : 32;
do {
int prev = -1;
tbits = 0;
fflag = 0;
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
start = w*128;
for (g = 0; g < sce->ics.num_swb; g++) {
const float *coefs = sce->coeffs + start;
const float *scaled = s->scoefs + start;
int bits = 0;
int cb;
float dist = 0.0f;
if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {
start += sce->ics.swb_sizes[g];
continue;
}
minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);
cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {
int b;
dist += quantize_band_cost(s, coefs + w2*128,
scaled + w2*128,
sce->ics.swb_sizes[g],
sce->sf_idx[w*16+g],
cb,
1.0f,
INFINITY,
&b);
bits += b;
}
dists[w*16+g] = dist - bits;
if (prev != -1) {
bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];
}
tbits += bits;
start += sce->ics.swb_sizes[g];
prev = sce->sf_idx[w*16+g];
}
}
if (tbits > destbits) {
for (i = 0; i < 128; i++)
if (sce->sf_idx[i] < 218 - qstep)
sce->sf_idx[i] += qstep;
} else {
for (i = 0; i < 128; i++)
if (sce->sf_idx[i] > 60 - qstep)
sce->sf_idx[i] -= qstep;
}
qstep >>= 1;
if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217)
qstep = 1;
} while (qstep);
fflag = 0;
minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);
for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
for (g = 0; g < sce->ics.num_swb; g++) {
int prevsc = sce->sf_idx[w*16+g];
if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) {
if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1))
sce->sf_idx[w*16+g]--;
else
sce->sf_idx[w*16+g]-=2;
}
sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF);
sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);
if (sce->sf_idx[w*16+g] != prevsc)
fflag = 1;
sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);
}
}
its++;
} while (fflag && its < 10);
} | ['static void search_for_quantizers_twoloop(AVCodecContext *avctx,\n AACEncContext *s,\n SingleChannelElement *sce,\n const float lambda)\n{\n int start = 0, i, w, w2, g;\n int destbits = avctx->bit_rate * 1024.0 / avctx->sample_rate / avctx->channels;\n float dists[128], uplims[128];\n float maxvals[128];\n int fflag, minscaler;\n int its = 0;\n int allz = 0;\n float minthr = INFINITY;\n memset(dists, 0, sizeof(dists));\n for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {\n for (g = 0; g < sce->ics.num_swb; g++) {\n int nz = 0;\n float uplim = 0.0f;\n for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {\n FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g];\n uplim += band->threshold;\n if (band->energy <= band->threshold || band->threshold == 0.0f) {\n sce->zeroes[(w+w2)*16+g] = 1;\n continue;\n }\n nz = 1;\n }\n uplims[w*16+g] = uplim *512;\n sce->zeroes[w*16+g] = !nz;\n if (nz)\n minthr = FFMIN(minthr, uplim);\n allz = FFMAX(allz, nz);\n }\n }\n for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {\n for (g = 0; g < sce->ics.num_swb; g++) {\n if (sce->zeroes[w*16+g]) {\n sce->sf_idx[w*16+g] = SCALE_ONE_POS;\n continue;\n }\n sce->sf_idx[w*16+g] = SCALE_ONE_POS + FFMIN(log2f(uplims[w*16+g]/minthr)*4,59);\n }\n }\n if (!allz)\n return;\n abs_pow34_v(s->scoefs, sce->coeffs, 1024);\n for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {\n start = w*128;\n for (g = 0; g < sce->ics.num_swb; g++) {\n const float *scaled = s->scoefs + start;\n maxvals[w*16+g] = find_max_val(sce->ics.group_len[w], sce->ics.swb_sizes[g], scaled);\n start += sce->ics.swb_sizes[g];\n }\n }\n do {\n int tbits, qstep;\n minscaler = sce->sf_idx[0];\n qstep = its ? 1 : 32;\n do {\n int prev = -1;\n tbits = 0;\n fflag = 0;\n for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {\n start = w*128;\n for (g = 0; g < sce->ics.num_swb; g++) {\n const float *coefs = sce->coeffs + start;\n const float *scaled = s->scoefs + start;\n int bits = 0;\n int cb;\n float dist = 0.0f;\n if (sce->zeroes[w*16+g] || sce->sf_idx[w*16+g] >= 218) {\n start += sce->ics.swb_sizes[g];\n continue;\n }\n minscaler = FFMIN(minscaler, sce->sf_idx[w*16+g]);\n cb = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);\n for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) {\n int b;\n dist += quantize_band_cost(s, coefs + w2*128,\n scaled + w2*128,\n sce->ics.swb_sizes[g],\n sce->sf_idx[w*16+g],\n cb,\n 1.0f,\n INFINITY,\n &b);\n bits += b;\n }\n dists[w*16+g] = dist - bits;\n if (prev != -1) {\n bits += ff_aac_scalefactor_bits[sce->sf_idx[w*16+g] - prev + SCALE_DIFF_ZERO];\n }\n tbits += bits;\n start += sce->ics.swb_sizes[g];\n prev = sce->sf_idx[w*16+g];\n }\n }\n if (tbits > destbits) {\n for (i = 0; i < 128; i++)\n if (sce->sf_idx[i] < 218 - qstep)\n sce->sf_idx[i] += qstep;\n } else {\n for (i = 0; i < 128; i++)\n if (sce->sf_idx[i] > 60 - qstep)\n sce->sf_idx[i] -= qstep;\n }\n qstep >>= 1;\n if (!qstep && tbits > destbits*1.02 && sce->sf_idx[0] < 217)\n qstep = 1;\n } while (qstep);\n fflag = 0;\n minscaler = av_clip(minscaler, 60, 255 - SCALE_MAX_DIFF);\n for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {\n for (g = 0; g < sce->ics.num_swb; g++) {\n int prevsc = sce->sf_idx[w*16+g];\n if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) {\n if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1))\n sce->sf_idx[w*16+g]--;\n else\n sce->sf_idx[w*16+g]-=2;\n }\n sce->sf_idx[w*16+g] = av_clip(sce->sf_idx[w*16+g], minscaler, minscaler + SCALE_MAX_DIFF);\n sce->sf_idx[w*16+g] = FFMIN(sce->sf_idx[w*16+g], 219);\n if (sce->sf_idx[w*16+g] != prevsc)\n fflag = 1;\n sce->band_type[w*16+g] = find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]);\n }\n }\n its++;\n } while (fflag && its < 10);\n}'] |
33,041 | 0 | https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/ffmpeg.c/#L3607 | static void opt_vstats (void)
{
char filename[40];
time_t today2 = time(NULL);
struct tm *today = localtime(&today2);
snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
today->tm_sec);
opt_vstats_file(filename);
} | ['static void opt_vstats (void)\n{\n char filename[40];\n time_t today2 = time(NULL);\n struct tm *today = localtime(&today2);\n snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,\n today->tm_sec);\n opt_vstats_file(filename);\n}'] |
33,042 | 0 | https://github.com/openssl/openssl/blob/6c2c3e9ba9146ef8c9b1fd2b660357b657706969/ssl/s2_clnt.c/#L956 | int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data)
{
STACK_OF(X509) *sk=NULL;
EVP_PKEY *pkey=NULL;
SESS_CERT *sc=NULL;
int i;
X509 *x509=NULL;
int ret=0;
x509=d2i_X509(NULL,&data,(long)len);
if (x509 == NULL)
{
SSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_X509_LIB);
goto err;
}
if ((sk=sk_X509_new_null()) == NULL || !sk_X509_push(sk,x509))
{
SSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_MALLOC_FAILURE);
goto err;
}
i=ssl_verify_cert_chain(s,sk);
if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
{
SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
goto err;
}
sc=ssl_sess_cert_new();
if (sc == NULL)
{
ret= -1;
goto err;
}
if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert);
s->session->sess_cert=sc;
sc->peer_pkeys[SSL_PKEY_RSA_ENC].x509=x509;
sc->peer_key= &(sc->peer_pkeys[SSL_PKEY_RSA_ENC]);
pkey=X509_get_pubkey(x509);
x509=NULL;
if (pkey == NULL)
{
SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY);
goto err;
}
if (pkey->type != EVP_PKEY_RSA)
{
SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_PUBLIC_KEY_NOT_RSA);
goto err;
}
if (!ssl_set_peer_cert_type(sc,SSL2_CT_X509_CERTIFICATE))
goto err;
ret=1;
err:
sk_X509_free(sk);
X509_free(x509);
EVP_PKEY_free(pkey);
return(ret);
} | ['int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data)\n\t{\n\tSTACK_OF(X509) *sk=NULL;\n\tEVP_PKEY *pkey=NULL;\n\tSESS_CERT *sc=NULL;\n\tint i;\n\tX509 *x509=NULL;\n\tint ret=0;\n\tx509=d2i_X509(NULL,&data,(long)len);\n\tif (x509 == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_X509_LIB);\n\t\tgoto err;\n\t\t}\n\tif ((sk=sk_X509_new_null()) == NULL || !sk_X509_push(sk,x509))\n\t\t{\n\t\tSSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ti=ssl_verify_cert_chain(s,sk);\n\tif ((s->verify_mode != SSL_VERIFY_NONE) && (!i))\n\t\t{\n\t\tSSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);\n\t\tgoto err;\n\t\t}\n\tsc=ssl_sess_cert_new();\n\tif (sc == NULL)\n\t\t{\n\t\tret= -1;\n\t\tgoto err;\n\t\t}\n\tif (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert);\n\ts->session->sess_cert=sc;\n\tsc->peer_pkeys[SSL_PKEY_RSA_ENC].x509=x509;\n\tsc->peer_key= &(sc->peer_pkeys[SSL_PKEY_RSA_ENC]);\n\tpkey=X509_get_pubkey(x509);\n\tx509=NULL;\n\tif (pkey == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY);\n\t\tgoto err;\n\t\t}\n\tif (pkey->type != EVP_PKEY_RSA)\n\t\t{\n\t\tSSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_PUBLIC_KEY_NOT_RSA);\n\t\tgoto err;\n\t\t}\n\tif (!ssl_set_peer_cert_type(sc,SSL2_CT_X509_CERTIFICATE))\n\t\tgoto err;\n\tret=1;\nerr:\n\tsk_X509_free(sk);\n\tX509_free(x509);\n\tEVP_PKEY_free(pkey);\n\treturn(ret);\n\t}', 'IMPLEMENT_STACK_OF(X509)', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void sk_free(STACK *st)\n\t{\n\tif (st == NULL) return;\n\tif (st->data != NULL) Free((char *)st->data);\n\tFree((char *)st);\n\t}', 'void X509_free(X509 *a)\n\t{\n\tint i;\n\tif (a == NULL) return;\n\ti=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_X509);\n#ifdef REF_PRINT\n\tREF_PRINT("X509",a);\n#endif\n\tif (i > 0) return;\n#ifdef REF_CHECK\n\tif (i < 0)\n\t\t{\n\t\tfprintf(stderr,"X509_free, bad reference count\\n");\n\t\tabort();\n\t\t}\n#endif\n\tCRYPTO_free_ex_data(x509_meth,a,&a->ex_data);\n\tX509_CINF_free(a->cert_info);\n\tX509_ALGOR_free(a->sig_alg);\n\tM_ASN1_BIT_STRING_free(a->signature);\n\tX509_CERT_AUX_free(a->aux);\n\tif (a->name != NULL) Free(a->name);\n\tFree((char *)a);\n\t}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n\t int line)\n\t{\n\tint ret;\n\tif (add_lock_callback != NULL)\n\t\t{\n#ifdef LOCK_DEBUG\n\t\tint before= *pointer;\n#endif\n\t\tret=add_lock_callback(pointer,amount,type,file,line);\n#ifdef LOCK_DEBUG\n\t\tfprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(),\n\t\t\tbefore,amount,ret,\n\t\t\tCRYPTO_get_lock_name(type),\n\t\t\tfile,line);\n#endif\n\t\t*pointer=ret;\n\t\t}\n\telse\n\t\t{\n\t\tCRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);\n\t\tret= *pointer+amount;\n#ifdef LOCK_DEBUG\n\t\tfprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(),\n\t\t\t*pointer,amount,ret,\n\t\t\tCRYPTO_get_lock_name(type),\n\t\t\tfile,line);\n#endif\n\t\t*pointer=ret;\n\t\tCRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);\n\t\t}\n\treturn(ret);\n\t}'] |
33,043 | 0 | https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavformat/mov.c/#L1478 | static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)
{
char *str = NULL;
int size;
uint16_t str_size;
if (c->itunes_metadata) {
int data_size = get_be32(pb);
int tag = get_le32(pb);
if (tag == MKTAG('d','a','t','a')) {
get_be32(pb);
get_be32(pb);
str_size = data_size - 16;
atom.size -= 16;
} else return 0;
} else {
str_size = get_be16(pb);
get_be16(pb);
atom.size -= 4;
}
switch (atom.type) {
case MKTAG(0xa9,'n','a','m'):
str = c->fc->title; size = sizeof(c->fc->title); break;
case MKTAG(0xa9,'A','R','T'):
case MKTAG(0xa9,'w','r','t'):
str = c->fc->author; size = sizeof(c->fc->author); break;
case MKTAG(0xa9,'c','p','y'):
str = c->fc->copyright; size = sizeof(c->fc->copyright); break;
case MKTAG(0xa9,'c','m','t'):
case MKTAG(0xa9,'i','n','f'):
str = c->fc->comment; size = sizeof(c->fc->comment); break;
case MKTAG(0xa9,'a','l','b'):
str = c->fc->album; size = sizeof(c->fc->album); break;
}
if (!str)
return 0;
if (atom.size < 0)
return -1;
get_buffer(pb, str, FFMIN3(size, str_size, atom.size));
dprintf(c->fc, "%.4s %s %d %lld\n", (char*)&atom.type, str, str_size, atom.size);
return 0;
} | ['static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom)\n{\n char *str = NULL;\n int size;\n uint16_t str_size;\n if (c->itunes_metadata) {\n int data_size = get_be32(pb);\n int tag = get_le32(pb);\n if (tag == MKTAG(\'d\',\'a\',\'t\',\'a\')) {\n get_be32(pb);\n get_be32(pb);\n str_size = data_size - 16;\n atom.size -= 16;\n } else return 0;\n } else {\n str_size = get_be16(pb);\n get_be16(pb);\n atom.size -= 4;\n }\n switch (atom.type) {\n case MKTAG(0xa9,\'n\',\'a\',\'m\'):\n str = c->fc->title; size = sizeof(c->fc->title); break;\n case MKTAG(0xa9,\'A\',\'R\',\'T\'):\n case MKTAG(0xa9,\'w\',\'r\',\'t\'):\n str = c->fc->author; size = sizeof(c->fc->author); break;\n case MKTAG(0xa9,\'c\',\'p\',\'y\'):\n str = c->fc->copyright; size = sizeof(c->fc->copyright); break;\n case MKTAG(0xa9,\'c\',\'m\',\'t\'):\n case MKTAG(0xa9,\'i\',\'n\',\'f\'):\n str = c->fc->comment; size = sizeof(c->fc->comment); break;\n case MKTAG(0xa9,\'a\',\'l\',\'b\'):\n str = c->fc->album; size = sizeof(c->fc->album); break;\n }\n if (!str)\n return 0;\n if (atom.size < 0)\n return -1;\n get_buffer(pb, str, FFMIN3(size, str_size, atom.size));\n dprintf(c->fc, "%.4s %s %d %lld\\n", (char*)&atom.type, str, str_size, atom.size);\n return 0;\n}'] |
33,044 | 0 | https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_lib.c/#L842 | int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
{
int i;
BN_ULONG aa, bb;
aa = a[n - 1];
bb = b[n - 1];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
for (i = n - 2; i >= 0; i--) {
aa = a[i];
bb = b[i];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
}
return (0);
} | ['int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a;\n const BIGNUM *ca;\n BN_CTX_start(ctx);\n if ((a = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (y != NULL) {\n if (x == y) {\n if (!BN_sqr(a, x, ctx))\n goto err;\n } else {\n if (!BN_mul(a, x, y, ctx))\n goto err;\n }\n ca = a;\n } else\n ca = x;\n ret = BN_div_recp(NULL, r, ca, recp, ctx);\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return (ret);\n}', '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_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n int dna, int dnb, BN_ULONG *t)\n{\n int n = n2 / 2, c1, c2;\n int tna = n + dna, tnb = n + dnb;\n unsigned int neg, zero;\n BN_ULONG ln, lo, *p;\n# ifdef BN_MUL_COMBA\n# if 0\n if (n2 == 4) {\n bn_mul_comba4(r, a, b);\n return;\n }\n# endif\n if (n2 == 8 && dna == 0 && dnb == 0) {\n bn_mul_comba8(r, a, b);\n return;\n }\n# endif\n if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);\n if ((dna + dnb) < 0)\n memset(&r[2 * n2 + dna + dnb], 0,\n sizeof(BN_ULONG) * -(dna + dnb));\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n zero = neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n zero = 1;\n break;\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n zero = 1;\n break;\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n zero = 1;\n break;\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# ifdef BN_MUL_COMBA\n if (n == 4 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 8);\n bn_mul_comba4(r, a, b);\n bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));\n } else if (n == 8 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 16);\n bn_mul_comba8(r, a, b);\n bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));\n } else\n# endif\n {\n p = &(t[n2 * 2]);\n if (!zero)\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n else\n memset(&t[n2], 0, sizeof(*t) * n2);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}'] |
33,045 | 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_block(AVCodecContext *avctx, BitstreamContext *bc,\n int16_t *dst0, int16_t *dst1)\n{\n RALFContext *ctx = avctx->priv_data;\n int len, ch, ret;\n int dmode, mode[2], bits[2];\n int *ch0, *ch1;\n int i, t, t2;\n len = 12 - get_unary(bc, 0, 6);\n if (len <= 7) len ^= 1;\n len = 1 << len;\n if (ctx->sample_offset + len > ctx->max_frame_size) {\n av_log(avctx, AV_LOG_ERROR,\n "Decoder\'s stomach is crying, it ate too many samples\\n");\n return AVERROR_INVALIDDATA;\n }\n if (avctx->channels > 1)\n dmode = bitstream_read(bc, 2) + 1;\n else\n dmode = 0;\n mode[0] = (dmode == 4) ? 1 : 0;\n mode[1] = (dmode >= 2) ? 2 : 0;\n bits[0] = 16;\n bits[1] = (mode[1] == 2) ? 17 : 16;\n for (ch = 0; ch < avctx->channels; ch++) {\n if ((ret = decode_channel(ctx, bc, ch, len, mode[ch], bits[ch])) < 0)\n return ret;\n if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {\n ctx->filter_bits += 3;\n apply_lpc(ctx, ch, len, bits[ch]);\n }\n if (bitstream_bits_left(bc) < 0)\n return AVERROR_INVALIDDATA;\n }\n ch0 = ctx->channel_data[0];\n ch1 = ctx->channel_data[1];\n switch (dmode) {\n case 0:\n for (i = 0; i < len; i++)\n dst0[i] = ch0[i] + ctx->bias[0];\n break;\n case 1:\n for (i = 0; i < len; i++) {\n dst0[i] = ch0[i] + ctx->bias[0];\n dst1[i] = ch1[i] + ctx->bias[1];\n }\n break;\n case 2:\n for (i = 0; i < len; i++) {\n ch0[i] += ctx->bias[0];\n dst0[i] = ch0[i];\n dst1[i] = ch0[i] - (ch1[i] + ctx->bias[1]);\n }\n break;\n case 3:\n for (i = 0; i < len; i++) {\n t = ch0[i] + ctx->bias[0];\n t2 = ch1[i] + ctx->bias[1];\n dst0[i] = t + t2;\n dst1[i] = t;\n }\n break;\n case 4:\n for (i = 0; i < len; i++) {\n t = ch1[i] + ctx->bias[1];\n t2 = ((ch0[i] + ctx->bias[0]) << 1) | (t & 1);\n dst0[i] = (t2 + t) / 2;\n dst1[i] = (t2 - t) / 2;\n }\n break;\n }\n ctx->sample_offset += len;\n return 0;\n}', 'static int decode_channel(RALFContext *ctx, BitstreamContext *bc, int ch,\n int length, int mode, int bits)\n{\n int i, t;\n int code_params;\n VLCSet *set = ctx->sets + mode;\n VLC *code_vlc; int range, range2, add_bits;\n int *dst = ctx->channel_data[ch];\n ctx->filter_params = bitstream_read_vlc(bc, set->filter_params.table, 9, 2);\n ctx->filter_bits = (ctx->filter_params - 2) >> 6;\n ctx->filter_length = ctx->filter_params - (ctx->filter_bits << 6) - 1;\n if (ctx->filter_params == FILTER_RAW) {\n for (i = 0; i < length; i++)\n dst[i] = bitstream_read(bc, bits);\n ctx->bias[ch] = 0;\n return 0;\n }\n ctx->bias[ch] = bitstream_read_vlc(bc, set->bias.table, 9, 2);\n ctx->bias[ch] = extend_code(bc, ctx->bias[ch], 127, 4);\n if (ctx->filter_params == FILTER_NONE) {\n memset(dst, 0, sizeof(*dst) * length);\n return 0;\n }\n if (ctx->filter_params > 1) {\n int cmode = 0, coeff = 0;\n VLC *vlc = set->filter_coeffs[ctx->filter_bits] + 5;\n add_bits = ctx->filter_bits;\n for (i = 0; i < ctx->filter_length; i++) {\n t = bitstream_read_vlc(bc, vlc[cmode].table, vlc[cmode].bits, 2);\n t = extend_code(bc, t, 21, add_bits);\n if (!cmode)\n coeff -= 12 << add_bits;\n coeff = t - coeff;\n ctx->filter[i] = coeff;\n cmode = coeff >> add_bits;\n if (cmode < 0) {\n cmode = -1 - av_log2(-cmode);\n if (cmode < -5)\n cmode = -5;\n } else if (cmode > 0) {\n cmode = 1 + av_log2(cmode);\n if (cmode > 5)\n cmode = 5;\n }\n }\n }\n code_params = bitstream_read_vlc(bc, set->coding_mode.table, set->coding_mode.bits, 2);\n if (code_params >= 15) {\n add_bits = av_clip((code_params / 5 - 3) / 2, 0, 10);\n if (add_bits > 9 && (code_params % 5) != 2)\n add_bits--;\n range = 10;\n range2 = 21;\n code_vlc = set->long_codes + code_params - 15;\n } else {\n add_bits = 0;\n range = 6;\n range2 = 13;\n code_vlc = set->short_codes + code_params;\n }\n for (i = 0; i < length; i += 2) {\n int code1, code2;\n t = bitstream_read_vlc(bc, code_vlc->table, code_vlc->bits, 2);\n code1 = t / range2;\n code2 = t % range2;\n dst[i] = extend_code(bc, code1, range, 0) << add_bits;\n dst[i + 1] = extend_code(bc, code2, range, 0) << add_bits;\n if (add_bits) {\n dst[i] |= bitstream_read(bc, add_bits);\n dst[i + 1] |= bitstream_read(bc, add_bits);\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}'] |
33,046 | 0 | https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavcodec/cook.c/#L1130 | static av_cold int cook_decode_init(AVCodecContext *avctx)
{
COOKContext *q = avctx->priv_data;
const uint8_t *edata_ptr = avctx->extradata;
if (avctx->extradata_size <= 0) {
av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
return -1;
} else {
av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
if (avctx->extradata_size >= 8){
q->cookversion = bytestream_get_be32(&edata_ptr);
q->samples_per_frame = bytestream_get_be16(&edata_ptr);
q->subbands = bytestream_get_be16(&edata_ptr);
}
if (avctx->extradata_size >= 16){
bytestream_get_be32(&edata_ptr);
q->js_subband_start = bytestream_get_be16(&edata_ptr);
q->js_vlc_bits = bytestream_get_be16(&edata_ptr);
}
}
q->sample_rate = avctx->sample_rate;
q->nb_channels = avctx->channels;
q->bit_rate = avctx->bit_rate;
av_random_init(&q->random_state, 1);
q->samples_per_channel = q->samples_per_frame / q->nb_channels;
q->bits_per_subpacket = avctx->block_align * 8;
q->log2_numvector_size = 5;
q->total_subbands = q->subbands;
av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion);
q->joint_stereo = 0;
switch (q->cookversion) {
case MONO:
if (q->nb_channels != 1) {
av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
return -1;
}
av_log(avctx,AV_LOG_DEBUG,"MONO\n");
break;
case STEREO:
if (q->nb_channels != 1) {
q->bits_per_subpacket = q->bits_per_subpacket/2;
}
av_log(avctx,AV_LOG_DEBUG,"STEREO\n");
break;
case JOINT_STEREO:
if (q->nb_channels != 2) {
av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
return -1;
}
av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
if (avctx->extradata_size >= 16){
q->total_subbands = q->subbands + q->js_subband_start;
q->joint_stereo = 1;
}
if (q->samples_per_channel > 256) {
q->log2_numvector_size = 6;
}
if (q->samples_per_channel > 512) {
q->log2_numvector_size = 7;
}
break;
case MC_COOK:
av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
return -1;
break;
default:
av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
return -1;
break;
}
q->numvector_size = (1 << q->log2_numvector_size);
init_pow2table();
init_gain_table(q);
init_cplscales_table(q);
if (init_cook_vlc_tables(q) != 0)
return -1;
if(avctx->block_align >= UINT_MAX/2)
return -1;
if (q->nb_channels==2 && q->joint_stereo==0) {
q->decoded_bytes_buffer =
av_mallocz(avctx->block_align/2
+ DECODE_BYTES_PAD2(avctx->block_align/2)
+ FF_INPUT_BUFFER_PADDING_SIZE);
} else {
q->decoded_bytes_buffer =
av_mallocz(avctx->block_align
+ DECODE_BYTES_PAD1(avctx->block_align)
+ FF_INPUT_BUFFER_PADDING_SIZE);
}
if (q->decoded_bytes_buffer == NULL)
return -1;
q->gains1.now = q->gain_1;
q->gains1.previous = q->gain_2;
q->gains2.now = q->gain_3;
q->gains2.previous = q->gain_4;
if ( init_cook_mlt(q) != 0 )
return -1;
if (1) {
q->scalar_dequant = scalar_dequant_float;
q->decouple = decouple_float;
q->imlt_window = imlt_window_float;
q->interpolate = interpolate_float;
q->saturate_output = saturate_output_float;
}
if (q->total_subbands > 53) {
av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
return -1;
}
if (q->subbands > 50) {
av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n");
return -1;
}
if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
} else {
av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
return -1;
}
if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
return -1;
}
avctx->sample_fmt = SAMPLE_FMT_S16;
avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
#ifdef COOKDEBUG
dump_cook_context(q);
#endif
return 0;
} | ['static av_cold int cook_decode_init(AVCodecContext *avctx)\n{\n COOKContext *q = avctx->priv_data;\n const uint8_t *edata_ptr = avctx->extradata;\n if (avctx->extradata_size <= 0) {\n av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\\n");\n return -1;\n } else {\n av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\\n",avctx->extradata_size);\n if (avctx->extradata_size >= 8){\n q->cookversion = bytestream_get_be32(&edata_ptr);\n q->samples_per_frame = bytestream_get_be16(&edata_ptr);\n q->subbands = bytestream_get_be16(&edata_ptr);\n }\n if (avctx->extradata_size >= 16){\n bytestream_get_be32(&edata_ptr);\n q->js_subband_start = bytestream_get_be16(&edata_ptr);\n q->js_vlc_bits = bytestream_get_be16(&edata_ptr);\n }\n }\n q->sample_rate = avctx->sample_rate;\n q->nb_channels = avctx->channels;\n q->bit_rate = avctx->bit_rate;\n av_random_init(&q->random_state, 1);\n q->samples_per_channel = q->samples_per_frame / q->nb_channels;\n q->bits_per_subpacket = avctx->block_align * 8;\n q->log2_numvector_size = 5;\n q->total_subbands = q->subbands;\n av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\\n",q->cookversion);\n q->joint_stereo = 0;\n switch (q->cookversion) {\n case MONO:\n if (q->nb_channels != 1) {\n av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\\n");\n return -1;\n }\n av_log(avctx,AV_LOG_DEBUG,"MONO\\n");\n break;\n case STEREO:\n if (q->nb_channels != 1) {\n q->bits_per_subpacket = q->bits_per_subpacket/2;\n }\n av_log(avctx,AV_LOG_DEBUG,"STEREO\\n");\n break;\n case JOINT_STEREO:\n if (q->nb_channels != 2) {\n av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\\n");\n return -1;\n }\n av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\\n");\n if (avctx->extradata_size >= 16){\n q->total_subbands = q->subbands + q->js_subband_start;\n q->joint_stereo = 1;\n }\n if (q->samples_per_channel > 256) {\n q->log2_numvector_size = 6;\n }\n if (q->samples_per_channel > 512) {\n q->log2_numvector_size = 7;\n }\n break;\n case MC_COOK:\n av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\\n");\n return -1;\n break;\n default:\n av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\\n");\n return -1;\n break;\n }\n q->numvector_size = (1 << q->log2_numvector_size);\n init_pow2table();\n init_gain_table(q);\n init_cplscales_table(q);\n if (init_cook_vlc_tables(q) != 0)\n return -1;\n if(avctx->block_align >= UINT_MAX/2)\n return -1;\n if (q->nb_channels==2 && q->joint_stereo==0) {\n q->decoded_bytes_buffer =\n av_mallocz(avctx->block_align/2\n + DECODE_BYTES_PAD2(avctx->block_align/2)\n + FF_INPUT_BUFFER_PADDING_SIZE);\n } else {\n q->decoded_bytes_buffer =\n av_mallocz(avctx->block_align\n + DECODE_BYTES_PAD1(avctx->block_align)\n + FF_INPUT_BUFFER_PADDING_SIZE);\n }\n if (q->decoded_bytes_buffer == NULL)\n return -1;\n q->gains1.now = q->gain_1;\n q->gains1.previous = q->gain_2;\n q->gains2.now = q->gain_3;\n q->gains2.previous = q->gain_4;\n if ( init_cook_mlt(q) != 0 )\n return -1;\n if (1) {\n q->scalar_dequant = scalar_dequant_float;\n q->decouple = decouple_float;\n q->imlt_window = imlt_window_float;\n q->interpolate = interpolate_float;\n q->saturate_output = saturate_output_float;\n }\n if (q->total_subbands > 53) {\n av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\\n");\n return -1;\n }\n if (q->subbands > 50) {\n av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\\n");\n return -1;\n }\n if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {\n } else {\n av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\\n",q->samples_per_channel);\n return -1;\n }\n if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {\n av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\\n",q->js_vlc_bits);\n return -1;\n }\n avctx->sample_fmt = SAMPLE_FMT_S16;\n avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;\n#ifdef COOKDEBUG\n dump_cook_context(q);\n#endif\n return 0;\n}'] |
33,047 | 0 | https://github.com/openssl/openssl/blob/11d01d371f67a9cacfeccb1078669c595d65002f/ssl/ssl_lib.c/#L1308 | char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)
{
char *p;
STACK_OF(SSL_CIPHER) *sk;
SSL_CIPHER *c;
int i;
if ((s->session == NULL) || (s->session->ciphers == NULL) ||
(len < 2))
return(NULL);
p=buf;
sk=s->session->ciphers;
for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
{
int n;
c=sk_SSL_CIPHER_value(sk,i);
n=strlen(c->name);
if (n+1 > len)
{
if (p != buf)
--p;
*p='\0';
return buf;
}
strcpy(p,c->name);
p+=n;
*(p++)=':';
len-=n+1;
}
p[-1]='\0';
return(buf);
} | ['static int init_ssl_connection(SSL *con)\n\t{\n\tint i;\n\tconst char *str;\n\tX509 *peer;\n\tlong verify_error;\n\tMS_STATIC char buf[BUFSIZ];\n\tif ((i=SSL_accept(con)) <= 0)\n\t\t{\n\t\tif (BIO_sock_should_retry(i))\n\t\t\t{\n\t\t\tBIO_printf(bio_s_out,"DELAY\\n");\n\t\t\treturn(1);\n\t\t\t}\n\t\tBIO_printf(bio_err,"ERROR\\n");\n\t\tverify_error=SSL_get_verify_result(con);\n\t\tif (verify_error != X509_V_OK)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"verify error:%s\\n",\n\t\t\t\tX509_verify_cert_error_string(verify_error));\n\t\t\t}\n\t\telse\n\t\t\tERR_print_errors(bio_err);\n\t\treturn(0);\n\t\t}\n\tPEM_write_bio_SSL_SESSION(bio_s_out,SSL_get_session(con));\n\tpeer=SSL_get_peer_certificate(con);\n\tif (peer != NULL)\n\t\t{\n\t\tBIO_printf(bio_s_out,"Client certificate\\n");\n\t\tPEM_write_bio_X509(bio_s_out,peer);\n\t\tX509_NAME_oneline(X509_get_subject_name(peer),buf,sizeof buf);\n\t\tBIO_printf(bio_s_out,"subject=%s\\n",buf);\n\t\tX509_NAME_oneline(X509_get_issuer_name(peer),buf,sizeof buf);\n\t\tBIO_printf(bio_s_out,"issuer=%s\\n",buf);\n\t\tX509_free(peer);\n\t\t}\n\tif (SSL_get_shared_ciphers(con,buf,sizeof buf) != NULL)\n\t\tBIO_printf(bio_s_out,"Shared ciphers:%s\\n",buf);\n\tstr=SSL_CIPHER_get_name(SSL_get_current_cipher(con));\n\tBIO_printf(bio_s_out,"CIPHER is %s\\n",(str != NULL)?str:"(NONE)");\n\tif (con->hit) BIO_printf(bio_s_out,"Reused session-id\\n");\n\tif (SSL_ctrl(con,SSL_CTRL_GET_FLAGS,0,NULL) &\n\t\tTLS1_FLAGS_TLS_PADDING_BUG)\n\t\tBIO_printf(bio_s_out,"Peer has incorrect TLSv1 block padding\\n");\n#ifndef OPENSSL_NO_KRB5\n\tif (con->kssl_ctx->client_princ != NULL)\n\t\t{\n\t\tBIO_printf(bio_s_out,"Kerberos peer principal is %s\\n",\n\t\t\tcon->kssl_ctx->client_princ);\n\t\t}\n#endif\n\treturn(1);\n\t}', "char *SSL_get_shared_ciphers(const SSL *s,char *buf,int len)\n\t{\n\tchar *p;\n\tSTACK_OF(SSL_CIPHER) *sk;\n\tSSL_CIPHER *c;\n\tint i;\n\tif ((s->session == NULL) || (s->session->ciphers == NULL) ||\n\t\t(len < 2))\n\t\treturn(NULL);\n\tp=buf;\n\tsk=s->session->ciphers;\n\tfor (i=0; i<sk_SSL_CIPHER_num(sk); i++)\n\t\t{\n\t\tint n;\n\t\tc=sk_SSL_CIPHER_value(sk,i);\n\t\tn=strlen(c->name);\n\t\tif (n+1 > len)\n\t\t\t{\n\t\t\tif (p != buf)\n\t\t\t\t--p;\n\t\t\t*p='\\0';\n\t\t\treturn buf;\n\t\t\t}\n\t\tstrcpy(p,c->name);\n\t\tp+=n;\n\t\t*(p++)=':';\n\t\tlen-=n+1;\n\t\t}\n\tp[-1]='\\0';\n\treturn(buf);\n\t}"] |
33,048 | 0 | https://github.com/openssl/openssl/blob/ff281ee8369350d88e8b57af139614f5683e1e8c/test/handshake_helper.c/#L96 | static void info_cb(const SSL *s, int where, int ret)
{
if (where & SSL_CB_ALERT) {
HANDSHAKE_EX_DATA *ex_data =
(HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
if (where & SSL_CB_WRITE) {
ex_data->alert_sent = ret;
if (strcmp(SSL_alert_type_string(ret), "F") == 0
|| strcmp(SSL_alert_desc_string(ret), "CN") == 0)
ex_data->num_fatal_alerts_sent++;
} else {
ex_data->alert_received = ret;
}
}
} | ['static void info_cb(const SSL *s, int where, int ret)\n{\n if (where & SSL_CB_ALERT) {\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (where & SSL_CB_WRITE) {\n ex_data->alert_sent = ret;\n if (strcmp(SSL_alert_type_string(ret), "F") == 0\n || strcmp(SSL_alert_desc_string(ret), "CN") == 0)\n ex_data->num_fatal_alerts_sent++;\n } else {\n ex_data->alert_received = ret;\n }\n }\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}'] |
33,049 | 0 | https://github.com/openssl/openssl/blob/d636aa7109aceeb870df83c4978b271824617530/crypto/bio/b_sock.c/#L700 | int BIO_get_accept_socket(char *host, int bind_mode)
{
int ret=0;
#if OPENSSL_USE_IPV6
# define ossl_sock_family(s) s.ss_family
struct sockaddr_storage server,client;
#else
# define ossl_sock_family(s) s.sa_family
struct sockaddr server,client;
#endif
struct sockaddr_in *sa_in;
int s=INVALID_SOCKET,cs;
unsigned char ip[4];
unsigned short port;
char *str=NULL,*e;
char *h,*p;
unsigned long l;
int err_num;
if (BIO_sock_init() != 1) return(INVALID_SOCKET);
if ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);
h=p=NULL;
h=str;
for (e=str; *e; e++)
{
if (*e == ':')
{
p=e;
}
else if (*e == '/')
{
*e='\0';
break;
}
}
if (p) *p++='\0';
else p=h,h=NULL;
#ifdef EAI_FAMILY
do {
static union { void *p;
int (*f)(const char *,const char *,
const struct addrinfo *,
struct addrinfo **);
} p_getaddrinfo = {NULL};
static union { void *p;
void (*f)(struct addrinfo *);
} p_freeaddrinfo = {NULL};
struct addrinfo *res,hint;
if (p_getaddrinfo.p==NULL)
{
if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL ||
(p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL)
p_getaddrinfo.p=(void*)-1;
}
if (p_getaddrinfo.p==(void *)-1) break;
memset(&hint,0,sizeof(hint));
if (h)
{
if (strchr(h,':'))
{
if (h[1]=='\0') h=NULL;
#if OPENSSL_USE_IPV6
hint.ai_family = AF_INET6;
#else
h=NULL;
#endif
}
else if (h[0]=='*' && h[1]=='\0')
h=NULL;
}
if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break;
#if OPENSSL_USE_IPV6
memcpy(&server, res->ai_addr, res->ai_addrlen);
#else
server = *res->ai_addr;
#endif
(*p_freeaddrinfo.f)(res);
goto again;
} while (0);
#endif
if (!BIO_get_port(p,&port)) goto err;
memset((char *)&server,0,sizeof(server));
sa_in = (struct sockaddr_in *)&server;
sa_in->sin_family=AF_INET;
sa_in->sin_port=htons(port);
if (h == NULL || strcmp(h,"*") == 0)
sa_in->sin_addr.s_addr=INADDR_ANY;
else
{
if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
l=(unsigned long)
((unsigned long)ip[0]<<24L)|
((unsigned long)ip[1]<<16L)|
((unsigned long)ip[2]<< 8L)|
((unsigned long)ip[3]);
sa_in->sin_addr.s_addr=htonl(l);
}
again:
s=socket(ossl_sock_family(server),SOCK_STREAM,SOCKET_PROTOCOL);
if (s == INVALID_SOCKET)
{
SYSerr(SYS_F_SOCKET,get_last_socket_error());
ERR_add_error_data(3,"port='",host,"'");
BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
goto err;
}
#ifdef SO_REUSEADDR
if (bind_mode == BIO_BIND_REUSEADDR)
{
int i=1;
ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
bind_mode=BIO_BIND_NORMAL;
}
#endif
if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
{
#ifdef SO_REUSEADDR
err_num=get_last_socket_error();
if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
(err_num == EADDRINUSE))
{
client = server;
if (h == NULL || strcmp(h,"*") == 0)
{
#if OPENSSL_USE_IPV6
if (ossl_sock_family(client) == AF_INET6)
{
struct sockaddr_in6 *sin6 =
(struct sockaddr_in6 *)&client;
memset(&sin6->sin6_addr,0,sizeof(sin6->sin6_addr));
sin6->sin6_addr.s6_addr[15]=1;
}
else
#endif
if (ossl_sock_family(client) == AF_INET)
{
struct sockaddr_in *sin4 =
(struct sockaddr_in *)&client;
sin4->sin_addr.s_addr=htonl(0x7F000001);
}
else goto err;
}
cs=socket(ossl_sock_family(client),SOCK_STREAM,SOCKET_PROTOCOL);
if (cs != INVALID_SOCKET)
{
int ii;
ii=connect(cs,(struct sockaddr *)&client,
sizeof(client));
closesocket(cs);
if (ii == INVALID_SOCKET)
{
bind_mode=BIO_BIND_REUSEADDR;
closesocket(s);
goto again;
}
}
}
#endif
SYSerr(SYS_F_BIND,err_num);
ERR_add_error_data(3,"port='",host,"'");
BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
goto err;
}
if (listen(s,MAX_LISTEN) == -1)
{
SYSerr(SYS_F_BIND,get_last_socket_error());
ERR_add_error_data(3,"port='",host,"'");
BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
goto err;
}
ret=1;
err:
if (str != NULL) OPENSSL_free(str);
if ((ret == 0) && (s != INVALID_SOCKET))
{
closesocket(s);
s= INVALID_SOCKET;
}
return(s);
} | ['int BIO_get_accept_socket(char *host, int bind_mode)\n\t{\n\tint ret=0;\n#if OPENSSL_USE_IPV6\n# define ossl_sock_family(s) s.ss_family\n\tstruct sockaddr_storage server,client;\n#else\n# define ossl_sock_family(s) s.sa_family\n\tstruct sockaddr server,client;\n#endif\n\tstruct sockaddr_in *sa_in;\n\tint s=INVALID_SOCKET,cs;\n\tunsigned char ip[4];\n\tunsigned short port;\n\tchar *str=NULL,*e;\n\tchar *h,*p;\n\tunsigned long l;\n\tint err_num;\n\tif (BIO_sock_init() != 1) return(INVALID_SOCKET);\n\tif ((str=BUF_strdup(host)) == NULL) return(INVALID_SOCKET);\n\th=p=NULL;\n\th=str;\n\tfor (e=str; *e; e++)\n\t\t{\n\t\tif (*e == \':\')\n\t\t\t{\n\t\t\tp=e;\n\t\t\t}\n\t\telse if (*e == \'/\')\n\t\t\t{\n\t\t\t*e=\'\\0\';\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\tif (p)\t*p++=\'\\0\';\n\telse\tp=h,h=NULL;\n#ifdef EAI_FAMILY\n\tdo {\n\tstatic union {\tvoid *p;\n\t\t\tint (*f)(const char *,const char *,\n\t\t\t\t const struct addrinfo *,\n\t\t\t\t struct addrinfo **);\n\t\t\t} p_getaddrinfo = {NULL};\n\tstatic union {\tvoid *p;\n\t\t\tvoid (*f)(struct addrinfo *);\n\t\t\t} p_freeaddrinfo = {NULL};\n\tstruct addrinfo *res,hint;\n\tif (p_getaddrinfo.p==NULL)\n\t\t{\n\t\tif ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL ||\n\t\t (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL)\n\t\t\tp_getaddrinfo.p=(void*)-1;\n\t\t}\n\tif (p_getaddrinfo.p==(void *)-1) break;\n\tmemset(&hint,0,sizeof(hint));\n\tif (h)\n\t\t{\n\t\tif (strchr(h,\':\'))\n\t\t\t{\n\t\t\tif (h[1]==\'\\0\') h=NULL;\n#if OPENSSL_USE_IPV6\n\t\t\thint.ai_family = AF_INET6;\n#else\n\t\t\th=NULL;\n#endif\n\t\t\t}\n\t \telse if (h[0]==\'*\' && h[1]==\'\\0\')\n\t\t\th=NULL;\n\t\t}\n\tif ((*p_getaddrinfo.f)(h,p,&hint,&res)) break;\n#if OPENSSL_USE_IPV6\n\tmemcpy(&server, res->ai_addr, res->ai_addrlen);\n#else\n\tserver = *res->ai_addr;\n#endif\n\t(*p_freeaddrinfo.f)(res);\n\tgoto again;\n\t} while (0);\n#endif\n\tif (!BIO_get_port(p,&port)) goto err;\n\tmemset((char *)&server,0,sizeof(server));\n\tsa_in = (struct sockaddr_in *)&server;\n\tsa_in->sin_family=AF_INET;\n\tsa_in->sin_port=htons(port);\n\tif (h == NULL || strcmp(h,"*") == 0)\n\t\tsa_in->sin_addr.s_addr=INADDR_ANY;\n\telse\n\t\t{\n if (!BIO_get_host_ip(h,&(ip[0]))) goto err;\n\t\tl=(unsigned long)\n\t\t\t((unsigned long)ip[0]<<24L)|\n\t\t\t((unsigned long)ip[1]<<16L)|\n\t\t\t((unsigned long)ip[2]<< 8L)|\n\t\t\t((unsigned long)ip[3]);\n\t\tsa_in->sin_addr.s_addr=htonl(l);\n\t\t}\nagain:\n\ts=socket(ossl_sock_family(server),SOCK_STREAM,SOCKET_PROTOCOL);\n\tif (s == INVALID_SOCKET)\n\t\t{\n\t\tSYSerr(SYS_F_SOCKET,get_last_socket_error());\n\t\tERR_add_error_data(3,"port=\'",host,"\'");\n\t\tBIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);\n\t\tgoto err;\n\t\t}\n#ifdef SO_REUSEADDR\n\tif (bind_mode == BIO_BIND_REUSEADDR)\n\t\t{\n\t\tint i=1;\n\t\tret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));\n\t\tbind_mode=BIO_BIND_NORMAL;\n\t\t}\n#endif\n\tif (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)\n\t\t{\n#ifdef SO_REUSEADDR\n\t\terr_num=get_last_socket_error();\n\t\tif ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&\n\t\t\t(err_num == EADDRINUSE))\n\t\t\t{\n\t\t\tclient = server;\n\t\t\tif (h == NULL || strcmp(h,"*") == 0)\n\t\t\t\t{\n#if OPENSSL_USE_IPV6\n\t\t\t\tif (ossl_sock_family(client) == AF_INET6)\n\t\t\t\t\t{\n\t\t\t\t\tstruct sockaddr_in6 *sin6 =\n\t\t\t\t\t\t(struct sockaddr_in6 *)&client;\n\t\t\t\t\tmemset(&sin6->sin6_addr,0,sizeof(sin6->sin6_addr));\n\t\t\t\t\tsin6->sin6_addr.s6_addr[15]=1;\n\t\t\t\t\t}\n\t\t\t\telse\n#endif\n\t\t\t\tif (ossl_sock_family(client) == AF_INET)\n\t\t\t\t\t{\n\t\t\t\t\tstruct sockaddr_in *sin4 =\n\t\t\t\t\t\t(struct sockaddr_in *)&client;\n\t\t\t\t\tsin4->sin_addr.s_addr=htonl(0x7F000001);\n\t\t\t\t\t}\n\t\t\t\telse\tgoto err;\n\t\t\t\t}\n\t\t\tcs=socket(ossl_sock_family(client),SOCK_STREAM,SOCKET_PROTOCOL);\n\t\t\tif (cs != INVALID_SOCKET)\n\t\t\t\t{\n\t\t\t\tint ii;\n\t\t\t\tii=connect(cs,(struct sockaddr *)&client,\n\t\t\t\t\tsizeof(client));\n\t\t\t\tclosesocket(cs);\n\t\t\t\tif (ii == INVALID_SOCKET)\n\t\t\t\t\t{\n\t\t\t\t\tbind_mode=BIO_BIND_REUSEADDR;\n\t\t\t\t\tclosesocket(s);\n\t\t\t\t\tgoto again;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n#endif\n\t\tSYSerr(SYS_F_BIND,err_num);\n\t\tERR_add_error_data(3,"port=\'",host,"\'");\n\t\tBIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);\n\t\tgoto err;\n\t\t}\n\tif (listen(s,MAX_LISTEN) == -1)\n\t\t{\n\t\tSYSerr(SYS_F_BIND,get_last_socket_error());\n\t\tERR_add_error_data(3,"port=\'",host,"\'");\n\t\tBIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);\n\t\tgoto err;\n\t\t}\n\tret=1;\nerr:\n\tif (str != NULL) OPENSSL_free(str);\n\tif ((ret == 0) && (s != INVALID_SOCKET))\n\t\t{\n\t\tclosesocket(s);\n\t\ts= INVALID_SOCKET;\n\t\t}\n\treturn(s);\n\t}'] |
33,050 | 0 | https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_ctx.c/#L276 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,\n const ECDSA_SIG *sig, EC_KEY *eckey)\n{\n int ret = -1, i;\n BN_CTX *ctx;\n const BIGNUM *order;\n BIGNUM *u1, *u2, *m, *X;\n EC_POINT *point = NULL;\n const EC_GROUP *group;\n const EC_POINT *pub_key;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||\n (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_MISSING_PARAMETERS);\n return -1;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return -1;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n BN_CTX_start(ctx);\n u1 = BN_CTX_get(ctx);\n u2 = BN_CTX_get(ctx);\n m = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n if (X == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||\n BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) ||\n BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_BAD_SIGNATURE);\n ret = 0;\n goto err;\n }\n if (!ec_group_do_inverse_ord(group, u2, sig->s, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n i = BN_num_bits(order);\n if (8 * dgst_len > i)\n dgst_len = (i + 7) / 8;\n if (!BN_bin2bn(dgst, dgst_len, m)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(u1, m, u2, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (!EC_POINT_get_affine_coordinates(group, point, X, NULL, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (!BN_nnmod(u1, X, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n ret = (BN_ucmp(u1, sig->r) == 0);\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n EC_POINT_free(point);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
33,051 | 0 | https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_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 d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(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_mul_mont_fixed_top(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 r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(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_mul_mont_fixed_top(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_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(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}', '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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
33,052 | 0 | https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/ps.c/#L834 | static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34)
{
float power[34][PS_QMF_TIME_SLOTS] = {{0}};
float transient_gain[34][PS_QMF_TIME_SLOTS];
float *peak_decay_nrg = ps->peak_decay_nrg;
float *power_smooth = ps->power_smooth;
float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth;
float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay;
float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay;
const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;
const float peak_decay_factor = 0.76592833836465f;
const float transient_impact = 1.5f;
const float a_smooth = 0.25f;
int i, k, m, n;
int n0 = 0, nL = 32;
static const int link_delay[] = { 3, 4, 5 };
static const float a[] = { 0.65143905753106f,
0.56471812200776f,
0.48954165955695f };
if (is34 != ps->is34bands_old) {
memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg));
memset(ps->power_smooth, 0, sizeof(ps->power_smooth));
memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth));
memset(ps->delay, 0, sizeof(ps->delay));
memset(ps->ap_delay, 0, sizeof(ps->ap_delay));
}
for (n = n0; n < nL; n++) {
for (k = 0; k < NR_BANDS[is34]; k++) {
int i = k_to_i[k];
power[i][n] += s[k][n][0] * s[k][n][0] + s[k][n][1] * s[k][n][1];
}
}
for (i = 0; i < NR_PAR_BANDS[is34]; i++) {
for (n = n0; n < nL; n++) {
float decayed_peak = peak_decay_factor * peak_decay_nrg[i];
float denom;
peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]);
power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]);
peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]);
denom = transient_impact * peak_decay_diff_smooth[i];
transient_gain[i][n] = (denom > power_smooth[i]) ?
power_smooth[i] / denom : 1.0f;
}
}
for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) {
int b = k_to_i[k];
float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]);
float ag[PS_AP_LINKS];
g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f);
memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
for (m = 0; m < PS_AP_LINKS; m++) {
memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0]));
ag[m] = a[m] * g_decay_slope;
}
for (n = n0; n < nL; n++) {
float in_re = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][0] -
delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][1];
float in_im = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][1] +
delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][0];
for (m = 0; m < PS_AP_LINKS; m++) {
float a_re = ag[m] * in_re;
float a_im = ag[m] * in_im;
float link_delay_re = ap_delay[k][m][n+5-link_delay[m]][0];
float link_delay_im = ap_delay[k][m][n+5-link_delay[m]][1];
float fractional_delay_re = Q_fract_allpass[is34][k][m][0];
float fractional_delay_im = Q_fract_allpass[is34][k][m][1];
ap_delay[k][m][n+5][0] = in_re;
ap_delay[k][m][n+5][1] = in_im;
in_re = link_delay_re * fractional_delay_re - link_delay_im * fractional_delay_im - a_re;
in_im = link_delay_re * fractional_delay_im + link_delay_im * fractional_delay_re - a_im;
ap_delay[k][m][n+5][0] += ag[m] * in_re;
ap_delay[k][m][n+5][1] += ag[m] * in_im;
}
out[k][n][0] = transient_gain[b][n] * in_re;
out[k][n][1] = transient_gain[b][n] * in_im;
}
}
for (; k < SHORT_DELAY_BAND[is34]; k++) {
memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
for (n = n0; n < nL; n++) {
out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][0];
out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][1];
}
}
for (; k < NR_BANDS[is34]; k++) {
memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));
memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));
for (n = n0; n < nL; n++) {
out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][0];
out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][1];
}
}
} | ['static void decorrelation(PSContext *ps, float (*out)[32][2], const float (*s)[32][2], int is34)\n{\n float power[34][PS_QMF_TIME_SLOTS] = {{0}};\n float transient_gain[34][PS_QMF_TIME_SLOTS];\n float *peak_decay_nrg = ps->peak_decay_nrg;\n float *power_smooth = ps->power_smooth;\n float *peak_decay_diff_smooth = ps->peak_decay_diff_smooth;\n float (*delay)[PS_QMF_TIME_SLOTS + PS_MAX_DELAY][2] = ps->delay;\n float (*ap_delay)[PS_AP_LINKS][PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2] = ps->ap_delay;\n const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20;\n const float peak_decay_factor = 0.76592833836465f;\n const float transient_impact = 1.5f;\n const float a_smooth = 0.25f;\n int i, k, m, n;\n int n0 = 0, nL = 32;\n static const int link_delay[] = { 3, 4, 5 };\n static const float a[] = { 0.65143905753106f,\n 0.56471812200776f,\n 0.48954165955695f };\n if (is34 != ps->is34bands_old) {\n memset(ps->peak_decay_nrg, 0, sizeof(ps->peak_decay_nrg));\n memset(ps->power_smooth, 0, sizeof(ps->power_smooth));\n memset(ps->peak_decay_diff_smooth, 0, sizeof(ps->peak_decay_diff_smooth));\n memset(ps->delay, 0, sizeof(ps->delay));\n memset(ps->ap_delay, 0, sizeof(ps->ap_delay));\n }\n for (n = n0; n < nL; n++) {\n for (k = 0; k < NR_BANDS[is34]; k++) {\n int i = k_to_i[k];\n power[i][n] += s[k][n][0] * s[k][n][0] + s[k][n][1] * s[k][n][1];\n }\n }\n for (i = 0; i < NR_PAR_BANDS[is34]; i++) {\n for (n = n0; n < nL; n++) {\n float decayed_peak = peak_decay_factor * peak_decay_nrg[i];\n float denom;\n peak_decay_nrg[i] = FFMAX(decayed_peak, power[i][n]);\n power_smooth[i] += a_smooth * (power[i][n] - power_smooth[i]);\n peak_decay_diff_smooth[i] += a_smooth * (peak_decay_nrg[i] - power[i][n] - peak_decay_diff_smooth[i]);\n denom = transient_impact * peak_decay_diff_smooth[i];\n transient_gain[i][n] = (denom > power_smooth[i]) ?\n power_smooth[i] / denom : 1.0f;\n }\n }\n for (k = 0; k < NR_ALLPASS_BANDS[is34]; k++) {\n int b = k_to_i[k];\n float g_decay_slope = 1.f - DECAY_SLOPE * (k - DECAY_CUTOFF[is34]);\n float ag[PS_AP_LINKS];\n g_decay_slope = av_clipf(g_decay_slope, 0.f, 1.f);\n memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));\n memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));\n for (m = 0; m < PS_AP_LINKS; m++) {\n memcpy(ap_delay[k][m], ap_delay[k][m]+numQMFSlots, 5*sizeof(ap_delay[k][m][0]));\n ag[m] = a[m] * g_decay_slope;\n }\n for (n = n0; n < nL; n++) {\n float in_re = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][0] -\n delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][1];\n float in_im = delay[k][n+PS_MAX_DELAY-2][0] * phi_fract[is34][k][1] +\n delay[k][n+PS_MAX_DELAY-2][1] * phi_fract[is34][k][0];\n for (m = 0; m < PS_AP_LINKS; m++) {\n float a_re = ag[m] * in_re;\n float a_im = ag[m] * in_im;\n float link_delay_re = ap_delay[k][m][n+5-link_delay[m]][0];\n float link_delay_im = ap_delay[k][m][n+5-link_delay[m]][1];\n float fractional_delay_re = Q_fract_allpass[is34][k][m][0];\n float fractional_delay_im = Q_fract_allpass[is34][k][m][1];\n ap_delay[k][m][n+5][0] = in_re;\n ap_delay[k][m][n+5][1] = in_im;\n in_re = link_delay_re * fractional_delay_re - link_delay_im * fractional_delay_im - a_re;\n in_im = link_delay_re * fractional_delay_im + link_delay_im * fractional_delay_re - a_im;\n ap_delay[k][m][n+5][0] += ag[m] * in_re;\n ap_delay[k][m][n+5][1] += ag[m] * in_im;\n }\n out[k][n][0] = transient_gain[b][n] * in_re;\n out[k][n][1] = transient_gain[b][n] * in_im;\n }\n }\n for (; k < SHORT_DELAY_BAND[is34]; k++) {\n memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));\n memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));\n for (n = n0; n < nL; n++) {\n out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][0];\n out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-14][1];\n }\n }\n for (; k < NR_BANDS[is34]; k++) {\n memcpy(delay[k], delay[k]+nL, PS_MAX_DELAY*sizeof(delay[k][0]));\n memcpy(delay[k]+PS_MAX_DELAY, s[k], numQMFSlots*sizeof(delay[k][0]));\n for (n = n0; n < nL; n++) {\n out[k][n][0] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][0];\n out[k][n][1] = transient_gain[k_to_i[k]][n] * delay[k][n+PS_MAX_DELAY-1][1];\n }\n }\n}'] |
33,053 | 0 | https://github.com/openssl/openssl/blob/02cba628daa7fea959c561531a8a984756bdf41c/crypto/bn/bn_shift.c/#L115 | int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return (0);
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return (1);
} | ["int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)\n{\n int i, first, len = 0, c, use_bn;\n char ftmp[24], *tmp = ftmp;\n int tmpsize = sizeof ftmp;\n const char *p;\n unsigned long l;\n BIGNUM *bl = NULL;\n if (num == 0)\n return (0);\n else if (num == -1)\n num = strlen(buf);\n p = buf;\n c = *(p++);\n num--;\n if ((c >= '0') && (c <= '2')) {\n first = c - '0';\n } else {\n ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_FIRST_NUM_TOO_LARGE);\n goto err;\n }\n if (num <= 0) {\n ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_MISSING_SECOND_NUMBER);\n goto err;\n }\n c = *(p++);\n num--;\n for (;;) {\n if (num <= 0)\n break;\n if ((c != '.') && (c != ' ')) {\n ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_SEPARATOR);\n goto err;\n }\n l = 0;\n use_bn = 0;\n for (;;) {\n if (num <= 0)\n break;\n num--;\n c = *(p++);\n if ((c == ' ') || (c == '.'))\n break;\n if ((c < '0') || (c > '9')) {\n ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_INVALID_DIGIT);\n goto err;\n }\n if (!use_bn && l >= ((ULONG_MAX - 80) / 10L)) {\n use_bn = 1;\n if (bl == NULL)\n bl = BN_new();\n if (bl == NULL || !BN_set_word(bl, l))\n goto err;\n }\n if (use_bn) {\n if (!BN_mul_word(bl, 10L)\n || !BN_add_word(bl, c - '0'))\n goto err;\n } else\n l = l * 10L + (long)(c - '0');\n }\n if (len == 0) {\n if ((first < 2) && (l >= 40)) {\n ASN1err(ASN1_F_A2D_ASN1_OBJECT,\n ASN1_R_SECOND_NUMBER_TOO_LARGE);\n goto err;\n }\n if (use_bn) {\n if (!BN_add_word(bl, first * 40))\n goto err;\n } else\n l += (long)first *40;\n }\n i = 0;\n if (use_bn) {\n int blsize;\n blsize = BN_num_bits(bl);\n blsize = (blsize + 6) / 7;\n if (blsize > tmpsize) {\n if (tmp != ftmp)\n OPENSSL_free(tmp);\n tmpsize = blsize + 32;\n tmp = OPENSSL_malloc(tmpsize);\n if (tmp == NULL)\n goto err;\n }\n while (blsize--) {\n BN_ULONG t = BN_div_word(bl, 0x80L);\n if (t == (BN_ULONG)-1)\n goto err;\n tmp[i++] = (unsigned char)t;\n }\n } else {\n for (;;) {\n tmp[i++] = (unsigned char)l & 0x7f;\n l >>= 7L;\n if (l == 0L)\n break;\n }\n }\n if (out != NULL) {\n if (len + i > olen) {\n ASN1err(ASN1_F_A2D_ASN1_OBJECT, ASN1_R_BUFFER_TOO_SMALL);\n goto err;\n }\n while (--i > 0)\n out[len++] = tmp[i] | 0x80;\n out[len++] = tmp[0];\n } else\n len += i;\n }\n if (tmp != ftmp)\n OPENSSL_free(tmp);\n BN_free(bl);\n return (len);\n err:\n if (tmp != ftmp)\n OPENSSL_free(tmp);\n BN_free(bl);\n return (0);\n}", 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', '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}'] |
33,054 | 0 | https://github.com/openssl/openssl/blob/819cf4b8868b80a929b90b44493a36d2b3b3581c/crypto/bn/bn_lib.c/#L217 | int BN_num_bits_word(BN_ULONG l)
{
__fips_constseg
static const unsigned char bits[256]={
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
};
#if defined(SIXTY_FOUR_BIT_LONG)
if (l & 0xffffffff00000000L)
{
if (l & 0xffff000000000000L)
{
if (l & 0xff00000000000000L)
{
return(bits[(int)(l>>56)]+56);
}
else return(bits[(int)(l>>48)]+48);
}
else
{
if (l & 0x0000ff0000000000L)
{
return(bits[(int)(l>>40)]+40);
}
else return(bits[(int)(l>>32)]+32);
}
}
else
#else
#ifdef SIXTY_FOUR_BIT
if (l & 0xffffffff00000000LL)
{
if (l & 0xffff000000000000LL)
{
if (l & 0xff00000000000000LL)
{
return(bits[(int)(l>>56)]+56);
}
else return(bits[(int)(l>>48)]+48);
}
else
{
if (l & 0x0000ff0000000000LL)
{
return(bits[(int)(l>>40)]+40);
}
else return(bits[(int)(l>>32)]+32);
}
}
else
#endif
#endif
{
#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
if (l & 0xffff0000L)
{
if (l & 0xff000000L)
return(bits[(int)(l>>24L)]+24);
else return(bits[(int)(l>>16L)]+16);
}
else
#endif
{
#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)
if (l & 0xff00L)
return(bits[(int)(l>>8)]+8);
else
#endif
return(bits[(int)(l )] );
}
}
} | ['int test_div_word(BIO *bp)\n\t{\n\tBIGNUM a,b;\n\tBN_ULONG r,s;\n\tint i;\n\tBN_init(&a);\n\tBN_init(&b);\n\tfor (i=0; i<num0; i++)\n\t\t{\n\t\tdo {\n\t\t\tBN_bntest_rand(&a,512,-1,0);\n\t\t\tBN_bntest_rand(&b,BN_BITS2,-1,0);\n\t\t\ts = b.d[0];\n\t\t} while (!s);\n\t\tBN_copy(&b, &a);\n\t\tr = BN_div_word(&b, s);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,&a);\n\t\t\t\tBIO_puts(bp," / ");\n\t\t\t\tprint_word(bp,s);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,&b);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,&a);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tprint_word(bp,s);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tprint_word(bp,r);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_mul_word(&b,s);\n\t\tBN_add_word(&b,r);\n\t\tBN_sub(&b,&a,&b);\n\t\tif(!BN_is_zero(&b))\n\t\t {\n\t\t fprintf(stderr,"Division (word) test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(&a);\n\tBN_free(&b);\n\treturn(1);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, const 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\ta->neg=b->neg;\n\tbn_check_top(a);\n\treturn(a);\n\t}', 'BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tBN_ULONG ret = 0;\n\tint i, j;\n\tbn_check_top(a);\n\tw &= BN_MASK2;\n\tif (!w)\n\t\treturn (BN_ULONG)-1;\n\tif (a->top == 0)\n\t\treturn 0;\n\tj = BN_BITS2 - BN_num_bits_word(w);\n\tw <<= j;\n\tif (!BN_lshift(a, a, j))\n\t\treturn (BN_ULONG)-1;\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tBN_ULONG l,d;\n\t\tl=a->d[i];\n\t\td=bn_div_words(ret,l,w);\n\t\tret=(l-((d*w)&BN_MASK2))&BN_MASK2;\n\t\ta->d[i]=d;\n\t\t}\n\tif ((a->top > 0) && (a->d[a->top-1] == 0))\n\t\ta->top--;\n\tret >>= j;\n\tbn_check_top(a);\n\treturn(ret);\n\t}', 'int BN_num_bits_word(BN_ULONG l)\n\t{\n\t__fips_constseg\n\tstatic const unsigned char bits[256]={\n\t\t0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,\n\t\t5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,\n\t\t6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n\t\t6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,\n\t\t7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n\t\t7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n\t\t7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n\t\t7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n\t\t};\n#if defined(SIXTY_FOUR_BIT_LONG)\n\tif (l & 0xffffffff00000000L)\n\t\t{\n\t\tif (l & 0xffff000000000000L)\n\t\t\t{\n\t\t\tif (l & 0xff00000000000000L)\n\t\t\t\t{\n\t\t\t\treturn(bits[(int)(l>>56)]+56);\n\t\t\t\t}\n\t\t\telse\treturn(bits[(int)(l>>48)]+48);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (l & 0x0000ff0000000000L)\n\t\t\t\t{\n\t\t\t\treturn(bits[(int)(l>>40)]+40);\n\t\t\t\t}\n\t\t\telse\treturn(bits[(int)(l>>32)]+32);\n\t\t\t}\n\t\t}\n\telse\n#else\n#ifdef SIXTY_FOUR_BIT\n\tif (l & 0xffffffff00000000LL)\n\t\t{\n\t\tif (l & 0xffff000000000000LL)\n\t\t\t{\n\t\t\tif (l & 0xff00000000000000LL)\n\t\t\t\t{\n\t\t\t\treturn(bits[(int)(l>>56)]+56);\n\t\t\t\t}\n\t\t\telse\treturn(bits[(int)(l>>48)]+48);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (l & 0x0000ff0000000000LL)\n\t\t\t\t{\n\t\t\t\treturn(bits[(int)(l>>40)]+40);\n\t\t\t\t}\n\t\t\telse\treturn(bits[(int)(l>>32)]+32);\n\t\t\t}\n\t\t}\n\telse\n#endif\n#endif\n\t\t{\n#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)\n\t\tif (l & 0xffff0000L)\n\t\t\t{\n\t\t\tif (l & 0xff000000L)\n\t\t\t\treturn(bits[(int)(l>>24L)]+24);\n\t\t\telse\treturn(bits[(int)(l>>16L)]+16);\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n#if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)\n\t\t\tif (l & 0xff00L)\n\t\t\t\treturn(bits[(int)(l>>8)]+8);\n\t\t\telse\n#endif\n\t\t\t\treturn(bits[(int)(l )] );\n\t\t\t}\n\t\t}\n\t}'] |
33,055 | 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)];
} | ['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (val2[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_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}'] |
33,056 | 0 | https://github.com/openssl/openssl/blob/ff64702b3d83d4c77756e0fd7b624e2165dbbdf0/crypto/packet.c/#L52 | int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
if (!ossl_assert(pkt->subs != NULL && len != 0))
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->buf != 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 dtls_raw_hello_verify_request(WPACKET *pkt, unsigned char *cookie,\n size_t cookie_len)\n{\n if (!WPACKET_put_bytes_u16(pkt, DTLS1_VERSION)\n || !WPACKET_sub_memcpy_u8(pkt, cookie, cookie_len))\n return 0;\n return 1;\n}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n unsigned char *data;\n if (!ossl_assert(size <= sizeof(unsigned int))\n || !WPACKET_allocate_bytes(pkt, size, &data)\n || !put_value(data, val, size))\n return 0;\n return 1;\n}', 'int WPACKET_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_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n if ((sub = OPENSSL_zalloc(sizeof(*sub))) == NULL) {\n SSLerr(SSL_F_WPACKET_START_SUB_PACKET_LEN__, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n sub->packet_len = pkt->written;\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\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 if (dest != NULL)\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf != 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}'] |
33,057 | 0 | https://github.com/libav/libav/blob/e89aa4bf56e5b5c45f569eb12733519789e057da/libavcodec/mpegvideo.c/#L2154 | void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur,
Picture *last, int y, int h, int picture_structure,
int first_field, int draw_edges, int low_delay,
int v_edge_pos, int h_edge_pos)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
int hshift = desc->log2_chroma_w;
int vshift = desc->log2_chroma_h;
const int field_pic = picture_structure != PICT_FRAME;
if(field_pic){
h <<= 1;
y <<= 1;
}
if (!avctx->hwaccel &&
draw_edges &&
cur->reference &&
!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
int *linesize = cur->f.linesize;
int sides = 0, edge_h;
if (y==0) sides |= EDGE_TOP;
if (y + h >= v_edge_pos)
sides |= EDGE_BOTTOM;
edge_h= FFMIN(h, v_edge_pos - y);
dsp->draw_edges(cur->f.data[0] + y * linesize[0],
linesize[0], h_edge_pos, edge_h,
EDGE_WIDTH, EDGE_WIDTH, sides);
dsp->draw_edges(cur->f.data[1] + (y >> vshift) * linesize[1],
linesize[1], h_edge_pos >> hshift, edge_h >> vshift,
EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);
dsp->draw_edges(cur->f.data[2] + (y >> vshift) * linesize[2],
linesize[2], h_edge_pos >> hshift, edge_h >> vshift,
EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);
}
h = FFMIN(h, avctx->height - y);
if(field_pic && first_field && !(avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;
if (avctx->draw_horiz_band) {
AVFrame *src;
int offset[AV_NUM_DATA_POINTERS];
int i;
if(cur->f.pict_type == AV_PICTURE_TYPE_B || low_delay ||
(avctx->slice_flags & SLICE_FLAG_CODED_ORDER))
src = &cur->f;
else if (last)
src = &last->f;
else
return;
if (cur->f.pict_type == AV_PICTURE_TYPE_B &&
picture_structure == PICT_FRAME &&
avctx->codec_id != AV_CODEC_ID_SVQ3) {
for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
offset[i] = 0;
}else{
offset[0]= y * src->linesize[0];
offset[1]=
offset[2]= (y >> vshift) * src->linesize[1];
for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
offset[i] = 0;
}
emms_c();
avctx->draw_horiz_band(avctx, src, offset,
y, picture_structure, h);
}
} | ['void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur,\n Picture *last, int y, int h, int picture_structure,\n int first_field, int draw_edges, int low_delay,\n int v_edge_pos, int h_edge_pos)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);\n int hshift = desc->log2_chroma_w;\n int vshift = desc->log2_chroma_h;\n const int field_pic = picture_structure != PICT_FRAME;\n if(field_pic){\n h <<= 1;\n y <<= 1;\n }\n if (!avctx->hwaccel &&\n draw_edges &&\n cur->reference &&\n !(avctx->flags & CODEC_FLAG_EMU_EDGE)) {\n int *linesize = cur->f.linesize;\n int sides = 0, edge_h;\n if (y==0) sides |= EDGE_TOP;\n if (y + h >= v_edge_pos)\n sides |= EDGE_BOTTOM;\n edge_h= FFMIN(h, v_edge_pos - y);\n dsp->draw_edges(cur->f.data[0] + y * linesize[0],\n linesize[0], h_edge_pos, edge_h,\n EDGE_WIDTH, EDGE_WIDTH, sides);\n dsp->draw_edges(cur->f.data[1] + (y >> vshift) * linesize[1],\n linesize[1], h_edge_pos >> hshift, edge_h >> vshift,\n EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);\n dsp->draw_edges(cur->f.data[2] + (y >> vshift) * linesize[2],\n linesize[2], h_edge_pos >> hshift, edge_h >> vshift,\n EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);\n }\n h = FFMIN(h, avctx->height - y);\n if(field_pic && first_field && !(avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;\n if (avctx->draw_horiz_band) {\n AVFrame *src;\n int offset[AV_NUM_DATA_POINTERS];\n int i;\n if(cur->f.pict_type == AV_PICTURE_TYPE_B || low_delay ||\n (avctx->slice_flags & SLICE_FLAG_CODED_ORDER))\n src = &cur->f;\n else if (last)\n src = &last->f;\n else\n return;\n if (cur->f.pict_type == AV_PICTURE_TYPE_B &&\n picture_structure == PICT_FRAME &&\n avctx->codec_id != AV_CODEC_ID_SVQ3) {\n for (i = 0; i < AV_NUM_DATA_POINTERS; i++)\n offset[i] = 0;\n }else{\n offset[0]= y * src->linesize[0];\n offset[1]=\n offset[2]= (y >> vshift) * src->linesize[1];\n for (i = 3; i < AV_NUM_DATA_POINTERS; i++)\n offset[i] = 0;\n }\n emms_c();\n avctx->draw_horiz_band(avctx, src, offset,\n y, picture_structure, h);\n }\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}'] |
33,058 | 0 | https://github.com/openssl/openssl/blob/5d99881e6a58a8775b8ca866b794f615a16bb033/crypto/bn/bn_ctx.c/#L273 | 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;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
33,059 | 0 | https://github.com/openssl/openssl/blob/4ebb5293fc7ae1fbb7c5cd8bbe114049bcd8685e/engines/e_sureware.c/#L658 | static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype)
{
EVP_PKEY *res = NULL;
#ifndef OPENSSL_NO_RSA
RSA *rsatmp = NULL;
#endif
#ifndef OPENSSL_NO_DSA
DSA *dsatmp=NULL;
#endif
char msg[64]="sureware_load_public";
int ret=0;
if(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey)
{
SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED);
goto err;
}
switch (keytype)
{
#ifndef OPENSSL_NO_RSA
case 1:
rsatmp = RSA_new_method(e);
RSA_set_ex_data(rsatmp,rsaHndidx,hptr);
rsatmp->flags |= RSA_FLAG_EXT_PKEY;
rsatmp->e = BN_new();
rsatmp->n = BN_new();
bn_expand2(rsatmp->e, el/sizeof(BN_ULONG));
bn_expand2(rsatmp->n, el/sizeof(BN_ULONG));
if (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))||
!rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG)))
goto err;
ret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el,
(unsigned long *)rsatmp->n->d,
(unsigned long *)rsatmp->e->d);
surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret);
if (ret!=1)
{
SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
goto err;
}
rsatmp->e->top=el/sizeof(BN_ULONG);
bn_fix_top(rsatmp->e);
rsatmp->n->top=el/sizeof(BN_ULONG);
bn_fix_top(rsatmp->n);
res = EVP_PKEY_new();
EVP_PKEY_assign_RSA(res, rsatmp);
break;
#endif
#ifndef OPENSSL_NO_DSA
case 2:
dsatmp = DSA_new_method(e);
DSA_set_ex_data(dsatmp,dsaHndidx,hptr);
dsatmp->pub_key = BN_new();
dsatmp->p = BN_new();
dsatmp->q = BN_new();
dsatmp->g = BN_new();
bn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG));
bn_expand2(dsatmp->p, el/sizeof(BN_ULONG));
bn_expand2(dsatmp->q, 20/sizeof(BN_ULONG));
bn_expand2(dsatmp->g, el/sizeof(BN_ULONG));
if (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))||
!dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) ||
!dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) ||
!dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG)))
goto err;
ret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el,
(unsigned long *)dsatmp->pub_key->d,
(unsigned long *)dsatmp->p->d,
(unsigned long *)dsatmp->q->d,
(unsigned long *)dsatmp->g->d);
surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret);
if (ret!=1)
{
SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
goto err;
}
dsatmp->pub_key->top=el/sizeof(BN_ULONG);
bn_fix_top(dsatmp->pub_key);
dsatmp->p->top=el/sizeof(BN_ULONG);
bn_fix_top(dsatmp->p);
dsatmp->q->top=20/sizeof(BN_ULONG);
bn_fix_top(dsatmp->q);
dsatmp->g->top=el/sizeof(BN_ULONG);
bn_fix_top(dsatmp->g);
res = EVP_PKEY_new();
EVP_PKEY_assign_DSA(res, dsatmp);
break;
#endif
default:
SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
return res;
err:
if (res)
EVP_PKEY_free(res);
#ifndef OPENSSL_NO_RSA
if (rsatmp)
RSA_free(rsatmp);
#endif
#ifndef OPENSSL_NO_DSA
if (dsatmp)
DSA_free(dsatmp);
#endif
return NULL;
} | ['static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype)\n{\n\tEVP_PKEY *res = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsatmp = NULL;\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsatmp=NULL;\n#endif\n\tchar msg[64]="sureware_load_public";\n\tint ret=0;\n\tif(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey)\n\t{\n\t\tSUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED);\n\t\tgoto err;\n\t}\n\tswitch (keytype)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tcase 1:\n\t\trsatmp = RSA_new_method(e);\n\t\tRSA_set_ex_data(rsatmp,rsaHndidx,hptr);\n\t\trsatmp->flags |= RSA_FLAG_EXT_PKEY;\n\t\trsatmp->e = BN_new();\n\t\trsatmp->n = BN_new();\n\t\tbn_expand2(rsatmp->e, el/sizeof(BN_ULONG));\n\t\tbn_expand2(rsatmp->n, el/sizeof(BN_ULONG));\n\t\tif (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))||\n\t\t\t!rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG)))\n\t\t\tgoto err;\n\t\tret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el,\n\t\t\t\t\t\t (unsigned long *)rsatmp->n->d,\n\t\t\t\t\t\t (unsigned long *)rsatmp->e->d);\n\t\tsurewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret);\n\t\tif (ret!=1)\n\t\t{\n\t\t\tSUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);\n\t\t\tgoto err;\n\t\t}\n\t\trsatmp->e->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(rsatmp->e);\n\t\trsatmp->n->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(rsatmp->n);\n\t\tres = EVP_PKEY_new();\n\t\tEVP_PKEY_assign_RSA(res, rsatmp);\n\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_DSA\n\tcase 2:\n\t\tdsatmp = DSA_new_method(e);\n\t\tDSA_set_ex_data(dsatmp,dsaHndidx,hptr);\n\t\tdsatmp->pub_key = BN_new();\n\t\tdsatmp->p = BN_new();\n\t\tdsatmp->q = BN_new();\n\t\tdsatmp->g = BN_new();\n\t\tbn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG));\n\t\tbn_expand2(dsatmp->p, el/sizeof(BN_ULONG));\n\t\tbn_expand2(dsatmp->q, 20/sizeof(BN_ULONG));\n\t\tbn_expand2(dsatmp->g, el/sizeof(BN_ULONG));\n\t\tif (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))||\n\t\t\t!dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) ||\n\t\t\t!dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) ||\n\t\t\t!dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG)))\n\t\t\tgoto err;\n\t\tret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el,\n\t\t\t\t\t\t (unsigned long *)dsatmp->pub_key->d,\n\t\t\t\t\t\t (unsigned long *)dsatmp->p->d,\n\t\t\t\t\t\t (unsigned long *)dsatmp->q->d,\n\t\t\t\t\t\t (unsigned long *)dsatmp->g->d);\n\t\tsurewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret);\n\t\tif (ret!=1)\n\t\t{\n\t\t\tSUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);\n\t\t\tgoto err;\n\t\t}\n\t\tdsatmp->pub_key->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->pub_key);\n\t\tdsatmp->p->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->p);\n\t\tdsatmp->q->top=20/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->q);\n\t\tdsatmp->g->top=el/sizeof(BN_ULONG);\n\t\tbn_fix_top(dsatmp->g);\n\t\tres = EVP_PKEY_new();\n\t\tEVP_PKEY_assign_DSA(res, dsatmp);\n\t\tbreak;\n#endif\n\tdefault:\n\t\tSUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY);\n\t\tgoto err;\n\t}\n\treturn res;\n err:\n\tif (res)\n\t\tEVP_PKEY_free(res);\n#ifndef OPENSSL_NO_RSA\n\tif (rsatmp)\n\t\tRSA_free(rsatmp);\n#endif\n#ifndef OPENSSL_NO_DSA\n\tif (dsatmp)\n\t\tDSA_free(dsatmp);\n#endif\n\treturn NULL;\n}', 'RSA *RSA_new_method(ENGINE *engine)\n\t{\n\tRSA *ret;\n\tret=(RSA *)OPENSSL_malloc(sizeof(RSA));\n\tif (ret == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tret->meth = RSA_get_default_method();\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_RSA();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_RSA(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD,\n\t\t\t\tERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\tret->pad=0;\n\tret->version=0;\n\tret->n=NULL;\n\tret->e=NULL;\n\tret->d=NULL;\n\tret->p=NULL;\n\tret->q=NULL;\n\tret->dmp1=NULL;\n\tret->dmq1=NULL;\n\tret->iqmp=NULL;\n\tret->references=1;\n\tret->_method_mod_n=NULL;\n\tret->_method_mod_p=NULL;\n\tret->_method_mod_q=NULL;\n\tret->blinding=NULL;\n\tret->bignum_data=NULL;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\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_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}'] |
33,060 | 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 dsa_builtin_keygen(DSA *dsa)\n{\n int ok = 0;\n BN_CTX *ctx = NULL;\n BIGNUM *pub_key = NULL, *priv_key = NULL;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n if (dsa->priv_key == NULL) {\n if ((priv_key = BN_secure_new()) == NULL)\n goto err;\n } else\n priv_key = dsa->priv_key;\n do\n if (!BN_rand_range(priv_key, dsa->q))\n goto err;\n while (BN_is_zero(priv_key)) ;\n if (dsa->pub_key == NULL) {\n if ((pub_key = BN_new()) == NULL)\n goto err;\n } else\n pub_key = dsa->pub_key;\n {\n BIGNUM *prk = BN_new();\n if (prk == NULL)\n goto err;\n BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {\n BN_free(prk);\n goto err;\n }\n BN_free(prk);\n }\n dsa->priv_key = priv_key;\n dsa->pub_key = pub_key;\n ok = 1;\n err:\n if (pub_key != dsa->pub_key)\n BN_free(pub_key);\n if (priv_key != dsa->priv_key)\n BN_free(priv_key);\n BN_CTX_free(ctx);\n return (ok);\n}', 'int BN_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 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', '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}'] |
33,061 | 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 decode_gain_control(BitstreamContext *bc, GainBlock *block,\n int num_bands)\n{\n int i, j;\n int *level, *loc;\n AtracGainInfo *gain = block->g_block;\n for (i = 0; i <= num_bands; i++) {\n gain[i].num_points = bitstream_read(bc, 3);\n level = gain[i].lev_code;\n loc = gain[i].loc_code;\n for (j = 0; j < gain[i].num_points; j++) {\n level[j] = bitstream_read(bc, 4);\n loc[j] = bitstream_read(bc, 5);\n if (j && loc[j] <= loc[j - 1])\n return AVERROR_INVALIDDATA;\n }\n }\n for (; i < 4 ; i++)\n gain[i].num_points = 0;\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}'] |
33,062 | 0 | https://github.com/openssl/openssl/blob/a3a2ff4cd9ada10effaa514af90c7638ab0e9824/ssl/s3_srvr.c/#L2102 | static int ssl3_get_client_key_exchange(SSL *s)
{
int i,al,ok;
long n;
unsigned long l;
unsigned char *p;
#ifndef OPENSSL_NO_RSA
RSA *rsa=NULL;
EVP_PKEY *pkey=NULL;
#endif
#ifndef OPENSSL_NO_DH
BIGNUM *pub=NULL;
DH *dh_srvr;
#endif
#ifndef OPENSSL_NO_KRB5
KSSL_ERR kssl_err;
#endif
#ifndef OPENSSL_NO_ECDH
EC_KEY *srvr_ecdh = NULL;
EVP_PKEY *clnt_pub_pkey = NULL;
EC_POINT *clnt_ecpoint = NULL;
BN_CTX *bn_ctx = NULL;
#endif
n=ssl3_get_message(s,
SSL3_ST_SR_KEY_EXCH_A,
SSL3_ST_SR_KEY_EXCH_B,
SSL3_MT_CLIENT_KEY_EXCHANGE,
2048,
&ok);
if (!ok) return((int)n);
p=(unsigned char *)s->init_msg;
l=s->s3->tmp.new_cipher->algorithms;
#ifndef OPENSSL_NO_RSA
if (l & SSL_kRSA)
{
if (s->s3->tmp.use_rsa_tmp)
{
if ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))
rsa=s->cert->rsa_tmp;
if (rsa == NULL)
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);
goto f_err;
}
}
else
{
pkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;
if ( (pkey == NULL) ||
(pkey->type != EVP_PKEY_RSA) ||
(pkey->pkey.rsa == NULL))
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);
goto f_err;
}
rsa=pkey->pkey.rsa;
}
if (s->version > SSL3_VERSION)
{
n2s(p,i);
if (n != i+2)
{
if (!(s->options & SSL_OP_TLS_D5_BUG))
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
goto err;
}
else
p-=2;
}
else
n=i;
}
i=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);
al = -1;
if (i != SSL_MAX_MASTER_KEY_LENGTH)
{
al=SSL_AD_DECODE_ERROR;
}
if ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))
{
if (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&
(p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))
{
al=SSL_AD_DECODE_ERROR;
}
}
if (al != -1)
{
ERR_clear_error();
i = SSL_MAX_MASTER_KEY_LENGTH;
p[0] = s->client_version >> 8;
p[1] = s->client_version & 0xff;
RAND_pseudo_bytes(p+2, i-2);
}
s->session->master_key_length=
s->method->ssl3_enc->generate_master_secret(s,
s->session->master_key,
p,i);
OPENSSL_cleanse(p,i);
}
else
#endif
#ifndef OPENSSL_NO_DH
if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
{
n2s(p,i);
if (n != i+2)
{
if (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
goto err;
}
else
{
p-=2;
i=(int)n;
}
}
if (n == 0L)
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);
goto f_err;
}
else
{
if (s->s3->tmp.dh == NULL)
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);
goto f_err;
}
else
dh_srvr=s->s3->tmp.dh;
}
pub=BN_bin2bn(p,i,NULL);
if (pub == NULL)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);
goto err;
}
i=DH_compute_key(p,pub,dh_srvr);
if (i <= 0)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
goto err;
}
DH_free(s->s3->tmp.dh);
s->s3->tmp.dh=NULL;
BN_clear_free(pub);
pub=NULL;
s->session->master_key_length=
s->method->ssl3_enc->generate_master_secret(s,
s->session->master_key,p,i);
OPENSSL_cleanse(p,i);
}
else
#endif
#ifndef OPENSSL_NO_KRB5
if (l & SSL_kKRB5)
{
krb5_error_code krb5rc;
krb5_data enc_ticket;
krb5_data authenticator;
krb5_data enc_pms;
KSSL_CTX *kssl_ctx = s->kssl_ctx;
EVP_CIPHER_CTX ciph_ctx;
EVP_CIPHER *enc = NULL;
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char pms[SSL_MAX_MASTER_KEY_LENGTH
+ EVP_MAX_BLOCK_LENGTH];
int padl, outl;
krb5_timestamp authtime = 0;
krb5_ticket_times ttimes;
EVP_CIPHER_CTX_init(&ciph_ctx);
if (!kssl_ctx) kssl_ctx = kssl_ctx_new();
n2s(p,i);
enc_ticket.length = i;
enc_ticket.data = (char *)p;
p+=enc_ticket.length;
n2s(p,i);
authenticator.length = i;
authenticator.data = (char *)p;
p+=authenticator.length;
n2s(p,i);
enc_pms.length = i;
enc_pms.data = (char *)p;
p+=enc_pms.length;
if(enc_pms.length > sizeof pms)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DATA_LENGTH_TOO_LONG);
goto err;
}
if (n != enc_ticket.length + authenticator.length +
enc_pms.length + 6)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DATA_LENGTH_TOO_LONG);
goto err;
}
if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,
&kssl_err)) != 0)
{
#ifdef KSSL_DEBUG
printf("kssl_sget_tkt rtn %d [%d]\n",
krb5rc, kssl_err.reason);
if (kssl_err.text)
printf("kssl_err text= %s\n", kssl_err.text);
#endif
SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
kssl_err.reason);
goto err;
}
if ((krb5rc = kssl_check_authent(kssl_ctx, &authenticator,
&authtime, &kssl_err)) != 0)
{
#ifdef KSSL_DEBUG
printf("kssl_check_authent rtn %d [%d]\n",
krb5rc, kssl_err.reason);
if (kssl_err.text)
printf("kssl_err text= %s\n", kssl_err.text);
#endif
SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,
kssl_err.reason);
goto err;
}
if ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0)
{
SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, krb5rc);
goto err;
}
#ifdef KSSL_DEBUG
kssl_ctx_show(kssl_ctx);
#endif
enc = kssl_map_enc(kssl_ctx->enctype);
if (enc == NULL)
goto err;
memset(iv, 0, sizeof iv);
if (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv))
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DECRYPTION_FAILED);
goto err;
}
if (!EVP_DecryptUpdate(&ciph_ctx, pms,&outl,
(unsigned char *)enc_pms.data, enc_pms.length))
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DECRYPTION_FAILED);
goto err;
}
if (outl > SSL_MAX_MASTER_KEY_LENGTH)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DATA_LENGTH_TOO_LONG);
goto err;
}
if (!EVP_DecryptFinal_ex(&ciph_ctx,&(pms[outl]),&padl))
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DECRYPTION_FAILED);
goto err;
}
outl += padl;
if (outl > SSL_MAX_MASTER_KEY_LENGTH)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_DATA_LENGTH_TOO_LONG);
goto err;
}
EVP_CIPHER_CTX_cleanup(&ciph_ctx);
s->session->master_key_length=
s->method->ssl3_enc->generate_master_secret(s,
s->session->master_key, pms, outl);
if (kssl_ctx->client_princ)
{
int len = strlen(kssl_ctx->client_princ);
if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH )
{
s->session->krb5_client_princ_len = len;
memcpy(s->session->krb5_client_princ,kssl_ctx->client_princ,len);
}
}
}
else
#endif
#ifndef OPENSSL_NO_ECDH
if ((l & SSL_kECDH) || (l & SSL_kECDHE))
{
int ret = 1;
if ((srvr_ecdh = EC_KEY_new()) == NULL)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
ERR_R_MALLOC_FAILURE);
goto err;
}
if (l & SSL_kECDH)
{
srvr_ecdh->group = s->cert->key->privatekey-> \
pkey.eckey->group;
srvr_ecdh->priv_key = s->cert->key->privatekey-> \
pkey.eckey->priv_key;
}
else
{
srvr_ecdh->group = s->s3->tmp.ecdh->group;
srvr_ecdh->priv_key = s->s3->tmp.ecdh->priv_key;
}
if ((clnt_ecpoint = EC_POINT_new(srvr_ecdh->group))
== NULL)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
ERR_R_MALLOC_FAILURE);
goto err;
}
if (n == 0L)
{
if (l & SSL_kECDHE)
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY);
goto f_err;
}
if (((clnt_pub_pkey=X509_get_pubkey(s->session->peer))
== NULL) ||
(clnt_pub_pkey->type != EVP_PKEY_EC))
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_UNABLE_TO_DECODE_ECDH_CERTS);
goto f_err;
}
EC_POINT_copy(clnt_ecpoint,
clnt_pub_pkey->pkey.eckey->pub_key);
ret = 2;
}
else
{
if ((bn_ctx = BN_CTX_new()) == NULL)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
ERR_R_MALLOC_FAILURE);
goto err;
}
i = *p;
p += 1;
if (EC_POINT_oct2point(srvr_ecdh->group,
clnt_ecpoint, p, i, bn_ctx) == 0)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
ERR_R_EC_LIB);
goto err;
}
p=(unsigned char *)s->init_buf->data;
}
i = ECDH_compute_key(p, KDF1_SHA1_len, clnt_ecpoint, srvr_ecdh, KDF1_SHA1);
if (i <= 0)
{
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
ERR_R_ECDH_LIB);
goto err;
}
EVP_PKEY_free(clnt_pub_pkey);
EC_POINT_free(clnt_ecpoint);
if (srvr_ecdh != NULL)
{
srvr_ecdh->priv_key = NULL;
srvr_ecdh->group = NULL;
EC_KEY_free(srvr_ecdh);
}
BN_CTX_free(bn_ctx);
s->session->master_key_length = s->method->ssl3_enc-> \
generate_master_secret(s, s->session->master_key, p, i);
OPENSSL_cleanse(p, i);
return (ret);
}
else
#endif
{
al=SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,
SSL_R_UNKNOWN_CIPHER_TYPE);
goto f_err;
}
return(1);
f_err:
ssl3_send_alert(s,SSL3_AL_FATAL,al);
#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH)
err:
#endif
#ifndef OPENSSL_NO_ECDH
EVP_PKEY_free(clnt_pub_pkey);
EC_POINT_free(clnt_ecpoint);
if (srvr_ecdh != NULL)
{
srvr_ecdh->priv_key = NULL;
srvr_ecdh->group = NULL;
EC_KEY_free(srvr_ecdh);
}
BN_CTX_free(bn_ctx);
#endif
return(-1);
} | ['static int ssl3_get_client_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long l;\n\tunsigned char *p;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef OPENSSL_NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n#ifndef OPENSSL_NO_KRB5\n KSSL_ERR kssl_err;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *srvr_ecdh = NULL;\n\tEVP_PKEY *clnt_pub_pkey = NULL;\n\tEC_POINT *clnt_ecpoint = NULL;\n\tBN_CTX *bn_ctx = NULL;\n#endif\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t2048,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_msg;\n\tl=s->s3->tmp.new_cipher->algorithms;\n#ifndef OPENSSL_NO_RSA\n\tif (l & SSL_kRSA)\n\t\t{\n\t\tif (s->s3->tmp.use_rsa_tmp)\n\t\t\t{\n\t\t\tif ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))\n\t\t\t\trsa=s->cert->rsa_tmp;\n\t\t\tif (rsa == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;\n\t\t\tif (\t(pkey == NULL) ||\n\t\t\t\t(pkey->type != EVP_PKEY_RSA) ||\n\t\t\t\t(pkey->pkey.rsa == NULL))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\trsa=pkey->pkey.rsa;\n\t\t\t}\n\t\tif (s->version > SSL3_VERSION)\n\t\t\t{\n\t\t\tn2s(p,i);\n\t\t\tif (n != i+2)\n\t\t\t\t{\n\t\t\t\tif (!(s->options & SSL_OP_TLS_D5_BUG))\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tp-=2;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tn=i;\n\t\t\t}\n\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n\t\tal = -1;\n\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\t}\n\t\tif ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff))))\n\t\t\t{\n\t\t\tif (!((s->options & SSL_OP_TLS_ROLLBACK_BUG) &&\n\t\t\t\t(p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff))))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\t\t}\n\t\t\t}\n\t\tif (al != -1)\n\t\t\t{\n\t\t\tERR_clear_error();\n\t\t\ti = SSL_MAX_MASTER_KEY_LENGTH;\n\t\t\tp[0] = s->client_version >> 8;\n\t\t\tp[1] = s->client_version & 0xff;\n\t\t\tRAND_pseudo_bytes(p+2, i-2);\n\t\t\t}\n\t\ts->session->master_key_length=\n\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\ts->session->master_key,\n\t\t\t\tp,i);\n\t\tOPENSSL_cleanse(p,i);\n\t\t}\n\telse\n#endif\n#ifndef OPENSSL_NO_DH\n\t\tif (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t{\n\t\tn2s(p,i);\n\t\tif (n != i+2)\n\t\t\t{\n\t\t\tif (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tp-=2;\n\t\t\t\ti=(int)n;\n\t\t\t\t}\n\t\t\t}\n\t\tif (n == 0L)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (s->s3->tmp.dh == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tdh_srvr=s->s3->tmp.dh;\n\t\t\t}\n\t\tpub=BN_bin2bn(p,i,NULL);\n\t\tif (pub == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ti=DH_compute_key(p,pub,dh_srvr);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tDH_free(s->s3->tmp.dh);\n\t\ts->s3->tmp.dh=NULL;\n\t\tBN_clear_free(pub);\n\t\tpub=NULL;\n\t\ts->session->master_key_length=\n\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\ts->session->master_key,p,i);\n\t\tOPENSSL_cleanse(p,i);\n\t\t}\n\telse\n#endif\n#ifndef OPENSSL_NO_KRB5\n if (l & SSL_kKRB5)\n {\n krb5_error_code\t\tkrb5rc;\n\t\tkrb5_data\t\tenc_ticket;\n\t\tkrb5_data\t\tauthenticator;\n\t\tkrb5_data\t\tenc_pms;\n KSSL_CTX\t\t*kssl_ctx = s->kssl_ctx;\n\t\tEVP_CIPHER_CTX\t\tciph_ctx;\n\t\tEVP_CIPHER\t\t*enc = NULL;\n\t\tunsigned char\t\tiv[EVP_MAX_IV_LENGTH];\n\t\tunsigned char\t\tpms[SSL_MAX_MASTER_KEY_LENGTH\n + EVP_MAX_BLOCK_LENGTH];\n\t\tint padl, outl;\n\t\tkrb5_timestamp\t\tauthtime = 0;\n\t\tkrb5_ticket_times\tttimes;\n\t\tEVP_CIPHER_CTX_init(&ciph_ctx);\n if (!kssl_ctx) kssl_ctx = kssl_ctx_new();\n\t\tn2s(p,i);\n\t\tenc_ticket.length = i;\n\t\tenc_ticket.data = (char *)p;\n\t\tp+=enc_ticket.length;\n\t\tn2s(p,i);\n\t\tauthenticator.length = i;\n\t\tauthenticator.data = (char *)p;\n\t\tp+=authenticator.length;\n\t\tn2s(p,i);\n\t\tenc_pms.length = i;\n\t\tenc_pms.data = (char *)p;\n\t\tp+=enc_pms.length;\n\t\tif(enc_pms.length > sizeof pms)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t SSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (n != enc_ticket.length + authenticator.length +\n\t\t\t\t\t\tenc_pms.length + 6)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n if ((krb5rc = kssl_sget_tkt(kssl_ctx, &enc_ticket, &ttimes,\n\t\t\t\t\t&kssl_err)) != 0)\n {\n#ifdef KSSL_DEBUG\n printf("kssl_sget_tkt rtn %d [%d]\\n",\n krb5rc, kssl_err.reason);\n if (kssl_err.text)\n printf("kssl_err text= %s\\n", kssl_err.text);\n#endif\n SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,\n kssl_err.reason);\n goto err;\n }\n\t\tif ((krb5rc = kssl_check_authent(kssl_ctx, &authenticator,\n\t\t\t\t\t&authtime, &kssl_err)) != 0)\n\t\t\t{\n#ifdef KSSL_DEBUG\n printf("kssl_check_authent rtn %d [%d]\\n",\n krb5rc, kssl_err.reason);\n if (kssl_err.text)\n printf("kssl_err text= %s\\n", kssl_err.text);\n#endif\n SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,\n kssl_err.reason);\n goto err;\n\t\t\t}\n\t\tif ((krb5rc = kssl_validate_times(authtime, &ttimes)) != 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE, krb5rc);\n goto err;\n\t\t\t}\n#ifdef KSSL_DEBUG\n kssl_ctx_show(kssl_ctx);\n#endif\n\t\tenc = kssl_map_enc(kssl_ctx->enctype);\n if (enc == NULL)\n goto err;\n\t\tmemset(iv, 0, sizeof iv);\n\t\tif (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DECRYPTION_FAILED);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!EVP_DecryptUpdate(&ciph_ctx, pms,&outl,\n\t\t\t\t\t(unsigned char *)enc_pms.data, enc_pms.length))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DECRYPTION_FAILED);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (outl > SSL_MAX_MASTER_KEY_LENGTH)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!EVP_DecryptFinal_ex(&ciph_ctx,&(pms[outl]),&padl))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DECRYPTION_FAILED);\n\t\t\tgoto err;\n\t\t\t}\n\t\toutl += padl;\n\t\tif (outl > SSL_MAX_MASTER_KEY_LENGTH)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_DATA_LENGTH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tEVP_CIPHER_CTX_cleanup(&ciph_ctx);\n s->session->master_key_length=\n s->method->ssl3_enc->generate_master_secret(s,\n s->session->master_key, pms, outl);\n if (kssl_ctx->client_princ)\n {\n int len = strlen(kssl_ctx->client_princ);\n if ( len < SSL_MAX_KRB5_PRINCIPAL_LENGTH )\n {\n s->session->krb5_client_princ_len = len;\n memcpy(s->session->krb5_client_princ,kssl_ctx->client_princ,len);\n }\n }\n }\n\telse\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\tif ((l & SSL_kECDH) || (l & SSL_kECDHE))\n\t\t{\n\t\tint ret = 1;\n\t\tif ((srvr_ecdh = EC_KEY_new()) == NULL)\n\t\t\t{\n \tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t ERR_R_MALLOC_FAILURE);\n \tgoto err;\n\t\t\t}\n\t\tif (l & SSL_kECDH)\n\t\t\t{\n\t\t\tsrvr_ecdh->group = s->cert->key->privatekey-> \\\n\t\t\t pkey.eckey->group;\n\t\t\tsrvr_ecdh->priv_key = s->cert->key->privatekey-> \\\n\t\t\t pkey.eckey->priv_key;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsrvr_ecdh->group = s->s3->tmp.ecdh->group;\n\t\t\tsrvr_ecdh->priv_key = s->s3->tmp.ecdh->priv_key;\n\t\t\t}\n\t\tif ((clnt_ecpoint = EC_POINT_new(srvr_ecdh->group))\n\t\t == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n if (n == 0L)\n {\n\t\t\t if (l & SSL_kECDHE)\n\t\t\t\t {\n\t\t\t\t al=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\t SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY);\n\t\t\t\t goto f_err;\n\t\t\t\t }\n if (((clnt_pub_pkey=X509_get_pubkey(s->session->peer))\n\t\t\t == NULL) ||\n\t\t\t (clnt_pub_pkey->type != EVP_PKEY_EC))\n \t{\n \tal=SSL_AD_HANDSHAKE_FAILURE;\n \tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\t SSL_R_UNABLE_TO_DECODE_ECDH_CERTS);\n \tgoto f_err;\n \t}\n\t\t\tEC_POINT_copy(clnt_ecpoint,\n\t\t\t clnt_pub_pkey->pkey.eckey->pub_key);\n ret = 2;\n }\n else\n {\n\t\t\tif ((bn_ctx = BN_CTX_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\t ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n i = *p;\n\t\t\tp += 1;\n if (EC_POINT_oct2point(srvr_ecdh->group,\n\t\t\t clnt_ecpoint, p, i, bn_ctx) == 0)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\t ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n p=(unsigned char *)s->init_buf->data;\n }\n i = ECDH_compute_key(p, KDF1_SHA1_len, clnt_ecpoint, srvr_ecdh, KDF1_SHA1);\n if (i <= 0)\n {\n SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t ERR_R_ECDH_LIB);\n goto err;\n }\n\t\tEVP_PKEY_free(clnt_pub_pkey);\n\t\tEC_POINT_free(clnt_ecpoint);\n\t\tif (srvr_ecdh != NULL)\n\t\t\t{\n\t\t\tsrvr_ecdh->priv_key = NULL;\n\t\t\tsrvr_ecdh->group = NULL;\n\t\t\tEC_KEY_free(srvr_ecdh);\n\t\t\t}\n\t\tBN_CTX_free(bn_ctx);\n s->session->master_key_length = s->method->ssl3_enc-> \\\n\t\t generate_master_secret(s, s->session->master_key, p, i);\n OPENSSL_cleanse(p, i);\n return (ret);\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,\n\t\t\t\tSSL_R_UNKNOWN_CIPHER_TYPE);\n\t\tgoto f_err;\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH)\nerr:\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEVP_PKEY_free(clnt_pub_pkey);\n\tEC_POINT_free(clnt_ecpoint);\n\tif (srvr_ecdh != NULL)\n\t\t{\n\t\tsrvr_ecdh->priv_key = NULL;\n\t\tsrvr_ecdh->group = NULL;\n\t\tEC_KEY_free(srvr_ecdh);\n\t\t}\n\tBN_CTX_free(bn_ctx);\n#endif\n\treturn(-1);\n\t}', 'int DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)\n\t{\n\treturn dh->meth->compute_key(key, pub_key, dh);\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}'] |
33,063 | 0 | https://github.com/openssl/openssl/blob/adf652436a42a5132e708f8003b7621647f0a404/crypto/bn/bn_lib.c/#L233 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['int DH_check(const DH *dh, int *ret)\n{\n int ok = 0, r;\n BN_CTX *ctx = NULL;\n BN_ULONG l;\n BIGNUM *t1 = NULL, *t2 = NULL;\n *ret = 0;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (dh->q) {\n if (BN_cmp(dh->g, BN_value_one()) <= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else if (BN_cmp(dh->g, dh->p) >= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else {\n if (!BN_mod_exp(t1, dh->g, dh->q, dh->p, ctx))\n goto err;\n if (!BN_is_one(t1))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n }\n r = BN_is_prime_ex(dh->q, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_Q_NOT_PRIME;\n if (!BN_div(t1, t2, dh->p, dh->q, ctx))\n goto err;\n if (!BN_is_one(t2))\n *ret |= DH_CHECK_INVALID_Q_VALUE;\n if (dh->j && BN_cmp(dh->j, t1))\n *ret |= DH_CHECK_INVALID_J_VALUE;\n } else if (BN_is_word(dh->g, DH_GENERATOR_2)) {\n l = BN_mod_word(dh->p, 24);\n if (l == (BN_ULONG)-1)\n goto err;\n if (l != 11)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else if (BN_is_word(dh->g, DH_GENERATOR_5)) {\n l = BN_mod_word(dh->p, 10);\n if (l == (BN_ULONG)-1)\n goto err;\n if ((l != 3) && (l != 7))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else\n *ret |= DH_UNABLE_TO_CHECK_GENERATOR;\n r = BN_is_prime_ex(dh->p, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_PRIME;\n else if (!dh->q) {\n if (!BN_rshift1(t1, dh->p))\n goto err;\n r = BN_is_prime_ex(t1, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_SAFE_PRIME;\n }\n ok = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}'] |
33,064 | 0 | https://github.com/libav/libav/blob/e4e30256f87f177decf59b59e923d05ef64147df/libavcodec/mpegvideo_enc.c/#L1963 | static av_always_inline void encode_mb_internal(MpegEncContext *s,
int motion_x, int motion_y,
int mb_block_height,
int mb_block_count)
{
int16_t weight[8][64];
DCTELEM orig[8][64];
const int mb_x = s->mb_x;
const int mb_y = s->mb_y;
int i;
int skip_dct[8];
int dct_offset = s->linesize * 8;
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
int wrap_y, wrap_c;
for (i = 0; i < mb_block_count; i++)
skip_dct[i] = s->skipdct;
if (s->adaptive_quant) {
const int last_qp = s->qscale;
const int mb_xy = mb_x + mb_y * s->mb_stride;
s->lambda = s->lambda_table[mb_xy];
update_qscale(s);
if (!(s->flags & CODEC_FLAG_QP_RD)) {
s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];
s->dquant = s->qscale - last_qp;
if (s->out_format == FMT_H263) {
s->dquant = av_clip(s->dquant, -2, 2);
if (s->codec_id == CODEC_ID_MPEG4) {
if (!s->mb_intra) {
if (s->pict_type == AV_PICTURE_TYPE_B) {
if (s->dquant & 1 || s->mv_dir & MV_DIRECT)
s->dquant = 0;
}
if (s->mv_type == MV_TYPE_8X8)
s->dquant = 0;
}
}
}
}
ff_set_qscale(s, last_qp + s->dquant);
} else if (s->flags & CODEC_FLAG_QP_RD)
ff_set_qscale(s, s->qscale + s->dquant);
wrap_y = s->linesize;
wrap_c = s->uvlinesize;
ptr_y = s->new_picture.f.data[0] +
(mb_y * 16 * wrap_y) + mb_x * 16;
ptr_cb = s->new_picture.f.data[1] +
(mb_y * mb_block_height * wrap_c) + mb_x * 8;
ptr_cr = s->new_picture.f.data[2] +
(mb_y * mb_block_height * wrap_c) + mb_x * 8;
if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) {
uint8_t *ebuf = s->edge_emu_buffer + 32;
s->dsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16,
mb_y * 16, s->width, s->height);
ptr_y = ebuf;
s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8,
mb_block_height, mb_x * 8, mb_y * 8,
s->width >> 1, s->height >> 1);
ptr_cb = ebuf + 18 * wrap_y;
s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8,
mb_block_height, mb_x * 8, mb_y * 8,
s->width >> 1, s->height >> 1);
ptr_cr = ebuf + 18 * wrap_y + 8;
}
if (s->mb_intra) {
if (s->flags & CODEC_FLAG_INTERLACED_DCT) {
int progressive_score, interlaced_score;
s->interlaced_dct = 0;
progressive_score = s->dsp.ildct_cmp[4](s, ptr_y,
NULL, wrap_y, 8) +
s->dsp.ildct_cmp[4](s, ptr_y + wrap_y * 8,
NULL, wrap_y, 8) - 400;
if (progressive_score > 0) {
interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y,
NULL, wrap_y * 2, 8) +
s->dsp.ildct_cmp[4](s, ptr_y + wrap_y,
NULL, wrap_y * 2, 8);
if (progressive_score > interlaced_score) {
s->interlaced_dct = 1;
dct_offset = wrap_y;
wrap_y <<= 1;
if (s->chroma_format == CHROMA_422)
wrap_c <<= 1;
}
}
}
s->dsp.get_pixels(s->block[0], ptr_y , wrap_y);
s->dsp.get_pixels(s->block[1], ptr_y + 8 , wrap_y);
s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y);
s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8 , wrap_y);
if (s->flags & CODEC_FLAG_GRAY) {
skip_dct[4] = 1;
skip_dct[5] = 1;
} else {
s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c);
s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c);
if (!s->chroma_y_shift) {
s->dsp.get_pixels(s->block[6],
ptr_cb + (dct_offset >> 1), wrap_c);
s->dsp.get_pixels(s->block[7],
ptr_cr + (dct_offset >> 1), wrap_c);
}
}
} else {
op_pixels_func (*op_pix)[4];
qpel_mc_func (*op_qpix)[16];
uint8_t *dest_y, *dest_cb, *dest_cr;
dest_y = s->dest[0];
dest_cb = s->dest[1];
dest_cr = s->dest[2];
if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
op_pix = s->dsp.put_pixels_tab;
op_qpix = s->dsp.put_qpel_pixels_tab;
} else {
op_pix = s->dsp.put_no_rnd_pixels_tab;
op_qpix = s->dsp.put_no_rnd_qpel_pixels_tab;
}
if (s->mv_dir & MV_DIR_FORWARD) {
MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data,
op_pix, op_qpix);
op_pix = s->dsp.avg_pixels_tab;
op_qpix = s->dsp.avg_qpel_pixels_tab;
}
if (s->mv_dir & MV_DIR_BACKWARD) {
MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data,
op_pix, op_qpix);
}
if (s->flags & CODEC_FLAG_INTERLACED_DCT) {
int progressive_score, interlaced_score;
s->interlaced_dct = 0;
progressive_score = s->dsp.ildct_cmp[0](s, dest_y,
ptr_y, wrap_y,
8) +
s->dsp.ildct_cmp[0](s, dest_y + wrap_y * 8,
ptr_y + wrap_y * 8, wrap_y,
8) - 400;
if (s->avctx->ildct_cmp == FF_CMP_VSSE)
progressive_score -= 400;
if (progressive_score > 0) {
interlaced_score = s->dsp.ildct_cmp[0](s, dest_y,
ptr_y,
wrap_y * 2, 8) +
s->dsp.ildct_cmp[0](s, dest_y + wrap_y,
ptr_y + wrap_y,
wrap_y * 2, 8);
if (progressive_score > interlaced_score) {
s->interlaced_dct = 1;
dct_offset = wrap_y;
wrap_y <<= 1;
if (s->chroma_format == CHROMA_422)
wrap_c <<= 1;
}
}
}
s->dsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y);
s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset,
dest_y + dct_offset, wrap_y);
s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8,
dest_y + dct_offset + 8, wrap_y);
if (s->flags & CODEC_FLAG_GRAY) {
skip_dct[4] = 1;
skip_dct[5] = 1;
} else {
s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
if (!s->chroma_y_shift) {
s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset >> 1),
dest_cb + (dct_offset >> 1), wrap_c);
s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset >> 1),
dest_cr + (dct_offset >> 1), wrap_c);
}
}
if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] <
2 * s->qscale * s->qscale) {
if (s->dsp.sad[1](NULL, ptr_y , dest_y,
wrap_y, 8) < 20 * s->qscale)
skip_dct[0] = 1;
if (s->dsp.sad[1](NULL, ptr_y + 8,
dest_y + 8, wrap_y, 8) < 20 * s->qscale)
skip_dct[1] = 1;
if (s->dsp.sad[1](NULL, ptr_y + dct_offset,
dest_y + dct_offset, wrap_y, 8) < 20 * s->qscale)
skip_dct[2] = 1;
if (s->dsp.sad[1](NULL, ptr_y + dct_offset + 8,
dest_y + dct_offset + 8,
wrap_y, 8) < 20 * s->qscale)
skip_dct[3] = 1;
if (s->dsp.sad[1](NULL, ptr_cb, dest_cb,
wrap_c, 8) < 20 * s->qscale)
skip_dct[4] = 1;
if (s->dsp.sad[1](NULL, ptr_cr, dest_cr,
wrap_c, 8) < 20 * s->qscale)
skip_dct[5] = 1;
if (!s->chroma_y_shift) {
if (s->dsp.sad[1](NULL, ptr_cb + (dct_offset >> 1),
dest_cb + (dct_offset >> 1),
wrap_c, 8) < 20 * s->qscale)
skip_dct[6] = 1;
if (s->dsp.sad[1](NULL, ptr_cr + (dct_offset >> 1),
dest_cr + (dct_offset >> 1),
wrap_c, 8) < 20 * s->qscale)
skip_dct[7] = 1;
}
}
}
if (s->avctx->quantizer_noise_shaping) {
if (!skip_dct[0])
get_visual_weight(weight[0], ptr_y , wrap_y);
if (!skip_dct[1])
get_visual_weight(weight[1], ptr_y + 8, wrap_y);
if (!skip_dct[2])
get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y);
if (!skip_dct[3])
get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);
if (!skip_dct[4])
get_visual_weight(weight[4], ptr_cb , wrap_c);
if (!skip_dct[5])
get_visual_weight(weight[5], ptr_cr , wrap_c);
if (!s->chroma_y_shift) {
if (!skip_dct[6])
get_visual_weight(weight[6], ptr_cb + (dct_offset >> 1),
wrap_c);
if (!skip_dct[7])
get_visual_weight(weight[7], ptr_cr + (dct_offset >> 1),
wrap_c);
}
memcpy(orig[0], s->block[0], sizeof(DCTELEM) * 64 * mb_block_count);
}
assert(s->out_format != FMT_MJPEG || s->qscale == 8);
{
for (i = 0; i < mb_block_count; i++) {
if (!skip_dct[i]) {
int overflow;
s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);
if (overflow)
clip_coeffs(s, s->block[i], s->block_last_index[i]);
} else
s->block_last_index[i] = -1;
}
if (s->avctx->quantizer_noise_shaping) {
for (i = 0; i < mb_block_count; i++) {
if (!skip_dct[i]) {
s->block_last_index[i] =
dct_quantize_refine(s, s->block[i], weight[i],
orig[i], i, s->qscale);
}
}
}
if (s->luma_elim_threshold && !s->mb_intra)
for (i = 0; i < 4; i++)
dct_single_coeff_elimination(s, i, s->luma_elim_threshold);
if (s->chroma_elim_threshold && !s->mb_intra)
for (i = 4; i < mb_block_count; i++)
dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
if (s->flags & CODEC_FLAG_CBP_RD) {
for (i = 0; i < mb_block_count; i++) {
if (s->block_last_index[i] == -1)
s->coded_score[i] = INT_MAX / 256;
}
}
}
if ((s->flags & CODEC_FLAG_GRAY) && s->mb_intra) {
s->block_last_index[4] =
s->block_last_index[5] = 0;
s->block[4][0] =
s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale;
}
if (s->alternate_scan && s->dct_quantize != dct_quantize_c) {
for (i = 0; i < mb_block_count; i++) {
int j;
if (s->block_last_index[i] > 0) {
for (j = 63; j > 0; j--) {
if (s->block[i][s->intra_scantable.permutated[j]])
break;
}
s->block_last_index[i] = j;
}
}
}
switch(s->codec_id){
case CODEC_ID_MPEG1VIDEO:
case CODEC_ID_MPEG2VIDEO:
if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)
mpeg1_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_MPEG4:
if (CONFIG_MPEG4_ENCODER)
mpeg4_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_MSMPEG4V2:
case CODEC_ID_MSMPEG4V3:
case CODEC_ID_WMV1:
if (CONFIG_MSMPEG4_ENCODER)
msmpeg4_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_WMV2:
if (CONFIG_WMV2_ENCODER)
ff_wmv2_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_H261:
if (CONFIG_H261_ENCODER)
ff_h261_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_H263:
case CODEC_ID_H263P:
case CODEC_ID_FLV1:
case CODEC_ID_RV10:
case CODEC_ID_RV20:
if (CONFIG_H263_ENCODER)
h263_encode_mb(s, s->block, motion_x, motion_y);
break;
case CODEC_ID_MJPEG:
if (CONFIG_MJPEG_ENCODER)
ff_mjpeg_encode_mb(s, s->block);
break;
default:
assert(0);
}
} | ['static av_always_inline void encode_mb_internal(MpegEncContext *s,\n int motion_x, int motion_y,\n int mb_block_height,\n int mb_block_count)\n{\n int16_t weight[8][64];\n DCTELEM orig[8][64];\n const int mb_x = s->mb_x;\n const int mb_y = s->mb_y;\n int i;\n int skip_dct[8];\n int dct_offset = s->linesize * 8;\n uint8_t *ptr_y, *ptr_cb, *ptr_cr;\n int wrap_y, wrap_c;\n for (i = 0; i < mb_block_count; i++)\n skip_dct[i] = s->skipdct;\n if (s->adaptive_quant) {\n const int last_qp = s->qscale;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n s->lambda = s->lambda_table[mb_xy];\n update_qscale(s);\n if (!(s->flags & CODEC_FLAG_QP_RD)) {\n s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];\n s->dquant = s->qscale - last_qp;\n if (s->out_format == FMT_H263) {\n s->dquant = av_clip(s->dquant, -2, 2);\n if (s->codec_id == CODEC_ID_MPEG4) {\n if (!s->mb_intra) {\n if (s->pict_type == AV_PICTURE_TYPE_B) {\n if (s->dquant & 1 || s->mv_dir & MV_DIRECT)\n s->dquant = 0;\n }\n if (s->mv_type == MV_TYPE_8X8)\n s->dquant = 0;\n }\n }\n }\n }\n ff_set_qscale(s, last_qp + s->dquant);\n } else if (s->flags & CODEC_FLAG_QP_RD)\n ff_set_qscale(s, s->qscale + s->dquant);\n wrap_y = s->linesize;\n wrap_c = s->uvlinesize;\n ptr_y = s->new_picture.f.data[0] +\n (mb_y * 16 * wrap_y) + mb_x * 16;\n ptr_cb = s->new_picture.f.data[1] +\n (mb_y * mb_block_height * wrap_c) + mb_x * 8;\n ptr_cr = s->new_picture.f.data[2] +\n (mb_y * mb_block_height * wrap_c) + mb_x * 8;\n if (mb_x * 16 + 16 > s->width || mb_y * 16 + 16 > s->height) {\n uint8_t *ebuf = s->edge_emu_buffer + 32;\n s->dsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16,\n mb_y * 16, s->width, s->height);\n ptr_y = ebuf;\n s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8,\n mb_block_height, mb_x * 8, mb_y * 8,\n s->width >> 1, s->height >> 1);\n ptr_cb = ebuf + 18 * wrap_y;\n s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8,\n mb_block_height, mb_x * 8, mb_y * 8,\n s->width >> 1, s->height >> 1);\n ptr_cr = ebuf + 18 * wrap_y + 8;\n }\n if (s->mb_intra) {\n if (s->flags & CODEC_FLAG_INTERLACED_DCT) {\n int progressive_score, interlaced_score;\n s->interlaced_dct = 0;\n progressive_score = s->dsp.ildct_cmp[4](s, ptr_y,\n NULL, wrap_y, 8) +\n s->dsp.ildct_cmp[4](s, ptr_y + wrap_y * 8,\n NULL, wrap_y, 8) - 400;\n if (progressive_score > 0) {\n interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y,\n NULL, wrap_y * 2, 8) +\n s->dsp.ildct_cmp[4](s, ptr_y + wrap_y,\n NULL, wrap_y * 2, 8);\n if (progressive_score > interlaced_score) {\n s->interlaced_dct = 1;\n dct_offset = wrap_y;\n wrap_y <<= 1;\n if (s->chroma_format == CHROMA_422)\n wrap_c <<= 1;\n }\n }\n }\n s->dsp.get_pixels(s->block[0], ptr_y , wrap_y);\n s->dsp.get_pixels(s->block[1], ptr_y + 8 , wrap_y);\n s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y);\n s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8 , wrap_y);\n if (s->flags & CODEC_FLAG_GRAY) {\n skip_dct[4] = 1;\n skip_dct[5] = 1;\n } else {\n s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c);\n s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c);\n if (!s->chroma_y_shift) {\n s->dsp.get_pixels(s->block[6],\n ptr_cb + (dct_offset >> 1), wrap_c);\n s->dsp.get_pixels(s->block[7],\n ptr_cr + (dct_offset >> 1), wrap_c);\n }\n }\n } else {\n op_pixels_func (*op_pix)[4];\n qpel_mc_func (*op_qpix)[16];\n uint8_t *dest_y, *dest_cb, *dest_cr;\n dest_y = s->dest[0];\n dest_cb = s->dest[1];\n dest_cr = s->dest[2];\n if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {\n op_pix = s->dsp.put_pixels_tab;\n op_qpix = s->dsp.put_qpel_pixels_tab;\n } else {\n op_pix = s->dsp.put_no_rnd_pixels_tab;\n op_qpix = s->dsp.put_no_rnd_qpel_pixels_tab;\n }\n if (s->mv_dir & MV_DIR_FORWARD) {\n MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data,\n op_pix, op_qpix);\n op_pix = s->dsp.avg_pixels_tab;\n op_qpix = s->dsp.avg_qpel_pixels_tab;\n }\n if (s->mv_dir & MV_DIR_BACKWARD) {\n MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data,\n op_pix, op_qpix);\n }\n if (s->flags & CODEC_FLAG_INTERLACED_DCT) {\n int progressive_score, interlaced_score;\n s->interlaced_dct = 0;\n progressive_score = s->dsp.ildct_cmp[0](s, dest_y,\n ptr_y, wrap_y,\n 8) +\n s->dsp.ildct_cmp[0](s, dest_y + wrap_y * 8,\n ptr_y + wrap_y * 8, wrap_y,\n 8) - 400;\n if (s->avctx->ildct_cmp == FF_CMP_VSSE)\n progressive_score -= 400;\n if (progressive_score > 0) {\n interlaced_score = s->dsp.ildct_cmp[0](s, dest_y,\n ptr_y,\n wrap_y * 2, 8) +\n s->dsp.ildct_cmp[0](s, dest_y + wrap_y,\n ptr_y + wrap_y,\n wrap_y * 2, 8);\n if (progressive_score > interlaced_score) {\n s->interlaced_dct = 1;\n dct_offset = wrap_y;\n wrap_y <<= 1;\n if (s->chroma_format == CHROMA_422)\n wrap_c <<= 1;\n }\n }\n }\n s->dsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y);\n s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);\n s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset,\n dest_y + dct_offset, wrap_y);\n s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8,\n dest_y + dct_offset + 8, wrap_y);\n if (s->flags & CODEC_FLAG_GRAY) {\n skip_dct[4] = 1;\n skip_dct[5] = 1;\n } else {\n s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);\n s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);\n if (!s->chroma_y_shift) {\n s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset >> 1),\n dest_cb + (dct_offset >> 1), wrap_c);\n s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset >> 1),\n dest_cr + (dct_offset >> 1), wrap_c);\n }\n }\n if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] <\n 2 * s->qscale * s->qscale) {\n if (s->dsp.sad[1](NULL, ptr_y , dest_y,\n wrap_y, 8) < 20 * s->qscale)\n skip_dct[0] = 1;\n if (s->dsp.sad[1](NULL, ptr_y + 8,\n dest_y + 8, wrap_y, 8) < 20 * s->qscale)\n skip_dct[1] = 1;\n if (s->dsp.sad[1](NULL, ptr_y + dct_offset,\n dest_y + dct_offset, wrap_y, 8) < 20 * s->qscale)\n skip_dct[2] = 1;\n if (s->dsp.sad[1](NULL, ptr_y + dct_offset + 8,\n dest_y + dct_offset + 8,\n wrap_y, 8) < 20 * s->qscale)\n skip_dct[3] = 1;\n if (s->dsp.sad[1](NULL, ptr_cb, dest_cb,\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[4] = 1;\n if (s->dsp.sad[1](NULL, ptr_cr, dest_cr,\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[5] = 1;\n if (!s->chroma_y_shift) {\n if (s->dsp.sad[1](NULL, ptr_cb + (dct_offset >> 1),\n dest_cb + (dct_offset >> 1),\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[6] = 1;\n if (s->dsp.sad[1](NULL, ptr_cr + (dct_offset >> 1),\n dest_cr + (dct_offset >> 1),\n wrap_c, 8) < 20 * s->qscale)\n skip_dct[7] = 1;\n }\n }\n }\n if (s->avctx->quantizer_noise_shaping) {\n if (!skip_dct[0])\n get_visual_weight(weight[0], ptr_y , wrap_y);\n if (!skip_dct[1])\n get_visual_weight(weight[1], ptr_y + 8, wrap_y);\n if (!skip_dct[2])\n get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y);\n if (!skip_dct[3])\n get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y);\n if (!skip_dct[4])\n get_visual_weight(weight[4], ptr_cb , wrap_c);\n if (!skip_dct[5])\n get_visual_weight(weight[5], ptr_cr , wrap_c);\n if (!s->chroma_y_shift) {\n if (!skip_dct[6])\n get_visual_weight(weight[6], ptr_cb + (dct_offset >> 1),\n wrap_c);\n if (!skip_dct[7])\n get_visual_weight(weight[7], ptr_cr + (dct_offset >> 1),\n wrap_c);\n }\n memcpy(orig[0], s->block[0], sizeof(DCTELEM) * 64 * mb_block_count);\n }\n assert(s->out_format != FMT_MJPEG || s->qscale == 8);\n {\n for (i = 0; i < mb_block_count; i++) {\n if (!skip_dct[i]) {\n int overflow;\n s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow);\n if (overflow)\n clip_coeffs(s, s->block[i], s->block_last_index[i]);\n } else\n s->block_last_index[i] = -1;\n }\n if (s->avctx->quantizer_noise_shaping) {\n for (i = 0; i < mb_block_count; i++) {\n if (!skip_dct[i]) {\n s->block_last_index[i] =\n dct_quantize_refine(s, s->block[i], weight[i],\n orig[i], i, s->qscale);\n }\n }\n }\n if (s->luma_elim_threshold && !s->mb_intra)\n for (i = 0; i < 4; i++)\n dct_single_coeff_elimination(s, i, s->luma_elim_threshold);\n if (s->chroma_elim_threshold && !s->mb_intra)\n for (i = 4; i < mb_block_count; i++)\n dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);\n if (s->flags & CODEC_FLAG_CBP_RD) {\n for (i = 0; i < mb_block_count; i++) {\n if (s->block_last_index[i] == -1)\n s->coded_score[i] = INT_MAX / 256;\n }\n }\n }\n if ((s->flags & CODEC_FLAG_GRAY) && s->mb_intra) {\n s->block_last_index[4] =\n s->block_last_index[5] = 0;\n s->block[4][0] =\n s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale;\n }\n if (s->alternate_scan && s->dct_quantize != dct_quantize_c) {\n for (i = 0; i < mb_block_count; i++) {\n int j;\n if (s->block_last_index[i] > 0) {\n for (j = 63; j > 0; j--) {\n if (s->block[i][s->intra_scantable.permutated[j]])\n break;\n }\n s->block_last_index[i] = j;\n }\n }\n }\n switch(s->codec_id){\n case CODEC_ID_MPEG1VIDEO:\n case CODEC_ID_MPEG2VIDEO:\n if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER)\n mpeg1_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_MPEG4:\n if (CONFIG_MPEG4_ENCODER)\n mpeg4_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_MSMPEG4V2:\n case CODEC_ID_MSMPEG4V3:\n case CODEC_ID_WMV1:\n if (CONFIG_MSMPEG4_ENCODER)\n msmpeg4_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_WMV2:\n if (CONFIG_WMV2_ENCODER)\n ff_wmv2_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_H261:\n if (CONFIG_H261_ENCODER)\n ff_h261_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_H263:\n case CODEC_ID_H263P:\n case CODEC_ID_FLV1:\n case CODEC_ID_RV10:\n case CODEC_ID_RV20:\n if (CONFIG_H263_ENCODER)\n h263_encode_mb(s, s->block, motion_x, motion_y);\n break;\n case CODEC_ID_MJPEG:\n if (CONFIG_MJPEG_ENCODER)\n ff_mjpeg_encode_mb(s, s->block);\n break;\n default:\n assert(0);\n }\n}'] |
33,065 | 0 | https://github.com/libav/libav/blob/0bf511d579c7b21f1244eec688abf571ca1235bd/libavfilter/vf_crop.c/#L180 | static int config_input(AVFilterLink *link)
{
AVFilterContext *ctx = link->dst;
CropContext *crop = ctx->priv;
const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(link->format);
int ret;
const char *expr;
double res;
crop->var_values[VAR_E] = M_E;
crop->var_values[VAR_PHI] = M_PHI;
crop->var_values[VAR_PI] = M_PI;
crop->var_values[VAR_IN_W] = crop->var_values[VAR_IW] = ctx->inputs[0]->w;
crop->var_values[VAR_IN_H] = crop->var_values[VAR_IH] = ctx->inputs[0]->h;
crop->var_values[VAR_X] = NAN;
crop->var_values[VAR_Y] = NAN;
crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = NAN;
crop->var_values[VAR_OUT_H] = crop->var_values[VAR_OH] = NAN;
crop->var_values[VAR_N] = 0;
crop->var_values[VAR_T] = NAN;
crop->var_values[VAR_POS] = NAN;
av_image_fill_max_pixsteps(crop->max_step, NULL, pix_desc);
crop->hsub = pix_desc->log2_chroma_w;
crop->vsub = pix_desc->log2_chroma_h;
if ((ret = av_expr_parse_and_eval(&res, (expr = crop->ow_expr),
var_names, crop->var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr;
crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = res;
if ((ret = av_expr_parse_and_eval(&res, (expr = crop->oh_expr),
var_names, crop->var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr;
crop->var_values[VAR_OUT_H] = crop->var_values[VAR_OH] = res;
if ((ret = av_expr_parse_and_eval(&res, (expr = crop->ow_expr),
var_names, crop->var_values,
NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr;
crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = res;
if (normalize_double(&crop->w, crop->var_values[VAR_OUT_W]) < 0 ||
normalize_double(&crop->h, crop->var_values[VAR_OUT_H]) < 0) {
av_log(ctx, AV_LOG_ERROR,
"Too big value or invalid expression for out_w/ow or out_h/oh. "
"Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n",
crop->ow_expr, crop->oh_expr);
return AVERROR(EINVAL);
}
crop->w &= ~((1 << crop->hsub) - 1);
crop->h &= ~((1 << crop->vsub) - 1);
if ((ret = av_expr_parse(&crop->x_pexpr, crop->x_expr, var_names,
NULL, NULL, NULL, NULL, 0, ctx)) < 0 ||
(ret = av_expr_parse(&crop->y_pexpr, crop->y_expr, var_names,
NULL, NULL, NULL, NULL, 0, ctx)) < 0)
return AVERROR(EINVAL);
av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\n",
link->w, link->h, crop->w, crop->h);
if (crop->w <= 0 || crop->h <= 0 ||
crop->w > link->w || crop->h > link->h) {
av_log(ctx, AV_LOG_ERROR,
"Invalid too big or non positive size for width '%d' or height '%d'\n",
crop->w, crop->h);
return AVERROR(EINVAL);
}
crop->x = (link->w - crop->w) / 2;
crop->y = (link->h - crop->h) / 2;
crop->x &= ~((1 << crop->hsub) - 1);
crop->y &= ~((1 << crop->vsub) - 1);
return 0;
fail_expr:
av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr);
return ret;
} | ['static int config_input(AVFilterLink *link)\n{\n AVFilterContext *ctx = link->dst;\n CropContext *crop = ctx->priv;\n const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(link->format);\n int ret;\n const char *expr;\n double res;\n crop->var_values[VAR_E] = M_E;\n crop->var_values[VAR_PHI] = M_PHI;\n crop->var_values[VAR_PI] = M_PI;\n crop->var_values[VAR_IN_W] = crop->var_values[VAR_IW] = ctx->inputs[0]->w;\n crop->var_values[VAR_IN_H] = crop->var_values[VAR_IH] = ctx->inputs[0]->h;\n crop->var_values[VAR_X] = NAN;\n crop->var_values[VAR_Y] = NAN;\n crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = NAN;\n crop->var_values[VAR_OUT_H] = crop->var_values[VAR_OH] = NAN;\n crop->var_values[VAR_N] = 0;\n crop->var_values[VAR_T] = NAN;\n crop->var_values[VAR_POS] = NAN;\n av_image_fill_max_pixsteps(crop->max_step, NULL, pix_desc);\n crop->hsub = pix_desc->log2_chroma_w;\n crop->vsub = pix_desc->log2_chroma_h;\n if ((ret = av_expr_parse_and_eval(&res, (expr = crop->ow_expr),\n var_names, crop->var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr;\n crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = res;\n if ((ret = av_expr_parse_and_eval(&res, (expr = crop->oh_expr),\n var_names, crop->var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr;\n crop->var_values[VAR_OUT_H] = crop->var_values[VAR_OH] = res;\n if ((ret = av_expr_parse_and_eval(&res, (expr = crop->ow_expr),\n var_names, crop->var_values,\n NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto fail_expr;\n crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = res;\n if (normalize_double(&crop->w, crop->var_values[VAR_OUT_W]) < 0 ||\n normalize_double(&crop->h, crop->var_values[VAR_OUT_H]) < 0) {\n av_log(ctx, AV_LOG_ERROR,\n "Too big value or invalid expression for out_w/ow or out_h/oh. "\n "Maybe the expression for out_w:\'%s\' or for out_h:\'%s\' is self-referencing.\\n",\n crop->ow_expr, crop->oh_expr);\n return AVERROR(EINVAL);\n }\n crop->w &= ~((1 << crop->hsub) - 1);\n crop->h &= ~((1 << crop->vsub) - 1);\n if ((ret = av_expr_parse(&crop->x_pexpr, crop->x_expr, var_names,\n NULL, NULL, NULL, NULL, 0, ctx)) < 0 ||\n (ret = av_expr_parse(&crop->y_pexpr, crop->y_expr, var_names,\n NULL, NULL, NULL, NULL, 0, ctx)) < 0)\n return AVERROR(EINVAL);\n av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d\\n",\n link->w, link->h, crop->w, crop->h);\n if (crop->w <= 0 || crop->h <= 0 ||\n crop->w > link->w || crop->h > link->h) {\n av_log(ctx, AV_LOG_ERROR,\n "Invalid too big or non positive size for width \'%d\' or height \'%d\'\\n",\n crop->w, crop->h);\n return AVERROR(EINVAL);\n }\n crop->x = (link->w - crop->w) / 2;\n crop->y = (link->h - crop->h) / 2;\n crop->x &= ~((1 << crop->hsub) - 1);\n crop->y &= ~((1 << crop->vsub) - 1);\n return 0;\nfail_expr:\n av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression \'%s\'\\n", expr);\n return ret;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}'] |
33,066 | 0 | https://github.com/libav/libav/blob/2934cd9dbf390962ec008182f9eddd4296cf5527/libavcodec/vp8.c/#L1242 | static av_always_inline
void vp8_mc(VP8Context *s, int luma,
uint8_t *dst, uint8_t *src, const VP56mv *mv,
int x_off, int y_off, int block_w, int block_h,
int width, int height, int linesize,
vp8_mc_func mc_func[3][3])
{
if (AV_RN32A(mv)) {
static const uint8_t idx[3][8] = {
{ 0, 1, 2, 1, 2, 1, 2, 1 },
{ 0, 3, 5, 3, 5, 3, 5, 3 },
{ 0, 2, 3, 2, 3, 2, 3, 2 },
};
int mx = (mv->x << luma)&7, mx_idx = idx[0][mx];
int my = (mv->y << luma)&7, my_idx = idx[0][my];
x_off += mv->x >> (3 - luma);
y_off += mv->y >> (3 - luma);
src += y_off * linesize + x_off;
if (x_off < mx_idx || x_off >= width - block_w - idx[2][mx] ||
y_off < my_idx || y_off >= height - block_h - idx[2][my]) {
ff_emulated_edge_mc(s->edge_emu_buffer, src - my_idx * linesize - mx_idx, linesize,
block_w + idx[1][mx], block_h + idx[1][my],
x_off - mx_idx, y_off - my_idx, width, height);
src = s->edge_emu_buffer + mx_idx + linesize * my_idx;
}
mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);
} else
mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
} | ['static av_always_inline\nvoid inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,\n int mb_x, int mb_y)\n{\n int x_off = mb_x << 4, y_off = mb_y << 4;\n int width = 16*s->mb_width, height = 16*s->mb_height;\n AVFrame *ref = s->framep[mb->ref_frame];\n VP56mv *bmv = mb->bmv;\n if (mb->mode < VP8_MVMODE_SPLIT) {\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 0, 0, 16, 16, width, height, &mb->mv);\n } else switch (mb->partitioning) {\n case VP8_SPLITMVMODE_4x4: {\n int x, y;\n VP56mv uvmv;\n for (y = 0; y < 4; y++) {\n for (x = 0; x < 4; x++) {\n vp8_mc(s, 1, dst[0] + 4*y*s->linesize + x*4,\n ref->data[0], &bmv[4*y + x],\n 4*x + x_off, 4*y + y_off, 4, 4,\n width, height, s->linesize,\n s->put_pixels_tab[2]);\n }\n }\n x_off >>= 1; y_off >>= 1; width >>= 1; height >>= 1;\n for (y = 0; y < 2; y++) {\n for (x = 0; x < 2; x++) {\n uvmv.x = mb->bmv[ 2*y * 4 + 2*x ].x +\n mb->bmv[ 2*y * 4 + 2*x+1].x +\n mb->bmv[(2*y+1) * 4 + 2*x ].x +\n mb->bmv[(2*y+1) * 4 + 2*x+1].x;\n uvmv.y = mb->bmv[ 2*y * 4 + 2*x ].y +\n mb->bmv[ 2*y * 4 + 2*x+1].y +\n mb->bmv[(2*y+1) * 4 + 2*x ].y +\n mb->bmv[(2*y+1) * 4 + 2*x+1].y;\n uvmv.x = (uvmv.x + 2 + (uvmv.x >> (INT_BIT-1))) >> 2;\n uvmv.y = (uvmv.y + 2 + (uvmv.y >> (INT_BIT-1))) >> 2;\n if (s->profile == 3) {\n uvmv.x &= ~7;\n uvmv.y &= ~7;\n }\n vp8_mc(s, 0, dst[1] + 4*y*s->uvlinesize + x*4,\n ref->data[1], &uvmv,\n 4*x + x_off, 4*y + y_off, 4, 4,\n width, height, s->uvlinesize,\n s->put_pixels_tab[2]);\n vp8_mc(s, 0, dst[2] + 4*y*s->uvlinesize + x*4,\n ref->data[2], &uvmv,\n 4*x + x_off, 4*y + y_off, 4, 4,\n width, height, s->uvlinesize,\n s->put_pixels_tab[2]);\n }\n }\n break;\n }\n case VP8_SPLITMVMODE_16x8:\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 0, 0, 16, 8, width, height, &bmv[0]);\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 0, 8, 16, 8, width, height, &bmv[1]);\n break;\n case VP8_SPLITMVMODE_8x16:\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 0, 0, 8, 16, width, height, &bmv[0]);\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 8, 0, 8, 16, width, height, &bmv[1]);\n break;\n case VP8_SPLITMVMODE_8x8:\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 0, 0, 8, 8, width, height, &bmv[0]);\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 8, 0, 8, 8, width, height, &bmv[1]);\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 0, 8, 8, 8, width, height, &bmv[2]);\n vp8_mc_part(s, dst, ref, x_off, y_off,\n 8, 8, 8, 8, width, height, &bmv[3]);\n break;\n }\n}', 'static av_always_inline\nvoid vp8_mc(VP8Context *s, int luma,\n uint8_t *dst, uint8_t *src, const VP56mv *mv,\n int x_off, int y_off, int block_w, int block_h,\n int width, int height, int linesize,\n vp8_mc_func mc_func[3][3])\n{\n if (AV_RN32A(mv)) {\n static const uint8_t idx[3][8] = {\n { 0, 1, 2, 1, 2, 1, 2, 1 },\n { 0, 3, 5, 3, 5, 3, 5, 3 },\n { 0, 2, 3, 2, 3, 2, 3, 2 },\n };\n int mx = (mv->x << luma)&7, mx_idx = idx[0][mx];\n int my = (mv->y << luma)&7, my_idx = idx[0][my];\n x_off += mv->x >> (3 - luma);\n y_off += mv->y >> (3 - luma);\n src += y_off * linesize + x_off;\n if (x_off < mx_idx || x_off >= width - block_w - idx[2][mx] ||\n y_off < my_idx || y_off >= height - block_h - idx[2][my]) {\n ff_emulated_edge_mc(s->edge_emu_buffer, src - my_idx * linesize - mx_idx, linesize,\n block_w + idx[1][mx], block_h + idx[1][my],\n x_off - mx_idx, y_off - my_idx, width, height);\n src = s->edge_emu_buffer + mx_idx + linesize * my_idx;\n }\n mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);\n } else\n mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);\n}'] |
33,067 | 0 | https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/asn1/x_cinf.c/#L168 | X509_CINF *X509_CINF_new(void)
{
X509_CINF *ret=NULL;
ASN1_CTX c;
M_ASN1_New_Malloc(ret,X509_CINF);
ret->version=NULL;
M_ASN1_New(ret->serialNumber,ASN1_INTEGER_new);
M_ASN1_New(ret->signature,X509_ALGOR_new);
M_ASN1_New(ret->issuer,X509_NAME_new);
M_ASN1_New(ret->validity,X509_VAL_new);
M_ASN1_New(ret->subject,X509_NAME_new);
M_ASN1_New(ret->key,X509_PUBKEY_new);
ret->issuerUID=NULL;
ret->subjectUID=NULL;
ret->extensions=NULL;
return(ret);
M_ASN1_New_Error(ASN1_F_X509_CINF_NEW);
} | ['X509_CINF *X509_CINF_new(void)\n\t{\n\tX509_CINF *ret=NULL;\n\tASN1_CTX c;\n\tM_ASN1_New_Malloc(ret,X509_CINF);\n\tret->version=NULL;\n\tM_ASN1_New(ret->serialNumber,ASN1_INTEGER_new);\n\tM_ASN1_New(ret->signature,X509_ALGOR_new);\n\tM_ASN1_New(ret->issuer,X509_NAME_new);\n\tM_ASN1_New(ret->validity,X509_VAL_new);\n\tM_ASN1_New(ret->subject,X509_NAME_new);\n\tM_ASN1_New(ret->key,X509_PUBKEY_new);\n\tret->issuerUID=NULL;\n\tret->subjectUID=NULL;\n\tret->extensions=NULL;\n\treturn(ret);\n\tM_ASN1_New_Error(ASN1_F_X509_CINF_NEW);\n\t}', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n\t{\n\tASN1_STRING *ret;\n\tret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING));\n\tif (ret == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->type=type;\n\tret->data=NULL;\n\tret->flags=0;\n\treturn(ret);\n\t}', 'X509_ALGOR *X509_ALGOR_new(void)\n\t{\n\tX509_ALGOR *ret=NULL;\n\tASN1_CTX c;\n\tM_ASN1_New_Malloc(ret,X509_ALGOR);\n\tret->algorithm=OBJ_nid2obj(NID_undef);\n\tret->parameter=NULL;\n\treturn(ret);\n\tM_ASN1_New_Error(ASN1_F_X509_ALGOR_NEW);\n\t}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn((ASN1_OBJECT *)&(nid_objs[n]));\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,(char *)&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}'] |
33,068 | 0 | https://github.com/libav/libav/blob/7c152a458d3fb0a2fb1aef1f05bfee90fe70697e/libavcodec/vorbisdec.c/#L1568 | static int vorbis_parse_audio_packet(vorbis_context *vc)
{
GetBitContext *gb = &vc->gb;
FFTContext *mdct;
unsigned previous_window = vc->previous_window;
unsigned mode_number, blockflag, blocksize;
int i, j;
uint_fast8_t no_residue[255];
uint_fast8_t do_not_decode[255];
vorbis_mapping *mapping;
float *ch_res_ptr = vc->channel_residues;
float *ch_floor_ptr = vc->channel_floors;
uint_fast8_t res_chan[255];
unsigned res_num = 0;
int retlen = 0;
if (get_bits1(gb)) {
av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
return -1;
}
if (vc->mode_count == 1) {
mode_number = 0;
} else {
GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count)
}
vc->mode_number = mode_number;
mapping = &vc->mappings[vc->modes[mode_number].mapping];
AV_DEBUG(" Mode number: %u , mapping: %d , blocktype %d\n", mode_number,
vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
blockflag = vc->modes[mode_number].blockflag;
blocksize = vc->blocksize[blockflag];
if (blockflag)
skip_bits(gb, 2);
memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2);
memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2);
for (i = 0; i < vc->audio_channels; ++i) {
vorbis_floor *floor;
int ret;
if (mapping->submaps > 1) {
floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]];
} else {
floor = &vc->floors[mapping->submap_floor[0]];
}
ret = floor->decode(vc, &floor->data, ch_floor_ptr);
if (ret < 0) {
av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n");
return -1;
}
no_residue[i] = ret;
ch_floor_ptr += blocksize / 2;
}
for (i = mapping->coupling_steps - 1; i >= 0; --i) {
if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {
no_residue[mapping->magnitude[i]] = 0;
no_residue[mapping->angle[i]] = 0;
}
}
for (i = 0; i < mapping->submaps; ++i) {
vorbis_residue *residue;
unsigned ch = 0;
for (j = 0; j < vc->audio_channels; ++j) {
if ((mapping->submaps == 1) || (i == mapping->mux[j])) {
res_chan[j] = res_num;
if (no_residue[j]) {
do_not_decode[ch] = 1;
} else {
do_not_decode[ch] = 0;
}
++ch;
++res_num;
}
}
residue = &vc->residues[mapping->submap_residue[i]];
vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2);
ch_res_ptr += ch * blocksize / 2;
}
for (i = mapping->coupling_steps - 1; i >= 0; --i) {
float *mag, *ang;
mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2;
ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2;
vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);
}
mdct = &vc->mdct[blockflag];
for (j = vc->audio_channels-1;j >= 0; j--) {
ch_floor_ptr = vc->channel_floors + j * blocksize / 2;
ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2;
vc->dsp.vector_fmul(ch_floor_ptr, ch_floor_ptr, ch_res_ptr, blocksize / 2);
mdct->imdct_half(mdct, ch_res_ptr, ch_floor_ptr);
}
retlen = (blocksize + vc->blocksize[previous_window]) / 4;
for (j = 0; j < vc->audio_channels; j++) {
unsigned bs0 = vc->blocksize[0];
unsigned bs1 = vc->blocksize[1];
float *residue = vc->channel_residues + res_chan[j] * blocksize / 2;
float *saved = vc->saved + j * bs1 / 4;
float *ret = vc->channel_floors + j * retlen;
float *buf = residue;
const float *win = vc->win[blockflag & previous_window];
if (blockflag == previous_window) {
vc->dsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4);
} else if (blockflag > previous_window) {
vc->dsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4);
memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float));
} else {
memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float));
vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4);
}
memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float));
}
vc->previous_window = blockflag;
return retlen;
} | ['static int vorbis_parse_audio_packet(vorbis_context *vc)\n{\n GetBitContext *gb = &vc->gb;\n FFTContext *mdct;\n unsigned previous_window = vc->previous_window;\n unsigned mode_number, blockflag, blocksize;\n int i, j;\n uint_fast8_t no_residue[255];\n uint_fast8_t do_not_decode[255];\n vorbis_mapping *mapping;\n float *ch_res_ptr = vc->channel_residues;\n float *ch_floor_ptr = vc->channel_floors;\n uint_fast8_t res_chan[255];\n unsigned res_num = 0;\n int retlen = 0;\n if (get_bits1(gb)) {\n av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\\n");\n return -1;\n }\n if (vc->mode_count == 1) {\n mode_number = 0;\n } else {\n GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count)\n }\n vc->mode_number = mode_number;\n mapping = &vc->mappings[vc->modes[mode_number].mapping];\n AV_DEBUG(" Mode number: %u , mapping: %d , blocktype %d\\n", mode_number,\n vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);\n blockflag = vc->modes[mode_number].blockflag;\n blocksize = vc->blocksize[blockflag];\n if (blockflag)\n skip_bits(gb, 2);\n memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2);\n memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2);\n for (i = 0; i < vc->audio_channels; ++i) {\n vorbis_floor *floor;\n int ret;\n if (mapping->submaps > 1) {\n floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]];\n } else {\n floor = &vc->floors[mapping->submap_floor[0]];\n }\n ret = floor->decode(vc, &floor->data, ch_floor_ptr);\n if (ret < 0) {\n av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\\n");\n return -1;\n }\n no_residue[i] = ret;\n ch_floor_ptr += blocksize / 2;\n }\n for (i = mapping->coupling_steps - 1; i >= 0; --i) {\n if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {\n no_residue[mapping->magnitude[i]] = 0;\n no_residue[mapping->angle[i]] = 0;\n }\n }\n for (i = 0; i < mapping->submaps; ++i) {\n vorbis_residue *residue;\n unsigned ch = 0;\n for (j = 0; j < vc->audio_channels; ++j) {\n if ((mapping->submaps == 1) || (i == mapping->mux[j])) {\n res_chan[j] = res_num;\n if (no_residue[j]) {\n do_not_decode[ch] = 1;\n } else {\n do_not_decode[ch] = 0;\n }\n ++ch;\n ++res_num;\n }\n }\n residue = &vc->residues[mapping->submap_residue[i]];\n vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2);\n ch_res_ptr += ch * blocksize / 2;\n }\n for (i = mapping->coupling_steps - 1; i >= 0; --i) {\n float *mag, *ang;\n mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2;\n ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2;\n vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);\n }\n mdct = &vc->mdct[blockflag];\n for (j = vc->audio_channels-1;j >= 0; j--) {\n ch_floor_ptr = vc->channel_floors + j * blocksize / 2;\n ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2;\n vc->dsp.vector_fmul(ch_floor_ptr, ch_floor_ptr, ch_res_ptr, blocksize / 2);\n mdct->imdct_half(mdct, ch_res_ptr, ch_floor_ptr);\n }\n retlen = (blocksize + vc->blocksize[previous_window]) / 4;\n for (j = 0; j < vc->audio_channels; j++) {\n unsigned bs0 = vc->blocksize[0];\n unsigned bs1 = vc->blocksize[1];\n float *residue = vc->channel_residues + res_chan[j] * blocksize / 2;\n float *saved = vc->saved + j * bs1 / 4;\n float *ret = vc->channel_floors + j * retlen;\n float *buf = residue;\n const float *win = vc->win[blockflag & previous_window];\n if (blockflag == previous_window) {\n vc->dsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4);\n } else if (blockflag > previous_window) {\n vc->dsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4);\n memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float));\n } else {\n memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float));\n vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4);\n }\n memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float));\n }\n vc->previous_window = blockflag;\n return retlen;\n}'] |
33,069 | 0 | https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int bn_probable_prime_dh(BIGNUM *rnd, int bits,\n const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *t1;\n BN_CTX_start(ctx);\n if ((t1 = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_rand(rnd, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n goto err;\n if (!BN_mod(t1, rnd, add, ctx))\n goto err;\n if (!BN_sub(rnd, rnd, t1))\n goto err;\n if (rem == NULL) {\n if (!BN_add_word(rnd, 1))\n goto err;\n } else {\n if (!BN_add(rnd, rnd, rem))\n goto err;\n }\n loop:\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(rnd, (BN_ULONG)primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod <= 1) {\n if (!BN_add(rnd, rnd, add))\n goto err;\n goto loop;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(rnd);\n return ret;\n}', '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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
33,070 | 0 | https://github.com/libav/libav/blob/cb7e2c1ca864a2ff44c851689ba8a2d4a81dfd27/libavformat/nutenc.c/#L626 | static int write_header(AVFormatContext *s){
NUTContext *nut = s->priv_data;
AVIOContext *bc = s->pb;
int i, j, ret;
nut->avf= s;
nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams);
nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters);
nut->time_base= av_mallocz(sizeof(AVRational )*(s->nb_streams +
s->nb_chapters));
for(i=0; i<s->nb_streams; i++){
AVStream *st= s->streams[i];
int ssize;
AVRational time_base;
ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);
av_set_pts_info(st, 64, time_base.num, time_base.den);
for(j=0; j<nut->time_base_count; j++){
if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){
break;
}
}
nut->time_base[j]= time_base;
nut->stream[i].time_base= &nut->time_base[j];
if(j==nut->time_base_count)
nut->time_base_count++;
if(INT64_C(1000) * time_base.num >= time_base.den)
nut->stream[i].msb_pts_shift = 7;
else
nut->stream[i].msb_pts_shift = 14;
nut->stream[i].max_pts_distance= FFMAX(time_base.den, time_base.num) / time_base.num;
}
for (i = 0; i < s->nb_chapters; i++) {
AVChapter *ch = s->chapters[i];
for (j = 0; j < nut->time_base_count; j++) {
if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational)))
break;
}
nut->time_base[j] = ch->time_base;
nut->chapter[i].time_base = &nut->time_base[j];
if(j == nut->time_base_count)
nut->time_base_count++;
}
nut->max_distance = MAX_DISTANCE;
build_elision_headers(s);
build_frame_code(s);
assert(nut->frame_code['N'].flags == FLAG_INVALID);
avio_write(bc, ID_STRING, strlen(ID_STRING));
avio_w8(bc, 0);
if ((ret = write_headers(s, bc)) < 0)
return ret;
avio_flush(bc);
return 0;
} | ["static int write_header(AVFormatContext *s){\n NUTContext *nut = s->priv_data;\n AVIOContext *bc = s->pb;\n int i, j, ret;\n nut->avf= s;\n nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams);\n nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters);\n nut->time_base= av_mallocz(sizeof(AVRational )*(s->nb_streams +\n s->nb_chapters));\n for(i=0; i<s->nb_streams; i++){\n AVStream *st= s->streams[i];\n int ssize;\n AVRational time_base;\n ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);\n av_set_pts_info(st, 64, time_base.num, time_base.den);\n for(j=0; j<nut->time_base_count; j++){\n if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){\n break;\n }\n }\n nut->time_base[j]= time_base;\n nut->stream[i].time_base= &nut->time_base[j];\n if(j==nut->time_base_count)\n nut->time_base_count++;\n if(INT64_C(1000) * time_base.num >= time_base.den)\n nut->stream[i].msb_pts_shift = 7;\n else\n nut->stream[i].msb_pts_shift = 14;\n nut->stream[i].max_pts_distance= FFMAX(time_base.den, time_base.num) / time_base.num;\n }\n for (i = 0; i < s->nb_chapters; i++) {\n AVChapter *ch = s->chapters[i];\n for (j = 0; j < nut->time_base_count; j++) {\n if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational)))\n break;\n }\n nut->time_base[j] = ch->time_base;\n nut->chapter[i].time_base = &nut->time_base[j];\n if(j == nut->time_base_count)\n nut->time_base_count++;\n }\n nut->max_distance = MAX_DISTANCE;\n build_elision_headers(s);\n build_frame_code(s);\n assert(nut->frame_code['N'].flags == FLAG_INVALID);\n avio_write(bc, ID_STRING, strlen(ID_STRING));\n avio_w8(bc, 0);\n if ((ret = write_headers(s, bc)) < 0)\n return ret;\n avio_flush(bc);\n return 0;\n}", 'void *av_mallocz(FF_INTERNAL_MEM_TYPE size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(FF_INTERNAL_MEM_TYPE size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}'] |
33,071 | 0 | https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
} | ['static int test_negzero()\n{\n BIGNUM *a = BN_new();\n BIGNUM *b = BN_new();\n BIGNUM *c = BN_new();\n BIGNUM *d = BN_new();\n BIGNUM *numerator = NULL, *denominator = NULL;\n int consttime, st = 0;\n if (a == NULL || b == NULL || c == NULL || d == NULL)\n goto err;\n if (!BN_set_word(a, 1))\n goto err;\n BN_set_negative(a, 1);\n BN_zero(b);\n if (!BN_mul(c, a, b, ctx))\n goto err;\n if (!BN_is_zero(c) || BN_is_negative(c)) {\n fprintf(stderr, "Multiplication test failed!\\n");\n goto err;\n }\n for (consttime = 0; consttime < 2; consttime++) {\n numerator = BN_new();\n denominator = BN_new();\n if (numerator == NULL || denominator == NULL)\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 (!BN_set_word(numerator, 1) || !BN_set_word(denominator, 2))\n goto err;\n BN_set_negative(numerator, 1);\n if (!BN_div(a, b, numerator, denominator, ctx))\n goto err;\n if (!BN_is_zero(a) || BN_is_negative(a)) {\n fprintf(stderr, "Incorrect quotient (consttime = %d).\\n",\n consttime);\n goto err;\n }\n if (!BN_set_word(denominator, 1))\n goto err;\n if (!BN_div(a, b, numerator, denominator, ctx))\n goto err;\n if (!BN_is_zero(b) || BN_is_negative(b)) {\n fprintf(stderr, "Incorrect remainder (consttime = %d).\\n",\n consttime);\n goto err;\n }\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 fprintf(stderr, "BN_set_negative produced a negative zero.\\n");\n goto err;\n }\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n BN_free(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# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}'] |
33,072 | 0 | https://github.com/libav/libav/blob/ccc87908a98e7fcbf69fb70ceda7efa5c6e545ec/ffmpeg.c/#L2881 | static int opt_metadata(const char *opt, const char *arg)
{
char *mid= strchr(arg, '=');
if(!mid){
fprintf(stderr, "Missing =\n");
av_exit(1);
}
*mid++= 0;
metadata_count++;
metadata= av_realloc(metadata, sizeof(*metadata)*metadata_count);
metadata[metadata_count-1].key = av_strdup(arg);
metadata[metadata_count-1].value= av_strdup(mid);
return 0;
} | ['static int opt_metadata(const char *opt, const char *arg)\n{\n char *mid= strchr(arg, \'=\');\n if(!mid){\n fprintf(stderr, "Missing =\\n");\n av_exit(1);\n }\n *mid++= 0;\n metadata_count++;\n metadata= av_realloc(metadata, sizeof(*metadata)*metadata_count);\n metadata[metadata_count-1].key = av_strdup(arg);\n metadata[metadata_count-1].value= av_strdup(mid);\n return 0;\n}'] |
33,073 | 0 | https://github.com/libav/libav/blob/5228bcd8705523cee43e351e1a113e12aefcf837/libavcodec/dca.c/#L683 | static int dca_subframe_header(DCAContext * s, int base_channel, int block_index)
{
int j, k;
if (!base_channel) {
s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;
s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);
}
for (j = base_channel; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++)
s->prediction_mode[j][k] = get_bits(&s->gb, 1);
}
for (j = base_channel; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++) {
if (s->prediction_mode[j][k] > 0) {
s->prediction_vq[j][k] = get_bits(&s->gb, 12);
}
}
}
for (j = base_channel; j < s->prim_channels; j++) {
for (k = 0; k < s->vq_start_subband[j]; k++) {
if (s->bitalloc_huffman[j] == 6)
s->bitalloc[j][k] = get_bits(&s->gb, 5);
else if (s->bitalloc_huffman[j] == 5)
s->bitalloc[j][k] = get_bits(&s->gb, 4);
else if (s->bitalloc_huffman[j] == 7) {
av_log(s->avctx, AV_LOG_ERROR,
"Invalid bit allocation index\n");
return -1;
} else {
s->bitalloc[j][k] =
get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);
}
if (s->bitalloc[j][k] > 26) {
return -1;
}
}
}
for (j = base_channel; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++) {
s->transition_mode[j][k] = 0;
if (s->subsubframes[s->current_subframe] > 1 &&
k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {
s->transition_mode[j][k] =
get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);
}
}
}
for (j = base_channel; j < s->prim_channels; j++) {
const uint32_t *scale_table;
int scale_sum;
memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);
if (s->scalefactor_huffman[j] == 6)
scale_table = scale_factor_quant7;
else
scale_table = scale_factor_quant6;
scale_sum = 0;
for (k = 0; k < s->subband_activity[j]; k++) {
if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {
scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
s->scale_factor[j][k][0] = scale_table[scale_sum];
}
if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {
scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);
s->scale_factor[j][k][1] = scale_table[scale_sum];
}
}
}
for (j = base_channel; j < s->prim_channels; j++) {
if (s->joint_intensity[j] > 0)
s->joint_huff[j] = get_bits(&s->gb, 3);
}
for (j = base_channel; j < s->prim_channels; j++) {
int source_channel;
if (s->joint_intensity[j] > 0) {
int scale = 0;
source_channel = s->joint_intensity[j] - 1;
for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {
scale = get_scale(&s->gb, s->joint_huff[j], 0);
scale += 64;
s->joint_scale_factor[j][k] = scale;
}
if (!(s->debug_flag & 0x02)) {
av_log(s->avctx, AV_LOG_DEBUG,
"Joint stereo coding not supported\n");
s->debug_flag |= 0x02;
}
}
}
if (!base_channel && s->prim_channels > 2) {
if (s->downmix) {
for (j = base_channel; j < s->prim_channels; j++) {
s->downmix_coef[j][0] = get_bits(&s->gb, 7);
s->downmix_coef[j][1] = get_bits(&s->gb, 7);
}
} else {
int am = s->amode & DCA_CHANNEL_MASK;
for (j = base_channel; j < s->prim_channels; j++) {
s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
}
}
}
if (s->dynrange)
s->dynrange_coef = get_bits(&s->gb, 8);
if (s->crc_present) {
get_bits(&s->gb, 16);
}
for (j = base_channel; j < s->prim_channels; j++)
for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
s->high_freq_vq[j][k] = get_bits(&s->gb, 10);
if (!base_channel && s->lfe) {
int lfe_samples = 2 * s->lfe * (4 + block_index);
int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
float lfe_scale;
for (j = lfe_samples; j < lfe_end_sample; j++) {
s->lfe_data[j] = get_sbits(&s->gb, 8);
}
s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];
lfe_scale = 0.035 * s->lfe_scale_factor;
for (j = lfe_samples; j < lfe_end_sample; j++)
s->lfe_data[j] *= lfe_scale;
}
#ifdef TRACE
av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes[s->current_subframe]);
av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n",
s->partial_samples[s->current_subframe]);
for (j = base_channel; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");
for (k = 0; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = base_channel; j < s->prim_channels; j++) {
for (k = 0; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG,
"prediction coefs: %f, %f, %f, %f\n",
(float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,
(float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,
(float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,
(float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);
}
for (j = base_channel; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");
for (k = 0; k < s->vq_start_subband[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = base_channel; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");
for (k = 0; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = base_channel; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");
for (k = 0; k < s->subband_activity[j]; k++) {
if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);
if (k < s->vq_start_subband[j] && s->transition_mode[j][k])
av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = base_channel; j < s->prim_channels; j++) {
if (s->joint_intensity[j] > 0) {
int source_channel = s->joint_intensity[j] - 1;
av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n");
for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)
av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
}
if (!base_channel && s->prim_channels > 2 && s->downmix) {
av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
for (j = 0; j < s->prim_channels; j++) {
av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);
av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
for (j = base_channel; j < s->prim_channels; j++)
for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)
av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]);
if (!base_channel && s->lfe) {
int lfe_samples = 2 * s->lfe * (4 + block_index);
int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n");
for (j = lfe_samples; j < lfe_end_sample; j++)
av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
#endif
return 0;
} | ['static int dca_subframe_header(DCAContext * s, int base_channel, int block_index)\n{\n int j, k;\n if (!base_channel) {\n s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1;\n s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3);\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n for (k = 0; k < s->subband_activity[j]; k++)\n s->prediction_mode[j][k] = get_bits(&s->gb, 1);\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n for (k = 0; k < s->subband_activity[j]; k++) {\n if (s->prediction_mode[j][k] > 0) {\n s->prediction_vq[j][k] = get_bits(&s->gb, 12);\n }\n }\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n for (k = 0; k < s->vq_start_subband[j]; k++) {\n if (s->bitalloc_huffman[j] == 6)\n s->bitalloc[j][k] = get_bits(&s->gb, 5);\n else if (s->bitalloc_huffman[j] == 5)\n s->bitalloc[j][k] = get_bits(&s->gb, 4);\n else if (s->bitalloc_huffman[j] == 7) {\n av_log(s->avctx, AV_LOG_ERROR,\n "Invalid bit allocation index\\n");\n return -1;\n } else {\n s->bitalloc[j][k] =\n get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]);\n }\n if (s->bitalloc[j][k] > 26) {\n return -1;\n }\n }\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n for (k = 0; k < s->subband_activity[j]; k++) {\n s->transition_mode[j][k] = 0;\n if (s->subsubframes[s->current_subframe] > 1 &&\n k < s->vq_start_subband[j] && s->bitalloc[j][k] > 0) {\n s->transition_mode[j][k] =\n get_bitalloc(&s->gb, &dca_tmode, s->transient_huffman[j]);\n }\n }\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n const uint32_t *scale_table;\n int scale_sum;\n memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2);\n if (s->scalefactor_huffman[j] == 6)\n scale_table = scale_factor_quant7;\n else\n scale_table = scale_factor_quant6;\n scale_sum = 0;\n for (k = 0; k < s->subband_activity[j]; k++) {\n if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) {\n scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);\n s->scale_factor[j][k][0] = scale_table[scale_sum];\n }\n if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) {\n scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum);\n s->scale_factor[j][k][1] = scale_table[scale_sum];\n }\n }\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n if (s->joint_intensity[j] > 0)\n s->joint_huff[j] = get_bits(&s->gb, 3);\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n int source_channel;\n if (s->joint_intensity[j] > 0) {\n int scale = 0;\n source_channel = s->joint_intensity[j] - 1;\n for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) {\n scale = get_scale(&s->gb, s->joint_huff[j], 0);\n scale += 64;\n s->joint_scale_factor[j][k] = scale;\n }\n if (!(s->debug_flag & 0x02)) {\n av_log(s->avctx, AV_LOG_DEBUG,\n "Joint stereo coding not supported\\n");\n s->debug_flag |= 0x02;\n }\n }\n }\n if (!base_channel && s->prim_channels > 2) {\n if (s->downmix) {\n for (j = base_channel; j < s->prim_channels; j++) {\n s->downmix_coef[j][0] = get_bits(&s->gb, 7);\n s->downmix_coef[j][1] = get_bits(&s->gb, 7);\n }\n } else {\n int am = s->amode & DCA_CHANNEL_MASK;\n for (j = base_channel; j < s->prim_channels; j++) {\n s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];\n s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];\n }\n }\n }\n if (s->dynrange)\n s->dynrange_coef = get_bits(&s->gb, 8);\n if (s->crc_present) {\n get_bits(&s->gb, 16);\n }\n for (j = base_channel; j < s->prim_channels; j++)\n for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)\n s->high_freq_vq[j][k] = get_bits(&s->gb, 10);\n if (!base_channel && s->lfe) {\n int lfe_samples = 2 * s->lfe * (4 + block_index);\n int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);\n float lfe_scale;\n for (j = lfe_samples; j < lfe_end_sample; j++) {\n s->lfe_data[j] = get_sbits(&s->gb, 8);\n }\n s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)];\n lfe_scale = 0.035 * s->lfe_scale_factor;\n for (j = lfe_samples; j < lfe_end_sample; j++)\n s->lfe_data[j] *= lfe_scale;\n }\n#ifdef TRACE\n av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\\n", s->subsubframes[s->current_subframe]);\n av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\\n",\n s->partial_samples[s->current_subframe]);\n for (j = base_channel; j < s->prim_channels; j++) {\n av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:");\n for (k = 0; k < s->subband_activity[j]; k++)\n av_log(s->avctx, AV_LOG_DEBUG, " %i", s->prediction_mode[j][k]);\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n for (k = 0; k < s->subband_activity[j]; k++)\n av_log(s->avctx, AV_LOG_DEBUG,\n "prediction coefs: %f, %f, %f, %f\\n",\n (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192,\n (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192,\n (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192,\n (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192);\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: ");\n for (k = 0; k < s->vq_start_subband[j]; k++)\n av_log(s->avctx, AV_LOG_DEBUG, "%2.2i ", s->bitalloc[j][k]);\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n av_log(s->avctx, AV_LOG_DEBUG, "Transition mode:");\n for (k = 0; k < s->subband_activity[j]; k++)\n av_log(s->avctx, AV_LOG_DEBUG, " %i", s->transition_mode[j][k]);\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n av_log(s->avctx, AV_LOG_DEBUG, "Scale factor:");\n for (k = 0; k < s->subband_activity[j]; k++) {\n if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0)\n av_log(s->avctx, AV_LOG_DEBUG, " %i", s->scale_factor[j][k][0]);\n if (k < s->vq_start_subband[j] && s->transition_mode[j][k])\n av_log(s->avctx, AV_LOG_DEBUG, " %i(t)", s->scale_factor[j][k][1]);\n }\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n for (j = base_channel; j < s->prim_channels; j++) {\n if (s->joint_intensity[j] > 0) {\n int source_channel = s->joint_intensity[j] - 1;\n av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\\n");\n for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++)\n av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]);\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n }\n if (!base_channel && s->prim_channels > 2 && s->downmix) {\n av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\\n");\n for (j = 0; j < s->prim_channels; j++) {\n av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]);\n av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]);\n }\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n for (j = base_channel; j < s->prim_channels; j++)\n for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++)\n av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\\n", s->high_freq_vq[j][k]);\n if (!base_channel && s->lfe) {\n int lfe_samples = 2 * s->lfe * (4 + block_index);\n int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);\n av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\\n");\n for (j = lfe_samples; j < lfe_end_sample; j++)\n av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]);\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n#endif\n return 0;\n}'] |
33,074 | 0 | https://github.com/libav/libav/blob/ad0278661b2625e56e09d1ee96f404fc575a9edf/libavfilter/avfilter.c/#L77 | void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
if (!ref)
return;
if (!(--ref->buf->refcount))
ref->buf->free(ref->buf);
av_free(ref->video);
av_free(ref->audio);
av_free(ref);
} | ['static void end_frame(AVFilterLink *inlink)\n{\n AVFilterContext *ctx = inlink->dst;\n int i;\n for (i = 0; i < ctx->output_count; i++)\n avfilter_end_frame(ctx->outputs[i]);\n avfilter_unref_buffer(inlink->cur_buf);\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 av_free(ref->video);\n av_free(ref->audio);\n av_free(ref);\n}'] |
33,075 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/des/des_enc.c/#L144 | void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)
{
register DES_LONG l,r,t,u;
#ifdef DES_PTR
register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
#endif
#ifndef DES_UNROLL
register int i;
#endif
register DES_LONG *s;
r=data[0];
l=data[1];
IP(r,l);
r=ROTATE(r,29)&0xffffffffL;
l=ROTATE(l,29)&0xffffffffL;
s=(DES_LONG *)ks;
if (enc)
{
#ifdef DES_UNROLL
D_ENCRYPT(l,r, 0);
D_ENCRYPT(r,l, 2);
D_ENCRYPT(l,r, 4);
D_ENCRYPT(r,l, 6);
D_ENCRYPT(l,r, 8);
D_ENCRYPT(r,l,10);
D_ENCRYPT(l,r,12);
D_ENCRYPT(r,l,14);
D_ENCRYPT(l,r,16);
D_ENCRYPT(r,l,18);
D_ENCRYPT(l,r,20);
D_ENCRYPT(r,l,22);
D_ENCRYPT(l,r,24);
D_ENCRYPT(r,l,26);
D_ENCRYPT(l,r,28);
D_ENCRYPT(r,l,30);
#else
for (i=0; i<32; i+=8)
{
D_ENCRYPT(l,r,i+0);
D_ENCRYPT(r,l,i+2);
D_ENCRYPT(l,r,i+4);
D_ENCRYPT(r,l,i+6);
}
#endif
}
else
{
#ifdef DES_UNROLL
D_ENCRYPT(l,r,30);
D_ENCRYPT(r,l,28);
D_ENCRYPT(l,r,26);
D_ENCRYPT(r,l,24);
D_ENCRYPT(l,r,22);
D_ENCRYPT(r,l,20);
D_ENCRYPT(l,r,18);
D_ENCRYPT(r,l,16);
D_ENCRYPT(l,r,14);
D_ENCRYPT(r,l,12);
D_ENCRYPT(l,r,10);
D_ENCRYPT(r,l, 8);
D_ENCRYPT(l,r, 6);
D_ENCRYPT(r,l, 4);
D_ENCRYPT(l,r, 2);
D_ENCRYPT(r,l, 0);
#else
for (i=30; i>0; i-=8)
{
D_ENCRYPT(l,r,i-0);
D_ENCRYPT(r,l,i-2);
D_ENCRYPT(l,r,i-4);
D_ENCRYPT(r,l,i-6);
}
#endif
}
l=ROTATE(l,3)&0xffffffffL;
r=ROTATE(r,3)&0xffffffffL;
FP(r,l);
data[0]=l;
data[1]=r;
l=r=t=u=0;
} | ['void des_string_to_2keys(const char *str, des_cblock key1, des_cblock key2)\n\t{\n\tdes_key_schedule ks;\n\tint i,length;\n\tregister unsigned char j;\n\tmemset(key1,0,8);\n\tmemset(key2,0,8);\n\tlength=strlen(str);\n#ifdef OLD_STR_TO_KEY\n\tif (length <= 8)\n\t\t{\n\t\tfor (i=0; i<length; i++)\n\t\t\t{\n\t\t\tkey2[i]=key1[i]=(str[i]<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tfor (i=0; i<length; i++)\n\t\t\t{\n\t\t\tif ((i/8)&1)\n\t\t\t\tkey2[i%8]^=(str[i]<<1);\n\t\t\telse\n\t\t\t\tkey1[i%8]^=(str[i]<<1);\n\t\t\t}\n\t\t}\n#else\n\tfor (i=0; i<length; i++)\n\t\t{\n\t\tj=str[i];\n\t\tif ((i%32) < 16)\n\t\t\t{\n\t\t\tif ((i%16) < 8)\n\t\t\t\tkey1[i%8]^=(j<<1);\n\t\t\telse\n\t\t\t\tkey2[i%8]^=(j<<1);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tj=((j<<4)&0xf0)|((j>>4)&0x0f);\n\t\t\tj=((j<<2)&0xcc)|((j>>2)&0x33);\n\t\t\tj=((j<<1)&0xaa)|((j>>1)&0x55);\n\t\t\tif ((i%16) < 8)\n\t\t\t\tkey1[7-(i%8)]^=j;\n\t\t\telse\n\t\t\t\tkey2[7-(i%8)]^=j;\n\t\t\t}\n\t\t}\n\tif (length <= 8) memcpy(key2,key1,8);\n#endif\n\tdes_set_odd_parity(key1);\n\tdes_set_odd_parity(key2);\n\ti=des_check_key;\n\tdes_check_key=0;\n\tdes_set_key(key1,ks);\n\tdes_cbc_cksum((unsigned char*)str,key1,length,ks,key1);\n\tdes_set_key(key2,ks);\n\tdes_cbc_cksum((unsigned char*)str,key2,length,ks,key2);\n\tdes_check_key=i;\n\tmemset(ks,0,sizeof(ks));\n\tdes_set_odd_parity(key1);\n\tdes_set_odd_parity(key2);\n\t}', 'DES_LONG des_cbc_cksum(const unsigned char *in, des_cblock out, long length,\n\t des_key_schedule schedule, const des_cblock iv)\n\t{\n\tregister DES_LONG tout0,tout1,tin0,tin1;\n\tregister long l=length;\n\tDES_LONG tin[2];\n\tc2l(iv,tout0);\n\tc2l(iv,tout1);\n\tfor (; l>0; l-=8)\n\t\t{\n\t\tif (l >= 8)\n\t\t\t{\n\t\t\tc2l(in,tin0);\n\t\t\tc2l(in,tin1);\n\t\t\t}\n\t\telse\n\t\t\tc2ln(in,tin0,tin1,l);\n\t\ttin0^=tout0; tin[0]=tin0;\n\t\ttin1^=tout1; tin[1]=tin1;\n\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);\n\t\ttout0=tin[0];\n\t\ttout1=tin[1];\n\t\t}\n\tif (out != NULL)\n\t\t{\n\t\tl2c(tout0,out);\n\t\tl2c(tout1,out);\n\t\t}\n\ttout0=tin0=tin1=tin[0]=tin[1]=0;\n\treturn(tout1);\n\t}', 'void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)\n\t{\n\tregister DES_LONG l,r,t,u;\n#ifdef DES_PTR\n\tregister const unsigned char *des_SP=(const unsigned char *)des_SPtrans;\n#endif\n#ifndef DES_UNROLL\n\tregister int i;\n#endif\n\tregister DES_LONG *s;\n\tr=data[0];\n\tl=data[1];\n\tIP(r,l);\n\tr=ROTATE(r,29)&0xffffffffL;\n\tl=ROTATE(l,29)&0xffffffffL;\n\ts=(DES_LONG *)ks;\n\tif (enc)\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r, 0);\n\t\tD_ENCRYPT(r,l, 2);\n\t\tD_ENCRYPT(l,r, 4);\n\t\tD_ENCRYPT(r,l, 6);\n\t\tD_ENCRYPT(l,r, 8);\n\t\tD_ENCRYPT(r,l,10);\n\t\tD_ENCRYPT(l,r,12);\n\t\tD_ENCRYPT(r,l,14);\n\t\tD_ENCRYPT(l,r,16);\n\t\tD_ENCRYPT(r,l,18);\n\t\tD_ENCRYPT(l,r,20);\n\t\tD_ENCRYPT(r,l,22);\n\t\tD_ENCRYPT(l,r,24);\n\t\tD_ENCRYPT(r,l,26);\n\t\tD_ENCRYPT(l,r,28);\n\t\tD_ENCRYPT(r,l,30);\n#else\n\t\tfor (i=0; i<32; i+=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i+0);\n\t\t\tD_ENCRYPT(r,l,i+2);\n\t\t\tD_ENCRYPT(l,r,i+4);\n\t\t\tD_ENCRYPT(r,l,i+6);\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r,30);\n\t\tD_ENCRYPT(r,l,28);\n\t\tD_ENCRYPT(l,r,26);\n\t\tD_ENCRYPT(r,l,24);\n\t\tD_ENCRYPT(l,r,22);\n\t\tD_ENCRYPT(r,l,20);\n\t\tD_ENCRYPT(l,r,18);\n\t\tD_ENCRYPT(r,l,16);\n\t\tD_ENCRYPT(l,r,14);\n\t\tD_ENCRYPT(r,l,12);\n\t\tD_ENCRYPT(l,r,10);\n\t\tD_ENCRYPT(r,l, 8);\n\t\tD_ENCRYPT(l,r, 6);\n\t\tD_ENCRYPT(r,l, 4);\n\t\tD_ENCRYPT(l,r, 2);\n\t\tD_ENCRYPT(r,l, 0);\n#else\n\t\tfor (i=30; i>0; i-=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i-0);\n\t\t\tD_ENCRYPT(r,l,i-2);\n\t\t\tD_ENCRYPT(l,r,i-4);\n\t\t\tD_ENCRYPT(r,l,i-6);\n\t\t\t}\n#endif\n\t\t}\n\tl=ROTATE(l,3)&0xffffffffL;\n\tr=ROTATE(r,3)&0xffffffffL;\n\tFP(r,l);\n\tdata[0]=l;\n\tdata[1]=r;\n\tl=r=t=u=0;\n\t}'] |
33,076 | 0 | https://github.com/openssl/openssl/blob/b90506e995d44dee0ef4dd0324b56b59154256c2/ssl/packet.c/#L46 | 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->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;
}
*allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;
return 1;
} | ['int tls_construct_certificate_request(SSL *s, WPACKET *pkt)\n{\n int i, nl;\n STACK_OF(X509_NAME) *sk = NULL;\n if (!WPACKET_start_sub_packet_u8(pkt)\n || !ssl3_get_req_cert_type(s, pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (SSL_USE_SIGALGS(s)) {\n const unsigned char *psigs;\n nl = tls12_get_psigalgs(s, &psigs);\n if (!WPACKET_start_sub_packet_u16(pkt)\n || !tls12_copy_sigalgs(s, pkt, psigs, nl)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n if (!WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n sk = SSL_get_client_CA_list(s);\n if (sk != NULL) {\n for (i = 0; i < sk_X509_NAME_num(sk); i++) {\n unsigned char *namebytes;\n X509_NAME *name = sk_X509_NAME_value(sk, i);\n int namelen;\n if (name == NULL\n || (namelen = i2d_X509_NAME(name, NULL)) < 0\n || !WPACKET_sub_allocate_bytes_u16(pkt, namelen,\n &namebytes)\n || i2d_X509_NAME(name, &namebytes) != namelen) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n }\n if (!WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CERTIFICATE_REQUEST, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n s->s3->tmp.cert_request = 1;\n return 1;\n err:\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n return 0;\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 - (unsigned char *)pkt->buf->data;\n return 1;\n}', 'int ssl3_get_req_cert_type(SSL *s, WPACKET *pkt)\n{\n uint32_t alg_k, alg_a = 0;\n if (s->cert->ctypes) {\n return WPACKET_memcpy(pkt, s->cert->ctypes, s->cert->ctype_num);\n }\n ssl_set_sig_mask(&alg_a, s, SSL_SECOP_SIGALG_MASK);\n alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n#ifndef OPENSSL_NO_GOST\n if (s->version >= TLS1_VERSION && (alg_k & SSL_kGOST))\n return WPACKET_put_bytes_u8(pkt, TLS_CT_GOST01_SIGN)\n && WPACKET_put_bytes_u8(pkt, TLS_CT_GOST12_SIGN)\n && WPACKET_put_bytes_u8(pkt, TLS_CT_GOST12_512_SIGN);\n#endif\n if ((s->version == SSL3_VERSION) && (alg_k & SSL_kDHE)) {\n#ifndef OPENSSL_NO_DH\n# ifndef OPENSSL_NO_RSA\n if (!WPACKET_put_bytes_u8(pkt, SSL3_CT_RSA_EPHEMERAL_DH))\n return 0;\n# endif\n# ifndef OPENSSL_NO_DSA\n if (!WPACKET_put_bytes_u8(pkt, SSL3_CT_DSS_EPHEMERAL_DH))\n return 0;\n# endif\n#endif\n }\n#ifndef OPENSSL_NO_RSA\n if (!(alg_a & SSL_aRSA) && !WPACKET_put_bytes_u8(pkt, SSL3_CT_RSA_SIGN))\n return 0;\n#endif\n#ifndef OPENSSL_NO_DSA\n if (!(alg_a & SSL_aDSS) && !WPACKET_put_bytes_u8(pkt, SSL3_CT_DSS_SIGN))\n return 0;\n#endif\n#ifndef OPENSSL_NO_EC\n if (s->version >= TLS1_VERSION\n && !(alg_a & SSL_aECDSA)\n && !WPACKET_put_bytes_u8(pkt, TLS_CT_ECDSA_SIGN))\n return 0;\n#endif\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->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 *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n return 1;\n}'] |
33,077 | 0 | https://github.com/openssl/openssl/blob/02703c74a4c10f3848cdd5e7ff5196ab45c7e67e/engines/e_chil.c/#L814 | static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
UI_METHOD *ui_method, void *callback_data)
{
#ifndef OPENSSL_NO_RSA
RSA *rtmp = NULL;
#endif
EVP_PKEY *res = NULL;
#ifndef OPENSSL_NO_RSA
HWCryptoHook_MPI e, n;
HWCryptoHook_RSAKeyHandle *hptr;
#endif
#if !defined(OPENSSL_NO_RSA)
char tempbuf[1024];
HWCryptoHook_ErrMsgBuf rmsg;
HWCryptoHook_PassphraseContext ppctx;
#endif
#if !defined(OPENSSL_NO_RSA)
rmsg.buf = tempbuf;
rmsg.size = sizeof(tempbuf);
#endif
if(!hwcrhk_context)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_NOT_INITIALISED);
goto err;
}
#ifndef OPENSSL_NO_RSA
hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));
if (!hptr)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
ERR_R_MALLOC_FAILURE);
goto err;
}
ppctx.ui_method = ui_method;
ppctx.callback_data = callback_data;
if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,
&rmsg, &ppctx))
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_CHIL_ERROR);
ERR_add_error_data(1,rmsg.buf);
goto err;
}
if (!*hptr)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_NO_KEY);
goto err;
}
#endif
#ifndef OPENSSL_NO_RSA
rtmp = RSA_new_method(eng);
RSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr);
rtmp->e = BN_new();
rtmp->n = BN_new();
rtmp->flags |= RSA_FLAG_EXT_PKEY;
MPI2BN(rtmp->e, e);
MPI2BN(rtmp->n, n);
if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)
!= HWCRYPTOHOOK_ERROR_MPISIZE)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,HWCRHK_R_CHIL_ERROR);
ERR_add_error_data(1,rmsg.buf);
goto err;
}
bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));
bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));
MPI2BN(rtmp->e, e);
MPI2BN(rtmp->n, n);
if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_CHIL_ERROR);
ERR_add_error_data(1,rmsg.buf);
goto err;
}
rtmp->e->top = e.size / sizeof(BN_ULONG);
bn_fix_top(rtmp->e);
rtmp->n->top = n.size / sizeof(BN_ULONG);
bn_fix_top(rtmp->n);
res = EVP_PKEY_new();
EVP_PKEY_assign_RSA(res, rtmp);
#endif
if (!res)
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED);
return res;
err:
if (res)
EVP_PKEY_free(res);
#ifndef OPENSSL_NO_RSA
if (rtmp)
RSA_free(rtmp);
#endif
return NULL;
} | ['static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,\n\tUI_METHOD *ui_method, void *callback_data)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tRSA *rtmp = NULL;\n#endif\n\tEVP_PKEY *res = NULL;\n#ifndef OPENSSL_NO_RSA\n\tHWCryptoHook_MPI e, n;\n\tHWCryptoHook_RSAKeyHandle *hptr;\n#endif\n#if !defined(OPENSSL_NO_RSA)\n\tchar tempbuf[1024];\n\tHWCryptoHook_ErrMsgBuf rmsg;\n\tHWCryptoHook_PassphraseContext ppctx;\n#endif\n#if !defined(OPENSSL_NO_RSA)\n\trmsg.buf = tempbuf;\n\trmsg.size = sizeof(tempbuf);\n#endif\n\tif(!hwcrhk_context)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_NOT_INITIALISED);\n\t\tgoto err;\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\thptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));\n\tif (!hptr)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n ppctx.ui_method = ui_method;\n\tppctx.callback_data = callback_data;\n\tif (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,\n\t\t&rmsg, &ppctx))\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_CHIL_ERROR);\n\t\tERR_add_error_data(1,rmsg.buf);\n\t\tgoto err;\n\t\t}\n\tif (!*hptr)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_NO_KEY);\n\t\tgoto err;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RSA\n\trtmp = RSA_new_method(eng);\n\tRSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr);\n\trtmp->e = BN_new();\n\trtmp->n = BN_new();\n\trtmp->flags |= RSA_FLAG_EXT_PKEY;\n\tMPI2BN(rtmp->e, e);\n\tMPI2BN(rtmp->n, n);\n\tif (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)\n\t\t!= HWCRYPTOHOOK_ERROR_MPISIZE)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,HWCRHK_R_CHIL_ERROR);\n\t\tERR_add_error_data(1,rmsg.buf);\n\t\tgoto err;\n\t\t}\n\tbn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));\n\tbn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));\n\tMPI2BN(rtmp->e, e);\n\tMPI2BN(rtmp->n, n);\n\tif (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_CHIL_ERROR);\n\t\tERR_add_error_data(1,rmsg.buf);\n\t\tgoto err;\n\t\t}\n\trtmp->e->top = e.size / sizeof(BN_ULONG);\n\tbn_fix_top(rtmp->e);\n\trtmp->n->top = n.size / sizeof(BN_ULONG);\n\tbn_fix_top(rtmp->n);\n\tres = EVP_PKEY_new();\n\tEVP_PKEY_assign_RSA(res, rtmp);\n#endif\n if (!res)\n HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED);\n\treturn res;\n err:\n\tif (res)\n\t\tEVP_PKEY_free(res);\n#ifndef OPENSSL_NO_RSA\n\tif (rtmp)\n\t\tRSA_free(rtmp);\n#endif\n\treturn NULL;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'RSA *RSA_new_method(ENGINE *engine)\n\t{\n\tRSA *ret;\n\tret=(RSA *)OPENSSL_malloc(sizeof(RSA));\n\tif (ret == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tret->meth = RSA_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_RSA();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_RSA(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD,\n\t\t\t\tERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n#endif\n\tret->pad=0;\n\tret->version=0;\n\tret->n=NULL;\n\tret->e=NULL;\n\tret->d=NULL;\n\tret->p=NULL;\n\tret->q=NULL;\n\tret->dmp1=NULL;\n\tret->dmq1=NULL;\n\tret->iqmp=NULL;\n\tret->references=1;\n\tret->_method_mod_n=NULL;\n\tret->_method_mod_p=NULL;\n\tret->_method_mod_q=NULL;\n\tret->blinding=NULL;\n\tret->mt_blinding=NULL;\n\tret->bignum_data=NULL;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n#ifndef OPENSSL_NO_ENGINE\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n#endif\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\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}'] |
33,078 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_sqr.c/#L168 | 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 DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL, *r = NULL, *s = NULL;\n BIGNUM *m;\n BIGNUM *xr;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int noredo = 0;\n m = BN_new();\n xr = BN_new();\n if (m == NULL || xr == NULL)\n goto err;\n if (!dsa->p || !dsa->q || !dsa->g) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n s = BN_new();\n if (s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n redo:\n if ((dsa->kinv == NULL) || (dsa->r == NULL)) {\n if (!dsa_sign_setup(dsa, ctx, &kinv, &r, dgst, dlen))\n goto err;\n } else {\n kinv = dsa->kinv;\n dsa->kinv = NULL;\n r = dsa->r;\n dsa->r = NULL;\n noredo = 1;\n }\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n if (!BN_mod_mul(xr, dsa->priv_key, r, dsa->q, ctx))\n goto err;\n if (!BN_add(s, xr, m))\n goto err;\n if (BN_cmp(s, dsa->q) > 0)\n if (!BN_sub(s, s, dsa->q))\n goto err;\n if (!BN_mod_mul(s, s, kinv, dsa->q, ctx))\n goto err;\n if (BN_is_zero(r) || BN_is_zero(s)) {\n if (noredo) {\n reason = DSA_R_NEED_NEW_SETUP_VALUES;\n goto err;\n }\n goto redo;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = r;\n ret->s = s;\n err:\n if (ret == NULL) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n BN_free(r);\n BN_free(s);\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(xr);\n BN_clear_free(kinv);\n return (ret);\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kq, *K, *kinv = NULL, *r = NULL;\n int ret = 0;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n kq = BN_new();\n if (k == NULL || kq == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n if ((r = BN_new()) == NULL)\n goto err;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) {\n BN_set_flags(k, BN_FLG_CONSTTIME);\n }\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n CRYPTO_LOCK_DSA, dsa->p, ctx))\n goto err;\n }\n if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) {\n if (!BN_copy(kq, k))\n goto err;\n if (!BN_add(kq, kq, dsa->q))\n goto err;\n if (BN_num_bits(kq) <= BN_num_bits(dsa->q)) {\n if (!BN_add(kq, kq, dsa->q))\n goto err;\n }\n K = kq;\n } else {\n K = k;\n }\n DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx,\n dsa->method_mont_p);\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n BN_clear_free(*rp);\n *rp = r;\n ret = 1;\n err:\n if (!ret) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n BN_clear_free(r);\n }\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n BN_clear_free(kq);\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 if ((top & 7) == 0)\n powerbufLen += 2 * top * sizeof(m->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 *np = mont->N.d, *n0 = mont->n0, *np2;\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 if (top & 7)\n np2 = np;\n else\n for (np2 = am.d + top, i = 0; i < top; i++)\n np2[2 * i] = np[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, np2, 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, np2, 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, np2, 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, np2, 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, np2, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np2, 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, numPowers))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, numPowers))\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\n (&tmp, top, powerbuf, 2, numPowers))\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\n (&tmp, top, powerbuf, i, numPowers))\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\n (&tmp, top, powerbuf, wvalue, numPowers))\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\n (&am, top, powerbuf, wvalue, numPowers))\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_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return (1);\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}'] |
33,079 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L352 | static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_malloc(words * sizeof(*a));
else
a = A = OPENSSL_malloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#ifdef PURIFY
memset(a, 0, sizeof(*a) * words);
#endif
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
} | ['int test_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_)\n{\n BIGNUM *a, *b, *c, *d;\n int i;\n b = BN_new();\n c = BN_new();\n d = BN_new();\n BN_one(c);\n if (a_)\n a = a_;\n else {\n a = BN_new();\n BN_bntest_rand(a, 200, 0, 0);\n a->neg = rand_neg();\n }\n for (i = 0; i < num0; i++) {\n BN_lshift(b, a, i + 1);\n BN_add(c, c, c);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " * ");\n BN_print(bp, c);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, b);\n BIO_puts(bp, "\\n");\n }\n BN_mul(d, a, c, ctx);\n BN_sub(d, d, b);\n if (!BN_is_zero(d)) {\n fprintf(stderr, "Left shift test failed!\\n");\n fprintf(stderr, "a=");\n BN_print_fp(stderr, a);\n fprintf(stderr, "\\nb=");\n BN_print_fp(stderr, b);\n fprintf(stderr, "\\nc=");\n BN_print_fp(stderr, c);\n fprintf(stderr, "\\nd=");\n BN_print_fp(stderr, d);\n fprintf(stderr, "\\n");\n return 0;\n }\n }\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n return (1);\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'int BN_bntest_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(2, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits < 0 || (bits == 1 && top > 0)) {\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n if (bits == 0) {\n BN_zero(rnd);\n return 1;\n }\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (pseudorand) {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n } else {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n }\n if (pseudorand == 2) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_malloc(words * sizeof(*a));\n else\n a = A = OPENSSL_malloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#ifdef PURIFY\n memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}'] |
33,080 | 0 | https://github.com/openssl/openssl/blob/c849c6d9d3bf806fecfe0c16eaa55d361979ff7f/ssl/packet_locl.h/#L83 | static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
pkt->curr += len;
pkt->remaining -= len;
} | ['int dtls1_listen(SSL *s, struct sockaddr *client)\n{\n int next, n, ret = 0, clearpkt = 0;\n unsigned char cookie[DTLS1_COOKIE_LENGTH];\n unsigned char seq[SEQ_NUM_SIZE];\n unsigned char *data, *p, *buf;\n unsigned long reclen, fragoff, fraglen, msglen;\n unsigned int rectype, versmajor, msgseq, msgtype, clientvers, cookielen;\n BIO *rbio, *wbio;\n BUF_MEM *bufm;\n struct sockaddr_storage tmpclient;\n PACKET pkt, msgpkt, msgpayload, session, cookiepkt;\n if (!SSL_clear(s))\n return -1;\n ERR_clear_error();\n rbio = SSL_get_rbio(s);\n wbio = SSL_get_wbio(s);\n if(!rbio || !wbio) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_BIO_NOT_SET);\n return -1;\n }\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n if ((s->version & 0xff00) != (DTLS1_VERSION & 0xff00)) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_UNSUPPORTED_SSL_VERSION);\n return -1;\n }\n if (s->init_buf == NULL) {\n if ((bufm = BUF_MEM_new()) == NULL) {\n SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n if (!BUF_MEM_grow(bufm, SSL3_RT_MAX_PLAIN_LENGTH)) {\n BUF_MEM_free(bufm);\n SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n s->init_buf = bufm;\n }\n buf = (unsigned char *)s->init_buf->data;\n do {\n clear_sys_error();\n n = BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n if (n <= 0) {\n if(BIO_should_retry(rbio)) {\n goto end;\n }\n return -1;\n }\n clearpkt = 1;\n if (!PACKET_buf_init(&pkt, buf, n)) {\n SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n if (n < DTLS1_RT_HEADER_LENGTH) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_RECORD_TOO_SMALL);\n goto end;\n }\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, buf,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n if (!PACKET_get_1(&pkt, &rectype)\n || !PACKET_get_1(&pkt, &versmajor)) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (rectype != SSL3_RT_HANDSHAKE) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n if (versmajor != DTLS1_VERSION_MAJOR) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_BAD_PROTOCOL_VERSION_NUMBER);\n goto end;\n }\n if (!PACKET_forward(&pkt, 1)\n || !PACKET_copy_bytes(&pkt, seq, SEQ_NUM_SIZE)\n || !PACKET_get_length_prefixed_2(&pkt, &msgpkt)\n || PACKET_remaining(&pkt) != 0) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (seq[0] != 0 || seq[1] != 0) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n data = PACKET_data(&msgpkt);\n if (!PACKET_get_1(&msgpkt, &msgtype)\n || !PACKET_get_net_3(&msgpkt, &msglen)\n || !PACKET_get_net_2(&msgpkt, &msgseq)\n || !PACKET_get_net_3(&msgpkt, &fragoff)\n || !PACKET_get_net_3(&msgpkt, &fraglen)\n || !PACKET_get_sub_packet(&msgpkt, &msgpayload, msglen)\n || PACKET_remaining(&msgpkt) != 0) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (msgtype != SSL3_MT_CLIENT_HELLO) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_UNEXPECTED_MESSAGE);\n goto end;\n }\n if(msgseq > 2) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_INVALID_SEQUENCE_NUMBER);\n goto end;\n }\n if (fragoff != 0 || fraglen != msglen) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_FRAGMENTED_CLIENT_HELLO);\n goto end;\n }\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, data,\n msglen + DTLS1_HM_HEADER_LENGTH, s,\n s->msg_callback_arg);\n if (!PACKET_get_net_2(&msgpayload, &clientvers)) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if ((clientvers > (unsigned int)s->method->version &&\n s->method->version != DTLS_ANY_VERSION)) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_WRONG_VERSION_NUMBER);\n goto end;\n }\n if (!PACKET_forward(&msgpayload, SSL3_RANDOM_SIZE)\n || !PACKET_get_length_prefixed_1(&msgpayload, &session)\n || !PACKET_get_length_prefixed_1(&msgpayload, &cookiepkt)) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_LENGTH_MISMATCH);\n goto end;\n }\n if (PACKET_remaining(&cookiepkt) == 0) {\n next = LISTEN_SEND_VERIFY_REQUEST;\n } else {\n if (s->ctx->app_verify_cookie_cb == NULL) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_NO_VERIFY_COOKIE_CALLBACK);\n return -1;\n }\n if (s->ctx->app_verify_cookie_cb(s, PACKET_data(&cookiepkt),\n PACKET_remaining(&cookiepkt)) ==\n 0) {\n next = LISTEN_SEND_VERIFY_REQUEST;\n } else {\n next = LISTEN_SUCCESS;\n }\n }\n if (next == LISTEN_SEND_VERIFY_REQUEST) {\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 1, NULL);\n if (s->ctx->app_gen_cookie_cb == NULL ||\n s->ctx->app_gen_cookie_cb(s, cookie, &cookielen) == 0 ||\n cookielen > 255) {\n SSLerr(SSL_F_DTLS1_LISTEN, SSL_R_COOKIE_GEN_CALLBACK_FAILURE);\n return -1;\n }\n p = &buf[DTLS1_RT_HEADER_LENGTH];\n msglen = dtls_raw_hello_verify_request(p + DTLS1_HM_HEADER_LENGTH,\n cookie, cookielen);\n *p++ = DTLS1_MT_HELLO_VERIFY_REQUEST;\n l2n3(msglen, p);\n s2n(0, p);\n l2n3(0, p);\n l2n3(msglen, p);\n reclen = msglen + DTLS1_HM_HEADER_LENGTH;\n p = buf;\n *(p++) = SSL3_RT_HANDSHAKE;\n if (s->method->version == DTLS_ANY_VERSION) {\n *(p++) = DTLS1_VERSION >> 8;\n *(p++) = DTLS1_VERSION & 0xff;\n } else {\n *(p++) = s->version >> 8;\n *(p++) = s->version & 0xff;\n }\n memcpy(p, seq, SEQ_NUM_SIZE);\n p += SEQ_NUM_SIZE;\n s2n(reclen, p);\n reclen += DTLS1_RT_HEADER_LENGTH;\n if (s->msg_callback)\n s->msg_callback(1, 0, SSL3_RT_HEADER, buf,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n if(BIO_dgram_get_peer(rbio, &tmpclient) <= 0\n || BIO_dgram_set_peer(wbio, &tmpclient) <= 0) {\n SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);\n goto end;\n }\n if (BIO_write(wbio, buf, reclen) < (int)reclen) {\n if(BIO_should_retry(wbio)) {\n goto end;\n }\n return -1;\n }\n if (BIO_flush(wbio) <= 0) {\n if(BIO_should_retry(wbio)) {\n goto end;\n }\n return -1;\n }\n }\n } while (next != LISTEN_SUCCESS);\n s->d1->handshake_read_seq = 1;\n s->d1->handshake_write_seq = 1;\n s->d1->next_handshake_write_seq = 1;\n DTLS_RECORD_LAYER_set_write_sequence(&s->rlayer, seq);\n SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);\n ossl_statem_set_hello_verify_done(s);\n if(BIO_dgram_get_peer(rbio, client) <= 0) {\n SSLerr(SSL_F_DTLS1_LISTEN, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n ret = 1;\n clearpkt = 0;\nend:\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_PEEK_MODE, 0, NULL);\n if (clearpkt) {\n BIO_read(rbio, buf, SSL3_RT_MAX_PLAIN_LENGTH);\n }\n return ret;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}'] |
33,081 | 0 | https://github.com/libav/libav/blob/47d2ddca802f4c1bc4b454c5ac40f06f79b740a0/libavcodec/mpegaudiodec.c/#L683 | 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 int qdm2_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n QDM2Context *s = avctx->priv_data;\n int16_t *out = data;\n int i;\n if(!buf)\n return 0;\n if(buf_size < s->checksum_size)\n return -1;\n av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\\n",\n buf_size, buf, s->checksum_size, data, *data_size);\n for (i = 0; i < 16; i++) {\n if (qdm2_decode(s, buf, out) < 0)\n return -1;\n out += s->channels * s->frame_size;\n }\n *data_size = (uint8_t*)out - (uint8_t*)data;\n return buf_size;\n}', 'static int qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)\n{\n int ch, i;\n const int frame_size = (q->frame_size * q->channels);\n q->compressed_data = in;\n q->compressed_size = q->checksum_size;\n memmove(q->output_buffer, &q->output_buffer[frame_size], frame_size * sizeof(float));\n memset(&q->output_buffer[frame_size], 0, frame_size * sizeof(float));\n if (q->sub_packet == 0) {\n q->has_errors = 0;\n av_log(NULL,AV_LOG_DEBUG,"Superblock follows\\n");\n qdm2_decode_super_block(q);\n }\n if (!q->has_errors) {\n if (q->sub_packet == 2)\n qdm2_decode_fft_packets(q);\n qdm2_fft_tone_synthesizer(q, q->sub_packet);\n }\n for (ch = 0; ch < q->channels; ch++) {\n qdm2_calculate_fft(q, ch, q->sub_packet);\n if (!q->has_errors && q->sub_packet_list_C[0].packet != NULL) {\n SAMPLES_NEEDED_2("has errors, and C list is not empty")\n return -1;\n }\n }\n if (!q->has_errors && q->do_synth_filter)\n qdm2_synthesis_filter(q, q->sub_packet);\n q->sub_packet = (q->sub_packet + 1) % 16;\n for (i = 0; i < frame_size; i++) {\n int value = (int)q->output_buffer[i];\n if (value > SOFTCLIP_THRESHOLD)\n value = (value > HARDCLIP_THRESHOLD) ? 32767 : softclip_table[ value - SOFTCLIP_THRESHOLD];\n else if (value < -SOFTCLIP_THRESHOLD)\n value = (value < -HARDCLIP_THRESHOLD) ? -32767 : -softclip_table[-value - SOFTCLIP_THRESHOLD];\n out[i] = value;\n }\n return 0;\n}', 'static void qdm2_synthesis_filter (QDM2Context *q, int index)\n{\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE];\n int i, k, ch, sb_used, sub_sampling, dither_state = 0;\n sb_used = QDM2_SB_USED(q->sub_sampling);\n for (ch = 0; ch < q->channels; ch++)\n for (i = 0; i < 8; i++)\n for (k=sb_used; k < SBLIMIT; k++)\n q->sb_samples[ch][(8 * index) + i][k] = 0;\n for (ch = 0; ch < q->nb_channels; ch++) {\n OUT_INT *samples_ptr = samples + ch;\n for (i = 0; i < 8; i++) {\n ff_mpa_synth_filter(q->synth_buf[ch], &(q->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, q->nb_channels,\n q->sb_samples[ch][(8 * index) + i]);\n samples_ptr += 32 * q->nb_channels;\n }\n }\n sub_sampling = (4 >> q->sub_sampling);\n for (ch = 0; ch < q->channels; ch++)\n for (i = 0; i < q->frame_size; i++)\n q->output_buffer[q->channels * i + ch] += (float)(samples[q->nb_channels * sub_sampling * i + ch] >> (sizeof(OUT_INT)*8-16));\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}'] |
33,082 | 0 | https://github.com/openssl/openssl/blob/c849c6d9d3bf806fecfe0c16eaa55d361979ff7f/ssl/packet_locl.h/#L83 | static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
pkt->curr += len;
pkt->remaining -= len;
} | ['static int test_PACKET_get_net_4(unsigned char buf[BUF_LEN])\n{\n unsigned long i;\n PACKET pkt;\n if ( !PACKET_buf_init(&pkt, buf, BUF_LEN)\n || !PACKET_get_net_4(&pkt, &i)\n || i != 0x02040608UL\n || !PACKET_forward(&pkt, BUF_LEN - 8)\n || !PACKET_get_net_4(&pkt, &i)\n || i != 0xf8fafcfeUL\n || PACKET_get_net_4(&pkt, &i)) {\n fprintf(stderr, "test_PACKET_get_net_4() failed\\n");\n return 0;\n }\n return 1;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}'] |
33,083 | 0 | https://github.com/openssl/openssl/blob/b2293b1e9bb0f2ddb9fdae8130f6103cce2df608/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);
} | ['static IMPLEMENT_LHASH_DOALL_ARG_FN(timeout, SSL_SESSION *, TIMEOUT_PARAM *)', 'static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)\n\t{\n\tif ((p->time == 0) || (p->time > (s->time+s->timeout)))\n\t\t{\n\t\tlh_delete(p->cache,s);\n\t\tSSL_SESSION_list_remove(p->ctx,s);\n\t\ts->not_resumable=1;\n\t\tif (p->ctx->remove_session_cb != NULL)\n\t\t\tp->ctx->remove_session_cb(p->ctx,s);\n\t\tSSL_SESSION_free(s);\n\t\t}\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\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}'] |
33,084 | 0 | https://github.com/openssl/openssl/blob/8ac6a53100bd6730a8824968ec25dccc727c29c9/test/handshake_helper.c/#L317 | static int do_not_call_session_ticket_cb(SSL *s, unsigned char *key_name,
unsigned char *iv,
EVP_CIPHER_CTX *ctx,
HMAC_CTX *hctx, int enc)
{
HANDSHAKE_EX_DATA *ex_data =
(HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
ex_data->session_ticket_do_not_call = 1;
return 0;
} | ['static int do_not_call_session_ticket_cb(SSL *s, unsigned char *key_name,\n unsigned char *iv,\n EVP_CIPHER_CTX *ctx,\n HMAC_CTX *hctx, int enc)\n{\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n ex_data->session_ticket_do_not_call = 1;\n return 0;\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return (CRYPTO_get_ex_data(&s->ex_data, idx));\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}'] |
33,085 | 0 | https://github.com/libav/libav/blob/4d4d7cf9d539a053f531f662a972b23d335738eb/libavcodec/fmvc.c/#L221 | static int decode_type2(GetByteContext *gb, PutByteContext *pb)
{
unsigned repeat = 0, first = 1, opcode;
int i, len, pos;
while (bytestream2_get_bytes_left(gb) > 0) {
GetByteContext gbc;
while (bytestream2_get_bytes_left(gb) > 0) {
if (first) {
first = 0;
if (bytestream2_peek_byte(gb) > 17) {
len = bytestream2_get_byte(gb) - 17;
if (len < 4) {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
continue;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
if (opcode < 0x10) {
bytestream2_skip(gb, 1);
pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
}
}
repeat = 0;
}
repeat = 1;
}
if (repeat) {
repeat = 0;
opcode = bytestream2_peek_byte(gb);
if (opcode < 0x10) {
bytestream2_skip(gb, 1);
if (!opcode) {
if (!bytestream2_peek_byte(gb)) {
do {
bytestream2_skip(gb, 1);
opcode += 255;
} while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);
}
opcode += bytestream2_get_byte(gb) + 15;
}
bytestream2_put_le32(pb, bytestream2_get_le32(gb));
for (i = opcode - 1; i > 0; --i)
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
opcode = bytestream2_peek_byte(gb);
if (opcode < 0x10) {
bytestream2_skip(gb, 1);
pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
}
}
}
if (opcode >= 0x40) {
bytestream2_skip(gb, 1);
pos = - ((opcode >> 2) & 7) - 1 - 8 * bytestream2_get_byte(gb);
len = (opcode >> 5) - 1;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
do {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
--len;
} while (len);
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
} else if (opcode < 0x20) {
break;
}
len = opcode & 0x1F;
bytestream2_skip(gb, 1);
if (!len) {
if (!bytestream2_peek_byte(gb)) {
do {
bytestream2_skip(gb, 1);
len += 255;
} while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);
}
len += bytestream2_get_byte(gb) + 31;
}
i = bytestream2_get_le16(gb);
pos = - (i >> 2) - 1;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
do {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
--len;
} while (len);
} else {
bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));
for (len = len - 2; len; --len)
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
}
len = i & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
}
bytestream2_skip(gb, 1);
if (opcode < 0x10) {
pos = -(opcode >> 2) - 1 - 4 * bytestream2_get_byte(gb);
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
len = opcode & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
continue;
}
len = opcode & 7;
if (!len) {
if (!bytestream2_peek_byte(gb)) {
do {
bytestream2_skip(gb, 1);
len += 255;
} while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);
}
len += bytestream2_get_byte(gb) + 7;
}
i = bytestream2_get_le16(gb);
pos = bytestream2_tell_p(pb) - 2048 * (opcode & 8);
pos = pos - (i >> 2);
if (pos == bytestream2_tell_p(pb))
break;
pos = pos - 0x4000;
bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);
bytestream2_seek(&gbc, pos, SEEK_SET);
if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
do {
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
--len;
} while (len);
} else {
bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));
for (len = len - 2; len; --len)
bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));
}
len = i & 3;
if (!len) {
repeat = 1;
} else {
do {
bytestream2_put_byte(pb, bytestream2_get_byte(gb));
--len;
} while (len);
opcode = bytestream2_peek_byte(gb);
}
}
return 0;
} | ['static int decode_type2(GetByteContext *gb, PutByteContext *pb)\n{\n unsigned repeat = 0, first = 1, opcode;\n int i, len, pos;\n while (bytestream2_get_bytes_left(gb) > 0) {\n GetByteContext gbc;\n while (bytestream2_get_bytes_left(gb) > 0) {\n if (first) {\n first = 0;\n if (bytestream2_peek_byte(gb) > 17) {\n len = bytestream2_get_byte(gb) - 17;\n if (len < 4) {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n continue;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n if (opcode < 0x10) {\n bytestream2_skip(gb, 1);\n pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n }\n }\n repeat = 0;\n }\n repeat = 1;\n }\n if (repeat) {\n repeat = 0;\n opcode = bytestream2_peek_byte(gb);\n if (opcode < 0x10) {\n bytestream2_skip(gb, 1);\n if (!opcode) {\n if (!bytestream2_peek_byte(gb)) {\n do {\n bytestream2_skip(gb, 1);\n opcode += 255;\n } while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);\n }\n opcode += bytestream2_get_byte(gb) + 15;\n }\n bytestream2_put_le32(pb, bytestream2_get_le32(gb));\n for (i = opcode - 1; i > 0; --i)\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n opcode = bytestream2_peek_byte(gb);\n if (opcode < 0x10) {\n bytestream2_skip(gb, 1);\n pos = - (opcode >> 2) - 4 * bytestream2_get_byte(gb) - 2049;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n }\n }\n }\n if (opcode >= 0x40) {\n bytestream2_skip(gb, 1);\n pos = - ((opcode >> 2) & 7) - 1 - 8 * bytestream2_get_byte(gb);\n len = (opcode >> 5) - 1;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n --len;\n } while (len);\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n } else if (opcode < 0x20) {\n break;\n }\n len = opcode & 0x1F;\n bytestream2_skip(gb, 1);\n if (!len) {\n if (!bytestream2_peek_byte(gb)) {\n do {\n bytestream2_skip(gb, 1);\n len += 255;\n } while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);\n }\n len += bytestream2_get_byte(gb) + 31;\n }\n i = bytestream2_get_le16(gb);\n pos = - (i >> 2) - 1;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n --len;\n } while (len);\n } else {\n bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));\n for (len = len - 2; len; --len)\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n }\n len = i & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n }\n bytestream2_skip(gb, 1);\n if (opcode < 0x10) {\n pos = -(opcode >> 2) - 1 - 4 * bytestream2_get_byte(gb);\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, bytestream2_tell_p(pb) + pos, SEEK_SET);\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n len = opcode & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n continue;\n }\n len = opcode & 7;\n if (!len) {\n if (!bytestream2_peek_byte(gb)) {\n do {\n bytestream2_skip(gb, 1);\n len += 255;\n } while (!bytestream2_peek_byte(gb) && bytestream2_get_bytes_left(gb) > 0);\n }\n len += bytestream2_get_byte(gb) + 7;\n }\n i = bytestream2_get_le16(gb);\n pos = bytestream2_tell_p(pb) - 2048 * (opcode & 8);\n pos = pos - (i >> 2);\n if (pos == bytestream2_tell_p(pb))\n break;\n pos = pos - 0x4000;\n bytestream2_init(&gbc, pb->buffer_start, pb->buffer_end - pb->buffer_start);\n bytestream2_seek(&gbc, pos, SEEK_SET);\n if (len < 6 || bytestream2_tell_p(pb) - bytestream2_tell(&gbc) < 4) {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n --len;\n } while (len);\n } else {\n bytestream2_put_le32(pb, bytestream2_get_le32(&gbc));\n for (len = len - 2; len; --len)\n bytestream2_put_byte(pb, bytestream2_get_byte(&gbc));\n }\n len = i & 3;\n if (!len) {\n repeat = 1;\n } else {\n do {\n bytestream2_put_byte(pb, bytestream2_get_byte(gb));\n --len;\n } while (len);\n opcode = bytestream2_peek_byte(gb);\n }\n }\n return 0;\n}'] |
33,086 | 0 | https://github.com/openssl/openssl/blob/92eb4c551d7433ba1e74e77001dab2e256f8a870/crypto/bn/bn_ctx.c/#L355 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)\n\t{\n\tBN_CTX *ctx;\n\tBIGNUM k,kq,*K,*kinv=NULL,*r=NULL;\n\tint ret=0;\n\tif (!dsa->p || !dsa->q || !dsa->g)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);\n\t\treturn 0;\n\t\t}\n\tBN_init(&k);\n\tBN_init(&kq);\n\tif (ctx_in == NULL)\n\t\t{\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tctx=ctx_in;\n\tif ((r=BN_new()) == NULL) goto err;\n\tdo\n\t\tif (!BN_rand_range(&k, dsa->q)) goto err;\n\twhile (BN_is_zero(&k));\n\tif ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t{\n\t\tBN_set_flags(&k, BN_FLG_CONSTTIME);\n\t\t}\n\tif (dsa->flags & DSA_FLAG_CACHE_MONT_P)\n\t\t{\n\t\tif (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n\t\t\t\t\t\tCRYPTO_LOCK_DSA,\n\t\t\t\t\t\tdsa->p, ctx))\n\t\t\tgoto err;\n\t\t}\n\tif ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t{\n\t\tif (!BN_copy(&kq, &k)) goto err;\n\t\tif (!BN_add(&kq, &kq, dsa->q)) goto err;\n\t\tif (BN_num_bits(&kq) <= BN_num_bits(dsa->q))\n\t\t\t{\n\t\t\tif (!BN_add(&kq, &kq, dsa->q)) goto err;\n\t\t\t}\n\t\tK = &kq;\n\t\t}\n\telse\n\t\t{\n\t\tK = &k;\n\t\t}\n\tDSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx,\n\t\t\tdsa->method_mont_p);\n\tif (!BN_mod(r,r,dsa->q,ctx)) goto err;\n\tif ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;\n\tif (*kinvp != NULL) BN_clear_free(*kinvp);\n\t*kinvp=kinv;\n\tkinv=NULL;\n\tif (*rp != NULL) BN_clear_free(*rp);\n\t*rp=r;\n\tret=1;\nerr:\n\tif (!ret)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);\n\t\tif (r != NULL)\n\t\t\tBN_clear_free(r);\n\t\t}\n\tif (ctx_in == NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&k);\n\tBN_clear_free(&kq);\n\treturn(ret);\n\t}', '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}', 'int BN_mod_exp_mont_consttime(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,bits,ret=0,idx,window,wvalue;\n\tint top;\n \tBIGNUM *r;\n\tconst BIGNUM *aa;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tint powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM *computeTemp=NULL, *am=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,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\tr = BN_CTX_get(ctx);\n\tif (r == NULL) 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\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*top*numPowers;\n\tif ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n \tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(r, top, powerbuf, 0, numPowers)) goto err;\n\tcomputeTemp = BN_CTX_get(ctx);\n\tam = BN_CTX_get(ctx);\n\tif (computeTemp==NULL || am==NULL) goto err;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(am,a,m,ctx))\n\t\t\tgoto err;\n\t\taa= am;\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(am,aa,mont,ctx)) goto err;\n\tif (!BN_copy(computeTemp, am)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tfor (i=2; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(computeTemp,am,computeTemp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(computeTemp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n \tbits = ((bits+window-1)/window)*window;\n \tidx=bits-1;\n \twhile (idx >= 0)\n \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,idx--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,idx);\n \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(computeTemp, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(r,r,computeTemp,mont,ctx)) goto err;\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\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tOPENSSL_free(powerbufFree);\n\t\t}\n \tif (am!=NULL) BN_clear(am);\n \tif (computeTemp!=NULL) BN_clear(computeTemp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tBN_init(&tmod);\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *rv;\n\tint noinv;\n\trv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n\tif (noinv)\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\treturn rv;\n\t}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *pnoinv)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tif (pnoinv)\n\t\t*pnoinv = 0;\n\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (pnoinv)\n\t\t\t*pnoinv = 1;\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM local_A, local_B;\n\tBIGNUM *pA, *pB;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\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(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 || tmp == NULL || snum == NULL)\n\t\tgoto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\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;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}'] |
33,087 | 0 | https://github.com/libav/libav/blob/562ef82d6a7f96f6b9da1219a5aaf7d9d7056f1b/libavcodec/takdec.c/#L388 | static void decode_filter_coeffs(TAKDecContext *s, int filter_order, int size,
int filter_quant, int16_t *filter)
{
BitstreamContext *bc = &s->bc;
int i, j, a, b;
int filter_tmp[MAX_PREDICTORS];
int16_t predictors[MAX_PREDICTORS];
predictors[0] = bitstream_read_signed(bc, 10);
predictors[1] = bitstream_read_signed(bc, 10);
predictors[2] = bitstream_read_signed(bc, size) << (10 - size);
predictors[3] = bitstream_read_signed(bc, size) << (10 - size);
if (filter_order > 4) {
int av_uninit(code_size);
int code_size_base = size - bitstream_read_bit(bc);
for (i = 4; i < filter_order; i++) {
if (!(i & 3))
code_size = code_size_base - bitstream_read(bc, 2);
predictors[i] = bitstream_read_signed(bc, code_size) << (10 - size);
}
}
filter_tmp[0] = predictors[0] << 6;
for (i = 1; i < filter_order; i++) {
int *p1 = &filter_tmp[0];
int *p2 = &filter_tmp[i - 1];
for (j = 0; j < (i + 1) / 2; j++) {
int tmp = *p1 + (predictors[i] * *p2 + 256 >> 9);
*p2 = *p2 + (predictors[i] * *p1 + 256 >> 9);
*p1 = tmp;
p1++;
p2--;
}
filter_tmp[i] = predictors[i] << 6;
}
a = 1 << (32 - (15 - filter_quant));
b = 1 << ((15 - filter_quant) - 1);
for (i = 0, j = filter_order - 1; i < filter_order / 2; i++, j--) {
filter[j] = a - ((filter_tmp[i] + b) >> (15 - filter_quant));
filter[i] = a - ((filter_tmp[j] + b) >> (15 - filter_quant));
}
} | ['static void decode_filter_coeffs(TAKDecContext *s, int filter_order, int size,\n int filter_quant, int16_t *filter)\n{\n BitstreamContext *bc = &s->bc;\n int i, j, a, b;\n int filter_tmp[MAX_PREDICTORS];\n int16_t predictors[MAX_PREDICTORS];\n predictors[0] = bitstream_read_signed(bc, 10);\n predictors[1] = bitstream_read_signed(bc, 10);\n predictors[2] = bitstream_read_signed(bc, size) << (10 - size);\n predictors[3] = bitstream_read_signed(bc, size) << (10 - size);\n if (filter_order > 4) {\n int av_uninit(code_size);\n int code_size_base = size - bitstream_read_bit(bc);\n for (i = 4; i < filter_order; i++) {\n if (!(i & 3))\n code_size = code_size_base - bitstream_read(bc, 2);\n predictors[i] = bitstream_read_signed(bc, code_size) << (10 - size);\n }\n }\n filter_tmp[0] = predictors[0] << 6;\n for (i = 1; i < filter_order; i++) {\n int *p1 = &filter_tmp[0];\n int *p2 = &filter_tmp[i - 1];\n for (j = 0; j < (i + 1) / 2; j++) {\n int tmp = *p1 + (predictors[i] * *p2 + 256 >> 9);\n *p2 = *p2 + (predictors[i] * *p1 + 256 >> 9);\n *p1 = tmp;\n p1++;\n p2--;\n }\n filter_tmp[i] = predictors[i] << 6;\n }\n a = 1 << (32 - (15 - filter_quant));\n b = 1 << ((15 - filter_quant) - 1);\n for (i = 0, j = filter_order - 1; i < filter_order / 2; i++, j--) {\n filter[j] = a - ((filter_tmp[i] + b) >> (15 - filter_quant));\n filter[i] = a - ((filter_tmp[j] + b) >> (15 - filter_quant));\n }\n}'] |
33,088 | 0 | https://github.com/openssl/openssl/blob/5ea564f154ebe8bda2a0e091a312e2058edf437f/crypto/bn/bn_lib.c/#L716 | int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
{
int i;
BN_ULONG aa, bb;
aa = a[n - 1];
bb = b[n - 1];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
for (i = n - 2; i >= 0; i--) {
aa = a[i];
bb = b[i];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
}
return (0);
} | ['int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d;\n BIGNUM *val[TABLE_SIZE];\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!d || !val[0])\n goto err;\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul(d, val[0], val[0], m, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul(val[i], val[i - 1], d, m, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\n }\n if (!BN_mod_mul(r, r, val[wvalue >> 1], m, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return (ret);\n}', '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_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}'] |
33,089 | 0 | https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_mul.c/#L266 | void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
int dna, int dnb, BN_ULONG *t)
{
int n = n2 / 2, c1, c2;
int tna = n + dna, tnb = n + dnb;
unsigned int neg, zero;
BN_ULONG ln, lo, *p;
# ifdef BN_MUL_COMBA
# if 0
if (n2 == 4) {
bn_mul_comba4(r, a, b);
return;
}
# endif
if (n2 == 8 && dna == 0 && dnb == 0) {
bn_mul_comba8(r, a, b);
return;
}
# endif
if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {
bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);
if ((dna + dnb) < 0)
memset(&r[2 * n2 + dna + dnb], 0,
sizeof(BN_ULONG) * -(dna + dnb));
return;
}
c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);
c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);
zero = neg = 0;
switch (c1 * 3 + c2) {
case -4:
bn_sub_part_words(t, &(a[n]), a, tna, tna - n);
bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);
break;
case -3:
zero = 1;
break;
case -2:
bn_sub_part_words(t, &(a[n]), a, tna, tna - n);
bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
neg = 1;
break;
case -1:
case 0:
case 1:
zero = 1;
break;
case 2:
bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);
neg = 1;
break;
case 3:
zero = 1;
break;
case 4:
bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
break;
}
# ifdef BN_MUL_COMBA
if (n == 4 && dna == 0 && dnb == 0) {
if (!zero)
bn_mul_comba4(&(t[n2]), t, &(t[n]));
else
memset(&t[n2], 0, sizeof(*t) * 8);
bn_mul_comba4(r, a, b);
bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));
} else if (n == 8 && dna == 0 && dnb == 0) {
if (!zero)
bn_mul_comba8(&(t[n2]), t, &(t[n]));
else
memset(&t[n2], 0, sizeof(*t) * 16);
bn_mul_comba8(r, a, b);
bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));
} else
# endif
{
p = &(t[n2 * 2]);
if (!zero)
bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
else
memset(&t[n2], 0, sizeof(*t) * n2);
bn_mul_recursive(r, a, b, n, 0, 0, p);
bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);
}
c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));
if (neg) {
c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));
} else {
c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));
}
c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));
if (c1) {
p = &(r[n + n2]);
lo = *p;
ln = (lo + c1) & BN_MASK2;
*p = ln;
if (ln < (BN_ULONG)c1) {
do {
p++;
lo = *p;
ln = (lo + 1) & BN_MASK2;
*p = ln;
} while (ln == 0);
}
}
} | ['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}', '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_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_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n int dna, int dnb, BN_ULONG *t)\n{\n int n = n2 / 2, c1, c2;\n int tna = n + dna, tnb = n + dnb;\n unsigned int neg, zero;\n BN_ULONG ln, lo, *p;\n# ifdef BN_MUL_COMBA\n# if 0\n if (n2 == 4) {\n bn_mul_comba4(r, a, b);\n return;\n }\n# endif\n if (n2 == 8 && dna == 0 && dnb == 0) {\n bn_mul_comba8(r, a, b);\n return;\n }\n# endif\n if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);\n if ((dna + dnb) < 0)\n memset(&r[2 * n2 + dna + dnb], 0,\n sizeof(BN_ULONG) * -(dna + dnb));\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n zero = neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n zero = 1;\n break;\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n zero = 1;\n break;\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n zero = 1;\n break;\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# ifdef BN_MUL_COMBA\n if (n == 4 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 8);\n bn_mul_comba4(r, a, b);\n bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));\n } else if (n == 8 && dna == 0 && dnb == 0) {\n if (!zero)\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n else\n memset(&t[n2], 0, sizeof(*t) * 16);\n bn_mul_comba8(r, a, b);\n bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));\n } else\n# endif\n {\n p = &(t[n2 * 2]);\n if (!zero)\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n else\n memset(&t[n2], 0, sizeof(*t) * n2);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}'] |
33,090 | 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 read_block_types(AVCodecContext *avctx, BitstreamContext *bc, Bundle *b)\n{\n int t, v;\n int last = 0;\n const uint8_t *dec_end;\n CHECK_READ_VAL(bc, b, t);\n dec_end = b->cur_dec + t;\n if (dec_end > b->data_end) {\n av_log(avctx, AV_LOG_ERROR, "Too many block type values\\n");\n return AVERROR_INVALIDDATA;\n }\n if (bitstream_read_bit(bc)) {\n v = bitstream_read(bc, 4);\n memset(b->cur_dec, v, t);\n b->cur_dec += t;\n } else {\n while (b->cur_dec < dec_end) {\n v = GET_HUFF(bc, b->tree);\n if (v < 12) {\n last = v;\n *b->cur_dec++ = v;\n } else {\n int run = bink_rlelens[v - 12];\n if (dec_end - b->cur_dec < run)\n return AVERROR_INVALIDDATA;\n memset(b->cur_dec, last, run);\n b->cur_dec += run;\n }\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 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}'] |
33,091 | 0 | https://github.com/openssl/openssl/blob/eaf6c61c9f378bec0132d4cae556eee563f545b5/apps/enc.c/#L528 | int MAIN(int argc, char **argv)
{
ENGINE *e = NULL;
static const char magic[]="Salted__";
char mbuf[sizeof magic-1];
char *strbuf=NULL;
unsigned char *buff=NULL,*bufsize=NULL;
int bsize=BSIZE,verbose=0;
int ret=1,inl;
int nopad = 0;
unsigned char key[EVP_MAX_KEY_LENGTH],iv[EVP_MAX_IV_LENGTH];
unsigned char salt[PKCS5_SALT_LEN];
char *str=NULL, *passarg = NULL, *pass = NULL;
char *hkey=NULL,*hiv=NULL,*hsalt = NULL;
int enc=1,printkey=0,i,base64=0;
int debug=0,olb64=0,nosalt=0;
const EVP_CIPHER *cipher=NULL,*c;
char *inf=NULL,*outf=NULL;
BIO *in=NULL,*out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL;
#define PROG_NAME_SIZE 39
char pname[PROG_NAME_SIZE+1];
char *engine = NULL;
apps_startup();
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);
if (strcmp(pname,"base64") == 0)
base64=1;
cipher=EVP_get_cipherbyname(pname);
if (!base64 && (cipher == NULL) && (strcmp(pname,"enc") != 0))
{
BIO_printf(bio_err,"%s is an unknown cipher\n",pname);
goto bad;
}
argc--;
argv++;
while (argc >= 1)
{
if (strcmp(*argv,"-e") == 0)
enc=1;
else if (strcmp(*argv,"-in") == 0)
{
if (--argc < 1) goto bad;
inf= *(++argv);
}
else if (strcmp(*argv,"-out") == 0)
{
if (--argc < 1) goto bad;
outf= *(++argv);
}
else if (strcmp(*argv,"-pass") == 0)
{
if (--argc < 1) goto bad;
passarg= *(++argv);
}
else if (strcmp(*argv,"-engine") == 0)
{
if (--argc < 1) goto bad;
engine= *(++argv);
}
else if (strcmp(*argv,"-d") == 0)
enc=0;
else if (strcmp(*argv,"-p") == 0)
printkey=1;
else if (strcmp(*argv,"-v") == 0)
verbose=1;
else if (strcmp(*argv,"-nopad") == 0)
nopad=1;
else if (strcmp(*argv,"-salt") == 0)
nosalt=0;
else if (strcmp(*argv,"-nosalt") == 0)
nosalt=1;
else if (strcmp(*argv,"-debug") == 0)
debug=1;
else if (strcmp(*argv,"-P") == 0)
printkey=2;
else if (strcmp(*argv,"-A") == 0)
olb64=1;
else if (strcmp(*argv,"-a") == 0)
base64=1;
else if (strcmp(*argv,"-base64") == 0)
base64=1;
else if (strcmp(*argv,"-bufsize") == 0)
{
if (--argc < 1) goto bad;
bufsize=(unsigned char *)*(++argv);
}
else if (strcmp(*argv,"-k") == 0)
{
if (--argc < 1) goto bad;
str= *(++argv);
}
else if (strcmp(*argv,"-kfile") == 0)
{
static char buf[128];
FILE *infile;
char *file;
if (--argc < 1) goto bad;
file= *(++argv);
infile=fopen(file,"r");
if (infile == NULL)
{
BIO_printf(bio_err,"unable to read key from '%s'\n",
file);
goto bad;
}
buf[0]='\0';
fgets(buf,sizeof buf,infile);
fclose(infile);
i=strlen(buf);
if ((i > 0) &&
((buf[i-1] == '\n') || (buf[i-1] == '\r')))
buf[--i]='\0';
if ((i > 0) &&
((buf[i-1] == '\n') || (buf[i-1] == '\r')))
buf[--i]='\0';
if (i < 1)
{
BIO_printf(bio_err,"zero length password\n");
goto bad;
}
str=buf;
}
else if (strcmp(*argv,"-K") == 0)
{
if (--argc < 1) goto bad;
hkey= *(++argv);
}
else if (strcmp(*argv,"-S") == 0)
{
if (--argc < 1) goto bad;
hsalt= *(++argv);
}
else if (strcmp(*argv,"-iv") == 0)
{
if (--argc < 1) goto bad;
hiv= *(++argv);
}
else if ((argv[0][0] == '-') &&
((c=EVP_get_cipherbyname(&(argv[0][1]))) != NULL))
{
cipher=c;
}
else if (strcmp(*argv,"-none") == 0)
cipher=NULL;
else
{
BIO_printf(bio_err,"unknown option '%s'\n",*argv);
bad:
BIO_printf(bio_err,"options are\n");
BIO_printf(bio_err,"%-14s input file\n","-in <file>");
BIO_printf(bio_err,"%-14s output file\n","-out <file>");
BIO_printf(bio_err,"%-14s pass phrase source\n","-pass <arg>");
BIO_printf(bio_err,"%-14s encrypt\n","-e");
BIO_printf(bio_err,"%-14s decrypt\n","-d");
BIO_printf(bio_err,"%-14s base64 encode/decode, depending on encryption flag\n","-a/-base64");
BIO_printf(bio_err,"%-14s key is the next argument\n","-k");
BIO_printf(bio_err,"%-14s key is the first line of the file argument\n","-kfile");
BIO_printf(bio_err,"%-14s key/iv in hex is the next argument\n","-K/-iv");
BIO_printf(bio_err,"%-14s print the iv/key (then exit if -P)\n","-[pP]");
BIO_printf(bio_err,"%-14s buffer size\n","-bufsize <n>");
BIO_printf(bio_err,"%-14s use engine e, possibly a hardware device.\n","-engine e");
BIO_printf(bio_err,"Cipher Types\n");
OBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH,
show_ciphers,
bio_err);
BIO_printf(bio_err,"\n");
goto end;
}
argc--;
argv++;
}
e = setup_engine(bio_err, engine, 0);
if (bufsize != NULL)
{
unsigned long n;
for (n=0; *bufsize; bufsize++)
{
i= *bufsize;
if ((i <= '9') && (i >= '0'))
n=n*10+i-'0';
else if (i == 'k')
{
n*=1024;
bufsize++;
break;
}
}
if (*bufsize != '\0')
{
BIO_printf(bio_err,"invalid 'bufsize' specified.\n");
goto end;
}
if (n < 80) n=80;
bsize=(int)n;
if (verbose) BIO_printf(bio_err,"bufsize=%d\n",bsize);
}
strbuf=OPENSSL_malloc(SIZE);
buff=(unsigned char *)OPENSSL_malloc(EVP_ENCODE_LENGTH(bsize));
if ((buff == NULL) || (strbuf == NULL))
{
BIO_printf(bio_err,"OPENSSL_malloc failure %ld\n",(long)EVP_ENCODE_LENGTH(bsize));
goto end;
}
in=BIO_new(BIO_s_file());
out=BIO_new(BIO_s_file());
if ((in == NULL) || (out == NULL))
{
ERR_print_errors(bio_err);
goto end;
}
if (debug)
{
BIO_set_callback(in,BIO_debug_callback);
BIO_set_callback(out,BIO_debug_callback);
BIO_set_callback_arg(in,bio_err);
BIO_set_callback_arg(out,bio_err);
}
if (inf == NULL)
BIO_set_fp(in,stdin,BIO_NOCLOSE);
else
{
if (BIO_read_filename(in,inf) <= 0)
{
perror(inf);
goto end;
}
}
if(!str && passarg) {
if(!app_passwd(bio_err, passarg, NULL, &pass, NULL)) {
BIO_printf(bio_err, "Error getting password\n");
goto end;
}
str = pass;
}
if ((str == NULL) && (cipher != NULL) && (hkey == NULL))
{
for (;;)
{
char buf[200];
sprintf(buf,"enter %s %s password:",
OBJ_nid2ln(EVP_CIPHER_nid(cipher)),
(enc)?"encryption":"decryption");
strbuf[0]='\0';
i=EVP_read_pw_string((char *)strbuf,SIZE,buf,enc);
if (i == 0)
{
if (strbuf[0] == '\0')
{
ret=1;
goto end;
}
str=strbuf;
break;
}
if (i < 0)
{
BIO_printf(bio_err,"bad password read\n");
goto end;
}
}
}
if (outf == NULL)
{
BIO_set_fp(out,stdout,BIO_NOCLOSE);
#ifdef OPENSSL_SYS_VMS
{
BIO *tmpbio = BIO_new(BIO_f_linebuffer());
out = BIO_push(tmpbio, out);
}
#endif
}
else
{
if (BIO_write_filename(out,outf) <= 0)
{
perror(outf);
goto end;
}
}
rbio=in;
wbio=out;
if (base64)
{
if ((b64=BIO_new(BIO_f_base64())) == NULL)
goto end;
if (debug)
{
BIO_set_callback(b64,BIO_debug_callback);
BIO_set_callback_arg(b64,bio_err);
}
if (olb64)
BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
if (enc)
wbio=BIO_push(b64,wbio);
else
rbio=BIO_push(b64,rbio);
}
if (cipher != NULL)
{
if (str != NULL)
{
unsigned char *sptr;
if(nosalt) sptr = NULL;
else {
if(enc) {
if(hsalt) {
if(!set_hex(hsalt,salt,sizeof salt)) {
BIO_printf(bio_err,
"invalid hex salt value\n");
goto end;
}
} else if (RAND_pseudo_bytes(salt, sizeof salt) < 0)
goto end;
if((printkey != 2)
&& (BIO_write(wbio,magic,
sizeof magic-1) != sizeof magic-1
|| BIO_write(wbio,
(char *)salt,
sizeof salt) != sizeof salt)) {
BIO_printf(bio_err,"error writing output file\n");
goto end;
}
} else if(BIO_read(rbio,mbuf,sizeof mbuf) != sizeof mbuf
|| BIO_read(rbio,
(unsigned char *)salt,
sizeof salt) != sizeof salt) {
BIO_printf(bio_err,"error reading input file\n");
goto end;
} else if(memcmp(mbuf,magic,sizeof magic-1)) {
BIO_printf(bio_err,"bad magic number\n");
goto end;
}
sptr = salt;
}
EVP_BytesToKey(cipher,EVP_md5(),sptr,
(unsigned char *)str,
strlen(str),1,key,iv);
if (str == strbuf)
memset(str,0,SIZE);
else
memset(str,0,strlen(str));
}
if ((hiv != NULL) && !set_hex(hiv,iv,sizeof iv))
{
BIO_printf(bio_err,"invalid hex iv value\n");
goto end;
}
if ((hiv == NULL) && (str == NULL))
{
BIO_printf(bio_err, "iv undefined\n");
goto end;
}
if ((hkey != NULL) && !set_hex(hkey,key,sizeof key))
{
BIO_printf(bio_err,"invalid hex key value\n");
goto end;
}
if ((benc=BIO_new(BIO_f_cipher())) == NULL)
goto end;
BIO_set_cipher(benc,cipher,key,iv,enc);
if (nopad)
{
EVP_CIPHER_CTX *ctx;
BIO_get_cipher_ctx(benc, &ctx);
EVP_CIPHER_CTX_set_padding(ctx, 0);
}
if (debug)
{
BIO_set_callback(benc,BIO_debug_callback);
BIO_set_callback_arg(benc,bio_err);
}
if (printkey)
{
if (!nosalt)
{
printf("salt=");
for (i=0; i<sizeof salt; i++)
printf("%02X",salt[i]);
printf("\n");
}
if (cipher->key_len > 0)
{
printf("key=");
for (i=0; i<cipher->key_len; i++)
printf("%02X",key[i]);
printf("\n");
}
if (cipher->iv_len > 0)
{
printf("iv =");
for (i=0; i<cipher->iv_len; i++)
printf("%02X",iv[i]);
printf("\n");
}
if (printkey == 2)
{
ret=0;
goto end;
}
}
}
if (benc != NULL)
wbio=BIO_push(benc,wbio);
for (;;)
{
inl=BIO_read(rbio,(char *)buff,bsize);
if (inl <= 0) break;
if (BIO_write(wbio,(char *)buff,inl) != inl)
{
BIO_printf(bio_err,"error writing output file\n");
goto end;
}
}
if (!BIO_flush(wbio))
{
BIO_printf(bio_err,"bad decrypt\n");
goto end;
}
ret=0;
if (verbose)
{
BIO_printf(bio_err,"bytes read :%8ld\n",BIO_number_read(in));
BIO_printf(bio_err,"bytes written:%8ld\n",BIO_number_written(out));
}
end:
ERR_print_errors(bio_err);
if (strbuf != NULL) OPENSSL_free(strbuf);
if (buff != NULL) OPENSSL_free(buff);
if (in != NULL) BIO_free(in);
if (out != NULL) BIO_free_all(out);
if (benc != NULL) BIO_free(benc);
if (b64 != NULL) BIO_free(b64);
if(pass) OPENSSL_free(pass);
apps_shutdown();
EXIT(ret);
} | ['int MAIN(int argc, char **argv)\n\t{\n\tENGINE *e = NULL;\n\tstatic const char magic[]="Salted__";\n\tchar mbuf[sizeof magic-1];\n\tchar *strbuf=NULL;\n\tunsigned char *buff=NULL,*bufsize=NULL;\n\tint bsize=BSIZE,verbose=0;\n\tint ret=1,inl;\n\tint nopad = 0;\n\tunsigned char key[EVP_MAX_KEY_LENGTH],iv[EVP_MAX_IV_LENGTH];\n\tunsigned char salt[PKCS5_SALT_LEN];\n\tchar *str=NULL, *passarg = NULL, *pass = NULL;\n\tchar *hkey=NULL,*hiv=NULL,*hsalt = NULL;\n\tint enc=1,printkey=0,i,base64=0;\n\tint debug=0,olb64=0,nosalt=0;\n\tconst EVP_CIPHER *cipher=NULL,*c;\n\tchar *inf=NULL,*outf=NULL;\n\tBIO *in=NULL,*out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL;\n#define PROG_NAME_SIZE 39\n\tchar pname[PROG_NAME_SIZE+1];\n\tchar *engine = NULL;\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\tprogram_name(argv[0],pname,sizeof pname);\n\tif (strcmp(pname,"base64") == 0)\n\t\tbase64=1;\n\tcipher=EVP_get_cipherbyname(pname);\n\tif (!base64 && (cipher == NULL) && (strcmp(pname,"enc") != 0))\n\t\t{\n\t\tBIO_printf(bio_err,"%s is an unknown cipher\\n",pname);\n\t\tgoto bad;\n\t\t}\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif\t(strcmp(*argv,"-e") == 0)\n\t\t\tenc=1;\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinf= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutf= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-pass") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpassarg= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tengine= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-d") == 0)\n\t\t\tenc=0;\n\t\telse if\t(strcmp(*argv,"-p") == 0)\n\t\t\tprintkey=1;\n\t\telse if\t(strcmp(*argv,"-v") == 0)\n\t\t\tverbose=1;\n\t\telse if\t(strcmp(*argv,"-nopad") == 0)\n\t\t\tnopad=1;\n\t\telse if\t(strcmp(*argv,"-salt") == 0)\n\t\t\tnosalt=0;\n\t\telse if\t(strcmp(*argv,"-nosalt") == 0)\n\t\t\tnosalt=1;\n\t\telse if\t(strcmp(*argv,"-debug") == 0)\n\t\t\tdebug=1;\n\t\telse if\t(strcmp(*argv,"-P") == 0)\n\t\t\tprintkey=2;\n\t\telse if\t(strcmp(*argv,"-A") == 0)\n\t\t\tolb64=1;\n\t\telse if\t(strcmp(*argv,"-a") == 0)\n\t\t\tbase64=1;\n\t\telse if\t(strcmp(*argv,"-base64") == 0)\n\t\t\tbase64=1;\n\t\telse if (strcmp(*argv,"-bufsize") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tbufsize=(unsigned char *)*(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-k") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tstr= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-kfile") == 0)\n\t\t\t{\n\t\t\tstatic char buf[128];\n\t\t\tFILE *infile;\n\t\t\tchar *file;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tfile= *(++argv);\n\t\t\tinfile=fopen(file,"r");\n\t\t\tif (infile == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"unable to read key from \'%s\'\\n",\n\t\t\t\t\tfile);\n\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\tbuf[0]=\'\\0\';\n\t\t\tfgets(buf,sizeof buf,infile);\n\t\t\tfclose(infile);\n\t\t\ti=strlen(buf);\n\t\t\tif ((i > 0) &&\n\t\t\t\t((buf[i-1] == \'\\n\') || (buf[i-1] == \'\\r\')))\n\t\t\t\tbuf[--i]=\'\\0\';\n\t\t\tif ((i > 0) &&\n\t\t\t\t((buf[i-1] == \'\\n\') || (buf[i-1] == \'\\r\')))\n\t\t\t\tbuf[--i]=\'\\0\';\n\t\t\tif (i < 1)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"zero length password\\n");\n\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\tstr=buf;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-K") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\thkey= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-S") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\thsalt= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-iv") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\thiv= *(++argv);\n\t\t\t}\n\t\telse if\t((argv[0][0] == \'-\') &&\n\t\t\t((c=EVP_get_cipherbyname(&(argv[0][1]))) != NULL))\n\t\t\t{\n\t\t\tcipher=c;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-none") == 0)\n\t\t\tcipher=NULL;\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option \'%s\'\\n",*argv);\nbad:\n\t\t\tBIO_printf(bio_err,"options are\\n");\n\t\t\tBIO_printf(bio_err,"%-14s input file\\n","-in <file>");\n\t\t\tBIO_printf(bio_err,"%-14s output file\\n","-out <file>");\n\t\t\tBIO_printf(bio_err,"%-14s pass phrase source\\n","-pass <arg>");\n\t\t\tBIO_printf(bio_err,"%-14s encrypt\\n","-e");\n\t\t\tBIO_printf(bio_err,"%-14s decrypt\\n","-d");\n\t\t\tBIO_printf(bio_err,"%-14s base64 encode/decode, depending on encryption flag\\n","-a/-base64");\n\t\t\tBIO_printf(bio_err,"%-14s key is the next argument\\n","-k");\n\t\t\tBIO_printf(bio_err,"%-14s key is the first line of the file argument\\n","-kfile");\n\t\t\tBIO_printf(bio_err,"%-14s key/iv in hex is the next argument\\n","-K/-iv");\n\t\t\tBIO_printf(bio_err,"%-14s print the iv/key (then exit if -P)\\n","-[pP]");\n\t\t\tBIO_printf(bio_err,"%-14s buffer size\\n","-bufsize <n>");\n\t\t\tBIO_printf(bio_err,"%-14s use engine e, possibly a hardware device.\\n","-engine e");\n\t\t\tBIO_printf(bio_err,"Cipher Types\\n");\n\t\t\tOBJ_NAME_do_all_sorted(OBJ_NAME_TYPE_CIPHER_METH,\n\t\t\t\t\t show_ciphers,\n\t\t\t\t\t bio_err);\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n e = setup_engine(bio_err, engine, 0);\n\tif (bufsize != NULL)\n\t\t{\n\t\tunsigned long n;\n\t\tfor (n=0; *bufsize; bufsize++)\n\t\t\t{\n\t\t\ti= *bufsize;\n\t\t\tif ((i <= \'9\') && (i >= \'0\'))\n\t\t\t\tn=n*10+i-\'0\';\n\t\t\telse if (i == \'k\')\n\t\t\t\t{\n\t\t\t\tn*=1024;\n\t\t\t\tbufsize++;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (*bufsize != \'\\0\')\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"invalid \'bufsize\' specified.\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (n < 80) n=80;\n\t\tbsize=(int)n;\n\t\tif (verbose) BIO_printf(bio_err,"bufsize=%d\\n",bsize);\n\t\t}\n\tstrbuf=OPENSSL_malloc(SIZE);\n\tbuff=(unsigned char *)OPENSSL_malloc(EVP_ENCODE_LENGTH(bsize));\n\tif ((buff == NULL) || (strbuf == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"OPENSSL_malloc failure %ld\\n",(long)EVP_ENCODE_LENGTH(bsize));\n\t\tgoto end;\n\t\t}\n\tin=BIO_new(BIO_s_file());\n\tout=BIO_new(BIO_s_file());\n\tif ((in == NULL) || (out == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (debug)\n\t\t{\n\t\tBIO_set_callback(in,BIO_debug_callback);\n\t\tBIO_set_callback(out,BIO_debug_callback);\n\t\tBIO_set_callback_arg(in,bio_err);\n\t\tBIO_set_callback_arg(out,bio_err);\n\t\t}\n\tif (inf == NULL)\n\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE);\n\telse\n\t\t{\n\t\tif (BIO_read_filename(in,inf) <= 0)\n\t\t\t{\n\t\t\tperror(inf);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif(!str && passarg) {\n\t\tif(!app_passwd(bio_err, passarg, NULL, &pass, NULL)) {\n\t\t\tBIO_printf(bio_err, "Error getting password\\n");\n\t\t\tgoto end;\n\t\t}\n\t\tstr = pass;\n\t}\n\tif ((str == NULL) && (cipher != NULL) && (hkey == NULL))\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\tchar buf[200];\n\t\t\tsprintf(buf,"enter %s %s password:",\n\t\t\t\tOBJ_nid2ln(EVP_CIPHER_nid(cipher)),\n\t\t\t\t(enc)?"encryption":"decryption");\n\t\t\tstrbuf[0]=\'\\0\';\n\t\t\ti=EVP_read_pw_string((char *)strbuf,SIZE,buf,enc);\n\t\t\tif (i == 0)\n\t\t\t\t{\n\t\t\t\tif (strbuf[0] == \'\\0\')\n\t\t\t\t\t{\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tstr=strbuf;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (i < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"bad password read\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (outf == NULL)\n\t\t{\n\t\tBIO_set_fp(out,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\t}\n\telse\n\t\t{\n\t\tif (BIO_write_filename(out,outf) <= 0)\n\t\t\t{\n\t\t\tperror(outf);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\trbio=in;\n\twbio=out;\n\tif (base64)\n\t\t{\n\t\tif ((b64=BIO_new(BIO_f_base64())) == NULL)\n\t\t\tgoto end;\n\t\tif (debug)\n\t\t\t{\n\t\t\tBIO_set_callback(b64,BIO_debug_callback);\n\t\t\tBIO_set_callback_arg(b64,bio_err);\n\t\t\t}\n\t\tif (olb64)\n\t\t\tBIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);\n\t\tif (enc)\n\t\t\twbio=BIO_push(b64,wbio);\n\t\telse\n\t\t\trbio=BIO_push(b64,rbio);\n\t\t}\n\tif (cipher != NULL)\n\t\t{\n\t\tif (str != NULL)\n\t\t\t{\n\t\t\tunsigned char *sptr;\n\t\t\tif(nosalt) sptr = NULL;\n\t\t\telse {\n\t\t\t\tif(enc) {\n\t\t\t\t\tif(hsalt) {\n\t\t\t\t\t\tif(!set_hex(hsalt,salt,sizeof salt)) {\n\t\t\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t\t\t"invalid hex salt value\\n");\n\t\t\t\t\t\t\tgoto end;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (RAND_pseudo_bytes(salt, sizeof salt) < 0)\n\t\t\t\t\t\tgoto end;\n\t\t\t\t\tif((printkey != 2)\n\t\t\t\t\t && (BIO_write(wbio,magic,\n\t\t\t\t\t\t\t sizeof magic-1) != sizeof magic-1\n\t\t\t\t\t || BIO_write(wbio,\n\t\t\t\t\t\t\t (char *)salt,\n\t\t\t\t\t\t\t sizeof salt) != sizeof salt)) {\n\t\t\t\t\t\tBIO_printf(bio_err,"error writing output file\\n");\n\t\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\t} else if(BIO_read(rbio,mbuf,sizeof mbuf) != sizeof mbuf\n\t\t\t\t\t || BIO_read(rbio,\n\t\t\t\t\t\t (unsigned char *)salt,\n\t\t\t\t sizeof salt) != sizeof salt) {\n\t\t\t\t\tBIO_printf(bio_err,"error reading input file\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t} else if(memcmp(mbuf,magic,sizeof magic-1)) {\n\t\t\t\t BIO_printf(bio_err,"bad magic number\\n");\n\t\t\t\t goto end;\n\t\t\t\t}\n\t\t\t\tsptr = salt;\n\t\t\t}\n\t\t\tEVP_BytesToKey(cipher,EVP_md5(),sptr,\n\t\t\t\t(unsigned char *)str,\n\t\t\t\tstrlen(str),1,key,iv);\n\t\t\tif (str == strbuf)\n\t\t\t\tmemset(str,0,SIZE);\n\t\t\telse\n\t\t\t\tmemset(str,0,strlen(str));\n\t\t\t}\n\t\tif ((hiv != NULL) && !set_hex(hiv,iv,sizeof iv))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"invalid hex iv value\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((hiv == NULL) && (str == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "iv undefined\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((hkey != NULL) && !set_hex(hkey,key,sizeof key))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"invalid hex key value\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((benc=BIO_new(BIO_f_cipher())) == NULL)\n\t\t\tgoto end;\n\t\tBIO_set_cipher(benc,cipher,key,iv,enc);\n\t\tif (nopad)\n\t\t\t{\n\t\t\tEVP_CIPHER_CTX *ctx;\n\t\t\tBIO_get_cipher_ctx(benc, &ctx);\n\t\t\tEVP_CIPHER_CTX_set_padding(ctx, 0);\n\t\t\t}\n\t\tif (debug)\n\t\t\t{\n\t\t\tBIO_set_callback(benc,BIO_debug_callback);\n\t\t\tBIO_set_callback_arg(benc,bio_err);\n\t\t\t}\n\t\tif (printkey)\n\t\t\t{\n\t\t\tif (!nosalt)\n\t\t\t\t{\n\t\t\t\tprintf("salt=");\n\t\t\t\tfor (i=0; i<sizeof salt; i++)\n\t\t\t\t\tprintf("%02X",salt[i]);\n\t\t\t\tprintf("\\n");\n\t\t\t\t}\n\t\t\tif (cipher->key_len > 0)\n\t\t\t\t{\n\t\t\t\tprintf("key=");\n\t\t\t\tfor (i=0; i<cipher->key_len; i++)\n\t\t\t\t\tprintf("%02X",key[i]);\n\t\t\t\tprintf("\\n");\n\t\t\t\t}\n\t\t\tif (cipher->iv_len > 0)\n\t\t\t\t{\n\t\t\t\tprintf("iv =");\n\t\t\t\tfor (i=0; i<cipher->iv_len; i++)\n\t\t\t\t\tprintf("%02X",iv[i]);\n\t\t\t\tprintf("\\n");\n\t\t\t\t}\n\t\t\tif (printkey == 2)\n\t\t\t\t{\n\t\t\t\tret=0;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (benc != NULL)\n\t\twbio=BIO_push(benc,wbio);\n\tfor (;;)\n\t\t{\n\t\tinl=BIO_read(rbio,(char *)buff,bsize);\n\t\tif (inl <= 0) break;\n\t\tif (BIO_write(wbio,(char *)buff,inl) != inl)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"error writing output file\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!BIO_flush(wbio))\n\t\t{\n\t\tBIO_printf(bio_err,"bad decrypt\\n");\n\t\tgoto end;\n\t\t}\n\tret=0;\n\tif (verbose)\n\t\t{\n\t\tBIO_printf(bio_err,"bytes read :%8ld\\n",BIO_number_read(in));\n\t\tBIO_printf(bio_err,"bytes written:%8ld\\n",BIO_number_written(out));\n\t\t}\nend:\n\tERR_print_errors(bio_err);\n\tif (strbuf != NULL) OPENSSL_free(strbuf);\n\tif (buff != NULL) OPENSSL_free(buff);\n\tif (in != NULL) BIO_free(in);\n\tif (out != NULL) BIO_free_all(out);\n\tif (benc != NULL) BIO_free(benc);\n\tif (b64 != NULL) BIO_free(b64);\n\tif(pass) OPENSSL_free(pass);\n\tapps_shutdown();\n\tEXIT(ret);\n\t}'] |
33,092 | 0 | https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/sha/sha1dgst.c/#L244 | void SHA1_Update(SHA_CTX *c, const register unsigned char *data,
unsigned long len)
{
register SHA_LONG *p;
int ew,ec,sw,sc;
SHA_LONG l;
if (len == 0) return;
l=(c->Nl+(len<<3))&0xffffffffL;
if (l < c->Nl)
c->Nh++;
c->Nh+=(len>>29);
c->Nl=l;
if (c->num != 0)
{
p=c->data;
sw=c->num>>2;
sc=c->num&0x03;
if ((c->num+len) >= SHA_CBLOCK)
{
l= p[sw];
M_p_c2nl(data,l,sc);
p[sw++]=l;
for (; sw<SHA_LBLOCK; sw++)
{
M_c2nl(data,l);
p[sw]=l;
}
len-=(SHA_CBLOCK-c->num);
sha1_block(c,p,64);
c->num=0;
}
else
{
c->num+=(int)len;
if ((sc+len) < 4)
{
l= p[sw];
M_p_c2nl_p(data,l,sc,len);
p[sw]=l;
}
else
{
ew=(c->num>>2);
ec=(c->num&0x03);
l= p[sw];
M_p_c2nl(data,l,sc);
p[sw++]=l;
for (; sw < ew; sw++)
{ M_c2nl(data,l); p[sw]=l; }
if (ec)
{
M_c2nl_p(data,l,ec);
p[sw]=l;
}
}
return;
}
}
#if 1
#if defined(B_ENDIAN) || defined(SHA1_ASM)
if ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)
{
sw=len/SHA_CBLOCK;
if (sw)
{
sw*=SHA_CBLOCK;
sha1_block(c,(SHA_LONG *)data,sw);
data+=sw;
len-=sw;
}
}
#endif
#endif
p=c->data;
while (len >= SHA_CBLOCK)
{
#if defined(B_ENDIAN) || defined(L_ENDIAN)
if (p != (SHA_LONG *)data)
memcpy(p,data,SHA_CBLOCK);
data+=SHA_CBLOCK;
# ifdef L_ENDIAN
# ifndef SHA1_ASM
for (sw=(SHA_LBLOCK/4); sw; sw--)
{
Endian_Reverse32(p[0]);
Endian_Reverse32(p[1]);
Endian_Reverse32(p[2]);
Endian_Reverse32(p[3]);
p+=4;
}
p=c->data;
# endif
# endif
#else
for (sw=(SHA_BLOCK/4); sw; sw--)
{
M_c2nl(data,l); *(p++)=l;
M_c2nl(data,l); *(p++)=l;
M_c2nl(data,l); *(p++)=l;
M_c2nl(data,l); *(p++)=l;
}
p=c->data;
#endif
sha1_block(c,p,64);
len-=SHA_CBLOCK;
}
ec=(int)len;
c->num=ec;
ew=(ec>>2);
ec&=0x03;
for (sw=0; sw < ew; sw++)
{ M_c2nl(data,l); p[sw]=l; }
M_c2nl_p(data,l,ec);
p[sw]=l;
} | ['int MAIN(int argc, char **argv)\n\t{\n\tunsigned char *buf=NULL,*buf2=NULL;\n\tint ret=1;\n#define ALGOR_NUM\t14\n#define SIZE_NUM\t5\n#define RSA_NUM\t\t4\n#define DSA_NUM\t\t3\n\tlong count,rsa_count;\n\tint i,j,k,rsa_num,rsa_num2;\n#ifndef NO_MD2\n\tunsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef NO_MDC2\n\tunsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef NO_MD5\n\tunsigned char md5[MD5_DIGEST_LENGTH];\n\tunsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef NO_SHA\n\tunsigned char sha[SHA_DIGEST_LENGTH];\n#endif\n#ifndef NO_RIPEMD\n\tunsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef NO_RC4\n\tRC4_KEY rc4_ks;\n#endif\n#ifndef NO_RC5\n\tRC5_32_KEY rc5_ks;\n#endif\n#ifndef NO_RC2\n\tRC2_KEY rc2_ks;\n#endif\n#ifndef NO_IDEA\n\tIDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef NO_BF\n\tBF_KEY bf_ks;\n#endif\n#ifndef NO_CAST\n\tCAST_KEY cast_ks;\n#endif\n\tstatic unsigned char key16[16]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tunsigned char iv[8];\n#ifndef NO_DES\n\tstatic des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};\n\tstatic des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tdes_key_schedule sch,sch2,sch3;\n#endif\n#define\tD_MD2\t\t0\n#define\tD_MDC2\t\t1\n#define\tD_MD5\t\t2\n#define\tD_HMAC\t\t3\n#define\tD_SHA1\t\t4\n#define D_RMD160\t5\n#define\tD_RC4\t\t6\n#define\tD_CBC_DES\t7\n#define\tD_EDE3_DES\t8\n#define\tD_CBC_IDEA\t9\n#define\tD_CBC_RC2\t10\n#define\tD_CBC_RC5\t11\n#define\tD_CBC_BF\t12\n#define\tD_CBC_CAST\t13\n\tdouble d,results[ALGOR_NUM][SIZE_NUM];\n\tstatic int lengths[SIZE_NUM]={8,64,256,1024,8*1024};\n\tlong c[ALGOR_NUM][SIZE_NUM];\n\tstatic char *names[ALGOR_NUM]={\n\t\t"md2","mdc2","md5","hmac(md5)","sha1","rmd160","rc4",\n\t\t"des cbc","des ede3","idea cbc",\n\t\t"rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"};\n#define\tR_DSA_512\t0\n#define\tR_DSA_1024\t1\n#define\tR_DSA_2048\t2\n#define\tR_RSA_512\t0\n#define\tR_RSA_1024\t1\n#define\tR_RSA_2048\t2\n#define\tR_RSA_4096\t3\n#ifndef NO_RSA\n\tRSA *rsa_key[RSA_NUM];\n\tlong rsa_c[RSA_NUM][2];\n\tdouble rsa_results[RSA_NUM][2];\n\tstatic unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};\n\tstatic unsigned char *rsa_data[RSA_NUM]=\n\t\t{test512,test1024,test2048,test4096};\n\tstatic int rsa_data_length[RSA_NUM]={\n\t\tsizeof(test512),sizeof(test1024),\n\t\tsizeof(test2048),sizeof(test4096)};\n#endif\n#ifndef NO_DSA\n\tDSA *dsa_key[DSA_NUM];\n\tlong dsa_c[DSA_NUM][2];\n\tdouble dsa_results[DSA_NUM][2];\n\tstatic unsigned int dsa_bits[DSA_NUM]={512,1024,2048};\n#endif\n\tint rsa_doit[RSA_NUM];\n\tint dsa_doit[DSA_NUM];\n\tint doit[ALGOR_NUM];\n\tint pr_header=0;\n\tapps_startup();\n#ifndef NO_DSA\n\tmemset(dsa_key,0,sizeof(dsa_key));\n#endif\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#ifndef NO_RSA\n\tmemset(rsa_key,0,sizeof(rsa_key));\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_key[i]=NULL;\n#endif\n\tif ((buf=(unsigned char *)Malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tif ((buf2=(unsigned char *)Malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tmemset(c,0,sizeof(c));\n\tmemset(iv,0,sizeof(iv));\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tdoit[i]=0;\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_doit[i]=0;\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tdsa_doit[i]=0;\n\tj=0;\n\targc--;\n\targv++;\n\twhile (argc)\n\t\t{\n#ifndef NO_MD2\n\t\tif\t(strcmp(*argv,"md2") == 0) doit[D_MD2]=1;\n\t\telse\n#endif\n#ifndef NO_MDC2\n\t\t\tif (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;\n\t\telse\n#endif\n#ifndef NO_MD5\n\t\t\tif (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;\n\t\telse\n#endif\n#ifndef NO_MD5\n\t\t\tif (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;\n\t\telse\n#endif\n#ifndef NO_SHA\n\t\t\tif (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1;\n\t\telse\n#endif\n#ifndef NO_RIPEMD\n\t\t\tif (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;\n\t\telse\n#endif\n#ifndef NO_RC4\n\t\t\tif (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;\n\t\telse\n#endif\n#ifndef NO_DEF\n\t\t\tif (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;\n\t\telse\tif (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;\n\t\telse\n#endif\n#ifndef NO_RSA\n#ifdef RSAref\n\t\t\tif (strcmp(*argv,"rsaref") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_method(RSA_PKCS1_RSAref());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n\t\t\tif (strcmp(*argv,"openssl") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_method(RSA_PKCS1_SSLeay());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n\t\t if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;\n\t\telse if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;\n\t\telse if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;\n\t\telse if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;\n\t\telse if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;\n\t\telse\n#ifndef NO_RC2\n\t\t if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;\n\t\telse if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;\n\t\telse\n#endif\n#ifndef NO_RC5\n\t\t if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;\n\t\telse if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;\n\t\telse\n#endif\n#ifndef NO_IDEA\n\t\t if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;\n\t\telse if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;\n\t\telse\n#endif\n#ifndef NO_BF\n\t\t if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;\n\t\telse\n#endif\n#ifndef NO_CAST\n\t\t if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;\n\t\telse\n#endif\n#ifndef NO_DES\n\t\t\tif (strcmp(*argv,"des") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_DES]=1;\n\t\t\tdoit[D_EDE3_DES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef NO_RSA\n\t\t\tif (strcmp(*argv,"rsa") == 0)\n\t\t\t{\n\t\t\trsa_doit[R_RSA_512]=1;\n\t\t\trsa_doit[R_RSA_1024]=1;\n\t\t\trsa_doit[R_RSA_2048]=1;\n\t\t\trsa_doit[R_RSA_4096]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\tif (strcmp(*argv,"dsa") == 0)\n\t\t\t{\n\t\t\tdsa_doit[R_DSA_512]=1;\n\t\t\tdsa_doit[R_DSA_1024]=1;\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"bad value, pick one of\\n");\n\t\t\tBIO_printf(bio_err,"md2 mdc2\tmd5 hmac sha1 rmd160\\n");\n#ifndef NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea-cbc ");\n#endif\n#ifndef NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2-cbc ");\n#endif\n#ifndef NO_RC5\n\t\t\tBIO_printf(bio_err,"rc5-cbc ");\n#endif\n#ifndef NO_BF\n\t\t\tBIO_printf(bio_err,"bf-cbc");\n#endif\n#if !defined(NO_IDEA) && !defined(NO_RC2) && !defined(NO_BF) && !defined(NO_RC5)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"des-cbc des-ede3 ");\n#ifndef NO_RC4\n\t\t\tBIO_printf(bio_err,"rc4");\n#endif\n#ifndef NO_RSA\n\t\t\tBIO_printf(bio_err,"\\nrsa512 rsa1024 rsa2048 rsa4096\\n");\n#endif\n#ifndef NO_DSA\n\t\t\tBIO_printf(bio_err,"\\ndsa512 dsa1024 dsa2048\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"idea rc2 des rsa blowfish\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\tj++;\n\t\t}\n\tif (j == 0)\n\t\t{\n\t\tfor (i=0; i<ALGOR_NUM; i++)\n\t\t\tdoit[i]=1;\n\t\tfor (i=0; i<RSA_NUM; i++)\n\t\t\trsa_doit[i]=1;\n\t\tfor (i=0; i<DSA_NUM; i++)\n\t\t\tdsa_doit[i]=1;\n\t\t}\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tif (doit[i]) pr_header++;\n#ifndef TIMES\n\tBIO_printf(bio_err,"To get the most accurate results, try to run this\\n");\n\tBIO_printf(bio_err,"program when this computer is idle.\\n");\n#endif\n#ifndef NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\t{\n\t\tunsigned char *p;\n\t\tp=rsa_data[i];\n\t\trsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);\n\t\tif (rsa_key[i] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"internal error loading RSA key number %d\\n",i);\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Loaded RSA key, %d bit modulus and e= 0x",BN_num_bits(rsa_key[i]->n));\n\t\t\tBN_print(bio_err,rsa_key[i]->e);\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t}\n#endif\n\t\t}\n#endif\n#ifndef NO_DSA\n\tdsa_key[0]=get_dsa512();\n\tdsa_key[1]=get_dsa1024();\n\tdsa_key[2]=get_dsa2048();\n#endif\n#ifndef NO_DES\n\tdes_set_key(key,sch);\n\tdes_set_key(key2,sch2);\n\tdes_set_key(key3,sch3);\n#endif\n#ifndef NO_IDEA\n\tidea_set_encrypt_key(key16,&idea_ks);\n#endif\n#ifndef NO_RC4\n\tRC4_set_key(&rc4_ks,16,key16);\n#endif\n#ifndef NO_RC2\n\tRC2_set_key(&rc2_ks,16,key16,128);\n#endif\n#ifndef NO_RC5\n\tRC5_32_set_key(&rc5_ks,16,key16,12);\n#endif\n#ifndef NO_BF\n\tBF_set_key(&bf_ks,16,key16);\n#endif\n#ifndef NO_CAST\n\tCAST_set_key(&cast_ks,16,key16);\n#endif\n#ifndef NO_RSA\n\tmemset(rsa_c,0,sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n\tBIO_printf(bio_err,"First we calculate the approximate speed ...\\n");\n\tcount=10;\n\tdo\t{\n\t\tlong i;\n\t\tcount*=2;\n\t\tTime_F(START);\n\t\tfor (i=count; i; i--)\n\t\t\tdes_ecb_encrypt(buf,buf, &(sch[0]),DES_ENCRYPT);\n\t\td=Time_F(STOP);\n\t\t} while (d <3);\n\tc[D_MD2][0]=count/10;\n\tc[D_MDC2][0]=count/10;\n\tc[D_MD5][0]=count;\n\tc[D_HMAC][0]=count;\n\tc[D_SHA1][0]=count;\n\tc[D_RMD160][0]=count;\n\tc[D_RC4][0]=count*5;\n\tc[D_CBC_DES][0]=count;\n\tc[D_EDE3_DES][0]=count/3;\n\tc[D_CBC_IDEA][0]=count;\n\tc[D_CBC_RC2][0]=count;\n\tc[D_CBC_RC5][0]=count;\n\tc[D_CBC_BF][0]=count;\n\tc[D_CBC_CAST][0]=count;\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tc[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];\n\t\tc[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];\n\t\tc[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];\n\t\t}\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tlong l0,l1;\n\t\tl0=(long)lengths[i-1];\n\t\tl1=(long)lengths[i];\n\t\tc[D_RC4][i]=c[D_RC4][i-1]*l0/l1;\n\t\tc[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;\n\t\tc[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;\n\t\tc[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;\n\t\tc[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;\n\t\tc[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;\n\t\tc[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;\n\t\tc[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;\n\t\t}\n#ifndef NO_RSA\n\trsa_c[R_RSA_512][0]=count/2000;\n\trsa_c[R_RSA_512][1]=count/400;\n\tfor (i=1; i<RSA_NUM; i++)\n\t\t{\n\t\trsa_c[i][0]=rsa_c[i-1][0]/8;\n\t\trsa_c[i][1]=rsa_c[i-1][1]/4;\n\t\tif ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n\t\t\trsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (rsa_c[i][0] == 0)\n\t\t\t\t{\n\t\t\t\trsa_c[i][0]=1;\n\t\t\t\trsa_c[i][1]=20;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n\tdsa_c[R_DSA_512][0]=count/1000;\n\tdsa_c[R_DSA_512][1]=count/1000/2;\n\tfor (i=1; i<DSA_NUM; i++)\n\t\t{\n\t\tdsa_c[i][0]=dsa_c[i-1][0]/4;\n\t\tdsa_c[i][1]=dsa_c[i-1][1]/4;\n\t\tif ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n\t\t\tdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (dsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tdsa_c[i][0]=1;\n\t\t\t\tdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#define COND(d)\t(count < (d))\n#define COUNT(d) (d)\n#else\n#define COND(c)\t(run)\n#define COUNT(d) (count)\n\tsignal(SIGALRM,sig_done);\n#endif\n#ifndef NO_MD2\n\tif (doit[D_MD2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD2],c[D_MD2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD2][j]); count++)\n\t\t\t\tMD2(buf,(unsigned long)lengths[j],&(md2[0]));\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_MD2],d);\n\t\t\tresults[D_MD2][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_MDC2\n\tif (doit[D_MDC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MDC2][j]); count++)\n\t\t\t\tMDC2(buf,(unsigned long)lengths[j],&(mdc2[0]));\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_MDC2],d);\n\t\t\tresults[D_MDC2][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_MD5\n\tif (doit[D_MD5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD5],c[D_MD5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD5][j]); count++)\n\t\t\t\tMD5(&(buf[0]),(unsigned long)lengths[j],&(md5[0]));\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_MD5],d);\n\t\t\tresults[D_MD5][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_MD5\n\tif (doit[D_HMAC])\n\t\t{\n\t\tHMAC_CTX hctx;\n\t\tHMAC_Init(&hctx,(unsigned char *)"This is a key...",\n\t\t\t16,EVP_md5());\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_HMAC][j]); count++)\n\t\t\t\t{\n\t\t\t\tHMAC_Init(&hctx,NULL,0,NULL);\n HMAC_Update(&hctx,buf,lengths[j]);\n HMAC_Final(&hctx,&(hmac[0]),NULL);\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_HMAC],d);\n\t\t\tresults[D_HMAC][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_SHA\n\tif (doit[D_SHA1])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA1][j]); count++)\n\t\t\t\tSHA1(buf,(unsigned long)lengths[j],&(sha[0]));\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_SHA1],d);\n\t\t\tresults[D_SHA1][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_RIPEMD\n\tif (doit[D_RMD160])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RMD160][j]); count++)\n\t\t\t\tRIPEMD160(buf,(unsigned long)lengths[j],&(rmd160[0]));\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_RMD160],d);\n\t\t\tresults[D_RMD160][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_RC4\n\tif (doit[D_RC4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RC4],c[D_RC4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RC4][j]); count++)\n\t\t\t\tRC4(&rc4_ks,(unsigned int)lengths[j],\n\t\t\t\t\tbuf,buf);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_RC4],d);\n\t\t\tresults[D_RC4][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_DES\n\tif (doit[D_CBC_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_DES][j]); count++)\n\t\t\t\tdes_ncbc_encrypt(buf,buf,lengths[j],sch,\n\t\t\t\t\t\t &(iv[0]),DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_CBC_DES],d);\n\t\t\tresults[D_CBC_DES][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n\tif (doit[D_EDE3_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)\n\t\t\t\tdes_ede3_cbc_encrypt(buf,buf,lengths[j],\n\t\t\t\t\t\t sch,sch2,sch3,\n\t\t\t\t\t\t &(iv[0]),DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_EDE3_DES],d);\n\t\t\tresults[D_EDE3_DES][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_IDEA\n\tif (doit[D_CBC_IDEA])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)\n\t\t\t\tidea_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&idea_ks,\n\t\t\t\t\t(unsigned char *)&(iv[0]),IDEA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_CBC_IDEA],d);\n\t\t\tresults[D_CBC_IDEA][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_RC2\n\tif (doit[D_CBC_RC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)\n\t\t\t\tRC2_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc2_ks,\n\t\t\t\t\t(unsigned char *)&(iv[0]),RC2_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_CBC_RC2],d);\n\t\t\tresults[D_CBC_RC2][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_RC5\n\tif (doit[D_CBC_RC5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)\n\t\t\t\tRC5_32_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc5_ks,\n\t\t\t\t\t(unsigned char *)&(iv[0]),RC5_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_CBC_RC5],d);\n\t\t\tresults[D_CBC_RC5][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_BF\n\tif (doit[D_CBC_BF])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_BF][j]); count++)\n\t\t\t\tBF_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&bf_ks,\n\t\t\t\t\t(unsigned char *)&(iv[0]),BF_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_CBC_BF],d);\n\t\t\tresults[D_CBC_BF][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n#ifndef NO_CAST\n\tif (doit[D_CBC_CAST])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)\n\t\t\t\tCAST_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&cast_ks,\n\t\t\t\t\t(unsigned char *)&(iv[0]),CAST_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,"%ld %s\'s in %.2fs\\n",\n\t\t\t\tcount,names[D_CBC_CAST],d);\n\t\t\tresults[D_CBC_CAST][j]=((double)count)/d*lengths[j];\n\t\t\t}\n\t\t}\n#endif\n\tRAND_bytes(buf,30);\n#ifndef NO_RSA\n\tfor (j=0; j<RSA_NUM; j++)\n\t\t{\n\t\tif (!rsa_doit[j]) continue;\n\t\trsa_num=RSA_private_encrypt(30,buf,buf2,rsa_key[j],\n\t\t\tRSA_PKCS1_PADDING);\n\t\tpkey_print_message("private","rsa",rsa_c[j][0],rsa_bits[j],\n\t\t\tRSA_SECONDS);\n\t\tTime_F(START);\n\t\tfor (count=0,run=1; COND(rsa_c[j][0]); count++)\n\t\t\t{\n\t\t\trsa_num=RSA_private_encrypt(30,buf,buf2,rsa_key[j],\n\t\t\t\tRSA_PKCS1_PADDING);\n\t\t\tif (rsa_num <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"RSA private encrypt failure\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tcount=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\td=Time_F(STOP);\n\t\tBIO_printf(bio_err,"%ld %d bit private RSA\'s in %.2fs\\n",\n\t\t\tcount,rsa_bits[j],d);\n\t\trsa_results[j][0]=d/(double)count;\n\t\trsa_count=count;\n#if 1\n\t\trsa_num2=RSA_public_decrypt(rsa_num,buf2,buf,rsa_key[j],\n\t\t\tRSA_PKCS1_PADDING);\n\t\tpkey_print_message("public","rsa",rsa_c[j][1],rsa_bits[j],\n\t\t\tRSA_SECONDS);\n\t\tTime_F(START);\n\t\tfor (count=0,run=1; COND(rsa_c[j][1]); count++)\n\t\t\t{\n\t\t\trsa_num2=RSA_public_decrypt(rsa_num,buf2,buf,rsa_key[j],\n\t\t\t\tRSA_PKCS1_PADDING);\n\t\t\tif (rsa_num2 <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"RSA public encrypt failure\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tcount=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\td=Time_F(STOP);\n\t\tBIO_printf(bio_err,"%ld %d bit public RSA\'s in %.2fs\\n",\n\t\t\tcount,rsa_bits[j],d);\n\t\trsa_results[j][1]=d/(double)count;\n#endif\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<RSA_NUM; j++)\n\t\t\t\trsa_doit[j]=0;\n\t\t\t}\n\t\t}\n#endif\n\tRAND_bytes(buf,20);\n#ifndef NO_DSA\n\tfor (j=0; j<DSA_NUM; j++)\n\t\t{\n\t\tunsigned int kk;\n\t\tif (!dsa_doit[j]) continue;\n\t\tDSA_generate_key(dsa_key[j]);\n\t\trsa_num=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t&kk,dsa_key[j]);\n\t\tpkey_print_message("sign","dsa",dsa_c[j][0],dsa_bits[j],\n\t\t\tDSA_SECONDS);\n\t\tTime_F(START);\n\t\tfor (count=0,run=1; COND(dsa_c[j][0]); count++)\n\t\t\t{\n\t\t\trsa_num=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t&kk,dsa_key[j]);\n\t\t\tif (rsa_num <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"DSA sign failure\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tcount=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\td=Time_F(STOP);\n\t\tBIO_printf(bio_err,"%ld %d bit DSA signs in %.2fs\\n",\n\t\t\tcount,dsa_bits[j],d);\n\t\tdsa_results[j][0]=d/(double)count;\n\t\trsa_count=count;\n\t\trsa_num2=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\tkk,dsa_key[j]);\n\t\tpkey_print_message("verify","dsa",dsa_c[j][1],dsa_bits[j],\n\t\t\tDSA_SECONDS);\n\t\tTime_F(START);\n\t\tfor (count=0,run=1; COND(dsa_c[j][1]); count++)\n\t\t\t{\n\t\t\trsa_num2=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\tkk,dsa_key[j]);\n\t\t\tif (rsa_num2 <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"DSA verify failure\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tcount=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\td=Time_F(STOP);\n\t\tBIO_printf(bio_err,"%ld %d bit DSA verify in %.2fs\\n",\n\t\t\tcount,dsa_bits[j],d);\n\t\tdsa_results[j][1]=d/(double)count;\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<DSA_NUM; j++)\n\t\t\t\tdsa_doit[j]=0;\n\t\t\t}\n\t\t}\n#endif\n\tfprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_BUILT_ON));\n\tprintf("options:");\n\tprintf("%s ",BN_options());\n#ifndef NO_MD2\n\tprintf("%s ",MD2_options());\n#endif\n#ifndef NO_RC4\n\tprintf("%s ",RC4_options());\n#endif\n#ifndef NO_DES\n\tprintf("%s ",des_options());\n#endif\n#ifndef NO_IDEA\n\tprintf("%s ",idea_options());\n#endif\n#ifndef NO_BF\n\tprintf("%s ",BF_options());\n#endif\n\tfprintf(stdout,"\\n%s\\n",SSLeay_version(SSLEAY_CFLAGS));\n\tif (pr_header)\n\t\t{\n\t\tfprintf(stdout,"The \'numbers\' are in 1000s of bytes per second processed.\\n");\n\t\tfprintf(stdout,"type ");\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\tfprintf(stdout,"%7d bytes",lengths[j]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tfor (k=0; k<ALGOR_NUM; k++)\n\t\t{\n\t\tif (!doit[k]) continue;\n\t\tfprintf(stdout,"%-13s",names[k]);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (results[k][j] > 10000)\n\t\t\t\tfprintf(stdout," %11.2fk",results[k][j]/1e3);\n\t\t\telse\n\t\t\t\tfprintf(stdout," %11.2f ",results[k][j]);\n\t\t\t}\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#ifndef NO_RSA\n\tj=1;\n\tfor (k=0; k<RSA_NUM; k++)\n\t\t{\n\t\tif (!rsa_doit[k]) continue;\n\t\tif (j)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tfprintf(stdout,"rsa %4d bits %8.4fs %8.4fs %8.1f %8.1f",\n\t\t\trsa_bits[k],rsa_results[k][0],rsa_results[k][1],\n\t\t\t1.0/rsa_results[k][0],1.0/rsa_results[k][1]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#endif\n#ifndef NO_DSA\n\tj=1;\n\tfor (k=0; k<DSA_NUM; k++)\n\t\t{\n\t\tif (!dsa_doit[k]) continue;\n\t\tif (j)\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tfprintf(stdout,"dsa %4d bits %8.4fs %8.4fs %8.1f %8.1f",\n\t\t\tdsa_bits[k],dsa_results[k][0],dsa_results[k][1],\n\t\t\t1.0/dsa_results[k][0],1.0/dsa_results[k][1]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#endif\n\tret=0;\nend:\n\tif (buf != NULL) Free(buf);\n\tif (buf2 != NULL) Free(buf2);\n#ifndef NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\tif (rsa_key[i] != NULL)\n\t\t\tRSA_free(rsa_key[i]);\n#endif\n#ifndef NO_DSA\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tif (dsa_key[i] != NULL)\n\t\t\tDSA_free(dsa_key[i]);\n#endif\n\tEXIT(ret);\n\t}', 'unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)\n\t{\n\tSHA_CTX c;\n\tstatic unsigned char m[SHA_DIGEST_LENGTH];\n\tif (md == NULL) md=m;\n\tSHA1_Init(&c);\n\tSHA1_Update(&c,d,n);\n\tSHA1_Final(md,&c);\n\tmemset(&c,0,sizeof(c));\n\treturn(md);\n\t}', 'void SHA1_Update(SHA_CTX *c, const register unsigned char *data,\n\t unsigned long len)\n\t{\n\tregister SHA_LONG *p;\n\tint ew,ec,sw,sc;\n\tSHA_LONG l;\n\tif (len == 0) return;\n\tl=(c->Nl+(len<<3))&0xffffffffL;\n\tif (l < c->Nl)\n\t\tc->Nh++;\n\tc->Nh+=(len>>29);\n\tc->Nl=l;\n\tif (c->num != 0)\n\t\t{\n\t\tp=c->data;\n\t\tsw=c->num>>2;\n\t\tsc=c->num&0x03;\n\t\tif ((c->num+len) >= SHA_CBLOCK)\n\t\t\t{\n\t\t\tl= p[sw];\n\t\t\tM_p_c2nl(data,l,sc);\n\t\t\tp[sw++]=l;\n\t\t\tfor (; sw<SHA_LBLOCK; sw++)\n\t\t\t\t{\n\t\t\t\tM_c2nl(data,l);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\tlen-=(SHA_CBLOCK-c->num);\n\t\t\tsha1_block(c,p,64);\n\t\t\tc->num=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tc->num+=(int)len;\n\t\t\tif ((sc+len) < 4)\n\t\t\t\t{\n\t\t\t\tl= p[sw];\n\t\t\t\tM_p_c2nl_p(data,l,sc,len);\n\t\t\t\tp[sw]=l;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tew=(c->num>>2);\n\t\t\t\tec=(c->num&0x03);\n\t\t\t\tl= p[sw];\n\t\t\t\tM_p_c2nl(data,l,sc);\n\t\t\t\tp[sw++]=l;\n\t\t\t\tfor (; sw < ew; sw++)\n\t\t\t\t\t{ M_c2nl(data,l); p[sw]=l; }\n\t\t\t\tif (ec)\n\t\t\t\t\t{\n\t\t\t\t\tM_c2nl_p(data,l,ec);\n\t\t\t\t\tp[sw]=l;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\treturn;\n\t\t\t}\n\t\t}\n#if 1\n#if defined(B_ENDIAN) || defined(SHA1_ASM)\n\tif ((((unsigned long)data)%sizeof(SHA_LONG)) == 0)\n\t\t{\n\t\tsw=len/SHA_CBLOCK;\n\t\tif (sw)\n\t\t\t{\n\t\t\tsw*=SHA_CBLOCK;\n\t\t\tsha1_block(c,(SHA_LONG *)data,sw);\n\t\t\tdata+=sw;\n\t\t\tlen-=sw;\n\t\t\t}\n\t\t}\n#endif\n#endif\n\tp=c->data;\n\twhile (len >= SHA_CBLOCK)\n\t\t{\n#if defined(B_ENDIAN) || defined(L_ENDIAN)\n\t\tif (p != (SHA_LONG *)data)\n\t\t\tmemcpy(p,data,SHA_CBLOCK);\n\t\tdata+=SHA_CBLOCK;\n# ifdef L_ENDIAN\n# ifndef SHA1_ASM\n\t\tfor (sw=(SHA_LBLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tEndian_Reverse32(p[0]);\n\t\t\tEndian_Reverse32(p[1]);\n\t\t\tEndian_Reverse32(p[2]);\n\t\t\tEndian_Reverse32(p[3]);\n\t\t\tp+=4;\n\t\t\t}\n\t\tp=c->data;\n# endif\n# endif\n#else\n\t\tfor (sw=(SHA_BLOCK/4); sw; sw--)\n\t\t\t{\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\tM_c2nl(data,l); *(p++)=l;\n\t\t\t}\n\t\tp=c->data;\n#endif\n\t\tsha1_block(c,p,64);\n\t\tlen-=SHA_CBLOCK;\n\t\t}\n\tec=(int)len;\n\tc->num=ec;\n\tew=(ec>>2);\n\tec&=0x03;\n\tfor (sw=0; sw < ew; sw++)\n\t\t{ M_c2nl(data,l); p[sw]=l; }\n\tM_c2nl_p(data,l,ec);\n\tp[sw]=l;\n\t}'] |
33,093 | 0 | https://github.com/openssl/openssl/blob/b59e1bed7da7933d4c6af750fe3f0300b57874fe/test/bntest.c/#L636 | int test_div_recp(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *b, *c, *d, *e;
BN_RECP_CTX *recp;
int i;
recp = BN_RECP_CTX_new();
a = BN_new();
b = BN_new();
c = BN_new();
d = BN_new();
e = BN_new();
for (i = 0; i < num0 + num1; i++) {
if (i < num1) {
BN_bntest_rand(a, 400, 0, 0);
BN_copy(b, a);
BN_lshift(a, a, i);
BN_add_word(a, i);
} else
BN_bntest_rand(b, 50 + 3 * (i - num1), 0, 0);
a->neg = rand_neg();
b->neg = rand_neg();
BN_RECP_CTX_set(recp, b, ctx);
BN_div_recp(d, c, a, recp, ctx);
if (bp != NULL) {
if (!results) {
BN_print(bp, a);
BIO_puts(bp, " / ");
BN_print(bp, b);
BIO_puts(bp, " - ");
}
BN_print(bp, d);
BIO_puts(bp, "\n");
if (!results) {
BN_print(bp, a);
BIO_puts(bp, " % ");
BN_print(bp, b);
BIO_puts(bp, " - ");
}
BN_print(bp, c);
BIO_puts(bp, "\n");
}
BN_mul(e, d, b, ctx);
BN_add(d, e, c);
BN_sub(d, d, a);
if (!BN_is_zero(d)) {
fprintf(stderr, "Reciprocal division test failed!\n");
fprintf(stderr, "a=");
BN_print_fp(stderr, a);
fprintf(stderr, "\nb=");
BN_print_fp(stderr, b);
fprintf(stderr, "\n");
return 0;
}
}
BN_free(a);
BN_free(b);
BN_free(c);
BN_free(d);
BN_free(e);
BN_RECP_CTX_free(recp);
return (1);
} | ['int test_div_recp(BIO *bp, BN_CTX *ctx)\n{\n BIGNUM *a, *b, *c, *d, *e;\n BN_RECP_CTX *recp;\n int i;\n recp = BN_RECP_CTX_new();\n a = BN_new();\n b = BN_new();\n c = BN_new();\n d = BN_new();\n e = BN_new();\n for (i = 0; i < num0 + num1; i++) {\n if (i < num1) {\n BN_bntest_rand(a, 400, 0, 0);\n BN_copy(b, a);\n BN_lshift(a, a, i);\n BN_add_word(a, i);\n } else\n BN_bntest_rand(b, 50 + 3 * (i - num1), 0, 0);\n a->neg = rand_neg();\n b->neg = rand_neg();\n BN_RECP_CTX_set(recp, b, ctx);\n BN_div_recp(d, c, a, recp, ctx);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " / ");\n BN_print(bp, b);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, d);\n BIO_puts(bp, "\\n");\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " % ");\n BN_print(bp, b);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, c);\n BIO_puts(bp, "\\n");\n }\n BN_mul(e, d, b, ctx);\n BN_add(d, e, c);\n BN_sub(d, d, a);\n if (!BN_is_zero(d)) {\n fprintf(stderr, "Reciprocal division test failed!\\n");\n fprintf(stderr, "a=");\n BN_print_fp(stderr, a);\n fprintf(stderr, "\\nb=");\n BN_print_fp(stderr, b);\n fprintf(stderr, "\\n");\n return 0;\n }\n }\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n BN_free(e);\n BN_RECP_CTX_free(recp);\n return (1);\n}', 'BN_RECP_CTX *BN_RECP_CTX_new(void)\n{\n BN_RECP_CTX *ret;\n if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)\n return (NULL);\n BN_RECP_CTX_init(ret);\n ret->flags = BN_FLG_MALLOCED;\n return (ret);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'void BN_RECP_CTX_init(BN_RECP_CTX *recp)\n{\n bn_init(&(recp->N));\n bn_init(&(recp->Nr));\n recp->num_bits = 0;\n recp->flags = 0;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void BN_free(BIGNUM *a)\n{\n if (a == NULL)\n return;\n bn_check_top(a);\n if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n bn_free_d(a);\n if (a->flags & BN_FLG_MALLOCED)\n OPENSSL_free(a);\n else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n a->flags |= BN_FLG_FREE;\n#endif\n a->d = NULL;\n }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n return b->flags & n;\n}'] |
33,094 | 0 | https://github.com/openssl/openssl/blob/16da72a824eddebb7d85297bea868be3a6f43c0e/crypto/mem.c/#L312 | void CRYPTO_free(void *str, const char *file, int line)
{
INCREMENT(free_count);
if (free_impl != NULL && free_impl != &CRYPTO_free) {
free_impl(str, file, line);
return;
}
#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)
if (call_malloc_debug) {
CRYPTO_mem_debug_free(str, 0, file, line);
free(str);
CRYPTO_mem_debug_free(str, 1, file, line);
} else {
free(str);
}
#else
free(str);
#endif
} | ['static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length)\n{\n ASN1_OCTET_STRING *os, **pos;\n pos = a;\n if (pos == NULL || *pos == NULL) {\n os = ASN1_OCTET_STRING_new();\n if (os == NULL)\n goto err;\n } else {\n os = *pos;\n }\n if (!ASN1_OCTET_STRING_set(os, *pp, length))\n goto err;\n *pp += length;\n if (pos)\n *pos = os;\n return os;\n err:\n if ((pos == NULL) || (*pos != os))\n ASN1_OCTET_STRING_free(os);\n OCSPerr(OCSP_F_D2I_OCSP_NONCE, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d,\n int len)\n{\n return ASN1_STRING_set(x, d, len);\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n unsigned char *c;\n const char *data = _data;\n if (len < 0) {\n if (data == NULL)\n return 0;\n else\n len = strlen(data);\n }\n if ((str->length <= len) || (str->data == NULL)) {\n c = str->data;\n str->data = OPENSSL_realloc(c, len + 1);\n if (str->data == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n str->data = c;\n return 0;\n }\n }\n str->length = len;\n if (data != NULL) {\n memcpy(str->data, data, len);\n str->data[len] = '\\0';\n }\n return 1;\n}", 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n INCREMENT(realloc_count);\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n FAILTEST();\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)(file); (void)(line);\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}'] |
33,095 | 0 | https://github.com/libav/libav/blob/2bd67175c7e16c1f5da15c9e55ae6db4ab1d23fd/libavcodec/huffyuv.c/#L400 | static int read_old_huffman_tables(HYuvContext *s)
{
#if 1
GetBitContext gb;
int i;
init_get_bits(&gb, classic_shift_luma,
classic_shift_luma_table_size * 8);
if (read_len_table(s->len[0], &gb) < 0)
return -1;
init_get_bits(&gb, classic_shift_chroma,
classic_shift_chroma_table_size * 8);
if (read_len_table(s->len[1], &gb) < 0)
return -1;
for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i];
for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i];
if (s->bitstream_bpp >= 24) {
memcpy(s->bits[1], s->bits[0], 256 * sizeof(uint32_t));
memcpy(s->len[1] , s->len [0], 256 * sizeof(uint8_t));
}
memcpy(s->bits[2], s->bits[1], 256 * sizeof(uint32_t));
memcpy(s->len[2] , s->len [1], 256 * sizeof(uint8_t));
for (i = 0; i < 3; i++) {
ff_free_vlc(&s->vlc[i]);
init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1,
s->bits[i], 4, 4, 0);
}
generate_joint_tables(s);
return 0;
#else
av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n");
return -1;
#endif
} | ['static int read_old_huffman_tables(HYuvContext *s)\n{\n#if 1\n GetBitContext gb;\n int i;\n init_get_bits(&gb, classic_shift_luma,\n classic_shift_luma_table_size * 8);\n if (read_len_table(s->len[0], &gb) < 0)\n return -1;\n init_get_bits(&gb, classic_shift_chroma,\n classic_shift_chroma_table_size * 8);\n if (read_len_table(s->len[1], &gb) < 0)\n return -1;\n for(i=0; i<256; i++) s->bits[0][i] = classic_add_luma [i];\n for(i=0; i<256; i++) s->bits[1][i] = classic_add_chroma[i];\n if (s->bitstream_bpp >= 24) {\n memcpy(s->bits[1], s->bits[0], 256 * sizeof(uint32_t));\n memcpy(s->len[1] , s->len [0], 256 * sizeof(uint8_t));\n }\n memcpy(s->bits[2], s->bits[1], 256 * sizeof(uint32_t));\n memcpy(s->len[2] , s->len [1], 256 * sizeof(uint8_t));\n for (i = 0; i < 3; i++) {\n ff_free_vlc(&s->vlc[i]);\n init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1,\n s->bits[i], 4, 4, 0);\n }\n generate_joint_tables(s);\n return 0;\n#else\n av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \\n");\n return -1;\n#endif\n}'] |
33,096 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250 | int BN_num_bits(const BIGNUM *a)
{
int i = a->top - 1;
bn_check_top(a);
if (BN_is_zero(a)) return 0;
return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
} | ['int ssl3_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long alg_k,Time=(unsigned long)time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tlong num1;\n\tint ret= -1;\n\tint new_state,state,skip=0;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tif (s->cert == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);\n\t\treturn(-1);\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch (s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_ACCEPT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_ACCEPT:\n\t\tcase SSL_ST_OK|SSL_ST_ACCEPT:\n\t\t\ts->server=1;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version>>8) != 3)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR);\n\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_ACCEPT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tif (s->state != SSL_ST_RENEGOTIATE)\n\t\t\t\t{\n\t\t\t\tif (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }\n\t\t\t\tssl3_init_finished_mac(s);\n\t\t\t\ts->state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\t\t\ts->ctx->stats.sess_accept++;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->ctx->stats.sess_accept_renegotiate++;\n\t\t\t\ts->state=SSL3_ST_SW_HELLO_REQ_A;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_A:\n\t\tcase SSL3_ST_SW_HELLO_REQ_B:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_send_hello_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_C:\n\t\t\ts->state=SSL_ST_OK;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CLNT_HELLO_A:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_B:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_C:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_get_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->new_session = 2;\n\t\t\ts->state=SSL3_ST_SW_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_HELLO_A:\n\t\tcase SSL3_ST_SW_SRVR_HELLO_B:\n\t\t\tret=ssl3_send_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\tif (s->hit)\n\t\t\t\t{\n\t\t\t\tif (s->tlsext_ticket_expected)\n\t\t\t\t\ts->state=SSL3_ST_SW_SESSION_TICKET_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\t\t}\n#else\n\t\t\tif (s->hit)\n\t\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n#endif\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CERT_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_A:\n\t\tcase SSL3_ST_SW_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL)\n\t\t\t\t&& !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)\n\t\t\t\t&& !(s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5))\n\t\t\t\t{\n\t\t\t\tret=ssl3_send_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\t\tif (s->tlsext_status_expected)\n\t\t\t\t\ts->state=SSL3_ST_SW_CERT_STATUS_A;\n\t\t\t\telse\n\t\t\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tskip = 1;\n\t\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\t\t}\n#else\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n#endif\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_KEY_EXCH_A:\n\t\tcase SSL3_ST_SW_KEY_EXCH_B:\n\t\t\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n#ifndef OPENSSL_NO_KRB5\n\t\t\t\t&& !(alg_k & SSL_kKRB5)\n#endif\n\t\t\t\t)\n\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\telse\n\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n\t\t\tif (s->s3->tmp.use_rsa_tmp\n#ifndef OPENSSL_NO_PSK\n\t\t\t || ((alg_k & SSL_kPSK) && s->ctx->psk_identity_hint)\n#endif\n\t\t\t || (alg_k & (SSL_kDHr|SSL_kDHd|SSL_kEDH))\n\t\t\t || (alg_k & SSL_kEECDH)\n\t\t\t || ((alg_k & SSL_kRSA)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL\n\t\t\t\t || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)\n\t\t\t\t\t&& EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t)\n\t\t\t )\n\t\t\t\t{\n\t\t\t\tret=ssl3_send_server_key_exchange(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_REQ_A:\n\t\tcase SSL3_ST_SW_CERT_REQ_B:\n\t\t\tif (\n\t\t\t\t!(s->verify_mode & SSL_VERIFY_PEER) ||\n\t\t\t\t((s->session->peer != NULL) &&\n\t\t\t\t (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||\n\t\t\t\t((s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&\n\t\t\t\t !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||\n\t\t\t\t(s->s3->tmp.new_cipher->algorithm_auth & SSL_aKRB5)\n\t\t\t\t|| (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))\n\t\t\t\t{\n\t\t\t\tskip=1;\n\t\t\t\ts->s3->tmp.cert_request=0;\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.cert_request=1;\n\t\t\t\tret=ssl3_send_certificate_request(s);\n\t\t\t\tif (ret <= 0) goto end;\n#ifndef NETSCAPE_HANG_BUG\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n#else\n\t\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n#endif\n\t\t\t\ts->init_num=0;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_DONE_A:\n\t\tcase SSL3_ST_SW_SRVR_DONE_B:\n\t\t\tret=ssl3_send_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_A:\n\t\tcase SSL3_ST_SR_CERT_B:\n\t\t\tret = ssl3_check_client_hello(s);\n\t\t\tif (ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif (ret == 2)\n\t\t\t\ts->state = SSL3_ST_SR_CLNT_HELLO_C;\n\t\t\telse {\n\t\t\t\tif (s->s3->tmp.cert_request)\n\t\t\t\t\t{\n\t\t\t\t\tret=ssl3_get_client_certificate(s);\n\t\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_num=0;\n\t\t\t\ts->state=SSL3_ST_SR_KEY_EXCH_A;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_KEY_EXCH_A:\n\t\tcase SSL3_ST_SR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_client_key_exchange(s);\n\t\t\tif (ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif (ret == 2)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\t\ts->init_num = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tint offset=0;\n\t\t\t\tint dgst_num;\n\t\t\t\ts->state=SSL3_ST_SR_CERT_VRFY_A;\n\t\t\t\ts->init_num=0;\n\t\t\t\tif (s->s3->handshake_buffer)\n\t\t\t\t\tssl3_digest_cached_records(s);\n\t\t\t\tfor (dgst_num=0; dgst_num<SSL_MAX_DIGEST;dgst_num++)\n\t\t\t\t\tif (s->s3->handshake_dgst[dgst_num])\n\t\t\t\t\t\t{\n\t\t\t\t\t\ts->method->ssl3_enc->cert_verify_mac(s,EVP_MD_CTX_type(s->s3->handshake_dgst[dgst_num]),&(s->s3->tmp.cert_verify_md[offset]));\n\t\t\t\t\t\toffset+=EVP_MD_CTX_size(s->s3->handshake_dgst[dgst_num]);\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_VRFY_A:\n\t\tcase SSL3_ST_SR_CERT_VRFY_B:\n\t\t\tret=ssl3_get_cert_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_FINISHED_A:\n\t\tcase SSL3_ST_SR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,\n\t\t\t\tSSL3_ST_SR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\tif (s->tlsext_ticket_expected)\n\t\t\t\ts->state=SSL3_ST_SW_SESSION_TICKET_A;\n\t\t\telse if (s->hit)\n\t\t\t\ts->state=SSL_ST_OK;\n#else\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL_ST_OK;\n#endif\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n#ifndef OPENSSL_NO_TLSEXT\n\t\tcase SSL3_ST_SW_SESSION_TICKET_A:\n\t\tcase SSL3_ST_SW_SESSION_TICKET_B:\n\t\t\tret=ssl3_send_newsession_ticket(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_STATUS_A:\n\t\tcase SSL3_ST_SW_CERT_STATUS_B:\n\t\t\tret=ssl3_send_cert_status(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n#endif\n\t\tcase SSL3_ST_SW_CHANGE_A:\n\t\tcase SSL3_ST_SW_CHANGE_B:\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{ ret= -1; goto end; }\n\t\t\tret=ssl3_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_SERVER_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FINISHED_A:\n\t\tcase SSL3_ST_SW_FINISHED_B:\n\t\t\tret=ssl3_send_finished(s,\n\t\t\t\tSSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->server_finished_label,\n\t\t\t\ts->method->ssl3_enc->server_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\tif (s->hit)\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;\n\t\t\telse\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\ts->init_buf=NULL;\n\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\tif (s->new_session == 2)\n\t\t\t\t{\n\t\t\t\ts->new_session=0;\n\t\t\t\tssl_update_cache(s,SSL_SESS_CACHE_SERVER);\n\t\t\t\ts->ctx->stats.sess_accept_good++;\n\t\t\t\ts->handshake_func=ssl3_accept;\n\t\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\t\t}\n\t\t\tret = 1;\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_ACCEPT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_ACCEPT_EXIT,ret);\n\treturn(ret);\n\t}', 'int ssl3_send_server_certificate(SSL *s)\n\t{\n\tunsigned long l;\n\tX509 *x;\n\tif (s->state == SSL3_ST_SW_CERT_A)\n\t\t{\n\t\tx=ssl_get_server_send_cert(s);\n\t\tif (x == NULL)\n\t\t\t{\n\t\t\tif ((s->s3->tmp.new_cipher->algorithm_auth != SSL_aKRB5) ||\n\t\t\t (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kKRB5))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_CERTIFICATE,ERR_R_INTERNAL_ERROR);\n\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t}\n\t\tl=ssl3_output_cert_chain(s,x);\n\t\ts->state=SSL3_ST_SW_CERT_B;\n\t\ts->init_num=(int)l;\n\t\ts->init_off=0;\n\t\t}\n\treturn(ssl3_do_write(s,SSL3_RT_HANDSHAKE));\n\t}', 'X509 *ssl_get_server_send_cert(SSL *s)\n\t{\n\tunsigned long alg_k,alg_a,mask_k,mask_a;\n\tCERT *c;\n\tint i,is_export;\n\tc=s->cert;\n\tssl_set_cert_masks(c, s->s3->tmp.new_cipher);\n\tis_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);\n\tif (is_export)\n\t\t{\n\t\tmask_k = c->export_mask_k;\n\t\tmask_a = c->export_mask_a;\n\t\t}\n\telse\n\t\t{\n\t\tmask_k = c->mask_k;\n\t\tmask_a = c->mask_a;\n\t\t}\n\talg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n\talg_a = s->s3->tmp.new_cipher->algorithm_auth;\n\tif (alg_k & (SSL_kECDHr|SSL_kECDHe))\n\t\t{\n\t\ti=SSL_PKEY_ECC;\n\t\t}\n\telse if (alg_a & SSL_aECDSA)\n\t\t{\n\t\ti=SSL_PKEY_ECC;\n\t\t}\n\telse if (alg_k & SSL_kDHr)\n\t\ti=SSL_PKEY_DH_RSA;\n\telse if (alg_k & SSL_kDHd)\n\t\ti=SSL_PKEY_DH_DSA;\n\telse if (alg_a & SSL_aDSS)\n\t\ti=SSL_PKEY_DSA_SIGN;\n\telse if (alg_a & SSL_aRSA)\n\t\t{\n\t\tif (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)\n\t\t\ti=SSL_PKEY_RSA_SIGN;\n\t\telse\n\t\t\ti=SSL_PKEY_RSA_ENC;\n\t\t}\n\telse if (alg_a & SSL_aKRB5)\n\t\t{\n\t\treturn(NULL);\n\t\t}\n\telse if (alg_a & SSL_aGOST94)\n\t\ti=SSL_PKEY_GOST94;\n\telse if (alg_a & SSL_aGOST01)\n\t\ti=SSL_PKEY_GOST01;\n\telse\n\t\t{\n\t\tSSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,ERR_R_INTERNAL_ERROR);\n\t\treturn(NULL);\n\t\t}\n\tif (c->pkeys[i].x509 == NULL) return(NULL);\n\treturn(c->pkeys[i].x509);\n\t}', 'void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)\n\t{\n\tCERT_PKEY *cpk;\n\tint rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;\n\tint rsa_enc_export,dh_rsa_export,dh_dsa_export;\n\tint rsa_tmp_export,dh_tmp_export,kl;\n\tunsigned long mask_k,mask_a,emask_k,emask_a;\n\tint have_ecc_cert, ecdh_ok, ecdsa_ok, ecc_pkey_size;\n#ifndef OPENSSL_NO_ECDH\n\tint have_ecdh_tmp;\n#endif\n\tX509 *x = NULL;\n\tEVP_PKEY *ecc_pkey = NULL;\n\tint signature_nid = 0;\n\tif (c == NULL) return;\n\tkl=SSL_C_EXPORT_PKEYLENGTH(cipher);\n#ifndef OPENSSL_NO_RSA\n\trsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);\n\trsa_tmp_export=(c->rsa_tmp_cb != NULL ||\n\t\t(rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));\n#else\n\trsa_tmp=rsa_tmp_export=0;\n#endif\n#ifndef OPENSSL_NO_DH\n\tdh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);\n\tdh_tmp_export=(c->dh_tmp_cb != NULL ||\n\t\t(dh_tmp && DH_size(c->dh_tmp)*8 <= kl));\n#else\n\tdh_tmp=dh_tmp_export=0;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\thave_ecdh_tmp=(c->ecdh_tmp != NULL || c->ecdh_tmp_cb != NULL);\n#endif\n\tcpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);\n\trsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);\n\trsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);\n\tcpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);\n\trsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);\n\tcpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);\n\tdsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);\n\tcpk= &(c->pkeys[SSL_PKEY_DH_RSA]);\n\tdh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);\n\tdh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);\n\tcpk= &(c->pkeys[SSL_PKEY_DH_DSA]);\n\tdh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);\n\tdh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);\n\tcpk= &(c->pkeys[SSL_PKEY_ECC]);\n\thave_ecc_cert= (cpk->x509 != NULL && cpk->privatekey != NULL);\n\tmask_k=0;\n\tmask_a=0;\n\temask_k=0;\n\temask_a=0;\n#ifdef CIPHER_DEBUG\n\tprintf("rt=%d rte=%d dht=%d ecdht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\\n",\n\t rsa_tmp,rsa_tmp_export,dh_tmp,have_ecdh_tmp,\n\t\trsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);\n#endif\n\tcpk = &(c->pkeys[SSL_PKEY_GOST01]);\n\tif (cpk->x509 != NULL && cpk->privatekey !=NULL) {\n\t\tmask_k |= SSL_kGOST;\n\t\tmask_a |= SSL_aGOST01;\n\t}\n\tcpk = &(c->pkeys[SSL_PKEY_GOST94]);\n\tif (cpk->x509 != NULL && cpk->privatekey !=NULL) {\n\t\tmask_k |= SSL_kGOST;\n\t\tmask_a |= SSL_aGOST94;\n\t}\n\tif (rsa_enc || (rsa_tmp && rsa_sign))\n\t\tmask_k|=SSL_kRSA;\n\tif (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))\n\t\temask_k|=SSL_kRSA;\n#if 0\n\tif (\t(dh_tmp || dh_rsa || dh_dsa) &&\n\t\t(rsa_enc || rsa_sign || dsa_sign))\n\t\tmask_k|=SSL_kEDH;\n\tif ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&\n\t\t(rsa_enc || rsa_sign || dsa_sign))\n\t\temask_k|=SSL_kEDH;\n#endif\n\tif (dh_tmp_export)\n\t\temask_k|=SSL_kEDH;\n\tif (dh_tmp)\n\t\tmask_k|=SSL_kEDH;\n\tif (dh_rsa) mask_k|=SSL_kDHr;\n\tif (dh_rsa_export) emask_k|=SSL_kDHr;\n\tif (dh_dsa) mask_k|=SSL_kDHd;\n\tif (dh_dsa_export) emask_k|=SSL_kDHd;\n\tif (rsa_enc || rsa_sign)\n\t\t{\n\t\tmask_a|=SSL_aRSA;\n\t\temask_a|=SSL_aRSA;\n\t\t}\n\tif (dsa_sign)\n\t\t{\n\t\tmask_a|=SSL_aDSS;\n\t\temask_a|=SSL_aDSS;\n\t\t}\n\tmask_a|=SSL_aNULL;\n\temask_a|=SSL_aNULL;\n#ifndef OPENSSL_NO_KRB5\n\tmask_k|=SSL_kKRB5;\n\tmask_a|=SSL_aKRB5;\n\temask_k|=SSL_kKRB5;\n\temask_a|=SSL_aKRB5;\n#endif\n\tif (have_ecc_cert)\n\t\t{\n\t\tx = (c->pkeys[SSL_PKEY_ECC]).x509;\n\t\tX509_check_purpose(x, -1, 0);\n\t\tecdh_ok = (x->ex_flags & EXFLAG_KUSAGE) ?\n\t\t (x->ex_kusage & X509v3_KU_KEY_AGREEMENT) : 1;\n\t\tecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE) ?\n\t\t (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE) : 1;\n\t\tecc_pkey = X509_get_pubkey(x);\n\t\tecc_pkey_size = (ecc_pkey != NULL) ?\n\t\t EVP_PKEY_bits(ecc_pkey) : 0;\n\t\tEVP_PKEY_free(ecc_pkey);\n\t\tif ((x->sig_alg) && (x->sig_alg->algorithm))\n\t\t\tsignature_nid = OBJ_obj2nid(x->sig_alg->algorithm);\n#ifndef OPENSSL_NO_ECDH\n\t\tif (ecdh_ok)\n\t\t\t{\n\t\t\tconst char *sig = OBJ_nid2ln(signature_nid);\n\t\t\tif (sig == NULL)\n\t\t\t\t{\n\t\t\t\tERR_clear_error();\n\t\t\t\tsig = "unknown";\n\t\t\t\t}\n\t\t\tif (strstr(sig, "WithRSA"))\n\t\t\t\t{\n\t\t\t\tmask_k|=SSL_kECDHr;\n\t\t\t\tmask_a|=SSL_aECDH;\n\t\t\t\tif (ecc_pkey_size <= 163)\n\t\t\t\t\t{\n\t\t\t\t\temask_k|=SSL_kECDHr;\n\t\t\t\t\temask_a|=SSL_aECDH;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (signature_nid == NID_ecdsa_with_SHA1)\n\t\t\t\t{\n\t\t\t\tmask_k|=SSL_kECDHe;\n\t\t\t\tmask_a|=SSL_aECDH;\n\t\t\t\tif (ecc_pkey_size <= 163)\n\t\t\t\t\t{\n\t\t\t\t\temask_k|=SSL_kECDHe;\n\t\t\t\t\temask_a|=SSL_aECDH;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\tif (ecdsa_ok)\n\t\t\t{\n\t\t\tmask_a|=SSL_aECDSA;\n\t\t\temask_a|=SSL_aECDSA;\n\t\t\t}\n#endif\n\t\t}\n#ifndef OPENSSL_NO_ECDH\n\tif (have_ecdh_tmp)\n\t\t{\n\t\tmask_k|=SSL_kEECDH;\n\t\temask_k|=SSL_kEECDH;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_PSK\n\tmask_k |= SSL_kPSK;\n\tmask_a |= SSL_aPSK;\n\temask_k |= SSL_kPSK;\n\temask_a |= SSL_aPSK;\n#endif\n\tc->mask_k=mask_k;\n\tc->mask_a=mask_a;\n\tc->export_mask_k=emask_k;\n\tc->export_mask_a=emask_a;\n\tc->valid=1;\n\t}', 'int RSA_size(const RSA *r)\n\t{\n\treturn(BN_num_bytes(r->n));\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}'] |
33,097 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L124 | static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;
src[0+2*stride]=
src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;
src[0+1*stride]=
src[1+2*stride]=
src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;
src[0+0*stride]=
src[1+1*stride]=
src[2+2*stride]=
src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;
src[1+0*stride]=
src[2+1*stride]=
src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;
src[2+0*stride]=
src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;
src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;
} | ['static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){\n const int lt= src[-1-1*stride];\n LOAD_TOP_EDGE\n LOAD_LEFT_EDGE\n src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2;\n src[0+2*stride]=\n src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2;\n src[0+1*stride]=\n src[1+2*stride]=\n src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2;\n src[0+0*stride]=\n src[1+1*stride]=\n src[2+2*stride]=\n src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2;\n src[1+0*stride]=\n src[2+1*stride]=\n src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2;\n src[2+0*stride]=\n src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2;\n src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2;\n}'] |
33,098 | 1 | https://github.com/nginx/nginx/blob/e302ed6fc3ea48f2ccb5bc410d6306522d4f7497/src/core/ngx_string.c/#L363 | u_char *
ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
{
u_char *p, zero;
int d;
double f;
size_t len, slen;
int64_t i64;
uint64_t ui64, frac;
ngx_msec_t ms;
ngx_uint_t width, sign, hex, max_width, frac_width, scale, n;
ngx_str_t *v;
ngx_variable_value_t *vv;
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 = ngx_min(((size_t) (last - buf)), v->len);
buf = ngx_cpymem(buf, v->data, len);
fmt++;
continue;
case 'v':
vv = va_arg(args, ngx_variable_value_t *);
len = ngx_min(((size_t) (last - buf)), vv->len);
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 = ngx_min(((size_t) (last - buf)), slen);
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 = va_arg(args, double);
if (f < 0) {
*buf++ = '-';
f = -f;
}
ui64 = (int64_t) f;
frac = 0;
if (frac_width) {
scale = 1;
for (n = frac_width; n; n--) {
scale *= 10;
}
frac = (uint64_t) ((f - (double) ui64) * scale + 0.5);
if (frac == scale) {
ui64++;
frac = 0;
}
}
buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
if (frac_width) {
if (buf < last) {
*buf++ = '.';
}
buf = ngx_sprintf_num(buf, last, frac, '0', 0, frac_width);
}
fmt++;
continue;
#if !(NGX_WIN32)
case 'r':
i64 = (int64_t) va_arg(args, rlim_t);
sign = 1;
break;
#endif
case 'p':
ui64 = (uintptr_t) va_arg(args, void *);
hex = 2;
sign = 0;
zero = '0';
width = NGX_PTR_SIZE * 2;
break;
case 'c':
d = va_arg(args, int);
*buf++ = (u_char) (d & 0xff);
fmt++;
continue;
case 'Z':
*buf++ = '\0';
fmt++;
continue;
case 'N':
#if (NGX_WIN32)
*buf++ = CR;
#endif
*buf++ = LF;
fmt++;
continue;
case '%':
*buf++ = '%';
fmt++;
continue;
default:
*buf++ = *fmt++;
continue;
}
if (sign) {
if (i64 < 0) {
*buf++ = '-';
ui64 = (uint64_t) -i64;
} else {
ui64 = (uint64_t) i64;
}
}
buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);
fmt++;
} else {
*buf++ = *fmt++;
}
}
return buf;
} | ['ngx_int_t\nngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)\n{\n ngx_http_upstream_rr_peer_data_t *rrp = data;\n time_t now;\n uintptr_t m;\n ngx_int_t rc;\n ngx_uint_t i, n;\n ngx_connection_t *c;\n ngx_http_upstream_rr_peer_t *peer;\n ngx_http_upstream_rr_peers_t *peers;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,\n "get rr peer, try: %ui", pc->tries);\n now = ngx_time();\n if (rrp->peers->last_cached) {\n c = rrp->peers->cached[rrp->peers->last_cached];\n rrp->peers->last_cached--;\n#if (NGX_THREADS)\n c->read->lock = c->read->own_lock;\n c->write->lock = c->write->own_lock;\n#endif\n pc->connection = c;\n pc->cached = 1;\n return NGX_OK;\n }\n pc->cached = 0;\n pc->connection = NULL;\n if (rrp->peers->single) {\n peer = &rrp->peers->peer[0];\n } else {\n if (pc->tries == rrp->peers->number) {\n i = pc->tries;\n for ( ;; ) {\n rrp->current = ngx_http_upstream_get_peer(rrp->peers);\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,\n "get rr peer, current: %ui %i",\n rrp->current,\n rrp->peers->peer[rrp->current].current_weight);\n n = rrp->current / (8 * sizeof(uintptr_t));\n m = (uintptr_t) 1 << rrp->current % (8 * sizeof(uintptr_t));\n if (!(rrp->tried[n] & m)) {\n peer = &rrp->peers->peer[rrp->current];\n if (!peer->down) {\n if (peer->max_fails == 0\n || peer->fails < peer->max_fails)\n {\n break;\n }\n if (now - peer->checked > peer->fail_timeout) {\n peer->checked = now;\n break;\n }\n peer->current_weight = 0;\n } else {\n rrp->tried[n] |= m;\n }\n pc->tries--;\n }\n if (pc->tries == 0) {\n goto failed;\n }\n if (--i == 0) {\n ngx_log_error(NGX_LOG_ALERT, pc->log, 0,\n "round robin upstream stuck on %ui tries",\n pc->tries);\n goto failed;\n }\n }\n peer->current_weight--;\n } else {\n i = pc->tries;\n for ( ;; ) {\n n = rrp->current / (8 * sizeof(uintptr_t));\n m = (uintptr_t) 1 << rrp->current % (8 * sizeof(uintptr_t));\n if (!(rrp->tried[n] & m)) {\n peer = &rrp->peers->peer[rrp->current];\n if (!peer->down) {\n if (peer->max_fails == 0\n || peer->fails < peer->max_fails)\n {\n break;\n }\n if (now - peer->checked > peer->fail_timeout) {\n peer->checked = now;\n break;\n }\n peer->current_weight = 0;\n } else {\n rrp->tried[n] |= m;\n }\n pc->tries--;\n }\n rrp->current++;\n if (rrp->current >= rrp->peers->number) {\n rrp->current = 0;\n }\n if (pc->tries == 0) {\n goto failed;\n }\n if (--i == 0) {\n ngx_log_error(NGX_LOG_ALERT, pc->log, 0,\n "round robin upstream stuck on %ui tries",\n pc->tries);\n goto failed;\n }\n }\n peer->current_weight--;\n }\n rrp->tried[n] |= m;\n }\n pc->sockaddr = peer->sockaddr;\n pc->socklen = peer->socklen;\n pc->name = &peer->name;\n if (pc->tries == 1 && rrp->peers->next) {\n pc->tries += rrp->peers->next->number;\n n = rrp->peers->next->number / (8 * sizeof(uintptr_t)) + 1;\n for (i = 0; i < n; i++) {\n rrp->tried[i] = 0;\n }\n }\n return NGX_OK;\nfailed:\n peers = rrp->peers;\n if (peers->next) {\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, "backup servers");\n rrp->peers = peers->next;\n pc->tries = rrp->peers->number;\n n = rrp->peers->number / (8 * sizeof(uintptr_t)) + 1;\n for (i = 0; i < n; i++) {\n rrp->tried[i] = 0;\n }\n rc = ngx_http_upstream_get_round_robin_peer(pc, rrp);\n if (rc != NGX_BUSY) {\n return rc;\n }\n }\n for (i = 0; i < peers->number; i++) {\n peers->peer[i].fails = 0;\n }\n pc->name = peers->name;\n return NGX_BUSY;\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 *p, *last, *msg;\n u_char errstr[NGX_MAX_ERROR_STR];\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_slprintf(p, last, " [%V] ", &err_levels[level]);\n p = ngx_slprintf(p, last, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_slprintf(p, last, "*%uA ", log->connection);\n }\n msg = p;\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vslprintf(p, last, fmt, args);\n va_end(args);\n#else\n p = ngx_vslprintf(p, last, fmt, args);\n#endif\n if (err) {\n p = ngx_log_errno(p, last, err);\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 if (!ngx_use_stderr\n || level > NGX_LOG_WARN\n || log->file->fd == ngx_stderr)\n {\n return;\n }\n msg -= (7 + err_levels[level].len + 3);\n (void) ngx_sprintf(msg, "nginx: [%V] ", &err_levels[level]);\n (void) ngx_write_console(ngx_stderr, msg, p - msg);\n}', 'u_char * ngx_cdecl\nngx_sprintf(u_char *buf, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vslprintf(buf, (void *) -1, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)\n{\n u_char *p, zero;\n int d;\n double f;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64, frac;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, scale, n;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\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 = ngx_min(((size_t) (last - buf)), v->len);\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 = ngx_min(((size_t) (last - buf)), vv->len);\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 = ngx_min(((size_t) (last - buf)), slen);\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 = va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n frac = 0;\n if (frac_width) {\n scale = 1;\n for (n = frac_width; n; n--) {\n scale *= 10;\n }\n frac = (uint64_t) ((f - (double) ui64) * scale + 0.5);\n if (frac == scale) {\n ui64++;\n frac = 0;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n buf = ngx_sprintf_num(buf, last, frac, '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}"] |
33,099 | 0 | https://github.com/openssl/openssl/blob/b90506e995d44dee0ef4dd0324b56b59154256c2/crypto/bn/bn_print.c/#L141 | int BN_hex2bn(BIGNUM **bn, const char *a)
{
BIGNUM *ret = NULL;
BN_ULONG l = 0;
int neg = 0, h, m, i, j, k, c;
int num;
if ((a == NULL) || (*a == '\0'))
return (0);
if (*a == '-') {
neg = 1;
a++;
}
for (i = 0; i <= (INT_MAX/4) && isxdigit((unsigned char)a[i]); i++)
continue;
if (i == 0 || i > INT_MAX/4)
goto err;
num = i + neg;
if (bn == NULL)
return (num);
if (*bn == NULL) {
if ((ret = BN_new()) == NULL)
return (0);
} else {
ret = *bn;
BN_zero(ret);
}
if (bn_expand(ret, i * 4) == NULL)
goto err;
j = i;
m = 0;
h = 0;
while (j > 0) {
m = ((BN_BYTES * 2) <= j) ? (BN_BYTES * 2) : j;
l = 0;
for (;;) {
c = a[j - m];
k = OPENSSL_hexchar2int(c);
if (k < 0)
k = 0;
l = (l << 4) | k;
if (--m <= 0) {
ret->d[h++] = l;
break;
}
}
j -= (BN_BYTES * 2);
}
ret->top = h;
bn_correct_top(ret);
*bn = ret;
bn_check_top(ret);
if (ret->top != 0)
ret->neg = neg;
return (num);
err:
if (*bn == NULL)
BN_free(ret);
return (0);
} | ['static int run_srp_kat(void)\n{\n int ret = 0;\n BIGNUM *s = NULL;\n BIGNUM *v = NULL;\n BIGNUM *a = NULL;\n BIGNUM *b = NULL;\n BIGNUM *u = NULL;\n BIGNUM *x = NULL;\n BIGNUM *Apub = NULL;\n BIGNUM *Bpub = NULL;\n BIGNUM *Kclient = NULL;\n BIGNUM *Kserver = NULL;\n const SRP_gN *GN = SRP_get_default_gN("1024");\n if (GN == NULL) {\n fprintf(stderr, "Failed to get SRP parameters\\n");\n goto err;\n }\n BN_hex2bn(&s, "BEB25379D1A8581EB5A727673A2441EE");\n if (!SRP_create_verifier_BN("alice", "password123", &s, &v, GN->N,\n GN->g)) {\n fprintf(stderr, "Failed to create SRP verifier\\n");\n goto err;\n }\n if (!check_bn("v", v,\n "7E273DE8696FFC4F4E337D05B4B375BEB0DDE1569E8FA00A9886D812"\n "9BADA1F1822223CA1A605B530E379BA4729FDC59F105B4787E5186F5"\n "C671085A1447B52A48CF1970B4FB6F8400BBF4CEBFBB168152E08AB5"\n "EA53D15C1AFF87B2B9DA6E04E058AD51CC72BFC9033B564E26480D78"\n "E955A5E29E7AB245DB2BE315E2099AFB"))\n goto err;\n BN_hex2bn(&b, "E487CB59D31AC550471E81F00F6928E01DDA08E974A004F49E61F5D1"\n "05284D20");\n Bpub = SRP_Calc_B(b, GN->N, GN->g, v);\n if (!SRP_Verify_B_mod_N(Bpub, GN->N)) {\n fprintf(stderr, "Invalid B\\n");\n goto err;\n }\n if (!check_bn("B", Bpub,\n "BD0C61512C692C0CB6D041FA01BB152D4916A1E77AF46AE105393011"\n "BAF38964DC46A0670DD125B95A981652236F99D9B681CBF87837EC99"\n "6C6DA04453728610D0C6DDB58B318885D7D82C7F8DEB75CE7BD4FBAA"\n "37089E6F9C6059F388838E7A00030B331EB76840910440B1B27AAEAE"\n "EB4012B7D7665238A8E3FB004B117B58"))\n goto err;\n BN_hex2bn(&a, "60975527035CF2AD1989806F0407210BC81EDC04E2762A56AFD529DD"\n "DA2D4393");\n Apub = SRP_Calc_A(a, GN->N, GN->g);\n if (!SRP_Verify_A_mod_N(Apub, GN->N)) {\n fprintf(stderr, "Invalid A\\n");\n return -1;\n }\n if (!check_bn("A", Apub,\n "61D5E490F6F1B79547B0704C436F523DD0E560F0C64115BB72557EC4"\n "4352E8903211C04692272D8B2D1A5358A2CF1B6E0BFCF99F921530EC"\n "8E39356179EAE45E42BA92AEACED825171E1E8B9AF6D9C03E1327F44"\n "BE087EF06530E69F66615261EEF54073CA11CF5858F0EDFDFE15EFEA"\n "B349EF5D76988A3672FAC47B0769447B"))\n goto err;\n u = SRP_Calc_u(Apub, Bpub, GN->N);\n if (!check_bn("u", u, "CE38B9593487DA98554ED47D70A7AE5F462EF019"))\n goto err;\n x = SRP_Calc_x(s, "alice", "password123");\n Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u);\n if (!check_bn("Client\'s key", Kclient,\n "B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D"\n "233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C"\n "41BB59B6D5979B5C00A172B4A2A5903A0BDCAF8A709585EB2AFAFA8F"\n "3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D"\n "C346D7E474B29EDE8A469FFECA686E5A"))\n goto err;\n Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N);\n if (!check_bn("Server\'s key", Kserver,\n "B0DC82BABCF30674AE450C0287745E7990A3381F63B387AAF271A10D"\n "233861E359B48220F7C4693C9AE12B0A6F67809F0876E2D013800D6C"\n "41BB59B6D5979B5C00A172B4A2A5903A0BDCAF8A709585EB2AFAFA8F"\n "3499B200210DCC1F10EB33943CD67FC88A2F39A4BE5BEC4EC0A3212D"\n "C346D7E474B29EDE8A469FFECA686E5A"))\n goto err;\n ret = 1;\n err:\n BN_clear_free(Kclient);\n BN_clear_free(Kserver);\n BN_clear_free(x);\n BN_free(u);\n BN_free(Apub);\n BN_clear_free(a);\n BN_free(Bpub);\n BN_clear_free(b);\n BN_free(s);\n BN_clear_free(v);\n return ret;\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) && isxdigit((unsigned char)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}"] |
33,100 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/ssl/ssl_lib.c/#L221 | static int dane_ctx_enable(struct dane_ctx_st *dctx)
{
const EVP_MD **mdevp;
uint8_t *mdord;
uint8_t mdmax = DANETLS_MATCHING_LAST;
int n = ((int) mdmax) + 1;
size_t i;
mdevp = OPENSSL_zalloc(n * sizeof(*mdevp));
mdord = OPENSSL_zalloc(n * sizeof(*mdord));
if (mdord == NULL || mdevp == NULL) {
OPENSSL_free(mdevp);
SSLerr(SSL_F_DANE_CTX_ENABLE, ERR_R_MALLOC_FAILURE);
return 0;
}
for (i = 0; i < OSSL_NELEM(dane_mds); ++i) {
const EVP_MD *md;
if (dane_mds[i].nid == NID_undef ||
(md = EVP_get_digestbynid(dane_mds[i].nid)) == NULL)
continue;
mdevp[dane_mds[i].mtype] = md;
mdord[dane_mds[i].mtype] = dane_mds[i].ord;
}
dctx->mdevp = mdevp;
dctx->mdord = mdord;
dctx->mdmax = mdmax;
return 1;
} | ['static int dane_ctx_enable(struct dane_ctx_st *dctx)\n{\n const EVP_MD **mdevp;\n uint8_t *mdord;\n uint8_t mdmax = DANETLS_MATCHING_LAST;\n int n = ((int) mdmax) + 1;\n size_t i;\n mdevp = OPENSSL_zalloc(n * sizeof(*mdevp));\n mdord = OPENSSL_zalloc(n * sizeof(*mdord));\n if (mdord == NULL || mdevp == NULL) {\n OPENSSL_free(mdevp);\n SSLerr(SSL_F_DANE_CTX_ENABLE, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n for (i = 0; i < OSSL_NELEM(dane_mds); ++i) {\n const EVP_MD *md;\n if (dane_mds[i].nid == NID_undef ||\n (md = EVP_get_digestbynid(dane_mds[i].nid)) == NULL)\n continue;\n mdevp[dane_mds[i].mtype] = md;\n mdord[dane_mds[i].mtype] = dane_mds[i].ord;\n }\n dctx->mdevp = mdevp;\n dctx->mdord = mdord;\n dctx->mdmax = mdmax;\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#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.