id
int64
1
36.7k
label
int64
0
1
bug_url
stringlengths
91
134
bug_function
stringlengths
13
72.7k
functions
stringlengths
17
79.2k
36,701
0
https://github.com/nginx/nginx/blob/88dc647481a9280fa6cedb0bed61a34123119b3c/src/core/ngx_resolver.c/#L3723
static ngx_int_t ngx_resolver_create_name_query(ngx_resolver_t *r, ngx_resolver_node_t *rn, ngx_str_t *name) { u_char *p, *s; size_t len, nlen; ngx_uint_t ident; ngx_resolver_qs_t *qs; ngx_resolver_hdr_t *query; nlen = name->len ? (1 + name->len + 1) : 1; len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t); #if (NGX_HAVE_INET6) p = ngx_resolver_alloc(r, r->ipv6 ? len * 2 : len); #else p = ngx_resolver_alloc(r, len); #endif if (p == NULL) { return NGX_ERROR; } rn->qlen = (u_short) len; rn->query = p; #if (NGX_HAVE_INET6) if (r->ipv6) { rn->query6 = p + len; } #endif query = (ngx_resolver_hdr_t *) p; ident = ngx_random(); ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve: \"%V\" A %i", name, ident & 0xffff); query->ident_hi = (u_char) ((ident >> 8) & 0xff); query->ident_lo = (u_char) (ident & 0xff); query->flags_hi = 1; query->flags_lo = 0; query->nqs_hi = 0; query->nqs_lo = 1; query->nan_hi = 0; query->nan_lo = 0; query->nns_hi = 0; query->nns_lo = 0; query->nar_hi = 0; query->nar_lo = 0; p += sizeof(ngx_resolver_hdr_t) + nlen; qs = (ngx_resolver_qs_t *) p; qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_A; qs->class_hi = 0; qs->class_lo = 1; len = 0; p--; *p-- = '\0'; if (name->len == 0) { return NGX_DECLINED; } for (s = name->data + name->len - 1; s >= name->data; s--) { if (*s != '.') { *p = *s; len++; } else { if (len == 0 || len > 255) { return NGX_DECLINED; } *p = (u_char) len; len = 0; } p--; } if (len == 0 || len > 255) { return NGX_DECLINED; } *p = (u_char) len; #if (NGX_HAVE_INET6) if (!r->ipv6) { return NGX_OK; } p = rn->query6; ngx_memcpy(p, rn->query, rn->qlen); query = (ngx_resolver_hdr_t *) p; ident = ngx_random(); ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve: \"%V\" AAAA %i", name, ident & 0xffff); query->ident_hi = (u_char) ((ident >> 8) & 0xff); query->ident_lo = (u_char) (ident & 0xff); p += sizeof(ngx_resolver_hdr_t) + nlen; qs = (ngx_resolver_qs_t *) p; qs->type_lo = NGX_RESOLVE_AAAA; #endif return NGX_OK; }
['static void\nngx_resolver_process_srv(ngx_resolver_t *r, u_char *buf, size_t n,\n ngx_uint_t ident, ngx_uint_t code, ngx_uint_t nan,\n ngx_uint_t trunc, ngx_uint_t ans)\n{\n char *err;\n u_char *cname;\n size_t len;\n int32_t ttl;\n uint32_t hash;\n ngx_str_t name;\n ngx_uint_t type, qident, class, start, nsrvs, a, i, j;\n ngx_resolver_an_t *an;\n ngx_resolver_ctx_t *ctx, *next;\n ngx_resolver_srv_t *srvs;\n ngx_resolver_node_t *rn;\n ngx_resolver_connection_t *rec;\n if (ngx_resolver_copy(r, &name, buf,\n buf + sizeof(ngx_resolver_hdr_t), buf + n)\n != NGX_OK)\n {\n return;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0, "resolver qs:%V", &name);\n hash = ngx_crc32_short(name.data, name.len);\n rn = ngx_resolver_lookup_srv(r, &name, hash);\n if (rn == NULL || rn->query == NULL) {\n ngx_log_error(r->log_level, r->log, 0,\n "unexpected response for %V", &name);\n ngx_resolver_free(r, name.data);\n goto failed;\n }\n if (trunc && rn->tcp) {\n ngx_resolver_free(r, name.data);\n goto failed;\n }\n qident = (rn->query[0] << 8) + rn->query[1];\n if (ident != qident) {\n ngx_log_error(r->log_level, r->log, 0,\n "wrong ident %ui response for %V, expect %ui",\n ident, &name, qident);\n ngx_resolver_free(r, name.data);\n goto failed;\n }\n ngx_resolver_free(r, name.data);\n if (trunc) {\n ngx_queue_remove(&rn->queue);\n if (rn->waiting == NULL) {\n ngx_rbtree_delete(&r->srv_rbtree, &rn->node);\n ngx_resolver_free_node(r, rn);\n return;\n }\n rec = r->connections.elts;\n rec = &rec[rn->last_connection];\n rn->tcp = 1;\n (void) ngx_resolver_send_tcp_query(r, rec, rn->query, rn->qlen);\n rn->expire = ngx_time() + r->resend_timeout;\n ngx_queue_insert_head(&r->srv_resend_queue, &rn->queue);\n return;\n }\n if (code == 0 && rn->code) {\n code = rn->code;\n }\n if (code == 0 && nan == 0) {\n code = NGX_RESOLVE_NXDOMAIN;\n }\n if (code) {\n next = rn->waiting;\n rn->waiting = NULL;\n ngx_queue_remove(&rn->queue);\n ngx_rbtree_delete(&r->srv_rbtree, &rn->node);\n while (next) {\n ctx = next;\n ctx->state = code;\n ctx->valid = ngx_time() + (r->valid ? r->valid : 10);\n next = ctx->next;\n ctx->handler(ctx);\n }\n ngx_resolver_free_node(r, rn);\n return;\n }\n i = ans;\n nsrvs = 0;\n cname = NULL;\n for (a = 0; a < nan; a++) {\n start = i;\n while (i < n) {\n if (buf[i] & 0xc0) {\n i += 2;\n goto found;\n }\n if (buf[i] == 0) {\n i++;\n goto test_length;\n }\n i += 1 + buf[i];\n }\n goto short_response;\n test_length:\n if (i - start < 2) {\n err = "invalid name DNS response";\n goto invalid;\n }\n found:\n if (i + sizeof(ngx_resolver_an_t) >= n) {\n goto short_response;\n }\n an = (ngx_resolver_an_t *) &buf[i];\n type = (an->type_hi << 8) + an->type_lo;\n class = (an->class_hi << 8) + an->class_lo;\n len = (an->len_hi << 8) + an->len_lo;\n ttl = (an->ttl[0] << 24) + (an->ttl[1] << 16)\n + (an->ttl[2] << 8) + (an->ttl[3]);\n if (class != 1) {\n ngx_log_error(r->log_level, r->log, 0,\n "unexpected RR class %ui", class);\n goto failed;\n }\n if (ttl < 0) {\n ttl = 0;\n }\n rn->ttl = ngx_min(rn->ttl, (uint32_t) ttl);\n i += sizeof(ngx_resolver_an_t);\n switch (type) {\n case NGX_RESOLVE_SRV:\n if (i + 6 > n) {\n goto short_response;\n }\n if (ngx_resolver_copy(r, NULL, buf, &buf[i + 6], buf + n)\n != NGX_OK)\n {\n goto failed;\n }\n nsrvs++;\n break;\n case NGX_RESOLVE_CNAME:\n cname = &buf[i];\n break;\n case NGX_RESOLVE_DNAME:\n break;\n default:\n ngx_log_error(r->log_level, r->log, 0,\n "unexpected RR type %ui", type);\n }\n i += len;\n }\n ngx_log_debug3(NGX_LOG_DEBUG_CORE, r->log, 0,\n "resolver nsrvs:%ui cname:%p ttl:%uD",\n nsrvs, cname, rn->ttl);\n if (nsrvs) {\n srvs = ngx_resolver_calloc(r, nsrvs * sizeof(ngx_resolver_srv_t));\n if (srvs == NULL) {\n goto failed;\n }\n rn->u.srvs = srvs;\n rn->nsrvs = (u_short) nsrvs;\n j = 0;\n i = ans;\n for (a = 0; a < nan; a++) {\n for ( ;; ) {\n if (buf[i] & 0xc0) {\n i += 2;\n break;\n }\n if (buf[i] == 0) {\n i++;\n break;\n }\n i += 1 + buf[i];\n }\n an = (ngx_resolver_an_t *) &buf[i];\n type = (an->type_hi << 8) + an->type_lo;\n len = (an->len_hi << 8) + an->len_lo;\n i += sizeof(ngx_resolver_an_t);\n if (type == NGX_RESOLVE_SRV) {\n srvs[j].priority = (buf[i] << 8) + buf[i + 1];\n srvs[j].weight = (buf[i + 2] << 8) + buf[i + 3];\n if (srvs[j].weight == 0) {\n srvs[j].weight = 1;\n }\n srvs[j].port = (buf[i + 4] << 8) + buf[i + 5];\n if (ngx_resolver_copy(r, &srvs[j].name, buf, &buf[i + 6],\n buf + n)\n != NGX_OK)\n {\n goto failed;\n }\n j++;\n }\n i += len;\n }\n ngx_sort(srvs, nsrvs, sizeof(ngx_resolver_srv_t),\n ngx_resolver_cmp_srvs);\n ngx_resolver_free(r, rn->query);\n rn->query = NULL;\n ngx_queue_remove(&rn->queue);\n rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl);\n rn->expire = ngx_time() + r->expire;\n ngx_queue_insert_head(&r->srv_expire_queue, &rn->queue);\n next = rn->waiting;\n rn->waiting = NULL;\n while (next) {\n ctx = next;\n next = ctx->next;\n ngx_resolver_resolve_srv_names(ctx, rn);\n }\n return;\n }\n rn->nsrvs = 0;\n if (cname) {\n if (ngx_resolver_copy(r, &name, buf, cname, buf + n) != NGX_OK) {\n goto failed;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_CORE, r->log, 0,\n "resolver cname:\\"%V\\"", &name);\n ngx_queue_remove(&rn->queue);\n rn->cnlen = (u_short) name.len;\n rn->u.cname = name.data;\n rn->valid = ngx_time() + (r->valid ? r->valid : (time_t) rn->ttl);\n rn->expire = ngx_time() + r->expire;\n ngx_queue_insert_head(&r->srv_expire_queue, &rn->queue);\n ngx_resolver_free(r, rn->query);\n rn->query = NULL;\n#if (NGX_HAVE_INET6)\n rn->query6 = NULL;\n#endif\n ctx = rn->waiting;\n rn->waiting = NULL;\n if (ctx) {\n if (ctx->recursion++ >= NGX_RESOLVER_MAX_RECURSION) {\n do {\n ctx->state = NGX_RESOLVE_NXDOMAIN;\n next = ctx->next;\n ctx->handler(ctx);\n ctx = next;\n } while (ctx);\n return;\n }\n for (next = ctx; next; next = next->next) {\n next->node = NULL;\n }\n (void) ngx_resolve_name_locked(r, ctx, &name);\n }\n return;\n }\n ngx_log_error(r->log_level, r->log, 0, "no SRV type in DNS response");\n return;\nshort_response:\n err = "short DNS response";\ninvalid:\n ngx_log_error(r->log_level, r->log, 0, err);\n return;\nfailed:\n return;\n}', 'static ngx_int_t\nngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,\n u_char *last)\n{\n char *err;\n u_char *p, *dst;\n ssize_t len;\n ngx_uint_t i, n;\n p = src;\n len = -1;\n for (i = 0; i < 128; i++) {\n n = *p++;\n if (n == 0) {\n goto done;\n }\n if (n & 0xc0) {\n n = ((n & 0x3f) << 8) + *p;\n p = &buf[n];\n } else {\n len += 1 + n;\n p = &p[n];\n }\n if (p >= last) {\n err = "name is out of response";\n goto invalid;\n }\n }\n err = "compression pointers loop";\ninvalid:\n ngx_log_error(r->log_level, r->log, 0, err);\n return NGX_ERROR;\ndone:\n if (name == NULL) {\n return NGX_OK;\n }\n if (len == -1) {\n ngx_str_null(name);\n return NGX_OK;\n }\n dst = ngx_resolver_alloc(r, len);\n if (dst == NULL) {\n return NGX_ERROR;\n }\n name->data = dst;\n n = *src++;\n for ( ;; ) {\n if (n & 0xc0) {\n n = ((n & 0x3f) << 8) + *src;\n src = &buf[n];\n n = *src++;\n } else {\n ngx_strlow(dst, src, n);\n dst += n;\n src += n;\n n = *src++;\n if (n != 0) {\n *dst++ = \'.\';\n }\n }\n if (n == 0) {\n name->len = dst - name->data;\n return NGX_OK;\n }\n }\n}', 'static ngx_int_t\nngx_resolve_name_locked(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx,\n ngx_str_t *name)\n{\n uint32_t hash;\n ngx_int_t rc;\n ngx_str_t cname;\n ngx_uint_t i, naddrs;\n ngx_queue_t *resend_queue, *expire_queue;\n ngx_rbtree_t *tree;\n ngx_resolver_ctx_t *next, *last;\n ngx_resolver_addr_t *addrs;\n ngx_resolver_node_t *rn;\n ngx_strlow(name->data, name->data, name->len);\n hash = ngx_crc32_short(name->data, name->len);\n if (ctx->service.len) {\n rn = ngx_resolver_lookup_srv(r, name, hash);\n tree = &r->srv_rbtree;\n resend_queue = &r->srv_resend_queue;\n expire_queue = &r->srv_expire_queue;\n } else {\n rn = ngx_resolver_lookup_name(r, name, hash);\n tree = &r->name_rbtree;\n resend_queue = &r->name_resend_queue;\n expire_queue = &r->name_expire_queue;\n }\n if (rn) {\n for (last = ctx; last->next; last = last->next);\n if (rn->valid >= ngx_time()) {\n ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached");\n ngx_queue_remove(&rn->queue);\n rn->expire = ngx_time() + r->expire;\n ngx_queue_insert_head(expire_queue, &rn->queue);\n naddrs = (rn->naddrs == (u_short) -1) ? 0 : rn->naddrs;\n#if (NGX_HAVE_INET6)\n naddrs += (rn->naddrs6 == (u_short) -1) ? 0 : rn->naddrs6;\n#endif\n if (naddrs) {\n if (naddrs == 1 && rn->naddrs == 1) {\n addrs = NULL;\n } else {\n addrs = ngx_resolver_export(r, rn, 1);\n if (addrs == NULL) {\n return NGX_ERROR;\n }\n }\n last->next = rn->waiting;\n rn->waiting = NULL;\n do {\n ctx->state = NGX_OK;\n ctx->valid = rn->valid;\n ctx->naddrs = naddrs;\n if (addrs == NULL) {\n ctx->addrs = &ctx->addr;\n ctx->addr.sockaddr = (struct sockaddr *) &ctx->sin;\n ctx->addr.socklen = sizeof(struct sockaddr_in);\n ngx_memzero(&ctx->sin, sizeof(struct sockaddr_in));\n ctx->sin.sin_family = AF_INET;\n ctx->sin.sin_addr.s_addr = rn->u.addr;\n } else {\n ctx->addrs = addrs;\n }\n next = ctx->next;\n ctx->handler(ctx);\n ctx = next;\n } while (ctx);\n if (addrs != NULL) {\n ngx_resolver_free(r, addrs->sockaddr);\n ngx_resolver_free(r, addrs);\n }\n return NGX_OK;\n }\n if (rn->nsrvs) {\n last->next = rn->waiting;\n rn->waiting = NULL;\n do {\n next = ctx->next;\n ngx_resolver_resolve_srv_names(ctx, rn);\n ctx = next;\n } while (ctx);\n return NGX_OK;\n }\n if (ctx->recursion++ < NGX_RESOLVER_MAX_RECURSION) {\n cname.len = rn->cnlen;\n cname.data = rn->u.cname;\n return ngx_resolve_name_locked(r, ctx, &cname);\n }\n last->next = rn->waiting;\n rn->waiting = NULL;\n do {\n ctx->state = NGX_RESOLVE_NXDOMAIN;\n ctx->valid = ngx_time() + (r->valid ? r->valid : 10);\n next = ctx->next;\n ctx->handler(ctx);\n ctx = next;\n } while (ctx);\n return NGX_OK;\n }\n if (rn->waiting) {\n if (ctx->event == NULL && ctx->timeout) {\n ctx->event = ngx_resolver_calloc(r, sizeof(ngx_event_t));\n if (ctx->event == NULL) {\n return NGX_ERROR;\n }\n ctx->event->handler = ngx_resolver_timeout_handler;\n ctx->event->data = ctx;\n ctx->event->log = r->log;\n ctx->ident = -1;\n ngx_add_timer(ctx->event, ctx->timeout);\n }\n last->next = rn->waiting;\n rn->waiting = ctx;\n ctx->state = NGX_AGAIN;\n do {\n ctx->node = rn;\n ctx = ctx->next;\n } while (ctx);\n return NGX_AGAIN;\n }\n ngx_queue_remove(&rn->queue);\n if (rn->query) {\n ngx_resolver_free_locked(r, rn->query);\n rn->query = NULL;\n#if (NGX_HAVE_INET6)\n rn->query6 = NULL;\n#endif\n }\n if (rn->cnlen) {\n ngx_resolver_free_locked(r, rn->u.cname);\n }\n if (rn->naddrs > 1 && rn->naddrs != (u_short) -1) {\n ngx_resolver_free_locked(r, rn->u.addrs);\n }\n#if (NGX_HAVE_INET6)\n if (rn->naddrs6 > 1 && rn->naddrs6 != (u_short) -1) {\n ngx_resolver_free_locked(r, rn->u6.addrs6);\n }\n#endif\n if (rn->nsrvs) {\n for (i = 0; i < rn->nsrvs; i++) {\n if (rn->u.srvs[i].name.data) {\n ngx_resolver_free_locked(r, rn->u.srvs[i].name.data);\n }\n }\n ngx_resolver_free_locked(r, rn->u.srvs);\n }\n } else {\n rn = ngx_resolver_alloc(r, sizeof(ngx_resolver_node_t));\n if (rn == NULL) {\n return NGX_ERROR;\n }\n rn->name = ngx_resolver_dup(r, name->data, name->len);\n if (rn->name == NULL) {\n ngx_resolver_free(r, rn);\n return NGX_ERROR;\n }\n rn->node.key = hash;\n rn->nlen = (u_short) name->len;\n rn->query = NULL;\n#if (NGX_HAVE_INET6)\n rn->query6 = NULL;\n#endif\n ngx_rbtree_insert(tree, &rn->node);\n }\n if (ctx->service.len) {\n rc = ngx_resolver_create_srv_query(r, rn, name);\n } else {\n rc = ngx_resolver_create_name_query(r, rn, name);\n }\n if (rc == NGX_ERROR) {\n goto failed;\n }\n if (rc == NGX_DECLINED) {\n ngx_rbtree_delete(tree, &rn->node);\n ngx_resolver_free(r, rn->query);\n ngx_resolver_free(r, rn->name);\n ngx_resolver_free(r, rn);\n do {\n ctx->state = NGX_RESOLVE_NXDOMAIN;\n next = ctx->next;\n ctx->handler(ctx);\n ctx = next;\n } while (ctx);\n return NGX_OK;\n }\n rn->last_connection = r->last_connection++;\n if (r->last_connection == r->connections.nelts) {\n r->last_connection = 0;\n }\n rn->naddrs = (u_short) -1;\n rn->tcp = 0;\n#if (NGX_HAVE_INET6)\n rn->naddrs6 = r->ipv6 ? (u_short) -1 : 0;\n rn->tcp6 = 0;\n#endif\n rn->nsrvs = 0;\n if (ngx_resolver_send_query(r, rn) != NGX_OK) {\n goto failed;\n }\n if (ctx->event == NULL && ctx->timeout) {\n ctx->event = ngx_resolver_calloc(r, sizeof(ngx_event_t));\n if (ctx->event == NULL) {\n goto failed;\n }\n ctx->event->handler = ngx_resolver_timeout_handler;\n ctx->event->data = ctx;\n ctx->event->log = r->log;\n ctx->ident = -1;\n ngx_add_timer(ctx->event, ctx->timeout);\n }\n if (ngx_queue_empty(resend_queue)) {\n ngx_add_timer(r->event, (ngx_msec_t) (r->resend_timeout * 1000));\n }\n rn->expire = ngx_time() + r->resend_timeout;\n ngx_queue_insert_head(resend_queue, &rn->queue);\n rn->code = 0;\n rn->cnlen = 0;\n rn->valid = 0;\n rn->ttl = NGX_MAX_UINT32_VALUE;\n rn->waiting = ctx;\n ctx->state = NGX_AGAIN;\n do {\n ctx->node = rn;\n ctx = ctx->next;\n } while (ctx);\n return NGX_AGAIN;\nfailed:\n ngx_rbtree_delete(tree, &rn->node);\n if (rn->query) {\n ngx_resolver_free(r, rn->query);\n }\n ngx_resolver_free(r, rn->name);\n ngx_resolver_free(r, rn);\n return NGX_ERROR;\n}', 'static ngx_int_t\nngx_resolver_create_name_query(ngx_resolver_t *r, ngx_resolver_node_t *rn,\n ngx_str_t *name)\n{\n u_char *p, *s;\n size_t len, nlen;\n ngx_uint_t ident;\n ngx_resolver_qs_t *qs;\n ngx_resolver_hdr_t *query;\n nlen = name->len ? (1 + name->len + 1) : 1;\n len = sizeof(ngx_resolver_hdr_t) + nlen + sizeof(ngx_resolver_qs_t);\n#if (NGX_HAVE_INET6)\n p = ngx_resolver_alloc(r, r->ipv6 ? len * 2 : len);\n#else\n p = ngx_resolver_alloc(r, len);\n#endif\n if (p == NULL) {\n return NGX_ERROR;\n }\n rn->qlen = (u_short) len;\n rn->query = p;\n#if (NGX_HAVE_INET6)\n if (r->ipv6) {\n rn->query6 = p + len;\n }\n#endif\n query = (ngx_resolver_hdr_t *) p;\n ident = ngx_random();\n ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0,\n "resolve: \\"%V\\" A %i", name, ident & 0xffff);\n query->ident_hi = (u_char) ((ident >> 8) & 0xff);\n query->ident_lo = (u_char) (ident & 0xff);\n query->flags_hi = 1; query->flags_lo = 0;\n query->nqs_hi = 0; query->nqs_lo = 1;\n query->nan_hi = 0; query->nan_lo = 0;\n query->nns_hi = 0; query->nns_lo = 0;\n query->nar_hi = 0; query->nar_lo = 0;\n p += sizeof(ngx_resolver_hdr_t) + nlen;\n qs = (ngx_resolver_qs_t *) p;\n qs->type_hi = 0; qs->type_lo = NGX_RESOLVE_A;\n qs->class_hi = 0; qs->class_lo = 1;\n len = 0;\n p--;\n *p-- = \'\\0\';\n if (name->len == 0) {\n return NGX_DECLINED;\n }\n for (s = name->data + name->len - 1; s >= name->data; s--) {\n if (*s != \'.\') {\n *p = *s;\n len++;\n } else {\n if (len == 0 || len > 255) {\n return NGX_DECLINED;\n }\n *p = (u_char) len;\n len = 0;\n }\n p--;\n }\n if (len == 0 || len > 255) {\n return NGX_DECLINED;\n }\n *p = (u_char) len;\n#if (NGX_HAVE_INET6)\n if (!r->ipv6) {\n return NGX_OK;\n }\n p = rn->query6;\n ngx_memcpy(p, rn->query, rn->qlen);\n query = (ngx_resolver_hdr_t *) p;\n ident = ngx_random();\n ngx_log_debug2(NGX_LOG_DEBUG_CORE, r->log, 0,\n "resolve: \\"%V\\" AAAA %i", name, ident & 0xffff);\n query->ident_hi = (u_char) ((ident >> 8) & 0xff);\n query->ident_lo = (u_char) (ident & 0xff);\n p += sizeof(ngx_resolver_hdr_t) + nlen;\n qs = (ngx_resolver_qs_t *) p;\n qs->type_lo = NGX_RESOLVE_AAAA;\n#endif\n return NGX_OK;\n}']
36,702
0
https://github.com/nginx/nginx/blob/3d791c46f5eddaa620be1f8a90b53b7c7aaa4cf3/src/core/ngx_string.c/#L922
ngx_int_t ngx_atoi(u_char *line, size_t n) { ngx_int_t value, cutoff, cutlim; if (n == 0) { return NGX_ERROR; } cutoff = NGX_MAX_INT_T_VALUE / 10; cutlim = NGX_MAX_INT_T_VALUE % 10; for (value = 0; n--; line++) { if (*line < '0' || *line > '9') { return NGX_ERROR; } if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) { return NGX_ERROR; } value = value * 10 + (*line - '0'); } return value; }
['static char *\nngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)\n{\n char *rv;\n void *mconf;\n ngx_str_t *value;\n ngx_url_t u;\n ngx_uint_t m;\n ngx_conf_t pcf;\n ngx_http_module_t *module;\n ngx_http_conf_ctx_t *ctx, *http_ctx;\n ngx_http_upstream_srv_conf_t *uscf;\n ngx_memzero(&u, sizeof(ngx_url_t));\n value = cf->args->elts;\n u.host = value[1];\n u.no_resolve = 1;\n u.no_port = 1;\n uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE\n |NGX_HTTP_UPSTREAM_WEIGHT\n |NGX_HTTP_UPSTREAM_MAX_FAILS\n |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT\n |NGX_HTTP_UPSTREAM_DOWN\n |NGX_HTTP_UPSTREAM_BACKUP);\n if (uscf == NULL) {\n return NGX_CONF_ERROR;\n }\n ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));\n if (ctx == NULL) {\n return NGX_CONF_ERROR;\n }\n http_ctx = cf->ctx;\n ctx->main_conf = http_ctx->main_conf;\n ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);\n if (ctx->srv_conf == NULL) {\n return NGX_CONF_ERROR;\n }\n ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf;\n uscf->srv_conf = ctx->srv_conf;\n ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);\n if (ctx->loc_conf == NULL) {\n return NGX_CONF_ERROR;\n }\n for (m = 0; cf->cycle->modules[m]; m++) {\n if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {\n continue;\n }\n module = cf->cycle->modules[m]->ctx;\n if (module->create_srv_conf) {\n mconf = module->create_srv_conf(cf);\n if (mconf == NULL) {\n return NGX_CONF_ERROR;\n }\n ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf;\n }\n if (module->create_loc_conf) {\n mconf = module->create_loc_conf(cf);\n if (mconf == NULL) {\n return NGX_CONF_ERROR;\n }\n ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf;\n }\n }\n uscf->servers = ngx_array_create(cf->pool, 4,\n sizeof(ngx_http_upstream_server_t));\n if (uscf->servers == NULL) {\n return NGX_CONF_ERROR;\n }\n pcf = *cf;\n cf->ctx = ctx;\n cf->cmd_type = NGX_HTTP_UPS_CONF;\n rv = ngx_conf_parse(cf, NULL);\n *cf = pcf;\n if (rv != NGX_CONF_OK) {\n return rv;\n }\n if (uscf->servers->nelts == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "no servers are inside upstream");\n return NGX_CONF_ERROR;\n }\n return rv;\n}', 'ngx_http_upstream_srv_conf_t *\nngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)\n{\n ngx_uint_t i;\n ngx_http_upstream_server_t *us;\n ngx_http_upstream_srv_conf_t *uscf, **uscfp;\n ngx_http_upstream_main_conf_t *umcf;\n if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) {\n if (ngx_parse_url(cf->pool, u) != NGX_OK) {\n if (u->err) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "%s in upstream \\"%V\\"", u->err, &u->url);\n }\n return NULL;\n }\n }\n umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module);\n uscfp = umcf->upstreams.elts;\n for (i = 0; i < umcf->upstreams.nelts; i++) {\n if (uscfp[i]->host.len != u->host.len\n || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len)\n != 0)\n {\n continue;\n }\n if ((flags & NGX_HTTP_UPSTREAM_CREATE)\n && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE))\n {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "duplicate upstream \\"%V\\"", &u->host);\n return NULL;\n }\n if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) {\n ngx_conf_log_error(NGX_LOG_WARN, cf, 0,\n "upstream \\"%V\\" may not have port %d",\n &u->host, u->port);\n return NULL;\n }\n if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) {\n ngx_log_error(NGX_LOG_WARN, cf->log, 0,\n "upstream \\"%V\\" may not have port %d in %s:%ui",\n &u->host, uscfp[i]->port,\n uscfp[i]->file_name, uscfp[i]->line);\n return NULL;\n }\n if (uscfp[i]->port && u->port\n && uscfp[i]->port != u->port)\n {\n continue;\n }\n if (uscfp[i]->default_port && u->default_port\n && uscfp[i]->default_port != u->default_port)\n {\n continue;\n }\n if (flags & NGX_HTTP_UPSTREAM_CREATE) {\n uscfp[i]->flags = flags;\n }\n return uscfp[i];\n }\n uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t));\n if (uscf == NULL) {\n return NULL;\n }\n uscf->flags = flags;\n uscf->host = u->host;\n uscf->file_name = cf->conf_file->file.name.data;\n uscf->line = cf->conf_file->line;\n uscf->port = u->port;\n uscf->default_port = u->default_port;\n uscf->no_port = u->no_port;\n if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {\n uscf->servers = ngx_array_create(cf->pool, 1,\n sizeof(ngx_http_upstream_server_t));\n if (uscf->servers == NULL) {\n return NULL;\n }\n us = ngx_array_push(uscf->servers);\n if (us == NULL) {\n return NULL;\n }\n ngx_memzero(us, sizeof(ngx_http_upstream_server_t));\n us->addrs = u->addrs;\n us->naddrs = 1;\n }\n uscfp = ngx_array_push(&umcf->upstreams);\n if (uscfp == NULL) {\n return NULL;\n }\n *uscfp = uscf;\n return uscf;\n}', 'ngx_int_t\nngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *p;\n size_t len;\n p = u->url.data;\n len = u->url.len;\n if (len >= 5 && ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) {\n return ngx_parse_unix_domain_url(pool, u);\n }\n if (len && p[0] == \'[\') {\n return ngx_parse_inet6_url(pool, u);\n }\n return ngx_parse_inet_url(pool, u);\n}', 'static ngx_int_t\nngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)\n{\n u_char *p, *host, *port, *last, *uri, *args;\n size_t len;\n ngx_int_t n;\n struct sockaddr_in *sin;\n#if (NGX_HAVE_INET6)\n struct sockaddr_in6 *sin6;\n#endif\n u->socklen = sizeof(struct sockaddr_in);\n sin = (struct sockaddr_in *) &u->sockaddr;\n sin->sin_family = AF_INET;\n u->family = AF_INET;\n host = u->url.data;\n last = host + u->url.len;\n port = ngx_strlchr(host, last, \':\');\n uri = ngx_strlchr(host, last, \'/\');\n args = ngx_strlchr(host, last, \'?\');\n if (args) {\n if (uri == NULL || args < uri) {\n uri = args;\n }\n }\n if (uri) {\n if (u->listen || !u->uri_part) {\n u->err = "invalid host";\n return NGX_ERROR;\n }\n u->uri.len = last - uri;\n u->uri.data = uri;\n last = uri;\n if (uri < port) {\n port = NULL;\n }\n }\n if (port) {\n port++;\n len = last - port;\n n = ngx_atoi(port, len);\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n u->port = (in_port_t) n;\n sin->sin_port = htons((in_port_t) n);\n u->port_text.len = len;\n u->port_text.data = port;\n last = port - 1;\n } else {\n if (uri == NULL) {\n if (u->listen) {\n n = ngx_atoi(host, last - host);\n if (n != NGX_ERROR) {\n if (n < 1 || n > 65535) {\n u->err = "invalid port";\n return NGX_ERROR;\n }\n u->port = (in_port_t) n;\n sin->sin_port = htons((in_port_t) n);\n u->port_text.len = last - host;\n u->port_text.data = host;\n u->wildcard = 1;\n return NGX_OK;\n }\n }\n }\n u->no_port = 1;\n u->port = u->default_port;\n sin->sin_port = htons(u->default_port);\n }\n len = last - host;\n if (len == 0) {\n u->err = "no host";\n return NGX_ERROR;\n }\n u->host.len = len;\n u->host.data = host;\n if (u->listen && len == 1 && *host == \'*\') {\n sin->sin_addr.s_addr = INADDR_ANY;\n u->wildcard = 1;\n return NGX_OK;\n }\n sin->sin_addr.s_addr = ngx_inet_addr(host, len);\n if (sin->sin_addr.s_addr != INADDR_NONE) {\n if (sin->sin_addr.s_addr == INADDR_ANY) {\n u->wildcard = 1;\n }\n u->naddrs = 1;\n u->addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));\n if (u->addrs == NULL) {\n return NGX_ERROR;\n }\n sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));\n if (sin == NULL) {\n return NGX_ERROR;\n }\n ngx_memcpy(sin, u->sockaddr, sizeof(struct sockaddr_in));\n u->addrs[0].sockaddr = (struct sockaddr *) sin;\n u->addrs[0].socklen = sizeof(struct sockaddr_in);\n p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1);\n if (p == NULL) {\n return NGX_ERROR;\n }\n u->addrs[0].name.len = ngx_sprintf(p, "%V:%d",\n &u->host, u->port) - p;\n u->addrs[0].name.data = p;\n return NGX_OK;\n }\n if (u->no_resolve) {\n return NGX_OK;\n }\n if (ngx_inet_resolve_host(pool, u) != NGX_OK) {\n return NGX_ERROR;\n }\n u->family = u->addrs[0].sockaddr->sa_family;\n u->socklen = u->addrs[0].socklen;\n ngx_memcpy(u->sockaddr, u->addrs[0].sockaddr, u->addrs[0].socklen);\n switch (u->family) {\n#if (NGX_HAVE_INET6)\n case AF_INET6:\n sin6 = (struct sockaddr_in6 *) &u->sockaddr;\n if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {\n u->wildcard = 1;\n }\n break;\n#endif\n default:\n sin = (struct sockaddr_in *) &u->sockaddr;\n if (sin->sin_addr.s_addr == INADDR_ANY) {\n u->wildcard = 1;\n }\n break;\n }\n return NGX_OK;\n}', 'static ngx_inline u_char *\nngx_strlchr(u_char *p, u_char *last, u_char c)\n{\n while (p < last) {\n if (*p == c) {\n return p;\n }\n p++;\n }\n return NULL;\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_INT_T_VALUE / 10;\n cutlim = NGX_MAX_INT_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
36,703
0
https://github.com/openssl/openssl/blob/6fda11ae5a06e28fd9463e5afb60735d074904b3/crypto/evp/evp_enc.c/#L475
int is_partially_overlapping(const void *ptr1, const void *ptr2, int len) { PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2; int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) | (diff > (0 - (PTRDIFF_T)len))); return overlapped; }
['static int i2b_PVK(unsigned char **out, EVP_PKEY *pk, int enclevel,\n pem_password_cb *cb, void *u)\n{\n int outlen = 24, pklen;\n unsigned char *p = NULL, *start = NULL, *salt = NULL;\n EVP_CIPHER_CTX *cctx = NULL;\n if (enclevel)\n outlen += PVK_SALTLEN;\n pklen = do_i2b(NULL, pk, 0);\n if (pklen < 0)\n return -1;\n outlen += pklen;\n if (out == NULL)\n return outlen;\n if (*out != NULL) {\n p = *out;\n } else {\n start = p = OPENSSL_malloc(outlen);\n if (p == NULL) {\n PEMerr(PEM_F_I2B_PVK, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n }\n cctx = EVP_CIPHER_CTX_new();\n if (cctx == NULL)\n goto error;\n write_ledword(&p, MS_PVKMAGIC);\n write_ledword(&p, 0);\n if (EVP_PKEY_id(pk) == EVP_PKEY_DSA)\n write_ledword(&p, MS_KEYTYPE_SIGN);\n else\n write_ledword(&p, MS_KEYTYPE_KEYX);\n write_ledword(&p, enclevel ? 1 : 0);\n write_ledword(&p, enclevel ? PVK_SALTLEN : 0);\n write_ledword(&p, pklen);\n if (enclevel) {\n if (RAND_bytes(p, PVK_SALTLEN) <= 0)\n goto error;\n salt = p;\n p += PVK_SALTLEN;\n }\n do_i2b(&p, pk, 0);\n if (enclevel != 0) {\n char psbuf[PEM_BUFSIZE];\n unsigned char keybuf[20];\n int enctmplen, inlen;\n if (cb)\n inlen = cb(psbuf, PEM_BUFSIZE, 1, u);\n else\n inlen = PEM_def_callback(psbuf, PEM_BUFSIZE, 1, u);\n if (inlen <= 0) {\n PEMerr(PEM_F_I2B_PVK, PEM_R_BAD_PASSWORD_READ);\n goto error;\n }\n if (!derive_pvk_key(keybuf, salt, PVK_SALTLEN,\n (unsigned char *)psbuf, inlen))\n goto error;\n if (enclevel == 1)\n memset(keybuf + 5, 0, 11);\n p = salt + PVK_SALTLEN + 8;\n if (!EVP_EncryptInit_ex(cctx, EVP_rc4(), NULL, keybuf, NULL))\n goto error;\n OPENSSL_cleanse(keybuf, 20);\n if (!EVP_DecryptUpdate(cctx, p, &enctmplen, p, pklen - 8))\n goto error;\n if (!EVP_DecryptFinal_ex(cctx, p + enctmplen, &enctmplen))\n goto error;\n }\n EVP_CIPHER_CTX_free(cctx);\n if (*out == NULL)\n *out = start;\n return outlen;\n error:\n EVP_CIPHER_CTX_free(cctx);\n if (*out == NULL)\n OPENSSL_free(start);\n return -1;\n}', 'int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n const unsigned char *in, int inl)\n{\n int fix_len, cmpl = inl, ret;\n unsigned int b;\n size_t soutl;\n int blocksize;\n if (ctx->encrypt) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_INVALID_OPERATION);\n return 0;\n }\n if (ctx->cipher == NULL || ctx->cipher->prov == NULL)\n goto legacy;\n blocksize = EVP_CIPHER_CTX_block_size(ctx);\n if (ctx->cipher->cupdate == NULL || blocksize < 1) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_UPDATE_ERROR);\n return 0;\n }\n ret = ctx->cipher->cupdate(ctx->provctx, out, &soutl,\n inl + (blocksize == 1 ? 0 : blocksize), in,\n (size_t)inl);\n if (ret) {\n if (soutl > INT_MAX) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_UPDATE_ERROR);\n return 0;\n }\n *outl = soutl;\n }\n return ret;\n legacy:\n b = ctx->cipher->block_size;\n if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))\n cmpl = (cmpl + 7) / 8;\n if (inl <= 0) {\n *outl = 0;\n return inl == 0;\n }\n if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n if (b == 1 && is_partially_overlapping(out, in, cmpl)) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n return 0;\n }\n fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);\n if (fix_len < 0) {\n *outl = 0;\n return 0;\n } else\n *outl = fix_len;\n return 1;\n }\n if (ctx->flags & EVP_CIPH_NO_PADDING)\n return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);\n OPENSSL_assert(b <= sizeof(ctx->final));\n if (ctx->final_used) {\n if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n || is_partially_overlapping(out, in, b)) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n return 0;\n }\n memcpy(out, ctx->final, b);\n out += b;\n fix_len = 1;\n } else\n fix_len = 0;\n if (!evp_EncryptDecryptUpdate(ctx, out, outl, in, inl))\n return 0;\n if (b > 1 && !ctx->buf_len) {\n *outl -= b;\n ctx->final_used = 1;\n memcpy(ctx->final, &out[*outl], b);\n } else\n ctx->final_used = 0;\n if (fix_len)\n *outl += b;\n return 1;\n}', 'int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)\n{\n PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n (diff > (0 - (PTRDIFF_T)len)));\n return overlapped;\n}']
36,704
0
https://github.com/openssl/openssl/blob/9507979228e9ec95371002b75639afb2e3540e83/crypto/bn/bn_nist.c/#L762
int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, BN_CTX *ctx) { int i, top = a->top; int carry = 0; register BN_ULONG *r_d, *a_d = a->d; BN_ULONG t_d[BN_NIST_384_TOP], buf[BN_NIST_384_TOP], c_d[BN_NIST_384_TOP], *res; PTR_SIZE_INT mask; union { bn_addsub_f f; PTR_SIZE_INT p; } u; static const BIGNUM _bignum_nist_p_384_sqr = { (BN_ULONG *)_nist_p_384_sqr, sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]), sizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]), 0,BN_FLG_STATIC_DATA }; field = &_bignum_nist_p_384; if (BN_is_negative(a) || BN_ucmp(a,&_bignum_nist_p_384_sqr)>=0) return BN_nnmod(r, a, field, ctx); i = BN_ucmp(field, a); if (i == 0) { BN_zero(r); return 1; } else if (i > 0) return (r == a)? 1 : (BN_copy(r ,a) != NULL); if (r != a) { if (!bn_wexpand(r, BN_NIST_384_TOP)) return 0; r_d = r->d; nist_cp_bn(r_d, a_d, BN_NIST_384_TOP); } else r_d = a_d; nist_cp_bn_0(buf, a_d + BN_NIST_384_TOP, top - BN_NIST_384_TOP, BN_NIST_384_TOP); nist_set_256(t_d, buf, 0, 0, 0, 0, 0, 23-4, 22-4, 21-4); { register BN_ULONG *ap,t,c; ap = t_d; c=0; for (i = 3; i != 0; --i) { t= *ap; *(ap++)=((t<<1)|c)&BN_MASK2; c=(t & BN_TBIT)?1:0; } *ap=c; } carry = (int)bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2), t_d, BN_NIST_256_TOP); carry += (int)bn_add_words(r_d, r_d, buf, BN_NIST_384_TOP); nist_set_384(t_d,buf,20,19,18,17,16,15,14,13,12,23,22,21); carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP); nist_set_384(t_d,buf,19,18,17,16,15,14,13,12,20,0,23,0); carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP); nist_set_384(t_d, buf,0,0,0,0,23,22,21,20,0,0,0,0); carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP); nist_set_384(t_d,buf,0,0,0,0,0,0,23,22,21,0,0,20); carry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP); nist_set_384(t_d,buf,22,21,20,19,18,17,16,15,14,13,12,23); carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP); nist_set_384(t_d,buf,0,0,0,0,0,0,0,23,22,21,20,0); carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP); nist_set_384(t_d,buf,0,0,0,0,0,0,0,23,23,0,0,0); carry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP); u.f = bn_sub_words; if (carry > 0) carry = (int)bn_sub_words(r_d,r_d,_nist_p_384[carry-1],BN_NIST_384_TOP); else if (carry < 0) { carry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP); mask = 0-(PTR_SIZE_INT)carry; u.p = ((PTR_SIZE_INT)bn_sub_words&mask) | ((PTR_SIZE_INT)bn_add_words&~mask); } else carry = 1; mask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP); mask &= 0-(PTR_SIZE_INT)carry; res = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) | ((PTR_SIZE_INT)r_d&mask)); nist_cp_bn(r_d, res, BN_NIST_384_TOP); r->top = BN_NIST_384_TOP; bn_correct_top(r); return 1; }
['int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,\n\tBN_CTX *ctx)\n\t{\n\tint\ti, top = a->top;\n\tint\tcarry = 0;\n\tregister BN_ULONG *r_d, *a_d = a->d;\n\tBN_ULONG t_d[BN_NIST_384_TOP],\n\t buf[BN_NIST_384_TOP],\n\t\t c_d[BN_NIST_384_TOP],\n\t\t*res;\n\tPTR_SIZE_INT mask;\n\tunion { bn_addsub_f f; PTR_SIZE_INT p; } u;\n\tstatic const BIGNUM _bignum_nist_p_384_sqr = {\n\t\t(BN_ULONG *)_nist_p_384_sqr,\n\t\tsizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]),\n\t\tsizeof(_nist_p_384_sqr)/sizeof(_nist_p_384_sqr[0]),\n\t\t0,BN_FLG_STATIC_DATA };\n\tfield = &_bignum_nist_p_384;\n \tif (BN_is_negative(a) || BN_ucmp(a,&_bignum_nist_p_384_sqr)>=0)\n\t\treturn BN_nnmod(r, a, field, ctx);\n\ti = BN_ucmp(field, a);\n\tif (i == 0)\n\t\t{\n\t\tBN_zero(r);\n\t\treturn 1;\n\t\t}\n\telse if (i > 0)\n\t\treturn (r == a)? 1 : (BN_copy(r ,a) != NULL);\n\tif (r != a)\n\t\t{\n\t\tif (!bn_wexpand(r, BN_NIST_384_TOP))\n\t\t\treturn 0;\n\t\tr_d = r->d;\n\t\tnist_cp_bn(r_d, a_d, BN_NIST_384_TOP);\n\t\t}\n\telse\n\t\tr_d = a_d;\n\tnist_cp_bn_0(buf, a_d + BN_NIST_384_TOP, top - BN_NIST_384_TOP, BN_NIST_384_TOP);\n\tnist_set_256(t_d, buf, 0, 0, 0, 0, 0, 23-4, 22-4, 21-4);\n\t\t{\n\t\tregister BN_ULONG *ap,t,c;\n\t\tap = t_d;\n\t\tc=0;\n\t\tfor (i = 3; i != 0; --i)\n\t\t\t{\n\t\t\tt= *ap;\n\t\t\t*(ap++)=((t<<1)|c)&BN_MASK2;\n\t\t\tc=(t & BN_TBIT)?1:0;\n\t\t\t}\n\t\t*ap=c;\n\t\t}\n\tcarry = (int)bn_add_words(r_d+(128/BN_BITS2), r_d+(128/BN_BITS2),\n\t\tt_d, BN_NIST_256_TOP);\n\tcarry += (int)bn_add_words(r_d, r_d, buf, BN_NIST_384_TOP);\n\tnist_set_384(t_d,buf,20,19,18,17,16,15,14,13,12,23,22,21);\n\tcarry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tnist_set_384(t_d,buf,19,18,17,16,15,14,13,12,20,0,23,0);\n\tcarry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tnist_set_384(t_d, buf,0,0,0,0,23,22,21,20,0,0,0,0);\n\tcarry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tnist_set_384(t_d,buf,0,0,0,0,0,0,23,22,21,0,0,20);\n\tcarry += (int)bn_add_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tnist_set_384(t_d,buf,22,21,20,19,18,17,16,15,14,13,12,23);\n\tcarry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tnist_set_384(t_d,buf,0,0,0,0,0,0,0,23,22,21,20,0);\n\tcarry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tnist_set_384(t_d,buf,0,0,0,0,0,0,0,23,23,0,0,0);\n\tcarry -= (int)bn_sub_words(r_d, r_d, t_d, BN_NIST_384_TOP);\n\tu.f = bn_sub_words;\n\tif (carry > 0)\n\t\tcarry = (int)bn_sub_words(r_d,r_d,_nist_p_384[carry-1],BN_NIST_384_TOP);\n\telse if (carry < 0)\n\t\t{\n\t\tcarry = (int)bn_add_words(r_d,r_d,_nist_p_384[-carry-1],BN_NIST_384_TOP);\n\t\tmask = 0-(PTR_SIZE_INT)carry;\n\t\tu.p = ((PTR_SIZE_INT)bn_sub_words&mask) |\n\t\t ((PTR_SIZE_INT)bn_add_words&~mask);\n\t\t}\n\telse\n\t\tcarry = 1;\n\tmask = 0-(PTR_SIZE_INT)(*u.f)(c_d,r_d,_nist_p_384[0],BN_NIST_384_TOP);\n\tmask &= 0-(PTR_SIZE_INT)carry;\n\tres = (BN_ULONG *)(((PTR_SIZE_INT)c_d&~mask) |\n\t ((PTR_SIZE_INT)r_d&mask));\n\tnist_cp_bn(r_d, res, BN_NIST_384_TOP);\n\tr->top = BN_NIST_384_TOP;\n\tbn_correct_top(r);\n\treturn 1;\n\t}', 'BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n {\n\tBN_ULONG c,l,t;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n\tc=0;\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (n&~3)\n\t\t{\n\t\tt=a[0];\n\t\tt=(t+c)&BN_MASK2;\n\t\tc=(t < c);\n\t\tl=(t+b[0])&BN_MASK2;\n\t\tc+=(l < t);\n\t\tr[0]=l;\n\t\tt=a[1];\n\t\tt=(t+c)&BN_MASK2;\n\t\tc=(t < c);\n\t\tl=(t+b[1])&BN_MASK2;\n\t\tc+=(l < t);\n\t\tr[1]=l;\n\t\tt=a[2];\n\t\tt=(t+c)&BN_MASK2;\n\t\tc=(t < c);\n\t\tl=(t+b[2])&BN_MASK2;\n\t\tc+=(l < t);\n\t\tr[2]=l;\n\t\tt=a[3];\n\t\tt=(t+c)&BN_MASK2;\n\t\tc=(t < c);\n\t\tl=(t+b[3])&BN_MASK2;\n\t\tc+=(l < t);\n\t\tr[3]=l;\n\t\ta+=4; b+=4; r+=4; n-=4;\n\t\t}\n#endif\n\twhile(n)\n\t\t{\n\t\tt=a[0];\n\t\tt=(t+c)&BN_MASK2;\n\t\tc=(t < c);\n\t\tl=(t+b[0])&BN_MASK2;\n\t\tc+=(l < t);\n\t\tr[0]=l;\n\t\ta++; b++; r++; n--;\n\t\t}\n\treturn((BN_ULONG)c);\n\t}']
36,705
0
https://github.com/openssl/openssl/blob/ed371b8cbac0d0349667558c061c1ae380cf75eb/crypto/bn/bn_ctx.c/#L276
static unsigned int BN_STACK_pop(BN_STACK *st) { return st->indexes[--(st->depth)]; }
['int BN_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}', '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_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n mont->RR.d[i] = 0;\n mont->RR.top = ret;\n mont->RR.flags |= BN_FLG_FIXED_TOP;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int BN_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}']
36,706
0
https://github.com/libav/libav/blob/7c020e1ad37d27c9d5db4d714401f09c80e3cc44/libavformat/utils.c/#L620
static void probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) { if(st->codec->codec_id == AV_CODEC_ID_PROBE){ AVProbeData *pd = &st->probe_data; av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index); --st->probe_packets; if (pkt) { pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size); pd->buf_size += pkt->size; memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); } else { st->probe_packets = 0; if (!pd->buf_size) { av_log(s, AV_LOG_ERROR, "nothing to probe for stream %d\n", st->index); return; } } if (!st->probe_packets || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0); if(st->codec->codec_id != AV_CODEC_ID_PROBE){ pd->buf_size=0; av_freep(&pd->buf); av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); } } } }
['static void probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)\n{\n if(st->codec->codec_id == AV_CODEC_ID_PROBE){\n AVProbeData *pd = &st->probe_data;\n av_log(s, AV_LOG_DEBUG, "probing stream %d\\n", st->index);\n --st->probe_packets;\n if (pkt) {\n pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);\n memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);\n pd->buf_size += pkt->size;\n memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);\n } else {\n st->probe_packets = 0;\n if (!pd->buf_size) {\n av_log(s, AV_LOG_ERROR, "nothing to probe for stream %d\\n",\n st->index);\n return;\n }\n }\n if (!st->probe_packets ||\n av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {\n set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0);\n if(st->codec->codec_id != AV_CODEC_ID_PROBE){\n pd->buf_size=0;\n av_freep(&pd->buf);\n av_log(s, AV_LOG_DEBUG, "probed stream %d\\n", st->index);\n }\n }\n }\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if (size > (INT_MAX - 16))\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if (!ptr)\n return av_malloc(size);\n diff = ((char *)ptr)[-1];\n return (char *)realloc((char *)ptr - diff, size + diff) + diff;\n#elif HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
36,707
0
https://github.com/openssl/openssl/blob/ec04e866343d40a1e3e8e5db79557e279a2dd0d8/crypto/bn/bn_recp.c/#L118
int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y, BN_RECP_CTX *recp, BN_CTX *ctx) { int ret = 0; BIGNUM *a; const BIGNUM *ca; BN_CTX_start(ctx); if ((a = BN_CTX_get(ctx)) == NULL) goto err; if (y != NULL) { if (x == y) { if (!BN_sqr(a, x, ctx)) goto err; } else { if (!BN_mul(a, x, y, ctx)) goto err; } ca = a; } else ca = x; ret = BN_div_recp(NULL, r, ca, recp, ctx); err: BN_CTX_end(ctx); bn_check_top(r); return (ret); }
['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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'static int BN_STACK_push(BN_STACK *st, unsigned int idx)\n{\n if (st->depth == st->size) {\n unsigned int newsize =\n st->size ? (st->size * 3 / 2) : BN_CTX_START_FRAMES;\n unsigned int *newitems = OPENSSL_malloc(sizeof(*newitems) * newsize);\n if (newitems == NULL)\n return 0;\n if (st->depth)\n memcpy(newitems, st->indexes, sizeof(*newitems) * st->depth);\n OPENSSL_free(st->indexes);\n st->indexes = newitems;\n st->size = newsize;\n }\n st->indexes[(st->depth)++] = idx;\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#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'void CRYPTO_free(void *str)\n{\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', '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}']
36,708
0
https://github.com/libav/libav/blob/4f0b80599a534dcca57be3184b89b98f82bf2a2c/libavcodec/dvbsubdec.c/#L945
static void dvbsub_parse_clut_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { DVBSubContext *ctx = avctx->priv_data; const uint8_t *buf_end = buf + buf_size; int clut_id; DVBSubCLUT *clut; int entry_id, depth , full_range; int y, cr, cb, alpha; int r, g, b, r_add, g_add, b_add; #ifdef DEBUG_PACKET_CONTENTS int i; av_log(avctx, AV_LOG_INFO, "DVB clut packet:\n"); for (i=0; i < buf_size; i++) { av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); if (i % 16 == 15) av_log(avctx, AV_LOG_INFO, "\n"); } if (i % 16) av_log(avctx, AV_LOG_INFO, "\n"); #endif clut_id = *buf++; buf += 1; clut = get_clut(ctx, clut_id); if (!clut) { clut = av_malloc(sizeof(DVBSubCLUT)); memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); clut->id = clut_id; clut->next = ctx->clut_list; ctx->clut_list = clut; } while (buf + 4 < buf_end) { entry_id = *buf++; depth = (*buf) & 0xe0; if (depth == 0) { av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf); return; } full_range = (*buf++) & 1; if (full_range) { y = *buf++; cr = *buf++; cb = *buf++; alpha = *buf++; } else { y = buf[0] & 0xfc; cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4; cb = (buf[1] << 2) & 0xf0; alpha = (buf[1] << 6) & 0xc0; buf += 2; } if (y == 0) alpha = 0xff; YUV_TO_RGB1_CCIR(cb, cr); YUV_TO_RGB2_CCIR(r, g, b, y); av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha); if (depth & 0x80) clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha); if (depth & 0x40) clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha); if (depth & 0x20) clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha); } }
['static void dvbsub_parse_clut_segment(AVCodecContext *avctx,\n const uint8_t *buf, int buf_size)\n{\n DVBSubContext *ctx = avctx->priv_data;\n const uint8_t *buf_end = buf + buf_size;\n int clut_id;\n DVBSubCLUT *clut;\n int entry_id, depth , full_range;\n int y, cr, cb, alpha;\n int r, g, b, r_add, g_add, b_add;\n#ifdef DEBUG_PACKET_CONTENTS\n int i;\n av_log(avctx, AV_LOG_INFO, "DVB clut packet:\\n");\n for (i=0; i < buf_size; i++) {\n av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);\n if (i % 16 == 15)\n av_log(avctx, AV_LOG_INFO, "\\n");\n }\n if (i % 16)\n av_log(avctx, AV_LOG_INFO, "\\n");\n#endif\n clut_id = *buf++;\n buf += 1;\n clut = get_clut(ctx, clut_id);\n if (!clut) {\n clut = av_malloc(sizeof(DVBSubCLUT));\n memcpy(clut, &default_clut, sizeof(DVBSubCLUT));\n clut->id = clut_id;\n clut->next = ctx->clut_list;\n ctx->clut_list = clut;\n }\n while (buf + 4 < buf_end) {\n entry_id = *buf++;\n depth = (*buf) & 0xe0;\n if (depth == 0) {\n av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\\n", *buf);\n return;\n }\n full_range = (*buf++) & 1;\n if (full_range) {\n y = *buf++;\n cr = *buf++;\n cb = *buf++;\n alpha = *buf++;\n } else {\n y = buf[0] & 0xfc;\n cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;\n cb = (buf[1] << 2) & 0xf0;\n alpha = (buf[1] << 6) & 0xc0;\n buf += 2;\n }\n if (y == 0)\n alpha = 0xff;\n YUV_TO_RGB1_CCIR(cb, cr);\n YUV_TO_RGB2_CCIR(r, g, b, y);\n av_dlog(avctx, "clut %d := (%d,%d,%d,%d)\\n", entry_id, r, g, b, alpha);\n if (depth & 0x80)\n clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);\n if (depth & 0x40)\n clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);\n if (depth & 0x20)\n clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);\n }\n}', 'static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)\n{\n DVBSubCLUT *ptr = ctx->clut_list;\n while (ptr && ptr->id != clut_id) {\n ptr = ptr->next;\n }\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) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
36,709
0
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_mul.c/#L728
void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) { BN_ULONG *rr; #ifdef BN_COUNT printf(" bn_mul_normal %d * %d\n",na,nb); #endif if (na < nb) { int itmp; BN_ULONG *ltmp; itmp=na; na=nb; nb=itmp; ltmp=a; a=b; b=ltmp; } rr= &(r[na]); rr[0]=bn_mul_words(r,a,na,b[0]); for (;;) { if (--nb <= 0) return; rr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]); if (--nb <= 0) return; rr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]); if (--nb <= 0) return; rr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]); if (--nb <= 0) return; rr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]); rr+=4; r+=4; b+=4; } }
['int test_mod_exp(BIO *bp, BN_CTX *ctx)\n\t{\n\tBIGNUM *a,*b,*c,*d,*e;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\td=BN_new();\n\te=BN_new();\n\tBN_rand(c,30,0,1);\n\tfor (i=0; i<6; i++)\n\t\t{\n\t\tBN_rand(a,20+i*5,0,0);\n\t\tBN_rand(b,2+i,0,0);\n\t\tif (!BN_mod_exp(d,a,b,c,ctx))\n\t\t\treturn(00);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,a);\n\t\t\t\tBIO_puts(bp," ^ ");\n\t\t\t\tBN_print(bp,b);\n\t\t\t\tBIO_puts(bp," % ");\n\t\t\t\tBN_print(bp,c);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,d);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\tBN_free(d);\n\tBN_free(e);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mod_exp(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{ ret=BN_mod_exp_mont(r,a,p,m,ctx,NULL); }\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, BIGNUM *a, BIGNUM *p, BIGNUM *m, BN_CTX *ctx,\n\t BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*aa,*r;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\td= &(ctx->bn[ctx->tos++]);\n\tr= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n#if 1\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n#endif\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&val[0]);\n\tts=1;\n\tif (BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tBN_mod(&(val[0]),a,m,ctx);\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\tif (bits <= 20)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n if (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tBN_from_montgomery(rr,r,mont,ctx);\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tctx->tos-=2;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,\n\t int n, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_part_recursive %d * %d\\n",tn+n,tn+n);\n#endif\n\tif (n < 8)\n\t\t{\n\t\ti=tn+n;\n\t\tbn_mul_normal(r,a,i,b,i);\n\t\treturn;\n\t\t}\n\tbn_sub_words(t, a, &(a[n]),n);\n\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n if (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\ti=n/2;\n\t\tj=tn-i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\tj,i,p);\n\t\t\t\tmemset(&(r[n2+tn*2]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tn*2));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ttn-i,i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n\t{\n\tBN_ULONG *rr;\n#ifdef BN_COUNT\nprintf(" bn_mul_normal %d * %d\\n",na,nb);\n#endif\n\tif (na < nb)\n\t\t{\n\t\tint itmp;\n\t\tBN_ULONG *ltmp;\n\t\titmp=na; na=nb; nb=itmp;\n\t\tltmp=a; a=b; b=ltmp;\n\t\t}\n\trr= &(r[na]);\n\trr[0]=bn_mul_words(r,a,na,b[0]);\n\tfor (;;)\n\t\t{\n\t\tif (--nb <= 0) return;\n\t\trr[1]=bn_mul_add_words(&(r[1]),a,na,b[1]);\n\t\tif (--nb <= 0) return;\n\t\trr[2]=bn_mul_add_words(&(r[2]),a,na,b[2]);\n\t\tif (--nb <= 0) return;\n\t\trr[3]=bn_mul_add_words(&(r[3]),a,na,b[3]);\n\t\tif (--nb <= 0) return;\n\t\trr[4]=bn_mul_add_words(&(r[4]),a,na,b[4]);\n\t\trr+=4;\n\t\tr+=4;\n\t\tb+=4;\n\t\t}\n\t}']
36,710
0
https://github.com/openssl/openssl/blob/69588edbaa424beb71c6a9b1be416588232cb78c/crypto/err/err.c/#L402
void ERR_clear_error(void) { int i; ERR_STATE *es; es = ERR_get_state(); for (i = 0; i < ERR_NUM_ERRORS; i++) { err_clear(es, i); } es->top = es->bottom = 0; }
['void ERR_clear_error(void)\n{\n int i;\n ERR_STATE *es;\n es = ERR_get_state();\n for (i = 0; i < ERR_NUM_ERRORS; i++) {\n err_clear(es, i);\n }\n es->top = es->bottom = 0;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
36,711
0
https://gitlab.com/libtiff/libtiff/blob/3adc33842b7533066daea2516741832edc44d5fd/libtiff/tif_tile.c/#L157
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); }
['DECLAREwriteFunc(writeBufferToSeparateStrips)\n{\n\tuint32 rowsize = imagewidth * spp;\n\tuint32 rowsperstrip;\n\ttdata_t obuf = _TIFFmalloc(TIFFStripSize(out));\n\ttstrip_t strip = 0;\n\ttsample_t s;\n\tif (obuf == NULL)\n\t\treturn (0);\n\t(void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);\n\tfor (s = 0; s < spp; s++) {\n\t\tuint32 row;\n\t\tfor (row = 0; row < imagelength; row += rowsperstrip) {\n\t\t\tuint32 nrows = (row+rowsperstrip > imagelength) ?\n\t\t\t imagelength-row : rowsperstrip;\n\t\t\ttsize_t stripsize = TIFFVStripSize(out, nrows);\n\t\t\tcpContigBufToSeparateBuf(\n\t\t\t obuf, (uint8*) buf + row*rowsize + s,\n\t\t\t nrows, imagewidth, 0, 0, spp, 1);\n\t\t\tif (TIFFWriteEncodedStrip(out, strip++, obuf, stripsize) < 0) {\n\t\t\t\tTIFFError(TIFFFileName(out),\n\t\t\t\t "Error, can\'t write strip %u",\n\t\t\t\t strip - 1);\n\t\t\t\t_TIFFfree(obuf);\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t}\n\t_TIFFfree(obuf);\n\treturn 1;\n}', 'tmsize_t\nTIFFStripSize(TIFF* tif)\n{\n\tstatic const char module[] = "TIFFStripSize";\n\tuint64 m;\n\ttmsize_t n;\n\tm=TIFFStripSize64(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\nTIFFStripSize64(TIFF* tif)\n{\n\tTIFFDirectory* td = &tif->tif_dir;\n\tuint32 rps = td->td_rowsperstrip;\n\tif (rps > td->td_imagelength)\n\t\trps = td->td_imagelength;\n\treturn (TIFFVStripSize64(tif, rps));\n}', 'tmsize_t\nTIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedStrip";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint16 sample;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn ((tmsize_t) -1);\n\tif (strip >= td->td_nstrips) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Can not grow image by strips when using separate planes");\n\t\t\treturn ((tmsize_t) -1);\n\t\t}\n\t\tif (!TIFFGrowStrips(tif, 1, module))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttd->td_stripsperimage =\n\t\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t) -1);\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curstrip = strip;\n\ttif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\tif( td->td_stripbytecount[strip] > 0 )\n {\n tif->tif_curoff = 0;\n }\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\tsample = (uint16)(strip / td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))\n\t\treturn (0);\n\tif (!(*tif->tif_postencode)(tif))\n\t\treturn ((tmsize_t) -1);\n\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\tTIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 &&\n\t !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\treturn (cc);\n}', 'int\nTIFFWriteCheck(TIFF* tif, int tiles, const char* module)\n{\n\tif (tif->tif_mode == O_RDONLY) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "File not open for writing");\n\t\treturn (0);\n\t}\n\tif (tiles ^ isTiled(tif)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module, tiles ?\n\t\t "Can not write tiles to a stripped image" :\n\t\t "Can not write scanlines to a tiled image");\n\t\treturn (0);\n\t}\n\tif (!TIFFFieldSet(tif, FIELD_IMAGEDIMENSIONS)) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "Must set \\"ImageWidth\\" before writing data");\n\t\treturn (0);\n\t}\n\tif (tif->tif_dir.td_samplesperpixel == 1) {\n\t\tif (!TIFFFieldSet(tif, FIELD_PLANARCONFIG))\n tif->tif_dir.td_planarconfig = PLANARCONFIG_CONTIG;\n\t} else {\n\t\tif (!TIFFFieldSet(tif, FIELD_PLANARCONFIG)) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Must set \\"PlanarConfiguration\\" before writing data");\n\t\t\treturn (0);\n\t\t}\n\t}\n\tif (tif->tif_dir.td_stripoffset == NULL && !TIFFSetupStrips(tif)) {\n\t\ttif->tif_dir.td_nstrips = 0;\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "No space for %s arrays",\n\t\t isTiled(tif) ? "tile" : "strip");\n\t\treturn (0);\n\t}\n\tif (isTiled(tif))\n\t{\n\t\ttif->tif_tilesize = TIFFTileSize(tif);\n\t\tif (tif->tif_tilesize == 0)\n\t\t\treturn (0);\n\t}\n\telse\n\t\ttif->tif_tilesize = (tmsize_t)(-1);\n\ttif->tif_scanlinesize = TIFFScanlineSize(tif);\n\tif (tif->tif_scanlinesize == 0)\n\t\treturn (0);\n\ttif->tif_flags |= TIFF_BEENWRITING;\n\treturn (1);\n}', 'int\nTIFFSetupStrips(TIFF* tif)\n{\n\tTIFFDirectory* td = &tif->tif_dir;\n\tif (isTiled(tif))\n\t\ttd->td_stripsperimage =\n\t\t isUnspecified(tif, FIELD_TILEDIMENSIONS) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfTiles(tif);\n\telse\n\t\ttd->td_stripsperimage =\n\t\t isUnspecified(tif, FIELD_ROWSPERSTRIP) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfStrips(tif);\n\ttd->td_nstrips = td->td_stripsperimage;\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttd->td_stripsperimage /= td->td_samplesperpixel;\n\ttd->td_stripoffset = (uint64 *)\n\t _TIFFmalloc(td->td_nstrips * sizeof (uint64));\n\ttd->td_stripbytecount = (uint64 *)\n\t _TIFFmalloc(td->td_nstrips * sizeof (uint64));\n\tif (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)\n\t\treturn (0);\n\t_TIFFmemset(td->td_stripoffset, 0, td->td_nstrips*sizeof (uint64));\n\t_TIFFmemset(td->td_stripbytecount, 0, td->td_nstrips*sizeof (uint64));\n\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\tTIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);\n\treturn (1);\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}']
36,712
0
https://github.com/libav/libav/blob/4d810ad2e943a59658ddf00a397121c2b62f7157/libavformat/wavdec.c/#L152
static int wav_parse_bext_tag(AVFormatContext *s, int64_t size) { char temp[131], *coding_history; int ret, x; uint64_t time_reference; int64_t umid_parts[8], umid_mask = 0; if ((ret = wav_parse_bext_string(s, "description", 256)) < 0 || (ret = wav_parse_bext_string(s, "originator", 32)) < 0 || (ret = wav_parse_bext_string(s, "originator_reference", 32)) < 0 || (ret = wav_parse_bext_string(s, "origination_date", 10)) < 0 || (ret = wav_parse_bext_string(s, "origination_time", 8)) < 0) return ret; time_reference = avio_rl64(s->pb); snprintf(temp, sizeof(temp), "%"PRIu64, time_reference); if ((ret = av_dict_set(&s->metadata, "time_reference", temp, 0)) < 0) return ret; if (avio_rl16(s->pb) >= 1) { for (x = 0; x < 8; x++) umid_mask |= umid_parts[x] = avio_rb64(s->pb); if (umid_mask) { if (umid_parts[4] == 0 && umid_parts[5] == 0 && umid_parts[6] == 0 && umid_parts[7] == 0) { snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64, umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3]); } else { snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64 "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64, umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3], umid_parts[4], umid_parts[5], umid_parts[6], umid_parts[7]); } if ((ret = av_dict_set(&s->metadata, "umid", temp, 0)) < 0) return ret; } avio_skip(s->pb, 190); } else avio_skip(s->pb, 254); if (size > 602) { size -= 602; if (!(coding_history = av_malloc(size + 1))) return AVERROR(ENOMEM); if ((ret = avio_read(s->pb, coding_history, size)) < 0) return ret; coding_history[size] = 0; if ((ret = av_dict_set(&s->metadata, "coding_history", coding_history, AV_DICT_DONT_STRDUP_VAL)) < 0) return ret; } return 0; }
['static int wav_parse_bext_tag(AVFormatContext *s, int64_t size)\n{\n char temp[131], *coding_history;\n int ret, x;\n uint64_t time_reference;\n int64_t umid_parts[8], umid_mask = 0;\n if ((ret = wav_parse_bext_string(s, "description", 256)) < 0 ||\n (ret = wav_parse_bext_string(s, "originator", 32)) < 0 ||\n (ret = wav_parse_bext_string(s, "originator_reference", 32)) < 0 ||\n (ret = wav_parse_bext_string(s, "origination_date", 10)) < 0 ||\n (ret = wav_parse_bext_string(s, "origination_time", 8)) < 0)\n return ret;\n time_reference = avio_rl64(s->pb);\n snprintf(temp, sizeof(temp), "%"PRIu64, time_reference);\n if ((ret = av_dict_set(&s->metadata, "time_reference", temp, 0)) < 0)\n return ret;\n if (avio_rl16(s->pb) >= 1) {\n for (x = 0; x < 8; x++)\n umid_mask |= umid_parts[x] = avio_rb64(s->pb);\n if (umid_mask) {\n if (umid_parts[4] == 0 && umid_parts[5] == 0 &&\n umid_parts[6] == 0 && umid_parts[7] == 0) {\n snprintf(temp, sizeof(temp),\n "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64,\n umid_parts[0], umid_parts[1],\n umid_parts[2], umid_parts[3]);\n } else {\n snprintf(temp, sizeof(temp),\n "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64\n "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64,\n umid_parts[0], umid_parts[1],\n umid_parts[2], umid_parts[3],\n umid_parts[4], umid_parts[5],\n umid_parts[6], umid_parts[7]);\n }\n if ((ret = av_dict_set(&s->metadata, "umid", temp, 0)) < 0)\n return ret;\n }\n avio_skip(s->pb, 190);\n } else\n avio_skip(s->pb, 254);\n if (size > 602) {\n size -= 602;\n if (!(coding_history = av_malloc(size + 1)))\n return AVERROR(ENOMEM);\n if ((ret = avio_read(s->pb, coding_history, size)) < 0)\n return ret;\n coding_history[size] = 0;\n if ((ret = av_dict_set(&s->metadata, "coding_history", coding_history,\n AV_DICT_DONT_STRDUP_VAL)) < 0)\n return ret;\n }\n return 0;\n}']
36,713
0
https://github.com/libav/libav/blob/fd7f59639c43f0ab6b83ad2c1ceccafc553d7845/libavformat/electronicarts.c/#L479
static int ea_read_packet(AVFormatContext *s, AVPacket *pkt) { EaDemuxContext *ea = s->priv_data; ByteIOContext *pb = s->pb; int ret = 0; int packet_read = 0; unsigned int chunk_type, chunk_size; int key = 0; int num_samples; while (!packet_read) { chunk_type = get_le32(pb); chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8; switch (chunk_type) { case ISNh_TAG: url_fskip(pb, 32); chunk_size -= 32; case ISNd_TAG: case SCDl_TAG: case SNDC_TAG: case SDEN_TAG: if (!ea->audio_codec) { url_fskip(pb, chunk_size); break; } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR || ea->audio_codec == CODEC_ID_MP3) { num_samples = get_le32(pb); url_fskip(pb, 8); chunk_size -= 12; } ret = av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) ret = AVERROR(EIO); else { pkt->stream_index = ea->audio_stream_index; pkt->pts = 90000; pkt->pts *= ea->audio_frame_counter; pkt->pts /= ea->sample_rate; switch (ea->audio_codec) { case CODEC_ID_ADPCM_EA: ea->audio_frame_counter += ((chunk_size - 12) * 2) / ea->num_channels; break; case CODEC_ID_PCM_S16LE_PLANAR: case CODEC_ID_MP3: ea->audio_frame_counter += num_samples; break; default: ea->audio_frame_counter += chunk_size / (ea->bytes * ea->num_channels); } } packet_read = 1; break; case 0: case ISNe_TAG: case SCEl_TAG: case SEND_TAG: case SEEN_TAG: ret = AVERROR(EIO); packet_read = 1; break; case MVIh_TAG: case kVGT_TAG: case pQGT_TAG: case TGQs_TAG: key = PKT_FLAG_KEY; case MVIf_TAG: case fVGT_TAG: url_fseek(pb, -8, SEEK_CUR); chunk_size += 8; goto get_video_packet; case mTCD_TAG: url_fseek(pb, 8, SEEK_CUR); chunk_size -= 8; goto get_video_packet; case MV0K_TAG: case MPCh_TAG: key = PKT_FLAG_KEY; case MV0F_TAG: get_video_packet: ret = av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) ret = AVERROR_IO; else { pkt->stream_index = ea->video_stream_index; pkt->flags |= key; } packet_read = 1; break; default: url_fseek(pb, chunk_size, SEEK_CUR); break; } } return ret; }
['static int ea_read_packet(AVFormatContext *s,\n AVPacket *pkt)\n{\n EaDemuxContext *ea = s->priv_data;\n ByteIOContext *pb = s->pb;\n int ret = 0;\n int packet_read = 0;\n unsigned int chunk_type, chunk_size;\n int key = 0;\n int num_samples;\n while (!packet_read) {\n chunk_type = get_le32(pb);\n chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8;\n switch (chunk_type) {\n case ISNh_TAG:\n url_fskip(pb, 32);\n chunk_size -= 32;\n case ISNd_TAG:\n case SCDl_TAG:\n case SNDC_TAG:\n case SDEN_TAG:\n if (!ea->audio_codec) {\n url_fskip(pb, chunk_size);\n break;\n } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR ||\n ea->audio_codec == CODEC_ID_MP3) {\n num_samples = get_le32(pb);\n url_fskip(pb, 8);\n chunk_size -= 12;\n }\n ret = av_get_packet(pb, pkt, chunk_size);\n if (ret != chunk_size)\n ret = AVERROR(EIO);\n else {\n pkt->stream_index = ea->audio_stream_index;\n pkt->pts = 90000;\n pkt->pts *= ea->audio_frame_counter;\n pkt->pts /= ea->sample_rate;\n switch (ea->audio_codec) {\n case CODEC_ID_ADPCM_EA:\n ea->audio_frame_counter += ((chunk_size - 12) * 2) /\n ea->num_channels;\n break;\n case CODEC_ID_PCM_S16LE_PLANAR:\n case CODEC_ID_MP3:\n ea->audio_frame_counter += num_samples;\n break;\n default:\n ea->audio_frame_counter += chunk_size /\n (ea->bytes * ea->num_channels);\n }\n }\n packet_read = 1;\n break;\n case 0:\n case ISNe_TAG:\n case SCEl_TAG:\n case SEND_TAG:\n case SEEN_TAG:\n ret = AVERROR(EIO);\n packet_read = 1;\n break;\n case MVIh_TAG:\n case kVGT_TAG:\n case pQGT_TAG:\n case TGQs_TAG:\n key = PKT_FLAG_KEY;\n case MVIf_TAG:\n case fVGT_TAG:\n url_fseek(pb, -8, SEEK_CUR);\n chunk_size += 8;\n goto get_video_packet;\n case mTCD_TAG:\n url_fseek(pb, 8, SEEK_CUR);\n chunk_size -= 8;\n goto get_video_packet;\n case MV0K_TAG:\n case MPCh_TAG:\n key = PKT_FLAG_KEY;\n case MV0F_TAG:\nget_video_packet:\n ret = av_get_packet(pb, pkt, chunk_size);\n if (ret != chunk_size)\n ret = AVERROR_IO;\n else {\n pkt->stream_index = ea->video_stream_index;\n pkt->flags |= key;\n }\n packet_read = 1;\n break;\n default:\n url_fseek(pb, chunk_size, SEEK_CUR);\n break;\n }\n }\n return ret;\n}', 'int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size)\n{\n int ret= av_new_packet(pkt, size);\n if(ret<0)\n return ret;\n pkt->pos= url_ftell(s);\n ret= get_buffer(s, pkt->data, size);\n if(ret<=0)\n av_free_packet(pkt);\n else\n pkt->size= ret;\n return ret;\n}', 'int av_new_packet(AVPacket *pkt, int size)\n{\n uint8_t *data;\n if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE)\n return AVERROR(ENOMEM);\n data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (!data)\n return AVERROR(ENOMEM);\n memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n av_init_packet(pkt);\n pkt->data = data;\n pkt->size = size;\n pkt->destruct = av_destruct_packet;\n return 0;\n}']
36,714
0
https://github.com/openssl/openssl/blob/00fe865dbec8fb626a63ed9f5b0be4073597c7a8/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; } }
['int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)\n\t{\n\tSSL_SESSION *ret=NULL,data;\n\tint fatal = 0;\n\tdata.ssl_version=s->version;\n\tdata.session_id_length=len;\n\tif (len > SSL_MAX_SSL_SESSION_ID_LENGTH)\n\t\tgoto err;\n\tmemcpy(data.session_id,session_id,len);\n\tif (!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))\n\t\t{\n\t\tCRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tret=(SSL_SESSION *)lh_retrieve(s->session_ctx->sessions,&data);\n\t\tif (ret != NULL)\n\t\t CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);\n\t\tCRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\t}\n\tif (ret == NULL)\n\t\t{\n\t\tint copy=1;\n\t\ts->session_ctx->stats.sess_miss++;\n\t\tret=NULL;\n\t\tif (s->session_ctx->get_session_cb != NULL\n\t\t && (ret=s->session_ctx->get_session_cb(s,session_id,len,&copy))\n\t\t != NULL)\n\t\t\t{\n\t\t\ts->session_ctx->stats.sess_cb_hit++;\n\t\t\tif (copy)\n\t\t\t\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);\n\t\t\tif(!(s->session_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE))\n\t\t\t\tSSL_CTX_add_session(s->session_ctx,ret);\n\t\t\t}\n\t\tif (ret == NULL)\n\t\t\tgoto err;\n\t\t}\n\tif((s->verify_mode&SSL_VERIFY_PEER)\n\t && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length\n\t || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))\n\t {\n\t\tif (s->sid_ctx_length == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);\n\t\t\tfatal = 1;\n\t\t\tgoto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n#if 0\n\t\t\tSSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);\n#endif\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (ret->cipher == NULL)\n\t\t{\n\t\tunsigned char buf[5],*p;\n\t\tunsigned long l;\n\t\tp=buf;\n\t\tl=ret->cipher_id;\n\t\tl2n(l,p);\n\t\tif ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)\n\t\t\tret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));\n\t\telse\n\t\t\tret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));\n\t\tif (ret->cipher == NULL)\n\t\t\tgoto err;\n\t\t}\n#if 0\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);\n#endif\n\tif (ret->timeout < (long)(time(NULL) - ret->time))\n\t\t{\n\t\ts->session_ctx->stats.sess_timeout++;\n\t\tSSL_CTX_remove_session(s->session_ctx,ret);\n\t\tgoto err;\n\t\t}\n\ts->session_ctx->stats.sess_hit++;\n\tif (s->session != NULL)\n\t\tSSL_SESSION_free(s->session);\n\ts->session=ret;\n\ts->verify_result = s->session->verify_result;\n\treturn(1);\n err:\n\tif (ret != NULL)\n\t\tSSL_SESSION_free(ret);\n\tif (fatal)\n\t\treturn -1;\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\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}']
36,715
0
https://gitlab.com/libtiff/libtiff/blob/d85a64b6d6379c9f9b8de6ff3a26e380b0fc3e18/tools/tiff2pdf.c/#L4039
void t2p_pdf_currenttime(T2P* t2p) { struct tm* currenttime; time_t timenow; if (time(&timenow) == (time_t) -1) { TIFFError(TIFF2PDF_MODULE, "Can't get the current time: %s", strerror(errno)); timenow = (time_t) 0; } currenttime = localtime(&timenow); snprintf(t2p->pdf_datetime, sizeof(t2p->pdf_datetime), "D:%.4d%.2d%.2d%.2d%.2d%.2d", (currenttime->tm_year + 1900) % 65536, (currenttime->tm_mon + 1) % 256, (currenttime->tm_mday) % 256, (currenttime->tm_hour) % 256, (currenttime->tm_min) % 256, (currenttime->tm_sec) % 256); return; }
['void t2p_pdf_currenttime(T2P* t2p)\n{\n\tstruct tm* currenttime;\n\ttime_t timenow;\n\tif (time(&timenow) == (time_t) -1) {\n\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t "Can\'t get the current time: %s", strerror(errno));\n\t\ttimenow = (time_t) 0;\n\t}\n\tcurrenttime = localtime(&timenow);\n\tsnprintf(t2p->pdf_datetime, sizeof(t2p->pdf_datetime),\n\t\t "D:%.4d%.2d%.2d%.2d%.2d%.2d",\n\t\t (currenttime->tm_year + 1900) % 65536,\n\t\t (currenttime->tm_mon + 1) % 256,\n\t\t (currenttime->tm_mday) % 256,\n\t\t (currenttime->tm_hour) % 256,\n\t\t (currenttime->tm_min) % 256,\n\t\t (currenttime->tm_sec) % 256);\n\treturn;\n}', 'void\nTIFFError(const char* module, const char* fmt, ...)\n{\n\tva_list ap;\n\tva_start(ap, fmt);\n\tif (_TIFFerrorHandler)\n\t\t(*_TIFFerrorHandler)(module, fmt, ap);\n\tif (_TIFFerrorHandlerExt)\n\t\t(*_TIFFerrorHandlerExt)(0, module, fmt, ap);\n\tva_end(ap);\n}']
36,716
0
https://gitlab.com/libtiff/libtiff/blob/6dac309a9701d15ac52d895d566ddae2ed49db9b/libtiff/tif_swab.c/#L113
void TIFFSwabArrayOfLong(register uint32* lp, tmsize_t n) { register unsigned char *cp; register unsigned char t; assert(sizeof(uint32)==4); while (n-- > 0) { cp = (unsigned char *)lp; t = cp[3]; cp[3] = cp[0]; cp[0] = t; t = cp[2]; cp[2] = cp[1]; cp[1] = t; lp++; } }
['int\nTIFFCheckpointDirectory(TIFF* tif)\n{\n\tint rc;\n\tif (tif->tif_dir.td_stripoffset == NULL)\n\t (void) TIFFSetupStrips(tif);\n\trc = TIFFWriteDirectorySec(tif,TRUE,FALSE,NULL);\n\t(void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END));\n\treturn rc;\n}', 'static int\nTIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)\n{\n\tstatic const char module[] = "TIFFWriteDirectorySec";\n\tuint32 ndir;\n\tTIFFDirEntry* dir;\n\tuint32 dirsize;\n\tvoid* dirmem;\n\tuint32 m;\n\tif (tif->tif_mode == O_RDONLY)\n\t\treturn (1);\n _TIFFFillStriles( tif );\n\tif (imagedone)\n\t{\n\t\tif (tif->tif_flags & TIFF_POSTENCODE)\n\t\t{\n\t\t\ttif->tif_flags &= ~TIFF_POSTENCODE;\n\t\t\tif (!(*tif->tif_postencode)(tif))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t\t "Error post-encoding before directory write");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\t(*tif->tif_close)(tif);\n\t\tif (tif->tif_rawcc > 0\n\t\t && (tif->tif_flags & TIFF_BEENWRITING) != 0 )\n\t\t{\n\t\t if( !TIFFFlushData1(tif) )\n {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Error flushing data before directory write");\n\t\t\treturn (0);\n }\n\t\t}\n\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t{\n\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_rawdata = NULL;\n\t\t\ttif->tif_rawcc = 0;\n\t\t\ttif->tif_rawdatasize = 0;\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = 0;\n\t\t}\n\t\ttif->tif_flags &= ~(TIFF_BEENWRITING|TIFF_BUFFERSETUP);\n\t}\n\tdir=NULL;\n\tdirmem=NULL;\n\tdirsize=0;\n\twhile (1)\n\t{\n\t\tndir=0;\n\t\tif (isimage)\n\t\t{\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGEWIDTH,tif->tif_dir.td_imagewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_IMAGELENGTH,tif->tif_dir.td_imagelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDIMENSIONS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILEWIDTH,tif->tif_dir.td_tilewidth))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_TILELENGTH,tif->tif_dir.td_tilelength))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XRESOLUTION,tif->tif_dir.td_xresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YRESOLUTION,tif->tif_dir.td_yresolution))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_POSITION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_XPOSITION,tif->tif_dir.td_xposition))\n\t\t\t\t\tgoto bad;\n\t\t\t\tif (!TIFFWriteDirectoryTagRational(tif,&ndir,dir,TIFFTAG_YPOSITION,tif->tif_dir.td_yposition))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBFILETYPE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_SUBFILETYPE,tif->tif_dir.td_subfiletype))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_BITSPERSAMPLE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_BITSPERSAMPLE,tif->tif_dir.td_bitspersample))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COMPRESSION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_COMPRESSION,tif->tif_dir.td_compression))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PHOTOMETRIC))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PHOTOMETRIC,tif->tif_dir.td_photometric))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_THRESHHOLDING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_THRESHHOLDING,tif->tif_dir.td_threshholding))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_FILLORDER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_FILLORDER,tif->tif_dir.td_fillorder))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ORIENTATION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_ORIENTATION,tif->tif_dir.td_orientation))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLESPERPIXEL))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_SAMPLESPERPIXEL,tif->tif_dir.td_samplesperpixel))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_ROWSPERSTRIP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortLong(tif,&ndir,dir,TIFFTAG_ROWSPERSTRIP,tif->tif_dir.td_rowsperstrip))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MINSAMPLEVALUE,tif->tif_dir.td_minsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_MAXSAMPLEVALUE,tif->tif_dir.td_maxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PLANARCONFIG))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_PLANARCONFIG,tif->tif_dir.td_planarconfig))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_RESOLUTIONUNIT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_RESOLUTIONUNIT,tif->tif_dir.td_resolutionunit))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_PAGENUMBER))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_PAGENUMBER,2,&tif->tif_dir.td_pagenumber[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPBYTECOUNTS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEBYTECOUNTS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripbytecount))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_STRIPOFFSETS))\n\t\t\t{\n\t\t\t\tif (!isTiled(tif))\n\t\t\t\t{\n if (tif->tif_dir.td_stripoffset != NULL &&\n !TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n goto bad;\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_TILEOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_COLORMAP))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagColormap(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_EXTRASAMPLES))\n\t\t\t{\n\t\t\t\tif (tif->tif_dir.td_extrasamples)\n\t\t\t\t{\n\t\t\t\t\tuint16 na;\n\t\t\t\t\tuint16* nb;\n\t\t\t\t\tTIFFGetFieldDefaulted(tif,TIFFTAG_EXTRASAMPLES,&na,&nb);\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_EXTRASAMPLES,na,nb))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SAMPLEFORMAT))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortPerSample(tif,&ndir,dir,TIFFTAG_SAMPLEFORMAT,tif->tif_dir.td_sampleformat))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMINSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_sminsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSampleformatArray(tif,&ndir,dir,TIFFTAG_SMAXSAMPLEVALUE,tif->tif_dir.td_samplesperpixel,tif->tif_dir.td_smaxsamplevalue))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_IMAGEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_IMAGEDEPTH,tif->tif_dir.td_imagedepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TILEDEPTH))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,TIFFTAG_TILEDEPTH,tif->tif_dir.td_tiledepth))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_HALFTONEHINTS))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_HALFTONEHINTS,2,&tif->tif_dir.td_halftonehints[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRSUBSAMPLING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,TIFFTAG_YCBCRSUBSAMPLING,2,&tif->tif_dir.td_ycbcrsubsampling[0]))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_YCBCRPOSITIONING))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,TIFFTAG_YCBCRPOSITIONING,tif->tif_dir.td_ycbcrpositioning))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_REFBLACKWHITE))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,TIFFTAG_REFERENCEBLACKWHITE,6,tif->tif_dir.td_refblackwhite))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_TRANSFERFUNCTION))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagTransferfunction(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_INKNAMES))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,TIFFTAG_INKNAMES,tif->tif_dir.td_inknameslen,tif->tif_dir.td_inknames))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD))\n\t\t\t{\n\t\t\t\tif (!TIFFWriteDirectoryTagSubifd(tif,&ndir,dir))\n\t\t\t\t\tgoto bad;\n\t\t\t}\n\t\t\t{\n\t\t\t\tuint32 n;\n\t\t\t\tfor (n=0; n<tif->tif_nfields; n++) {\n\t\t\t\t\tconst TIFFField* o;\n\t\t\t\t\to = tif->tif_fields[n];\n\t\t\t\t\tif ((o->field_bit>=FIELD_CODEC)&&(TIFFFieldSet(tif,o->field_bit)))\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch (o->get_field_type)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase TIFF_SETGET_ASCII:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tchar* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_ASCII);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pb);\n\t\t\t\t\t\t\t\t\tpa=(uint32)(strlen(pb));\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,(uint16)o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT16:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint16 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_SHORT);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagShort(tif,&ndir,dir,(uint16)o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_UINT32:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 p;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_LONG);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==1);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==0);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&p);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagLong(tif,&ndir,dir,(uint16)o->field_tag,p))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tcase TIFF_SETGET_C32_UINT8:\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tuint32 pa;\n\t\t\t\t\t\t\t\t\tvoid* pb;\n\t\t\t\t\t\t\t\t\tassert(o->field_type==TIFF_UNDEFINED);\n\t\t\t\t\t\t\t\t\tassert(o->field_readcount==TIFF_VARIABLE2);\n\t\t\t\t\t\t\t\t\tassert(o->field_passcount==1);\n\t\t\t\t\t\t\t\t\tTIFFGetField(tif,o->field_tag,&pa,&pb);\n\t\t\t\t\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,(uint16)o->field_tag,pa,pb))\n\t\t\t\t\t\t\t\t\t\tgoto bad;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tassert(0);\n\t\t\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\t\tfor (m=0; m<(uint32)(tif->tif_dir.td_customValueCount); m++)\n\t\t{\n uint16 tag = (uint16)tif->tif_dir.td_customValues[m].info->field_tag;\n uint32 count = tif->tif_dir.td_customValues[m].count;\n\t\t\tswitch (tif->tif_dir.td_customValues[m].info->field_type)\n\t\t\t{\n\t\t\t\tcase TIFF_ASCII:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagAscii(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_UNDEFINED:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagUndefinedArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_BYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagByteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SBYTE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSbyteArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagShortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SSHORT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSshortArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlongArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_LONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagLong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SLONG8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSlong8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_RATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagRationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_SRATIONAL:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagSrationalArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_FLOAT:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagFloatArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_DOUBLE:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagDoubleArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdArray(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TIFF_IFD8:\n\t\t\t\t\tif (!TIFFWriteDirectoryTagIfdIfd8Array(tif,&ndir,dir,tag,count,tif->tif_dir.td_customValues[m].value))\n\t\t\t\t\t\tgoto bad;\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tassert(0);\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (dir!=NULL)\n\t\t\tbreak;\n\t\tdir=_TIFFmalloc(ndir*sizeof(TIFFDirEntry));\n\t\tif (dir==NULL)\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (isimage)\n\t\t{\n\t\t\tif ((tif->tif_diroff==0)&&(!TIFFLinkDirectory(tif)))\n\t\t\t\tgoto bad;\n\t\t}\n\t\telse\n\t\t\ttif->tif_diroff=(TIFFSeekFile(tif,0,SEEK_END)+1)&(~((toff_t)1));\n\t\tif (pdiroff!=NULL)\n\t\t\t*pdiroff=tif->tif_diroff;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\tdirsize=2+ndir*12+4;\n\t\telse\n\t\t\tdirsize=8+ndir*20+8;\n\t\ttif->tif_dataoff=tif->tif_diroff+dirsize;\n\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\ttif->tif_dataoff=(uint32)tif->tif_dataoff;\n\t\tif ((tif->tif_dataoff<tif->tif_diroff)||(tif->tif_dataoff<(uint64)dirsize))\n\t\t{\n\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Maximum TIFF file size exceeded");\n\t\t\tgoto bad;\n\t\t}\n\t\tif (tif->tif_dataoff&1)\n\t\t\ttif->tif_dataoff++;\n\t\tif (isimage)\n\t\t\ttif->tif_curdir++;\n\t}\n\tif (isimage)\n\t{\n\t\tif (TIFFFieldSet(tif,FIELD_SUBIFD)&&(tif->tif_subifdoff==0))\n\t\t{\n\t\t\tuint32 na;\n\t\t\tTIFFDirEntry* nb;\n\t\t\tfor (na=0, nb=dir; ; na++, nb++)\n\t\t\t{\n\t\t\t\tif( na == ndir )\n {\n TIFFErrorExt(tif->tif_clientdata,module,\n "Cannot find SubIFD tag");\n goto bad;\n }\n\t\t\t\tif (nb->tdir_tag==TIFFTAG_SUBIFD)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+2+na*12+8;\n\t\t\telse\n\t\t\t\ttif->tif_subifdoff=tif->tif_diroff+8+na*20+12;\n\t\t}\n\t}\n\tdirmem=_TIFFmalloc(dirsize);\n\tif (dirmem==NULL)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n\t\tgoto bad;\n\t}\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tuint8* n;\n\t\tuint32 nTmp;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint16*)n=(uint16)ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabShort((uint16*)n);\n\t\tn+=2;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\tnTmp = (uint32)o->tdir_count;\n\t\t\t_TIFFmemcpy(n,&nTmp,4);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong((uint32*)n);\n\t\t\tn+=4;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,4);\n\t\t\tn+=4;\n\t\t\to++;\n\t\t}\n\t\tnTmp = (uint32)tif->tif_nextdiroff;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong(&nTmp);\n\t\t_TIFFmemcpy(n,&nTmp,4);\n\t}\n\telse\n\t{\n\t\tuint8* n;\n\t\tTIFFDirEntry* o;\n\t\tn=dirmem;\n\t\t*(uint64*)n=ndir;\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t\tn+=8;\n\t\to=dir;\n\t\tfor (m=0; m<ndir; m++)\n\t\t{\n\t\t\t*(uint16*)n=o->tdir_tag;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t*(uint16*)n=o->tdir_type;\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabShort((uint16*)n);\n\t\t\tn+=2;\n\t\t\t_TIFFmemcpy(n,&o->tdir_count,8);\n\t\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\t\tTIFFSwabLong8((uint64*)n);\n\t\t\tn+=8;\n\t\t\t_TIFFmemcpy(n,&o->tdir_offset,8);\n\t\t\tn+=8;\n\t\t\to++;\n\t\t}\n\t\t_TIFFmemcpy(n,&tif->tif_nextdiroff,8);\n\t\tif (tif->tif_flags&TIFF_SWAB)\n\t\t\tTIFFSwabLong8((uint64*)n);\n\t}\n\t_TIFFfree(dir);\n\tdir=NULL;\n\tif (!SeekOK(tif,tif->tif_diroff))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\tif (!WriteOK(tif,dirmem,(tmsize_t)dirsize))\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata,module,"IO error writing directory");\n\t\tgoto bad;\n\t}\n\t_TIFFfree(dirmem);\n\tif (imagedone)\n\t{\n\t\tTIFFFreeDirectory(tif);\n\t\ttif->tif_flags &= ~TIFF_DIRTYDIRECT;\n\t\ttif->tif_flags &= ~TIFF_DIRTYSTRIP;\n\t\t(*tif->tif_cleanup)(tif);\n\t\tTIFFCreateDirectory(tif);\n\t}\n\treturn(1);\nbad:\n\tif (dir!=NULL)\n\t\t_TIFFfree(dir);\n\tif (dirmem!=NULL)\n\t\t_TIFFfree(dirmem);\n\treturn(0);\n}', 'static int\nTIFFWriteDirectoryTagLongLong8Array(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint64* value)\n{\n static const char module[] = "TIFFWriteDirectoryTagLongLong8Array";\n uint64* ma;\n uint32 mb;\n uint32* p;\n uint32* q;\n int o;\n if (dir==NULL)\n {\n (*ndir)++;\n return(1);\n }\n if( tif->tif_flags&TIFF_BIGTIFF )\n return TIFFWriteDirectoryTagCheckedLong8Array(tif,ndir,dir,\n tag,count,value);\n p = _TIFFmalloc(count*sizeof(uint32));\n if (p==NULL)\n {\n TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");\n return(0);\n }\n for (q=p, ma=value, mb=0; mb<count; ma++, mb++, q++)\n {\n if (*ma>0xFFFFFFFF)\n {\n TIFFErrorExt(tif->tif_clientdata,module,\n "Attempt to write value larger than 0xFFFFFFFF in Classic TIFF file.");\n _TIFFfree(p);\n return(0);\n }\n *q= (uint32)(*ma);\n }\n o=TIFFWriteDirectoryTagCheckedLongArray(tif,ndir,dir,tag,count,p);\n _TIFFfree(p);\n return(o);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n if (s == 0)\n return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}', 'static int\nTIFFWriteDirectoryTagCheckedLongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, uint32* value)\n{\n\tassert(count<0x40000000);\n\tassert(sizeof(uint32)==4);\n\tif (tif->tif_flags&TIFF_SWAB)\n\t\tTIFFSwabArrayOfLong(value,count);\n\treturn(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_LONG,count,count*4,value));\n}', 'void\nTIFFSwabArrayOfLong(register uint32* lp, tmsize_t n)\n{\n\tregister unsigned char *cp;\n\tregister unsigned char t;\n\tassert(sizeof(uint32)==4);\n\twhile (n-- > 0) {\n\t\tcp = (unsigned char *)lp;\n\t\tt = cp[3]; cp[3] = cp[0]; cp[0] = t;\n\t\tt = cp[2]; cp[2] = cp[1]; cp[1] = t;\n\t\tlp++;\n\t}\n}']
36,717
0
https://github.com/libav/libav/blob/21ffd4101167ef4dcc271132f950e0f9ec58a7bd/libswscale/utils.c/#L781
static void getSubSampleFactors(int *h, int *v, enum AVPixelFormat format) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format); *h = desc->log2_chroma_w; *v = desc->log2_chroma_h; }
['static void getSubSampleFactors(int *h, int *v, enum AVPixelFormat format)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);\n *h = desc->log2_chroma_w;\n *v = desc->log2_chroma_h;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
36,718
0
https://github.com/openssl/openssl/blob/033d001e907f4ca7f9a3876e6b1033dec6d7cb1b/crypto/asn1/d2i_r_pr.c/#L87
RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length) { int i=ASN1_R_PARSING; ASN1_INTEGER *bs=NULL; M_ASN1_D2I_vars(a,RSA *,RSA_new); M_ASN1_D2I_Init(); M_ASN1_D2I_start_sequence(); M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if (bs->length == 0) ret->version=0; else ret->version=bs->data[0]; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->d=BN_bin2bn(bs->data,bs->length,ret->d)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->dmp1=BN_bin2bn(bs->data,bs->length,ret->dmp1)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->dmq1=BN_bin2bn(bs->data,bs->length,ret->dmq1)) == NULL) goto err_bn; M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); if ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL) goto err_bn; M_ASN1_INTEGER_free(bs); M_ASN1_D2I_Finish_2(a); err_bn: i=ERR_R_BN_LIB; err: ASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i); if ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret); if (bs != NULL) M_ASN1_INTEGER_free(bs); return(NULL); }
['RSA *d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ASN1_R_PARSING;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,RSA *,RSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif (bs->length == 0)\n\t\tret->version=0;\n\telse\tret->version=bs->data[0];\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->n=BN_bin2bn(bs->data,bs->length,ret->n)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->e=BN_bin2bn(bs->data,bs->length,ret->e)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->d=BN_bin2bn(bs->data,bs->length,ret->d)) == NULL) goto err_bn;\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->dmp1=BN_bin2bn(bs->data,bs->length,ret->dmp1)) == NULL)\n\t\tgoto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->dmq1=BN_bin2bn(bs->data,bs->length,ret->dmq1)) == NULL)\n\t\tgoto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->iqmp=BN_bin2bn(bs->data,bs->length,ret->iqmp)) == NULL)\n\t\tgoto err_bn;\n\tM_ASN1_INTEGER_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_RSAPRIVATEKEY,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) RSA_free(ret);\n\tif (bs != NULL) M_ASN1_INTEGER_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}', 'ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,\n\t long length)\n{\n\tunsigned char *p;\n\tlong len;\n\tint i;\n\tint inf,tag,xclass;\n\tASN1_INTEGER *ret;\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\tret = c2i_ASN1_INTEGER(a, &p, len);\n\tif(ret) *pp = p;\n\treturn ret;\nerr:\n\tASN1err(ASN1_F_D2I_ASN1_INTEGER,i);\n\treturn(NULL);\n}']
36,719
0
https://github.com/openssl/openssl/blob/0b33dac3100c68ab19a6be804cdeaaa87582b9a0/ssl/s3_lib.c/#L2228
SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt, STACK_OF(SSL_CIPHER) *srvr) { SSL_CIPHER *c,*ret=NULL; STACK_OF(SSL_CIPHER) *prio, *allow; int i,j,ok; #ifndef OPENSSL_NO_TLSEXT #ifndef OPENSSL_NO_EC int ec_ok, ec_nid; unsigned char ec_search1, ec_search2; #endif #endif CERT *cert; unsigned long alg,mask,emask; cert=s->cert; #if 0 sk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp); sk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp); #endif #ifdef CIPHER_DEBUG printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), srvr); for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i) { c=sk_SSL_CIPHER_value(srvr,i); printf("%p:%s\n",c,c->name); } printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), clnt); for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i) { c=sk_SSL_CIPHER_value(clnt,i); printf("%p:%s\n",c,c->name); } #endif if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) { prio = srvr; allow = clnt; } else { prio = clnt; allow = srvr; } for (i=0; i<sk_SSL_CIPHER_num(prio); i++) { c=sk_SSL_CIPHER_value(prio,i); ssl_set_cert_masks(cert,c); mask=cert->mask; emask=cert->export_mask; #ifdef KSSL_DEBUG printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms); #endif alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK); #ifndef OPENSSL_NO_KRB5 if (alg & SSL_KRB5) { if ( !kssl_keytab_is_available(s->kssl_ctx) ) continue; } #endif #ifndef OPENSSL_NO_PSK if ((alg & SSL_PSK) && s->psk_server_callback == NULL) continue; #endif if (SSL_C_IS_EXPORT(c)) { ok=((alg & emask) == alg)?1:0; #ifdef CIPHER_DEBUG printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask, c,c->name); #endif } else { ok=((alg & mask) == alg)?1:0; #ifdef CIPHER_DEBUG printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c, c->name); #endif } #ifndef OPENSSL_NO_TLSEXT #ifndef OPENSSL_NO_EC if ( (alg & SSL_aECDSA) && (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL) && ((s->session->tlsext_ecpointformatlist_length > 0) && (s->session->tlsext_ecpointformatlist != NULL)) && ( (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info != NULL) && (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key != NULL) && (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key != NULL) && (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data != NULL) && ( (*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED) || (*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED + 1) ) ) ) { ec_ok = 0; if ( (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL) && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL) && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL) && (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field) ) { for (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++) { if (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime) { ec_ok = 1; break; } } } else if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field) { for (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++) { if (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2) { ec_ok = 1; break; } } } ok = ok && ec_ok; } if ( (alg & SSL_aECDSA) && (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL) && ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL)) ) { ec_ok = 0; if ( (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL) && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL) ) { ec_nid = EC_GROUP_get_curve_name(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group); if ((ec_nid == 0) && (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL) ) { if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field) { ec_search1 = 0xFF; ec_search2 = 0x01; } else if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field) { ec_search1 = 0xFF; ec_search2 = 0x02; } } else { ec_search1 = 0x00; ec_search2 = tls1_ec_nid2curve_id(ec_nid); } if ((ec_search1 != 0) || (ec_search2 != 0)) { for (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++) { if ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2)) { ec_ok = 1; break; } } } } ok = ok && ec_ok; } if ( ((alg & SSL_kECDH) || (alg & SSL_kECDHE)) && (s->cert->ecdh_tmp != NULL) && ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL)) ) { ec_ok = 0; if (s->cert->ecdh_tmp->group != NULL) { ec_nid = EC_GROUP_get_curve_name(s->cert->ecdh_tmp->group); if ((ec_nid == 0) && (s->cert->ecdh_tmp->group->meth != NULL) ) { if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_prime_field) { ec_search1 = 0xFF; ec_search2 = 0x01; } else if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_characteristic_two_field) { ec_search1 = 0xFF; ec_search2 = 0x02; } } else { ec_search1 = 0x00; ec_search2 = tls1_ec_nid2curve_id(ec_nid); } if ((ec_search1 != 0) || (ec_search2 != 0)) { for (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++) { if ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2)) { ec_ok = 1; break; } } } } ok = ok && ec_ok; } #endif #endif if (!ok) continue; j=sk_SSL_CIPHER_find(allow,c); if (j >= 0) { ret=sk_SSL_CIPHER_value(allow,j); break; } } return(ret); }
['SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,\n\t STACK_OF(SSL_CIPHER) *srvr)\n\t{\n\tSSL_CIPHER *c,*ret=NULL;\n\tSTACK_OF(SSL_CIPHER) *prio, *allow;\n\tint i,j,ok;\n#ifndef OPENSSL_NO_TLSEXT\n#ifndef OPENSSL_NO_EC\n\tint ec_ok, ec_nid;\n\tunsigned char ec_search1, ec_search2;\n#endif\n#endif\n\tCERT *cert;\n\tunsigned long alg,mask,emask;\n\tcert=s->cert;\n#if 0\n\tsk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp);\n\tsk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp);\n#endif\n#ifdef CIPHER_DEBUG\n printf("Server has %d from %p:\\n", sk_SSL_CIPHER_num(srvr), srvr);\n for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)\n\t {\n\t c=sk_SSL_CIPHER_value(srvr,i);\n\t printf("%p:%s\\n",c,c->name);\n\t }\n printf("Client sent %d from %p:\\n", sk_SSL_CIPHER_num(clnt), clnt);\n for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)\n\t {\n\t c=sk_SSL_CIPHER_value(clnt,i);\n\t printf("%p:%s\\n",c,c->name);\n\t }\n#endif\n\tif (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE)\n\t {\n\t prio = srvr;\n\t allow = clnt;\n\t }\n\telse\n\t {\n\t prio = clnt;\n\t allow = srvr;\n\t }\n\tfor (i=0; i<sk_SSL_CIPHER_num(prio); i++)\n\t\t{\n\t\tc=sk_SSL_CIPHER_value(prio,i);\n\t\tssl_set_cert_masks(cert,c);\n\t\tmask=cert->mask;\n\t\temask=cert->export_mask;\n#ifdef KSSL_DEBUG\n\t\tprintf("ssl3_choose_cipher %d alg= %lx\\n", i,c->algorithms);\n#endif\n\t\talg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);\n#ifndef OPENSSL_NO_KRB5\n if (alg & SSL_KRB5)\n {\n if ( !kssl_keytab_is_available(s->kssl_ctx) )\n continue;\n }\n#endif\n#ifndef OPENSSL_NO_PSK\n\t\tif ((alg & SSL_PSK) && s->psk_server_callback == NULL)\n\t\t\tcontinue;\n#endif\n\t\tif (SSL_C_IS_EXPORT(c))\n\t\t\t{\n\t\t\tok=((alg & emask) == alg)?1:0;\n#ifdef CIPHER_DEBUG\n\t\t\tprintf("%d:[%08lX:%08lX]%p:%s (export)\\n",ok,alg,emask,\n\t\t\t c,c->name);\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tok=((alg & mask) == alg)?1:0;\n#ifdef CIPHER_DEBUG\n\t\t\tprintf("%d:[%08lX:%08lX]%p:%s\\n",ok,alg,mask,c,\n\t\t\t c->name);\n#endif\n\t\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n#ifndef OPENSSL_NO_EC\n\t\tif (\n\t\t\t(alg & SSL_aECDSA)\n\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL)\n\t\t\t&& ((s->session->tlsext_ecpointformatlist_length > 0) && (s->session->tlsext_ecpointformatlist != NULL))\n\t\t\t&& (\n\t\t\t\t(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info != NULL)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key != NULL)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key != NULL)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data != NULL)\n\t\t\t\t&& (\n\t\t\t\t\t(*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED)\n\t\t\t\t\t|| (*(s->cert->pkeys[SSL_PKEY_ECC].x509->cert_info->key->public_key->data) == POINT_CONVERSION_COMPRESSED + 1)\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t)\n\t\t\t{\n\t\t\tec_ok = 0;\n\t\t\tif (\n\t\t\t\t(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL)\n\t\t\t\t&& (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field)\n\t\t\t)\n\t\t\t\t{\n\t\t\t\tfor (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++)\n\t\t\t\t\t{\n\t\t\t\t\tif (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tec_ok = 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field)\n\t\t\t\t{\n\t\t\t\tfor (j = 0; j < s->session->tlsext_ecpointformatlist_length; j++)\n\t\t\t\t\t{\n\t\t\t\t\tif (s->session->tlsext_ecpointformatlist[j] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tec_ok = 1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tok = ok && ec_ok;\n\t\t\t}\n\t\tif (\n\t\t\t(alg & SSL_aECDSA)\n\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].x509 != NULL)\n\t\t\t&& ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL))\n\t\t)\n\t\t\t{\n\t\t\tec_ok = 0;\n\t\t\tif (\n\t\t\t\t(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec != NULL)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group != NULL)\n\t\t\t)\n\t\t\t\t{\n\t\t\t\tec_nid = EC_GROUP_get_curve_name(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group);\n\t\t\t\tif ((ec_nid == 0)\n\t\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth != NULL)\n\t\t\t\t)\n\t\t\t\t\t{\n\t\t\t\t\tif (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_prime_field)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tec_search1 = 0xFF;\n\t\t\t\t\t\tec_search2 = 0x01;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (EC_METHOD_get_field_type(s->cert->pkeys[SSL_PKEY_ECC].privatekey->pkey.ec->group->meth) == NID_X9_62_characteristic_two_field)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tec_search1 = 0xFF;\n\t\t\t\t\t\tec_search2 = 0x02;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tec_search1 = 0x00;\n\t\t\t\t\tec_search2 = tls1_ec_nid2curve_id(ec_nid);\n\t\t\t\t\t}\n\t\t\t\tif ((ec_search1 != 0) || (ec_search2 != 0))\n\t\t\t\t\t{\n\t\t\t\t\tfor (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tec_ok = 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tok = ok && ec_ok;\n\t\t\t}\n\t\tif (\n\t\t\t((alg & SSL_kECDH) || (alg & SSL_kECDHE))\n\t\t\t&& (s->cert->ecdh_tmp != NULL)\n\t\t\t&& ((s->session->tlsext_ellipticcurvelist_length > 0) && (s->session->tlsext_ellipticcurvelist != NULL))\n\t\t)\n\t\t\t{\n\t\t\tec_ok = 0;\n\t\t\tif (s->cert->ecdh_tmp->group != NULL)\n\t\t\t\t{\n\t\t\t\tec_nid = EC_GROUP_get_curve_name(s->cert->ecdh_tmp->group);\n\t\t\t\tif ((ec_nid == 0)\n\t\t\t\t\t&& (s->cert->ecdh_tmp->group->meth != NULL)\n\t\t\t\t)\n\t\t\t\t\t{\n\t\t\t\t\tif (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_prime_field)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tec_search1 = 0xFF;\n\t\t\t\t\t\tec_search2 = 0x01;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (EC_METHOD_get_field_type(s->cert->ecdh_tmp->group->meth) == NID_X9_62_characteristic_two_field)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tec_search1 = 0xFF;\n\t\t\t\t\t\tec_search2 = 0x02;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tec_search1 = 0x00;\n\t\t\t\t\tec_search2 = tls1_ec_nid2curve_id(ec_nid);\n\t\t\t\t\t}\n\t\t\t\tif ((ec_search1 != 0) || (ec_search2 != 0))\n\t\t\t\t\t{\n\t\t\t\t\tfor (j = 0; j < s->session->tlsext_ellipticcurvelist_length / 2; j++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif ((s->session->tlsext_ellipticcurvelist[2*j] == ec_search1) && (s->session->tlsext_ellipticcurvelist[2*j+1] == ec_search2))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tec_ok = 1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tok = ok && ec_ok;\n\t\t\t}\n#endif\n#endif\n\t\tif (!ok) continue;\n\t\tj=sk_SSL_CIPHER_find(allow,c);\n\t\tif (j >= 0)\n\t\t\t{\n\t\t\tret=sk_SSL_CIPHER_value(allow,j);\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}']