id
int64 1
36.7k
| label
int64 0
1
| bug_url
stringlengths 91
134
| bug_function
stringlengths 13
72.7k
| functions
stringlengths 17
79.2k
|
|---|---|---|---|---|
1,101
| 0
|
https://github.com/libav/libav/blob/f0319383436e1abc3fc1464fe4e5f4dc40db3419/ffmpeg.c/#L1020
|
static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
int frame_size)
{
AVCodecContext *enc;
int frame_number;
double ti1, bitrate, avg_bitrate;
if (!vstats_file) {
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
av_exit(1);
}
}
enc = ost->st->codec;
if (enc->codec_type == CODEC_TYPE_VIDEO) {
frame_number = ost->frame_number;
fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
if (enc->flags&CODEC_FLAG_PSNR)
fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
fprintf(vstats_file,"f_size= %6d ", frame_size);
ti1 = ost->sync_opts * av_q2d(enc->time_base);
if (ti1 < 0.01)
ti1 = 0.01;
bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
(double)video_size / 1024, ti1, bitrate, avg_bitrate);
fprintf(vstats_file,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type));
}
}
|
['static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,\n int frame_size)\n{\n AVCodecContext *enc;\n int frame_number;\n double ti1, bitrate, avg_bitrate;\n if (!vstats_file) {\n vstats_file = fopen(vstats_filename, "w");\n if (!vstats_file) {\n perror("fopen");\n av_exit(1);\n }\n }\n enc = ost->st->codec;\n if (enc->codec_type == CODEC_TYPE_VIDEO) {\n frame_number = ost->frame_number;\n fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);\n if (enc->flags&CODEC_FLAG_PSNR)\n fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));\n fprintf(vstats_file,"f_size= %6d ", frame_size);\n ti1 = ost->sync_opts * av_q2d(enc->time_base);\n if (ti1 < 0.01)\n ti1 = 0.01;\n bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;\n avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;\n fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",\n (double)video_size / 1024, ti1, bitrate, avg_bitrate);\n fprintf(vstats_file,"type= %c\\n", av_get_pict_type_char(enc->coded_frame->pict_type));\n }\n}']
|
1,102
| 0
|
https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244
|
u_char *
ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)
{
u_char *p, zero, *last;
int d;
float f, scale;
size_t len, slen;
int64_t i64;
uint64_t ui64;
ngx_msec_t ms;
ngx_uint_t width, sign, hex, max_width, frac_width, i;
ngx_str_t *v;
ngx_variable_value_t *vv;
if (max == 0) {
return buf;
}
last = buf + max;
while (*fmt && buf < last) {
if (*fmt == '%') {
i64 = 0;
ui64 = 0;
zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hex = 0;
max_width = 0;
frac_width = 0;
slen = (size_t) -1;
while (*fmt >= '0' && *fmt <= '9') {
width = width * 10 + *fmt++ - '0';
}
for ( ;; ) {
switch (*fmt) {
case 'u':
sign = 0;
fmt++;
continue;
case 'm':
max_width = 1;
fmt++;
continue;
case 'X':
hex = 2;
sign = 0;
fmt++;
continue;
case 'x':
hex = 1;
sign = 0;
fmt++;
continue;
case '.':
fmt++;
while (*fmt >= '0' && *fmt <= '9') {
frac_width = frac_width * 10 + *fmt++ - '0';
}
break;
case '*':
slen = va_arg(args, size_t);
fmt++;
continue;
default:
break;
}
break;
}
switch (*fmt) {
case 'V':
v = va_arg(args, ngx_str_t *);
len = v->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, v->data, len);
fmt++;
continue;
case 'v':
vv = va_arg(args, ngx_variable_value_t *);
len = vv->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, vv->data, len);
fmt++;
continue;
case 's':
p = va_arg(args, u_char *);
if (slen == (size_t) -1) {
while (*p && buf < last) {
*buf++ = *p++;
}
} else {
len = (buf + slen < last) ? slen : (size_t) (last - buf);
buf = ngx_cpymem(buf, p, len);
}
fmt++;
continue;
case 'O':
i64 = (int64_t) va_arg(args, off_t);
sign = 1;
break;
case 'P':
i64 = (int64_t) va_arg(args, ngx_pid_t);
sign = 1;
break;
case 'T':
i64 = (int64_t) va_arg(args, time_t);
sign = 1;
break;
case 'M':
ms = (ngx_msec_t) va_arg(args, ngx_msec_t);
if ((ngx_msec_int_t) ms == -1) {
sign = 1;
i64 = -1;
} else {
sign = 0;
ui64 = (uint64_t) ms;
}
break;
case 'z':
if (sign) {
i64 = (int64_t) va_arg(args, ssize_t);
} else {
ui64 = (uint64_t) va_arg(args, size_t);
}
break;
case 'i':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_uint_t);
}
if (max_width) {
width = NGX_INT_T_LEN;
}
break;
case 'd':
if (sign) {
i64 = (int64_t) va_arg(args, int);
} else {
ui64 = (uint64_t) va_arg(args, u_int);
}
break;
case 'l':
if (sign) {
i64 = (int64_t) va_arg(args, long);
} else {
ui64 = (uint64_t) va_arg(args, u_long);
}
break;
case 'D':
if (sign) {
i64 = (int64_t) va_arg(args, int32_t);
} else {
ui64 = (uint64_t) va_arg(args, uint32_t);
}
break;
case 'L':
if (sign) {
i64 = va_arg(args, int64_t);
} else {
ui64 = va_arg(args, uint64_t);
}
break;
case 'A':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_atomic_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);
}
if (max_width) {
width = NGX_ATOMIC_T_LEN;
}
break;
case 'f':
f = (float) va_arg(args, double);
if (f < 0) {
*buf++ = '-';
f = -f;
}
ui64 = (int64_t) f;
buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
if (frac_width) {
if (buf < last) {
*buf++ = '.';
}
scale = 1.0;
for (i = 0; i < frac_width; i++) {
scale *= 10.0;
}
ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);
buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);
}
fmt++;
continue;
#if !(NGX_WIN32)
case 'r':
i64 = (int64_t) va_arg(args, rlim_t);
sign = 1;
break;
#endif
case 'p':
ui64 = (uintptr_t) va_arg(args, void *);
hex = 2;
sign = 0;
zero = '0';
width = NGX_PTR_SIZE * 2;
break;
case 'c':
d = va_arg(args, int);
*buf++ = (u_char) (d & 0xff);
fmt++;
continue;
case 'Z':
*buf++ = '\0';
fmt++;
continue;
case 'N':
#if (NGX_WIN32)
*buf++ = CR;
#endif
*buf++ = LF;
fmt++;
continue;
case '%':
*buf++ = '%';
fmt++;
continue;
default:
*buf++ = *fmt++;
continue;
}
if (sign) {
if (i64 < 0) {
*buf++ = '-';
ui64 = (uint64_t) -i64;
} else {
ui64 = (uint64_t) i64;
}
}
buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);
fmt++;
} else {
*buf++ = *fmt++;
}
}
return buf;
}
|
['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->accessed > peer->fail_timeout) {\n peer->fails = 0;\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->accessed > peer->fail_timeout) {\n peer->fails = 0;\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 errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"]
|
1,103
| 0
|
https://github.com/libav/libav/blob/0fdc9f81a00f0f32eb93c324bad65d8014deb4dd/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_gop_header(IVI45DecContext *ctx, AVCodecContext *avctx)\n{\n int result, i, p, tile_size, pic_size_indx, mb_size, blk_size;\n int quant_mat, blk_size_changed = 0;\n IVIBandDesc *band, *band1, *band2;\n IVIPicConfig pic_conf;\n ctx->gop_flags = bitstream_read(&ctx->bc, 8);\n ctx->gop_hdr_size = (ctx->gop_flags & 1) ? bitstream_read(&ctx->bc, 16) : 0;\n if (ctx->gop_flags & IVI5_IS_PROTECTED)\n ctx->lock_word = bitstream_read(&ctx->bc, 32);\n tile_size = (ctx->gop_flags & 0x40) ? 64 << bitstream_read(&ctx->bc, 2) : 0;\n if (tile_size > 256) {\n av_log(avctx, AV_LOG_ERROR, "Invalid tile size: %d\\n", tile_size);\n return AVERROR_INVALIDDATA;\n }\n pic_conf.luma_bands = bitstream_read(&ctx->bc, 2) * 3 + 1;\n pic_conf.chroma_bands = bitstream_read_bit(&ctx->bc) * 3 + 1;\n ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;\n if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {\n av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\\n",\n pic_conf.luma_bands, pic_conf.chroma_bands);\n return AVERROR_INVALIDDATA;\n }\n pic_size_indx = bitstream_read(&ctx->bc, 4);\n if (pic_size_indx == IVI5_PIC_SIZE_ESC) {\n pic_conf.pic_height = bitstream_read(&ctx->bc, 13);\n pic_conf.pic_width = bitstream_read(&ctx->bc, 13);\n } else {\n pic_conf.pic_height = ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;\n pic_conf.pic_width = ivi5_common_pic_sizes[pic_size_indx * 2 ] << 2;\n }\n if (ctx->gop_flags & 2) {\n avpriv_report_missing_feature(avctx, "YV12 picture format");\n return AVERROR_PATCHWELCOME;\n }\n pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;\n pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;\n if (!tile_size) {\n pic_conf.tile_height = pic_conf.pic_height;\n pic_conf.tile_width = pic_conf.pic_width;\n } else {\n pic_conf.tile_height = pic_conf.tile_width = tile_size;\n }\n if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf) || ctx->gop_invalid) {\n result = ff_ivi_init_planes(ctx->planes, &pic_conf, 0);\n if (result < 0) {\n av_log(avctx, AV_LOG_ERROR, "Couldn\'t reallocate color planes!\\n");\n return result;\n }\n ctx->pic_conf = pic_conf;\n blk_size_changed = 1;\n }\n for (p = 0; p <= 1; p++) {\n for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {\n band = &ctx->planes[p].bands[i];\n band->is_halfpel = bitstream_read_bit(&ctx->bc);\n mb_size = bitstream_read_bit(&ctx->bc);\n blk_size = 8 >> bitstream_read_bit(&ctx->bc);\n mb_size = blk_size << !mb_size;\n blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;\n if (blk_size_changed) {\n band->mb_size = mb_size;\n band->blk_size = blk_size;\n }\n if (bitstream_read_bit(&ctx->bc)) {\n avpriv_report_missing_feature(avctx, "Extended transform info");\n return AVERROR_PATCHWELCOME;\n }\n switch ((p << 2) + i) {\n case 0:\n band->inv_transform = ff_ivi_inverse_slant_8x8;\n band->dc_transform = ff_ivi_dc_slant_2d;\n band->scan = ff_zigzag_direct;\n band->transform_size = 8;\n break;\n case 1:\n band->inv_transform = ff_ivi_row_slant8;\n band->dc_transform = ff_ivi_dc_row_slant;\n band->scan = ff_ivi_vertical_scan_8x8;\n band->transform_size = 8;\n break;\n case 2:\n band->inv_transform = ff_ivi_col_slant8;\n band->dc_transform = ff_ivi_dc_col_slant;\n band->scan = ff_ivi_horizontal_scan_8x8;\n band->transform_size = 8;\n break;\n case 3:\n band->inv_transform = ff_ivi_put_pixels_8x8;\n band->dc_transform = ff_ivi_put_dc_pixel_8x8;\n band->scan = ff_ivi_horizontal_scan_8x8;\n band->transform_size = 8;\n break;\n case 4:\n band->inv_transform = ff_ivi_inverse_slant_4x4;\n band->dc_transform = ff_ivi_dc_slant_2d;\n band->scan = ff_ivi_direct_scan_4x4;\n band->transform_size = 4;\n break;\n }\n band->is_2d_trans = band->inv_transform == ff_ivi_inverse_slant_8x8 ||\n band->inv_transform == ff_ivi_inverse_slant_4x4;\n if (band->transform_size != band->blk_size)\n return AVERROR_INVALIDDATA;\n if (!p) {\n quant_mat = (pic_conf.luma_bands > 1) ? i+1 : 0;\n } else {\n quant_mat = 5;\n }\n if (band->blk_size == 8) {\n band->intra_base = &ivi5_base_quant_8x8_intra[quant_mat][0];\n band->inter_base = &ivi5_base_quant_8x8_inter[quant_mat][0];\n band->intra_scale = &ivi5_scale_quant_8x8_intra[quant_mat][0];\n band->inter_scale = &ivi5_scale_quant_8x8_inter[quant_mat][0];\n } else {\n band->intra_base = ivi5_base_quant_4x4_intra;\n band->inter_base = ivi5_base_quant_4x4_inter;\n band->intra_scale = ivi5_scale_quant_4x4_intra;\n band->inter_scale = ivi5_scale_quant_4x4_inter;\n }\n if (bitstream_read(&ctx->bc, 2)) {\n av_log(avctx, AV_LOG_ERROR, "End marker missing!\\n");\n return AVERROR_INVALIDDATA;\n }\n }\n }\n for (i = 0; i < pic_conf.chroma_bands; i++) {\n band1 = &ctx->planes[1].bands[i];\n band2 = &ctx->planes[2].bands[i];\n band2->width = band1->width;\n band2->height = band1->height;\n band2->mb_size = band1->mb_size;\n band2->blk_size = band1->blk_size;\n band2->is_halfpel = band1->is_halfpel;\n band2->intra_base = band1->intra_base;\n band2->inter_base = band1->inter_base;\n band2->intra_scale = band1->intra_scale;\n band2->inter_scale = band1->inter_scale;\n band2->scan = band1->scan;\n band2->inv_transform = band1->inv_transform;\n band2->dc_transform = band1->dc_transform;\n band2->is_2d_trans = band1->is_2d_trans;\n }\n if (blk_size_changed) {\n result = ff_ivi_init_tiles(ctx->planes, pic_conf.tile_width,\n pic_conf.tile_height);\n if (result < 0) {\n av_log(avctx, AV_LOG_ERROR,\n "Couldn\'t reallocate internal structures!\\n");\n return result;\n }\n }\n if (ctx->gop_flags & 8) {\n if (bitstream_read(&ctx->bc, 3)) {\n av_log(avctx, AV_LOG_ERROR, "Alignment bits are not zero!\\n");\n return AVERROR_INVALIDDATA;\n }\n if (bitstream_read_bit(&ctx->bc))\n bitstream_skip(&ctx->bc, 24);\n }\n bitstream_align(&ctx->bc);\n bitstream_skip(&ctx->bc, 23);\n if (bitstream_read_bit(&ctx->bc)) {\n do {\n i = bitstream_read(&ctx->bc, 16);\n } while (i & 0x8000);\n }\n bitstream_align(&ctx->bc);\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
1,104
| 0
|
https://github.com/openssl/openssl/blob/3ba25ee86a3758cc659c954b59718d8397030768/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 int ssl3_get_key_exchange(SSL *s)\n\t{\n#ifndef NO_RSA\n\tunsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];\n#endif\n\tEVP_MD_CTX md_ctx;\n\tunsigned char *param,*p;\n\tint al,i,j,param_len,ok;\n\tlong n,alg;\n\tEVP_PKEY *pkey=NULL;\n#ifndef NO_RSA\n\tRSA *rsa=NULL;\n#endif\n#ifndef NO_DH\n\tDH *dh=NULL;\n#endif\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_CR_KEY_EXCH_A,\n\t\tSSL3_ST_CR_KEY_EXCH_B,\n\t\t-1,\n\t\t1024*8,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tparam=p=(unsigned char *)s->init_buf->data;\n\tif (s->session->sess_cert != NULL)\n\t\t{\n#ifndef NO_RSA\n\t\tif (s->session->sess_cert->peer_rsa_tmp != NULL)\n\t\t\t{\n\t\t\tRSA_free(s->session->sess_cert->peer_rsa_tmp);\n\t\t\ts->session->sess_cert->peer_rsa_tmp=NULL;\n\t\t\t}\n#endif\n#ifndef NO_DH\n\t\tif (s->session->sess_cert->peer_dh_tmp)\n\t\t\t{\n\t\t\tDH_free(s->session->sess_cert->peer_dh_tmp);\n\t\t\ts->session->sess_cert->peer_dh_tmp=NULL;\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n\t\ts->session->sess_cert=ssl_sess_cert_new();\n\t\t}\n\tparam_len=0;\n\talg=s->s3->tmp.new_cipher->algorithms;\n#ifndef NO_RSA\n\tif (alg & SSL_kRSA)\n\t\t{\n\t\tif ((rsa=RSA_new()) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(rsa->n=BN_bin2bn(p,i,rsa->n)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(rsa->e=BN_bin2bn(p,i,rsa->e)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn-=param_len;\n\t\tif (alg & SSL_aRSA)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);\n\t\telse\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->session->sess_cert->peer_rsa_tmp=rsa;\n\t\trsa=NULL;\n\t\t}\n#else\n\tif (0)\n\t\t;\n#endif\n#ifndef NO_DH\n\telse if (alg & SSL_kEDH)\n\t\t{\n\t\tif ((dh=DH_new()) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tn2s(p,i);\n\t\tparam_len=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(dh->p=BN_bin2bn(p,i,NULL)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(dh->g=BN_bin2bn(p,i,NULL)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn2s(p,i);\n\t\tparam_len+=i+2;\n\t\tif (param_len > n)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (!(dh->pub_key=BN_bin2bn(p,i,NULL)))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=i;\n\t\tn-=param_len;\n#ifndef NO_RSA\n\t\tif (alg & SSL_aRSA)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509);\n#else\n\t\tif (0)\n\t\t\t;\n#endif\n#ifndef NO_DSA\n\t\telse if (alg & SSL_aDSS)\n\t\t\tpkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509);\n#endif\n\t\ts->session->sess_cert->peer_dh_tmp=dh;\n\t\tdh=NULL;\n\t\t}\n\telse if ((alg & SSL_kDHr) || (alg & SSL_kDHd))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);\n\t\tgoto f_err;\n\t\t}\n#endif\n\tif (alg & SSL_aFZA)\n\t\t{\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);\n\t\tgoto f_err;\n\t\t}\n\tif (pkey != NULL)\n\t\t{\n\t\tn2s(p,i);\n\t\tn-=2;\n\t\tj=EVP_PKEY_size(pkey);\n\t\tif ((i != n) || (n > j) || (n <= 0))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);\n\t\t\tgoto f_err;\n\t\t\t}\n#ifndef NO_RSA\n\t\tif (pkey->type == EVP_PKEY_RSA)\n\t\t\t{\n\t\t\tint num;\n\t\t\tj=0;\n\t\t\tq=md_buf;\n\t\t\tfor (num=2; num > 0; num--)\n\t\t\t\t{\n\t\t\t\tEVP_DigestInit(&md_ctx,(num == 2)\n\t\t\t\t\t?s->ctx->md5:s->ctx->sha1);\n\t\t\t\tEVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_DigestUpdate(&md_ctx,param,param_len);\n\t\t\t\tEVP_DigestFinal(&md_ctx,q,(unsigned int *)&i);\n\t\t\t\tq+=i;\n\t\t\t\tj+=i;\n\t\t\t\t}\n\t\t\ti=RSA_verify(NID_md5_sha1, md_buf, j, p, n,\n\t\t\t\t\t\t\t\tpkey->pkey.rsa);\n\t\t\tif (i < 0)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tif (i == 0)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\t{\n\t\t\tEVP_VerifyInit(&md_ctx,EVP_dss1());\n\t\t\tEVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\tEVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\tEVP_VerifyUpdate(&md_ctx,param,param_len);\n\t\t\tif (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECRYPT_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (!(alg & SSL_aNULL))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (n != 0)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tEVP_PKEY_free(pkey);\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\tEVP_PKEY_free(pkey);\n#ifndef NO_RSA\n\tif (rsa != NULL)\n\t\tRSA_free(rsa);\n#endif\n#ifndef NO_DH\n\tif (dh != NULL)\n\t\tDH_free(dh);\n#endif\n\treturn(-1);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\tint skip_message;\n\t\tdo\n\t\t\t{\n\t\t\twhile (s->init_num < 4)\n\t\t\t\t{\n\t\t\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t\t4 - s->init_num, 0);\n\t\t\t\tif (i <= 0)\n\t\t\t\t\t{\n\t\t\t\t\ts->rwstate=SSL_READING;\n\t\t\t\t\t*ok = 0;\n\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\ts->init_num+=i;\n\t\t\t\t}\n\t\t\tskip_message = 0;\n\t\t\tif (!s->server)\n\t\t\t\tif (p[0] == SSL3_MT_HELLO_REQUEST)\n\t\t\t\t\tif (p[1] == 0 && p[2] == 0 &&p[3] == 0)\n\t\t\t\t\t\tskip_message = 1;\n\t\t\t}\n\t\twhile (skip_message);\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t\t\t(st1 == SSL3_ST_SR_CERT_A) &&\n\t\t\t\t\t(stn == SSL3_ST_SR_CERT_B))\n\t\t\t{\n\t\t\tssl3_init_finished_mac(s);\n\t\t\t}\n\t\tssl3_finish_mac(s, (unsigned char *)s->init_buf->data, 4);\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\twhile (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\ts->rwstate=SSL_READING;\n\t\t\t*ok = 0;\n\t\t\treturn i;\n\t\t\t}\n\t\ts->init_num += i;\n\t\tn -= i;\n\t\t}\n\tssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num);\n\t*ok=1;\n\treturn s->init_num;\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn((void *)ret);\n\t}']
|
1,105
| 0
|
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/crypto/bn/bn_ctx.c/#L401
|
static void BN_POOL_release(BN_POOL *p, unsigned int num)
{
unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;
p->used -= num;
while (num--) {
bn_check_top(p->current->vals + offset);
if (offset == 0) {
offset = BN_CTX_POOL_SIZE - 1;
p->current = p->current->prev;
} else
offset--;
}
}
|
['int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,\n BN_CTX *ctx)\n{\n int ret = 0;\n BN_CTX *ctx_new = NULL;\n if (!group || !r || !a) {\n ECerr(EC_F_EC_GFP_NIST_FIELD_SQR, EC_R_PASSED_NULL_PARAMETER);\n goto err;\n }\n if (!ctx)\n if ((ctx_new = ctx = BN_CTX_new()) == NULL)\n goto err;\n if (!BN_sqr(r, a, ctx))\n goto err;\n if (!group->field_mod_func(r, r, group->field, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_free(ctx_new);\n return ret;\n}', '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}', '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}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
|
1,106
| 0
|
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavformat/utils.c/#L2944
|
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
{
const char *p;
char tag[128], *q;
p = info;
if (*p == '?')
p++;
for(;;) {
q = tag;
while (*p != '\0' && *p != '=' && *p != '&') {
if ((q - tag) < sizeof(tag) - 1)
*q++ = *p;
p++;
}
*q = '\0';
q = arg;
if (*p == '=') {
p++;
while (*p != '&' && *p != '\0') {
if ((q - arg) < arg_size - 1) {
if (*p == '+')
*q++ = ' ';
else
*q++ = *p;
}
p++;
}
*q = '\0';
}
if (!strcmp(tag, tag1))
return 1;
if (*p != '&')
break;
p++;
}
return 0;
}
|
['static void rtsp_cmd_setup(HTTPContext *c, const char *url,\n RTSPHeader *h)\n{\n FFStream *stream;\n int stream_index, port;\n char buf[1024];\n char path1[1024];\n const char *path;\n HTTPContext *rtp_c;\n RTSPTransportField *th;\n struct sockaddr_in dest_addr;\n RTSPActionServerSetup setup;\n url_split(NULL, 0, NULL, 0, NULL, 0, NULL, path1, sizeof(path1), url);\n path = path1;\n if (*path == \'/\')\n path++;\n for(stream = first_stream; stream != NULL; stream = stream->next) {\n if (!stream->is_feed &&\n stream->fmt && !strcmp(stream->fmt->name, "rtp")) {\n if (!strcmp(path, stream->filename)) {\n if (stream->nb_streams != 1) {\n rtsp_reply_error(c, RTSP_STATUS_AGGREGATE);\n return;\n }\n stream_index = 0;\n goto found;\n }\n for(stream_index = 0; stream_index < stream->nb_streams;\n stream_index++) {\n snprintf(buf, sizeof(buf), "%s/streamid=%d",\n stream->filename, stream_index);\n if (!strcmp(path, buf))\n goto found;\n }\n }\n }\n rtsp_reply_error(c, RTSP_STATUS_SERVICE);\n return;\n found:\n if (h->session_id[0] == \'\\0\')\n snprintf(h->session_id, sizeof(h->session_id), "%08x%08x",\n av_random(&random_state), av_random(&random_state));\n rtp_c = find_rtp_session(h->session_id);\n if (!rtp_c) {\n th = find_transport(h, RTSP_PROTOCOL_RTP_UDP);\n if (!th) {\n th = find_transport(h, RTSP_PROTOCOL_RTP_TCP);\n if (!th) {\n rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);\n return;\n }\n }\n rtp_c = rtp_new_connection(&c->from_addr, stream, h->session_id,\n th->protocol);\n if (!rtp_c) {\n rtsp_reply_error(c, RTSP_STATUS_BANDWIDTH);\n return;\n }\n if (open_input_stream(rtp_c, "") < 0) {\n rtsp_reply_error(c, RTSP_STATUS_INTERNAL);\n return;\n }\n }\n if (rtp_c->stream != stream) {\n rtsp_reply_error(c, RTSP_STATUS_SERVICE);\n return;\n }\n if (rtp_c->rtp_ctx[stream_index]) {\n rtsp_reply_error(c, RTSP_STATUS_STATE);\n return;\n }\n th = find_transport(h, rtp_c->rtp_protocol);\n if (!th || (th->protocol == RTSP_PROTOCOL_RTP_UDP &&\n th->client_port_min <= 0)) {\n rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);\n return;\n }\n setup.transport_option[0] = \'\\0\';\n dest_addr = rtp_c->from_addr;\n dest_addr.sin_port = htons(th->client_port_min);\n if (rtp_new_av_stream(rtp_c, stream_index, &dest_addr, c) < 0) {\n rtsp_reply_error(c, RTSP_STATUS_TRANSPORT);\n return;\n }\n rtsp_reply_header(c, RTSP_STATUS_OK);\n url_fprintf(c->pb, "Session: %s\\r\\n", rtp_c->session_id);\n switch(rtp_c->rtp_protocol) {\n case RTSP_PROTOCOL_RTP_UDP:\n port = rtp_get_local_port(rtp_c->rtp_handles[stream_index]);\n url_fprintf(c->pb, "Transport: RTP/AVP/UDP;unicast;"\n "client_port=%d-%d;server_port=%d-%d",\n th->client_port_min, th->client_port_min + 1,\n port, port + 1);\n break;\n case RTSP_PROTOCOL_RTP_TCP:\n url_fprintf(c->pb, "Transport: RTP/AVP/TCP;interleaved=%d-%d",\n stream_index * 2, stream_index * 2 + 1);\n break;\n default:\n break;\n }\n if (setup.transport_option[0] != \'\\0\')\n url_fprintf(c->pb, ";%s", setup.transport_option);\n url_fprintf(c->pb, "\\r\\n");\n url_fprintf(c->pb, "\\r\\n");\n}', 'static int open_input_stream(HTTPContext *c, const char *info)\n{\n char buf[128];\n char input_filename[1024];\n AVFormatContext *s;\n int buf_size, i, ret;\n int64_t stream_pos;\n if (c->stream->feed) {\n strcpy(input_filename, c->stream->feed->feed_filename);\n buf_size = FFM_PACKET_SIZE;\n if (find_info_tag(buf, sizeof(buf), "date", info)) {\n stream_pos = parse_date(buf, 0);\n if (stream_pos == INT64_MIN)\n return -1;\n } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) {\n int prebuffer = strtol(buf, 0, 10);\n stream_pos = av_gettime() - prebuffer * (int64_t)1000000;\n } else\n stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000;\n } else {\n strcpy(input_filename, c->stream->feed_filename);\n buf_size = 0;\n if (find_info_tag(buf, sizeof(buf), "date", info)) {\n stream_pos = parse_date(buf, 1);\n if (stream_pos == INT64_MIN)\n return -1;\n } else\n stream_pos = 0;\n }\n if (input_filename[0] == \'\\0\')\n return -1;\n#if 0\n { time_t when = stream_pos / 1000000;\n http_log("Stream pos = %"PRId64", time=%s", stream_pos, ctime(&when));\n }\n#endif\n if ((ret = av_open_input_file(&s, input_filename, c->stream->ifmt,\n buf_size, c->stream->ap_in)) < 0) {\n http_log("could not open %s: %d\\n", input_filename, ret);\n return -1;\n }\n s->flags |= AVFMT_FLAG_GENPTS;\n c->fmt_in = s;\n av_find_stream_info(c->fmt_in);\n for(i=0;i<s->nb_streams;i++)\n open_parser(s, i);\n c->pts_stream_index = 0;\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->pts_stream_index == 0 &&\n c->stream->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) {\n c->pts_stream_index = i;\n }\n }\n#if 1\n if (c->fmt_in->iformat->read_seek)\n av_seek_frame(c->fmt_in, -1, stream_pos, 0);\n#endif\n c->start_time = cur_time;\n c->first_pts = AV_NOPTS_VALUE;\n return 0;\n}', "int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)\n{\n const char *p;\n char tag[128], *q;\n p = info;\n if (*p == '?')\n p++;\n for(;;) {\n q = tag;\n while (*p != '\\0' && *p != '=' && *p != '&') {\n if ((q - tag) < sizeof(tag) - 1)\n *q++ = *p;\n p++;\n }\n *q = '\\0';\n q = arg;\n if (*p == '=') {\n p++;\n while (*p != '&' && *p != '\\0') {\n if ((q - arg) < arg_size - 1) {\n if (*p == '+')\n *q++ = ' ';\n else\n *q++ = *p;\n }\n p++;\n }\n *q = '\\0';\n }\n if (!strcmp(tag, tag1))\n return 1;\n if (*p != '&')\n break;\n p++;\n }\n return 0;\n}"]
|
1,107
| 0
|
https://github.com/libav/libav/blob/8e3d8a82e6eb8ef37daecddf651fe6cdadaab7e8/ffmpeg.c/#L1028
|
static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
int frame_size)
{
AVCodecContext *enc;
int frame_number;
double ti1, bitrate, avg_bitrate;
if (!vstats_file) {
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
av_exit(1);
}
}
enc = ost->st->codec;
if (enc->codec_type == CODEC_TYPE_VIDEO) {
frame_number = ost->frame_number;
fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
if (enc->flags&CODEC_FLAG_PSNR)
fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
fprintf(vstats_file,"f_size= %6d ", frame_size);
ti1 = ost->sync_opts * av_q2d(enc->time_base);
if (ti1 < 0.01)
ti1 = 0.01;
bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
(double)video_size / 1024, ti1, bitrate, avg_bitrate);
fprintf(vstats_file,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type));
}
}
|
['static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,\n int frame_size)\n{\n AVCodecContext *enc;\n int frame_number;\n double ti1, bitrate, avg_bitrate;\n if (!vstats_file) {\n vstats_file = fopen(vstats_filename, "w");\n if (!vstats_file) {\n perror("fopen");\n av_exit(1);\n }\n }\n enc = ost->st->codec;\n if (enc->codec_type == CODEC_TYPE_VIDEO) {\n frame_number = ost->frame_number;\n fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);\n if (enc->flags&CODEC_FLAG_PSNR)\n fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));\n fprintf(vstats_file,"f_size= %6d ", frame_size);\n ti1 = ost->sync_opts * av_q2d(enc->time_base);\n if (ti1 < 0.01)\n ti1 = 0.01;\n bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;\n avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;\n fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",\n (double)video_size / 1024, ti1, bitrate, avg_bitrate);\n fprintf(vstats_file,"type= %c\\n", av_get_pict_type_char(enc->coded_frame->pict_type));\n }\n}']
|
1,108
| 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 void print_stuff(BIO *bio, SSL *s, int full)\n{\n X509 *peer = NULL;\n char buf[BUFSIZ];\n STACK_OF(X509) *sk;\n STACK_OF(X509_NAME) *sk2;\n const SSL_CIPHER *c;\n X509_NAME *xn;\n int i;\n int mdpth;\n EVP_PKEY *mspki;\n const char *peername;\n#ifndef OPENSSL_NO_COMP\n const COMP_METHOD *comp, *expansion;\n#endif\n unsigned char *exportedkeymat;\n if (full) {\n int got_a_chain = 0;\n sk = SSL_get_peer_cert_chain(s);\n if (sk != NULL) {\n got_a_chain = 1;\n BIO_printf(bio, "---\\nCertificate chain\\n");\n for (i = 0; i < sk_X509_num(sk); i++) {\n X509_NAME_oneline(X509_get_subject_name(sk_X509_value(sk, i)),\n buf, sizeof buf);\n BIO_printf(bio, "%2d s:%s\\n", i, buf);\n X509_NAME_oneline(X509_get_issuer_name(sk_X509_value(sk, i)),\n buf, sizeof buf);\n BIO_printf(bio, " i:%s\\n", buf);\n if (c_showcerts)\n PEM_write_bio_X509(bio, sk_X509_value(sk, i));\n }\n }\n BIO_printf(bio, "---\\n");\n peer = SSL_get_peer_certificate(s);\n if (peer != NULL) {\n BIO_printf(bio, "Server certificate\\n");\n if (!(c_showcerts && got_a_chain))\n PEM_write_bio_X509(bio, peer);\n X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf);\n BIO_printf(bio, "subject=%s\\n", buf);\n X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf);\n BIO_printf(bio, "issuer=%s\\n", buf);\n } else\n BIO_printf(bio, "no peer certificate available\\n");\n sk2 = SSL_get_client_CA_list(s);\n if ((sk2 != NULL) && (sk_X509_NAME_num(sk2) > 0)) {\n BIO_printf(bio, "---\\nAcceptable client certificate CA names\\n");\n for (i = 0; i < sk_X509_NAME_num(sk2); i++) {\n xn = sk_X509_NAME_value(sk2, i);\n X509_NAME_oneline(xn, buf, sizeof(buf));\n BIO_write(bio, buf, strlen(buf));\n BIO_write(bio, "\\n", 1);\n }\n } else {\n BIO_printf(bio, "---\\nNo client certificate CA names sent\\n");\n }\n ssl_print_sigalgs(bio, s);\n ssl_print_tmp_key(bio, s);\n BIO_printf(bio,\n "---\\nSSL handshake has read %"PRIu64" bytes and written %"PRIu64" bytes\\n",\n BIO_number_read(SSL_get_rbio(s)),\n BIO_number_written(SSL_get_wbio(s)));\n }\n if ((mdpth = SSL_get0_dane_authority(s, NULL, &mspki)) >= 0) {\n uint8_t usage, selector, mtype;\n mdpth = SSL_get0_dane_tlsa(s, &usage, &selector, &mtype, NULL, NULL);\n BIO_printf(bio, "DANE TLSA %d %d %d %s at depth %d\\n",\n usage, selector, mtype,\n (mspki != NULL) ? "TA public key verified certificate" :\n mdpth ? "matched TA certificate" : "matched EE certificate",\n mdpth);\n }\n if (SSL_get_verify_result(s) == X509_V_OK &&\n (peername = SSL_get0_peername(s)) != NULL)\n BIO_printf(bio, "Verified peername: %s\\n", peername);\n BIO_printf(bio, (SSL_cache_hit(s) ? "---\\nReused, " : "---\\nNew, "));\n c = SSL_get_current_cipher(s);\n BIO_printf(bio, "%s, Cipher is %s\\n",\n SSL_CIPHER_get_version(c), SSL_CIPHER_get_name(c));\n if (peer != NULL) {\n EVP_PKEY *pktmp;\n pktmp = X509_get0_pubkey(peer);\n BIO_printf(bio, "Server public key is %d bit\\n",\n EVP_PKEY_bits(pktmp));\n }\n BIO_printf(bio, "Secure Renegotiation IS%s supported\\n",\n SSL_get_secure_renegotiation_support(s) ? "" : " NOT");\n#ifndef OPENSSL_NO_COMP\n comp = SSL_get_current_compression(s);\n expansion = SSL_get_current_expansion(s);\n BIO_printf(bio, "Compression: %s\\n",\n comp ? SSL_COMP_get_name(comp) : "NONE");\n BIO_printf(bio, "Expansion: %s\\n",\n expansion ? SSL_COMP_get_name(expansion) : "NONE");\n#endif\n#ifdef SSL_DEBUG\n {\n int sock;\n struct sockaddr_in ladd;\n socklen_t ladd_size = sizeof(ladd);\n sock = SSL_get_fd(s);\n getsockname(sock, (struct sockaddr *)&ladd, &ladd_size);\n BIO_printf(bio_c_out, "LOCAL PORT is %u\\n", ntohs(ladd.sin_port));\n }\n#endif\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n if (next_proto.status != -1) {\n const unsigned char *proto;\n unsigned int proto_len;\n SSL_get0_next_proto_negotiated(s, &proto, &proto_len);\n BIO_printf(bio, "Next protocol: (%d) ", next_proto.status);\n BIO_write(bio, proto, proto_len);\n BIO_write(bio, "\\n", 1);\n }\n#endif\n {\n const unsigned char *proto;\n unsigned int proto_len;\n SSL_get0_alpn_selected(s, &proto, &proto_len);\n if (proto_len > 0) {\n BIO_printf(bio, "ALPN protocol: ");\n BIO_write(bio, proto, proto_len);\n BIO_write(bio, "\\n", 1);\n } else\n BIO_printf(bio, "No ALPN negotiated\\n");\n }\n#ifndef OPENSSL_NO_SRTP\n {\n SRTP_PROTECTION_PROFILE *srtp_profile =\n SSL_get_selected_srtp_profile(s);\n if (srtp_profile)\n BIO_printf(bio, "SRTP Extension negotiated, profile=%s\\n",\n srtp_profile->name);\n }\n#endif\n SSL_SESSION_print(bio, SSL_get_session(s));\n if (keymatexportlabel != NULL) {\n BIO_printf(bio, "Keying material exporter:\\n");\n BIO_printf(bio, " Label: \'%s\'\\n", keymatexportlabel);\n BIO_printf(bio, " Length: %i bytes\\n", keymatexportlen);\n exportedkeymat = app_malloc(keymatexportlen, "export key");\n if (!SSL_export_keying_material(s, exportedkeymat,\n keymatexportlen,\n keymatexportlabel,\n strlen(keymatexportlabel),\n NULL, 0, 0)) {\n BIO_printf(bio, " Error\\n");\n } else {\n BIO_printf(bio, " Keying material: ");\n for (i = 0; i < keymatexportlen; i++)\n BIO_printf(bio, "%02X", exportedkeymat[i]);\n BIO_printf(bio, "\\n");\n }\n OPENSSL_free(exportedkeymat);\n }\n BIO_printf(bio, "---\\n");\n X509_free(peer);\n (void)BIO_flush(bio);\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}']
|
1,109
| 0
|
https://github.com/libav/libav/blob/f52edef30197735bfb937e9e723ab1e7b31165c6/libavformat/utils.c/#L2521
|
void avformat_free_context(AVFormatContext *s)
{
int i;
AVStream *st;
av_opt_free(s);
if (s->iformat && s->iformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
}
if (st->attached_pic.data)
av_free_packet(&st->attached_pic);
av_dict_free(&st->metadata);
av_freep(&st->probe_data.buf);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
av_dict_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
av_dict_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_dict_free(&s->metadata);
av_freep(&s->streams);
av_free(s);
}
|
['static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)\n{\n SegmentContext *seg = s->priv_data;\n AVFormatContext *oc = seg->avf;\n AVStream *st = s->streams[pkt->stream_index];\n int64_t end_pts = seg->recording_time * seg->number;\n int ret, can_split = 1;\n if (seg->has_video) {\n can_split = st->codec->codec_type == AVMEDIA_TYPE_VIDEO &&\n pkt->flags & AV_PKT_FLAG_KEY;\n }\n if (can_split && av_compare_ts(pkt->pts, st->time_base, end_pts,\n AV_TIME_BASE_Q) >= 0) {\n av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\\n",\n pkt->stream_index, pkt->pts);\n ret = segment_end(oc, seg->individual_header_trailer);\n if (!ret)\n ret = segment_start(s, seg->individual_header_trailer);\n if (ret)\n goto fail;\n oc = seg->avf;\n if (seg->list) {\n if (seg->list_type == LIST_HLS) {\n if ((ret = segment_hls_window(s, 0)) < 0)\n goto fail;\n } else {\n avio_printf(seg->pb, "%s\\n", oc->filename);\n avio_flush(seg->pb);\n if (seg->size && !(seg->number % seg->size)) {\n avio_closep(&seg->pb);\n if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,\n &s->interrupt_callback, NULL)) < 0)\n goto fail;\n }\n }\n }\n }\n ret = ff_write_chained(oc, pkt->stream_index, pkt, s);\nfail:\n if (ret < 0) {\n if (seg->list)\n avio_close(seg->pb);\n avformat_free_context(oc);\n }\n return ret;\n}', 'int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,\n AVFormatContext *src)\n{\n AVPacket local_pkt;\n local_pkt = *pkt;\n local_pkt.stream_index = dst_stream;\n if (pkt->pts != AV_NOPTS_VALUE)\n local_pkt.pts = av_rescale_q(pkt->pts,\n src->streams[pkt->stream_index]->time_base,\n dst->streams[dst_stream]->time_base);\n if (pkt->dts != AV_NOPTS_VALUE)\n local_pkt.dts = av_rescale_q(pkt->dts,\n src->streams[pkt->stream_index]->time_base,\n dst->streams[dst_stream]->time_base);\n return av_write_frame(dst, &local_pkt);\n}', 'int av_write_frame(AVFormatContext *s, AVPacket *pkt)\n{\n int ret;\n if (!pkt) {\n if (s->oformat->flags & AVFMT_ALLOW_FLUSH)\n return s->oformat->write_packet(s, pkt);\n return 1;\n }\n ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt);\n if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))\n return ret;\n ret = write_packet(s, pkt);\n if (ret >= 0)\n s->streams[pkt->stream_index]->nb_frames++;\n return ret;\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n }\n if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\n av_dict_free(&st->metadata);\n av_freep(&st->probe_data.buf);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_free(s);\n}']
|
1,110
| 0
|
https://gitlab.com/libtiff/libtiff/blob/3adc33842b7533066daea2516741832edc44d5fd/libtiff/tif_tile.c/#L159
|
uint32
TIFFNumberOfTiles(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
uint32 dx = td->td_tilewidth;
uint32 dy = td->td_tilelength;
uint32 dz = td->td_tiledepth;
uint32 ntiles;
if (dx == (uint32) -1)
dx = td->td_imagewidth;
if (dy == (uint32) -1)
dy = td->td_imagelength;
if (dz == (uint32) -1)
dz = td->td_imagedepth;
ntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :
multiply_32(tif, multiply_32(tif, TIFFhowmany_32(td->td_imagewidth, dx),
TIFFhowmany_32(td->td_imagelength, dy),
"TIFFNumberOfTiles"),
TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
ntiles = multiply_32(tif, ntiles, td->td_samplesperpixel,
"TIFFNumberOfTiles");
return (ntiles);
}
|
['tsize_t t2p_write_pdf(T2P* t2p, TIFF* input, TIFF* output){\n\ttsize_t written=0;\n\tttile_t i2=0;\n\ttsize_t streamlen=0;\n\tuint16 i=0;\n\tt2p_read_tiff_init(t2p, input);\n\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\tt2p->pdf_xrefoffsets= (uint32*) _TIFFmalloc(t2p->pdf_xrefcount * sizeof(uint32) );\n\tif(t2p->pdf_xrefoffsets==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %u bytes of memory for t2p_write_pdf",\n\t\t\tt2p->pdf_xrefcount * sizeof(uint32) );\n\t\treturn(written);\n\t}\n\tt2p->pdf_xrefcount=0;\n\tt2p->pdf_catalog=1;\n\tt2p->pdf_info=2;\n\tt2p->pdf_pages=3;\n\twritten += t2p_write_pdf_header(t2p, output);\n\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\tt2p->pdf_catalog=t2p->pdf_xrefcount;\n\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\twritten += t2p_write_pdf_catalog(t2p, output);\n\twritten += t2p_write_pdf_obj_end(output);\n\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\tt2p->pdf_info=t2p->pdf_xrefcount;\n\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\twritten += t2p_write_pdf_info(t2p, input, output);\n\twritten += t2p_write_pdf_obj_end(output);\n\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\tt2p->pdf_pages=t2p->pdf_xrefcount;\n\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\twritten += t2p_write_pdf_pages(t2p, output);\n\twritten += t2p_write_pdf_obj_end(output);\n\tfor(t2p->pdf_page=0;t2p->pdf_page<t2p->tiff_pagecount;t2p->pdf_page++){\n\t\tt2p_read_tiff_data(t2p, input);\n\t\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\twritten += t2p_write_pdf_page(t2p->pdf_xrefcount, t2p, output);\n\t\twritten += t2p_write_pdf_obj_end(output);\n\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\twritten += t2p_write_pdf_stream_dict(0, t2p->pdf_xrefcount+1, output);\n\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\twritten += t2p_write_pdf_stream_start(output);\n\t\tstreamlen=written;\n\t\twritten += t2p_write_pdf_page_content_stream(t2p, output);\n\t\tstreamlen=written-streamlen;\n\t\twritten += t2p_write_pdf_stream_end(output);\n\t\twritten += t2p_write_pdf_obj_end(output);\n\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\twritten += t2p_write_pdf_stream_length(streamlen, output);\n\t\twritten += t2p_write_pdf_obj_end(output);\n\t\tif(t2p->tiff_transferfunctioncount != 0){\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_transfer(t2p, output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\tfor(i=0; i < t2p->tiff_transferfunctioncount; i++){\n\t\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\t\twritten += t2p_write_pdf_transfer_dict(t2p, output, i);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\t\tstreamlen=written;\n\t\t\t\twritten += t2p_write_pdf_transfer_stream(t2p, output, i);\n\t\t\t\tstreamlen=written-streamlen;\n\t\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\t}\n\t\t}\n\t\tif( (t2p->pdf_colorspace & T2P_CS_PALETTE) != 0){\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\tt2p->pdf_palettecs=t2p->pdf_xrefcount;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\twritten += t2p_write_pdf_stream_dict(t2p->pdf_palettesize, 0, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\tstreamlen=written;\n\t\t\twritten += t2p_write_pdf_xobject_palettecs_stream(t2p, output);\n\t\t\tstreamlen=written-streamlen;\n\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t}\n\t\tif( (t2p->pdf_colorspace & T2P_CS_ICCBASED) != 0){\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\tt2p->pdf_icccs=t2p->pdf_xrefcount;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\twritten += t2p_write_pdf_xobject_icccs_dict(t2p, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\tstreamlen=written;\n\t\t\twritten += t2p_write_pdf_xobject_icccs_stream(t2p, output);\n\t\t\tstreamlen=written-streamlen;\n\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t}\n\t\tif(t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount !=0){\n\t\t\tfor(i2=0;i2<t2p->tiff_tiles[t2p->pdf_page].tiles_tilecount;i2++){\n\t\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\t\twritten += t2p_write_pdf_xobject_stream_dict(\n\t\t\t\t\ti2+1,\n\t\t\t\t\tt2p,\n\t\t\t\t\toutput);\n\t\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\t\tstreamlen=written;\n\t\t\t\tt2p_read_tiff_size_tile(t2p, input, i2);\n\t\t\t\twritten += t2p_readwrite_pdf_image_tile(t2p, input, output, i2);\n\t\t\t\tt2p_write_advance_directory(t2p, output);\n\t\t\t\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\t\t\t\tstreamlen=written-streamlen;\n\t\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\t\twritten += t2p_write_pdf_stream_length(streamlen, output);\n\t\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\t}\n\t\t} else {\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_dict_start(output);\n\t\t\twritten += t2p_write_pdf_xobject_stream_dict(\n\t\t\t\t0,\n\t\t\t\tt2p,\n\t\t\t\toutput);\n\t\t\twritten += t2p_write_pdf_stream_dict_end(output);\n\t\t\twritten += t2p_write_pdf_stream_start(output);\n\t\t\tstreamlen=written;\n\t\t\tt2p_read_tiff_size(t2p, input);\n\t\t\twritten += t2p_readwrite_pdf_image(t2p, input, output);\n\t\t\tt2p_write_advance_directory(t2p, output);\n\t\t\tif(t2p->t2p_error!=T2P_ERR_OK){return(0);}\n\t\t\tstreamlen=written-streamlen;\n\t\t\twritten += t2p_write_pdf_stream_end(output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t\tt2p->pdf_xrefoffsets[t2p->pdf_xrefcount++]=written;\n\t\t\twritten += t2p_write_pdf_obj_start(t2p->pdf_xrefcount, output);\n\t\t\twritten += t2p_write_pdf_stream_length(streamlen, output);\n\t\t\twritten += t2p_write_pdf_obj_end(output);\n\t\t}\n\t}\n\tt2p->pdf_startxref = written;\n\twritten += t2p_write_pdf_xreftable(t2p, output);\n\twritten += t2p_write_pdf_trailer(t2p, output);\n\tt2p_disable(output);\n\treturn(written);\n}', 'void t2p_read_tiff_init(T2P* t2p, TIFF* input){\n\ttdir_t directorycount=0;\n\ttdir_t i=0;\n\tuint16 pagen=0;\n\tuint16 paged=0;\n\tuint16 xuint16=0;\n\tdirectorycount=TIFFNumberOfDirectories(input);\n\tt2p->tiff_pages = (T2P_PAGE*) _TIFFmalloc(directorycount * sizeof(T2P_PAGE));\n\tif(t2p->tiff_pages==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %lu bytes of memory for tiff_pages array, %s",\n\t\t\t(unsigned long) directorycount * sizeof(T2P_PAGE),\n\t\t\tTIFFFileName(input));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\t_TIFFmemset( t2p->tiff_pages, 0x00, directorycount * sizeof(T2P_PAGE));\n\tt2p->tiff_tiles = (T2P_TILES*) _TIFFmalloc(directorycount * sizeof(T2P_TILES));\n\tif(t2p->tiff_tiles==NULL){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Can\'t allocate %lu bytes of memory for tiff_tiles array, %s",\n\t\t\t(unsigned long) directorycount * sizeof(T2P_TILES),\n\t\t\tTIFFFileName(input));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\t_TIFFmemset( t2p->tiff_tiles, 0x00, directorycount * sizeof(T2P_TILES));\n\tfor(i=0;i<directorycount;i++){\n\t\tuint32 subfiletype = 0;\n\t\tif(!TIFFSetDirectory(input, i)){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"Can\'t set directory %u of input file %s",\n\t\t\t\ti,\n\t\t\t\tTIFFFileName(input));\n\t\t\treturn;\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_PAGENUMBER, &pagen, &paged)){\n\t\t\tif((pagen>paged) && (paged != 0)){\n\t\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number =\n\t\t\t\t\tpaged;\n\t\t\t} else {\n\t\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number =\n\t\t\t\t\tpagen;\n\t\t\t}\n\t\t\tgoto ispage2;\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_SUBFILETYPE, &subfiletype)){\n\t\t\tif ( ((subfiletype & FILETYPE_PAGE) != 0)\n || (subfiletype == 0)){\n\t\t\t\tgoto ispage;\n\t\t\t} else {\n\t\t\t\tgoto isnotpage;\n\t\t\t}\n\t\t}\n\t\tif(TIFFGetField(input, TIFFTAG_OSUBFILETYPE, &subfiletype)){\n\t\t\tif ((subfiletype == OFILETYPE_IMAGE)\n\t\t\t\t|| (subfiletype == OFILETYPE_PAGE)\n\t\t\t\t|| (subfiletype == 0) ){\n\t\t\t\tgoto ispage;\n\t\t\t} else {\n\t\t\t\tgoto isnotpage;\n\t\t\t}\n\t\t}\n\t\tispage:\n\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_number=t2p->tiff_pagecount;\n\t\tispage2:\n\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_directory=i;\n\t\tif(TIFFIsTiled(input)){\n\t\t\tt2p->tiff_pages[t2p->tiff_pagecount].page_tilecount =\n\t\t\t\tTIFFNumberOfTiles(input);\n\t\t}\n\t\tt2p->tiff_pagecount++;\n\t\tisnotpage:\n\t\t(void)0;\n\t}\n\tqsort((void*) t2p->tiff_pages, t2p->tiff_pagecount,\n sizeof(T2P_PAGE), t2p_cmp_t2p_page);\n\tfor(i=0;i<t2p->tiff_pagecount;i++){\n\t\tt2p->pdf_xrefcount += 5;\n\t\tTIFFSetDirectory(input, t2p->tiff_pages[i].page_directory );\n\t\tif((TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &xuint16)\n && (xuint16==PHOTOMETRIC_PALETTE))\n\t\t || TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)) {\n\t\t\tt2p->tiff_pages[i].page_extra++;\n\t\t\tt2p->pdf_xrefcount++;\n\t\t}\n#ifdef ZIP_SUPPORT\n\t\tif (TIFFGetField(input, TIFFTAG_COMPRESSION, &xuint16)) {\n if( (xuint16== COMPRESSION_DEFLATE ||\n xuint16== COMPRESSION_ADOBE_DEFLATE) &&\n ((t2p->tiff_pages[i].page_tilecount != 0)\n || TIFFNumberOfStrips(input)==1) &&\n (t2p->pdf_nopassthrough==0)\t){\n if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}\n }\n }\n#endif\n\t\tif (TIFFGetField(input, TIFFTAG_TRANSFERFUNCTION,\n &(t2p->tiff_transferfunction[0]),\n &(t2p->tiff_transferfunction[1]),\n &(t2p->tiff_transferfunction[2]))) {\n\t\t\tif(t2p->tiff_transferfunction[1] !=\n\t\t\t t2p->tiff_transferfunction[0]) {\n\t\t\t\tt2p->tiff_transferfunctioncount = 3;\n\t\t\t\tt2p->tiff_pages[i].page_extra += 4;\n\t\t\t\tt2p->pdf_xrefcount += 4;\n\t\t\t} else {\n\t\t\t\tt2p->tiff_transferfunctioncount = 1;\n\t\t\t\tt2p->tiff_pages[i].page_extra += 2;\n\t\t\t\tt2p->pdf_xrefcount += 2;\n\t\t\t}\n\t\t\tif(t2p->pdf_minorversion < 2)\n\t\t\t\tt2p->pdf_minorversion = 2;\n } else {\n\t\t\tt2p->tiff_transferfunctioncount=0;\n\t\t}\n\t\tif( TIFFGetField(\n\t\t\tinput,\n\t\t\tTIFFTAG_ICCPROFILE,\n\t\t\t&(t2p->tiff_iccprofilelength),\n\t\t\t&(t2p->tiff_iccprofile)) != 0){\n\t\t\tt2p->tiff_pages[i].page_extra++;\n\t\t\tt2p->pdf_xrefcount++;\n\t\t\tif(t2p->pdf_minorversion<3){t2p->pdf_minorversion=3;}\n\t\t}\n\t\tt2p->tiff_tiles[i].tiles_tilecount=\n\t\t\tt2p->tiff_pages[i].page_tilecount;\n\t\tif( (TIFFGetField(input, TIFFTAG_PLANARCONFIG, &xuint16) != 0)\n\t\t\t&& (xuint16 == PLANARCONFIG_SEPARATE ) ){\n\t\t\t\tTIFFGetField(input, TIFFTAG_SAMPLESPERPIXEL, &xuint16);\n\t\t\t\tt2p->tiff_tiles[i].tiles_tilecount/= xuint16;\n\t\t}\n\t\tif( t2p->tiff_tiles[i].tiles_tilecount > 0){\n\t\t\tt2p->pdf_xrefcount +=\n\t\t\t\t(t2p->tiff_tiles[i].tiles_tilecount -1)*2;\n\t\t\tTIFFGetField(input,\n\t\t\t\tTIFFTAG_TILEWIDTH,\n\t\t\t\t&( t2p->tiff_tiles[i].tiles_tilewidth) );\n\t\t\tTIFFGetField(input,\n\t\t\t\tTIFFTAG_TILELENGTH,\n\t\t\t\t&( t2p->tiff_tiles[i].tiles_tilelength) );\n\t\t\tt2p->tiff_tiles[i].tiles_tiles =\n\t\t\t(T2P_TILE*) _TIFFmalloc(\n\t\t\t\tt2p->tiff_tiles[i].tiles_tilecount\n\t\t\t\t* sizeof(T2P_TILE) );\n\t\t\tif( t2p->tiff_tiles[i].tiles_tiles == NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory for t2p_read_tiff_init, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_tiles[i].tiles_tilecount * sizeof(T2P_TILE),\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\treturn;\n}', 'void t2p_read_tiff_data(T2P* t2p, TIFF* input){\n\tint i=0;\n\tuint16* r;\n\tuint16* g;\n\tuint16* b;\n\tuint16* a;\n\tuint16 xuint16;\n\tuint16* xuint16p;\n\tfloat* xfloatp;\n\tt2p->pdf_transcode = T2P_TRANSCODE_ENCODE;\n\tt2p->pdf_sample = T2P_SAMPLE_NOTHING;\n t2p->pdf_switchdecode = t2p->pdf_colorspace_invert;\n\tTIFFSetDirectory(input, t2p->tiff_pages[t2p->pdf_page].page_directory);\n\tTIFFGetField(input, TIFFTAG_IMAGEWIDTH, &(t2p->tiff_width));\n\tif(t2p->tiff_width == 0){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with zero width",\n\t\t\tTIFFFileName(input)\t);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\tTIFFGetField(input, TIFFTAG_IMAGELENGTH, &(t2p->tiff_length));\n\tif(t2p->tiff_length == 0){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with zero length",\n\t\t\tTIFFFileName(input)\t);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n if(TIFFGetField(input, TIFFTAG_COMPRESSION, &(t2p->tiff_compression)) == 0){\n TIFFError(\n TIFF2PDF_MODULE,\n "No support for %s with no compression tag",\n TIFFFileName(input) );\n t2p->t2p_error = T2P_ERR_ERROR;\n return;\n }\n if( TIFFIsCODECConfigured(t2p->tiff_compression) == 0){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with compression type %u: not configured",\n\t\t\tTIFFFileName(input),\n\t\t\tt2p->tiff_compression\n\t\t\t);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\tTIFFGetFieldDefaulted(input, TIFFTAG_BITSPERSAMPLE, &(t2p->tiff_bitspersample));\n\tswitch(t2p->tiff_bitspersample){\n\t\tcase 1:\n\t\tcase 2:\n\t\tcase 4:\n\t\tcase 8:\n\t\t\tbreak;\n\t\tcase 0:\n\t\t\tTIFFWarning(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"Image %s has 0 bits per sample, assuming 1",\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->tiff_bitspersample=1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with %u bits per sample",\n\t\t\t\tTIFFFileName(input),\n\t\t\t\tt2p->tiff_bitspersample);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn;\n\t}\n\tTIFFGetFieldDefaulted(input, TIFFTAG_SAMPLESPERPIXEL, &(t2p->tiff_samplesperpixel));\n\tif(t2p->tiff_samplesperpixel>4){\n\t\tTIFFError(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"No support for %s with %u samples per pixel",\n\t\t\tTIFFFileName(input),\n\t\t\tt2p->tiff_samplesperpixel);\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn;\n\t}\n\tif(t2p->tiff_samplesperpixel==0){\n\t\tTIFFWarning(\n\t\t\tTIFF2PDF_MODULE,\n\t\t\t"Image %s has 0 samples per pixel, assuming 1",\n\t\t\tTIFFFileName(input));\n\t\tt2p->tiff_samplesperpixel=1;\n\t}\n\tif(TIFFGetField(input, TIFFTAG_SAMPLEFORMAT, &xuint16) != 0 ){\n\t\tswitch(xuint16){\n\t\t\tcase 0:\n\t\t\tcase 1:\n\t\t\tcase 4:\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for %s with sample format %u",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\txuint16);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tTIFFGetFieldDefaulted(input, TIFFTAG_FILLORDER, &(t2p->tiff_fillorder));\n if(TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &(t2p->tiff_photometric)) == 0){\n TIFFError(\n TIFF2PDF_MODULE,\n "No support for %s with no photometric interpretation tag",\n TIFFFileName(input) );\n t2p->t2p_error = T2P_ERR_ERROR;\n return;\n }\n\tswitch(t2p->tiff_photometric){\n\t\tcase PHOTOMETRIC_MINISWHITE:\n\t\tcase PHOTOMETRIC_MINISBLACK:\n\t\t\tif (t2p->tiff_bitspersample==1){\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_BILEVEL;\n\t\t\t\tif(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){\n\t\t\t\t\tt2p->pdf_switchdecode ^= 1;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_GRAY;\n\t\t\t\tif(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){\n\t\t\t\t\tt2p->pdf_switchdecode ^= 1;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_RGB:\n\t\t\tt2p->pdf_colorspace=T2P_CS_RGB;\n\t\t\tif(t2p->tiff_samplesperpixel == 3){\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)){\n\t\t\t\tif(xuint16==1)\n\t\t\t\t\tgoto photometric_palette;\n\t\t\t}\n\t\t\tif(t2p->tiff_samplesperpixel > 3) {\n\t\t\t\tif(t2p->tiff_samplesperpixel == 4) {\n\t\t\t\t\tt2p->pdf_colorspace = T2P_CS_RGB;\n\t\t\t\t\tif(TIFFGetField(input,\n\t\t\t\t\t\t\tTIFFTAG_EXTRASAMPLES,\n\t\t\t\t\t\t\t&xuint16, &xuint16p)\n\t\t\t\t\t && xuint16 == 1) {\n\t\t\t\t\t\tif(xuint16p[0] == EXTRASAMPLE_ASSOCALPHA){\n\t\t\t\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_RGBAA_TO_RGB;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif(xuint16p[0] == EXTRASAMPLE_UNASSALPHA){\n\t\t\t\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_RGBA_TO_RGB;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tTIFFWarning(\n\t\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t\t"RGB image %s has 4 samples per pixel, assuming RGBA",\n\t\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tt2p->pdf_colorspace=T2P_CS_CMYK;\n\t\t\t\t\tt2p->pdf_switchdecode ^= 1;\n\t\t\t\t\tTIFFWarning(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"RGB image %s has 4 samples per pixel, assuming inverse CMYK",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tTIFFError(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"No support for RGB image %s with %u samples per pixel",\n\t\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\t\tt2p->tiff_samplesperpixel);\n\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for RGB image %s with %u samples per pixel",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\tt2p->tiff_samplesperpixel);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tcase PHOTOMETRIC_PALETTE:\n\t\t\tphotometric_palette:\n\t\t\tif(t2p->tiff_samplesperpixel!=1){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for palettized image %s with not one sample per pixel",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tt2p->pdf_colorspace=T2P_CS_RGB | T2P_CS_PALETTE;\n\t\t\tt2p->pdf_palettesize=0x0001<<t2p->tiff_bitspersample;\n\t\t\tif(!TIFFGetField(input, TIFFTAG_COLORMAP, &r, &g, &b)){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Palettized image %s has no color map",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(t2p->pdf_palette != NULL){\n\t\t\t\t_TIFFfree(t2p->pdf_palette);\n\t\t\t\tt2p->pdf_palette=NULL;\n\t\t\t}\n\t\t\tt2p->pdf_palette = (unsigned char*)\n\t\t\t\t_TIFFmalloc(t2p->pdf_palettesize*3);\n\t\t\tif(t2p->pdf_palette==NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %u bytes of memory for t2p_read_tiff_image, %s",\n\t\t\t\t\tt2p->pdf_palettesize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(i=0;i<t2p->pdf_palettesize;i++){\n\t\t\t\tt2p->pdf_palette[(i*3)] = (unsigned char) (r[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*3)+1]= (unsigned char) (g[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*3)+2]= (unsigned char) (b[i]>>8);\n\t\t\t}\n\t\t\tt2p->pdf_palettesize *= 3;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_SEPARATED:\n\t\t\tif(TIFFGetField(input, TIFFTAG_INDEXED, &xuint16)){\n\t\t\t\tif(xuint16==1){\n\t\t\t\t\t\tgoto photometric_palette_cmyk;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif( TIFFGetField(input, TIFFTAG_INKSET, &xuint16) ){\n\t\t\t\tif(xuint16 != INKSET_CMYK){\n\t\t\t\t\tTIFFError(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"No support for %s because its inkset is not CMYK",\n\t\t\t\t\t\tTIFFFileName(input) );\n\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(t2p->tiff_samplesperpixel==4){\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_CMYK;\n\t\t\t} else {\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for %s because it has %u samples per pixel",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\tt2p->tiff_samplesperpixel);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tbreak;\n\t\t\tphotometric_palette_cmyk:\n\t\t\tif(t2p->tiff_samplesperpixel!=1){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for palettized CMYK image %s with not one sample per pixel",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tt2p->pdf_colorspace=T2P_CS_CMYK | T2P_CS_PALETTE;\n\t\t\tt2p->pdf_palettesize=0x0001<<t2p->tiff_bitspersample;\n\t\t\tif(!TIFFGetField(input, TIFFTAG_COLORMAP, &r, &g, &b, &a)){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Palettized image %s has no color map",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif(t2p->pdf_palette != NULL){\n\t\t\t\t_TIFFfree(t2p->pdf_palette);\n\t\t\t\tt2p->pdf_palette=NULL;\n\t\t\t}\n\t\t\tt2p->pdf_palette = (unsigned char*)\n\t\t\t\t_TIFFmalloc(t2p->pdf_palettesize*4);\n\t\t\tif(t2p->pdf_palette==NULL){\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %u bytes of memory for t2p_read_tiff_image, %s",\n\t\t\t\t\tt2p->pdf_palettesize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tfor(i=0;i<t2p->pdf_palettesize;i++){\n\t\t\t\tt2p->pdf_palette[(i*4)] = (unsigned char) (r[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*4)+1]= (unsigned char) (g[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*4)+2]= (unsigned char) (b[i]>>8);\n\t\t\t\tt2p->pdf_palette[(i*4)+3]= (unsigned char) (a[i]>>8);\n\t\t\t}\n\t\t\tt2p->pdf_palettesize *= 4;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_YCBCR:\n\t\t\tt2p->pdf_colorspace=T2P_CS_RGB;\n\t\t\tif(t2p->tiff_samplesperpixel==1){\n\t\t\t\tt2p->pdf_colorspace=T2P_CS_GRAY;\n\t\t\t\tt2p->tiff_photometric=PHOTOMETRIC_MINISBLACK;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tt2p->pdf_sample=T2P_SAMPLE_YCBCR_TO_RGB;\n#ifdef JPEG_SUPPORT\n\t\t\tif(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){\n\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_NOTHING;\n\t\t\t}\n#endif\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_CIELAB:\n\t\t\tt2p->pdf_labrange[0]= -127;\n\t\t\tt2p->pdf_labrange[1]= 127;\n\t\t\tt2p->pdf_labrange[2]= -127;\n\t\t\tt2p->pdf_labrange[3]= 127;\n\t\t\tt2p->pdf_sample=T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED;\n\t\t\tt2p->pdf_colorspace=T2P_CS_LAB;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_ICCLAB:\n\t\t\tt2p->pdf_labrange[0]= 0;\n\t\t\tt2p->pdf_labrange[1]= 255;\n\t\t\tt2p->pdf_labrange[2]= 0;\n\t\t\tt2p->pdf_labrange[3]= 255;\n\t\t\tt2p->pdf_colorspace=T2P_CS_LAB;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_ITULAB:\n\t\t\tt2p->pdf_labrange[0]=-85;\n\t\t\tt2p->pdf_labrange[1]=85;\n\t\t\tt2p->pdf_labrange[2]=-75;\n\t\t\tt2p->pdf_labrange[3]=124;\n\t\t\tt2p->pdf_sample=T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED;\n\t\t\tt2p->pdf_colorspace=T2P_CS_LAB;\n\t\t\tbreak;\n\t\tcase PHOTOMETRIC_LOGL:\n\t\tcase PHOTOMETRIC_LOGLUV:\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with photometric interpretation LogL/LogLuv",\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn;\n\t\tdefault:\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with photometric interpretation %u",\n\t\t\t\tTIFFFileName(input),\n\t\t\t\tt2p->tiff_photometric);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn;\n\t}\n\tif(TIFFGetField(input, TIFFTAG_PLANARCONFIG, &(t2p->tiff_planar))){\n\t\tswitch(t2p->tiff_planar){\n\t\t\tcase 0:\n\t\t\t\tTIFFWarning(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"Image %s has planar configuration 0, assuming 1",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->tiff_planar=PLANARCONFIG_CONTIG;\n\t\t\tcase PLANARCONFIG_CONTIG:\n\t\t\t\tbreak;\n\t\t\tcase PLANARCONFIG_SEPARATE:\n\t\t\t\tt2p->pdf_sample=T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG;\n\t\t\t\tif(t2p->tiff_bitspersample!=8){\n\t\t\t\t\tTIFFError(\n\t\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t\t"No support for %s with separated planar configuration and %u bits per sample",\n\t\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\t\tt2p->tiff_bitspersample);\n\t\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tTIFFError(\n\t\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t\t"No support for %s with planar configuration %u",\n\t\t\t\t\tTIFFFileName(input),\n\t\t\t\t\tt2p->tiff_planar);\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn;\n\t\t}\n\t}\n TIFFGetFieldDefaulted(input, TIFFTAG_ORIENTATION,\n &(t2p->tiff_orientation));\n if(t2p->tiff_orientation>8){\n TIFFWarning(TIFF2PDF_MODULE,\n "Image %s has orientation %u, assuming 0",\n TIFFFileName(input), t2p->tiff_orientation);\n t2p->tiff_orientation=0;\n }\n if(TIFFGetField(input, TIFFTAG_XRESOLUTION, &(t2p->tiff_xres) ) == 0){\n t2p->tiff_xres=0.0;\n }\n if(TIFFGetField(input, TIFFTAG_YRESOLUTION, &(t2p->tiff_yres) ) == 0){\n t2p->tiff_yres=0.0;\n }\n\tTIFFGetFieldDefaulted(input, TIFFTAG_RESOLUTIONUNIT,\n\t\t\t &(t2p->tiff_resunit));\n\tif(t2p->tiff_resunit == RESUNIT_CENTIMETER) {\n\t\tt2p->tiff_xres *= 2.54F;\n\t\tt2p->tiff_yres *= 2.54F;\n\t} else if (t2p->tiff_resunit != RESUNIT_INCH\n\t\t && t2p->pdf_centimeters != 0) {\n\t\tt2p->tiff_xres *= 2.54F;\n\t\tt2p->tiff_yres *= 2.54F;\n\t}\n\tt2p_compose_pdf_page(t2p);\n\tt2p->pdf_transcode = T2P_TRANSCODE_ENCODE;\n\tif(t2p->pdf_nopassthrough==0){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->tiff_compression==COMPRESSION_CCITTFAX4\n\t\t\t){\n\t\t\tif(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){\n\t\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\t\tt2p->pdf_compression=T2P_COMPRESS_G4;\n\t\t\t}\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->tiff_compression== COMPRESSION_ADOBE_DEFLATE\n\t\t\t|| t2p->tiff_compression==COMPRESSION_DEFLATE){\n\t\t\tif(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){\n\t\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\t\tt2p->pdf_compression=T2P_COMPRESS_ZIP;\n\t\t\t}\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression==COMPRESSION_OJPEG){\n\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\tt2p->pdf_compression=T2P_COMPRESS_JPEG;\n\t\t\tt2p_process_ojpeg_tables(t2p, input);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression==COMPRESSION_JPEG){\n\t\t\tt2p->pdf_transcode = T2P_TRANSCODE_RAW;\n\t\t\tt2p->pdf_compression=T2P_COMPRESS_JPEG;\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_transcode!=T2P_TRANSCODE_RAW){\n\t\tt2p->pdf_compression = t2p->pdf_defaultcompression;\n\t}\n#ifdef JPEG_SUPPORT\n\tif(t2p->pdf_defaultcompression==T2P_COMPRESS_JPEG){\n\t\tif(t2p->pdf_colorspace & T2P_CS_PALETTE){\n\t\t\tt2p->pdf_sample|=T2P_SAMPLE_REALIZE_PALETTE;\n\t\t\tt2p->pdf_colorspace ^= T2P_CS_PALETTE;\n\t\t\tt2p->tiff_pages[t2p->pdf_page].page_extra--;\n\t\t}\n\t}\n\tif(t2p->tiff_compression==COMPRESSION_JPEG){\n\t\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with JPEG compression and separated planar configuration",\n\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn;\n\t\t}\n\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\tif(t2p->tiff_compression==COMPRESSION_OJPEG){\n\t\tif(t2p->tiff_planar==PLANARCONFIG_SEPARATE){\n\t\t\tTIFFError(\n\t\t\t\tTIFF2PDF_MODULE,\n\t\t\t\t"No support for %s with OJPEG compression and separated planar configuration",\n\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn;\n\t\t}\n\t}\n#endif\n\tif(t2p->pdf_sample & T2P_SAMPLE_REALIZE_PALETTE){\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\tt2p->tiff_samplesperpixel=4;\n\t\t\tt2p->tiff_photometric=PHOTOMETRIC_SEPARATED;\n\t\t} else {\n\t\t\tt2p->tiff_samplesperpixel=3;\n\t\t\tt2p->tiff_photometric=PHOTOMETRIC_RGB;\n\t\t}\n\t}\n\tif (TIFFGetField(input, TIFFTAG_TRANSFERFUNCTION,\n\t\t\t &(t2p->tiff_transferfunction[0]),\n\t\t\t &(t2p->tiff_transferfunction[1]),\n\t\t\t &(t2p->tiff_transferfunction[2]))) {\n\t\tif(t2p->tiff_transferfunction[1] !=\n\t\t t2p->tiff_transferfunction[0]) {\n\t\t\tt2p->tiff_transferfunctioncount=3;\n\t\t} else {\n\t\t\tt2p->tiff_transferfunctioncount=1;\n\t\t}\n\t} else {\n\t\tt2p->tiff_transferfunctioncount=0;\n\t}\n\tif(TIFFGetField(input, TIFFTAG_WHITEPOINT, &xfloatp)!=0){\n\t\tt2p->tiff_whitechromaticities[0]=xfloatp[0];\n\t\tt2p->tiff_whitechromaticities[1]=xfloatp[1];\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\tt2p->pdf_colorspace |= T2P_CS_CALGRAY;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_RGB){\n\t\t\tt2p->pdf_colorspace |= T2P_CS_CALRGB;\n\t\t}\n\t}\n\tif(TIFFGetField(input, TIFFTAG_PRIMARYCHROMATICITIES, &xfloatp)!=0){\n\t\tt2p->tiff_primarychromaticities[0]=xfloatp[0];\n\t\tt2p->tiff_primarychromaticities[1]=xfloatp[1];\n\t\tt2p->tiff_primarychromaticities[2]=xfloatp[2];\n\t\tt2p->tiff_primarychromaticities[3]=xfloatp[3];\n\t\tt2p->tiff_primarychromaticities[4]=xfloatp[4];\n\t\tt2p->tiff_primarychromaticities[5]=xfloatp[5];\n\t\tif(t2p->pdf_colorspace & T2P_CS_RGB){\n\t\t\tt2p->pdf_colorspace |= T2P_CS_CALRGB;\n\t\t}\n\t}\n\tif(t2p->pdf_colorspace & T2P_CS_LAB){\n\t\tif(TIFFGetField(input, TIFFTAG_WHITEPOINT, &xfloatp) != 0){\n\t\t\tt2p->tiff_whitechromaticities[0]=xfloatp[0];\n\t\t\tt2p->tiff_whitechromaticities[1]=xfloatp[1];\n\t\t} else {\n\t\t\tt2p->tiff_whitechromaticities[0]=0.3457F;\n\t\t\tt2p->tiff_whitechromaticities[1]=0.3585F;\n\t\t}\n\t}\n\tif(TIFFGetField(input,\n\t\tTIFFTAG_ICCPROFILE,\n\t\t&(t2p->tiff_iccprofilelength),\n\t\t&(t2p->tiff_iccprofile))!=0){\n\t\tt2p->pdf_colorspace |= T2P_CS_ICCBASED;\n\t} else {\n\t\tt2p->tiff_iccprofilelength=0;\n\t\tt2p->tiff_iccprofile=NULL;\n\t}\n#ifdef CCITT_SUPPORT\n\tif( t2p->tiff_bitspersample==1 &&\n\t\tt2p->tiff_samplesperpixel==1){\n\t\tt2p->pdf_compression = T2P_COMPRESS_G4;\n\t}\n#endif\n\treturn;\n}', 'int\nTIFFSetDirectory(TIFF* tif, uint16 dirn)\n{\n\tuint64 nextdir;\n\tuint16 n;\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\telse\n\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\tfor (n = dirn; n > 0 && nextdir != 0; n--)\n\t\tif (!TIFFAdvanceDirectory(tif, &nextdir, NULL))\n\t\t\treturn (0);\n\ttif->tif_nextdiroff = nextdir;\n\ttif->tif_curdir = (dirn - n) - 1;\n\ttif->tif_dirnumber = 0;\n\treturn (TIFFReadDirectory(tif));\n}', 'tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){\n\tuint16 edge=0;\n\ttsize_t written=0;\n\tunsigned char* buffer=NULL;\n\ttsize_t bufferoffset=0;\n\tunsigned char* samplebuffer=NULL;\n\ttsize_t samplebufferoffset=0;\n\ttsize_t read=0;\n\tuint16 i=0;\n\tttile_t tilecount=0;\n\ttsize_t tilesize=0;\n\tttile_t septilecount=0;\n\ttsize_t septilesize=0;\n#ifdef JPEG_SUPPORT\n\tunsigned char* jpt;\n\tfloat* xfloatp;\n\tuint32 xuint32=0;\n#endif\n\tedge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tedge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tif( (t2p->pdf_transcode == T2P_TRANSCODE_RAW) && ((edge == 0)\n#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)\n\t\t|| (t2p->pdf_compression == T2P_COMPRESS_JPEG)\n#endif\n\t)\n\t){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(! t2p->pdf_ojpegdata){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"No support for OJPEG image %s with "\n "bad tables",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tbuffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\t_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);\n\t\t\tif(edge!=0){\n\t\t\t\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[7]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength >> 8) & 0xff;\n\t\t\t\t\tbuffer[8]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength ) & 0xff;\n\t\t\t\t}\n\t\t\t\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[9]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth >> 8) & 0xff;\n\t\t\t\t\tbuffer[10]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth ) & 0xff;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbufferoffset=t2p->pdf_ojpegdatalength;\n\t\t\tbufferoffset+=TIFFReadRawTile(input,\n\t\t\t\t\ttile,\n\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t-1);\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xff;\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xd9;\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG){\n\t\t\tunsigned char table_end[2];\n\t\t\tuint32 count = 0;\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\tt2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {\n\t\t\t\tif (count > 0) {\n\t\t\t\t\t_TIFFmemcpy(buffer, jpt, count);\n\t\t\t\t\tbufferoffset += count - 2;\n\t\t\t\t\ttable_end[0] = buffer[bufferoffset-2];\n\t\t\t\t\ttable_end[1] = buffer[bufferoffset-1];\n\t\t\t\t}\n\t\t\t\tif (count > 0) {\n\t\t\t\t\txuint32 = bufferoffset;\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset-2]),\n\t\t\t\t\t\t-1);\n\t\t\t\t\t\tbuffer[xuint32-2]=table_end[0];\n\t\t\t\t\t\tbuffer[xuint32-1]=table_end[1];\n\t\t\t\t} else {\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t\t-1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_sample==T2P_SAMPLE_NOTHING){\n\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\tif(buffer==NULL){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Can\'t allocate %lu bytes of memory for "\n "t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tread = TIFFReadEncodedTile(\n\t\t\tinput,\n\t\t\ttile,\n\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\tt2p->tiff_datasize);\n\t\tif(read==-1){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\ttile,\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t} else {\n\t\tif(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){\n\t\t\tseptilesize=TIFFTileSize(input);\n\t\t\tseptilecount=TIFFNumberOfTiles(input);\n\t\t\ttilesize=septilesize*t2p->tiff_samplesperpixel;\n\t\t\ttilecount=septilecount/t2p->tiff_samplesperpixel;\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(samplebuffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebufferoffset=0;\n\t\t\tfor(i=0;i<t2p->tiff_samplesperpixel;i++){\n\t\t\t\tread =\n\t\t\t\t\tTIFFReadEncodedTile(input,\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\t(tdata_t) &(samplebuffer[samplebufferoffset]),\n\t\t\t\t\t\tseptilesize);\n\t\t\t\tif(read==-1){\n\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t_TIFFfree(samplebuffer);\n\t\t\t\t\t\t_TIFFfree(buffer);\n\t\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t\tsamplebufferoffset+=read;\n\t\t\t}\n\t\t\tt2p_sample_planar_separate_to_contig(\n\t\t\t\tt2p,\n\t\t\t\t&(buffer[bufferoffset]),\n\t\t\t\tsamplebuffer,\n\t\t\t\tsamplebufferoffset);\n\t\t\tbufferoffset+=samplebufferoffset;\n\t\t\t_TIFFfree(samplebuffer);\n\t\t}\n\t\tif(buffer==NULL){\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tread = TIFFReadEncodedTile(\n\t\t\t\tinput,\n\t\t\t\ttile,\n\t\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\t\tt2p->tiff_datasize);\n\t\t\tif(read==-1){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\ttile,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t_TIFFfree(buffer);\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgba_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBAA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgbaa_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"No support for YCbCr to RGB in tile for %s",\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED){\n\t\t\tt2p->tiff_datasize=t2p_sample_lab_signed_to_unsigned(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t}\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) != 0){\n\t\tt2p_tile_collapse_left(\n\t\t\tbuffer,\n\t\t\tTIFFTileRowSize(input),\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t}\n\tt2p_disable(output);\n\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric);\n\tTIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample);\n\tTIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel);\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);\n\t}\n\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t}\n\tTIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);\n\tTIFFSetField(output, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);\n\tswitch(t2p->pdf_compression){\n\tcase T2P_COMPRESS_NONE:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\t\tbreak;\n#ifdef CCITT_SUPPORT\n\tcase T2P_COMPRESS_G4:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);\n\t\tbreak;\n#endif\n#ifdef JPEG_SUPPORT\n\tcase T2P_COMPRESS_JPEG:\n\t\tif (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) {\n\t\t\tuint16 hor = 0, ver = 0;\n\t\t\tif (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) {\n\t\t\t\tif (hor != 0 && ver != 0) {\n\t\t\t\t\tTIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){\n\t\t\t\tTIFFSetField(output, TIFFTAG_REFERENCEBLACKWHITE, xfloatp);\n\t\t\t}\n\t\t}\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n\t\tTIFFSetField(output, TIFFTAG_JPEGTABLESMODE, 0);\n\t\tif(t2p->pdf_colorspace & (T2P_CS_RGB | T2P_CS_LAB)){\n\t\t\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n\t\t\tif(t2p->tiff_photometric != PHOTOMETRIC_YCBCR){\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n\t\t\t} else {\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_JPEGQUALITY,\n\t\t\t\tt2p->pdf_defaultcompressionquality);\n\t\t}\n\t\tbreak;\n#endif\n#ifdef ZIP_SUPPORT\n\tcase T2P_COMPRESS_ZIP:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);\n\t\tif(t2p->pdf_defaultcompressionquality%100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_PREDICTOR,\n\t\t\t\tt2p->pdf_defaultcompressionquality % 100);\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality/100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_ZIPQUALITY,\n\t\t\t\t(t2p->pdf_defaultcompressionquality / 100));\n\t\t}\n\t\tbreak;\n#endif\n\tdefault:\n\t\tbreak;\n\t}\n\tt2p_enable(output);\n\tt2p->outputwritten = 0;\n\tbufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer,\n\t\t\t\t\t TIFFStripSize(output));\n\tif (buffer != NULL) {\n\t\t_TIFFfree(buffer);\n\t\tbuffer = NULL;\n\t}\n\tif (bufferoffset == -1) {\n\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t "Error writing encoded tile to output PDF %s",\n\t\t\t TIFFFileName(output));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn(0);\n\t}\n\twritten = t2p->outputwritten;\n\treturn(written);\n}', 'uint32\nTIFFNumberOfTiles(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 dx = td->td_tilewidth;\n\tuint32 dy = td->td_tilelength;\n\tuint32 dz = td->td_tiledepth;\n\tuint32 ntiles;\n\tif (dx == (uint32) -1)\n\t\tdx = td->td_imagewidth;\n\tif (dy == (uint32) -1)\n\t\tdy = td->td_imagelength;\n\tif (dz == (uint32) -1)\n\t\tdz = td->td_imagedepth;\n\tntiles = (dx == 0 || dy == 0 || dz == 0) ? 0 :\n\t multiply_32(tif, multiply_32(tif, TIFFhowmany_32(td->td_imagewidth, dx),\n\t TIFFhowmany_32(td->td_imagelength, dy),\n\t "TIFFNumberOfTiles"),\n\t TIFFhowmany_32(td->td_imagedepth, dz), "TIFFNumberOfTiles");\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tntiles = multiply_32(tif, ntiles, td->td_samplesperpixel,\n\t\t "TIFFNumberOfTiles");\n\treturn (ntiles);\n}']
|
1,111
| 0
|
https://github.com/libav/libav/blob/c41b9842ceac42bedfd74a7ba2d02add82f818a9/libavcodec/rv40.c/#L518
|
static void rv40_loop_filter(RV34DecContext *r, int row)
{
MpegEncContext *s = &r->s;
int mb_pos, mb_x;
int i, j, k;
uint8_t *Y, *C;
int alpha, beta, betaY, betaC;
int q;
int mbtype[4];
int mb_strong[4];
int clip[4];
int cbp[4];
int uvcbp[4][2];
int mvmasks[4];
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
r->cbp_chroma[mb_pos] = 0xFF;
}
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int y_h_deblock, y_v_deblock;
int c_v_deblock[2], c_h_deblock[2];
int clip_left;
int avail[4];
int y_to_deblock, c_to_deblock[2];
q = s->current_picture_ptr->f.qscale_table[mb_pos];
alpha = rv40_alpha_tab[q];
beta = rv40_beta_tab [q];
betaY = betaC = beta * 3;
if(s->width * s->height <= 176*144)
betaY += beta;
avail[0] = 1;
avail[1] = row;
avail[2] = mb_x;
avail[3] = row < s->mb_height - 1;
for(i = 0; i < 4; i++){
if(avail[i]){
int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;
mvmasks[i] = r->deblock_coefs[pos];
mbtype [i] = s->current_picture_ptr->f.mb_type[pos];
cbp [i] = r->cbp_luma[pos];
uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;
uvcbp[i][1] = r->cbp_chroma[pos] >> 4;
}else{
mvmasks[i] = 0;
mbtype [i] = mbtype[0];
cbp [i] = 0;
uvcbp[i][0] = uvcbp[i][1] = 0;
}
mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);
clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];
}
y_to_deblock = mvmasks[POS_CUR]
| (mvmasks[POS_BOTTOM] << 16);
y_h_deblock = y_to_deblock
| ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)
| ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);
y_v_deblock = y_to_deblock
| ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)
| ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);
if(!mb_x)
y_v_deblock &= ~MASK_Y_LEFT_COL;
if(!row)
y_h_deblock &= ~MASK_Y_TOP_ROW;
if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))
y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);
for(i = 0; i < 2; i++){
c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];
c_v_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)
| ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);
c_h_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)
| (uvcbp[POS_CUR][i] << 2);
if(!mb_x)
c_v_deblock[i] &= ~MASK_C_LEFT_COL;
if(!row)
c_h_deblock[i] &= ~MASK_C_TOP_ROW;
if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])
c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);
}
for(j = 0; j < 16; j += 4){
Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
int dither = j ? ij : i*4;
if(y_h_deblock & (MASK_BOTTOM << ij)){
rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,
s->linesize, dither,
y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,
clip_cur, alpha, beta, betaY,
0, 0, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){
if(!i)
clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
else
clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 0, 1);
}
if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,
alpha, beta, betaY, 0, 1, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){
clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 1, 1);
}
}
}
for(k = 0; k < 2; k++){
for(j = 0; j < 2; j++){
C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + j*2;
int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
if(c_h_deblock[k] & (MASK_CUR << (ij+2))){
int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,
clip_bot,
clip_cur,
alpha, beta, betaC, 1, 0, 0);
}
if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){
if(!i)
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
else
clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 0, 1);
}
if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){
int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,
clip_cur,
clip_top,
alpha, beta, betaC, 1, 1, 0);
}
if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 1, 1);
}
}
}
}
}
}
|
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->f.qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->f.mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,\n s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur, alpha, beta, betaY,\n 0, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0, 1);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0, 1);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1, 0);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1, 1);\n }\n }\n }\n }\n }\n}']
|
1,112
| 0
|
https://github.com/openssl/openssl/blob/1a50eedf2a1fbb1e0e009ad616d8be678e4c6340/crypto/bn/bn_lib.c/#L232
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k = NULL, *r = NULL, *X = NULL;\n const BIGNUM *order;\n EC_POINT *tmp_point = NULL;\n const EC_GROUP *group;\n int ret = 0;\n int order_bits;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return 0;\n }\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n } else\n ctx = ctx_in;\n k = BN_new();\n r = BN_new();\n X = BN_new();\n if (k == NULL || r == NULL || X == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if ((tmp_point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n order_bits = BN_num_bits(order);\n if (!BN_set_bit(k, order_bits)\n || !BN_set_bit(r, order_bits)\n || !BN_set_bit(X, order_bits))\n goto err;\n do {\n do\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce\n (k, order, EC_KEY_get0_private_key(eckey), dgst, dlen,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n } else {\n if (!BN_priv_rand_range(k, order)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n }\n while (BN_is_zero(k));\n if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==\n NID_X9_62_prime_field) {\n if (!EC_POINT_get_affine_coordinates_GFp\n (group, tmp_point, X, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#ifndef OPENSSL_NO_EC2M\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group,\n tmp_point, X, NULL,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#endif\n if (!BN_nnmod(r, X, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n }\n while (BN_is_zero(r));\n if (!ec_group_do_inverse_ord(group, k, k, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n BN_clear_free(*rp);\n BN_clear_free(*kinvp);\n *rp = r;\n *kinvp = k;\n ret = 1;\n err:\n if (!ret) {\n BN_clear_free(k);\n BN_clear_free(r);\n }\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n EC_POINT_free(tmp_point);\n BN_clear_free(X);\n return ret;\n}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n int i, j, k;\n if (n < 0)\n return 0;\n i = n / BN_BITS2;\n j = n % BN_BITS2;\n if (a->top <= i) {\n if (bn_wexpand(a, i + 1) == NULL)\n return 0;\n for (k = a->top; k < i + 1; k++)\n a->d[k] = 0;\n a->top = i + 1;\n a->flags &= ~BN_FLG_FIXED_TOP;\n }\n a->d[i] |= (((BN_ULONG)1) << j);\n bn_check_top(a);\n return 1;\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n int ret = 0;\n size_t i = 0;\n BN_CTX *new_ctx = NULL;\n if ((scalar == NULL) && (num == 0)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n if (!ec_point_is_compat(r, group)) {\n ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n for (i = 0; i < num; i++) {\n if (!ec_point_is_compat(points[i], group)) {\n ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL) {\n ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (group->meth->mul != NULL)\n ret = group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n else\n ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n const EC_POINT *generator = NULL;\n EC_POINT *tmp = NULL;\n size_t totalnum;\n size_t blocksize = 0, numblocks = 0;\n size_t pre_points_per_block = 0;\n size_t i, j;\n int k;\n int r_is_inverted = 0;\n int r_is_at_infinity = 1;\n size_t *wsize = NULL;\n signed char **wNAF = NULL;\n size_t *wNAF_len = NULL;\n size_t max_len = 0;\n size_t num_val;\n EC_POINT **val = NULL;\n EC_POINT **v;\n EC_POINT ***val_sub = NULL;\n const EC_PRE_COMP *pre_comp = NULL;\n int num_scalar = 0;\n int ret = 0;\n if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) {\n if ((scalar != NULL) && (num == 0)) {\n return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);\n }\n if ((scalar == NULL) && (num == 1)) {\n return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx);\n }\n }\n if (scalar != NULL) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.ec;\n if (pre_comp && pre_comp->numblocks\n && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n 0)) {\n blocksize = pre_comp->blocksize;\n numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n if (numblocks > pre_comp->numblocks)\n numblocks = pre_comp->numblocks;\n pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n pre_comp = NULL;\n numblocks = 1;\n num_scalar = 1;\n }\n }\n totalnum = num + numblocks;\n wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));\n wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));\n wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));\n val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));\n if (wNAF != NULL)\n wNAF[0] = NULL;\n if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n num_val = 0;\n for (i = 0; i < num + num_scalar; i++) {\n size_t bits;\n bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n wsize[i] = EC_window_bits_for_scalar_size(bits);\n num_val += (size_t)1 << (wsize[i] - 1);\n wNAF[i + 1] = NULL;\n wNAF[i] =\n bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n &wNAF_len[i]);\n if (wNAF[i] == NULL)\n goto err;\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n }\n if (numblocks) {\n if (pre_comp == NULL) {\n if (num_scalar != 1) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n signed char *tmp_wNAF = NULL;\n size_t tmp_len = 0;\n if (num_scalar != 0) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n wsize[num] = pre_comp->w;\n tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n if (!tmp_wNAF)\n goto err;\n if (tmp_len <= max_len) {\n numblocks = 1;\n totalnum = num + 1;\n wNAF[num] = tmp_wNAF;\n wNAF[num + 1] = NULL;\n wNAF_len[num] = tmp_len;\n val_sub[num] = pre_comp->points;\n } else {\n signed char *pp;\n EC_POINT **tmp_points;\n if (tmp_len < numblocks * blocksize) {\n numblocks = (tmp_len + blocksize - 1) / blocksize;\n if (numblocks > pre_comp->numblocks) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n totalnum = num + numblocks;\n }\n pp = tmp_wNAF;\n tmp_points = pre_comp->points;\n for (i = num; i < totalnum; i++) {\n if (i < totalnum - 1) {\n wNAF_len[i] = blocksize;\n if (tmp_len < blocksize) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n tmp_len -= blocksize;\n } else\n wNAF_len[i] = tmp_len;\n wNAF[i + 1] = NULL;\n wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n if (wNAF[i] == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n memcpy(wNAF[i], pp, wNAF_len[i]);\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n if (*tmp_points == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n val_sub[i] = tmp_points;\n tmp_points += pre_points_per_block;\n pp += blocksize;\n }\n OPENSSL_free(tmp_wNAF);\n }\n }\n }\n val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));\n if (val == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n val[num_val] = NULL;\n v = val;\n for (i = 0; i < num + num_scalar; i++) {\n val_sub[i] = v;\n for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n *v = EC_POINT_new(group);\n if (*v == NULL)\n goto err;\n v++;\n }\n }\n if (!(v == val + num_val)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if ((tmp = EC_POINT_new(group)) == NULL)\n goto err;\n for (i = 0; i < num + num_scalar; i++) {\n if (i < num) {\n if (!EC_POINT_copy(val_sub[i][0], points[i]))\n goto err;\n } else {\n if (!EC_POINT_copy(val_sub[i][0], generator))\n goto err;\n }\n if (wsize[i] > 1) {\n if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n goto err;\n for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n if (!EC_POINT_add\n (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n goto err;\n }\n }\n }\n if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n goto err;\n r_is_at_infinity = 1;\n for (k = max_len - 1; k >= 0; k--) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n }\n for (i = 0; i < totalnum; i++) {\n if (wNAF_len[i] > (size_t)k) {\n int digit = wNAF[i][k];\n int is_neg;\n if (digit) {\n is_neg = digit < 0;\n if (is_neg)\n digit = -digit;\n if (is_neg != r_is_inverted) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n r_is_inverted = !r_is_inverted;\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n goto err;\n r_is_at_infinity = 0;\n } else {\n if (!EC_POINT_add\n (group, r, r, val_sub[i][digit >> 1], ctx))\n goto err;\n }\n }\n }\n }\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (r_is_inverted)\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n ret = 1;\n err:\n EC_POINT_free(tmp);\n OPENSSL_free(wsize);\n OPENSSL_free(wNAF_len);\n if (wNAF != NULL) {\n signed char **w;\n for (w = wNAF; *w != NULL; w++)\n OPENSSL_free(*w);\n OPENSSL_free(wNAF);\n }\n if (val != NULL) {\n for (v = val; *v != NULL; v++)\n EC_POINT_clear_free(*v);\n OPENSSL_free(val);\n }\n OPENSSL_free(val_sub);\n return ret;\n}', 'int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int i, cardinality_bits, group_top, kbit, pbit, Z_is_one;\n EC_POINT *p = NULL;\n EC_POINT *s = NULL;\n BIGNUM *k = NULL;\n BIGNUM *lambda = NULL;\n BIGNUM *cardinality = NULL;\n int ret = 0;\n if (point != NULL && EC_POINT_is_at_infinity(group, point))\n return EC_POINT_set_to_infinity(group, r);\n if (BN_is_zero(group->order)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_ORDER);\n return 0;\n }\n if (BN_is_zero(group->cofactor)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_COFACTOR);\n return 0;\n }\n BN_CTX_start(ctx);\n if (((p = EC_POINT_new(group)) == NULL)\n || ((s = EC_POINT_new(group)) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (point == NULL) {\n if (!EC_POINT_copy(p, group->generator)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);\n goto err;\n }\n } else {\n if (!EC_POINT_copy(p, point)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);\n goto err;\n }\n }\n EC_POINT_BN_set_flags(p, BN_FLG_CONSTTIME);\n EC_POINT_BN_set_flags(r, BN_FLG_CONSTTIME);\n EC_POINT_BN_set_flags(s, BN_FLG_CONSTTIME);\n cardinality = BN_CTX_get(ctx);\n lambda = BN_CTX_get(ctx);\n k = BN_CTX_get(ctx);\n if (k == NULL) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!BN_mul(cardinality, group->order, group->cofactor, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n cardinality_bits = BN_num_bits(cardinality);\n group_top = bn_get_top(cardinality);\n if ((bn_wexpand(k, group_top + 1) == NULL)\n || (bn_wexpand(lambda, group_top + 1) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_copy(k, scalar)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if ((BN_num_bits(k) > cardinality_bits) || (BN_is_negative(k))) {\n if (!BN_nnmod(k, k, cardinality, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n }\n if (!BN_add(lambda, k, cardinality)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(lambda, BN_FLG_CONSTTIME);\n if (!BN_add(k, lambda, cardinality)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n kbit = BN_is_bit_set(lambda, cardinality_bits);\n BN_consttime_swap(kbit, k, lambda, group_top + 1);\n group_top = bn_get_top(group->field);\n if ((bn_wexpand(s->X, group_top) == NULL)\n || (bn_wexpand(s->Y, group_top) == NULL)\n || (bn_wexpand(s->Z, group_top) == NULL)\n || (bn_wexpand(r->X, group_top) == NULL)\n || (bn_wexpand(r->Y, group_top) == NULL)\n || (bn_wexpand(r->Z, group_top) == NULL)\n || (bn_wexpand(p->X, group_top) == NULL)\n || (bn_wexpand(p->Y, group_top) == NULL)\n || (bn_wexpand(p->Z, group_top) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n if (!ec_point_blind_coordinates(group, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_POINT_COORDINATES_BLIND_FAILURE);\n goto err;\n }\n if (!ec_point_ladder_pre(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_PRE_FAILURE);\n goto err;\n }\n pbit = 1;\n#define EC_POINT_CSWAP(c, a, b, w, t) do { \\\n BN_consttime_swap(c, (a)->X, (b)->X, w); \\\n BN_consttime_swap(c, (a)->Y, (b)->Y, w); \\\n BN_consttime_swap(c, (a)->Z, (b)->Z, w); \\\n t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \\\n (a)->Z_is_one ^= (t); \\\n (b)->Z_is_one ^= (t); \\\n} while(0)\n for (i = cardinality_bits - 1; i >= 0; i--) {\n kbit = BN_is_bit_set(k, i) ^ pbit;\n EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);\n if (!ec_point_ladder_step(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_STEP_FAILURE);\n goto err;\n }\n pbit ^= kbit;\n }\n EC_POINT_CSWAP(pbit, r, s, group_top, Z_is_one);\n#undef EC_POINT_CSWAP\n if (!ec_point_ladder_post(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_POST_FAILURE);\n goto err;\n }\n ret = 1;\n err:\n EC_POINT_free(p);\n EC_POINT_free(s);\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,113
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L260
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, size_t num,\n const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n int ret = 0;\n size_t i;\n EC_POINT *p = NULL;\n EC_POINT *acc = NULL;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n if ((scalar && (num > 1)) || (num > 2)\n || (num == 0 && EC_GROUP_have_precompute_mult(group))) {\n ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n goto err;\n }\n if ((p = EC_POINT_new(group)) == NULL)\n goto err;\n if ((acc = EC_POINT_new(group)) == NULL)\n goto err;\n if (!EC_POINT_set_to_infinity(group, acc))\n goto err;\n if (scalar) {\n if (!ec_GF2m_montgomery_point_multiply\n (group, p, scalar, group->generator, ctx))\n goto err;\n if (BN_is_negative(scalar))\n if (!group->meth->invert(group, p, ctx))\n goto err;\n if (!group->meth->add(group, acc, acc, p, ctx))\n goto err;\n }\n for (i = 0; i < num; i++) {\n if (!ec_GF2m_montgomery_point_multiply\n (group, p, scalars[i], points[i], ctx))\n goto err;\n if (BN_is_negative(scalars[i]))\n if (!group->meth->invert(group, p, ctx))\n goto err;\n if (!group->meth->add(group, acc, acc, p, ctx))\n goto err;\n }\n if (!EC_POINT_copy(r, acc))\n goto err;\n ret = 1;\n err:\n EC_POINT_free(p);\n EC_POINT_free(acc);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'static int ec_GF2m_montgomery_point_multiply(const EC_GROUP *group,\n EC_POINT *r,\n const BIGNUM *scalar,\n const EC_POINT *point,\n BN_CTX *ctx)\n{\n BIGNUM *x1, *x2, *z1, *z2;\n int ret = 0, i, group_top;\n BN_ULONG mask, word;\n if (r == point) {\n ECerr(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY, EC_R_INVALID_ARGUMENT);\n return 0;\n }\n if ((scalar == NULL) || BN_is_zero(scalar) || (point == NULL) ||\n EC_POINT_is_at_infinity(group, point)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n if (!point->Z_is_one)\n return 0;\n BN_CTX_start(ctx);\n x1 = BN_CTX_get(ctx);\n z1 = BN_CTX_get(ctx);\n if (z1 == NULL)\n goto err;\n x2 = r->X;\n z2 = r->Y;\n group_top = bn_get_top(group->field);\n if (bn_wexpand(x1, group_top) == NULL\n || bn_wexpand(z1, group_top) == NULL\n || bn_wexpand(x2, group_top) == NULL\n || bn_wexpand(z2, group_top) == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(x1, point->X, group->poly))\n goto err;\n if (!BN_one(z1))\n goto err;\n if (!group->meth->field_sqr(group, z2, x1, ctx))\n goto err;\n if (!group->meth->field_sqr(group, x2, z2, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->b))\n goto err;\n i = bn_get_top(scalar) - 1;\n mask = BN_TBIT;\n word = bn_get_words(scalar)[i];\n while (!(word & mask))\n mask >>= 1;\n mask >>= 1;\n if (!mask) {\n i--;\n mask = BN_TBIT;\n }\n for (; i >= 0; i--) {\n word = bn_get_words(scalar)[i];\n while (mask) {\n BN_consttime_swap(word & mask, x1, x2, group_top);\n BN_consttime_swap(word & mask, z1, z2, group_top);\n if (!gf2m_Madd(group, point->X, x2, z2, x1, z1, ctx))\n goto err;\n if (!gf2m_Mdouble(group, x1, z1, ctx))\n goto err;\n BN_consttime_swap(word & mask, x1, x2, group_top);\n BN_consttime_swap(word & mask, z1, z2, group_top);\n mask >>= 1;\n }\n mask = BN_TBIT;\n }\n i = gf2m_Mxy(group, point->X, point->Y, x1, z1, x2, z2, ctx);\n if (i == 0)\n goto err;\n else if (i == 1) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (!BN_one(r->Z))\n goto err;\n r->Z_is_one = 1;\n }\n BN_set_negative(r->X, 0);\n BN_set_negative(r->Y, 0);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,114
| 0
|
https://github.com/openssl/openssl/blob/9b67b4b3caf071f490b95128f5dd44d9ce52032d/crypto/asn1/asn1_lib.c/#L101
|
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
long omax)
{
int i,ret;
long l;
unsigned char *p= *pp;
int tag,xclass,inf;
long max=omax;
if (!max) goto err;
ret=(*p&V_ASN1_CONSTRUCTED);
xclass=(*p&V_ASN1_PRIVATE);
i= *p&V_ASN1_PRIMITIVE_TAG;
if (i == V_ASN1_PRIMITIVE_TAG)
{
p++;
if (--max == 0) goto err;
l=0;
while (*p&0x80)
{
l<<=7L;
l|= *(p++)&0x7f;
if (--max == 0) goto err;
}
l<<=7L;
l|= *(p++)&0x7f;
tag=(int)l;
}
else
{
tag=i;
p++;
if (--max == 0) goto err;
}
*ptag=tag;
*pclass=xclass;
if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
#if 0
fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
(int)(omax+ *pp));
#endif
#if 0
if ((p+ *plength) > (omax+ *pp))
{
ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
ret|=0x80;
}
#endif
*pp=p;
return(ret|inf);
err:
ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
return(0x80);
}
|
['int PKCS7_dataVerify(X509_STORE *cert_store, X509_STORE_CTX *ctx, BIO *bio,\n\t PKCS7 *p7, PKCS7_SIGNER_INFO *si)\n\t{\n\tPKCS7_ISSUER_AND_SERIAL *ias;\n\tint ret=0,i;\n\tSTACK_OF(X509) *cert;\n\tX509 *x509;\n\tif (PKCS7_type_is_signed(p7))\n\t\t{\n\t\tcert=p7->d.sign->cert;\n\t\t}\n\telse if (PKCS7_type_is_signedAndEnveloped(p7))\n\t\t{\n\t\tcert=p7->d.signed_and_enveloped->cert;\n\t\t}\n\telse\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_WRONG_PKCS7_TYPE);\n\t\tgoto err;\n\t\t}\n\tias=si->issuer_and_serial;\n\tx509=X509_find_by_issuer_and_serial(cert,ias->issuer,ias->serial);\n\tif (x509 == NULL)\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_DATAVERIFY,PKCS7_R_UNABLE_TO_FIND_CERTIFICATE);\n\t\tgoto err;\n\t\t}\n\tX509_STORE_CTX_init(ctx,cert_store,x509,cert);\n\ti=X509_verify_cert(ctx);\n\tif (i <= 0)\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_DATAVERIFY,ERR_R_X509_LIB);\n\t\tgoto err;\n\t\t}\n\tX509_STORE_CTX_cleanup(ctx);\n\treturn PKCS7_signatureVerify(bio, p7, si, x509);\n\terr:\n\treturn ret;\n\t}', 'int X509_verify_cert(X509_STORE_CTX *ctx)\n\t{\n\tX509 *x,*xtmp,*chain_ss=NULL;\n\tX509_NAME *xn;\n\tX509_OBJECT obj;\n\tint depth,i,ok=0;\n\tint num;\n\tint (*cb)();\n\tSTACK_OF(X509) *sktmp=NULL;\n\tif (ctx->cert == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);\n\t\treturn(-1);\n\t\t}\n\tcb=ctx->ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tif (ctx->chain == NULL)\n\t\t{\n\t\tif (\t((ctx->chain=sk_X509_new_null()) == NULL) ||\n\t\t\t(!sk_X509_push(ctx->chain,ctx->cert)))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto end;\n\t\t\t}\n\t\tCRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);\n\t\tctx->last_untrusted=1;\n\t\t}\n\tif (ctx->untrusted != NULL\n\t && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\tgoto end;\n\t\t}\n\tnum=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,num-1);\n\tdepth=ctx->depth;\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)\n\t\t\tbreak;\n\t\tif (ctx->untrusted != NULL)\n\t\t\t{\n\t\t\txtmp=X509_find_by_subject(sktmp,xn);\n\t\t\tif (xtmp != NULL)\n\t\t\t\t{\n\t\t\t\tif (!sk_X509_push(ctx->chain,xtmp))\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tCRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);\n\t\t\t\tsk_X509_delete_ptr(sktmp,xtmp);\n\t\t\t\tctx->last_untrusted++;\n\t\t\t\tx=xtmp;\n\t\t\t\tnum++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\tbreak;\n\t\t}\n\ti=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,i-1);\n\tif (X509_NAME_cmp(X509_get_subject_name(x),X509_get_issuer_name(x))\n\t\t== 0)\n\t\t{\n\t\tif (sk_X509_num(ctx->chain) == 1)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\tctx->error_depth=i-1;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tchain_ss=sk_X509_pop(ctx->chain);\n\t\t\tctx->last_untrusted--;\n\t\t\tnum--;\n\t\t\tx=sk_X509_value(ctx->chain,num-1);\n\t\t\t}\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\txn=X509_get_issuer_name(x);\n\t\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) == 0)\n\t\t\tbreak;\n\t\tok=X509_STORE_get_by_subject(ctx,X509_LU_X509,xn,&obj);\n\t\tif (ok != X509_LU_X509)\n\t\t\t{\n\t\t\tif (ok == X509_LU_RETRY)\n\t\t\t\t{\n\t\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);\n\t\t\t\treturn(ok);\n\t\t\t\t}\n\t\t\telse if (ok != X509_LU_FAIL)\n\t\t\t\t{\n\t\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\t\treturn(ok);\n\t\t\t\t}\n\t\t\tbreak;\n\t\t\t}\n\t\tx=obj.data.x509;\n\t\tif (!sk_X509_push(ctx->chain,obj.data.x509))\n\t\t\t{\n\t\t\tX509_OBJECT_free_contents(&obj);\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(0);\n\t\t\t}\n\t\tnum++;\n\t\t}\n\txn=X509_get_issuer_name(x);\n\tif (X509_NAME_cmp(X509_get_subject_name(x),xn) != 0)\n\t\t{\n\t\tif ((chain_ss == NULL) || (X509_NAME_cmp(X509_get_subject_name(chain_ss),xn) != 0))\n\t\t\t{\n\t\t\tif (ctx->last_untrusted >= num)\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;\n\t\t\telse\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsk_X509_push(ctx->chain,chain_ss);\n\t\t\tnum++;\n\t\t\tctx->last_untrusted=num;\n\t\t\tctx->current_cert=chain_ss;\n\t\t\tctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;\n\t\t\tchain_ss=NULL;\n\t\t\t}\n\t\tctx->error_depth=num-1;\n\t\tok=cb(0,ctx);\n\t\tif (!ok) goto end;\n\t\t}\n\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\tif (ctx->ctx->verify != NULL)\n\t\tok=ctx->ctx->verify(ctx);\n\telse\n\t\tok=internal_verify(ctx);\n\tif (0)\n\t\t{\nend:\n\t\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\t\t}\n\tif (sktmp != NULL) sk_X509_free(sktmp);\n\tif (chain_ss != NULL) X509_free(chain_ss);\n\treturn(ok);\n\t}', 'void X509_OBJECT_free_contents(X509_OBJECT *a)\n\t{\n\tswitch (a->type)\n\t\t{\n\tcase X509_LU_X509:\n\t\tX509_free(a->data.x509);\n\t\tbreak;\n\tcase X509_LU_CRL:\n\t\tX509_CRL_free(a->data.crl);\n\t\tbreak;\n\t\t}\n\t}', 'int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,\n\t\t\t\t\t\t\t\tX509 *x509)\n\t{\n\tASN1_OCTET_STRING *os;\n\tEVP_MD_CTX mdc_tmp,*mdc;\n\tunsigned char *pp,*p;\n\tint ret=0,i;\n\tint md_type;\n\tSTACK_OF(X509_ATTRIBUTE) *sk;\n\tBIO *btmp;\n\tEVP_PKEY *pkey;\n\tif (!PKCS7_type_is_signed(p7) &&\n\t\t\t\t!PKCS7_type_is_signedAndEnveloped(p7)) {\n\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\tPKCS7_R_WRONG_PKCS7_TYPE);\n\t\tgoto err;\n\t}\n\tmd_type=OBJ_obj2nid(si->digest_alg->algorithm);\n\tbtmp=bio;\n\tfor (;;)\n\t\t{\n\t\tif ((btmp == NULL) ||\n\t\t\t((btmp=BIO_find_type(btmp,BIO_TYPE_MD)) == NULL))\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\tPKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\tBIO_get_md_ctx(btmp,&mdc);\n\t\tif (mdc == NULL)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\t\tPKCS7_R_INTERNAL_ERROR);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (EVP_MD_type(EVP_MD_CTX_type(mdc)) == md_type)\n\t\t\tbreak;\n\t\tbtmp=btmp->next_bio;\n\t\t}\n\tmemcpy(&mdc_tmp,mdc,sizeof(mdc_tmp));\n\tsk=si->auth_attr;\n\tif ((sk != NULL) && (sk_X509_ATTRIBUTE_num(sk) != 0))\n\t\t{\n\t\tunsigned char md_dat[EVP_MAX_MD_SIZE];\n unsigned int md_len;\n\t\tASN1_OCTET_STRING *message_digest;\n\t\tEVP_DigestFinal(&mdc_tmp,md_dat,&md_len);\n\t\tmessage_digest=PKCS7_digest_from_attributes(sk);\n\t\tif (!message_digest)\n\t\t\t{\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\tPKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif ((message_digest->length != (int)md_len) ||\n\t\t\t(memcmp(message_digest->data,md_dat,md_len)))\n\t\t\t{\n#if 0\n{\nint ii;\nfor (ii=0; ii<message_digest->length; ii++)\n\tprintf("%02X",message_digest->data[ii]); printf(" sent\\n");\nfor (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\\n");\n}\n#endif\n\t\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\t\tPKCS7_R_DIGEST_FAILURE);\n\t\t\tret= -1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tEVP_VerifyInit(&mdc_tmp,EVP_get_digestbynid(md_type));\n\t\ti=i2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,NULL,i2d_X509_ATTRIBUTE,\n\t\t\tV_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);\n\t\tpp=Malloc(i);\n\t\tp=pp;\n\t\ti2d_ASN1_SET_OF_X509_ATTRIBUTE(sk,&p,i2d_X509_ATTRIBUTE,\n\t\t\tV_ASN1_SET,V_ASN1_UNIVERSAL, IS_SEQUENCE);\n\t\tEVP_VerifyUpdate(&mdc_tmp,pp,i);\n\t\tFree(pp);\n\t\t}\n\tos=si->enc_digest;\n\tpkey = X509_get_pubkey(x509);\n\tif(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();\n\ti=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);\n\tEVP_PKEY_free(pkey);\n\tif (i <= 0)\n\t\t{\n\t\tPKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY,\n\t\t\t\t\t\tPKCS7_R_SIGNATURE_FAILURE);\n\t\tret= -1;\n\t\tgoto err;\n\t\t}\n\telse\n\t\tret=1;\nerr:\n\treturn(ret);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
|
1,115
| 0
|
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/x509v3/v3_prn.c/#L130
|
int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag,
int indent)
{
void *ext_str = NULL;
char *value = NULL;
ASN1_OCTET_STRING *extoct;
const unsigned char *p;
int extlen;
const X509V3_EXT_METHOD *method;
STACK_OF(CONF_VALUE) *nval = NULL;
int ok = 1;
extoct = X509_EXTENSION_get_data(ext);
p = ASN1_STRING_data(extoct);
extlen = ASN1_STRING_length(extoct);
if ((method = X509V3_EXT_get(ext)) == NULL)
return unknown_ext_print(out, p, extlen, flag, indent, 0);
if (method->it)
ext_str = ASN1_item_d2i(NULL, &p, extlen, ASN1_ITEM_ptr(method->it));
else
ext_str = method->d2i(NULL, &p, extlen);
if (!ext_str)
return unknown_ext_print(out, p, extlen, flag, indent, 1);
if (method->i2s) {
if ((value = method->i2s(method, ext_str)) == NULL) {
ok = 0;
goto err;
}
#ifndef CHARSET_EBCDIC
BIO_printf(out, "%*s%s", indent, "", value);
#else
{
int len;
char *tmp;
len = strlen(value) + 1;
tmp = OPENSSL_malloc(len);
if (tmp != NULL) {
ascii2ebcdic(tmp, value, len);
BIO_printf(out, "%*s%s", indent, "", tmp);
OPENSSL_free(tmp);
}
}
#endif
} else if (method->i2v) {
if ((nval = method->i2v(method, ext_str, NULL)) == NULL) {
ok = 0;
goto err;
}
X509V3_EXT_val_prn(out, nval, indent,
method->ext_flags & X509V3_EXT_MULTILINE);
} else if (method->i2r) {
if (!method->i2r(method, ext_str, out, indent))
ok = 0;
} else
ok = 0;
err:
sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
OPENSSL_free(value);
if (method->it)
ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));
else
method->ext_free(ext_str);
return ok;
}
|
['int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag,\n int indent)\n{\n void *ext_str = NULL;\n char *value = NULL;\n ASN1_OCTET_STRING *extoct;\n const unsigned char *p;\n int extlen;\n const X509V3_EXT_METHOD *method;\n STACK_OF(CONF_VALUE) *nval = NULL;\n int ok = 1;\n extoct = X509_EXTENSION_get_data(ext);\n p = ASN1_STRING_data(extoct);\n extlen = ASN1_STRING_length(extoct);\n if ((method = X509V3_EXT_get(ext)) == NULL)\n return unknown_ext_print(out, p, extlen, flag, indent, 0);\n if (method->it)\n ext_str = ASN1_item_d2i(NULL, &p, extlen, ASN1_ITEM_ptr(method->it));\n else\n ext_str = method->d2i(NULL, &p, extlen);\n if (!ext_str)\n return unknown_ext_print(out, p, extlen, flag, indent, 1);\n if (method->i2s) {\n if ((value = method->i2s(method, ext_str)) == NULL) {\n ok = 0;\n goto err;\n }\n#ifndef CHARSET_EBCDIC\n BIO_printf(out, "%*s%s", indent, "", value);\n#else\n {\n int len;\n char *tmp;\n len = strlen(value) + 1;\n tmp = OPENSSL_malloc(len);\n if (tmp != NULL) {\n ascii2ebcdic(tmp, value, len);\n BIO_printf(out, "%*s%s", indent, "", tmp);\n OPENSSL_free(tmp);\n }\n }\n#endif\n } else if (method->i2v) {\n if ((nval = method->i2v(method, ext_str, NULL)) == NULL) {\n ok = 0;\n goto err;\n }\n X509V3_EXT_val_prn(out, nval, indent,\n method->ext_flags & X509V3_EXT_MULTILINE);\n } else if (method->i2r) {\n if (!method->i2r(method, ext_str, out, indent))\n ok = 0;\n } else\n ok = 0;\n err:\n sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);\n OPENSSL_free(value);\n if (method->it)\n ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));\n else\n method->ext_free(ext_str);\n return ok;\n}', 'ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex)\n{\n if (ex == NULL)\n return (NULL);\n return &ex->value;\n}', 'unsigned char *ASN1_STRING_data(ASN1_STRING *x)\n{\n return x->data;\n}']
|
1,116
| 0
|
https://github.com/openssl/openssl/blob/a5a95f8d65c2c616ebee13ae4b33eacde34bb2d3/crypto/x509/x509_lu.c/#L598
|
X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h,
X509_OBJECT *x)
{
int idx, i;
X509_OBJECT *obj;
idx = sk_X509_OBJECT_find(h, x);
if (idx == -1)
return NULL;
if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL))
return sk_X509_OBJECT_value(h, idx);
for (i = idx; i < sk_X509_OBJECT_num(h); i++) {
obj = sk_X509_OBJECT_value(h, i);
if (x509_object_cmp
((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x))
return NULL;
if (x->type == X509_LU_X509) {
if (!X509_cmp(obj->data.x509, x->data.x509))
return obj;
} else if (x->type == X509_LU_CRL) {
if (!X509_CRL_match(obj->data.crl, x->data.crl))
return obj;
} else
return obj;
}
return NULL;
}
|
['X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h,\n X509_OBJECT *x)\n{\n int idx, i;\n X509_OBJECT *obj;\n idx = sk_X509_OBJECT_find(h, x);\n if (idx == -1)\n return NULL;\n if ((x->type != X509_LU_X509) && (x->type != X509_LU_CRL))\n return sk_X509_OBJECT_value(h, idx);\n for (i = idx; i < sk_X509_OBJECT_num(h); i++) {\n obj = sk_X509_OBJECT_value(h, i);\n if (x509_object_cmp\n ((const X509_OBJECT **)&obj, (const X509_OBJECT **)&x))\n return NULL;\n if (x->type == X509_LU_X509) {\n if (!X509_cmp(obj->data.x509, x->data.x509))\n return obj;\n } else if (x->type == X509_LU_CRL) {\n if (!X509_CRL_match(obj->data.crl, x->data.crl))\n return obj;\n } else\n return obj;\n }\n return NULL;\n}', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n int ret_val_options)\n{\n const void *r;\n int i;\n if (st == NULL)\n return -1;\n if (st->comp == NULL) {\n for (i = 0; i < st->num; i++)\n if (st->data[i] == data)\n return (i);\n return (-1);\n }\n OPENSSL_sk_sort(st);\n if (data == NULL)\n return (-1);\n r = OBJ_bsearch_ex_(&data, st->data, st->num, sizeof(void *), st->comp,\n ret_val_options);\n if (r == NULL)\n return (-1);\n return (int)((const char **)r - st->data);\n}', 'int OPENSSL_sk_num(const OPENSSL_STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n if (st == NULL || i < 0 || i >= st->num)\n return NULL;\n return (void *)st->data[i];\n}', 'static int x509_object_cmp(const X509_OBJECT *const *a,\n const X509_OBJECT *const *b)\n{\n int ret;\n ret = ((*a)->type - (*b)->type);\n if (ret)\n return ret;\n switch ((*a)->type) {\n case X509_LU_X509:\n ret = X509_subject_name_cmp((*a)->data.x509, (*b)->data.x509);\n break;\n case X509_LU_CRL:\n ret = X509_CRL_cmp((*a)->data.crl, (*b)->data.crl);\n break;\n default:\n return 0;\n }\n return ret;\n}']
|
1,117
| 0
|
https://github.com/openssl/openssl/blob/14c6d27d63795ead1b70d97e3303731b433c0db8/crypto/ocsp/ocsp_res.c/#L599
|
int i2d_OCSP_CERTSTATUS(OCSP_CERTSTATUS *a, unsigned char **pp)
{
unsigned char *qq;
M_ASN1_I2D_vars(a);
ret += 0;
if (a == NULL) return(0);
switch (a->tag)
{
case V_OCSP_CERTSTATUS_GOOD:
case V_OCSP_CERTSTATUS_UNKNOWN:
r = 2;
if (pp)
{
qq=p=*pp;
ASN1_put_object(&p,0,0,
V_ASN1_NULL,V_ASN1_UNIVERSAL);
*qq=(V_ASN1_CONTEXT_SPECIFIC|a->tag|
(*qq&V_ASN1_CONSTRUCTED));
}
break;
case V_OCSP_CERTSTATUS_REVOKED:
r = i2d_OCSP_REVOKEDINFO(a->revoked,NULL);
if (pp)
{
p=*pp;
M_ASN1_I2D_put_IMP_opt(a->revoked,
i2d_OCSP_REVOKEDINFO,
a->tag);
}
break;
}
if (pp && *pp) *pp=p;
return(r);
}
|
['int i2d_OCSP_CERTSTATUS(OCSP_CERTSTATUS *a, unsigned char **pp)\n\t{\n\tunsigned char *qq;\n\tM_ASN1_I2D_vars(a);\n\tret += 0;\n\tif (a == NULL) return(0);\n\tswitch (a->tag)\n\t\t{\n\t\tcase V_OCSP_CERTSTATUS_GOOD:\n\t\tcase V_OCSP_CERTSTATUS_UNKNOWN:\n\t\t r = 2;\n\t\t\tif (pp)\n\t\t\t\t{\n\t\t\t\tqq=p=*pp;\n\t\t\t\tASN1_put_object(&p,0,0,\n\t\t\t\t\t\tV_ASN1_NULL,V_ASN1_UNIVERSAL);\n\t\t\t\t*qq=(V_ASN1_CONTEXT_SPECIFIC|a->tag|\n\t\t\t\t (*qq&V_ASN1_CONSTRUCTED));\n\t\t\t\t}\n\t\t break;\n\t\tcase V_OCSP_CERTSTATUS_REVOKED:\n\t\t r = i2d_OCSP_REVOKEDINFO(a->revoked,NULL);\n\t\t\tif (pp)\n\t\t\t {\n\t\t\t\tp=*pp;\n\t\t\t M_ASN1_I2D_put_IMP_opt(a->revoked,\n\t\t\t\t\t\t i2d_OCSP_REVOKEDINFO,\n\t\t\t\t\t\t a->tag);\n\t\t\t\t}\n\t\t break;\n\t\t}\n\tif (pp && *pp) *pp=p;\n\treturn(r);\n\t}']
|
1,118
| 0
|
https://github.com/openssl/openssl/blob/260a16f33682a819414fcba6161708a5e6bdff50/crypto/lhash/lhash.c/#L200
|
static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
OPENSSL_LH_DOALL_FUNC func,
OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
int i;
OPENSSL_LH_NODE *a, *n;
if (lh == NULL)
return;
for (i = lh->num_nodes - 1; i >= 0; i--) {
a = lh->b[i];
while (a != NULL) {
n = a->next;
if (use_arg)
func_arg(a->data, arg);
else
func(a->data);
a = n;
}
}
}
|
['static int test_srp(int tst)\n{\n char *userid = "test", *password = "password", *tstsrpfile;\n SSL_CTX *cctx = NULL, *sctx = NULL;\n SSL *clientssl = NULL, *serverssl = NULL;\n int ret, testresult = 0;\n vbase = SRP_VBASE_new(NULL);\n if (!TEST_ptr(vbase))\n goto end;\n if (tst == 0 || tst == 1) {\n if (!TEST_true(create_new_vbase(userid, password)))\n goto end;\n } else {\n if (tst == 4 || tst == 5) {\n if (!TEST_true(create_new_vfile(userid, password, tmpfilename)))\n goto end;\n tstsrpfile = tmpfilename;\n } else {\n tstsrpfile = srpvfile;\n }\n if (!TEST_int_eq(SRP_VBASE_init(vbase, tstsrpfile), SRP_NO_ERROR))\n goto end;\n }\n if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),\n TLS1_VERSION, 0,\n &sctx, &cctx, cert, privkey)))\n goto end;\n if (!TEST_int_gt(SSL_CTX_set_srp_username_callback(sctx, ssl_srp_cb), 0)\n || !TEST_true(SSL_CTX_set_cipher_list(cctx, "SRP-AES-128-CBC-SHA"))\n || !TEST_true(SSL_CTX_set_max_proto_version(sctx, TLS1_2_VERSION))\n || !TEST_true(SSL_CTX_set_max_proto_version(cctx, TLS1_2_VERSION))\n || !TEST_int_gt(SSL_CTX_set_srp_username(cctx, userid), 0))\n goto end;\n if (tst % 2 == 1) {\n if (!TEST_int_gt(SSL_CTX_set_srp_password(cctx, "badpass"), 0))\n goto end;\n } else {\n if (!TEST_int_gt(SSL_CTX_set_srp_password(cctx, password), 0))\n goto end;\n }\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,\n NULL, NULL)))\n goto end;\n ret = create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE);\n if (ret) {\n if (!TEST_true(tst % 2 == 0))\n goto end;\n } else {\n if (!TEST_true(tst % 2 == 1))\n goto end;\n }\n testresult = 1;\n end:\n SRP_VBASE_free(vbase);\n vbase = NULL;\n SSL_free(serverssl);\n SSL_free(clientssl);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl != NULL)\n serverssl = *sssl;\n else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n goto error;\n if (*cssl != NULL)\n clientssl = *cssl;\n else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n goto error;\n if (SSL_is_dtls(clientssl)) {\n if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n goto error;\n } else {\n if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n goto error;\n }\n if (s_to_c_fbio != NULL\n && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n goto error;\n if (c_to_s_fbio != NULL\n && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n goto error;\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return NULL;\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return NULL;\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->references = 1;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n OPENSSL_free(s);\n s = NULL;\n goto err;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->max_early_data = ctx->max_early_data;\n s->recv_max_early_data = ctx->recv_max_early_data;\n s->num_tickets = ctx->num_tickets;\n s->pha_enabled = ctx->pha_enabled;\n s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n if (s->tls13_ciphersuites == NULL)\n goto err;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n s->allow_early_data_cb = ctx->allow_early_data_cb;\n s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->async_cb = ctx->async_cb;\n s->async_cb_arg = ctx->async_cb_arg;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(a->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n OPENSSL_secure_free(a->ext.secure);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
|
1,119
| 0
|
https://github.com/libav/libav/blob/4391805916a1557278351f25428d0145b1073520/libavcodec/smacker.c/#L290
|
static int decode_header_trees(SmackVContext *smk) {
GetBitContext gb;
int mmap_size, mclr_size, full_size, type_size;
mmap_size = AV_RL32(smk->avctx->extradata);
mclr_size = AV_RL32(smk->avctx->extradata + 4);
full_size = AV_RL32(smk->avctx->extradata + 8);
type_size = AV_RL32(smk->avctx->extradata + 12);
init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n");
smk->mmap_tbl = av_malloc(sizeof(int) * 2);
smk->mmap_tbl[0] = 0;
smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;
} else {
if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size))
return -1;
}
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n");
smk->mclr_tbl = av_malloc(sizeof(int) * 2);
smk->mclr_tbl[0] = 0;
smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;
} else {
if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size))
return -1;
}
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n");
smk->full_tbl = av_malloc(sizeof(int) * 2);
smk->full_tbl[0] = 0;
smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;
} else {
if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size))
return -1;
}
if(!get_bits1(&gb)) {
av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n");
smk->type_tbl = av_malloc(sizeof(int) * 2);
smk->type_tbl[0] = 0;
smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;
} else {
if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size))
return -1;
}
return 0;
}
|
['static int decode_header_trees(SmackVContext *smk) {\n GetBitContext gb;\n int mmap_size, mclr_size, full_size, type_size;\n mmap_size = AV_RL32(smk->avctx->extradata);\n mclr_size = AV_RL32(smk->avctx->extradata + 4);\n full_size = AV_RL32(smk->avctx->extradata + 8);\n type_size = AV_RL32(smk->avctx->extradata + 12);\n init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\\n");\n smk->mmap_tbl = av_malloc(sizeof(int) * 2);\n smk->mmap_tbl[0] = 0;\n smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\\n");\n smk->mclr_tbl = av_malloc(sizeof(int) * 2);\n smk->mclr_tbl[0] = 0;\n smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\\n");\n smk->full_tbl = av_malloc(sizeof(int) * 2);\n smk->full_tbl[0] = 0;\n smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size))\n return -1;\n }\n if(!get_bits1(&gb)) {\n av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\\n");\n smk->type_tbl = av_malloc(sizeof(int) * 2);\n smk->type_tbl[0] = 0;\n smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;\n } else {\n if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size))\n return -1;\n }\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
1,120
| 0
|
https://github.com/openssl/openssl/blob/3f97052392cb10fca5309212bf720685262ad4a6/ssl/statem/statem_clnt.c/#L2867
|
static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)
{
#ifndef OPENSSL_NO_RSA
unsigned char *encdata = NULL;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t enclen;
unsigned char *pms = NULL;
size_t pmslen = 0;
if (s->session->peer == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
return 0;
}
pkey = X509_get0_pubkey(s->session->peer);
if (EVP_PKEY_get0_RSA(pkey) == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
return 0;
}
pmslen = SSL_MAX_MASTER_KEY_LENGTH;
pms = OPENSSL_malloc(pmslen);
if (pms == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);
*al = SSL_AD_INTERNAL_ERROR;
return 0;
}
pms[0] = s->client_version >> 8;
pms[1] = s->client_version & 0xff;
if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
goto err;
}
if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
goto err;
}
pctx = EVP_PKEY_CTX_new(pkey, NULL);
if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0
|| EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);
goto err;
}
if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)
|| EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);
goto err;
}
EVP_PKEY_CTX_free(pctx);
pctx = NULL;
if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
goto err;
}
if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen))
goto err;
s->s3->tmp.pms = pms;
s->s3->tmp.pmslen = pmslen;
return 1;
err:
OPENSSL_clear_free(pms, pmslen);
EVP_PKEY_CTX_free(pctx);
return 0;
#else
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
*al = SSL_AD_INTERNAL_ERROR;
return 0;
#endif
}
|
['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *encdata = NULL;\n EVP_PKEY *pkey = NULL;\n EVP_PKEY_CTX *pctx = NULL;\n size_t enclen;\n unsigned char *pms = NULL;\n size_t pmslen = 0;\n if (s->session->peer == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pkey = X509_get0_pubkey(s->session->peer);\n if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n pms = OPENSSL_malloc(pmslen);\n if (pms == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n }\n pms[0] = s->client_version >> 8;\n pms[1] = s->client_version & 0xff;\n if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {\n goto err;\n }\n if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n pctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);\n goto err;\n }\n if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);\n goto err;\n }\n EVP_PKEY_CTX_free(pctx);\n pctx = NULL;\n if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!ssl_log_rsa_client_key_exchange(s, encdata, enclen, pms, pmslen))\n goto err;\n s->s3->tmp.pms = pms;\n s->s3->tmp.pmslen = pmslen;\n return 1;\n err:\n OPENSSL_clear_free(pms, pmslen);\n EVP_PKEY_CTX_free(pctx);\n return 0;\n#else\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)\n{\n if (pkey->type != EVP_PKEY_RSA) {\n EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);\n return NULL;\n }\n return pkey->pkey.rsa;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int RAND_bytes(unsigned char *buf, int num)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth && meth->bytes)\n return meth->bytes(buf, num);\n return (-1);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n const RAND_METHOD *tmp_meth = NULL;\n if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))\n return NULL;\n CRYPTO_THREAD_write_lock(rand_meth_lock);\n if (!default_RAND_meth) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e = ENGINE_get_default_RAND();\n if (e) {\n default_RAND_meth = ENGINE_get_RAND(e);\n if (default_RAND_meth == NULL) {\n ENGINE_finish(e);\n e = NULL;\n }\n }\n if (e)\n funct_ref = e;\n else\n#endif\n default_RAND_meth = RAND_OpenSSL();\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void CRYPTO_clear_free(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return;\n if (num)\n OPENSSL_cleanse(str, num);\n CRYPTO_free(str, file, line);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
1,121
| 0
|
https://github.com/openssl/openssl/blob/d8028b202bfe337200a0cc89b80983ea1838cb30/crypto/lhash/lhash.c/#L164
|
static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
OPENSSL_LH_DOALL_FUNC func,
OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
int i;
OPENSSL_LH_NODE *a, *n;
if (lh == NULL)
return;
for (i = lh->num_nodes - 1; i >= 0; i--) {
a = lh->b[i];
while (a != NULL) {
n = a->next;
if (use_arg)
func_arg(a->data, arg);
else
func(a->data);
a = n;
}
}
}
|
['OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,\n const char *host, const char *path,\n const char *port, int use_ssl,\n STACK_OF(CONF_VALUE) *headers,\n int req_timeout)\n{\n BIO *cbio = NULL;\n SSL_CTX *ctx = NULL;\n OCSP_RESPONSE *resp = NULL;\n cbio = BIO_new_connect(host);\n if (!cbio) {\n BIO_printf(bio_err, "Error creating connect BIO\\n");\n goto end;\n }\n if (port)\n BIO_set_conn_port(cbio, port);\n if (use_ssl == 1) {\n BIO *sbio;\n ctx = SSL_CTX_new(TLS_client_method());\n if (ctx == NULL) {\n BIO_printf(bio_err, "Error creating SSL context.\\n");\n goto end;\n }\n SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);\n sbio = BIO_new_ssl(ctx, 1);\n cbio = BIO_push(sbio, cbio);\n }\n resp = query_responder(cbio, host, path, headers, req, req_timeout);\n if (!resp)\n BIO_printf(bio_err, "Error querying OCSP responder\\n");\n end:\n BIO_free_all(cbio);\n SSL_CTX_free(ctx);\n return resp;\n}', 'SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)\n{\n SSL_CTX *ret = NULL;\n if (meth == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_NULL_SSL_METHOD_PASSED);\n return (NULL);\n }\n if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL))\n return NULL;\n if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n goto err;\n }\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL)\n goto err;\n ret->method = meth;\n ret->min_proto_version = 0;\n ret->max_proto_version = 0;\n ret->session_cache_mode = SSL_SESS_CACHE_SERVER;\n ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n ret->session_timeout = meth->get_timeout();\n ret->references = 1;\n ret->lock = CRYPTO_THREAD_lock_new();\n if (ret->lock == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(ret);\n return NULL;\n }\n ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;\n ret->verify_mode = SSL_VERIFY_NONE;\n if ((ret->cert = ssl_cert_new()) == NULL)\n goto err;\n ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp);\n if (ret->sessions == NULL)\n goto err;\n ret->cert_store = X509_STORE_new();\n if (ret->cert_store == NULL)\n goto err;\n#ifndef OPENSSL_NO_CT\n ret->ctlog_store = CTLOG_STORE_new();\n if (ret->ctlog_store == NULL)\n goto err;\n#endif\n if (!ssl_create_cipher_list(ret->method,\n &ret->cipher_list, &ret->cipher_list_by_id,\n SSL_DEFAULT_CIPHER_LIST, ret->cert)\n || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);\n goto err2;\n }\n ret->param = X509_VERIFY_PARAM_new();\n if (ret->param == NULL)\n goto err;\n if ((ret->md5 = EVP_get_digestbyname("ssl3-md5")) == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n goto err2;\n }\n if ((ret->sha1 = EVP_get_digestbyname("ssl3-sha1")) == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n goto err2;\n }\n if ((ret->ca_names = sk_X509_NAME_new_null()) == NULL)\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data))\n goto err;\n if (!(meth->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS))\n ret->comp_methods = SSL_COMP_get_compression_methods();\n ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n ret->split_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n if ((RAND_bytes(ret->ext.tick_key_name,\n sizeof(ret->ext.tick_key_name)) <= 0)\n || (RAND_bytes(ret->ext.tick_hmac_key,\n sizeof(ret->ext.tick_hmac_key)) <= 0)\n || (RAND_bytes(ret->ext.tick_aes_key,\n sizeof(ret->ext.tick_aes_key)) <= 0))\n ret->options |= SSL_OP_NO_TICKET;\n#ifndef OPENSSL_NO_SRP\n if (!SSL_CTX_SRP_CTX_init(ret))\n goto err;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n# ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO\n# define eng_strx(x) #x\n# define eng_str(x) eng_strx(x)\n {\n ENGINE *eng;\n eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n if (!eng) {\n ERR_clear_error();\n ENGINE_load_builtin_engines();\n eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n }\n if (!eng || !SSL_CTX_set_client_cert_engine(ret, eng))\n ERR_clear_error();\n }\n# endif\n#endif\n ret->options |= SSL_OP_LEGACY_SERVER_CONNECT;\n ret->options |= SSL_OP_NO_COMPRESSION;\n ret->ext.status_type = TLSEXT_STATUSTYPE_nothing;\n ret->max_early_data = SSL3_RT_MAX_PLAIN_LENGTH;\n return ret;\n err:\n SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n err2:\n SSL_CTX_free(ret);\n return NULL;\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)\n{\n OPENSSL_LHASH *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)\n goto err0;\n if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n goto err1;\n ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);\n ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);\n ret->num_nodes = MIN_NODES / 2;\n ret->num_alloc_nodes = MIN_NODES;\n ret->pmax = MIN_NODES / 2;\n ret->up_load = UP_LOAD;\n ret->down_load = DOWN_LOAD;\n return (ret);\n err1:\n OPENSSL_free(ret);\n err0:\n return (NULL);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
|
1,122
| 0
|
https://github.com/libav/libav/blob/53e35fd340d75c40395e4446b76a72bb1962899b/libavformat/mpc8.c/#L239
|
static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap)
{
MPCContext *c = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st;
int tag = 0;
int64_t size, pos;
c->header_pos = avio_tell(pb);
if(avio_rl32(pb) != TAG_MPCK){
av_log(s, AV_LOG_ERROR, "Not a Musepack8 file\n");
return -1;
}
while(!url_feof(pb)){
pos = avio_tell(pb);
mpc8_get_chunk_header(pb, &tag, &size);
if(tag == TAG_STREAMHDR)
break;
mpc8_handle_chunk(s, tag, pos, size);
}
if(tag != TAG_STREAMHDR){
av_log(s, AV_LOG_ERROR, "Stream header not found\n");
return -1;
}
pos = avio_tell(pb);
avio_seek(pb, 4, SEEK_CUR);
c->ver = avio_r8(pb);
if(c->ver != 8){
av_log(s, AV_LOG_ERROR, "Unknown stream version %d\n", c->ver);
return -1;
}
c->samples = ff_get_v(pb);
ff_get_v(pb);
st = av_new_stream(s, 0);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
st->codec->codec_id = CODEC_ID_MUSEPACK8;
st->codec->bits_per_coded_sample = 16;
st->codec->extradata_size = 2;
st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
avio_read(pb, st->codec->extradata, st->codec->extradata_size);
st->codec->channels = (st->codec->extradata[1] >> 4) + 1;
st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5];
av_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate);
st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2);
size -= avio_tell(pb) - pos;
return 0;
}
|
['static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n MPCContext *c = s->priv_data;\n AVIOContext *pb = s->pb;\n AVStream *st;\n int tag = 0;\n int64_t size, pos;\n c->header_pos = avio_tell(pb);\n if(avio_rl32(pb) != TAG_MPCK){\n av_log(s, AV_LOG_ERROR, "Not a Musepack8 file\\n");\n return -1;\n }\n while(!url_feof(pb)){\n pos = avio_tell(pb);\n mpc8_get_chunk_header(pb, &tag, &size);\n if(tag == TAG_STREAMHDR)\n break;\n mpc8_handle_chunk(s, tag, pos, size);\n }\n if(tag != TAG_STREAMHDR){\n av_log(s, AV_LOG_ERROR, "Stream header not found\\n");\n return -1;\n }\n pos = avio_tell(pb);\n avio_seek(pb, 4, SEEK_CUR);\n c->ver = avio_r8(pb);\n if(c->ver != 8){\n av_log(s, AV_LOG_ERROR, "Unknown stream version %d\\n", c->ver);\n return -1;\n }\n c->samples = ff_get_v(pb);\n ff_get_v(pb);\n st = av_new_stream(s, 0);\n if (!st)\n return AVERROR(ENOMEM);\n st->codec->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codec->codec_id = CODEC_ID_MUSEPACK8;\n st->codec->bits_per_coded_sample = 16;\n st->codec->extradata_size = 2;\n st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);\n avio_read(pb, st->codec->extradata, st->codec->extradata_size);\n st->codec->channels = (st->codec->extradata[1] >> 4) + 1;\n st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5];\n av_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate);\n st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2);\n size -= avio_tell(pb) - pos;\n return 0;\n}']
|
1,123
| 0
|
https://github.com/libav/libav/blob/67ce33162aa93bee1a5f9e8d6f00060329fa67da/libavcodec/lpc.h/#L77
|
static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,
LPC_TYPE *lpc, int lpc_stride, int fail,
int normalize)
{
int i, j;
LPC_TYPE err;
LPC_TYPE *lpc_last = lpc;
if (normalize)
err = *autoc++;
if (fail && (autoc[max_order - 1] == 0 || err <= 0))
return -1;
for(i=0; i<max_order; i++) {
LPC_TYPE r = -autoc[i];
if (normalize) {
for(j=0; j<i; j++)
r -= lpc_last[j] * autoc[i-j-1];
r /= err;
err *= 1.0 - (r * r);
}
lpc[i] = r;
for(j=0; j < (i+1)>>1; j++) {
LPC_TYPE f = lpc_last[ j];
LPC_TYPE b = lpc_last[i-1-j];
lpc[ j] = f + r * b;
lpc[i-1-j] = b + r * f;
}
if (fail && err < 0)
return -1;
lpc_last = lpc;
lpc += lpc_stride;
}
return 0;
}
|
['static void backward_filter(RA288Context *ractx)\n{\n float temp1[37];\n float temp2[11];\n do_hybrid_window(36, 40, 35, ractx->sp_block+1, temp1, ractx->sp_hist,\n ractx->sp_rec, syn_window);\n if (!compute_lpc_coefs(temp1, 36, ractx->sp_lpc, 0, 1, 1))\n colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36);\n do_hybrid_window(10, 8, 20, ractx->gain_block+2, temp2, ractx->gain_hist,\n ractx->gain_rec, gain_window);\n if (!compute_lpc_coefs(temp2, 10, ractx->gain_lpc, 0, 1, 1))\n colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10);\n}', 'static inline int compute_lpc_coefs(const LPC_TYPE *autoc, int max_order,\n LPC_TYPE *lpc, int lpc_stride, int fail,\n int normalize)\n{\n int i, j;\n LPC_TYPE err;\n LPC_TYPE *lpc_last = lpc;\n if (normalize)\n err = *autoc++;\n if (fail && (autoc[max_order - 1] == 0 || err <= 0))\n return -1;\n for(i=0; i<max_order; i++) {\n LPC_TYPE r = -autoc[i];\n if (normalize) {\n for(j=0; j<i; j++)\n r -= lpc_last[j] * autoc[i-j-1];\n r /= err;\n err *= 1.0 - (r * r);\n }\n lpc[i] = r;\n for(j=0; j < (i+1)>>1; j++) {\n LPC_TYPE f = lpc_last[ j];\n LPC_TYPE b = lpc_last[i-1-j];\n lpc[ j] = f + r * b;\n lpc[i-1-j] = b + r * f;\n }\n if (fail && err < 0)\n return -1;\n lpc_last = lpc;\n lpc += lpc_stride;\n }\n return 0;\n}']
|
1,124
| 0
|
https://github.com/openssl/openssl/blob/0f3ffbd1581fad58095fedcc32b0da42a486b8b7/apps/passwd.c/#L807
|
static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,
char *passwd, BIO *out, int quiet, int table,
int reverse, size_t pw_maxlen, passwd_modes mode)
{
char *hash = NULL;
assert(salt_p != NULL);
assert(salt_malloc_p != NULL);
if (!passed_salt) {
size_t saltlen = 0;
size_t i;
#ifndef OPENSSL_NO_DES
if (mode == passwd_crypt)
saltlen = 2;
#endif
if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5)
saltlen = 8;
if (mode == passwd_sha256 || mode == passwd_sha512)
saltlen = 16;
assert(saltlen != 0);
if (*salt_malloc_p == NULL)
*salt_p = *salt_malloc_p = app_malloc(saltlen + 1, "salt buffer");
if (RAND_bytes((unsigned char *)*salt_p, saltlen) <= 0)
goto end;
for (i = 0; i < saltlen; i++)
(*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f];
(*salt_p)[i] = 0;
# ifdef CHARSET_EBCDIC
ascii2ebcdic(*salt_p, *salt_p, saltlen);
# endif
}
assert(*salt_p != NULL);
if ((strlen(passwd) > pw_maxlen)) {
if (!quiet)
BIO_printf(bio_err,
"Warning: truncating password to %u characters\n",
(unsigned)pw_maxlen);
passwd[pw_maxlen] = 0;
}
assert(strlen(passwd) <= pw_maxlen);
#ifndef OPENSSL_NO_DES
if (mode == passwd_crypt)
hash = DES_crypt(passwd, *salt_p);
#endif
if (mode == passwd_md5 || mode == passwd_apr1)
hash = md5crypt(passwd, (mode == passwd_md5 ? "1" : "apr1"), *salt_p);
if (mode == passwd_aixmd5)
hash = md5crypt(passwd, "", *salt_p);
if (mode == passwd_sha256 || mode == passwd_sha512)
hash = shacrypt(passwd, (mode == passwd_sha256 ? "5" : "6"), *salt_p);
assert(hash != NULL);
if (table && !reverse)
BIO_printf(out, "%s\t%s\n", passwd, hash);
else if (table && reverse)
BIO_printf(out, "%s\t%s\n", hash, passwd);
else
BIO_printf(out, "%s\n", hash);
return 1;
end:
return 0;
}
|
['static int do_passwd(int passed_salt, char **salt_p, char **salt_malloc_p,\n char *passwd, BIO *out, int quiet, int table,\n int reverse, size_t pw_maxlen, passwd_modes mode)\n{\n char *hash = NULL;\n assert(salt_p != NULL);\n assert(salt_malloc_p != NULL);\n if (!passed_salt) {\n size_t saltlen = 0;\n size_t i;\n#ifndef OPENSSL_NO_DES\n if (mode == passwd_crypt)\n saltlen = 2;\n#endif\n if (mode == passwd_md5 || mode == passwd_apr1 || mode == passwd_aixmd5)\n saltlen = 8;\n if (mode == passwd_sha256 || mode == passwd_sha512)\n saltlen = 16;\n assert(saltlen != 0);\n if (*salt_malloc_p == NULL)\n *salt_p = *salt_malloc_p = app_malloc(saltlen + 1, "salt buffer");\n if (RAND_bytes((unsigned char *)*salt_p, saltlen) <= 0)\n goto end;\n for (i = 0; i < saltlen; i++)\n (*salt_p)[i] = cov_2char[(*salt_p)[i] & 0x3f];\n (*salt_p)[i] = 0;\n# ifdef CHARSET_EBCDIC\n ascii2ebcdic(*salt_p, *salt_p, saltlen);\n# endif\n }\n assert(*salt_p != NULL);\n if ((strlen(passwd) > pw_maxlen)) {\n if (!quiet)\n BIO_printf(bio_err,\n "Warning: truncating password to %u characters\\n",\n (unsigned)pw_maxlen);\n passwd[pw_maxlen] = 0;\n }\n assert(strlen(passwd) <= pw_maxlen);\n#ifndef OPENSSL_NO_DES\n if (mode == passwd_crypt)\n hash = DES_crypt(passwd, *salt_p);\n#endif\n if (mode == passwd_md5 || mode == passwd_apr1)\n hash = md5crypt(passwd, (mode == passwd_md5 ? "1" : "apr1"), *salt_p);\n if (mode == passwd_aixmd5)\n hash = md5crypt(passwd, "", *salt_p);\n if (mode == passwd_sha256 || mode == passwd_sha512)\n hash = shacrypt(passwd, (mode == passwd_sha256 ? "5" : "6"), *salt_p);\n assert(hash != NULL);\n if (table && !reverse)\n BIO_printf(out, "%s\\t%s\\n", passwd, hash);\n else if (table && reverse)\n BIO_printf(out, "%s\\t%s\\n", hash, passwd);\n else\n BIO_printf(out, "%s\\n", hash);\n return 1;\n end:\n return 0;\n}']
|
1,125
| 0
|
https://github.com/libav/libav/blob/25b6837f7cacd691b19cbc12b9dad1ce84a318a1/libavcodec/vp8dsp.c/#L72
|
static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])
{
int i, a1, b1, c1, d1;
int16_t tmp[16];
for (i = 0; i < 4; i++) {
a1 = (dc[i * 4 + 0] + dc[i * 4 + 2]) * 23170;
b1 = (dc[i * 4 + 0] - dc[i * 4 + 2]) * 23170;
c1 = dc[i * 4 + 1] * 12540 - dc[i * 4 + 3] * 30274;
d1 = dc[i * 4 + 1] * 30274 + dc[i * 4 + 3] * 12540;
tmp[i * 4 + 0] = (a1 + d1) >> 14;
tmp[i * 4 + 3] = (a1 - d1) >> 14;
tmp[i * 4 + 1] = (b1 + c1) >> 14;
tmp[i * 4 + 2] = (b1 - c1) >> 14;
}
for (i = 0; i < 4; i++) {
a1 = (tmp[i + 0] + tmp[i + 8]) * 23170;
b1 = (tmp[i + 0] - tmp[i + 8]) * 23170;
c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;
d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;
dc[i * 4 + 0] = 0;
dc[i * 4 + 1] = 0;
dc[i * 4 + 2] = 0;
dc[i * 4 + 3] = 0;
block[0][i][0] = (a1 + d1 + 0x20000) >> 18;
block[3][i][0] = (a1 - d1 + 0x20000) >> 18;
block[1][i][0] = (b1 + c1 + 0x20000) >> 18;
block[2][i][0] = (b1 - c1 + 0x20000) >> 18;
}
}
|
['static void vp7_luma_dc_wht_c(int16_t block[4][4][16], int16_t dc[16])\n{\n int i, a1, b1, c1, d1;\n int16_t tmp[16];\n for (i = 0; i < 4; i++) {\n a1 = (dc[i * 4 + 0] + dc[i * 4 + 2]) * 23170;\n b1 = (dc[i * 4 + 0] - dc[i * 4 + 2]) * 23170;\n c1 = dc[i * 4 + 1] * 12540 - dc[i * 4 + 3] * 30274;\n d1 = dc[i * 4 + 1] * 30274 + dc[i * 4 + 3] * 12540;\n tmp[i * 4 + 0] = (a1 + d1) >> 14;\n tmp[i * 4 + 3] = (a1 - d1) >> 14;\n tmp[i * 4 + 1] = (b1 + c1) >> 14;\n tmp[i * 4 + 2] = (b1 - c1) >> 14;\n }\n for (i = 0; i < 4; i++) {\n a1 = (tmp[i + 0] + tmp[i + 8]) * 23170;\n b1 = (tmp[i + 0] - tmp[i + 8]) * 23170;\n c1 = tmp[i + 4] * 12540 - tmp[i + 12] * 30274;\n d1 = tmp[i + 4] * 30274 + tmp[i + 12] * 12540;\n dc[i * 4 + 0] = 0;\n dc[i * 4 + 1] = 0;\n dc[i * 4 + 2] = 0;\n dc[i * 4 + 3] = 0;\n block[0][i][0] = (a1 + d1 + 0x20000) >> 18;\n block[3][i][0] = (a1 - d1 + 0x20000) >> 18;\n block[1][i][0] = (b1 + c1 + 0x20000) >> 18;\n block[2][i][0] = (b1 - c1 + 0x20000) >> 18;\n }\n}']
|
1,126
| 0
|
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num,\n EC_POINT *points[], BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp, *tmp_Z;\n BIGNUM **prod_Z = NULL;\n size_t i;\n int ret = 0;\n if (num == 0)\n return 1;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n tmp_Z = BN_CTX_get(ctx);\n if (tmp_Z == NULL)\n goto err;\n prod_Z = OPENSSL_malloc(num * sizeof(prod_Z[0]));\n if (prod_Z == NULL)\n goto err;\n for (i = 0; i < num; i++) {\n prod_Z[i] = BN_new();\n if (prod_Z[i] == NULL)\n goto err;\n }\n if (!BN_is_zero(points[0]->Z)) {\n if (!BN_copy(prod_Z[0], points[0]->Z))\n goto err;\n } else {\n if (group->meth->field_set_to_one != 0) {\n if (!group->meth->field_set_to_one(group, prod_Z[0], ctx))\n goto err;\n } else {\n if (!BN_one(prod_Z[0]))\n goto err;\n }\n }\n for (i = 1; i < num; i++) {\n if (!BN_is_zero(points[i]->Z)) {\n if (!group->\n meth->field_mul(group, prod_Z[i], prod_Z[i - 1], points[i]->Z,\n ctx))\n goto err;\n } else {\n if (!BN_copy(prod_Z[i], prod_Z[i - 1]))\n goto err;\n }\n }\n if (!BN_mod_inverse(tmp, prod_Z[num - 1], group->field, ctx)) {\n ECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);\n goto err;\n }\n if (group->meth->field_encode != 0) {\n if (!group->meth->field_encode(group, tmp, tmp, ctx))\n goto err;\n if (!group->meth->field_encode(group, tmp, tmp, ctx))\n goto err;\n }\n for (i = num - 1; i > 0; --i) {\n if (!BN_is_zero(points[i]->Z)) {\n if (!group->\n meth->field_mul(group, tmp_Z, prod_Z[i - 1], tmp, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp, tmp, points[i]->Z, ctx))\n goto err;\n if (!BN_copy(points[i]->Z, tmp_Z))\n goto err;\n }\n }\n if (!BN_is_zero(points[0]->Z)) {\n if (!BN_copy(points[0]->Z, tmp))\n goto err;\n }\n for (i = 0; i < num; i++) {\n EC_POINT *p = points[i];\n if (!BN_is_zero(p->Z)) {\n if (!group->meth->field_sqr(group, tmp, p->Z, ctx))\n goto err;\n if (!group->meth->field_mul(group, p->X, p->X, tmp, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp, tmp, p->Z, ctx))\n goto err;\n if (!group->meth->field_mul(group, p->Y, p->Y, tmp, ctx))\n goto err;\n if (group->meth->field_set_to_one != 0) {\n if (!group->meth->field_set_to_one(group, p->Z, ctx))\n goto err;\n } else {\n if (!BN_one(p->Z))\n goto err;\n }\n p->Z_is_one = 1;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n if (prod_Z != NULL) {\n for (i = 0; i < num; i++) {\n if (prod_Z[i] == NULL)\n break;\n BN_clear_free(prod_Z[i]);\n }\n OPENSSL_free(prod_Z);\n }\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,127
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_lib.c/#L393
|
int BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
return 0;
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
bn_check_top(a);
return 1;
}
|
['static int dh_builtin_genparams(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n BIGNUM *t1, *t2;\n int g, ok = -1;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (!ret->p && ((ret->p = BN_new()) == NULL))\n goto err;\n if (!ret->g && ((ret->g = BN_new()) == NULL))\n goto err;\n if (generator <= 1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);\n goto err;\n }\n if (generator == DH_GENERATOR_2) {\n if (!BN_set_word(t1, 24))\n goto err;\n if (!BN_set_word(t2, 11))\n goto err;\n g = 2;\n } else if (generator == DH_GENERATOR_5) {\n if (!BN_set_word(t1, 10))\n goto err;\n if (!BN_set_word(t2, 3))\n goto err;\n g = 5;\n } else {\n if (!BN_set_word(t1, 2))\n goto err;\n if (!BN_set_word(t2, 1))\n goto err;\n g = generator;\n }\n if (!BN_generate_prime_ex(ret->p, prime_len, 1, t1, t2, cb))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n if (!BN_set_word(ret->g, g))\n goto err;\n ok = 1;\n err:\n if (ok == -1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB);\n ok = 0;\n }\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}']
|
1,128
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_asm.c/#L404
|
BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
{
BN_ULONG t1,t2;
int c=0;
bn_check_num(n);
if (n <= 0) return((BN_ULONG)0);
for (;;)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
t1=a[1]; t2=b[1];
r[1]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
t1=a[2]; t2=b[2];
r[2]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
t1=a[3]; t2=b[3];
r[3]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
a+=4;
b+=4;
r+=4;
}
return(c);
}
|
['int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)\n\t{\n\tBN_CTX *ctx;\n\tBIGNUM k,*kinv=NULL,*r=NULL;\n\tint ret=0;\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\tBN_init(&k);\n\tif ((r=BN_new()) == NULL) goto err;\n\tkinv=NULL;\n\tfor (;;)\n\t\t{\n\t\tif (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err;\n\t\tif (BN_cmp(&k,dsa->q) >= 0)\n\t\t\tBN_sub(&k,&k,dsa->q);\n\t\tif (!BN_is_zero(&k)) break;\n\t\t}\n\tif ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p,\n\t\t\t\tdsa->p,ctx)) goto err;\n\t\t}\n\tif (!BN_mod_exp_mont(r,dsa->g,&k,dsa->p,ctx,\n\t\t(BN_MONT_CTX *)dsa->method_mont_p)) goto err;\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 (kinv != NULL) BN_clear_free(kinv);\n\t\tif (r != NULL) BN_clear_free(r);\n\t\t}\n\tif (ctx_in == NULL) BN_CTX_free(ctx);\n\tif (kinv != NULL) BN_clear_free(kinv);\n\tBN_clear_free(&k);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,\n\t BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*aa,*r;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n#if 1\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n#endif\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&val[0]);\n\tts=1;\n\tif (BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0]),a,m,ctx);\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,\n\t int n, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_part_recursive %d * %d\\n",tn+n,tn+n);\n#endif\n\tif (n < 8)\n\t\t{\n\t\ti=tn+n;\n\t\tbn_mul_normal(r,a,i,b,i);\n\t\treturn;\n\t\t}\n\tbn_sub_words(t, a, &(a[n]),n);\n\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n if (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\ti=n/2;\n\t\tj=tn-i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\tj,i,p);\n\t\t\t\tmemset(&(r[n2+tn*2]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tn*2));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ttn-i,i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)\n {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tbn_check_num(n);\n\tif (n <= 0) return((BN_ULONG)0);\n\tfor (;;)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\ta+=4;\n\t\tb+=4;\n\t\tr+=4;\n\t\t}\n\treturn(c);\n\t}']
|
1,129
| 0
|
https://github.com/openssl/openssl/blob/ce4b274aa1b0c584b0b863e888acb954d5040352/crypto/lhash/lhash.c/#L365
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['static int sv_body(char *hostname, int s, unsigned char *context)\n\t{\n\tchar *buf=NULL;\n\tfd_set readfds;\n\tint ret=1,width;\n\tint k,i;\n\tunsigned long l;\n\tSSL *con=NULL;\n\tBIO *sbio;\n#ifdef OPENSSL_SYS_WINDOWS\n\tstruct timeval tv;\n#endif\n\tif ((buf=OPENSSL_malloc(bufsize)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto err;\n\t\t}\n#ifdef FIONBIO\n\tif (s_nbio)\n\t\t{\n\t\tunsigned long sl=1;\n\t\tif (!s_quiet)\n\t\t\tBIO_printf(bio_err,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&sl) < 0)\n\t\t\tERR_print_errors(bio_err);\n\t\t}\n#endif\n\tif (con == NULL) {\n\t\tcon=SSL_new(ctx);\n#ifndef OPENSSL_NO_KRB5\n\t\tif ((con->kssl_ctx = kssl_ctx_new()) != NULL)\n {\n kssl_ctx_setstring(con->kssl_ctx, KSSL_SERVICE,\n\t\t\t\t\t\t\t\tKRB5SVC);\n kssl_ctx_setstring(con->kssl_ctx, KSSL_KEYTAB,\n\t\t\t\t\t\t\t\tKRB5KEYTAB);\n }\n#endif\n\t\tif(context)\n\t\t SSL_set_session_id_context(con, context,\n\t\t\t\t\t\t strlen((char *)context));\n\t}\n\tSSL_clear(con);\n\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (s_nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_accept_state(con);\n\tif (s_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(SSL_get_rbio(con),bio_dump_cb);\n\t\tBIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);\n\t\t}\n\tif (s_msg)\n\t\t{\n\t\tSSL_set_msg_callback(con, msg_cb);\n\t\tSSL_set_msg_callback_arg(con, bio_s_out);\n\t\t}\n\twidth=s+1;\n\tfor (;;)\n\t\t{\n\t\tint read_from_terminal;\n\t\tint read_from_sslcon;\n\t\tread_from_terminal = 0;\n\t\tread_from_sslcon = SSL_pending(con);\n\t\tif (!read_from_sslcon)\n\t\t\t{\n\t\t\tFD_ZERO(&readfds);\n#ifndef OPENSSL_SYS_WINDOWS\n\t\t\tFD_SET(fileno(stdin),&readfds);\n#endif\n\t\t\tFD_SET(s,&readfds);\n#ifdef OPENSSL_SYS_WINDOWS\n\t\t\ttv.tv_sec = 1;\n\t\t\ttv.tv_usec = 0;\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,&tv);\n\t\t\tif((i < 0) || (!i && !_kbhit() ) )continue;\n\t\t\tif(_kbhit())\n\t\t\t\tread_from_terminal = 1;\n#else\n\t\t\ti=select(width,(void *)&readfds,NULL,NULL,NULL);\n\t\t\tif (i <= 0) continue;\n\t\t\tif (FD_ISSET(fileno(stdin),&readfds))\n\t\t\t\tread_from_terminal = 1;\n#endif\n\t\t\tif (FD_ISSET(s,&readfds))\n\t\t\t\tread_from_sslcon = 1;\n\t\t\t}\n\t\tif (read_from_terminal)\n\t\t\t{\n\t\t\tif (s_crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=read(fileno(stdin), buf, bufsize/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (buf[j] == \'\\n\')\n\t\t\t\t\t\tlf_num++;\n\t\t\t\tfor (j = i-1; j >= 0; j--)\n\t\t\t\t\t{\n\t\t\t\t\tbuf[j+lf_num] = buf[j];\n\t\t\t\t\tif (buf[j] == \'\\n\')\n\t\t\t\t\t\t{\n\t\t\t\t\t\tlf_num--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tbuf[j+lf_num] = \'\\r\';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tassert(lf_num == 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ti=read(fileno(stdin),buf,bufsize);\n\t\t\tif (!s_quiet)\n\t\t\t\t{\n\t\t\t\tif ((i <= 0) || (buf[0] == \'Q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tclose_accept_socket();\n\t\t\t\t\tret= -11;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((i <= 0) || (buf[0] == \'q\'))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tSHUTDOWN(s);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'r\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif ((buf[0] == \'R\') &&\n\t\t\t\t\t((buf[1] == \'\\n\') || (buf[1] == \'\\r\')))\n\t\t\t\t\t{\n\t\t\t\t\tSSL_set_verify(con,\n\t\t\t\t\t\tSSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);\n\t\t\t\t\tSSL_renegotiate(con);\n\t\t\t\t\ti=SSL_do_handshake(con);\n\t\t\t\t\tprintf("SSL_do_handshake -> %d\\n",i);\n\t\t\t\t\ti=0;\n\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'P\')\n\t\t\t\t\t{\n\t\t\t\t\tstatic char *str="Lets print some clear text\\n";\n\t\t\t\t\tBIO_write(SSL_get_wbio(con),str,strlen(str));\n\t\t\t\t\t}\n\t\t\t\tif (buf[0] == \'S\')\n\t\t\t\t\t{\n\t\t\t\t\tprint_stats(bio_s_out,SSL_get_SSL_CTX(con));\n\t\t\t\t\t}\n\t\t\t\t}\n#ifdef CHARSET_EBCDIC\n\t\t\tebcdic2ascii(buf,buf,i);\n#endif\n\t\t\tl=k=0;\n\t\t\tfor (;;)\n\t\t\t\t{\n#ifdef RENEG\n{ static count=0; if (++count == 100) { count=0; SSL_renegotiate(con); } }\n#endif\n\t\t\t\tk=SSL_write(con,&(buf[l]),(unsigned int)i);\n\t\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Write BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\tl+=k;\n\t\t\t\ti-=k;\n\t\t\t\tif (i <= 0) break;\n\t\t\t\t}\n\t\t\t}\n\t\tif (read_from_sslcon)\n\t\t\t{\n\t\t\tif (!SSL_is_init_finished(con))\n\t\t\t\t{\n\t\t\t\ti=init_ssl_connection(con);\n\t\t\t\tif (i < 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=0;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse if (i == 0)\n\t\t\t\t\t{\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\nagain:\n\t\t\t\ti=SSL_read(con,(char *)buf,bufsize);\n\t\t\t\tswitch (SSL_get_error(con,i))\n\t\t\t\t\t{\n\t\t\t\tcase SSL_ERROR_NONE:\n#ifdef CHARSET_EBCDIC\n\t\t\t\t\tascii2ebcdic(buf,buf,i);\n#endif\n\t\t\t\t\twrite(fileno(stdout),buf,\n\t\t\t\t\t\t(unsigned int)i);\n\t\t\t\t\tif (SSL_pending(con)) goto again;\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\t\tBIO_printf(bio_s_out,"Read BLOCK\\n");\n\t\t\t\t\tbreak;\n\t\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\t\tBIO_printf(bio_s_out,"ERROR\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\t\tBIO_printf(bio_s_out,"DONE\\n");\n\t\t\t\t\tret=1;\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\nerr:\n\tBIO_printf(bio_s_out,"shutting down SSL\\n");\n#if 1\n\tSSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);\n#else\n\tSSL_shutdown(con);\n#endif\n\tif (con != NULL) SSL_free(con);\n\tBIO_printf(bio_s_out,"CONNECTION CLOSED\\n");\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bufsize);\n\t\tOPENSSL_free(buf);\n\t\t}\n\tif (ret >= 0)\n\t\tBIO_printf(bio_s_out,"ACCEPT\\n");\n\treturn(ret);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->max_cert_list=ctx->max_cert_list;\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->read_ahead=ctx->read_ahead;\n\ts->msg_callback=ctx->msg_callback;\n\ts->msg_callback_arg=ctx->msg_callback_arg;\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_depth=ctx->verify_depth;\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tOPENSSL_free(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#else\n\tif (s->new_session)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR);\n\t\treturn 0;\n\t\t}\n#endif\n\ts->type=0;\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n#if 0\n\ts->read_ahead=s->ctx->read_ahead;\n#endif\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\ts->first_packet=0;\n#if 1\n\tif (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\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}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,130
| 0
|
https://gitlab.com/libtiff/libtiff/blob/3adc33842b7533066daea2516741832edc44d5fd/libtiff/tif_read.c/#L948
|
static int
TIFFStartTile(TIFF* tif, uint32 tile)
{
TIFFDirectory *td = &tif->tif_dir;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupdecode)(tif))
return (0);
tif->tif_flags |= TIFF_CODERSETUP;
}
tif->tif_curtile = tile;
tif->tif_row =
(tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *
td->td_tilelength;
tif->tif_col =
(tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *
td->td_tilewidth;
tif->tif_flags &= ~TIFF_BUF4WRITE;
if (tif->tif_flags&TIFF_NOREADRAW)
{
tif->tif_rawcp = NULL;
tif->tif_rawcc = 0;
}
else
{
tif->tif_rawcp = tif->tif_rawdata;
tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];
}
return ((*tif->tif_predecode)(tif,
(uint16)(tile/td->td_stripsperimage)));
}
|
['DECLAREreadFunc(readContigTilesIntoBuffer)\n{\n\tint status = 1;\n\ttdata_t tilebuf = _TIFFmalloc(TIFFTileSize(in));\n\tuint32 imagew = TIFFScanlineSize(in);\n\tuint32 tilew = TIFFTileRowSize(in);\n\tint iskew = imagew - tilew;\n\tuint8* bufp = (uint8*) buf;\n\tuint32 tw, tl;\n\tuint32 row;\n\t(void) spp;\n\tif (tilebuf == 0)\n\t\treturn 0;\n\t(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);\n\t(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);\n\tfor (row = 0; row < imagelength; row += tl) {\n\t\tuint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;\n\t\tuint32 colb = 0;\n\t\tuint32 col;\n\t\tfor (col = 0; col < imagewidth; col += tw) {\n\t\t\tif (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0\n\t\t\t && !ignore) {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t "Error, can\'t read tile at %lu %lu",\n\t\t\t\t (unsigned long) col,\n\t\t\t\t (unsigned long) row);\n\t\t\t\tstatus = 0;\n\t\t\t\tgoto done;\n\t\t\t}\n\t\t\tif (colb + tilew > imagew) {\n\t\t\t\tuint32 width = imagew - colb;\n\t\t\t\tuint32 oskew = tilew - width;\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t tilebuf, nrow, width,\n\t\t\t\t oskew + iskew, oskew );\n\t\t\t} else\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t tilebuf, nrow, tilew,\n\t\t\t\t iskew, 0);\n\t\t\tcolb += tilew;\n\t\t}\n\t\tbufp += imagew * nrow;\n\t}\ndone:\n\t_TIFFfree(tilebuf);\n\treturn status;\n}', 'tmsize_t\nTIFFTileSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileSize64(TIFF* tif)\n{\n\treturn (TIFFVTileSize64(tif, tif->tif_dir.td_tilelength));\n}', 'uint64\nTIFFVTileSize64(TIFF* tif, uint32 nrows)\n{\n\tstatic const char module[] = "TIFFVTileSize64";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (td->td_tilelength == 0 || td->td_tilewidth == 0 ||\n\t td->td_tiledepth == 0)\n\t\treturn (0);\n\tif ((td->td_planarconfig==PLANARCONFIG_CONTIG)&&\n\t (td->td_photometric==PHOTOMETRIC_YCBCR)&&\n\t (td->td_samplesperpixel==3)&&\n\t (!isUpSampled(tif)))\n\t{\n\t\tuint16 ycbcrsubsampling[2];\n\t\tuint16 samplingblock_samples;\n\t\tuint32 samplingblocks_hor;\n\t\tuint32 samplingblocks_ver;\n\t\tuint64 samplingrow_samples;\n\t\tuint64 samplingrow_size;\n\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_YCBCRSUBSAMPLING,ycbcrsubsampling+0,\n\t\t ycbcrsubsampling+1);\n\t\tassert((ycbcrsubsampling[0]==1)||(ycbcrsubsampling[0]==2)||(ycbcrsubsampling[0]==4));\n\t\tassert((ycbcrsubsampling[1]==1)||(ycbcrsubsampling[1]==2)||(ycbcrsubsampling[1]==4));\n\t\tif (ycbcrsubsampling[0]*ycbcrsubsampling[1]==0)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t "Invalid YCbCr subsampling");\n\t\t\treturn 0;\n\t\t}\n\t\tsamplingblock_samples=ycbcrsubsampling[0]*ycbcrsubsampling[1]+2;\n\t\tsamplingblocks_hor=TIFFhowmany_32(td->td_tilewidth,ycbcrsubsampling[0]);\n\t\tsamplingblocks_ver=TIFFhowmany_32(nrows,ycbcrsubsampling[1]);\n\t\tsamplingrow_samples=multiply_64(tif,samplingblocks_hor,samplingblock_samples,module);\n\t\tsamplingrow_size=TIFFhowmany8_64(multiply_64(tif,samplingrow_samples,td->td_bitspersample,module));\n\t\treturn(multiply_64(tif,samplingrow_size,samplingblocks_ver,module));\n\t}\n\telse\n\t\treturn(multiply_64(tif,nrows,TIFFTileRowSize64(tif),module));\n}', 'tmsize_t\nTIFFTileRowSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFTileRowSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFTileRowSize64(tif);\n\tn=(tmsize_t)m;\n\tif ((uint64)n!=m)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\tn=0;\n\t}\n\treturn(n);\n}', 'uint64\nTIFFTileRowSize64(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint64 rowsize;\n\tif (td->td_tilelength == 0 || td->td_tilewidth == 0)\n\t\treturn (0);\n\trowsize = multiply_64(tif, td->td_bitspersample, td->td_tilewidth,\n\t "TIFFTileRowSize");\n\tif (td->td_planarconfig == PLANARCONFIG_CONTIG)\n\t\trowsize = multiply_64(tif, rowsize, td->td_samplesperpixel,\n\t\t "TIFFTileRowSize");\n\treturn (TIFFhowmany8_64(rowsize));\n}', 'tmsize_t\nTIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFReadEncodedTile(tif,\n\t TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}']
|
1,131
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L536
|
int BN_set_word(BIGNUM *a, BN_ULONG w)
{
bn_check_top(a);
if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
return (0);
a->neg = 0;
a->d[0] = w;
a->top = (w ? 1 : 0);
bn_check_top(a);
return (1);
}
|
['static int 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 *local_prk = NULL;\n BIGNUM *prk;\n if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) {\n local_prk = prk = BN_new();\n if (local_prk == NULL)\n goto err;\n BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n } else {\n prk = priv_key;\n }\n if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {\n BN_free(local_prk);\n goto err;\n }\n BN_free(local_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_rand_range(BIGNUM *r, const BIGNUM *range)\n{\n return bn_rand_range(0, r, range);\n}', 'static int bn_rand_range(int pseudo, BIGNUM *r, const BIGNUM *range)\n{\n int (*bn_rand) (BIGNUM *, int, int, int) =\n pseudo ? BN_pseudo_rand : BN_rand;\n int n;\n int count = 100;\n if (range->neg || BN_is_zero(range)) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE);\n return 0;\n }\n n = BN_num_bits(range);\n if (n == 1)\n BN_zero(r);\n else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {\n do {\n if (!bn_rand(r, n + 1, -1, 0))\n return 0;\n if (BN_cmp(r, range) >= 0) {\n if (!BN_sub(r, r, range))\n return 0;\n if (BN_cmp(r, range) >= 0)\n if (!BN_sub(r, r, range))\n return 0;\n }\n if (!--count) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n } else {\n do {\n if (!bn_rand(r, n, -1, 0))\n return 0;\n if (!--count) {\n BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n }\n bn_check_top(r);\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}']
|
1,132
| 0
|
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_lib.c/#L447
|
BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*a;
const BN_ULONG *B;
int i;
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);
}
#if 1
B=b->d;
if (B != NULL)
{
#if 0
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:
;
}
#else
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: ;
}
#endif
Free(b->d);
}
b->d=a;
b->max=words;
A= &(b->d[b->top]);
for (i=(b->max - b->top)>>3; i>0; i--,A+=8)
{
A[0]=0; A[1]=0; A[2]=0; A[3]=0;
A[4]=0; A[5]=0; A[6]=0; A[7]=0;
}
for (i=(b->max - b->top)&7; i>0; i--,A++)
A[0]=0;
#else
memset(A,0,sizeof(BN_ULONG)*(words+1));
memcpy(A,b->d,sizeof(b->d[0])*b->top);
b->d=a;
b->max=words;
#endif
}
return(b);
}
|
['int BN_mod_exp2_mont(BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, BIGNUM *a2,\n\t BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,k,bits,bits1,bits2,ret=0,wstart,wend,window,xvalue,yvalue;\n\tint start=1,ts=0,x,y;\n\tBIGNUM *d,*aa1,*aa2,*r;\n\tBIGNUM val[EXP2_TABLE_SIZE][EXP2_TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a1);\n\tbn_check_top(p1);\n\tbn_check_top(a2);\n\tbn_check_top(p2);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits1=BN_num_bits(p1);\n\tbits2=BN_num_bits(p2);\n\tif ((bits1 == 0) && (bits2 == 0))\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tbits=(bits1 > bits2)?bits1:bits2;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&(val[0][0]));\n\tBN_init(&(val[1][1]));\n\tBN_init(&(val[0][1]));\n\tBN_init(&(val[1][0]));\n\tts=1;\n\tif (BN_ucmp(a1,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[1][0]),a1,m,ctx);\n\t\taa1= &(val[1][0]);\n\t\t}\n\telse\n\t\taa1=a1;\n\tif (BN_ucmp(a2,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0][1]),a2,m,ctx);\n\t\taa2= &(val[0][1]);\n\t\t}\n\telse\n\t\taa2=a2;\n\tif (!BN_to_montgomery(&(val[1][0]),aa1,mont,ctx)) goto err;\n\tif (!BN_to_montgomery(&(val[0][1]),aa2,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(&(val[1][1]),\n\t\t&(val[1][0]),&(val[0][1]),mont,ctx))\n\t\tgoto err;\n#if 0\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits > 250)\n\t\twindow=5;\n\telse if (bits >= 120)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n#else\n\twindow=EXP2_TABLE_BITS;\n#endif\n\tk=1<<window;\n\tfor (x=0; x<k; x++)\n\t\t{\n\t\tif (x >= 2)\n\t\t\t{\n\t\t\tBN_init(&(val[x][0]));\n\t\t\tBN_init(&(val[x][1]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][0]),\n\t\t\t\t&(val[1][0]),&(val[x-1][0]),mont,ctx)) goto err;\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][1]),\n\t\t\t\t&(val[1][0]),&(val[x-1][1]),mont,ctx)) goto err;\n\t\t\t}\n\t\tfor (y=2; y<k; y++)\n\t\t\t{\n\t\t\tBN_init(&(val[x][y]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[x][y]),\n\t\t\t\t&(val[x][y-1]),&(val[0][1]),mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tts=k;\n\tstart=1;\n\txvalue=0;\n\tyvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\txvalue=BN_is_bit_set(p1,wstart);\n\t\tyvalue=BN_is_bit_set(p2,wstart);\n\t\tif (!(xvalue || yvalue))\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\twstart--;\n\t\t\tif (wstart < 0) break;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\txvalue+=xvalue;\n\t\t\txvalue|=BN_is_bit_set(p1,wstart-i);\n\t\t\tyvalue+=yvalue;\n\t\t\tyvalue|=BN_is_bit_set(p2,wstart-i);\n\t\t\t}\n\t\tif (!start)\n\t\t\tfor (j=0; j<i; j++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (xvalue || yvalue)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,&(val[xvalue][yvalue]),\n\t\t\t\tmont,ctx)) goto err;\n\t\t\t}\n\t\twstart-=i;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\t{\n\t\tfor (j=0; j<ts; j++)\n\t\t\t{\n\t\t\tBN_clear_free(&(val[i][j]));\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*a;\n\tconst BN_ULONG *B;\n\tint i;\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}\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n#if 0\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#else\n\t\t\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t\t\t{\n\t\t\t\tBN_ULONG a0,a1,a2,a3;\n\t\t\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\t\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t\t\t}\n\t\t\tswitch (b->top&3)\n\t\t\t\t{\n\t\t\t\tcase 3:\tA[2]=B[2];\n\t\t\t\tcase 2:\tA[1]=B[1];\n\t\t\t\tcase 1:\tA[0]=B[0];\n\t\t\t\tcase 0:\t;\n\t\t\t\t}\n#endif\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tA= &(b->d[b->top]);\n\t\tfor (i=(b->max - b->top)>>3; i>0; i--,A+=8)\n\t\t\t{\n\t\t\tA[0]=0; A[1]=0; A[2]=0; A[3]=0;\n\t\t\tA[4]=0; A[5]=0; A[6]=0; A[7]=0;\n\t\t\t}\n\t\tfor (i=(b->max - b->top)&7; i>0; i--,A++)\n\t\t\tA[0]=0;\n#else\n\t\t\tmemset(A,0,sizeof(BN_ULONG)*(words+1));\n\t\t\tmemcpy(A,b->d,sizeof(b->d[0])*b->top);\n\t\t\tb->d=a;\n\t\t\tb->max=words;\n#endif\n\t\t}\n\treturn(b);\n\t}']
|
1,133
| 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]));
}
|
['BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n\t{\n\tBIGNUM *ret = in;\n\tint err = 1;\n\tint r;\n\tBIGNUM *A, *b, *q, *t, *x, *y;\n\tint e, i, j;\n\tif (!BN_is_odd(p) || BN_abs_is_word(p, 1))\n\t\t{\n\t\tif (BN_abs_is_word(p, 2))\n\t\t\t{\n\t\t\tif (ret == NULL)\n\t\t\t\tret = BN_new();\n\t\t\tif (ret == NULL)\n\t\t\t\tgoto end;\n\t\t\tif (!BN_set_word(ret, BN_is_bit_set(a, 0)))\n\t\t\t\t{\n\t\t\t\tif (ret != in)\n\t\t\t\t\tBN_free(ret);\n\t\t\t\treturn NULL;\n\t\t\t\t}\n\t\t\tbn_check_top(ret);\n\t\t\treturn ret;\n\t\t\t}\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n\t\treturn(NULL);\n\t\t}\n\tif (BN_is_zero(a) || BN_is_one(a))\n\t\t{\n\t\tif (ret == NULL)\n\t\t\tret = BN_new();\n\t\tif (ret == NULL)\n\t\t\tgoto end;\n\t\tif (!BN_set_word(ret, BN_is_one(a)))\n\t\t\t{\n\t\t\tif (ret != in)\n\t\t\t\tBN_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tbn_check_top(ret);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tb = BN_CTX_get(ctx);\n\tq = BN_CTX_get(ctx);\n\tt = BN_CTX_get(ctx);\n\tx = BN_CTX_get(ctx);\n\ty = BN_CTX_get(ctx);\n\tif (y == NULL) goto end;\n\tif (ret == NULL)\n\t\tret = BN_new();\n\tif (ret == NULL) goto end;\n\tif (!BN_nnmod(A, a, p, ctx)) goto end;\n\te = 1;\n\twhile (!BN_is_bit_set(p, e))\n\t\te++;\n\tif (e == 1)\n\t\t{\n\t\tif (!BN_rshift(q, p, 2)) goto end;\n\t\tq->neg = 0;\n\t\tif (!BN_add_word(q, 1)) goto end;\n\t\tif (!BN_mod_exp(ret, A, q, p, ctx)) goto end;\n\t\terr = 0;\n\t\tgoto vrfy;\n\t\t}\n\tif (e == 2)\n\t\t{\n\t\tif (!BN_mod_lshift1_quick(t, A, p)) goto end;\n\t\tif (!BN_rshift(q, p, 3)) goto end;\n\t\tq->neg = 0;\n\t\tif (!BN_mod_exp(b, t, q, p, ctx)) goto end;\n\t\tif (!BN_mod_sqr(y, b, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(t, t, y, p, ctx)) goto end;\n\t\tif (!BN_sub_word(t, 1)) goto end;\n\t\tif (!BN_mod_mul(x, A, b, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(x, x, t, p, ctx)) goto end;\n\t\tif (!BN_copy(ret, x)) goto end;\n\t\terr = 0;\n\t\tgoto vrfy;\n\t\t}\n\tif (!BN_copy(q, p)) goto end;\n\tq->neg = 0;\n\ti = 2;\n\tdo\n\t\t{\n\t\tif (i < 22)\n\t\t\t{\n\t\t\tif (!BN_set_word(y, i)) goto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0)) goto end;\n\t\t\tif (BN_ucmp(y, p) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!(p->neg ? BN_add : BN_sub)(y, y, p)) goto end;\n\t\t\t\t}\n\t\t\tif (BN_is_zero(y))\n\t\t\t\tif (!BN_set_word(y, i)) goto end;\n\t\t\t}\n\t\tr = BN_kronecker(y, q, ctx);\n\t\tif (r < -1) goto end;\n\t\tif (r == 0)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\twhile (r == 1 && ++i < 82);\n\tif (r != -1)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);\n\t\tgoto end;\n\t\t}\n\tif (!BN_rshift(q, q, e)) goto end;\n\tif (!BN_mod_exp(y, y, q, p, ctx)) goto end;\n\tif (BN_is_one(y))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n\t\tgoto end;\n\t\t}\n\tif (!BN_rshift1(t, q)) goto end;\n\tif (BN_is_zero(t))\n\t\t{\n\t\tif (!BN_nnmod(t, A, p, ctx)) goto end;\n\t\tif (BN_is_zero(t))\n\t\t\t{\n\t\t\tBN_zero(ret);\n\t\t\terr = 0;\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\tif (!BN_one(x)) goto end;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mod_exp(x, A, t, p, ctx)) goto end;\n\t\tif (BN_is_zero(x))\n\t\t\t{\n\t\t\tBN_zero(ret);\n\t\t\terr = 0;\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!BN_mod_sqr(b, x, p, ctx)) goto end;\n\tif (!BN_mod_mul(b, b, A, p, ctx)) goto end;\n\tif (!BN_mod_mul(x, x, A, p, ctx)) goto end;\n\twhile (1)\n\t\t{\n\t\tif (BN_is_one(b))\n\t\t\t{\n\t\t\tif (!BN_copy(ret, x)) goto end;\n\t\t\terr = 0;\n\t\t\tgoto vrfy;\n\t\t\t}\n\t\ti = 1;\n\t\tif (!BN_mod_sqr(t, b, p, ctx)) goto end;\n\t\twhile (!BN_is_one(t))\n\t\t\t{\n\t\t\ti++;\n\t\t\tif (i == e)\n\t\t\t\t{\n\t\t\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif (!BN_mod_mul(t, t, t, p, ctx)) goto end;\n\t\t\t}\n\t\tif (!BN_copy(t, y)) goto end;\n\t\tfor (j = e - i - 1; j > 0; j--)\n\t\t\t{\n\t\t\tif (!BN_mod_sqr(t, t, p, ctx)) goto end;\n\t\t\t}\n\t\tif (!BN_mod_mul(y, t, t, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(x, x, t, p, ctx)) goto end;\n\t\tif (!BN_mod_mul(b, b, y, p, ctx)) goto end;\n\t\te = i;\n\t\t}\n vrfy:\n\tif (!err)\n\t\t{\n\t\tif (!BN_mod_sqr(x, ret, p, ctx))\n\t\t\terr = 1;\n\t\tif (!err && 0 != BN_cmp(x, A))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n\t\t\terr = 1;\n\t\t\t}\n\t\t}\n end:\n\tif (err)\n\t\t{\n\t\tif (ret != NULL && ret != in)\n\t\t\t{\n\t\t\tBN_clear_free(ret);\n\t\t\t}\n\t\tret = NULL;\n\t\t}\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn ret;\n\t}', 'int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)\n\t{\n\tif (!BN_lshift1(r, a)) return 0;\n\tbn_check_top(r);\n\tif (BN_cmp(r, m) >= 0)\n\t\treturn BN_sub(r, r, m);\n\treturn 1;\n\t}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n\t{\n\tint i,j,nw,lb,rb;\n\tBN_ULONG *t,*f;\n\tBN_ULONG l,tmp;\n\tbn_check_top(r);\n\tbn_check_top(a);\n\tnw=n/BN_BITS2;\n\trb=n%BN_BITS2;\n\tlb=BN_BITS2-rb;\n\tif (nw >= a->top || a->top == 0)\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\tif (r != a)\n\t\t{\n\t\tr->neg=a->neg;\n\t\tif (bn_wexpand(r,a->top-nw+1) == NULL) return(0);\n\t\t}\n\telse\n\t\t{\n\t\tif (n == 0)\n\t\t\treturn 1;\n\t\t}\n\tf= &(a->d[nw]);\n\tt=r->d;\n\tj=a->top-nw;\n\tr->top=j;\n\tif (rb == 0)\n\t\t{\n\t\tfor (i=j; i != 0; i--)\n\t\t\t*(t++)= *(f++);\n\t\t}\n\telse\n\t\t{\n\t\tl= *(f++);\n\t\tfor (i=j-1; i != 0; i--)\n\t\t\t{\n\t\t\ttmp =(l>>rb)&BN_MASK2;\n\t\t\tl= *(f++);\n\t\t\t*(t++) =(tmp|(l<<lb))&BN_MASK2;\n\t\t\t}\n\t\t*(t++) =(l>>rb)&BN_MASK2;\n\t\t}\n\tbn_correct_top(r);\n\tbn_check_top(r);\n\treturn(1);\n\t}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\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\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(r);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\taa = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif(!aa || !val[0]) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (m->neg)\n\t\t{\n\t\tif (!BN_copy(aa, m)) goto err;\n\t\taa->neg = 0;\n\t\tif (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\t\t}\n\tif (!BN_nnmod(val[0],a,m,ctx)) goto err;\n\tif (BN_is_zero(val[0]))\n\t\t{\n\t\tBN_zero(r);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,val[0],val[0],&recp,ctx))\n\t\t\tgoto 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_reciprocal(val[i],val[i-1],\n\t\t\t\t\t\taa,&recp,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_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\tBN_CTX_end(ctx);\n\tBN_RECP_CTX_free(&recp);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!BN_copy(&(recp->N),d)) return 0;\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, 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}', '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}']
|
1,134
| 0
|
https://github.com/openssl/openssl/blob/31db43df0859210a32af3708df08f0149c46ede0/apps/ts.c/#L1086
|
static X509_STORE *create_cert_store(char *ca_path, char *ca_file)
{
X509_STORE *cert_ctx = NULL;
X509_LOOKUP *lookup = NULL;
int i;
cert_ctx = X509_STORE_new();
X509_STORE_set_verify_cb_func(cert_ctx, verify_cb);
if (ca_path)
{
lookup = X509_STORE_add_lookup(cert_ctx,
X509_LOOKUP_hash_dir());
if (lookup == NULL)
{
BIO_printf(bio_err, "memory allocation failure\n");
goto err;
}
i = X509_LOOKUP_add_dir(lookup, ca_path, X509_FILETYPE_PEM);
if (!i)
{
BIO_printf(bio_err, "Error loading directory %s\n",
ca_path);
goto err;
}
}
if (ca_file)
{
lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
if (lookup == NULL)
{
BIO_printf(bio_err, "memory allocation failure\n");
goto err;
}
i = X509_LOOKUP_load_file(lookup, ca_file, X509_FILETYPE_PEM);
if (!i)
{
BIO_printf(bio_err, "Error loading file %s\n", ca_file);
goto err;
}
}
return cert_ctx;
err:
X509_STORE_free(cert_ctx);
return NULL;
}
|
['static X509_STORE *create_cert_store(char *ca_path, char *ca_file)\n\t{\n\tX509_STORE *cert_ctx = NULL;\n\tX509_LOOKUP *lookup = NULL;\n\tint i;\n\tcert_ctx = X509_STORE_new();\n\tX509_STORE_set_verify_cb_func(cert_ctx, verify_cb);\n\tif (ca_path)\n\t\t{\n\t\tlookup = X509_STORE_add_lookup(cert_ctx,\n\t\t\t\t\t X509_LOOKUP_hash_dir());\n\t\tif (lookup == 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\ti = X509_LOOKUP_add_dir(lookup, ca_path, X509_FILETYPE_PEM);\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error loading directory %s\\n",\n\t\t\t\t ca_path);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (ca_file)\n\t\t{\n\t\tlookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());\n\t\tif (lookup == 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\ti = X509_LOOKUP_load_file(lookup, ca_file, X509_FILETYPE_PEM);\n\t\tif (!i)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error loading file %s\\n", ca_file);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\treturn cert_ctx;\n err:\n\tX509_STORE_free(cert_ctx);\n\treturn NULL;\n\t}', 'X509_STORE *X509_STORE_new(void)\n\t{\n\tX509_STORE *ret;\n\tif ((ret=(X509_STORE *)OPENSSL_malloc(sizeof(X509_STORE))) == NULL)\n\t\treturn NULL;\n\tret->objs = sk_X509_OBJECT_new(x509_object_cmp);\n\tret->cache=1;\n\tret->get_cert_methods=sk_X509_LOOKUP_new_null();\n\tret->verify=0;\n\tret->verify_cb=0;\n\tif ((ret->param = X509_VERIFY_PARAM_new()) == NULL)\n\t\treturn NULL;\n\tret->get_issuer = 0;\n\tret->check_issued = 0;\n\tret->check_revocation = 0;\n\tret->get_crl = 0;\n\tret->check_crl = 0;\n\tret->cert_crl = 0;\n\tret->lookup_certs = 0;\n\tret->lookup_crls = 0;\n\tret->cleanup = 0;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data);\n\tret->references=1;\n\treturn ret;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\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#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}']
|
1,135
| 0
|
https://github.com/openssl/openssl/blob/4013f3bf1e4f0c3267f16cf8a5e5fa056a4bd1d3/ssl/ssl_ciph.c/#L675
|
static int ssl_cipher_process_rulestr(const char *rule_str,
CIPHER_ORDER *list, CIPHER_ORDER **head_p,
CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
{
unsigned long algorithms, mask, algo_strength, mask_strength;
const char *l, *start, *buf;
int j, multi, found, rule, retval, ok, buflen;
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;
}
algorithms = mask = algo_strength = mask_strength = 0;
start=l;
for (;;)
{
ch = *l;
buf = l;
buflen = 0;
#ifndef CHARSET_EBCDIC
while ( ((ch >= 'A') && (ch <= 'Z')) ||
((ch >= '0') && (ch <= '9')) ||
((ch >= 'a') && (ch <= 'z')) ||
(ch == '-'))
#else
while ( isalnum(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;
while (ca_list[j])
{
if ((ca_list[j]->name[buflen] == '\0') &&
!strncmp(buf, ca_list[j]->name, buflen))
{
found = 1;
break;
}
else
j++;
}
if (!found)
break;
algorithms |= ca_list[j]->algorithms;
mask |= ca_list[j]->mask;
algo_strength |= ca_list[j]->algo_strength;
mask_strength |= ca_list[j]->mask_strength;
if (!multi) break;
}
if (rule == CIPHER_SPECIAL)
{
ok = 0;
if ((buflen == 8) &&
!strncmp(buf, "STRENGTH", 8))
ok = ssl_cipher_strength_sort(list,
head_p, tail_p);
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(algorithms, mask,
algo_strength, mask_strength, rule, -1,
list, head_p, tail_p);
}
else
{
while ((*l != '\0') && ITEM_SEP(*l))
l++;
}
if (*l == '\0') break;
}
return(retval);
}
|
['static int ssl_cipher_process_rulestr(const char *rule_str,\n\t\tCIPHER_ORDER *list, CIPHER_ORDER **head_p,\n\t\tCIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)\n\t{\n\tunsigned long algorithms, mask, algo_strength, mask_strength;\n\tconst char *l, *start, *buf;\n\tint j, multi, found, rule, retval, ok, buflen;\n\tchar ch;\n\tretval = 1;\n\tl = rule_str;\n\tfor (;;)\n\t\t{\n\t\tch = *l;\n\t\tif (ch == \'\\0\')\n\t\t\tbreak;\n\t\tif (ch == \'-\')\n\t\t\t{ rule = CIPHER_DEL; l++; }\n\t\telse if (ch == \'+\')\n\t\t\t{ rule = CIPHER_ORD; l++; }\n\t\telse if (ch == \'!\')\n\t\t\t{ rule = CIPHER_KILL; l++; }\n\t\telse if (ch == \'@\')\n\t\t\t{ rule = CIPHER_SPECIAL; l++; }\n\t\telse\n\t\t\t{ rule = CIPHER_ADD; }\n\t\tif (ITEM_SEP(ch))\n\t\t\t{\n\t\t\tl++;\n\t\t\tcontinue;\n\t\t\t}\n\t\talgorithms = mask = algo_strength = mask_strength = 0;\n\t\tstart=l;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tch = *l;\n\t\t\tbuf = l;\n\t\t\tbuflen = 0;\n#ifndef CHARSET_EBCDIC\n\t\t\twhile (\t((ch >= \'A\') && (ch <= \'Z\')) ||\n\t\t\t\t((ch >= \'0\') && (ch <= \'9\')) ||\n\t\t\t\t((ch >= \'a\') && (ch <= \'z\')) ||\n\t\t\t\t (ch == \'-\'))\n#else\n\t\t\twhile (\tisalnum(ch) || (ch == \'-\'))\n#endif\n\t\t\t\t {\n\t\t\t\t ch = *(++l);\n\t\t\t\t buflen++;\n\t\t\t\t }\n\t\t\tif (buflen == 0)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,\n\t\t\t\t SSL_R_INVALID_COMMAND);\n\t\t\t\tretval = found = 0;\n\t\t\t\tl++;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (rule == CIPHER_SPECIAL)\n\t\t\t\t{\n\t\t\t\tfound = 0;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tif (ch == \'+\')\n\t\t\t\t{\n\t\t\t\tmulti=1;\n\t\t\t\tl++;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tmulti=0;\n\t\t\t j = found = 0;\n\t\t\t while (ca_list[j])\n\t\t\t\t{\n\t\t\t\tif ((ca_list[j]->name[buflen] == \'\\0\') &&\n\t\t\t\t !strncmp(buf, ca_list[j]->name, buflen))\n\t\t\t\t\t{\n\t\t\t\t\tfound = 1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tj++;\n\t\t\t\t}\n\t\t\tif (!found)\n\t\t\t\tbreak;\n\t\t\talgorithms |= ca_list[j]->algorithms;\n\t\t\tmask |= ca_list[j]->mask;\n\t\t\talgo_strength |= ca_list[j]->algo_strength;\n\t\t\tmask_strength |= ca_list[j]->mask_strength;\n\t\t\tif (!multi) break;\n\t\t\t}\n\t\tif (rule == CIPHER_SPECIAL)\n\t\t\t{\n\t\t\tok = 0;\n\t\t\tif ((buflen == 8) &&\n\t\t\t\t!strncmp(buf, "STRENGTH", 8))\n\t\t\t\tok = ssl_cipher_strength_sort(list,\n\t\t\t\t\thead_p, tail_p);\n\t\t\telse\n\t\t\t\tSSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,\n\t\t\t\t\tSSL_R_INVALID_COMMAND);\n\t\t\tif (ok == 0)\n\t\t\t\tretval = 0;\n\t\t\twhile ((*l != \'\\0\') && ITEM_SEP(*l))\n\t\t\t\tl++;\n\t\t\t}\n\t\telse if (found)\n\t\t\t{\n\t\t\tssl_cipher_apply_rule(algorithms, mask,\n\t\t\t\talgo_strength, mask_strength, rule, -1,\n\t\t\t\tlist, head_p, tail_p);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\twhile ((*l != \'\\0\') && ITEM_SEP(*l))\n\t\t\t\tl++;\n\t\t\t}\n\t\tif (*l == \'\\0\') break;\n\t\t}\n\treturn(retval);\n\t}']
|
1,136
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/ssl/d1_lib.c/#L139
|
int dtls1_new(SSL *s)
{
DTLS1_STATE *d1;
if (!DTLS_RECORD_LAYER_new(&s->rlayer)) {
return 0;
}
if (!ssl3_new(s))
return (0);
if ((d1 = OPENSSL_zalloc(sizeof(*d1))) == NULL) {
ssl3_free(s);
return (0);
}
d1->buffered_messages = pqueue_new();
d1->sent_messages = pqueue_new();
if (s->server) {
d1->cookie_len = sizeof(s->d1->cookie);
}
d1->link_mtu = 0;
d1->mtu = 0;
if (d1->buffered_messages == NULL || d1->sent_messages == NULL) {
pqueue_free(d1->buffered_messages);
pqueue_free(d1->sent_messages);
OPENSSL_free(d1);
ssl3_free(s);
return (0);
}
s->d1 = d1;
s->method->ssl_clear(s);
return (1);
}
|
['int dtls1_new(SSL *s)\n{\n DTLS1_STATE *d1;\n if (!DTLS_RECORD_LAYER_new(&s->rlayer)) {\n return 0;\n }\n if (!ssl3_new(s))\n return (0);\n if ((d1 = OPENSSL_zalloc(sizeof(*d1))) == NULL) {\n ssl3_free(s);\n return (0);\n }\n d1->buffered_messages = pqueue_new();\n d1->sent_messages = pqueue_new();\n if (s->server) {\n d1->cookie_len = sizeof(s->d1->cookie);\n }\n d1->link_mtu = 0;\n d1->mtu = 0;\n if (d1->buffered_messages == NULL || d1->sent_messages == NULL) {\n pqueue_free(d1->buffered_messages);\n pqueue_free(d1->sent_messages);\n OPENSSL_free(d1);\n ssl3_free(s);\n return (0);\n }\n s->d1 = d1;\n s->method->ssl_clear(s);\n return (1);\n}', 'int DTLS_RECORD_LAYER_new(RECORD_LAYER *rl)\n{\n DTLS_RECORD_LAYER *d;\n if ((d = OPENSSL_malloc(sizeof(*d))) == NULL)\n return (0);\n rl->d = d;\n d->unprocessed_rcds.q = pqueue_new();\n d->processed_rcds.q = pqueue_new();\n d->buffered_app_data.q = pqueue_new();\n if (d->unprocessed_rcds.q == NULL || d->processed_rcds.q == NULL\n || d->buffered_app_data.q == NULL) {\n pqueue_free(d->unprocessed_rcds.q);\n pqueue_free(d->processed_rcds.q);\n pqueue_free(d->buffered_app_data.q);\n OPENSSL_free(d);\n rl->d = NULL;\n return (0);\n }\n return 1;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'pqueue_s *pqueue_new()\n{\n pqueue_s *pq = OPENSSL_zalloc(sizeof(*pq));\n return pq;\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}']
|
1,137
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_shift.c/#L159
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
r->neg = a->neg;
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return (0);
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return (1);
}
|
['int gost2001_do_verify(const unsigned char *dgst, int dgst_len,\n DSA_SIG *sig, EC_KEY *ec)\n{\n BN_CTX *ctx = BN_CTX_new();\n const EC_GROUP *group = EC_KEY_get0_group(ec);\n BIGNUM *order;\n BIGNUM *md = NULL, *e = NULL, *R = NULL, *v = NULL, *z1 = NULL, *z2 =\n NULL;\n BIGNUM *X = NULL, *tmp = NULL;\n EC_POINT *C = NULL;\n const EC_POINT *pub_key = NULL;\n int ok = 0;\n if (!ctx || !group) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n BN_CTX_start(ctx);\n order = BN_CTX_get(ctx);\n e = BN_CTX_get(ctx);\n z1 = BN_CTX_get(ctx);\n z2 = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n R = BN_CTX_get(ctx);\n v = BN_CTX_get(ctx);\n if (!order || !e || !z1 || !z2 || !tmp || !X || !R || !v) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n pub_key = EC_KEY_get0_public_key(ec);\n if (!pub_key || !EC_GROUP_get_order(group, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||\n (BN_cmp(sig->s, order) >= 1) || (BN_cmp(sig->r, order) >= 1)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY,\n GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n goto err;\n }\n md = hashsum2bn(dgst);\n if (!md || !BN_mod(e, md, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef DEBUG_SIGN\n fprintf(stderr, "digest as bignum: ");\n BN_print_fp(stderr, md);\n fprintf(stderr, "\\ndigest mod q: ");\n BN_print_fp(stderr, e);\n#endif\n if (BN_is_zero(e) && !BN_one(e)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n v = BN_mod_inverse(v, e, order, ctx);\n if (!v\n || !BN_mod_mul(z1, sig->s, v, order, ctx)\n || !BN_sub(tmp, order, sig->r)\n || !BN_mod_mul(z2, tmp, v, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef DEBUG_SIGN\n fprintf(stderr, "\\nInverted digest value: ");\n BN_print_fp(stderr, v);\n fprintf(stderr, "\\nz1: ");\n BN_print_fp(stderr, z1);\n fprintf(stderr, "\\nz2: ");\n BN_print_fp(stderr, z2);\n#endif\n C = EC_POINT_new(group);\n if (!C) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EC_POINT_mul(group, C, z1, pub_key, z2, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);\n goto err;\n }\n if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);\n goto err;\n }\n if (!BN_mod(R, X, order, ctx)) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n#ifdef DEBUG_SIGN\n fprintf(stderr, "\\nX=");\n BN_print_fp(stderr, X);\n fprintf(stderr, "\\nX mod q=");\n BN_print_fp(stderr, R);\n fprintf(stderr, "\\n");\n#endif\n if (BN_cmp(R, sig->r) != 0) {\n GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH);\n } else {\n ok = 1;\n }\n err:\n EC_POINT_free(C);\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n BN_free(md);\n return ok;\n}', 'BIGNUM *hashsum2bn(const unsigned char *dgst)\n{\n unsigned char buf[32];\n BUF_reverse(buf, (unsigned char*)dgst, 32);\n return BN_bin2bn(buf, 32, NULL);\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return (NULL);\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return (ret);\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return (ret);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n r->neg = a->neg;\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return (1);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,138
| 0
|
https://github.com/nginx/nginx/blob/7e4f193bb0e1cfa4128052f538dd60519cac02e4/src/http/ngx_http_request.c/#L2860
|
static ngx_int_t
ngx_http_post_action(ngx_http_request_t *r)
{
ngx_http_core_loc_conf_t *clcf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->post_action.data == NULL) {
return NGX_DECLINED;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"post action: \"%V\"", &clcf->post_action);
r->main->count--;
r->http_version = NGX_HTTP_VERSION_9;
r->header_only = 1;
r->post_action = 1;
r->read_event_handler = ngx_http_block_reading;
if (clcf->post_action.data[0] == '/') {
ngx_http_internal_redirect(r, &clcf->post_action, NULL);
} else {
ngx_http_named_location(r, &clcf->post_action);
}
return NGX_OK;
}
|
['static void\nngx_http_upstream_cleanup(void *data)\n{\n ngx_http_request_t *r = data;\n ngx_http_upstream_t *u;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "cleanup http upstream request: \\"%V\\"", &r->uri);\n u = r->upstream;\n if (u->resolved && u->resolved->ctx) {\n ngx_resolve_name_done(u->resolved->ctx);\n u->resolved->ctx = NULL;\n }\n ngx_http_upstream_finalize_request(r, u, NGX_DONE);\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 }\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 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 (NGX_HTTP_CACHE)\n if (u->cacheable && r->cache) {\n time_t valid;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream cache fd: %d",\n r->cache->file.fd);\n if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\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 ngx_http_file_cache_free(r, u->pipe->temp_file);\n }\n#endif\n if (u->header_sent\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 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 return;\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#if (NGX_DEBUG)\n if (r != c->data) {\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 }\n#endif\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\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 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 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 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "post action: \\"%V\\"", &clcf->post_action);\n r->main->count--;\n r->http_version = NGX_HTTP_VERSION_9;\n r->header_only = 1;\n r->post_action = 1;\n r->read_event_handler = ngx_http_block_reading;\n if (clcf->post_action.data[0] == \'/\') {\n ngx_http_internal_redirect(r, &clcf->post_action, NULL);\n } else {\n ngx_http_named_location(r, &clcf->post_action);\n }\n return NGX_OK;\n}']
|
1,139
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/lhash/lhash.c/#L233
|
void *lh_delete(_LHASH *lh, const void *data)
{
unsigned long hash;
LHASH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return (NULL);
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return (ret);
}
|
['int dtls1_get_record(SSL *s)\n{\n int ssl_major, ssl_minor;\n int i, n;\n SSL3_RECORD *rr;\n unsigned char *p = NULL;\n unsigned short version;\n DTLS1_BITMAP *bitmap;\n unsigned int is_next_epoch;\n rr = &(s->s3->rrec);\n if (dtls1_process_buffered_records(s) < 0)\n return -1;\n if (dtls1_get_processed_record(s))\n return 1;\n again:\n if ((s->rstate != SSL_ST_READ_BODY) ||\n (s->packet_length < DTLS1_RT_HEADER_LENGTH)) {\n n = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH, s->s3->rbuf.len, 0);\n if (n <= 0)\n return (n);\n if (s->packet_length != DTLS1_RT_HEADER_LENGTH) {\n s->packet_length = 0;\n goto again;\n }\n s->rstate = SSL_ST_READ_BODY;\n p = s->packet;\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, p, DTLS1_RT_HEADER_LENGTH,\n s, s->msg_callback_arg);\n rr->type = *(p++);\n ssl_major = *(p++);\n ssl_minor = *(p++);\n version = (ssl_major << 8) | ssl_minor;\n n2s(p, rr->epoch);\n memcpy(&(s->s3->read_sequence[2]), p, 6);\n p += 6;\n n2s(p, rr->length);\n if (!s->first_packet) {\n if (version != s->version) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n }\n if ((version & 0xff00) != (s->version & 0xff00)) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n }\n if (rr->length > s->packet_length - DTLS1_RT_HEADER_LENGTH) {\n i = rr->length;\n n = ssl3_read_n(s, i, i, 1);\n if (n != i) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n }\n s->rstate = SSL_ST_READ_HEADER;\n bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);\n if (bitmap == NULL) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n#ifndef OPENSSL_NO_SCTP\n if (!BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n#endif\n if (!(s->d1->listen && rr->type == SSL3_RT_HANDSHAKE &&\n s->packet_length > DTLS1_RT_HEADER_LENGTH &&\n s->packet[DTLS1_RT_HEADER_LENGTH] == SSL3_MT_CLIENT_HELLO) &&\n !dtls1_record_replay_check(s, bitmap)) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n#ifndef OPENSSL_NO_SCTP\n }\n#endif\n if (rr->length == 0)\n goto again;\n if (is_next_epoch) {\n if ((SSL_in_init(s) || s->in_handshake) && !s->d1->listen) {\n if (dtls1_buffer_record\n (s, &(s->d1->unprocessed_rcds), rr->seq_num) < 0)\n return -1;\n dtls1_record_bitmap_update(s, bitmap);\n }\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n if (!dtls1_process_record(s)) {\n rr->length = 0;\n s->packet_length = 0;\n goto again;\n }\n dtls1_record_bitmap_update(s, bitmap);\n return (1);\n}', 'static int dtls1_process_buffered_records(SSL *s)\n{\n pitem *item;\n item = pqueue_peek(s->d1->unprocessed_rcds.q);\n if (item) {\n if (s->d1->unprocessed_rcds.epoch != s->d1->r_epoch)\n return (1);\n while (pqueue_peek(s->d1->unprocessed_rcds.q)) {\n dtls1_get_unprocessed_record(s);\n if (!dtls1_process_record(s))\n return (0);\n if (dtls1_buffer_record(s, &(s->d1->processed_rcds),\n s->s3->rrec.seq_num) < 0)\n return -1;\n }\n }\n s->d1->processed_rcds.epoch = s->d1->r_epoch;\n s->d1->unprocessed_rcds.epoch = s->d1->r_epoch + 1;\n return (1);\n}', 'static int dtls1_process_record(SSL *s)\n{\n int i, al;\n int enc_err;\n SSL_SESSION *sess;\n SSL3_RECORD *rr;\n unsigned int mac_size;\n unsigned char md[EVP_MAX_MD_SIZE];\n rr = &(s->s3->rrec);\n sess = s->session;\n rr->input = &(s->packet[DTLS1_RT_HEADER_LENGTH]);\n if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);\n goto f_err;\n }\n rr->data = rr->input;\n rr->orig_len = rr->length;\n enc_err = s->method->ssl3_enc->enc(s, 0);\n if (enc_err == 0) {\n rr->length = 0;\n s->packet_length = 0;\n goto err;\n }\n#ifdef TLS_DEBUG\n printf("dec %d\\n", rr->length);\n {\n unsigned int z;\n for (z = 0; z < rr->length; z++)\n printf("%02X%c", rr->data[z], ((z + 1) % 16) ? \' \' : \'\\n\');\n }\n printf("\\n");\n#endif\n if ((sess != NULL) &&\n (s->enc_read_ctx != NULL) && (EVP_MD_CTX_md(s->read_hash) != NULL)) {\n unsigned char *mac = NULL;\n unsigned char mac_tmp[EVP_MAX_MD_SIZE];\n mac_size = EVP_MD_CTX_size(s->read_hash);\n OPENSSL_assert(mac_size <= EVP_MAX_MD_SIZE);\n if (rr->orig_len < mac_size ||\n (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n rr->orig_len < mac_size + 1)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n if (EVP_CIPHER_CTX_mode(s->enc_read_ctx) == EVP_CIPH_CBC_MODE) {\n mac = mac_tmp;\n ssl3_cbc_copy_mac(mac_tmp, rr, mac_size);\n rr->length -= mac_size;\n } else {\n rr->length -= mac_size;\n mac = &rr->data[rr->length];\n }\n i = s->method->ssl3_enc->mac(s, md, 0 );\n if (i < 0 || mac == NULL\n || CRYPTO_memcmp(md, mac, (size_t)mac_size) != 0)\n enc_err = -1;\n if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_size)\n enc_err = -1;\n }\n if (enc_err < 0) {\n rr->length = 0;\n s->packet_length = 0;\n goto err;\n }\n if (s->expand != NULL) {\n if (rr->length > SSL3_RT_MAX_COMPRESSED_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD,\n SSL_R_COMPRESSED_LENGTH_TOO_LONG);\n goto f_err;\n }\n if (!ssl3_do_uncompress(s)) {\n al = SSL_AD_DECOMPRESSION_FAILURE;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_BAD_DECOMPRESSION);\n goto f_err;\n }\n }\n if (rr->length > SSL3_RT_MAX_PLAIN_LENGTH) {\n al = SSL_AD_RECORD_OVERFLOW;\n SSLerr(SSL_F_DTLS1_PROCESS_RECORD, SSL_R_DATA_LENGTH_TOO_LONG);\n goto f_err;\n }\n rr->off = 0;\n s->packet_length = 0;\n return (1);\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n return (0);\n}', 'int ssl3_send_alert(SSL *s, int level, int desc)\n{\n desc = s->method->ssl3_enc->alert_value(desc);\n if (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n desc = SSL_AD_HANDSHAKE_FAILURE;\n if (desc < 0)\n return -1;\n if ((level == SSL3_AL_FATAL) && (s->session != NULL))\n SSL_CTX_remove_session(s->ctx, s->session);\n s->s3->alert_dispatch = 1;\n s->s3->send_alert[0] = level;\n s->s3->send_alert[1] = desc;\n if (s->s3->wbuf.left == 0)\n return s->method->ssl_dispatch_alert(s);\n return -1;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n if (lck)\n CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n if (ret) {\n r->not_resumable = 1;\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, r);\n SSL_SESSION_free(r);\n }\n } else\n ret = 0;\n return (ret);\n}', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n unsigned long hash;\n LHASH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
|
1,140
| 0
|
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['static int vp9_raw_reorder_frame_parse(AVBSFContext *bsf, VP9RawReorderFrame *frame)\n{\n BitstreamContext bc;\n int err;\n unsigned int frame_marker;\n unsigned int profile_low_bit, profile_high_bit, reserved_zero;\n unsigned int error_resilient_mode;\n unsigned int frame_sync_code;\n err = bitstream_init8(&bc, frame->packet->data, frame->packet->size);\n if (err)\n return err;\n frame_marker = bitstream_read(&bc, 2);\n if (frame_marker != 2) {\n av_log(bsf, AV_LOG_ERROR, "Invalid frame marker: %u.\\n",\n frame_marker);\n return AVERROR_INVALIDDATA;\n }\n profile_low_bit = bitstream_read_bit(&bc);\n profile_high_bit = bitstream_read_bit(&bc);\n frame->profile = (profile_high_bit << 1) | profile_low_bit;\n if (frame->profile == 3) {\n reserved_zero = bitstream_read_bit(&bc);\n if (reserved_zero != 0) {\n av_log(bsf, AV_LOG_ERROR, "Profile reserved_zero bit set: "\n "unsupported profile or invalid bitstream.\\n");\n return AVERROR_INVALIDDATA;\n }\n }\n frame->show_existing_frame = bitstream_read_bit(&bc);\n if (frame->show_existing_frame) {\n frame->frame_to_show = bitstream_read(&bc, 3);\n return 0;\n }\n frame->frame_type = bitstream_read_bit(&bc);\n frame->show_frame = bitstream_read_bit(&bc);\n error_resilient_mode = bitstream_read_bit(&bc);\n if (frame->frame_type == 0) {\n frame_sync_code = bitstream_read(&bc, 24);\n if (frame_sync_code != 0x498342) {\n av_log(bsf, AV_LOG_ERROR, "Invalid frame sync code: %06x.\\n",\n frame_sync_code);\n return AVERROR_INVALIDDATA;\n }\n frame->refresh_frame_flags = 0xff;\n } else {\n unsigned int intra_only;\n if (frame->show_frame == 0)\n intra_only = bitstream_read_bit(&bc);\n else\n intra_only = 0;\n if (error_resilient_mode == 0) {\n bitstream_skip(&bc, 2);\n }\n if (intra_only) {\n frame_sync_code = bitstream_read(&bc, 24);\n if (frame_sync_code != 0x498342) {\n av_log(bsf, AV_LOG_ERROR, "Invalid frame sync code: "\n "%06x.\\n", frame_sync_code);\n return AVERROR_INVALIDDATA;\n }\n if (frame->profile > 0) {\n unsigned int color_space;\n if (frame->profile >= 2) {\n bitstream_skip(&bc, 1);\n }\n color_space = bitstream_read(&bc, 3);\n if (color_space != 7 ) {\n bitstream_skip(&bc, 1);\n if (frame->profile == 1 || frame->profile == 3) {\n bitstream_skip(&bc, 3);\n }\n } else {\n if (frame->profile == 1 || frame->profile == 3)\n bitstream_skip(&bc, 1);\n }\n }\n frame->refresh_frame_flags = bitstream_read(&bc, 8);\n } else {\n frame->refresh_frame_flags = bitstream_read(&bc, 8);\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}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
1,141
| 0
|
https://github.com/libav/libav/blob/10d39405fa82473367e1ba1ed3c4ecbeca2a7986/ffmpeg.c/#L3692
|
static void opt_output_file(const char *filename)
{
AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle;
int input_has_video, input_has_audio, input_has_subtitle;
AVFormatParameters params, *ap = ¶ms;
AVOutputFormat *file_oformat;
if (!strcmp(filename, "-"))
filename = "pipe:";
oc = avformat_alloc_context();
if (!oc) {
print_error(filename, AVERROR(ENOMEM));
ffmpeg_exit(1);
}
if (last_asked_format) {
file_oformat = av_guess_format(last_asked_format, NULL, NULL);
if (!file_oformat) {
fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
ffmpeg_exit(1);
}
last_asked_format = NULL;
} else {
file_oformat = av_guess_format(NULL, filename, NULL);
if (!file_oformat) {
fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
filename);
ffmpeg_exit(1);
}
}
oc->oformat = file_oformat;
av_strlcpy(oc->filename, filename, sizeof(oc->filename));
if (!strcmp(file_oformat->name, "ffm") &&
av_strstart(filename, "http:", NULL)) {
int err = read_ffserver_streams(oc, filename);
if (err < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
} else {
use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
if (nb_input_files > 0) {
check_audio_video_sub_inputs(&input_has_video, &input_has_audio,
&input_has_subtitle);
if (!input_has_video)
use_video = 0;
if (!input_has_audio)
use_audio = 0;
if (!input_has_subtitle)
use_subtitle = 0;
}
if (audio_disable) use_audio = 0;
if (video_disable) use_video = 0;
if (subtitle_disable) use_subtitle = 0;
if (use_video) new_video_stream(oc, nb_output_files);
if (use_audio) new_audio_stream(oc, nb_output_files);
if (use_subtitle) new_subtitle_stream(oc, nb_output_files);
oc->timestamp = recording_timestamp;
av_metadata_copy(&oc->metadata, metadata, 0);
av_metadata_free(&metadata);
}
output_files[nb_output_files++] = oc;
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR(EINVAL));
ffmpeg_exit(1);
}
}
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
filename[1] == ':' ||
av_strstart(filename, "file:", NULL))) {
if (avio_check(filename, 0) == 0) {
if (!using_stdin) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
if (!read_yesno()) {
fprintf(stderr, "Not overwriting - exiting\n");
ffmpeg_exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
ffmpeg_exit(1);
}
}
}
if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
}
memset(ap, 0, sizeof(*ap));
if (av_set_parameters(oc, ap) < 0) {
fprintf(stderr, "%s: Invalid encoding parameters\n",
oc->filename);
ffmpeg_exit(1);
}
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
av_freep(&forced_key_frames);
}
|
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = ¶ms;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n ffmpeg_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n ffmpeg_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) use_audio = 0;\n if (video_disable) use_video = 0;\n if (subtitle_disable) use_subtitle = 0;\n if (use_video) new_video_stream(oc, nb_output_files);\n if (use_audio) new_audio_stream(oc, nb_output_files);\n if (use_subtitle) new_subtitle_stream(oc, nb_output_files);\n oc->timestamp = recording_timestamp;\n av_metadata_copy(&oc->metadata, metadata, 0);\n av_metadata_free(&metadata);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR(EINVAL));\n ffmpeg_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (avio_check(filename, 0) == 0) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n ffmpeg_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n ffmpeg_exit(1);\n }\n }\n }\n if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n ffmpeg_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);\n av_freep(&forced_key_frames);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n size_t len = 0;\n while (++len < size && *src)\n *dst++ = *src++;\n if (len <= size)\n *dst = 0;\n return len + strlen(src) - 1;\n}']
|
1,142
| 0
|
https://github.com/openssl/openssl/blob/c849c6d9d3bf806fecfe0c16eaa55d361979ff7f/include/internal/constant_time_locl.h/#L145
|
static ossl_inline unsigned int constant_time_lt(unsigned int a,
unsigned int b)
{
return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
}
|
['int RSA_padding_check_PKCS1_type_2(unsigned char *to, int tlen,\n const unsigned char *from, int flen,\n int num)\n{\n int i;\n unsigned char *em = NULL;\n unsigned int good, found_zero_byte;\n int zero_index = 0, msg_index, mlen = -1;\n if (tlen < 0 || flen < 0)\n return -1;\n if (flen > num)\n goto err;\n if (num < 11)\n goto err;\n em = OPENSSL_zalloc(num);\n if (em == NULL) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n memcpy(em + num - flen, from, flen);\n good = constant_time_is_zero(em[0]);\n good &= constant_time_eq(em[1], 2);\n found_zero_byte = 0;\n for (i = 2; i < num; i++) {\n unsigned int equals0 = constant_time_is_zero(em[i]);\n zero_index =\n constant_time_select_int(~found_zero_byte & equals0, i,\n zero_index);\n found_zero_byte |= equals0;\n }\n good &= constant_time_ge((unsigned int)(zero_index), 2 + 8);\n msg_index = zero_index + 1;\n mlen = num - msg_index;\n good &= constant_time_ge((unsigned int)(tlen), (unsigned int)(mlen));\n if (!good) {\n mlen = -1;\n goto err;\n }\n memcpy(to, em + msg_index, mlen);\n err:\n OPENSSL_free(em);\n if (mlen == -1)\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_TYPE_2,\n RSA_R_PKCS_DECODING_ERROR);\n return mlen;\n}', 'static ossl_inline unsigned int constant_time_ge(unsigned int a,\n unsigned int b)\n{\n return ~constant_time_lt(a, b);\n}', 'static ossl_inline unsigned int constant_time_lt(unsigned int a,\n unsigned int b)\n{\n return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));\n}']
|
1,143
| 0
|
https://github.com/libav/libav/blob/bf2cba453244a74331238a472fe0e309f116f4d9/ffmpeg.c/#L1311
|
static void do_video_stats(AVFormatContext *os, OutputStream *ost,
int frame_size)
{
AVCodecContext *enc;
int frame_number;
double ti1, bitrate, avg_bitrate;
if (!vstats_file) {
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
ffmpeg_exit(1);
}
}
enc = ost->st->codec;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
frame_number = ost->frame_number;
fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
if (enc->flags&CODEC_FLAG_PSNR)
fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
fprintf(vstats_file,"f_size= %6d ", frame_size);
ti1 = ost->sync_opts * av_q2d(enc->time_base);
if (ti1 < 0.01)
ti1 = 0.01;
bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
(double)video_size / 1024, ti1, bitrate, avg_bitrate);
fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type));
}
}
|
['static void do_video_stats(AVFormatContext *os, OutputStream *ost,\n int frame_size)\n{\n AVCodecContext *enc;\n int frame_number;\n double ti1, bitrate, avg_bitrate;\n if (!vstats_file) {\n vstats_file = fopen(vstats_filename, "w");\n if (!vstats_file) {\n perror("fopen");\n ffmpeg_exit(1);\n }\n }\n enc = ost->st->codec;\n if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {\n frame_number = ost->frame_number;\n fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);\n if (enc->flags&CODEC_FLAG_PSNR)\n fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));\n fprintf(vstats_file,"f_size= %6d ", frame_size);\n ti1 = ost->sync_opts * av_q2d(enc->time_base);\n if (ti1 < 0.01)\n ti1 = 0.01;\n bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;\n avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;\n fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",\n (double)video_size / 1024, ti1, bitrate, avg_bitrate);\n fprintf(vstats_file, "type= %c\\n", av_get_picture_type_char(enc->coded_frame->pict_type));\n }\n}']
|
1,144
| 0
|
https://github.com/openssl/openssl/blob/8d9fb8c8dbdaad8c7e6009c96618b17aac9662b9/crypto/init.c/#L384
|
int ossl_init_thread_start(uint64_t opts)
{
struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);
if (locals == NULL)
return 0;
if (opts & OPENSSL_INIT_THREAD_ASYNC) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for async\n");
#endif
locals->async = 1;
}
if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for err_state\n");
#endif
locals->err_state = 1;
}
return 1;
}
|
['int ossl_init_thread_start(uint64_t opts)\n{\n struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);\n if (locals == NULL)\n return 0;\n if (opts & OPENSSL_INIT_THREAD_ASYNC) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for async\\n");\n#endif\n locals->async = 1;\n }\n if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for err_state\\n");\n#endif\n locals->err_state = 1;\n }\n return 1;\n}', 'static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)\n{\n struct thread_local_inits_st *local =\n CRYPTO_THREAD_get_local(&threadstopkey);\n if (local == NULL && alloc) {\n local = OPENSSL_zalloc(sizeof *local);\n CRYPTO_THREAD_set_local(&threadstopkey, local);\n }\n if (!alloc) {\n CRYPTO_THREAD_set_local(&threadstopkey, NULL);\n }\n return local;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}']
|
1,145
| 0
|
https://github.com/libav/libav/blob/a1c1c7801918c46da5525cfddb99f3467c522b02/libavcodec/rv40.c/#L599
|
static void rv40_loop_filter(RV34DecContext *r, int row)
{
MpegEncContext *s = &r->s;
int mb_pos, mb_x;
int i, j, k;
uint8_t *Y, *C;
int alpha, beta, betaY, betaC;
int q;
int mbtype[4];
int mb_strong[4];
int clip[4];
int cbp[4];
int uvcbp[4][2];
int mvmasks[4];
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int mbtype = s->current_picture_ptr->mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->cbp_luma [mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
r->cbp_chroma[mb_pos] = 0xFF;
}
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int y_h_deblock, y_v_deblock;
int c_v_deblock[2], c_h_deblock[2];
int clip_left;
int avail[4];
int y_to_deblock, c_to_deblock[2];
q = s->current_picture_ptr->qscale_table[mb_pos];
alpha = rv40_alpha_tab[q];
beta = rv40_beta_tab [q];
betaY = betaC = beta * 3;
if(s->width * s->height <= 176*144)
betaY += beta;
avail[0] = 1;
avail[1] = row;
avail[2] = mb_x;
avail[3] = row < s->mb_height - 1;
for(i = 0; i < 4; i++){
if(avail[i]){
int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;
mvmasks[i] = r->deblock_coefs[pos];
mbtype [i] = s->current_picture_ptr->mb_type[pos];
cbp [i] = r->cbp_luma[pos];
uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;
uvcbp[i][1] = r->cbp_chroma[pos] >> 4;
}else{
mvmasks[i] = 0;
mbtype [i] = mbtype[0];
cbp [i] = 0;
uvcbp[i][0] = uvcbp[i][1] = 0;
}
mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);
clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];
}
y_to_deblock = cbp[POS_CUR]
| (cbp[POS_BOTTOM] << 16)
| mvmasks[POS_CUR]
| (mvmasks[POS_BOTTOM] << 16);
y_h_deblock = y_to_deblock
| ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)
| ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);
y_v_deblock = y_to_deblock
| ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)
| ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);
if(!mb_x)
y_v_deblock &= ~MASK_Y_LEFT_COL;
if(!row)
y_h_deblock &= ~MASK_Y_TOP_ROW;
if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))
y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);
for(i = 0; i < 2; i++){
c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];
c_v_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)
| ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);
c_h_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)
| (uvcbp[POS_CUR][i] << 2);
if(!mb_x)
c_v_deblock[i] &= ~MASK_C_LEFT_COL;
if(!row)
c_h_deblock[i] &= ~MASK_C_TOP_ROW;
if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])
c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);
}
for(j = 0; j < 16; j += 4){
Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
int dither = j ? ij : i*4;
if(y_h_deblock & (MASK_BOTTOM << ij)){
rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither,
y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,
clip_cur,
alpha, beta, betaY, 0, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){
if(!i)
clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
else
clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_v_loop_filter(Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 0);
}
if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){
rv40_h_loop_filter(Y, s->linesize, dither,
clip_cur,
(cbp[POS_TOP] | mvmasks[POS_TOP]) & (MASK_TOP << i) ? clip[POS_TOP] : 0,
alpha, beta, betaY, 0, 1);
}
if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){
clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
rv40_v_loop_filter(Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 1);
}
}
}
for(k = 0; k < 2; k++){
for(j = 0; j < 2; j++){
C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + j*2;
int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
if(c_h_deblock[k] & (MASK_CUR << (ij+2))){
int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;
rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8,
clip_bot,
clip_cur,
alpha, beta, betaC, 1, 0);
}
if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){
if(!i)
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
else
clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_v_loop_filter(C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 0);
}
if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){
int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;
rv40_h_loop_filter(C, s->uvlinesize, i*8,
clip_cur,
clip_top,
alpha, beta, betaC, 1, 1);
}
if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
rv40_v_loop_filter(C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 1);
}
}
}
}
}
}
|
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = cbp[POS_CUR]\n | (cbp[POS_BOTTOM] << 16)\n | mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur,\n alpha, beta, betaY, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_h_loop_filter(Y, s->linesize, dither,\n clip_cur,\n (cbp[POS_TOP] | mvmasks[POS_TOP]) & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = (cbp[POS_LEFT] | mvmasks[POS_LEFT]) & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_v_loop_filter(Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_h_loop_filter(C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_v_loop_filter(C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1);\n }\n }\n }\n }\n }\n}']
|
1,146
| 0
|
https://github.com/libav/libav/blob/e445647b4fdf481b13b2743b303d84de4f43bedd/libavcodec/mpegvideo.c/#L883
|
static int init_context_frame(MpegEncContext *s)
{
int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
s->mb_width = (s->width + 15) / 16;
s->mb_stride = s->mb_width + 1;
s->b8_stride = s->mb_width * 2 + 1;
s->b4_stride = s->mb_width * 4 + 1;
mb_array_size = s->mb_height * s->mb_stride;
mv_table_size = (s->mb_height + 2) * s->mb_stride + 1;
s->h_edge_pos = s->mb_width * 16;
s->v_edge_pos = s->mb_height * 16;
s->mb_num = s->mb_width * s->mb_height;
s->block_wrap[0] =
s->block_wrap[1] =
s->block_wrap[2] =
s->block_wrap[3] = s->b8_stride;
s->block_wrap[4] =
s->block_wrap[5] = s->mb_stride;
y_size = s->b8_stride * (2 * s->mb_height + 1);
c_size = s->mb_stride * (s->mb_height + 1);
yc_size = y_size + 2 * c_size;
FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int),
fail);
for (y = 0; y < s->mb_height; y++)
for (x = 0; x < s->mb_width; x++)
s->mb_index2xy[x + y * s->mb_width] = x + y * s->mb_stride;
s->mb_index2xy[s->mb_height * s->mb_width] =
(s->mb_height - 1) * s->mb_stride + s->mb_width;
if (s->encoding) {
FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base,
mv_table_size * 2 * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base,
mv_table_size * 2 * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base,
mv_table_size * 2 * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base,
mv_table_size * 2 * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base,
mv_table_size * 2 * sizeof(int16_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base,
mv_table_size * 2 * sizeof(int16_t), fail);
s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;
s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;
s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;
s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base +
s->mb_stride + 1;
s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base +
s->mb_stride + 1;
s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;
FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type, mb_array_size *
sizeof(uint16_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size *
sizeof(int), fail);
FF_ALLOC_OR_GOTO(s->avctx, s->cplx_tab,
mb_array_size * sizeof(float), fail);
FF_ALLOC_OR_GOTO(s->avctx, s->bits_tab,
mb_array_size * sizeof(float), fail);
}
if (s->codec_id == AV_CODEC_ID_MPEG4 ||
(s->flags & CODEC_FLAG_INTERLACED_ME)) {
for (i = 0; i < 2; i++) {
int j, k;
for (j = 0; j < 2; j++) {
for (k = 0; k < 2; k++) {
FF_ALLOCZ_OR_GOTO(s->avctx,
s->b_field_mv_table_base[i][j][k],
mv_table_size * 2 * sizeof(int16_t),
fail);
s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] +
s->mb_stride + 1;
}
FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j],
mb_array_size * 2 * sizeof(uint8_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j],
mv_table_size * 2 * sizeof(int16_t), fail);
s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]
+ s->mb_stride + 1;
}
FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i],
mb_array_size * 2 * sizeof(uint8_t), fail);
}
}
if (s->out_format == FMT_H263) {
FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);
s->coded_block = s->coded_block_base + s->b8_stride + 1;
FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table,
mb_array_size * sizeof(uint8_t), fail);
FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table,
mb_array_size * sizeof(uint8_t), fail);
}
if (s->h263_pred || s->h263_plus || !s->encoding) {
FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base,
yc_size * sizeof(int16_t), fail);
s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
s->dc_val[2] = s->dc_val[1] + c_size;
for (i = 0; i < yc_size; i++)
s->dc_val_base[i] = 1024;
}
FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);
memset(s->mbintra_table, 1, mb_array_size);
FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size + 2, fail);
return init_er(s);
fail:
return AVERROR(ENOMEM);
}
|
['static int init_context_frame(MpegEncContext *s)\n{\n int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;\n s->mb_width = (s->width + 15) / 16;\n s->mb_stride = s->mb_width + 1;\n s->b8_stride = s->mb_width * 2 + 1;\n s->b4_stride = s->mb_width * 4 + 1;\n mb_array_size = s->mb_height * s->mb_stride;\n mv_table_size = (s->mb_height + 2) * s->mb_stride + 1;\n s->h_edge_pos = s->mb_width * 16;\n s->v_edge_pos = s->mb_height * 16;\n s->mb_num = s->mb_width * s->mb_height;\n s->block_wrap[0] =\n s->block_wrap[1] =\n s->block_wrap[2] =\n s->block_wrap[3] = s->b8_stride;\n s->block_wrap[4] =\n s->block_wrap[5] = s->mb_stride;\n y_size = s->b8_stride * (2 * s->mb_height + 1);\n c_size = s->mb_stride * (s->mb_height + 1);\n yc_size = y_size + 2 * c_size;\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int),\n fail);\n for (y = 0; y < s->mb_height; y++)\n for (x = 0; x < s->mb_width; x++)\n s->mb_index2xy[x + y * s->mb_width] = x + y * s->mb_stride;\n s->mb_index2xy[s->mb_height * s->mb_width] =\n (s->mb_height - 1) * s->mb_stride + s->mb_width;\n if (s->encoding) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->p_mv_table_base,\n mv_table_size * 2 * sizeof(int16_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_forw_mv_table_base,\n mv_table_size * 2 * sizeof(int16_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_back_mv_table_base,\n mv_table_size * 2 * sizeof(int16_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_forw_mv_table_base,\n mv_table_size * 2 * sizeof(int16_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_bidir_back_mv_table_base,\n mv_table_size * 2 * sizeof(int16_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_direct_mv_table_base,\n mv_table_size * 2 * sizeof(int16_t), fail);\n s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1;\n s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1;\n s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1;\n s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base +\n s->mb_stride + 1;\n s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base +\n s->mb_stride + 1;\n s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1;\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_type, mb_array_size *\n sizeof(uint16_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size *\n sizeof(int), fail);\n FF_ALLOC_OR_GOTO(s->avctx, s->cplx_tab,\n mb_array_size * sizeof(float), fail);\n FF_ALLOC_OR_GOTO(s->avctx, s->bits_tab,\n mb_array_size * sizeof(float), fail);\n }\n if (s->codec_id == AV_CODEC_ID_MPEG4 ||\n (s->flags & CODEC_FLAG_INTERLACED_ME)) {\n for (i = 0; i < 2; i++) {\n int j, k;\n for (j = 0; j < 2; j++) {\n for (k = 0; k < 2; k++) {\n FF_ALLOCZ_OR_GOTO(s->avctx,\n s->b_field_mv_table_base[i][j][k],\n mv_table_size * 2 * sizeof(int16_t),\n fail);\n s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] +\n s->mb_stride + 1;\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j],\n mb_array_size * 2 * sizeof(uint8_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j],\n mv_table_size * 2 * sizeof(int16_t), fail);\n s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]\n + s->mb_stride + 1;\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i],\n mb_array_size * 2 * sizeof(uint8_t), fail);\n }\n }\n if (s->out_format == FMT_H263) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail);\n s->coded_block = s->coded_block_base + s->b8_stride + 1;\n FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table,\n mb_array_size * sizeof(uint8_t), fail);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table,\n mb_array_size * sizeof(uint8_t), fail);\n }\n if (s->h263_pred || s->h263_plus || !s->encoding) {\n FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base,\n yc_size * sizeof(int16_t), fail);\n s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;\n s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;\n s->dc_val[2] = s->dc_val[1] + c_size;\n for (i = 0; i < yc_size; i++)\n s->dc_val_base[i] = 1024;\n }\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail);\n memset(s->mbintra_table, 1, mb_array_size);\n FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size + 2, fail);\n return init_er(s);\nfail:\n return AVERROR(ENOMEM);\n}', 'void *av_mallocz(size_t size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\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}']
|
1,147
| 0
|
https://github.com/libav/libav/blob/fc322d6a70189da24dbd445c710bb214eb031ce7/libavcodec/bitstream.h/#L139
|
static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
}
|
['static int read_channel_params(MLPDecodeContext *m, unsigned int substr,\n BitstreamContext *bc, unsigned int ch)\n{\n SubStream *s = &m->substream[substr];\n ChannelParams *cp = &s->channel_params[ch];\n FilterParams *fir = &cp->filter_params[FIR];\n FilterParams *iir = &cp->filter_params[IIR];\n int ret;\n if (s->param_presence_flags & PARAM_FIR)\n if (bitstream_read_bit(bc))\n if ((ret = read_filter_params(m, bc, substr, ch, FIR)) < 0)\n return ret;\n if (s->param_presence_flags & PARAM_IIR)\n if (bitstream_read_bit(bc))\n if ((ret = read_filter_params(m, bc, substr, ch, IIR)) < 0)\n return ret;\n if (fir->order + iir->order > 8) {\n av_log(m->avctx, AV_LOG_ERROR, "Total filter orders too high.\\n");\n return AVERROR_INVALIDDATA;\n }\n if (fir->order && iir->order &&\n fir->shift != iir->shift) {\n av_log(m->avctx, AV_LOG_ERROR,\n "FIR and IIR filters must use the same precision.\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!fir->order && iir->order)\n fir->shift = iir->shift;\n if (s->param_presence_flags & PARAM_HUFFOFFSET)\n if (bitstream_read_bit(bc))\n cp->huff_offset = bitstream_read_signed(bc, 15);\n cp->codebook = bitstream_read(bc, 2);\n cp->huff_lsbs = bitstream_read(bc, 5);\n if (cp->huff_lsbs > 24) {\n av_log(m->avctx, AV_LOG_ERROR, "Invalid huff_lsbs.\\n");\n return AVERROR_INVALIDDATA;\n }\n cp->sign_huff_offset = calculate_sign_huff(m, substr, ch);\n return 0;\n}', 'static inline 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}']
|
1,148
| 0
|
https://github.com/openssl/openssl/blob/8e826a339f8cda20a4311fa88a1de782972cf40d/crypto/bn/bn_sqr.c/#L120
|
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);
}
|
['char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n char **verifier, const char *N, const char *g)\n{\n int len;\n char *result = NULL, *vf = NULL;\n const BIGNUM *N_bn = NULL, *g_bn = NULL;\n BIGNUM *N_bn_alloc = NULL, *g_bn_alloc = NULL, *s = NULL, *v = NULL;\n unsigned char tmp[MAX_LEN];\n unsigned char tmp2[MAX_LEN];\n char *defgNid = NULL;\n int vfsize = 0;\n if ((user == NULL) ||\n (pass == NULL) || (salt == NULL) || (verifier == NULL))\n goto err;\n if (N) {\n if ((len = t_fromb64(tmp, sizeof(tmp), N)) <= 0)\n goto err;\n N_bn_alloc = BN_bin2bn(tmp, len, NULL);\n N_bn = N_bn_alloc;\n if ((len = t_fromb64(tmp, sizeof(tmp) ,g)) <= 0)\n goto err;\n g_bn_alloc = BN_bin2bn(tmp, len, NULL);\n g_bn = g_bn_alloc;\n defgNid = "*";\n } else {\n SRP_gN *gN = SRP_get_gN_by_id(g, NULL);\n if (gN == NULL)\n goto err;\n N_bn = gN->N;\n g_bn = gN->g;\n defgNid = gN->id;\n }\n if (*salt == NULL) {\n if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n goto err;\n s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n } else {\n if ((len = t_fromb64(tmp2, sizeof(tmp2), *salt)) <= 0)\n goto err;\n s = BN_bin2bn(tmp2, len, NULL);\n }\n if (!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn))\n goto err;\n BN_bn2bin(v, tmp);\n vfsize = BN_num_bytes(v) * 2;\n if (((vf = OPENSSL_malloc(vfsize)) == NULL))\n goto err;\n t_tob64(vf, tmp, BN_num_bytes(v));\n if (*salt == NULL) {\n char *tmp_salt;\n if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) {\n goto err;\n }\n t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN);\n *salt = tmp_salt;\n }\n *verifier = vf;\n vf = NULL;\n result = defgNid;\n err:\n BN_free(N_bn_alloc);\n BN_free(g_bn_alloc);\n OPENSSL_clear_free(vf, vfsize);\n BN_clear_free(s);\n BN_clear_free(v);\n return result;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return (NULL);\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return (ret);\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return (ret);\n}', 'int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n BIGNUM **verifier, const BIGNUM *N,\n const BIGNUM *g)\n{\n int result = 0;\n BIGNUM *x = NULL;\n BN_CTX *bn_ctx = BN_CTX_new();\n unsigned char tmp2[MAX_LEN];\n BIGNUM *salttmp = NULL;\n if ((user == NULL) ||\n (pass == NULL) ||\n (salt == NULL) ||\n (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n goto err;\n if (*salt == NULL) {\n if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n goto err;\n salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n } else {\n salttmp = *salt;\n }\n x = SRP_Calc_x(salttmp, user, pass);\n *verifier = BN_new();\n if (*verifier == NULL)\n goto err;\n if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n BN_clear_free(*verifier);\n goto err;\n }\n result = 1;\n *salt = salttmp;\n err:\n if (salt != NULL && *salt != salttmp)\n BN_clear_free(salttmp);\n BN_clear_free(x);\n BN_CTX_free(bn_ctx);\n return result;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_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(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 = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return (ret);\n}', '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}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,149
| 0
|
https://github.com/openssl/openssl/blob/bd01733fdd9a5a0acdc72cf5c6601d37e8ddd801/crypto/bn/bn_lib.c/#L232
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['static int generate_key(DH *dh)\n{\n int ok = 0;\n int generate_new_key = 0;\n unsigned l;\n BN_CTX *ctx = NULL;\n BN_MONT_CTX *mont = NULL;\n BIGNUM *pub_key = NULL, *priv_key = NULL;\n if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {\n DHerr(DH_F_GENERATE_KEY, DH_R_MODULUS_TOO_LARGE);\n return 0;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n if (dh->priv_key == NULL) {\n priv_key = BN_secure_new();\n if (priv_key == NULL)\n goto err;\n generate_new_key = 1;\n } else\n priv_key = dh->priv_key;\n if (dh->pub_key == NULL) {\n pub_key = BN_new();\n if (pub_key == NULL)\n goto err;\n } else\n pub_key = dh->pub_key;\n if (dh->flags & DH_FLAG_CACHE_MONT_P) {\n mont = BN_MONT_CTX_set_locked(&dh->method_mont_p,\n dh->lock, dh->p, ctx);\n if (!mont)\n goto err;\n }\n if (generate_new_key) {\n if (dh->q) {\n do {\n if (!BN_priv_rand_range(priv_key, dh->q))\n goto err;\n }\n while (BN_is_zero(priv_key) || BN_is_one(priv_key));\n } else {\n l = dh->length ? dh->length : BN_num_bits(dh->p) - 1;\n if (!BN_priv_rand(priv_key, l, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto err;\n }\n }\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 (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) {\n BN_free(prk);\n goto err;\n }\n BN_free(prk);\n }\n dh->pub_key = pub_key;\n dh->priv_key = priv_key;\n ok = 1;\n err:\n if (ok != 1)\n DHerr(DH_F_GENERATE_KEY, ERR_R_BN_LIB);\n if (pub_key != dh->pub_key)\n BN_free(pub_key);\n if (priv_key != dh->priv_key)\n BN_free(priv_key);\n BN_CTX_free(ctx);\n return ok;\n}', 'int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(PRIVATE, rnd, bits, top, bottom, NULL);\n}', 'static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom,\n BN_CTX *ctx)\n{\n unsigned char *buf = NULL;\n int b, ret = 0, bit, bytes, mask;\n OPENSSL_CTX *libctx = bn_get_lib_ctx(ctx);\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n b = flag == NORMAL ? rand_bytes_ex(libctx, buf, bytes)\n : rand_priv_bytes_ex(libctx, buf, bytes);\n if (b <= 0)\n goto err;\n if (flag == TESTING) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (rand_bytes_ex(libctx, &c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return ret;\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
1,150
| 0
|
https://github.com/libav/libav/blob/606cc8afa1cb782311f68560c8f9bad978cdcc32/libavcodec/h264_parser.c/#L224
|
static inline int parse_nal_units(AVCodecParserContext *s,
AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
H264Context *h = s->priv_data;
const uint8_t *buf_end = buf + buf_size;
unsigned int pps_id;
unsigned int slice_type;
int state = -1, got_reset = 0;
const uint8_t *ptr;
int field_poc[2];
s->pict_type = AV_PICTURE_TYPE_I;
s->key_frame = 0;
s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
h->avctx = avctx;
ff_h264_reset_sei(h);
if (!buf_size)
return 0;
for (;;) {
int src_length, dst_length, consumed;
buf = avpriv_find_start_code(buf, buf_end, &state);
if (buf >= buf_end)
break;
--buf;
src_length = buf_end - buf;
switch (state & 0x1f) {
case NAL_SLICE:
case NAL_IDR_SLICE:
if ((state & 0x1f) == NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {
if (src_length > 60)
src_length = 60;
} else {
if (src_length > 1000)
src_length = 1000;
}
break;
}
ptr = ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);
if (ptr == NULL || dst_length < 0)
break;
init_get_bits(&h->gb, ptr, 8 * dst_length);
switch (h->nal_unit_type) {
case NAL_SPS:
ff_h264_decode_seq_parameter_set(h);
break;
case NAL_PPS:
ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);
break;
case NAL_SEI:
ff_h264_decode_sei(h);
break;
case NAL_IDR_SLICE:
s->key_frame = 1;
h->prev_frame_num = 0;
h->prev_frame_num_offset = 0;
h->prev_poc_msb =
h->prev_poc_lsb = 0;
case NAL_SLICE:
get_ue_golomb(&h->gb);
slice_type = get_ue_golomb_31(&h->gb);
s->pict_type = golomb_to_pict_type[slice_type % 5];
if (h->sei_recovery_frame_cnt >= 0) {
s->key_frame = 1;
}
pps_id = get_ue_golomb(&h->gb);
if (pps_id >= MAX_PPS_COUNT) {
av_log(h->avctx, AV_LOG_ERROR,
"pps_id %u out of range\n", pps_id);
return -1;
}
if (!h->pps_buffers[pps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing PPS %u referenced\n", pps_id);
return -1;
}
h->pps = *h->pps_buffers[pps_id];
if (!h->sps_buffers[h->pps.sps_id]) {
av_log(h->avctx, AV_LOG_ERROR,
"non-existing SPS %u referenced\n", h->pps.sps_id);
return -1;
}
h->sps = *h->sps_buffers[h->pps.sps_id];
h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);
avctx->profile = ff_h264_get_profile(&h->sps);
avctx->level = h->sps.level_idc;
if (h->sps.frame_mbs_only_flag) {
h->picture_structure = PICT_FRAME;
} else {
if (get_bits1(&h->gb)) {
h->picture_structure = PICT_TOP_FIELD + get_bits1(&h->gb);
} else {
h->picture_structure = PICT_FRAME;
}
}
if (h->nal_unit_type == NAL_IDR_SLICE)
get_ue_golomb(&h->gb);
if (h->sps.poc_type == 0) {
h->poc_lsb = get_bits(&h->gb, h->sps.log2_max_poc_lsb);
if (h->pps.pic_order_present == 1 &&
h->picture_structure == PICT_FRAME)
h->delta_poc_bottom = get_se_golomb(&h->gb);
}
if (h->sps.poc_type == 1 &&
!h->sps.delta_pic_order_always_zero_flag) {
h->delta_poc[0] = get_se_golomb(&h->gb);
if (h->pps.pic_order_present == 1 &&
h->picture_structure == PICT_FRAME)
h->delta_poc[1] = get_se_golomb(&h->gb);
}
field_poc[0] = field_poc[1] = INT_MAX;
ff_init_poc(h, field_poc, &s->output_picture_number);
if (h->nal_ref_idc && h->nal_unit_type != NAL_IDR_SLICE) {
got_reset = scan_mmco_reset(s);
if (got_reset < 0)
return got_reset;
}
h->prev_frame_num = got_reset ? 0 : h->frame_num;
h->prev_frame_num_offset = got_reset ? 0 : h->frame_num_offset;
if (h->nal_ref_idc != 0) {
if (!got_reset) {
h->prev_poc_msb = h->poc_msb;
h->prev_poc_lsb = h->poc_lsb;
} else {
h->prev_poc_msb = 0;
h->prev_poc_lsb =
h->picture_structure == PICT_BOTTOM_FIELD ? 0 : field_poc[0];
}
}
if (h->sps.pic_struct_present_flag) {
switch (h->sei_pic_struct) {
case SEI_PIC_STRUCT_TOP_FIELD:
case SEI_PIC_STRUCT_BOTTOM_FIELD:
s->repeat_pict = 0;
break;
case SEI_PIC_STRUCT_FRAME:
case SEI_PIC_STRUCT_TOP_BOTTOM:
case SEI_PIC_STRUCT_BOTTOM_TOP:
s->repeat_pict = 1;
break;
case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
s->repeat_pict = 2;
break;
case SEI_PIC_STRUCT_FRAME_DOUBLING:
s->repeat_pict = 3;
break;
case SEI_PIC_STRUCT_FRAME_TRIPLING:
s->repeat_pict = 5;
break;
default:
s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;
break;
}
} else {
s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;
}
if (h->picture_structure == PICT_FRAME) {
s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;
if (h->sps.pic_struct_present_flag) {
switch (h->sei_pic_struct) {
case SEI_PIC_STRUCT_TOP_BOTTOM:
case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
s->field_order = AV_FIELD_TT;
break;
case SEI_PIC_STRUCT_BOTTOM_TOP:
case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
s->field_order = AV_FIELD_BB;
break;
default:
s->field_order = AV_FIELD_PROGRESSIVE;
break;
}
} else {
if (field_poc[0] < field_poc[1])
s->field_order = AV_FIELD_TT;
else if (field_poc[0] > field_poc[1])
s->field_order = AV_FIELD_BB;
else
s->field_order = AV_FIELD_PROGRESSIVE;
}
} else {
if (h->picture_structure == PICT_TOP_FIELD)
s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;
else
s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;
s->field_order = AV_FIELD_UNKNOWN;
}
return 0;
}
buf += consumed;
}
av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\n");
return -1;
}
|
['static inline int parse_nal_units(AVCodecParserContext *s,\n AVCodecContext *avctx,\n const uint8_t *buf, int buf_size)\n{\n H264Context *h = s->priv_data;\n const uint8_t *buf_end = buf + buf_size;\n unsigned int pps_id;\n unsigned int slice_type;\n int state = -1, got_reset = 0;\n const uint8_t *ptr;\n int field_poc[2];\n s->pict_type = AV_PICTURE_TYPE_I;\n s->key_frame = 0;\n s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;\n h->avctx = avctx;\n ff_h264_reset_sei(h);\n if (!buf_size)\n return 0;\n for (;;) {\n int src_length, dst_length, consumed;\n buf = avpriv_find_start_code(buf, buf_end, &state);\n if (buf >= buf_end)\n break;\n --buf;\n src_length = buf_end - buf;\n switch (state & 0x1f) {\n case NAL_SLICE:\n case NAL_IDR_SLICE:\n if ((state & 0x1f) == NAL_IDR_SLICE || ((state >> 5) & 0x3) == 0) {\n if (src_length > 60)\n src_length = 60;\n } else {\n if (src_length > 1000)\n src_length = 1000;\n }\n break;\n }\n ptr = ff_h264_decode_nal(h, buf, &dst_length, &consumed, src_length);\n if (ptr == NULL || dst_length < 0)\n break;\n init_get_bits(&h->gb, ptr, 8 * dst_length);\n switch (h->nal_unit_type) {\n case NAL_SPS:\n ff_h264_decode_seq_parameter_set(h);\n break;\n case NAL_PPS:\n ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);\n break;\n case NAL_SEI:\n ff_h264_decode_sei(h);\n break;\n case NAL_IDR_SLICE:\n s->key_frame = 1;\n h->prev_frame_num = 0;\n h->prev_frame_num_offset = 0;\n h->prev_poc_msb =\n h->prev_poc_lsb = 0;\n case NAL_SLICE:\n get_ue_golomb(&h->gb);\n slice_type = get_ue_golomb_31(&h->gb);\n s->pict_type = golomb_to_pict_type[slice_type % 5];\n if (h->sei_recovery_frame_cnt >= 0) {\n s->key_frame = 1;\n }\n pps_id = get_ue_golomb(&h->gb);\n if (pps_id >= MAX_PPS_COUNT) {\n av_log(h->avctx, AV_LOG_ERROR,\n "pps_id %u out of range\\n", pps_id);\n return -1;\n }\n if (!h->pps_buffers[pps_id]) {\n av_log(h->avctx, AV_LOG_ERROR,\n "non-existing PPS %u referenced\\n", pps_id);\n return -1;\n }\n h->pps = *h->pps_buffers[pps_id];\n if (!h->sps_buffers[h->pps.sps_id]) {\n av_log(h->avctx, AV_LOG_ERROR,\n "non-existing SPS %u referenced\\n", h->pps.sps_id);\n return -1;\n }\n h->sps = *h->sps_buffers[h->pps.sps_id];\n h->frame_num = get_bits(&h->gb, h->sps.log2_max_frame_num);\n avctx->profile = ff_h264_get_profile(&h->sps);\n avctx->level = h->sps.level_idc;\n if (h->sps.frame_mbs_only_flag) {\n h->picture_structure = PICT_FRAME;\n } else {\n if (get_bits1(&h->gb)) {\n h->picture_structure = PICT_TOP_FIELD + get_bits1(&h->gb);\n } else {\n h->picture_structure = PICT_FRAME;\n }\n }\n if (h->nal_unit_type == NAL_IDR_SLICE)\n get_ue_golomb(&h->gb);\n if (h->sps.poc_type == 0) {\n h->poc_lsb = get_bits(&h->gb, h->sps.log2_max_poc_lsb);\n if (h->pps.pic_order_present == 1 &&\n h->picture_structure == PICT_FRAME)\n h->delta_poc_bottom = get_se_golomb(&h->gb);\n }\n if (h->sps.poc_type == 1 &&\n !h->sps.delta_pic_order_always_zero_flag) {\n h->delta_poc[0] = get_se_golomb(&h->gb);\n if (h->pps.pic_order_present == 1 &&\n h->picture_structure == PICT_FRAME)\n h->delta_poc[1] = get_se_golomb(&h->gb);\n }\n field_poc[0] = field_poc[1] = INT_MAX;\n ff_init_poc(h, field_poc, &s->output_picture_number);\n if (h->nal_ref_idc && h->nal_unit_type != NAL_IDR_SLICE) {\n got_reset = scan_mmco_reset(s);\n if (got_reset < 0)\n return got_reset;\n }\n h->prev_frame_num = got_reset ? 0 : h->frame_num;\n h->prev_frame_num_offset = got_reset ? 0 : h->frame_num_offset;\n if (h->nal_ref_idc != 0) {\n if (!got_reset) {\n h->prev_poc_msb = h->poc_msb;\n h->prev_poc_lsb = h->poc_lsb;\n } else {\n h->prev_poc_msb = 0;\n h->prev_poc_lsb =\n h->picture_structure == PICT_BOTTOM_FIELD ? 0 : field_poc[0];\n }\n }\n if (h->sps.pic_struct_present_flag) {\n switch (h->sei_pic_struct) {\n case SEI_PIC_STRUCT_TOP_FIELD:\n case SEI_PIC_STRUCT_BOTTOM_FIELD:\n s->repeat_pict = 0;\n break;\n case SEI_PIC_STRUCT_FRAME:\n case SEI_PIC_STRUCT_TOP_BOTTOM:\n case SEI_PIC_STRUCT_BOTTOM_TOP:\n s->repeat_pict = 1;\n break;\n case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:\n case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:\n s->repeat_pict = 2;\n break;\n case SEI_PIC_STRUCT_FRAME_DOUBLING:\n s->repeat_pict = 3;\n break;\n case SEI_PIC_STRUCT_FRAME_TRIPLING:\n s->repeat_pict = 5;\n break;\n default:\n s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;\n break;\n }\n } else {\n s->repeat_pict = h->picture_structure == PICT_FRAME ? 1 : 0;\n }\n if (h->picture_structure == PICT_FRAME) {\n s->picture_structure = AV_PICTURE_STRUCTURE_FRAME;\n if (h->sps.pic_struct_present_flag) {\n switch (h->sei_pic_struct) {\n case SEI_PIC_STRUCT_TOP_BOTTOM:\n case SEI_PIC_STRUCT_TOP_BOTTOM_TOP:\n s->field_order = AV_FIELD_TT;\n break;\n case SEI_PIC_STRUCT_BOTTOM_TOP:\n case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:\n s->field_order = AV_FIELD_BB;\n break;\n default:\n s->field_order = AV_FIELD_PROGRESSIVE;\n break;\n }\n } else {\n if (field_poc[0] < field_poc[1])\n s->field_order = AV_FIELD_TT;\n else if (field_poc[0] > field_poc[1])\n s->field_order = AV_FIELD_BB;\n else\n s->field_order = AV_FIELD_PROGRESSIVE;\n }\n } else {\n if (h->picture_structure == PICT_TOP_FIELD)\n s->picture_structure = AV_PICTURE_STRUCTURE_TOP_FIELD;\n else\n s->picture_structure = AV_PICTURE_STRUCTURE_BOTTOM_FIELD;\n s->field_order = AV_FIELD_UNKNOWN;\n }\n return 0;\n }\n buf += consumed;\n }\n av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit\\n");\n return -1;\n}', 'void ff_h264_reset_sei(H264Context *h)\n{\n h->sei_recovery_frame_cnt = -1;\n h->sei_dpb_output_delay = 0;\n h->sei_cpb_removal_delay = -1;\n h->sei_buffering_period_present = 0;\n h->sei_frame_packing_present = 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'int ff_h264_decode_seq_parameter_set(H264Context *h)\n{\n int profile_idc, level_idc, constraint_set_flags = 0;\n unsigned int sps_id;\n int i, log2_max_frame_num_minus4;\n SPS *sps;\n profile_idc = get_bits(&h->gb, 8);\n constraint_set_flags |= get_bits1(&h->gb) << 0;\n constraint_set_flags |= get_bits1(&h->gb) << 1;\n constraint_set_flags |= get_bits1(&h->gb) << 2;\n constraint_set_flags |= get_bits1(&h->gb) << 3;\n constraint_set_flags |= get_bits1(&h->gb) << 4;\n constraint_set_flags |= get_bits1(&h->gb) << 5;\n skip_bits(&h->gb, 2);\n level_idc = get_bits(&h->gb, 8);\n sps_id = get_ue_golomb_31(&h->gb);\n if (sps_id >= MAX_SPS_COUNT) {\n av_log(h->avctx, AV_LOG_ERROR, "sps_id %u out of range\\n", sps_id);\n return AVERROR_INVALIDDATA;\n }\n sps = av_mallocz(sizeof(SPS));\n if (!sps)\n return AVERROR(ENOMEM);\n sps->sps_id = sps_id;\n sps->time_offset_length = 24;\n sps->profile_idc = profile_idc;\n sps->constraint_set_flags = constraint_set_flags;\n sps->level_idc = level_idc;\n memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));\n memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));\n sps->scaling_matrix_present = 0;\n if (sps->profile_idc == 100 ||\n sps->profile_idc == 110 ||\n sps->profile_idc == 122 ||\n sps->profile_idc == 244 ||\n sps->profile_idc == 44 ||\n sps->profile_idc == 83 ||\n sps->profile_idc == 86 ||\n sps->profile_idc == 118 ||\n sps->profile_idc == 128 ||\n sps->profile_idc == 138 ||\n sps->profile_idc == 144) {\n sps->chroma_format_idc = get_ue_golomb_31(&h->gb);\n if (sps->chroma_format_idc > 3) {\n avpriv_request_sample(h->avctx, "chroma_format_idc %u",\n sps->chroma_format_idc);\n goto fail;\n } else if (sps->chroma_format_idc == 3) {\n sps->residual_color_transform_flag = get_bits1(&h->gb);\n }\n sps->bit_depth_luma = get_ue_golomb(&h->gb) + 8;\n sps->bit_depth_chroma = get_ue_golomb(&h->gb) + 8;\n if (sps->bit_depth_chroma != sps->bit_depth_luma) {\n avpriv_request_sample(h->avctx,\n "Different chroma and luma bit depth");\n goto fail;\n }\n sps->transform_bypass = get_bits1(&h->gb);\n decode_scaling_matrices(h, sps, NULL, 1,\n sps->scaling_matrix4, sps->scaling_matrix8);\n } else {\n sps->chroma_format_idc = 1;\n sps->bit_depth_luma = 8;\n sps->bit_depth_chroma = 8;\n }\n log2_max_frame_num_minus4 = get_ue_golomb(&h->gb);\n if (log2_max_frame_num_minus4 < MIN_LOG2_MAX_FRAME_NUM - 4 ||\n log2_max_frame_num_minus4 > MAX_LOG2_MAX_FRAME_NUM - 4) {\n av_log(h->avctx, AV_LOG_ERROR,\n "log2_max_frame_num_minus4 out of range (0-12): %d\\n",\n log2_max_frame_num_minus4);\n goto fail;\n }\n sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;\n sps->poc_type = get_ue_golomb_31(&h->gb);\n if (sps->poc_type == 0) {\n sps->log2_max_poc_lsb = get_ue_golomb(&h->gb) + 4;\n } else if (sps->poc_type == 1) {\n sps->delta_pic_order_always_zero_flag = get_bits1(&h->gb);\n sps->offset_for_non_ref_pic = get_se_golomb(&h->gb);\n sps->offset_for_top_to_bottom_field = get_se_golomb(&h->gb);\n sps->poc_cycle_length = get_ue_golomb(&h->gb);\n if ((unsigned)sps->poc_cycle_length >=\n FF_ARRAY_ELEMS(sps->offset_for_ref_frame)) {\n av_log(h->avctx, AV_LOG_ERROR,\n "poc_cycle_length overflow %u\\n", sps->poc_cycle_length);\n goto fail;\n }\n for (i = 0; i < sps->poc_cycle_length; i++)\n sps->offset_for_ref_frame[i] = get_se_golomb(&h->gb);\n } else if (sps->poc_type != 2) {\n av_log(h->avctx, AV_LOG_ERROR, "illegal POC type %d\\n", sps->poc_type);\n goto fail;\n }\n sps->ref_frame_count = get_ue_golomb_31(&h->gb);\n if (sps->ref_frame_count > H264_MAX_PICTURE_COUNT - 2 ||\n sps->ref_frame_count >= 32U) {\n av_log(h->avctx, AV_LOG_ERROR,\n "too many reference frames %d\\n", sps->ref_frame_count);\n goto fail;\n }\n sps->gaps_in_frame_num_allowed_flag = get_bits1(&h->gb);\n sps->mb_width = get_ue_golomb(&h->gb) + 1;\n sps->mb_height = get_ue_golomb(&h->gb) + 1;\n if ((unsigned)sps->mb_width >= INT_MAX / 16 ||\n (unsigned)sps->mb_height >= INT_MAX / 16 ||\n av_image_check_size(16 * sps->mb_width,\n 16 * sps->mb_height, 0, h->avctx)) {\n av_log(h->avctx, AV_LOG_ERROR, "mb_width/height overflow\\n");\n goto fail;\n }\n sps->frame_mbs_only_flag = get_bits1(&h->gb);\n if (!sps->frame_mbs_only_flag)\n sps->mb_aff = get_bits1(&h->gb);\n else\n sps->mb_aff = 0;\n sps->direct_8x8_inference_flag = get_bits1(&h->gb);\n if (!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag) {\n av_log(h->avctx, AV_LOG_ERROR,\n "This stream was generated by a broken encoder, invalid 8x8 inference\\n");\n goto fail;\n }\n#ifndef ALLOW_INTERLACE\n if (sps->mb_aff)\n av_log(h->avctx, AV_LOG_ERROR,\n "MBAFF support not included; enable it at compile-time.\\n");\n#endif\n sps->crop = get_bits1(&h->gb);\n if (sps->crop) {\n int crop_left = get_ue_golomb(&h->gb);\n int crop_right = get_ue_golomb(&h->gb);\n int crop_top = get_ue_golomb(&h->gb);\n int crop_bottom = get_ue_golomb(&h->gb);\n if (h->avctx->flags2 & CODEC_FLAG2_IGNORE_CROP) {\n av_log(h->avctx, AV_LOG_DEBUG, "discarding sps cropping, original "\n "values are l:%u r:%u t:%u b:%u\\n",\n crop_left, crop_right, crop_top, crop_bottom);\n sps->crop_left =\n sps->crop_right =\n sps->crop_top =\n sps->crop_bottom = 0;\n } else {\n int vsub = (sps->chroma_format_idc == 1) ? 1 : 0;\n int hsub = (sps->chroma_format_idc == 1 ||\n sps->chroma_format_idc == 2) ? 1 : 0;\n int step_x = 1 << hsub;\n int step_y = (2 - sps->frame_mbs_only_flag) << vsub;\n if (crop_left & (0x1F >> (sps->bit_depth_luma > 8)) &&\n !(h->avctx->flags & CODEC_FLAG_UNALIGNED)) {\n crop_left &= ~(0x1F >> (sps->bit_depth_luma > 8));\n av_log(h->avctx, AV_LOG_WARNING,\n "Reducing left cropping to %d "\n "chroma samples to preserve alignment.\\n",\n crop_left);\n }\n sps->crop_left = crop_left * step_x;\n sps->crop_right = crop_right * step_x;\n sps->crop_top = crop_top * step_y;\n sps->crop_bottom = crop_bottom * step_y;\n }\n } else {\n sps->crop_left =\n sps->crop_right =\n sps->crop_top =\n sps->crop_bottom =\n sps->crop = 0;\n }\n sps->vui_parameters_present_flag = get_bits1(&h->gb);\n if (sps->vui_parameters_present_flag) {\n int ret = decode_vui_parameters(h, sps);\n if (ret < 0 && h->avctx->err_recognition & AV_EF_EXPLODE)\n goto fail;\n }\n if (!sps->sar.den)\n sps->sar.den = 1;\n if (h->avctx->debug & FF_DEBUG_PICT_INFO) {\n static const char csp[4][5] = { "Gray", "420", "422", "444" };\n av_log(h->avctx, AV_LOG_DEBUG,\n "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d\\n",\n sps_id, sps->profile_idc, sps->level_idc,\n sps->poc_type,\n sps->ref_frame_count,\n sps->mb_width, sps->mb_height,\n sps->frame_mbs_only_flag ? "FRM" : (sps->mb_aff ? "MB-AFF" : "PIC-AFF"),\n sps->direct_8x8_inference_flag ? "8B8" : "",\n sps->crop_left, sps->crop_right,\n sps->crop_top, sps->crop_bottom,\n sps->vui_parameters_present_flag ? "VUI" : "",\n csp[sps->chroma_format_idc],\n sps->timing_info_present_flag ? sps->num_units_in_tick : 0,\n sps->timing_info_present_flag ? sps->time_scale : 0);\n }\n sps->new = 1;\n av_free(h->sps_buffers[sps_id]);\n h->sps_buffers[sps_id] = sps;\n h->sps = *sps;\n return 0;\nfail:\n av_free(sps);\n return -1;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
1,151
| 0
|
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_sha1.c/#L270
|
static const u_char *
ngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)
{
uint32_t a, b, c, d, e, temp;
uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;
uint32_t words[80];
ngx_uint_t i;
const u_char *p;
p = data;
a = ctx->a;
b = ctx->b;
c = ctx->c;
d = ctx->d;
e = ctx->e;
do {
saved_a = a;
saved_b = b;
saved_c = c;
saved_d = d;
saved_e = e;
for (i = 0; i < 16; i++) {
words[i] = GET(i);
}
for (i = 16; i < 80; i++) {
words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]
^ words[i - 16]);
}
STEP(F1, a, b, c, d, e, words[0], 0x5a827999);
STEP(F1, a, b, c, d, e, words[1], 0x5a827999);
STEP(F1, a, b, c, d, e, words[2], 0x5a827999);
STEP(F1, a, b, c, d, e, words[3], 0x5a827999);
STEP(F1, a, b, c, d, e, words[4], 0x5a827999);
STEP(F1, a, b, c, d, e, words[5], 0x5a827999);
STEP(F1, a, b, c, d, e, words[6], 0x5a827999);
STEP(F1, a, b, c, d, e, words[7], 0x5a827999);
STEP(F1, a, b, c, d, e, words[8], 0x5a827999);
STEP(F1, a, b, c, d, e, words[9], 0x5a827999);
STEP(F1, a, b, c, d, e, words[10], 0x5a827999);
STEP(F1, a, b, c, d, e, words[11], 0x5a827999);
STEP(F1, a, b, c, d, e, words[12], 0x5a827999);
STEP(F1, a, b, c, d, e, words[13], 0x5a827999);
STEP(F1, a, b, c, d, e, words[14], 0x5a827999);
STEP(F1, a, b, c, d, e, words[15], 0x5a827999);
STEP(F1, a, b, c, d, e, words[16], 0x5a827999);
STEP(F1, a, b, c, d, e, words[17], 0x5a827999);
STEP(F1, a, b, c, d, e, words[18], 0x5a827999);
STEP(F1, a, b, c, d, e, words[19], 0x5a827999);
STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);
STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);
STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);
a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
e += saved_e;
p += 64;
} while (size -= 64);
ctx->a = a;
ctx->b = b;
ctx->c = c;
ctx->d = d;
ctx->e = e;
return p;
}
|
['static const u_char *\nngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)\n{\n uint32_t a, b, c, d, e, temp;\n uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;\n uint32_t words[80];\n ngx_uint_t i;\n const u_char *p;\n p = data;\n a = ctx->a;\n b = ctx->b;\n c = ctx->c;\n d = ctx->d;\n e = ctx->e;\n do {\n saved_a = a;\n saved_b = b;\n saved_c = c;\n saved_d = d;\n saved_e = e;\n for (i = 0; i < 16; i++) {\n words[i] = GET(i);\n }\n for (i = 16; i < 80; i++) {\n words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]\n ^ words[i - 16]);\n }\n STEP(F1, a, b, c, d, e, words[0], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[1], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[2], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[3], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[4], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[5], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[6], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[7], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[8], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[9], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[10], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[11], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[12], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[13], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[14], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[15], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[16], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[17], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[18], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[19], 0x5a827999);\n STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);\n STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);\n STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);\n a += saved_a;\n b += saved_b;\n c += saved_c;\n d += saved_d;\n e += saved_e;\n p += 64;\n } while (size -= 64);\n ctx->a = a;\n ctx->b = b;\n ctx->c = c;\n ctx->d = d;\n ctx->e = e;\n return p;\n}']
|
1,152
| 0
|
https://github.com/libav/libav/blob/5bf2ac2b37ae17df7f2bd541801bec8c049b8d2c/libavcodec/h264.c/#L1171
|
static void copy_parameter_set(void **to, void **from, int count, int size)
{
int i;
for (i=0; i<count; i++){
if (to[i] && !from[i]) av_freep(&to[i]);
else if (from[i] && !to[i]) to[i] = av_malloc(size);
if (from[i]) memcpy(to[i], from[i], size);
}
}
|
['static void copy_parameter_set(void **to, void **from, int count, int size)\n{\n int i;\n for (i=0; i<count; i++){\n if (to[i] && !from[i]) av_freep(&to[i]);\n else if (from[i] && !to[i]) to[i] = av_malloc(size);\n if (from[i]) memcpy(to[i], from[i], size);\n }\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,153
| 0
|
https://github.com/openssl/openssl/blob/b1860d6c71733314417d053a72af66ae72e8268e/crypto/bn/bn_ctx.c/#L276
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', '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}']
|
1,154
| 0
|
https://github.com/openssl/openssl/blob/0bde1089f895718db2fe2637fda4a0c2ed6df904/crypto/lhash/lhash.c/#L240
|
void *lh_delete(LHASH *lh, void *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
void *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['static SSL *doConnection(SSL *scon)\n\t{\n\tBIO *conn;\n\tSSL *serverCon;\n\tint width, i;\n\tfd_set readfds;\n\tif ((conn=BIO_new(BIO_s_connect())) == NULL)\n\t\treturn(NULL);\n\tBIO_set_conn_hostname(conn,host);\n\tif (scon == NULL)\n\t\tserverCon=(SSL *)SSL_new(tm_ctx);\n\telse\n\t\t{\n\t\tserverCon=scon;\n\t\tSSL_set_connect_state(serverCon);\n\t\t}\n\tSSL_set_bio(serverCon,conn,conn);\n#if 0\n\tif( scon != NULL )\n\t\tSSL_set_session(serverCon,SSL_get_session(scon));\n#endif\n\tfor(;;) {\n\t\ti=SSL_connect(serverCon);\n\t\tif (BIO_sock_should_retry(i))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DELAY\\n");\n\t\t\ti=SSL_get_fd(serverCon);\n\t\t\twidth=i+1;\n\t\t\tFD_ZERO(&readfds);\n\t\t\tFD_SET(i,&readfds);\n\t\t\tselect(width,(void *)&readfds,NULL,NULL,NULL);\n\t\t\tcontinue;\n\t\t\t}\n\t\tbreak;\n\t\t}\n\tif(i <= 0)\n\t\t{\n\t\tBIO_printf(bio_err,"ERROR\\n");\n\t\tif (verify_error != X509_V_OK)\n\t\t\tBIO_printf(bio_err,"verify error:%s\\n",\n\t\t\t\tX509_verify_cert_error_string(verify_error));\n\t\telse\n\t\t\tERR_print_errors(bio_err);\n\t\tif (scon == NULL)\n\t\t\tSSL_free(serverCon);\n\t\treturn NULL;\n\t\t}\n\treturn serverCon;\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)Malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_depth=ctx->verify_depth;\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tFree(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tint state;\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#endif\n\tstate=s->state;\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n\ts->read_ahead=s->ctx->read_ahead;\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->first_packet=0;\n#if 1\n\tif ((s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
|
1,155
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_sqr.c/#L114
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['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_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}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,156
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/vc1.c/#L657
|
static void vc1_mc_4mv_chroma(VC1Context *v)
{
MpegEncContext *s = &v->s;
DSPContext *dsp = &v->s.dsp;
uint8_t *srcU, *srcV;
int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;
int i, idx, tx = 0, ty = 0;
int mvx[4], mvy[4], intra[4];
static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};
if(!v->s.last_picture.data[0])return;
if(s->flags & CODEC_FLAG_GRAY) return;
for(i = 0; i < 4; i++) {
mvx[i] = s->mv[0][i][0];
mvy[i] = s->mv[0][i][1];
intra[i] = v->mb_type[0][s->block_index[i]];
}
idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];
if(!idx) {
tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);
ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);
} else if(count[idx] == 1) {
switch(idx) {
case 0x1:
tx = mid_pred(mvx[1], mvx[2], mvx[3]);
ty = mid_pred(mvy[1], mvy[2], mvy[3]);
break;
case 0x2:
tx = mid_pred(mvx[0], mvx[2], mvx[3]);
ty = mid_pred(mvy[0], mvy[2], mvy[3]);
break;
case 0x4:
tx = mid_pred(mvx[0], mvx[1], mvx[3]);
ty = mid_pred(mvy[0], mvy[1], mvy[3]);
break;
case 0x8:
tx = mid_pred(mvx[0], mvx[1], mvx[2]);
ty = mid_pred(mvy[0], mvy[1], mvy[2]);
break;
}
} else if(count[idx] == 2) {
int t1 = 0, t2 = 0;
for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}
for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}
tx = (mvx[t1] + mvx[t2]) / 2;
ty = (mvy[t1] + mvy[t2]) / 2;
} else {
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
return;
}
s->current_picture.motion_val[1][s->block_index[0]][0] = tx;
s->current_picture.motion_val[1][s->block_index[0]][1] = ty;
uvmx = (tx + ((tx&3) == 3)) >> 1;
uvmy = (ty + ((ty&3) == 3)) >> 1;
if(v->fastuvmc) {
uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));
uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));
}
uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
if(v->profile != PROFILE_ADVANCED){
uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);
uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);
}else{
uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);
uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);
}
srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)
|| (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9
|| (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){
ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,
uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
srcU = s->edge_emu_buffer;
srcV = s->edge_emu_buffer + 16;
if(v->rangeredfrm) {
int i, j;
uint8_t *src, *src2;
src = srcU; src2 = srcV;
for(j = 0; j < 9; j++) {
for(i = 0; i < 9; i++) {
src[i] = ((src[i] - 128) >> 1) + 128;
src2[i] = ((src2[i] - 128) >> 1) + 128;
}
src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {
int i, j;
uint8_t *src, *src2;
src = srcU; src2 = srcV;
for(j = 0; j < 9; j++) {
for(i = 0; i < 9; i++) {
src[i] = v->lutuv[src[i]];
src2[i] = v->lutuv[src2[i]];
}
src += s->uvlinesize;
src2 += s->uvlinesize;
}
}
}
uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);
uvmx = (uvmx&3)<<1;
uvmy = (uvmy&3)<<1;
if(!v->rnd){
dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
}else{
dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);
dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);
}
}
|
['static void vc1_mc_4mv_chroma(VC1Context *v)\n{\n MpegEncContext *s = &v->s;\n DSPContext *dsp = &v->s.dsp;\n uint8_t *srcU, *srcV;\n int uvdxy, uvmx, uvmy, uvsrc_x, uvsrc_y;\n int i, idx, tx = 0, ty = 0;\n int mvx[4], mvy[4], intra[4];\n static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4};\n if(!v->s.last_picture.data[0])return;\n if(s->flags & CODEC_FLAG_GRAY) return;\n for(i = 0; i < 4; i++) {\n mvx[i] = s->mv[0][i][0];\n mvy[i] = s->mv[0][i][1];\n intra[i] = v->mb_type[0][s->block_index[i]];\n }\n idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0];\n if(!idx) {\n tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]);\n ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]);\n } else if(count[idx] == 1) {\n switch(idx) {\n case 0x1:\n tx = mid_pred(mvx[1], mvx[2], mvx[3]);\n ty = mid_pred(mvy[1], mvy[2], mvy[3]);\n break;\n case 0x2:\n tx = mid_pred(mvx[0], mvx[2], mvx[3]);\n ty = mid_pred(mvy[0], mvy[2], mvy[3]);\n break;\n case 0x4:\n tx = mid_pred(mvx[0], mvx[1], mvx[3]);\n ty = mid_pred(mvy[0], mvy[1], mvy[3]);\n break;\n case 0x8:\n tx = mid_pred(mvx[0], mvx[1], mvx[2]);\n ty = mid_pred(mvy[0], mvy[1], mvy[2]);\n break;\n }\n } else if(count[idx] == 2) {\n int t1 = 0, t2 = 0;\n for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;}\n for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;}\n tx = (mvx[t1] + mvx[t2]) / 2;\n ty = (mvy[t1] + mvy[t2]) / 2;\n } else {\n s->current_picture.motion_val[1][s->block_index[0]][0] = 0;\n s->current_picture.motion_val[1][s->block_index[0]][1] = 0;\n return;\n }\n s->current_picture.motion_val[1][s->block_index[0]][0] = tx;\n s->current_picture.motion_val[1][s->block_index[0]][1] = ty;\n uvmx = (tx + ((tx&3) == 3)) >> 1;\n uvmy = (ty + ((ty&3) == 3)) >> 1;\n if(v->fastuvmc) {\n uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1));\n uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1));\n }\n uvsrc_x = s->mb_x * 8 + (uvmx >> 2);\n uvsrc_y = s->mb_y * 8 + (uvmy >> 2);\n if(v->profile != PROFILE_ADVANCED){\n uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8);\n uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8);\n }else{\n uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1);\n uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1);\n }\n srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;\n srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;\n if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP)\n || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9\n || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){\n ff_emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1,\n uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n ff_emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1,\n uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);\n srcU = s->edge_emu_buffer;\n srcV = s->edge_emu_buffer + 16;\n if(v->rangeredfrm) {\n int i, j;\n uint8_t *src, *src2;\n src = srcU; src2 = srcV;\n for(j = 0; j < 9; j++) {\n for(i = 0; i < 9; i++) {\n src[i] = ((src[i] - 128) >> 1) + 128;\n src2[i] = ((src2[i] - 128) >> 1) + 128;\n }\n src += s->uvlinesize;\n src2 += s->uvlinesize;\n }\n }\n if(v->mv_mode == MV_PMODE_INTENSITY_COMP) {\n int i, j;\n uint8_t *src, *src2;\n src = srcU; src2 = srcV;\n for(j = 0; j < 9; j++) {\n for(i = 0; i < 9; i++) {\n src[i] = v->lutuv[src[i]];\n src2[i] = v->lutuv[src2[i]];\n }\n src += s->uvlinesize;\n src2 += s->uvlinesize;\n }\n }\n }\n uvdxy = ((uvmy & 3) << 2) | (uvmx & 3);\n uvmx = (uvmx&3)<<1;\n uvmy = (uvmy&3)<<1;\n if(!v->rnd){\n dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);\n dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);\n }else{\n dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy);\n dsp->put_no_rnd_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy);\n }\n}']
|
1,157
| 0
|
https://github.com/libav/libav/blob/e3245b2631990fee05183cf12d5c860ef923b8d9/cmdutils.c/#L1037
|
void *grow_array(void *array, int elem_size, int *size, int new_size)
{
if (new_size >= INT_MAX / elem_size) {
av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
exit_program(1);
}
if (*size < new_size) {
uint8_t *tmp = av_realloc(array, new_size*elem_size);
if (!tmp) {
av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
exit_program(1);
}
memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
*size = new_size;
return tmp;
}
return array;
}
|
['static int opt_streamid(OptionsContext *o, const char *opt, const char *arg)\n{\n int idx;\n char *p;\n char idx_str[16];\n av_strlcpy(idx_str, arg, sizeof(idx_str));\n p = strchr(idx_str, \':\');\n if (!p) {\n av_log(NULL, AV_LOG_FATAL,\n "Invalid value \'%s\' for option \'%s\', required syntax is \'index:value\'\\n",\n arg, opt);\n exit_program(1);\n }\n *p++ = \'\\0\';\n idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, INT_MAX);\n o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);\n o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);\n return 0;\n}', 'double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)\n{\n char *tail;\n const char *error;\n double d = av_strtod(numstr, &tail);\n if (*tail)\n error= "Expected number for %s but found: %s\\n";\n else if (d < min || d > max)\n error= "The value for %s was %s which is not within %f - %f\\n";\n else if(type == OPT_INT64 && (int64_t)d != d)\n error= "Expected int64 for %s but found %s\\n";\n else if (type == OPT_INT && (int)d != d)\n error= "Expected int for %s but found %s\\n";\n else\n return d;\n av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);\n exit_program(1);\n return 0;\n}', 'void *grow_array(void *array, int elem_size, int *size, int new_size)\n{\n if (new_size >= INT_MAX / elem_size) {\n av_log(NULL, AV_LOG_ERROR, "Array too big.\\n");\n exit_program(1);\n }\n if (*size < new_size) {\n uint8_t *tmp = av_realloc(array, new_size*elem_size);\n if (!tmp) {\n av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\\n");\n exit_program(1);\n }\n memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);\n *size = new_size;\n return tmp;\n }\n return array;\n}']
|
1,158
| 0
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, j, ret = -1;\n int k;\n BN_CTX *ctx = NULL;\n BIGNUM *A1, *A1_odd, *A3, *check;\n BN_MONT_CTX *mont = NULL;\n if (BN_is_word(a, 2) || BN_is_word(a, 3))\n return 1;\n if (!BN_is_odd(a) || BN_cmp(a, BN_value_one()) <= 0)\n return 0;\n if (checks == BN_prime_checks)\n checks = BN_prime_checks_for_size(BN_num_bits(a));\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(a, primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod == 0)\n return BN_is_word(a, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n goto err;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n A1 = BN_CTX_get(ctx);\n A3 = BN_CTX_get(ctx);\n A1_odd = BN_CTX_get(ctx);\n check = BN_CTX_get(ctx);\n if (check == NULL)\n goto err;\n if (!BN_copy(A1, a) || !BN_sub_word(A1, 1))\n goto err;\n if (!BN_copy(A3, a) || !BN_sub_word(A3, 3))\n goto err;\n k = 1;\n while (!BN_is_bit_set(A1, k))\n k++;\n if (!BN_rshift(A1_odd, A1, k))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, a, ctx))\n goto err;\n for (i = 0; i < checks; i++) {\n if (!BN_priv_rand_range(check, A3) || !BN_add_word(check, 2))\n goto err;\n j = witness(check, a, A1, A1_odd, k, ctx, mont);\n if (j == -1)\n goto err;\n if (j) {\n ret = 0;\n goto err;\n }\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n }\n BN_MONT_CTX_free(mont);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,159
| 0
|
https://github.com/openssl/openssl/blob/9f519addc09b2005fa8c6cde36e3267de02577bb/crypto/init.c/#L391
|
int ossl_init_thread_start(uint64_t opts)
{
struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);
if (locals == NULL)
return 0;
if (opts & OPENSSL_INIT_THREAD_ASYNC) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for async\n");
#endif
locals->async = 1;
}
if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {
#ifdef OPENSSL_INIT_DEBUG
fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "
"marking thread for err_state\n");
#endif
locals->err_state = 1;
}
return 1;
}
|
['int ossl_init_thread_start(uint64_t opts)\n{\n struct thread_local_inits_st *locals = ossl_init_get_thread_local(1);\n if (locals == NULL)\n return 0;\n if (opts & OPENSSL_INIT_THREAD_ASYNC) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for async\\n");\n#endif\n locals->async = 1;\n }\n if (opts & OPENSSL_INIT_THREAD_ERR_STATE) {\n#ifdef OPENSSL_INIT_DEBUG\n fprintf(stderr, "OPENSSL_INIT: ossl_init_thread_start: "\n "marking thread for err_state\\n");\n#endif\n locals->err_state = 1;\n }\n return 1;\n}', 'static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)\n{\n struct thread_local_inits_st *local =\n CRYPTO_THREAD_get_local(&threadstopkey);\n if (local == NULL && alloc) {\n local = OPENSSL_zalloc(sizeof *local);\n CRYPTO_THREAD_set_local(&threadstopkey, local);\n }\n if (!alloc) {\n CRYPTO_THREAD_set_local(&threadstopkey, NULL);\n }\n return local;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}']
|
1,160
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/lhash/lhash.c/#L372
|
static void contract(_LHASH *lh)
{
LHASH_NODE **n, *n1, *np;
np = lh->b[lh->p + lh->pmax - 1];
lh->b[lh->p + lh->pmax - 1] = NULL;
if (lh->p == 0) {
n = (LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)
* lh->pmax));
if (n == NULL) {
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes /= 2;
lh->pmax /= 2;
lh->p = lh->pmax - 1;
lh->b = n;
} else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1 = lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p] = np;
else {
while (n1->next != NULL)
n1 = n1->next;
n1->next = np;
}
}
|
['static void contract(_LHASH *lh)\n{\n LHASH_NODE **n, *n1, *np;\n np = lh->b[lh->p + lh->pmax - 1];\n lh->b[lh->p + lh->pmax - 1] = NULL;\n if (lh->p == 0) {\n n = (LHASH_NODE **)OPENSSL_realloc(lh->b,\n (unsigned int)(sizeof(LHASH_NODE *)\n * lh->pmax));\n if (n == NULL) {\n lh->error++;\n return;\n }\n lh->num_contract_reallocs++;\n lh->num_alloc_nodes /= 2;\n lh->pmax /= 2;\n lh->p = lh->pmax - 1;\n lh->b = n;\n } else\n lh->p--;\n lh->num_nodes--;\n lh->num_contracts++;\n n1 = lh->b[(int)lh->p];\n if (n1 == NULL)\n lh->b[(int)lh->p] = np;\n else {\n while (n1->next != NULL)\n n1 = n1->next;\n n1->next = np;\n }\n}']
|
1,161
| 0
|
https://github.com/libav/libav/blob/187d719760bd130f848194ec4a6bd476341914bb/libavcodec/mss2.c/#L477
|
static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MSS2Context *ctx = avctx->priv_data;
MSS12Context *c = &ctx->c;
AVFrame *frame = data;
GetBitContext gb;
GetByteContext gB;
ArithCoder acoder;
int keyframe, has_wmv9, has_mv, is_rle, is_555, ret;
Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;
int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask);
init_get_bits(&gb, buf, buf_size * 8);
if (keyframe = get_bits1(&gb))
skip_bits(&gb, 7);
has_wmv9 = get_bits1(&gb);
has_mv = keyframe ? 0 : get_bits1(&gb);
is_rle = get_bits1(&gb);
is_555 = is_rle && get_bits1(&gb);
if (c->slice_split > 0)
ctx->split_position = c->slice_split;
else if (c->slice_split < 0) {
if (get_bits1(&gb)) {
if (get_bits1(&gb)) {
if (get_bits1(&gb))
ctx->split_position = get_bits(&gb, 16);
else
ctx->split_position = get_bits(&gb, 12);
} else
ctx->split_position = get_bits(&gb, 8) << 4;
} else {
if (keyframe)
ctx->split_position = avctx->height / 2;
}
} else
ctx->split_position = avctx->height;
if (c->slice_split && (ctx->split_position < 1 - is_555 ||
ctx->split_position > avctx->height - 1))
return AVERROR_INVALIDDATA;
align_get_bits(&gb);
buf += get_bits_count(&gb) >> 3;
buf_size -= get_bits_count(&gb) >> 3;
if (buf_size < 1)
return AVERROR_INVALIDDATA;
if (is_555 && (has_wmv9 || has_mv || c->slice_split && ctx->split_position))
return AVERROR_INVALIDDATA;
avctx->pix_fmt = is_555 ? AV_PIX_FMT_RGB555 : AV_PIX_FMT_RGB24;
if (ctx->last_pic->format != avctx->pix_fmt)
av_frame_unref(ctx->last_pic);
if (has_wmv9) {
bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
arith2_init(&acoder, &gB);
implicit_rect = !arith2_get_bit(&acoder);
while (arith2_get_bit(&acoder)) {
if (used_rects == MAX_WMV9_RECTANGLES)
return AVERROR_INVALIDDATA;
r = &wmv9rects[used_rects];
if (!used_rects)
r->x = arith2_get_number(&acoder, avctx->width);
else
r->x = arith2_get_number(&acoder, avctx->width -
wmv9rects[used_rects - 1].x) +
wmv9rects[used_rects - 1].x;
r->y = arith2_get_number(&acoder, avctx->height);
r->w = arith2_get_number(&acoder, avctx->width - r->x) + 1;
r->h = arith2_get_number(&acoder, avctx->height - r->y) + 1;
used_rects++;
}
if (implicit_rect && used_rects) {
av_log(avctx, AV_LOG_ERROR, "implicit_rect && used_rects > 0\n");
return AVERROR_INVALIDDATA;
}
if (implicit_rect) {
wmv9rects[0].x = 0;
wmv9rects[0].y = 0;
wmv9rects[0].w = avctx->width;
wmv9rects[0].h = avctx->height;
used_rects = 1;
}
for (i = 0; i < used_rects; i++) {
if (!implicit_rect && arith2_get_bit(&acoder)) {
av_log(avctx, AV_LOG_ERROR, "Unexpected grandchildren\n");
return AVERROR_INVALIDDATA;
}
if (!i) {
wmv9_mask = arith2_get_bit(&acoder) - 1;
if (!wmv9_mask)
wmv9_mask = arith2_get_number(&acoder, 256);
}
wmv9rects[i].coded = arith2_get_number(&acoder, 2);
}
buf += arith2_get_consumed_bytes(&acoder);
buf_size -= arith2_get_consumed_bytes(&acoder);
if (buf_size < 1)
return AVERROR_INVALIDDATA;
}
c->mvX = c->mvY = 0;
if (keyframe && !is_555) {
if ((i = decode_pal_v2(c, buf, buf_size)) < 0)
return AVERROR_INVALIDDATA;
buf += i;
buf_size -= i;
} else if (has_mv) {
buf += 4;
buf_size -= 4;
if (buf_size < 1)
return AVERROR_INVALIDDATA;
c->mvX = AV_RB16(buf - 4) - avctx->width;
c->mvY = AV_RB16(buf - 2) - avctx->height;
}
if (c->mvX < 0 || c->mvY < 0) {
FFSWAP(uint8_t *, c->pal_pic, c->last_pal_pic);
if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
if (ctx->last_pic->data[0]) {
av_assert0(frame->linesize[0] == ctx->last_pic->linesize[0]);
c->last_rgb_pic = ctx->last_pic->data[0] +
ctx->last_pic->linesize[0] * (avctx->height - 1);
} else {
av_log(avctx, AV_LOG_ERROR, "Missing keyframe\n");
return AVERROR_INVALIDDATA;
}
} else {
if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret;
}
if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0)
return ret;
c->last_rgb_pic = NULL;
}
c->rgb_pic = frame->data[0] +
frame->linesize[0] * (avctx->height - 1);
c->rgb_stride = -frame->linesize[0];
frame->key_frame = keyframe;
frame->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
if (is_555) {
bytestream2_init(&gB, buf, buf_size);
if (decode_555(&gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1,
keyframe, avctx->width, avctx->height))
return AVERROR_INVALIDDATA;
buf_size -= bytestream2_tell(&gB);
} else {
if (keyframe) {
c->corrupted = 0;
ff_mss12_slicecontext_reset(&ctx->sc[0]);
if (c->slice_split)
ff_mss12_slicecontext_reset(&ctx->sc[1]);
}
if (is_rle) {
init_get_bits(&gb, buf, buf_size * 8);
if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,
c->rgb_pic, c->rgb_stride, c->pal, keyframe,
ctx->split_position, 0,
avctx->width, avctx->height))
return ret;
align_get_bits(&gb);
if (c->slice_split)
if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,
c->rgb_pic, c->rgb_stride, c->pal, keyframe,
ctx->split_position, 1,
avctx->width, avctx->height))
return ret;
align_get_bits(&gb);
buf += get_bits_count(&gb) >> 3;
buf_size -= get_bits_count(&gb) >> 3;
} else if (!implicit_rect || wmv9_mask != -1) {
if (c->corrupted)
return AVERROR_INVALIDDATA;
bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
arith2_init(&acoder, &gB);
c->keyframe = keyframe;
if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, 0,
avctx->width,
ctx->split_position))
return AVERROR_INVALIDDATA;
buf += arith2_get_consumed_bytes(&acoder);
buf_size -= arith2_get_consumed_bytes(&acoder);
if (c->slice_split) {
if (buf_size < 1)
return AVERROR_INVALIDDATA;
bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
arith2_init(&acoder, &gB);
if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0,
ctx->split_position,
avctx->width,
avctx->height - ctx->split_position))
return AVERROR_INVALIDDATA;
buf += arith2_get_consumed_bytes(&acoder);
buf_size -= arith2_get_consumed_bytes(&acoder);
}
} else
memset(c->pal_pic, 0, c->pal_stride * avctx->height);
}
if (has_wmv9) {
for (i = 0; i < used_rects; i++) {
int x = wmv9rects[i].x;
int y = wmv9rects[i].y;
int w = wmv9rects[i].w;
int h = wmv9rects[i].h;
if (wmv9rects[i].coded) {
int WMV9codedFrameSize;
if (buf_size < 4 || !(WMV9codedFrameSize = AV_RL24(buf)))
return AVERROR_INVALIDDATA;
if (ret = decode_wmv9(avctx, buf + 3, buf_size - 3,
x, y, w, h, wmv9_mask))
return ret;
buf += WMV9codedFrameSize + 3;
buf_size -= WMV9codedFrameSize + 3;
} else {
uint8_t *dst = c->rgb_pic + y * c->rgb_stride + x * 3;
if (wmv9_mask != -1) {
ctx->dsp.mss2_gray_fill_masked(dst, c->rgb_stride,
wmv9_mask,
c->pal_pic + y * c->pal_stride + x,
c->pal_stride,
w, h);
} else {
do {
memset(dst, 0x80, w * 3);
dst += c->rgb_stride;
} while (--h);
}
}
}
}
if (buf_size)
av_log(avctx, AV_LOG_WARNING, "buffer not fully consumed\n");
if (c->mvX < 0 || c->mvY < 0) {
av_frame_unref(ctx->last_pic);
ret = av_frame_ref(ctx->last_pic, frame);
if (ret < 0)
return ret;
}
*got_frame = 1;
return avpkt->size;
}
|
['static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MSS2Context *ctx = avctx->priv_data;\n MSS12Context *c = &ctx->c;\n AVFrame *frame = data;\n GetBitContext gb;\n GetByteContext gB;\n ArithCoder acoder;\n int keyframe, has_wmv9, has_mv, is_rle, is_555, ret;\n Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;\n int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask);\n init_get_bits(&gb, buf, buf_size * 8);\n if (keyframe = get_bits1(&gb))\n skip_bits(&gb, 7);\n has_wmv9 = get_bits1(&gb);\n has_mv = keyframe ? 0 : get_bits1(&gb);\n is_rle = get_bits1(&gb);\n is_555 = is_rle && get_bits1(&gb);\n if (c->slice_split > 0)\n ctx->split_position = c->slice_split;\n else if (c->slice_split < 0) {\n if (get_bits1(&gb)) {\n if (get_bits1(&gb)) {\n if (get_bits1(&gb))\n ctx->split_position = get_bits(&gb, 16);\n else\n ctx->split_position = get_bits(&gb, 12);\n } else\n ctx->split_position = get_bits(&gb, 8) << 4;\n } else {\n if (keyframe)\n ctx->split_position = avctx->height / 2;\n }\n } else\n ctx->split_position = avctx->height;\n if (c->slice_split && (ctx->split_position < 1 - is_555 ||\n ctx->split_position > avctx->height - 1))\n return AVERROR_INVALIDDATA;\n align_get_bits(&gb);\n buf += get_bits_count(&gb) >> 3;\n buf_size -= get_bits_count(&gb) >> 3;\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n if (is_555 && (has_wmv9 || has_mv || c->slice_split && ctx->split_position))\n return AVERROR_INVALIDDATA;\n avctx->pix_fmt = is_555 ? AV_PIX_FMT_RGB555 : AV_PIX_FMT_RGB24;\n if (ctx->last_pic->format != avctx->pix_fmt)\n av_frame_unref(ctx->last_pic);\n if (has_wmv9) {\n bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);\n arith2_init(&acoder, &gB);\n implicit_rect = !arith2_get_bit(&acoder);\n while (arith2_get_bit(&acoder)) {\n if (used_rects == MAX_WMV9_RECTANGLES)\n return AVERROR_INVALIDDATA;\n r = &wmv9rects[used_rects];\n if (!used_rects)\n r->x = arith2_get_number(&acoder, avctx->width);\n else\n r->x = arith2_get_number(&acoder, avctx->width -\n wmv9rects[used_rects - 1].x) +\n wmv9rects[used_rects - 1].x;\n r->y = arith2_get_number(&acoder, avctx->height);\n r->w = arith2_get_number(&acoder, avctx->width - r->x) + 1;\n r->h = arith2_get_number(&acoder, avctx->height - r->y) + 1;\n used_rects++;\n }\n if (implicit_rect && used_rects) {\n av_log(avctx, AV_LOG_ERROR, "implicit_rect && used_rects > 0\\n");\n return AVERROR_INVALIDDATA;\n }\n if (implicit_rect) {\n wmv9rects[0].x = 0;\n wmv9rects[0].y = 0;\n wmv9rects[0].w = avctx->width;\n wmv9rects[0].h = avctx->height;\n used_rects = 1;\n }\n for (i = 0; i < used_rects; i++) {\n if (!implicit_rect && arith2_get_bit(&acoder)) {\n av_log(avctx, AV_LOG_ERROR, "Unexpected grandchildren\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!i) {\n wmv9_mask = arith2_get_bit(&acoder) - 1;\n if (!wmv9_mask)\n wmv9_mask = arith2_get_number(&acoder, 256);\n }\n wmv9rects[i].coded = arith2_get_number(&acoder, 2);\n }\n buf += arith2_get_consumed_bytes(&acoder);\n buf_size -= arith2_get_consumed_bytes(&acoder);\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n }\n c->mvX = c->mvY = 0;\n if (keyframe && !is_555) {\n if ((i = decode_pal_v2(c, buf, buf_size)) < 0)\n return AVERROR_INVALIDDATA;\n buf += i;\n buf_size -= i;\n } else if (has_mv) {\n buf += 4;\n buf_size -= 4;\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n c->mvX = AV_RB16(buf - 4) - avctx->width;\n c->mvY = AV_RB16(buf - 2) - avctx->height;\n }\n if (c->mvX < 0 || c->mvY < 0) {\n FFSWAP(uint8_t *, c->pal_pic, c->last_pal_pic);\n if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n if (ctx->last_pic->data[0]) {\n av_assert0(frame->linesize[0] == ctx->last_pic->linesize[0]);\n c->last_rgb_pic = ctx->last_pic->data[0] +\n ctx->last_pic->linesize[0] * (avctx->height - 1);\n } else {\n av_log(avctx, AV_LOG_ERROR, "Missing keyframe\\n");\n return AVERROR_INVALIDDATA;\n }\n } else {\n if ((ret = ff_reget_buffer(avctx, ctx->last_pic)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\\n");\n return ret;\n }\n if ((ret = av_frame_ref(frame, ctx->last_pic)) < 0)\n return ret;\n c->last_rgb_pic = NULL;\n }\n c->rgb_pic = frame->data[0] +\n frame->linesize[0] * (avctx->height - 1);\n c->rgb_stride = -frame->linesize[0];\n frame->key_frame = keyframe;\n frame->pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;\n if (is_555) {\n bytestream2_init(&gB, buf, buf_size);\n if (decode_555(&gB, (uint16_t *)c->rgb_pic, c->rgb_stride >> 1,\n keyframe, avctx->width, avctx->height))\n return AVERROR_INVALIDDATA;\n buf_size -= bytestream2_tell(&gB);\n } else {\n if (keyframe) {\n c->corrupted = 0;\n ff_mss12_slicecontext_reset(&ctx->sc[0]);\n if (c->slice_split)\n ff_mss12_slicecontext_reset(&ctx->sc[1]);\n }\n if (is_rle) {\n init_get_bits(&gb, buf, buf_size * 8);\n if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,\n c->rgb_pic, c->rgb_stride, c->pal, keyframe,\n ctx->split_position, 0,\n avctx->width, avctx->height))\n return ret;\n align_get_bits(&gb);\n if (c->slice_split)\n if (ret = decode_rle(&gb, c->pal_pic, c->pal_stride,\n c->rgb_pic, c->rgb_stride, c->pal, keyframe,\n ctx->split_position, 1,\n avctx->width, avctx->height))\n return ret;\n align_get_bits(&gb);\n buf += get_bits_count(&gb) >> 3;\n buf_size -= get_bits_count(&gb) >> 3;\n } else if (!implicit_rect || wmv9_mask != -1) {\n if (c->corrupted)\n return AVERROR_INVALIDDATA;\n bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);\n arith2_init(&acoder, &gB);\n c->keyframe = keyframe;\n if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, 0,\n avctx->width,\n ctx->split_position))\n return AVERROR_INVALIDDATA;\n buf += arith2_get_consumed_bytes(&acoder);\n buf_size -= arith2_get_consumed_bytes(&acoder);\n if (c->slice_split) {\n if (buf_size < 1)\n return AVERROR_INVALIDDATA;\n bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);\n arith2_init(&acoder, &gB);\n if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0,\n ctx->split_position,\n avctx->width,\n avctx->height - ctx->split_position))\n return AVERROR_INVALIDDATA;\n buf += arith2_get_consumed_bytes(&acoder);\n buf_size -= arith2_get_consumed_bytes(&acoder);\n }\n } else\n memset(c->pal_pic, 0, c->pal_stride * avctx->height);\n }\n if (has_wmv9) {\n for (i = 0; i < used_rects; i++) {\n int x = wmv9rects[i].x;\n int y = wmv9rects[i].y;\n int w = wmv9rects[i].w;\n int h = wmv9rects[i].h;\n if (wmv9rects[i].coded) {\n int WMV9codedFrameSize;\n if (buf_size < 4 || !(WMV9codedFrameSize = AV_RL24(buf)))\n return AVERROR_INVALIDDATA;\n if (ret = decode_wmv9(avctx, buf + 3, buf_size - 3,\n x, y, w, h, wmv9_mask))\n return ret;\n buf += WMV9codedFrameSize + 3;\n buf_size -= WMV9codedFrameSize + 3;\n } else {\n uint8_t *dst = c->rgb_pic + y * c->rgb_stride + x * 3;\n if (wmv9_mask != -1) {\n ctx->dsp.mss2_gray_fill_masked(dst, c->rgb_stride,\n wmv9_mask,\n c->pal_pic + y * c->pal_stride + x,\n c->pal_stride,\n w, h);\n } else {\n do {\n memset(dst, 0x80, w * 3);\n dst += c->rgb_stride;\n } while (--h);\n }\n }\n }\n }\n if (buf_size)\n av_log(avctx, AV_LOG_WARNING, "buffer not fully consumed\\n");\n if (c->mvX < 0 || c->mvY < 0) {\n av_frame_unref(ctx->last_pic);\n ret = av_frame_ref(ctx->last_pic, frame);\n if (ret < 0)\n return ret;\n }\n *got_frame = 1;\n return avpkt->size;\n}']
|
1,162
| 0
|
https://github.com/libav/libav/blob/b42c483f076e4b24fdeada59e138e421326c45ec/libavformat/utils.c/#L2469
|
void av_close_input_stream(AVFormatContext *s)
{
int i;
AVStream *st;
if (s->iformat->read_close)
s->iformat->read_close(s);
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_metadata_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec);
#if FF_API_OLD_METADATA
av_free(st->filename);
#endif
av_free(st->priv_data);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
#if FF_API_OLD_METADATA
av_freep(&s->programs[i]->provider_name);
av_freep(&s->programs[i]->name);
#endif
av_metadata_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
flush_packet_queue(s);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
#if FF_API_OLD_METADATA
av_free(s->chapters[s->nb_chapters]->title);
#endif
av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_metadata_free(&s->metadata);
av_free(s);
}
|
['static void opt_input_file(const char *filename)\n{\n AVFormatContext *ic;\n AVFormatParameters params, *ap = ¶ms;\n AVInputFormat *file_iformat = NULL;\n int err, i, ret, rfps, rfps_base;\n int64_t timestamp;\n if (last_asked_format) {\n if (!(file_iformat = av_find_input_format(last_asked_format))) {\n fprintf(stderr, "Unknown input format: \'%s\'\\n", last_asked_format);\n ffmpeg_exit(1);\n }\n last_asked_format = NULL;\n }\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n using_stdin |= !strncmp(filename, "pipe:", 5) ||\n !strcmp(filename, "/dev/stdin");\n ic = avformat_alloc_context();\n if (!ic) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n memset(ap, 0, sizeof(*ap));\n ap->prealloced_context = 1;\n ap->sample_rate = audio_sample_rate;\n ap->channels = audio_channels;\n ap->time_base.den = frame_rate.num;\n ap->time_base.num = frame_rate.den;\n ap->width = frame_width;\n ap->height = frame_height;\n ap->pix_fmt = frame_pix_fmt;\n ap->channel = video_channel;\n ap->standard = video_standard;\n set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM);\n ic->video_codec_id =\n find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0,\n avcodec_opts[AVMEDIA_TYPE_VIDEO ]->strict_std_compliance);\n ic->audio_codec_id =\n find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0,\n avcodec_opts[AVMEDIA_TYPE_AUDIO ]->strict_std_compliance);\n ic->subtitle_codec_id=\n find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0,\n avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);\n ic->flags |= AVFMT_FLAG_NONBLOCK;\n if(pgmyuv_compatibility_hack)\n ic->video_codec_id= CODEC_ID_PGMYUV;\n err = av_open_input_file(&ic, filename, file_iformat, 0, ap);\n if (err < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n if(opt_programid) {\n int i, j;\n int found=0;\n for(i=0; i<ic->nb_streams; i++){\n ic->streams[i]->discard= AVDISCARD_ALL;\n }\n for(i=0; i<ic->nb_programs; i++){\n AVProgram *p= ic->programs[i];\n if(p->id != opt_programid){\n p->discard = AVDISCARD_ALL;\n }else{\n found=1;\n for(j=0; j<p->nb_stream_indexes; j++){\n ic->streams[p->stream_index[j]]->discard= AVDISCARD_DEFAULT;\n }\n }\n }\n if(!found){\n fprintf(stderr, "Specified program id not found\\n");\n ffmpeg_exit(1);\n }\n opt_programid=0;\n }\n ic->loop_input = loop_input;\n ret = av_find_stream_info(ic);\n if (ret < 0 && verbose >= 0) {\n fprintf(stderr, "%s: could not find codec parameters\\n", filename);\n av_close_input_file(ic);\n ffmpeg_exit(1);\n }\n timestamp = start_time;\n if (ic->start_time != AV_NOPTS_VALUE)\n timestamp += ic->start_time;\n if (start_time != 0) {\n ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);\n if (ret < 0) {\n fprintf(stderr, "%s: could not seek to position %0.3f\\n",\n filename, (double)timestamp / AV_TIME_BASE);\n }\n start_time = 0;\n }\n for(i=0;i<ic->nb_streams;i++) {\n AVStream *st = ic->streams[i];\n AVCodecContext *dec = st->codec;\n avcodec_thread_init(dec, thread_count);\n switch (dec->codec_type) {\n case AVMEDIA_TYPE_AUDIO:\n set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM);\n channel_layout = dec->channel_layout;\n audio_channels = dec->channels;\n audio_sample_rate = dec->sample_rate;\n audio_sample_fmt = dec->sample_fmt;\n input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(audio_codec_name);\n if(audio_disable)\n st->discard= AVDISCARD_ALL;\n break;\n case AVMEDIA_TYPE_VIDEO:\n set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM);\n frame_height = dec->height;\n frame_width = dec->width;\n if(ic->streams[i]->sample_aspect_ratio.num)\n frame_aspect_ratio=av_q2d(ic->streams[i]->sample_aspect_ratio);\n else\n frame_aspect_ratio=av_q2d(dec->sample_aspect_ratio);\n frame_aspect_ratio *= (float) dec->width / dec->height;\n frame_pix_fmt = dec->pix_fmt;\n rfps = ic->streams[i]->r_frame_rate.num;\n rfps_base = ic->streams[i]->r_frame_rate.den;\n if (dec->lowres) {\n dec->flags |= CODEC_FLAG_EMU_EDGE;\n frame_height >>= dec->lowres;\n frame_width >>= dec->lowres;\n }\n if(me_threshold)\n dec->debug |= FF_DEBUG_MV;\n if (dec->time_base.den != rfps*dec->ticks_per_frame || dec->time_base.num != rfps_base) {\n if (verbose >= 0)\n fprintf(stderr,"\\nSeems stream %d codec frame rate differs from container frame rate: %2.2f (%d/%d) -> %2.2f (%d/%d)\\n",\n i, (float)dec->time_base.den / dec->time_base.num, dec->time_base.den, dec->time_base.num,\n (float)rfps / rfps_base, rfps, rfps_base);\n }\n frame_rate.num = rfps;\n frame_rate.den = rfps_base;\n input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(video_codec_name);\n if(video_disable)\n st->discard= AVDISCARD_ALL;\n else if(video_discard)\n st->discard= video_discard;\n break;\n case AVMEDIA_TYPE_DATA:\n break;\n case AVMEDIA_TYPE_SUBTITLE:\n input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(subtitle_codec_name);\n if(subtitle_disable)\n st->discard = AVDISCARD_ALL;\n break;\n case AVMEDIA_TYPE_ATTACHMENT:\n case AVMEDIA_TYPE_UNKNOWN:\n nb_icodecs++;\n break;\n default:\n abort();\n }\n }\n input_files[nb_input_files] = ic;\n input_files_ts_offset[nb_input_files] = input_ts_offset - (copy_ts ? 0 : timestamp);\n if (verbose >= 0)\n dump_format(ic, nb_input_files, filename, 0);\n nb_input_files++;\n video_channel = 0;\n av_freep(&video_codec_name);\n av_freep(&audio_codec_name);\n av_freep(&subtitle_codec_name);\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;\n av_close_input_stream(s);\n if (pb)\n url_fclose(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_metadata_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec);\n#if FF_API_OLD_METADATA\n av_free(st->filename);\n#endif\n av_free(st->priv_data);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n#if FF_API_OLD_METADATA\n av_freep(&s->programs[i]->provider_name);\n av_freep(&s->programs[i]->name);\n#endif\n av_metadata_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n flush_packet_queue(s);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n#if FF_API_OLD_METADATA\n av_free(s->chapters[s->nb_chapters]->title);\n#endif\n av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_metadata_free(&s->metadata);\n av_free(s);\n}']
|
1,163
| 0
|
https://github.com/openssl/openssl/blob/8fa6a40be2935ca109a28cc43d28cd27051ada01/crypto/lhash/lhash.c/#L365
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['void CRYPTO_dbg_realloc(void *addr1, void *addr2, int num,\n\tconst char *file, int line, int before_p)\n\t{\n\tMEM m,*mp;\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \\"%s\\", line = %d, before_p = %d)\\n",\n\t\taddr1, addr2, num, file, line, before_p);\n#endif\n\tswitch(before_p)\n\t\t{\n\tcase 0:\n\t\tbreak;\n\tcase 1:\n\t\tif (addr2 == NULL)\n\t\t\tbreak;\n\t\tif (addr1 == NULL)\n\t\t\t{\n\t\t\tCRYPTO_dbg_malloc(addr2, num, file, line, 128 | before_p);\n\t\t\tbreak;\n\t\t\t}\n\t\tif (is_MemCheck_on())\n\t\t\t{\n\t\t\tMemCheck_off();\n\t\t\tm.addr=addr1;\n\t\t\tmp=(MEM *)lh_delete(mh,(char *)&m);\n\t\t\tif (mp != NULL)\n\t\t\t\t{\n#ifdef LEVITTE_DEBUG_MEM\n\t\t\t\tfprintf(stderr, "LEVITTE_DEBUG_MEM: [%5d] * 0x%p (%d) -> 0x%p (%d)\\n",\n\t\t\t\t\tmp->order,\n\t\t\t\t\tmp->addr, mp->num,\n\t\t\t\t\taddr2, num);\n#endif\n\t\t\t\tmp->addr=addr2;\n\t\t\t\tmp->num=num;\n\t\t\t\tlh_insert(mh,(char *)mp);\n\t\t\t\t}\n\t\t\tMemCheck_on();\n\t\t\t}\n\t\tbreak;\n\t\t}\n\treturn;\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,164
| 0
|
https://github.com/libav/libav/blob/63380b5e54f64abdde4a8b6bce0d60f1fa4a22a1/libavformat/oggparsevorbis.c/#L154
|
static unsigned int
fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,
uint8_t **buf)
{
int i,offset, len;
unsigned char *ptr;
len = priv->len[0] + priv->len[1] + priv->len[2];
ptr = *buf = av_mallocz(len + len/255 + 64);
ptr[0] = 2;
offset = 1;
offset += av_xiphlacing(&ptr[offset], priv->len[0]);
offset += av_xiphlacing(&ptr[offset], priv->len[1]);
for (i = 0; i < 3; i++) {
memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
offset += priv->len[i];
}
*buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);
return offset;
}
|
['static unsigned int\nfixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,\n uint8_t **buf)\n{\n int i,offset, len;\n unsigned char *ptr;\n len = priv->len[0] + priv->len[1] + priv->len[2];\n ptr = *buf = av_mallocz(len + len/255 + 64);\n ptr[0] = 2;\n offset = 1;\n offset += av_xiphlacing(&ptr[offset], priv->len[0]);\n offset += av_xiphlacing(&ptr[offset], priv->len[1]);\n for (i = 0; i < 3; i++) {\n memcpy(&ptr[offset], priv->packet[i], priv->len[i]);\n offset += priv->len[i];\n }\n *buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);\n return offset;\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,165
| 0
|
https://github.com/openssl/openssl/blob/79a578b90244b890c8a6a8fc26c03943da71c054/crypto/x509v3/v3_ncons.c/#L138
|
static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
{
int i;
CONF_VALUE tval, *val;
STACK_OF(GENERAL_SUBTREE) **ptree = NULL;
NAME_CONSTRAINTS *ncons = NULL;
GENERAL_SUBTREE *sub = NULL;
ncons = NAME_CONSTRAINTS_new();
if (!ncons)
goto memerr;
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {
val = sk_CONF_VALUE_value(nval, i);
if (!strncmp(val->name, "permitted", 9) && val->name[9]) {
ptree = &ncons->permittedSubtrees;
tval.name = val->name + 10;
} else if (!strncmp(val->name, "excluded", 8) && val->name[8]) {
ptree = &ncons->excludedSubtrees;
tval.name = val->name + 9;
} else {
X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, X509V3_R_INVALID_SYNTAX);
goto err;
}
tval.value = val->value;
sub = GENERAL_SUBTREE_new();
if (!v2i_GENERAL_NAME_ex(sub->base, method, ctx, &tval, 1))
goto err;
if (!*ptree)
*ptree = sk_GENERAL_SUBTREE_new_null();
if (!*ptree || !sk_GENERAL_SUBTREE_push(*ptree, sub))
goto memerr;
sub = NULL;
}
return ncons;
memerr:
X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, ERR_R_MALLOC_FAILURE);
err:
if (ncons)
NAME_CONSTRAINTS_free(ncons);
if (sub)
GENERAL_SUBTREE_free(sub);
return NULL;
}
|
['static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,\n X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)\n{\n int i;\n CONF_VALUE tval, *val;\n STACK_OF(GENERAL_SUBTREE) **ptree = NULL;\n NAME_CONSTRAINTS *ncons = NULL;\n GENERAL_SUBTREE *sub = NULL;\n ncons = NAME_CONSTRAINTS_new();\n if (!ncons)\n goto memerr;\n for (i = 0; i < sk_CONF_VALUE_num(nval); i++) {\n val = sk_CONF_VALUE_value(nval, i);\n if (!strncmp(val->name, "permitted", 9) && val->name[9]) {\n ptree = &ncons->permittedSubtrees;\n tval.name = val->name + 10;\n } else if (!strncmp(val->name, "excluded", 8) && val->name[8]) {\n ptree = &ncons->excludedSubtrees;\n tval.name = val->name + 9;\n } else {\n X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, X509V3_R_INVALID_SYNTAX);\n goto err;\n }\n tval.value = val->value;\n sub = GENERAL_SUBTREE_new();\n if (!v2i_GENERAL_NAME_ex(sub->base, method, ctx, &tval, 1))\n goto err;\n if (!*ptree)\n *ptree = sk_GENERAL_SUBTREE_new_null();\n if (!*ptree || !sk_GENERAL_SUBTREE_push(*ptree, sub))\n goto memerr;\n sub = NULL;\n }\n return ncons;\n memerr:\n X509V3err(X509V3_F_V2I_NAME_CONSTRAINTS, ERR_R_MALLOC_FAILURE);\n err:\n if (ncons)\n NAME_CONSTRAINTS_free(ncons);\n if (sub)\n GENERAL_SUBTREE_free(sub);\n return NULL;\n}', 'IMPLEMENT_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS)', 'ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)\n{\n ASN1_VALUE *ret = NULL;\n if (ASN1_item_ex_new(&ret, it) > 0)\n return ret;\n return NULL;\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}', 'IMPLEMENT_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE)']
|
1,166
| 0
|
https://github.com/libav/libav/blob/313b52fbfff47ed934cdeccaebda9b3406466575/libavcodec/ffv1.c/#L288
|
static inline int get_context(PlaneContext *p, int_fast16_t *src, int_fast16_t *last, int_fast16_t *last2){
const int LT= last[-1];
const int T= last[ 0];
const int RT= last[ 1];
const int L = src[-1];
if(p->quant_table[3][127]){
const int TT= last2[0];
const int LL= src[-2];
return p->quant_table[0][(L-LT) & 0xFF] + p->quant_table[1][(LT-T) & 0xFF] + p->quant_table[2][(T-RT) & 0xFF]
+p->quant_table[3][(LL-L) & 0xFF] + p->quant_table[4][(TT-T) & 0xFF];
}else
return p->quant_table[0][(L-LT) & 0xFF] + p->quant_table[1][(LT-T) & 0xFF] + p->quant_table[2][(T-RT) & 0xFF];
}
|
['static int encode_slice(AVCodecContext *c, void *arg){\n FFV1Context *fs= *(void**)arg;\n FFV1Context *f= fs->avctx->priv_data;\n int width = fs->slice_width;\n int height= fs->slice_height;\n int x= fs->slice_x;\n int y= fs->slice_y;\n AVFrame * const p= &f->picture;\n if(f->colorspace==0){\n const int chroma_width = -((-width )>>f->chroma_h_shift);\n const int chroma_height= -((-height)>>f->chroma_v_shift);\n const int cx= x>>f->chroma_h_shift;\n const int cy= y>>f->chroma_v_shift;\n encode_plane(fs, p->data[0] + x + y*p->linesize[0], width, height, p->linesize[0], 0);\n encode_plane(fs, p->data[1] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);\n encode_plane(fs, p->data[2] + cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);\n }else{\n encode_rgb_frame(fs, (uint32_t*)(p->data[0]) + x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4);\n }\n emms_c();\n return 0;\n}', 'static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){\n int x, y, p, i;\n const int ring_size= s->avctx->context_model ? 3 : 2;\n int_fast16_t *sample[3][3];\n s->run_index=0;\n memset(s->sample_buffer, 0, ring_size*3*(w+6)*sizeof(*s->sample_buffer));\n for(y=0; y<h; y++){\n for(i=0; i<ring_size; i++)\n for(p=0; p<3; p++)\n sample[p][i]= s->sample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3;\n for(x=0; x<w; x++){\n int v= src[x + stride*y];\n int b= v&0xFF;\n int g= (v>>8)&0xFF;\n int r= (v>>16)&0xFF;\n b -= g;\n r -= g;\n g += (b + r)>>2;\n b += 0x100;\n r += 0x100;\n sample[0][0][x]= g;\n sample[1][0][x]= b;\n sample[2][0][x]= r;\n }\n for(p=0; p<3; p++){\n sample[p][0][-1]= sample[p][1][0 ];\n sample[p][1][ w]= sample[p][1][w-1];\n encode_line(s, w, sample[p], FFMIN(p, 1), 9);\n }\n }\n}', 'static av_always_inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){\n PlaneContext * const p= &s->plane[plane_index];\n RangeCoder * const c= &s->c;\n int x;\n int run_index= s->run_index;\n int run_count=0;\n int run_mode=0;\n if(s->ac){\n if(c->bytestream_end - c->bytestream < w*20){\n av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\\n");\n return -1;\n }\n }else{\n if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < w*4){\n av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\\n");\n return -1;\n }\n }\n for(x=0; x<w; x++){\n int diff, context;\n context= get_context(p, sample[0]+x, sample[1]+x, sample[2]+x);\n diff= sample[0][x] - predict(sample[0]+x, sample[1]+x);\n if(context < 0){\n context = -context;\n diff= -diff;\n }\n diff= fold(diff, bits);\n if(s->ac){\n put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat);\n }else{\n if(context == 0) run_mode=1;\n if(run_mode){\n if(diff){\n while(run_count >= 1<<ff_log2_run[run_index]){\n run_count -= 1<<ff_log2_run[run_index];\n run_index++;\n put_bits(&s->pb, 1, 1);\n }\n put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count);\n if(run_index) run_index--;\n run_count=0;\n run_mode=0;\n if(diff>0) diff--;\n }else{\n run_count++;\n }\n }\n if(run_mode == 0)\n put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits);\n }\n }\n if(run_mode){\n while(run_count >= 1<<ff_log2_run[run_index]){\n run_count -= 1<<ff_log2_run[run_index];\n run_index++;\n put_bits(&s->pb, 1, 1);\n }\n if(run_count)\n put_bits(&s->pb, 1, 1);\n }\n s->run_index= run_index;\n return 0;\n}', 'static inline int get_context(PlaneContext *p, int_fast16_t *src, int_fast16_t *last, int_fast16_t *last2){\n const int LT= last[-1];\n const int T= last[ 0];\n const int RT= last[ 1];\n const int L = src[-1];\n if(p->quant_table[3][127]){\n const int TT= last2[0];\n const int LL= src[-2];\n return p->quant_table[0][(L-LT) & 0xFF] + p->quant_table[1][(LT-T) & 0xFF] + p->quant_table[2][(T-RT) & 0xFF]\n +p->quant_table[3][(LL-L) & 0xFF] + p->quant_table[4][(TT-T) & 0xFF];\n }else\n return p->quant_table[0][(L-LT) & 0xFF] + p->quant_table[1][(LT-T) & 0xFF] + p->quant_table[2][(T-RT) & 0xFF];\n}']
|
1,167
| 0
|
https://github.com/openssl/openssl/blob/43a0449fe6ce18b750803be8a115a412a7235496/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)\n{\n BIGNUM *t;\n int i;\n if ((nbits < 1024) || (nbits & 0xff))\n return 0;\n nbits >>= 1;\n if (!BN_rand(Xp, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n for (i = 0; i < 1000; i++) {\n if (!BN_rand(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto err;\n BN_sub(t, Xp, Xq);\n if (BN_num_bits(t) > (nbits - 100))\n break;\n }\n BN_CTX_end(ctx);\n if (i < 1000)\n return 1;\n return 0;\n err:\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(0, rnd, bits, top, bottom);\n}', 'static int bnrand(int testing, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n if (testing) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,168
| 0
|
https://github.com/libav/libav/blob/4f0b80599a534dcca57be3184b89b98f82bf2a2c/ffmpeg.c/#L3692
|
static void opt_output_file(const char *filename)
{
AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle;
int input_has_video, input_has_audio, input_has_subtitle;
AVFormatParameters params, *ap = ¶ms;
AVOutputFormat *file_oformat;
if (!strcmp(filename, "-"))
filename = "pipe:";
oc = avformat_alloc_context();
if (!oc) {
print_error(filename, AVERROR(ENOMEM));
ffmpeg_exit(1);
}
if (last_asked_format) {
file_oformat = av_guess_format(last_asked_format, NULL, NULL);
if (!file_oformat) {
fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
ffmpeg_exit(1);
}
last_asked_format = NULL;
} else {
file_oformat = av_guess_format(NULL, filename, NULL);
if (!file_oformat) {
fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
filename);
ffmpeg_exit(1);
}
}
oc->oformat = file_oformat;
av_strlcpy(oc->filename, filename, sizeof(oc->filename));
if (!strcmp(file_oformat->name, "ffm") &&
av_strstart(filename, "http:", NULL)) {
int err = read_ffserver_streams(oc, filename);
if (err < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
} else {
use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
if (nb_input_files > 0) {
check_audio_video_sub_inputs(&input_has_video, &input_has_audio,
&input_has_subtitle);
if (!input_has_video)
use_video = 0;
if (!input_has_audio)
use_audio = 0;
if (!input_has_subtitle)
use_subtitle = 0;
}
if (audio_disable) use_audio = 0;
if (video_disable) use_video = 0;
if (subtitle_disable) use_subtitle = 0;
if (use_video) new_video_stream(oc, nb_output_files);
if (use_audio) new_audio_stream(oc, nb_output_files);
if (use_subtitle) new_subtitle_stream(oc, nb_output_files);
oc->timestamp = recording_timestamp;
av_metadata_copy(&oc->metadata, metadata, 0);
av_metadata_free(&metadata);
}
output_files[nb_output_files++] = oc;
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR(EINVAL));
ffmpeg_exit(1);
}
}
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
filename[1] == ':' ||
av_strstart(filename, "file:", NULL))) {
if (avio_check(filename, 0) == 0) {
if (!using_stdin) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
if (!read_yesno()) {
fprintf(stderr, "Not overwriting - exiting\n");
ffmpeg_exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
ffmpeg_exit(1);
}
}
}
if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
}
memset(ap, 0, sizeof(*ap));
if (av_set_parameters(oc, ap) < 0) {
fprintf(stderr, "%s: Invalid encoding parameters\n",
oc->filename);
ffmpeg_exit(1);
}
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
av_freep(&forced_key_frames);
}
|
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = ¶ms;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n ffmpeg_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n ffmpeg_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) use_audio = 0;\n if (video_disable) use_video = 0;\n if (subtitle_disable) use_subtitle = 0;\n if (use_video) new_video_stream(oc, nb_output_files);\n if (use_audio) new_audio_stream(oc, nb_output_files);\n if (use_subtitle) new_subtitle_stream(oc, nb_output_files);\n oc->timestamp = recording_timestamp;\n av_metadata_copy(&oc->metadata, metadata, 0);\n av_metadata_free(&metadata);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR(EINVAL));\n ffmpeg_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (avio_check(filename, 0) == 0) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n ffmpeg_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n ffmpeg_exit(1);\n }\n }\n }\n if ((err = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE)) < 0) {\n print_error(filename, err);\n ffmpeg_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n ffmpeg_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);\n av_freep(&forced_key_frames);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(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}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n size_t len = 0;\n while (++len < size && *src)\n *dst++ = *src++;\n if (len <= size)\n *dst = 0;\n return len + strlen(src) - 1;\n}']
|
1,169
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/x509/x509_cmp.c/#L410
|
int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,
unsigned long flags)
{
int rv, i, sign_nid;
EVP_PKEY *pk = NULL;
unsigned long tflags;
if (!(flags & X509_V_FLAG_SUITEB_128_LOS))
return X509_V_OK;
tflags = flags;
if (x == NULL) {
x = sk_X509_value(chain, 0);
i = 1;
} else
i = 0;
if (X509_get_version(x) != 2) {
rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
i = 0;
goto end;
}
pk = X509_get_pubkey(x);
rv = check_suite_b(pk, -1, &tflags);
if (rv != X509_V_OK) {
i = 0;
goto end;
}
for (; i < sk_X509_num(chain); i++) {
sign_nid = X509_get_signature_nid(x);
x = sk_X509_value(chain, i);
if (X509_get_version(x) != 2) {
rv = X509_V_ERR_SUITE_B_INVALID_VERSION;
goto end;
}
EVP_PKEY_free(pk);
pk = X509_get_pubkey(x);
rv = check_suite_b(pk, sign_nid, &tflags);
if (rv != X509_V_OK)
goto end;
}
rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);
end:
if (pk)
EVP_PKEY_free(pk);
if (rv != X509_V_OK) {
if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM
|| rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && i)
i--;
if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags)
rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;
if (perror_depth)
*perror_depth = i;
}
return rv;
}
|
['int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain,\n unsigned long flags)\n{\n int rv, i, sign_nid;\n EVP_PKEY *pk = NULL;\n unsigned long tflags;\n if (!(flags & X509_V_FLAG_SUITEB_128_LOS))\n return X509_V_OK;\n tflags = flags;\n if (x == NULL) {\n x = sk_X509_value(chain, 0);\n i = 1;\n } else\n i = 0;\n if (X509_get_version(x) != 2) {\n rv = X509_V_ERR_SUITE_B_INVALID_VERSION;\n i = 0;\n goto end;\n }\n pk = X509_get_pubkey(x);\n rv = check_suite_b(pk, -1, &tflags);\n if (rv != X509_V_OK) {\n i = 0;\n goto end;\n }\n for (; i < sk_X509_num(chain); i++) {\n sign_nid = X509_get_signature_nid(x);\n x = sk_X509_value(chain, i);\n if (X509_get_version(x) != 2) {\n rv = X509_V_ERR_SUITE_B_INVALID_VERSION;\n goto end;\n }\n EVP_PKEY_free(pk);\n pk = X509_get_pubkey(x);\n rv = check_suite_b(pk, sign_nid, &tflags);\n if (rv != X509_V_OK)\n goto end;\n }\n rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags);\n end:\n if (pk)\n EVP_PKEY_free(pk);\n if (rv != X509_V_OK) {\n if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM\n || rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && i)\n i--;\n if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags)\n rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256;\n if (perror_depth)\n *perror_depth = i;\n }\n return rv;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}']
|
1,170
| 1
|
https://github.com/openssl/openssl/blob/9b10986d7742a5105ac8c5f4eba8b103caf57ae9/crypto/bn/bn_sqr.c/#L118
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL;\n BIGNUM *m, *blind, *blindm, *tmp;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int rv = 0;\n if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n m = BN_CTX_get(ctx);\n blind = BN_CTX_get(ctx);\n blindm = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n redo:\n if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n goto err;\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n do {\n if (!BN_priv_rand(blind, BN_num_bits(dsa->q) - 1,\n BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n goto err;\n } while (BN_is_zero(blind));\n BN_set_flags(blind, BN_FLG_CONSTTIME);\n BN_set_flags(blindm, BN_FLG_CONSTTIME);\n BN_set_flags(tmp, BN_FLG_CONSTTIME);\n if (!BN_mod_mul(tmp, blind, dsa->priv_key, dsa->q, ctx))\n goto err;\n if (!BN_mod_mul(tmp, tmp, ret->r, dsa->q, ctx))\n goto err;\n if (!BN_mod_mul(blindm, blind, m, dsa->q, ctx))\n goto err;\n if (!BN_mod_add_quick(ret->s, tmp, blindm, dsa->q))\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n goto err;\n if (BN_mod_inverse(blind, blind, dsa->q, ctx) == NULL)\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, blind, dsa->q, ctx))\n goto err;\n if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n goto redo;\n rv = 1;\n err:\n if (rv == 0) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n DSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(kinv);\n return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n BIGNUM *l;\n int ret = 0;\n int q_bits, q_words;\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 l = BN_new();\n if (k == NULL || l == 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 q_bits = BN_num_bits(dsa->q);\n q_words = bn_get_top(dsa->q);\n if (!bn_wexpand(k, q_words + 2)\n || !bn_wexpand(l, q_words + 2))\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_priv_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n BN_set_flags(l, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(l, k, dsa->q)\n || !BN_add(k, l, dsa->q))\n goto err;\n BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2);\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = dsa_mod_inverse_fermat(k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n BN_clear_free(l);\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 || 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}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#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_mont_fixed_top(&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_mont_fixed_top(&am, &am, mont, ctx))\n goto err;\n } else if (!bn_to_mont_fixed_top(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,171
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L183
|
static void pred4x4_down_left_rv40_c(uint8_t *src, uint8_t *topright, int stride){
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
LOAD_LEFT_EDGE
LOAD_DOWN_LEFT_EDGE
src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3;
src[1+0*stride]=
src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3;
src[2+0*stride]=
src[1+1*stride]=
src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + l4 + 2*l3 + 2)>>3;
src[3+0*stride]=
src[2+1*stride]=
src[1+2*stride]=
src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3 + l5 + 2*l4 + 2)>>3;
src[3+1*stride]=
src[2+2*stride]=
src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l4 + l6 + 2*l5 + 2)>>3;
src[3+2*stride]=
src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l5 + l7 + 2*l6 + 2)>>3;
src[3+3*stride]=(t6 + t7 + 1 + l6 + l7 + 1)>>2;
}
|
['static void pred4x4_down_left_rv40_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n LOAD_LEFT_EDGE\n LOAD_DOWN_LEFT_EDGE\n src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3;\n src[1+0*stride]=\n src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3;\n src[2+0*stride]=\n src[1+1*stride]=\n src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + l4 + 2*l3 + 2)>>3;\n src[3+0*stride]=\n src[2+1*stride]=\n src[1+2*stride]=\n src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3 + l5 + 2*l4 + 2)>>3;\n src[3+1*stride]=\n src[2+2*stride]=\n src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l4 + l6 + 2*l5 + 2)>>3;\n src[3+2*stride]=\n src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l5 + l7 + 2*l6 + 2)>>3;\n src[3+3*stride]=(t6 + t7 + 1 + l6 + l7 + 1)>>2;\n}']
|
1,172
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/x509/x509_vfy.c/#L433
|
int X509_cmp_current_time(ASN1_UTCTIME *ctm)
{
char *str;
ASN1_UTCTIME atm;
time_t offset;
char buff1[24],buff2[24],*p;
int i,j;
p=buff1;
i=ctm->length;
str=(char *)ctm->data;
if ((i < 11) || (i > 17)) return(0);
memcpy(p,str,10);
p+=10;
str+=10;
if ((*str == 'Z') || (*str == '-') || (*str == '+'))
{ *(p++)='0'; *(p++)='0'; }
else { *(p++)= *(str++); *(p++)= *(str++); }
*(p++)='Z';
*(p++)='\0';
if (*str == 'Z')
offset=0;
else
{
if ((*str != '+') && (str[5] != '-'))
return(0);
offset=((str[1]-'0')*10+(str[2]-'0'))*60;
offset+=(str[3]-'0')*10+(str[4]-'0');
if (*str == '-')
offset= -offset;
}
atm.type=V_ASN1_UTCTIME;
atm.length=sizeof(buff2);
atm.data=(unsigned char *)buff2;
X509_gmtime_adj(&atm,-offset);
i=(buff1[0]-'0')*10+(buff1[1]-'0');
if (i < 50) i+=100;
j=(buff2[0]-'0')*10+(buff2[1]-'0');
if (j < 50) j+=100;
if (i < j) return (-1);
if (i > j) return (1);
i=strcmp(buff1,buff2);
if (i == 0)
return(-1);
else
return(i);
}
|
['static int internal_verify(X509_STORE_CTX *ctx)\n\t{\n\tint i,ok=0,n;\n\tX509 *xs,*xi;\n\tEVP_PKEY *pkey=NULL;\n\tint (*cb)();\n\tcb=ctx->ctx->verify_cb;\n\tif (cb == NULL) cb=null_callback;\n\tn=sk_num(ctx->chain);\n\tctx->error_depth=n-1;\n\tn--;\n\txi=(X509 *)sk_value(ctx->chain,n);\n\tif (X509_NAME_cmp(X509_get_subject_name(xi),\n\t\tX509_get_issuer_name(xi)) == 0)\n\t\txs=xi;\n\telse\n\t\t{\n\t\tif (n <= 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;\n\t\t\tctx->current_cert=xi;\n\t\t\tok=cb(0,ctx);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tn--;\n\t\t\tctx->error_depth=n;\n\t\t\txs=(X509 *)sk_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\twhile (n >= 0)\n\t\t{\n\t\tctx->error_depth=n;\n\t\tif (!xs->valid)\n\t\t\t{\n\t\t\tif ((pkey=X509_get_pubkey(xi)) == NULL)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;\n\t\t\t\tctx->current_cert=xi;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tif (X509_verify(xs,pkey) <= 0)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY_free(pkey);\n\t\t\t\tctx->error=X509_V_ERR_CERT_SIGNATURE_FAILURE;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tEVP_PKEY_free(pkey);\n\t\t\tpkey=NULL;\n\t\t\ti=X509_cmp_current_time(X509_get_notBefore(xs));\n\t\t\tif (i == 0)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tif (i > 0)\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_CERT_NOT_YET_VALID;\n\t\t\t\tctx->current_cert=xs;\n\t\t\t\tok=(*cb)(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\txs->valid=1;\n\t\t\t}\n\t\ti=X509_cmp_current_time(X509_get_notAfter(xs));\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;\n\t\t\tctx->current_cert=xs;\n\t\t\tok=(*cb)(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tctx->error=X509_V_ERR_CERT_HAS_EXPIRED;\n\t\t\tctx->current_cert=xs;\n\t\t\tok=(*cb)(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tctx->current_cert=xs;\n\t\tok=(*cb)(1,ctx);\n\t\tif (!ok) goto end;\n\t\tn--;\n\t\tif (n >= 0)\n\t\t\t{\n\t\t\txi=xs;\n\t\t\txs=(X509 *)sk_value(ctx->chain,n);\n\t\t\t}\n\t\t}\n\tok=1;\nend:\n\treturn(ok);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t {\n\t CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t return(key->pkey);\n\t }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n j=key->public_key->length;\n if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,\n\t long length)\n\t{\n\tASN1_INTEGER *ret=NULL;\n\tunsigned char *p,*to,*s;\n\tlong len;\n\tint inf,tag,xclass;\n\tint i;\n\tif ((a == NULL) || ((*a) == NULL))\n\t\t{\n\t\tif ((ret=ASN1_INTEGER_new()) == NULL) return(NULL);\n\t\tret->type=V_ASN1_INTEGER;\n\t\t}\n\telse\n\t\tret=(*a);\n\tp= *pp;\n\tinf=ASN1_get_object(&p,&len,&tag,&xclass,length);\n\tif (inf & 0x80)\n\t\t{\n\t\ti=ASN1_R_BAD_OBJECT_HEADER;\n\t\tgoto err;\n\t\t}\n\tif (tag != V_ASN1_INTEGER)\n\t\t{\n\t\ti=ASN1_R_EXPECTING_AN_INTEGER;\n\t\tgoto err;\n\t\t}\n\ts=(unsigned char *)Malloc((int)len+1);\n\tif (s == NULL)\n\t\t{\n\t\ti=ERR_R_MALLOC_FAILURE;\n\t\tgoto err;\n\t\t}\n\tto=s;\n\tif (*p & 0x80)\n\t\t{\n\t\tret->type=V_ASN1_NEG_INTEGER;\n\t\tif (*p == 0xff)\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tfor (i=(int)len; i>0; i--)\n\t\t\t*(to++)= (*(p++)^0xFF)+1;\n\t\t}\n\telse\n\t\t{\n\t\tret->type=V_ASN1_INTEGER;\n\t\tif ((*p == 0) && (len != 1))\n\t\t\t{\n\t\t\tp++;\n\t\t\tlen--;\n\t\t\t}\n\t\tmemcpy(s,p,(int)len);\n\t\tp+=len;\n\t\t}\n\tif (ret->data != NULL) Free((char *)ret->data);\n\tret->data=s;\n\tret->length=(int)len;\n\tif (a != NULL) (*a)=ret;\n\t*pp=p;\n\treturn(ret);\nerr:\n\tASN1err(ASN1_F_D2I_ASN1_INTEGER,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\tASN1_INTEGER_free(ret);\n\treturn(NULL);\n\t}', "int X509_cmp_current_time(ASN1_UTCTIME *ctm)\n\t{\n\tchar *str;\n\tASN1_UTCTIME atm;\n\ttime_t offset;\n\tchar buff1[24],buff2[24],*p;\n\tint i,j;\n\tp=buff1;\n\ti=ctm->length;\n\tstr=(char *)ctm->data;\n\tif ((i < 11) || (i > 17)) return(0);\n\tmemcpy(p,str,10);\n\tp+=10;\n\tstr+=10;\n\tif ((*str == 'Z') || (*str == '-') || (*str == '+'))\n\t\t{ *(p++)='0'; *(p++)='0'; }\n\telse\t{ *(p++)= *(str++); *(p++)= *(str++); }\n\t*(p++)='Z';\n\t*(p++)='\\0';\n\tif (*str == 'Z')\n\t\toffset=0;\n\telse\n\t\t{\n\t\tif ((*str != '+') && (str[5] != '-'))\n\t\t\treturn(0);\n\t\toffset=((str[1]-'0')*10+(str[2]-'0'))*60;\n\t\toffset+=(str[3]-'0')*10+(str[4]-'0');\n\t\tif (*str == '-')\n\t\t\toffset= -offset;\n\t\t}\n\tatm.type=V_ASN1_UTCTIME;\n\tatm.length=sizeof(buff2);\n\tatm.data=(unsigned char *)buff2;\n\tX509_gmtime_adj(&atm,-offset);\n\ti=(buff1[0]-'0')*10+(buff1[1]-'0');\n\tif (i < 50) i+=100;\n\tj=(buff2[0]-'0')*10+(buff2[1]-'0');\n\tif (j < 50) j+=100;\n\tif (i < j) return (-1);\n\tif (i > j) return (1);\n\ti=strcmp(buff1,buff2);\n\tif (i == 0)\n\t\treturn(-1);\n\telse\n\t\treturn(i);\n\t}"]
|
1,173
| 0
|
https://github.com/openssl/openssl/blob/6c2c3e9ba9146ef8c9b1fd2b660357b657706969/crypto/lhash/lhash.c/#L243
|
char *lh_delete(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free((char *)nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['static int ssl3_get_client_hello(SSL *s)\n\t{\n\tint i,j,ok,al,ret= -1;\n\tlong n;\n\tunsigned long id;\n\tunsigned char *p,*d,*q;\n\tSSL_CIPHER *c;\n\tSSL_COMP *comp=NULL;\n\tSTACK_OF(SSL_CIPHER) *ciphers=NULL;\n\tif (s->state == SSL3_ST_SR_CLNT_HELLO_A)\n\t\t{\n\t\ts->first_packet=1;\n\t\ts->state=SSL3_ST_SR_CLNT_HELLO_B;\n\t\t}\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_CLNT_HELLO_B,\n\t\tSSL3_ST_SR_CLNT_HELLO_C,\n\t\tSSL3_MT_CLIENT_HELLO,\n\t\tSSL3_RT_MAX_PLAIN_LENGTH,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\td=p=(unsigned char *)s->init_buf->data;\n\ts->client_version=(((int)p[0])<<8)|(int)p[1];\n\tp+=2;\n\tmemcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);\n\tp+=SSL3_RANDOM_SIZE;\n\tj= *(p++);\n\ts->hit=0;\n\tif (j == 0)\n\t\t{\n\t\tif (!ssl_get_new_session(s,1))\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\t{\n\t\ti=ssl_get_prev_session(s,p,j);\n\t\tif (i == 1)\n\t\t\t{\n\t\t\ts->hit=1;\n\t\t\t}\n\t\telse if (i == -1)\n\t\t\tgoto err;\n\t\telse\n\t\t\t{\n\t\t\tif (!ssl_get_new_session(s,1))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tp+=j;\n\tn2s(p,i);\n\tif ((i == 0) && (j != 0))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\tif ((i+p) > (d+n))\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tif ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))\n\t\t== NULL))\n\t\t{\n\t\tgoto err;\n\t\t}\n\tp+=i;\n\tif ((s->hit) && (i > 0))\n\t\t{\n\t\tj=0;\n\t\tid=s->session->cipher->id;\n#ifdef CIPHER_DEBUG\n\t\tprintf("client sent %d ciphers\\n",sk_num(ciphers));\n#endif\n\t\tfor (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)\n\t\t\t{\n\t\t\tc=sk_SSL_CIPHER_value(ciphers,i);\n#ifdef CIPHER_DEBUG\n\t\t\tprintf("client [%2d of %2d]:%s\\n",\n\t\t\t\ti,sk_num(ciphers),SSL_CIPHER_get_name(c));\n#endif\n\t\t\tif (c->id == id)\n\t\t\t\t{\n\t\t\t\tj=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))\n\t\t\t\t{\n\t\t\t\ts->session->cipher=sk_SSL_CIPHER_value(ciphers,\n\t\t\t\t\t\t\t\t 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\ti= *(p++);\n\tq=p;\n\tfor (j=0; j<i; j++)\n\t\t{\n\t\tif (p[j] == 0) break;\n\t\t}\n\tp+=i;\n\tif (j >= i)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\ts->s3->tmp.new_compression=NULL;\n\tif (s->ctx->comp_methods != NULL)\n\t\t{\n\t\tint m,nn,o,v,done=0;\n\t\tnn=sk_SSL_COMP_num(s->ctx->comp_methods);\n\t\tfor (m=0; m<nn; m++)\n\t\t\t{\n\t\t\tcomp=sk_SSL_COMP_value(s->ctx->comp_methods,m);\n\t\t\tv=comp->id;\n\t\t\tfor (o=0; o<i; o++)\n\t\t\t\t{\n\t\t\t\tif (v == q[o])\n\t\t\t\t\t{\n\t\t\t\t\tdone=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (done) break;\n\t\t\t}\n\t\tif (done)\n\t\t\ts->s3->tmp.new_compression=comp;\n\t\telse\n\t\t\tcomp=NULL;\n\t\t}\n\tif (s->version == SSL3_VERSION)\n\t\t{\n\t\tif (p > (d+n))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif (!s->hit)\n\t\t{\n\t\ts->session->compress_meth=(comp == NULL)?0:comp->id;\n\t\tif (s->session->ciphers != NULL)\n\t\t\tsk_SSL_CIPHER_free(s->session->ciphers);\n\t\ts->session->ciphers=ciphers;\n\t\tif (ciphers == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tciphers=NULL;\n\t\tc=ssl3_choose_cipher(s,s->session->ciphers,\n\t\t\t\t ssl_get_ciphers_by_id(s));\n\t\tif (c == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.new_cipher=c;\n\t\t}\n\telse\n\t\t{\n#ifdef REUSE_CIPHER_BUG\n\t\tSTACK_OF(SSL_CIPHER) *sk;\n\t\tSSL_CIPHER *nc=NULL;\n\t\tSSL_CIPHER *ec=NULL;\n\t\tif (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)\n\t\t\t{\n\t\t\tsk=s->session->ciphers;\n\t\t\tfor (i=0; i<sk_SSL_CIPHER_num(sk); i++)\n\t\t\t\t{\n\t\t\t\tc=sk_SSL_CIPHER_value(sk,i);\n\t\t\t\tif (c->algorithms & SSL_eNULL)\n\t\t\t\t\tnc=c;\n\t\t\t\tif (SSL_C_IS_EXPORT(c))\n\t\t\t\t\tec=c;\n\t\t\t\t}\n\t\t\tif (nc != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=nc;\n\t\t\telse if (ec != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=ec;\n\t\t\telse\n\t\t\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t\t}\n\t\telse\n#endif\n\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t}\n\tret=1;\n\tif (0)\n\t\t{\nf_err:\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t}\nerr:\n\tif (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);\n\treturn(ret);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t 4-s->init_num);\n\t\tif (i < (4-s->init_num))\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t\t\t(st1 == SSL3_ST_SR_CERT_A) &&\n\t\t\t\t\t(stn == SSL3_ST_SR_CERT_B))\n\t\t\t{\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tssl3_finish_mac(s, p + s->init_num, i);\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\tif (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);\n\t\tif (i != (int)n)\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\t}\n\t*ok=1;\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
|
1,174
| 0
|
https://github.com/openssl/openssl/blob/27a3d9f9aa1ca6137ffd13a23775709c6f1ef567/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int\tBN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *u;\n\tbn_check_top(a);\n\tif (!p[0])\n\t\t{\n\t\tBN_zero(r);\n\t\treturn 1;\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((u = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!BN_set_bit(u, p[0] - 1)) goto err;\n\tret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);\n\tbn_check_top(r);\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,175
| 0
|
https://github.com/openssl/openssl/blob/0f3ffbd1581fad58095fedcc32b0da42a486b8b7/crypto/ocsp/ocsp_ht.c/#L80
|
OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline)
{
OCSP_REQ_CTX *rctx = OPENSSL_zalloc(sizeof(*rctx));
if (rctx == NULL)
return NULL;
rctx->state = OHS_ERROR;
rctx->max_resp_len = OCSP_MAX_RESP_LENGTH;
rctx->mem = BIO_new(BIO_s_mem());
rctx->io = io;
if (maxline > 0)
rctx->iobuflen = maxline;
else
rctx->iobuflen = OCSP_MAX_LINE_LEN;
rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);
if (rctx->iobuf == NULL || rctx->mem == NULL) {
OCSP_REQ_CTX_free(rctx);
return NULL;
}
return rctx;
}
|
['OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline)\n{\n OCSP_REQ_CTX *rctx = OPENSSL_zalloc(sizeof(*rctx));\n if (rctx == NULL)\n return NULL;\n rctx->state = OHS_ERROR;\n rctx->max_resp_len = OCSP_MAX_RESP_LENGTH;\n rctx->mem = BIO_new(BIO_s_mem());\n rctx->io = io;\n if (maxline > 0)\n rctx->iobuflen = maxline;\n else\n rctx->iobuflen = OCSP_MAX_LINE_LEN;\n rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);\n if (rctx->iobuf == NULL || rctx->mem == NULL) {\n OCSP_REQ_CTX_free(rctx);\n return NULL;\n }\n return rctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'const BIO_METHOD *BIO_s_mem(void)\n{\n return (&mem_method);\n}', 'void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx)\n{\n if (!rctx)\n return;\n BIO_free(rctx->mem);\n OPENSSL_free(rctx->iobuf);\n OPENSSL_free(rctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
1,176
| 1
|
https://github.com/libav/libav/blob/6e7c397b5c8f7f3558cc3201a1fe03251deab3b3/libavcodec/h264.h/#L1225
|
static int fill_filter_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
int top_xy, left_xy[2];
int top_type, left_type[2];
top_xy = mb_xy - (s->mb_stride << MB_FIELD);
left_xy[1] = left_xy[0] = mb_xy-1;
if(FRAME_MBAFF){
const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);
const int curr_mb_field_flag = IS_INTERLACED(mb_type);
if(s->mb_y&1){
if (left_mb_field_flag != curr_mb_field_flag) {
left_xy[0] -= s->mb_stride;
}
}else{
if(curr_mb_field_flag){
top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);
}
if (left_mb_field_flag != curr_mb_field_flag) {
left_xy[1] += s->mb_stride;
}
}
}
h->top_mb_xy = top_xy;
h->left_mb_xy[0] = left_xy[0];
h->left_mb_xy[1] = left_xy[1];
{
int qp_thresh = h->qp_thresh;
int qp = s->current_picture.qscale_table[mb_xy];
if(qp <= qp_thresh
&& (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh)
&& (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){
if(!FRAME_MBAFF)
return 1;
if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh)
&& (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh))
return 1;
}
}
if(h->deblocking_filter == 2){
h->top_type = top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;
h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;
h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;
}else{
h->top_type = top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0;
h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0;
h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0;
}
if(IS_INTRA(mb_type))
return 0;
AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]);
AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]);
*((uint32_t*)&h->non_zero_count_cache[0+8*5])= *((uint32_t*)&h->non_zero_count[mb_xy][16]);
*((uint32_t*)&h->non_zero_count_cache[4+8*3])= *((uint32_t*)&h->non_zero_count[mb_xy][20]);
AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]);
h->cbp= h->cbp_table[mb_xy];
{
int list;
for(list=0; list<h->list_count; list++){
int8_t *ref;
int y, b_stride;
int16_t (*mv_dst)[2];
int16_t (*mv_src)[2];
if(!USES_LIST(mb_type, list)){
fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4);
*(uint32_t*)&h->ref_cache[list][scan8[ 0]] =
*(uint32_t*)&h->ref_cache[list][scan8[ 2]] =
*(uint32_t*)&h->ref_cache[list][scan8[ 8]] =
*(uint32_t*)&h->ref_cache[list][scan8[10]] = ((LIST_NOT_USED)&0xFF)*0x01010101U;
continue;
}
ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]];
{
int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ] + (MB_MBAFF ? 20 : 2);
*(uint32_t*)&h->ref_cache[list][scan8[ 0]] =
*(uint32_t*)&h->ref_cache[list][scan8[ 2]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;
ref += h->b8_stride;
*(uint32_t*)&h->ref_cache[list][scan8[ 8]] =
*(uint32_t*)&h->ref_cache[list][scan8[10]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;
}
b_stride = h->b_stride;
mv_dst = &h->mv_cache[list][scan8[0]];
mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];
for(y=0; y<4; y++){
AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride);
}
}
}
if(top_type){
*(uint32_t*)&h->non_zero_count_cache[4+8*0]= *(uint32_t*)&h->non_zero_count[top_xy][4+3*8];
}
if(left_type[0]){
h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8];
h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8];
h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8];
h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8];
}
if(!CABAC && h->pps.transform_8x8_mode){
if(IS_8x8DCT(top_type)){
h->non_zero_count_cache[4+8*0]=
h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4;
h->non_zero_count_cache[6+8*0]=
h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8;
}
if(IS_8x8DCT(left_type[0])){
h->non_zero_count_cache[3+8*1]=
h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2;
}
if(IS_8x8DCT(left_type[1])){
h->non_zero_count_cache[3+8*3]=
h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8;
}
if(IS_8x8DCT(mb_type)){
h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]=
h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp & 1;
h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]=
h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp & 2;
h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]=
h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp & 4;
h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]=
h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp & 8;
}
}
if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){
int list;
for(list=0; list<h->list_count; list++){
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;
int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ] + (MB_MBAFF ? 20 : 2);
AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);
h->ref_cache[list][scan8[0] + 0 - 1*8]=
h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]];
h->ref_cache[list][scan8[0] + 2 - 1*8]=
h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]];
}else{
AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);
*(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((LIST_NOT_USED)&0xFF)*0x01010101U;
}
if(!IS_INTERLACED(mb_type^left_type[0])){
if(USES_LIST(left_type[0], list)){
const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1;
int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ] + (MB_MBAFF ? 20 : 2);
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*0];
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 8 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*1];
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 +16 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*2];
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 +24 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*3];
h->ref_cache[list][scan8[0] - 1 + 0 ]=
h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*0]];
h->ref_cache[list][scan8[0] - 1 +16 ]=
h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*1]];
}else{
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0 ]=
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 8 ]=
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 +16 ]=
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 +24 ]= 0;
h->ref_cache[list][scan8[0] - 1 + 0 ]=
h->ref_cache[list][scan8[0] - 1 + 8 ]=
h->ref_cache[list][scan8[0] - 1 + 16 ]=
h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED;
}
}
}
}
return 0;
}
|
['static int fill_filter_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int top_xy, left_xy[2];\n int top_type, left_type[2];\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n left_xy[1] = left_xy[0] = mb_xy-1;\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[0] -= s->mb_stride;\n }\n }else{\n if(curr_mb_field_flag){\n top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n }\n }\n }\n h->top_mb_xy = top_xy;\n h->left_mb_xy[0] = left_xy[0];\n h->left_mb_xy[1] = left_xy[1];\n {\n int qp_thresh = h->qp_thresh;\n int qp = s->current_picture.qscale_table[mb_xy];\n if(qp <= qp_thresh\n && (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh)\n && (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){\n if(!FRAME_MBAFF)\n return 1;\n if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh)\n && (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh))\n return 1;\n }\n }\n if(h->deblocking_filter == 2){\n h->top_type = top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;\n h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;\n }else{\n h->top_type = top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0;\n h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0;\n }\n if(IS_INTRA(mb_type))\n return 0;\n AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]);\n AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]);\n *((uint32_t*)&h->non_zero_count_cache[0+8*5])= *((uint32_t*)&h->non_zero_count[mb_xy][16]);\n *((uint32_t*)&h->non_zero_count_cache[4+8*3])= *((uint32_t*)&h->non_zero_count[mb_xy][20]);\n AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]);\n h->cbp= h->cbp_table[mb_xy];\n {\n int list;\n for(list=0; list<h->list_count; list++){\n int8_t *ref;\n int y, b_stride;\n int16_t (*mv_dst)[2];\n int16_t (*mv_src)[2];\n if(!USES_LIST(mb_type, list)){\n fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4);\n *(uint32_t*)&h->ref_cache[list][scan8[ 0]] =\n *(uint32_t*)&h->ref_cache[list][scan8[ 2]] =\n *(uint32_t*)&h->ref_cache[list][scan8[ 8]] =\n *(uint32_t*)&h->ref_cache[list][scan8[10]] = ((LIST_NOT_USED)&0xFF)*0x01010101U;\n continue;\n }\n ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]];\n {\n int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ] + (MB_MBAFF ? 20 : 2);\n *(uint32_t*)&h->ref_cache[list][scan8[ 0]] =\n *(uint32_t*)&h->ref_cache[list][scan8[ 2]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;\n ref += h->b8_stride;\n *(uint32_t*)&h->ref_cache[list][scan8[ 8]] =\n *(uint32_t*)&h->ref_cache[list][scan8[10]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;\n }\n b_stride = h->b_stride;\n mv_dst = &h->mv_cache[list][scan8[0]];\n mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];\n for(y=0; y<4; y++){\n AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride);\n }\n }\n }\n if(top_type){\n *(uint32_t*)&h->non_zero_count_cache[4+8*0]= *(uint32_t*)&h->non_zero_count[top_xy][4+3*8];\n }\n if(left_type[0]){\n h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8];\n h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8];\n h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8];\n h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8];\n }\n if(!CABAC && h->pps.transform_8x8_mode){\n if(IS_8x8DCT(top_type)){\n h->non_zero_count_cache[4+8*0]=\n h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4;\n h->non_zero_count_cache[6+8*0]=\n h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8;\n }\n if(IS_8x8DCT(left_type[0])){\n h->non_zero_count_cache[3+8*1]=\n h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2;\n }\n if(IS_8x8DCT(left_type[1])){\n h->non_zero_count_cache[3+8*3]=\n h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8;\n }\n if(IS_8x8DCT(mb_type)){\n h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]=\n h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp & 1;\n h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]=\n h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp & 2;\n h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]=\n h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp & 4;\n h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]=\n h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp & 8;\n }\n }\n if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){\n int list;\n for(list=0; list<h->list_count; list++){\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;\n int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ] + (MB_MBAFF ? 20 : 2);\n AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);\n h->ref_cache[list][scan8[0] + 0 - 1*8]=\n h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]];\n h->ref_cache[list][scan8[0] + 2 - 1*8]=\n h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]];\n }else{\n AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);\n *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((LIST_NOT_USED)&0xFF)*0x01010101U;\n }\n if(!IS_INTERLACED(mb_type^left_type[0])){\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2b_xy[left_xy[0]] + 3;\n const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1;\n int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ] + (MB_MBAFF ? 20 : 2);\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*0];\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 8 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*1];\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 +16 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*2];\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 +24 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*3];\n h->ref_cache[list][scan8[0] - 1 + 0 ]=\n h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*0]];\n h->ref_cache[list][scan8[0] - 1 +16 ]=\n h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*1]];\n }else{\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0 ]=\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 8 ]=\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 +16 ]=\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 +24 ]= 0;\n h->ref_cache[list][scan8[0] - 1 + 0 ]=\n h->ref_cache[list][scan8[0] - 1 + 8 ]=\n h->ref_cache[list][scan8[0] - 1 + 16 ]=\n h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED;\n }\n }\n }\n }\n return 0;\n}']
|
1,177
| 0
|
https://github.com/openssl/openssl/blob/1145e03870dd82eae00bb45e0b2162494b9b2f38/apps/x509.c/#L1193
|
static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest,
CONF *conf, char *section)
{
EVP_PKEY *pktmp;
pktmp = X509_get_pubkey(x);
EVP_PKEY_copy_parameters(pktmp,pkey);
EVP_PKEY_save_parameters(pktmp,1);
EVP_PKEY_free(pktmp);
if (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err;
if (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err;
if (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)
goto err;
if (!X509_set_pubkey(x,pkey)) goto err;
if (clrext)
{
while (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);
}
if (conf)
{
X509V3_CTX ctx;
X509_set_version(x,2);
X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0);
X509V3_set_nconf(&ctx, conf);
if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err;
}
if (!X509_sign(x,pkey,digest)) goto err;
return 1;
err:
ERR_print_errors(bio_err);
return 0;
}
|
['static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, const EVP_MD *digest,\n\t\t\t\t\t\tCONF *conf, char *section)\n\t{\n\tEVP_PKEY *pktmp;\n\tpktmp = X509_get_pubkey(x);\n\tEVP_PKEY_copy_parameters(pktmp,pkey);\n\tEVP_PKEY_save_parameters(pktmp,1);\n\tEVP_PKEY_free(pktmp);\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(x))) goto err;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0) == NULL) goto err;\n\tif (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)\n\t\tgoto err;\n\tif (!X509_set_pubkey(x,pkey)) goto err;\n\tif (clrext)\n\t\t{\n\t\twhile (X509_get_ext_count(x) > 0) X509_delete_ext(x, 0);\n\t\t}\n\tif (conf)\n\t\t{\n\t\tX509V3_CTX ctx;\n\t\tX509_set_version(x,2);\n X509V3_set_ctx(&ctx, x, x, NULL, NULL, 0);\n X509V3_set_nconf(&ctx, conf);\n if (!X509V3_EXT_add_nconf(conf, &ctx, section, x)) goto err;\n\t\t}\n\tif (!X509_sign(x,pkey,digest)) goto err;\n\treturn 1;\nerr:\n\tERR_print_errors(bio_err);\n\treturn 0;\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\tconst unsigned char *cp;\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t\t{\n\t\tCRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\t\treturn(key->pkey);\n\t\t}\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tif ((ret = EVP_PKEY_new()) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tret->type = EVP_PKEY_type(type);\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\ta=key->algor;\n#endif\n\tif (0)\n\t\t;\n#ifndef OPENSSL_NO_DSA\n\telse if (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tif ((ret->pkey.dsa = DSA_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tcp=p=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_EC\n\telse if (ret->type == EVP_PKEY_EC)\n\t\t{\n\t\tif (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))\n\t\t\t{\n\t\t\tif ((ret->pkey.eckey= EC_KEY_new()) == NULL)\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET,\n\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tcp = p = a->parameter->value.sequence->data;\n\t\t\tj = a->parameter->value.sequence->length;\n\t\t\tif (!d2i_ECParameters(&ret->pkey.eckey, &cp, (long)j))\n\t\t\t\t{\n\t\t\t\tX509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))\n\t\t\t{\n\t\t\tEC_KEY *eckey;\n\t\t\tif (ret->pkey.eckey == NULL)\n\t\t\t\tret->pkey.eckey = EC_KEY_new();\n\t\t\teckey = ret->pkey.eckey;\n\t\t\tif (eckey->group)\n\t\t\t\tEC_GROUP_free(eckey->group);\n\t\t\tif ((eckey->group = EC_GROUP_new_by_nid(\n OBJ_obj2nid(a->parameter->value.object))) == NULL)\n\t\t\t\tgoto err;\n\t\t\tEC_GROUP_set_asn1_flag(eckey->group,\n\t\t\t\t\t\tOPENSSL_EC_NAMED_CURVE);\n\t\t\t}\n\t\tret->save_parameters = 1;\n\t\t}\n#endif\n\tp=key->public_key->data;\n j=key->public_key->length;\n if (!d2i_PublicKey(type, &ret, &p, (long)j))\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET, X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tkey->pkey = ret;\n\tCRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'int OBJ_obj2nid(const ASN1_OBJECT *a)\n\t{\n\tASN1_OBJECT **op;\n\tADDED_OBJ ad,*adp;\n\tif (a == NULL)\n\t\treturn(NID_undef);\n\tif (a->nid != 0)\n\t\treturn(a->nid);\n\tif (added != NULL)\n\t\t{\n\t\tad.type=ADDED_DATA;\n\t\tad.obj=(ASN1_OBJECT *)a;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL) return (adp->obj->nid);\n\t\t}\n\top=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,\n\t\tsizeof(ASN1_OBJECT *),obj_cmp);\n\tif (op == NULL)\n\t\treturn(NID_undef);\n\treturn((*op)->nid);\n\t}', 'void *lh_retrieve(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE **rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_retrieve_miss++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\tlh->num_retrieve++;\n\t\t}\n\treturn((void *)ret);\n\t}', 'EVP_PKEY *EVP_PKEY_new(void)\n\t{\n\tEVP_PKEY *ret;\n\tret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY));\n\tif (ret == NULL)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->type=EVP_PKEY_NONE;\n\tret->references=1;\n\tret->pkey.ptr=NULL;\n\tret->attributes=NULL;\n\tret->save_parameters=1;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)\n\t{\n\tif (to->type != from->type)\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_DIFFERENT_KEY_TYPES);\n\t\tgoto err;\n\t\t}\n\tif (EVP_PKEY_missing_parameters(from))\n\t\t{\n\t\tEVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS,EVP_R_MISSING_PARAMETERS);\n\t\tgoto err;\n\t\t}\n#ifndef OPENSSL_NO_DSA\n\tif (to->type == EVP_PKEY_DSA)\n\t\t{\n\t\tBIGNUM *a;\n\t\tif ((a=BN_dup(from->pkey.dsa->p)) == NULL) goto err;\n\t\tif (to->pkey.dsa->p != NULL) BN_free(to->pkey.dsa->p);\n\t\tto->pkey.dsa->p=a;\n\t\tif ((a=BN_dup(from->pkey.dsa->q)) == NULL) goto err;\n\t\tif (to->pkey.dsa->q != NULL) BN_free(to->pkey.dsa->q);\n\t\tto->pkey.dsa->q=a;\n\t\tif ((a=BN_dup(from->pkey.dsa->g)) == NULL) goto err;\n\t\tif (to->pkey.dsa->g != NULL) BN_free(to->pkey.dsa->g);\n\t\tto->pkey.dsa->g=a;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_EC\n\tif (to->type == EVP_PKEY_EC)\n\t\t{\n\t\tif (to->pkey.eckey->group != NULL)\n\t\t\tEC_GROUP_free(to->pkey.eckey->group);\n\t\tif ((to->pkey.eckey->group = EC_GROUP_new(\n\t\t\tEC_GROUP_method_of(from->pkey.eckey->group))) == NULL)\n\t\t\tgoto err;\n\t\tif (!EC_GROUP_copy(to->pkey.eckey->group,\n\t\t\tfrom->pkey.eckey->group)) goto err;\n\t\t}\n#endif\n\treturn(1);\nerr:\n\treturn(0);\n\t}']
|
1,178
| 0
|
https://github.com/libav/libav/blob/b297129bdb0e779824db9b50440570212df58353/ffmpeg.c/#L3463
|
static void opt_output_file(const char *filename)
{
AVFormatContext *oc;
int use_video, use_audio, use_subtitle;
int input_has_video, input_has_audio, input_has_subtitle;
AVFormatParameters params, *ap = ¶ms;
AVOutputFormat *file_oformat;
if (!strcmp(filename, "-"))
filename = "pipe:";
oc = avformat_alloc_context();
if (!oc) {
print_error(filename, AVERROR(ENOMEM));
av_exit(1);
}
if (last_asked_format) {
file_oformat = av_guess_format(last_asked_format, NULL, NULL);
if (!file_oformat) {
fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
av_exit(1);
}
last_asked_format = NULL;
} else {
file_oformat = av_guess_format(NULL, filename, NULL);
if (!file_oformat) {
fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
filename);
av_exit(1);
}
}
oc->oformat = file_oformat;
av_strlcpy(oc->filename, filename, sizeof(oc->filename));
if (!strcmp(file_oformat->name, "ffm") &&
av_strstart(filename, "http:", NULL)) {
int err = read_ffserver_streams(oc, filename);
if (err < 0) {
print_error(filename, err);
av_exit(1);
}
} else {
use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
if (nb_input_files > 0) {
check_audio_video_sub_inputs(&input_has_video, &input_has_audio,
&input_has_subtitle);
if (!input_has_video)
use_video = 0;
if (!input_has_audio)
use_audio = 0;
if (!input_has_subtitle)
use_subtitle = 0;
}
if (audio_disable) {
use_audio = 0;
}
if (video_disable) {
use_video = 0;
}
if (subtitle_disable) {
use_subtitle = 0;
}
if (use_video) {
new_video_stream(oc);
}
if (use_audio) {
new_audio_stream(oc);
}
if (use_subtitle) {
new_subtitle_stream(oc);
}
oc->timestamp = rec_timestamp;
for(; metadata_count>0; metadata_count--){
av_metadata_set(&oc->metadata, metadata[metadata_count-1].key,
metadata[metadata_count-1].value);
}
av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);
}
output_files[nb_output_files++] = oc;
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR_NUMEXPECTED);
av_exit(1);
}
}
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
filename[1] == ':' ||
av_strstart(filename, "file:", NULL))) {
if (url_exist(filename)) {
if (!using_stdin) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
if (!read_yesno()) {
fprintf(stderr, "Not overwriting - exiting\n");
av_exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
av_exit(1);
}
}
}
if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {
fprintf(stderr, "Could not open '%s'\n", filename);
av_exit(1);
}
}
memset(ap, 0, sizeof(*ap));
if (av_set_parameters(oc, ap) < 0) {
fprintf(stderr, "%s: Invalid encoding parameters\n",
oc->filename);
av_exit(1);
}
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);
}
|
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = ¶ms;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n av_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n av_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n av_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) {\n use_audio = 0;\n }\n if (video_disable) {\n use_video = 0;\n }\n if (subtitle_disable) {\n use_subtitle = 0;\n }\n if (use_video) {\n new_video_stream(oc);\n }\n if (use_audio) {\n new_audio_stream(oc);\n }\n if (use_subtitle) {\n new_subtitle_stream(oc);\n }\n oc->timestamp = rec_timestamp;\n for(; metadata_count>0; metadata_count--){\n av_metadata_set(&oc->metadata, metadata[metadata_count-1].key,\n metadata[metadata_count-1].value);\n }\n av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n av_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n av_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n av_exit(1);\n }\n }\n }\n if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) {\n fprintf(stderr, "Could not open \'%s\'\\n", filename);\n av_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n av_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n size_t len = 0;\n while (++len < size && *src)\n *dst++ = *src++;\n if (len <= size)\n *dst = 0;\n return len + strlen(src) - 1;\n}']
|
1,179
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L237
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size,\n const uint8_t *mb_info, int mb_info_size)\n{\n RTPMuxContext *s = s1->priv_data;\n int len, sbits = 0, ebits = 0;\n BitstreamContext bc;\n struct H263Info info = { 0 };\n struct H263State state = { 0 };\n int mb_info_pos = 0, mb_info_count = mb_info_size / 12;\n const uint8_t *buf_base = buf;\n s->timestamp = s->cur_timestamp;\n bitstream_init8(&bc, buf, size);\n if (bitstream_read(&bc, 22) == 0x20) {\n info.tr = bitstream_read(&bc, 8);\n bitstream_skip(&bc, 2);\n bitstream_skip(&bc, 3);\n info.src = bitstream_read(&bc, 3);\n info.i = bitstream_read(&bc, 1);\n info.u = bitstream_read(&bc, 1);\n info.s = bitstream_read(&bc, 1);\n info.a = bitstream_read(&bc, 1);\n info.pb = bitstream_read(&bc, 1);\n }\n while (size > 0) {\n struct H263State packet_start_state = state;\n len = FFMIN(s->max_payload_size - 8, size);\n if (len < size) {\n const uint8_t *end = ff_h263_find_resync_marker_reverse(buf,\n buf + len);\n len = end - buf;\n if (len == s->max_payload_size - 8) {\n while (mb_info_pos < mb_info_count) {\n uint32_t pos = AV_RL32(&mb_info[12*mb_info_pos])/8;\n if (pos >= buf - buf_base)\n break;\n mb_info_pos++;\n }\n while (mb_info_pos + 1 < mb_info_count) {\n uint32_t pos = AV_RL32(&mb_info[12*(mb_info_pos + 1)])/8;\n if (pos >= end - buf_base)\n break;\n mb_info_pos++;\n }\n if (mb_info_pos < mb_info_count) {\n const uint8_t *ptr = &mb_info[12*mb_info_pos];\n uint32_t bit_pos = AV_RL32(ptr);\n uint32_t pos = (bit_pos + 7)/8;\n if (pos <= end - buf_base) {\n state.quant = ptr[4];\n state.gobn = ptr[5];\n state.mba = AV_RL16(&ptr[6]);\n state.hmv1 = (int8_t) ptr[8];\n state.vmv1 = (int8_t) ptr[9];\n state.hmv2 = (int8_t) ptr[10];\n state.vmv2 = (int8_t) ptr[11];\n ebits = 8 * pos - bit_pos;\n len = pos - (buf - buf_base);\n mb_info_pos++;\n } else {\n av_log(s1, AV_LOG_ERROR,\n "Unable to split H.263 packet, use -mb_info %d "\n "or lower.\\n", s->max_payload_size - 8);\n }\n } else {\n av_log(s1, AV_LOG_ERROR, "Unable to split H.263 packet, "\n "use -mb_info %d or -ps 1.\\n",\n s->max_payload_size - 8);\n }\n }\n }\n if (size > 2 && !buf[0] && !buf[1])\n send_mode_a(s1, &info, buf, len, ebits, len == size);\n else\n send_mode_b(s1, &info, &packet_start_state, buf, len, sbits,\n ebits, len == size);\n if (ebits) {\n sbits = 8 - ebits;\n len--;\n } else {\n sbits = 0;\n }\n buf += len;\n size -= len;\n ebits = 0;\n }\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
1,180
| 0
|
https://github.com/libav/libav/blob/7c152a458d3fb0a2fb1aef1f05bfee90fe70697e/libavutil/log.c/#L106
|
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
{
static int print_prefix=1;
static int count;
static char prev[1024];
char line[1024];
static int is_atty;
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
if(level>av_log_level)
return;
line[0]=0;
#undef fprintf
if(print_prefix && avc) {
if (avc->parent_log_context_offset) {
AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset);
if(parent && *parent){
snprintf(line, sizeof(line), "[%s @ %p] ", (*parent)->item_name(parent), parent);
}
}
snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr);
}
vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
print_prefix= line[strlen(line)-1] == '\n';
#if HAVE_ISATTY
if(!is_atty) is_atty= isatty(2) ? 1 : -1;
#endif
if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strncmp(line, prev, sizeof line)){
count++;
if(is_atty==1)
fprintf(stderr, " Last message repeated %d times\r", count);
return;
}
if(count>0){
fprintf(stderr, " Last message repeated %d times\n", count);
count=0;
}
colored_fputs(av_clip(level>>3, 0, 6), line);
strncpy(prev, line, sizeof line);
}
|
['void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)\n{\n static int print_prefix=1;\n static int count;\n static char prev[1024];\n char line[1024];\n static int is_atty;\n AVClass* avc= ptr ? *(AVClass**)ptr : NULL;\n if(level>av_log_level)\n return;\n line[0]=0;\n#undef fprintf\n if(print_prefix && avc) {\n if (avc->parent_log_context_offset) {\n AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset);\n if(parent && *parent){\n snprintf(line, sizeof(line), "[%s @ %p] ", (*parent)->item_name(parent), parent);\n }\n }\n snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr);\n }\n vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);\n print_prefix= line[strlen(line)-1] == \'\\n\';\n#if HAVE_ISATTY\n if(!is_atty) is_atty= isatty(2) ? 1 : -1;\n#endif\n if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strncmp(line, prev, sizeof line)){\n count++;\n if(is_atty==1)\n fprintf(stderr, " Last message repeated %d times\\r", count);\n return;\n }\n if(count>0){\n fprintf(stderr, " Last message repeated %d times\\n", count);\n count=0;\n }\n colored_fputs(av_clip(level>>3, 0, 6), line);\n strncpy(prev, line, sizeof line);\n}']
|
1,181
| 0
|
https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/faandct.c/#L118
|
static av_always_inline void row_fdct(FLOAT temp[64], int16_t *data)
{
FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
FLOAT tmp10, tmp11, tmp12, tmp13;
FLOAT z2, z4, z11, z13;
FLOAT av_unused z5;
int i;
for (i=0; i<8*8; i+=8) {
tmp0= data[0 + i] + data[7 + i];
tmp7= data[0 + i] - data[7 + i];
tmp1= data[1 + i] + data[6 + i];
tmp6= data[1 + i] - data[6 + i];
tmp2= data[2 + i] + data[5 + i];
tmp5= data[2 + i] - data[5 + i];
tmp3= data[3 + i] + data[4 + i];
tmp4= data[3 + i] - data[4 + i];
tmp10= tmp0 + tmp3;
tmp13= tmp0 - tmp3;
tmp11= tmp1 + tmp2;
tmp12= tmp1 - tmp2;
temp[0 + i]= tmp10 + tmp11;
temp[4 + i]= tmp10 - tmp11;
tmp12 += tmp13;
tmp12 *= A1;
temp[2 + i]= tmp13 + tmp12;
temp[6 + i]= tmp13 - tmp12;
tmp4 += tmp5;
tmp5 += tmp6;
tmp6 += tmp7;
#if 0
z5= (tmp4 - tmp6) * A5;
z2= tmp4*A2 + z5;
z4= tmp6*A4 + z5;
#else
z2= tmp4*(A2+A5) - tmp6*A5;
z4= tmp6*(A4-A5) + tmp4*A5;
#endif
tmp5*=A1;
z11= tmp7 + tmp5;
z13= tmp7 - tmp5;
temp[5 + i]= z13 + z2;
temp[3 + i]= z13 - z2;
temp[1 + i]= z11 + z4;
temp[7 + i]= z11 - z4;
}
}
|
['void ff_faandct(int16_t *data)\n{\n FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n FLOAT tmp10, tmp11, tmp12, tmp13;\n FLOAT z2, z4, z11, z13;\n FLOAT av_unused z5;\n FLOAT temp[64];\n int i;\n emms_c();\n row_fdct(temp, data);\n for (i=0; i<8; i++) {\n tmp0= temp[8*0 + i] + temp[8*7 + i];\n tmp7= temp[8*0 + i] - temp[8*7 + i];\n tmp1= temp[8*1 + i] + temp[8*6 + i];\n tmp6= temp[8*1 + i] - temp[8*6 + i];\n tmp2= temp[8*2 + i] + temp[8*5 + i];\n tmp5= temp[8*2 + i] - temp[8*5 + i];\n tmp3= temp[8*3 + i] + temp[8*4 + i];\n tmp4= temp[8*3 + i] - temp[8*4 + i];\n tmp10= tmp0 + tmp3;\n tmp13= tmp0 - tmp3;\n tmp11= tmp1 + tmp2;\n tmp12= tmp1 - tmp2;\n data[8*0 + i]= lrintf(postscale[8*0 + i] * (tmp10 + tmp11));\n data[8*4 + i]= lrintf(postscale[8*4 + i] * (tmp10 - tmp11));\n tmp12 += tmp13;\n tmp12 *= A1;\n data[8*2 + i]= lrintf(postscale[8*2 + i] * (tmp13 + tmp12));\n data[8*6 + i]= lrintf(postscale[8*6 + i] * (tmp13 - tmp12));\n tmp4 += tmp5;\n tmp5 += tmp6;\n tmp6 += tmp7;\n#if 0\n z5= (tmp4 - tmp6) * A5;\n z2= tmp4*A2 + z5;\n z4= tmp6*A4 + z5;\n#else\n z2= tmp4*(A2+A5) - tmp6*A5;\n z4= tmp6*(A4-A5) + tmp4*A5;\n#endif\n tmp5*=A1;\n z11= tmp7 + tmp5;\n z13= tmp7 - tmp5;\n data[8*5 + i]= lrintf(postscale[8*5 + i] * (z13 + z2));\n data[8*3 + i]= lrintf(postscale[8*3 + i] * (z13 - z2));\n data[8*1 + i]= lrintf(postscale[8*1 + i] * (z11 + z4));\n data[8*7 + i]= lrintf(postscale[8*7 + i] * (z11 - z4));\n }\n}', 'static av_always_inline void row_fdct(FLOAT temp[64], int16_t *data)\n{\n FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n FLOAT tmp10, tmp11, tmp12, tmp13;\n FLOAT z2, z4, z11, z13;\n FLOAT av_unused z5;\n int i;\n for (i=0; i<8*8; i+=8) {\n tmp0= data[0 + i] + data[7 + i];\n tmp7= data[0 + i] - data[7 + i];\n tmp1= data[1 + i] + data[6 + i];\n tmp6= data[1 + i] - data[6 + i];\n tmp2= data[2 + i] + data[5 + i];\n tmp5= data[2 + i] - data[5 + i];\n tmp3= data[3 + i] + data[4 + i];\n tmp4= data[3 + i] - data[4 + i];\n tmp10= tmp0 + tmp3;\n tmp13= tmp0 - tmp3;\n tmp11= tmp1 + tmp2;\n tmp12= tmp1 - tmp2;\n temp[0 + i]= tmp10 + tmp11;\n temp[4 + i]= tmp10 - tmp11;\n tmp12 += tmp13;\n tmp12 *= A1;\n temp[2 + i]= tmp13 + tmp12;\n temp[6 + i]= tmp13 - tmp12;\n tmp4 += tmp5;\n tmp5 += tmp6;\n tmp6 += tmp7;\n#if 0\n z5= (tmp4 - tmp6) * A5;\n z2= tmp4*A2 + z5;\n z4= tmp6*A4 + z5;\n#else\n z2= tmp4*(A2+A5) - tmp6*A5;\n z4= tmp6*(A4-A5) + tmp4*A5;\n#endif\n tmp5*=A1;\n z11= tmp7 + tmp5;\n z13= tmp7 - tmp5;\n temp[5 + i]= z13 + z2;\n temp[3 + i]= z13 - z2;\n temp[1 + i]= z11 + z4;\n temp[7 + i]= z11 - z4;\n }\n}']
|
1,182
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/alac.c/#L545
|
static int alac_decode_frame(AVCodecContext *avctx,
void *outbuffer, int *outputsize,
const uint8_t *inbuffer, int input_buffer_size)
{
ALACContext *alac = avctx->priv_data;
int channels;
int32_t outputsamples;
int hassize;
int readsamplesize;
int wasted_bytes;
int isnotcompressed;
uint8_t interlacing_shift;
uint8_t interlacing_leftweight;
if (!inbuffer || !input_buffer_size)
return input_buffer_size;
if (!alac->context_initialized) {
if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {
av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",
ALAC_EXTRADATA_SIZE);
return input_buffer_size;
}
if (alac_set_info(alac)) {
av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");
return input_buffer_size;
}
alac->context_initialized = 1;
}
init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
channels = get_bits(&alac->gb, 3) + 1;
if (channels > MAX_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n",
MAX_CHANNELS);
return input_buffer_size;
}
skip_bits(&alac->gb, 4);
skip_bits(&alac->gb, 12);
hassize = get_bits1(&alac->gb);
wasted_bytes = get_bits(&alac->gb, 2);
isnotcompressed = get_bits1(&alac->gb);
if (hassize) {
outputsamples = get_bits(&alac->gb, 32);
} else
outputsamples = alac->setinfo_max_samples_per_frame;
*outputsize = outputsamples * alac->bytespersample;
readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + channels - 1;
if (!isnotcompressed) {
int16_t predictor_coef_table[channels][32];
int predictor_coef_num[channels];
int prediction_type[channels];
int prediction_quantitization[channels];
int ricemodifier[channels];
int i, chan;
interlacing_shift = get_bits(&alac->gb, 8);
interlacing_leftweight = get_bits(&alac->gb, 8);
for (chan = 0; chan < channels; chan++) {
prediction_type[chan] = get_bits(&alac->gb, 4);
prediction_quantitization[chan] = get_bits(&alac->gb, 4);
ricemodifier[chan] = get_bits(&alac->gb, 3);
predictor_coef_num[chan] = get_bits(&alac->gb, 5);
for (i = 0; i < predictor_coef_num[chan]; i++)
predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);
}
if (wasted_bytes)
av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n");
for (chan = 0; chan < channels; chan++) {
bastardized_rice_decompress(alac,
alac->predicterror_buffer[chan],
outputsamples,
readsamplesize,
alac->setinfo_rice_initialhistory,
alac->setinfo_rice_kmodifier,
ricemodifier[chan] * alac->setinfo_rice_historymult / 4,
(1 << alac->setinfo_rice_kmodifier) - 1);
if (prediction_type[chan] == 0) {
predictor_decompress_fir_adapt(alac->predicterror_buffer[chan],
alac->outputsamples_buffer[chan],
outputsamples,
readsamplesize,
predictor_coef_table[chan],
predictor_coef_num[chan],
prediction_quantitization[chan]);
} else {
av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);
}
}
} else {
if (alac->setinfo_sample_size <= 16) {
int i, chan;
for (chan = 0; chan < channels; chan++)
for (i = 0; i < outputsamples; i++) {
int32_t audiobits;
audiobits = get_bits(&alac->gb, alac->setinfo_sample_size);
audiobits = extend_sign32(audiobits, readsamplesize);
alac->outputsamples_buffer[chan][i] = audiobits;
}
} else {
int i, chan;
for (chan = 0; chan < channels; chan++)
for (i = 0; i < outputsamples; i++) {
int32_t audiobits;
audiobits = get_bits(&alac->gb, 16);
audiobits = audiobits << 16;
audiobits = audiobits >> (32 - alac->setinfo_sample_size);
audiobits |= get_bits(&alac->gb, alac->setinfo_sample_size - 16);
alac->outputsamples_buffer[chan][i] = audiobits;
}
}
interlacing_shift = 0;
interlacing_leftweight = 0;
}
switch(alac->setinfo_sample_size) {
case 16:
if (channels == 2) {
reconstruct_stereo_16(alac->outputsamples_buffer,
(int16_t*)outbuffer,
alac->numchannels,
outputsamples,
interlacing_shift,
interlacing_leftweight);
} else {
int i;
for (i = 0; i < outputsamples; i++) {
int16_t sample = alac->outputsamples_buffer[0][i];
((int16_t*)outbuffer)[i * alac->numchannels] = sample;
}
}
break;
case 20:
case 24:
case 32:
av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size);
break;
default:
break;
}
return input_buffer_size;
}
|
['static int alac_decode_frame(AVCodecContext *avctx,\n void *outbuffer, int *outputsize,\n const uint8_t *inbuffer, int input_buffer_size)\n{\n ALACContext *alac = avctx->priv_data;\n int channels;\n int32_t outputsamples;\n int hassize;\n int readsamplesize;\n int wasted_bytes;\n int isnotcompressed;\n uint8_t interlacing_shift;\n uint8_t interlacing_leftweight;\n if (!inbuffer || !input_buffer_size)\n return input_buffer_size;\n if (!alac->context_initialized) {\n if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {\n av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\\n",\n ALAC_EXTRADATA_SIZE);\n return input_buffer_size;\n }\n if (alac_set_info(alac)) {\n av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\\n");\n return input_buffer_size;\n }\n alac->context_initialized = 1;\n }\n init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);\n channels = get_bits(&alac->gb, 3) + 1;\n if (channels > MAX_CHANNELS) {\n av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\\n",\n MAX_CHANNELS);\n return input_buffer_size;\n }\n skip_bits(&alac->gb, 4);\n skip_bits(&alac->gb, 12);\n hassize = get_bits1(&alac->gb);\n wasted_bytes = get_bits(&alac->gb, 2);\n isnotcompressed = get_bits1(&alac->gb);\n if (hassize) {\n outputsamples = get_bits(&alac->gb, 32);\n } else\n outputsamples = alac->setinfo_max_samples_per_frame;\n *outputsize = outputsamples * alac->bytespersample;\n readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + channels - 1;\n if (!isnotcompressed) {\n int16_t predictor_coef_table[channels][32];\n int predictor_coef_num[channels];\n int prediction_type[channels];\n int prediction_quantitization[channels];\n int ricemodifier[channels];\n int i, chan;\n interlacing_shift = get_bits(&alac->gb, 8);\n interlacing_leftweight = get_bits(&alac->gb, 8);\n for (chan = 0; chan < channels; chan++) {\n prediction_type[chan] = get_bits(&alac->gb, 4);\n prediction_quantitization[chan] = get_bits(&alac->gb, 4);\n ricemodifier[chan] = get_bits(&alac->gb, 3);\n predictor_coef_num[chan] = get_bits(&alac->gb, 5);\n for (i = 0; i < predictor_coef_num[chan]; i++)\n predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);\n }\n if (wasted_bytes)\n av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\\n");\n for (chan = 0; chan < channels; chan++) {\n bastardized_rice_decompress(alac,\n alac->predicterror_buffer[chan],\n outputsamples,\n readsamplesize,\n alac->setinfo_rice_initialhistory,\n alac->setinfo_rice_kmodifier,\n ricemodifier[chan] * alac->setinfo_rice_historymult / 4,\n (1 << alac->setinfo_rice_kmodifier) - 1);\n if (prediction_type[chan] == 0) {\n predictor_decompress_fir_adapt(alac->predicterror_buffer[chan],\n alac->outputsamples_buffer[chan],\n outputsamples,\n readsamplesize,\n predictor_coef_table[chan],\n predictor_coef_num[chan],\n prediction_quantitization[chan]);\n } else {\n av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\\n", prediction_type[chan]);\n }\n }\n } else {\n if (alac->setinfo_sample_size <= 16) {\n int i, chan;\n for (chan = 0; chan < channels; chan++)\n for (i = 0; i < outputsamples; i++) {\n int32_t audiobits;\n audiobits = get_bits(&alac->gb, alac->setinfo_sample_size);\n audiobits = extend_sign32(audiobits, readsamplesize);\n alac->outputsamples_buffer[chan][i] = audiobits;\n }\n } else {\n int i, chan;\n for (chan = 0; chan < channels; chan++)\n for (i = 0; i < outputsamples; i++) {\n int32_t audiobits;\n audiobits = get_bits(&alac->gb, 16);\n audiobits = audiobits << 16;\n audiobits = audiobits >> (32 - alac->setinfo_sample_size);\n audiobits |= get_bits(&alac->gb, alac->setinfo_sample_size - 16);\n alac->outputsamples_buffer[chan][i] = audiobits;\n }\n }\n interlacing_shift = 0;\n interlacing_leftweight = 0;\n }\n switch(alac->setinfo_sample_size) {\n case 16:\n if (channels == 2) {\n reconstruct_stereo_16(alac->outputsamples_buffer,\n (int16_t*)outbuffer,\n alac->numchannels,\n outputsamples,\n interlacing_shift,\n interlacing_leftweight);\n } else {\n int i;\n for (i = 0; i < outputsamples; i++) {\n int16_t sample = alac->outputsamples_buffer[0][i];\n ((int16_t*)outbuffer)[i * alac->numchannels] = sample;\n }\n }\n break;\n case 20:\n case 24:\n case 32:\n av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\\n", alac->setinfo_sample_size);\n break;\n default:\n break;\n }\n return input_buffer_size;\n}']
|
1,183
| 0
|
https://github.com/libav/libav/blob/c433a3f9a5ead7bd107384e20ea21de9f4c3f911/libavcodec/mpc7.c/#L83
|
static av_cold int mpc7_decode_init(AVCodecContext * avctx)
{
int i, j;
MPCContext *c = avctx->priv_data;
GetBitContext gb;
uint8_t buf[16];
static int vlc_initialized = 0;
static VLC_TYPE scfi_table[1 << MPC7_SCFI_BITS][2];
static VLC_TYPE dscf_table[1 << MPC7_DSCF_BITS][2];
static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2];
static VLC_TYPE quant_tables[7224][2];
if (avctx->channels != 2) {
av_log_ask_for_sample(avctx, "Unsupported number of channels: %d\n",
avctx->channels);
return AVERROR_PATCHWELCOME;
}
if(avctx->extradata_size < 16){
av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
return -1;
}
memset(c->oldDSCF, 0, sizeof(c->oldDSCF));
av_lfg_init(&c->rnd, 0xDEADBEEF);
dsputil_init(&c->dsp, avctx);
ff_mpadsp_init(&c->mpadsp);
c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4);
ff_mpc_init();
init_get_bits(&gb, buf, 128);
c->IS = get_bits1(&gb);
c->MSS = get_bits1(&gb);
c->maxbands = get_bits(&gb, 6);
if(c->maxbands >= BANDS){
av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->maxbands);
return -1;
}
skip_bits_long(&gb, 88);
c->gapless = get_bits1(&gb);
c->lastframelen = get_bits(&gb, 11);
av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n",
c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);
c->frames_to_skip = 0;
avctx->sample_fmt = AV_SAMPLE_FMT_S16;
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
if(vlc_initialized) return 0;
av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
scfi_vlc.table = scfi_table;
scfi_vlc.table_allocated = 1 << MPC7_SCFI_BITS;
if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,
&mpc7_scfi[1], 2, 1,
&mpc7_scfi[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n");
return -1;
}
dscf_vlc.table = dscf_table;
dscf_vlc.table_allocated = 1 << MPC7_DSCF_BITS;
if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,
&mpc7_dscf[1], 2, 1,
&mpc7_dscf[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n");
return -1;
}
hdr_vlc.table = hdr_table;
hdr_vlc.table_allocated = 1 << MPC7_HDR_BITS;
if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,
&mpc7_hdr[1], 2, 1,
&mpc7_hdr[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n");
return -1;
}
for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){
for(j = 0; j < 2; j++){
quant_vlc[i][j].table = &quant_tables[quant_offsets[i*2 + j]];
quant_vlc[i][j].table_allocated = quant_offsets[i*2 + j + 1] - quant_offsets[i*2 + j];
if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],
&mpc7_quant_vlc[i][j][1], 4, 2,
&mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_NEW_STATIC)){
av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j);
return -1;
}
}
}
vlc_initialized = 1;
return 0;
}
|
['static av_cold int mpc7_decode_init(AVCodecContext * avctx)\n{\n int i, j;\n MPCContext *c = avctx->priv_data;\n GetBitContext gb;\n uint8_t buf[16];\n static int vlc_initialized = 0;\n static VLC_TYPE scfi_table[1 << MPC7_SCFI_BITS][2];\n static VLC_TYPE dscf_table[1 << MPC7_DSCF_BITS][2];\n static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2];\n static VLC_TYPE quant_tables[7224][2];\n if (avctx->channels != 2) {\n av_log_ask_for_sample(avctx, "Unsupported number of channels: %d\\n",\n avctx->channels);\n return AVERROR_PATCHWELCOME;\n }\n if(avctx->extradata_size < 16){\n av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\\n", avctx->extradata_size);\n return -1;\n }\n memset(c->oldDSCF, 0, sizeof(c->oldDSCF));\n av_lfg_init(&c->rnd, 0xDEADBEEF);\n dsputil_init(&c->dsp, avctx);\n ff_mpadsp_init(&c->mpadsp);\n c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4);\n ff_mpc_init();\n init_get_bits(&gb, buf, 128);\n c->IS = get_bits1(&gb);\n c->MSS = get_bits1(&gb);\n c->maxbands = get_bits(&gb, 6);\n if(c->maxbands >= BANDS){\n av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\\n", c->maxbands);\n return -1;\n }\n skip_bits_long(&gb, 88);\n c->gapless = get_bits1(&gb);\n c->lastframelen = get_bits(&gb, 11);\n av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\\n",\n c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands);\n c->frames_to_skip = 0;\n avctx->sample_fmt = AV_SAMPLE_FMT_S16;\n avctx->channel_layout = AV_CH_LAYOUT_STEREO;\n if(vlc_initialized) return 0;\n av_log(avctx, AV_LOG_DEBUG, "Initing VLC\\n");\n scfi_vlc.table = scfi_table;\n scfi_vlc.table_allocated = 1 << MPC7_SCFI_BITS;\n if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE,\n &mpc7_scfi[1], 2, 1,\n &mpc7_scfi[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){\n av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\\n");\n return -1;\n }\n dscf_vlc.table = dscf_table;\n dscf_vlc.table_allocated = 1 << MPC7_DSCF_BITS;\n if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE,\n &mpc7_dscf[1], 2, 1,\n &mpc7_dscf[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){\n av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\\n");\n return -1;\n }\n hdr_vlc.table = hdr_table;\n hdr_vlc.table_allocated = 1 << MPC7_HDR_BITS;\n if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE,\n &mpc7_hdr[1], 2, 1,\n &mpc7_hdr[0], 2, 1, INIT_VLC_USE_NEW_STATIC)){\n av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\\n");\n return -1;\n }\n for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){\n for(j = 0; j < 2; j++){\n quant_vlc[i][j].table = &quant_tables[quant_offsets[i*2 + j]];\n quant_vlc[i][j].table_allocated = quant_offsets[i*2 + j + 1] - quant_offsets[i*2 + j];\n if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i],\n &mpc7_quant_vlc[i][j][1], 4, 2,\n &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_NEW_STATIC)){\n av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\\n",i,j);\n return -1;\n }\n }\n }\n vlc_initialized = 1;\n return 0;\n}', 'void ff_mpadsp_init(MPADSPContext *s)\n{\n DCTContext dct;\n ff_dct_init(&dct, 5, DCT_II);\n s->apply_window_float = ff_mpadsp_apply_window_float;\n s->apply_window_fixed = ff_mpadsp_apply_window_fixed;\n s->dct32_float = dct.dct32;\n s->dct32_fixed = ff_dct32_fixed;\n if (ARCH_ARM) ff_mpadsp_init_arm(s);\n if (HAVE_MMX) ff_mpadsp_init_mmx(s);\n if (HAVE_ALTIVEC) ff_mpadsp_init_altivec(s);\n}', 'void ff_mpc_init(void)\n{\n ff_mpa_synth_init_fixed(ff_mpa_synth_window_fixed);\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n s->buffer_end = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index = 0;\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3);\n s->bit_count = 32 + 8*((intptr_t)buffer & 3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n index++;\n s->index = index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
|
1,184
| 0
|
https://github.com/openssl/openssl/blob/f3ff481f318b10a223d6157bde9645e1797487c5/ssl/packet.c/#L25
|
int WPACKET_allocate_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;
if (pkt->buf->length > SIZE_MAX / 2) {
newlen = SIZE_MAX;
} else {
newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE
: pkt->buf->length * 2;
}
if (BUF_MEM_grow(pkt->buf, newlen) == 0)
return 0;
}
*allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;
pkt->written += len;
pkt->curr += len;
return 1;
}
|
['int ssl_add_clienthello_tlsext(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_EC\n int using_ecc = 0;\n if (s->version >= TLS1_VERSION || SSL_IS_DTLS(s)) {\n int i;\n unsigned long alg_k, alg_a;\n STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);\n for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {\n const SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);\n alg_k = c->algorithm_mkey;\n alg_a = c->algorithm_auth;\n if ((alg_k & (SSL_kECDHE | SSL_kECDHEPSK))\n || (alg_a & SSL_aECDSA)) {\n using_ecc = 1;\n break;\n }\n }\n }\n#endif\n if (s->renegotiate) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_renegotiate)\n || !WPACKET_sub_memcpy_u16(pkt, s->s3->previous_client_finished,\n s->s3->previous_client_finished_len)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (s->client_version == SSL3_VERSION)\n goto done;\n if (s->tlsext_hostname != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_server_name)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_NAMETYPE_host_name)\n || !WPACKET_sub_memcpy_u16(pkt, s->tlsext_hostname,\n strlen(s->tlsext_hostname))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_SRP\n if (s->srp_ctx.login != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u8(pkt)\n || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)\n || !WPACKET_memcpy(pkt, s->srp_ctx.login,\n strlen(s->srp_ctx.login))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_EC\n if (using_ecc) {\n const unsigned char *pcurves, *pformats;\n size_t num_curves, num_formats;\n size_t i;\n tls1_get_formatlist(s, &pformats, &num_formats);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_ec_point_formats)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u8(pkt, pformats, num_formats)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pcurves = s->tlsext_ellipticcurvelist;\n if (!tls1_get_curvelist(s, 0, &pcurves, &num_curves)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_elliptic_curves)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < num_curves; i++, pcurves += 2) {\n if (tls_curve_allowed(s, pcurves, SSL_SECOP_CURVE_SUPPORTED)) {\n if (!WPACKET_put_bytes_u8(pkt, pcurves[0])\n || !WPACKET_put_bytes_u8(pkt, pcurves[1])) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (tls_use_ticket(s)) {\n int ticklen;\n if (!s->new_session && s->session && s->session->tlsext_tick)\n ticklen = s->session->tlsext_ticklen;\n else if (s->session && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data) {\n ticklen = s->tlsext_session_ticket->length;\n s->session->tlsext_tick = OPENSSL_malloc(ticklen);\n if (s->session->tlsext_tick == NULL) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memcpy(s->session->tlsext_tick,\n s->tlsext_session_ticket->data, ticklen);\n s->session->tlsext_ticklen = ticklen;\n } else\n ticklen = 0;\n if (ticklen == 0 && s->tlsext_session_ticket &&\n s->tlsext_session_ticket->data == NULL)\n goto skip_ext;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_session_ticket)\n || !WPACKET_sub_memcpy_u16(pkt, s->session->tlsext_tick,\n ticklen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n skip_ext:\n if (SSL_CLIENT_USE_SIGALGS(s)) {\n size_t salglen;\n const unsigned char *salg;\n salglen = tls12_get_psigalgs(s, &salg);\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signature_algorithms)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !tls12_copy_sigalgs(s, pkt, salg, salglen)\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#ifndef OPENSSL_NO_OCSP\n if (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp) {\n int i;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_status_request)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, TLSEXT_STATUSTYPE_ocsp)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {\n unsigned char *idbytes;\n int idlen;\n OCSP_RESPID *id;\n id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids, i);\n idlen = i2d_OCSP_RESPID(id, NULL);\n if (idlen <= 0\n || !WPACKET_sub_allocate_bytes_u16(pkt, idlen, &idbytes)\n || i2d_OCSP_RESPID(id, &idbytes) != idlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->tlsext_ocsp_exts) {\n unsigned char *extbytes;\n int extlen = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, NULL);\n if (extlen < 0) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_allocate_bytes(pkt, extlen, &extbytes)\n || i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &extbytes)\n != extlen) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_HEARTBEATS\n if (SSL_IS_DTLS(s)) {\n unsigned int mode;\n if (s->tlsext_heartbeat & SSL_DTLSEXT_HB_DONT_RECV_REQUESTS)\n mode = SSL_DTLSEXT_HB_DONT_SEND_REQUESTS;\n else\n mode = SSL_DTLSEXT_HB_ENABLED;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_heartbeat)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_put_bytes_u8(pkt, mode)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n if (s->ctx->next_proto_select_cb && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_next_proto_neg)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) {\n if (!WPACKET_put_bytes_u16(pkt,\n TLSEXT_TYPE_application_layer_protocol_negotiation)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_sub_memcpy_u16(pkt, s->alpn_client_proto_list,\n s->alpn_client_proto_list_len)\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n s->s3->alpn_sent = 1;\n }\n#ifndef OPENSSL_NO_SRTP\n if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) {\n STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = 0;\n SRTP_PROTECTION_PROFILE *prof;\n int i, ct;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_use_srtp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n ct = sk_SRTP_PROTECTION_PROFILE_num(clnt);\n for (i = 0; i < ct; i++) {\n prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i);\n if (prof == NULL || !WPACKET_put_bytes_u16(pkt, prof->id)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_close(pkt) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n custom_ext_init(&s->cert->cli_ext);\n if (!custom_ext_add(s, 0, pkt, al)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_encrypt_then_mac)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n#ifndef OPENSSL_NO_CT\n if (s->ct_validation_callback != NULL) {\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_signed_certificate_timestamp)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n#endif\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_extended_master_secret)\n || !WPACKET_put_bytes_u16(pkt, 0)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->options & SSL_OP_TLSEXT_PADDING) {\n unsigned char *padbytes;\n size_t hlen;\n if (!WPACKET_get_total_written(pkt, &hlen)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (hlen > 0xff && hlen < 0x200) {\n hlen = 0x200 - hlen;\n if (hlen >= 4)\n hlen -= 4;\n else\n hlen = 0;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_padding)\n || !WPACKET_sub_allocate_bytes_u16(pkt, hlen, &padbytes)) {\n SSLerr(SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n memset(padbytes, 0, hlen);\n }\n }\n done:\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - (unsigned char *)pkt->buf->data;\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_allocate_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 if (pkt->buf->length > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = (pkt->buf->length == 0) ? DEFAULT_BUF_SIZE\n : pkt->buf->length * 2;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}']
|
1,185
| 0
|
https://github.com/libav/libav/blob/cdee08e36582e443ff8a9bed17ec409551c9f93b/avconv.c/#L4713
|
static int opt_vstats(const char *opt, const char *arg)
{
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);
return opt_vstats_file(opt, filename);
}
|
['static int opt_vstats(const char *opt, const char *arg)\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 return opt_vstats_file(opt, filename);\n}']
|
1,186
| 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 ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_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 = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,187
| 0
|
https://github.com/libav/libav/blob/65dd2ded3ffe26602e180c40b31c325ad0adba28/ffmpeg.c/#L3693
|
static void opt_output_file(const char *filename)
{
AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle;
int input_has_video, input_has_audio, input_has_subtitle;
AVFormatParameters params, *ap = ¶ms;
AVOutputFormat *file_oformat;
if (!strcmp(filename, "-"))
filename = "pipe:";
oc = avformat_alloc_context();
if (!oc) {
print_error(filename, AVERROR(ENOMEM));
av_exit(1);
}
if (last_asked_format) {
file_oformat = av_guess_format(last_asked_format, NULL, NULL);
if (!file_oformat) {
fprintf(stderr, "Requested output format '%s' is not a suitable output format\n", last_asked_format);
av_exit(1);
}
last_asked_format = NULL;
} else {
file_oformat = av_guess_format(NULL, filename, NULL);
if (!file_oformat) {
fprintf(stderr, "Unable to find a suitable output format for '%s'\n",
filename);
av_exit(1);
}
}
oc->oformat = file_oformat;
av_strlcpy(oc->filename, filename, sizeof(oc->filename));
if (!strcmp(file_oformat->name, "ffm") &&
av_strstart(filename, "http:", NULL)) {
int err = read_ffserver_streams(oc, filename);
if (err < 0) {
print_error(filename, err);
av_exit(1);
}
} else {
use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;
use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;
use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;
if (nb_input_files > 0) {
check_audio_video_sub_inputs(&input_has_video, &input_has_audio,
&input_has_subtitle);
if (!input_has_video)
use_video = 0;
if (!input_has_audio)
use_audio = 0;
if (!input_has_subtitle)
use_subtitle = 0;
}
if (audio_disable) {
use_audio = 0;
}
if (video_disable) {
use_video = 0;
}
if (subtitle_disable) {
use_subtitle = 0;
}
if (use_video) {
new_video_stream(oc);
}
if (use_audio) {
new_audio_stream(oc);
}
if (use_subtitle) {
new_subtitle_stream(oc);
}
oc->timestamp = recording_timestamp;
for(; metadata_count>0; metadata_count--){
av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key,
metadata[metadata_count-1].value, 0);
}
av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);
}
output_files[nb_output_files++] = oc;
if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
if (!av_filename_number_test(oc->filename)) {
print_error(oc->filename, AVERROR_NUMEXPECTED);
av_exit(1);
}
}
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
if (!file_overwrite &&
(strchr(filename, ':') == NULL ||
filename[1] == ':' ||
av_strstart(filename, "file:", NULL))) {
if (url_exist(filename)) {
if (!using_stdin) {
fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
fflush(stderr);
if (!read_yesno()) {
fprintf(stderr, "Not overwriting - exiting\n");
av_exit(1);
}
}
else {
fprintf(stderr,"File '%s' already exists. Exiting.\n", filename);
av_exit(1);
}
}
}
if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {
print_error(filename, err);
av_exit(1);
}
}
memset(ap, 0, sizeof(*ap));
if (av_set_parameters(oc, ap) < 0) {
fprintf(stderr, "%s: Invalid encoding parameters\n",
oc->filename);
av_exit(1);
}
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);
memset(streamid_map, 0, sizeof(streamid_map));
}
|
['static void opt_output_file(const char *filename)\n{\n AVFormatContext *oc;\n int err, use_video, use_audio, use_subtitle;\n int input_has_video, input_has_audio, input_has_subtitle;\n AVFormatParameters params, *ap = ¶ms;\n AVOutputFormat *file_oformat;\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n oc = avformat_alloc_context();\n if (!oc) {\n print_error(filename, AVERROR(ENOMEM));\n av_exit(1);\n }\n if (last_asked_format) {\n file_oformat = av_guess_format(last_asked_format, NULL, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Requested output format \'%s\' is not a suitable output format\\n", last_asked_format);\n av_exit(1);\n }\n last_asked_format = NULL;\n } else {\n file_oformat = av_guess_format(NULL, filename, NULL);\n if (!file_oformat) {\n fprintf(stderr, "Unable to find a suitable output format for \'%s\'\\n",\n filename);\n av_exit(1);\n }\n }\n oc->oformat = file_oformat;\n av_strlcpy(oc->filename, filename, sizeof(oc->filename));\n if (!strcmp(file_oformat->name, "ffm") &&\n av_strstart(filename, "http:", NULL)) {\n int err = read_ffserver_streams(oc, filename);\n if (err < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n } else {\n use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name;\n use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name;\n use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name;\n if (nb_input_files > 0) {\n check_audio_video_sub_inputs(&input_has_video, &input_has_audio,\n &input_has_subtitle);\n if (!input_has_video)\n use_video = 0;\n if (!input_has_audio)\n use_audio = 0;\n if (!input_has_subtitle)\n use_subtitle = 0;\n }\n if (audio_disable) {\n use_audio = 0;\n }\n if (video_disable) {\n use_video = 0;\n }\n if (subtitle_disable) {\n use_subtitle = 0;\n }\n if (use_video) {\n new_video_stream(oc);\n }\n if (use_audio) {\n new_audio_stream(oc);\n }\n if (use_subtitle) {\n new_subtitle_stream(oc);\n }\n oc->timestamp = recording_timestamp;\n for(; metadata_count>0; metadata_count--){\n av_metadata_set2(&oc->metadata, metadata[metadata_count-1].key,\n metadata[metadata_count-1].value, 0);\n }\n av_metadata_conv(oc, oc->oformat->metadata_conv, NULL);\n }\n output_files[nb_output_files++] = oc;\n if (oc->oformat->flags & AVFMT_NEEDNUMBER) {\n if (!av_filename_number_test(oc->filename)) {\n print_error(oc->filename, AVERROR_NUMEXPECTED);\n av_exit(1);\n }\n }\n if (!(oc->oformat->flags & AVFMT_NOFILE)) {\n if (!file_overwrite &&\n (strchr(filename, \':\') == NULL ||\n filename[1] == \':\' ||\n av_strstart(filename, "file:", NULL))) {\n if (url_exist(filename)) {\n if (!using_stdin) {\n fprintf(stderr,"File \'%s\' already exists. Overwrite ? [y/N] ", filename);\n fflush(stderr);\n if (!read_yesno()) {\n fprintf(stderr, "Not overwriting - exiting\\n");\n av_exit(1);\n }\n }\n else {\n fprintf(stderr,"File \'%s\' already exists. Exiting.\\n", filename);\n av_exit(1);\n }\n }\n }\n if ((err = url_fopen(&oc->pb, filename, URL_WRONLY)) < 0) {\n print_error(filename, err);\n av_exit(1);\n }\n }\n memset(ap, 0, sizeof(*ap));\n if (av_set_parameters(oc, ap) < 0) {\n fprintf(stderr, "%s: Invalid encoding parameters\\n",\n oc->filename);\n av_exit(1);\n }\n oc->preload= (int)(mux_preload*AV_TIME_BASE);\n oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);\n oc->loop_output = loop_output;\n oc->flags |= AVFMT_FLAG_NONBLOCK;\n set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);\n memset(streamid_map, 0, sizeof(streamid_map));\n}', 'AVFormatContext *avformat_alloc_context(void)\n{\n AVFormatContext *ic;\n ic = av_malloc(sizeof(AVFormatContext));\n if (!ic) return ic;\n avformat_get_context_defaults(ic);\n ic->av_class = &av_format_context_class;\n return ic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'void print_error(const char *filename, int err)\n{\n char errbuf[128];\n const char *errbuf_ptr = errbuf;\n if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)\n errbuf_ptr = strerror(AVUNERROR(err));\n fprintf(stderr, "%s: %s\\n", filename, errbuf_ptr);\n}', 'int av_strerror(int errnum, char *errbuf, size_t errbuf_size)\n{\n int ret = 0;\n const char *errstr = NULL;\n switch (errnum) {\n case AVERROR_EOF: errstr = "End of file"; break;\n case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input"; break;\n case AVERROR_NUMEXPECTED: errstr = "Number syntax expected in filename"; break;\n case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break;\n }\n if (errstr) {\n av_strlcpy(errbuf, errstr, errbuf_size);\n } else {\n#if HAVE_STRERROR_R\n ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);\n#else\n ret = -1;\n#endif\n if (ret < 0)\n snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);\n }\n return ret;\n}']
|
1,188
| 0
|
https://github.com/libav/libav/blob/a18ef7a76c735bcf78ed4825e33ad7f9f6f77a54/libavformat/mpegts.c/#L704
|
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
{
GetBitContext gb;
int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
int dts_flag = -1, cts_flag = -1;
int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;
init_get_bits(&gb, buf, buf_size*8);
if (sl->use_au_start)
au_start_flag = get_bits1(&gb);
if (sl->use_au_end)
au_end_flag = get_bits1(&gb);
if (!sl->use_au_start && !sl->use_au_end)
au_start_flag = au_end_flag = 1;
if (sl->ocr_len > 0)
ocr_flag = get_bits1(&gb);
if (sl->use_idle)
idle_flag = get_bits1(&gb);
if (sl->use_padding)
padding_flag = get_bits1(&gb);
if (padding_flag)
padding_bits = get_bits(&gb, 3);
if (!idle_flag && (!padding_flag || padding_bits != 0)) {
if (sl->packet_seq_num_len)
skip_bits_long(&gb, sl->packet_seq_num_len);
if (sl->degr_prior_len)
if (get_bits1(&gb))
skip_bits(&gb, sl->degr_prior_len);
if (ocr_flag)
skip_bits_long(&gb, sl->ocr_len);
if (au_start_flag) {
if (sl->use_rand_acc_pt)
get_bits1(&gb);
if (sl->au_seq_num_len > 0)
skip_bits_long(&gb, sl->au_seq_num_len);
if (sl->use_timestamps) {
dts_flag = get_bits1(&gb);
cts_flag = get_bits1(&gb);
}
}
if (sl->inst_bitrate_len)
inst_bitrate_flag = get_bits1(&gb);
if (dts_flag == 1)
dts = get_bits64(&gb, sl->timestamp_len);
if (cts_flag == 1)
cts = get_bits64(&gb, sl->timestamp_len);
if (sl->au_len > 0)
skip_bits_long(&gb, sl->au_len);
if (inst_bitrate_flag)
skip_bits_long(&gb, sl->inst_bitrate_len);
}
if (dts != AV_NOPTS_VALUE)
pes->dts = dts;
if (cts != AV_NOPTS_VALUE)
pes->pts = cts;
if (sl->timestamp_len && sl->timestamp_res)
avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);
return (get_bits_count(&gb) + 7) >> 3;
}
|
['static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)\n{\n GetBitContext gb;\n int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;\n int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;\n int dts_flag = -1, cts_flag = -1;\n int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;\n init_get_bits(&gb, buf, buf_size*8);\n if (sl->use_au_start)\n au_start_flag = get_bits1(&gb);\n if (sl->use_au_end)\n au_end_flag = get_bits1(&gb);\n if (!sl->use_au_start && !sl->use_au_end)\n au_start_flag = au_end_flag = 1;\n if (sl->ocr_len > 0)\n ocr_flag = get_bits1(&gb);\n if (sl->use_idle)\n idle_flag = get_bits1(&gb);\n if (sl->use_padding)\n padding_flag = get_bits1(&gb);\n if (padding_flag)\n padding_bits = get_bits(&gb, 3);\n if (!idle_flag && (!padding_flag || padding_bits != 0)) {\n if (sl->packet_seq_num_len)\n skip_bits_long(&gb, sl->packet_seq_num_len);\n if (sl->degr_prior_len)\n if (get_bits1(&gb))\n skip_bits(&gb, sl->degr_prior_len);\n if (ocr_flag)\n skip_bits_long(&gb, sl->ocr_len);\n if (au_start_flag) {\n if (sl->use_rand_acc_pt)\n get_bits1(&gb);\n if (sl->au_seq_num_len > 0)\n skip_bits_long(&gb, sl->au_seq_num_len);\n if (sl->use_timestamps) {\n dts_flag = get_bits1(&gb);\n cts_flag = get_bits1(&gb);\n }\n }\n if (sl->inst_bitrate_len)\n inst_bitrate_flag = get_bits1(&gb);\n if (dts_flag == 1)\n dts = get_bits64(&gb, sl->timestamp_len);\n if (cts_flag == 1)\n cts = get_bits64(&gb, sl->timestamp_len);\n if (sl->au_len > 0)\n skip_bits_long(&gb, sl->au_len);\n if (inst_bitrate_flag)\n skip_bits_long(&gb, sl->inst_bitrate_len);\n }\n if (dts != AV_NOPTS_VALUE)\n pes->dts = dts;\n if (cts != AV_NOPTS_VALUE)\n pes->pts = cts;\n if (sl->timestamp_len && sl->timestamp_res)\n avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);\n return (get_bits_count(&gb) + 7) >> 3;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
1,189
| 0
|
https://github.com/openssl/openssl/blob/f1429b85c5821e55224e5878da9d0fa420a41f71/test/evp_test.c/#L1814
|
static int encode_test_run(struct evp_test *t)
{
struct encode_data *edata = t->data;
unsigned char *encode_out = NULL, *decode_out = NULL;
int output_len, chunk_len;
const char *err = "INTERNAL_ERROR";
EVP_ENCODE_CTX *decode_ctx = EVP_ENCODE_CTX_new();
if (decode_ctx == NULL)
goto err;
if (edata->encoding == BASE64_CANONICAL_ENCODING) {
EVP_ENCODE_CTX *encode_ctx = EVP_ENCODE_CTX_new();
if (encode_ctx == NULL)
goto err;
encode_out = OPENSSL_malloc(EVP_ENCODE_LENGTH(edata->input_len));
if (encode_out == NULL)
goto err;
EVP_EncodeInit(encode_ctx);
EVP_EncodeUpdate(encode_ctx, encode_out, &chunk_len,
edata->input, edata->input_len);
output_len = chunk_len;
EVP_EncodeFinal(encode_ctx, encode_out + chunk_len, &chunk_len);
output_len += chunk_len;
EVP_ENCODE_CTX_free(encode_ctx);
if (check_var_length_output(t, edata->output, edata->output_len,
encode_out, output_len)) {
err = "BAD_ENCODING";
goto err;
}
}
decode_out = OPENSSL_malloc(EVP_DECODE_LENGTH(edata->output_len));
if (decode_out == NULL)
goto err;
EVP_DecodeInit(decode_ctx);
if (EVP_DecodeUpdate(decode_ctx, decode_out, &chunk_len, edata->output,
edata->output_len) < 0) {
err = "DECODE_ERROR";
goto err;
}
output_len = chunk_len;
if (EVP_DecodeFinal(decode_ctx, decode_out + chunk_len, &chunk_len) != 1) {
err = "DECODE_ERROR";
goto err;
}
output_len += chunk_len;
if (edata->encoding != BASE64_INVALID_ENCODING &&
check_var_length_output(t, edata->input, edata->input_len,
decode_out, output_len)) {
err = "BAD_DECODING";
goto err;
}
err = NULL;
err:
t->err = err;
OPENSSL_free(encode_out);
OPENSSL_free(decode_out);
EVP_ENCODE_CTX_free(decode_ctx);
return 1;
}
|
['static int encode_test_run(struct evp_test *t)\n{\n struct encode_data *edata = t->data;\n unsigned char *encode_out = NULL, *decode_out = NULL;\n int output_len, chunk_len;\n const char *err = "INTERNAL_ERROR";\n EVP_ENCODE_CTX *decode_ctx = EVP_ENCODE_CTX_new();\n if (decode_ctx == NULL)\n goto err;\n if (edata->encoding == BASE64_CANONICAL_ENCODING) {\n EVP_ENCODE_CTX *encode_ctx = EVP_ENCODE_CTX_new();\n if (encode_ctx == NULL)\n goto err;\n encode_out = OPENSSL_malloc(EVP_ENCODE_LENGTH(edata->input_len));\n if (encode_out == NULL)\n goto err;\n EVP_EncodeInit(encode_ctx);\n EVP_EncodeUpdate(encode_ctx, encode_out, &chunk_len,\n edata->input, edata->input_len);\n output_len = chunk_len;\n EVP_EncodeFinal(encode_ctx, encode_out + chunk_len, &chunk_len);\n output_len += chunk_len;\n EVP_ENCODE_CTX_free(encode_ctx);\n if (check_var_length_output(t, edata->output, edata->output_len,\n encode_out, output_len)) {\n err = "BAD_ENCODING";\n goto err;\n }\n }\n decode_out = OPENSSL_malloc(EVP_DECODE_LENGTH(edata->output_len));\n if (decode_out == NULL)\n goto err;\n EVP_DecodeInit(decode_ctx);\n if (EVP_DecodeUpdate(decode_ctx, decode_out, &chunk_len, edata->output,\n edata->output_len) < 0) {\n err = "DECODE_ERROR";\n goto err;\n }\n output_len = chunk_len;\n if (EVP_DecodeFinal(decode_ctx, decode_out + chunk_len, &chunk_len) != 1) {\n err = "DECODE_ERROR";\n goto err;\n }\n output_len += chunk_len;\n if (edata->encoding != BASE64_INVALID_ENCODING &&\n check_var_length_output(t, edata->input, edata->input_len,\n decode_out, output_len)) {\n err = "BAD_DECODING";\n goto err;\n }\n err = NULL;\n err:\n t->err = err;\n OPENSSL_free(encode_out);\n OPENSSL_free(decode_out);\n EVP_ENCODE_CTX_free(decode_ctx);\n return 1;\n}', 'EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,190
| 0
|
https://github.com/libav/libav/blob/e445647b4fdf481b13b2743b303d84de4f43bedd/libavcodec/flac_parser.c/#L97
|
static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,
FLACFrameInfo *fi)
{
GetBitContext gb;
init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);
return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);
}
|
['static int frame_header_is_valid(AVCodecContext *avctx, const uint8_t *buf,\n FLACFrameInfo *fi)\n{\n GetBitContext gb;\n init_get_bits(&gb, buf, MAX_FRAME_HEADER_SIZE * 8);\n return !ff_flac_decode_frame_header(avctx, &gb, fi, 127);\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,\n FLACFrameInfo *fi, int log_level_offset)\n{\n int bs_code, sr_code, bps_code;\n if ((get_bits(gb, 15) & 0x7FFF) != 0x7FFC) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset, "invalid sync code\\n");\n return -1;\n }\n fi->is_var_size = get_bits1(gb);\n bs_code = get_bits(gb, 4);\n sr_code = get_bits(gb, 4);\n fi->ch_mode = get_bits(gb, 4);\n if (fi->ch_mode < FLAC_MAX_CHANNELS) {\n fi->channels = fi->ch_mode + 1;\n fi->ch_mode = FLAC_CHMODE_INDEPENDENT;\n } else if (fi->ch_mode < FLAC_MAX_CHANNELS + FLAC_CHMODE_MID_SIDE) {\n fi->channels = 2;\n fi->ch_mode -= FLAC_MAX_CHANNELS - 1;\n } else {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "invalid channel mode: %d\\n", fi->ch_mode);\n return -1;\n }\n bps_code = get_bits(gb, 3);\n if (bps_code == 3 || bps_code == 7) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "invalid sample size code (%d)\\n",\n bps_code);\n return -1;\n }\n fi->bps = sample_size_table[bps_code];\n if (get_bits1(gb)) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "broken stream, invalid padding\\n");\n return -1;\n }\n fi->frame_or_sample_num = get_utf8(gb);\n if (fi->frame_or_sample_num < 0) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "sample/frame number invalid; utf8 fscked\\n");\n return -1;\n }\n if (bs_code == 0) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "reserved blocksize code: 0\\n");\n return -1;\n } else if (bs_code == 6) {\n fi->blocksize = get_bits(gb, 8) + 1;\n } else if (bs_code == 7) {\n fi->blocksize = get_bits(gb, 16) + 1;\n } else {\n fi->blocksize = ff_flac_blocksize_table[bs_code];\n }\n if (sr_code < 12) {\n fi->samplerate = ff_flac_sample_rate_table[sr_code];\n } else if (sr_code == 12) {\n fi->samplerate = get_bits(gb, 8) * 1000;\n } else if (sr_code == 13) {\n fi->samplerate = get_bits(gb, 16);\n } else if (sr_code == 14) {\n fi->samplerate = get_bits(gb, 16) * 10;\n } else {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "illegal sample rate code %d\\n",\n sr_code);\n return -1;\n }\n skip_bits(gb, 8);\n if (av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, gb->buffer,\n get_bits_count(gb)/8)) {\n av_log(avctx, AV_LOG_ERROR + log_level_offset,\n "header crc mismatch\\n");\n return -1;\n }\n return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
1,191
| 0
|
https://github.com/openssl/openssl/blob/10f0c85cfc26ffafd426d9797275191829efd599/crypto/bn/bn_asm.c/#L405
|
BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
{
BN_ULONG t1,t2;
int c=0;
assert(n >= 0);
if (n <= 0) return((BN_ULONG)0);
#ifndef OPENSSL_SMALL_FOOTPRINT
while (n&~3)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[1]; t2=b[1];
r[1]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[2]; t2=b[2];
r[2]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[3]; t2=b[3];
r[3]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
a+=4; b+=4; r+=4; n-=4;
}
#endif
while (n)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
a++; b++; r++; n--;
}
return(c);
}
|
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n\tconst BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n\tBN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2;\n\tint r_is_one=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *a_mod_m;\n\tBIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a1);\n\tbn_check_top(p1);\n\tbn_check_top(a2);\n\tbn_check_top(p2);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP2_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits1=BN_num_bits(p1);\n\tbits2=BN_num_bits(p2);\n\tif ((bits1 == 0) && (bits2 == 0))\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tbits=(bits1 > bits2)?bits1:bits2;\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval1[0] = BN_CTX_get(ctx);\n\tval2[0] = BN_CTX_get(ctx);\n\tif(!d || !r || !val1[0] || !val2[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow1 = BN_window_bits_for_exponent_size(bits1);\n\twindow2 = BN_window_bits_for_exponent_size(bits2);\n\tif (a1->neg || BN_ucmp(a1,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(val1[0],a1,m,ctx))\n\t\t\tgoto err;\n\t\ta_mod_m = val1[0];\n\t\t}\n\telse\n\t\ta_mod_m = a1;\n\tif (BN_is_zero(a_mod_m))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val1[0],a_mod_m,mont,ctx)) goto err;\n\tif (window1 > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val1[0],val1[0],mont,ctx)) goto err;\n\t\tj=1<<(window1-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val1[i],val1[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (a2->neg || BN_ucmp(a2,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(val2[0],a2,m,ctx))\n\t\t\tgoto err;\n\t\ta_mod_m = val2[0];\n\t\t}\n\telse\n\t\ta_mod_m = a2;\n\tif (BN_is_zero(a_mod_m))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val2[0],a_mod_m,mont,ctx)) goto err;\n\tif (window2 > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val2[0],val2[0],mont,ctx)) goto err;\n\t\tj=1<<(window2-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val2[i],val2[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tr_is_one=1;\n\twvalue1=0;\n\twvalue2=0;\n\twpos1=0;\n\twpos2=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (b=bits-1; b>=0; b--)\n\t\t{\n\t\tif (!r_is_one)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (!wvalue1)\n\t\t\tif (BN_is_bit_set(p1, b))\n\t\t\t\t{\n\t\t\t\ti = b-window1+1;\n\t\t\t\twhile (!BN_is_bit_set(p1, i))\n\t\t\t\t\ti++;\n\t\t\t\twpos1 = i;\n\t\t\t\twvalue1 = 1;\n\t\t\t\tfor (i = b-1; i >= wpos1; i--)\n\t\t\t\t\t{\n\t\t\t\t\twvalue1 <<= 1;\n\t\t\t\t\tif (BN_is_bit_set(p1, i))\n\t\t\t\t\t\twvalue1++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tif (!wvalue2)\n\t\t\tif (BN_is_bit_set(p2, b))\n\t\t\t\t{\n\t\t\t\ti = b-window2+1;\n\t\t\t\twhile (!BN_is_bit_set(p2, i))\n\t\t\t\t\ti++;\n\t\t\t\twpos2 = i;\n\t\t\t\twvalue2 = 1;\n\t\t\t\tfor (i = b-1; i >= wpos2; i--)\n\t\t\t\t\t{\n\t\t\t\t\twvalue2 <<= 1;\n\t\t\t\t\tif (BN_is_bit_set(p2, i))\n\t\t\t\t\t\twvalue2++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\tif (wvalue1 && b == wpos1)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,val1[wvalue1>>1],mont,ctx))\n\t\t\t\tgoto err;\n\t\t\twvalue1 = 0;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\tif (wvalue2 && b == wpos2)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,val2[wvalue2>>1],mont,ctx))\n\t\t\t\tgoto err;\n\t\t\twvalue2 = 0;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'const BIGNUM *BN_value_one(void)\n\t{\n\tstatic BN_ULONG data_one=1L;\n\tstatic BIGNUM const_one={&data_one,1,1,0,BN_FLG_STATIC_DATA};\n\treturn(&const_one);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n\tint num = mont->N.top;\n\tif (num>1 && a->top==num && b->top==num)\n\t\t{\n\t\tif (bn_wexpand(r,num) == NULL) return(0);\n\t\tif (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))\n\t\t\t{\n\t\t\tr->neg = a->neg^b->neg;\n\t\t\tr->top = num;\n\t\t\tbn_correct_top(r);\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n#ifdef MONT_WORD\n\tif (!BN_from_montgomery_word(r,tmp,mont)) goto err;\n#else\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n#endif\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_correct_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tbn_check_top(r);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n\t int tna, int tnb, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tint c1,c2,neg,zero;\n\tBN_ULONG ln,lo,*p;\n# ifdef BN_COUNT\n\tfprintf(stderr," bn_mul_part_recursive (%d%+d) * (%d%+d)\\n",\n\t\tn, tna, n, tnb);\n# endif\n\tif (n < 8)\n\t\t{\n\t\tbn_mul_normal(r,a,n+tna,b,n+tnb);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_part_words(a,&(a[n]),tna,n-tna);\n\tc2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\tcase -2:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\tcase 2:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\tcase 4:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tbreak;\n\t\t}\n# if 0\n\tif (n == 4)\n\t\t{\n\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n# endif\n\tif (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\n\t\tmemset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p);\n\t\tbn_mul_recursive(r,a,b,n,0,0,p);\n\t\ti=n/2;\n\t\tif (tna > tnb)\n\t\t\tj = tna - i;\n\t\telse\n\t\t\tj = tnb - i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\tmemset(&(r[n2+tna+tnb]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tna-tnb));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n\t\t\t\t&& tnb < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tna || i < tnb)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tna || i == tnb)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tint n,i;\n\tn = cl-1;\n\tif (dl < 0)\n\t\t{\n\t\tfor (i=dl; i<0; i++)\n\t\t\t{\n\t\t\tif (b[n-i] != 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif (dl > 0)\n\t\t{\n\t\tfor (i=dl; i>0; i--)\n\t\t\t{\n\t\t\tif (a[n+i] != 0)\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\treturn bn_cmp_words(a,b,cl);\n\t}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n\tconst BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tBN_ULONG c, t;\n\tassert(cl >= 0);\n\tc = bn_sub_words(r, a, b, cl);\n\tif (dl == 0)\n\t\treturn c;\n\tr += cl;\n\ta += cl;\n\tb += cl;\n\tif (dl < 0)\n\t\t{\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl < 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt = b[0];\n\t\t\tr[0] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[1];\n\t\t\tr[1] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[2];\n\t\t\tr[2] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[3];\n\t\t\tr[3] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tb += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tint save_dl = dl;\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\twhile(c)\n\t\t\t{\n\t\t\tt = a[0];\n\t\t\tr[0] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[1];\n\t\t\tr[1] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[2];\n\t\t\tr[2] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[3];\n\t\t\tr[3] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tsave_dl = dl;\n\t\t\ta += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c == 0)\\n", cl, dl);\n#endif\n\t\t\tif (save_dl > dl)\n\t\t\t\t{\n\t\t\t\tswitch (save_dl - dl)\n\t\t\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tr[1] = a[1];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 2:\n\t\t\t\t\tr[2] = a[2];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 3:\n\t\t\t\t\tr[3] = a[3];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\t\t}\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, copy)\\n", cl, dl);\n#endif\n\t\t\tfor(;;)\n\t\t\t\t{\n\t\t\t\tr[0] = a[0];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[1] = a[1];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[2] = a[2];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[3] = a[3];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn c;\n\t}', 'BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (n&~3)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta+=4; b+=4; r+=4; n-=4;\n\t\t}\n#endif\n\twhile (n)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta++; b++; r++; n--;\n\t\t}\n\treturn(c);\n\t}']
|
1,192
| 0
|
https://github.com/nginx/nginx/blob/58e26b88b774bbffbcd54bfc2de57a1b902ed4dd/src/http/ngx_http_core_module.c/#L2567
|
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_init_request(ngx_http_request_t *r)\n{\n ngx_str_t *host;\n ngx_uint_t i;\n ngx_resolver_ctx_t *ctx, temp;\n ngx_http_cleanup_t *cln;\n ngx_http_upstream_t *u;\n ngx_http_core_loc_conf_t *clcf;\n ngx_http_upstream_srv_conf_t *uscf, **uscfp;\n ngx_http_upstream_main_conf_t *umcf;\n if (r->aio) {\n return;\n }\n u = r->upstream;\n#if (NGX_HTTP_CACHE)\n if (u->conf->cache) {\n ngx_int_t rc;\n rc = ngx_http_upstream_cache(r, u);\n if (rc == NGX_BUSY) {\n r->write_event_handler = ngx_http_upstream_init_request;\n return;\n }\n r->write_event_handler = ngx_http_request_empty_handler;\n if (rc == NGX_DONE) {\n return;\n }\n if (rc != NGX_DECLINED) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n }\n#endif\n u->store = (u->conf->store || u->conf->store_lengths);\n if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {\n r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;\n r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;\n }\n if (r->request_body) {\n u->request_bufs = r->request_body->bufs;\n }\n if (u->create_request(r) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->peer.local = ngx_http_upstream_get_local(r, u->conf->local);\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n u->output.alignment = clcf->directio_alignment;\n u->output.pool = r->pool;\n u->output.bufs.num = 1;\n u->output.bufs.size = clcf->client_body_buffer_size;\n u->output.output_filter = ngx_chain_writer;\n u->output.filter_ctx = &u->writer;\n u->writer.pool = r->pool;\n if (r->upstream_states == NULL) {\n r->upstream_states = ngx_array_create(r->pool, 1,\n sizeof(ngx_http_upstream_state_t));\n if (r->upstream_states == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n } else {\n u->state = ngx_array_push(r->upstream_states);\n if (u->state == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));\n }\n cln = ngx_http_cleanup_add(r, 0);\n if (cln == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n cln->handler = ngx_http_upstream_cleanup;\n cln->data = r;\n u->cleanup = &cln->handler;\n if (u->resolved == NULL) {\n uscf = u->conf->upstream;\n#if (NGX_HTTP_SSL)\n u->ssl_name = uscf->host;\n#endif\n } else {\n#if (NGX_HTTP_SSL)\n u->ssl_name = u->resolved->host;\n#endif\n if (u->resolved->sockaddr) {\n if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_http_upstream_connect(r, u);\n return;\n }\n host = &u->resolved->host;\n umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n uscfp = umcf->upstreams.elts;\n for (i = 0; i < umcf->upstreams.nelts; i++) {\n uscf = uscfp[i];\n if (uscf->host.len == host->len\n && ((uscf->port == 0 && u->resolved->no_port)\n || uscf->port == u->resolved->port)\n && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)\n {\n goto found;\n }\n }\n if (u->resolved->port == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no port in upstream \\"%V\\"", host);\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n temp.name = *host;\n ctx = ngx_resolve_start(clcf->resolver, &temp);\n if (ctx == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (ctx == NGX_NO_RESOLVER) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no resolver defined to resolve %V", host);\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);\n return;\n }\n ctx->name = *host;\n ctx->handler = ngx_http_upstream_resolve_handler;\n ctx->data = r;\n ctx->timeout = clcf->resolver_timeout;\n u->resolved->ctx = ctx;\n if (ngx_resolve_name(ctx) != NGX_OK) {\n u->resolved->ctx = NULL;\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\nfound:\n if (uscf == NULL) {\n ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n "no upstream configuration");\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (uscf->peer.init(r, uscf) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_http_upstream_connect(r, u);\n}', 'static ngx_int_t\nngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_int_t rc;\n ngx_http_cache_t *c;\n c = r->cache;\n if (c == NULL) {\n if (!(r->method & u->conf->cache_methods)) {\n return NGX_DECLINED;\n }\n if (r->method & NGX_HTTP_HEAD) {\n u->method = ngx_http_core_get_method;\n }\n if (ngx_http_file_cache_new(r) != NGX_OK) {\n return NGX_ERROR;\n }\n if (u->create_key(r) != NGX_OK) {\n return NGX_ERROR;\n }\n ngx_http_file_cache_create_key(r);\n if (r->cache->header_start + 256 >= u->conf->buffer_size) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "%V_buffer_size %uz is not enough for cache key, "\n "it should be increased to at least %uz",\n &u->conf->module, u->conf->buffer_size,\n ngx_align(r->cache->header_start + 256, 1024));\n r->cache = NULL;\n return NGX_DECLINED;\n }\n u->cacheable = 1;\n switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {\n case NGX_ERROR:\n return NGX_ERROR;\n case NGX_DECLINED:\n u->cache_status = NGX_HTTP_CACHE_BYPASS;\n return NGX_DECLINED;\n default:\n break;\n }\n c = r->cache;\n c->min_uses = u->conf->cache_min_uses;\n c->body_start = u->conf->buffer_size;\n c->file_cache = u->conf->cache->data;\n c->lock = u->conf->cache_lock;\n c->lock_timeout = u->conf->cache_lock_timeout;\n u->cache_status = NGX_HTTP_CACHE_MISS;\n }\n rc = ngx_http_file_cache_open(r);\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream cache: %i", rc);\n switch (rc) {\n case NGX_HTTP_CACHE_UPDATING:\n if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) {\n u->cache_status = rc;\n rc = NGX_OK;\n } else {\n rc = NGX_HTTP_CACHE_STALE;\n }\n break;\n case NGX_OK:\n u->cache_status = NGX_HTTP_CACHE_HIT;\n }\n switch (rc) {\n case NGX_OK:\n rc = ngx_http_upstream_cache_send(r, u);\n if (rc != NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n return rc;\n }\n break;\n case NGX_HTTP_CACHE_STALE:\n c->valid_sec = 0;\n u->buffer.start = NULL;\n u->cache_status = NGX_HTTP_CACHE_EXPIRED;\n break;\n case NGX_DECLINED:\n if ((size_t) (u->buffer.end - u->buffer.start) < u->conf->buffer_size) {\n u->buffer.start = NULL;\n } else {\n u->buffer.pos = u->buffer.start + c->header_start;\n u->buffer.last = u->buffer.pos;\n }\n break;\n case NGX_HTTP_CACHE_SCARCE:\n u->cacheable = 0;\n break;\n case NGX_AGAIN:\n return NGX_BUSY;\n case NGX_ERROR:\n return NGX_ERROR;\n default:\n u->cache_status = NGX_HTTP_CACHE_HIT;\n return rc;\n }\n r->cached = 0;\n return NGX_DECLINED;\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}']
|
1,193
| 0
|
https://github.com/libav/libav/blob/01fdfa51aca9086e04bd354fe3f103a49352c085/libavutil/samplefmt.c/#L124
|
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
enum AVSampleFormat sample_fmt, int align)
{
int line_size;
int sample_size = av_get_bytes_per_sample(sample_fmt);
int planar = av_sample_fmt_is_planar(sample_fmt);
if (!sample_size || nb_samples <= 0 || nb_channels <= 0)
return AVERROR(EINVAL);
if (!align) {
if (nb_samples > INT_MAX - 31)
return AVERROR(EINVAL);
align = 1;
nb_samples = FFALIGN(nb_samples, 32);
}
if (nb_channels > INT_MAX / align ||
(int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)
return AVERROR(EINVAL);
line_size = planar ? FFALIGN(nb_samples * sample_size, align) :
FFALIGN(nb_samples * sample_size * nb_channels, align);
if (linesize)
*linesize = line_size;
return planar ? line_size * nb_channels : line_size;
}
|
['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n H264Context *h = avctx->priv_data;\n AVFrame *pict = data;\n int buf_index = 0;\n int ret;\n h->flags = avctx->flags;\nout:\n if (buf_size == 0) {\n H264Picture *out;\n int i, out_idx;\n h->cur_pic_ptr = NULL;\n out = h->delayed_pic[0];\n out_idx = 0;\n for (i = 1;\n h->delayed_pic[i] &&\n !h->delayed_pic[i]->f->key_frame &&\n !h->delayed_pic[i]->mmco_reset;\n i++)\n if (h->delayed_pic[i]->poc < out->poc) {\n out = h->delayed_pic[i];\n out_idx = i;\n }\n for (i = out_idx; h->delayed_pic[i]; i++)\n h->delayed_pic[i] = h->delayed_pic[i + 1];\n if (out) {\n ret = output_frame(h, pict, out->f);\n if (ret < 0)\n return ret;\n *got_frame = 1;\n }\n return buf_index;\n }\n buf_index = decode_nal_units(h, buf, buf_size, 0);\n if (buf_index < 0)\n return AVERROR_INVALIDDATA;\n if (!h->cur_pic_ptr && h->nal_unit_type == NAL_END_SEQUENCE) {\n buf_size = 0;\n goto out;\n }\n if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n if (avctx->skip_frame >= AVDISCARD_NONREF)\n return 0;\n av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n return AVERROR_INVALIDDATA;\n }\n if (!(avctx->flags2 & CODEC_FLAG2_CHUNKS) ||\n (h->mb_y >= h->mb_height && h->mb_height)) {\n if (avctx->flags2 & CODEC_FLAG2_CHUNKS)\n decode_postinit(h, 1);\n ff_h264_field_end(h, &h->slice_ctx[0], 0);\n *got_frame = 0;\n if (h->next_output_pic && ((avctx->flags & CODEC_FLAG_OUTPUT_CORRUPT) ||\n h->next_output_pic->recovered)) {\n if (!h->next_output_pic->recovered)\n h->next_output_pic->f->flags |= AV_FRAME_FLAG_CORRUPT;\n ret = output_frame(h, pict, h->next_output_pic->f);\n if (ret < 0)\n return ret;\n *got_frame = 1;\n }\n }\n assert(pict->buf[0] || !*got_frame);\n return get_consumed_bytes(buf_index, buf_size);\n}', 'int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup)\n{\n AVCodecContext *const avctx = h->avctx;\n int err = 0;\n h->mb_y = 0;\n if (!in_setup && !h->droppable)\n ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n h->picture_structure == PICT_BOTTOM_FIELD);\n if (in_setup || !(avctx->active_thread_type & FF_THREAD_FRAME)) {\n if (!h->droppable) {\n err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n h->prev_poc_msb = h->poc_msb;\n h->prev_poc_lsb = h->poc_lsb;\n }\n h->prev_frame_num_offset = h->frame_num_offset;\n h->prev_frame_num = h->frame_num;\n }\n if (avctx->hwaccel) {\n if (avctx->hwaccel->end_frame(avctx) < 0)\n av_log(avctx, AV_LOG_ERROR,\n "hardware accelerator failed to decode picture\\n");\n }\n#if CONFIG_ERROR_RESILIENCE\n if (!FIELD_PICTURE(h) && h->enable_er) {\n h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr);\n h264_set_erpic(&sl->er.last_pic,\n sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL);\n h264_set_erpic(&sl->er.next_pic,\n sl->ref_count[1] ? sl->ref_list[1][0].parent : NULL);\n ff_er_frame_end(&sl->er);\n }\n#endif\n emms_c();\n h->current_slice = 0;\n return err;\n}', 'void ff_er_frame_end(ERContext *s)\n{\n int *linesize = s->cur_pic.f->linesize;\n int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;\n int distance;\n int threshold_part[4] = { 100, 100, 100 };\n int threshold = 50;\n int is_intra_likely;\n if (!s->avctx->error_concealment || s->error_count == 0 ||\n s->avctx->hwaccel ||\n !s->cur_pic.f ||\n s->cur_pic.field_picture ||\n s->error_count == 3 * s->mb_width *\n (s->avctx->skip_top + s->avctx->skip_bottom)) {\n return;\n };\n if (!s->cur_pic.motion_val[0] || !s->cur_pic.ref_index[0]) {\n av_log(s->avctx, AV_LOG_ERROR, "MVs not available, ER not possible.\\n");\n return;\n }\n if (s->avctx->debug & FF_DEBUG_ER) {\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n int status = s->error_status_table[mb_x + mb_y * s->mb_stride];\n av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);\n }\n av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n }\n }\n for (error_type = 1; error_type <= 3; error_type++) {\n int end_ok = 0;\n for (i = s->mb_num - 1; i >= 0; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (error & (1 << error_type))\n end_ok = 1;\n if (error & (8 << error_type))\n end_ok = 1;\n if (!end_ok)\n s->error_status_table[mb_xy] |= 1 << error_type;\n if (error & VP_START)\n end_ok = 0;\n }\n }\n if (s->partitioned_frame) {\n int end_ok = 0;\n for (i = s->mb_num - 1; i >= 0; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (error & ER_AC_END)\n end_ok = 0;\n if ((error & ER_MV_END) ||\n (error & ER_DC_END) ||\n (error & ER_AC_ERROR))\n end_ok = 1;\n if (!end_ok)\n s->error_status_table[mb_xy]|= ER_AC_ERROR;\n if (error & VP_START)\n end_ok = 0;\n }\n }\n if (s->avctx->err_recognition & AV_EF_EXPLODE) {\n int end_ok = 1;\n for (i = s->mb_num - 2; i >= s->mb_width + 100; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error1 = s->error_status_table[mb_xy];\n int error2 = s->error_status_table[s->mb_index2xy[i + 1]];\n if (error1 & VP_START)\n end_ok = 1;\n if (error2 == (VP_START | ER_MB_ERROR | ER_MB_END) &&\n error1 != (VP_START | ER_MB_ERROR | ER_MB_END) &&\n ((error1 & ER_AC_END) || (error1 & ER_DC_END) ||\n (error1 & ER_MV_END))) {\n end_ok = 0;\n }\n if (!end_ok)\n s->error_status_table[mb_xy] |= ER_MB_ERROR;\n }\n }\n distance = 9999999;\n for (error_type = 1; error_type <= 3; error_type++) {\n for (i = s->mb_num - 1; i >= 0; i--) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (s->mbskip_table && !s->mbskip_table[mb_xy])\n distance++;\n if (error & (1 << error_type))\n distance = 0;\n if (s->partitioned_frame) {\n if (distance < threshold_part[error_type - 1])\n s->error_status_table[mb_xy] |= 1 << error_type;\n } else {\n if (distance < threshold)\n s->error_status_table[mb_xy] |= 1 << error_type;\n }\n if (error & VP_START)\n distance = 9999999;\n }\n }\n error = 0;\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n int old_error = s->error_status_table[mb_xy];\n if (old_error & VP_START) {\n error = old_error & ER_MB_ERROR;\n } else {\n error |= old_error & ER_MB_ERROR;\n s->error_status_table[mb_xy] |= error;\n }\n }\n if (!s->partitioned_frame) {\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n error = s->error_status_table[mb_xy];\n if (error & ER_MB_ERROR)\n error |= ER_MB_ERROR;\n s->error_status_table[mb_xy] = error;\n }\n }\n dc_error = ac_error = mv_error = 0;\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n error = s->error_status_table[mb_xy];\n if (error & ER_DC_ERROR)\n dc_error++;\n if (error & ER_AC_ERROR)\n ac_error++;\n if (error & ER_MV_ERROR)\n mv_error++;\n }\n av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\\n",\n dc_error, ac_error, mv_error);\n is_intra_likely = is_intra_more_likely(s);\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n error = s->error_status_table[mb_xy];\n if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n continue;\n if (is_intra_likely)\n s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n else\n s->cur_pic.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;\n }\n if (!(s->last_pic.f && s->last_pic.f->data[0]) &&\n !(s->next_pic.f && s->next_pic.f->data[0]))\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n if (!IS_INTRA(s->cur_pic.mb_type[mb_xy]))\n s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n }\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n const int dir = !(s->last_pic.f && s->last_pic.f->data[0]);\n const int mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n int mv_type;\n error = s->error_status_table[mb_xy];\n if (IS_INTRA(mb_type))\n continue;\n if (error & ER_MV_ERROR)\n continue;\n if (!(error & ER_AC_ERROR))\n continue;\n if (IS_8X8(mb_type)) {\n int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride;\n int j;\n mv_type = MV_TYPE_8X8;\n for (j = 0; j < 4; j++) {\n s->mv[0][j][0] = s->cur_pic.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];\n s->mv[0][j][1] = s->cur_pic.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];\n }\n } else {\n mv_type = MV_TYPE_16X16;\n s->mv[0][0][0] = s->cur_pic.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0];\n s->mv[0][0][1] = s->cur_pic.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1];\n }\n s->decode_mb(s->opaque, 0 ,\n mv_dir, mv_type, &s->mv, mb_x, mb_y, 0, 0);\n }\n }\n if (s->cur_pic.f->pict_type == AV_PICTURE_TYPE_B) {\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n int xy = mb_x * 2 + mb_y * 2 * s->b8_stride;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n int mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n error = s->error_status_table[mb_xy];\n if (IS_INTRA(mb_type))\n continue;\n if (!(error & ER_MV_ERROR))\n continue;\n if (!(error & ER_AC_ERROR))\n continue;\n if (!(s->last_pic.f && s->last_pic.f->data[0]))\n mv_dir &= ~MV_DIR_FORWARD;\n if (!(s->next_pic.f && s->next_pic.f->data[0]))\n mv_dir &= ~MV_DIR_BACKWARD;\n if (s->pp_time) {\n int time_pp = s->pp_time;\n int time_pb = s->pb_time;\n ff_thread_await_progress(s->next_pic.tf, mb_y, 0);\n s->mv[0][0][0] = s->next_pic.motion_val[0][xy][0] * time_pb / time_pp;\n s->mv[0][0][1] = s->next_pic.motion_val[0][xy][1] * time_pb / time_pp;\n s->mv[1][0][0] = s->next_pic.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;\n s->mv[1][0][1] = s->next_pic.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp;\n } else {\n s->mv[0][0][0] = 0;\n s->mv[0][0][1] = 0;\n s->mv[1][0][0] = 0;\n s->mv[1][0][1] = 0;\n }\n s->decode_mb(s->opaque, 0, mv_dir, MV_TYPE_16X16, &s->mv,\n mb_x, mb_y, 0, 0);\n }\n }\n } else\n guess_mv(s);\n#if FF_API_XVMC\nFF_DISABLE_DEPRECATION_WARNINGS\n if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n goto ec_clean;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n int dc, dcu, dcv, y, n;\n int16_t *dc_ptr;\n uint8_t *dest_y, *dest_cb, *dest_cr;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n error = s->error_status_table[mb_xy];\n if (IS_INTRA(mb_type) && s->partitioned_frame)\n continue;\n dest_y = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0];\n dest_cb = s->cur_pic.f->data[1] + mb_x * 8 + mb_y * 8 * linesize[1];\n dest_cr = s->cur_pic.f->data[2] + mb_x * 8 + mb_y * 8 * linesize[2];\n dc_ptr = &s->dc_val[0][mb_x * 2 + mb_y * 2 * s->b8_stride];\n for (n = 0; n < 4; n++) {\n dc = 0;\n for (y = 0; y < 8; y++) {\n int x;\n for (x = 0; x < 8; x++)\n dc += dest_y[x + (n & 1) * 8 +\n (y + (n >> 1) * 8) * linesize[0]];\n }\n dc_ptr[(n & 1) + (n >> 1) * s->b8_stride] = (dc + 4) >> 3;\n }\n dcu = dcv = 0;\n for (y = 0; y < 8; y++) {\n int x;\n for (x = 0; x < 8; x++) {\n dcu += dest_cb[x + y * linesize[1]];\n dcv += dest_cr[x + y * linesize[2]];\n }\n }\n s->dc_val[1][mb_x + mb_y * s->mb_stride] = (dcu + 4) >> 3;\n s->dc_val[2][mb_x + mb_y * s->mb_stride] = (dcv + 4) >> 3;\n }\n }\n guess_dc(s, s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride, 1);\n guess_dc(s, s->dc_val[1], s->mb_width, s->mb_height, s->mb_stride, 0);\n guess_dc(s, s->dc_val[2], s->mb_width, s->mb_height, s->mb_stride, 0);\n filter181(s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride);\n for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n uint8_t *dest_y, *dest_cb, *dest_cr;\n const int mb_xy = mb_x + mb_y * s->mb_stride;\n const int mb_type = s->cur_pic.mb_type[mb_xy];\n error = s->error_status_table[mb_xy];\n if (IS_INTER(mb_type))\n continue;\n if (!(error & ER_AC_ERROR))\n continue;\n dest_y = s->cur_pic.f->data[0] + mb_x * 16 + mb_y * 16 * linesize[0];\n dest_cb = s->cur_pic.f->data[1] + mb_x * 8 + mb_y * 8 * linesize[1];\n dest_cr = s->cur_pic.f->data[2] + mb_x * 8 + mb_y * 8 * linesize[2];\n put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);\n }\n }\n if (s->avctx->error_concealment & FF_EC_DEBLOCK) {\n h_block_filter(s, s->cur_pic.f->data[0], s->mb_width * 2,\n s->mb_height * 2, linesize[0], 1);\n h_block_filter(s, s->cur_pic.f->data[1], s->mb_width,\n s->mb_height, linesize[1], 0);\n h_block_filter(s, s->cur_pic.f->data[2], s->mb_width,\n s->mb_height, linesize[2], 0);\n v_block_filter(s, s->cur_pic.f->data[0], s->mb_width * 2,\n s->mb_height * 2, linesize[0], 1);\n v_block_filter(s, s->cur_pic.f->data[1], s->mb_width,\n s->mb_height, linesize[1], 0);\n v_block_filter(s, s->cur_pic.f->data[2], s->mb_width,\n s->mb_height, linesize[2], 0);\n }\nec_clean:\n for (i = 0; i < s->mb_num; i++) {\n const int mb_xy = s->mb_index2xy[i];\n int error = s->error_status_table[mb_xy];\n if (s->mbskip_table && s->cur_pic.f->pict_type != AV_PICTURE_TYPE_B &&\n (error & (ER_DC_ERROR | ER_MV_ERROR | ER_AC_ERROR))) {\n s->mbskip_table[mb_xy] = 0;\n }\n if (s->mbintra_table)\n s->mbintra_table[mb_xy] = 1;\n }\n memset(&s->cur_pic, 0, sizeof(ERPicture));\n memset(&s->last_pic, 0, sizeof(ERPicture));\n memset(&s->next_pic, 0, sizeof(ERPicture));\n}', 'void ff_thread_await_progress(ThreadFrame *f, int n, int field)\n{\n PerThreadContext *p;\n int *progress = f->progress ? (int*)f->progress->data : NULL;\n if (!progress || progress[field] >= n) return;\n p = f->owner->internal->thread_ctx;\n if (f->owner->debug&FF_DEBUG_THREADS)\n av_log(f->owner, AV_LOG_DEBUG, "thread awaiting %d field %d from %p\\n", n, field, progress);\n pthread_mutex_lock(&p->progress_mutex);\n while (progress[field] < n)\n pthread_cond_wait(&p->progress_cond, &p->progress_mutex);\n pthread_mutex_unlock(&p->progress_mutex);\n}', 'static int output_frame(H264Context *h, AVFrame *dst, AVFrame *src)\n{\n int i;\n int ret = av_frame_ref(dst, src);\n if (ret < 0)\n return ret;\n if (!h->sps.crop)\n return 0;\n for (i = 0; i < 3; i++) {\n int hshift = (i > 0) ? h->chroma_x_shift : 0;\n int vshift = (i > 0) ? h->chroma_y_shift : 0;\n int off = ((h->sps.crop_left >> hshift) << h->pixel_shift) +\n (h->sps.crop_top >> vshift) * dst->linesize[i];\n dst->data[i] += off;\n }\n return 0;\n}', 'int av_frame_ref(AVFrame *dst, const AVFrame *src)\n{\n int i, ret = 0;\n dst->format = src->format;\n dst->width = src->width;\n dst->height = src->height;\n dst->channel_layout = src->channel_layout;\n dst->nb_samples = src->nb_samples;\n ret = av_frame_copy_props(dst, src);\n if (ret < 0)\n return ret;\n if (!src->buf[0]) {\n ret = av_frame_get_buffer(dst, 32);\n if (ret < 0)\n return ret;\n ret = av_frame_copy(dst, src);\n if (ret < 0)\n av_frame_unref(dst);\n return ret;\n }\n for (i = 0; i < FF_ARRAY_ELEMS(src->buf) && src->buf[i]; i++) {\n dst->buf[i] = av_buffer_ref(src->buf[i]);\n if (!dst->buf[i]) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n }\n if (src->extended_buf) {\n dst->extended_buf = av_mallocz(sizeof(*dst->extended_buf) *\n src->nb_extended_buf);\n if (!dst->extended_buf) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n dst->nb_extended_buf = src->nb_extended_buf;\n for (i = 0; i < src->nb_extended_buf; i++) {\n dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);\n if (!dst->extended_buf[i]) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n }\n }\n if (src->extended_data != src->data) {\n int ch = av_get_channel_layout_nb_channels(src->channel_layout);\n if (!ch) {\n ret = AVERROR(EINVAL);\n goto fail;\n }\n dst->extended_data = av_malloc(sizeof(*dst->extended_data) * ch);\n if (!dst->extended_data) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);\n } else\n dst->extended_data = dst->data;\n memcpy(dst->data, src->data, sizeof(src->data));\n memcpy(dst->linesize, src->linesize, sizeof(src->linesize));\n return 0;\nfail:\n av_frame_unref(dst);\n return ret;\n}', 'int av_frame_get_buffer(AVFrame *frame, int align)\n{\n if (frame->format < 0)\n return AVERROR(EINVAL);\n if (frame->width > 0 && frame->height > 0)\n return get_video_buffer(frame, align);\n else if (frame->nb_samples > 0 && frame->channel_layout)\n return get_audio_buffer(frame, align);\n return AVERROR(EINVAL);\n}', 'static int get_audio_buffer(AVFrame *frame, int align)\n{\n int channels = av_get_channel_layout_nb_channels(frame->channel_layout);\n int planar = av_sample_fmt_is_planar(frame->format);\n int planes = planar ? channels : 1;\n int ret, i;\n if (!frame->linesize[0]) {\n ret = av_samples_get_buffer_size(&frame->linesize[0], channels,\n frame->nb_samples, frame->format,\n align);\n if (ret < 0)\n return ret;\n }\n if (planes > AV_NUM_DATA_POINTERS) {\n frame->extended_data = av_mallocz(planes *\n sizeof(*frame->extended_data));\n frame->extended_buf = av_mallocz((planes - AV_NUM_DATA_POINTERS) *\n sizeof(*frame->extended_buf));\n if (!frame->extended_data || !frame->extended_buf) {\n av_freep(&frame->extended_data);\n av_freep(&frame->extended_buf);\n return AVERROR(ENOMEM);\n }\n frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;\n } else\n frame->extended_data = frame->data;\n for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {\n frame->buf[i] = av_buffer_alloc(frame->linesize[0]);\n if (!frame->buf[i]) {\n av_frame_unref(frame);\n return AVERROR(ENOMEM);\n }\n frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;\n }\n for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {\n frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);\n if (!frame->extended_buf[i]) {\n av_frame_unref(frame);\n return AVERROR(ENOMEM);\n }\n frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;\n }\n return 0;\n}', 'int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,\n enum AVSampleFormat sample_fmt, int align)\n{\n int line_size;\n int sample_size = av_get_bytes_per_sample(sample_fmt);\n int planar = av_sample_fmt_is_planar(sample_fmt);\n if (!sample_size || nb_samples <= 0 || nb_channels <= 0)\n return AVERROR(EINVAL);\n if (!align) {\n if (nb_samples > INT_MAX - 31)\n return AVERROR(EINVAL);\n align = 1;\n nb_samples = FFALIGN(nb_samples, 32);\n }\n if (nb_channels > INT_MAX / align ||\n (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)\n return AVERROR(EINVAL);\n line_size = planar ? FFALIGN(nb_samples * sample_size, align) :\n FFALIGN(nb_samples * sample_size * nb_channels, align);\n if (linesize)\n *linesize = line_size;\n return planar ? line_size * nb_channels : line_size;\n}']
|
1,194
| 0
|
https://github.com/openssl/openssl/blob/1dc920c8de5b7109727a21163843feecdf06a8cf/crypto/objects/obj_dat.c/#L467
|
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
{
int i,idx=0,n=0,len,nid;
unsigned long l;
unsigned char *p;
const char *s;
char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
if (buf_len <= 0) return(0);
if ((a == NULL) || (a->data == NULL)) {
buf[0]='\0';
return(0);
}
if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {
len=a->length;
p=a->data;
idx=0;
l=0;
while (idx < a->length) {
l|=(p[idx]&0x7f);
if (!(p[idx] & 0x80)) break;
l<<=7L;
idx++;
}
idx++;
i=(int)(l/40);
if (i > 2) i=2;
l-=(long)(i*40);
sprintf(tbuf,"%d.%lu",i,l);
i=strlen(tbuf);
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
for (; idx<len; idx++) {
l|=p[idx]&0x7f;
if (!(p[idx] & 0x80)) {
sprintf(tbuf,".%lu",l);
i=strlen(tbuf);
if (buf_len > 0)
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
}
l<<=7L;
}
} else {
s=OBJ_nid2ln(nid);
if (s == NULL)
s=OBJ_nid2sn(nid);
strncpy(buf,s,buf_len);
n=strlen(s);
}
buf[buf_len-1]='\0';
return(n);
}
|
['EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)\n{\n\tEVP_PKEY *pkey = NULL;\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa = NULL;\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsa = NULL;\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tECDSA *ecdsa = NULL;\n#endif\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\tASN1_INTEGER *privkey;\n\tASN1_TYPE *t1, *t2, *param = NULL;\n\tSTACK_OF(ASN1_TYPE) *n_stack = NULL;\n\tBN_CTX *ctx = NULL;\n\tint plen;\n#endif\n\tX509_ALGOR *a;\n\tunsigned char *p;\n\tconst unsigned char *cp;\n\tint pkeylen;\n\tint nid;\n\tchar obj_tmp[80];\n\tif(p8->pkey->type == V_ASN1_OCTET_STRING) {\n\t\tp8->broken = PKCS8_OK;\n\t\tp = p8->pkey->value.octet_string->data;\n\t\tpkeylen = p8->pkey->value.octet_string->length;\n\t} else {\n\t\tp8->broken = PKCS8_NO_OCTET;\n\t\tp = p8->pkey->value.sequence->data;\n\t\tpkeylen = p8->pkey->value.sequence->length;\n\t}\n\tif (!(pkey = EVP_PKEY_new())) {\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\ta = p8->pkeyalg;\n\tnid = OBJ_obj2nid(a->algorithm);\n\tswitch(nid)\n\t{\n#ifndef OPENSSL_NO_RSA\n\t\tcase NID_rsaEncryption:\n\t\tcp = p;\n\t\tif (!(rsa = d2i_RSAPrivateKey (NULL,&cp, pkeylen))) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\treturn NULL;\n\t\t}\n\t\tEVP_PKEY_assign_RSA (pkey, rsa);\n\t\tbreak;\n#endif\n#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)\n\t\tcase NID_ecdsa_with_SHA1:\n\t\tcase NID_dsa:\n\t\tif(*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))\n\t\t{\n\t\t \tif(!(n_stack = ASN1_seq_unpack_ASN1_TYPE(p, pkeylen,\n\t\t\t\t\t\t\t d2i_ASN1_TYPE,\n\t\t\t\t\t\t\t ASN1_TYPE_free)))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t \t}\n\t\t \tif(sk_ASN1_TYPE_num(n_stack) != 2 )\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t \t}\n\t\t t1 = sk_ASN1_TYPE_value(n_stack, 0);\n\t\t t2 = sk_ASN1_TYPE_value(n_stack, 1);\n\t\t if(t1->type == V_ASN1_SEQUENCE)\n\t\t {\n\t\t\tp8->broken = PKCS8_EMBEDDED_PARAM;\n\t\t\tparam = t1;\n\t\t }\n\t\t else if(a->parameter->type == V_ASN1_SEQUENCE)\n\t\t {\n\t\t\tp8->broken = PKCS8_NS_DB;\n\t\t\tparam = a->parameter;\n\t\t }\n\t\t else\n\t\t {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto err;\n\t\t }\n\t\t if(t2->type != V_ASN1_INTEGER) {\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto err;\n\t\t }\n\t\t privkey = t2->value.integer;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tif (!(privkey=d2i_ASN1_INTEGER (NULL, &p, pkeylen)))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tparam = p8->pkeyalg->parameter;\n\t\t}\n\t\tif (!param || (param->type != V_ASN1_SEQUENCE))\n\t\t{\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\tgoto err;\n\t\t}\n\t\tcp = p = param->value.sequence->data;\n\t\tplen = param->value.sequence->length;\n\t\tif (!(ctx = BN_CTX_new()))\n\t\t{\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t}\n\t\tif (nid == NID_dsa)\n\t\t{\n#ifndef OPENSSL_NO_DSA\n\t\t\tif (!(dsa = d2i_DSAparams (NULL, &cp, plen)))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif (!(dsa->pub_key = BN_new()))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif (!BN_mod_exp(dsa->pub_key, dsa->g,\n\t\t\t\t\t\t dsa->priv_key, dsa->p, ctx))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY,EVP_R_BN_PUBKEY_ERROR);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tEVP_PKEY_assign_DSA(pkey, dsa);\n\t\t\tBN_CTX_free(ctx);\n\t\t\tif(n_stack) sk_ASN1_TYPE_pop_free(n_stack, ASN1_TYPE_free);\n\t\t\telse ASN1_INTEGER_free(privkey);\n#else\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\t\tgoto err;\n#endif\n\t\t}\n\t\telse\n\t\t{\n#ifndef OPENSSL_NO_ECDSA\n\t\t\tif ((ecdsa = d2i_ECDSAParameters(NULL, &cp, plen)) == NULL)\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif ((ecdsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)) == NULL)\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif ((ecdsa->pub_key = EC_POINT_new(ecdsa->group)) == NULL)\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif (!EC_POINT_copy(ecdsa->pub_key, EC_GROUP_get0_generator(ecdsa->group)))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tif (!EC_POINT_mul(ecdsa->group, ecdsa->pub_key, ecdsa->priv_key,\n\t\t\t\t\t NULL, NULL, ctx))\n\t\t\t{\n\t\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tEVP_PKEY_assign_ECDSA(pkey, ecdsa);\n\t\t\tBN_CTX_free(ctx);\n\t\t\tif (n_stack) sk_ASN1_TYPE_pop_free(n_stack, ASN1_TYPE_free);\n\t\t\telse\n\t\t\t\tASN1_INTEGER_free(privkey);\n#else\n\t\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\t\tgoto err;\n#endif\n\t\t}\n\t\tbreak;\nerr:\n\t\tif (ctx) BN_CTX_free(ctx);\n\t\tsk_ASN1_TYPE_pop_free(n_stack, ASN1_TYPE_free);\n#ifndef OPENSSL_NO_DSA\n\t\tif (dsa) DSA_free(dsa);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\tif (ecdsa) ECDSA_free(ecdsa);\n#endif\n\t\tif (pkey) EVP_PKEY_free(pkey);\n\t\treturn NULL;\n\t\tbreak;\n#endif\n\t\tdefault:\n\t\tEVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\tif (!a->algorithm) strcpy (obj_tmp, "NULL");\n\t\telse i2t_ASN1_OBJECT(obj_tmp, 80, a->algorithm);\n\t\tERR_add_error_data(2, "TYPE=", obj_tmp);\n\t\tEVP_PKEY_free (pkey);\n\t\treturn NULL;\n\t}\n\treturn pkey;\n}', 'int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)\n{\n\treturn OBJ_obj2txt(buf, buf_len, a, 0);\n}', 'int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n\tint i,idx=0,n=0,len,nid;\n\tunsigned long l;\n\tunsigned char *p;\n\tconst char *s;\n\tchar tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];\n\tif (buf_len <= 0) return(0);\n\tif ((a == NULL) || (a->data == NULL)) {\n\t\tbuf[0]=\'\\0\';\n\t\treturn(0);\n\t}\n\tif (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {\n\t\tlen=a->length;\n\t\tp=a->data;\n\t\tidx=0;\n\t\tl=0;\n\t\twhile (idx < a->length) {\n\t\t\tl|=(p[idx]&0x7f);\n\t\t\tif (!(p[idx] & 0x80)) break;\n\t\t\tl<<=7L;\n\t\t\tidx++;\n\t\t}\n\t\tidx++;\n\t\ti=(int)(l/40);\n\t\tif (i > 2) i=2;\n\t\tl-=(long)(i*40);\n\t\tsprintf(tbuf,"%d.%lu",i,l);\n\t\ti=strlen(tbuf);\n\t\tstrncpy(buf,tbuf,buf_len);\n\t\tbuf_len-=i;\n\t\tbuf+=i;\n\t\tn+=i;\n\t\tl=0;\n\t\tfor (; idx<len; idx++) {\n\t\t\tl|=p[idx]&0x7f;\n\t\t\tif (!(p[idx] & 0x80)) {\n\t\t\t\tsprintf(tbuf,".%lu",l);\n\t\t\t\ti=strlen(tbuf);\n\t\t\t\tif (buf_len > 0)\n\t\t\t\t\tstrncpy(buf,tbuf,buf_len);\n\t\t\t\tbuf_len-=i;\n\t\t\t\tbuf+=i;\n\t\t\t\tn+=i;\n\t\t\t\tl=0;\n\t\t\t}\n\t\t\tl<<=7L;\n\t\t}\n\t} else {\n\t\ts=OBJ_nid2ln(nid);\n\t\tif (s == NULL)\n\t\t\ts=OBJ_nid2sn(nid);\n\t\tstrncpy(buf,s,buf_len);\n\t\tn=strlen(s);\n\t}\n\tbuf[buf_len-1]=\'\\0\';\n\treturn(n);\n}']
|
1,195
| 0
|
https://github.com/openssl/openssl/blob/5c98b2caf5ce545fbf77611431c7084979da8177/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t const 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\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(r);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tif ((aa = BN_CTX_get(ctx)) == NULL) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (m->neg)\n\t\t{\n\t\tif (!BN_copy(aa, m)) goto err;\n\t\taa->neg = 0;\n\t\tif (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\t\t}\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_nnmod(&(val[0]),a,m,ctx)) goto err;\n\tif (BN_is_zero(&(val[0])))\n\t\t{\n\t\tBN_zero(r);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))\n\t\t\tgoto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tBN_init(&val[i]);\n\t\t\tif (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tts=i;\n\t\t}\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\tBN_CTX_end(ctx);\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\tBN_RECP_CTX_free(&recp);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif (dv)\n\t\tbn_check_top(dv);\n\tif (rm)\n\t\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tif (rm)\n\t\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n\tBN_RECP_CTX *recp, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tBIGNUM *a;\n\tconst BIGNUM *ca;\n\tBN_CTX_start(ctx);\n\tif ((a = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (y != NULL)\n\t\t{\n\t\tif (x == y)\n\t\t\t{ if (!BN_sqr(a,x,ctx)) goto err; }\n\t\telse\n\t\t\t{ if (!BN_mul(a,x,y,ctx)) goto err; }\n\t\tca = a;\n\t\t}\n\telse\n\t\tca=x;\n\tret = BN_div_recp(NULL,r,ca,recp,ctx);\nerr:\n\tBN_CTX_end(ctx);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_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\tif(rr) bn_check_top(rr);\n\tif(tmp) bn_check_top(tmp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,196
| 0
|
https://github.com/nginx/nginx/blob/824856fc10b5580fcd047fc8db0e4c3f133f60e6/src/http/ngx_http_file_cache.c/#L925
|
void
ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf)
{
ngx_http_file_cache_t *cache;
ngx_http_file_cache_node_t *fcn;
if (c->updated) {
return;
}
cache = c->file_cache;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
"http file cache free, fd: %d", c->file.fd);
ngx_shmtx_lock(&cache->shpool->mutex);
fcn = c->node;
fcn->count--;
if (c->updating) {
fcn->updating = 0;
}
if (c->error) {
fcn->error = c->error;
if (c->valid_sec) {
fcn->valid_sec = c->valid_sec;
fcn->valid_msec = c->valid_msec;
}
} else if (!fcn->exists && fcn->count == 0 && c->min_uses == 1) {
ngx_queue_remove(&fcn->queue);
ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);
ngx_slab_free_locked(cache->shpool, fcn);
c->node = NULL;
}
ngx_shmtx_unlock(&cache->shpool->mutex);
c->updated = 1;
c->updating = 0;
if (c->temp_file) {
if (tf && tf->file.fd != NGX_INVALID_FILE) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,
"http file cache incomplete: \"%s\"",
tf->file.name.data);
if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno,
ngx_delete_file_n " \"%s\" failed",
tf->file.name.data);
}
}
}
}
|
['static void\nngx_http_file_cache_cleanup(void *data)\n{\n ngx_http_cache_t *c = data;\n if (c->updated) {\n return;\n }\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0,\n "http file cache cleanup");\n if (c->updating) {\n ngx_log_error(NGX_LOG_ALERT, c->file.log, 0,\n "stalled cache updating, error:%ui", c->error);\n }\n ngx_http_file_cache_free(c, NULL);\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 -= (err_levels[level].len + 4);\n (void) ngx_sprintf(msg, "[%V]: ", &err_levels[level]);\n (void) ngx_write_console(ngx_stderr, msg, p - msg);\n}', 'void\nngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf)\n{\n ngx_http_file_cache_t *cache;\n ngx_http_file_cache_node_t *fcn;\n if (c->updated) {\n return;\n }\n cache = c->file_cache;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,\n "http file cache free, fd: %d", c->file.fd);\n ngx_shmtx_lock(&cache->shpool->mutex);\n fcn = c->node;\n fcn->count--;\n if (c->updating) {\n fcn->updating = 0;\n }\n if (c->error) {\n fcn->error = c->error;\n if (c->valid_sec) {\n fcn->valid_sec = c->valid_sec;\n fcn->valid_msec = c->valid_msec;\n }\n } else if (!fcn->exists && fcn->count == 0 && c->min_uses == 1) {\n ngx_queue_remove(&fcn->queue);\n ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node);\n ngx_slab_free_locked(cache->shpool, fcn);\n c->node = NULL;\n }\n ngx_shmtx_unlock(&cache->shpool->mutex);\n c->updated = 1;\n c->updating = 0;\n if (c->temp_file) {\n if (tf && tf->file.fd != NGX_INVALID_FILE) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0,\n "http file cache incomplete: \\"%s\\"",\n tf->file.name.data);\n if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) {\n ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno,\n ngx_delete_file_n " \\"%s\\" failed",\n tf->file.name.data);\n }\n }\n }\n}']
|
1,197
| 0
|
https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/simple_idct.c/#L164
|
static inline void idct4row(int16_t *row)
{
int c0, c1, c2, c3, a0, a1, a2, a3;
a0 = row[0];
a1 = row[1];
a2 = row[2];
a3 = row[3];
c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));
c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));
c1 = a1 * R1 + a3 * R2;
c3 = a1 * R2 - a3 * R1;
row[0]= (c0 + c1) >> R_SHIFT;
row[1]= (c2 + c3) >> R_SHIFT;
row[2]= (c2 - c3) >> R_SHIFT;
row[3]= (c0 - c1) >> R_SHIFT;
}
|
['void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){\n Wmv2Context * const w= (Wmv2Context*)s;\n wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);\n wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);\n wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);\n wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);\n if(s->flags&CODEC_FLAG_GRAY) return;\n wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);\n wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);\n}', 'static void wmv2_add_block(Wmv2Context *w, int16_t *block1, uint8_t *dst, int stride, int n){\n MpegEncContext * const s= &w->s;\n if (s->block_last_index[n] >= 0) {\n switch(w->abt_type_table[n]){\n case 0:\n w->wdsp.idct_add(dst, stride, block1);\n break;\n case 1:\n ff_simple_idct84_add(dst , stride, block1);\n ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);\n s->dsp.clear_block(w->abt_block2[n]);\n break;\n case 2:\n ff_simple_idct48_add(dst , stride, block1);\n ff_simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);\n s->dsp.clear_block(w->abt_block2[n]);\n break;\n default:\n av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\\n");\n }\n }\n}', 'void ff_simple_idct48_add(uint8_t *dest, int line_size, int16_t *block)\n{\n int i;\n for(i=0; i<8; i++) {\n idct4row(block + i*8);\n }\n for(i=0; i<4; i++){\n idctSparseColAdd_8(dest + i, line_size, block + i);\n }\n}', 'static inline void idct4row(int16_t *row)\n{\n int c0, c1, c2, c3, a0, a1, a2, a3;\n a0 = row[0];\n a1 = row[1];\n a2 = row[2];\n a3 = row[3];\n c0 = (a0 + a2)*R3 + (1 << (R_SHIFT - 1));\n c2 = (a0 - a2)*R3 + (1 << (R_SHIFT - 1));\n c1 = a1 * R1 + a3 * R2;\n c3 = a1 * R2 - a3 * R1;\n row[0]= (c0 + c1) >> R_SHIFT;\n row[1]= (c2 + c3) >> R_SHIFT;\n row[2]= (c2 - c3) >> R_SHIFT;\n row[3]= (c0 - c1) >> R_SHIFT;\n}']
|
1,198
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/ssl/s3_srvr.c/#L1880
|
int ssl3_send_server_key_exchange(SSL *s)
{
#ifndef OPENSSL_NO_RSA
unsigned char *q;
int j, num;
RSA *rsa;
unsigned char md_buf[MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH];
unsigned int u;
#endif
#ifndef OPENSSL_NO_DH
DH *dh = NULL, *dhp;
#endif
#ifndef OPENSSL_NO_ECDH
EC_KEY *ecdh = NULL, *ecdhp;
unsigned char *encodedPoint = NULL;
int encodedlen = 0;
int curve_id = 0;
BN_CTX *bn_ctx = NULL;
#endif
EVP_PKEY *pkey;
const EVP_MD *md = NULL;
unsigned char *p, *d;
int al, i;
unsigned long type;
int n;
CERT *cert;
BIGNUM *r[4];
int nr[4], kn;
BUF_MEM *buf;
EVP_MD_CTX md_ctx;
EVP_MD_CTX_init(&md_ctx);
if (s->state == SSL3_ST_SW_KEY_EXCH_A) {
type = s->s3->tmp.new_cipher->algorithm_mkey;
cert = s->cert;
buf = s->init_buf;
r[0] = r[1] = r[2] = r[3] = NULL;
n = 0;
#ifndef OPENSSL_NO_RSA
if (type & SSL_kRSA) {
rsa = cert->rsa_tmp;
if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL)) {
rsa = s->cert->rsa_tmp_cb(s,
SSL_C_IS_EXPORT(s->s3->
tmp.new_cipher),
SSL_C_EXPORT_PKEYLENGTH(s->s3->
tmp.new_cipher));
if (rsa == NULL) {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_ERROR_GENERATING_TMP_RSA_KEY);
goto f_err;
}
RSA_up_ref(rsa);
cert->rsa_tmp = rsa;
}
if (rsa == NULL) {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_MISSING_TMP_RSA_KEY);
goto f_err;
}
r[0] = rsa->n;
r[1] = rsa->e;
s->s3->tmp.use_rsa_tmp = 1;
} else
#endif
#ifndef OPENSSL_NO_DH
if (type & SSL_kDHE) {
if (s->cert->dh_tmp_auto) {
dhp = ssl_get_auto_dh(s);
if (dhp == NULL) {
al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
ERR_R_INTERNAL_ERROR);
goto f_err;
}
} else
dhp = cert->dh_tmp;
if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))
dhp = s->cert->dh_tmp_cb(s,
SSL_C_IS_EXPORT(s->s3->
tmp.new_cipher),
SSL_C_EXPORT_PKEYLENGTH(s->s3->
tmp.new_cipher));
if (dhp == NULL) {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_MISSING_TMP_DH_KEY);
goto f_err;
}
if (!ssl_security(s, SSL_SECOP_TMP_DH,
DH_security_bits(dhp), 0, dhp)) {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_DH_KEY_TOO_SMALL);
goto f_err;
}
if (s->s3->tmp.dh != NULL) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
ERR_R_INTERNAL_ERROR);
goto err;
}
if (s->cert->dh_tmp_auto)
dh = dhp;
else if ((dh = DHparams_dup(dhp)) == NULL) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_DH_LIB);
goto err;
}
s->s3->tmp.dh = dh;
if ((dhp->pub_key == NULL ||
dhp->priv_key == NULL ||
(s->options & SSL_OP_SINGLE_DH_USE))) {
if (!DH_generate_key(dh)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_DH_LIB);
goto err;
}
} else {
dh->pub_key = BN_dup(dhp->pub_key);
dh->priv_key = BN_dup(dhp->priv_key);
if ((dh->pub_key == NULL) || (dh->priv_key == NULL)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_DH_LIB);
goto err;
}
}
r[0] = dh->p;
r[1] = dh->g;
r[2] = dh->pub_key;
} else
#endif
#ifndef OPENSSL_NO_ECDH
if (type & SSL_kECDHE) {
const EC_GROUP *group;
ecdhp = cert->ecdh_tmp;
if (s->cert->ecdh_tmp_auto) {
int nid = tls1_shared_curve(s, -2);
if (nid != NID_undef)
ecdhp = EC_KEY_new_by_curve_name(nid);
} else if ((ecdhp == NULL) && s->cert->ecdh_tmp_cb) {
ecdhp = s->cert->ecdh_tmp_cb(s,
SSL_C_IS_EXPORT(s->s3->
tmp.new_cipher),
SSL_C_EXPORT_PKEYLENGTH(s->
s3->tmp.new_cipher));
}
if (ecdhp == NULL) {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_MISSING_TMP_ECDH_KEY);
goto f_err;
}
if (s->s3->tmp.ecdh != NULL) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
ERR_R_INTERNAL_ERROR);
goto err;
}
if (ecdhp == NULL) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);
goto err;
}
if (s->cert->ecdh_tmp_auto)
ecdh = ecdhp;
else if ((ecdh = EC_KEY_dup(ecdhp)) == NULL) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);
goto err;
}
s->s3->tmp.ecdh = ecdh;
if ((EC_KEY_get0_public_key(ecdh) == NULL) ||
(EC_KEY_get0_private_key(ecdh) == NULL) ||
(s->options & SSL_OP_SINGLE_ECDH_USE)) {
if (!EC_KEY_generate_key(ecdh)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
ERR_R_ECDH_LIB);
goto err;
}
}
if (((group = EC_KEY_get0_group(ecdh)) == NULL) ||
(EC_KEY_get0_public_key(ecdh) == NULL) ||
(EC_KEY_get0_private_key(ecdh) == NULL)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);
goto err;
}
if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&
(EC_GROUP_get_degree(group) > 163)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER);
goto err;
}
if ((curve_id =
tls1_ec_nid2curve_id(EC_GROUP_get_curve_name(group)))
== 0) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
goto err;
}
encodedlen = EC_POINT_point2oct(group,
EC_KEY_get0_public_key(ecdh),
POINT_CONVERSION_UNCOMPRESSED,
NULL, 0, NULL);
encodedPoint = (unsigned char *)
OPENSSL_malloc(encodedlen * sizeof(unsigned char));
bn_ctx = BN_CTX_new();
if ((encodedPoint == NULL) || (bn_ctx == NULL)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
ERR_R_MALLOC_FAILURE);
goto err;
}
encodedlen = EC_POINT_point2oct(group,
EC_KEY_get0_public_key(ecdh),
POINT_CONVERSION_UNCOMPRESSED,
encodedPoint, encodedlen, bn_ctx);
if (encodedlen == 0) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);
goto err;
}
BN_CTX_free(bn_ctx);
bn_ctx = NULL;
n = 4 + encodedlen;
r[0] = NULL;
r[1] = NULL;
r[2] = NULL;
r[3] = NULL;
} else
#endif
#ifndef OPENSSL_NO_PSK
if (type & SSL_kPSK) {
n += 2 + strlen(s->ctx->psk_identity_hint);
} else
#endif
#ifndef OPENSSL_NO_SRP
if (type & SSL_kSRP) {
if ((s->srp_ctx.N == NULL) ||
(s->srp_ctx.g == NULL) ||
(s->srp_ctx.s == NULL) || (s->srp_ctx.B == NULL)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_MISSING_SRP_PARAM);
goto err;
}
r[0] = s->srp_ctx.N;
r[1] = s->srp_ctx.g;
r[2] = s->srp_ctx.s;
r[3] = s->srp_ctx.B;
} else
#endif
{
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
goto f_err;
}
for (i = 0; i < 4 && r[i] != NULL; i++) {
nr[i] = BN_num_bytes(r[i]);
#ifndef OPENSSL_NO_SRP
if ((i == 2) && (type & SSL_kSRP))
n += 1 + nr[i];
else
#endif
n += 2 + nr[i];
}
if (!(s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL | SSL_aSRP))
&& !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {
if ((pkey = ssl_get_sign_pkey(s, s->s3->tmp.new_cipher, &md))
== NULL) {
al = SSL_AD_DECODE_ERROR;
goto f_err;
}
kn = EVP_PKEY_size(pkey);
} else {
pkey = NULL;
kn = 0;
}
if (!BUF_MEM_grow_clean(buf, n + SSL_HM_HEADER_LENGTH(s) + kn)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_LIB_BUF);
goto err;
}
d = p = ssl_handshake_start(s);
for (i = 0; i < 4 && r[i] != NULL; i++) {
#ifndef OPENSSL_NO_SRP
if ((i == 2) && (type & SSL_kSRP)) {
*p = nr[i];
p++;
} else
#endif
s2n(nr[i], p);
BN_bn2bin(r[i], p);
p += nr[i];
}
#ifndef OPENSSL_NO_ECDH
if (type & SSL_kECDHE) {
*p = NAMED_CURVE_TYPE;
p += 1;
*p = 0;
p += 1;
*p = curve_id;
p += 1;
*p = encodedlen;
p += 1;
memcpy((unsigned char *)p,
(unsigned char *)encodedPoint, encodedlen);
OPENSSL_free(encodedPoint);
encodedPoint = NULL;
p += encodedlen;
}
#endif
#ifndef OPENSSL_NO_PSK
if (type & SSL_kPSK) {
s2n(strlen(s->ctx->psk_identity_hint), p);
strncpy((char *)p, s->ctx->psk_identity_hint,
strlen(s->ctx->psk_identity_hint));
p += strlen(s->ctx->psk_identity_hint);
}
#endif
if (pkey != NULL) {
#ifndef OPENSSL_NO_RSA
if (pkey->type == EVP_PKEY_RSA && !SSL_USE_SIGALGS(s)) {
q = md_buf;
j = 0;
for (num = 2; num > 0; num--) {
EVP_MD_CTX_set_flags(&md_ctx,
EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
EVP_DigestInit_ex(&md_ctx, (num == 2)
? s->ctx->md5 : s->ctx->sha1, NULL);
EVP_DigestUpdate(&md_ctx, &(s->s3->client_random[0]),
SSL3_RANDOM_SIZE);
EVP_DigestUpdate(&md_ctx, &(s->s3->server_random[0]),
SSL3_RANDOM_SIZE);
EVP_DigestUpdate(&md_ctx, d, n);
EVP_DigestFinal_ex(&md_ctx, q, (unsigned int *)&i);
q += i;
j += i;
}
if (RSA_sign(NID_md5_sha1, md_buf, j,
&(p[2]), &u, pkey->pkey.rsa) <= 0) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_LIB_RSA);
goto err;
}
s2n(u, p);
n += u + 2;
} else
#endif
if (md) {
if (SSL_USE_SIGALGS(s)) {
if (!tls12_get_sigandhash(p, pkey, md)) {
al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
ERR_R_INTERNAL_ERROR);
goto f_err;
}
p += 2;
}
#ifdef SSL_DEBUG
fprintf(stderr, "Using hash %s\n", EVP_MD_name(md));
#endif
EVP_SignInit_ex(&md_ctx, md, NULL);
EVP_SignUpdate(&md_ctx, &(s->s3->client_random[0]),
SSL3_RANDOM_SIZE);
EVP_SignUpdate(&md_ctx, &(s->s3->server_random[0]),
SSL3_RANDOM_SIZE);
EVP_SignUpdate(&md_ctx, d, n);
if (!EVP_SignFinal(&md_ctx, &(p[2]),
(unsigned int *)&i, pkey)) {
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_LIB_EVP);
goto err;
}
s2n(i, p);
n += i + 2;
if (SSL_USE_SIGALGS(s))
n += 2;
} else {
al = SSL_AD_HANDSHAKE_FAILURE;
SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,
SSL_R_UNKNOWN_PKEY_TYPE);
goto f_err;
}
}
ssl_set_handshake_header(s, SSL3_MT_SERVER_KEY_EXCHANGE, n);
}
s->state = SSL3_ST_SW_KEY_EXCH_B;
EVP_MD_CTX_cleanup(&md_ctx);
return ssl_do_write(s);
f_err:
ssl3_send_alert(s, SSL3_AL_FATAL, al);
err:
#ifndef OPENSSL_NO_ECDH
if (encodedPoint != NULL)
OPENSSL_free(encodedPoint);
BN_CTX_free(bn_ctx);
#endif
EVP_MD_CTX_cleanup(&md_ctx);
return (-1);
}
|
['int ssl3_send_server_key_exchange(SSL *s)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *q;\n int j, num;\n RSA *rsa;\n unsigned char md_buf[MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH];\n unsigned int u;\n#endif\n#ifndef OPENSSL_NO_DH\n DH *dh = NULL, *dhp;\n#endif\n#ifndef OPENSSL_NO_ECDH\n EC_KEY *ecdh = NULL, *ecdhp;\n unsigned char *encodedPoint = NULL;\n int encodedlen = 0;\n int curve_id = 0;\n BN_CTX *bn_ctx = NULL;\n#endif\n EVP_PKEY *pkey;\n const EVP_MD *md = NULL;\n unsigned char *p, *d;\n int al, i;\n unsigned long type;\n int n;\n CERT *cert;\n BIGNUM *r[4];\n int nr[4], kn;\n BUF_MEM *buf;\n EVP_MD_CTX md_ctx;\n EVP_MD_CTX_init(&md_ctx);\n if (s->state == SSL3_ST_SW_KEY_EXCH_A) {\n type = s->s3->tmp.new_cipher->algorithm_mkey;\n cert = s->cert;\n buf = s->init_buf;\n r[0] = r[1] = r[2] = r[3] = NULL;\n n = 0;\n#ifndef OPENSSL_NO_RSA\n if (type & SSL_kRSA) {\n rsa = cert->rsa_tmp;\n if ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL)) {\n rsa = s->cert->rsa_tmp_cb(s,\n SSL_C_IS_EXPORT(s->s3->\n tmp.new_cipher),\n SSL_C_EXPORT_PKEYLENGTH(s->s3->\n tmp.new_cipher));\n if (rsa == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_ERROR_GENERATING_TMP_RSA_KEY);\n goto f_err;\n }\n RSA_up_ref(rsa);\n cert->rsa_tmp = rsa;\n }\n if (rsa == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_RSA_KEY);\n goto f_err;\n }\n r[0] = rsa->n;\n r[1] = rsa->e;\n s->s3->tmp.use_rsa_tmp = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_DH\n if (type & SSL_kDHE) {\n if (s->cert->dh_tmp_auto) {\n dhp = ssl_get_auto_dh(s);\n if (dhp == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n } else\n dhp = cert->dh_tmp;\n if ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))\n dhp = s->cert->dh_tmp_cb(s,\n SSL_C_IS_EXPORT(s->s3->\n tmp.new_cipher),\n SSL_C_EXPORT_PKEYLENGTH(s->s3->\n tmp.new_cipher));\n if (dhp == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_DH_KEY);\n goto f_err;\n }\n if (!ssl_security(s, SSL_SECOP_TMP_DH,\n DH_security_bits(dhp), 0, dhp)) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_DH_KEY_TOO_SMALL);\n goto f_err;\n }\n if (s->s3->tmp.dh != NULL) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (s->cert->dh_tmp_auto)\n dh = dhp;\n else if ((dh = DHparams_dup(dhp)) == NULL) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_DH_LIB);\n goto err;\n }\n s->s3->tmp.dh = dh;\n if ((dhp->pub_key == NULL ||\n dhp->priv_key == NULL ||\n (s->options & SSL_OP_SINGLE_DH_USE))) {\n if (!DH_generate_key(dh)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_DH_LIB);\n goto err;\n }\n } else {\n dh->pub_key = BN_dup(dhp->pub_key);\n dh->priv_key = BN_dup(dhp->priv_key);\n if ((dh->pub_key == NULL) || (dh->priv_key == NULL)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_DH_LIB);\n goto err;\n }\n }\n r[0] = dh->p;\n r[1] = dh->g;\n r[2] = dh->pub_key;\n } else\n#endif\n#ifndef OPENSSL_NO_ECDH\n if (type & SSL_kECDHE) {\n const EC_GROUP *group;\n ecdhp = cert->ecdh_tmp;\n if (s->cert->ecdh_tmp_auto) {\n int nid = tls1_shared_curve(s, -2);\n if (nid != NID_undef)\n ecdhp = EC_KEY_new_by_curve_name(nid);\n } else if ((ecdhp == NULL) && s->cert->ecdh_tmp_cb) {\n ecdhp = s->cert->ecdh_tmp_cb(s,\n SSL_C_IS_EXPORT(s->s3->\n tmp.new_cipher),\n SSL_C_EXPORT_PKEYLENGTH(s->\n s3->tmp.new_cipher));\n }\n if (ecdhp == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_MISSING_TMP_ECDH_KEY);\n goto f_err;\n }\n if (s->s3->tmp.ecdh != NULL) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (ecdhp == NULL) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);\n goto err;\n }\n if (s->cert->ecdh_tmp_auto)\n ecdh = ecdhp;\n else if ((ecdh = EC_KEY_dup(ecdhp)) == NULL) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);\n goto err;\n }\n s->s3->tmp.ecdh = ecdh;\n if ((EC_KEY_get0_public_key(ecdh) == NULL) ||\n (EC_KEY_get0_private_key(ecdh) == NULL) ||\n (s->options & SSL_OP_SINGLE_ECDH_USE)) {\n if (!EC_KEY_generate_key(ecdh)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n ERR_R_ECDH_LIB);\n goto err;\n }\n }\n if (((group = EC_KEY_get0_group(ecdh)) == NULL) ||\n (EC_KEY_get0_public_key(ecdh) == NULL) ||\n (EC_KEY_get0_private_key(ecdh) == NULL)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);\n goto err;\n }\n if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&\n (EC_GROUP_get_degree(group) > 163)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER);\n goto err;\n }\n if ((curve_id =\n tls1_ec_nid2curve_id(EC_GROUP_get_curve_name(group)))\n == 0) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);\n goto err;\n }\n encodedlen = EC_POINT_point2oct(group,\n EC_KEY_get0_public_key(ecdh),\n POINT_CONVERSION_UNCOMPRESSED,\n NULL, 0, NULL);\n encodedPoint = (unsigned char *)\n OPENSSL_malloc(encodedlen * sizeof(unsigned char));\n bn_ctx = BN_CTX_new();\n if ((encodedPoint == NULL) || (bn_ctx == NULL)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n ERR_R_MALLOC_FAILURE);\n goto err;\n }\n encodedlen = EC_POINT_point2oct(group,\n EC_KEY_get0_public_key(ecdh),\n POINT_CONVERSION_UNCOMPRESSED,\n encodedPoint, encodedlen, bn_ctx);\n if (encodedlen == 0) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB);\n goto err;\n }\n BN_CTX_free(bn_ctx);\n bn_ctx = NULL;\n n = 4 + encodedlen;\n r[0] = NULL;\n r[1] = NULL;\n r[2] = NULL;\n r[3] = NULL;\n } else\n#endif\n#ifndef OPENSSL_NO_PSK\n if (type & SSL_kPSK) {\n n += 2 + strlen(s->ctx->psk_identity_hint);\n } else\n#endif\n#ifndef OPENSSL_NO_SRP\n if (type & SSL_kSRP) {\n if ((s->srp_ctx.N == NULL) ||\n (s->srp_ctx.g == NULL) ||\n (s->srp_ctx.s == NULL) || (s->srp_ctx.B == NULL)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_MISSING_SRP_PARAM);\n goto err;\n }\n r[0] = s->srp_ctx.N;\n r[1] = s->srp_ctx.g;\n r[2] = s->srp_ctx.s;\n r[3] = s->srp_ctx.B;\n } else\n#endif\n {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);\n goto f_err;\n }\n for (i = 0; i < 4 && r[i] != NULL; i++) {\n nr[i] = BN_num_bytes(r[i]);\n#ifndef OPENSSL_NO_SRP\n if ((i == 2) && (type & SSL_kSRP))\n n += 1 + nr[i];\n else\n#endif\n n += 2 + nr[i];\n }\n if (!(s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL | SSL_aSRP))\n && !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK)) {\n if ((pkey = ssl_get_sign_pkey(s, s->s3->tmp.new_cipher, &md))\n == NULL) {\n al = SSL_AD_DECODE_ERROR;\n goto f_err;\n }\n kn = EVP_PKEY_size(pkey);\n } else {\n pkey = NULL;\n kn = 0;\n }\n if (!BUF_MEM_grow_clean(buf, n + SSL_HM_HEADER_LENGTH(s) + kn)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_LIB_BUF);\n goto err;\n }\n d = p = ssl_handshake_start(s);\n for (i = 0; i < 4 && r[i] != NULL; i++) {\n#ifndef OPENSSL_NO_SRP\n if ((i == 2) && (type & SSL_kSRP)) {\n *p = nr[i];\n p++;\n } else\n#endif\n s2n(nr[i], p);\n BN_bn2bin(r[i], p);\n p += nr[i];\n }\n#ifndef OPENSSL_NO_ECDH\n if (type & SSL_kECDHE) {\n *p = NAMED_CURVE_TYPE;\n p += 1;\n *p = 0;\n p += 1;\n *p = curve_id;\n p += 1;\n *p = encodedlen;\n p += 1;\n memcpy((unsigned char *)p,\n (unsigned char *)encodedPoint, encodedlen);\n OPENSSL_free(encodedPoint);\n encodedPoint = NULL;\n p += encodedlen;\n }\n#endif\n#ifndef OPENSSL_NO_PSK\n if (type & SSL_kPSK) {\n s2n(strlen(s->ctx->psk_identity_hint), p);\n strncpy((char *)p, s->ctx->psk_identity_hint,\n strlen(s->ctx->psk_identity_hint));\n p += strlen(s->ctx->psk_identity_hint);\n }\n#endif\n if (pkey != NULL) {\n#ifndef OPENSSL_NO_RSA\n if (pkey->type == EVP_PKEY_RSA && !SSL_USE_SIGALGS(s)) {\n q = md_buf;\n j = 0;\n for (num = 2; num > 0; num--) {\n EVP_MD_CTX_set_flags(&md_ctx,\n EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);\n EVP_DigestInit_ex(&md_ctx, (num == 2)\n ? s->ctx->md5 : s->ctx->sha1, NULL);\n EVP_DigestUpdate(&md_ctx, &(s->s3->client_random[0]),\n SSL3_RANDOM_SIZE);\n EVP_DigestUpdate(&md_ctx, &(s->s3->server_random[0]),\n SSL3_RANDOM_SIZE);\n EVP_DigestUpdate(&md_ctx, d, n);\n EVP_DigestFinal_ex(&md_ctx, q, (unsigned int *)&i);\n q += i;\n j += i;\n }\n if (RSA_sign(NID_md5_sha1, md_buf, j,\n &(p[2]), &u, pkey->pkey.rsa) <= 0) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_LIB_RSA);\n goto err;\n }\n s2n(u, p);\n n += u + 2;\n } else\n#endif\n if (md) {\n if (SSL_USE_SIGALGS(s)) {\n if (!tls12_get_sigandhash(p, pkey, md)) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n p += 2;\n }\n#ifdef SSL_DEBUG\n fprintf(stderr, "Using hash %s\\n", EVP_MD_name(md));\n#endif\n EVP_SignInit_ex(&md_ctx, md, NULL);\n EVP_SignUpdate(&md_ctx, &(s->s3->client_random[0]),\n SSL3_RANDOM_SIZE);\n EVP_SignUpdate(&md_ctx, &(s->s3->server_random[0]),\n SSL3_RANDOM_SIZE);\n EVP_SignUpdate(&md_ctx, d, n);\n if (!EVP_SignFinal(&md_ctx, &(p[2]),\n (unsigned int *)&i, pkey)) {\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_LIB_EVP);\n goto err;\n }\n s2n(i, p);\n n += i + 2;\n if (SSL_USE_SIGALGS(s))\n n += 2;\n } else {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n SSL_R_UNKNOWN_PKEY_TYPE);\n goto f_err;\n }\n }\n ssl_set_handshake_header(s, SSL3_MT_SERVER_KEY_EXCHANGE, n);\n }\n s->state = SSL3_ST_SW_KEY_EXCH_B;\n EVP_MD_CTX_cleanup(&md_ctx);\n return ssl_do_write(s);\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n#ifndef OPENSSL_NO_ECDH\n if (encodedPoint != NULL)\n OPENSSL_free(encodedPoint);\n BN_CTX_free(bn_ctx);\n#endif\n EVP_MD_CTX_cleanup(&md_ctx);\n return (-1);\n}']
|
1,199
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L68
|
static inline void refill_32(BitstreamContext *bc)
{
if (bc->ptr >= bc->buffer_end)
return;
#ifdef BITSTREAM_READER_LE
bc->bits = (uint64_t)AV_RL32(bc->ptr) << bc->bits_left | bc->bits;
#else
bc->bits = bc->bits | (uint64_t)AV_RB32(bc->ptr) << (32 - bc->bits_left);
#endif
bc->ptr += 4;
bc->bits_left += 32;
}
|
['static inline int decode_slice_header(AVSContext *h, BitstreamContext *bc)\n{\n if (h->stc > 0xAF)\n av_log(h->avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\\n", h->stc);\n h->mby = h->stc;\n h->mbidx = h->mby * h->mb_width;\n h->flags &= ~(B_AVAIL | C_AVAIL);\n if ((h->mby == 0) && (!h->qp_fixed)) {\n h->qp_fixed = bitstream_read_bit(bc);\n h->qp = bitstream_read(bc, 6);\n }\n if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||\n (!h->pic_structure && h->mby >= h->mb_width / 2))\n if (bitstream_read_bit(bc)) {\n av_log(h->avctx, AV_LOG_ERROR,\n "weighted prediction not yet supported\\n");\n }\n return 0;\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}', '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 void refill_32(BitstreamContext *bc)\n{\n if (bc->ptr >= bc->buffer_end)\n return;\n#ifdef BITSTREAM_READER_LE\n bc->bits = (uint64_t)AV_RL32(bc->ptr) << bc->bits_left | bc->bits;\n#else\n bc->bits = bc->bits | (uint64_t)AV_RB32(bc->ptr) << (32 - bc->bits_left);\n#endif\n bc->ptr += 4;\n bc->bits_left += 32;\n}']
|
1,200
| 0
|
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/motion_est.c/#L176
|
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
const int size, const int h, int ref_index, int src_index,
me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){
MotionEstContext * const c= &s->me;
const int stride= c->stride;
const int uvstride= c->uvstride;
const int qpel= flags&FLAG_QPEL;
const int chroma= flags&FLAG_CHROMA;
const int dxy= subx + (suby<<(1+qpel));
const int hx= subx + (x<<(1+qpel));
const int hy= suby + (y<<(1+qpel));
uint8_t * const * const ref= c->ref[ref_index];
uint8_t * const * const src= c->src[src_index];
int d;
if(flags&FLAG_DIRECT){
assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));
if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){
const int time_pp= s->pp_time;
const int time_pb= s->pb_time;
const int mask= 2*qpel+1;
if(s->mv_type==MV_TYPE_8X8){
int i;
for(i=0; i<4; i++){
int fx = c->direct_basis_mv[i][0] + hx;
int fy = c->direct_basis_mv[i][1] + hy;
int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));
int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));
int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);
if(qpel){
c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);
c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);
}else{
c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);
c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);
}
}
}else{
int fx = c->direct_basis_mv[0][0] + hx;
int fy = c->direct_basis_mv[0][1] + hy;
int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);
int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);
int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));
int bxy= (bx&mask) + ((by&mask)<<(qpel+1));
if(qpel){
c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);
c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);
c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);
c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);
c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);
c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);
c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);
c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);
}else{
assert((fx>>1) + 16*s->mb_x >= -16);
assert((fy>>1) + 16*s->mb_y >= -16);
assert((fx>>1) + 16*s->mb_x <= s->width);
assert((fy>>1) + 16*s->mb_y <= s->height);
assert((bx>>1) + 16*s->mb_x >= -16);
assert((by>>1) + 16*s->mb_y >= -16);
assert((bx>>1) + 16*s->mb_x <= s->width);
assert((by>>1) + 16*s->mb_y <= s->height);
c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);
c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);
}
}
d = cmp_func(s, c->temp, src[0], stride, 16);
}else
d= 256*256*256*32;
}else{
int uvdxy;
if(dxy){
if(qpel){
c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride);
if(chroma){
int cx= hx/2;
int cy= hy/2;
cx= (cx>>1)|(cx&1);
cy= (cy>>1)|(cy&1);
uvdxy= (cx&1) + 2*(cy&1);
}
}else{
c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);
if(chroma)
uvdxy= dxy | (x&1) | (2*(y&1));
}
d = cmp_func(s, c->temp, src[0], stride, h);
}else{
d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
if(chroma)
uvdxy= (x&1) + 2*(y&1);
}
if(chroma){
uint8_t * const uvtemp= c->temp + 16*stride;
c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);
d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);
}
}
#if 0
if(full_pel){
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);
score_map[index]= d;
}
d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;
#endif
return d;
}
|
['int ff_pre_estimate_p_frame_motion(MpegEncContext * s,\n int mb_x, int mb_y)\n{\n MotionEstContext * const c= &s->me;\n int mx, my, dmin;\n int P[10][2];\n const int shift= 1+s->quarter_sample;\n const int xy= mb_x + mb_y*s->mb_stride;\n init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);\n assert(s->quarter_sample==0 || s->quarter_sample==1);\n c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp);\n c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;\n get_limits(s, 16*mb_x, 16*mb_y);\n c->skip=0;\n P_LEFT[0] = s->p_mv_table[xy + 1][0];\n P_LEFT[1] = s->p_mv_table[xy + 1][1];\n if(P_LEFT[0] < (c->xmin<<shift)) P_LEFT[0] = (c->xmin<<shift);\n if (s->first_slice_line) {\n c->pred_x= P_LEFT[0];\n c->pred_y= P_LEFT[1];\n P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=\n P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0;\n } else {\n P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0];\n P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1];\n P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];\n P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];\n if(P_TOP[1] < (c->ymin<<shift)) P_TOP[1] = (c->ymin<<shift);\n if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);\n if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift);\n P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);\n P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);\n c->pred_x = P_MEDIAN[0];\n c->pred_y = P_MEDIAN[1];\n }\n dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16);\n s->p_mv_table[xy][0] = mx<<shift;\n s->p_mv_table[xy][1] = my<<shift;\n return dmin;\n}', 'inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,\n int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],\n int ref_mv_scale, int size, int h)\n{\n MotionEstContext * const c= &s->me;\n if(c->flags==0 && h==16 && size==0){\n return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);\n }else{\n return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);\n }\n}', 'static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,\n int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],\n int ref_mv_scale, int flags, int size, int h)\n{\n MotionEstContext * const c= &s->me;\n int best[2]={0, 0};\n int d;\n int dmin;\n int map_generation;\n int penalty_factor;\n const int ref_mv_stride= s->mb_stride;\n const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride;\n me_cmp_func cmpf, chroma_cmpf;\n LOAD_COMMON\n LOAD_COMMON2\n if(c->pre_pass){\n penalty_factor= c->pre_penalty_factor;\n cmpf= s->dsp.me_pre_cmp[size];\n chroma_cmpf= s->dsp.me_pre_cmp[size+1];\n }else{\n penalty_factor= c->penalty_factor;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n }\n map_generation= update_map_generation(c);\n assert(cmpf);\n dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\n map[0]= map_generation;\n score_map[0]= dmin;\n if((s->pict_type == FF_B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0)\n dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor;\n if (s->first_slice_line) {\n CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n }else{\n if(dmin<((h*h*s->avctx->mv0_threshold)>>8)\n && ( P_LEFT[0] |P_LEFT[1]\n |P_TOP[0] |P_TOP[1]\n |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){\n *mx_ptr= 0;\n *my_ptr= 0;\n c->skip=1;\n return dmin;\n }\n CHECK_MV( P_MEDIAN[0] >>shift , P_MEDIAN[1] >>shift)\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)-1)\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift) , (P_MEDIAN[1]>>shift)+1)\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)-1, (P_MEDIAN[1]>>shift) )\n CHECK_CLIPPED_MV((P_MEDIAN[0]>>shift)+1, (P_MEDIAN[1]>>shift) )\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)\n CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)\n CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)\n CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)\n }\n if(dmin>h*h*4){\n if(c->pre_pass){\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)\n if(!s->first_slice_line)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)\n }else{\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)\n if(s->mb_y+1<s->end_mb_y)\n CHECK_CLIPPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,\n (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)\n }\n }\n if(c->avctx->last_predictor_count){\n const int count= c->avctx->last_predictor_count;\n const int xstart= FFMAX(0, s->mb_x - count);\n const int ystart= FFMAX(0, s->mb_y - count);\n const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);\n const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);\n int mb_y;\n for(mb_y=ystart; mb_y<yend; mb_y++){\n int mb_x;\n for(mb_x=xstart; mb_x<xend; mb_x++){\n const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;\n int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;\n int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;\n if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;\n CHECK_MV(mx,my)\n }\n }\n }\n dmin= diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n *mx_ptr= best[0];\n *my_ptr= best[1];\n return dmin;\n}', 'static av_always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags){\n MotionEstContext * const c= &s->me;\n if(c->dia_size==-1)\n return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size<-1)\n return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size<2)\n return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>1024)\n return full_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>768)\n return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else if(c->dia_size>512)\n return hex_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags, c->dia_size&0xFF);\n else if(c->dia_size>256)\n return l2s_dia_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n else\n return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);\n}', 'static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags)\n{\n MotionEstContext * const c= &s->me;\n me_cmp_func cmpf, chroma_cmpf;\n int dia_size;\n LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n for(dia_size=1; dia_size<=4; dia_size++){\n int dir;\n const int x= best[0];\n const int y= best[1];\n if(dia_size&(dia_size-1)) continue;\n if( x + dia_size > xmax\n || x - dia_size < xmin\n || y + dia_size > ymax\n || y - dia_size < ymin)\n continue;\n for(dir= 0; dir<dia_size; dir+=2){\n int d;\n CHECK_MV(x + dir , y + dia_size - dir);\n CHECK_MV(x + dia_size - dir, y - dir );\n CHECK_MV(x - dir , y - dia_size + dir);\n CHECK_MV(x - dia_size + dir, y + dir );\n }\n if(x!=best[0] || y!=best[1])\n dia_size=0;\n#if 0\n{\nint dx, dy, i;\nstatic int stats[8*8];\ndx= FFABS(x-best[0]);\ndy= FFABS(y-best[1]);\nif(dy>dx){\n dx^=dy; dy^=dx; dx^=dy;\n}\nstats[dy*8 + dx] ++;\nif(256*256*256*64 % (stats[0]+1)==0){\n for(i=0; i<64; i++){\n if((i&7)==0) printf("\\n");\n printf("%8d ", stats[i]);\n }\n printf("\\n");\n}\n}\n#endif\n }\n return dmin;\n}', 'static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,\n const int size, const int h, int ref_index, int src_index,\n me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){\n MotionEstContext * const c= &s->me;\n const int stride= c->stride;\n const int uvstride= c->uvstride;\n const int qpel= flags&FLAG_QPEL;\n const int chroma= flags&FLAG_CHROMA;\n const int dxy= subx + (suby<<(1+qpel));\n const int hx= subx + (x<<(1+qpel));\n const int hy= suby + (y<<(1+qpel));\n uint8_t * const * const ref= c->ref[ref_index];\n uint8_t * const * const src= c->src[src_index];\n int d;\n if(flags&FLAG_DIRECT){\n assert(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1));\n if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){\n const int time_pp= s->pp_time;\n const int time_pb= s->pb_time;\n const int mask= 2*qpel+1;\n if(s->mv_type==MV_TYPE_8X8){\n int i;\n for(i=0; i<4; i++){\n int fx = c->direct_basis_mv[i][0] + hx;\n int fy = c->direct_basis_mv[i][1] + hy;\n int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4));\n int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4));\n int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1);\n if(qpel){\n c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride);\n c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride);\n }else{\n c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8);\n c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8);\n }\n }\n }else{\n int fx = c->direct_basis_mv[0][0] + hx;\n int fy = c->direct_basis_mv[0][1] + hy;\n int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp);\n int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp);\n int fxy= (fx&mask) + ((fy&mask)<<(qpel+1));\n int bxy= (bx&mask) + ((by&mask)<<(qpel+1));\n if(qpel){\n c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride);\n c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride);\n c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride);\n c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride);\n c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride);\n c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride);\n c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride);\n c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride);\n }else{\n assert((fx>>1) + 16*s->mb_x >= -16);\n assert((fy>>1) + 16*s->mb_y >= -16);\n assert((fx>>1) + 16*s->mb_x <= s->width);\n assert((fy>>1) + 16*s->mb_y <= s->height);\n assert((bx>>1) + 16*s->mb_x >= -16);\n assert((by>>1) + 16*s->mb_y >= -16);\n assert((bx>>1) + 16*s->mb_x <= s->width);\n assert((by>>1) + 16*s->mb_y <= s->height);\n c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16);\n c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16);\n }\n }\n d = cmp_func(s, c->temp, src[0], stride, 16);\n }else\n d= 256*256*256*32;\n }else{\n int uvdxy;\n if(dxy){\n if(qpel){\n c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride);\n if(chroma){\n int cx= hx/2;\n int cy= hy/2;\n cx= (cx>>1)|(cx&1);\n cy= (cy>>1)|(cy&1);\n uvdxy= (cx&1) + 2*(cy&1);\n }\n }else{\n c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h);\n if(chroma)\n uvdxy= dxy | (x&1) | (2*(y&1));\n }\n d = cmp_func(s, c->temp, src[0], stride, h);\n }else{\n d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);\n if(chroma)\n uvdxy= (x&1) + 2*(y&1);\n }\n if(chroma){\n uint8_t * const uvtemp= c->temp + 16*stride;\n c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);\n c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);\n d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);\n d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);\n }\n }\n#if 0\n if(full_pel){\n const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\n score_map[index]= d;\n }\n d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor;\n#endif\n return d;\n}']
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.