id
int64 1
36.7k
| label
int64 0
1
| bug_url
stringlengths 91
134
| bug_function
stringlengths 13
72.7k
| functions
stringlengths 17
79.2k
|
|---|---|---|---|---|
1,601
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/asn1/asn1_lib.c/#L248
|
static void asn1_put_length(unsigned char **pp, int length)
{
unsigned char *p = *pp;
int i, l;
if (length <= 127)
*(p++) = (unsigned char)length;
else {
l = length;
for (i = 0; l > 0; i++)
l >>= 8;
*(p++) = i | 0x80;
l = i;
while (i-- > 0) {
p[i] = length & 0xff;
length >>= 8;
}
p += l;
}
*pp = p;
}
|
['static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc)\n{\n ASN1_STRING *seq = NULL;\n unsigned char *p, *pp = NULL;\n int len;\n len = i2d_ESS_SIGNING_CERT(sc, NULL);\n if ((pp = OPENSSL_malloc(len)) == NULL) {\n TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n p = pp;\n i2d_ESS_SIGNING_CERT(sc, &p);\n if ((seq = ASN1_STRING_new()) == NULL || !ASN1_STRING_set(seq, pp, len)) {\n TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n OPENSSL_free(pp);\n pp = NULL;\n return PKCS7_add_signed_attribute(si,\n NID_id_smime_aa_signingCertificate,\n V_ASN1_SEQUENCE, seq);\n err:\n ASN1_STRING_free(seq);\n OPENSSL_free(pp);\n return 0;\n}', 'IMPLEMENT_ASN1_FUNCTIONS_const(ESS_SIGNING_CERT)', 'int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)\n{\n return asn1_item_flags_i2d(val, out, it, 0);\n}', 'static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,\n const ASN1_ITEM *it, int flags)\n{\n if (out && !*out) {\n unsigned char *p, *buf;\n int len;\n len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);\n if (len <= 0)\n return len;\n buf = OPENSSL_malloc(len);\n if (buf == NULL)\n return -1;\n p = buf;\n ASN1_item_ex_i2d(&val, &p, it, -1, flags);\n *out = buf;\n return len;\n }\n return ASN1_item_ex_i2d(&val, out, it, -1, flags);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,\n const ASN1_ITEM *it, int tag, int aclass)\n{\n const ASN1_TEMPLATE *tt = NULL;\n int i, seqcontlen, seqlen, ndef = 1;\n const ASN1_EXTERN_FUNCS *ef;\n const ASN1_AUX *aux = it->funcs;\n ASN1_aux_cb *asn1_cb = 0;\n if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval)\n return 0;\n if (aux && aux->asn1_cb)\n asn1_cb = aux->asn1_cb;\n switch (it->itype) {\n case ASN1_ITYPE_PRIMITIVE:\n if (it->templates)\n return asn1_template_ex_i2d(pval, out, it->templates,\n tag, aclass);\n return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);\n case ASN1_ITYPE_MSTRING:\n return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);\n case ASN1_ITYPE_CHOICE:\n if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))\n return 0;\n i = asn1_get_choice_selector(pval, it);\n if ((i >= 0) && (i < it->tcount)) {\n ASN1_VALUE **pchval;\n const ASN1_TEMPLATE *chtt;\n chtt = it->templates + i;\n pchval = asn1_get_field_ptr(pval, chtt);\n return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass);\n }\n if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))\n return 0;\n break;\n case ASN1_ITYPE_EXTERN:\n ef = it->funcs;\n return ef->asn1_ex_i2d(pval, out, it, tag, aclass);\n case ASN1_ITYPE_NDEF_SEQUENCE:\n if (aclass & ASN1_TFLG_NDEF)\n ndef = 2;\n case ASN1_ITYPE_SEQUENCE:\n i = asn1_enc_restore(&seqcontlen, out, pval, it);\n if (i < 0)\n return 0;\n if (i > 0)\n return seqcontlen;\n seqcontlen = 0;\n if (tag == -1) {\n tag = V_ASN1_SEQUENCE;\n aclass = (aclass & ~ASN1_TFLG_TAG_CLASS)\n | V_ASN1_UNIVERSAL;\n }\n if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))\n return 0;\n for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {\n const ASN1_TEMPLATE *seqtt;\n ASN1_VALUE **pseqval;\n seqtt = asn1_do_adb(pval, tt, 1);\n if (!seqtt)\n return 0;\n pseqval = asn1_get_field_ptr(pval, seqtt);\n seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt,\n -1, aclass);\n }\n seqlen = ASN1_object_size(ndef, seqcontlen, tag);\n if (!out)\n return seqlen;\n ASN1_put_object(out, ndef, seqcontlen, tag, aclass);\n for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {\n const ASN1_TEMPLATE *seqtt;\n ASN1_VALUE **pseqval;\n seqtt = asn1_do_adb(pval, tt, 1);\n if (!seqtt)\n return 0;\n pseqval = asn1_get_field_ptr(pval, seqtt);\n asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass);\n }\n if (ndef == 2)\n ASN1_put_eoc(out);\n if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL))\n return 0;\n return seqlen;\n default:\n return 0;\n }\n return 0;\n}', 'static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,\n const ASN1_ITEM *it, int tag, int aclass)\n{\n int len;\n int utype;\n int usetag;\n int ndef = 0;\n utype = it->utype;\n len = asn1_ex_i2c(pval, NULL, &utype, it);\n if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||\n (utype == V_ASN1_OTHER))\n usetag = 0;\n else\n usetag = 1;\n if (len == -1)\n return 0;\n if (len == -2) {\n ndef = 2;\n len = 0;\n }\n if (tag == -1)\n tag = utype;\n if (out) {\n if (usetag)\n ASN1_put_object(out, ndef, len, tag, aclass);\n asn1_ex_i2c(pval, *out, &utype, it);\n if (ndef)\n ASN1_put_eoc(out);\n else\n *out += len;\n }\n if (usetag)\n return ASN1_object_size(ndef, len, tag);\n return len;\n}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n int xclass)\n{\n unsigned char *p = *pp;\n int i, ttag;\n i = (constructed) ? V_ASN1_CONSTRUCTED : 0;\n i |= (xclass & V_ASN1_PRIVATE);\n if (tag < 31)\n *(p++) = i | (tag & V_ASN1_PRIMITIVE_TAG);\n else {\n *(p++) = i | V_ASN1_PRIMITIVE_TAG;\n for (i = 0, ttag = tag; ttag > 0; i++)\n ttag >>= 7;\n ttag = i;\n while (i-- > 0) {\n p[i] = tag & 0x7f;\n if (i != (ttag - 1))\n p[i] |= 0x80;\n tag >>= 7;\n }\n p += ttag;\n }\n if (constructed == 2)\n *(p++) = 0x80;\n else\n asn1_put_length(&p, length);\n *pp = p;\n}', 'static void asn1_put_length(unsigned char **pp, int length)\n{\n unsigned char *p = *pp;\n int i, l;\n if (length <= 127)\n *(p++) = (unsigned char)length;\n else {\n l = length;\n for (i = 0; l > 0; i++)\n l >>= 8;\n *(p++) = i | 0x80;\n l = i;\n while (i-- > 0) {\n p[i] = length & 0xff;\n length >>= 8;\n }\n p += l;\n }\n *pp = p;\n}']
|
1,602
| 0
|
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\n const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)\n{\n BIGNUM *t;\n int found = 0;\n int i, j, c1 = 0;\n BN_CTX *ctx = NULL;\n prime_t *mods = NULL;\n int checks = BN_prime_checks_for_size(bits);\n if (bits < 2) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n } else if (bits == 2 && safe) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);\n if (mods == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n loop:\n if (add == NULL) {\n if (!probable_prime(ret, bits, mods))\n goto err;\n } else {\n if (safe) {\n if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))\n goto err;\n } else {\n if (!bn_probable_prime_dh(ret, bits, add, rem, ctx))\n goto err;\n }\n }\n if (!BN_GENCB_call(cb, 0, c1++))\n goto err;\n if (!safe) {\n i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);\n if (i == -1)\n goto err;\n if (i == 0)\n goto loop;\n } else {\n if (!BN_rshift1(t, ret))\n goto err;\n for (i = 0; i < checks; i++) {\n j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n if (!BN_GENCB_call(cb, 2, c1 - 1))\n goto err;\n }\n }\n found = 1;\n err:\n OPENSSL_free(mods);\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n bn_check_top(ret);\n return found;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int bn_probable_prime_dh(BIGNUM *rnd, int bits,\n const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *t1;\n BN_CTX_start(ctx);\n if ((t1 = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_rand(rnd, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n goto err;\n if (!BN_mod(t1, rnd, add, ctx))\n goto err;\n if (!BN_sub(rnd, rnd, t1))\n goto err;\n if (rem == NULL) {\n if (!BN_add_word(rnd, 1))\n goto err;\n } else {\n if (!BN_add(rnd, rnd, rem))\n goto err;\n }\n loop:\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(rnd, (BN_ULONG)primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod <= 1) {\n if (!BN_add(rnd, rnd, add))\n goto err;\n goto loop;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(rnd);\n return ret;\n}', '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("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,603
| 0
|
https://github.com/libav/libav/blob/490a022d86ef1c506a79744c5a95368af356fc69/libavformat/utils.c/#L2553
|
void avformat_free_context(AVFormatContext *s)
{
int i;
AVStream *st;
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_metadata_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
av_metadata_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_metadata_free(&s->metadata);
av_freep(&s->key);
av_free(s);
}
|
['void ff_rtsp_close_streams(AVFormatContext *s)\n{\n RTSPState *rt = s->priv_data;\n int i;\n RTSPStream *rtsp_st;\n ff_rtsp_undo_setup(s);\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n rtsp_st = rt->rtsp_streams[i];\n if (rtsp_st) {\n if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context)\n rtsp_st->dynamic_handler->close(\n rtsp_st->dynamic_protocol_context);\n av_free(rtsp_st);\n }\n }\n av_free(rt->rtsp_streams);\n if (rt->asf_ctx) {\n av_close_input_stream (rt->asf_ctx);\n rt->asf_ctx = NULL;\n }\n av_free(rt->p);\n av_free(rt->recvbuf);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n flush_packet_queue(s);\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n avformat_free_context(s);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_metadata_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_metadata_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_metadata_free(&s->metadata);\n av_freep(&s->key);\n av_free(s);\n}']
|
1,604
| 0
|
https://gitlab.com/libtiff/libtiff/blob/bfbc717684115d7beb96c82255dad2dd4a4b8845/libtiff/tif_tile.c/#L113
|
int
TIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s)
{
TIFFDirectory *td = &tif->tif_dir;
if (x >= td->td_imagewidth) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Col out of range, max %lu",
(unsigned long) x,
(unsigned long) (td->td_imagewidth - 1));
return (0);
}
if (y >= td->td_imagelength) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Row out of range, max %lu",
(unsigned long) y,
(unsigned long) (td->td_imagelength - 1));
return (0);
}
if (z >= td->td_imagedepth) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Depth out of range, max %lu",
(unsigned long) z,
(unsigned long) (td->td_imagedepth - 1));
return (0);
}
if (td->td_planarconfig == PLANARCONFIG_SEPARATE &&
s >= td->td_samplesperpixel) {
TIFFErrorExt(tif->tif_clientdata, tif->tif_name,
"%lu: Sample out of range, max %lu",
(unsigned long) s,
(unsigned long) (td->td_samplesperpixel - 1));
return (0);
}
return (1);
}
|
['static int writeBufferToContigTiles (TIFF* out, uint8* buf, uint32 imagelength,\n\t\t\t\t uint32 imagewidth, tsample_t spp,\n struct dump_opts* dump)\n {\n uint16 bps;\n uint32 tl, tw;\n uint32 row, col, nrow, ncol;\n uint32 src_rowsize, col_offset;\n uint32 tile_rowsize = TIFFTileRowSize(out);\n uint8* bufp = (uint8*) buf;\n tsize_t tile_buffsize = 0;\n tsize_t tilesize = TIFFTileSize(out);\n unsigned char *tilebuf = NULL;\n TIFFGetField(out, TIFFTAG_TILELENGTH, &tl);\n TIFFGetField(out, TIFFTAG_TILEWIDTH, &tw);\n TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps);\n tile_buffsize = tilesize;\n if (tilesize < (tsize_t)(tl * tile_rowsize))\n {\n#ifdef DEBUG2\n TIFFError("writeBufferToContigTiles",\n\t "Tilesize %lu is too small, using alternate calculation %u",\n tilesize, tl * tile_rowsize);\n#endif\n tile_buffsize = tl * tile_rowsize;\n }\n tilebuf = _TIFFmalloc(tile_buffsize);\n if (tilebuf == 0)\n return 1;\n src_rowsize = ((imagewidth * spp * bps) + 7) / 8;\n for (row = 0; row < imagelength; row += tl)\n {\n nrow = (row + tl > imagelength) ? imagelength - row : tl;\n for (col = 0; col < imagewidth; col += tw)\n {\n if (col + tw > imagewidth)\n\tncol = imagewidth - col;\n else\n ncol = tw;\n col_offset = (((col * bps * spp) + 7) / 8);\n bufp = buf + (row * src_rowsize) + col_offset;\n if (extractContigSamplesToTileBuffer(tilebuf, bufp, nrow, ncol, imagewidth,\n\t\t\t\t\t tw, 0, spp, spp, bps, dump) > 0)\n {\n\tTIFFError("writeBufferToContigTiles",\n "Unable to extract data to tile for row %lu, col %lu",\n (unsigned long) row, (unsigned long)col);\n\t_TIFFfree(tilebuf);\n\treturn 1;\n }\n if (TIFFWriteTile(out, tilebuf, col, row, 0, 0) < 0)\n {\n\tTIFFError("writeBufferToContigTiles",\n\t "Cannot write tile at %lu %lu",\n\t (unsigned long) col, (unsigned long) row);\n\t _TIFFfree(tilebuf);\n\treturn 1;\n\t}\n }\n }\n _TIFFfree(tilebuf);\n return 0;\n }', 'tmsize_t\nTIFFWriteTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFWriteEncodedTile(tif,\n\t TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'int\nTIFFCheckTile(TIFF* tif, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif (x >= td->td_imagewidth) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Col out of range, max %lu",\n\t\t\t (unsigned long) x,\n\t\t\t (unsigned long) (td->td_imagewidth - 1));\n\t\treturn (0);\n\t}\n\tif (y >= td->td_imagelength) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Row out of range, max %lu",\n\t\t\t (unsigned long) y,\n\t\t\t (unsigned long) (td->td_imagelength - 1));\n\t\treturn (0);\n\t}\n\tif (z >= td->td_imagedepth) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Depth out of range, max %lu",\n\t\t\t (unsigned long) z,\n\t\t\t (unsigned long) (td->td_imagedepth - 1));\n\t\treturn (0);\n\t}\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE &&\n\t s >= td->td_samplesperpixel) {\n\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t "%lu: Sample out of range, max %lu",\n\t\t\t (unsigned long) s,\n\t\t\t (unsigned long) (td->td_samplesperpixel - 1));\n\t\treturn (0);\n\t}\n\treturn (1);\n}']
|
1,605
| 0
|
https://github.com/libav/libav/blob/b12b16c5d35adaba0979a7c2fa76b88e48f5f839/libavcodec/sonic.c/#L809
|
static av_cold int sonic_decode_init(AVCodecContext *avctx)
{
SonicContext *s = avctx->priv_data;
GetBitContext gb;
int i, version;
s->channels = avctx->channels;
s->samplerate = avctx->sample_rate;
if (!avctx->extradata)
{
av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n");
return -1;
}
init_get_bits(&gb, avctx->extradata, avctx->extradata_size);
version = get_bits(&gb, 2);
if (version > 1)
{
av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n");
return -1;
}
if (version == 1)
{
s->channels = get_bits(&gb, 2);
s->samplerate = samplerate_table[get_bits(&gb, 4)];
av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n",
s->channels, s->samplerate);
}
if (s->channels > MAX_CHANNELS)
{
av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n");
return -1;
}
s->lossless = get_bits1(&gb);
if (!s->lossless)
skip_bits(&gb, 3);
s->decorrelation = get_bits(&gb, 2);
s->downsampling = get_bits(&gb, 2);
s->num_taps = (get_bits(&gb, 5)+1)<<5;
if (get_bits1(&gb))
av_log(avctx, AV_LOG_INFO, "Custom quant table\n");
s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling;
s->frame_size = s->channels*s->block_align*s->downsampling;
av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n",
version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);
s->tap_quant = av_mallocz(4* s->num_taps);
for (i = 0; i < s->num_taps; i++)
s->tap_quant[i] = (int)(sqrt(i+1));
s->predictor_k = av_mallocz(4* s->num_taps);
for (i = 0; i < s->channels; i++)
{
s->predictor_state[i] = av_mallocz(4* s->num_taps);
if (!s->predictor_state[i])
return -1;
}
for (i = 0; i < s->channels; i++)
{
s->coded_samples[i] = av_mallocz(4* s->block_align);
if (!s->coded_samples[i])
return -1;
}
s->int_samples = av_mallocz(4* s->frame_size);
avctx->sample_fmt = SAMPLE_FMT_S16;
return 0;
}
|
['static av_cold int sonic_decode_init(AVCodecContext *avctx)\n{\n SonicContext *s = avctx->priv_data;\n GetBitContext gb;\n int i, version;\n s->channels = avctx->channels;\n s->samplerate = avctx->sample_rate;\n if (!avctx->extradata)\n {\n av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\\n");\n return -1;\n }\n init_get_bits(&gb, avctx->extradata, avctx->extradata_size);\n version = get_bits(&gb, 2);\n if (version > 1)\n {\n av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\\n");\n return -1;\n }\n if (version == 1)\n {\n s->channels = get_bits(&gb, 2);\n s->samplerate = samplerate_table[get_bits(&gb, 4)];\n av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\\n",\n s->channels, s->samplerate);\n }\n if (s->channels > MAX_CHANNELS)\n {\n av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\\n");\n return -1;\n }\n s->lossless = get_bits1(&gb);\n if (!s->lossless)\n skip_bits(&gb, 3);\n s->decorrelation = get_bits(&gb, 2);\n s->downsampling = get_bits(&gb, 2);\n s->num_taps = (get_bits(&gb, 5)+1)<<5;\n if (get_bits1(&gb))\n av_log(avctx, AV_LOG_INFO, "Custom quant table\\n");\n s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling;\n s->frame_size = s->channels*s->block_align*s->downsampling;\n av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\\n",\n version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling);\n s->tap_quant = av_mallocz(4* s->num_taps);\n for (i = 0; i < s->num_taps; i++)\n s->tap_quant[i] = (int)(sqrt(i+1));\n s->predictor_k = av_mallocz(4* s->num_taps);\n for (i = 0; i < s->channels; i++)\n {\n s->predictor_state[i] = av_mallocz(4* s->num_taps);\n if (!s->predictor_state[i])\n return -1;\n }\n for (i = 0; i < s->channels; i++)\n {\n s->coded_samples[i] = av_mallocz(4* s->block_align);\n if (!s->coded_samples[i])\n return -1;\n }\n s->int_samples = av_mallocz(4* s->frame_size);\n avctx->sample_fmt = SAMPLE_FMT_S16;\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size= (bit_size+7)>>3;\n if(buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer= buffer;\n s->size_in_bits= bit_size;\n s->buffer_end= buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index=0;\n#elif defined LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits(GetBitContext *s, int n){\n register int tmp;\n OPEN_READER(re, s)\n UPDATE_CACHE(re, s)\n tmp= SHOW_UBITS(re, s, n);\n LAST_SKIP_BITS(re, s, n)\n CLOSE_READER(re, s)\n return tmp;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);\n x= (x>>16) | (x<<16);\n return x;\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,606
| 0
|
https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_lib.c/#L342
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = A = OPENSSL_zalloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
}
|
['int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *xx, const int p[],\n BN_CTX *ctx)\n{\n BIGNUM *field;\n int ret = 0;\n bn_check_top(xx);\n BN_CTX_start(ctx);\n if ((field = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_GF2m_arr2poly(p, field))\n goto err;\n ret = BN_GF2m_mod_inv(r, xx, field, ctx);\n bn_check_top(r);\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_GF2m_arr2poly(const int p[], BIGNUM *a)\n{\n int i;\n bn_check_top(a);\n BN_zero(a);\n for (i = 0; p[i] != -1; i++) {\n if (BN_set_bit(a, p[i]) == 0)\n return 0;\n }\n bn_check_top(a);\n return 1;\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = A = OPENSSL_zalloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
|
1,607
| 1
|
https://github.com/openssl/openssl/blob/96826bfc84c63207b720543443626029946a0fc7/crypto/pem/pem_all.c/#L223
|
DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
void *u)
{
EVP_PKEY *pktmp;
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
return pkey_get_dsa(pktmp, dsa);
}
|
['DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,\n\t\t\t\t\t\t\t\tvoid *u)\n{\n\tEVP_PKEY *pktmp;\n\tpktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);\n\treturn pkey_get_dsa(pktmp, dsa);\n}', 'EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)\n\t{\n\tchar *nm=NULL;\n\tconst unsigned char *p=NULL;\n\tunsigned char *data=NULL;\n\tlong len;\n\tint slen;\n\tEVP_PKEY *ret=NULL;\n\tif (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))\n\t\treturn NULL;\n\tp = data;\n\tif (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {\n\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\tp8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);\n\t\tif(!p8inf) goto p8err;\n\t\tret = EVP_PKCS82PKEY(p8inf);\n\t\tif(x) {\n\t\t\tif(*x) EVP_PKEY_free((EVP_PKEY *)*x);\n\t\t\t*x = ret;\n\t\t}\n\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t} else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {\n\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\tX509_SIG *p8;\n\t\tint klen;\n\t\tchar psbuf[PEM_BUFSIZE];\n\t\tp8 = d2i_X509_SIG(NULL, &p, len);\n\t\tif(!p8) goto p8err;\n\t\tif (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);\n\t\telse klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);\n\t\tif (klen <= 0) {\n\t\t\tPEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,\n\t\t\t\t\tPEM_R_BAD_PASSWORD_READ);\n\t\t\tX509_SIG_free(p8);\n\t\t\tgoto err;\n\t\t}\n\t\tp8inf = PKCS8_decrypt(p8, psbuf, klen);\n\t\tX509_SIG_free(p8);\n\t\tif(!p8inf) goto p8err;\n\t\tret = EVP_PKCS82PKEY(p8inf);\n\t\tif(x) {\n\t\t\tif(*x) EVP_PKEY_free((EVP_PKEY *)*x);\n\t\t\t*x = ret;\n\t\t}\n\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t} else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0)\n\t\t{\n\t\tconst EVP_PKEY_ASN1_METHOD *ameth;\n\t\tameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);\n\t\tif (!ameth || !ameth->old_priv_decode)\n\t\t\tgoto p8err;\n\t\tret=d2i_PrivateKey(ameth->pkey_id,x,&p,len);\n\t\t}\np8err:\n\tif (ret == NULL)\n\t\tPEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB);\nerr:\n\tOPENSSL_free(nm);\n\tOPENSSL_cleanse(data, len);\n\tOPENSSL_free(data);\n\treturn(ret);\n\t}', 'int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,\n\t pem_password_cb *cb, void *u)\n\t{\n\tEVP_CIPHER_INFO cipher;\n\tchar *nm=NULL,*header=NULL;\n\tunsigned char *data=NULL;\n\tlong len;\n\tint ret = 0;\n\tfor (;;)\n\t\t{\n\t\tif (!PEM_read_bio(bp,&nm,&header,&data,&len)) {\n\t\t\tif(ERR_GET_REASON(ERR_peek_error()) ==\n\t\t\t\tPEM_R_NO_START_LINE)\n\t\t\t\tERR_add_error_data(2, "Expecting: ", name);\n\t\t\treturn 0;\n\t\t}\n\t\tif(check_pem(nm, name)) break;\n\t\tOPENSSL_free(nm);\n\t\tOPENSSL_free(header);\n\t\tOPENSSL_free(data);\n\t\t}\n\tif (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;\n\tif (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;\n\t*pdata = data;\n\t*plen = len;\n\tif (pnm)\n\t\t*pnm = nm;\n\tret = 1;\nerr:\n\tif (!ret || !pnm) OPENSSL_free(nm);\n\tOPENSSL_free(header);\n\tif (!ret) OPENSSL_free(data);\n\treturn ret;\n\t}', 'int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,\n\t long *len)\n\t{\n\tEVP_ENCODE_CTX ctx;\n\tint end=0,i,k,bl=0,hl=0,nohead=0;\n\tchar buf[256];\n\tBUF_MEM *nameB;\n\tBUF_MEM *headerB;\n\tBUF_MEM *dataB,*tmpB;\n\tnameB=BUF_MEM_new();\n\theaderB=BUF_MEM_new();\n\tdataB=BUF_MEM_new();\n\tif ((nameB == NULL) || (headerB == NULL) || (dataB == NULL))\n\t\t{\n\t\tBUF_MEM_free(nameB);\n\t\tBUF_MEM_free(headerB);\n\t\tBUF_MEM_free(dataB);\n\t\tPEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tbuf[254]=\'\\0\';\n\tfor (;;)\n\t\t{\n\t\ti=BIO_gets(bp,buf,254);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_NO_START_LINE);\n\t\t\tgoto err;\n\t\t\t}\n\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\tif (strncmp(buf,"-----BEGIN ",11) == 0)\n\t\t\t{\n\t\t\ti=strlen(&(buf[11]));\n\t\t\tif (strncmp(&(buf[11+i-6]),"-----\\n",6) != 0)\n\t\t\t\tcontinue;\n\t\t\tif (!BUF_MEM_grow(nameB,i+9))\n\t\t\t\t{\n\t\t\t\tPEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tmemcpy(nameB->data,&(buf[11]),i-6);\n\t\t\tnameB->data[i-6]=\'\\0\';\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\thl=0;\n\tif (!BUF_MEM_grow(headerB,256))\n\t\t{ PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }\n\theaderB->data[0]=\'\\0\';\n\tfor (;;)\n\t\t{\n\t\ti=BIO_gets(bp,buf,254);\n\t\tif (i <= 0) break;\n\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\tif (buf[0] == \'\\n\') break;\n\t\tif (!BUF_MEM_grow(headerB,hl+i+9))\n\t\t\t{ PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }\n\t\tif (strncmp(buf,"-----END ",9) == 0)\n\t\t\t{\n\t\t\tnohead=1;\n\t\t\tbreak;\n\t\t\t}\n\t\tmemcpy(&(headerB->data[hl]),buf,i);\n\t\theaderB->data[hl+i]=\'\\0\';\n\t\thl+=i;\n\t\t}\n\tbl=0;\n\tif (!BUF_MEM_grow(dataB,1024))\n\t\t{ PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); goto err; }\n\tdataB->data[0]=\'\\0\';\n\tif (!nohead)\n\t\t{\n\t\tfor (;;)\n\t\t\t{\n\t\t\ti=BIO_gets(bp,buf,254);\n\t\t\tif (i <= 0) break;\n\t\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\t\tif (i != 65) end=1;\n\t\t\tif (strncmp(buf,"-----END ",9) == 0)\n\t\t\t\tbreak;\n\t\t\tif (i > 65) break;\n\t\t\tif (!BUF_MEM_grow_clean(dataB,i+bl+9))\n\t\t\t\t{\n\t\t\t\tPEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tmemcpy(&(dataB->data[bl]),buf,i);\n\t\t\tdataB->data[bl+i]=\'\\0\';\n\t\t\tbl+=i;\n\t\t\tif (end)\n\t\t\t\t{\n\t\t\t\tbuf[0]=\'\\0\';\n\t\t\t\ti=BIO_gets(bp,buf,254);\n\t\t\t\tif (i <= 0) break;\n\t\t\t\twhile ((i >= 0) && (buf[i] <= \' \')) i--;\n\t\t\t\tbuf[++i]=\'\\n\'; buf[++i]=\'\\0\';\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\ttmpB=headerB;\n\t\theaderB=dataB;\n\t\tdataB=tmpB;\n\t\tbl=hl;\n\t\t}\n\ti=strlen(nameB->data);\n\tif (\t(strncmp(buf,"-----END ",9) != 0) ||\n\t\t(strncmp(nameB->data,&(buf[9]),i) != 0) ||\n\t\t(strncmp(&(buf[9+i]),"-----\\n",6) != 0))\n\t\t{\n\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_END_LINE);\n\t\tgoto err;\n\t\t}\n\tEVP_DecodeInit(&ctx);\n\ti=EVP_DecodeUpdate(&ctx,\n\t\t(unsigned char *)dataB->data,&bl,\n\t\t(unsigned char *)dataB->data,bl);\n\tif (i < 0)\n\t\t{\n\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);\n\t\tgoto err;\n\t\t}\n\ti=EVP_DecodeFinal(&ctx,(unsigned char *)&(dataB->data[bl]),&k);\n\tif (i < 0)\n\t\t{\n\t\tPEMerr(PEM_F_PEM_READ_BIO,PEM_R_BAD_BASE64_DECODE);\n\t\tgoto err;\n\t\t}\n\tbl+=k;\n\tif (bl == 0) goto err;\n\t*name=nameB->data;\n\t*header=headerB->data;\n\t*data=(unsigned char *)dataB->data;\n\t*len=bl;\n\tOPENSSL_free(nameB);\n\tOPENSSL_free(headerB);\n\tOPENSSL_free(dataB);\n\treturn(1);\nerr:\n\tBUF_MEM_free(nameB);\n\tBUF_MEM_free(headerB);\n\tBUF_MEM_free(dataB);\n\treturn(0);\n\t}', 'BUF_MEM *BUF_MEM_new(void)\n\t{\n\tBUF_MEM *ret;\n\tret=OPENSSL_malloc(sizeof(BUF_MEM));\n\tif (ret == NULL)\n\t\t{\n\t\tBUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->max=0;\n\tret->data=NULL;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void BUF_MEM_free(BUF_MEM *a)\n\t{\n\tif(a == NULL)\n\t return;\n\tif (a->data != NULL)\n\t\t{\n\t\tmemset(a->data,0,(unsigned int)a->max);\n\t\tOPENSSL_free(a->data);\n\t\t}\n\tOPENSSL_free(a);\n\t}', 'unsigned long ERR_peek_error(void)\n\t{ return(get_error_values(0,0,NULL,NULL,NULL,NULL)); }']
|
1,608
| 0
|
https://github.com/openssl/openssl/blob/3a66e306e45215b2dac68f66eb6b1012a94f17e5/crypto/asn1/asn1_lib.c/#L101
|
int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
long omax)
{
int i,ret;
long l;
unsigned char *p= *pp;
int tag,xclass,inf;
long max=omax;
if (!max) goto err;
ret=(*p&V_ASN1_CONSTRUCTED);
xclass=(*p&V_ASN1_PRIVATE);
i= *p&V_ASN1_PRIMITIVE_TAG;
if (i == V_ASN1_PRIMITIVE_TAG)
{
p++;
if (--max == 0) goto err;
l=0;
while (*p&0x80)
{
l<<=7L;
l|= *(p++)&0x7f;
if (--max == 0) goto err;
}
l<<=7L;
l|= *(p++)&0x7f;
tag=(int)l;
}
else
{
tag=i;
p++;
if (--max == 0) goto err;
}
*ptag=tag;
*pclass=xclass;
if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
#if 0
fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n",
(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
(int)(omax+ *pp));
#endif
#if 0
if ((p+ *plength) > (omax+ *pp))
{
ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
ret|=0x80;
}
#endif
*pp=p;
return(ret|inf);
err:
ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
return(0x80);
}
|
['int MAIN(int argc, char **argv)\n{\n\tchar **args, *infile = NULL, *outfile = NULL;\n\tBIO *in = NULL, *out = NULL;\n\tint topk8 = 0;\n\tint pbe_nid = -1;\n\tint iter = PKCS12_DEFAULT_ITER;\n\tint informat, outformat;\n\tint p8_broken = PKCS8_OK;\n\tint nocrypt = 0;\n\tX509_SIG *p8;\n\tPKCS8_PRIV_KEY_INFO *p8inf;\n\tEVP_PKEY *pkey;\n\tchar pass[50];\n\tint badarg = 0;\n\tif (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tERR_load_crypto_strings();\n\tSSLeay_add_all_algorithms();\n\targs = argv + 1;\n\twhile (!badarg && *args && *args[0] == \'-\') {\n\t\tif (!strcmp(*args,"-inform")) {\n\t\t\tif (args[1]) {\n\t\t\t\targs++;\n\t\t\t\tinformat=str2fmt(*args);\n\t\t\t} else badarg = 1;\n\t\t} else if (!strcmp(*args,"-outform")) {\n\t\t\tif (args[1]) {\n\t\t\t\targs++;\n\t\t\t\toutformat=str2fmt(*args);\n\t\t\t} else badarg = 1;\n\t\t} else if (!strcmp (*args, "-topk8")) topk8 = 1;\n\t\telse if (!strcmp (*args, "-noiter")) iter = 1;\n\t\telse if (!strcmp (*args, "-nocrypt")) nocrypt = 1;\n\t\telse if (!strcmp (*args, "-nooct")) p8_broken = PKCS8_NO_OCTET;\n\t\telse if (!strcmp (*args, "-in")) {\n\t\t\tif (args[1]) {\n\t\t\t\targs++;\n\t\t\t\tinfile = *args;\n\t\t\t} else badarg = 1;\n\t\t} else if (!strcmp (*args, "-out")) {\n\t\t\tif (args[1]) {\n\t\t\t\targs++;\n\t\t\t\toutfile = *args;\n\t\t\t} else badarg = 1;\n\t\t} else badarg = 1;\n\t\targs++;\n\t}\n\tif (badarg) {\n\t\tBIO_printf (bio_err, "Usage pkcs8 [options]\\n");\n\t\tBIO_printf (bio_err, "where options are\\n");\n\t\tBIO_printf (bio_err, "-in file input file\\n");\n\t\tBIO_printf (bio_err, "-inform X input format (DER or PEM)\\n");\n\t\tBIO_printf (bio_err, "-outform X output format (DER or PEM)\\n");\n\t\tBIO_printf (bio_err, "-out file output file\\n");\n\t\tBIO_printf (bio_err, "-topk8 output PKCS8 file\\n");\n\t\tBIO_printf (bio_err, "-nooct use (broken) no octet form\\n");\n\t\tBIO_printf (bio_err, "-noiter use 1 as iteration count\\n");\n\t\tBIO_printf (bio_err, "-nocrypt use or expect unencrypted private key\\n");\n\t\treturn (1);\n\t}\n\tif (pbe_nid == -1) pbe_nid = NID_pbeWithMD5AndDES_CBC;\n\tif (infile) {\n\t\tif (!(in = BIO_new_file (infile, "rb"))) {\n\t\t\tBIO_printf (bio_err,\n\t\t\t\t "Can\'t open input file %s\\n", infile);\n\t\t\treturn (1);\n\t\t}\n\t} else in = BIO_new_fp (stdin, BIO_NOCLOSE);\n\tif (outfile) {\n\t\tif (!(out = BIO_new_file (outfile, "wb"))) {\n\t\t\tBIO_printf (bio_err,\n\t\t\t\t "Can\'t open output file %s\\n", outfile);\n\t\t\treturn (1);\n\t\t}\n\t} else out = BIO_new_fp (stdout, BIO_NOCLOSE);\n\tif (topk8) {\n\t\tif (!(pkey = PEM_read_bio_PrivateKey(in, NULL, NULL))) {\n\t\t\tBIO_printf (bio_err, "Error reading key\\n", outfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\treturn (1);\n\t\t}\n\t\tif (!(p8inf = EVP_PKEY2PKCS8(pkey))) {\n\t\t\tBIO_printf (bio_err, "Error converting key\\n", outfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\treturn (1);\n\t\t}\n\t\tPKCS8_set_broken(p8inf, p8_broken);\n\t\tif(nocrypt) {\n\t\t\tif(outformat == FORMAT_PEM)\n\t\t\t\tPEM_write_bio_PKCS8_PRIV_KEY_INFO(out, p8inf);\n\t\t\telse if(outformat == FORMAT_ASN1)\n\t\t\t\ti2d_PKCS8_PRIV_KEY_INFO_bio(out, p8inf);\n\t\t\telse {\n\t\t\t\tBIO_printf(bio_err, "Bad format specified for key\\n");\n\t\t\t\treturn (1);\n\t\t\t}\n\t\t} else {\n\t\t\tEVP_read_pw_string(pass, 50, "Enter Encryption Password:", 1);\n\t\t\tif (!(p8 = PKCS8_encrypt(pbe_nid, pass, strlen(pass),\n\t\t\t\t\t NULL, 0, iter, p8inf))) {\n\t\t\t\tBIO_printf (bio_err, "Error encrypting key\\n",\n\t\t\t\t\t\t\t\t outfile);\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\treturn (1);\n\t\t\t}\n\t\t\tif(outformat == FORMAT_PEM)\n\t\t\t\tPEM_write_bio_PKCS8 (out, p8);\n\t\t\telse if(outformat == FORMAT_ASN1)\n\t\t\t\ti2d_PKCS8_bio(out, p8);\n\t\t\telse {\n\t\t\t\tBIO_printf(bio_err, "Bad format specified for key\\n");\n\t\t\t\treturn (1);\n\t\t\t}\n\t\t\tX509_SIG_free(p8);\n\t\t}\n\t\tPKCS8_PRIV_KEY_INFO_free (p8inf);\n\t\treturn (0);\n\t}\n\tif(nocrypt) {\n\t\tif(informat == FORMAT_PEM)\n\t\t\tp8inf = PEM_read_bio_PKCS8_PRIV_KEY_INFO(in,NULL,NULL);\n\t\telse if(informat == FORMAT_ASN1)\n\t\t\tp8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(in, NULL);\n\t\telse {\n\t\t\tBIO_printf(bio_err, "Bad format specified for key\\n");\n\t\t\treturn (1);\n\t\t}\n\t} else {\n\t\tif(informat == FORMAT_PEM)\n\t\t\tp8 = PEM_read_bio_PKCS8(in, NULL, NULL);\n\t\telse if(informat == FORMAT_ASN1)\n\t\t\tp8 = d2i_PKCS8_bio(in, NULL);\n\t\telse {\n\t\t\tBIO_printf(bio_err, "Bad format specified for key\\n");\n\t\t\treturn (1);\n\t\t}\n\t\tif (!p8) {\n\t\t\tBIO_printf (bio_err, "Error reading key\\n", outfile);\n\t\t\tERR_print_errors(bio_err);\n\t\t\treturn (1);\n\t\t}\n\t\tEVP_read_pw_string(pass, 50, "Enter Password:", 0);\n\t\tp8inf = M_PKCS8_decrypt(p8, pass, strlen(pass));\n\t}\n\tif (!p8inf) {\n\t\tBIO_printf(bio_err, "Error decrypting key\\n", outfile);\n\t\tERR_print_errors(bio_err);\n\t\treturn (1);\n\t}\n\tif (!(pkey = EVP_PKCS82PKEY(p8inf))) {\n\t\tBIO_printf(bio_err, "Error converting key\\n", outfile);\n\t\tERR_print_errors(bio_err);\n\t\treturn (1);\n\t}\n\tif (p8inf->broken) {\n\t\tBIO_printf(bio_err, "Warning: broken key encoding: ");\n\t\tswitch (p8inf->broken) {\n\t\t\tcase PKCS8_NO_OCTET:\n\t\t\tBIO_printf(bio_err, "No Octet String\\n");\n\t\t\tbreak;\n\t\t\tdefault:\n\t\t\tBIO_printf(bio_err, "Unknown broken type\\n");\n\t\t\tbreak;\n\t\t}\n\t}\n\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\tPEM_write_bio_PrivateKey(out, pkey, NULL, NULL, 0, NULL);\n\treturn (0);\n}', 'X509_SIG *PEM_read_bio_PKCS8(BIO *bp,\n\t X509_SIG **x, pem_password_cb *cb)\n\t{\n\treturn((X509_SIG *)\n\t\tPEM_ASN1_read_bio((char *(*)())d2i_X509_SIG,\n\t\tPEM_STRING_PKCS8,bp,(char **)x,cb));\n\t}', 'char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,\n\t pem_password_cb *cb)\n\t{\n\tEVP_CIPHER_INFO cipher;\n\tchar *nm=NULL,*header=NULL;\n\tunsigned char *p=NULL,*data=NULL;\n\tlong len;\n\tchar *ret=NULL;\n\tfor (;;)\n\t\t{\n\t\tif (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL);\n\t\tif (\t(strcmp(nm,name) == 0) ||\n\t\t\t((strcmp(nm,PEM_STRING_RSA) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_DSA) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_PKCS8) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_PKCS8INF) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_X509) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_X509_REQ) == 0))\n\t\t\t)\n\t\t\tbreak;\n\t\tFree(nm);\n\t\tFree(header);\n\t\tFree(data);\n\t\t}\n\tif (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;\n\tif (!PEM_do_header(&cipher,data,&len,cb)) goto err;\n\tp=data;\n\tif (strcmp(name,PEM_STRING_EVP_PKEY) == 0) {\n\t\tif (strcmp(nm,PEM_STRING_RSA) == 0)\n\t\t\tret=d2i(EVP_PKEY_RSA,x,&p,len);\n\t\telse if (strcmp(nm,PEM_STRING_DSA) == 0)\n\t\t\tret=d2i(EVP_PKEY_DSA,x,&p,len);\n\t\telse if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {\n\t\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\t\tp8inf=d2i_PKCS8_PRIV_KEY_INFO(\n\t\t\t\t\t(PKCS8_PRIV_KEY_INFO **) x, &p, len);\n\t\t\tret = (char *)EVP_PKCS82PKEY(p8inf);\n\t\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t\t} else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {\n\t\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\t\tX509_SIG *p8;\n\t\t\tint klen;\n\t\t\tchar psbuf[PEM_BUFSIZE];\n\t\t\tp8 = d2i_X509_SIG((X509_SIG **)x, &p, len);\n\t\t\tif(!p8) goto p8err;\n\t\t\tif (cb) klen=cb(psbuf,PEM_BUFSIZE,0);\n\t\t\telse klen=def_callback(psbuf,PEM_BUFSIZE,0);\n\t\t\tif (klen <= 0) {\n\t\t\t\tPEMerr(PEM_F_PEM_ASN1_READ_BIO,\n\t\t\t\t\t\tPEM_R_BAD_PASSWORD_READ);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tp8inf = M_PKCS8_decrypt(p8, psbuf, klen);\n\t\t\tX509_SIG_free(p8);\n\t\t\tif(!p8inf) goto p8err;\n\t\t\tret = (char *)EVP_PKCS82PKEY(p8inf);\n\t\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t\t}\n\t} else\tret=d2i(x,&p,len);\np8err:\n\tif (ret == NULL)\n\t\tPEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);\nerr:\n\tFree(nm);\n\tFree(header);\n\tFree(data);\n\treturn(ret);\n\t}', 'PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO(PKCS8_PRIV_KEY_INFO **a,\n\t unsigned char **pp, long length)\n{\n\tM_ASN1_D2I_vars(a,PKCS8_PRIV_KEY_INFO *,PKCS8_PRIV_KEY_INFO_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get (ret->version, d2i_ASN1_INTEGER);\n\tM_ASN1_D2I_get (ret->pkeyalg, d2i_X509_ALGOR);\n\tM_ASN1_D2I_get (ret->pkey, d2i_ASN1_TYPE);\n\tM_ASN1_D2I_get_IMP_set_opt_type(X509_ATTRIBUTE, ret->attributes,\n\t\t\t\t\td2i_X509_ATTRIBUTE,\n\t\t\t\t\tX509_ATTRIBUTE_free, 0);\n\tif (ASN1_TYPE_get(ret->pkey) == V_ASN1_SEQUENCE)\n\t\t\t\t\t\tret->broken = PKCS8_NO_OCTET;\n\tM_ASN1_D2I_Finish(a, PKCS8_PRIV_KEY_INFO_free, ASN1_F_D2I_PKCS8_PRIV_KEY_INFO);\n}', 'char * PKCS12_decrypt_d2i (X509_ALGOR *algor, char * (*d2i)(),\n\t void (*free_func)(), const char *pass, int passlen,\n\t ASN1_OCTET_STRING *oct, int seq)\n{\n\tunsigned char *out, *p;\n\tchar *ret;\n\tint outlen;\n\tif (!PKCS12_pbe_crypt (algor, pass, passlen, oct->data, oct->length,\n\t\t\t &out, &outlen, 0)) {\n\t\tPKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);\n\t\treturn NULL;\n\t}\n\tp = out;\n#ifdef DEBUG_DECRYPT\n\t{\n\t\tFILE *op;\n\t\tchar fname[30];\n\t\tstatic int fnm = 1;\n\t\tsprintf(fname, "DER%d", fnm++);\n\t\top = fopen(fname, "wb");\n\t\tfwrite (p, 1, outlen, op);\n\t\tfclose(op);\n\t}\n#endif\n\tif (seq & 1) ret = (char *) d2i_ASN1_SET(NULL, &p, outlen, d2i,\n\t\t\t\tfree_func, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);\n\telse ret = d2i(NULL, &p, outlen);\n\tif (seq & 2) memset(out, 0, outlen);\n\tif(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);\n\tFree (out);\n\treturn ret;\n}', 'unsigned char * PKCS12_pbe_crypt (X509_ALGOR *algor, const char *pass,\n\t int passlen, unsigned char *in, int inlen, unsigned char **data,\n\t int *datalen, int en_de)\n{\n\tunsigned char *out;\n\tint outlen, i;\n\tEVP_CIPHER_CTX ctx;\n\tif(!(out = Malloc (inlen + 8))) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n if (!EVP_PBE_CipherInit (algor->algorithm, pass, passlen,\n\t\t\t\t\t algor->parameter, &ctx, en_de)) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);\n\t\treturn NULL;\n\t}\n\tEVP_CipherUpdate (&ctx, out, &i, in, inlen);\n\toutlen = i;\n\tif(!EVP_CipherFinal (&ctx, out + i, &i)) {\n\t\tFree (out);\n\t\tPKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);\n\t\treturn NULL;\n\t}\n\toutlen += i;\n\tif (datalen) *datalen = outlen;\n\tif (data) *data = out;\n\treturn out;\n}', 'STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,\n\t char *(*func)(), void (*free_func)(), int ex_tag, int ex_class)\n\t{\n\tASN1_CTX c;\n\tSTACK *ret=NULL;\n\tif ((a == NULL) || ((*a) == NULL))\n\t\t{ if ((ret=sk_new(NULL)) == NULL) goto err; }\n\telse\n\t\tret=(*a);\n\tc.p= *pp;\n\tc.max=(length == 0)?0:(c.p+length);\n\tc.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p);\n\tif (c.inf & 0x80) goto err;\n\tif (ex_class != c.xclass)\n\t\t{\n\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS);\n\t\tgoto err;\n\t\t}\n\tif (ex_tag != c.tag)\n\t\t{\n\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG);\n\t\tgoto err;\n\t\t}\n\tif ((c.slen+c.p) > c.max)\n\t\t{\n\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (c.inf == (V_ASN1_CONSTRUCTED+1))\n\t\tc.slen=length+ *pp-c.p;\n\tc.max=c.p+c.slen;\n\twhile (c.p < c.max)\n\t\t{\n\t\tchar *s;\n\t\tif (M_ASN1_D2I_end_sequence()) break;\n\t\tif ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);\n\t\t\tasn1_add_error(*pp,(int)(c.q- *pp));\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!sk_push(ret,s)) goto err;\n\t\t}\n\tif (a != NULL) (*a)=ret;\n\t*pp=c.p;\n\treturn(ret);\nerr:\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret)))\n\t\t{\n\t\tif (free_func != NULL)\n\t\t\tsk_pop_free(ret,free_func);\n\t\telse\n\t\t\tsk_free(ret);\n\t\t}\n\treturn(NULL);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']
|
1,609
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_sqr.c/#L162
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (!d || !r || !val1[0] || !val2[0])\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return (1);\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,610
| 0
|
https://github.com/openssl/openssl/blob/7ef8206859f9a52f48e817c023c744fe00e82c5d/ssl/ssl_cert.c/#L741
|
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
const char *dir)
{
DIR *d;
struct dirent *dstruct;
int ret = 0;
CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
d = opendir(dir);
if(!d)
{
SYSerr(SYS_F_OPENDIR, get_last_sys_error());
ERR_add_error_data(3, "opendir('", dir, "')");
SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
goto err;
}
while((dstruct=readdir(d)))
{
char buf[1024];
int r;
if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
{
SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
goto err;
}
r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);
if (r <= 0 || r >= sizeof buf)
goto err;
if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
goto err;
}
ret = 1;
err:
CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
return ret;
}
|
['int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,\n\t\t\t\t const char *dir)\n\t{\n\tDIR *d;\n\tstruct dirent *dstruct;\n\tint ret = 0;\n\tCRYPTO_w_lock(CRYPTO_LOCK_READDIR);\n\td = opendir(dir);\n\tif(!d)\n\t\t{\n\t\tSYSerr(SYS_F_OPENDIR, get_last_sys_error());\n\t\tERR_add_error_data(3, "opendir(\'", dir, "\')");\n\t\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);\n\t\tgoto err;\n\t\t}\n\twhile((dstruct=readdir(d)))\n\t\t{\n\t\tchar buf[1024];\n\t\tint r;\n\t\tif(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tr = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);\n\t\tif (r <= 0 || r >= sizeof buf)\n\t\t\tgoto err;\n\t\tif(!SSL_add_file_cert_subjects_to_stack(stack,buf))\n\t\t\tgoto err;\n\t\t}\n\tret = 1;\nerr:\n\tCRYPTO_w_unlock(CRYPTO_LOCK_READDIR);\n\treturn ret;\n\t}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tint i = -type - 1;\n\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t= CRYPTO_get_dynlock_value(i);\n\t\tif (pointer)\n\t\t\t{\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\t}\n\t\tCRYPTO_destroy_dynlockid(i);\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n\t{\n\tva_list args;\n\tsize_t retlen;\n\tint truncated;\n\tva_start(args, format);\n\t_dopr(dopr_outch, dopr_isbig, dopr_copy,\n\t\t&buf, &n, &retlen, &truncated, format, args);\n\tif (truncated)\n\t\treturn -1;\n\telse\n\t\treturn (retlen <= INT_MAX) ? retlen : -1;\n\t}']
|
1,611
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/apps/speed.c/#L1984
|
int MAIN(int argc, char **argv)
{
unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
unsigned char *buf = NULL, *buf2 = NULL;
int mret = 1;
long count = 0, save_count = 0;
int i, j, k;
# if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
long rsa_count;
# endif
# ifndef OPENSSL_NO_RSA
unsigned rsa_num;
# endif
unsigned char md[EVP_MAX_MD_SIZE];
# ifndef OPENSSL_NO_MD2
unsigned char md2[MD2_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_MDC2
unsigned char mdc2[MDC2_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_MD4
unsigned char md4[MD4_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_MD5
unsigned char md5[MD5_DIGEST_LENGTH];
unsigned char hmac[MD5_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_SHA
unsigned char sha[SHA_DIGEST_LENGTH];
# ifndef OPENSSL_NO_SHA256
unsigned char sha256[SHA256_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_SHA512
unsigned char sha512[SHA512_DIGEST_LENGTH];
# endif
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_RMD160
unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_RC4
RC4_KEY rc4_ks;
# endif
# ifndef OPENSSL_NO_RC5
RC5_32_KEY rc5_ks;
# endif
# ifndef OPENSSL_NO_RC2
RC2_KEY rc2_ks;
# endif
# ifndef OPENSSL_NO_IDEA
IDEA_KEY_SCHEDULE idea_ks;
# endif
# ifndef OPENSSL_NO_SEED
SEED_KEY_SCHEDULE seed_ks;
# endif
# ifndef OPENSSL_NO_BF
BF_KEY bf_ks;
# endif
# ifndef OPENSSL_NO_CAST
CAST_KEY cast_ks;
# endif
static const unsigned char key16[16] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
};
# ifndef OPENSSL_NO_AES
static const unsigned char key24[24] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
};
static const unsigned char key32[32] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
};
# endif
# ifndef OPENSSL_NO_CAMELLIA
static const unsigned char ckey24[24] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
};
static const unsigned char ckey32[32] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
};
# endif
# ifndef OPENSSL_NO_AES
# define MAX_BLOCK_SIZE 128
# else
# define MAX_BLOCK_SIZE 64
# endif
unsigned char DES_iv[8];
unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
# ifndef OPENSSL_NO_DES
static DES_cblock key =
{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
static DES_cblock key2 =
{ 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
static DES_cblock key3 =
{ 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
DES_key_schedule sch;
DES_key_schedule sch2;
DES_key_schedule sch3;
# endif
# ifndef OPENSSL_NO_AES
AES_KEY aes_ks1, aes_ks2, aes_ks3;
# endif
# ifndef OPENSSL_NO_CAMELLIA
CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
# endif
# define D_MD2 0
# define D_MDC2 1
# define D_MD4 2
# define D_MD5 3
# define D_HMAC 4
# define D_SHA1 5
# define D_RMD160 6
# define D_RC4 7
# define D_CBC_DES 8
# define D_EDE3_DES 9
# define D_CBC_IDEA 10
# define D_CBC_SEED 11
# define D_CBC_RC2 12
# define D_CBC_RC5 13
# define D_CBC_BF 14
# define D_CBC_CAST 15
# define D_CBC_128_AES 16
# define D_CBC_192_AES 17
# define D_CBC_256_AES 18
# define D_CBC_128_CML 19
# define D_CBC_192_CML 20
# define D_CBC_256_CML 21
# define D_EVP 22
# define D_SHA256 23
# define D_SHA512 24
# define D_WHIRLPOOL 25
# define D_IGE_128_AES 26
# define D_IGE_192_AES 27
# define D_IGE_256_AES 28
# define D_GHASH 29
double d = 0.0;
long c[ALGOR_NUM][SIZE_NUM];
# ifndef OPENSSL_SYS_WIN32
# endif
# define R_DSA_512 0
# define R_DSA_1024 1
# define R_DSA_2048 2
# define R_RSA_512 0
# define R_RSA_1024 1
# define R_RSA_2048 2
# define R_RSA_3072 3
# define R_RSA_4096 4
# define R_RSA_7680 5
# define R_RSA_15360 6
# define R_EC_P160 0
# define R_EC_P192 1
# define R_EC_P224 2
# define R_EC_P256 3
# define R_EC_P384 4
# define R_EC_P521 5
# define R_EC_K163 6
# define R_EC_K233 7
# define R_EC_K283 8
# define R_EC_K409 9
# define R_EC_K571 10
# define R_EC_B163 11
# define R_EC_B233 12
# define R_EC_B283 13
# define R_EC_B409 14
# define R_EC_B571 15
# ifndef OPENSSL_NO_RSA
RSA *rsa_key[RSA_NUM];
long rsa_c[RSA_NUM][2];
static unsigned int rsa_bits[RSA_NUM] = {
512, 1024, 2048, 3072, 4096, 7680, 15360
};
static unsigned char *rsa_data[RSA_NUM] = {
test512, test1024, test2048, test3072, test4096, test7680, test15360
};
static int rsa_data_length[RSA_NUM] = {
sizeof(test512), sizeof(test1024),
sizeof(test2048), sizeof(test3072),
sizeof(test4096), sizeof(test7680),
sizeof(test15360)
};
# endif
# ifndef OPENSSL_NO_DSA
DSA *dsa_key[DSA_NUM];
long dsa_c[DSA_NUM][2];
static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
# endif
# ifndef OPENSSL_NO_EC
static unsigned int test_curves[EC_NUM] = {
NID_secp160r1,
NID_X9_62_prime192v1,
NID_secp224r1,
NID_X9_62_prime256v1,
NID_secp384r1,
NID_secp521r1,
NID_sect163k1,
NID_sect233k1,
NID_sect283k1,
NID_sect409k1,
NID_sect571k1,
NID_sect163r2,
NID_sect233r1,
NID_sect283r1,
NID_sect409r1,
NID_sect571r1
};
static const char *test_curves_names[EC_NUM] = {
"secp160r1",
"nistp192",
"nistp224",
"nistp256",
"nistp384",
"nistp521",
"nistk163",
"nistk233",
"nistk283",
"nistk409",
"nistk571",
"nistb163",
"nistb233",
"nistb283",
"nistb409",
"nistb571"
};
static int test_curves_bits[EC_NUM] = {
160, 192, 224, 256, 384, 521,
163, 233, 283, 409, 571,
163, 233, 283, 409, 571
};
# endif
# ifndef OPENSSL_NO_ECDSA
unsigned char ecdsasig[256];
unsigned int ecdsasiglen;
EC_KEY *ecdsa[EC_NUM];
long ecdsa_c[EC_NUM][2];
# endif
# ifndef OPENSSL_NO_ECDH
EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
int secret_size_a, secret_size_b;
int ecdh_checks = 0;
int secret_idx = 0;
long ecdh_c[EC_NUM][2];
# endif
int rsa_doit[RSA_NUM];
int dsa_doit[DSA_NUM];
# ifndef OPENSSL_NO_ECDSA
int ecdsa_doit[EC_NUM];
# endif
# ifndef OPENSSL_NO_ECDH
int ecdh_doit[EC_NUM];
# endif
int doit[ALGOR_NUM];
int pr_header = 0;
const EVP_CIPHER *evp_cipher = NULL;
const EVP_MD *evp_md = NULL;
int decrypt = 0;
# ifndef NO_FORK
int multi = 0;
# endif
int multiblock = 0;
int misalign = MAX_MISALIGNMENT + 1;
# ifndef TIMES
usertime = -1;
# endif
apps_startup();
memset(results, 0, sizeof(results));
# ifndef OPENSSL_NO_DSA
memset(dsa_key, 0, sizeof(dsa_key));
# endif
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa[i] = NULL;
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++) {
ecdh_a[i] = NULL;
ecdh_b[i] = NULL;
}
# endif
if (bio_err == NULL)
if ((bio_err = BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
# ifndef OPENSSL_NO_RSA
memset(rsa_key, 0, sizeof(rsa_key));
for (i = 0; i < RSA_NUM; i++)
rsa_key[i] = NULL;
# endif
if ((buf_malloc =
(unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
BIO_printf(bio_err, "out of memory\n");
goto end;
}
if ((buf2_malloc =
(unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
BIO_printf(bio_err, "out of memory\n");
goto end;
}
misalign = 0;
buf = buf_malloc;
buf2 = buf2_malloc;
memset(c, 0, sizeof(c));
memset(DES_iv, 0, sizeof(DES_iv));
memset(iv, 0, sizeof(iv));
for (i = 0; i < ALGOR_NUM; i++)
doit[i] = 0;
for (i = 0; i < RSA_NUM; i++)
rsa_doit[i] = 0;
for (i = 0; i < DSA_NUM; i++)
dsa_doit[i] = 0;
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 0;
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 0;
# endif
j = 0;
argc--;
argv++;
while (argc) {
if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
usertime = 0;
j--;
} else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no EVP given\n");
goto end;
}
evp_cipher = EVP_get_cipherbyname(*argv);
if (!evp_cipher) {
evp_md = EVP_get_digestbyname(*argv);
}
if (!evp_cipher && !evp_md) {
BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
*argv);
goto end;
}
doit[D_EVP] = 1;
} else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
decrypt = 1;
j--;
}
# ifndef OPENSSL_NO_ENGINE
else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no engine given\n");
goto end;
}
setup_engine(bio_err, *argv, 0);
j--;
}
# endif
# ifndef NO_FORK
else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no multi count given\n");
goto end;
}
multi = atoi(argv[0]);
if (multi <= 0) {
BIO_printf(bio_err, "bad multi count\n");
goto end;
}
j--;
}
# endif
else if (argc > 0 && !strcmp(*argv, "-mr")) {
mr = 1;
j--;
} else if (argc > 0 && !strcmp(*argv, "-mb")) {
multiblock = 1;
j--;
} else if (argc > 0 && !strcmp(*argv, "-misalign")) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no misalignment given\n");
goto end;
}
misalign = atoi(argv[0]);
if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
BIO_printf(bio_err,
"misalignment is outsize permitted range 0-%d\n",
MAX_MISALIGNMENT);
goto end;
}
buf = buf_malloc + misalign;
buf2 = buf2_malloc + misalign;
j--;
} else
# ifndef OPENSSL_NO_MD2
if (strcmp(*argv, "md2") == 0)
doit[D_MD2] = 1;
else
# endif
# ifndef OPENSSL_NO_MDC2
if (strcmp(*argv, "mdc2") == 0)
doit[D_MDC2] = 1;
else
# endif
# ifndef OPENSSL_NO_MD4
if (strcmp(*argv, "md4") == 0)
doit[D_MD4] = 1;
else
# endif
# ifndef OPENSSL_NO_MD5
if (strcmp(*argv, "md5") == 0)
doit[D_MD5] = 1;
else
# endif
# ifndef OPENSSL_NO_MD5
if (strcmp(*argv, "hmac") == 0)
doit[D_HMAC] = 1;
else
# endif
# ifndef OPENSSL_NO_SHA
if (strcmp(*argv, "sha1") == 0)
doit[D_SHA1] = 1;
else if (strcmp(*argv, "sha") == 0)
doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
else
# ifndef OPENSSL_NO_SHA256
if (strcmp(*argv, "sha256") == 0)
doit[D_SHA256] = 1;
else
# endif
# ifndef OPENSSL_NO_SHA512
if (strcmp(*argv, "sha512") == 0)
doit[D_SHA512] = 1;
else
# endif
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
if (strcmp(*argv, "whirlpool") == 0)
doit[D_WHIRLPOOL] = 1;
else
# endif
# ifndef OPENSSL_NO_RMD160
if (strcmp(*argv, "ripemd") == 0)
doit[D_RMD160] = 1;
else if (strcmp(*argv, "rmd160") == 0)
doit[D_RMD160] = 1;
else if (strcmp(*argv, "ripemd160") == 0)
doit[D_RMD160] = 1;
else
# endif
# ifndef OPENSSL_NO_RC4
if (strcmp(*argv, "rc4") == 0)
doit[D_RC4] = 1;
else
# endif
# ifndef OPENSSL_NO_DES
if (strcmp(*argv, "des-cbc") == 0)
doit[D_CBC_DES] = 1;
else if (strcmp(*argv, "des-ede3") == 0)
doit[D_EDE3_DES] = 1;
else
# endif
# ifndef OPENSSL_NO_AES
if (strcmp(*argv, "aes-128-cbc") == 0)
doit[D_CBC_128_AES] = 1;
else if (strcmp(*argv, "aes-192-cbc") == 0)
doit[D_CBC_192_AES] = 1;
else if (strcmp(*argv, "aes-256-cbc") == 0)
doit[D_CBC_256_AES] = 1;
else if (strcmp(*argv, "aes-128-ige") == 0)
doit[D_IGE_128_AES] = 1;
else if (strcmp(*argv, "aes-192-ige") == 0)
doit[D_IGE_192_AES] = 1;
else if (strcmp(*argv, "aes-256-ige") == 0)
doit[D_IGE_256_AES] = 1;
else
# endif
# ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv, "camellia-128-cbc") == 0)
doit[D_CBC_128_CML] = 1;
else if (strcmp(*argv, "camellia-192-cbc") == 0)
doit[D_CBC_192_CML] = 1;
else if (strcmp(*argv, "camellia-256-cbc") == 0)
doit[D_CBC_256_CML] = 1;
else
# endif
# ifndef OPENSSL_NO_RSA
# if 0
if (strcmp(*argv, "rsaref") == 0) {
RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
j--;
} else
# endif
# ifndef RSA_NULL
if (strcmp(*argv, "openssl") == 0) {
RSA_set_default_method(RSA_PKCS1_SSLeay());
j--;
} else
# endif
# endif
if (strcmp(*argv, "dsa512") == 0)
dsa_doit[R_DSA_512] = 2;
else if (strcmp(*argv, "dsa1024") == 0)
dsa_doit[R_DSA_1024] = 2;
else if (strcmp(*argv, "dsa2048") == 0)
dsa_doit[R_DSA_2048] = 2;
else if (strcmp(*argv, "rsa512") == 0)
rsa_doit[R_RSA_512] = 2;
else if (strcmp(*argv, "rsa1024") == 0)
rsa_doit[R_RSA_1024] = 2;
else if (strcmp(*argv, "rsa2048") == 0)
rsa_doit[R_RSA_2048] = 2;
else if (strcmp(*argv, "rsa3072") == 0)
rsa_doit[R_RSA_3072] = 2;
else if (strcmp(*argv, "rsa4096") == 0)
rsa_doit[R_RSA_4096] = 2;
else if (strcmp(*argv, "rsa7680") == 0)
rsa_doit[R_RSA_7680] = 2;
else if (strcmp(*argv, "rsa15360") == 0)
rsa_doit[R_RSA_15360] = 2;
else
# ifndef OPENSSL_NO_RC2
if (strcmp(*argv, "rc2-cbc") == 0)
doit[D_CBC_RC2] = 1;
else if (strcmp(*argv, "rc2") == 0)
doit[D_CBC_RC2] = 1;
else
# endif
# ifndef OPENSSL_NO_RC5
if (strcmp(*argv, "rc5-cbc") == 0)
doit[D_CBC_RC5] = 1;
else if (strcmp(*argv, "rc5") == 0)
doit[D_CBC_RC5] = 1;
else
# endif
# ifndef OPENSSL_NO_IDEA
if (strcmp(*argv, "idea-cbc") == 0)
doit[D_CBC_IDEA] = 1;
else if (strcmp(*argv, "idea") == 0)
doit[D_CBC_IDEA] = 1;
else
# endif
# ifndef OPENSSL_NO_SEED
if (strcmp(*argv, "seed-cbc") == 0)
doit[D_CBC_SEED] = 1;
else if (strcmp(*argv, "seed") == 0)
doit[D_CBC_SEED] = 1;
else
# endif
# ifndef OPENSSL_NO_BF
if (strcmp(*argv, "bf-cbc") == 0)
doit[D_CBC_BF] = 1;
else if (strcmp(*argv, "blowfish") == 0)
doit[D_CBC_BF] = 1;
else if (strcmp(*argv, "bf") == 0)
doit[D_CBC_BF] = 1;
else
# endif
# ifndef OPENSSL_NO_CAST
if (strcmp(*argv, "cast-cbc") == 0)
doit[D_CBC_CAST] = 1;
else if (strcmp(*argv, "cast") == 0)
doit[D_CBC_CAST] = 1;
else if (strcmp(*argv, "cast5") == 0)
doit[D_CBC_CAST] = 1;
else
# endif
# ifndef OPENSSL_NO_DES
if (strcmp(*argv, "des") == 0) {
doit[D_CBC_DES] = 1;
doit[D_EDE3_DES] = 1;
} else
# endif
# ifndef OPENSSL_NO_AES
if (strcmp(*argv, "aes") == 0) {
doit[D_CBC_128_AES] = 1;
doit[D_CBC_192_AES] = 1;
doit[D_CBC_256_AES] = 1;
} else if (strcmp(*argv, "ghash") == 0) {
doit[D_GHASH] = 1;
} else
# endif
# ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv, "camellia") == 0) {
doit[D_CBC_128_CML] = 1;
doit[D_CBC_192_CML] = 1;
doit[D_CBC_256_CML] = 1;
} else
# endif
# ifndef OPENSSL_NO_RSA
if (strcmp(*argv, "rsa") == 0) {
rsa_doit[R_RSA_512] = 1;
rsa_doit[R_RSA_1024] = 1;
rsa_doit[R_RSA_2048] = 1;
rsa_doit[R_RSA_3072] = 1;
rsa_doit[R_RSA_4096] = 1;
rsa_doit[R_RSA_7680] = 1;
rsa_doit[R_RSA_15360] = 1;
} else
# endif
# ifndef OPENSSL_NO_DSA
if (strcmp(*argv, "dsa") == 0) {
dsa_doit[R_DSA_512] = 1;
dsa_doit[R_DSA_1024] = 1;
dsa_doit[R_DSA_2048] = 1;
} else
# endif
# ifndef OPENSSL_NO_ECDSA
if (strcmp(*argv, "ecdsap160") == 0)
ecdsa_doit[R_EC_P160] = 2;
else if (strcmp(*argv, "ecdsap192") == 0)
ecdsa_doit[R_EC_P192] = 2;
else if (strcmp(*argv, "ecdsap224") == 0)
ecdsa_doit[R_EC_P224] = 2;
else if (strcmp(*argv, "ecdsap256") == 0)
ecdsa_doit[R_EC_P256] = 2;
else if (strcmp(*argv, "ecdsap384") == 0)
ecdsa_doit[R_EC_P384] = 2;
else if (strcmp(*argv, "ecdsap521") == 0)
ecdsa_doit[R_EC_P521] = 2;
else if (strcmp(*argv, "ecdsak163") == 0)
ecdsa_doit[R_EC_K163] = 2;
else if (strcmp(*argv, "ecdsak233") == 0)
ecdsa_doit[R_EC_K233] = 2;
else if (strcmp(*argv, "ecdsak283") == 0)
ecdsa_doit[R_EC_K283] = 2;
else if (strcmp(*argv, "ecdsak409") == 0)
ecdsa_doit[R_EC_K409] = 2;
else if (strcmp(*argv, "ecdsak571") == 0)
ecdsa_doit[R_EC_K571] = 2;
else if (strcmp(*argv, "ecdsab163") == 0)
ecdsa_doit[R_EC_B163] = 2;
else if (strcmp(*argv, "ecdsab233") == 0)
ecdsa_doit[R_EC_B233] = 2;
else if (strcmp(*argv, "ecdsab283") == 0)
ecdsa_doit[R_EC_B283] = 2;
else if (strcmp(*argv, "ecdsab409") == 0)
ecdsa_doit[R_EC_B409] = 2;
else if (strcmp(*argv, "ecdsab571") == 0)
ecdsa_doit[R_EC_B571] = 2;
else if (strcmp(*argv, "ecdsa") == 0) {
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 1;
} else
# endif
# ifndef OPENSSL_NO_ECDH
if (strcmp(*argv, "ecdhp160") == 0)
ecdh_doit[R_EC_P160] = 2;
else if (strcmp(*argv, "ecdhp192") == 0)
ecdh_doit[R_EC_P192] = 2;
else if (strcmp(*argv, "ecdhp224") == 0)
ecdh_doit[R_EC_P224] = 2;
else if (strcmp(*argv, "ecdhp256") == 0)
ecdh_doit[R_EC_P256] = 2;
else if (strcmp(*argv, "ecdhp384") == 0)
ecdh_doit[R_EC_P384] = 2;
else if (strcmp(*argv, "ecdhp521") == 0)
ecdh_doit[R_EC_P521] = 2;
else if (strcmp(*argv, "ecdhk163") == 0)
ecdh_doit[R_EC_K163] = 2;
else if (strcmp(*argv, "ecdhk233") == 0)
ecdh_doit[R_EC_K233] = 2;
else if (strcmp(*argv, "ecdhk283") == 0)
ecdh_doit[R_EC_K283] = 2;
else if (strcmp(*argv, "ecdhk409") == 0)
ecdh_doit[R_EC_K409] = 2;
else if (strcmp(*argv, "ecdhk571") == 0)
ecdh_doit[R_EC_K571] = 2;
else if (strcmp(*argv, "ecdhb163") == 0)
ecdh_doit[R_EC_B163] = 2;
else if (strcmp(*argv, "ecdhb233") == 0)
ecdh_doit[R_EC_B233] = 2;
else if (strcmp(*argv, "ecdhb283") == 0)
ecdh_doit[R_EC_B283] = 2;
else if (strcmp(*argv, "ecdhb409") == 0)
ecdh_doit[R_EC_B409] = 2;
else if (strcmp(*argv, "ecdhb571") == 0)
ecdh_doit[R_EC_B571] = 2;
else if (strcmp(*argv, "ecdh") == 0) {
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 1;
} else
# endif
{
BIO_printf(bio_err, "Error: bad option or value\n");
BIO_printf(bio_err, "\n");
BIO_printf(bio_err, "Available values:\n");
# ifndef OPENSSL_NO_MD2
BIO_printf(bio_err, "md2 ");
# endif
# ifndef OPENSSL_NO_MDC2
BIO_printf(bio_err, "mdc2 ");
# endif
# ifndef OPENSSL_NO_MD4
BIO_printf(bio_err, "md4 ");
# endif
# ifndef OPENSSL_NO_MD5
BIO_printf(bio_err, "md5 ");
# ifndef OPENSSL_NO_HMAC
BIO_printf(bio_err, "hmac ");
# endif
# endif
# ifndef OPENSSL_NO_SHA1
BIO_printf(bio_err, "sha1 ");
# endif
# ifndef OPENSSL_NO_SHA256
BIO_printf(bio_err, "sha256 ");
# endif
# ifndef OPENSSL_NO_SHA512
BIO_printf(bio_err, "sha512 ");
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
BIO_printf(bio_err, "whirlpool");
# endif
# ifndef OPENSSL_NO_RMD160
BIO_printf(bio_err, "rmd160");
# endif
# if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
!defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
!defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \
!defined(OPENSSL_NO_WHIRLPOOL)
BIO_printf(bio_err, "\n");
# endif
# ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err, "idea-cbc ");
# endif
# ifndef OPENSSL_NO_SEED
BIO_printf(bio_err, "seed-cbc ");
# endif
# ifndef OPENSSL_NO_RC2
BIO_printf(bio_err, "rc2-cbc ");
# endif
# ifndef OPENSSL_NO_RC5
BIO_printf(bio_err, "rc5-cbc ");
# endif
# ifndef OPENSSL_NO_BF
BIO_printf(bio_err, "bf-cbc");
# endif
# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
!defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
BIO_printf(bio_err, "\n");
# endif
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "des-cbc des-ede3 ");
# endif
# ifndef OPENSSL_NO_AES
BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
# endif
# ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err, "\n");
BIO_printf(bio_err,
"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
# endif
# ifndef OPENSSL_NO_RC4
BIO_printf(bio_err, "rc4");
# endif
BIO_printf(bio_err, "\n");
# ifndef OPENSSL_NO_RSA
BIO_printf(bio_err,
"rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
BIO_printf(bio_err, "rsa7680 rsa15360\n");
# endif
# ifndef OPENSSL_NO_DSA
BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
# endif
# ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
"ecdsap256 ecdsap384 ecdsap521\n");
BIO_printf(bio_err,
"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
BIO_printf(bio_err,
"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
BIO_printf(bio_err, "ecdsa\n");
# endif
# ifndef OPENSSL_NO_ECDH
BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
"ecdhp256 ecdhp384 ecdhp521\n");
BIO_printf(bio_err,
"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
BIO_printf(bio_err,
"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
BIO_printf(bio_err, "ecdh\n");
# endif
# ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err, "idea ");
# endif
# ifndef OPENSSL_NO_SEED
BIO_printf(bio_err, "seed ");
# endif
# ifndef OPENSSL_NO_RC2
BIO_printf(bio_err, "rc2 ");
# endif
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "des ");
# endif
# ifndef OPENSSL_NO_AES
BIO_printf(bio_err, "aes ");
# endif
# ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err, "camellia ");
# endif
# ifndef OPENSSL_NO_RSA
BIO_printf(bio_err, "rsa ");
# endif
# ifndef OPENSSL_NO_BF
BIO_printf(bio_err, "blowfish");
# endif
# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
!defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
!defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
!defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
BIO_printf(bio_err, "\n");
# endif
BIO_printf(bio_err, "\n");
BIO_printf(bio_err, "Available options:\n");
# if defined(TIMES) || defined(USE_TOD)
BIO_printf(bio_err, "-elapsed "
"measure time in real time instead of CPU user time.\n");
# endif
# ifndef OPENSSL_NO_ENGINE
BIO_printf(bio_err,
"-engine e "
"use engine e, possibly a hardware device.\n");
# endif
BIO_printf(bio_err, "-evp e " "use EVP e.\n");
BIO_printf(bio_err,
"-decrypt "
"time decryption instead of encryption (only EVP).\n");
BIO_printf(bio_err,
"-mr "
"produce machine readable output.\n");
BIO_printf(bio_err,
"-mb "
"perform multi-block benchmark (for specific ciphers)\n");
BIO_printf(bio_err,
"-misalign n "
"perform benchmark with misaligned data\n");
# ifndef NO_FORK
BIO_printf(bio_err,
"-multi n " "run n benchmarks in parallel.\n");
# endif
goto end;
}
argc--;
argv++;
j++;
}
# ifndef NO_FORK
if (multi && do_multi(multi))
goto show_res;
# endif
if (j == 0) {
for (i = 0; i < ALGOR_NUM; i++) {
if (i != D_EVP)
doit[i] = 1;
}
for (i = 0; i < RSA_NUM; i++)
rsa_doit[i] = 1;
for (i = 0; i < DSA_NUM; i++)
dsa_doit[i] = 1;
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 1;
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 1;
# endif
}
for (i = 0; i < ALGOR_NUM; i++)
if (doit[i])
pr_header++;
if (usertime == 0 && !mr)
BIO_printf(bio_err,
"You have chosen to measure elapsed time "
"instead of user CPU time.\n");
# ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++) {
const unsigned char *p;
p = rsa_data[i];
rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
if (rsa_key[i] == NULL) {
BIO_printf(bio_err, "internal error loading RSA key number %d\n",
i);
goto end;
}
# if 0
else {
BIO_printf(bio_err,
mr ? "+RK:%d:"
: "Loaded RSA key, %d bit modulus and e= 0x",
BN_num_bits(rsa_key[i]->n));
BN_print(bio_err, rsa_key[i]->e);
BIO_printf(bio_err, "\n");
}
# endif
}
# endif
# ifndef OPENSSL_NO_DSA
dsa_key[0] = get_dsa512();
dsa_key[1] = get_dsa1024();
dsa_key[2] = get_dsa2048();
# endif
# ifndef OPENSSL_NO_DES
DES_set_key_unchecked(&key, &sch);
DES_set_key_unchecked(&key2, &sch2);
DES_set_key_unchecked(&key3, &sch3);
# endif
# ifndef OPENSSL_NO_AES
AES_set_encrypt_key(key16, 128, &aes_ks1);
AES_set_encrypt_key(key24, 192, &aes_ks2);
AES_set_encrypt_key(key32, 256, &aes_ks3);
# endif
# ifndef OPENSSL_NO_CAMELLIA
Camellia_set_key(key16, 128, &camellia_ks1);
Camellia_set_key(ckey24, 192, &camellia_ks2);
Camellia_set_key(ckey32, 256, &camellia_ks3);
# endif
# ifndef OPENSSL_NO_IDEA
idea_set_encrypt_key(key16, &idea_ks);
# endif
# ifndef OPENSSL_NO_SEED
SEED_set_key(key16, &seed_ks);
# endif
# ifndef OPENSSL_NO_RC4
RC4_set_key(&rc4_ks, 16, key16);
# endif
# ifndef OPENSSL_NO_RC2
RC2_set_key(&rc2_ks, 16, key16, 128);
# endif
# ifndef OPENSSL_NO_RC5
RC5_32_set_key(&rc5_ks, 16, key16, 12);
# endif
# ifndef OPENSSL_NO_BF
BF_set_key(&bf_ks, 16, key16);
# endif
# ifndef OPENSSL_NO_CAST
CAST_set_key(&cast_ks, 16, key16);
# endif
# ifndef OPENSSL_NO_RSA
memset(rsa_c, 0, sizeof(rsa_c));
# endif
# ifndef SIGALRM
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
count = 10;
do {
long it;
count *= 2;
Time_F(START);
for (it = count; it; it--)
DES_ecb_encrypt((DES_cblock *)buf,
(DES_cblock *)buf, &sch, DES_ENCRYPT);
d = Time_F(STOP);
} while (d < 3);
save_count = count;
c[D_MD2][0] = count / 10;
c[D_MDC2][0] = count / 10;
c[D_MD4][0] = count;
c[D_MD5][0] = count;
c[D_HMAC][0] = count;
c[D_SHA1][0] = count;
c[D_RMD160][0] = count;
c[D_RC4][0] = count * 5;
c[D_CBC_DES][0] = count;
c[D_EDE3_DES][0] = count / 3;
c[D_CBC_IDEA][0] = count;
c[D_CBC_SEED][0] = count;
c[D_CBC_RC2][0] = count;
c[D_CBC_RC5][0] = count;
c[D_CBC_BF][0] = count;
c[D_CBC_CAST][0] = count;
c[D_CBC_128_AES][0] = count;
c[D_CBC_192_AES][0] = count;
c[D_CBC_256_AES][0] = count;
c[D_CBC_128_CML][0] = count;
c[D_CBC_192_CML][0] = count;
c[D_CBC_256_CML][0] = count;
c[D_SHA256][0] = count;
c[D_SHA512][0] = count;
c[D_WHIRLPOOL][0] = count;
c[D_IGE_128_AES][0] = count;
c[D_IGE_192_AES][0] = count;
c[D_IGE_256_AES][0] = count;
c[D_GHASH][0] = count;
for (i = 1; i < SIZE_NUM; i++) {
long l0, l1;
l0 = (long)lengths[0];
l1 = (long)lengths[i];
c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
l0 = (long)lengths[i - 1];
c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
}
# ifndef OPENSSL_NO_RSA
rsa_c[R_RSA_512][0] = count / 2000;
rsa_c[R_RSA_512][1] = count / 400;
for (i = 1; i < RSA_NUM; i++) {
rsa_c[i][0] = rsa_c[i - 1][0] / 8;
rsa_c[i][1] = rsa_c[i - 1][1] / 4;
if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
rsa_doit[i] = 0;
else {
if (rsa_c[i][0] == 0) {
rsa_c[i][0] = 1;
rsa_c[i][1] = 20;
}
}
}
# endif
# ifndef OPENSSL_NO_DSA
dsa_c[R_DSA_512][0] = count / 1000;
dsa_c[R_DSA_512][1] = count / 1000 / 2;
for (i = 1; i < DSA_NUM; i++) {
dsa_c[i][0] = dsa_c[i - 1][0] / 4;
dsa_c[i][1] = dsa_c[i - 1][1] / 4;
if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
dsa_doit[i] = 0;
else {
if (dsa_c[i] == 0) {
dsa_c[i][0] = 1;
dsa_c[i][1] = 1;
}
}
}
# endif
# ifndef OPENSSL_NO_ECDSA
ecdsa_c[R_EC_P160][0] = count / 1000;
ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
ecdsa_c[R_EC_K163][0] = count / 1000;
ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
ecdsa_c[R_EC_B163][0] = count / 1000;
ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
for (i = R_EC_B233; i <= R_EC_B571; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
# endif
# ifndef OPENSSL_NO_ECDH
ecdh_c[R_EC_P160][0] = count / 1000;
ecdh_c[R_EC_P160][1] = count / 1000;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
ecdh_c[R_EC_K163][0] = count / 1000;
ecdh_c[R_EC_K163][1] = count / 1000;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
ecdh_c[R_EC_B163][0] = count / 1000;
ecdh_c[R_EC_B163][1] = count / 1000;
for (i = R_EC_B233; i <= R_EC_B571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
# endif
# define COND(d) (count < (d))
# define COUNT(d) (d)
# else
# error "You cannot disable DES on systems without SIGALRM."
# endif
# else
# define COND(c) (run && count<0x7fffffff)
# define COUNT(d) (count)
# ifndef _WIN32
signal(SIGALRM, sig_done);
# endif
# endif
# ifndef OPENSSL_NO_MD2
if (doit[D_MD2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
EVP_md2(), NULL);
d = Time_F(STOP);
print_result(D_MD2, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_MDC2
if (doit[D_MDC2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
EVP_mdc2(), NULL);
d = Time_F(STOP);
print_result(D_MDC2, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_MD4
if (doit[D_MD4]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
NULL, EVP_md4(), NULL);
d = Time_F(STOP);
print_result(D_MD4, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_MD5
if (doit[D_MD5]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
MD5(buf, lengths[j], md5);
d = Time_F(STOP);
print_result(D_MD5, j, count, d);
}
}
# endif
# if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
if (doit[D_HMAC]) {
HMAC_CTX hctx;
HMAC_CTX_init(&hctx);
HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
16, EVP_md5(), NULL);
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
HMAC_Update(&hctx, buf, lengths[j]);
HMAC_Final(&hctx, &(hmac[0]), NULL);
}
d = Time_F(STOP);
print_result(D_HMAC, j, count, d);
}
HMAC_CTX_cleanup(&hctx);
}
# endif
# ifndef OPENSSL_NO_SHA
if (doit[D_SHA1]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
# if 0
EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
EVP_sha1(), NULL);
# else
SHA1(buf, lengths[j], sha);
# endif
d = Time_F(STOP);
print_result(D_SHA1, j, count, d);
}
}
# ifndef OPENSSL_NO_SHA256
if (doit[D_SHA256]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
SHA256(buf, lengths[j], sha256);
d = Time_F(STOP);
print_result(D_SHA256, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_SHA512
if (doit[D_SHA512]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
SHA512(buf, lengths[j], sha512);
d = Time_F(STOP);
print_result(D_SHA512, j, count, d);
}
}
# endif
# endif
# ifndef OPENSSL_NO_WHIRLPOOL
if (doit[D_WHIRLPOOL]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
WHIRLPOOL(buf, lengths[j], whirlpool);
d = Time_F(STOP);
print_result(D_WHIRLPOOL, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RMD160
if (doit[D_RMD160]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
EVP_ripemd160(), NULL);
d = Time_F(STOP);
print_result(D_RMD160, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RC4
if (doit[D_RC4]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
d = Time_F(STOP);
print_result(D_RC4, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_DES
if (doit[D_CBC_DES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
&DES_iv, DES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_DES, j, count, d);
}
}
if (doit[D_EDE3_DES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
DES_ede3_cbc_encrypt(buf, buf, lengths[j],
&sch, &sch2, &sch3,
&DES_iv, DES_ENCRYPT);
d = Time_F(STOP);
print_result(D_EDE3_DES, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_AES
if (doit[D_CBC_128_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks1,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_128_AES, j, count, d);
}
}
if (doit[D_CBC_192_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks2,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_192_AES, j, count, d);
}
}
if (doit[D_CBC_256_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks3,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_256_AES, j, count, d);
}
}
if (doit[D_IGE_128_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks1,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_128_AES, j, count, d);
}
}
if (doit[D_IGE_192_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks2,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_192_AES, j, count, d);
}
}
if (doit[D_IGE_256_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks3,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_256_AES, j, count, d);
}
}
if (doit[D_GHASH]) {
GCM128_CONTEXT *ctx =
CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
d = Time_F(STOP);
print_result(D_GHASH, j, count, d);
}
CRYPTO_gcm128_release(ctx);
}
# endif
# ifndef OPENSSL_NO_CAMELLIA
if (doit[D_CBC_128_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks1,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_128_CML, j, count, d);
}
}
if (doit[D_CBC_192_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks2,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_192_CML, j, count, d);
}
}
if (doit[D_CBC_256_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks3,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_256_CML, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_IDEA
if (doit[D_CBC_IDEA]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
idea_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &idea_ks,
iv, IDEA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_IDEA, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_SEED
if (doit[D_CBC_SEED]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
SEED_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &seed_ks, iv, 1);
d = Time_F(STOP);
print_result(D_CBC_SEED, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RC2
if (doit[D_CBC_RC2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
RC2_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &rc2_ks,
iv, RC2_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_RC2, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_RC5
if (doit[D_CBC_RC5]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
RC5_32_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &rc5_ks,
iv, RC5_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_RC5, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_BF
if (doit[D_CBC_BF]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
BF_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &bf_ks,
iv, BF_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_BF, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_CAST
if (doit[D_CBC_CAST]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
CAST_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &cast_ks,
iv, CAST_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_CAST, j, count, d);
}
}
# endif
if (doit[D_EVP]) {
# ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
if (multiblock && evp_cipher) {
if (!
(EVP_CIPHER_flags(evp_cipher) &
EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
fprintf(stderr, "%s is not multi-block capable\n",
OBJ_nid2ln(evp_cipher->nid));
goto end;
}
multiblock_speed(evp_cipher);
mret = 0;
goto end;
}
# endif
for (j = 0; j < SIZE_NUM; j++) {
if (evp_cipher) {
EVP_CIPHER_CTX ctx;
int outl;
names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
print_message(names[D_EVP], save_count, lengths[j]);
EVP_CIPHER_CTX_init(&ctx);
if (decrypt)
EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
else
EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
EVP_CIPHER_CTX_set_padding(&ctx, 0);
Time_F(START);
if (decrypt)
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]);
count++)
EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
else
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]);
count++)
EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
if (decrypt)
EVP_DecryptFinal_ex(&ctx, buf, &outl);
else
EVP_EncryptFinal_ex(&ctx, buf, &outl);
d = Time_F(STOP);
EVP_CIPHER_CTX_cleanup(&ctx);
}
if (evp_md) {
names[D_EVP] = OBJ_nid2ln(evp_md->type);
print_message(names[D_EVP], save_count, lengths[j]);
Time_F(START);
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]); count++)
EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
d = Time_F(STOP);
}
print_result(D_EVP, j, count, d);
}
}
# ifndef OPENSSL_SYS_WIN32
# endif
RAND_pseudo_bytes(buf, 36);
# ifndef OPENSSL_NO_RSA
for (j = 0; j < RSA_NUM; j++) {
int ret;
if (!rsa_doit[j])
continue;
ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err,
"RSA sign failure. No RSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("private", "rsa",
rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
&rsa_num, rsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err, "RSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R1:%ld:%d:%.2f\n"
: "%ld %d bit private RSA's in %.2fs\n",
count, rsa_bits[j], d);
rsa_results[j][0] = d / (double)count;
rsa_count = count;
}
# if 1
ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err,
"RSA verify failure. No RSA verify will be done.\n");
ERR_print_errors(bio_err);
rsa_doit[j] = 0;
} else {
pkey_print_message("public", "rsa",
rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
rsa_num, rsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err, "RSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R2:%ld:%d:%.2f\n"
: "%ld %d bit public RSA's in %.2fs\n",
count, rsa_bits[j], d);
rsa_results[j][1] = d / (double)count;
}
# endif
if (rsa_count <= 1) {
for (j++; j < RSA_NUM; j++)
rsa_doit[j] = 0;
}
}
# endif
RAND_pseudo_bytes(buf, 20);
# ifndef OPENSSL_NO_DSA
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < DSA_NUM; j++) {
unsigned int kk;
int ret;
if (!dsa_doit[j])
continue;
ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err,
"DSA sign failure. No DSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "dsa",
dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err, "DSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R3:%ld:%d:%.2f\n"
: "%ld %d bit DSA signs in %.2fs\n",
count, dsa_bits[j], d);
dsa_results[j][0] = d / (double)count;
rsa_count = count;
}
ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err,
"DSA verify failure. No DSA verify will be done.\n");
ERR_print_errors(bio_err);
dsa_doit[j] = 0;
} else {
pkey_print_message("verify", "dsa",
dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err, "DSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R4:%ld:%d:%.2f\n"
: "%ld %d bit DSA verify in %.2fs\n",
count, dsa_bits[j], d);
dsa_results[j][1] = d / (double)count;
}
if (rsa_count <= 1) {
for (j++; j < DSA_NUM; j++)
dsa_doit[j] = 0;
}
}
if (rnd_fake)
RAND_cleanup();
# endif
# ifndef OPENSSL_NO_ECDSA
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < EC_NUM; j++) {
int ret;
if (!ecdsa_doit[j])
continue;
ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if (ecdsa[j] == NULL) {
BIO_printf(bio_err, "ECDSA failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
# if 1
EC_KEY_precompute_mult(ecdsa[j], NULL);
# endif
EC_KEY_generate_key(ecdsa[j]);
ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
if (ret == 0) {
BIO_printf(bio_err,
"ECDSA sign failure. No ECDSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "ecdsa",
ecdsa_c[j][0],
test_curves_bits[j], ECDSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
ret = ECDSA_sign(0, buf, 20,
ecdsasig, &ecdsasiglen, ecdsa[j]);
if (ret == 0) {
BIO_printf(bio_err, "ECDSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R5:%ld:%d:%.2f\n" :
"%ld %d bit ECDSA signs in %.2fs \n",
count, test_curves_bits[j], d);
ecdsa_results[j][0] = d / (double)count;
rsa_count = count;
}
ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
if (ret != 1) {
BIO_printf(bio_err,
"ECDSA verify failure. No ECDSA verify will be done.\n");
ERR_print_errors(bio_err);
ecdsa_doit[j] = 0;
} else {
pkey_print_message("verify", "ecdsa",
ecdsa_c[j][1],
test_curves_bits[j], ECDSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
ret =
ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
ecdsa[j]);
if (ret != 1) {
BIO_printf(bio_err, "ECDSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R6:%ld:%d:%.2f\n"
: "%ld %d bit ECDSA verify in %.2fs\n",
count, test_curves_bits[j], d);
ecdsa_results[j][1] = d / (double)count;
}
if (rsa_count <= 1) {
for (j++; j < EC_NUM; j++)
ecdsa_doit[j] = 0;
}
}
}
if (rnd_fake)
RAND_cleanup();
# endif
# ifndef OPENSSL_NO_ECDH
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < EC_NUM; j++) {
if (!ecdh_doit[j])
continue;
ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
BIO_printf(bio_err, "ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
if (!EC_KEY_generate_key(ecdh_a[j]) ||
!EC_KEY_generate_key(ecdh_b[j])) {
BIO_printf(bio_err, "ECDH key generation failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
int field_size, outlen;
void *(*kdf) (const void *in, size_t inlen, void *out,
size_t *xoutlen);
field_size =
EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
if (field_size <= 24 * 8) {
outlen = KDF1_SHA1_len;
kdf = KDF1_SHA1;
} else {
outlen = (field_size + 7) / 8;
kdf = NULL;
}
secret_size_a =
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
secret_size_b =
ECDH_compute_key(secret_b, outlen,
EC_KEY_get0_public_key(ecdh_a[j]),
ecdh_b[j], kdf);
if (secret_size_a != secret_size_b)
ecdh_checks = 0;
else
ecdh_checks = 1;
for (secret_idx = 0; (secret_idx < secret_size_a)
&& (ecdh_checks == 1); secret_idx++) {
if (secret_a[secret_idx] != secret_b[secret_idx])
ecdh_checks = 0;
}
if (ecdh_checks == 0) {
BIO_printf(bio_err, "ECDH computations don't match.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
}
pkey_print_message("", "ecdh",
ecdh_c[j][0],
test_curves_bits[j], ECDH_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R7:%ld:%d:%.2f\n" :
"%ld %d-bit ECDH ops in %.2fs\n", count,
test_curves_bits[j], d);
ecdh_results[j][0] = d / (double)count;
rsa_count = count;
}
}
if (rsa_count <= 1) {
for (j++; j < EC_NUM; j++)
ecdh_doit[j] = 0;
}
}
if (rnd_fake)
RAND_cleanup();
# endif
# ifndef NO_FORK
show_res:
# endif
if (!mr) {
fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
printf("options:");
printf("%s ", BN_options());
# ifndef OPENSSL_NO_MD2
printf("%s ", MD2_options());
# endif
# ifndef OPENSSL_NO_RC4
printf("%s ", RC4_options());
# endif
# ifndef OPENSSL_NO_DES
printf("%s ", DES_options());
# endif
# ifndef OPENSSL_NO_AES
printf("%s ", AES_options());
# endif
# ifndef OPENSSL_NO_IDEA
printf("%s ", idea_options());
# endif
# ifndef OPENSSL_NO_BF
printf("%s ", BF_options());
# endif
fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
}
if (pr_header) {
if (mr)
fprintf(stdout, "+H");
else {
fprintf(stdout,
"The 'numbers' are in 1000s of bytes per second processed.\n");
fprintf(stdout, "type ");
}
for (j = 0; j < SIZE_NUM; j++)
fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
fprintf(stdout, "\n");
}
for (k = 0; k < ALGOR_NUM; k++) {
if (!doit[k])
continue;
if (mr)
fprintf(stdout, "+F:%d:%s", k, names[k]);
else
fprintf(stdout, "%-13s", names[k]);
for (j = 0; j < SIZE_NUM; j++) {
if (results[k][j] > 10000 && !mr)
fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
else
fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
}
fprintf(stdout, "\n");
}
# ifndef OPENSSL_NO_RSA
j = 1;
for (k = 0; k < RSA_NUM; k++) {
if (!rsa_doit[k])
continue;
if (j && !mr) {
printf("%18ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F2:%u:%u:%f:%f\n",
k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
else
fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
}
# endif
# ifndef OPENSSL_NO_DSA
j = 1;
for (k = 0; k < DSA_NUM; k++) {
if (!dsa_doit[k])
continue;
if (j && !mr) {
printf("%18ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F3:%u:%u:%f:%f\n",
k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
else
fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
}
# endif
# ifndef OPENSSL_NO_ECDSA
j = 1;
for (k = 0; k < EC_NUM; k++) {
if (!ecdsa_doit[k])
continue;
if (j && !mr) {
printf("%30ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F4:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdsa_results[k][0], ecdsa_results[k][1]);
else
fprintf(stdout,
"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdsa_results[k][0], ecdsa_results[k][1],
1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
}
# endif
# ifndef OPENSSL_NO_ECDH
j = 1;
for (k = 0; k < EC_NUM; k++) {
if (!ecdh_doit[k])
continue;
if (j && !mr) {
printf("%30sop op/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F5:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
else
fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
}
# endif
mret = 0;
end:
ERR_print_errors(bio_err);
if (buf_malloc != NULL)
OPENSSL_free(buf_malloc);
if (buf2_malloc != NULL)
OPENSSL_free(buf2_malloc);
# ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++)
if (rsa_key[i] != NULL)
RSA_free(rsa_key[i]);
# endif
# ifndef OPENSSL_NO_DSA
for (i = 0; i < DSA_NUM; i++)
if (dsa_key[i] != NULL)
DSA_free(dsa_key[i]);
# endif
# ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
if (ecdsa[i] != NULL)
EC_KEY_free(ecdsa[i]);
# endif
# ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++) {
if (ecdh_a[i] != NULL)
EC_KEY_free(ecdh_a[i]);
if (ecdh_b[i] != NULL)
EC_KEY_free(ecdh_b[i]);
}
# endif
apps_shutdown();
OPENSSL_EXIT(mret);
}
|
['int MAIN(int argc, char **argv)\n{\n unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;\n unsigned char *buf = NULL, *buf2 = NULL;\n int mret = 1;\n long count = 0, save_count = 0;\n int i, j, k;\n# if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n long rsa_count;\n# endif\n# ifndef OPENSSL_NO_RSA\n unsigned rsa_num;\n# endif\n unsigned char md[EVP_MAX_MD_SIZE];\n# ifndef OPENSSL_NO_MD2\n unsigned char md2[MD2_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MDC2\n unsigned char mdc2[MDC2_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MD4\n unsigned char md4[MD4_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_MD5\n unsigned char md5[MD5_DIGEST_LENGTH];\n unsigned char hmac[MD5_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA\n unsigned char sha[SHA_DIGEST_LENGTH];\n# ifndef OPENSSL_NO_SHA256\n unsigned char sha256[SHA256_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA512\n unsigned char sha512[SHA512_DIGEST_LENGTH];\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_RMD160\n unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_RC4\n RC4_KEY rc4_ks;\n# endif\n# ifndef OPENSSL_NO_RC5\n RC5_32_KEY rc5_ks;\n# endif\n# ifndef OPENSSL_NO_RC2\n RC2_KEY rc2_ks;\n# endif\n# ifndef OPENSSL_NO_IDEA\n IDEA_KEY_SCHEDULE idea_ks;\n# endif\n# ifndef OPENSSL_NO_SEED\n SEED_KEY_SCHEDULE seed_ks;\n# endif\n# ifndef OPENSSL_NO_BF\n BF_KEY bf_ks;\n# endif\n# ifndef OPENSSL_NO_CAST\n CAST_KEY cast_ks;\n# endif\n static const unsigned char key16[16] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12\n };\n# ifndef OPENSSL_NO_AES\n static const unsigned char key24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char key32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n static const unsigned char ckey24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char ckey32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n# endif\n# ifndef OPENSSL_NO_AES\n# define MAX_BLOCK_SIZE 128\n# else\n# define MAX_BLOCK_SIZE 64\n# endif\n unsigned char DES_iv[8];\n unsigned char iv[2 * MAX_BLOCK_SIZE / 8];\n# ifndef OPENSSL_NO_DES\n static DES_cblock key =\n { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };\n static DES_cblock key2 =\n { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };\n static DES_cblock key3 =\n { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };\n DES_key_schedule sch;\n DES_key_schedule sch2;\n DES_key_schedule sch3;\n# endif\n# ifndef OPENSSL_NO_AES\n AES_KEY aes_ks1, aes_ks2, aes_ks3;\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n# endif\n# define D_MD2 0\n# define D_MDC2 1\n# define D_MD4 2\n# define D_MD5 3\n# define D_HMAC 4\n# define D_SHA1 5\n# define D_RMD160 6\n# define D_RC4 7\n# define D_CBC_DES 8\n# define D_EDE3_DES 9\n# define D_CBC_IDEA 10\n# define D_CBC_SEED 11\n# define D_CBC_RC2 12\n# define D_CBC_RC5 13\n# define D_CBC_BF 14\n# define D_CBC_CAST 15\n# define D_CBC_128_AES 16\n# define D_CBC_192_AES 17\n# define D_CBC_256_AES 18\n# define D_CBC_128_CML 19\n# define D_CBC_192_CML 20\n# define D_CBC_256_CML 21\n# define D_EVP 22\n# define D_SHA256 23\n# define D_SHA512 24\n# define D_WHIRLPOOL 25\n# define D_IGE_128_AES 26\n# define D_IGE_192_AES 27\n# define D_IGE_256_AES 28\n# define D_GHASH 29\n double d = 0.0;\n long c[ALGOR_NUM][SIZE_NUM];\n# ifndef OPENSSL_SYS_WIN32\n# endif\n# define R_DSA_512 0\n# define R_DSA_1024 1\n# define R_DSA_2048 2\n# define R_RSA_512 0\n# define R_RSA_1024 1\n# define R_RSA_2048 2\n# define R_RSA_3072 3\n# define R_RSA_4096 4\n# define R_RSA_7680 5\n# define R_RSA_15360 6\n# define R_EC_P160 0\n# define R_EC_P192 1\n# define R_EC_P224 2\n# define R_EC_P256 3\n# define R_EC_P384 4\n# define R_EC_P521 5\n# define R_EC_K163 6\n# define R_EC_K233 7\n# define R_EC_K283 8\n# define R_EC_K409 9\n# define R_EC_K571 10\n# define R_EC_B163 11\n# define R_EC_B233 12\n# define R_EC_B283 13\n# define R_EC_B409 14\n# define R_EC_B571 15\n# ifndef OPENSSL_NO_RSA\n RSA *rsa_key[RSA_NUM];\n long rsa_c[RSA_NUM][2];\n static unsigned int rsa_bits[RSA_NUM] = {\n 512, 1024, 2048, 3072, 4096, 7680, 15360\n };\n static unsigned char *rsa_data[RSA_NUM] = {\n test512, test1024, test2048, test3072, test4096, test7680, test15360\n };\n static int rsa_data_length[RSA_NUM] = {\n sizeof(test512), sizeof(test1024),\n sizeof(test2048), sizeof(test3072),\n sizeof(test4096), sizeof(test7680),\n sizeof(test15360)\n };\n# endif\n# ifndef OPENSSL_NO_DSA\n DSA *dsa_key[DSA_NUM];\n long dsa_c[DSA_NUM][2];\n static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };\n# endif\n# ifndef OPENSSL_NO_EC\n static unsigned int test_curves[EC_NUM] = {\n NID_secp160r1,\n NID_X9_62_prime192v1,\n NID_secp224r1,\n NID_X9_62_prime256v1,\n NID_secp384r1,\n NID_secp521r1,\n NID_sect163k1,\n NID_sect233k1,\n NID_sect283k1,\n NID_sect409k1,\n NID_sect571k1,\n NID_sect163r2,\n NID_sect233r1,\n NID_sect283r1,\n NID_sect409r1,\n NID_sect571r1\n };\n static const char *test_curves_names[EC_NUM] = {\n "secp160r1",\n "nistp192",\n "nistp224",\n "nistp256",\n "nistp384",\n "nistp521",\n "nistk163",\n "nistk233",\n "nistk283",\n "nistk409",\n "nistk571",\n "nistb163",\n "nistb233",\n "nistb283",\n "nistb409",\n "nistb571"\n };\n static int test_curves_bits[EC_NUM] = {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n# endif\n# ifndef OPENSSL_NO_ECDSA\n unsigned char ecdsasig[256];\n unsigned int ecdsasiglen;\n EC_KEY *ecdsa[EC_NUM];\n long ecdsa_c[EC_NUM][2];\n# endif\n# ifndef OPENSSL_NO_ECDH\n EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n int secret_size_a, secret_size_b;\n int ecdh_checks = 0;\n int secret_idx = 0;\n long ecdh_c[EC_NUM][2];\n# endif\n int rsa_doit[RSA_NUM];\n int dsa_doit[DSA_NUM];\n# ifndef OPENSSL_NO_ECDSA\n int ecdsa_doit[EC_NUM];\n# endif\n# ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n# endif\n int doit[ALGOR_NUM];\n int pr_header = 0;\n const EVP_CIPHER *evp_cipher = NULL;\n const EVP_MD *evp_md = NULL;\n int decrypt = 0;\n# ifndef NO_FORK\n int multi = 0;\n# endif\n int multiblock = 0;\n int misalign = MAX_MISALIGNMENT + 1;\n# ifndef TIMES\n usertime = -1;\n# endif\n apps_startup();\n memset(results, 0, sizeof(results));\n# ifndef OPENSSL_NO_DSA\n memset(dsa_key, 0, sizeof(dsa_key));\n# endif\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa[i] = NULL;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n ecdh_a[i] = NULL;\n ecdh_b[i] = NULL;\n }\n# endif\n if (bio_err == NULL)\n if ((bio_err = BIO_new(BIO_s_file())) != NULL)\n BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);\n if (!load_config(bio_err, NULL))\n goto end;\n# ifndef OPENSSL_NO_RSA\n memset(rsa_key, 0, sizeof(rsa_key));\n for (i = 0; i < RSA_NUM; i++)\n rsa_key[i] = NULL;\n# endif\n if ((buf_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n if ((buf2_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n misalign = 0;\n buf = buf_malloc;\n buf2 = buf2_malloc;\n memset(c, 0, sizeof(c));\n memset(DES_iv, 0, sizeof(DES_iv));\n memset(iv, 0, sizeof(iv));\n for (i = 0; i < ALGOR_NUM; i++)\n doit[i] = 0;\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 0;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 0;\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 0;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 0;\n# endif\n j = 0;\n argc--;\n argv++;\n while (argc) {\n if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {\n usertime = 0;\n j--;\n } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no EVP given\\n");\n goto end;\n }\n evp_cipher = EVP_get_cipherbyname(*argv);\n if (!evp_cipher) {\n evp_md = EVP_get_digestbyname(*argv);\n }\n if (!evp_cipher && !evp_md) {\n BIO_printf(bio_err, "%s is an unknown cipher or digest\\n",\n *argv);\n goto end;\n }\n doit[D_EVP] = 1;\n } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {\n decrypt = 1;\n j--;\n }\n# ifndef OPENSSL_NO_ENGINE\n else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no engine given\\n");\n goto end;\n }\n setup_engine(bio_err, *argv, 0);\n j--;\n }\n# endif\n# ifndef NO_FORK\n else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no multi count given\\n");\n goto end;\n }\n multi = atoi(argv[0]);\n if (multi <= 0) {\n BIO_printf(bio_err, "bad multi count\\n");\n goto end;\n }\n j--;\n }\n# endif\n else if (argc > 0 && !strcmp(*argv, "-mr")) {\n mr = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-mb")) {\n multiblock = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-misalign")) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no misalignment given\\n");\n goto end;\n }\n misalign = atoi(argv[0]);\n if (misalign < 0 || misalign > MAX_MISALIGNMENT) {\n BIO_printf(bio_err,\n "misalignment is outsize permitted range 0-%d\\n",\n MAX_MISALIGNMENT);\n goto end;\n }\n buf = buf_malloc + misalign;\n buf2 = buf2_malloc + misalign;\n j--;\n } else\n# ifndef OPENSSL_NO_MD2\n if (strcmp(*argv, "md2") == 0)\n doit[D_MD2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MDC2\n if (strcmp(*argv, "mdc2") == 0)\n doit[D_MDC2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD4\n if (strcmp(*argv, "md4") == 0)\n doit[D_MD4] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "md5") == 0)\n doit[D_MD5] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "hmac") == 0)\n doit[D_HMAC] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA\n if (strcmp(*argv, "sha1") == 0)\n doit[D_SHA1] = 1;\n else if (strcmp(*argv, "sha") == 0)\n doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;\n else\n# ifndef OPENSSL_NO_SHA256\n if (strcmp(*argv, "sha256") == 0)\n doit[D_SHA256] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (strcmp(*argv, "sha512") == 0)\n doit[D_SHA512] = 1;\n else\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n if (strcmp(*argv, "whirlpool") == 0)\n doit[D_WHIRLPOOL] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RMD160\n if (strcmp(*argv, "ripemd") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "rmd160") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "ripemd160") == 0)\n doit[D_RMD160] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RC4\n if (strcmp(*argv, "rc4") == 0)\n doit[D_RC4] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des-cbc") == 0)\n doit[D_CBC_DES] = 1;\n else if (strcmp(*argv, "des-ede3") == 0)\n doit[D_EDE3_DES] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes-128-cbc") == 0)\n doit[D_CBC_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-cbc") == 0)\n doit[D_CBC_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-cbc") == 0)\n doit[D_CBC_256_AES] = 1;\n else if (strcmp(*argv, "aes-128-ige") == 0)\n doit[D_IGE_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-ige") == 0)\n doit[D_IGE_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-ige") == 0)\n doit[D_IGE_256_AES] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia-128-cbc") == 0)\n doit[D_CBC_128_CML] = 1;\n else if (strcmp(*argv, "camellia-192-cbc") == 0)\n doit[D_CBC_192_CML] = 1;\n else if (strcmp(*argv, "camellia-256-cbc") == 0)\n doit[D_CBC_256_CML] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RSA\n# if 0\n if (strcmp(*argv, "rsaref") == 0) {\n RSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n j--;\n } else\n# endif\n# ifndef RSA_NULL\n if (strcmp(*argv, "openssl") == 0) {\n RSA_set_default_method(RSA_PKCS1_SSLeay());\n j--;\n } else\n# endif\n# endif\n if (strcmp(*argv, "dsa512") == 0)\n dsa_doit[R_DSA_512] = 2;\n else if (strcmp(*argv, "dsa1024") == 0)\n dsa_doit[R_DSA_1024] = 2;\n else if (strcmp(*argv, "dsa2048") == 0)\n dsa_doit[R_DSA_2048] = 2;\n else if (strcmp(*argv, "rsa512") == 0)\n rsa_doit[R_RSA_512] = 2;\n else if (strcmp(*argv, "rsa1024") == 0)\n rsa_doit[R_RSA_1024] = 2;\n else if (strcmp(*argv, "rsa2048") == 0)\n rsa_doit[R_RSA_2048] = 2;\n else if (strcmp(*argv, "rsa3072") == 0)\n rsa_doit[R_RSA_3072] = 2;\n else if (strcmp(*argv, "rsa4096") == 0)\n rsa_doit[R_RSA_4096] = 2;\n else if (strcmp(*argv, "rsa7680") == 0)\n rsa_doit[R_RSA_7680] = 2;\n else if (strcmp(*argv, "rsa15360") == 0)\n rsa_doit[R_RSA_15360] = 2;\n else\n# ifndef OPENSSL_NO_RC2\n if (strcmp(*argv, "rc2-cbc") == 0)\n doit[D_CBC_RC2] = 1;\n else if (strcmp(*argv, "rc2") == 0)\n doit[D_CBC_RC2] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_RC5\n if (strcmp(*argv, "rc5-cbc") == 0)\n doit[D_CBC_RC5] = 1;\n else if (strcmp(*argv, "rc5") == 0)\n doit[D_CBC_RC5] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_IDEA\n if (strcmp(*argv, "idea-cbc") == 0)\n doit[D_CBC_IDEA] = 1;\n else if (strcmp(*argv, "idea") == 0)\n doit[D_CBC_IDEA] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SEED\n if (strcmp(*argv, "seed-cbc") == 0)\n doit[D_CBC_SEED] = 1;\n else if (strcmp(*argv, "seed") == 0)\n doit[D_CBC_SEED] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_BF\n if (strcmp(*argv, "bf-cbc") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "blowfish") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "bf") == 0)\n doit[D_CBC_BF] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_CAST\n if (strcmp(*argv, "cast-cbc") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast5") == 0)\n doit[D_CBC_CAST] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des") == 0) {\n doit[D_CBC_DES] = 1;\n doit[D_EDE3_DES] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes") == 0) {\n doit[D_CBC_128_AES] = 1;\n doit[D_CBC_192_AES] = 1;\n doit[D_CBC_256_AES] = 1;\n } else if (strcmp(*argv, "ghash") == 0) {\n doit[D_GHASH] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia") == 0) {\n doit[D_CBC_128_CML] = 1;\n doit[D_CBC_192_CML] = 1;\n doit[D_CBC_256_CML] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_RSA\n if (strcmp(*argv, "rsa") == 0) {\n rsa_doit[R_RSA_512] = 1;\n rsa_doit[R_RSA_1024] = 1;\n rsa_doit[R_RSA_2048] = 1;\n rsa_doit[R_RSA_3072] = 1;\n rsa_doit[R_RSA_4096] = 1;\n rsa_doit[R_RSA_7680] = 1;\n rsa_doit[R_RSA_15360] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_DSA\n if (strcmp(*argv, "dsa") == 0) {\n dsa_doit[R_DSA_512] = 1;\n dsa_doit[R_DSA_1024] = 1;\n dsa_doit[R_DSA_2048] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_ECDSA\n if (strcmp(*argv, "ecdsap160") == 0)\n ecdsa_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdsap192") == 0)\n ecdsa_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdsap224") == 0)\n ecdsa_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdsap256") == 0)\n ecdsa_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdsap384") == 0)\n ecdsa_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdsap521") == 0)\n ecdsa_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdsak163") == 0)\n ecdsa_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdsak233") == 0)\n ecdsa_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdsak283") == 0)\n ecdsa_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdsak409") == 0)\n ecdsa_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdsak571") == 0)\n ecdsa_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdsab163") == 0)\n ecdsa_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdsab233") == 0)\n ecdsa_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdsab283") == 0)\n ecdsa_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdsab409") == 0)\n ecdsa_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdsab571") == 0)\n ecdsa_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdsa") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n } else\n# endif\n# ifndef OPENSSL_NO_ECDH\n if (strcmp(*argv, "ecdhp160") == 0)\n ecdh_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdhp192") == 0)\n ecdh_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdhp224") == 0)\n ecdh_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdhp256") == 0)\n ecdh_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdhp384") == 0)\n ecdh_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdhp521") == 0)\n ecdh_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdhk163") == 0)\n ecdh_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdhk233") == 0)\n ecdh_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdhk283") == 0)\n ecdh_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdhk409") == 0)\n ecdh_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdhk571") == 0)\n ecdh_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdhb163") == 0)\n ecdh_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdhb233") == 0)\n ecdh_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdhb283") == 0)\n ecdh_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdhb409") == 0)\n ecdh_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdhb571") == 0)\n ecdh_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdh") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n } else\n# endif\n {\n BIO_printf(bio_err, "Error: bad option or value\\n");\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available values:\\n");\n# ifndef OPENSSL_NO_MD2\n BIO_printf(bio_err, "md2 ");\n# endif\n# ifndef OPENSSL_NO_MDC2\n BIO_printf(bio_err, "mdc2 ");\n# endif\n# ifndef OPENSSL_NO_MD4\n BIO_printf(bio_err, "md4 ");\n# endif\n# ifndef OPENSSL_NO_MD5\n BIO_printf(bio_err, "md5 ");\n# ifndef OPENSSL_NO_HMAC\n BIO_printf(bio_err, "hmac ");\n# endif\n# endif\n# ifndef OPENSSL_NO_SHA1\n BIO_printf(bio_err, "sha1 ");\n# endif\n# ifndef OPENSSL_NO_SHA256\n BIO_printf(bio_err, "sha256 ");\n# endif\n# ifndef OPENSSL_NO_SHA512\n BIO_printf(bio_err, "sha512 ");\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n BIO_printf(bio_err, "whirlpool");\n# endif\n# ifndef OPENSSL_NO_RMD160\n BIO_printf(bio_err, "rmd160");\n# endif\n# if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \\\n !defined(OPENSSL_NO_WHIRLPOOL)\n BIO_printf(bio_err, "\\n");\n# endif\n# ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea-cbc ");\n# endif\n# ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC5\n BIO_printf(bio_err, "rc5-cbc ");\n# endif\n# ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "bf-cbc");\n# endif\n# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n BIO_printf(bio_err, "\\n");\n# endif\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des-cbc des-ede3 ");\n# endif\n# ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");\n BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err,\n "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n# endif\n# ifndef OPENSSL_NO_RC4\n BIO_printf(bio_err, "rc4");\n# endif\n BIO_printf(bio_err, "\\n");\n# ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err,\n "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\\n");\n BIO_printf(bio_err, "rsa7680 rsa15360\\n");\n# endif\n# ifndef OPENSSL_NO_DSA\n BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\\n");\n# endif\n# ifndef OPENSSL_NO_ECDSA\n BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "\n "ecdsap256 ecdsap384 ecdsap521\\n");\n BIO_printf(bio_err,\n "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n BIO_printf(bio_err,\n "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n BIO_printf(bio_err, "ecdsa\\n");\n# endif\n# ifndef OPENSSL_NO_ECDH\n BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "\n "ecdhp256 ecdhp384 ecdhp521\\n");\n BIO_printf(bio_err,\n "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n BIO_printf(bio_err,\n "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n BIO_printf(bio_err, "ecdh\\n");\n# endif\n# ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea ");\n# endif\n# ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed ");\n# endif\n# ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2 ");\n# endif\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des ");\n# endif\n# ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes ");\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "camellia ");\n# endif\n# ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err, "rsa ");\n# endif\n# ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "blowfish");\n# endif\n# if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \\\n !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \\\n !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \\\n !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)\n BIO_printf(bio_err, "\\n");\n# endif\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available options:\\n");\n# if defined(TIMES) || defined(USE_TOD)\n BIO_printf(bio_err, "-elapsed "\n "measure time in real time instead of CPU user time.\\n");\n# endif\n# ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n "-engine e "\n "use engine e, possibly a hardware device.\\n");\n# endif\n BIO_printf(bio_err, "-evp e " "use EVP e.\\n");\n BIO_printf(bio_err,\n "-decrypt "\n "time decryption instead of encryption (only EVP).\\n");\n BIO_printf(bio_err,\n "-mr "\n "produce machine readable output.\\n");\n BIO_printf(bio_err,\n "-mb "\n "perform multi-block benchmark (for specific ciphers)\\n");\n BIO_printf(bio_err,\n "-misalign n "\n "perform benchmark with misaligned data\\n");\n# ifndef NO_FORK\n BIO_printf(bio_err,\n "-multi n " "run n benchmarks in parallel.\\n");\n# endif\n goto end;\n }\n argc--;\n argv++;\n j++;\n }\n# ifndef NO_FORK\n if (multi && do_multi(multi))\n goto show_res;\n# endif\n if (j == 0) {\n for (i = 0; i < ALGOR_NUM; i++) {\n if (i != D_EVP)\n doit[i] = 1;\n }\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 1;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 1;\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n# endif\n }\n for (i = 0; i < ALGOR_NUM; i++)\n if (doit[i])\n pr_header++;\n if (usertime == 0 && !mr)\n BIO_printf(bio_err,\n "You have chosen to measure elapsed time "\n "instead of user CPU time.\\n");\n# ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++) {\n const unsigned char *p;\n p = rsa_data[i];\n rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);\n if (rsa_key[i] == NULL) {\n BIO_printf(bio_err, "internal error loading RSA key number %d\\n",\n i);\n goto end;\n }\n# if 0\n else {\n BIO_printf(bio_err,\n mr ? "+RK:%d:"\n : "Loaded RSA key, %d bit modulus and e= 0x",\n BN_num_bits(rsa_key[i]->n));\n BN_print(bio_err, rsa_key[i]->e);\n BIO_printf(bio_err, "\\n");\n }\n# endif\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_key[0] = get_dsa512();\n dsa_key[1] = get_dsa1024();\n dsa_key[2] = get_dsa2048();\n# endif\n# ifndef OPENSSL_NO_DES\n DES_set_key_unchecked(&key, &sch);\n DES_set_key_unchecked(&key2, &sch2);\n DES_set_key_unchecked(&key3, &sch3);\n# endif\n# ifndef OPENSSL_NO_AES\n AES_set_encrypt_key(key16, 128, &aes_ks1);\n AES_set_encrypt_key(key24, 192, &aes_ks2);\n AES_set_encrypt_key(key32, 256, &aes_ks3);\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n Camellia_set_key(key16, 128, &camellia_ks1);\n Camellia_set_key(ckey24, 192, &camellia_ks2);\n Camellia_set_key(ckey32, 256, &camellia_ks3);\n# endif\n# ifndef OPENSSL_NO_IDEA\n idea_set_encrypt_key(key16, &idea_ks);\n# endif\n# ifndef OPENSSL_NO_SEED\n SEED_set_key(key16, &seed_ks);\n# endif\n# ifndef OPENSSL_NO_RC4\n RC4_set_key(&rc4_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_RC2\n RC2_set_key(&rc2_ks, 16, key16, 128);\n# endif\n# ifndef OPENSSL_NO_RC5\n RC5_32_set_key(&rc5_ks, 16, key16, 12);\n# endif\n# ifndef OPENSSL_NO_BF\n BF_set_key(&bf_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_CAST\n CAST_set_key(&cast_ks, 16, key16);\n# endif\n# ifndef OPENSSL_NO_RSA\n memset(rsa_c, 0, sizeof(rsa_c));\n# endif\n# ifndef SIGALRM\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "First we calculate the approximate speed ...\\n");\n count = 10;\n do {\n long it;\n count *= 2;\n Time_F(START);\n for (it = count; it; it--)\n DES_ecb_encrypt((DES_cblock *)buf,\n (DES_cblock *)buf, &sch, DES_ENCRYPT);\n d = Time_F(STOP);\n } while (d < 3);\n save_count = count;\n c[D_MD2][0] = count / 10;\n c[D_MDC2][0] = count / 10;\n c[D_MD4][0] = count;\n c[D_MD5][0] = count;\n c[D_HMAC][0] = count;\n c[D_SHA1][0] = count;\n c[D_RMD160][0] = count;\n c[D_RC4][0] = count * 5;\n c[D_CBC_DES][0] = count;\n c[D_EDE3_DES][0] = count / 3;\n c[D_CBC_IDEA][0] = count;\n c[D_CBC_SEED][0] = count;\n c[D_CBC_RC2][0] = count;\n c[D_CBC_RC5][0] = count;\n c[D_CBC_BF][0] = count;\n c[D_CBC_CAST][0] = count;\n c[D_CBC_128_AES][0] = count;\n c[D_CBC_192_AES][0] = count;\n c[D_CBC_256_AES][0] = count;\n c[D_CBC_128_CML][0] = count;\n c[D_CBC_192_CML][0] = count;\n c[D_CBC_256_CML][0] = count;\n c[D_SHA256][0] = count;\n c[D_SHA512][0] = count;\n c[D_WHIRLPOOL][0] = count;\n c[D_IGE_128_AES][0] = count;\n c[D_IGE_192_AES][0] = count;\n c[D_IGE_256_AES][0] = count;\n c[D_GHASH][0] = count;\n for (i = 1; i < SIZE_NUM; i++) {\n long l0, l1;\n l0 = (long)lengths[0];\n l1 = (long)lengths[i];\n c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;\n c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;\n c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;\n c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;\n c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;\n c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;\n c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;\n c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;\n c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;\n c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;\n l0 = (long)lengths[i - 1];\n c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;\n c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;\n c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;\n c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;\n c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;\n c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;\n c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;\n c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;\n c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;\n c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;\n c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;\n c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;\n c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;\n c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;\n c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;\n c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;\n c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;\n c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;\n }\n# ifndef OPENSSL_NO_RSA\n rsa_c[R_RSA_512][0] = count / 2000;\n rsa_c[R_RSA_512][1] = count / 400;\n for (i = 1; i < RSA_NUM; i++) {\n rsa_c[i][0] = rsa_c[i - 1][0] / 8;\n rsa_c[i][1] = rsa_c[i - 1][1] / 4;\n if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n rsa_doit[i] = 0;\n else {\n if (rsa_c[i][0] == 0) {\n rsa_c[i][0] = 1;\n rsa_c[i][1] = 20;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_c[R_DSA_512][0] = count / 1000;\n dsa_c[R_DSA_512][1] = count / 1000 / 2;\n for (i = 1; i < DSA_NUM; i++) {\n dsa_c[i][0] = dsa_c[i - 1][0] / 4;\n dsa_c[i][1] = dsa_c[i - 1][1] / 4;\n if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n dsa_doit[i] = 0;\n else {\n if (dsa_c[i] == 0) {\n dsa_c[i][0] = 1;\n dsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n ecdsa_c[R_EC_P160][0] = count / 1000;\n ecdsa_c[R_EC_P160][1] = count / 1000 / 2;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_K163][0] = count / 1000;\n ecdsa_c[R_EC_K163][1] = count / 1000 / 2;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_B163][0] = count / 1000;\n ecdsa_c[R_EC_B163][1] = count / 1000 / 2;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n ecdh_c[R_EC_P160][0] = count / 1000;\n ecdh_c[R_EC_P160][1] = count / 1000;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_K163][0] = count / 1000;\n ecdh_c[R_EC_K163][1] = count / 1000;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_B163][0] = count / 1000;\n ecdh_c[R_EC_B163][1] = count / 1000;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n# endif\n# define COND(d) (count < (d))\n# define COUNT(d) (d)\n# else\n# error "You cannot disable DES on systems without SIGALRM."\n# endif\n# else\n# define COND(c) (run && count<0x7fffffff)\n# define COUNT(d) (count)\n# ifndef _WIN32\n signal(SIGALRM, sig_done);\n# endif\n# endif\n# ifndef OPENSSL_NO_MD2\n if (doit[D_MD2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD2], c[D_MD2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,\n EVP_md2(), NULL);\n d = Time_F(STOP);\n print_result(D_MD2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MDC2\n if (doit[D_MDC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,\n EVP_mdc2(), NULL);\n d = Time_F(STOP);\n print_result(D_MDC2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MD4\n if (doit[D_MD4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD4], c[D_MD4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD4][j]); count++)\n EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),\n NULL, EVP_md4(), NULL);\n d = Time_F(STOP);\n print_result(D_MD4, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_MD5\n if (doit[D_MD5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD5], c[D_MD5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD5][j]); count++)\n MD5(buf, lengths[j], md5);\n d = Time_F(STOP);\n print_result(D_MD5, j, count, d);\n }\n }\n# endif\n# if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n if (doit[D_HMAC]) {\n HMAC_CTX hctx;\n HMAC_CTX_init(&hctx);\n HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",\n 16, EVP_md5(), NULL);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {\n HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);\n HMAC_Update(&hctx, buf, lengths[j]);\n HMAC_Final(&hctx, &(hmac[0]), NULL);\n }\n d = Time_F(STOP);\n print_result(D_HMAC, j, count, d);\n }\n HMAC_CTX_cleanup(&hctx);\n }\n# endif\n# ifndef OPENSSL_NO_SHA\n if (doit[D_SHA1]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)\n# if 0\n EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,\n EVP_sha1(), NULL);\n# else\n SHA1(buf, lengths[j], sha);\n# endif\n d = Time_F(STOP);\n print_result(D_SHA1, j, count, d);\n }\n }\n# ifndef OPENSSL_NO_SHA256\n if (doit[D_SHA256]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)\n SHA256(buf, lengths[j], sha256);\n d = Time_F(STOP);\n print_result(D_SHA256, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (doit[D_SHA512]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)\n SHA512(buf, lengths[j], sha512);\n d = Time_F(STOP);\n print_result(D_SHA512, j, count, d);\n }\n }\n# endif\n# endif\n# ifndef OPENSSL_NO_WHIRLPOOL\n if (doit[D_WHIRLPOOL]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)\n WHIRLPOOL(buf, lengths[j], whirlpool);\n d = Time_F(STOP);\n print_result(D_WHIRLPOOL, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RMD160\n if (doit[D_RMD160]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,\n EVP_ripemd160(), NULL);\n d = Time_F(STOP);\n print_result(D_RMD160, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC4\n if (doit[D_RC4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RC4], c[D_RC4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RC4][j]); count++)\n RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);\n d = Time_F(STOP);\n print_result(D_RC4, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_DES\n if (doit[D_CBC_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)\n DES_ncbc_encrypt(buf, buf, lengths[j], &sch,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_DES, j, count, d);\n }\n }\n if (doit[D_EDE3_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)\n DES_ede3_cbc_encrypt(buf, buf, lengths[j],\n &sch, &sch2, &sch3,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_EDE3_DES, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_AES\n if (doit[D_CBC_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_AES, j, count, d);\n }\n }\n if (doit[D_CBC_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_AES, j, count, d);\n }\n }\n if (doit[D_CBC_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_AES, j, count, d);\n }\n }\n if (doit[D_IGE_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_128_AES, j, count, d);\n }\n }\n if (doit[D_IGE_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_192_AES, j, count, d);\n }\n }\n if (doit[D_IGE_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_256_AES, j, count, d);\n }\n }\n if (doit[D_GHASH]) {\n GCM128_CONTEXT *ctx =\n CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);\n CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)\n CRYPTO_gcm128_aad(ctx, buf, lengths[j]);\n d = Time_F(STOP);\n print_result(D_GHASH, j, count, d);\n }\n CRYPTO_gcm128_release(ctx);\n }\n# endif\n# ifndef OPENSSL_NO_CAMELLIA\n if (doit[D_CBC_128_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks1,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_CML, j, count, d);\n }\n }\n if (doit[D_CBC_192_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks2,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_CML, j, count, d);\n }\n }\n if (doit[D_CBC_256_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks3,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_CML, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_IDEA\n if (doit[D_CBC_IDEA]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)\n idea_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &idea_ks,\n iv, IDEA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_IDEA, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SEED\n if (doit[D_CBC_SEED]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)\n SEED_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &seed_ks, iv, 1);\n d = Time_F(STOP);\n print_result(D_CBC_SEED, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC2\n if (doit[D_CBC_RC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)\n RC2_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc2_ks,\n iv, RC2_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC2, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_RC5\n if (doit[D_CBC_RC5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)\n RC5_32_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc5_ks,\n iv, RC5_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC5, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_BF\n if (doit[D_CBC_BF]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)\n BF_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &bf_ks,\n iv, BF_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_BF, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_CAST\n if (doit[D_CBC_CAST]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)\n CAST_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &cast_ks,\n iv, CAST_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_CAST, j, count, d);\n }\n }\n# endif\n if (doit[D_EVP]) {\n# ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n if (multiblock && evp_cipher) {\n if (!\n (EVP_CIPHER_flags(evp_cipher) &\n EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {\n fprintf(stderr, "%s is not multi-block capable\\n",\n OBJ_nid2ln(evp_cipher->nid));\n goto end;\n }\n multiblock_speed(evp_cipher);\n mret = 0;\n goto end;\n }\n# endif\n for (j = 0; j < SIZE_NUM; j++) {\n if (evp_cipher) {\n EVP_CIPHER_CTX ctx;\n int outl;\n names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);\n print_message(names[D_EVP], save_count, lengths[j]);\n EVP_CIPHER_CTX_init(&ctx);\n if (decrypt)\n EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n else\n EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n EVP_CIPHER_CTX_set_padding(&ctx, 0);\n Time_F(START);\n if (decrypt)\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n else\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n if (decrypt)\n EVP_DecryptFinal_ex(&ctx, buf, &outl);\n else\n EVP_EncryptFinal_ex(&ctx, buf, &outl);\n d = Time_F(STOP);\n EVP_CIPHER_CTX_cleanup(&ctx);\n }\n if (evp_md) {\n names[D_EVP] = OBJ_nid2ln(evp_md->type);\n print_message(names[D_EVP], save_count, lengths[j]);\n Time_F(START);\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]); count++)\n EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);\n d = Time_F(STOP);\n }\n print_result(D_EVP, j, count, d);\n }\n }\n# ifndef OPENSSL_SYS_WIN32\n# endif\n RAND_pseudo_bytes(buf, 36);\n# ifndef OPENSSL_NO_RSA\n for (j = 0; j < RSA_NUM; j++) {\n int ret;\n if (!rsa_doit[j])\n continue;\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "RSA sign failure. No RSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("private", "rsa",\n rsa_c[j][0], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,\n &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "RSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R1:%ld:%d:%.2f\\n"\n : "%ld %d bit private RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n# if 1\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "RSA verify failure. No RSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_doit[j] = 0;\n } else {\n pkey_print_message("public", "rsa",\n rsa_c[j][1], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,\n rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "RSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R2:%ld:%d:%.2f\\n"\n : "%ld %d bit public RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][1] = d / (double)count;\n }\n# endif\n if (rsa_count <= 1) {\n for (j++; j < RSA_NUM; j++)\n rsa_doit[j] = 0;\n }\n }\n# endif\n RAND_pseudo_bytes(buf, 20);\n# ifndef OPENSSL_NO_DSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < DSA_NUM; j++) {\n unsigned int kk;\n int ret;\n if (!dsa_doit[j])\n continue;\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "DSA sign failure. No DSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "dsa",\n dsa_c[j][0], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "DSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R3:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA signs in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "DSA verify failure. No DSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n dsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "dsa",\n dsa_c[j][1], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "DSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R4:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA verify in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < DSA_NUM; j++)\n dsa_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef OPENSSL_NO_ECDSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n int ret;\n if (!ecdsa_doit[j])\n continue;\n ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if (ecdsa[j] == NULL) {\n BIO_printf(bio_err, "ECDSA failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n# if 1\n EC_KEY_precompute_mult(ecdsa[j], NULL);\n# endif\n EC_KEY_generate_key(ecdsa[j]);\n ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "ECDSA sign failure. No ECDSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "ecdsa",\n ecdsa_c[j][0],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {\n ret = ECDSA_sign(0, buf, 20,\n ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "ECDSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R5:%ld:%d:%.2f\\n" :\n "%ld %d bit ECDSA signs in %.2fs \\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err,\n "ECDSA verify failure. No ECDSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n ecdsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "ecdsa",\n ecdsa_c[j][1],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {\n ret =\n ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,\n ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err, "ECDSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R6:%ld:%d:%.2f\\n"\n : "%ld %d bit ECDSA verify in %.2fs\\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdsa_doit[j] = 0;\n }\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef OPENSSL_NO_ECDH\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n if (!ecdh_doit[j])\n continue;\n ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {\n BIO_printf(bio_err, "ECDH failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n if (!EC_KEY_generate_key(ecdh_a[j]) ||\n !EC_KEY_generate_key(ecdh_b[j])) {\n BIO_printf(bio_err, "ECDH key generation failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n int field_size, outlen;\n void *(*kdf) (const void *in, size_t inlen, void *out,\n size_t *xoutlen);\n field_size =\n EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n if (field_size <= 24 * 8) {\n outlen = KDF1_SHA1_len;\n kdf = KDF1_SHA1;\n } else {\n outlen = (field_size + 7) / 8;\n kdf = NULL;\n }\n secret_size_a =\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n secret_size_b =\n ECDH_compute_key(secret_b, outlen,\n EC_KEY_get0_public_key(ecdh_a[j]),\n ecdh_b[j], kdf);\n if (secret_size_a != secret_size_b)\n ecdh_checks = 0;\n else\n ecdh_checks = 1;\n for (secret_idx = 0; (secret_idx < secret_size_a)\n && (ecdh_checks == 1); secret_idx++) {\n if (secret_a[secret_idx] != secret_b[secret_idx])\n ecdh_checks = 0;\n }\n if (ecdh_checks == 0) {\n BIO_printf(bio_err, "ECDH computations don\'t match.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n }\n pkey_print_message("", "ecdh",\n ecdh_c[j][0],\n test_curves_bits[j], ECDH_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R7:%ld:%d:%.2f\\n" :\n "%ld %d-bit ECDH ops in %.2fs\\n", count,\n test_curves_bits[j], d);\n ecdh_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdh_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n# endif\n# ifndef NO_FORK\n show_res:\n# endif\n if (!mr) {\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_BUILT_ON));\n printf("options:");\n printf("%s ", BN_options());\n# ifndef OPENSSL_NO_MD2\n printf("%s ", MD2_options());\n# endif\n# ifndef OPENSSL_NO_RC4\n printf("%s ", RC4_options());\n# endif\n# ifndef OPENSSL_NO_DES\n printf("%s ", DES_options());\n# endif\n# ifndef OPENSSL_NO_AES\n printf("%s ", AES_options());\n# endif\n# ifndef OPENSSL_NO_IDEA\n printf("%s ", idea_options());\n# endif\n# ifndef OPENSSL_NO_BF\n printf("%s ", BF_options());\n# endif\n fprintf(stdout, "\\n%s\\n", SSLeay_version(SSLEAY_CFLAGS));\n }\n if (pr_header) {\n if (mr)\n fprintf(stdout, "+H");\n else {\n fprintf(stdout,\n "The \'numbers\' are in 1000s of bytes per second processed.\\n");\n fprintf(stdout, "type ");\n }\n for (j = 0; j < SIZE_NUM; j++)\n fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);\n fprintf(stdout, "\\n");\n }\n for (k = 0; k < ALGOR_NUM; k++) {\n if (!doit[k])\n continue;\n if (mr)\n fprintf(stdout, "+F:%d:%s", k, names[k]);\n else\n fprintf(stdout, "%-13s", names[k]);\n for (j = 0; j < SIZE_NUM; j++) {\n if (results[k][j] > 10000 && !mr)\n fprintf(stdout, " %11.2fk", results[k][j] / 1e3);\n else\n fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);\n }\n fprintf(stdout, "\\n");\n }\n# ifndef OPENSSL_NO_RSA\n j = 1;\n for (k = 0; k < RSA_NUM; k++) {\n if (!rsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F2:%u:%u:%f:%f\\n",\n k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);\n else\n fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n rsa_bits[k], rsa_results[k][0], rsa_results[k][1],\n 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n j = 1;\n for (k = 0; k < DSA_NUM; k++) {\n if (!dsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F3:%u:%u:%f:%f\\n",\n k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);\n else\n fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n dsa_bits[k], dsa_results[k][0], dsa_results[k][1],\n 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%30ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F4:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdsa_results[k][0], ecdsa_results[k][1]);\n else\n fprintf(stdout,\n "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdsa_results[k][0], ecdsa_results[k][1],\n 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdh_doit[k])\n continue;\n if (j && !mr) {\n printf("%30sop op/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F5:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n else\n fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n }\n# endif\n mret = 0;\n end:\n ERR_print_errors(bio_err);\n if (buf_malloc != NULL)\n OPENSSL_free(buf_malloc);\n if (buf2_malloc != NULL)\n OPENSSL_free(buf2_malloc);\n# ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++)\n if (rsa_key[i] != NULL)\n RSA_free(rsa_key[i]);\n# endif\n# ifndef OPENSSL_NO_DSA\n for (i = 0; i < DSA_NUM; i++)\n if (dsa_key[i] != NULL)\n DSA_free(dsa_key[i]);\n# endif\n# ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n if (ecdsa[i] != NULL)\n EC_KEY_free(ecdsa[i]);\n# endif\n# ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n if (ecdh_a[i] != NULL)\n EC_KEY_free(ecdh_a[i]);\n if (ecdh_b[i] != NULL)\n EC_KEY_free(ecdh_b[i]);\n }\n# endif\n apps_shutdown();\n OPENSSL_EXIT(mret);\n}']
|
1,612
| 0
|
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/asn1/asn1_lib.c/#L198
|
void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
int xclass)
{
unsigned char *p= *pp;
int i;
i=(constructed)?V_ASN1_CONSTRUCTED:0;
i|=(xclass&V_ASN1_PRIVATE);
if (tag < 31)
*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
else
{
*(p++)=i|V_ASN1_PRIMITIVE_TAG;
while (tag > 0x7f)
{
*(p++)=(tag&0x7f)|0x80;
tag>>=7;
}
*(p++)=(tag&0x7f);
}
if ((constructed == 2) && (length == 0))
*(p++)=0x80;
else
asn1_put_length(&p,length);
*pp=p;
}
|
['PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey)\n{\n\tPKCS8_PRIV_KEY_INFO *p8;\n#ifndef NO_DSA\n\tASN1_INTEGER *dpkey;\n\tunsigned char *p, *q;\n\tint len;\n#endif\n\tif (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {\n\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tASN1_INTEGER_set (p8->version, 0);\n\tif (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {\n\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\treturn NULL;\n\t}\n\tswitch (EVP_PKEY_type(pkey->type)) {\n#ifndef NO_RSA\n\t\tcase EVP_PKEY_RSA:\n\t\tp8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);\n\t\tp8->pkeyalg->parameter->type = V_ASN1_NULL;\n\t\tif (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,\n\t\t\t\t\t &p8->pkey->value.octet_string)) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tbreak;\n#endif\n#ifndef NO_DSA\n\t\tcase EVP_PKEY_DSA:\n\t\tp8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);\n\t\tlen = i2d_DSAparams (pkey->pkey.dsa, NULL);\n\t\tif (!(p = Malloc(len))) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tq = p;\n\t\ti2d_DSAparams (pkey->pkey.dsa, &q);\n\t\tp8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;\n\t\tp8->pkeyalg->parameter->value.sequence = ASN1_STRING_new();\n\t\tASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, len);\n\t\tFree(p);\n\t\tif (!(dpkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (!ASN1_pack_string((char *)dpkey, i2d_ASN1_INTEGER,\n\t\t\t\t\t &p8->pkey->value.octet_string)) {\n\t\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);\n\t\t\tASN1_INTEGER_free (dpkey);\n\t\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\t\treturn NULL;\n\t\t}\n\t\tASN1_INTEGER_free (dpkey);\n\t\tbreak;\n#endif\n\t\tdefault:\n\t\tEVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);\n\t\tPKCS8_PRIV_KEY_INFO_free (p8);\n\t\treturn NULL;\n\t}\n\tp8->pkey->type = V_ASN1_OCTET_STRING;\n\tRAND_seed (p8->pkey->value.octet_string->data,\n\t\t\t\t\t p8->pkey->value.octet_string->length);\n\treturn p8;\n}', 'int i2d_DSAparams(DSA *a, unsigned char **pp)\n\t{\n\tBIGNUM *num[3];\n\tASN1_INTEGER bs;\n\tunsigned int j,i,tot=0,len,max=0;\n\tint t,ret= -1;\n\tunsigned char *p;\n\tif (a == NULL) return(0);\n\tnum[0]=a->p;\n\tnum[1]=a->q;\n\tnum[2]=a->g;\n\tfor (i=0; i<3; i++)\n\t\t{\n\t\tif (num[i] == NULL) continue;\n\t\tj=BN_num_bits(num[i]);\n\t\tlen=((j == 0)?0:((j/8)+1));\n\t\tif (len > max) max=len;\n\t\tlen=ASN1_object_size(0,len,\n\t\t\t(num[i]->neg)?V_ASN1_NEG_INTEGER:V_ASN1_INTEGER);\n\t\ttot+=len;\n\t\t}\n\tt=ASN1_object_size(1,tot,V_ASN1_SEQUENCE);\n\tif (pp == NULL) return(t);\n\tp= *pp;\n\tASN1_put_object(&p,1,tot,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);\n\tbs.type=V_ASN1_INTEGER;\n\tbs.data=(unsigned char *)Malloc(max+4);\n\tif (bs.data == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_I2D_DSAPARAMS,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tfor (i=0; i<3; i++)\n\t\t{\n\t\tif (num[i] == NULL) continue;\n\t\tbs.length=BN_bn2bin(num[i],bs.data);\n\t\ti2d_ASN1_INTEGER(&bs,&p);\n\t\t}\n\tFree((char *)bs.data);\n\tret=t;\nerr:\n\t*pp=p;\n\treturn(ret);\n\t}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMITIVE_TAG;\n\t\twhile (tag > 0x7f)\n\t\t\t{\n\t\t\t*(p++)=(tag&0x7f)|0x80;\n\t\t\ttag>>=7;\n\t\t\t}\n\t\t*(p++)=(tag&0x7f);\n\t\t}\n\tif ((constructed == 2) && (length == 0))\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}']
|
1,613
| 0
|
https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L139
|
static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
}
|
['static int decode_channel_code_tab(BitstreamContext *bc, Atrac3pChanUnitCtx *ctx,\n int ch_num, AVCodecContext *avctx)\n{\n int i, num_vals, num_bits, pred;\n int mask = ctx->use_full_table ? 7 : 3;\n VLC *vlc_tab, *delta_vlc;\n Atrac3pChanParams *chan = &ctx->channels[ch_num];\n Atrac3pChanParams *ref_chan = &ctx->channels[0];\n chan->table_type = bitstream_read_bit(bc);\n switch (bitstream_read(bc, 2)) {\n case 0:\n num_bits = ctx->use_full_table + 2;\n DEC_CT_IDX_COMMON(CODING_DIRECT);\n break;\n case 1:\n vlc_tab = ctx->use_full_table ? &ct_vlc_tabs[1]\n : ct_vlc_tabs;\n DEC_CT_IDX_COMMON(CODING_VLC);\n break;\n case 2:\n if (ctx->use_full_table) {\n vlc_tab = &ct_vlc_tabs[1];\n delta_vlc = &ct_vlc_tabs[2];\n } else {\n vlc_tab = ct_vlc_tabs;\n delta_vlc = ct_vlc_tabs;\n }\n pred = 0;\n DEC_CT_IDX_COMMON(CODING_VLC_DELTA);\n break;\n case 3:\n if (ch_num) {\n vlc_tab = ctx->use_full_table ? &ct_vlc_tabs[3]\n : ct_vlc_tabs;\n DEC_CT_IDX_COMMON(CODING_VLC_DIFF);\n }\n break;\n }\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
1,614
| 0
|
https://github.com/libav/libav/blob/df84d7d9bdf6b8e6896c711880f130b72738c828/libavcodec/mpegaudiodec.c/#L885
|
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT])
{
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
int j, offset;
OUT_INT *samples2;
#if FRAC_BITS <= 15
int32_t tmp[32];
int sum, sum2;
#else
int64_t sum, sum2;
#endif
offset = *synth_buf_offset;
synth_buf = synth_buf_ptr + offset;
#if FRAC_BITS <= 15
dct32(tmp, sb_samples);
for(j=0;j<32;j++) {
synth_buf[j] = av_clip_int16(tmp[j]);
}
#else
dct32(synth_buf, sb_samples);
#endif
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
offset = (offset - 32) & 511;
*synth_buf_offset = offset;
}
|
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n int32_t sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}']
|
1,615
| 0
|
https://github.com/openssl/openssl/blob/cfd3bb1785581def14fe8851906887d167b2f0f3/crypto/bio/b_print.c/#L629
|
static void
fmtfp(
char **sbuffer,
char **buffer,
size_t *currlen,
size_t *maxlen,
LDOUBLE fvalue,
int min,
int max,
int flags)
{
int signvalue = 0;
LDOUBLE ufvalue;
char iconvert[20];
char fconvert[20];
int iplace = 0;
int fplace = 0;
int padlen = 0;
int zpadlen = 0;
int caps = 0;
long intpart;
long fracpart;
if (max < 0)
max = 6;
ufvalue = abs_val(fvalue);
if (fvalue < 0)
signvalue = '-';
else if (flags & DP_F_PLUS)
signvalue = '+';
else if (flags & DP_F_SPACE)
signvalue = ' ';
intpart = (long)ufvalue;
if (max > 9)
max = 9;
fracpart = round((pow10(max)) * (ufvalue - intpart));
if (fracpart >= pow10(max)) {
intpart++;
fracpart -= (long)pow10(max);
}
do {
iconvert[iplace++] =
(caps ? "0123456789ABCDEF"
: "0123456789abcdef")[intpart % 10];
intpart = (intpart / 10);
} while (intpart && (iplace < 20));
if (iplace == 20)
iplace--;
iconvert[iplace] = 0;
do {
fconvert[fplace++] =
(caps ? "0123456789ABCDEF"
: "0123456789abcdef")[fracpart % 10];
fracpart = (fracpart / 10);
} while (fracpart && (fplace < 20));
if (fplace == 20)
fplace--;
fconvert[fplace] = 0;
padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
zpadlen = max - fplace;
if (zpadlen < 0)
zpadlen = 0;
if (padlen < 0)
padlen = 0;
if (flags & DP_F_MINUS)
padlen = -padlen;
if ((flags & DP_F_ZERO) && (padlen > 0)) {
if (signvalue) {
doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
--padlen;
signvalue = 0;
}
while (padlen > 0) {
doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
--padlen;
}
}
while (padlen > 0) {
doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
--padlen;
}
if (signvalue)
doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
while (iplace > 0)
doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
if (max > 0) {
doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
while (fplace > 0)
doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
}
while (zpadlen > 0) {
doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
--zpadlen;
}
while (padlen < 0) {
doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
++padlen;
}
}
|
['static void\nfmtfp(\n char **sbuffer,\n char **buffer,\n size_t *currlen,\n size_t *maxlen,\n LDOUBLE fvalue,\n int min,\n int max,\n int flags)\n{\n int signvalue = 0;\n LDOUBLE ufvalue;\n char iconvert[20];\n char fconvert[20];\n int iplace = 0;\n int fplace = 0;\n int padlen = 0;\n int zpadlen = 0;\n int caps = 0;\n long intpart;\n long fracpart;\n if (max < 0)\n max = 6;\n ufvalue = abs_val(fvalue);\n if (fvalue < 0)\n signvalue = \'-\';\n else if (flags & DP_F_PLUS)\n signvalue = \'+\';\n else if (flags & DP_F_SPACE)\n signvalue = \' \';\n intpart = (long)ufvalue;\n if (max > 9)\n max = 9;\n fracpart = round((pow10(max)) * (ufvalue - intpart));\n if (fracpart >= pow10(max)) {\n intpart++;\n fracpart -= (long)pow10(max);\n }\n do {\n iconvert[iplace++] =\n (caps ? "0123456789ABCDEF"\n : "0123456789abcdef")[intpart % 10];\n intpart = (intpart / 10);\n } while (intpart && (iplace < 20));\n if (iplace == 20)\n iplace--;\n iconvert[iplace] = 0;\n do {\n fconvert[fplace++] =\n (caps ? "0123456789ABCDEF"\n : "0123456789abcdef")[fracpart % 10];\n fracpart = (fracpart / 10);\n } while (fracpart && (fplace < 20));\n if (fplace == 20)\n fplace--;\n fconvert[fplace] = 0;\n padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);\n zpadlen = max - fplace;\n if (zpadlen < 0)\n zpadlen = 0;\n if (padlen < 0)\n padlen = 0;\n if (flags & DP_F_MINUS)\n padlen = -padlen;\n if ((flags & DP_F_ZERO) && (padlen > 0)) {\n if (signvalue) {\n doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n --padlen;\n signvalue = 0;\n }\n while (padlen > 0) {\n doapr_outch(sbuffer, buffer, currlen, maxlen, \'0\');\n --padlen;\n }\n }\n while (padlen > 0) {\n doapr_outch(sbuffer, buffer, currlen, maxlen, \' \');\n --padlen;\n }\n if (signvalue)\n doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);\n while (iplace > 0)\n doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);\n if (max > 0) {\n doapr_outch(sbuffer, buffer, currlen, maxlen, \'.\');\n while (fplace > 0)\n doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);\n }\n while (zpadlen > 0) {\n doapr_outch(sbuffer, buffer, currlen, maxlen, \'0\');\n --zpadlen;\n }\n while (padlen < 0) {\n doapr_outch(sbuffer, buffer, currlen, maxlen, \' \');\n ++padlen;\n }\n}', 'static LDOUBLE\nabs_val(LDOUBLE value)\n{\n LDOUBLE result = value;\n if (value < 0)\n result = -value;\n return result;\n}']
|
1,616
| 0
|
https://github.com/openssl/openssl/blob/6438632420cee9821409221ef6717edc5ee408c1/ssl/statem/statem_clnt.c/#L2198
|
static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)
{
#ifndef OPENSSL_NO_RSA
unsigned char *encdata = NULL;
EVP_PKEY *pkey = NULL;
EVP_PKEY_CTX *pctx = NULL;
size_t enclen;
unsigned char *pms = NULL;
size_t pmslen = 0;
if (s->session->peer == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
return 0;
}
pkey = X509_get0_pubkey(s->session->peer);
if (EVP_PKEY_get0_RSA(pkey) == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
return 0;
}
pmslen = SSL_MAX_MASTER_KEY_LENGTH;
pms = OPENSSL_malloc(pmslen);
if (pms == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);
*al = SSL_AD_INTERNAL_ERROR;
return 0;
}
pms[0] = s->client_version >> 8;
pms[1] = s->client_version & 0xff;
if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {
goto err;
}
if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
goto err;
}
pctx = EVP_PKEY_CTX_new(pkey, NULL);
if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0
|| EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);
goto err;
}
if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)
|| EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);
goto err;
}
EVP_PKEY_CTX_free(pctx);
pctx = NULL;
# ifdef PKCS1_CHECK
if (s->options & SSL_OP_PKCS1_CHECK_1)
(*p)[1]++;
if (s->options & SSL_OP_PKCS1_CHECK_2)
tmp_buf[0] = 0x70;
# endif
if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
goto err;
}
s->s3->tmp.pms = pms;
s->s3->tmp.pmslen = pmslen;
return 1;
err:
OPENSSL_clear_free(pms, pmslen);
EVP_PKEY_CTX_free(pctx);
return 0;
#else
SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);
*al = SSL_AD_INTERNAL_ERROR;
return 0;
#endif
}
|
['static int tls_construct_cke_rsa(SSL *s, WPACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char *encdata = NULL;\n EVP_PKEY *pkey = NULL;\n EVP_PKEY_CTX *pctx = NULL;\n size_t enclen;\n unsigned char *pms = NULL;\n size_t pmslen = 0;\n if (s->session->peer == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pkey = X509_get0_pubkey(s->session->peer);\n if (EVP_PKEY_get0_RSA(pkey) == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n pmslen = SSL_MAX_MASTER_KEY_LENGTH;\n pms = OPENSSL_malloc(pmslen);\n if (pms == NULL) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_MALLOC_FAILURE);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n }\n pms[0] = s->client_version >> 8;\n pms[1] = s->client_version & 0xff;\n if (RAND_bytes(pms + 2, (int)(pmslen - 2)) <= 0) {\n goto err;\n }\n if (s->version > SSL3_VERSION && !WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n pctx = EVP_PKEY_CTX_new(pkey, NULL);\n if (pctx == NULL || EVP_PKEY_encrypt_init(pctx) <= 0\n || EVP_PKEY_encrypt(pctx, NULL, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_EVP_LIB);\n goto err;\n }\n if (!WPACKET_allocate_bytes(pkt, enclen, &encdata)\n || EVP_PKEY_encrypt(pctx, encdata, &enclen, pms, pmslen) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, SSL_R_BAD_RSA_ENCRYPT);\n goto err;\n }\n EVP_PKEY_CTX_free(pctx);\n pctx = NULL;\n# ifdef PKCS1_CHECK\n if (s->options & SSL_OP_PKCS1_CHECK_1)\n (*p)[1]++;\n if (s->options & SSL_OP_PKCS1_CHECK_2)\n tmp_buf[0] = 0x70;\n# endif\n if (s->version > SSL3_VERSION && !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n s->s3->tmp.pms = pms;\n s->s3->tmp.pmslen = pmslen;\n return 1;\n err:\n OPENSSL_clear_free(pms, pmslen);\n EVP_PKEY_CTX_free(pctx);\n return 0;\n#else\n SSLerr(SSL_F_TLS_CONSTRUCT_CKE_RSA, ERR_R_INTERNAL_ERROR);\n *al = SSL_AD_INTERNAL_ERROR;\n return 0;\n#endif\n}', 'EVP_PKEY *X509_get0_pubkey(const X509 *x)\n{\n if (x == NULL)\n return NULL;\n return X509_PUBKEY_get0(x->cert_info.key);\n}', 'EVP_PKEY *X509_PUBKEY_get0(X509_PUBKEY *key)\n{\n EVP_PKEY *ret = NULL;\n if (key == NULL || key->public_key == NULL)\n return NULL;\n if (key->pkey != NULL)\n return key->pkey;\n x509_pubkey_decode(&ret, key);\n if (ret != NULL) {\n X509err(X509_F_X509_PUBKEY_GET0, ERR_R_INTERNAL_ERROR);\n EVP_PKEY_free(ret);\n }\n return NULL;\n}', 'static int x509_pubkey_decode(EVP_PKEY **ppkey, X509_PUBKEY *key)\n {\n EVP_PKEY *pkey = EVP_PKEY_new();\n if (pkey == NULL) {\n X509err(X509_F_X509_PUBKEY_DECODE, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n if (!EVP_PKEY_set_type(pkey, OBJ_obj2nid(key->algor->algorithm))) {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_UNSUPPORTED_ALGORITHM);\n goto error;\n }\n if (pkey->ameth->pub_decode) {\n if (!pkey->ameth->pub_decode(pkey, key)) {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_PUBLIC_KEY_DECODE_ERROR);\n goto error;\n }\n } else {\n X509err(X509_F_X509_PUBKEY_DECODE, X509_R_METHOD_NOT_SUPPORTED);\n goto error;\n }\n *ppkey = pkey;\n return 1;\n error:\n EVP_PKEY_free(pkey);\n return 0;\n}', 'RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)\n{\n if (pkey->type != EVP_PKEY_RSA) {\n EVPerr(EVP_F_EVP_PKEY_GET0_RSA, EVP_R_EXPECTING_AN_RSA_KEY);\n return NULL;\n }\n return pkey->pkey.rsa;\n}']
|
1,617
| 0
|
https://github.com/openssl/openssl/blob/fa9bb6201e1d16ba8ccab938833d140ef81a7f73/crypto/bn/bn_lib.c/#L440
|
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
int i;
BN_ULONG *A;
const BN_ULONG *B;
bn_check_top(b);
if (a == b)
return (a);
if (bn_wexpand(a, b->top) == NULL)
return (NULL);
#if 1
A = a->d;
B = b->d;
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:;
}
#else
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
#endif
a->top = b->top;
a->neg = b->neg;
bn_check_top(a);
return (a);
}
|
['static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)\n{\n const unsigned char *p, *pm;\n int pklen, pmlen;\n int ptype;\n void *pval;\n ASN1_STRING *pstr;\n X509_ALGOR *palg;\n ASN1_INTEGER *privkey = NULL;\n BN_CTX *ctx = NULL;\n STACK_OF(ASN1_TYPE) *ndsa = NULL;\n DSA *dsa = NULL;\n if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))\n return 0;\n X509_ALGOR_get0(NULL, &ptype, &pval, palg);\n if (*p == (V_ASN1_SEQUENCE | V_ASN1_CONSTRUCTED)) {\n ASN1_TYPE *t1, *t2;\n if ((ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen)) == NULL)\n goto decerr;\n if (sk_ASN1_TYPE_num(ndsa) != 2)\n goto decerr;\n t1 = sk_ASN1_TYPE_value(ndsa, 0);\n t2 = sk_ASN1_TYPE_value(ndsa, 1);\n if (t1->type == V_ASN1_SEQUENCE) {\n p8->broken = PKCS8_EMBEDDED_PARAM;\n pval = t1->value.ptr;\n } else if (ptype == V_ASN1_SEQUENCE)\n p8->broken = PKCS8_NS_DB;\n else\n goto decerr;\n if (t2->type != V_ASN1_INTEGER)\n goto decerr;\n privkey = t2->value.integer;\n } else {\n const unsigned char *q = p;\n if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL)\n goto decerr;\n if (privkey->type == V_ASN1_NEG_INTEGER) {\n p8->broken = PKCS8_NEG_PRIVKEY;\n ASN1_STRING_clear_free(privkey);\n if ((privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen)) == NULL)\n goto decerr;\n }\n if (ptype != V_ASN1_SEQUENCE)\n goto decerr;\n }\n pstr = pval;\n pm = pstr->data;\n pmlen = pstr->length;\n if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL)\n goto decerr;\n if ((dsa->priv_key = BN_secure_new()) == NULL\n || !ASN1_INTEGER_to_BN(privkey, dsa->priv_key)) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);\n goto dsaerr;\n }\n if ((dsa->pub_key = BN_new()) == NULL) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);\n goto dsaerr;\n }\n if ((ctx = BN_CTX_new()) == NULL) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);\n goto dsaerr;\n }\n if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);\n goto dsaerr;\n }\n EVP_PKEY_assign_DSA(pkey, dsa);\n BN_CTX_free(ctx);\n if (ndsa)\n sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);\n else\n ASN1_STRING_clear_free(privkey);\n return 1;\n decerr:\n DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR);\n dsaerr:\n BN_CTX_free(ctx);\n ASN1_STRING_clear_free(privkey);\n sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);\n DSA_free(dsa);\n return 0;\n}', 'BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)\n{\n return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);\n}', 'static BIGNUM *asn1_string_to_bn(const ASN1_INTEGER *ai, BIGNUM *bn,\n int itype)\n{\n BIGNUM *ret;\n if ((ai->type & ~V_ASN1_NEG) != itype) {\n ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_WRONG_INTEGER_TYPE);\n return NULL;\n }\n ret = BN_bin2bn(ai->data, ai->length, bn);\n if (ret == 0) {\n ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_BN_LIB);\n return NULL;\n }\n if (ai->type & V_ASN1_NEG)\n BN_set_negative(ret, 1);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!aa || !val[0])\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}']
|
1,618
| 0
|
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/mem.c/#L244
|
void CRYPTO_free(void *str)
{
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (call_malloc_debug) {
CRYPTO_mem_debug_free(str, 0);
free(str);
CRYPTO_mem_debug_free(str, 1);
} else {
free(str);
}
#else
free(str);
#endif
}
|
["static int int_x509_param_set_hosts(X509_VERIFY_PARAM *vpm, int mode,\n const char *name, size_t namelen)\n{\n char *copy;\n if (namelen == 0 || name == NULL)\n namelen = name ? strlen(name) : 0;\n else if (name && memchr(name, '\\0', namelen > 1 ? namelen - 1 : namelen))\n return 0;\n if (namelen > 0 && name[namelen - 1] == '\\0')\n --namelen;\n if (mode == SET_HOST) {\n sk_OPENSSL_STRING_pop_free(vpm->hosts, str_free);\n vpm->hosts = NULL;\n }\n if (name == NULL || namelen == 0)\n return 1;\n copy = OPENSSL_strndup(name, namelen);\n if (copy == NULL)\n return 0;\n if (vpm->hosts == NULL &&\n (vpm->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {\n OPENSSL_free(copy);\n return 0;\n }\n if (!sk_OPENSSL_STRING_push(vpm->hosts, copy)) {\n OPENSSL_free(copy);\n if (sk_OPENSSL_STRING_num(vpm->hosts) == 0) {\n sk_OPENSSL_STRING_free(vpm->hosts);\n vpm->hosts = NULL;\n }\n return 0;\n }\n return 1;\n}", 'DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str)\n{\n#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}']
|
1,619
| 0
|
https://github.com/libav/libav/blob/5351964a2b524d1cb70c268c3e9436fd2990429b/libavcodec/mpeg12dec.c/#L249
|
static inline int mpeg1_decode_block_inter(MpegEncContext *s,
int16_t *block, int n)
{
int level, i, j, run;
RLTable *rl = &ff_rl_mpeg1;
uint8_t *const scantable = s->intra_scantable.permutated;
const uint16_t *quant_matrix = s->inter_matrix;
const int qscale = s->qscale;
{
OPEN_READER(re, &s->gb);
i = -1;
UPDATE_CACHE(re, &s->gb);
if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
level = (3 * qscale * quant_matrix[0]) >> 5;
level = (level - 1) | 1;
if (GET_CACHE(re, &s->gb) & 0x40000000)
level = -level;
block[0] = level;
i++;
SKIP_BITS(re, &s->gb, 2);
if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
goto end;
}
for (;;) {
GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0],
TEX_VLC_BITS, 2, 0);
if (level != 0) {
i += run;
check_scantable_index(s, i);
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level - 1) | 1;
level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
SHOW_SBITS(re, &s->gb, 1);
SKIP_BITS(re, &s->gb, 1);
} else {
run = SHOW_UBITS(re, &s->gb, 6) + 1;
LAST_SKIP_BITS(re, &s->gb, 6);
UPDATE_CACHE(re, &s->gb);
level = SHOW_SBITS(re, &s->gb, 8);
SKIP_BITS(re, &s->gb, 8);
if (level == -128) {
level = SHOW_UBITS(re, &s->gb, 8) - 256;
SKIP_BITS(re, &s->gb, 8);
} else if (level == 0) {
level = SHOW_UBITS(re, &s->gb, 8);
SKIP_BITS(re, &s->gb, 8);
}
i += run;
check_scantable_index(s, i);
j = scantable[i];
if (level < 0) {
level = -level;
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level - 1) | 1;
level = -level;
} else {
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level - 1) | 1;
}
}
block[j] = level;
if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
break;
UPDATE_CACHE(re, &s->gb);
}
end:
LAST_SKIP_BITS(re, &s->gb, 2);
CLOSE_READER(re, &s->gb);
}
s->block_last_index[n] = i;
return 0;
}
|
['static inline int mpeg1_decode_block_inter(MpegEncContext *s,\n int16_t *block, int n)\n{\n int level, i, j, run;\n RLTable *rl = &ff_rl_mpeg1;\n uint8_t *const scantable = s->intra_scantable.permutated;\n const uint16_t *quant_matrix = s->inter_matrix;\n const int qscale = s->qscale;\n {\n OPEN_READER(re, &s->gb);\n i = -1;\n UPDATE_CACHE(re, &s->gb);\n if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {\n level = (3 * qscale * quant_matrix[0]) >> 5;\n level = (level - 1) | 1;\n if (GET_CACHE(re, &s->gb) & 0x40000000)\n level = -level;\n block[0] = level;\n i++;\n SKIP_BITS(re, &s->gb, 2);\n if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)\n goto end;\n }\n for (;;) {\n GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0],\n TEX_VLC_BITS, 2, 0);\n if (level != 0) {\n i += run;\n check_scantable_index(s, i);\n j = scantable[i];\n level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;\n level = (level - 1) | 1;\n level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -\n SHOW_SBITS(re, &s->gb, 1);\n SKIP_BITS(re, &s->gb, 1);\n } else {\n run = SHOW_UBITS(re, &s->gb, 6) + 1;\n LAST_SKIP_BITS(re, &s->gb, 6);\n UPDATE_CACHE(re, &s->gb);\n level = SHOW_SBITS(re, &s->gb, 8);\n SKIP_BITS(re, &s->gb, 8);\n if (level == -128) {\n level = SHOW_UBITS(re, &s->gb, 8) - 256;\n SKIP_BITS(re, &s->gb, 8);\n } else if (level == 0) {\n level = SHOW_UBITS(re, &s->gb, 8);\n SKIP_BITS(re, &s->gb, 8);\n }\n i += run;\n check_scantable_index(s, i);\n j = scantable[i];\n if (level < 0) {\n level = -level;\n level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;\n level = (level - 1) | 1;\n level = -level;\n } else {\n level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;\n level = (level - 1) | 1;\n }\n }\n block[j] = level;\n if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)\n break;\n UPDATE_CACHE(re, &s->gb);\n }\nend:\n LAST_SKIP_BITS(re, &s->gb, 2);\n CLOSE_READER(re, &s->gb);\n }\n s->block_last_index[n] = i;\n return 0;\n}']
|
1,620
| 0
|
https://github.com/libav/libav/blob/fd16f567987524a769d5d4f1f69089f000386ac2/libavcodec/alac.c/#L469
|
static int alac_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
const uint8_t *inbuffer = avpkt->data;
int input_buffer_size = avpkt->size;
ALACContext *alac = avctx->priv_data;
int channels;
unsigned int outputsamples;
int hassize;
unsigned int readsamplesize;
int isnotcompressed;
uint8_t interlacing_shift;
uint8_t interlacing_leftweight;
int i, ch, ret;
init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
channels = get_bits(&alac->gb, 3) + 1;
if (channels != avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n");
return AVERROR_INVALIDDATA;
}
skip_bits(&alac->gb, 4);
skip_bits(&alac->gb, 12);
hassize = get_bits1(&alac->gb);
alac->extra_bits = get_bits(&alac->gb, 2) << 3;
isnotcompressed = get_bits1(&alac->gb);
if (hassize) {
outputsamples = get_bits_long(&alac->gb, 32);
if(outputsamples > alac->setinfo_max_samples_per_frame){
av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame);
return -1;
}
} else
outputsamples = alac->setinfo_max_samples_per_frame;
if (outputsamples > INT32_MAX) {
av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n", outputsamples);
return AVERROR_INVALIDDATA;
}
alac->frame.nb_samples = outputsamples;
if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
readsamplesize = alac->setinfo_sample_size - alac->extra_bits + channels - 1;
if (readsamplesize > MIN_CACHE_BITS) {
av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);
return -1;
}
if (!isnotcompressed) {
int16_t predictor_coef_table[MAX_CHANNELS][32];
int predictor_coef_num[MAX_CHANNELS];
int prediction_type[MAX_CHANNELS];
int prediction_quantitization[MAX_CHANNELS];
int ricemodifier[MAX_CHANNELS];
interlacing_shift = get_bits(&alac->gb, 8);
interlacing_leftweight = get_bits(&alac->gb, 8);
for (ch = 0; ch < channels; ch++) {
prediction_type[ch] = get_bits(&alac->gb, 4);
prediction_quantitization[ch] = get_bits(&alac->gb, 4);
ricemodifier[ch] = get_bits(&alac->gb, 3);
predictor_coef_num[ch] = get_bits(&alac->gb, 5);
for (i = 0; i < predictor_coef_num[ch]; i++)
predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16);
}
if (alac->extra_bits) {
for (i = 0; i < outputsamples; i++) {
for (ch = 0; ch < channels; ch++)
alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits);
}
}
for (ch = 0; ch < channels; ch++) {
bastardized_rice_decompress(alac,
alac->predicterror_buffer[ch],
outputsamples,
readsamplesize,
alac->setinfo_rice_initialhistory,
alac->setinfo_rice_kmodifier,
ricemodifier[ch] * alac->setinfo_rice_historymult / 4,
(1 << alac->setinfo_rice_kmodifier) - 1);
if (prediction_type[ch] == 15) {
predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
alac->predicterror_buffer[ch],
outputsamples, readsamplesize,
NULL, 31, 0);
} else if (prediction_type[ch] > 0) {
av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n",
prediction_type[ch]);
}
predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
alac->outputsamples_buffer[ch],
outputsamples, readsamplesize,
predictor_coef_table[ch],
predictor_coef_num[ch],
prediction_quantitization[ch]);
}
} else {
for (i = 0; i < outputsamples; i++) {
for (ch = 0; ch < channels; ch++) {
alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb,
alac->setinfo_sample_size);
}
}
alac->extra_bits = 0;
interlacing_shift = 0;
interlacing_leftweight = 0;
}
if (get_bits(&alac->gb, 3) != 7)
av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
if (channels == 2 && interlacing_leftweight) {
decorrelate_stereo(alac->outputsamples_buffer, outputsamples,
interlacing_shift, interlacing_leftweight);
}
if (alac->extra_bits) {
append_extra_bits(alac->outputsamples_buffer, alac->extra_bits_buffer,
alac->extra_bits, alac->numchannels, outputsamples);
}
switch(alac->setinfo_sample_size) {
case 16:
if (channels == 2) {
interleave_stereo_16(alac->outputsamples_buffer,
(int16_t *)alac->frame.data[0], outputsamples);
} else {
int16_t *outbuffer = (int16_t *)alac->frame.data[0];
for (i = 0; i < outputsamples; i++) {
outbuffer[i] = alac->outputsamples_buffer[0][i];
}
}
break;
case 24:
if (channels == 2) {
interleave_stereo_24(alac->outputsamples_buffer,
(int32_t *)alac->frame.data[0], outputsamples);
} else {
int32_t *outbuffer = (int32_t *)alac->frame.data[0];
for (i = 0; i < outputsamples; i++)
outbuffer[i] = alac->outputsamples_buffer[0][i] << 8;
}
break;
}
if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)
av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb));
*got_frame_ptr = 1;
*(AVFrame *)data = alac->frame;
return input_buffer_size;
}
|
['static int alac_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n const uint8_t *inbuffer = avpkt->data;\n int input_buffer_size = avpkt->size;\n ALACContext *alac = avctx->priv_data;\n int channels;\n unsigned int outputsamples;\n int hassize;\n unsigned int readsamplesize;\n int isnotcompressed;\n uint8_t interlacing_shift;\n uint8_t interlacing_leftweight;\n int i, ch, ret;\n init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);\n channels = get_bits(&alac->gb, 3) + 1;\n if (channels != avctx->channels) {\n av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\\n");\n return AVERROR_INVALIDDATA;\n }\n skip_bits(&alac->gb, 4);\n skip_bits(&alac->gb, 12);\n hassize = get_bits1(&alac->gb);\n alac->extra_bits = get_bits(&alac->gb, 2) << 3;\n isnotcompressed = get_bits1(&alac->gb);\n if (hassize) {\n outputsamples = get_bits_long(&alac->gb, 32);\n if(outputsamples > alac->setinfo_max_samples_per_frame){\n av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\\n", outputsamples, alac->setinfo_max_samples_per_frame);\n return -1;\n }\n } else\n outputsamples = alac->setinfo_max_samples_per_frame;\n if (outputsamples > INT32_MAX) {\n av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\\n", outputsamples);\n return AVERROR_INVALIDDATA;\n }\n alac->frame.nb_samples = outputsamples;\n if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n readsamplesize = alac->setinfo_sample_size - alac->extra_bits + channels - 1;\n if (readsamplesize > MIN_CACHE_BITS) {\n av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\\n", readsamplesize);\n return -1;\n }\n if (!isnotcompressed) {\n int16_t predictor_coef_table[MAX_CHANNELS][32];\n int predictor_coef_num[MAX_CHANNELS];\n int prediction_type[MAX_CHANNELS];\n int prediction_quantitization[MAX_CHANNELS];\n int ricemodifier[MAX_CHANNELS];\n interlacing_shift = get_bits(&alac->gb, 8);\n interlacing_leftweight = get_bits(&alac->gb, 8);\n for (ch = 0; ch < channels; ch++) {\n prediction_type[ch] = get_bits(&alac->gb, 4);\n prediction_quantitization[ch] = get_bits(&alac->gb, 4);\n ricemodifier[ch] = get_bits(&alac->gb, 3);\n predictor_coef_num[ch] = get_bits(&alac->gb, 5);\n for (i = 0; i < predictor_coef_num[ch]; i++)\n predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16);\n }\n if (alac->extra_bits) {\n for (i = 0; i < outputsamples; i++) {\n for (ch = 0; ch < channels; ch++)\n alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits);\n }\n }\n for (ch = 0; ch < channels; ch++) {\n bastardized_rice_decompress(alac,\n alac->predicterror_buffer[ch],\n outputsamples,\n readsamplesize,\n alac->setinfo_rice_initialhistory,\n alac->setinfo_rice_kmodifier,\n ricemodifier[ch] * alac->setinfo_rice_historymult / 4,\n (1 << alac->setinfo_rice_kmodifier) - 1);\n if (prediction_type[ch] == 15) {\n predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],\n alac->predicterror_buffer[ch],\n outputsamples, readsamplesize,\n NULL, 31, 0);\n } else if (prediction_type[ch] > 0) {\n av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\\n",\n prediction_type[ch]);\n }\n predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],\n alac->outputsamples_buffer[ch],\n outputsamples, readsamplesize,\n predictor_coef_table[ch],\n predictor_coef_num[ch],\n prediction_quantitization[ch]);\n }\n } else {\n for (i = 0; i < outputsamples; i++) {\n for (ch = 0; ch < channels; ch++) {\n alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb,\n alac->setinfo_sample_size);\n }\n }\n alac->extra_bits = 0;\n interlacing_shift = 0;\n interlacing_leftweight = 0;\n }\n if (get_bits(&alac->gb, 3) != 7)\n av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\\n");\n if (channels == 2 && interlacing_leftweight) {\n decorrelate_stereo(alac->outputsamples_buffer, outputsamples,\n interlacing_shift, interlacing_leftweight);\n }\n if (alac->extra_bits) {\n append_extra_bits(alac->outputsamples_buffer, alac->extra_bits_buffer,\n alac->extra_bits, alac->numchannels, outputsamples);\n }\n switch(alac->setinfo_sample_size) {\n case 16:\n if (channels == 2) {\n interleave_stereo_16(alac->outputsamples_buffer,\n (int16_t *)alac->frame.data[0], outputsamples);\n } else {\n int16_t *outbuffer = (int16_t *)alac->frame.data[0];\n for (i = 0; i < outputsamples; i++) {\n outbuffer[i] = alac->outputsamples_buffer[0][i];\n }\n }\n break;\n case 24:\n if (channels == 2) {\n interleave_stereo_24(alac->outputsamples_buffer,\n (int32_t *)alac->frame.data[0], outputsamples);\n } else {\n int32_t *outbuffer = (int32_t *)alac->frame.data[0];\n for (i = 0; i < outputsamples; i++)\n outbuffer[i] = alac->outputsamples_buffer[0][i] << 8;\n }\n break;\n }\n if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)\n av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\\n", input_buffer_size * 8 - get_bits_count(&alac->gb));\n *got_frame_ptr = 1;\n *(AVFrame *)data = alac->frame;\n return input_buffer_size;\n}']
|
1,621
| 0
|
https://github.com/openssl/openssl/blob/1d3159bccaa400d6966005b9bc49cca1f6719962/crypto/x509v3/v3_purp.c/#L121
|
int X509_check_purpose(X509 *x, int id, int ca)
{
int idx;
const X509_PURPOSE *pt;
if(!(x->ex_flags & EXFLAG_SET)) {
CRYPTO_w_lock(CRYPTO_LOCK_X509);
x509v3_cache_extensions(x);
CRYPTO_w_unlock(CRYPTO_LOCK_X509);
}
if(id == -1) return 1;
idx = X509_PURPOSE_get_by_id(id);
if(idx == -1) return -1;
pt = X509_PURPOSE_get0(idx);
return pt->check_purpose(pt, x, ca);
}
|
['int X509_check_purpose(X509 *x, int id, int ca)\n{\n\tint idx;\n\tconst X509_PURPOSE *pt;\n\tif(!(x->ex_flags & EXFLAG_SET)) {\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_X509);\n\t\tx509v3_cache_extensions(x);\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_X509);\n\t}\n\tif(id == -1) return 1;\n\tidx = X509_PURPOSE_get_by_id(id);\n\tif(idx == -1) return -1;\n\tpt = X509_PURPOSE_get0(idx);\n\treturn pt->check_purpose(pt, x, ca);\n}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t= CRYPTO_get_dynlock_value(type);\n\t\tif (pointer && dynlock_lock_callback)\n\t\t\t{\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\t}\n\t\tCRYPTO_destroy_dynlockid(type);\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n\tX509_PURPOSE tmp;\n\tint idx;\n\tif((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n\t\treturn purpose - X509_PURPOSE_MIN;\n\ttmp.purpose = purpose;\n\tif(!xptable) return -1;\n\tidx = sk_X509_PURPOSE_find(xptable, &tmp);\n\tif(idx == -1) return -1;\n\treturn idx + X509_PURPOSE_COUNT;\n}', 'X509_PURPOSE * X509_PURPOSE_get0(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_PURPOSE_COUNT) return xstandard + idx;\n\treturn sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']
|
1,622
| 0
|
https://github.com/openssl/openssl/blob/21e8bbf2904e5ac8709d46424e18f8ba6e813b06/crypto/x509v3/v3_utl.c/#L518
|
static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
{
STACK *ret = NULL;
X509_NAME_ENTRY *ne;
ASN1_IA5STRING *email;
GENERAL_NAME *gen;
int i;
i = -1;
while((i = X509_NAME_get_index_by_NID(name,
NID_pkcs9_emailAddress, i)) >= 0) {
ne = X509_NAME_get_entry(name, i);
email = X509_NAME_ENTRY_get_data(ne);
if(!append_ia5(&ret, email)) return NULL;
}
for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
{
gen = sk_GENERAL_NAME_value(gens, i);
if(gen->type != GEN_EMAIL) continue;
if(!append_ia5(&ret, gen->d.ia5)) return NULL;
}
return ret;
}
|
['static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)\n{\n\tSTACK *ret = NULL;\n\tX509_NAME_ENTRY *ne;\n\tASN1_IA5STRING *email;\n\tGENERAL_NAME *gen;\n\tint i;\n\ti = -1;\n\twhile((i = X509_NAME_get_index_by_NID(name,\n\t\t\t\t\t NID_pkcs9_emailAddress, i)) >= 0) {\n\t\tne = X509_NAME_get_entry(name, i);\n\t\temail = X509_NAME_ENTRY_get_data(ne);\n\t\tif(!append_ia5(&ret, email)) return NULL;\n\t}\n\tfor(i = 0; i < sk_GENERAL_NAME_num(gens); i++)\n\t{\n\t\tgen = sk_GENERAL_NAME_value(gens, i);\n\t\tif(gen->type != GEN_EMAIL) continue;\n\t\tif(!append_ia5(&ret, gen->d.ia5)) return NULL;\n\t}\n\treturn ret;\n}', 'int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)\n\t{\n\tASN1_OBJECT *obj;\n\tobj=OBJ_nid2obj(nid);\n\tif (obj == NULL) return(-2);\n\treturn(X509_NAME_get_index_by_OBJ(name,obj,lastpos));\n\t}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn((ASN1_OBJECT *)&(nid_objs[n]));\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}', 'X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)\n\t{\n\tif(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc\n\t || loc < 0)\n\t\treturn(NULL);\n\telse\n\t\treturn(sk_X509_NAME_ENTRY_value(name->entries,loc));\n\t}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}', 'ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)\n\t{\n\tif (ne == NULL) return(NULL);\n\treturn(ne->value);\n\t}', 'static int append_ia5(STACK **sk, ASN1_IA5STRING *email)\n{\n\tchar *emtmp;\n\tif(email->type != V_ASN1_IA5STRING) return 1;\n\tif(!email->data || !email->length) return 1;\n\tif(!*sk) *sk = sk_new(sk_strcmp);\n\tif(!*sk) return 0;\n\tif(sk_find(*sk, (char *)email->data) != -1) return 1;\n\temtmp = BUF_strdup((char *)email->data);\n\tif(!emtmp || !sk_push(*sk, emtmp)) {\n\t\tX509_email_free(*sk);\n\t\t*sk = NULL;\n\t\treturn 0;\n\t}\n\treturn 1;\n}']
|
1,623
| 0
|
https://github.com/openssl/openssl/blob/58351fbd02e9960af199df99f6f003419c1487a4/ssl/tls13_enc.c/#L690
|
int tls13_export_keying_material(SSL *s, unsigned char *out, size_t olen,
const char *label, size_t llen,
const unsigned char *context,
size_t contextlen, int use_context)
{
unsigned char exportsecret[EVP_MAX_MD_SIZE];
static const unsigned char exporterlabel[] = "exporter";
unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];
const EVP_MD *md = ssl_handshake_md(s);
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
unsigned int hashsize, datalen;
int ret = 0;
if (ctx == NULL || !ossl_statem_export_allowed(s))
goto err;
if (!use_context)
contextlen = 0;
if (EVP_DigestInit_ex(ctx, md, NULL) <= 0
|| EVP_DigestUpdate(ctx, context, contextlen) <= 0
|| EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0
|| EVP_DigestInit_ex(ctx, md, NULL) <= 0
|| EVP_DigestFinal_ex(ctx, data, &datalen) <= 0
|| !tls13_hkdf_expand(s, md, s->exporter_master_secret,
(const unsigned char *)label, llen,
data, datalen, exportsecret, hashsize)
|| !tls13_hkdf_expand(s, md, exportsecret, exporterlabel,
sizeof(exporterlabel) - 1, hash, hashsize,
out, olen))
goto err;
ret = 1;
err:
EVP_MD_CTX_free(ctx);
return ret;
}
|
['int tls13_export_keying_material(SSL *s, unsigned char *out, size_t olen,\n const char *label, size_t llen,\n const unsigned char *context,\n size_t contextlen, int use_context)\n{\n unsigned char exportsecret[EVP_MAX_MD_SIZE];\n static const unsigned char exporterlabel[] = "exporter";\n unsigned char hash[EVP_MAX_MD_SIZE], data[EVP_MAX_MD_SIZE];\n const EVP_MD *md = ssl_handshake_md(s);\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n unsigned int hashsize, datalen;\n int ret = 0;\n if (ctx == NULL || !ossl_statem_export_allowed(s))\n goto err;\n if (!use_context)\n contextlen = 0;\n if (EVP_DigestInit_ex(ctx, md, NULL) <= 0\n || EVP_DigestUpdate(ctx, context, contextlen) <= 0\n || EVP_DigestFinal_ex(ctx, hash, &hashsize) <= 0\n || EVP_DigestInit_ex(ctx, md, NULL) <= 0\n || EVP_DigestFinal_ex(ctx, data, &datalen) <= 0\n || !tls13_hkdf_expand(s, md, s->exporter_master_secret,\n (const unsigned char *)label, llen,\n data, datalen, exportsecret, hashsize)\n || !tls13_hkdf_expand(s, md, exportsecret, exporterlabel,\n sizeof(exporterlabel) - 1, hash, hashsize,\n out, olen))\n goto err;\n ret = 1;\n err:\n EVP_MD_CTX_free(ctx);\n return ret;\n}', 'const EVP_MD *ssl_handshake_md(SSL *s)\n{\n return EVP_sha256();\n}', 'const EVP_MD *EVP_sha256(void)\n{\n return &sha256_md;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int ossl_statem_export_allowed(SSL *s)\n{\n return 1;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
1,624
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L149
|
static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;
src[1+0*stride]=
src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;
src[2+0*stride]=
src[1+1*stride]=
src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;
src[3+0*stride]=
src[2+1*stride]=
src[1+2*stride]=
src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;
src[3+1*stride]=
src[2+2*stride]=
src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;
src[3+2*stride]=
src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;
src[3+3*stride]=(t6 + 3*t7 + 2)>>2;
}
|
['static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2;\n src[1+0*stride]=\n src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2;\n src[2+0*stride]=\n src[1+1*stride]=\n src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2;\n src[3+0*stride]=\n src[2+1*stride]=\n src[1+2*stride]=\n src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2;\n src[3+1*stride]=\n src[2+2*stride]=\n src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2;\n src[3+2*stride]=\n src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2;\n src[3+3*stride]=(t6 + 3*t7 + 2)>>2;\n}']
|
1,625
| 0
|
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/packet_locl.h/#L36
|
static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
pkt->curr += len;
pkt->remaining -= len;
}
|
['MSG_PROCESS_RETURN tls_process_client_hello(SSL *s, PACKET *pkt)\n{\n int i, al = SSL_AD_INTERNAL_ERROR;\n unsigned int j, complen = 0;\n unsigned long id;\n const SSL_CIPHER *c;\n#ifndef OPENSSL_NO_COMP\n SSL_COMP *comp = NULL;\n#endif\n STACK_OF(SSL_CIPHER) *ciphers = NULL;\n int protverr;\n PACKET session_id, cipher_suites, compression, extensions, cookie;\n int is_v2_record;\n static const unsigned char null_compression = 0;\n is_v2_record = RECORD_LAYER_is_sslv2_record(&s->rlayer);\n PACKET_null_init(&cookie);\n if (is_v2_record) {\n unsigned int version;\n unsigned int mt;\n if (!PACKET_get_1(pkt, &mt)\n || mt != SSL2_MT_CLIENT_HELLO) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!PACKET_get_net_2(pkt, &version)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_UNKNOWN_PROTOCOL);\n goto err;\n }\n if (version == 0x0002) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_UNKNOWN_PROTOCOL);\n goto err;\n } else if ((version & 0xff00) == (SSL3_VERSION_MAJOR << 8)) {\n s->client_version = version;\n } else {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_UNKNOWN_PROTOCOL);\n goto err;\n }\n } else {\n if (!PACKET_get_net_2(pkt, (unsigned int *)&s->client_version)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_LENGTH_TOO_SHORT);\n goto f_err;\n }\n }\n if (!SSL_IS_DTLS(s)) {\n protverr = ssl_choose_server_version(s);\n } else if (s->method->version != DTLS_ANY_VERSION &&\n DTLS_VERSION_LT(s->client_version, s->version)) {\n protverr = SSL_R_VERSION_TOO_LOW;\n } else {\n protverr = 0;\n }\n if (protverr) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, protverr);\n if ((!s->enc_write_ctx && !s->write_hash)) {\n s->version = s->client_version;\n }\n al = SSL_AD_PROTOCOL_VERSION;\n goto f_err;\n }\n if (is_v2_record) {\n unsigned int cipher_len, session_id_len, challenge_len;\n PACKET challenge;\n if (!PACKET_get_net_2(pkt, &cipher_len)\n || !PACKET_get_net_2(pkt, &session_id_len)\n || !PACKET_get_net_2(pkt, &challenge_len)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_RECORD_LENGTH_MISMATCH);\n al = SSL_AD_DECODE_ERROR;\n goto f_err;\n }\n if (session_id_len > SSL_MAX_SSL_SESSION_ID_LENGTH) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (!PACKET_get_sub_packet(pkt, &cipher_suites, cipher_len)\n || !PACKET_get_sub_packet(pkt, &session_id, session_id_len)\n || !PACKET_get_sub_packet(pkt, &challenge, challenge_len)\n || PACKET_remaining(pkt) != 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_RECORD_LENGTH_MISMATCH);\n al = SSL_AD_DECODE_ERROR;\n goto f_err;\n }\n challenge_len = challenge_len > SSL3_RANDOM_SIZE ? SSL3_RANDOM_SIZE :\n challenge_len;\n memset(s->s3->client_random, 0, SSL3_RANDOM_SIZE);\n if (!PACKET_copy_bytes(&challenge,\n s->s3->client_random + SSL3_RANDOM_SIZE -\n challenge_len, challenge_len)\n || !PACKET_buf_init(&compression, &null_compression, 1)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n al = SSL_AD_INTERNAL_ERROR;\n goto f_err;\n }\n PACKET_null_init(&extensions);\n } else {\n if (!PACKET_copy_bytes(pkt, s->s3->client_random, SSL3_RANDOM_SIZE)\n || !PACKET_get_length_prefixed_1(pkt, &session_id)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (PACKET_remaining(&session_id) > SSL_MAX_SSL_SESSION_ID_LENGTH) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (SSL_IS_DTLS(s)) {\n if (!PACKET_get_length_prefixed_1(pkt, &cookie)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n if (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) {\n if (PACKET_remaining(&cookie) == 0)\n return 1;\n }\n }\n if (!PACKET_get_length_prefixed_2(pkt, &cipher_suites)\n || !PACKET_get_length_prefixed_1(pkt, &compression)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);\n goto f_err;\n }\n extensions = *pkt;\n }\n if (SSL_IS_DTLS(s)) {\n if (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) {\n if (s->ctx->app_verify_cookie_cb != NULL) {\n if (s->ctx->app_verify_cookie_cb(s, PACKET_data(&cookie),\n PACKET_remaining(&cookie)) ==\n 0) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_COOKIE_MISMATCH);\n goto f_err;\n }\n } else if (!PACKET_equal(&cookie, s->d1->cookie, s->d1->cookie_len)) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_COOKIE_MISMATCH);\n goto f_err;\n }\n s->d1->cookie_verified = 1;\n }\n if (s->method->version == DTLS_ANY_VERSION) {\n protverr = ssl_choose_server_version(s);\n if (protverr != 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, protverr);\n s->version = s->client_version;\n al = SSL_AD_PROTOCOL_VERSION;\n goto f_err;\n }\n }\n }\n s->hit = 0;\n if (is_v2_record ||\n (s->new_session &&\n (s->options & SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION))) {\n if (!ssl_get_new_session(s, 1))\n goto err;\n } else {\n i = ssl_get_prev_session(s, &extensions, &session_id);\n if (i == 1 && s->version == s->session->ssl_version) {\n s->hit = 1;\n } else if (i == -1) {\n goto err;\n } else {\n if (!ssl_get_new_session(s, 1))\n goto err;\n }\n }\n if (ssl_bytes_to_cipher_list(s, &cipher_suites, &(ciphers),\n is_v2_record, &al) == NULL) {\n goto f_err;\n }\n if (s->hit) {\n j = 0;\n id = s->session->cipher->id;\n#ifdef CIPHER_DEBUG\n fprintf(stderr, "client sent %d ciphers\\n", sk_SSL_CIPHER_num(ciphers));\n#endif\n for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {\n c = sk_SSL_CIPHER_value(ciphers, i);\n#ifdef CIPHER_DEBUG\n fprintf(stderr, "client [%2d of %2d]:%s\\n",\n i, sk_SSL_CIPHER_num(ciphers), SSL_CIPHER_get_name(c));\n#endif\n if (c->id == id) {\n j = 1;\n break;\n }\n }\n if (j == 0) {\n al = SSL_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_REQUIRED_CIPHER_MISSING);\n goto f_err;\n }\n }\n complen = PACKET_remaining(&compression);\n for (j = 0; j < complen; j++) {\n if (PACKET_data(&compression)[j] == 0)\n break;\n }\n if (j >= complen) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_NO_COMPRESSION_SPECIFIED);\n goto f_err;\n }\n if (s->version >= SSL3_VERSION) {\n if (!ssl_parse_clienthello_tlsext(s, &extensions)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_PARSE_TLSEXT);\n goto err;\n }\n }\n {\n unsigned char *pos;\n pos = s->s3->server_random;\n if (ssl_fill_hello_random(s, 1, pos, SSL3_RANDOM_SIZE) <= 0) {\n goto f_err;\n }\n }\n if (!s->hit && s->version >= TLS1_VERSION && s->tls_session_secret_cb) {\n const SSL_CIPHER *pref_cipher = NULL;\n s->session->master_key_length = sizeof(s->session->master_key);\n if (s->tls_session_secret_cb(s, s->session->master_key,\n &s->session->master_key_length, ciphers,\n &pref_cipher,\n s->tls_session_secret_cb_arg)) {\n s->hit = 1;\n s->session->ciphers = ciphers;\n s->session->verify_result = X509_V_OK;\n ciphers = NULL;\n pref_cipher =\n pref_cipher ? pref_cipher : ssl3_choose_cipher(s,\n s->\n session->ciphers,\n SSL_get_ciphers\n (s));\n if (pref_cipher == NULL) {\n al = SSL_AD_HANDSHAKE_FAILURE;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_NO_SHARED_CIPHER);\n goto f_err;\n }\n s->session->cipher = pref_cipher;\n sk_SSL_CIPHER_free(s->cipher_list);\n s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n s->cipher_list_by_id = sk_SSL_CIPHER_dup(s->session->ciphers);\n }\n }\n s->s3->tmp.new_compression = NULL;\n#ifndef OPENSSL_NO_COMP\n if (s->session->compress_meth != 0) {\n int m, comp_id = s->session->compress_meth;\n unsigned int k;\n if (!ssl_allow_compression(s)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_INCONSISTENT_COMPRESSION);\n goto f_err;\n }\n for (m = 0; m < sk_SSL_COMP_num(s->ctx->comp_methods); m++) {\n comp = sk_SSL_COMP_value(s->ctx->comp_methods, m);\n if (comp_id == comp->id) {\n s->s3->tmp.new_compression = comp;\n break;\n }\n }\n if (s->s3->tmp.new_compression == NULL) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_INVALID_COMPRESSION_ALGORITHM);\n goto f_err;\n }\n for (k = 0; k < complen; k++) {\n if (PACKET_data(&compression)[k] == comp_id)\n break;\n }\n if (k >= complen) {\n al = SSL_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO,\n SSL_R_REQUIRED_COMPRESSION_ALGORITHM_MISSING);\n goto f_err;\n }\n } else if (s->hit)\n comp = NULL;\n else if (ssl_allow_compression(s) && s->ctx->comp_methods) {\n int m, nn, v, done = 0;\n unsigned int o;\n nn = sk_SSL_COMP_num(s->ctx->comp_methods);\n for (m = 0; m < nn; m++) {\n comp = sk_SSL_COMP_value(s->ctx->comp_methods, m);\n v = comp->id;\n for (o = 0; o < complen; o++) {\n if (v == PACKET_data(&compression)[o]) {\n done = 1;\n break;\n }\n }\n if (done)\n break;\n }\n if (done)\n s->s3->tmp.new_compression = comp;\n else\n comp = NULL;\n }\n#else\n if (s->session->compress_meth != 0) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_INCONSISTENT_COMPRESSION);\n goto f_err;\n }\n#endif\n if (!s->hit) {\n#ifdef OPENSSL_NO_COMP\n s->session->compress_meth = 0;\n#else\n s->session->compress_meth = (comp == NULL) ? 0 : comp->id;\n#endif\n sk_SSL_CIPHER_free(s->session->ciphers);\n s->session->ciphers = ciphers;\n if (ciphers == NULL) {\n al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n goto f_err;\n }\n ciphers = NULL;\n if (!tls1_set_server_sigalgs(s)) {\n SSLerr(SSL_F_TLS_PROCESS_CLIENT_HELLO, SSL_R_CLIENTHELLO_TLSEXT);\n goto err;\n }\n }\n sk_SSL_CIPHER_free(ciphers);\n return MSG_PROCESS_CONTINUE_PROCESSING;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n ossl_statem_set_error(s);\n sk_SSL_CIPHER_free(ciphers);\n return MSG_PROCESS_ERROR;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}']
|
1,626
| 0
|
https://github.com/openssl/openssl/blob/d8028b202bfe337200a0cc89b80983ea1838cb30/crypto/lhash/lhash.c/#L164
|
static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
OPENSSL_LH_DOALL_FUNC func,
OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
int i;
OPENSSL_LH_NODE *a, *n;
if (lh == NULL)
return;
for (i = lh->num_nodes - 1; i >= 0; i--) {
a = lh->b[i];
while (a != NULL) {
n = a->next;
if (use_arg)
func_arg(a->data, arg);
else
func(a->data);
a = n;
}
}
}
|
['static int test_handshake_secrets(void)\n{\n SSL_CTX *ctx = NULL;\n SSL *s = NULL;\n int ret = 0;\n size_t hashsize;\n unsigned char out_master_secret[EVP_MAX_MD_SIZE];\n size_t master_secret_length;\n ctx = SSL_CTX_new(TLS_method());\n if (!TEST_ptr(ctx))\n goto err;\n s = SSL_new(ctx);\n if (!TEST_ptr(s ))\n goto err;\n s->session = SSL_SESSION_new();\n if (!TEST_ptr(s->session))\n goto err;\n if (!TEST_true(tls13_generate_secret(s, ssl_handshake_md(s), NULL, NULL, 0,\n (unsigned char *)&s->early_secret))) {\n TEST_info("Early secret generation failed");\n goto err;\n }\n if (!TEST_mem_eq(s->early_secret, sizeof(early_secret),\n early_secret, sizeof(early_secret))) {\n TEST_info("Early secret does not match");\n goto err;\n }\n if (!TEST_true(tls13_generate_handshake_secret(s, ecdhe_secret,\n sizeof(ecdhe_secret)))) {\n TEST_info("Hanshake secret generation failed");\n goto err;\n }\n if (!TEST_mem_eq(s->handshake_secret, sizeof(handshake_secret),\n handshake_secret, sizeof(handshake_secret)))\n goto err;\n hashsize = EVP_MD_size(ssl_handshake_md(s));\n if (!TEST_size_t_eq(sizeof(client_hts), hashsize))\n goto err;\n if (!TEST_size_t_eq(sizeof(client_hts_key), KEYLEN))\n goto err;\n if (!TEST_size_t_eq(sizeof(client_hts_iv), IVLEN))\n goto err;\n if (!TEST_true(test_secret(s, s->handshake_secret,\n (unsigned char *)client_hts_label,\n strlen(client_hts_label), client_hts,\n client_hts_key, client_hts_iv))) {\n TEST_info("Client handshake secret test failed");\n goto err;\n }\n if (!TEST_size_t_eq(sizeof(server_hts), hashsize))\n goto err;\n if (!TEST_size_t_eq(sizeof(server_hts_key), KEYLEN))\n goto err;\n if (!TEST_size_t_eq(sizeof(server_hts_iv), IVLEN))\n goto err;\n if (!TEST_true(test_secret(s, s->handshake_secret,\n (unsigned char *)server_hts_label,\n strlen(server_hts_label), server_hts,\n server_hts_key, server_hts_iv))) {\n TEST_info("Server handshake secret test failed");\n goto err;\n }\n full_hash = 1;\n if (!TEST_true(tls13_generate_master_secret(s, out_master_secret,\n s->handshake_secret, hashsize,\n &master_secret_length))) {\n TEST_info("Master secret generation failed");\n goto err;\n }\n if (!TEST_mem_eq(out_master_secret, master_secret_length,\n master_secret, sizeof(master_secret))) {\n TEST_info("Master secret does not match");\n goto err;\n }\n if (!TEST_size_t_eq(sizeof(client_ats), hashsize))\n goto err;\n if (!TEST_size_t_eq(sizeof(client_ats_key), KEYLEN))\n goto err;\n if (!TEST_size_t_eq(sizeof(client_ats_iv), IVLEN))\n goto err;\n if (!TEST_true(test_secret(s, out_master_secret,\n (unsigned char *)client_ats_label,\n strlen(client_ats_label), client_ats,\n client_ats_key, client_ats_iv))) {\n TEST_info("Client application data secret test failed");\n goto err;\n }\n if (!TEST_size_t_eq(sizeof(server_ats), hashsize))\n goto err;\n if (!TEST_size_t_eq(sizeof(server_ats_key), KEYLEN))\n goto err;\n if (!TEST_size_t_eq(sizeof(server_ats_iv), IVLEN))\n goto err;\n if (!TEST_true(test_secret(s, out_master_secret,\n (unsigned char *)server_ats_label,\n strlen(server_ats_label), server_ats,\n server_ats_key, server_ats_iv))) {\n TEST_info("Server application data secret test failed");\n goto err;\n }\n ret = 1;\n err:\n SSL_free(s);\n SSL_CTX_free(ctx);\n return ret;\n}', 'SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)\n{\n SSL_CTX *ret = NULL;\n if (meth == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_NULL_SSL_METHOD_PASSED);\n return (NULL);\n }\n if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL))\n return NULL;\n if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n goto err;\n }\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL)\n goto err;\n ret->method = meth;\n ret->min_proto_version = 0;\n ret->max_proto_version = 0;\n ret->session_cache_mode = SSL_SESS_CACHE_SERVER;\n ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n ret->session_timeout = meth->get_timeout();\n ret->references = 1;\n ret->lock = CRYPTO_THREAD_lock_new();\n if (ret->lock == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(ret);\n return NULL;\n }\n ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;\n ret->verify_mode = SSL_VERIFY_NONE;\n if ((ret->cert = ssl_cert_new()) == NULL)\n goto err;\n ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp);\n if (ret->sessions == NULL)\n goto err;\n ret->cert_store = X509_STORE_new();\n if (ret->cert_store == NULL)\n goto err;\n#ifndef OPENSSL_NO_CT\n ret->ctlog_store = CTLOG_STORE_new();\n if (ret->ctlog_store == NULL)\n goto err;\n#endif\n if (!ssl_create_cipher_list(ret->method,\n &ret->cipher_list, &ret->cipher_list_by_id,\n SSL_DEFAULT_CIPHER_LIST, ret->cert)\n || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);\n goto err2;\n }\n ret->param = X509_VERIFY_PARAM_new();\n if (ret->param == NULL)\n goto err;\n if ((ret->md5 = EVP_get_digestbyname("ssl3-md5")) == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n goto err2;\n }\n if ((ret->sha1 = EVP_get_digestbyname("ssl3-sha1")) == NULL) {\n SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n goto err2;\n }\n if ((ret->ca_names = sk_X509_NAME_new_null()) == NULL)\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data))\n goto err;\n if (!(meth->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS))\n ret->comp_methods = SSL_COMP_get_compression_methods();\n ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n ret->split_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n if ((RAND_bytes(ret->ext.tick_key_name,\n sizeof(ret->ext.tick_key_name)) <= 0)\n || (RAND_bytes(ret->ext.tick_hmac_key,\n sizeof(ret->ext.tick_hmac_key)) <= 0)\n || (RAND_bytes(ret->ext.tick_aes_key,\n sizeof(ret->ext.tick_aes_key)) <= 0))\n ret->options |= SSL_OP_NO_TICKET;\n#ifndef OPENSSL_NO_SRP\n if (!SSL_CTX_SRP_CTX_init(ret))\n goto err;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n# ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO\n# define eng_strx(x) #x\n# define eng_str(x) eng_strx(x)\n {\n ENGINE *eng;\n eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n if (!eng) {\n ERR_clear_error();\n ENGINE_load_builtin_engines();\n eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n }\n if (!eng || !SSL_CTX_set_client_cert_engine(ret, eng))\n ERR_clear_error();\n }\n# endif\n#endif\n ret->options |= SSL_OP_LEGACY_SERVER_CONNECT;\n ret->options |= SSL_OP_NO_COMPRESSION;\n ret->ext.status_type = TLSEXT_STATUSTYPE_nothing;\n ret->max_early_data = SSL3_RT_MAX_PLAIN_LENGTH;\n return ret;\n err:\n SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n err2:\n SSL_CTX_free(ret);\n return NULL;\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)\n{\n OPENSSL_LHASH *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)\n goto err0;\n if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n goto err1;\n ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);\n ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);\n ret->num_nodes = MIN_NODES / 2;\n ret->num_alloc_nodes = MIN_NODES;\n ret->pmax = MIN_NODES / 2;\n ret->up_load = UP_LOAD;\n ret->down_load = DOWN_LOAD;\n return (ret);\n err1:\n OPENSSL_free(ret);\n err0:\n return (NULL);\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n BIO_free_all(s->rbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n int i;\n if (a == NULL)\n return;\n CRYPTO_DOWN_REF(&a->references, &i, a->lock);\n REF_PRINT_COUNT("SSL_CTX", a);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(a->param);\n dane_ctx_final(&a->dane);\n if (a->sessions != NULL)\n SSL_CTX_flush_sessions(a, 0);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n lh_SSL_SESSION_free(a->sessions);\n X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n CTLOG_STORE_free(a->ctlog_store);\n#endif\n sk_SSL_CIPHER_free(a->cipher_list);\n sk_SSL_CIPHER_free(a->cipher_list_by_id);\n ssl_cert_free(a->cert);\n sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n sk_X509_pop_free(a->extra_certs, X509_free);\n a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(a->ext.ecpointformats);\n OPENSSL_free(a->ext.supportedgroups);\n#endif\n OPENSSL_free(a->ext.alpn);\n CRYPTO_THREAD_lock_free(a->lock);\n OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n unsigned long i;\n TIMEOUT_PARAM tp;\n tp.ctx = s;\n tp.cache = s->sessions;\n if (tp.cache == NULL)\n return;\n tp.time = t;\n CRYPTO_THREAD_write_lock(s->lock);\n i = lh_SSL_SESSION_get_down_load(s->sessions);\n lh_SSL_SESSION_set_down_load(s->sessions, 0);\n lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n lh_SSL_SESSION_set_down_load(s->sessions, i);\n CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n OPENSSL_LH_DOALL_FUNC func,\n OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n int i;\n OPENSSL_LH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}']
|
1,627
| 0
|
https://github.com/openssl/openssl/blob/7de2b9c4afd90359e47d81a5fa70bcb8506fbf91/test/threadstest.c/#L87
|
static int test_lock(void)
{
CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();
if (!TEST_true(CRYPTO_THREAD_read_lock(lock))
|| !TEST_true(CRYPTO_THREAD_unlock(lock)))
return 0;
CRYPTO_THREAD_lock_free(lock);
return 1;
}
|
['static int test_lock(void)\n{\n CRYPTO_RWLOCK *lock = CRYPTO_THREAD_lock_new();\n if (!TEST_true(CRYPTO_THREAD_read_lock(lock))\n || !TEST_true(CRYPTO_THREAD_unlock(lock)))\n return 0;\n CRYPTO_THREAD_lock_free(lock);\n return 1;\n}', 'CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)\n{\n# ifdef USE_RWLOCK\n CRYPTO_RWLOCK *lock;\n if ((lock = OPENSSL_zalloc(sizeof(pthread_rwlock_t))) == NULL) {\n return NULL;\n }\n if (pthread_rwlock_init(lock, NULL) != 0) {\n OPENSSL_free(lock);\n return NULL;\n }\n# else\n pthread_mutexattr_t attr;\n CRYPTO_RWLOCK *lock;\n if ((lock = OPENSSL_zalloc(sizeof(pthread_mutex_t))) == NULL) {\n return NULL;\n }\n pthread_mutexattr_init(&attr);\n pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);\n if (pthread_mutex_init(lock, &attr) != 0) {\n pthread_mutexattr_destroy(&attr);\n OPENSSL_free(lock);\n return NULL;\n }\n pthread_mutexattr_destroy(&attr);\n# endif\n return lock;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)\n{\n# ifdef USE_RWLOCK\n if (pthread_rwlock_rdlock(lock) != 0)\n return 0;\n# else\n if (pthread_mutex_lock(lock) != 0)\n return 0;\n# endif\n return 1;\n}', 'int test_true(const char *file, int line, const char *s, int b)\n{\n if (b)\n return 1;\n test_fail_message(NULL, file, line, "bool", s, "true", "==", "false");\n return 0;\n}']
|
1,628
| 0
|
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int ec_field_inverse_mod_ord(const EC_GROUP *group, BIGNUM *r,\n const BIGNUM *x, BN_CTX *ctx)\n{\n BIGNUM *e = NULL;\n BN_CTX *new_ctx = NULL;\n int ret = 0;\n if (group->mont_data == NULL)\n return 0;\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)\n return 0;\n BN_CTX_start(ctx);\n if ((e = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_set_word(e, 2))\n goto err;\n if (!BN_sub(e, group->order, e))\n goto err;\n if (!BN_mod_exp_mont(r, x, e, group->order, ctx, group->mont_data))\n goto err;\n ret = 1;\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n BIGNUM *reduced = BN_CTX_get(ctx);\n if (reduced == NULL\n || !BN_nnmod(reduced, a, m, ctx)) {\n goto err;\n }\n a = reduced;\n }\n#ifdef RSAZ_ENABLED\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!bn_to_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_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("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,629
| 0
|
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int test_expmodone(void)\n{\n int ret = 0, i;\n BIGNUM *r = BN_new();\n BIGNUM *a = BN_new();\n BIGNUM *p = BN_new();\n BIGNUM *m = BN_new();\n if (!TEST_ptr(r)\n || !TEST_ptr(a)\n || !TEST_ptr(p)\n || !TEST_ptr(p)\n || !TEST_ptr(m)\n || !TEST_true(BN_set_word(a, 1))\n || !TEST_true(BN_set_word(p, 0))\n || !TEST_true(BN_set_word(m, 1)))\n goto err;\n for (i = 0; i < 2; i++) {\n if (!TEST_true(BN_mod_exp(r, a, p, m, NULL))\n || !TEST_BN_eq_zero(r)\n || !TEST_true(BN_mod_exp_mont(r, a, p, m, NULL, NULL))\n || !TEST_BN_eq_zero(r)\n || !TEST_true(BN_mod_exp_mont_consttime(r, a, p, m, NULL, NULL))\n || !TEST_BN_eq_zero(r)\n || !TEST_true(BN_mod_exp_mont_word(r, 1, p, m, NULL, NULL))\n || !TEST_BN_eq_zero(r)\n || !TEST_true(BN_mod_exp_simple(r, a, p, m, NULL))\n || !TEST_BN_eq_zero(r)\n || !TEST_true(BN_mod_exp_recp(r, a, p, m, NULL))\n || !TEST_BN_eq_zero(r))\n goto err;\n if (i == 0)\n BN_set_negative(m, 1);\n }\n ret = 1;\n err:\n BN_free(r);\n BN_free(a);\n BN_free(p);\n BN_free(m);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n BIGNUM *reduced = BN_CTX_get(ctx);\n if (reduced == NULL\n || !BN_nnmod(reduced, a, m, ctx)) {\n goto err;\n }\n a = reduced;\n }\n#ifdef RSAZ_ENABLED\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!bn_to_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d;\n BIGNUM *val[TABLE_SIZE];\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul(d, val[0], val[0], m, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul(val[i], val[i - 1], d, m, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\n }\n if (!BN_mod_mul(r, r, val[wvalue >> 1], m, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,630
| 0
|
https://github.com/libav/libav/blob/8305041e137f4f2a49669dd588bf6ccfbbac2b58/libavcodec/aacenc.c/#L210
|
static av_cold int aac_encode_init(AVCodecContext *avctx)
{
AACEncContext *s = avctx->priv_data;
int i;
const uint8_t *sizes[2];
uint8_t grouping[AAC_MAX_CHANNELS];
int lengths[2];
avctx->frame_size = 1024;
for (i = 0; i < 16; i++)
if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i])
break;
if (i == 16) {
av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate);
return -1;
}
if (avctx->channels > AAC_MAX_CHANNELS) {
av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", avctx->channels);
return -1;
}
if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) {
av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", avctx->profile);
return -1;
}
if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n");
return -1;
}
s->samplerate_index = i;
dsputil_init(&s->dsp, avctx);
ff_mdct_init(&s->mdct1024, 11, 0, 1.0);
ff_mdct_init(&s->mdct128, 8, 0, 1.0);
ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);
ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);
ff_init_ff_sine_windows(10);
ff_init_ff_sine_windows(7);
s->chan_map = aac_chan_configs[avctx->channels-1];
s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0]));
s->cpe = av_mallocz(sizeof(ChannelElement) * s->chan_map[0]);
avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE);
avctx->extradata_size = 5;
put_audio_specific_config(avctx);
sizes[0] = swb_size_1024[i];
sizes[1] = swb_size_128[i];
lengths[0] = ff_aac_num_swb_1024[i];
lengths[1] = ff_aac_num_swb_128[i];
for (i = 0; i < s->chan_map[0]; i++)
grouping[i] = s->chan_map[i + 1] == TYPE_CPE;
ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping);
s->psypp = ff_psy_preprocess_init(avctx);
s->coder = &ff_aac_coders[2];
s->lambda = avctx->global_quality ? avctx->global_quality : 120;
ff_aac_tableinit();
return 0;
}
|
['static av_cold int aac_encode_init(AVCodecContext *avctx)\n{\n AACEncContext *s = avctx->priv_data;\n int i;\n const uint8_t *sizes[2];\n uint8_t grouping[AAC_MAX_CHANNELS];\n int lengths[2];\n avctx->frame_size = 1024;\n for (i = 0; i < 16; i++)\n if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i])\n break;\n if (i == 16) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\\n", avctx->sample_rate);\n return -1;\n }\n if (avctx->channels > AAC_MAX_CHANNELS) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\\n", avctx->channels);\n return -1;\n }\n if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\\n", avctx->profile);\n return -1;\n }\n if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) {\n av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\\n");\n return -1;\n }\n s->samplerate_index = i;\n dsputil_init(&s->dsp, avctx);\n ff_mdct_init(&s->mdct1024, 11, 0, 1.0);\n ff_mdct_init(&s->mdct128, 8, 0, 1.0);\n ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024);\n ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128);\n ff_init_ff_sine_windows(10);\n ff_init_ff_sine_windows(7);\n s->chan_map = aac_chan_configs[avctx->channels-1];\n s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0]));\n s->cpe = av_mallocz(sizeof(ChannelElement) * s->chan_map[0]);\n avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE);\n avctx->extradata_size = 5;\n put_audio_specific_config(avctx);\n sizes[0] = swb_size_1024[i];\n sizes[1] = swb_size_128[i];\n lengths[0] = ff_aac_num_swb_1024[i];\n lengths[1] = ff_aac_num_swb_128[i];\n for (i = 0; i < s->chan_map[0]; i++)\n grouping[i] = s->chan_map[i + 1] == TYPE_CPE;\n ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping);\n s->psypp = ff_psy_preprocess_init(avctx);\n s->coder = &ff_aac_coders[2];\n s->lambda = avctx->global_quality ? avctx->global_quality : 120;\n ff_aac_tableinit();\n return 0;\n}']
|
1,631
| 0
|
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/crypto/hmac/hmac.c/#L130
|
HMAC_CTX *HMAC_CTX_new(void)
{
HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(HMAC_CTX));
if (ctx != NULL) {
if (!HMAC_CTX_reset(ctx)) {
HMAC_CTX_free(ctx);
return NULL;
}
}
return ctx;
}
|
['HMAC_CTX *HMAC_CTX_new(void)\n{\n HMAC_CTX *ctx = OPENSSL_zalloc(sizeof(HMAC_CTX));\n if (ctx != NULL) {\n if (!HMAC_CTX_reset(ctx)) {\n HMAC_CTX_free(ctx);\n return NULL;\n }\n }\n return ctx;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,632
| 0
|
https://github.com/libav/libav/blob/6aa4e88106a554cef1d2294bb0a18b8f843032ef/libavcodec/bgmc.c/#L470
|
int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status)
{
*cf_lut = av_malloc(sizeof(*cf_lut) * LUT_BUFF * 16 * LUT_SIZE);
*cf_lut_status = av_malloc(sizeof(*cf_lut_status) * LUT_BUFF);
if (!cf_lut || !cf_lut_status) {
ff_bgmc_end(cf_lut, cf_lut_status);
av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n");
return AVERROR(ENOMEM);
} else {
memset(*cf_lut_status, -1, sizeof(*cf_lut_status) * LUT_BUFF);
}
return 0;
}
|
['int ff_bgmc_init(AVCodecContext *avctx, uint8_t **cf_lut, int **cf_lut_status)\n{\n *cf_lut = av_malloc(sizeof(*cf_lut) * LUT_BUFF * 16 * LUT_SIZE);\n *cf_lut_status = av_malloc(sizeof(*cf_lut_status) * LUT_BUFF);\n if (!cf_lut || !cf_lut_status) {\n ff_bgmc_end(cf_lut, cf_lut_status);\n av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\\n");\n return AVERROR(ENOMEM);\n } else {\n memset(*cf_lut_status, -1, sizeof(*cf_lut_status) * LUT_BUFF);\n }\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n assert(size);\n if (size > (INT_MAX-32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,633
| 0
|
https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/mpegaudiodec.c/#L867
|
static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
int *dither_state, OUT_INT *samples, int incr)
{
register const MPA_INT *w, *w2, *p;
int j;
OUT_INT *samples2;
#if CONFIG_FLOAT
float sum, sum2;
#elif FRAC_BITS <= 15
int sum, sum2;
#else
int64_t sum, sum2;
#endif
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
}
|
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}']
|
1,634
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L237
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['static int decode_seq_header(AVSContext *h)\n{\n int frame_rate_code;\n int width, height;\n h->profile = bitstream_read(&h->bc, 8);\n h->level = bitstream_read(&h->bc, 8);\n bitstream_skip(&h->bc, 1);\n width = bitstream_read(&h->bc, 14);\n height = bitstream_read(&h->bc, 14);\n if ((h->width || h->height) && (h->width != width || h->height != height)) {\n avpriv_report_missing_feature(h->avctx,\n "Width/height changing in CAVS");\n return AVERROR_PATCHWELCOME;\n }\n h->width = width;\n h->height = height;\n bitstream_skip(&h->bc, 2);\n bitstream_skip(&h->bc, 3);\n h->aspect_ratio = bitstream_read(&h->bc, 4);\n frame_rate_code = bitstream_read(&h->bc, 4);\n bitstream_skip(&h->bc, 18);\n bitstream_skip(&h->bc, 1);\n bitstream_skip(&h->bc, 12);\n h->low_delay = bitstream_read_bit(&h->bc);\n h->mb_width = (h->width + 15) >> 4;\n h->mb_height = (h->height + 15) >> 4;\n h->avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_code];\n h->avctx->width = h->width;\n h->avctx->height = h->height;\n if (!h->top_qp)\n ff_cavs_init_top_lines(h);\n return 0;\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
1,635
| 0
|
https://github.com/openssl/openssl/blob/27a3d9f9aa1ca6137ffd13a23775709c6f1ef567/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int\tBN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const int p[], BN_CTX *ctx)\n\t{\n\tint ret = 0, i, n;\n\tBIGNUM *u;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (BN_is_zero(b))\n\t\treturn(BN_one(r));\n\tif (BN_abs_is_word(b, 1))\n\t\treturn (BN_copy(r, a) != NULL);\n\tBN_CTX_start(ctx);\n\tif ((u = BN_CTX_get(ctx)) == NULL) goto err;\n\tif (!BN_GF2m_mod_arr(u, a, p)) goto err;\n\tn = BN_num_bits(b) - 1;\n\tfor (i = n - 1; i >= 0; i--)\n\t\t{\n\t\tif (!BN_GF2m_mod_sqr_arr(u, u, p, ctx)) goto err;\n\t\tif (BN_is_bit_set(b, i))\n\t\t\t{\n\t\t\tif (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx)) goto err;\n\t\t\t}\n\t\t}\n\tif (!BN_copy(r, u)) goto err;\n\tbn_check_top(r);\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int\tBN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[], BN_CTX *ctx)\n\t{\n\tint i, ret = 0;\n\tBIGNUM *s;\n\tbn_check_top(a);\n\tBN_CTX_start(ctx);\n\tif ((s = BN_CTX_get(ctx)) == NULL) return 0;\n\tif (!bn_wexpand(s, 2 * a->top)) goto err;\n\tfor (i = a->top - 1; i >= 0; i--)\n\t\t{\n\t\ts->d[2*i+1] = SQR1(a->d[i]);\n\t\ts->d[2*i ] = SQR0(a->d[i]);\n\t\t}\n\ts->top = 2 * a->top;\n\tbn_correct_top(s);\n\tif (!BN_GF2m_mod_arr(r, s, p)) goto err;\n\tbn_check_top(r);\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,636
| 0
|
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/lhash/lhash.c/#L122
|
void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return NULL;
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return ret;
}
|
['static int execute_test_session(int maxprot, int use_int_cache,\n int use_ext_cache)\n{\n SSL_CTX *sctx = NULL, *cctx = NULL;\n SSL *serverssl1 = NULL, *clientssl1 = NULL;\n SSL *serverssl2 = NULL, *clientssl2 = NULL;\n# ifndef OPENSSL_NO_TLS1_1\n SSL *serverssl3 = NULL, *clientssl3 = NULL;\n# endif\n SSL_SESSION *sess1 = NULL, *sess2 = NULL;\n int testresult = 0;\n new_called = remove_called = 0;\n if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),\n TLS_client_method(), &sctx,\n &cctx, cert, privkey)))\n return 0;\n SSL_CTX_set_min_proto_version(cctx, maxprot);\n SSL_CTX_set_max_proto_version(cctx, maxprot);\n if (use_ext_cache) {\n SSL_CTX_sess_set_new_cb(cctx, new_session_cb);\n SSL_CTX_sess_set_remove_cb(cctx, remove_session_cb);\n }\n if (use_int_cache) {\n SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);\n } else {\n SSL_CTX_set_session_cache_mode(cctx,\n SSL_SESS_CACHE_CLIENT\n | SSL_SESS_CACHE_NO_INTERNAL_STORE);\n }\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,\n NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl1, clientssl1,\n SSL_ERROR_NONE))\n || !TEST_ptr(sess1 = SSL_get1_session(clientssl1)))\n goto end;\n if (use_int_cache && !TEST_false(SSL_CTX_add_session(cctx, sess1)))\n goto end;\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 1) || !TEST_int_eq(remove_called, 0)))\n goto end;\n new_called = remove_called = 0;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl2,\n &clientssl2, NULL, NULL))\n || !TEST_true(SSL_set_session(clientssl2, sess1))\n || !TEST_true(create_ssl_connection(serverssl2, clientssl2,\n SSL_ERROR_NONE))\n || !TEST_true(SSL_session_reused(clientssl2)))\n goto end;\n if (maxprot == TLS1_3_VERSION) {\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 1)\n || !TEST_int_eq(remove_called, 1)))\n goto end;\n } else {\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 0)\n || !TEST_int_eq(remove_called, 0)))\n goto end;\n }\n SSL_SESSION_free(sess1);\n if (!TEST_ptr(sess1 = SSL_get1_session(clientssl2)))\n goto end;\n shutdown_ssl_connection(serverssl2, clientssl2);\n serverssl2 = clientssl2 = NULL;\n new_called = remove_called = 0;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl2,\n &clientssl2, NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl2, clientssl2,\n SSL_ERROR_NONE)))\n goto end;\n if (!TEST_ptr(sess2 = SSL_get1_session(clientssl2)))\n goto end;\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 1) || !TEST_int_eq(remove_called, 0)))\n goto end;\n new_called = remove_called = 0;\n if (!TEST_true(SSL_set_session(clientssl2, sess1)))\n goto end;\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 0) || !TEST_int_eq(remove_called, 1)))\n goto end;\n if (!TEST_ptr_eq(SSL_get_session(clientssl2), sess1))\n goto end;\n if (use_int_cache) {\n if (!TEST_true(SSL_CTX_add_session(cctx, sess2))\n || !TEST_true(SSL_CTX_remove_session(cctx, sess2)))\n goto end;\n }\n new_called = remove_called = 0;\n if (!TEST_false(SSL_CTX_remove_session(cctx, sess2)))\n goto end;\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 0) || !TEST_int_eq(remove_called, 1)))\n goto end;\n# if !defined(OPENSSL_NO_TLS1_1)\n new_called = remove_called = 0;\n SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl3,\n &clientssl3, NULL, NULL))\n || !TEST_true(SSL_set_session(clientssl3, sess1))\n || !TEST_false(create_ssl_connection(serverssl3, clientssl3,\n SSL_ERROR_NONE)))\n goto end;\n if (use_ext_cache\n && (!TEST_int_eq(new_called, 0) || !TEST_int_eq(remove_called, 1)))\n goto end;\n if (use_int_cache && !TEST_true(SSL_CTX_add_session(cctx, sess2)))\n goto end;\n# endif\n if (use_ext_cache) {\n SSL_CTX_sess_set_new_cb(cctx, NULL);\n SSL_CTX_sess_set_remove_cb(cctx, NULL);\n SSL_CTX_sess_set_new_cb(sctx, new_session_cb);\n SSL_CTX_sess_set_remove_cb(sctx, remove_session_cb);\n SSL_CTX_sess_set_get_cb(sctx, get_session_cb);\n get_sess_val = NULL;\n }\n SSL_CTX_set_session_cache_mode(cctx, 0);\n if (!use_int_cache)\n SSL_CTX_set_session_cache_mode(sctx,\n SSL_SESS_CACHE_SERVER\n | SSL_SESS_CACHE_NO_INTERNAL_STORE);\n SSL_free(serverssl1);\n SSL_free(clientssl1);\n serverssl1 = clientssl1 = NULL;\n SSL_free(serverssl2);\n SSL_free(clientssl2);\n serverssl2 = clientssl2 = NULL;\n SSL_SESSION_free(sess1);\n sess1 = NULL;\n SSL_SESSION_free(sess2);\n sess2 = NULL;\n SSL_CTX_set_max_proto_version(sctx, maxprot);\n SSL_CTX_set_options(sctx, SSL_OP_NO_TICKET);\n new_called = remove_called = get_called = 0;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,\n NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl1, clientssl1,\n SSL_ERROR_NONE))\n || !TEST_ptr(sess1 = SSL_get1_session(clientssl1))\n || !TEST_ptr(sess2 = SSL_get1_session(serverssl1)))\n goto end;\n if (use_int_cache && !TEST_false(SSL_CTX_add_session(sctx, sess2)))\n goto end;\n if (use_ext_cache) {\n SSL_SESSION *tmp = sess2;\n if (!TEST_int_eq(new_called, 1)\n || !TEST_int_eq(remove_called, 0)\n || !TEST_int_eq(get_called, 0))\n goto end;\n if (use_int_cache) {\n if (!TEST_ptr(tmp = SSL_SESSION_dup(sess2))\n || !TEST_true(SSL_CTX_remove_session(sctx, sess2)))\n goto end;\n SSL_SESSION_free(sess2);\n }\n sess2 = tmp;\n }\n new_called = remove_called = get_called = 0;\n get_sess_val = sess2;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl2,\n &clientssl2, NULL, NULL))\n || !TEST_true(SSL_set_session(clientssl2, sess1))\n || !TEST_true(create_ssl_connection(serverssl2, clientssl2,\n SSL_ERROR_NONE))\n || !TEST_true(SSL_session_reused(clientssl2)))\n goto end;\n if (use_ext_cache) {\n if (!TEST_int_eq(new_called, 0)\n || !TEST_int_eq(remove_called, 0))\n goto end;\n if (maxprot == TLS1_3_VERSION) {\n if (!TEST_int_eq(get_called, 0))\n goto end;\n } else {\n if (!TEST_int_eq(get_called, 1))\n goto end;\n }\n }\n testresult = 1;\n end:\n SSL_free(serverssl1);\n SSL_free(clientssl1);\n SSL_free(serverssl2);\n SSL_free(clientssl2);\n# ifndef OPENSSL_NO_TLS1_1\n SSL_free(serverssl3);\n SSL_free(clientssl3);\n# endif\n SSL_SESSION_free(sess1);\n SSL_SESSION_free(sess2);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl != NULL)\n serverssl = *sssl;\n else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n goto error;\n if (*cssl != NULL)\n clientssl = *cssl;\n else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n goto error;\n if (SSL_is_dtls(clientssl)) {\n if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n goto error;\n } else {\n if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n goto error;\n }\n if (s_to_c_fbio != NULL\n && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n goto error;\n if (c_to_s_fbio != NULL\n && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n goto error;\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL)\n goto err;\n if (RAND_get_rand_method() == RAND_OpenSSL()) {\n s->drbg = RAND_DRBG_new(NID_aes_128_ctr, RAND_DRBG_FLAG_CTR_USE_DF,\n RAND_DRBG_get0_global());\n if (s->drbg == NULL\n || RAND_DRBG_instantiate(s->drbg, NULL, 0) == 0) {\n CRYPTO_THREAD_lock_free(s->lock);\n goto err;\n }\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->references = 1;\n s->max_early_data = ctx->max_early_data;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof s->sid_ctx))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'int SSL_set_session(SSL *s, SSL_SESSION *session)\n{\n ssl_clear_bad_session(s);\n if (s->ctx->method != s->method) {\n if (!SSL_set_ssl_method(s, s->ctx->method))\n return 0;\n }\n if (session != NULL) {\n SSL_SESSION_up_ref(session);\n s->verify_result = session->verify_result;\n }\n SSL_SESSION_free(s->session);\n s->session = session;\n return 1;\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return 1;\n } else\n return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return NULL;\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return ret;\n}']
|
1,637
| 0
|
https://gitlab.com/libtiff/libtiff/blob/69ce2652ef2feae25a4569eb57b837dde0a1bd71/libtiff/tif_swab.c/#L111
|
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++;
}
}
|
['static TIFF* openSrcImage (char **imageSpec)\n{\n\tTIFF *tif;\n\tchar *fn = *imageSpec;\n\t*imageSpec = strchr (fn, comma);\n\tif (*imageSpec) {\n\t\t**imageSpec = \'\\0\';\n\t\ttif = TIFFOpen (fn, "r");\n\t\tif (!(*imageSpec)[1]) {*imageSpec = NULL; return tif;}\n\t\tif (tif) {\n\t\t\t**imageSpec = comma;\n\t\t\tif (!nextSrcImage(tif, imageSpec)) {\n\t\t\t\tTIFFClose (tif);\n\t\t\t\ttif = NULL;\n\t\t\t}\n\t\t}\n\t}else\n\t\ttif = TIFFOpen (fn, "r");\n\treturn tif;\n}', 'static int nextSrcImage (TIFF *tif, char **imageSpec)\n{\n\tif (**imageSpec == comma) {\n\t\tchar *start = *imageSpec + 1;\n\t\ttdir_t nextImage = (tdir_t)strtol(start, imageSpec, 0);\n\t\tif (start == *imageSpec) nextImage = TIFFCurrentDirectory (tif);\n\t\tif (**imageSpec)\n\t\t{\n\t\t\tif (**imageSpec == comma) {\n\t\t\t\tif ((*imageSpec)[1] == \'\\0\') *imageSpec = NULL;\n\t\t\t}else{\n\t\t\t\tfprintf (stderr,\n\t\t\t\t "Expected a %c separated image # list after %s\\n",\n\t\t\t\t comma, TIFFFileName (tif));\n\t\t\t\texit (-4);\n\t\t\t}\n\t\t}\n\t\tif (TIFFSetDirectory (tif, nextImage)) return 1;\n\t\tfprintf (stderr, "%s%c%d not found!\\n",\n\t\t TIFFFileName(tif), comma, (int) nextImage);\n\t}\n\treturn 0;\n}', 'void\nTIFFClose(TIFF* tif)\n{\n\tTIFFCloseProc closeproc = tif->tif_closeproc;\n\tthandle_t fd = tif->tif_clientdata;\n\tTIFFCleanup(tif);\n\t(void) (*closeproc)(fd);\n}', 'void\nTIFFCleanup(TIFF* tif)\n{\n\tif (tif->tif_mode != O_RDONLY)\n\t\tTIFFFlush(tif);\n\t(*tif->tif_cleanup)(tif);\n\tTIFFFreeDirectory(tif);\n\tif (tif->tif_dirlist)\n\t\t_TIFFfree(tif->tif_dirlist);\n\twhile( tif->tif_clientinfo )\n\t{\n\t\tTIFFClientInfoLink *psLink = tif->tif_clientinfo;\n\t\ttif->tif_clientinfo = psLink->next;\n\t\t_TIFFfree( psLink->name );\n\t\t_TIFFfree( psLink );\n\t}\n\tif (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))\n\t\t_TIFFfree(tif->tif_rawdata);\n\tif (isMapped(tif))\n\t\tTIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size);\n\tif (tif->tif_fields && tif->tif_nfields > 0) {\n\t\tuint32 i;\n\t\tfor (i = 0; i < tif->tif_nfields; i++) {\n\t\t\tTIFFField *fld = tif->tif_fields[i];\n\t\t\tif (fld->field_bit == FIELD_CUSTOM &&\n\t\t\t strncmp("Tag ", fld->field_name, 4) == 0) {\n\t\t\t\t_TIFFfree(fld->field_name);\n\t\t\t\t_TIFFfree(fld);\n\t\t\t}\n\t\t}\n\t\t_TIFFfree(tif->tif_fields);\n\t}\n if (tif->tif_nfieldscompat > 0) {\n uint32 i;\n for (i = 0; i < tif->tif_nfieldscompat; i++) {\n if (tif->tif_fieldscompat[i].allocated_size)\n _TIFFfree(tif->tif_fieldscompat[i].fields);\n }\n _TIFFfree(tif->tif_fieldscompat);\n }\n\t_TIFFfree(tif);\n}', 'int\nTIFFFlush(TIFF* tif)\n{\n if( tif->tif_mode == O_RDONLY )\n return 1;\n if (!TIFFFlushData(tif))\n return (0);\n if( (tif->tif_flags & TIFF_DIRTYSTRIP)\n && !(tif->tif_flags & TIFF_DIRTYDIRECT)\n && tif->tif_mode == O_RDWR )\n {\n if( TIFFForceStrileArrayWriting(tif) )\n return 1;\n }\n if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))\n && !TIFFRewriteDirectory(tif))\n return (0);\n return (1);\n}', 'int\nTIFFRewriteDirectory( TIFF *tif )\n{\n\tstatic const char module[] = "TIFFRewriteDirectory";\n\tif( tif->tif_diroff == 0 )\n\t\treturn TIFFWriteDirectory( tif );\n\tif (!(tif->tif_flags&TIFF_BIGTIFF))\n\t{\n\t\tif (tif->tif_header.classic.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.classic.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,4,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.classic.tiff_diroff),4))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint32 nextdir;\n\t\t\tnextdir = tif->tif_header.classic.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint32 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t !ReadOK(tif, &dircount, 2)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabShort(&dircount);\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 4)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint32 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t nextdir+2+dircount*12, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 4)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\telse\n\t{\n\t\tif (tif->tif_header.big.tiff_diroff == tif->tif_diroff)\n\t\t{\n\t\t\ttif->tif_header.big.tiff_diroff = 0;\n\t\t\ttif->tif_diroff = 0;\n\t\t\tTIFFSeekFile(tif,8,SEEK_SET);\n\t\t\tif (!WriteOK(tif, &(tif->tif_header.big.tiff_diroff),8))\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n\t\t\t\t "Error updating TIFF header");\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tuint64 nextdir;\n\t\t\tnextdir = tif->tif_header.big.tiff_diroff;\n\t\t\twhile(1) {\n\t\t\t\tuint64 dircount64;\n\t\t\t\tuint16 dircount;\n\t\t\t\tuint64 nextnextdir;\n\t\t\t\tif (!SeekOK(tif, nextdir) ||\n\t\t\t\t !ReadOK(tif, &dircount64, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory count");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&dircount64);\n\t\t\t\tif (dircount64>0xFFFF)\n\t\t\t\t{\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Sanity check on tag count failed, likely corrupt TIFF");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tdircount=(uint16)dircount64;\n\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\tif (!ReadOK(tif, &nextnextdir, 8)) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Error fetching directory link");\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (tif->tif_flags & TIFF_SWAB)\n\t\t\t\t\tTIFFSwabLong8(&nextnextdir);\n\t\t\t\tif (nextnextdir==tif->tif_diroff)\n\t\t\t\t{\n\t\t\t\t\tuint64 m;\n\t\t\t\t\tm=0;\n\t\t\t\t\t(void) TIFFSeekFile(tif,\n\t\t\t\t\t nextdir+8+dircount*20, SEEK_SET);\n\t\t\t\t\tif (!WriteOK(tif, &m, 8)) {\n\t\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t\t "Error writing directory link");\n\t\t\t\t\t\treturn (0);\n\t\t\t\t\t}\n\t\t\t\t\ttif->tif_diroff=0;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tnextdir=nextnextdir;\n\t\t\t}\n\t\t}\n\t}\n\treturn TIFFWriteDirectory( tif );\n}', 'int\nTIFFWriteDirectory(TIFF* tif)\n{\n\treturn TIFFWriteDirectorySec(tif,TRUE,TRUE,NULL);\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_p))\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_p))\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_p != NULL &&\n !TIFFWriteDirectoryTagLongLong8Array(tif,&ndir,dir,TIFFTAG_STRIPOFFSETS,tif->tif_dir.td_nstrips,tif->tif_dir.td_stripoffset_p))\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_p))\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\tTIFFErrorExt(tif->tif_clientdata,module,\n\t\t\t\t\t\t\t\t "Cannot write tag %d (%s)",\n\t\t\t\t\t\t\t\t TIFFFieldTag(o),\n o->field_name ? o->field_name : "unknown");\n\t\t\t\t\t\t\t\tgoto bad;\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\nTIFFWriteDirectoryTagSampleformatArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, double* value)\n{\n\tstatic const char module[] = "TIFFWriteDirectoryTagSampleformatArray";\n\tvoid* conv;\n\tuint32 i;\n\tint ok;\n\tconv = _TIFFmalloc(count*sizeof(double));\n\tif (conv == NULL)\n\t{\n\t\tTIFFErrorExt(tif->tif_clientdata, module, "Out of memory");\n\t\treturn (0);\n\t}\n\tswitch (tif->tif_dir.td_sampleformat)\n\t{\n\t\tcase SAMPLEFORMAT_IEEEFP:\n\t\t\tif (tif->tif_dir.td_bitspersample<=32)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((float*)conv)[i] = _TIFFClampDoubleToFloat(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagFloatArray(tif,ndir,dir,tag,count,(float*)conv);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tok = TIFFWriteDirectoryTagDoubleArray(tif,ndir,dir,tag,count,value);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SAMPLEFORMAT_INT:\n\t\t\tif (tif->tif_dir.td_bitspersample<=8)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((int8*)conv)[i] = TIFFClampDoubleToInt8(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagSbyteArray(tif,ndir,dir,tag,count,(int8*)conv);\n\t\t\t}\n\t\t\telse if (tif->tif_dir.td_bitspersample<=16)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((int16*)conv)[i] = TIFFClampDoubleToInt16(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagSshortArray(tif,ndir,dir,tag,count,(int16*)conv);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((int32*)conv)[i] = TIFFClampDoubleToInt32(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagSlongArray(tif,ndir,dir,tag,count,(int32*)conv);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SAMPLEFORMAT_UINT:\n\t\t\tif (tif->tif_dir.td_bitspersample<=8)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((uint8*)conv)[i] = TIFFClampDoubleToUInt8(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagByteArray(tif,ndir,dir,tag,count,(uint8*)conv);\n\t\t\t}\n\t\t\telse if (tif->tif_dir.td_bitspersample<=16)\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((uint16*)conv)[i] = TIFFClampDoubleToUInt16(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagShortArray(tif,ndir,dir,tag,count,(uint16*)conv);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tfor (i = 0; i < count; ++i)\n\t\t\t\t\t((uint32*)conv)[i] = TIFFClampDoubleToUInt32(value[i]);\n\t\t\t\tok = TIFFWriteDirectoryTagLongArray(tif,ndir,dir,tag,count,(uint32*)conv);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tok = 0;\n\t}\n\t_TIFFfree(conv);\n\treturn (ok);\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\nTIFFWriteDirectoryTagSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value)\n{\n\tif (dir==NULL)\n\t{\n\t\t(*ndir)++;\n\t\treturn(1);\n\t}\n\treturn(TIFFWriteDirectoryTagCheckedSlongArray(tif,ndir,dir,tag,count,value));\n}', 'static int\nTIFFWriteDirectoryTagCheckedSlongArray(TIFF* tif, uint32* ndir, TIFFDirEntry* dir, uint16 tag, uint32 count, int32* value)\n{\n\tassert(count<0x40000000);\n\tassert(sizeof(int32)==4);\n\tif (tif->tif_flags&TIFF_SWAB)\n\t\tTIFFSwabArrayOfLong((uint32*)value,count);\n\treturn(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_SLONG,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}']
|
1,638
| 0
|
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['static int dh_builtin_genparams(DH *ret, int prime_len, int generator,\n BN_GENCB *cb)\n{\n BIGNUM *t1, *t2;\n int g, ok = -1;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (!ret->p && ((ret->p = BN_new()) == NULL))\n goto err;\n if (!ret->g && ((ret->g = BN_new()) == NULL))\n goto err;\n if (generator <= 1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR);\n goto err;\n }\n if (generator == DH_GENERATOR_2) {\n if (!BN_set_word(t1, 24))\n goto err;\n if (!BN_set_word(t2, 11))\n goto err;\n g = 2;\n } else if (generator == DH_GENERATOR_5) {\n if (!BN_set_word(t1, 10))\n goto err;\n if (!BN_set_word(t2, 3))\n goto err;\n g = 5;\n } else {\n if (!BN_set_word(t1, 2))\n goto err;\n if (!BN_set_word(t2, 1))\n goto err;\n g = generator;\n }\n if (!BN_generate_prime_ex(ret->p, prime_len, 1, t1, t2, cb))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n if (!BN_set_word(ret->g, g))\n goto err;\n ok = 1;\n err:\n if (ok == -1) {\n DHerr(DH_F_DH_BUILTIN_GENPARAMS, ERR_R_BN_LIB);\n ok = 0;\n }\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return ok;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
1,639
| 0
|
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_shift.c/#L150
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i,nw,lb,rb;
BN_ULONG *t,*f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
r->neg=a->neg;
nw=n/BN_BITS2;
if (bn_wexpand(r,a->top+nw+1) == NULL) return(0);
lb=n%BN_BITS2;
rb=BN_BITS2-lb;
f=a->d;
t=r->d;
t[a->top+nw]=0;
if (lb == 0)
for (i=a->top-1; i>=0; i--)
t[nw+i]=f[i];
else
for (i=a->top-1; i>=0; i--)
{
l=f[i];
t[nw+i+1]|=(l>>rb)&BN_MASK2;
t[nw+i]=(l<<lb)&BN_MASK2;
}
memset(t,0,nw*sizeof(t[0]));
r->top=a->top+nw+1;
bn_correct_top(r);
bn_check_top(r);
return(1);
}
|
['static int run_jpake(JPAKE_CTX *alice, JPAKE_CTX *bob)\n {\n JPAKE_STEP1 alice_s1;\n JPAKE_STEP1 bob_s1;\n JPAKE_STEP2 alice_s2;\n JPAKE_STEP2 bob_s2;\n JPAKE_STEP3A alice_s3a;\n JPAKE_STEP3B bob_s3b;\n puts("A->B s1");\n JPAKE_STEP1_init(&alice_s1);\n JPAKE_STEP1_generate(&alice_s1, alice);\n if(!JPAKE_STEP1_process(bob, &alice_s1))\n\t{\n\tprintf("Bob fails to process Alice\'s step 1\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 1;\n\t}\n JPAKE_STEP1_release(&alice_s1);\n puts("B->A s1");\n JPAKE_STEP1_init(&bob_s1);\n JPAKE_STEP1_generate(&bob_s1, bob);\n if(!JPAKE_STEP1_process(alice, &bob_s1))\n\t{\n\tprintf("Alice fails to process Bob\'s step 1\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 2;\n\t}\n JPAKE_STEP1_release(&bob_s1);\n puts("A->B s2");\n JPAKE_STEP2_init(&alice_s2);\n JPAKE_STEP2_generate(&alice_s2, alice);\n if(!JPAKE_STEP2_process(bob, &alice_s2))\n\t{\n\tprintf("Bob fails to process Alice\'s step 2\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 3;\n\t}\n JPAKE_STEP2_release(&alice_s2);\n puts("B->A s2");\n JPAKE_STEP2_init(&bob_s2);\n JPAKE_STEP2_generate(&bob_s2, bob);\n if(!JPAKE_STEP2_process(alice, &bob_s2))\n\t{\n\tprintf("Alice fails to process Bob\'s step 2\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 4;\n\t}\n JPAKE_STEP2_release(&bob_s2);\n showbn("Alice\'s key", JPAKE_get_shared_key(alice));\n showbn("Bob\'s key ", JPAKE_get_shared_key(bob));\n puts("A->B s3a");\n JPAKE_STEP3A_init(&alice_s3a);\n JPAKE_STEP3A_generate(&alice_s3a, alice);\n if(!JPAKE_STEP3A_process(bob, &alice_s3a))\n\t{\n\tprintf("Bob fails to process Alice\'s step 3a\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 5;\n\t}\n JPAKE_STEP3A_release(&alice_s3a);\n puts("B->A s3b");\n JPAKE_STEP3B_init(&bob_s3b);\n JPAKE_STEP3B_generate(&bob_s3b, bob);\n if(!JPAKE_STEP3B_process(alice, &bob_s3b))\n\t{\n\tprintf("Alice fails to process Bob\'s step 3b\\n");\n\tERR_print_errors_fp(stdout);\n\treturn 6;\n\t}\n JPAKE_STEP3B_release(&bob_s3b);\n return 0;\n }', 'void JPAKE_STEP1_init(JPAKE_STEP1 *s1)\n {\n JPAKE_STEP_PART_init(&s1->p1);\n JPAKE_STEP_PART_init(&s1->p2);\n }', 'void JPAKE_STEP_PART_init(JPAKE_STEP_PART *p)\n {\n p->gx = BN_new();\n JPAKE_ZKP_init(&p->zkpx);\n }', 'static void JPAKE_ZKP_init(JPAKE_ZKP *zkp)\n {\n zkp->gr = BN_new();\n zkp->b = BN_new();\n }', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->dmax=0;\n\tret->d=NULL;\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx)\n {\n genrand(ctx);\n generate_step_part(&send->p1, ctx->xa, ctx->p.g, ctx);\n generate_step_part(&send->p2, ctx->xb, ctx->p.g, ctx);\n return 1;\n }', 'static void generate_step_part(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *g, JPAKE_CTX *ctx)\n {\n BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx);\n generate_zkp(p, x, g, ctx);\n }', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\treturn BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif (!d || !r || !val[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_nnmod(val[0],a,m,ctx))\n\t\t\tgoto err;\n\t\taa= val[0];\n\t\t}\n\telse\n\t\taa=a;\n\tif (BN_is_zero(aa))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val[i],val[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,bits,ret=0,idx,window,wvalue;\n\tsize_t top;\n \tBIGNUM *r;\n\tconst BIGNUM *aa;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tsize_t powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM *computeTemp=NULL, *am=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tr = BN_CTX_get(ctx);\n\tif (r == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*top*numPowers;\n\tif ((powerbufFree=OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n \tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(r, top, powerbuf, 0, numPowers)) goto err;\n\tcomputeTemp = BN_CTX_get(ctx);\n\tam = BN_CTX_get(ctx);\n\tif (computeTemp==NULL || am==NULL) goto err;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(am,a,m,ctx))\n\t\t\tgoto err;\n\t\taa= am;\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(am,aa,mont,ctx)) goto err;\n\tif (!BN_copy(computeTemp, am)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tfor (i=2; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(computeTemp,am,computeTemp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(computeTemp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n \tbits = ((bits+window-1)/window)*window;\n \tidx=bits-1;\n \twhile (idx >= 0)\n \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,idx--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,idx);\n \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(computeTemp, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(r,r,computeTemp,mont,ctx)) goto err;\n \t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tOPENSSL_free(powerbufFree);\n\t\t}\n \tif (am!=NULL) BN_clear(am);\n \tif (computeTemp!=NULL) BN_clear(computeTemp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i;\n\tsize_t loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp, div_n+1)) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,loop+1U)) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,div_n+1U)) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n\t{\n\tint i,nw,lb,rb;\n\tBN_ULONG *t,*f;\n\tBN_ULONG l;\n\tbn_check_top(r);\n\tbn_check_top(a);\n\tr->neg=a->neg;\n\tnw=n/BN_BITS2;\n\tif (bn_wexpand(r,a->top+nw+1) == NULL) return(0);\n\tlb=n%BN_BITS2;\n\trb=BN_BITS2-lb;\n\tf=a->d;\n\tt=r->d;\n\tt[a->top+nw]=0;\n\tif (lb == 0)\n\t\tfor (i=a->top-1; i>=0; i--)\n\t\t\tt[nw+i]=f[i];\n\telse\n\t\tfor (i=a->top-1; i>=0; i--)\n\t\t\t{\n\t\t\tl=f[i];\n\t\t\tt[nw+i+1]|=(l>>rb)&BN_MASK2;\n\t\t\tt[nw+i]=(l<<lb)&BN_MASK2;\n\t\t\t}\n\tmemset(t,0,nw*sizeof(t[0]));\n\tr->top=a->top+nw+1;\n\tbn_correct_top(r);\n\tbn_check_top(r);\n\treturn(1);\n\t}']
|
1,640
| 0
|
https://github.com/openssl/openssl/blob/fa9bb6201e1d16ba8ccab938833d140ef81a7f73/crypto/bn/bn_ctx.c/#L327
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x,\n BIGNUM *a, BIGNUM *u)\n{\n BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL\n || a == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((tmp = BN_new()) == NULL ||\n (tmp2 = BN_new()) == NULL ||\n (tmp3 = BN_new()) == NULL ||\n (K = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, g, x, N, bn_ctx))\n goto err;\n if ((k = srp_Calc_k(N, g)) == NULL)\n goto err;\n if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))\n goto err;\n if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))\n goto err;\n if (!BN_mod_mul(tmp3, u, x, N, bn_ctx))\n goto err;\n if (!BN_mod_add(tmp2, a, tmp3, N, bn_ctx))\n goto err;\n if (!BN_mod_exp(K, tmp, tmp2, N, bn_ctx))\n goto err;\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n BN_clear_free(tmp2);\n BN_clear_free(tmp3);\n BN_free(k);\n return K;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *d, *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return -1;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (d == NULL || r == NULL || t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,641
| 0
|
https://github.com/nginx/nginx/blob/4fe0a09942f8aed90f84c77969847980e9aadd98/src/core/ngx_string.c/#L922
|
ngx_int_t
ngx_atoi(u_char *line, size_t n)
{
ngx_int_t value, cutoff, cutlim;
if (n == 0) {
return NGX_ERROR;
}
cutoff = NGX_MAX_INT_T_VALUE / 10;
cutlim = NGX_MAX_INT_T_VALUE % 10;
for (value = 0; n--; line++) {
if (*line < '0' || *line > '9') {
return NGX_ERROR;
}
if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {
return NGX_ERROR;
}
value = value * 10 + (*line - '0');
}
return value;
}
|
['static char *\nngx_http_rewrite_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n ngx_http_rewrite_loc_conf_t *lcf = conf;\n ngx_int_t index;\n ngx_str_t *value;\n ngx_http_variable_t *v;\n ngx_http_script_var_code_t *vcode;\n ngx_http_script_var_handler_code_t *vhcode;\n value = cf->args->elts;\n if (value[1].data[0] != \'$\') {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"%V\\"", &value[1]);\n return NGX_CONF_ERROR;\n }\n value[1].len--;\n value[1].data++;\n v = ngx_http_add_variable(cf, &value[1], NGX_HTTP_VAR_CHANGEABLE);\n if (v == NULL) {\n return NGX_CONF_ERROR;\n }\n index = ngx_http_get_variable_index(cf, &value[1]);\n if (index == NGX_ERROR) {\n return NGX_CONF_ERROR;\n }\n if (v->get_handler == NULL\n && ngx_strncasecmp(value[1].data, (u_char *) "http_", 5) != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "sent_http_", 10) != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "upstream_http_", 14) != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "cookie_", 7) != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "upstream_cookie_", 16)\n != 0\n && ngx_strncasecmp(value[1].data, (u_char *) "arg_", 4) != 0)\n {\n v->get_handler = ngx_http_rewrite_var;\n v->data = index;\n }\n if (ngx_http_rewrite_value(cf, lcf, &value[2]) != NGX_CONF_OK) {\n return NGX_CONF_ERROR;\n }\n if (v->set_handler) {\n vhcode = ngx_http_script_start_code(cf->pool, &lcf->codes,\n sizeof(ngx_http_script_var_handler_code_t));\n if (vhcode == NULL) {\n return NGX_CONF_ERROR;\n }\n vhcode->code = ngx_http_script_var_set_handler_code;\n vhcode->handler = v->set_handler;\n vhcode->data = v->data;\n return NGX_CONF_OK;\n }\n vcode = ngx_http_script_start_code(cf->pool, &lcf->codes,\n sizeof(ngx_http_script_var_code_t));\n if (vcode == NULL) {\n return NGX_CONF_ERROR;\n }\n vcode->code = ngx_http_script_set_var_code;\n vcode->index = (uintptr_t) index;\n return NGX_CONF_OK;\n}', 'ngx_http_variable_t *\nngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)\n{\n ngx_int_t rc;\n ngx_uint_t i;\n ngx_hash_key_t *key;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n if (name->len == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"$\\"");\n return NULL;\n }\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n key = cmcf->variables_keys->keys.elts;\n for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) {\n if (name->len != key[i].key.len\n || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0)\n {\n continue;\n }\n v = key[i].value;\n if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "the duplicate \\"%V\\" variable", name);\n return NULL;\n }\n return v;\n }\n v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t));\n if (v == NULL) {\n return NULL;\n }\n v->name.len = name->len;\n v->name.data = ngx_pnalloc(cf->pool, name->len);\n if (v->name.data == NULL) {\n return NULL;\n }\n ngx_strlow(v->name.data, name->data, name->len);\n v->set_handler = NULL;\n v->get_handler = NULL;\n v->data = 0;\n v->flags = flags;\n v->index = 0;\n rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0);\n if (rc == NGX_ERROR) {\n return NULL;\n }\n if (rc == NGX_BUSY) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "conflicting variable name \\"%V\\"", name);\n return NULL;\n }\n return v;\n}', 'ngx_int_t\nngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)\n{\n ngx_uint_t i;\n ngx_http_variable_t *v;\n ngx_http_core_main_conf_t *cmcf;\n if (name->len == 0) {\n ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n "invalid variable name \\"$\\"");\n return NGX_ERROR;\n }\n cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);\n v = cmcf->variables.elts;\n if (v == NULL) {\n if (ngx_array_init(&cmcf->variables, cf->pool, 4,\n sizeof(ngx_http_variable_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n } else {\n for (i = 0; i < cmcf->variables.nelts; i++) {\n if (name->len != v[i].name.len\n || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)\n {\n continue;\n }\n return i;\n }\n }\n v = ngx_array_push(&cmcf->variables);\n if (v == NULL) {\n return NGX_ERROR;\n }\n v->name.len = name->len;\n v->name.data = ngx_pnalloc(cf->pool, name->len);\n if (v->name.data == NULL) {\n return NGX_ERROR;\n }\n ngx_strlow(v->name.data, name->data, name->len);\n v->set_handler = NULL;\n v->get_handler = NULL;\n v->data = 0;\n v->flags = 0;\n v->index = cmcf->variables.nelts - 1;\n return v->index;\n}', 'static char *\nngx_http_rewrite_value(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf,\n ngx_str_t *value)\n{\n ngx_int_t n;\n ngx_http_script_compile_t sc;\n ngx_http_script_value_code_t *val;\n ngx_http_script_complex_value_code_t *complex;\n n = ngx_http_script_variables_count(value);\n if (n == 0) {\n val = ngx_http_script_start_code(cf->pool, &lcf->codes,\n sizeof(ngx_http_script_value_code_t));\n if (val == NULL) {\n return NGX_CONF_ERROR;\n }\n n = ngx_atoi(value->data, value->len);\n if (n == NGX_ERROR) {\n n = 0;\n }\n val->code = ngx_http_script_value_code;\n val->value = (uintptr_t) n;\n val->text_len = (uintptr_t) value->len;\n val->text_data = (uintptr_t) value->data;\n return NGX_CONF_OK;\n }\n complex = ngx_http_script_start_code(cf->pool, &lcf->codes,\n sizeof(ngx_http_script_complex_value_code_t));\n if (complex == NULL) {\n return NGX_CONF_ERROR;\n }\n complex->code = ngx_http_script_complex_value_code;\n complex->lengths = NULL;\n ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));\n sc.cf = cf;\n sc.source = value;\n sc.lengths = &complex->lengths;\n sc.values = &lcf->codes;\n sc.variables = n;\n sc.complete_lengths = 1;\n if (ngx_http_script_compile(&sc) != NGX_OK) {\n return NGX_CONF_ERROR;\n }\n return NGX_CONF_OK;\n}', "ngx_uint_t\nngx_http_script_variables_count(ngx_str_t *value)\n{\n ngx_uint_t i, n;\n for (n = 0, i = 0; i < value->len; i++) {\n if (value->data[i] == '$') {\n n++;\n }\n }\n return n;\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}"]
|
1,642
| 0
|
https://github.com/libav/libav/blob/ab492ca2ab105aeb24d955f3f03756bdb3139ee1/libavcodec/golomb.h/#L128
|
static inline int svq3_get_ue_golomb(GetBitContext *gb){
uint32_t buf;
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf=GET_CACHE(re, gb);
if(buf&0xAA800000){
buf >>= 32 - 8;
LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);
CLOSE_READER(re, gb);
return ff_interleaved_ue_golomb_vlc_code[buf];
}else{
int ret = 1;
do {
buf >>= 32 - 8;
LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
if (ff_interleaved_golomb_vlc_len[buf] != 9){
ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;
ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
break;
}
ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
} while (HAVE_BITS_REMAINING(re, gb));
CLOSE_READER(re, gb);
return ret - 1;
}
}
|
['static inline int svq3_get_ue_golomb(GetBitContext *gb){\n uint32_t buf;\n OPEN_READER(re, gb);\n UPDATE_CACHE(re, gb);\n buf=GET_CACHE(re, gb);\n if(buf&0xAA800000){\n buf >>= 32 - 8;\n LAST_SKIP_BITS(re, gb, ff_interleaved_golomb_vlc_len[buf]);\n CLOSE_READER(re, gb);\n return ff_interleaved_ue_golomb_vlc_code[buf];\n }else{\n int ret = 1;\n do {\n buf >>= 32 - 8;\n LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));\n if (ff_interleaved_golomb_vlc_len[buf] != 9){\n ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;\n ret |= ff_interleaved_dirac_golomb_vlc_code[buf];\n break;\n }\n ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];\n UPDATE_CACHE(re, gb);\n buf = GET_CACHE(re, gb);\n } while (HAVE_BITS_REMAINING(re, gb));\n CLOSE_READER(re, gb);\n return ret - 1;\n }\n}']
|
1,643
| 1
|
https://github.com/openssl/openssl/blob/e4cf866322a4549c55153f9f135f9dadf4d3fc31/crypto/buffer/buf_str.c/#L98
|
char *BUF_strndup(const char *str, size_t siz)
{
char *ret;
if (str == NULL)
return NULL;
siz = BUF_strnlen(str, siz);
if (siz >= INT_MAX)
return NULL;
ret = OPENSSL_malloc(siz + 1);
if (ret == NULL) {
BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE);
return NULL;
}
memcpy(ret, str, siz);
ret[siz] = '\0';
return (ret);
}
|
['static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,\n AUTHORITY_KEYID *akeyid,\n STACK_OF(CONF_VALUE)\n *extlist)\n{\n char *tmp;\n if (akeyid->keyid) {\n tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);\n X509V3_add_value("keyid", tmp, &extlist);\n OPENSSL_free(tmp);\n }\n if (akeyid->issuer)\n extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);\n if (akeyid->serial) {\n tmp = hex_to_string(akeyid->serial->data, akeyid->serial->length);\n X509V3_add_value("serial", tmp, &extlist);\n OPENSSL_free(tmp);\n }\n return extlist;\n}', 'int X509V3_add_value(const char *name, const char *value,\n STACK_OF(CONF_VALUE) **extlist)\n{\n CONF_VALUE *vtmp = NULL;\n char *tname = NULL, *tvalue = NULL;\n if (name && (tname = BUF_strdup(name)) == NULL)\n goto err;\n if (value && (tvalue = BUF_strdup(value)) == NULL)\n goto err;\n if ((vtmp = OPENSSL_malloc(sizeof(*vtmp))) == NULL)\n goto err;\n if (*extlist == NULL && (*extlist = sk_CONF_VALUE_new_null()) == NULL)\n goto err;\n vtmp->section = NULL;\n vtmp->name = tname;\n vtmp->value = tvalue;\n if (!sk_CONF_VALUE_push(*extlist, vtmp))\n goto err;\n return 1;\n err:\n X509V3err(X509V3_F_X509V3_ADD_VALUE, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(vtmp);\n OPENSSL_free(tname);\n OPENSSL_free(tvalue);\n return 0;\n}', 'char *BUF_strdup(const char *str)\n{\n if (str == NULL)\n return NULL;\n return BUF_strndup(str, strlen(str));\n}', "char *BUF_strndup(const char *str, size_t siz)\n{\n char *ret;\n if (str == NULL)\n return NULL;\n siz = BUF_strnlen(str, siz);\n if (siz >= INT_MAX)\n return NULL;\n ret = OPENSSL_malloc(siz + 1);\n if (ret == NULL) {\n BUFerr(BUF_F_BUF_STRNDUP, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n memcpy(ret, str, siz);\n ret[siz] = '\\0';\n return (ret);\n}", "size_t BUF_strnlen(const char *str, size_t maxlen)\n{\n const char *p;\n for (p = str; maxlen-- != 0 && *p != '\\0'; ++p) ;\n return p - str;\n}"]
|
1,644
| 0
|
https://github.com/libav/libav/blob/53e35fd340d75c40395e4446b76a72bb1962899b/libavformat/movenc.c/#L1094
|
static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track)
{
const char *hdlr, *descr = NULL, *hdlr_type = NULL;
int64_t pos = avio_tell(pb);
if (!track) {
hdlr = "dhlr";
hdlr_type = "url ";
descr = "DataHandler";
} else {
hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\0\0\0\0";
if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) {
hdlr_type = "vide";
descr = "VideoHandler";
} else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
hdlr_type = "soun";
descr = "SoundHandler";
} else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) {
if (track->tag == MKTAG('t','x','3','g')) hdlr_type = "sbtl";
else hdlr_type = "text";
descr = "SubtitleHandler";
} else if (track->enc->codec_tag == MKTAG('r','t','p',' ')) {
hdlr_type = "hint";
descr = "HintHandler";
}
}
avio_wb32(pb, 0);
ffio_wfourcc(pb, "hdlr");
avio_wb32(pb, 0);
avio_write(pb, hdlr, 4);
ffio_wfourcc(pb, hdlr_type);
avio_wb32(pb ,0);
avio_wb32(pb ,0);
avio_wb32(pb ,0);
if (!track || track->mode == MODE_MOV)
avio_w8(pb, strlen(descr));
avio_write(pb, descr, strlen(descr));
if (track && track->mode != MODE_MOV)
avio_w8(pb, 0);
return updateSize(pb, pos);
}
|
['static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track)\n{\n const char *hdlr, *descr = NULL, *hdlr_type = NULL;\n int64_t pos = avio_tell(pb);\n if (!track) {\n hdlr = "dhlr";\n hdlr_type = "url ";\n descr = "DataHandler";\n } else {\n hdlr = (track->mode == MODE_MOV) ? "mhlr" : "\\0\\0\\0\\0";\n if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) {\n hdlr_type = "vide";\n descr = "VideoHandler";\n } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {\n hdlr_type = "soun";\n descr = "SoundHandler";\n } else if (track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE) {\n if (track->tag == MKTAG(\'t\',\'x\',\'3\',\'g\')) hdlr_type = "sbtl";\n else hdlr_type = "text";\n descr = "SubtitleHandler";\n } else if (track->enc->codec_tag == MKTAG(\'r\',\'t\',\'p\',\' \')) {\n hdlr_type = "hint";\n descr = "HintHandler";\n }\n }\n avio_wb32(pb, 0);\n ffio_wfourcc(pb, "hdlr");\n avio_wb32(pb, 0);\n avio_write(pb, hdlr, 4);\n ffio_wfourcc(pb, hdlr_type);\n avio_wb32(pb ,0);\n avio_wb32(pb ,0);\n avio_wb32(pb ,0);\n if (!track || track->mode == MODE_MOV)\n avio_w8(pb, strlen(descr));\n avio_write(pb, descr, strlen(descr));\n if (track && track->mode != MODE_MOV)\n avio_w8(pb, 0);\n return updateSize(pb, pos);\n}', 'static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s)\n{\n avio_wl32(pb, MKTAG(s[0], s[1], s[2], s[3]));\n}']
|
1,645
| 0
|
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_mont.c/#L127
|
static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
{
BIGNUM *n;
BN_ULONG *ap, *np, *rp, n0, v, carry;
int nl, max, i;
n = &(mont->N);
nl = n->top;
if (nl == 0) {
ret->top = 0;
return 1;
}
max = (2 * nl);
if (bn_wexpand(r, max) == NULL)
return 0;
r->neg ^= n->neg;
np = n->d;
rp = r->d;
i = max - r->top;
if (i)
memset(&rp[r->top], 0, sizeof(*rp) * i);
r->top = max;
r->flags |= BN_FLG_FIXED_TOP;
n0 = mont->n0[0];
for (carry = 0, i = 0; i < nl; i++, rp++) {
v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
v = (v + carry + rp[nl]) & BN_MASK2;
carry |= (v != rp[nl]);
carry &= (v <= rp[nl]);
rp[nl] = v;
}
if (bn_wexpand(ret, nl) == NULL)
return 0;
ret->top = nl;
ret->flags |= BN_FLG_FIXED_TOP;
ret->neg = r->neg;
rp = ret->d;
ap = &(r->d[nl]);
carry -= bn_sub_words(rp, ap, np, nl);
for (i = 0; i < nl; i++) {
rp[i] = (carry & ap[i]) | (~carry & rp[i]);
ap[i] = 0;
}
return 1;
}
|
['static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return 1;\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return 0;\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n i = max - r->top;\n if (i)\n memset(&rp[r->top], 0, sizeof(*rp) * i);\n r->top = max;\n r->flags |= BN_FLG_FIXED_TOP;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return 0;\n ret->top = nl;\n ret->flags |= BN_FLG_FIXED_TOP;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n carry -= bn_sub_words(rp, ap, np, nl);\n for (i = 0; i < nl; i++) {\n rp[i] = (carry & ap[i]) | (~carry & rp[i]);\n ap[i] = 0;\n }\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,646
| 0
|
https://github.com/openssl/openssl/blob/a1099821f9937717f92464056d80f2e303a73a4d/crypto/rand/rand_lib.c/#L202
|
void RAND_add(const void *buf, int num, double randomness)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth->add != NULL)
meth->add(buf, num, randomness);
}
|
['void RAND_add(const void *buf, int num, double randomness)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth->add != NULL)\n meth->add(buf, num, randomness);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n const RAND_METHOD *tmp_meth = NULL;\n if (!RUN_ONCE(&rand_init, do_rand_init))\n return NULL;\n CRYPTO_THREAD_write_lock(rand_meth_lock);\n if (default_RAND_meth == NULL) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e;\n if ((e = ENGINE_get_default_RAND()) != NULL\n && (tmp_meth = ENGINE_get_RAND(e)) != NULL) {\n funct_ref = e;\n default_RAND_meth = tmp_meth;\n } else {\n ENGINE_finish(e);\n default_RAND_meth = &openssl_rand_meth;\n }\n#else\n default_RAND_meth = &openssl_rand_meth;\n#endif\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
|
1,647
| 0
|
https://github.com/libav/libav/blob/4ab26cb4cc9af2ab2199105aa273aa23e1f27911/libavformat/ac3dec.c/#L71
|
static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id)
{
int max_frames, first_frames = 0, frames;
uint8_t *buf, *buf2, *end;
AC3HeaderInfo hdr;
GetBitContext gbc;
enum AVCodecID codec_id = AV_CODEC_ID_AC3;
max_frames = 0;
buf = p->buf;
end = buf + p->buf_size;
for(; buf < end; buf++) {
buf2 = buf;
for(frames = 0; buf2 < end; frames++) {
init_get_bits(&gbc, buf2, 54);
if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
break;
if(buf2 + hdr.frame_size > end ||
av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
break;
if (hdr.bitstream_id > 10)
codec_id = AV_CODEC_ID_EAC3;
buf2 += hdr.frame_size;
}
max_frames = FFMAX(max_frames, frames);
if(buf == p->buf)
first_frames = frames;
}
if(codec_id != expected_codec_id) return 0;
if (first_frames >= 4) return AVPROBE_SCORE_MAX / 2 + 1;
if (max_frames) {
int pes = 0, i;
unsigned int code = -1;
#define VIDEO_ID 0x000001e0
#define AUDIO_ID 0x000001c0
for (i = 0; i<p->buf_size; i++) {
code = (code << 8) + p->buf[i];
if ((code & 0xffffff00) == 0x100) {
if ((code & 0x1f0) == VIDEO_ID) pes++;
else if((code & 0x1e0) == AUDIO_ID) pes++;
}
}
if (pes)
max_frames = (max_frames + pes - 1) / pes;
}
if (max_frames > 500) return AVPROBE_SCORE_MAX / 2;
else if (max_frames >= 4) return AVPROBE_SCORE_MAX / 4;
else if (max_frames >= 1) return 1;
else return 0;
}
|
['static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id)\n{\n int max_frames, first_frames = 0, frames;\n uint8_t *buf, *buf2, *end;\n AC3HeaderInfo hdr;\n GetBitContext gbc;\n enum AVCodecID codec_id = AV_CODEC_ID_AC3;\n max_frames = 0;\n buf = p->buf;\n end = buf + p->buf_size;\n for(; buf < end; buf++) {\n buf2 = buf;\n for(frames = 0; buf2 < end; frames++) {\n init_get_bits(&gbc, buf2, 54);\n if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)\n break;\n if(buf2 + hdr.frame_size > end ||\n av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))\n break;\n if (hdr.bitstream_id > 10)\n codec_id = AV_CODEC_ID_EAC3;\n buf2 += hdr.frame_size;\n }\n max_frames = FFMAX(max_frames, frames);\n if(buf == p->buf)\n first_frames = frames;\n }\n if(codec_id != expected_codec_id) return 0;\n if (first_frames >= 4) return AVPROBE_SCORE_MAX / 2 + 1;\n if (max_frames) {\n int pes = 0, i;\n unsigned int code = -1;\n#define VIDEO_ID 0x000001e0\n#define AUDIO_ID 0x000001c0\n for (i = 0; i<p->buf_size; i++) {\n code = (code << 8) + p->buf[i];\n if ((code & 0xffffff00) == 0x100) {\n if ((code & 0x1f0) == VIDEO_ID) pes++;\n else if((code & 0x1e0) == AUDIO_ID) pes++;\n }\n }\n if (pes)\n max_frames = (max_frames + pes - 1) / pes;\n }\n if (max_frames > 500) return AVPROBE_SCORE_MAX / 2;\n else if (max_frames >= 4) return AVPROBE_SCORE_MAX / 4;\n else if (max_frames >= 1) return 1;\n else return 0;\n}']
|
1,648
| 0
|
https://github.com/openssl/openssl/blob/77fa04a9bca6686b7123bdbe80c4dd4c2a3cc8cb/apps/ca.c/#L2137
|
static int do_revoke(X509 *x509, TXT_DB *db)
{
ASN1_UTCTIME *tm=NULL;
char *row[DB_NUMBER],**rrow,**irow;
int ok=-1,i;
for (i=0; i<DB_NUMBER; i++)
row[i]=NULL;
row[DB_name]=X509_NAME_oneline(x509->cert_info->subject,NULL,0);
row[DB_serial]=BN_bn2hex(ASN1_INTEGER_to_BN(x509->cert_info->serialNumber,NULL));
if ((row[DB_name] == NULL) || (row[DB_serial] == NULL))
{
BIO_printf(bio_err,"Malloc failure\n");
goto err;
}
rrow=TXT_DB_get_by_index(db,DB_name,row);
if (rrow == NULL)
{
BIO_printf(bio_err,"Adding Entry to DB for %s\n", row[DB_name]);
row[DB_type]=(char *)Malloc(2);
tm=X509_get_notAfter(x509);
row[DB_exp_date]=(char *)Malloc(tm->length+1);
memcpy(row[DB_exp_date],tm->data,tm->length);
row[DB_exp_date][tm->length]='\0';
row[DB_rev_date]=NULL;
row[DB_file]=(char *)Malloc(8);
if ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) ||
(row[DB_file] == NULL))
{
BIO_printf(bio_err,"Malloc failure\n");
goto err;
}
strcpy(row[DB_file],"unknown");
row[DB_type][0]='V';
row[DB_type][1]='\0';
if ((irow=(char **)Malloc(sizeof(char *)*(DB_NUMBER+1))) == NULL)
{
BIO_printf(bio_err,"Malloc failure\n");
goto err;
}
for (i=0; i<DB_NUMBER; i++)
{
irow[i]=row[i];
row[i]=NULL;
}
irow[DB_NUMBER]=NULL;
if (!TXT_DB_insert(db,irow))
{
BIO_printf(bio_err,"failed to update database\n");
BIO_printf(bio_err,"TXT_DB error number %ld\n",db->error);
goto err;
}
do_revoke(x509,db);
ok=1;
goto err;
}
else if (index_serial_cmp(row,rrow))
{
BIO_printf(bio_err,"ERROR:no same serial number %s\n",
row[DB_serial]);
goto err;
}
else if (rrow[DB_type][0]=='R')
{
BIO_printf(bio_err,"ERROR:Already revoked, serial number %s\n",
row[DB_serial]);
goto err;
}
else
{
BIO_printf(bio_err,"Revoking Certificate %s.\n", rrow[DB_serial]);
tm=X509_gmtime_adj(tm,0);
rrow[DB_type][0]='R';
rrow[DB_type][1]='\0';
rrow[DB_rev_date]=(char *)Malloc(tm->length+1);
memcpy(rrow[DB_rev_date],tm->data,tm->length);
rrow[DB_rev_date][tm->length]='\0';
}
ok=1;
err:
for (i=0; i<DB_NUMBER; i++)
{
if (row[i] != NULL)
Free(row[i]);
}
ASN1_UTCTIME_free(tm);
return(ok);
}
|
['static int do_revoke(X509 *x509, TXT_DB *db)\n{\n\tASN1_UTCTIME *tm=NULL;\n\tchar *row[DB_NUMBER],**rrow,**irow;\n\tint ok=-1,i;\n\tfor (i=0; i<DB_NUMBER; i++)\n\t\trow[i]=NULL;\n\trow[DB_name]=X509_NAME_oneline(x509->cert_info->subject,NULL,0);\n\trow[DB_serial]=BN_bn2hex(ASN1_INTEGER_to_BN(x509->cert_info->serialNumber,NULL));\n\tif ((row[DB_name] == NULL) || (row[DB_serial] == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"Malloc failure\\n");\n\t\tgoto err;\n\t\t}\n\trrow=TXT_DB_get_by_index(db,DB_name,row);\n\tif (rrow == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"Adding Entry to DB for %s\\n", row[DB_name]);\n\t\trow[DB_type]=(char *)Malloc(2);\n\t\ttm=X509_get_notAfter(x509);\n\t\trow[DB_exp_date]=(char *)Malloc(tm->length+1);\n\t\tmemcpy(row[DB_exp_date],tm->data,tm->length);\n\t\trow[DB_exp_date][tm->length]=\'\\0\';\n\t\trow[DB_rev_date]=NULL;\n\t\trow[DB_file]=(char *)Malloc(8);\n\t\tif ((row[DB_type] == NULL) || (row[DB_exp_date] == NULL) ||\n\t\t\t(row[DB_file] == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Malloc failure\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tstrcpy(row[DB_file],"unknown");\n\t\trow[DB_type][0]=\'V\';\n\t\trow[DB_type][1]=\'\\0\';\n\t\tif ((irow=(char **)Malloc(sizeof(char *)*(DB_NUMBER+1))) == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Malloc failure\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tfor (i=0; i<DB_NUMBER; i++)\n\t\t\t{\n\t\t\tirow[i]=row[i];\n\t\t\trow[i]=NULL;\n\t\t\t}\n\t\tirow[DB_NUMBER]=NULL;\n\t\tif (!TXT_DB_insert(db,irow))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"failed to update database\\n");\n\t\t\tBIO_printf(bio_err,"TXT_DB error number %ld\\n",db->error);\n\t\t\tgoto err;\n\t\t\t}\n\t\tdo_revoke(x509,db);\n\t\tok=1;\n\t\tgoto err;\n\t\t}\n\telse if (index_serial_cmp(row,rrow))\n\t\t{\n\t\tBIO_printf(bio_err,"ERROR:no same serial number %s\\n",\n\t\t\t row[DB_serial]);\n\t\tgoto err;\n\t\t}\n\telse if (rrow[DB_type][0]==\'R\')\n\t\t{\n\t\tBIO_printf(bio_err,"ERROR:Already revoked, serial number %s\\n",\n\t\t\t row[DB_serial]);\n\t\tgoto err;\n\t\t}\n\telse\n\t\t{\n\t\tBIO_printf(bio_err,"Revoking Certificate %s.\\n", rrow[DB_serial]);\n\t\ttm=X509_gmtime_adj(tm,0);\n\t\trrow[DB_type][0]=\'R\';\n\t\trrow[DB_type][1]=\'\\0\';\n\t\trrow[DB_rev_date]=(char *)Malloc(tm->length+1);\n\t\tmemcpy(rrow[DB_rev_date],tm->data,tm->length);\n\t\trrow[DB_rev_date][tm->length]=\'\\0\';\n\t\t}\n\tok=1;\nerr:\n\tfor (i=0; i<DB_NUMBER; i++)\n\t\t{\n\t\tif (row[i] != NULL)\n\t\t\tFree(row[i]);\n\t\t}\n\tASN1_UTCTIME_free(tm);\n\treturn(ok);\n}', 'char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)\n\t{\n\tX509_NAME_ENTRY *ne;\nint i;\n\tint n,lold,l,l1,l2,num,j,type;\n\tconst char *s;\n\tchar *p;\n\tunsigned char *q;\n\tBUF_MEM *b=NULL;\n\tstatic char hex[17]="0123456789ABCDEF";\n\tint gs_doit[4];\n\tchar tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n\tchar ebcdic_buf[1024];\n#endif\n\tif (buf == NULL)\n\t\t{\n\t\tif ((b=BUF_MEM_new()) == NULL) goto err;\n\t\tif (!BUF_MEM_grow(b,200)) goto err;\n\t\tb->data[0]=\'\\0\';\n\t\tlen=200;\n\t\t}\n\tif (a == NULL)\n\t {\n\t if(b)\n\t\t{\n\t\tbuf=b->data;\n\t\tFree(b);\n\t\t}\n\t strncpy(buf,"NO X509_NAME",len);\n\t return buf;\n\t }\n\tlen--;\n\tl=0;\n\tfor (i=0; i<sk_X509_NAME_ENTRY_num(a->entries); i++)\n\t\t{\n\t\tne=sk_X509_NAME_ENTRY_value(a->entries,i);\n\t\tn=OBJ_obj2nid(ne->object);\n\t\tif ((n == NID_undef) || ((s=OBJ_nid2sn(n)) == NULL))\n\t\t\t{\n\t\t\ti2t_ASN1_OBJECT(tmp_buf,sizeof(tmp_buf),ne->object);\n\t\t\ts=tmp_buf;\n\t\t\t}\n\t\tl1=strlen(s);\n\t\ttype=ne->value->type;\n\t\tnum=ne->value->length;\n\t\tq=ne->value->data;\n#ifdef CHARSET_EBCDIC\n if (type == V_ASN1_GENERALSTRING ||\n\t\t type == V_ASN1_VISIBLESTRING ||\n\t\t type == V_ASN1_PRINTABLESTRING ||\n\t\t type == V_ASN1_TELETEXSTRING ||\n\t\t type == V_ASN1_VISIBLESTRING ||\n\t\t type == V_ASN1_IA5STRING) {\n ascii2ebcdic(ebcdic_buf, q,\n\t\t\t\t (num > sizeof ebcdic_buf)\n\t\t\t\t ? sizeof ebcdic_buf : num);\n q=ebcdic_buf;\n\t\t}\n#endif\n\t\tif ((type == V_ASN1_GENERALSTRING) && ((num%4) == 0))\n\t\t\t{\n\t\t\tgs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=0;\n\t\t\tfor (j=0; j<num; j++)\n\t\t\t\tif (q[j] != 0) gs_doit[j&3]=1;\n\t\t\tif (gs_doit[0]|gs_doit[1]|gs_doit[2])\n\t\t\t\tgs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tgs_doit[0]=gs_doit[1]=gs_doit[2]=0;\n\t\t\t\tgs_doit[3]=1;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\tgs_doit[0]=gs_doit[1]=gs_doit[2]=gs_doit[3]=1;\n\t\tfor (l2=j=0; j<num; j++)\n\t\t\t{\n\t\t\tif (!gs_doit[j&3]) continue;\n\t\t\tl2++;\n#ifndef CHARSET_EBCDIC\n\t\t\tif ((q[j] < \' \') || (q[j] > \'~\')) l2+=3;\n#else\n\t\t\tif ((os_toascii[q[j]] < os_toascii[\' \']) ||\n\t\t\t (os_toascii[q[j]] > os_toascii[\'~\'])) l2+=3;\n#endif\n\t\t\t}\n\t\tlold=l;\n\t\tl+=1+l1+1+l2;\n\t\tif (b != NULL)\n\t\t\t{\n\t\t\tif (!BUF_MEM_grow(b,l+1)) goto err;\n\t\t\tp= &(b->data[lold]);\n\t\t\t}\n\t\telse if (l > len)\n\t\t\t{\n\t\t\tbreak;\n\t\t\t}\n\t\telse\n\t\t\tp= &(buf[lold]);\n\t\t*(p++)=\'/\';\n\t\tmemcpy(p,s,(unsigned int)l1); p+=l1;\n\t\t*(p++)=\'=\';\n#ifndef CHARSET_EBCDIC\n\t\tq=ne->value->data;\n#endif\n\t\tfor (j=0; j<num; j++)\n\t\t\t{\n\t\t\tif (!gs_doit[j&3]) continue;\n#ifndef CHARSET_EBCDIC\n\t\t\tn=q[j];\n\t\t\tif ((n < \' \') || (n > \'~\'))\n\t\t\t\t{\n\t\t\t\t*(p++)=\'\\\\\';\n\t\t\t\t*(p++)=\'x\';\n\t\t\t\t*(p++)=hex[(n>>4)&0x0f];\n\t\t\t\t*(p++)=hex[n&0x0f];\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t*(p++)=n;\n#else\n\t\t\tn=os_toascii[q[j]];\n\t\t\tif ((n < os_toascii[\' \']) ||\n\t\t\t (n > os_toascii[\'~\']))\n\t\t\t\t{\n\t\t\t\t*(p++)=\'\\\\\';\n\t\t\t\t*(p++)=\'x\';\n\t\t\t\t*(p++)=hex[(n>>4)&0x0f];\n\t\t\t\t*(p++)=hex[n&0x0f];\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t*(p++)=q[j];\n#endif\n\t\t\t}\n\t\t*p=\'\\0\';\n\t\t}\n\tif (b != NULL)\n\t\t{\n\t\tp=b->data;\n\t\tFree(b);\n\t\t}\n\telse\n\t\tp=buf;\n\treturn(p);\nerr:\n\tX509err(X509_F_X509_NAME_ONELINE,ERR_R_MALLOC_FAILURE);\n\tif (b != NULL) BUF_MEM_free(b);\n\treturn(NULL);\n\t}']
|
1,649
| 0
|
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L342
|
static void BN_POOL_release(BN_POOL *p, unsigned int num)
{
unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;
p->used -= num;
while (num--) {
bn_check_top(p->current->vals + offset);
if (offset == 0) {
offset = BN_CTX_POOL_SIZE - 1;
p->current = p->current->prev;
} else
offset--;
}
}
|
['int bn_rsa_fips186_4_derive_prime(BIGNUM *Y, BIGNUM *X, const BIGNUM *Xin,\n const BIGNUM *r1, const BIGNUM *r2, int nlen,\n const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n int ret = 0;\n int i, imax;\n int bits = nlen >> 1;\n int checks = bn_rsa_fips186_4_prime_MR_min_checks(nlen);\n BIGNUM *tmp, *R, *r1r2x2, *y1, *r1x2;\n if (checks == 0)\n return 0;\n BN_CTX_start(ctx);\n R = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n r1r2x2 = BN_CTX_get(ctx);\n y1 = BN_CTX_get(ctx);\n r1x2 = BN_CTX_get(ctx);\n if (r1x2 == NULL)\n goto err;\n if (Xin != NULL && BN_copy(X, Xin) == NULL)\n goto err;\n if (!(BN_lshift1(r1x2, r1)\n && BN_gcd(tmp, r1x2, r2, ctx)\n && BN_is_one(tmp)\n && BN_mod_inverse(R, r2, r1x2, ctx)\n && BN_mul(R, R, r2, ctx)\n && BN_mod_inverse(tmp, r1x2, r2, ctx)\n && BN_mul(tmp, tmp, r1x2, ctx)\n && BN_sub(R, R, tmp)\n && BN_mul(r1r2x2, r1x2, r2, ctx)))\n goto err;\n if (BN_is_negative(R) && !BN_add(R, R, r1r2x2))\n goto err;\n imax = 5 * bits;\n for (;;) {\n if (Xin == NULL) {\n if (!BN_priv_rand(X, bits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto end;\n }\n if (!BN_mod_sub(Y, R, X, r1r2x2, ctx) || !BN_add(Y, Y, X))\n goto err;\n i = 0;\n for (;;) {\n if (BN_num_bits(Y) > bits) {\n if (Xin == NULL)\n break;\n else\n goto err;\n }\n BN_GENCB_call(cb, 0, 2);\n if (BN_copy(y1, Y) == NULL\n || !BN_sub_word(y1, 1)\n || !BN_gcd(tmp, y1, e, ctx))\n goto err;\n if (BN_is_one(tmp)\n && BN_is_prime_fasttest_ex(Y, checks, ctx, 1, cb))\n goto end;\n if (++i >= imax || !BN_add(Y, Y, r1r2x2))\n goto err;\n }\n }\nend:\n ret = 1;\n BN_GENCB_call(cb, 3, 0);\nerr:\n BN_clear(y1);\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n BIGNUM *a, *b, *t;\n int ret = 0;\n bn_check_top(in_a);\n bn_check_top(in_b);\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_copy(a, in_a) == NULL)\n goto err;\n if (BN_copy(b, in_b) == NULL)\n goto err;\n a->neg = 0;\n b->neg = 0;\n if (BN_cmp(a, b) < 0) {\n t = a;\n a = b;\n b = t;\n }\n t = euclid(a, b);\n if (t == NULL)\n goto err;\n if (BN_copy(r, t) == NULL)\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', '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}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'int BN_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}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (offset == 0) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
|
1,650
| 0
|
https://github.com/openssl/openssl/blob/ea32151f7b9353f8906188d007c6893704ac17bb/crypto/bn/bn_ctx.c/#L273
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,651
| 0
|
https://github.com/openssl/openssl/blob/877e8e970c3c94c43ce1db50fdbb8e9b0342b90e/crypto/bn/bn_asm.c/#L405
|
BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
{
BN_ULONG t1,t2;
int c=0;
assert(n >= 0);
if (n <= 0) return((BN_ULONG)0);
#ifndef OPENSSL_SMALL_FOOTPRINT
while (n&~3)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[1]; t2=b[1];
r[1]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[2]; t2=b[2];
r[2]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[3]; t2=b[3];
r[3]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
a+=4; b+=4; r+=4; n-=4;
}
#endif
while (n)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
a++; b++; r++; n--;
}
return(c);
}
|
['void bn_sqr_recursive(BN_ULONG *r, const BN_ULONG *a, int n2, BN_ULONG *t)\n\t{\n\tint n=n2/2;\n\tint zero,c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\n\tfprintf(stderr," bn_sqr_recursive %d * %d\\n",n2,n2);\n#endif\n\tif (n2 == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tbn_sqr_normal(r,a,4,t);\n#else\n\t\tbn_sqr_comba4(r,a);\n#endif\n\t\treturn;\n\t\t}\n\telse if (n2 == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tbn_sqr_normal(r,a,8,t);\n#else\n\t\tbn_sqr_comba8(r,a);\n#endif\n\t\treturn;\n\t\t}\n\tif (n2 < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t{\n\t\tbn_sqr_normal(r,a,n2,t);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_words(a,&(a[n]),n);\n\tzero=0;\n\tif (c1 > 0)\n\t\tbn_sub_words(t,a,&(a[n]),n);\n\telse if (c1 < 0)\n\t\tbn_sub_words(t,&(a[n]),a,n);\n\telse\n\t\tzero=1;\n\tp= &(t[n2*2]);\n\tif (!zero)\n\t\tbn_sqr_recursive(&(t[n2]),t,n,p);\n\telse\n\t\tmemset(&(t[n2]),0,n2*sizeof(BN_ULONG));\n\tbn_sqr_recursive(r,a,n,p);\n\tbn_sqr_recursive(&(r[n2]),&(a[n]),n,p);\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 < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', '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}', 'BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (n&~3)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta+=4; b+=4; r+=4; n-=4;\n\t\t}\n#endif\n\twhile (n)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta++; b++; r++; n--;\n\t\t}\n\treturn(c);\n\t}']
|
1,652
| 0
|
https://github.com/libav/libav/blob/ecf79c4d3e8baaf2f303278ef81db6f8407656bc/libavfilter/buffer.c/#L78
|
void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
if (!ref)
return;
if (!(--ref->buf->refcount))
ref->buf->free(ref->buf);
if (ref->extended_data != ref->data)
av_freep(&ref->extended_data);
av_free(ref->video);
av_free(ref->audio);
av_free(ref);
}
|
['static void end_frame(AVFilterLink *link)\n{\n ff_end_frame(link->dst->outputs[0]);\n avfilter_unref_buffer(link->cur_buf);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n if (!ref)\n return;\n if (!(--ref->buf->refcount))\n ref->buf->free(ref->buf);\n if (ref->extended_data != ref->data)\n av_freep(&ref->extended_data);\n av_free(ref->video);\n av_free(ref->audio);\n av_free(ref);\n}']
|
1,653
| 0
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
1,654
| 0
|
https://github.com/openssl/openssl/blob/f826bf779854ab9375f89a74d77f0142bf6944ae/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int print_gost_01(BIO *out, const EVP_PKEY *pkey, int indent,\n\tASN1_PCTX *pctx, int type)\n\t{\n\tint param_nid = NID_undef;\n\tif (type == 2)\n\t\t{\n\t\tBIGNUM *key;\n\t\tif (!BIO_indent(out,indent,128)) return 0;\n\t\tBIO_printf(out,"Private key: ");\n\t\tkey = gost_get0_priv_key(pkey);\n\t\tif (!key)\n\t\t\tBIO_printf(out,"<undefined)");\n\t\telse\n\t\t\tBN_print(out,key);\n\t\tBIO_printf(out,"\\n");\n\t\t}\n\tif (type >= 1)\n\t\t{\n\t\tBN_CTX *ctx = BN_CTX_new();\n\t\tBIGNUM *X,*Y;\n\t\tconst EC_POINT *pubkey;\n\t\tconst EC_GROUP *group;\n\t\tif (!ctx)\n\t\t\t{\n\t\t\tGOSTerr(GOST_F_PRINT_GOST_01,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t\t}\n\t\tBN_CTX_start(ctx);\n\t\tX = BN_CTX_get(ctx);\n\t\tY = BN_CTX_get(ctx);\n\t\tpubkey = EC_KEY_get0_public_key((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));\n\t\tgroup = EC_KEY_get0_group((EC_KEY *)EVP_PKEY_get0((EVP_PKEY *)pkey));\n\t\tif (!EC_POINT_get_affine_coordinates_GFp(group,pubkey,X,Y,ctx))\n\t\t\t{\n\t\t\tGOSTerr(GOST_F_PRINT_GOST_01,ERR_R_EC_LIB);\n\t\t\tBN_CTX_free(ctx);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif (!BIO_indent(out,indent,128)) return 0;\n\t\tBIO_printf(out,"Public key:\\n");\n\t\tif (!BIO_indent(out,indent+3,128)) return 0;\n\t\tBIO_printf(out,"X:");\n\t\tBN_print(out,X);\n\t\tBIO_printf(out,"\\n");\n\t\tBIO_indent(out,indent+3,128);\n\t\tBIO_printf(out,"Y:");\n\t\tBN_print(out,Y);\n\t\tBIO_printf(out,"\\n");\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tparam_nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(EVP_PKEY_get0((EVP_PKEY *)pkey)));\n\tif (!BIO_indent(out,indent,128)) return 0;\n\tBIO_printf(out,"Parameter set: %s\\n",OBJ_nid2ln(param_nid));\n\treturn 1;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,655
| 0
|
https://github.com/openssl/openssl/blob/c1e744b9125a883450c2239ec55ea606c618a5c0/crypto/bf/bf_skey.c/#L81
|
void BF_set_key(BF_KEY *key, int len, unsigned char *data)
{
int i;
BF_LONG *p,ri,in[2];
unsigned char *d,*end;
memcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));
p=key->P;
if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
d=data;
end= &(data[len]);
for (i=0; i<(BF_ROUNDS+2); i++)
{
ri= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
p[i]^=ri;
}
in[0]=0L;
in[1]=0L;
for (i=0; i<(BF_ROUNDS+2); i+=2)
{
BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
p=key->S;
for (i=0; i<4*256; i+=2)
{
BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
}
|
['static int test(void)\n\t{\n\tunsigned char cbc_in[40],cbc_out[40],iv[8];\n\tint i,n,err=0;\n\tBF_KEY key;\n\tBF_LONG data[2];\n\tunsigned char out[8];\n\tBF_LONG len;\n#ifdef CHARSET_EBCDIC\n\tebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));\n#endif\n\tprintf("testing blowfish in raw ecb mode\\n");\n\tfor (n=0; n<2; n++)\n\t\t{\n#ifdef CHARSET_EBCDIC\n\t\tebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));\n#endif\n\t\tBF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);\n\t\tdata[0]=bf_plain[n][0];\n\t\tdata[1]=bf_plain[n][1];\n\t\tBF_encrypt(data,&key);\n\t\tif (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_encrypt error encrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)data[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)bf_cipher[n][i]);\n\t\t\terr=1;\n\t\t\tprintf("\\n");\n\t\t\t}\n\t\tBF_decrypt(&(data[0]),&key);\n\t\tif (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_encrypt error decrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)data[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)bf_plain[n][i]);\n\t\t\tprintf("\\n");\n\t\t\terr=1;\n\t\t\t}\n\t\t}\n\tprintf("testing blowfish in ecb mode\\n");\n\tfor (n=0; n<NUM_TESTS; n++)\n\t\t{\n\t\tBF_set_key(&key,8,ecb_data[n]);\n\t\tBF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT);\n\t\tif (memcmp(&(cipher_data[n][0]),out,8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_ecb_encrypt blowfish error encrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",out[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",cipher_data[n][i]);\n\t\t\terr=1;\n\t\t\tprintf("\\n");\n\t\t\t}\n\t\tBF_ecb_encrypt(out,out,&key,BF_DECRYPT);\n\t\tif (memcmp(&(plain_data[n][0]),out,8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_ecb_encrypt error decrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",out[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",plain_data[n][i]);\n\t\t\tprintf("\\n");\n\t\t\terr=1;\n\t\t\t}\n\t\t}\n\tprintf("testing blowfish set_key\\n");\n\tfor (n=1; n<KEY_TEST_NUM; n++)\n\t\t{\n\t\tBF_set_key(&key,n,key_test);\n\t\tBF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT);\n\t\tif (memcmp(out,&(key_out[n-1][0]),8) != 0)\n\t\t\t{\n\t\t\tprintf("blowfish setkey error\\n");\n\t\t\terr=1;\n\t\t\t}\n\t\t}\n\tprintf("testing blowfish in cbc mode\\n");\n\tlen=strlen(cbc_data)+1;\n\tBF_set_key(&key,16,cbc_key);\n\tmemset(cbc_in,0,40);\n\tmemset(cbc_out,0,40);\n\tmemcpy(iv,cbc_iv,8);\n\tBF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len,\n\t\t&key,iv,BF_ENCRYPT);\n\tif (memcmp(cbc_out,cbc_ok,32) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("BF_cbc_encrypt encrypt error\\n");\n\t\tfor (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]);\n\t\t}\n\tmemcpy(iv,cbc_iv,8);\n\tBF_cbc_encrypt(cbc_out,cbc_in,len,\n\t\t&key,iv,BF_DECRYPT);\n\tif (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)\n\t\t{\n\t\tprintf("BF_cbc_encrypt decrypt error\\n");\n\t\terr=1;\n\t\t}\n\tprintf("testing blowfish in cfb64 mode\\n");\n\tBF_set_key(&key,16,cbc_key);\n\tmemset(cbc_in,0,40);\n\tmemset(cbc_out,0,40);\n\tmemcpy(iv,cbc_iv,8);\n\tn=0;\n\tBF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,\n\t\t&key,iv,&n,BF_ENCRYPT);\n\tBF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13,\n\t\t&key,iv,&n,BF_ENCRYPT);\n\tif (memcmp(cbc_out,cfb64_ok,(int)len) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("BF_cfb64_encrypt encrypt error\\n");\n\t\tfor (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);\n\t\t}\n\tn=0;\n\tmemcpy(iv,cbc_iv,8);\n\tBF_cfb64_encrypt(cbc_out,cbc_in,17,\n\t\t&key,iv,&n,BF_DECRYPT);\n\tBF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,\n\t\t&key,iv,&n,BF_DECRYPT);\n\tif (memcmp(cbc_in,cbc_data,(int)len) != 0)\n\t\t{\n\t\tprintf("BF_cfb64_encrypt decrypt error\\n");\n\t\terr=1;\n\t\t}\n\tprintf("testing blowfish in ofb64\\n");\n\tBF_set_key(&key,16,cbc_key);\n\tmemset(cbc_in,0,40);\n\tmemset(cbc_out,0,40);\n\tmemcpy(iv,cbc_iv,8);\n\tn=0;\n\tBF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n);\n\tBF_ofb64_encrypt((unsigned char *)&(cbc_data[13]),\n\t\t&(cbc_out[13]),len-13,&key,iv,&n);\n\tif (memcmp(cbc_out,ofb64_ok,(int)len) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("BF_ofb64_encrypt encrypt error\\n");\n\t\tfor (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);\n\t\t}\n\tn=0;\n\tmemcpy(iv,cbc_iv,8);\n\tBF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n);\n\tBF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n);\n\tif (memcmp(cbc_in,cbc_data,(int)len) != 0)\n\t\t{\n\t\tprintf("BF_ofb64_encrypt decrypt error\\n");\n\t\terr=1;\n\t\t}\n\treturn(err);\n\t}', 'void BF_set_key(BF_KEY *key, int len, unsigned char *data)\n\t{\n\tint i;\n\tBF_LONG *p,ri,in[2];\n\tunsigned char *d,*end;\n\tmemcpy((char *)key,(char *)&bf_init,sizeof(BF_KEY));\n\tp=key->P;\n\tif (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;\n\td=data;\n\tend= &(data[len]);\n\tfor (i=0; i<(BF_ROUNDS+2); i++)\n\t\t{\n\t\tri= *(d++);\n\t\tif (d >= end) d=data;\n\t\tri<<=8;\n\t\tri|= *(d++);\n\t\tif (d >= end) d=data;\n\t\tri<<=8;\n\t\tri|= *(d++);\n\t\tif (d >= end) d=data;\n\t\tri<<=8;\n\t\tri|= *(d++);\n\t\tif (d >= end) d=data;\n\t\tp[i]^=ri;\n\t\t}\n\tin[0]=0L;\n\tin[1]=0L;\n\tfor (i=0; i<(BF_ROUNDS+2); i+=2)\n\t\t{\n\t\tBF_encrypt(in,key);\n\t\tp[i ]=in[0];\n\t\tp[i+1]=in[1];\n\t\t}\n\tp=key->S;\n\tfor (i=0; i<4*256; i+=2)\n\t\t{\n\t\tBF_encrypt(in,key);\n\t\tp[i ]=in[0];\n\t\tp[i+1]=in[1];\n\t\t}\n\t}']
|
1,656
| 0
|
https://github.com/openssl/openssl/blob/40a706286febe0279336c96374c607daaa1b1d49/crypto/lhash/lhash.c/#L240
|
void *lh_delete(_LHASH *lh, const void *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
void *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['static long\ndtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)\n\t{\n\tunsigned char wire[DTLS1_HM_HEADER_LENGTH];\n\tunsigned long l, frag_off, frag_len;\n\tint i,al;\n\tstruct hm_header_st msg_hdr;\n\tif ((frag_len = dtls1_retrieve_buffered_fragment(s,max,ok)) || *ok)\n\t\t{\n\t\tif (*ok)\ts->init_num += frag_len;\n\t\treturn frag_len;\n\t\t}\n\ti=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,wire,\n\t\tDTLS1_HM_HEADER_LENGTH, 0);\n\tif (i <= 0)\n\t\t{\n\t\ts->rwstate=SSL_READING;\n\t\t*ok = 0;\n\t\treturn i;\n\t\t}\n\tOPENSSL_assert(i == DTLS1_HM_HEADER_LENGTH);\n\tdtls1_get_message_header(wire, &msg_hdr);\n\tif ( msg_hdr.seq != s->d1->handshake_read_seq)\n\t\treturn dtls1_process_out_of_seq_message(s, &msg_hdr, ok);\n\tl = msg_hdr.msg_len;\n\tfrag_off = msg_hdr.frag_off;\n\tfrag_len = msg_hdr.frag_len;\n\tif (!s->server && s->d1->r_msg_hdr.frag_off == 0 &&\n\t\twire[0] == SSL3_MT_HELLO_REQUEST)\n\t\t{\n\t\tif (wire[1] == 0 && wire[2] == 0 && wire[3] == 0)\n\t\t\t{\n\t\t\tif (s->msg_callback)\n\t\t\t\ts->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n\t\t\t\t\twire, DTLS1_HM_HEADER_LENGTH, s,\n\t\t\t\t\ts->msg_callback_arg);\n\t\t\ts->init_num = 0;\n\t\t\treturn dtls1_get_message_fragment(s, st1, stn,\n\t\t\t\tmax, ok);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_DTLS1_GET_MESSAGE_FRAGMENT,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif ((al=dtls1_preprocess_fragment(s,&msg_hdr,max)))\n\t\tgoto f_err;\n\ts->state=stn;\n\tif ( frag_len > 0)\n\t\t{\n\t\tunsigned char *p=(unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH;\n\t\ti=s->method->ssl_read_bytes(s,SSL3_RT_HANDSHAKE,\n\t\t\t&p[frag_off],frag_len,0);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\ts->rwstate=SSL_READING;\n\t\t\t*ok = 0;\n\t\t\treturn i;\n\t\t\t}\n\t\t}\n\telse\n\t\ti = 0;\n\tOPENSSL_assert(i == (int)frag_len);\n\t*ok = 1;\n\ts->init_num += frag_len;\n\treturn frag_len;\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\ts->init_num = 0;\n\t*ok=0;\n\treturn(-1);\n\t}', 'static int\ndtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok)\n\t{\n\tpitem *item;\n\thm_fragment *frag;\n\tint al;\n\t*ok = 0;\n\titem = pqueue_peek(s->d1->buffered_messages);\n\tif ( item == NULL)\n\t\treturn 0;\n\tfrag = (hm_fragment *)item->data;\n\tif ( s->d1->handshake_read_seq == frag->msg_header.seq)\n\t\t{\n\t\tpqueue_pop(s->d1->buffered_messages);\n\t\tal=dtls1_preprocess_fragment(s,&frag->msg_header,max);\n\t\tif (al==0)\n\t\t\t{\n\t\t\tunsigned char *p = (unsigned char *)s->init_buf->data+DTLS1_HM_HEADER_LENGTH;\n\t\t\tmemcpy(&p[frag->msg_header.frag_off],\n\t\t\t\tfrag->fragment,frag->msg_header.frag_len);\n\t\t\t}\n\t\tdtls1_hm_fragment_free(frag);\n\t\tpitem_free(item);\n\t\tif (al==0)\n\t\t\t{\n\t\t\t*ok = 1;\n\t\t\treturn frag->msg_header.frag_len;\n\t\t\t}\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\ts->init_num = 0;\n\t\t*ok = 0;\n\t\treturn -1;\n\t\t}\n\telse\n\t\treturn 0;\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\ts->method->ssl_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=lh_SSL_SESSION_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}']
|
1,657
| 0
|
https://github.com/openssl/openssl/blob/1a50eedf2a1fbb1e0e009ad616d8be678e4c6340/crypto/bn/bn_lib.c/#L291
|
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
bn_check_top(b);
if (a == b)
return a;
if (bn_wexpand(a, b->top) == NULL)
return NULL;
if (b->top > 0)
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
a->neg = b->neg;
a->top = b->top;
a->flags |= b->flags & BN_FLG_FIXED_TOP;
bn_check_top(a);
return a;
}
|
['int sm2_decrypt(const EC_KEY *key,\n const EVP_MD *digest,\n const uint8_t *ciphertext,\n size_t ciphertext_len, uint8_t *ptext_buf, size_t *ptext_len)\n{\n int rc = 0;\n int i;\n BN_CTX *ctx = NULL;\n const EC_GROUP *group = EC_KEY_get0_group(key);\n EC_POINT *C1 = NULL;\n struct SM2_Ciphertext_st *sm2_ctext = NULL;\n BIGNUM *x2 = NULL;\n BIGNUM *y2 = NULL;\n uint8_t *x2y2 = NULL;\n uint8_t *computed_C3 = NULL;\n const size_t field_size = ec_field_size(group);\n const int hash_size = EVP_MD_size(digest);\n uint8_t *msg_mask = NULL;\n const uint8_t *C2 = NULL;\n const uint8_t *C3 = NULL;\n int msg_len = 0;\n EVP_MD_CTX *hash = NULL;\n if (field_size == 0 || hash_size <= 0)\n goto done;\n memset(ptext_buf, 0xFF, *ptext_len);\n sm2_ctext = d2i_SM2_Ciphertext(NULL, &ciphertext, ciphertext_len);\n if (sm2_ctext == NULL) {\n SM2err(SM2_F_SM2_DECRYPT, SM2_R_ASN1_ERROR);\n goto done;\n }\n if (sm2_ctext->C3->length != hash_size) {\n SM2err(SM2_F_SM2_DECRYPT, SM2_R_INVALID_ENCODING);\n goto done;\n }\n C2 = sm2_ctext->C2->data;\n C3 = sm2_ctext->C3->data;\n msg_len = sm2_ctext->C2->length;\n ctx = BN_CTX_new();\n if (ctx == NULL) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n BN_CTX_start(ctx);\n x2 = BN_CTX_get(ctx);\n y2 = BN_CTX_get(ctx);\n if (y2 == NULL) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_BN_LIB);\n goto done;\n }\n msg_mask = OPENSSL_zalloc(msg_len);\n x2y2 = OPENSSL_zalloc(2 * field_size);\n computed_C3 = OPENSSL_zalloc(hash_size);\n if (msg_mask == NULL || x2y2 == NULL || computed_C3 == NULL) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n C1 = EC_POINT_new(group);\n if (C1 == NULL) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n if (!EC_POINT_set_affine_coordinates_GFp(group, C1, sm2_ctext->C1x,\n sm2_ctext->C1y, ctx)\n || !EC_POINT_mul(group, C1, NULL, C1, EC_KEY_get0_private_key(key),\n ctx)\n || !EC_POINT_get_affine_coordinates_GFp(group, C1, x2, y2, ctx)) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_EC_LIB);\n goto done;\n }\n if (BN_bn2binpad(x2, x2y2, field_size) < 0\n || BN_bn2binpad(y2, x2y2 + field_size, field_size) < 0\n || !ECDH_KDF_X9_62(msg_mask, msg_len, x2y2, 2 * field_size, NULL, 0,\n digest)) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_INTERNAL_ERROR);\n goto done;\n }\n for (i = 0; i != msg_len; ++i)\n ptext_buf[i] = C2[i] ^ msg_mask[i];\n hash = EVP_MD_CTX_new();\n if (hash == NULL) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n if (!EVP_DigestInit(hash, digest)\n || !EVP_DigestUpdate(hash, x2y2, field_size)\n || !EVP_DigestUpdate(hash, ptext_buf, msg_len)\n || !EVP_DigestUpdate(hash, x2y2 + field_size, field_size)\n || !EVP_DigestFinal(hash, computed_C3, NULL)) {\n SM2err(SM2_F_SM2_DECRYPT, ERR_R_EVP_LIB);\n goto done;\n }\n if (CRYPTO_memcmp(computed_C3, C3, hash_size) != 0) {\n SM2err(SM2_F_SM2_DECRYPT, SM2_R_INVALID_DIGEST);\n goto done;\n }\n rc = 1;\n *ptext_len = msg_len;\n done:\n if (rc == 0)\n memset(ptext_buf, 0, *ptext_len);\n OPENSSL_free(msg_mask);\n OPENSSL_free(x2y2);\n OPENSSL_free(computed_C3);\n EC_POINT_free(C1);\n BN_CTX_free(ctx);\n SM2_Ciphertext_free(sm2_ctext);\n EVP_MD_CTX_free(hash);\n return rc;\n}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n int ret = 0;\n size_t i = 0;\n BN_CTX *new_ctx = NULL;\n if ((scalar == NULL) && (num == 0)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n if (!ec_point_is_compat(r, group)) {\n ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n for (i = 0; i < num; i++) {\n if (!ec_point_is_compat(points[i], group)) {\n ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL) {\n ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (group->meth->mul != NULL)\n ret = group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n else\n ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n const EC_POINT *generator = NULL;\n EC_POINT *tmp = NULL;\n size_t totalnum;\n size_t blocksize = 0, numblocks = 0;\n size_t pre_points_per_block = 0;\n size_t i, j;\n int k;\n int r_is_inverted = 0;\n int r_is_at_infinity = 1;\n size_t *wsize = NULL;\n signed char **wNAF = NULL;\n size_t *wNAF_len = NULL;\n size_t max_len = 0;\n size_t num_val;\n EC_POINT **val = NULL;\n EC_POINT **v;\n EC_POINT ***val_sub = NULL;\n const EC_PRE_COMP *pre_comp = NULL;\n int num_scalar = 0;\n int ret = 0;\n if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) {\n if ((scalar != NULL) && (num == 0)) {\n return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);\n }\n if ((scalar == NULL) && (num == 1)) {\n return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx);\n }\n }\n if (scalar != NULL) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.ec;\n if (pre_comp && pre_comp->numblocks\n && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n 0)) {\n blocksize = pre_comp->blocksize;\n numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n if (numblocks > pre_comp->numblocks)\n numblocks = pre_comp->numblocks;\n pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n pre_comp = NULL;\n numblocks = 1;\n num_scalar = 1;\n }\n }\n totalnum = num + numblocks;\n wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));\n wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));\n wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));\n val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));\n if (wNAF != NULL)\n wNAF[0] = NULL;\n if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n num_val = 0;\n for (i = 0; i < num + num_scalar; i++) {\n size_t bits;\n bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n wsize[i] = EC_window_bits_for_scalar_size(bits);\n num_val += (size_t)1 << (wsize[i] - 1);\n wNAF[i + 1] = NULL;\n wNAF[i] =\n bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n &wNAF_len[i]);\n if (wNAF[i] == NULL)\n goto err;\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n }\n if (numblocks) {\n if (pre_comp == NULL) {\n if (num_scalar != 1) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n signed char *tmp_wNAF = NULL;\n size_t tmp_len = 0;\n if (num_scalar != 0) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n wsize[num] = pre_comp->w;\n tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n if (!tmp_wNAF)\n goto err;\n if (tmp_len <= max_len) {\n numblocks = 1;\n totalnum = num + 1;\n wNAF[num] = tmp_wNAF;\n wNAF[num + 1] = NULL;\n wNAF_len[num] = tmp_len;\n val_sub[num] = pre_comp->points;\n } else {\n signed char *pp;\n EC_POINT **tmp_points;\n if (tmp_len < numblocks * blocksize) {\n numblocks = (tmp_len + blocksize - 1) / blocksize;\n if (numblocks > pre_comp->numblocks) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n totalnum = num + numblocks;\n }\n pp = tmp_wNAF;\n tmp_points = pre_comp->points;\n for (i = num; i < totalnum; i++) {\n if (i < totalnum - 1) {\n wNAF_len[i] = blocksize;\n if (tmp_len < blocksize) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n tmp_len -= blocksize;\n } else\n wNAF_len[i] = tmp_len;\n wNAF[i + 1] = NULL;\n wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n if (wNAF[i] == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n memcpy(wNAF[i], pp, wNAF_len[i]);\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n if (*tmp_points == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n val_sub[i] = tmp_points;\n tmp_points += pre_points_per_block;\n pp += blocksize;\n }\n OPENSSL_free(tmp_wNAF);\n }\n }\n }\n val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));\n if (val == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n val[num_val] = NULL;\n v = val;\n for (i = 0; i < num + num_scalar; i++) {\n val_sub[i] = v;\n for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n *v = EC_POINT_new(group);\n if (*v == NULL)\n goto err;\n v++;\n }\n }\n if (!(v == val + num_val)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if ((tmp = EC_POINT_new(group)) == NULL)\n goto err;\n for (i = 0; i < num + num_scalar; i++) {\n if (i < num) {\n if (!EC_POINT_copy(val_sub[i][0], points[i]))\n goto err;\n } else {\n if (!EC_POINT_copy(val_sub[i][0], generator))\n goto err;\n }\n if (wsize[i] > 1) {\n if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n goto err;\n for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n if (!EC_POINT_add\n (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n goto err;\n }\n }\n }\n if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n goto err;\n r_is_at_infinity = 1;\n for (k = max_len - 1; k >= 0; k--) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n }\n for (i = 0; i < totalnum; i++) {\n if (wNAF_len[i] > (size_t)k) {\n int digit = wNAF[i][k];\n int is_neg;\n if (digit) {\n is_neg = digit < 0;\n if (is_neg)\n digit = -digit;\n if (is_neg != r_is_inverted) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n r_is_inverted = !r_is_inverted;\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n goto err;\n r_is_at_infinity = 0;\n } else {\n if (!EC_POINT_add\n (group, r, r, val_sub[i][digit >> 1], ctx))\n goto err;\n }\n }\n }\n }\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (r_is_inverted)\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n ret = 1;\n err:\n EC_POINT_free(tmp);\n OPENSSL_free(wsize);\n OPENSSL_free(wNAF_len);\n if (wNAF != NULL) {\n signed char **w;\n for (w = wNAF; *w != NULL; w++)\n OPENSSL_free(*w);\n OPENSSL_free(wNAF);\n }\n if (val != NULL) {\n for (v = val; *v != NULL; v++)\n EC_POINT_clear_free(*v);\n OPENSSL_free(val);\n }\n OPENSSL_free(val_sub);\n return ret;\n}', 'int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int i, cardinality_bits, group_top, kbit, pbit, Z_is_one;\n EC_POINT *p = NULL;\n EC_POINT *s = NULL;\n BIGNUM *k = NULL;\n BIGNUM *lambda = NULL;\n BIGNUM *cardinality = NULL;\n int ret = 0;\n if (point != NULL && EC_POINT_is_at_infinity(group, point))\n return EC_POINT_set_to_infinity(group, r);\n if (BN_is_zero(group->order)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_ORDER);\n return 0;\n }\n if (BN_is_zero(group->cofactor)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_COFACTOR);\n return 0;\n }\n BN_CTX_start(ctx);\n if (((p = EC_POINT_new(group)) == NULL)\n || ((s = EC_POINT_new(group)) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (point == NULL) {\n if (!EC_POINT_copy(p, group->generator)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);\n goto err;\n }\n } else {\n if (!EC_POINT_copy(p, point)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);\n goto err;\n }\n }\n EC_POINT_BN_set_flags(p, BN_FLG_CONSTTIME);\n EC_POINT_BN_set_flags(r, BN_FLG_CONSTTIME);\n EC_POINT_BN_set_flags(s, BN_FLG_CONSTTIME);\n cardinality = BN_CTX_get(ctx);\n lambda = BN_CTX_get(ctx);\n k = BN_CTX_get(ctx);\n if (k == NULL) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!BN_mul(cardinality, group->order, group->cofactor, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n cardinality_bits = BN_num_bits(cardinality);\n group_top = bn_get_top(cardinality);\n if ((bn_wexpand(k, group_top + 1) == NULL)\n || (bn_wexpand(lambda, group_top + 1) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_copy(k, scalar)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if ((BN_num_bits(k) > cardinality_bits) || (BN_is_negative(k))) {\n if (!BN_nnmod(k, k, cardinality, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n }\n if (!BN_add(lambda, k, cardinality)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(lambda, BN_FLG_CONSTTIME);\n if (!BN_add(k, lambda, cardinality)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n kbit = BN_is_bit_set(lambda, cardinality_bits);\n BN_consttime_swap(kbit, k, lambda, group_top + 1);\n group_top = bn_get_top(group->field);\n if ((bn_wexpand(s->X, group_top) == NULL)\n || (bn_wexpand(s->Y, group_top) == NULL)\n || (bn_wexpand(s->Z, group_top) == NULL)\n || (bn_wexpand(r->X, group_top) == NULL)\n || (bn_wexpand(r->Y, group_top) == NULL)\n || (bn_wexpand(r->Z, group_top) == NULL)\n || (bn_wexpand(p->X, group_top) == NULL)\n || (bn_wexpand(p->Y, group_top) == NULL)\n || (bn_wexpand(p->Z, group_top) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n if (!ec_point_blind_coordinates(group, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_POINT_COORDINATES_BLIND_FAILURE);\n goto err;\n }\n if (!ec_point_ladder_pre(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_PRE_FAILURE);\n goto err;\n }\n pbit = 1;\n#define EC_POINT_CSWAP(c, a, b, w, t) do { \\\n BN_consttime_swap(c, (a)->X, (b)->X, w); \\\n BN_consttime_swap(c, (a)->Y, (b)->Y, w); \\\n BN_consttime_swap(c, (a)->Z, (b)->Z, w); \\\n t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \\\n (a)->Z_is_one ^= (t); \\\n (b)->Z_is_one ^= (t); \\\n} while(0)\n for (i = cardinality_bits - 1; i >= 0; i--) {\n kbit = BN_is_bit_set(k, i) ^ pbit;\n EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);\n if (!ec_point_ladder_step(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_STEP_FAILURE);\n goto err;\n }\n pbit ^= kbit;\n }\n EC_POINT_CSWAP(pbit, r, s, group_top, Z_is_one);\n#undef EC_POINT_CSWAP\n if (!ec_point_ladder_post(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_POST_FAILURE);\n goto err;\n }\n ret = 1;\n err:\n EC_POINT_free(p);\n EC_POINT_free(s);\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,658
| 0
|
https://github.com/libav/libav/blob/490a022d86ef1c506a79744c5a95368af356fc69/libavformat/oggparsevorbis.c/#L177
|
static unsigned int
fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,
uint8_t **buf)
{
int i,offset, len;
unsigned char *ptr;
len = priv->len[0] + priv->len[1] + priv->len[2];
ptr = *buf = av_mallocz(len + len/255 + 64);
ptr[0] = 2;
offset = 1;
offset += av_xiphlacing(&ptr[offset], priv->len[0]);
offset += av_xiphlacing(&ptr[offset], priv->len[1]);
for (i = 0; i < 3; i++) {
memcpy(&ptr[offset], priv->packet[i], priv->len[i]);
offset += priv->len[i];
av_freep(&priv->packet[i]);
}
*buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);
return offset;
}
|
['static unsigned int\nfixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,\n uint8_t **buf)\n{\n int i,offset, len;\n unsigned char *ptr;\n len = priv->len[0] + priv->len[1] + priv->len[2];\n ptr = *buf = av_mallocz(len + len/255 + 64);\n ptr[0] = 2;\n offset = 1;\n offset += av_xiphlacing(&ptr[offset], priv->len[0]);\n offset += av_xiphlacing(&ptr[offset], priv->len[1]);\n for (i = 0; i < 3; i++) {\n memcpy(&ptr[offset], priv->packet[i], priv->len[i]);\n offset += priv->len[i];\n av_freep(&priv->packet[i]);\n }\n *buf = av_realloc(*buf, offset + FF_INPUT_BUFFER_PADDING_SIZE);\n return offset;\n}', 'void *av_mallocz(size_t size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,659
| 1
|
https://github.com/openssl/openssl/blob/9b10986d7742a5105ac8c5f4eba8b103caf57ae9/crypto/bn/bn_sqr.c/#L118
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['int SSL_set_srp_server_param_pw(SSL *s, const char *user, const char *pass,\n const char *grp)\n{\n SRP_gN *GN = SRP_get_default_gN(grp);\n if (GN == NULL)\n return -1;\n s->srp_ctx.N = BN_dup(GN->N);\n s->srp_ctx.g = BN_dup(GN->g);\n BN_clear_free(s->srp_ctx.v);\n s->srp_ctx.v = NULL;\n BN_clear_free(s->srp_ctx.s);\n s->srp_ctx.s = NULL;\n if (!SRP_create_verifier_BN\n (user, pass, &s->srp_ctx.s, &s->srp_ctx.v, GN->N, GN->g))\n return -1;\n return 1;\n}', 'BIGNUM *BN_dup(const BIGNUM *a)\n{\n BIGNUM *t;\n if (a == NULL)\n return NULL;\n bn_check_top(a);\n t = BN_get_flags(a, BN_FLG_SECURE) ? BN_secure_new() : BN_new();\n if (t == NULL)\n return NULL;\n if (!BN_copy(t, a)) {\n BN_free(t);\n return NULL;\n }\n bn_check_top(t);\n return t;\n}', 'int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n BIGNUM **verifier, const BIGNUM *N,\n const BIGNUM *g)\n{\n int result = 0;\n BIGNUM *x = NULL;\n BN_CTX *bn_ctx = BN_CTX_new();\n unsigned char tmp2[MAX_LEN];\n BIGNUM *salttmp = NULL;\n if ((user == NULL) ||\n (pass == NULL) ||\n (salt == NULL) ||\n (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n goto err;\n if (*salt == NULL) {\n if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n goto err;\n salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n if (salttmp == NULL)\n goto err;\n } else {\n salttmp = *salt;\n }\n x = SRP_Calc_x(salttmp, user, pass);\n if (x == NULL)\n goto err;\n *verifier = BN_new();\n if (*verifier == NULL)\n goto err;\n if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n BN_clear_free(*verifier);\n goto err;\n }\n result = 1;\n *salt = salttmp;\n err:\n if (salt != NULL && *salt != salttmp)\n BN_clear_free(salttmp);\n BN_clear_free(x);\n BN_CTX_free(bn_ctx);\n return result;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!bn_to_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, &am, mont, ctx))\n goto err;\n } else if (!bn_to_mont_fixed_top(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_to_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,660
| 0
|
https://github.com/openssl/openssl/blob/fa9bb6201e1d16ba8ccab938833d140ef81a7f73/crypto/mem.c/#L241
|
void CRYPTO_free(void *str, const char *file, int line)
{
if (free_impl != NULL && free_impl != &CRYPTO_free) {
free_impl(str, file, line);
return;
}
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (call_malloc_debug) {
CRYPTO_mem_debug_free(str, 0, file, line);
free(str);
CRYPTO_mem_debug_free(str, 1, file, line);
} else {
free(str);
}
#else
free(str);
#endif
}
|
['int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n EVP_MD_CTX_reset(out);\n return EVP_MD_CTX_copy_ex(out, in);\n}', 'int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)\n{\n if (ctx == NULL)\n return 1;\n if (ctx->digest && ctx->digest->cleanup\n && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))\n ctx->digest->cleanup(ctx);\n if (ctx->digest && ctx->digest->ctx_size && ctx->md_data\n && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {\n OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);\n }\n EVP_PKEY_CTX_free(ctx->pctx);\n#ifndef OPENSSL_NO_ENGINE\n if (ctx->engine)\n ENGINE_finish(ctx->engine);\n#endif\n memset(ctx, 0, sizeof(*ctx));\n return 1;\n}', 'void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n if (ctx->pmeth && ctx->pmeth->cleanup)\n ctx->pmeth->cleanup(ctx);\n EVP_PKEY_free(ctx->pkey);\n EVP_PKEY_free(ctx->peerkey);\n#ifndef OPENSSL_NO_ENGINE\n if (ctx->engine)\n ENGINE_finish(ctx->engine);\n#endif\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
1,661
| 0
|
https://github.com/libav/libav/blob/eec7f032a903e06d249d1e8aa6630b65292bf40f/libavcodec/vp9block.c/#L1294
|
static int inter_recon(AVCodecContext *avctx)
{
static const uint8_t bwlog_tab[2][N_BS_SIZES] = {
{ 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
{ 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 },
};
VP9Context *s = avctx->priv_data;
VP9Block *const b = &s->b;
int row = b->row, col = b->col;
AVFrame *ref1 = s->refs[s->refidx[b->ref[0]]];
AVFrame *ref2 = b->comp ? s->refs[s->refidx[b->ref[1]]] : NULL;
int w = avctx->width, h = avctx->height;
ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride;
if (!ref1->data[0] || (b->comp && !ref2->data[0]))
return AVERROR_INVALIDDATA;
if (b->bs > BS_8x8) {
if (b->bs == BS_8x4) {
mc_luma_dir(s, s->dsp.mc[3][b->filter][0], b->dst[0], ls_y,
ref1->data[0], ref1->linesize[0],
row << 3, col << 3, &b->mv[0][0], 8, 4, w, h);
mc_luma_dir(s, s->dsp.mc[3][b->filter][0],
b->dst[0] + 4 * ls_y, ls_y,
ref1->data[0], ref1->linesize[0],
(row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w, h);
if (b->comp) {
mc_luma_dir(s, s->dsp.mc[3][b->filter][1], b->dst[0], ls_y,
ref2->data[0], ref2->linesize[0],
row << 3, col << 3, &b->mv[0][1], 8, 4, w, h);
mc_luma_dir(s, s->dsp.mc[3][b->filter][1],
b->dst[0] + 4 * ls_y, ls_y,
ref2->data[0], ref2->linesize[0],
(row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w, h);
}
} else if (b->bs == BS_4x8) {
mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,
ref1->data[0], ref1->linesize[0],
row << 3, col << 3, &b->mv[0][0], 4, 8, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,
ref1->data[0], ref1->linesize[0],
row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w, h);
if (b->comp) {
mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,
ref2->data[0], ref2->linesize[0],
row << 3, col << 3, &b->mv[0][1], 4, 8, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,
ref2->data[0], ref2->linesize[0],
row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w, h);
}
} else {
av_assert2(b->bs == BS_4x4);
mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,
ref1->data[0], ref1->linesize[0],
row << 3, col << 3, &b->mv[0][0], 4, 4, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,
ref1->data[0], ref1->linesize[0],
row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][0],
b->dst[0] + 4 * ls_y, ls_y,
ref1->data[0], ref1->linesize[0],
(row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][0],
b->dst[0] + 4 * ls_y + 4, ls_y,
ref1->data[0], ref1->linesize[0],
(row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w, h);
if (b->comp) {
mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,
ref2->data[0], ref2->linesize[0],
row << 3, col << 3, &b->mv[0][1], 4, 4, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,
ref2->data[0], ref2->linesize[0],
row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][1],
b->dst[0] + 4 * ls_y, ls_y,
ref2->data[0], ref2->linesize[0],
(row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w, h);
mc_luma_dir(s, s->dsp.mc[4][b->filter][1],
b->dst[0] + 4 * ls_y + 4, ls_y,
ref2->data[0], ref2->linesize[0],
(row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w, h);
}
}
} else {
int bwl = bwlog_tab[0][b->bs];
int bw = bwh_tab[0][b->bs][0] * 4;
int bh = bwh_tab[0][b->bs][1] * 4;
mc_luma_dir(s, s->dsp.mc[bwl][b->filter][0], b->dst[0], ls_y,
ref1->data[0], ref1->linesize[0],
row << 3, col << 3, &b->mv[0][0], bw, bh, w, h);
if (b->comp)
mc_luma_dir(s, s->dsp.mc[bwl][b->filter][1], b->dst[0], ls_y,
ref2->data[0], ref2->linesize[0],
row << 3, col << 3, &b->mv[0][1], bw, bh, w, h);
}
{
int bwl = bwlog_tab[1][b->bs];
int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4;
VP56mv mvuv;
w = (w + 1) >> 1;
h = (h + 1) >> 1;
if (b->bs > BS_8x8) {
mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x +
b->mv[2][0].x + b->mv[3][0].x, 4);
mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y +
b->mv[2][0].y + b->mv[3][0].y, 4);
} else {
mvuv = b->mv[0][0];
}
mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][0],
b->dst[1], b->dst[2], ls_uv,
ref1->data[1], ref1->linesize[1],
ref1->data[2], ref1->linesize[2],
row << 2, col << 2, &mvuv, bw, bh, w, h);
if (b->comp) {
if (b->bs > BS_8x8) {
mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x +
b->mv[2][1].x + b->mv[3][1].x, 4);
mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y +
b->mv[2][1].y + b->mv[3][1].y, 4);
} else {
mvuv = b->mv[0][1];
}
mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][1],
b->dst[1], b->dst[2], ls_uv,
ref2->data[1], ref2->linesize[1],
ref2->data[2], ref2->linesize[2],
row << 2, col << 2, &mvuv, bw, bh, w, h);
}
}
if (!b->skip) {
int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;
int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);
int end_x = FFMIN(2 * (s->cols - col), w4);
int end_y = FFMIN(2 * (s->rows - row), h4);
int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless;
int uvstep1d = 1 << b->uvtx, p;
uint8_t *dst = b->dst[0];
for (n = 0, y = 0; y < end_y; y += step1d) {
uint8_t *ptr = dst;
for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d, n += step) {
int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n];
if (eob)
s->dsp.itxfm_add[tx][DCT_DCT](ptr, b->y_stride,
s->block + 16 * n, eob);
}
dst += 4 * b->y_stride * step1d;
}
h4 >>= 1;
w4 >>= 1;
end_x >>= 1;
end_y >>= 1;
step = 1 << (b->uvtx * 2);
for (p = 0; p < 2; p++) {
dst = b->dst[p + 1];
for (n = 0, y = 0; y < end_y; y += uvstep1d) {
uint8_t *ptr = dst;
for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d, n += step) {
int eob = b->uvtx > TX_8X8 ? AV_RN16A(&s->uveob[p][n])
: s->uveob[p][n];
if (eob)
s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, b->uv_stride,
s->uvblock[p] + 16 * n, eob);
}
dst += 4 * uvstep1d * b->uv_stride;
}
}
}
return 0;
}
|
['static int inter_recon(AVCodecContext *avctx)\n{\n static const uint8_t bwlog_tab[2][N_BS_SIZES] = {\n { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },\n { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 },\n };\n VP9Context *s = avctx->priv_data;\n VP9Block *const b = &s->b;\n int row = b->row, col = b->col;\n AVFrame *ref1 = s->refs[s->refidx[b->ref[0]]];\n AVFrame *ref2 = b->comp ? s->refs[s->refidx[b->ref[1]]] : NULL;\n int w = avctx->width, h = avctx->height;\n ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride;\n if (!ref1->data[0] || (b->comp && !ref2->data[0]))\n return AVERROR_INVALIDDATA;\n if (b->bs > BS_8x8) {\n if (b->bs == BS_8x4) {\n mc_luma_dir(s, s->dsp.mc[3][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], 8, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[3][b->filter][0],\n b->dst[0] + 4 * ls_y, ls_y,\n ref1->data[0], ref1->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w, h);\n if (b->comp) {\n mc_luma_dir(s, s->dsp.mc[3][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], 8, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[3][b->filter][1],\n b->dst[0] + 4 * ls_y, ls_y,\n ref2->data[0], ref2->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w, h);\n }\n } else if (b->bs == BS_4x8) {\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], 4, 8, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w, h);\n if (b->comp) {\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], 4, 8, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w, h);\n }\n } else {\n av_assert2(b->bs == BS_4x4);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0],\n b->dst[0] + 4 * ls_y, ls_y,\n ref1->data[0], ref1->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][0],\n b->dst[0] + 4 * ls_y + 4, ls_y,\n ref1->data[0], ref1->linesize[0],\n (row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w, h);\n if (b->comp) {\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1],\n b->dst[0] + 4 * ls_y, ls_y,\n ref2->data[0], ref2->linesize[0],\n (row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w, h);\n mc_luma_dir(s, s->dsp.mc[4][b->filter][1],\n b->dst[0] + 4 * ls_y + 4, ls_y,\n ref2->data[0], ref2->linesize[0],\n (row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w, h);\n }\n }\n } else {\n int bwl = bwlog_tab[0][b->bs];\n int bw = bwh_tab[0][b->bs][0] * 4;\n int bh = bwh_tab[0][b->bs][1] * 4;\n mc_luma_dir(s, s->dsp.mc[bwl][b->filter][0], b->dst[0], ls_y,\n ref1->data[0], ref1->linesize[0],\n row << 3, col << 3, &b->mv[0][0], bw, bh, w, h);\n if (b->comp)\n mc_luma_dir(s, s->dsp.mc[bwl][b->filter][1], b->dst[0], ls_y,\n ref2->data[0], ref2->linesize[0],\n row << 3, col << 3, &b->mv[0][1], bw, bh, w, h);\n }\n {\n int bwl = bwlog_tab[1][b->bs];\n int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4;\n VP56mv mvuv;\n w = (w + 1) >> 1;\n h = (h + 1) >> 1;\n if (b->bs > BS_8x8) {\n mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x +\n b->mv[2][0].x + b->mv[3][0].x, 4);\n mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y +\n b->mv[2][0].y + b->mv[3][0].y, 4);\n } else {\n mvuv = b->mv[0][0];\n }\n mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][0],\n b->dst[1], b->dst[2], ls_uv,\n ref1->data[1], ref1->linesize[1],\n ref1->data[2], ref1->linesize[2],\n row << 2, col << 2, &mvuv, bw, bh, w, h);\n if (b->comp) {\n if (b->bs > BS_8x8) {\n mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x +\n b->mv[2][1].x + b->mv[3][1].x, 4);\n mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y +\n b->mv[2][1].y + b->mv[3][1].y, 4);\n } else {\n mvuv = b->mv[0][1];\n }\n mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][1],\n b->dst[1], b->dst[2], ls_uv,\n ref2->data[1], ref2->linesize[1],\n ref2->data[2], ref2->linesize[2],\n row << 2, col << 2, &mvuv, bw, bh, w, h);\n }\n }\n if (!b->skip) {\n int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;\n int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);\n int end_x = FFMIN(2 * (s->cols - col), w4);\n int end_y = FFMIN(2 * (s->rows - row), h4);\n int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless;\n int uvstep1d = 1 << b->uvtx, p;\n uint8_t *dst = b->dst[0];\n for (n = 0, y = 0; y < end_y; y += step1d) {\n uint8_t *ptr = dst;\n for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d, n += step) {\n int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n];\n if (eob)\n s->dsp.itxfm_add[tx][DCT_DCT](ptr, b->y_stride,\n s->block + 16 * n, eob);\n }\n dst += 4 * b->y_stride * step1d;\n }\n h4 >>= 1;\n w4 >>= 1;\n end_x >>= 1;\n end_y >>= 1;\n step = 1 << (b->uvtx * 2);\n for (p = 0; p < 2; p++) {\n dst = b->dst[p + 1];\n for (n = 0, y = 0; y < end_y; y += uvstep1d) {\n uint8_t *ptr = dst;\n for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d, n += step) {\n int eob = b->uvtx > TX_8X8 ? AV_RN16A(&s->uveob[p][n])\n : s->uveob[p][n];\n if (eob)\n s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, b->uv_stride,\n s->uvblock[p] + 16 * n, eob);\n }\n dst += 4 * uvstep1d * b->uv_stride;\n }\n }\n }\n return 0;\n}']
|
1,662
| 1
|
https://github.com/openssl/openssl/blob/b79aa47a0c8478bea62fc2bb55f99e0be172da3d/apps/apps.c/#L1402
|
char *make_config_name()
{
const char *t=X509_get_default_cert_area();
char *p;
p=OPENSSL_malloc(strlen(t)+strlen(OPENSSL_CONF)+2);
strcpy(p,t);
#ifndef OPENSSL_SYS_VMS
strcat(p,"/");
#endif
strcat(p,OPENSSL_CONF);
return p;
}
|
['char *make_config_name()\n\t{\n\tconst char *t=X509_get_default_cert_area();\n\tchar *p;\n\tp=OPENSSL_malloc(strlen(t)+strlen(OPENSSL_CONF)+2);\n\tstrcpy(p,t);\n#ifndef OPENSSL_SYS_VMS\n\tstrcat(p,"/");\n#endif\n\tstrcat(p,OPENSSL_CONF);\n\treturn p;\n\t}', 'const char *X509_get_default_cert_area(void)\n\t{ return(X509_CERT_AREA); }', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}']
|
1,663
| 0
|
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['static int cllc_decode_frame(AVCodecContext *avctx, void *data,\n int *got_picture_ptr, AVPacket *avpkt)\n{\n CLLCContext *ctx = avctx->priv_data;\n AVFrame *pic = data;\n uint8_t *src = avpkt->data;\n uint32_t info_tag, info_offset;\n int data_size;\n BitstreamContext bc;\n int coding_type, ret;\n if (avpkt->size < 4 + 4) {\n av_log(avctx, AV_LOG_ERROR, "Frame is too small %d.\\n", avpkt->size);\n return AVERROR_INVALIDDATA;\n }\n info_offset = 0;\n info_tag = AV_RL32(src);\n if (info_tag == MKTAG(\'I\', \'N\', \'F\', \'O\')) {\n info_offset = AV_RL32(src + 4);\n if (info_offset > UINT32_MAX - 8 || info_offset + 8 > avpkt->size) {\n av_log(avctx, AV_LOG_ERROR,\n "Invalid INFO header offset: 0x%08"PRIX32" is too large.\\n",\n info_offset);\n return AVERROR_INVALIDDATA;\n }\n ff_canopus_parse_info_tag(avctx, src + 8, info_offset);\n info_offset += 8;\n src += info_offset;\n }\n data_size = (avpkt->size - info_offset) & ~1;\n av_fast_padded_malloc(&ctx->swapped_buf,\n &ctx->swapped_buf_size, data_size);\n if (!ctx->swapped_buf) {\n av_log(avctx, AV_LOG_ERROR, "Could not allocate swapped buffer.\\n");\n return AVERROR(ENOMEM);\n }\n ctx->bdsp.bswap16_buf((uint16_t *) ctx->swapped_buf, (uint16_t *) src,\n data_size / 2);\n bitstream_init8(&bc, ctx->swapped_buf, data_size);\n coding_type = (AV_RL32(src) >> 8) & 0xFF;\n av_log(avctx, AV_LOG_DEBUG, "Frame coding type: %d\\n", coding_type);\n switch (coding_type) {\n case 0:\n avctx->pix_fmt = AV_PIX_FMT_YUV422P;\n avctx->bits_per_raw_sample = 8;\n ret = ff_get_buffer(avctx, pic, 0);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\\n");\n return ret;\n }\n ret = decode_yuv_frame(ctx, &bc, pic);\n if (ret < 0)\n return ret;\n break;\n case 1:\n case 2:\n avctx->pix_fmt = AV_PIX_FMT_RGB24;\n avctx->bits_per_raw_sample = 8;\n ret = ff_get_buffer(avctx, pic, 0);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\\n");\n return ret;\n }\n ret = decode_rgb24_frame(ctx, &bc, pic);\n if (ret < 0)\n return ret;\n break;\n case 3:\n avctx->pix_fmt = AV_PIX_FMT_ARGB;\n avctx->bits_per_raw_sample = 8;\n ret = ff_get_buffer(avctx, pic, 0);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\\n");\n return ret;\n }\n ret = decode_argb_frame(ctx, &bc, pic);\n if (ret < 0)\n return ret;\n break;\n default:\n av_log(avctx, AV_LOG_ERROR, "Unknown coding type: %d.\\n", coding_type);\n return AVERROR_INVALIDDATA;\n }\n pic->key_frame = 1;\n pic->pict_type = AV_PICTURE_TYPE_I;\n *got_picture_ptr = 1;\n return avpkt->size;\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n unsigned byte_size)\n{\n if (byte_size > INT_MAX / 8)\n return AVERROR_INVALIDDATA;\n return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static int decode_rgb24_frame(CLLCContext *ctx, BitstreamContext *bc, AVFrame *pic)\n{\n AVCodecContext *avctx = ctx->avctx;\n uint8_t *dst;\n int pred[3];\n int ret;\n int i, j;\n VLC vlc[3];\n pred[0] = 0x80;\n pred[1] = 0x80;\n pred[2] = 0x80;\n dst = pic->data[0];\n bitstream_skip(bc, 16);\n for (i = 0; i < 3; i++) {\n ret = read_code_table(ctx, bc, &vlc[i]);\n if (ret < 0) {\n for (j = 0; j <= i; j++)\n ff_free_vlc(&vlc[j]);\n av_log(ctx->avctx, AV_LOG_ERROR,\n "Could not read code table %d.\\n", i);\n return ret;\n }\n }\n for (i = 0; i < avctx->height; i++) {\n for (j = 0; j < 3; j++)\n read_rgb24_component_line(ctx, bc, &pred[j], &vlc[j], &dst[j]);\n dst += pic->linesize[0];\n }\n for (i = 0; i < 3; i++)\n ff_free_vlc(&vlc[i]);\n return 0;\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
1,664
| 1
|
https://github.com/openssl/openssl/blob/ff281ee8369350d88e8b57af139614f5683e1e8c/crypto/bio/b_print.c/#L353
|
static int
_dopr(char **sbuffer,
char **buffer,
size_t *maxlen,
size_t *retlen, int *truncated, const char *format, va_list args)
{
char ch;
int64_t value;
LDOUBLE fvalue;
char *strvalue;
int min;
int max;
int state;
int flags;
int cflags;
size_t currlen;
state = DP_S_DEFAULT;
flags = currlen = cflags = min = 0;
max = -1;
ch = *format++;
while (state != DP_S_DONE) {
if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
state = DP_S_DONE;
switch (state) {
case DP_S_DEFAULT:
if (ch == '%')
state = DP_S_FLAGS;
else
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
return 0;
ch = *format++;
break;
case DP_S_FLAGS:
switch (ch) {
case '-':
flags |= DP_F_MINUS;
ch = *format++;
break;
case '+':
flags |= DP_F_PLUS;
ch = *format++;
break;
case ' ':
flags |= DP_F_SPACE;
ch = *format++;
break;
case '#':
flags |= DP_F_NUM;
ch = *format++;
break;
case '0':
flags |= DP_F_ZERO;
ch = *format++;
break;
default:
state = DP_S_MIN;
break;
}
break;
case DP_S_MIN:
if (isdigit((unsigned char)ch)) {
min = 10 * min + char_to_int(ch);
ch = *format++;
} else if (ch == '*') {
min = va_arg(args, int);
ch = *format++;
state = DP_S_DOT;
} else
state = DP_S_DOT;
break;
case DP_S_DOT:
if (ch == '.') {
state = DP_S_MAX;
ch = *format++;
} else
state = DP_S_MOD;
break;
case DP_S_MAX:
if (isdigit((unsigned char)ch)) {
if (max < 0)
max = 0;
max = 10 * max + char_to_int(ch);
ch = *format++;
} else if (ch == '*') {
max = va_arg(args, int);
ch = *format++;
state = DP_S_MOD;
} else
state = DP_S_MOD;
break;
case DP_S_MOD:
switch (ch) {
case 'h':
cflags = DP_C_SHORT;
ch = *format++;
break;
case 'l':
if (*format == 'l') {
cflags = DP_C_LLONG;
format++;
} else
cflags = DP_C_LONG;
ch = *format++;
break;
case 'q':
case 'j':
cflags = DP_C_LLONG;
ch = *format++;
break;
case 'L':
cflags = DP_C_LDOUBLE;
ch = *format++;
break;
case 'z':
cflags = DP_C_SIZE;
ch = *format++;
break;
default:
break;
}
state = DP_S_CONV;
break;
case DP_S_CONV:
switch (ch) {
case 'd':
case 'i':
switch (cflags) {
case DP_C_SHORT:
value = (short int)va_arg(args, int);
break;
case DP_C_LONG:
value = va_arg(args, long int);
break;
case DP_C_LLONG:
value = va_arg(args, int64_t);
break;
case DP_C_SIZE:
value = va_arg(args, ossl_ssize_t);
break;
default:
value = va_arg(args, int);
break;
}
if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,
max, flags))
return 0;
break;
case 'X':
flags |= DP_F_UP;
case 'x':
case 'o':
case 'u':
flags |= DP_F_UNSIGNED;
switch (cflags) {
case DP_C_SHORT:
value = (unsigned short int)va_arg(args, unsigned int);
break;
case DP_C_LONG:
value = va_arg(args, unsigned long int);
break;
case DP_C_LLONG:
value = va_arg(args, uint64_t);
break;
case DP_C_SIZE:
value = va_arg(args, size_t);
break;
default:
value = va_arg(args, unsigned int);
break;
}
if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,
ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
min, max, flags))
return 0;
break;
case 'f':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
flags, F_FORMAT))
return 0;
break;
case 'E':
flags |= DP_F_UP;
case 'e':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
flags, E_FORMAT))
return 0;
break;
case 'G':
flags |= DP_F_UP;
case 'g':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg(args, LDOUBLE);
else
fvalue = va_arg(args, double);
if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
flags, G_FORMAT))
return 0;
break;
case 'c':
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen,
va_arg(args, int)))
return 0;
break;
case 's':
strvalue = va_arg(args, char *);
if (max < 0) {
if (buffer)
max = INT_MAX;
else
max = *maxlen;
}
if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
flags, min, max))
return 0;
break;
case 'p':
value = (size_t)va_arg(args, void *);
if (!fmtint(sbuffer, buffer, &currlen, maxlen,
value, 16, min, max, flags | DP_F_NUM))
return 0;
break;
case 'n':
{
int *num;
num = va_arg(args, int *);
*num = currlen;
}
break;
case '%':
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
return 0;
break;
case 'w':
ch = *format++;
break;
default:
break;
}
ch = *format++;
state = DP_S_DEFAULT;
flags = cflags = min = 0;
max = -1;
break;
case DP_S_DONE:
break;
default:
break;
}
}
if (buffer == NULL) {
*truncated = (currlen > *maxlen - 1);
if (*truncated)
currlen = *maxlen - 1;
}
if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'))
return 0;
*retlen = currlen - 1;
return 1;
}
|
['long BIO_debug_callback(BIO *bio, int cmd, const char *argp,\n int argi, long argl, long ret)\n{\n BIO *b;\n char buf[256];\n char *p;\n long r = 1;\n int len;\n size_t p_maxlen;\n if (BIO_CB_RETURN & cmd)\n r = ret;\n len = BIO_snprintf(buf, sizeof buf, "BIO[%p]: ", (void *)bio);\n if (len < 0)\n len = 0;\n p = buf + len;\n p_maxlen = sizeof(buf) - len;\n switch (cmd) {\n case BIO_CB_FREE:\n BIO_snprintf(p, p_maxlen, "Free - %s\\n", bio->method->name);\n break;\n case BIO_CB_READ:\n if (bio->method->type & BIO_TYPE_DESCRIPTOR)\n BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s fd=%d\\n",\n bio->num, (unsigned long)argi,\n bio->method->name, bio->num);\n else\n BIO_snprintf(p, p_maxlen, "read(%d,%lu) - %s\\n",\n bio->num, (unsigned long)argi, bio->method->name);\n break;\n case BIO_CB_WRITE:\n if (bio->method->type & BIO_TYPE_DESCRIPTOR)\n BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s fd=%d\\n",\n bio->num, (unsigned long)argi,\n bio->method->name, bio->num);\n else\n BIO_snprintf(p, p_maxlen, "write(%d,%lu) - %s\\n",\n bio->num, (unsigned long)argi, bio->method->name);\n break;\n case BIO_CB_PUTS:\n BIO_snprintf(p, p_maxlen, "puts() - %s\\n", bio->method->name);\n break;\n case BIO_CB_GETS:\n BIO_snprintf(p, p_maxlen, "gets(%lu) - %s\\n", (unsigned long)argi,\n bio->method->name);\n break;\n case BIO_CB_CTRL:\n BIO_snprintf(p, p_maxlen, "ctrl(%lu) - %s\\n", (unsigned long)argi,\n bio->method->name);\n break;\n case BIO_CB_RETURN | BIO_CB_READ:\n BIO_snprintf(p, p_maxlen, "read return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_WRITE:\n BIO_snprintf(p, p_maxlen, "write return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_GETS:\n BIO_snprintf(p, p_maxlen, "gets return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_PUTS:\n BIO_snprintf(p, p_maxlen, "puts return %ld\\n", ret);\n break;\n case BIO_CB_RETURN | BIO_CB_CTRL:\n BIO_snprintf(p, p_maxlen, "ctrl return %ld\\n", ret);\n break;\n default:\n BIO_snprintf(p, p_maxlen, "bio callback - unknown type (%d)\\n", cmd);\n break;\n }\n b = (BIO *)bio->cb_arg;\n if (b != NULL)\n BIO_write(b, buf, strlen(buf));\n#if !defined(OPENSSL_NO_STDIO)\n else\n fputs(buf, stderr);\n#endif\n return (r);\n}', 'int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n{\n va_list args;\n int ret;\n va_start(args, format);\n ret = BIO_vsnprintf(buf, n, format, args);\n va_end(args);\n return (ret);\n}', 'int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n{\n size_t retlen;\n int truncated;\n if(!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))\n return -1;\n if (truncated)\n return -1;\n else\n return (retlen <= INT_MAX) ? (int)retlen : -1;\n}', "static int\n_dopr(char **sbuffer,\n char **buffer,\n size_t *maxlen,\n size_t *retlen, int *truncated, const char *format, va_list args)\n{\n char ch;\n int64_t value;\n LDOUBLE fvalue;\n char *strvalue;\n int min;\n int max;\n int state;\n int flags;\n int cflags;\n size_t currlen;\n state = DP_S_DEFAULT;\n flags = currlen = cflags = min = 0;\n max = -1;\n ch = *format++;\n while (state != DP_S_DONE) {\n if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n state = DP_S_DONE;\n switch (state) {\n case DP_S_DEFAULT:\n if (ch == '%')\n state = DP_S_FLAGS;\n else\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n return 0;\n ch = *format++;\n break;\n case DP_S_FLAGS:\n switch (ch) {\n case '-':\n flags |= DP_F_MINUS;\n ch = *format++;\n break;\n case '+':\n flags |= DP_F_PLUS;\n ch = *format++;\n break;\n case ' ':\n flags |= DP_F_SPACE;\n ch = *format++;\n break;\n case '#':\n flags |= DP_F_NUM;\n ch = *format++;\n break;\n case '0':\n flags |= DP_F_ZERO;\n ch = *format++;\n break;\n default:\n state = DP_S_MIN;\n break;\n }\n break;\n case DP_S_MIN:\n if (isdigit((unsigned char)ch)) {\n min = 10 * min + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n min = va_arg(args, int);\n ch = *format++;\n state = DP_S_DOT;\n } else\n state = DP_S_DOT;\n break;\n case DP_S_DOT:\n if (ch == '.') {\n state = DP_S_MAX;\n ch = *format++;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MAX:\n if (isdigit((unsigned char)ch)) {\n if (max < 0)\n max = 0;\n max = 10 * max + char_to_int(ch);\n ch = *format++;\n } else if (ch == '*') {\n max = va_arg(args, int);\n ch = *format++;\n state = DP_S_MOD;\n } else\n state = DP_S_MOD;\n break;\n case DP_S_MOD:\n switch (ch) {\n case 'h':\n cflags = DP_C_SHORT;\n ch = *format++;\n break;\n case 'l':\n if (*format == 'l') {\n cflags = DP_C_LLONG;\n format++;\n } else\n cflags = DP_C_LONG;\n ch = *format++;\n break;\n case 'q':\n case 'j':\n cflags = DP_C_LLONG;\n ch = *format++;\n break;\n case 'L':\n cflags = DP_C_LDOUBLE;\n ch = *format++;\n break;\n case 'z':\n cflags = DP_C_SIZE;\n ch = *format++;\n break;\n default:\n break;\n }\n state = DP_S_CONV;\n break;\n case DP_S_CONV:\n switch (ch) {\n case 'd':\n case 'i':\n switch (cflags) {\n case DP_C_SHORT:\n value = (short int)va_arg(args, int);\n break;\n case DP_C_LONG:\n value = va_arg(args, long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, int64_t);\n break;\n case DP_C_SIZE:\n value = va_arg(args, ossl_ssize_t);\n break;\n default:\n value = va_arg(args, int);\n break;\n }\n if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,\n max, flags))\n return 0;\n break;\n case 'X':\n flags |= DP_F_UP;\n case 'x':\n case 'o':\n case 'u':\n flags |= DP_F_UNSIGNED;\n switch (cflags) {\n case DP_C_SHORT:\n value = (unsigned short int)va_arg(args, unsigned int);\n break;\n case DP_C_LONG:\n value = va_arg(args, unsigned long int);\n break;\n case DP_C_LLONG:\n value = va_arg(args, uint64_t);\n break;\n case DP_C_SIZE:\n value = va_arg(args, size_t);\n break;\n default:\n value = va_arg(args, unsigned int);\n break;\n }\n if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,\n ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n min, max, flags))\n return 0;\n break;\n case 'f':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags, F_FORMAT))\n return 0;\n break;\n case 'E':\n flags |= DP_F_UP;\n case 'e':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags, E_FORMAT))\n return 0;\n break;\n case 'G':\n flags |= DP_F_UP;\n case 'g':\n if (cflags == DP_C_LDOUBLE)\n fvalue = va_arg(args, LDOUBLE);\n else\n fvalue = va_arg(args, double);\n if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n flags, G_FORMAT))\n return 0;\n break;\n case 'c':\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen,\n va_arg(args, int)))\n return 0;\n break;\n case 's':\n strvalue = va_arg(args, char *);\n if (max < 0) {\n if (buffer)\n max = INT_MAX;\n else\n max = *maxlen;\n }\n if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n flags, min, max))\n return 0;\n break;\n case 'p':\n value = (size_t)va_arg(args, void *);\n if (!fmtint(sbuffer, buffer, &currlen, maxlen,\n value, 16, min, max, flags | DP_F_NUM))\n return 0;\n break;\n case 'n':\n {\n int *num;\n num = va_arg(args, int *);\n *num = currlen;\n }\n break;\n case '%':\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n return 0;\n break;\n case 'w':\n ch = *format++;\n break;\n default:\n break;\n }\n ch = *format++;\n state = DP_S_DEFAULT;\n flags = cflags = min = 0;\n max = -1;\n break;\n case DP_S_DONE:\n break;\n default:\n break;\n }\n }\n if (buffer == NULL) {\n *truncated = (currlen > *maxlen - 1);\n if (*truncated)\n currlen = *maxlen - 1;\n }\n if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0'))\n return 0;\n *retlen = currlen - 1;\n return 1;\n}"]
|
1,665
| 0
|
https://github.com/openssl/openssl/blob/a3a2ff4cd9ada10effaa514af90c7638ab0e9824/engines/e_ncipher.c/#L798
|
static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
UI_METHOD *ui_method, void *callback_data)
{
#ifndef OPENSSL_NO_RSA
RSA *rtmp = NULL;
#endif
EVP_PKEY *res = NULL;
#ifndef OPENSSL_NO_RSA
HWCryptoHook_MPI e, n;
HWCryptoHook_RSAKeyHandle *hptr;
#endif
#if !defined(OPENSSL_NO_RSA)
char tempbuf[1024];
HWCryptoHook_ErrMsgBuf rmsg;
#endif
HWCryptoHook_PassphraseContext ppctx;
#if !defined(OPENSSL_NO_RSA)
rmsg.buf = tempbuf;
rmsg.size = sizeof(tempbuf);
#endif
if(!hwcrhk_context)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_NOT_INITIALISED);
goto err;
}
#ifndef OPENSSL_NO_RSA
hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));
if (!hptr)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
ERR_R_MALLOC_FAILURE);
goto err;
}
ppctx.ui_method = ui_method;
ppctx.callback_data = callback_data;
if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,
&rmsg, &ppctx))
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_CHIL_ERROR);
ERR_add_error_data(1,rmsg.buf);
goto err;
}
if (!*hptr)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
HWCRHK_R_NO_KEY);
goto err;
}
#endif
#ifndef OPENSSL_NO_RSA
rtmp = RSA_new_method(eng);
RSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr);
rtmp->e = BN_new();
rtmp->n = BN_new();
rtmp->flags |= RSA_FLAG_EXT_PKEY;
MPI2BN(rtmp->e, e);
MPI2BN(rtmp->n, n);
if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)
!= HWCRYPTOHOOK_ERROR_MPISIZE)
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,HWCRHK_R_CHIL_ERROR);
ERR_add_error_data(1,rmsg.buf);
goto err;
}
bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));
bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));
MPI2BN(rtmp->e, e);
MPI2BN(rtmp->n, n);
if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))
{
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,
HWCRHK_R_CHIL_ERROR);
ERR_add_error_data(1,rmsg.buf);
goto err;
}
rtmp->e->top = e.size / sizeof(BN_ULONG);
bn_fix_top(rtmp->e);
rtmp->n->top = n.size / sizeof(BN_ULONG);
bn_fix_top(rtmp->n);
res = EVP_PKEY_new();
EVP_PKEY_assign_RSA(res, rtmp);
#endif
if (!res)
HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,
HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED);
return res;
err:
if (res)
EVP_PKEY_free(res);
#ifndef OPENSSL_NO_RSA
if (rtmp)
RSA_free(rtmp);
#endif
return NULL;
}
|
['static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,\n\tUI_METHOD *ui_method, void *callback_data)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tRSA *rtmp = NULL;\n#endif\n\tEVP_PKEY *res = NULL;\n#ifndef OPENSSL_NO_RSA\n\tHWCryptoHook_MPI e, n;\n\tHWCryptoHook_RSAKeyHandle *hptr;\n#endif\n#if !defined(OPENSSL_NO_RSA)\n\tchar tempbuf[1024];\n\tHWCryptoHook_ErrMsgBuf rmsg;\n#endif\n\tHWCryptoHook_PassphraseContext ppctx;\n#if !defined(OPENSSL_NO_RSA)\n\trmsg.buf = tempbuf;\n\trmsg.size = sizeof(tempbuf);\n#endif\n\tif(!hwcrhk_context)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_NOT_INITIALISED);\n\t\tgoto err;\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\thptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));\n\tif (!hptr)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n ppctx.ui_method = ui_method;\n\tppctx.callback_data = callback_data;\n\tif (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,\n\t\t&rmsg, &ppctx))\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_CHIL_ERROR);\n\t\tERR_add_error_data(1,rmsg.buf);\n\t\tgoto err;\n\t\t}\n\tif (!*hptr)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,\n\t\t\tHWCRHK_R_NO_KEY);\n\t\tgoto err;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RSA\n\trtmp = RSA_new_method(eng);\n\tRSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr);\n\trtmp->e = BN_new();\n\trtmp->n = BN_new();\n\trtmp->flags |= RSA_FLAG_EXT_PKEY;\n\tMPI2BN(rtmp->e, e);\n\tMPI2BN(rtmp->n, n);\n\tif (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)\n\t\t!= HWCRYPTOHOOK_ERROR_MPISIZE)\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,HWCRHK_R_CHIL_ERROR);\n\t\tERR_add_error_data(1,rmsg.buf);\n\t\tgoto err;\n\t\t}\n\tbn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));\n\tbn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));\n\tMPI2BN(rtmp->e, e);\n\tMPI2BN(rtmp->n, n);\n\tif (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))\n\t\t{\n\t\tHWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,\n\t\t\tHWCRHK_R_CHIL_ERROR);\n\t\tERR_add_error_data(1,rmsg.buf);\n\t\tgoto err;\n\t\t}\n\trtmp->e->top = e.size / sizeof(BN_ULONG);\n\tbn_fix_top(rtmp->e);\n\trtmp->n->top = n.size / sizeof(BN_ULONG);\n\tbn_fix_top(rtmp->n);\n\tres = EVP_PKEY_new();\n\tEVP_PKEY_assign_RSA(res, rtmp);\n#endif\n if (!res)\n HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,\n HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED);\n\treturn res;\n err:\n\tif (res)\n\t\tEVP_PKEY_free(res);\n#ifndef OPENSSL_NO_RSA\n\tif (rtmp)\n\t\tRSA_free(rtmp);\n#endif\n\treturn NULL;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tif (num < 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'RSA *RSA_new_method(ENGINE *engine)\n\t{\n\tRSA *ret;\n\tret=(RSA *)OPENSSL_malloc(sizeof(RSA));\n\tif (ret == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tret->meth = RSA_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_RSA();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_RSA(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD,\n\t\t\t\tERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n#endif\n\tret->pad=0;\n\tret->version=0;\n\tret->n=NULL;\n\tret->e=NULL;\n\tret->d=NULL;\n\tret->p=NULL;\n\tret->q=NULL;\n\tret->dmp1=NULL;\n\tret->dmq1=NULL;\n\tret->iqmp=NULL;\n\tret->references=1;\n\tret->_method_mod_n=NULL;\n\tret->_method_mod_p=NULL;\n\tret->_method_mod_q=NULL;\n\tret->blinding=NULL;\n\tret->bignum_data=NULL;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n#ifndef OPENSSL_NO_ENGINE\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n#endif\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']
|
1,666
| 0
|
https://github.com/openssl/openssl/blob/a00ae6c46e0d7907a7c9f9e85334e968aa5fd338/crypto/bf/bf_skey.c/#L78
|
void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
{
int i;
BF_LONG *p, ri, in[2];
const unsigned char *d, *end;
memcpy(key, &bf_init, sizeof(BF_KEY));
p = key->P;
if (len > ((BF_ROUNDS + 2) * 4))
len = (BF_ROUNDS + 2) * 4;
d = data;
end = &(data[len]);
for (i = 0; i < (BF_ROUNDS + 2); i++) {
ri = *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
p[i] ^= ri;
}
in[0] = 0L;
in[1] = 0L;
for (i = 0; i < (BF_ROUNDS + 2); i += 2) {
BF_encrypt(in, key);
p[i] = in[0];
p[i + 1] = in[1];
}
p = key->S;
for (i = 0; i < 4 * 256; i += 2) {
BF_encrypt(in, key);
p[i] = in[0];
p[i + 1] = in[1];
}
}
|
['int MAIN(int argc, char **argv)\n{\n unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;\n unsigned char *buf = NULL, *buf2 = NULL;\n int mret = 1;\n long count = 0, save_count = 0;\n int i, j, k;\n#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n long rsa_count;\n#endif\n#ifndef OPENSSL_NO_RSA\n unsigned rsa_num;\n#endif\n unsigned char md[EVP_MAX_MD_SIZE];\n#ifndef OPENSSL_NO_MD2\n unsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MDC2\n unsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD4\n unsigned char md4[MD4_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD5\n unsigned char md5[MD5_DIGEST_LENGTH];\n unsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA\n unsigned char sha[SHA_DIGEST_LENGTH];\n# ifndef OPENSSL_NO_SHA256\n unsigned char sha256[SHA256_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA512\n unsigned char sha512[SHA512_DIGEST_LENGTH];\n# endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RMD160\n unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RC4\n RC4_KEY rc4_ks;\n#endif\n#ifndef OPENSSL_NO_RC5\n RC5_32_KEY rc5_ks;\n#endif\n#ifndef OPENSSL_NO_RC2\n RC2_KEY rc2_ks;\n#endif\n#ifndef OPENSSL_NO_IDEA\n IDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef OPENSSL_NO_SEED\n SEED_KEY_SCHEDULE seed_ks;\n#endif\n#ifndef OPENSSL_NO_BF\n BF_KEY bf_ks;\n#endif\n#ifndef OPENSSL_NO_CAST\n CAST_KEY cast_ks;\n#endif\n static const unsigned char key16[16] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12\n };\n#ifndef OPENSSL_NO_AES\n static const unsigned char key24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char key32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n static const unsigned char ckey24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char ckey32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n#endif\n#ifndef OPENSSL_NO_AES\n# define MAX_BLOCK_SIZE 128\n#else\n# define MAX_BLOCK_SIZE 64\n#endif\n unsigned char DES_iv[8];\n unsigned char iv[2 * MAX_BLOCK_SIZE / 8];\n#ifndef OPENSSL_NO_DES\n static DES_cblock key =\n { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };\n static DES_cblock key2 =\n { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };\n static DES_cblock key3 =\n { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };\n DES_key_schedule sch;\n DES_key_schedule sch2;\n DES_key_schedule sch3;\n#endif\n#ifndef OPENSSL_NO_AES\n AES_KEY aes_ks1, aes_ks2, aes_ks3;\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n#endif\n#define D_MD2 0\n#define D_MDC2 1\n#define D_MD4 2\n#define D_MD5 3\n#define D_HMAC 4\n#define D_SHA1 5\n#define D_RMD160 6\n#define D_RC4 7\n#define D_CBC_DES 8\n#define D_EDE3_DES 9\n#define D_CBC_IDEA 10\n#define D_CBC_SEED 11\n#define D_CBC_RC2 12\n#define D_CBC_RC5 13\n#define D_CBC_BF 14\n#define D_CBC_CAST 15\n#define D_CBC_128_AES 16\n#define D_CBC_192_AES 17\n#define D_CBC_256_AES 18\n#define D_CBC_128_CML 19\n#define D_CBC_192_CML 20\n#define D_CBC_256_CML 21\n#define D_EVP 22\n#define D_SHA256 23\n#define D_SHA512 24\n#define D_WHIRLPOOL 25\n#define D_IGE_128_AES 26\n#define D_IGE_192_AES 27\n#define D_IGE_256_AES 28\n#define D_GHASH 29\n double d = 0.0;\n long c[ALGOR_NUM][SIZE_NUM];\n#ifndef OPENSSL_SYS_WIN32\n#endif\n#define R_DSA_512 0\n#define R_DSA_1024 1\n#define R_DSA_2048 2\n#define R_RSA_512 0\n#define R_RSA_1024 1\n#define R_RSA_2048 2\n#define R_RSA_3072 3\n#define R_RSA_4096 4\n#define R_RSA_7680 5\n#define R_RSA_15360 6\n#define R_EC_P160 0\n#define R_EC_P192 1\n#define R_EC_P224 2\n#define R_EC_P256 3\n#define R_EC_P384 4\n#define R_EC_P521 5\n#define R_EC_K163 6\n#define R_EC_K233 7\n#define R_EC_K283 8\n#define R_EC_K409 9\n#define R_EC_K571 10\n#define R_EC_B163 11\n#define R_EC_B233 12\n#define R_EC_B283 13\n#define R_EC_B409 14\n#define R_EC_B571 15\n#ifndef OPENSSL_NO_RSA\n RSA *rsa_key[RSA_NUM];\n long rsa_c[RSA_NUM][2];\n static unsigned int rsa_bits[RSA_NUM] = {\n 512, 1024, 2048, 3072, 4096, 7680, 15360\n };\n static unsigned char *rsa_data[RSA_NUM] = {\n test512, test1024, test2048, test3072, test4096, test7680, test15360\n };\n static int rsa_data_length[RSA_NUM] = {\n sizeof(test512), sizeof(test1024),\n sizeof(test2048), sizeof(test3072),\n sizeof(test4096), sizeof(test7680),\n sizeof(test15360)\n };\n#endif\n#ifndef OPENSSL_NO_DSA\n DSA *dsa_key[DSA_NUM];\n long dsa_c[DSA_NUM][2];\n static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };\n#endif\n#ifndef OPENSSL_NO_EC\n static unsigned int test_curves[EC_NUM] = {\n NID_secp160r1,\n NID_X9_62_prime192v1,\n NID_secp224r1,\n NID_X9_62_prime256v1,\n NID_secp384r1,\n NID_secp521r1,\n NID_sect163k1,\n NID_sect233k1,\n NID_sect283k1,\n NID_sect409k1,\n NID_sect571k1,\n NID_sect163r2,\n NID_sect233r1,\n NID_sect283r1,\n NID_sect409r1,\n NID_sect571r1\n };\n static const char *test_curves_names[EC_NUM] = {\n "secp160r1",\n "nistp192",\n "nistp224",\n "nistp256",\n "nistp384",\n "nistp521",\n "nistk163",\n "nistk233",\n "nistk283",\n "nistk409",\n "nistk571",\n "nistb163",\n "nistb233",\n "nistb283",\n "nistb409",\n "nistb571"\n };\n static int test_curves_bits[EC_NUM] = {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n#endif\n#ifndef OPENSSL_NO_ECDSA\n unsigned char ecdsasig[256];\n unsigned int ecdsasiglen;\n EC_KEY *ecdsa[EC_NUM];\n long ecdsa_c[EC_NUM][2];\n#endif\n#ifndef OPENSSL_NO_ECDH\n EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n int secret_size_a, secret_size_b;\n int ecdh_checks = 0;\n int secret_idx = 0;\n long ecdh_c[EC_NUM][2];\n#endif\n int rsa_doit[RSA_NUM];\n int dsa_doit[DSA_NUM];\n#ifndef OPENSSL_NO_ECDSA\n int ecdsa_doit[EC_NUM];\n#endif\n#ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n#endif\n int doit[ALGOR_NUM];\n int pr_header = 0;\n const EVP_CIPHER *evp_cipher = NULL;\n const EVP_MD *evp_md = NULL;\n int decrypt = 0;\n#ifndef NO_FORK\n int multi = 0;\n#endif\n int multiblock = 0;\n int misalign = MAX_MISALIGNMENT + 1;\n#ifndef TIMES\n usertime = -1;\n#endif\n apps_startup();\n memset(results, 0, sizeof(results));\n#ifndef OPENSSL_NO_DSA\n memset(dsa_key, 0, sizeof(dsa_key));\n#endif\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa[i] = NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n ecdh_a[i] = NULL;\n ecdh_b[i] = NULL;\n }\n#endif\n if (bio_err == NULL)\n if ((bio_err = BIO_new(BIO_s_file())) != NULL)\n BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);\n if (!load_config(bio_err, NULL))\n goto end;\n#ifndef OPENSSL_NO_RSA\n memset(rsa_key, 0, sizeof(rsa_key));\n for (i = 0; i < RSA_NUM; i++)\n rsa_key[i] = NULL;\n#endif\n if ((buf_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n if ((buf2_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n misalign = 0;\n buf = buf_malloc;\n buf2 = buf2_malloc;\n memset(c, 0, sizeof(c));\n memset(DES_iv, 0, sizeof(DES_iv));\n memset(iv, 0, sizeof(iv));\n for (i = 0; i < ALGOR_NUM; i++)\n doit[i] = 0;\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 0;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 0;\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 0;\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 0;\n#endif\n j = 0;\n argc--;\n argv++;\n while (argc) {\n if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {\n usertime = 0;\n j--;\n } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no EVP given\\n");\n goto end;\n }\n evp_cipher = EVP_get_cipherbyname(*argv);\n if (!evp_cipher) {\n evp_md = EVP_get_digestbyname(*argv);\n }\n if (!evp_cipher && !evp_md) {\n BIO_printf(bio_err, "%s is an unknown cipher or digest\\n",\n *argv);\n goto end;\n }\n doit[D_EVP] = 1;\n } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {\n decrypt = 1;\n j--;\n }\n#ifndef OPENSSL_NO_ENGINE\n else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no engine given\\n");\n goto end;\n }\n setup_engine(bio_err, *argv, 0);\n j--;\n }\n#endif\n#ifndef NO_FORK\n else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no multi count given\\n");\n goto end;\n }\n multi = atoi(argv[0]);\n if (multi <= 0) {\n BIO_printf(bio_err, "bad multi count\\n");\n goto end;\n }\n j--;\n }\n#endif\n else if (argc > 0 && !strcmp(*argv, "-mr")) {\n mr = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-mb")) {\n multiblock = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-misalign")) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no misalignment given\\n");\n goto end;\n }\n misalign = atoi(argv[0]);\n if (misalign < 0 || misalign > MAX_MISALIGNMENT) {\n BIO_printf(bio_err,\n "misalignment is outsize permitted range 0-%d\\n",\n MAX_MISALIGNMENT);\n goto end;\n }\n buf = buf_malloc + misalign;\n buf2 = buf2_malloc + misalign;\n j--;\n } else\n#ifndef OPENSSL_NO_MD2\n if (strcmp(*argv, "md2") == 0)\n doit[D_MD2] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MDC2\n if (strcmp(*argv, "mdc2") == 0)\n doit[D_MDC2] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MD4\n if (strcmp(*argv, "md4") == 0)\n doit[D_MD4] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "md5") == 0)\n doit[D_MD5] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "hmac") == 0)\n doit[D_HMAC] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_SHA\n if (strcmp(*argv, "sha1") == 0)\n doit[D_SHA1] = 1;\n else if (strcmp(*argv, "sha") == 0)\n doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;\n else\n# ifndef OPENSSL_NO_SHA256\n if (strcmp(*argv, "sha256") == 0)\n doit[D_SHA256] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (strcmp(*argv, "sha512") == 0)\n doit[D_SHA512] = 1;\n else\n# endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n if (strcmp(*argv, "whirlpool") == 0)\n doit[D_WHIRLPOOL] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RMD160\n if (strcmp(*argv, "ripemd") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "rmd160") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "ripemd160") == 0)\n doit[D_RMD160] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RC4\n if (strcmp(*argv, "rc4") == 0)\n doit[D_RC4] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des-cbc") == 0)\n doit[D_CBC_DES] = 1;\n else if (strcmp(*argv, "des-ede3") == 0)\n doit[D_EDE3_DES] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes-128-cbc") == 0)\n doit[D_CBC_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-cbc") == 0)\n doit[D_CBC_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-cbc") == 0)\n doit[D_CBC_256_AES] = 1;\n else if (strcmp(*argv, "aes-128-ige") == 0)\n doit[D_IGE_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-ige") == 0)\n doit[D_IGE_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-ige") == 0)\n doit[D_IGE_256_AES] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia-128-cbc") == 0)\n doit[D_CBC_128_CML] = 1;\n else if (strcmp(*argv, "camellia-192-cbc") == 0)\n doit[D_CBC_192_CML] = 1;\n else if (strcmp(*argv, "camellia-256-cbc") == 0)\n doit[D_CBC_256_CML] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RSA\n# if 0\n if (strcmp(*argv, "rsaref") == 0) {\n RSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n j--;\n } else\n# endif\n# ifndef RSA_NULL\n if (strcmp(*argv, "openssl") == 0) {\n RSA_set_default_method(RSA_PKCS1_SSLeay());\n j--;\n } else\n# endif\n#endif\n if (strcmp(*argv, "dsa512") == 0)\n dsa_doit[R_DSA_512] = 2;\n else if (strcmp(*argv, "dsa1024") == 0)\n dsa_doit[R_DSA_1024] = 2;\n else if (strcmp(*argv, "dsa2048") == 0)\n dsa_doit[R_DSA_2048] = 2;\n else if (strcmp(*argv, "rsa512") == 0)\n rsa_doit[R_RSA_512] = 2;\n else if (strcmp(*argv, "rsa1024") == 0)\n rsa_doit[R_RSA_1024] = 2;\n else if (strcmp(*argv, "rsa2048") == 0)\n rsa_doit[R_RSA_2048] = 2;\n else if (strcmp(*argv, "rsa3072") == 0)\n rsa_doit[R_RSA_3072] = 2;\n else if (strcmp(*argv, "rsa4096") == 0)\n rsa_doit[R_RSA_4096] = 2;\n else if (strcmp(*argv, "rsa7680") == 0)\n rsa_doit[R_RSA_7680] = 2;\n else if (strcmp(*argv, "rsa15360") == 0)\n rsa_doit[R_RSA_15360] = 2;\n else\n#ifndef OPENSSL_NO_RC2\n if (strcmp(*argv, "rc2-cbc") == 0)\n doit[D_CBC_RC2] = 1;\n else if (strcmp(*argv, "rc2") == 0)\n doit[D_CBC_RC2] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RC5\n if (strcmp(*argv, "rc5-cbc") == 0)\n doit[D_CBC_RC5] = 1;\n else if (strcmp(*argv, "rc5") == 0)\n doit[D_CBC_RC5] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_IDEA\n if (strcmp(*argv, "idea-cbc") == 0)\n doit[D_CBC_IDEA] = 1;\n else if (strcmp(*argv, "idea") == 0)\n doit[D_CBC_IDEA] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_SEED\n if (strcmp(*argv, "seed-cbc") == 0)\n doit[D_CBC_SEED] = 1;\n else if (strcmp(*argv, "seed") == 0)\n doit[D_CBC_SEED] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_BF\n if (strcmp(*argv, "bf-cbc") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "blowfish") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "bf") == 0)\n doit[D_CBC_BF] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_CAST\n if (strcmp(*argv, "cast-cbc") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast5") == 0)\n doit[D_CBC_CAST] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des") == 0) {\n doit[D_CBC_DES] = 1;\n doit[D_EDE3_DES] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes") == 0) {\n doit[D_CBC_128_AES] = 1;\n doit[D_CBC_192_AES] = 1;\n doit[D_CBC_256_AES] = 1;\n } else if (strcmp(*argv, "ghash") == 0) {\n doit[D_GHASH] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia") == 0) {\n doit[D_CBC_128_CML] = 1;\n doit[D_CBC_192_CML] = 1;\n doit[D_CBC_256_CML] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_RSA\n if (strcmp(*argv, "rsa") == 0) {\n rsa_doit[R_RSA_512] = 1;\n rsa_doit[R_RSA_1024] = 1;\n rsa_doit[R_RSA_2048] = 1;\n rsa_doit[R_RSA_3072] = 1;\n rsa_doit[R_RSA_4096] = 1;\n rsa_doit[R_RSA_7680] = 1;\n rsa_doit[R_RSA_15360] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_DSA\n if (strcmp(*argv, "dsa") == 0) {\n dsa_doit[R_DSA_512] = 1;\n dsa_doit[R_DSA_1024] = 1;\n dsa_doit[R_DSA_2048] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_ECDSA\n if (strcmp(*argv, "ecdsap160") == 0)\n ecdsa_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdsap192") == 0)\n ecdsa_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdsap224") == 0)\n ecdsa_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdsap256") == 0)\n ecdsa_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdsap384") == 0)\n ecdsa_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdsap521") == 0)\n ecdsa_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdsak163") == 0)\n ecdsa_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdsak233") == 0)\n ecdsa_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdsak283") == 0)\n ecdsa_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdsak409") == 0)\n ecdsa_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdsak571") == 0)\n ecdsa_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdsab163") == 0)\n ecdsa_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdsab233") == 0)\n ecdsa_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdsab283") == 0)\n ecdsa_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdsab409") == 0)\n ecdsa_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdsab571") == 0)\n ecdsa_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdsa") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_ECDH\n if (strcmp(*argv, "ecdhp160") == 0)\n ecdh_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdhp192") == 0)\n ecdh_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdhp224") == 0)\n ecdh_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdhp256") == 0)\n ecdh_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdhp384") == 0)\n ecdh_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdhp521") == 0)\n ecdh_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdhk163") == 0)\n ecdh_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdhk233") == 0)\n ecdh_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdhk283") == 0)\n ecdh_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdhk409") == 0)\n ecdh_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdhk571") == 0)\n ecdh_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdhb163") == 0)\n ecdh_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdhb233") == 0)\n ecdh_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdhb283") == 0)\n ecdh_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdhb409") == 0)\n ecdh_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdhb571") == 0)\n ecdh_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdh") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n } else\n#endif\n {\n BIO_printf(bio_err, "Error: bad option or value\\n");\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available values:\\n");\n#ifndef OPENSSL_NO_MD2\n BIO_printf(bio_err, "md2 ");\n#endif\n#ifndef OPENSSL_NO_MDC2\n BIO_printf(bio_err, "mdc2 ");\n#endif\n#ifndef OPENSSL_NO_MD4\n BIO_printf(bio_err, "md4 ");\n#endif\n#ifndef OPENSSL_NO_MD5\n BIO_printf(bio_err, "md5 ");\n# ifndef OPENSSL_NO_HMAC\n BIO_printf(bio_err, "hmac ");\n# endif\n#endif\n#ifndef OPENSSL_NO_SHA1\n BIO_printf(bio_err, "sha1 ");\n#endif\n#ifndef OPENSSL_NO_SHA256\n BIO_printf(bio_err, "sha256 ");\n#endif\n#ifndef OPENSSL_NO_SHA512\n BIO_printf(bio_err, "sha512 ");\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n BIO_printf(bio_err, "whirlpool");\n#endif\n#ifndef OPENSSL_NO_RMD160\n BIO_printf(bio_err, "rmd160");\n#endif\n#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \\\n !defined(OPENSSL_NO_WHIRLPOOL)\n BIO_printf(bio_err, "\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea-cbc ");\n#endif\n#ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC5\n BIO_printf(bio_err, "rc5-cbc ");\n#endif\n#ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "bf-cbc");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n BIO_printf(bio_err, "\\n");\n#endif\n#ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des-cbc des-ede3 ");\n#endif\n#ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");\n BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err,\n "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC4\n BIO_printf(bio_err, "rc4");\n#endif\n BIO_printf(bio_err, "\\n");\n#ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err,\n "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\\n");\n BIO_printf(bio_err, "rsa7680 rsa15360\\n");\n#endif\n#ifndef OPENSSL_NO_DSA\n BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\\n");\n#endif\n#ifndef OPENSSL_NO_ECDSA\n BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "\n "ecdsap256 ecdsap384 ecdsap521\\n");\n BIO_printf(bio_err,\n "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n BIO_printf(bio_err,\n "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n BIO_printf(bio_err, "ecdsa\\n");\n#endif\n#ifndef OPENSSL_NO_ECDH\n BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "\n "ecdhp256 ecdhp384 ecdhp521\\n");\n BIO_printf(bio_err,\n "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n BIO_printf(bio_err,\n "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n BIO_printf(bio_err, "ecdh\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea ");\n#endif\n#ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed ");\n#endif\n#ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2 ");\n#endif\n#ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des ");\n#endif\n#ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "camellia ");\n#endif\n#ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err, "rsa ");\n#endif\n#ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "blowfish");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \\\n !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \\\n !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \\\n !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)\n BIO_printf(bio_err, "\\n");\n#endif\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available options:\\n");\n#if defined(TIMES) || defined(USE_TOD)\n BIO_printf(bio_err, "-elapsed "\n "measure time in real time instead of CPU user time.\\n");\n#endif\n#ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n "-engine e "\n "use engine e, possibly a hardware device.\\n");\n#endif\n BIO_printf(bio_err, "-evp e " "use EVP e.\\n");\n BIO_printf(bio_err,\n "-decrypt "\n "time decryption instead of encryption (only EVP).\\n");\n BIO_printf(bio_err,\n "-mr "\n "produce machine readable output.\\n");\n BIO_printf(bio_err,\n "-mb "\n "perform multi-block benchmark (for specific ciphers)\\n");\n BIO_printf(bio_err,\n "-misalign n "\n "perform benchmark with misaligned data\\n");\n#ifndef NO_FORK\n BIO_printf(bio_err,\n "-multi n " "run n benchmarks in parallel.\\n");\n#endif\n goto end;\n }\n argc--;\n argv++;\n j++;\n }\n#ifndef NO_FORK\n if (multi && do_multi(multi))\n goto show_res;\n#endif\n if (j == 0) {\n for (i = 0; i < ALGOR_NUM; i++) {\n if (i != D_EVP)\n doit[i] = 1;\n }\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 1;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 1;\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n#endif\n }\n for (i = 0; i < ALGOR_NUM; i++)\n if (doit[i])\n pr_header++;\n if (usertime == 0 && !mr)\n BIO_printf(bio_err,\n "You have chosen to measure elapsed time "\n "instead of user CPU time.\\n");\n#ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++) {\n const unsigned char *p;\n p = rsa_data[i];\n rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);\n if (rsa_key[i] == NULL) {\n BIO_printf(bio_err, "internal error loading RSA key number %d\\n",\n i);\n goto end;\n }\n# if 0\n else {\n BIO_printf(bio_err,\n mr ? "+RK:%d:"\n : "Loaded RSA key, %d bit modulus and e= 0x",\n BN_num_bits(rsa_key[i]->n));\n BN_print(bio_err, rsa_key[i]->e);\n BIO_printf(bio_err, "\\n");\n }\n# endif\n }\n#endif\n#ifndef OPENSSL_NO_DSA\n dsa_key[0] = get_dsa512();\n dsa_key[1] = get_dsa1024();\n dsa_key[2] = get_dsa2048();\n#endif\n#ifndef OPENSSL_NO_DES\n DES_set_key_unchecked(&key, &sch);\n DES_set_key_unchecked(&key2, &sch2);\n DES_set_key_unchecked(&key3, &sch3);\n#endif\n#ifndef OPENSSL_NO_AES\n AES_set_encrypt_key(key16, 128, &aes_ks1);\n AES_set_encrypt_key(key24, 192, &aes_ks2);\n AES_set_encrypt_key(key32, 256, &aes_ks3);\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n Camellia_set_key(key16, 128, &camellia_ks1);\n Camellia_set_key(ckey24, 192, &camellia_ks2);\n Camellia_set_key(ckey32, 256, &camellia_ks3);\n#endif\n#ifndef OPENSSL_NO_IDEA\n idea_set_encrypt_key(key16, &idea_ks);\n#endif\n#ifndef OPENSSL_NO_SEED\n SEED_set_key(key16, &seed_ks);\n#endif\n#ifndef OPENSSL_NO_RC4\n RC4_set_key(&rc4_ks, 16, key16);\n#endif\n#ifndef OPENSSL_NO_RC2\n RC2_set_key(&rc2_ks, 16, key16, 128);\n#endif\n#ifndef OPENSSL_NO_RC5\n RC5_32_set_key(&rc5_ks, 16, key16, 12);\n#endif\n#ifndef OPENSSL_NO_BF\n BF_set_key(&bf_ks, 16, key16);\n#endif\n#ifndef OPENSSL_NO_CAST\n CAST_set_key(&cast_ks, 16, key16);\n#endif\n#ifndef OPENSSL_NO_RSA\n memset(rsa_c, 0, sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "First we calculate the approximate speed ...\\n");\n count = 10;\n do {\n long it;\n count *= 2;\n Time_F(START);\n for (it = count; it; it--)\n DES_ecb_encrypt((DES_cblock *)buf,\n (DES_cblock *)buf, &sch, DES_ENCRYPT);\n d = Time_F(STOP);\n } while (d < 3);\n save_count = count;\n c[D_MD2][0] = count / 10;\n c[D_MDC2][0] = count / 10;\n c[D_MD4][0] = count;\n c[D_MD5][0] = count;\n c[D_HMAC][0] = count;\n c[D_SHA1][0] = count;\n c[D_RMD160][0] = count;\n c[D_RC4][0] = count * 5;\n c[D_CBC_DES][0] = count;\n c[D_EDE3_DES][0] = count / 3;\n c[D_CBC_IDEA][0] = count;\n c[D_CBC_SEED][0] = count;\n c[D_CBC_RC2][0] = count;\n c[D_CBC_RC5][0] = count;\n c[D_CBC_BF][0] = count;\n c[D_CBC_CAST][0] = count;\n c[D_CBC_128_AES][0] = count;\n c[D_CBC_192_AES][0] = count;\n c[D_CBC_256_AES][0] = count;\n c[D_CBC_128_CML][0] = count;\n c[D_CBC_192_CML][0] = count;\n c[D_CBC_256_CML][0] = count;\n c[D_SHA256][0] = count;\n c[D_SHA512][0] = count;\n c[D_WHIRLPOOL][0] = count;\n c[D_IGE_128_AES][0] = count;\n c[D_IGE_192_AES][0] = count;\n c[D_IGE_256_AES][0] = count;\n c[D_GHASH][0] = count;\n for (i = 1; i < SIZE_NUM; i++) {\n long l0, l1;\n l0 = (long)lengths[0];\n l1 = (long)lengths[i];\n c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;\n c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;\n c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;\n c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;\n c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;\n c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;\n c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;\n c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;\n c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;\n c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;\n l0 = (long)lengths[i - 1];\n c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;\n c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;\n c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;\n c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;\n c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;\n c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;\n c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;\n c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;\n c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;\n c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;\n c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;\n c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;\n c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;\n c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;\n c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;\n c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;\n c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;\n c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;\n }\n# ifndef OPENSSL_NO_RSA\n rsa_c[R_RSA_512][0] = count / 2000;\n rsa_c[R_RSA_512][1] = count / 400;\n for (i = 1; i < RSA_NUM; i++) {\n rsa_c[i][0] = rsa_c[i - 1][0] / 8;\n rsa_c[i][1] = rsa_c[i - 1][1] / 4;\n if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n rsa_doit[i] = 0;\n else {\n if (rsa_c[i][0] == 0) {\n rsa_c[i][0] = 1;\n rsa_c[i][1] = 20;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_c[R_DSA_512][0] = count / 1000;\n dsa_c[R_DSA_512][1] = count / 1000 / 2;\n for (i = 1; i < DSA_NUM; i++) {\n dsa_c[i][0] = dsa_c[i - 1][0] / 4;\n dsa_c[i][1] = dsa_c[i - 1][1] / 4;\n if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n dsa_doit[i] = 0;\n else {\n if (dsa_c[i] == 0) {\n dsa_c[i][0] = 1;\n dsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n ecdsa_c[R_EC_P160][0] = count / 1000;\n ecdsa_c[R_EC_P160][1] = count / 1000 / 2;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_K163][0] = count / 1000;\n ecdsa_c[R_EC_K163][1] = count / 1000 / 2;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_B163][0] = count / 1000;\n ecdsa_c[R_EC_B163][1] = count / 1000 / 2;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n ecdh_c[R_EC_P160][0] = count / 1000;\n ecdh_c[R_EC_P160][1] = count / 1000;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_K163][0] = count / 1000;\n ecdh_c[R_EC_K163][1] = count / 1000;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_B163][0] = count / 1000;\n ecdh_c[R_EC_B163][1] = count / 1000;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n# endif\n# define COND(d) (count < (d))\n# define COUNT(d) (d)\n# else\n# error "You cannot disable DES on systems without SIGALRM."\n# endif\n#else\n# define COND(c) (run && count<0x7fffffff)\n# define COUNT(d) (count)\n# ifndef _WIN32\n signal(SIGALRM, sig_done);\n# endif\n#endif\n#ifndef OPENSSL_NO_MD2\n if (doit[D_MD2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD2], c[D_MD2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,\n EVP_md2(), NULL);\n d = Time_F(STOP);\n print_result(D_MD2, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_MDC2\n if (doit[D_MDC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,\n EVP_mdc2(), NULL);\n d = Time_F(STOP);\n print_result(D_MDC2, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_MD4\n if (doit[D_MD4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD4], c[D_MD4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD4][j]); count++)\n EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),\n NULL, EVP_md4(), NULL);\n d = Time_F(STOP);\n print_result(D_MD4, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_MD5\n if (doit[D_MD5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD5], c[D_MD5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD5][j]); count++)\n MD5(buf, lengths[j], md5);\n d = Time_F(STOP);\n print_result(D_MD5, j, count, d);\n }\n }\n#endif\n#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n if (doit[D_HMAC]) {\n HMAC_CTX hctx;\n HMAC_CTX_init(&hctx);\n HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",\n 16, EVP_md5(), NULL);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {\n HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);\n HMAC_Update(&hctx, buf, lengths[j]);\n HMAC_Final(&hctx, &(hmac[0]), NULL);\n }\n d = Time_F(STOP);\n print_result(D_HMAC, j, count, d);\n }\n HMAC_CTX_cleanup(&hctx);\n }\n#endif\n#ifndef OPENSSL_NO_SHA\n if (doit[D_SHA1]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)\n# if 0\n EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,\n EVP_sha1(), NULL);\n# else\n SHA1(buf, lengths[j], sha);\n# endif\n d = Time_F(STOP);\n print_result(D_SHA1, j, count, d);\n }\n }\n# ifndef OPENSSL_NO_SHA256\n if (doit[D_SHA256]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)\n SHA256(buf, lengths[j], sha256);\n d = Time_F(STOP);\n print_result(D_SHA256, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (doit[D_SHA512]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)\n SHA512(buf, lengths[j], sha512);\n d = Time_F(STOP);\n print_result(D_SHA512, j, count, d);\n }\n }\n# endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n if (doit[D_WHIRLPOOL]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)\n WHIRLPOOL(buf, lengths[j], whirlpool);\n d = Time_F(STOP);\n print_result(D_WHIRLPOOL, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RMD160\n if (doit[D_RMD160]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,\n EVP_ripemd160(), NULL);\n d = Time_F(STOP);\n print_result(D_RMD160, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RC4\n if (doit[D_RC4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RC4], c[D_RC4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RC4][j]); count++)\n RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);\n d = Time_F(STOP);\n print_result(D_RC4, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_DES\n if (doit[D_CBC_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)\n DES_ncbc_encrypt(buf, buf, lengths[j], &sch,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_DES, j, count, d);\n }\n }\n if (doit[D_EDE3_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)\n DES_ede3_cbc_encrypt(buf, buf, lengths[j],\n &sch, &sch2, &sch3,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_EDE3_DES, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_AES\n if (doit[D_CBC_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_AES, j, count, d);\n }\n }\n if (doit[D_CBC_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_AES, j, count, d);\n }\n }\n if (doit[D_CBC_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_AES, j, count, d);\n }\n }\n if (doit[D_IGE_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_128_AES, j, count, d);\n }\n }\n if (doit[D_IGE_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_192_AES, j, count, d);\n }\n }\n if (doit[D_IGE_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_256_AES, j, count, d);\n }\n }\n if (doit[D_GHASH]) {\n GCM128_CONTEXT *ctx =\n CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);\n CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)\n CRYPTO_gcm128_aad(ctx, buf, lengths[j]);\n d = Time_F(STOP);\n print_result(D_GHASH, j, count, d);\n }\n CRYPTO_gcm128_release(ctx);\n }\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n if (doit[D_CBC_128_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks1,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_CML, j, count, d);\n }\n }\n if (doit[D_CBC_192_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks2,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_CML, j, count, d);\n }\n }\n if (doit[D_CBC_256_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks3,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_CML, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_IDEA\n if (doit[D_CBC_IDEA]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)\n idea_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &idea_ks,\n iv, IDEA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_IDEA, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_SEED\n if (doit[D_CBC_SEED]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)\n SEED_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &seed_ks, iv, 1);\n d = Time_F(STOP);\n print_result(D_CBC_SEED, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RC2\n if (doit[D_CBC_RC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)\n RC2_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc2_ks,\n iv, RC2_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC2, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RC5\n if (doit[D_CBC_RC5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)\n RC5_32_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc5_ks,\n iv, RC5_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC5, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_BF\n if (doit[D_CBC_BF]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)\n BF_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &bf_ks,\n iv, BF_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_BF, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_CAST\n if (doit[D_CBC_CAST]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)\n CAST_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &cast_ks,\n iv, CAST_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_CAST, j, count, d);\n }\n }\n#endif\n if (doit[D_EVP]) {\n#ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n if (multiblock && evp_cipher) {\n if (!\n (EVP_CIPHER_flags(evp_cipher) &\n EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {\n fprintf(stderr, "%s is not multi-block capable\\n",\n OBJ_nid2ln(evp_cipher->nid));\n goto end;\n }\n multiblock_speed(evp_cipher);\n mret = 0;\n goto end;\n }\n#endif\n for (j = 0; j < SIZE_NUM; j++) {\n if (evp_cipher) {\n EVP_CIPHER_CTX ctx;\n int outl;\n names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);\n print_message(names[D_EVP], save_count, lengths[j]);\n EVP_CIPHER_CTX_init(&ctx);\n if (decrypt)\n EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n else\n EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n EVP_CIPHER_CTX_set_padding(&ctx, 0);\n Time_F(START);\n if (decrypt)\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n else\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n if (decrypt)\n EVP_DecryptFinal_ex(&ctx, buf, &outl);\n else\n EVP_EncryptFinal_ex(&ctx, buf, &outl);\n d = Time_F(STOP);\n EVP_CIPHER_CTX_cleanup(&ctx);\n }\n if (evp_md) {\n names[D_EVP] = OBJ_nid2ln(evp_md->type);\n print_message(names[D_EVP], save_count, lengths[j]);\n Time_F(START);\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]); count++)\n EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);\n d = Time_F(STOP);\n }\n print_result(D_EVP, j, count, d);\n }\n }\n#ifndef OPENSSL_SYS_WIN32\n#endif\n RAND_pseudo_bytes(buf, 36);\n#ifndef OPENSSL_NO_RSA\n for (j = 0; j < RSA_NUM; j++) {\n int ret;\n if (!rsa_doit[j])\n continue;\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "RSA sign failure. No RSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("private", "rsa",\n rsa_c[j][0], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,\n &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "RSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R1:%ld:%d:%.2f\\n"\n : "%ld %d bit private RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n# if 1\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "RSA verify failure. No RSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_doit[j] = 0;\n } else {\n pkey_print_message("public", "rsa",\n rsa_c[j][1], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,\n rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "RSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R2:%ld:%d:%.2f\\n"\n : "%ld %d bit public RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][1] = d / (double)count;\n }\n# endif\n if (rsa_count <= 1) {\n for (j++; j < RSA_NUM; j++)\n rsa_doit[j] = 0;\n }\n }\n#endif\n RAND_pseudo_bytes(buf, 20);\n#ifndef OPENSSL_NO_DSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < DSA_NUM; j++) {\n unsigned int kk;\n int ret;\n if (!dsa_doit[j])\n continue;\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "DSA sign failure. No DSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "dsa",\n dsa_c[j][0], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "DSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R3:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA signs in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "DSA verify failure. No DSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n dsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "dsa",\n dsa_c[j][1], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "DSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R4:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA verify in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < DSA_NUM; j++)\n dsa_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n int ret;\n if (!ecdsa_doit[j])\n continue;\n ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if (ecdsa[j] == NULL) {\n BIO_printf(bio_err, "ECDSA failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n# if 1\n EC_KEY_precompute_mult(ecdsa[j], NULL);\n# endif\n EC_KEY_generate_key(ecdsa[j]);\n ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "ECDSA sign failure. No ECDSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "ecdsa",\n ecdsa_c[j][0],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {\n ret = ECDSA_sign(0, buf, 20,\n ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "ECDSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R5:%ld:%d:%.2f\\n" :\n "%ld %d bit ECDSA signs in %.2fs \\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err,\n "ECDSA verify failure. No ECDSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n ecdsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "ecdsa",\n ecdsa_c[j][1],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {\n ret =\n ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,\n ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err, "ECDSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R6:%ld:%d:%.2f\\n"\n : "%ld %d bit ECDSA verify in %.2fs\\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdsa_doit[j] = 0;\n }\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDH\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n if (!ecdh_doit[j])\n continue;\n ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {\n BIO_printf(bio_err, "ECDH failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n if (!EC_KEY_generate_key(ecdh_a[j]) ||\n !EC_KEY_generate_key(ecdh_b[j])) {\n BIO_printf(bio_err, "ECDH key generation failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n int field_size, outlen;\n void *(*kdf) (const void *in, size_t inlen, void *out,\n size_t *xoutlen);\n field_size =\n EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n if (field_size <= 24 * 8) {\n outlen = KDF1_SHA1_len;\n kdf = KDF1_SHA1;\n } else {\n outlen = (field_size + 7) / 8;\n kdf = NULL;\n }\n secret_size_a =\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n secret_size_b =\n ECDH_compute_key(secret_b, outlen,\n EC_KEY_get0_public_key(ecdh_a[j]),\n ecdh_b[j], kdf);\n if (secret_size_a != secret_size_b)\n ecdh_checks = 0;\n else\n ecdh_checks = 1;\n for (secret_idx = 0; (secret_idx < secret_size_a)\n && (ecdh_checks == 1); secret_idx++) {\n if (secret_a[secret_idx] != secret_b[secret_idx])\n ecdh_checks = 0;\n }\n if (ecdh_checks == 0) {\n BIO_printf(bio_err, "ECDH computations don\'t match.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n }\n pkey_print_message("", "ecdh",\n ecdh_c[j][0],\n test_curves_bits[j], ECDH_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R7:%ld:%d:%.2f\\n" :\n "%ld %d-bit ECDH ops in %.2fs\\n", count,\n test_curves_bits[j], d);\n ecdh_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdh_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n#endif\n#ifndef NO_FORK\n show_res:\n#endif\n if (!mr) {\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_BUILT_ON));\n printf("options:");\n printf("%s ", BN_options());\n#ifndef OPENSSL_NO_MD2\n printf("%s ", MD2_options());\n#endif\n#ifndef OPENSSL_NO_RC4\n printf("%s ", RC4_options());\n#endif\n#ifndef OPENSSL_NO_DES\n printf("%s ", DES_options());\n#endif\n#ifndef OPENSSL_NO_AES\n printf("%s ", AES_options());\n#endif\n#ifndef OPENSSL_NO_IDEA\n printf("%s ", idea_options());\n#endif\n#ifndef OPENSSL_NO_BF\n printf("%s ", BF_options());\n#endif\n fprintf(stdout, "\\n%s\\n", SSLeay_version(SSLEAY_CFLAGS));\n }\n if (pr_header) {\n if (mr)\n fprintf(stdout, "+H");\n else {\n fprintf(stdout,\n "The \'numbers\' are in 1000s of bytes per second processed.\\n");\n fprintf(stdout, "type ");\n }\n for (j = 0; j < SIZE_NUM; j++)\n fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);\n fprintf(stdout, "\\n");\n }\n for (k = 0; k < ALGOR_NUM; k++) {\n if (!doit[k])\n continue;\n if (mr)\n fprintf(stdout, "+F:%d:%s", k, names[k]);\n else\n fprintf(stdout, "%-13s", names[k]);\n for (j = 0; j < SIZE_NUM; j++) {\n if (results[k][j] > 10000 && !mr)\n fprintf(stdout, " %11.2fk", results[k][j] / 1e3);\n else\n fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);\n }\n fprintf(stdout, "\\n");\n }\n#ifndef OPENSSL_NO_RSA\n j = 1;\n for (k = 0; k < RSA_NUM; k++) {\n if (!rsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F2:%u:%u:%f:%f\\n",\n k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);\n else\n fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n rsa_bits[k], rsa_results[k][0], rsa_results[k][1],\n 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);\n }\n#endif\n#ifndef OPENSSL_NO_DSA\n j = 1;\n for (k = 0; k < DSA_NUM; k++) {\n if (!dsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F3:%u:%u:%f:%f\\n",\n k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);\n else\n fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n dsa_bits[k], dsa_results[k][0], dsa_results[k][1],\n 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);\n }\n#endif\n#ifndef OPENSSL_NO_ECDSA\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%30ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F4:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdsa_results[k][0], ecdsa_results[k][1]);\n else\n fprintf(stdout,\n "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdsa_results[k][0], ecdsa_results[k][1],\n 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);\n }\n#endif\n#ifndef OPENSSL_NO_ECDH\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdh_doit[k])\n continue;\n if (j && !mr) {\n printf("%30sop op/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F5:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n else\n fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n }\n#endif\n mret = 0;\n end:\n ERR_print_errors(bio_err);\n if (buf_malloc != NULL)\n OPENSSL_free(buf_malloc);\n if (buf2_malloc != NULL)\n OPENSSL_free(buf2_malloc);\n#ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++)\n if (rsa_key[i] != NULL)\n RSA_free(rsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_DSA\n for (i = 0; i < DSA_NUM; i++)\n if (dsa_key[i] != NULL)\n DSA_free(dsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n if (ecdsa[i] != NULL)\n EC_KEY_free(ecdsa[i]);\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n if (ecdh_a[i] != NULL)\n EC_KEY_free(ecdh_a[i]);\n if (ecdh_b[i] != NULL)\n EC_KEY_free(ecdh_b[i]);\n }\n#endif\n apps_shutdown();\n OPENSSL_EXIT(mret);\n}', 'void BF_set_key(BF_KEY *key, int len, const unsigned char *data)\n{\n int i;\n BF_LONG *p, ri, in[2];\n const unsigned char *d, *end;\n memcpy(key, &bf_init, sizeof(BF_KEY));\n p = key->P;\n if (len > ((BF_ROUNDS + 2) * 4))\n len = (BF_ROUNDS + 2) * 4;\n d = data;\n end = &(data[len]);\n for (i = 0; i < (BF_ROUNDS + 2); i++) {\n ri = *(d++);\n if (d >= end)\n d = data;\n ri <<= 8;\n ri |= *(d++);\n if (d >= end)\n d = data;\n ri <<= 8;\n ri |= *(d++);\n if (d >= end)\n d = data;\n ri <<= 8;\n ri |= *(d++);\n if (d >= end)\n d = data;\n p[i] ^= ri;\n }\n in[0] = 0L;\n in[1] = 0L;\n for (i = 0; i < (BF_ROUNDS + 2); i += 2) {\n BF_encrypt(in, key);\n p[i] = in[0];\n p[i + 1] = in[1];\n }\n p = key->S;\n for (i = 0; i < 4 * 256; i += 2) {\n BF_encrypt(in, key);\n p[i] = in[0];\n p[i + 1] = in[1];\n }\n}']
|
1,667
| 0
|
https://github.com/libav/libav/blob/a734fa575f94c7c28103420f756b5f64dd0c806b/ffmpeg.c/#L3651
|
static int opt_streamid(const char *opt, const char *arg)
{
int idx;
char *p;
char idx_str[16];
strncpy(idx_str, arg, sizeof(idx_str));
idx_str[sizeof(idx_str)-1] = '\0';
p = strchr(idx_str, ':');
if (!p) {
fprintf(stderr,
"Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
arg, opt);
ffmpeg_exit(1);
}
*p++ = '\0';
idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);
streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
return 0;
}
|
['static int opt_streamid(const char *opt, const char *arg)\n{\n int idx;\n char *p;\n char idx_str[16];\n strncpy(idx_str, arg, sizeof(idx_str));\n idx_str[sizeof(idx_str)-1] = \'\\0\';\n p = strchr(idx_str, \':\');\n if (!p) {\n fprintf(stderr,\n "Invalid value \'%s\' for option \'%s\', required syntax is \'index:value\'\\n",\n arg, opt);\n ffmpeg_exit(1);\n }\n *p++ = \'\\0\';\n idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);\n streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);\n streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);\n return 0;\n}', 'static void *grow_array(void *array, int elem_size, int *size, int new_size)\n{\n if (new_size >= INT_MAX / elem_size) {\n fprintf(stderr, "Array too big.\\n");\n ffmpeg_exit(1);\n }\n if (*size < new_size) {\n uint8_t *tmp = av_realloc(array, new_size*elem_size);\n if (!tmp) {\n fprintf(stderr, "Could not alloc buffer.\\n");\n ffmpeg_exit(1);\n }\n memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);\n *size = new_size;\n return tmp;\n }\n return array;\n}', '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) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}']
|
1,668
| 0
|
https://github.com/libav/libav/blob/4860abb116674c7be31e825db05cdcfd30f3aff2/libavcodec/mpegvideo_common.h/#L662
|
static av_always_inline void MPV_motion_internal(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb,
uint8_t *dest_cr, int dir,
uint8_t **ref_picture,
op_pixels_func (*pix_op)[4],
qpel_mc_func (*qpix_op)[16], int is_mpeg12)
{
int dxy, mx, my, src_x, src_y, motion_x, motion_y;
int mb_x, mb_y, i;
uint8_t *ptr, *dest;
mb_x = s->mb_x;
mb_y = s->mb_y;
prefetch_motion(s, ref_picture, dir);
if(!is_mpeg12 && s->obmc && s->pict_type != FF_B_TYPE){
int16_t mv_cache[4][4][2];
const int xy= s->mb_x + s->mb_y*s->mb_stride;
const int mot_stride= s->b8_stride;
const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
assert(!s->mb_skipped);
memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
}else{
memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
}
if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
*(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
*(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
}else{
*(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
*(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
}
if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
*(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
*(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
}else{
*(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
*(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
}
mx = 0;
my = 0;
for(i=0;i<4;i++) {
const int x= (i&1)+1;
const int y= (i>>1)+1;
int16_t mv[5][2]= {
{mv_cache[y][x ][0], mv_cache[y][x ][1]},
{mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
{mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
{mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
{mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
ref_picture[0],
mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
pix_op[1],
mv);
mx += mv[0][0];
my += mv[0][1];
}
if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
return;
}
switch(s->mv_type) {
case MV_TYPE_16X16:
if(s->mcsel){
if(s->real_sprite_warping_points==1){
gmc1_motion(s, dest_y, dest_cb, dest_cr,
ref_picture);
}else{
gmc_motion(s, dest_y, dest_cb, dest_cr,
ref_picture);
}
}else if(!is_mpeg12 && s->quarter_sample){
qpel_motion(s, dest_y, dest_cb, dest_cr,
0, 0, 0,
ref_picture, pix_op, qpix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
}else if(!is_mpeg12 && ENABLE_WMV2 && s->mspel){
ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
}else
{
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, 0,
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
}
break;
case MV_TYPE_8X8:
if (!is_mpeg12) {
mx = 0;
my = 0;
if(s->quarter_sample){
for(i=0;i<4;i++) {
motion_x = s->mv[dir][i][0];
motion_y = s->mv[dir][i][1];
dxy = ((motion_y & 3) << 2) | (motion_x & 3);
src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
src_x = av_clip(src_x, -16, s->width);
if (src_x == s->width)
dxy &= ~3;
src_y = av_clip(src_y, -16, s->height);
if (src_y == s->height)
dxy &= ~12;
ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
if(s->flags&CODEC_FLAG_EMU_EDGE){
if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
|| (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
ff_emulated_edge_mc(s->edge_emu_buffer, ptr,
s->linesize, 9, 9,
src_x, src_y,
s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer;
}
}
dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;
qpix_op[1][dxy](dest, ptr, s->linesize);
mx += s->mv[dir][i][0]/2;
my += s->mv[dir][i][1]/2;
}
}else{
for(i=0;i<4;i++) {
hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,
ref_picture[0], 0, 0,
mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
s->width, s->height, s->linesize,
s->h_edge_pos, s->v_edge_pos,
8, 8, pix_op[1],
s->mv[dir][i][0], s->mv[dir][i][1]);
mx += s->mv[dir][i][0];
my += s->mv[dir][i][1];
}
}
if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))
chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
}
break;
case MV_TYPE_FIELD:
if (s->picture_structure == PICT_FRAME) {
if(!is_mpeg12 && s->quarter_sample){
for(i=0; i<2; i++){
qpel_motion(s, dest_y, dest_cb, dest_cr,
1, i, s->field_select[dir][i],
ref_picture, pix_op, qpix_op,
s->mv[dir][i][0], s->mv[dir][i][1], 8);
}
}else{
mpeg_motion(s, dest_y, dest_cb, dest_cr,
1, 0, s->field_select[dir][0],
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 8);
mpeg_motion(s, dest_y, dest_cb, dest_cr,
1, 1, s->field_select[dir][1],
ref_picture, pix_op,
s->mv[dir][1][0], s->mv[dir][1][1], 8);
}
} else {
if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != FF_B_TYPE && !s->first_field){
ref_picture= s->current_picture_ptr->data;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, s->field_select[dir][0],
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
}
break;
case MV_TYPE_16X8:
for(i=0; i<2; i++){
uint8_t ** ref2picture;
if(s->picture_structure == s->field_select[dir][i] + 1
|| s->pict_type == FF_B_TYPE || s->first_field){
ref2picture= ref_picture;
}else{
ref2picture= s->current_picture_ptr->data;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, s->field_select[dir][i],
ref2picture, pix_op,
s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8);
dest_y += 16*s->linesize;
dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;
}
break;
case MV_TYPE_DMV:
if(s->picture_structure == PICT_FRAME){
for(i=0; i<2; i++){
int j;
for(j=0; j<2; j++){
mpeg_motion(s, dest_y, dest_cb, dest_cr,
1, j, j^i,
ref_picture, pix_op,
s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8);
}
pix_op = s->dsp.avg_pixels_tab;
}
}else{
for(i=0; i<2; i++){
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, s->picture_structure != i+1,
ref_picture, pix_op,
s->mv[dir][2*i][0],s->mv[dir][2*i][1],16);
pix_op=s->dsp.avg_pixels_tab;
if(!s->first_field){
ref_picture = s->current_picture_ptr->data;
}
}
}
break;
default: assert(0);
}
}
|
['static av_always_inline void MPV_motion_internal(MpegEncContext *s,\n uint8_t *dest_y, uint8_t *dest_cb,\n uint8_t *dest_cr, int dir,\n uint8_t **ref_picture,\n op_pixels_func (*pix_op)[4],\n qpel_mc_func (*qpix_op)[16], int is_mpeg12)\n{\n int dxy, mx, my, src_x, src_y, motion_x, motion_y;\n int mb_x, mb_y, i;\n uint8_t *ptr, *dest;\n mb_x = s->mb_x;\n mb_y = s->mb_y;\n prefetch_motion(s, ref_picture, dir);\n if(!is_mpeg12 && s->obmc && s->pict_type != FF_B_TYPE){\n int16_t mv_cache[4][4][2];\n const int xy= s->mb_x + s->mb_y*s->mb_stride;\n const int mot_stride= s->b8_stride;\n const int mot_xy= mb_x*2 + mb_y*2*mot_stride;\n assert(!s->mb_skipped);\n memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);\n memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);\n memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);\n if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){\n memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);\n }else{\n memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);\n }\n if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){\n *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];\n *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];\n }else{\n *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];\n *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];\n }\n if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){\n *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];\n *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];\n }else{\n *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];\n *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];\n }\n mx = 0;\n my = 0;\n for(i=0;i<4;i++) {\n const int x= (i&1)+1;\n const int y= (i>>1)+1;\n int16_t mv[5][2]= {\n {mv_cache[y][x ][0], mv_cache[y][x ][1]},\n {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},\n {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},\n {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},\n {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};\n obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,\n ref_picture[0],\n mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,\n pix_op[1],\n mv);\n mx += mv[0][0];\n my += mv[0][1];\n }\n if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))\n chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);\n return;\n }\n switch(s->mv_type) {\n case MV_TYPE_16X16:\n if(s->mcsel){\n if(s->real_sprite_warping_points==1){\n gmc1_motion(s, dest_y, dest_cb, dest_cr,\n ref_picture);\n }else{\n gmc_motion(s, dest_y, dest_cb, dest_cr,\n ref_picture);\n }\n }else if(!is_mpeg12 && s->quarter_sample){\n qpel_motion(s, dest_y, dest_cb, dest_cr,\n 0, 0, 0,\n ref_picture, pix_op, qpix_op,\n s->mv[dir][0][0], s->mv[dir][0][1], 16);\n }else if(!is_mpeg12 && ENABLE_WMV2 && s->mspel){\n ff_mspel_motion(s, dest_y, dest_cb, dest_cr,\n ref_picture, pix_op,\n s->mv[dir][0][0], s->mv[dir][0][1], 16);\n }else\n {\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 0, 0, 0,\n ref_picture, pix_op,\n s->mv[dir][0][0], s->mv[dir][0][1], 16);\n }\n break;\n case MV_TYPE_8X8:\n if (!is_mpeg12) {\n mx = 0;\n my = 0;\n if(s->quarter_sample){\n for(i=0;i<4;i++) {\n motion_x = s->mv[dir][i][0];\n motion_y = s->mv[dir][i][1];\n dxy = ((motion_y & 3) << 2) | (motion_x & 3);\n src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;\n src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;\n src_x = av_clip(src_x, -16, s->width);\n if (src_x == s->width)\n dxy &= ~3;\n src_y = av_clip(src_y, -16, s->height);\n if (src_y == s->height)\n dxy &= ~12;\n ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);\n if(s->flags&CODEC_FLAG_EMU_EDGE){\n if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8\n || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){\n ff_emulated_edge_mc(s->edge_emu_buffer, ptr,\n s->linesize, 9, 9,\n src_x, src_y,\n s->h_edge_pos, s->v_edge_pos);\n ptr= s->edge_emu_buffer;\n }\n }\n dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize;\n qpix_op[1][dxy](dest, ptr, s->linesize);\n mx += s->mv[dir][i][0]/2;\n my += s->mv[dir][i][1]/2;\n }\n }else{\n for(i=0;i<4;i++) {\n hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize,\n ref_picture[0], 0, 0,\n mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,\n s->width, s->height, s->linesize,\n s->h_edge_pos, s->v_edge_pos,\n 8, 8, pix_op[1],\n s->mv[dir][i][0], s->mv[dir][i][1]);\n mx += s->mv[dir][i][0];\n my += s->mv[dir][i][1];\n }\n }\n if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY))\n chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);\n }\n break;\n case MV_TYPE_FIELD:\n if (s->picture_structure == PICT_FRAME) {\n if(!is_mpeg12 && s->quarter_sample){\n for(i=0; i<2; i++){\n qpel_motion(s, dest_y, dest_cb, dest_cr,\n 1, i, s->field_select[dir][i],\n ref_picture, pix_op, qpix_op,\n s->mv[dir][i][0], s->mv[dir][i][1], 8);\n }\n }else{\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 1, 0, s->field_select[dir][0],\n ref_picture, pix_op,\n s->mv[dir][0][0], s->mv[dir][0][1], 8);\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 1, 1, s->field_select[dir][1],\n ref_picture, pix_op,\n s->mv[dir][1][0], s->mv[dir][1][1], 8);\n }\n } else {\n if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != FF_B_TYPE && !s->first_field){\n ref_picture= s->current_picture_ptr->data;\n }\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 0, 0, s->field_select[dir][0],\n ref_picture, pix_op,\n s->mv[dir][0][0], s->mv[dir][0][1], 16);\n }\n break;\n case MV_TYPE_16X8:\n for(i=0; i<2; i++){\n uint8_t ** ref2picture;\n if(s->picture_structure == s->field_select[dir][i] + 1\n || s->pict_type == FF_B_TYPE || s->first_field){\n ref2picture= ref_picture;\n }else{\n ref2picture= s->current_picture_ptr->data;\n }\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 0, 0, s->field_select[dir][i],\n ref2picture, pix_op,\n s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8);\n dest_y += 16*s->linesize;\n dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;\n dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;\n }\n break;\n case MV_TYPE_DMV:\n if(s->picture_structure == PICT_FRAME){\n for(i=0; i<2; i++){\n int j;\n for(j=0; j<2; j++){\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 1, j, j^i,\n ref_picture, pix_op,\n s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8);\n }\n pix_op = s->dsp.avg_pixels_tab;\n }\n }else{\n for(i=0; i<2; i++){\n mpeg_motion(s, dest_y, dest_cb, dest_cr,\n 0, 0, s->picture_structure != i+1,\n ref_picture, pix_op,\n s->mv[dir][2*i][0],s->mv[dir][2*i][1],16);\n pix_op=s->dsp.avg_pixels_tab;\n if(!s->first_field){\n ref_picture = s->current_picture_ptr->data;\n }\n }\n }\n break;\n default: assert(0);\n }\n}']
|
1,669
| 0
|
https://github.com/openssl/openssl/blob/019bfef89964105cdf9256b6a6bc0aa7790bd020/crypto/x509/x509_vfy.c/#L420
|
static int check_chain_extensions(X509_STORE_CTX *ctx)
{
#ifdef OPENSSL_NO_CHAIN_VERIFY
return 1;
#else
int i, ok=0, must_be_ca;
X509 *x;
int (*cb)(int xok,X509_STORE_CTX *xctx);
int proxy_path_length = 0;
int allow_proxy_certs =
!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
cb=ctx->verify_cb;
must_be_ca = -1;
if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
allow_proxy_certs = 1;
for (i = 0; i < ctx->last_untrusted; i++)
{
int ret;
x = sk_X509_value(ctx->chain, i);
if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
&& (x->ex_flags & EXFLAG_CRITICAL))
{
ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
ctx->error_depth = i;
ctx->current_cert = x;
ok=cb(0,ctx);
if (!ok) goto end;
}
if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))
{
ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
ctx->error_depth = i;
ctx->current_cert = x;
ok=cb(0,ctx);
if (!ok) goto end;
}
ret = X509_check_ca(x);
switch(must_be_ca)
{
case -1:
if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1) && (ret != 0))
{
ret = 0;
ctx->error = X509_V_ERR_INVALID_CA;
}
else
ret = 1;
break;
case 0:
if (ret != 0)
{
ret = 0;
ctx->error = X509_V_ERR_INVALID_NON_CA;
}
else
ret = 1;
break;
default:
if ((ret == 0)
|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1)))
{
ret = 0;
ctx->error = X509_V_ERR_INVALID_CA;
}
else
ret = 1;
break;
}
if (ret == 0)
{
ctx->error_depth = i;
ctx->current_cert = x;
ok=cb(0,ctx);
if (!ok) goto end;
}
if (ctx->param->purpose > 0)
{
ret = X509_check_purpose(x, ctx->param->purpose,
must_be_ca > 0);
if ((ret == 0)
|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1)))
{
ctx->error = X509_V_ERR_INVALID_PURPOSE;
ctx->error_depth = i;
ctx->current_cert = x;
ok=cb(0,ctx);
if (!ok) goto end;
}
}
if ((i > 1) && (x->ex_pathlen != -1)
&& (i > (x->ex_pathlen + proxy_path_length + 1)))
{
ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
ctx->error_depth = i;
ctx->current_cert = x;
ok=cb(0,ctx);
if (!ok) goto end;
}
if (x->ex_flags & EXFLAG_PROXY)
{
if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen)
{
ctx->error =
X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
ctx->error_depth = i;
ctx->current_cert = x;
ok=cb(0,ctx);
if (!ok) goto end;
}
proxy_path_length++;
must_be_ca = 0;
}
else
must_be_ca = 1;
}
ok = 1;
end:
return ok;
#endif
}
|
['static int check_chain_extensions(X509_STORE_CTX *ctx)\n{\n#ifdef OPENSSL_NO_CHAIN_VERIFY\n\treturn 1;\n#else\n\tint i, ok=0, must_be_ca;\n\tX509 *x;\n\tint (*cb)(int xok,X509_STORE_CTX *xctx);\n\tint proxy_path_length = 0;\n\tint allow_proxy_certs =\n\t\t!!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);\n\tcb=ctx->verify_cb;\n\tmust_be_ca = -1;\n\tif (getenv("OPENSSL_ALLOW_PROXY_CERTS"))\n\t\tallow_proxy_certs = 1;\n\tfor (i = 0; i < ctx->last_untrusted; i++)\n\t\t{\n\t\tint ret;\n\t\tx = sk_X509_value(ctx->chain, i);\n\t\tif (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)\n\t\t\t&& (x->ex_flags & EXFLAG_CRITICAL))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tret = X509_check_ca(x);\n\t\tswitch(must_be_ca)\n\t\t\t{\n\t\tcase -1:\n\t\t\tif ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t&& (ret != 1) && (ret != 0))\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\tcase 0:\n\t\t\tif (ret != 0)\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_NON_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tif ((ret == 0)\n\t\t\t\t|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t\t&& (ret != 1)))\n\t\t\t\t{\n\t\t\t\tret = 0;\n\t\t\t\tctx->error = X509_V_ERR_INVALID_CA;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tret = 1;\n\t\t\tbreak;\n\t\t\t}\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (ctx->param->purpose > 0)\n\t\t\t{\n\t\t\tret = X509_check_purpose(x, ctx->param->purpose,\n\t\t\t\tmust_be_ca > 0);\n\t\t\tif ((ret == 0)\n\t\t\t\t|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n\t\t\t\t\t&& (ret != 1)))\n\t\t\t\t{\n\t\t\t\tctx->error = X509_V_ERR_INVALID_PURPOSE;\n\t\t\t\tctx->error_depth = i;\n\t\t\t\tctx->current_cert = x;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\t}\n\t\tif ((i > 1) && (x->ex_pathlen != -1)\n\t\t\t && (i > (x->ex_pathlen + proxy_path_length + 1)))\n\t\t\t{\n\t\t\tctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;\n\t\t\tctx->error_depth = i;\n\t\t\tctx->current_cert = x;\n\t\t\tok=cb(0,ctx);\n\t\t\tif (!ok) goto end;\n\t\t\t}\n\t\tif (x->ex_flags & EXFLAG_PROXY)\n\t\t\t{\n\t\t\tif (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen)\n\t\t\t\t{\n\t\t\t\tctx->error =\n\t\t\t\t\tX509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;\n\t\t\t\tctx->error_depth = i;\n\t\t\t\tctx->current_cert = x;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\tproxy_path_length++;\n\t\t\tmust_be_ca = 0;\n\t\t\t}\n\t\telse\n\t\t\tmust_be_ca = 1;\n\t\t}\n\tok = 1;\n end:\n\treturn ok;\n#endif\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}']
|
1,670
| 0
|
https://github.com/openssl/openssl/blob/54b5fd537f7a7ac1874359fd42a4721b6839f7a1/engines/ccgost/gost_pmeth.c/#L321
|
static int pkey_gost01_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey,int type)
{
struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
EC_KEY *ec=NULL;
if (data->sign_param_nid == NID_undef)
{
if (type == NID_id_GostR3410_2001_cc)
{
data->sign_param_nid = NID_id_GostR3410_2001_ParamSet_cc;
}
else {
GOSTerr(GOST_F_PKEY_GOST01_KEYGEN,
GOST_R_NO_PARAMETERS_SET);
return 0;
}
}
ec = EC_KEY_new();
if (!fill_GOST2001_params(ec,data->sign_param_nid))
{
EC_KEY_free(ec);
return 0;
}
gost2001_keygen(ec);
EVP_PKEY_assign(pkey,type,ec);
return 1;
}
|
['static int pkey_gost01_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey,int type)\n\t{\n\tstruct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);\n\tEC_KEY *ec=NULL;\n\tif (data->sign_param_nid == NID_undef)\n\t\t{\n\t\tif (type == NID_id_GostR3410_2001_cc)\n\t\t\t{\n\t\t\tdata->sign_param_nid = NID_id_GostR3410_2001_ParamSet_cc;\n\t\t\t}\n\t\telse {\n\t\t\tGOSTerr(GOST_F_PKEY_GOST01_KEYGEN,\n\t\t\t\tGOST_R_NO_PARAMETERS_SET);\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\tec = EC_KEY_new();\n\tif (!fill_GOST2001_params(ec,data->sign_param_nid))\n\t\t{\n\t\tEC_KEY_free(ec);\n\t\treturn 0;\n\t\t}\n\tgost2001_keygen(ec);\n\tEVP_PKEY_assign(pkey,type,ec);\n\treturn 1;\n\t}', 'void *EVP_PKEY_CTX_get_data(EVP_PKEY_CTX *ctx)\n\t{\n\treturn ctx->data;\n\t}', 'EC_KEY *EC_KEY_new(void)\n\t{\n\tEC_KEY *ret;\n\tret=(EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY));\n\tif (ret == NULL)\n\t\t{\n\t\tECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->version = 1;\n\tret->group = NULL;\n\tret->pub_key = NULL;\n\tret->priv_key= NULL;\n\tret->enc_flag= 0;\n\tret->conv_form = POINT_CONVERSION_UNCOMPRESSED;\n\tret->references= 1;\n\tret->method_data = NULL;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']
|
1,671
| 1
|
https://github.com/openssl/openssl/blob/3da2e9c4ee45989a426ff513dc6c6250d1e460de/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_add(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int ret, r_neg, cmp_res;\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg == b->neg) {\n r_neg = a->neg;\n ret = BN_uadd(r, a, b);\n } else {\n cmp_res = BN_ucmp(a, b);\n if (cmp_res > 0) {\n r_neg = a->neg;\n ret = BN_usub(r, a, b);\n } else if (cmp_res < 0) {\n r_neg = b->neg;\n ret = BN_usub(r, b, a);\n } else {\n r_neg = 0;\n BN_zero(r);\n ret = 1;\n }\n }\n r->neg = r_neg;\n bn_check_top(r);\n return ret;\n}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int max, min, dif;\n BN_ULONG t1, t2, borrow, *rp;\n const BN_ULONG *ap, *bp;\n bn_check_top(a);\n bn_check_top(b);\n max = a->top;\n min = b->top;\n dif = max - min;\n if (dif < 0) {\n BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);\n return 0;\n }\n if (bn_wexpand(r, max) == NULL)\n return 0;\n ap = a->d;\n bp = b->d;\n rp = r->d;\n borrow = bn_sub_words(rp, ap, bp, min);\n ap += min;\n rp += min;\n while (dif) {\n dif--;\n t1 = *(ap++);\n t2 = (t1 - borrow) & BN_MASK2;\n *(rp++) = t2;\n borrow &= (t1 == 0);\n }\n while (max && *--rp == 0)\n max--;\n r->top = max;\n r->neg = 0;\n bn_pollute(r);\n return 1;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n l0 = bn_sub_words(wnum.d, wnum.d, 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.d, wnum.d, tmp->d, div_n);\n (*wnump) += l0;\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,672
| 0
|
https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavformat/utils.c/#L2220
|
void av_close_input_stream(AVFormatContext *s)
{
int i;
AVStream *st;
if (s->cur_st && s->cur_st->parser)
av_free_packet(&s->cur_pkt);
if (s->iformat->read_close)
s->iformat->read_close(s);
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
}
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec);
av_free(st->filename);
av_free(st->priv_data);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
av_freep(&s->programs[i]->provider_name);
av_freep(&s->programs[i]->name);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
flush_packet_queue(s);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
av_free(s->chapters[s->nb_chapters]->title);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_free(s);
}
|
['static int http_server(void)\n{\n int server_fd = 0, rtsp_server_fd = 0;\n int ret, delay, delay1;\n struct pollfd poll_table[HTTP_MAX_CONNECTIONS + 2], *poll_entry;\n HTTPContext *c, *c_next;\n if (my_http_addr.sin_port) {\n server_fd = socket_open_listen(&my_http_addr);\n if (server_fd < 0)\n return -1;\n }\n if (my_rtsp_addr.sin_port) {\n rtsp_server_fd = socket_open_listen(&my_rtsp_addr);\n if (rtsp_server_fd < 0)\n return -1;\n }\n if (!rtsp_server_fd && !server_fd) {\n http_log("HTTP and RTSP disabled.\\n");\n return -1;\n }\n http_log("ffserver started.\\n");\n start_children(first_feed);\n start_multicast();\n for(;;) {\n poll_entry = poll_table;\n if (server_fd) {\n poll_entry->fd = server_fd;\n poll_entry->events = POLLIN;\n poll_entry++;\n }\n if (rtsp_server_fd) {\n poll_entry->fd = rtsp_server_fd;\n poll_entry->events = POLLIN;\n poll_entry++;\n }\n c = first_http_ctx;\n delay = 1000;\n while (c != NULL) {\n int fd;\n fd = c->fd;\n switch(c->state) {\n case HTTPSTATE_SEND_HEADER:\n case RTSPSTATE_SEND_REPLY:\n case RTSPSTATE_SEND_PACKET:\n c->poll_entry = poll_entry;\n poll_entry->fd = fd;\n poll_entry->events = POLLOUT;\n poll_entry++;\n break;\n case HTTPSTATE_SEND_DATA_HEADER:\n case HTTPSTATE_SEND_DATA:\n case HTTPSTATE_SEND_DATA_TRAILER:\n if (!c->is_packetized) {\n c->poll_entry = poll_entry;\n poll_entry->fd = fd;\n poll_entry->events = POLLOUT;\n poll_entry++;\n } else {\n delay1 = 10;\n if (delay1 < delay)\n delay = delay1;\n }\n break;\n case HTTPSTATE_WAIT_REQUEST:\n case HTTPSTATE_RECEIVE_DATA:\n case HTTPSTATE_WAIT_FEED:\n case RTSPSTATE_WAIT_REQUEST:\n c->poll_entry = poll_entry;\n poll_entry->fd = fd;\n poll_entry->events = POLLIN;\n poll_entry++;\n break;\n default:\n c->poll_entry = NULL;\n break;\n }\n c = c->next;\n }\n do {\n ret = poll(poll_table, poll_entry - poll_table, delay);\n if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) &&\n ff_neterrno() != FF_NETERROR(EINTR))\n return -1;\n } while (ret < 0);\n cur_time = av_gettime() / 1000;\n if (need_to_start_children) {\n need_to_start_children = 0;\n start_children(first_feed);\n }\n for(c = first_http_ctx; c != NULL; c = c_next) {\n c_next = c->next;\n if (handle_connection(c) < 0) {\n log_connection(c);\n close_connection(c);\n }\n }\n poll_entry = poll_table;\n if (server_fd) {\n if (poll_entry->revents & POLLIN)\n new_connection(server_fd, 0);\n poll_entry++;\n }\n if (rtsp_server_fd) {\n if (poll_entry->revents & POLLIN)\n new_connection(rtsp_server_fd, 1);\n }\n }\n}', 'static int handle_connection(HTTPContext *c)\n{\n int len, ret;\n switch(c->state) {\n case HTTPSTATE_WAIT_REQUEST:\n case RTSPSTATE_WAIT_REQUEST:\n if ((c->timeout - cur_time) < 0)\n return -1;\n if (c->poll_entry->revents & (POLLERR | POLLHUP))\n return -1;\n if (!(c->poll_entry->revents & POLLIN))\n return 0;\n read_loop:\n len = recv(c->fd, c->buffer_ptr, 1, 0);\n if (len < 0) {\n if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n ff_neterrno() != FF_NETERROR(EINTR))\n return -1;\n } else if (len == 0) {\n return -1;\n } else {\n uint8_t *ptr;\n c->buffer_ptr += len;\n ptr = c->buffer_ptr;\n if ((ptr >= c->buffer + 2 && !memcmp(ptr-2, "\\n\\n", 2)) ||\n (ptr >= c->buffer + 4 && !memcmp(ptr-4, "\\r\\n\\r\\n", 4))) {\n if (c->state == HTTPSTATE_WAIT_REQUEST) {\n ret = http_parse_request(c);\n } else {\n ret = rtsp_parse_request(c);\n }\n if (ret < 0)\n return -1;\n } else if (ptr >= c->buffer_end) {\n return -1;\n } else goto read_loop;\n }\n break;\n case HTTPSTATE_SEND_HEADER:\n if (c->poll_entry->revents & (POLLERR | POLLHUP))\n return -1;\n if (!(c->poll_entry->revents & POLLOUT))\n return 0;\n len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);\n if (len < 0) {\n if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n ff_neterrno() != FF_NETERROR(EINTR)) {\n av_freep(&c->pb_buffer);\n return -1;\n }\n } else {\n c->buffer_ptr += len;\n if (c->stream)\n c->stream->bytes_served += len;\n c->data_count += len;\n if (c->buffer_ptr >= c->buffer_end) {\n av_freep(&c->pb_buffer);\n if (c->http_error)\n return -1;\n c->state = HTTPSTATE_SEND_DATA_HEADER;\n c->buffer_ptr = c->buffer_end = c->buffer;\n }\n }\n break;\n case HTTPSTATE_SEND_DATA:\n case HTTPSTATE_SEND_DATA_HEADER:\n case HTTPSTATE_SEND_DATA_TRAILER:\n if (!c->is_packetized) {\n if (c->poll_entry->revents & (POLLERR | POLLHUP))\n return -1;\n if (!(c->poll_entry->revents & POLLOUT))\n return 0;\n }\n if (http_send_data(c) < 0)\n return -1;\n if (c->state == HTTPSTATE_SEND_DATA_TRAILER)\n return -1;\n break;\n case HTTPSTATE_RECEIVE_DATA:\n if (c->poll_entry->revents & (POLLERR | POLLHUP))\n return -1;\n if (!(c->poll_entry->revents & POLLIN))\n return 0;\n if (http_receive_data(c) < 0)\n return -1;\n break;\n case HTTPSTATE_WAIT_FEED:\n if (c->poll_entry->revents & (POLLIN | POLLERR | POLLHUP))\n return -1;\n break;\n case RTSPSTATE_SEND_REPLY:\n if (c->poll_entry->revents & (POLLERR | POLLHUP)) {\n av_freep(&c->pb_buffer);\n return -1;\n }\n if (!(c->poll_entry->revents & POLLOUT))\n return 0;\n len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);\n if (len < 0) {\n if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n ff_neterrno() != FF_NETERROR(EINTR)) {\n av_freep(&c->pb_buffer);\n return -1;\n }\n } else {\n c->buffer_ptr += len;\n c->data_count += len;\n if (c->buffer_ptr >= c->buffer_end) {\n av_freep(&c->pb_buffer);\n start_wait_request(c, 1);\n }\n }\n break;\n case RTSPSTATE_SEND_PACKET:\n if (c->poll_entry->revents & (POLLERR | POLLHUP)) {\n av_freep(&c->packet_buffer);\n return -1;\n }\n if (!(c->poll_entry->revents & POLLOUT))\n return 0;\n len = send(c->fd, c->packet_buffer_ptr,\n c->packet_buffer_end - c->packet_buffer_ptr, 0);\n if (len < 0) {\n if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n ff_neterrno() != FF_NETERROR(EINTR)) {\n av_freep(&c->packet_buffer);\n return -1;\n }\n } else {\n c->packet_buffer_ptr += len;\n if (c->packet_buffer_ptr >= c->packet_buffer_end) {\n av_freep(&c->packet_buffer);\n c->state = RTSPSTATE_WAIT_REQUEST;\n }\n }\n break;\n case HTTPSTATE_READY:\n break;\n default:\n return -1;\n }\n return 0;\n}', "static int http_send_data(HTTPContext *c)\n{\n int len, ret;\n for(;;) {\n if (c->buffer_ptr >= c->buffer_end) {\n ret = http_prepare_data(c);\n if (ret < 0)\n return -1;\n else if (ret != 0)\n break;\n } else {\n if (c->is_packetized) {\n len = c->buffer_end - c->buffer_ptr;\n if (len < 4) {\n fail1:\n c->buffer_ptr = c->buffer_end;\n return 0;\n }\n len = (c->buffer_ptr[0] << 24) |\n (c->buffer_ptr[1] << 16) |\n (c->buffer_ptr[2] << 8) |\n (c->buffer_ptr[3]);\n if (len > (c->buffer_end - c->buffer_ptr))\n goto fail1;\n if ((get_packet_send_clock(c) - get_server_clock(c)) > 0) {\n return 0;\n }\n c->data_count += len;\n update_datarate(&c->datarate, c->data_count);\n if (c->stream)\n c->stream->bytes_served += len;\n if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP) {\n ByteIOContext *pb;\n int interleaved_index, size;\n uint8_t header[4];\n HTTPContext *rtsp_c;\n rtsp_c = c->rtsp_c;\n if (!rtsp_c)\n return -1;\n if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST)\n break;\n if (url_open_dyn_buf(&pb) < 0)\n goto fail1;\n interleaved_index = c->packet_stream_index * 2;\n if (c->buffer_ptr[1] == 200)\n interleaved_index++;\n header[0] = '$';\n header[1] = interleaved_index;\n header[2] = len >> 8;\n header[3] = len;\n put_buffer(pb, header, 4);\n c->buffer_ptr += 4;\n put_buffer(pb, c->buffer_ptr, len);\n size = url_close_dyn_buf(pb, &c->packet_buffer);\n rtsp_c->packet_buffer_ptr = c->packet_buffer;\n rtsp_c->packet_buffer_end = c->packet_buffer + size;\n c->buffer_ptr += len;\n len = send(rtsp_c->fd, rtsp_c->packet_buffer_ptr,\n rtsp_c->packet_buffer_end - rtsp_c->packet_buffer_ptr, 0);\n if (len > 0)\n rtsp_c->packet_buffer_ptr += len;\n if (rtsp_c->packet_buffer_ptr < rtsp_c->packet_buffer_end) {\n rtsp_c->state = RTSPSTATE_SEND_PACKET;\n break;\n } else\n av_freep(&c->packet_buffer);\n } else {\n c->buffer_ptr += 4;\n url_write(c->rtp_handles[c->packet_stream_index],\n c->buffer_ptr, len);\n c->buffer_ptr += len;\n }\n } else {\n len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0);\n if (len < 0) {\n if (ff_neterrno() != FF_NETERROR(EAGAIN) &&\n ff_neterrno() != FF_NETERROR(EINTR))\n return -1;\n else\n return 0;\n } else\n c->buffer_ptr += len;\n c->data_count += len;\n update_datarate(&c->datarate, c->data_count);\n if (c->stream)\n c->stream->bytes_served += len;\n break;\n }\n }\n }\n return 0;\n}", 'static int http_prepare_data(HTTPContext *c)\n{\n int i, len, ret;\n AVFormatContext *ctx;\n av_freep(&c->pb_buffer);\n switch(c->state) {\n case HTTPSTATE_SEND_DATA_HEADER:\n memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx));\n av_strlcpy(c->fmt_ctx.author, c->stream->author,\n sizeof(c->fmt_ctx.author));\n av_strlcpy(c->fmt_ctx.comment, c->stream->comment,\n sizeof(c->fmt_ctx.comment));\n av_strlcpy(c->fmt_ctx.copyright, c->stream->copyright,\n sizeof(c->fmt_ctx.copyright));\n av_strlcpy(c->fmt_ctx.title, c->stream->title,\n sizeof(c->fmt_ctx.title));\n for(i=0;i<c->stream->nb_streams;i++) {\n AVStream *st;\n AVStream *src;\n st = av_mallocz(sizeof(AVStream));\n c->fmt_ctx.streams[i] = st;\n if (!c->stream->feed ||\n c->stream->feed == c->stream)\n src = c->stream->streams[i];\n else\n src = c->stream->feed->streams[c->stream->feed_streams[i]];\n *st = *src;\n st->priv_data = 0;\n st->codec->frame_number = 0;\n }\n c->fmt_ctx.oformat = c->stream->fmt;\n c->fmt_ctx.nb_streams = c->stream->nb_streams;\n c->got_key_frame = 0;\n if (url_open_dyn_buf(&c->fmt_ctx.pb) < 0) {\n return -1;\n }\n c->fmt_ctx.pb->is_streamed = 1;\n c->fmt_ctx.preload = (int)(0.5*AV_TIME_BASE);\n c->fmt_ctx.max_delay = (int)(0.7*AV_TIME_BASE);\n av_set_parameters(&c->fmt_ctx, NULL);\n if (av_write_header(&c->fmt_ctx) < 0) {\n http_log("Error writing output header\\n");\n return -1;\n }\n len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer);\n c->buffer_ptr = c->pb_buffer;\n c->buffer_end = c->pb_buffer + len;\n c->state = HTTPSTATE_SEND_DATA;\n c->last_packet_sent = 0;\n break;\n case HTTPSTATE_SEND_DATA:\n if (c->stream->feed)\n ffm_set_write_index(c->fmt_in,\n c->stream->feed->feed_write_index,\n c->stream->feed->feed_size);\n if (c->stream->max_time &&\n c->stream->max_time + c->start_time - cur_time < 0)\n c->state = HTTPSTATE_SEND_DATA_TRAILER;\n else {\n AVPacket pkt;\n redo:\n if (av_read_frame(c->fmt_in, &pkt) < 0) {\n if (c->stream->feed && c->stream->feed->feed_opened) {\n c->state = HTTPSTATE_WAIT_FEED;\n return 1;\n } else {\n if (c->stream->loop) {\n av_close_input_file(c->fmt_in);\n c->fmt_in = NULL;\n if (open_input_stream(c, "") < 0)\n goto no_loop;\n goto redo;\n } else {\n no_loop:\n c->state = HTTPSTATE_SEND_DATA_TRAILER;\n }\n }\n } else {\n int source_index = pkt.stream_index;\n if (c->first_pts == AV_NOPTS_VALUE) {\n c->first_pts = av_rescale_q(pkt.dts, c->fmt_in->streams[pkt.stream_index]->time_base, AV_TIME_BASE_Q);\n c->start_time = cur_time;\n }\n if (c->stream->feed) {\n if (c->switch_pending) {\n c->switch_pending = 0;\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->switch_feed_streams[i] == pkt.stream_index)\n if (pkt.flags & PKT_FLAG_KEY)\n do_switch_stream(c, i);\n if (c->switch_feed_streams[i] >= 0)\n c->switch_pending = 1;\n }\n }\n for(i=0;i<c->stream->nb_streams;i++) {\n if (c->feed_streams[i] == pkt.stream_index) {\n AVStream *st = c->fmt_in->streams[source_index];\n pkt.stream_index = i;\n if (pkt.flags & PKT_FLAG_KEY &&\n (st->codec->codec_type == CODEC_TYPE_VIDEO ||\n c->stream->nb_streams == 1))\n c->got_key_frame = 1;\n if (!c->stream->send_on_key || c->got_key_frame)\n goto send_it;\n }\n }\n } else {\n AVCodecContext *codec;\n AVStream *ist, *ost;\n send_it:\n ist = c->fmt_in->streams[source_index];\n if (c->is_packetized) {\n c->cur_pts = av_rescale_q(pkt.dts, ist->time_base, AV_TIME_BASE_Q);\n if (ist->start_time != AV_NOPTS_VALUE)\n c->cur_pts -= av_rescale_q(ist->start_time, ist->time_base, AV_TIME_BASE_Q);\n c->cur_frame_duration = av_rescale_q(pkt.duration, ist->time_base, AV_TIME_BASE_Q);\n#if 0\n printf("index=%d pts=%0.3f duration=%0.6f\\n",\n pkt.stream_index,\n (double)c->cur_pts /\n AV_TIME_BASE,\n (double)c->cur_frame_duration /\n AV_TIME_BASE);\n#endif\n c->packet_stream_index = pkt.stream_index;\n ctx = c->rtp_ctx[c->packet_stream_index];\n if(!ctx) {\n av_free_packet(&pkt);\n break;\n }\n codec = ctx->streams[0]->codec;\n pkt.stream_index = 0;\n } else {\n ctx = &c->fmt_ctx;\n codec = ctx->streams[pkt.stream_index]->codec;\n }\n if (c->is_packetized) {\n int max_packet_size;\n if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP)\n max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;\n else\n max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]);\n ret = url_open_dyn_packet_buf(&ctx->pb, max_packet_size);\n } else {\n ret = url_open_dyn_buf(&ctx->pb);\n }\n if (ret < 0) {\n return -1;\n }\n ost = ctx->streams[pkt.stream_index];\n ctx->pb->is_streamed = 1;\n if (pkt.dts != AV_NOPTS_VALUE)\n pkt.dts = av_rescale_q(pkt.dts, ist->time_base, ost->time_base);\n if (pkt.pts != AV_NOPTS_VALUE)\n pkt.pts = av_rescale_q(pkt.pts, ist->time_base, ost->time_base);\n pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);\n if (av_write_frame(ctx, &pkt) < 0) {\n http_log("Error writing frame to output\\n");\n c->state = HTTPSTATE_SEND_DATA_TRAILER;\n }\n len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n c->cur_frame_bytes = len;\n c->buffer_ptr = c->pb_buffer;\n c->buffer_end = c->pb_buffer + len;\n codec->frame_number++;\n if (len == 0) {\n av_free_packet(&pkt);\n goto redo;\n }\n }\n av_free_packet(&pkt);\n }\n }\n break;\n default:\n case HTTPSTATE_SEND_DATA_TRAILER:\n if (c->last_packet_sent || c->is_packetized)\n return -1;\n ctx = &c->fmt_ctx;\n if (url_open_dyn_buf(&ctx->pb) < 0) {\n return -1;\n }\n c->fmt_ctx.pb->is_streamed = 1;\n av_write_trailer(ctx);\n len = url_close_dyn_buf(ctx->pb, &c->pb_buffer);\n c->buffer_ptr = c->pb_buffer;\n c->buffer_end = c->pb_buffer + len;\n c->last_packet_sent = 1;\n break;\n }\n return 0;\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;\n av_close_input_stream(s);\n if (pb)\n url_fclose(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n if (s->cur_st && s->cur_st->parser)\n av_free_packet(&s->cur_pkt);\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n }\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec);\n av_free(st->filename);\n av_free(st->priv_data);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_freep(&s->programs[i]->provider_name);\n av_freep(&s->programs[i]->name);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n flush_packet_queue(s);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_free(s->chapters[s->nb_chapters]->title);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_free(s);\n}']
|
1,673
| 0
|
https://github.com/libav/libav/blob/03f8fc0897c128028111182e6276139fa00b891b/libavcodec/wmaprodec.c/#L832
|
static int decode_coeffs(WMAProDecodeCtx *s, int c)
{
static const int fval_tab[16] = {
0x00000000, 0x3f800000, 0x40000000, 0x40400000,
0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
0x41000000, 0x41100000, 0x41200000, 0x41300000,
0x41400000, 0x41500000, 0x41600000, 0x41700000,
};
int vlctable;
VLC* vlc;
WMAProChannelCtx* ci = &s->channel[c];
int rl_mode = 0;
int cur_coeff = 0;
int num_zeros = 0;
const uint16_t* run;
const float* level;
dprintf(s->avctx, "decode coefficients for channel %i\n", c);
vlctable = get_bits1(&s->gb);
vlc = &coef_vlc[vlctable];
if (vlctable) {
run = coef1_run;
level = coef1_level;
} else {
run = coef0_run;
level = coef0_level;
}
while (!rl_mode && cur_coeff + 3 < s->subframe_len) {
int vals[4];
int i;
unsigned int idx;
idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
if (idx == HUFF_VEC4_SIZE - 1) {
for (i = 0; i < 4; i += 2) {
idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
if (idx == HUFF_VEC2_SIZE - 1) {
int v0, v1;
v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
if (v0 == HUFF_VEC1_SIZE - 1)
v0 += ff_wma_get_large_val(&s->gb);
v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
if (v1 == HUFF_VEC1_SIZE - 1)
v1 += ff_wma_get_large_val(&s->gb);
((float*)vals)[i ] = v0;
((float*)vals)[i+1] = v1;
} else {
vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];
vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
}
}
} else {
vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];
vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
}
for (i = 0; i < 4; i++) {
if (vals[i]) {
int sign = get_bits1(&s->gb) - 1;
*(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31;
num_zeros = 0;
} else {
ci->coeffs[cur_coeff] = 0;
rl_mode |= (++num_zeros > s->subframe_len >> 8);
}
++cur_coeff;
}
}
if (rl_mode) {
memset(&ci->coeffs[cur_coeff], 0,
sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
level, run, 1, ci->coeffs,
cur_coeff, s->subframe_len,
s->subframe_len, s->esc_len, 0))
return AVERROR_INVALIDDATA;
}
return 0;
}
|
['static int decode_coeffs(WMAProDecodeCtx *s, int c)\n{\n static const int fval_tab[16] = {\n 0x00000000, 0x3f800000, 0x40000000, 0x40400000,\n 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,\n 0x41000000, 0x41100000, 0x41200000, 0x41300000,\n 0x41400000, 0x41500000, 0x41600000, 0x41700000,\n };\n int vlctable;\n VLC* vlc;\n WMAProChannelCtx* ci = &s->channel[c];\n int rl_mode = 0;\n int cur_coeff = 0;\n int num_zeros = 0;\n const uint16_t* run;\n const float* level;\n dprintf(s->avctx, "decode coefficients for channel %i\\n", c);\n vlctable = get_bits1(&s->gb);\n vlc = &coef_vlc[vlctable];\n if (vlctable) {\n run = coef1_run;\n level = coef1_level;\n } else {\n run = coef0_run;\n level = coef0_level;\n }\n while (!rl_mode && cur_coeff + 3 < s->subframe_len) {\n int vals[4];\n int i;\n unsigned int idx;\n idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);\n if (idx == HUFF_VEC4_SIZE - 1) {\n for (i = 0; i < 4; i += 2) {\n idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);\n if (idx == HUFF_VEC2_SIZE - 1) {\n int v0, v1;\n v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);\n if (v0 == HUFF_VEC1_SIZE - 1)\n v0 += ff_wma_get_large_val(&s->gb);\n v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);\n if (v1 == HUFF_VEC1_SIZE - 1)\n v1 += ff_wma_get_large_val(&s->gb);\n ((float*)vals)[i ] = v0;\n ((float*)vals)[i+1] = v1;\n } else {\n vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];\n vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];\n }\n }\n } else {\n vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];\n vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];\n vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];\n vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];\n }\n for (i = 0; i < 4; i++) {\n if (vals[i]) {\n int sign = get_bits1(&s->gb) - 1;\n *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31;\n num_zeros = 0;\n } else {\n ci->coeffs[cur_coeff] = 0;\n rl_mode |= (++num_zeros > s->subframe_len >> 8);\n }\n ++cur_coeff;\n }\n }\n if (rl_mode) {\n memset(&ci->coeffs[cur_coeff], 0,\n sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));\n if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,\n level, run, 1, ci->coeffs,\n cur_coeff, s->subframe_len,\n s->subframe_len, s->esc_len, 0))\n return AVERROR_INVALIDDATA;\n }\n return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
|
1,674
| 0
|
https://github.com/openssl/openssl/blob/a055a8815587f402d700093dea0dec6bf34631a3/crypto/err/err.c/#L780
|
int ERR_set_mark(void)
{
ERR_STATE *es;
es = ERR_get_state();
if (es == NULL)
return 0;
if (es->bottom == es->top)
return 0;
es->err_flags[es->top] |= ERR_FLAG_MARK;
return 1;
}
|
['int ERR_set_mark(void)\n{\n ERR_STATE *es;\n es = ERR_get_state();\n if (es == NULL)\n return 0;\n if (es->bottom == es->top)\n return 0;\n es->err_flags[es->top] |= ERR_FLAG_MARK;\n return 1;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n if (!RUN_ONCE(&err_init, err_do_init))\n return NULL;\n state = CRYPTO_THREAD_get_local(&err_thread_local);\n if (state == NULL) {\n state = OPENSSL_zalloc(sizeof(*state));\n if (state == NULL)\n return NULL;\n if (!CRYPTO_THREAD_set_local(&err_thread_local, state)) {\n ERR_STATE_free(state);\n return NULL;\n }\n OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);\n ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE);\n }\n return state;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}']
|
1,675
| 0
|
https://github.com/libav/libav/blob/645e75992d8876a5e0aa056739885d3afd08d431/libavcodec/vorbis_enc.c/#L977
|
static av_cold int vorbis_encode_init(AVCodecContext *avccontext)
{
vorbis_enc_context *venc = avccontext->priv_data;
if (avccontext->channels != 2) {
av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n");
return -1;
}
create_vorbis_context(venc, avccontext);
if (avccontext->flags & CODEC_FLAG_QSCALE)
venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;
else
venc->quality = 0.03;
venc->quality *= venc->quality;
avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);
avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);
avccontext->coded_frame = avcodec_alloc_frame();
avccontext->coded_frame->key_frame = 1;
return 0;
}
|
['static av_cold int vorbis_encode_init(AVCodecContext *avccontext)\n{\n vorbis_enc_context *venc = avccontext->priv_data;\n if (avccontext->channels != 2) {\n av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\\n");\n return -1;\n }\n create_vorbis_context(venc, avccontext);\n if (avccontext->flags & CODEC_FLAG_QSCALE)\n venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.;\n else\n venc->quality = 0.03;\n venc->quality *= venc->quality;\n avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata);\n avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1);\n avccontext->coded_frame = avcodec_alloc_frame();\n avccontext->coded_frame->key_frame = 1;\n return 0;\n}', 'AVFrame *avcodec_alloc_frame(void){\n AVFrame *pic= av_malloc(sizeof(AVFrame));\n if(pic==NULL) return NULL;\n avcodec_get_frame_defaults(pic);\n return pic;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,676
| 0
|
https://github.com/openssl/openssl/blob/c504a5e78386aa9f02462d18a90da759f9131321/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int generate_key(DH *dh)\n\t{\n\tint ok=0;\n\tint generate_new_key=0;\n\tunsigned l;\n\tBN_CTX *ctx;\n\tBN_MONT_CTX *mont=NULL;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tctx = BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tif (dh->priv_key == NULL)\n\t\t{\n\t\tpriv_key=BN_new();\n\t\tif (priv_key == NULL) goto err;\n\t\tgenerate_new_key=1;\n\t\t}\n\telse\n\t\tpriv_key=dh->priv_key;\n\tif (dh->pub_key == NULL)\n\t\t{\n\t\tpub_key=BN_new();\n\t\tif (pub_key == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dh->pub_key;\n\tif (dh->flags & DH_FLAG_CACHE_MONT_P)\n\t\t{\n\t\tmont = BN_MONT_CTX_set_locked(&dh->method_mont_p,\n\t\t\t\tCRYPTO_LOCK_DH, dh->p, ctx);\n\t\tif (!mont)\n\t\t\tgoto err;\n\t\t}\n\tif (generate_new_key)\n\t\t{\n\t\tl = dh->length ? dh->length : BN_num_bits(dh->p)-1;\n\t\tif (!BN_rand(priv_key, l, 0, 0)) goto err;\n\t\t}\n\t{\n\t\tBIGNUM local_prk;\n\t\tBIGNUM *prk;\n\t\tif ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t\t{\n\t\t\tBN_init(&local_prk);\n\t\t\tprk = &local_prk;\n\t\t\tBN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n\t\t\t}\n\t\telse\n\t\t\tprk = priv_key;\n\t\tif (!dh->meth->bn_mod_exp(dh, pub_key, dh->g, prk, dh->p, ctx, mont)) goto err;\n\t}\n\tdh->pub_key=pub_key;\n\tdh->priv_key=priv_key;\n\tok=1;\nerr:\n\tif (ok != 1)\n\t\tDHerr(DH_F_GENERATE_KEY,ERR_R_BN_LIB);\n\tif ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);\n\tBN_CTX_free(ctx);\n\treturn(ok);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint got_write_lock = 0;\n\tBN_MONT_CTX *ret;\n\tCRYPTO_r_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\tCRYPTO_r_unlock(lock);\n\t\tCRYPTO_w_lock(lock);\n\t\tgot_write_lock = 1;\n\t\tif (!*pmont)\n\t\t\t{\n\t\t\tret = BN_MONT_CTX_new();\n\t\t\tif (ret && !BN_MONT_CTX_set(ret, mod, ctx))\n\t\t\t\tBN_MONT_CTX_free(ret);\n\t\t\telse\n\t\t\t\t*pmont = ret;\n\t\t\t}\n\t\t}\n\tret = *pmont;\n\tif (got_write_lock)\n\t\tCRYPTO_w_unlock(lock);\n\telse\n\t\tCRYPTO_r_unlock(lock);\n\treturn ret;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM local_A, local_B;\n\tBIGNUM *pA, *pB;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,677
| 0
|
https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavformat/ncdec.c/#L71
|
static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
{
int size;
int ret;
uint32_t state=-1;
while (state != NC_VIDEO_FLAG) {
if (url_feof(s->pb))
return AVERROR(EIO);
state = (state<<8) + get_byte(s->pb);
}
get_byte(s->pb);
size = get_le16(s->pb);
url_fskip(s->pb, 9);
if (size == 0) {
av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n");
return AVERROR(EAGAIN);
}
ret = av_get_packet(s->pb, pkt, size);
if (ret != size) {
if (ret > 0) av_free_packet(pkt);
return AVERROR(EIO);
}
pkt->stream_index = 0;
return size;
}
|
['static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)\n{\n int size;\n int ret;\n uint32_t state=-1;\n while (state != NC_VIDEO_FLAG) {\n if (url_feof(s->pb))\n return AVERROR(EIO);\n state = (state<<8) + get_byte(s->pb);\n }\n get_byte(s->pb);\n size = get_le16(s->pb);\n url_fskip(s->pb, 9);\n if (size == 0) {\n av_log(s, AV_LOG_DEBUG, "Next packet size is zero\\n");\n return AVERROR(EAGAIN);\n }\n ret = av_get_packet(s->pb, pkt, size);\n if (ret != size) {\n if (ret > 0) av_free_packet(pkt);\n return AVERROR(EIO);\n }\n pkt->stream_index = 0;\n return size;\n}', 'int get_byte(ByteIOContext *s)\n{\n if (s->buf_ptr < s->buf_end) {\n return *s->buf_ptr++;\n } else {\n fill_buffer(s);\n if (s->buf_ptr < s->buf_end)\n return *s->buf_ptr++;\n else\n return 0;\n }\n}']
|
1,678
| 0
|
https://github.com/openssl/openssl/blob/95ed0e7c1f4206191c1b0288e352010e70e252db/crypto/asn1/t_req.c/#L120
|
int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
unsigned long cflag)
{
long l;
int i;
X509_REQ_INFO *ri;
EVP_PKEY *pkey;
STACK_OF(X509_ATTRIBUTE) *sk;
STACK_OF(X509_EXTENSION) *exts;
char mlch = ' ';
int nmindent = 0;
if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {
mlch = '\n';
nmindent = 12;
}
if (nmflags == X509_FLAG_COMPAT)
nmindent = 16;
ri = &x->req_info;
if (!(cflag & X509_FLAG_NO_HEADER)) {
if (BIO_write(bp, "Certificate Request:\n", 21) <= 0)
goto err;
if (BIO_write(bp, " Data:\n", 10) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_VERSION)) {
l = X509_REQ_get_version(x);
if (BIO_printf(bp, "%8sVersion: %ld (0x%lx)\n", "", l + 1, l) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_SUBJECT)) {
if (BIO_printf(bp, " Subject:%c", mlch) <= 0)
goto err;
if (X509_NAME_print_ex(bp, ri->subject, nmindent, nmflags) < 0)
goto err;
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
if (!(cflag & X509_FLAG_NO_PUBKEY)) {
if (BIO_write(bp, " Subject Public Key Info:\n", 33) <= 0)
goto err;
if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)
goto err;
if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)
goto err;
if (BIO_puts(bp, "\n") <= 0)
goto err;
pkey = X509_REQ_get_pubkey(x);
if (pkey == NULL) {
BIO_printf(bp, "%12sUnable to load Public Key\n", "");
ERR_print_errors(bp);
} else {
EVP_PKEY_print_public(bp, pkey, 16, NULL);
EVP_PKEY_free(pkey);
}
}
if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {
if (BIO_printf(bp, "%8sAttributes:\n", "") <= 0)
goto err;
sk = x->req_info.attributes;
if (sk_X509_ATTRIBUTE_num(sk) == 0) {
if (BIO_printf(bp, "%12sa0:00\n", "") <= 0)
goto err;
} else {
for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {
ASN1_TYPE *at;
X509_ATTRIBUTE *a;
ASN1_BIT_STRING *bs = NULL;
ASN1_OBJECT *aobj;
int j, type = 0, count = 1, ii = 0;
a = sk_X509_ATTRIBUTE_value(sk, i);
aobj = X509_ATTRIBUTE_get0_object(a);
if (X509_REQ_extension_nid(OBJ_obj2nid(aobj)))
continue;
if (BIO_printf(bp, "%12s", "") <= 0)
goto err;
if ((j = i2a_ASN1_OBJECT(bp, aobj)) > 0) {
ii = 0;
count = X509_ATTRIBUTE_count(a);
get_next:
at = X509_ATTRIBUTE_get0_type(a, ii);
type = at->type;
bs = at->value.asn1_string;
}
for (j = 25 - j; j > 0; j--)
if (BIO_write(bp, " ", 1) != 1)
goto err;
if (BIO_puts(bp, ":") <= 0)
goto err;
if ((type == V_ASN1_PRINTABLESTRING) ||
(type == V_ASN1_T61STRING) ||
(type == V_ASN1_IA5STRING)) {
if (BIO_write(bp, (char *)bs->data, bs->length)
!= bs->length)
goto err;
BIO_puts(bp, "\n");
} else {
BIO_puts(bp, "unable to print attribute\n");
}
if (++ii < count)
goto get_next;
}
}
}
if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {
exts = X509_REQ_get_extensions(x);
if (exts) {
BIO_printf(bp, "%8sRequested Extensions:\n", "");
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
ASN1_OBJECT *obj;
X509_EXTENSION *ex;
int j;
ex = sk_X509_EXTENSION_value(exts, i);
if (BIO_printf(bp, "%12s", "") <= 0)
goto err;
obj = X509_EXTENSION_get_object(ex);
i2a_ASN1_OBJECT(bp, obj);
j = X509_EXTENSION_get_critical(ex);
if (BIO_printf(bp, ": %s\n", j ? "critical" : "") <= 0)
goto err;
if (!X509V3_EXT_print(bp, ex, cflag, 16)) {
BIO_printf(bp, "%16s", "");
ASN1_STRING_print(bp, X509_EXTENSION_get_data(ex));
}
if (BIO_write(bp, "\n", 1) <= 0)
goto err;
}
sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);
}
}
if (!(cflag & X509_FLAG_NO_SIGDUMP)) {
if (!X509_signature_print(bp, x->sig_alg, x->signature))
goto err;
}
return (1);
err:
X509err(X509_F_X509_REQ_PRINT_EX, ERR_R_BUF_LIB);
return (0);
}
|
['int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,\n unsigned long cflag)\n{\n long l;\n int i;\n X509_REQ_INFO *ri;\n EVP_PKEY *pkey;\n STACK_OF(X509_ATTRIBUTE) *sk;\n STACK_OF(X509_EXTENSION) *exts;\n char mlch = \' \';\n int nmindent = 0;\n if ((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) {\n mlch = \'\\n\';\n nmindent = 12;\n }\n if (nmflags == X509_FLAG_COMPAT)\n nmindent = 16;\n ri = &x->req_info;\n if (!(cflag & X509_FLAG_NO_HEADER)) {\n if (BIO_write(bp, "Certificate Request:\\n", 21) <= 0)\n goto err;\n if (BIO_write(bp, " Data:\\n", 10) <= 0)\n goto err;\n }\n if (!(cflag & X509_FLAG_NO_VERSION)) {\n l = X509_REQ_get_version(x);\n if (BIO_printf(bp, "%8sVersion: %ld (0x%lx)\\n", "", l + 1, l) <= 0)\n goto err;\n }\n if (!(cflag & X509_FLAG_NO_SUBJECT)) {\n if (BIO_printf(bp, " Subject:%c", mlch) <= 0)\n goto err;\n if (X509_NAME_print_ex(bp, ri->subject, nmindent, nmflags) < 0)\n goto err;\n if (BIO_write(bp, "\\n", 1) <= 0)\n goto err;\n }\n if (!(cflag & X509_FLAG_NO_PUBKEY)) {\n if (BIO_write(bp, " Subject Public Key Info:\\n", 33) <= 0)\n goto err;\n if (BIO_printf(bp, "%12sPublic Key Algorithm: ", "") <= 0)\n goto err;\n if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0)\n goto err;\n if (BIO_puts(bp, "\\n") <= 0)\n goto err;\n pkey = X509_REQ_get_pubkey(x);\n if (pkey == NULL) {\n BIO_printf(bp, "%12sUnable to load Public Key\\n", "");\n ERR_print_errors(bp);\n } else {\n EVP_PKEY_print_public(bp, pkey, 16, NULL);\n EVP_PKEY_free(pkey);\n }\n }\n if (!(cflag & X509_FLAG_NO_ATTRIBUTES)) {\n if (BIO_printf(bp, "%8sAttributes:\\n", "") <= 0)\n goto err;\n sk = x->req_info.attributes;\n if (sk_X509_ATTRIBUTE_num(sk) == 0) {\n if (BIO_printf(bp, "%12sa0:00\\n", "") <= 0)\n goto err;\n } else {\n for (i = 0; i < sk_X509_ATTRIBUTE_num(sk); i++) {\n ASN1_TYPE *at;\n X509_ATTRIBUTE *a;\n ASN1_BIT_STRING *bs = NULL;\n ASN1_OBJECT *aobj;\n int j, type = 0, count = 1, ii = 0;\n a = sk_X509_ATTRIBUTE_value(sk, i);\n aobj = X509_ATTRIBUTE_get0_object(a);\n if (X509_REQ_extension_nid(OBJ_obj2nid(aobj)))\n continue;\n if (BIO_printf(bp, "%12s", "") <= 0)\n goto err;\n if ((j = i2a_ASN1_OBJECT(bp, aobj)) > 0) {\n ii = 0;\n count = X509_ATTRIBUTE_count(a);\n get_next:\n at = X509_ATTRIBUTE_get0_type(a, ii);\n type = at->type;\n bs = at->value.asn1_string;\n }\n for (j = 25 - j; j > 0; j--)\n if (BIO_write(bp, " ", 1) != 1)\n goto err;\n if (BIO_puts(bp, ":") <= 0)\n goto err;\n if ((type == V_ASN1_PRINTABLESTRING) ||\n (type == V_ASN1_T61STRING) ||\n (type == V_ASN1_IA5STRING)) {\n if (BIO_write(bp, (char *)bs->data, bs->length)\n != bs->length)\n goto err;\n BIO_puts(bp, "\\n");\n } else {\n BIO_puts(bp, "unable to print attribute\\n");\n }\n if (++ii < count)\n goto get_next;\n }\n }\n }\n if (!(cflag & X509_FLAG_NO_EXTENSIONS)) {\n exts = X509_REQ_get_extensions(x);\n if (exts) {\n BIO_printf(bp, "%8sRequested Extensions:\\n", "");\n for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {\n ASN1_OBJECT *obj;\n X509_EXTENSION *ex;\n int j;\n ex = sk_X509_EXTENSION_value(exts, i);\n if (BIO_printf(bp, "%12s", "") <= 0)\n goto err;\n obj = X509_EXTENSION_get_object(ex);\n i2a_ASN1_OBJECT(bp, obj);\n j = X509_EXTENSION_get_critical(ex);\n if (BIO_printf(bp, ": %s\\n", j ? "critical" : "") <= 0)\n goto err;\n if (!X509V3_EXT_print(bp, ex, cflag, 16)) {\n BIO_printf(bp, "%16s", "");\n ASN1_STRING_print(bp, X509_EXTENSION_get_data(ex));\n }\n if (BIO_write(bp, "\\n", 1) <= 0)\n goto err;\n }\n sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free);\n }\n }\n if (!(cflag & X509_FLAG_NO_SIGDUMP)) {\n if (!X509_signature_print(bp, x->sig_alg, x->signature))\n goto err;\n }\n return (1);\n err:\n X509err(X509_F_X509_REQ_PRINT_EX, ERR_R_BUF_LIB);\n return (0);\n}', 'long X509_REQ_get_version(X509_REQ *req)\n{\n return ASN1_INTEGER_get(req->req_info.version);\n}', 'long ASN1_INTEGER_get(const ASN1_INTEGER *a)\n{\n int i;\n int64_t r;\n if (a == NULL)\n return 0;\n i = ASN1_INTEGER_get_int64(&r, a);\n if (i == 0)\n return -1;\n if (r > LONG_MAX || r < LONG_MIN)\n return -1;\n return (long)r;\n}']
|
1,679
| 0
|
https://github.com/openssl/openssl/blob/3ad4af89cf7380aa94d1995e05e713d59e1c469a/crypto/err/err.c/#L867
|
int ERR_set_mark(void)
{
ERR_STATE *es;
es = ERR_get_state();
if (es->bottom == es->top)
return 0;
es->err_flags[es->top] |= ERR_FLAG_MARK;
return 1;
}
|
['int ERR_set_mark(void)\n{\n ERR_STATE *es;\n es = ERR_get_state();\n if (es->bottom == es->top)\n return 0;\n es->err_flags[es->top] |= ERR_FLAG_MARK;\n return 1;\n}', 'ERR_STATE *ERR_get_state(void)\n{\n ERR_STATE *state = NULL;\n CRYPTO_THREAD_run_once(&err_init, err_do_init);\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}', 'void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)\n{\n return pthread_getspecific(*key);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)\n{\n if (pthread_setspecific(*key, val) != 0)\n return 0;\n return 1;\n}']
|
1,680
| 0
|
https://github.com/openssl/openssl/blob/0350ef69add8758dd180e73cbc7c1961bf64e503/crypto/bn/bn_ctx.c/#L437
|
static void BN_POOL_release(BN_POOL *p, unsigned int num)
{
unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;
p->used -= num;
while (num--) {
bn_check_top(p->current->vals + offset);
if (!offset) {
offset = BN_CTX_POOL_SIZE - 1;
p->current = p->current->prev;
} else
offset--;
}
}
|
['int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifdef BN_DEBUG_LEVITTE\n fprintf(stderr, "DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n", n0, n1, d0, q);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (!offset) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}']
|
1,681
| 0
|
https://github.com/libav/libav/blob/cf6bae6883607f83f3b042b7b9d711197f736e2a/libswscale/swscale.c/#L3172
|
static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){
int length= a->length + b->length - 1;
double *coeff= av_malloc(length*sizeof(double));
int i, j;
SwsVector *vec= av_malloc(sizeof(SwsVector));
vec->coeff= coeff;
vec->length= length;
for (i=0; i<length; i++) coeff[i]= 0.0;
for (i=0; i<a->length; i++)
{
for (j=0; j<b->length; j++)
{
coeff[i+j]+= a->coeff[i]*b->coeff[j];
}
}
return vec;
}
|
['static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){\n int length= a->length + b->length - 1;\n double *coeff= av_malloc(length*sizeof(double));\n int i, j;\n SwsVector *vec= av_malloc(sizeof(SwsVector));\n vec->coeff= coeff;\n vec->length= length;\n for (i=0; i<length; i++) coeff[i]= 0.0;\n for (i=0; i<a->length; i++)\n {\n for (j=0; j<b->length; j++)\n {\n coeff[i+j]+= a->coeff[i]*b->coeff[j];\n }\n }\n return vec;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,682
| 0
|
https://github.com/openssl/openssl/blob/61f5b6f33807306d09bccbc2dcad474d1d04ca40/crypto/lhash/lhash.c/#L254
|
char *lh_delete(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free((char *)nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len)\n\t{\n\tint al,i,j,n,ret;\n\tSSL3_RECORD *rr;\n\tvoid (*cb)()=NULL;\n\tBIO *bio;\n\tif (s->s3->rbuf.buf == NULL)\n\t\tif (!ssl3_setup_buffers(s))\n\t\t\treturn(-1);\n\tif (!s->in_handshake && SSL_in_init(s))\n\t\t{\n\t\ti=s->handshake_func(s);\n\t\tif (i < 0) return(i);\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);\n\t\t\treturn(-1);\n\t\t\t}\n\t\t}\nstart:\n\ts->rwstate=SSL_NOTHING;\n\trr= &(s->s3->rrec);\n\tif ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY))\n\t\t{\n\t\tret=ssl3_get_record(s);\n\t\tif (ret <= 0) return(ret);\n\t\t}\n\tif (s->s3->change_cipher_spec && (rr->type != SSL3_RT_HANDSHAKE))\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_DATA_BETWEEN_CCS_AND_FINISHED);\n\t\tgoto err;\n\t\t}\n\tif (s->shutdown & SSL_RECEIVED_SHUTDOWN)\n\t\t{\n\t\trr->length=0;\n\t\ts->rwstate=SSL_NOTHING;\n\t\treturn(0);\n\t\t}\n\tif ((rr->type == SSL3_RT_HANDSHAKE) && (rr->length == 4) &&\n\t\t(rr->data[0] == SSL3_MT_CLIENT_REQUEST) &&\n\t\t(s->session != NULL) && (s->session->cipher != NULL))\n\t\t{\n\t\tif ((rr->data[1] != 0) || (rr->data[2] != 0) ||\n\t\t\t(rr->data[3] != 0))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CLIENT_REQUEST);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (SSL_is_init_finished(s) &&\n\t\t\t!(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&\n\t\t\t!s->s3->renegotiate)\n\t\t\t{\n\t\t\tssl3_renegotiate(s);\n\t\t\tif (ssl3_renegotiate_check(s))\n\t\t\t\t{\n\t\t\t\tn=s->handshake_func(s);\n\t\t\t\tif (n < 0) return(n);\n\t\t\t\tif (n == 0)\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);\n\t\t\t\t\treturn(-1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\trr->length=0;\n \tgoto start;\n\t\t}\n\tif ((rr->type != type) || (s->shutdown & SSL_SENT_SHUTDOWN))\n\t\t{\n\t\tif (rr->type == SSL3_RT_ALERT)\n\t\t\t{\n\t\t\tif ((rr->length != 2) || (rr->off != 0))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_ALERT_RECORD);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\ti=rr->data[0];\n\t\t\tn=rr->data[1];\n\t\t\trr->length=0;\n\t\t\tif (s->info_callback != NULL)\n\t\t\t\tcb=s->info_callback;\n\t\t\telse if (s->ctx->info_callback != NULL)\n\t\t\t\tcb=s->ctx->info_callback;\n\t\t\tif (cb != NULL)\n\t\t\t\t{\n\t\t\t\tj=(i<<8)|n;\n\t\t\t\tcb(s,SSL_CB_READ_ALERT,j);\n\t\t\t\t}\n\t\t\tif (i == 1)\n\t\t\t\t{\n\t\t\t\ts->s3->warn_alert=n;\n\t\t\t\tif (n == SSL_AD_CLOSE_NOTIFY)\n\t\t\t\t\t{\n\t\t\t\t\ts->shutdown|=SSL_RECEIVED_SHUTDOWN;\n\t\t\t\t\treturn(0);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if (i == 2)\n\t\t\t\t{\n\t\t\t\tchar tmp[16];\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\ts->s3->fatal_alert=n;\n\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,\n\t\t\t\t\tSSL_AD_REASON_OFFSET+n);\n\t\t\t\tsprintf(tmp,"%d",n);\n\t\t\t\tERR_add_error_data(2,"SSL alert number ",tmp);\n\t\t\t\ts->shutdown|=SSL_RECEIVED_SHUTDOWN;\n\t\t\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNKNOWN_ALERT_TYPE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\trr->length=0;\n\t\t\tgoto start;\n\t\t\t}\n\t\tif (s->shutdown & SSL_SENT_SHUTDOWN)\n\t\t\t{\n\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\trr->length=0;\n\t\t\treturn(0);\n\t\t\t}\n\t\tif (rr->type == SSL3_RT_CHANGE_CIPHER_SPEC)\n\t\t\t{\n\t\t\tif (\t(rr->length != 1) || (rr->off != 0) ||\n\t\t\t\t(rr->data[0] != SSL3_MT_CCS))\n\t\t\t\t{\n\t\t\t\ti=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_BAD_CHANGE_CIPHER_SPEC);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\trr->length=0;\n\t\t\ts->s3->change_cipher_spec=1;\n\t\t\tif (!do_change_cipher_spec(s))\n\t\t\t\tgoto err;\n\t\t\telse\n\t\t\t\tgoto start;\n\t\t\t}\n\t\tif ((rr->type == SSL3_RT_HANDSHAKE) &&\n\t\t\t!s->in_handshake)\n\t\t\t{\n\t\t\tif (((s->state&SSL_ST_MASK) == SSL_ST_OK) &&\n\t\t\t\t!(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS))\n\t\t\t\t{\n\t\t\t\ts->state=SSL_ST_BEFORE|(s->server)\n\t\t\t\t\t\t?SSL_ST_ACCEPT\n\t\t\t\t\t\t:SSL_ST_CONNECT;\n\t\t\t\ts->new_session=1;\n\t\t\t\t}\n\t\t\tn=s->handshake_func(s);\n\t\t\tif (n < 0) return(n);\n\t\t\tif (n == 0)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_SSL_HANDSHAKE_FAILURE);\n\t\t\t\treturn(-1);\n\t\t\t\t}\n\t\t\ts->rwstate=SSL_READING;\n\t\t\tbio=SSL_get_rbio(s);\n\t\t\tBIO_clear_retry_flags(bio);\n\t\t\tBIO_set_retry_read(bio);\n\t\t\treturn(-1);\n\t\t\t}\n\t\tswitch (rr->type)\n\t\t\t{\n\t\tdefault:\n#ifndef NO_TLS\n\t\t\tif (s->version == TLS1_VERSION)\n\t\t\t\t{\n\t\t\t\tgoto start;\n\t\t\t\t}\n#endif\n\t\tcase SSL3_RT_CHANGE_CIPHER_SPEC:\n\t\tcase SSL3_RT_ALERT:\n\t\tcase SSL3_RT_HANDSHAKE:\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);\n\t\t\tgoto f_err;\n\t\tcase SSL3_RT_APPLICATION_DATA:\n\t\t\tif (s->s3->in_read_app_data &&\n\t\t\t\t(s->s3->total_renegotiations != 0) &&\n\t\t\t\t((\n\t\t\t\t (s->state & SSL_ST_CONNECT) &&\n\t\t\t\t (s->state >= SSL3_ST_CW_CLNT_HELLO_A) &&\n\t\t\t\t (s->state <= SSL3_ST_CR_SRVR_HELLO_A)\n\t\t\t\t ) || (\n\t\t\t\t (s->state & SSL_ST_ACCEPT) &&\n\t\t\t\t (s->state <= SSL3_ST_SW_HELLO_REQ_A) &&\n\t\t\t\t (s->state >= SSL3_ST_SR_CLNT_HELLO_A)\n\t\t\t\t )\n\t\t\t\t))\n\t\t\t\t{\n\t\t\t\ts->s3->in_read_app_data=0;\n\t\t\t\treturn(-1);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_UNEXPECTED_RECORD);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&\n\t\t(s->enc_read_ctx == NULL))\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_READ_BYTES,SSL_R_APP_DATA_IN_HANDSHAKE);\n\t\tgoto f_err;\n\t\t}\n\tif (len <= 0) return(len);\n\tif ((unsigned int)len > rr->length)\n\t\tn=rr->length;\n\telse\n\t\tn=len;\n\tmemcpy(buf,&(rr->data[rr->off]),(unsigned int)n);\n\trr->length-=n;\n\trr->off+=n;\n\tif (rr->length <= 0)\n\t\t{\n\t\ts->rstate=SSL_ST_READ_HEADER;\n\t\trr->off=0;\n\t\t}\n\tif (type == SSL3_RT_HANDSHAKE)\n\t\tssl3_finish_mac(s,buf,n);\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\treturn(-1);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
|
1,683
| 0
|
https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_prime.c/#L196
|
int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),
BN_CTX *ctx_passed, char *cb_arg)
{
int i,j,c2=0,ret= -1;
BIGNUM *check;
BN_CTX *ctx=NULL,*ctx2=NULL;
BN_MONT_CTX *mont=NULL;
if (!BN_is_odd(a))
return(0);
if (ctx_passed != NULL)
ctx=ctx_passed;
else
if ((ctx=BN_CTX_new()) == NULL) goto err;
if ((ctx2=BN_CTX_new()) == NULL) goto err;
if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
check= &(ctx->bn[ctx->tos++]);
if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
for (i=0; i<checks; i++)
{
if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;
j=witness(check,a,ctx,ctx2,mont);
if (j == -1) goto err;
if (j)
{
ret=0;
goto err;
}
if (callback != NULL) callback(1,c2++,cb_arg);
}
ret=1;
err:
ctx->tos--;
if ((ctx_passed == NULL) && (ctx != NULL))
BN_CTX_free(ctx);
if (ctx2 != NULL)
BN_CTX_free(ctx2);
if (mont != NULL) BN_MONT_CTX_free(mont);
return(ret);
}
|
['int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),\n\t BN_CTX *ctx_passed, char *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n\t{\n\tBN_MONT_CTX *ret;\n\tif ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)\n\t\treturn(NULL);\n\tBN_MONT_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}']
|
1,684
| 0
|
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/test/bntest.c/#L723
|
int test_sqr(BIO *bp, BN_CTX *ctx)
{
BIGNUM *a, *c, *d, *e;
int i, ret = 0;
a = BN_new();
c = BN_new();
d = BN_new();
e = BN_new();
if (a == NULL || c == NULL || d == NULL || e == NULL) {
goto err;
}
for (i = 0; i < num0; i++) {
BN_bntest_rand(a, 40 + i * 10, 0, 0);
a->neg = rand_neg();
BN_sqr(c, a, ctx);
if (bp != NULL) {
if (!results) {
BN_print(bp, a);
BIO_puts(bp, " * ");
BN_print(bp, a);
BIO_puts(bp, " - ");
}
BN_print(bp, c);
BIO_puts(bp, "\n");
}
BN_div(d, e, c, a, ctx);
BN_sub(d, d, a);
if (!BN_is_zero(d) || !BN_is_zero(e)) {
fprintf(stderr, "Square test failed!\n");
goto err;
}
}
BN_hex2bn(&a,
"80000000000000008000000000000001"
"FFFFFFFFFFFFFFFE0000000000000000");
BN_sqr(c, a, ctx);
if (bp != NULL) {
if (!results) {
BN_print(bp, a);
BIO_puts(bp, " * ");
BN_print(bp, a);
BIO_puts(bp, " - ");
}
BN_print(bp, c);
BIO_puts(bp, "\n");
}
BN_mul(d, a, a, ctx);
if (BN_cmp(c, d)) {
fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
"different results!\n");
goto err;
}
BN_hex2bn(&a,
"80000000000000000000000080000001"
"FFFFFFFE000000000000000000000000");
BN_sqr(c, a, ctx);
if (bp != NULL) {
if (!results) {
BN_print(bp, a);
BIO_puts(bp, " * ");
BN_print(bp, a);
BIO_puts(bp, " - ");
}
BN_print(bp, c);
BIO_puts(bp, "\n");
}
BN_mul(d, a, a, ctx);
if (BN_cmp(c, d)) {
fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "
"different results!\n");
goto err;
}
ret = 1;
err:
BN_free(a);
BN_free(c);
BN_free(d);
BN_free(e);
return ret;
}
|
['int test_sqr(BIO *bp, BN_CTX *ctx)\n{\n BIGNUM *a, *c, *d, *e;\n int i, ret = 0;\n a = BN_new();\n c = BN_new();\n d = BN_new();\n e = BN_new();\n if (a == NULL || c == NULL || d == NULL || e == NULL) {\n goto err;\n }\n for (i = 0; i < num0; i++) {\n BN_bntest_rand(a, 40 + i * 10, 0, 0);\n a->neg = rand_neg();\n BN_sqr(c, a, ctx);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " * ");\n BN_print(bp, a);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, c);\n BIO_puts(bp, "\\n");\n }\n BN_div(d, e, c, a, ctx);\n BN_sub(d, d, a);\n if (!BN_is_zero(d) || !BN_is_zero(e)) {\n fprintf(stderr, "Square test failed!\\n");\n goto err;\n }\n }\n BN_hex2bn(&a,\n "80000000000000008000000000000001"\n "FFFFFFFFFFFFFFFE0000000000000000");\n BN_sqr(c, a, ctx);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " * ");\n BN_print(bp, a);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, c);\n BIO_puts(bp, "\\n");\n }\n BN_mul(d, a, a, ctx);\n if (BN_cmp(c, d)) {\n fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "\n "different results!\\n");\n goto err;\n }\n BN_hex2bn(&a,\n "80000000000000000000000080000001"\n "FFFFFFFE000000000000000000000000");\n BN_sqr(c, a, ctx);\n if (bp != NULL) {\n if (!results) {\n BN_print(bp, a);\n BIO_puts(bp, " * ");\n BN_print(bp, a);\n BIO_puts(bp, " - ");\n }\n BN_print(bp, c);\n BIO_puts(bp, "\\n");\n }\n BN_mul(d, a, a, ctx);\n if (BN_cmp(c, d)) {\n fprintf(stderr, "Square test failed: BN_sqr and BN_mul produce "\n "different results!\\n");\n goto err;\n }\n ret = 1;\n err:\n BN_free(a);\n BN_free(c);\n BN_free(d);\n BN_free(e);\n return ret;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *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}']
|
1,685
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_sqr.c/#L168
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group,\n const EC_POINT *point,\n BIGNUM *x, BIGNUM *y,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *Z, *Z_1, *Z_2, *Z_3;\n const BIGNUM *Z_;\n int ret = 0;\n if (EC_POINT_is_at_infinity(group, point)) {\n ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES,\n EC_R_POINT_AT_INFINITY);\n return 0;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n Z = BN_CTX_get(ctx);\n Z_1 = BN_CTX_get(ctx);\n Z_2 = BN_CTX_get(ctx);\n Z_3 = BN_CTX_get(ctx);\n if (Z_3 == NULL)\n goto err;\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, Z, point->Z, ctx))\n goto err;\n Z_ = Z;\n } else {\n Z_ = point->Z;\n }\n if (BN_is_one(Z_)) {\n if (group->meth->field_decode) {\n if (x != NULL) {\n if (!group->meth->field_decode(group, x, point->X, ctx))\n goto err;\n }\n if (y != NULL) {\n if (!group->meth->field_decode(group, y, point->Y, ctx))\n goto err;\n }\n } else {\n if (x != NULL) {\n if (!BN_copy(x, point->X))\n goto err;\n }\n if (y != NULL) {\n if (!BN_copy(y, point->Y))\n goto err;\n }\n }\n } else {\n if (!BN_mod_inverse(Z_1, Z_, group->field, ctx)) {\n ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (group->meth->field_encode == 0) {\n if (!group->meth->field_sqr(group, Z_2, Z_1, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(Z_2, Z_1, group->field, ctx))\n goto err;\n }\n if (x != NULL) {\n if (!group->meth->field_mul(group, x, point->X, Z_2, ctx))\n goto err;\n }\n if (y != NULL) {\n if (group->meth->field_encode == 0) {\n if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx))\n goto err;\n } else {\n if (!BN_mod_mul(Z_3, Z_2, Z_1, group->field, ctx))\n goto err;\n }\n if (!group->meth->field_mul(group, y, point->Y, Z_3, ctx))\n goto err;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (!rr || !tmp)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (rr != r)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,686
| 0
|
https://github.com/libav/libav/blob/2c8077621b6466da205ba26fd20a9c906bb71893/libavcodec/snow.c/#L1031
|
static void horizontal_compose53i(IDWTELEM *b, int width){
IDWTELEM temp[width];
const int width2= width>>1;
const int w2= (width+1)>>1;
int x;
for(x=0; x<width2; x++){
temp[2*x ]= b[x ];
temp[2*x + 1]= b[x+w2];
}
if(width&1)
temp[2*x ]= b[x ];
b[0] = temp[0] - ((temp[1]+1)>>1);
for(x=2; x<width-1; x+=2){
b[x ] = temp[x ] - ((temp[x-1] + temp[x+1]+2)>>2);
b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);
}
if(width&1){
b[x ] = temp[x ] - ((temp[x-1]+1)>>1);
b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);
}else
b[x-1] = temp[x-1] + b[x-2];
}
|
['static void horizontal_compose53i(IDWTELEM *b, int width){\n IDWTELEM temp[width];\n const int width2= width>>1;\n const int w2= (width+1)>>1;\n int x;\n for(x=0; x<width2; x++){\n temp[2*x ]= b[x ];\n temp[2*x + 1]= b[x+w2];\n }\n if(width&1)\n temp[2*x ]= b[x ];\n b[0] = temp[0] - ((temp[1]+1)>>1);\n for(x=2; x<width-1; x+=2){\n b[x ] = temp[x ] - ((temp[x-1] + temp[x+1]+2)>>2);\n b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);\n }\n if(width&1){\n b[x ] = temp[x ] - ((temp[x-1]+1)>>1);\n b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1);\n }else\n b[x-1] = temp[x-1] + b[x-2];\n}']
|
1,687
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k = NULL, *r = NULL, *X = NULL;\n const BIGNUM *order;\n EC_POINT *tmp_point = NULL;\n const EC_GROUP *group;\n int ret = 0;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return 0;\n }\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n } else\n ctx = ctx_in;\n k = BN_new();\n r = BN_new();\n X = BN_new();\n if (k == NULL || r == NULL || X == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if ((tmp_point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n do {\n do\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce\n (k, order, EC_KEY_get0_private_key(eckey), dgst, dlen,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n } else {\n if (!BN_priv_rand_range(k, order)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n }\n while (BN_is_zero(k));\n if (!BN_add(k, k, order))\n goto err;\n if (BN_num_bits(k) <= BN_num_bits(order))\n if (!BN_add(k, k, order))\n goto err;\n if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==\n NID_X9_62_prime_field) {\n if (!EC_POINT_get_affine_coordinates_GFp\n (group, tmp_point, X, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#ifndef OPENSSL_NO_EC2M\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group,\n tmp_point, X, NULL,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#endif\n if (!BN_nnmod(r, X, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n }\n while (BN_is_zero(r));\n if (EC_GROUP_get_mont_data(group) != NULL) {\n if (!BN_set_word(X, 2)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_sub(X, order, X, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(X, BN_FLG_CONSTTIME);\n if (!BN_mod_exp_mont_consttime\n (k, k, X, order, ctx, EC_GROUP_get_mont_data(group))) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n } else {\n if (!BN_mod_inverse(k, k, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n }\n BN_clear_free(*rp);\n BN_clear_free(*kinvp);\n *rp = r;\n *kinvp = k;\n ret = 1;\n err:\n if (!ret) {\n BN_clear_free(k);\n BN_clear_free(r);\n }\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n EC_POINT_free(tmp_point);\n BN_clear_free(X);\n return ret;\n}', 'int BN_generate_dsa_nonce(BIGNUM *out, const BIGNUM *range,\n const BIGNUM *priv, const unsigned char *message,\n size_t message_len, BN_CTX *ctx)\n{\n SHA512_CTX sha;\n unsigned char random_bytes[64];\n unsigned char digest[SHA512_DIGEST_LENGTH];\n unsigned done, todo;\n const unsigned num_k_bytes = BN_num_bytes(range) + 8;\n unsigned char private_bytes[96];\n unsigned char *k_bytes;\n int ret = 0;\n k_bytes = OPENSSL_malloc(num_k_bytes);\n if (k_bytes == NULL)\n goto err;\n todo = sizeof(priv->d[0]) * priv->top;\n if (todo > sizeof(private_bytes)) {\n BNerr(BN_F_BN_GENERATE_DSA_NONCE, BN_R_PRIVATE_KEY_TOO_LARGE);\n goto err;\n }\n memcpy(private_bytes, priv->d, todo);\n memset(private_bytes + todo, 0, sizeof(private_bytes) - todo);\n for (done = 0; done < num_k_bytes;) {\n if (RAND_bytes(random_bytes, sizeof(random_bytes)) != 1)\n goto err;\n SHA512_Init(&sha);\n SHA512_Update(&sha, &done, sizeof(done));\n SHA512_Update(&sha, private_bytes, sizeof(private_bytes));\n SHA512_Update(&sha, message, message_len);\n SHA512_Update(&sha, random_bytes, sizeof(random_bytes));\n SHA512_Final(digest, &sha);\n todo = num_k_bytes - done;\n if (todo > SHA512_DIGEST_LENGTH)\n todo = SHA512_DIGEST_LENGTH;\n memcpy(k_bytes + done, digest, todo);\n done += todo;\n }\n if (!BN_bin2bn(k_bytes, num_k_bytes, out))\n goto err;\n if (BN_mod(out, out, range, ctx) != 1)\n goto err;\n ret = 1;\n err:\n OPENSSL_free(k_bytes);\n OPENSSL_cleanse(private_bytes, sizeof(private_bytes));\n return ret;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,688
| 0
|
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L907
|
PUT_HEVC_QPEL_HV(3, 1)
|
['QPEL(32)', 'PUT_HEVC_QPEL_HV(3, 1)']
|
1,689
| 0
|
https://github.com/libav/libav/blob/548a99742c2498575d0dbcd1aa030b9d51d28b18/ffmpeg.c/#L3026
|
static void new_video_stream(AVFormatContext *oc)
{
AVStream *st;
AVCodecContext *video_enc;
int codec_id;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;
video_bitstream_filters= NULL;
if(thread_count>1)
avcodec_thread_init(st->codec, thread_count);
video_enc = st->codec;
if(video_codec_tag)
video_enc->codec_tag= video_codec_tag;
if( (video_global_header&1)
|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){
video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
if(video_global_header&2){
video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
avcodec_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;
}
if (video_stream_copy) {
st->stream_copy = 1;
video_enc->codec_type = CODEC_TYPE_VIDEO;
video_enc->sample_aspect_ratio =
st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
} else {
const char *p;
int i;
AVCodec *codec;
AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
if (video_codec_name) {
codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);
codec = avcodec_find_encoder_by_name(video_codec_name);
output_codecs[nb_ocodecs] = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
codec = avcodec_find_encoder(codec_id);
}
video_enc->codec_id = codec_id;
set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
if (codec && codec->supported_framerates && !force_fps)
fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
video_enc->time_base.den = fps.num;
video_enc->time_base.num = fps.den;
video_enc->width = frame_width + frame_padright + frame_padleft;
video_enc->height = frame_height + frame_padtop + frame_padbottom;
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);
video_enc->pix_fmt = frame_pix_fmt;
st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
if(codec && codec->pix_fmts){
const enum PixelFormat *p= codec->pix_fmts;
for(; *p!=-1; p++){
if(*p == video_enc->pix_fmt)
break;
}
if(*p == -1)
video_enc->pix_fmt = codec->pix_fmts[0];
}
if (intra_only)
video_enc->gop_size = 0;
if (video_qscale || same_quality) {
video_enc->flags |= CODEC_FLAG_QSCALE;
video_enc->global_quality=
st->quality = FF_QP2LAMBDA * video_qscale;
}
if(intra_matrix)
video_enc->intra_matrix = intra_matrix;
if(inter_matrix)
video_enc->inter_matrix = inter_matrix;
video_enc->thread_count = thread_count;
p= video_rc_override_string;
for(i=0; p; i++){
int start, end, q;
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
if(e!=3){
fprintf(stderr, "error parsing rc_override\n");
av_exit(1);
}
video_enc->rc_override=
av_realloc(video_enc->rc_override,
sizeof(RcOverride)*(i+1));
video_enc->rc_override[i].start_frame= start;
video_enc->rc_override[i].end_frame = end;
if(q>0){
video_enc->rc_override[i].qscale= q;
video_enc->rc_override[i].quality_factor= 1.0;
}
else{
video_enc->rc_override[i].qscale= 0;
video_enc->rc_override[i].quality_factor= -q/100.0;
}
p= strchr(p, '/');
if(p) p++;
}
video_enc->rc_override_count=i;
if (!video_enc->rc_initial_buffer_occupancy)
video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
video_enc->me_threshold= me_threshold;
video_enc->intra_dc_precision= intra_dc_precision - 8;
if (do_psnr)
video_enc->flags|= CODEC_FLAG_PSNR;
if (do_pass) {
if (do_pass == 1) {
video_enc->flags |= CODEC_FLAG_PASS1;
} else {
video_enc->flags |= CODEC_FLAG_PASS2;
}
}
}
nb_ocodecs++;
video_disable = 0;
av_freep(&video_codec_name);
video_stream_copy = 0;
}
|
['static void new_video_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *video_enc;\n int codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;\n video_bitstream_filters= NULL;\n if(thread_count>1)\n avcodec_thread_init(st->codec, thread_count);\n video_enc = st->codec;\n if(video_codec_tag)\n video_enc->codec_tag= video_codec_tag;\n if( (video_global_header&1)\n || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){\n video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if(video_global_header&2){\n video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;\n avcodec_opts[CODEC_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;\n }\n if (video_stream_copy) {\n st->stream_copy = 1;\n video_enc->codec_type = CODEC_TYPE_VIDEO;\n video_enc->sample_aspect_ratio =\n st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);\n } else {\n const char *p;\n int i;\n AVCodec *codec;\n AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};\n if (video_codec_name) {\n codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);\n codec = avcodec_find_encoder_by_name(video_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);\n codec = avcodec_find_encoder(codec_id);\n }\n video_enc->codec_id = codec_id;\n set_context_opts(video_enc, avcodec_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (codec && codec->supported_framerates && !force_fps)\n fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];\n video_enc->time_base.den = fps.num;\n video_enc->time_base.num = fps.den;\n video_enc->width = frame_width + frame_padright + frame_padleft;\n video_enc->height = frame_height + frame_padtop + frame_padbottom;\n video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);\n video_enc->pix_fmt = frame_pix_fmt;\n st->sample_aspect_ratio = video_enc->sample_aspect_ratio;\n if(codec && codec->pix_fmts){\n const enum PixelFormat *p= codec->pix_fmts;\n for(; *p!=-1; p++){\n if(*p == video_enc->pix_fmt)\n break;\n }\n if(*p == -1)\n video_enc->pix_fmt = codec->pix_fmts[0];\n }\n if (intra_only)\n video_enc->gop_size = 0;\n if (video_qscale || same_quality) {\n video_enc->flags |= CODEC_FLAG_QSCALE;\n video_enc->global_quality=\n st->quality = FF_QP2LAMBDA * video_qscale;\n }\n if(intra_matrix)\n video_enc->intra_matrix = intra_matrix;\n if(inter_matrix)\n video_enc->inter_matrix = inter_matrix;\n video_enc->thread_count = thread_count;\n p= video_rc_override_string;\n for(i=0; p; i++){\n int start, end, q;\n int e=sscanf(p, "%d,%d,%d", &start, &end, &q);\n if(e!=3){\n fprintf(stderr, "error parsing rc_override\\n");\n av_exit(1);\n }\n video_enc->rc_override=\n av_realloc(video_enc->rc_override,\n sizeof(RcOverride)*(i+1));\n video_enc->rc_override[i].start_frame= start;\n video_enc->rc_override[i].end_frame = end;\n if(q>0){\n video_enc->rc_override[i].qscale= q;\n video_enc->rc_override[i].quality_factor= 1.0;\n }\n else{\n video_enc->rc_override[i].qscale= 0;\n video_enc->rc_override[i].quality_factor= -q/100.0;\n }\n p= strchr(p, \'/\');\n if(p) p++;\n }\n video_enc->rc_override_count=i;\n if (!video_enc->rc_initial_buffer_occupancy)\n video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;\n video_enc->me_threshold= me_threshold;\n video_enc->intra_dc_precision= intra_dc_precision - 8;\n if (do_psnr)\n video_enc->flags|= CODEC_FLAG_PSNR;\n if (do_pass) {\n if (do_pass == 1) {\n video_enc->flags |= CODEC_FLAG_PASS1;\n } else {\n video_enc->flags |= CODEC_FLAG_PASS2;\n }\n }\n }\n nb_ocodecs++;\n video_disable = 0;\n av_freep(&video_codec_name);\n video_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}']
|
1,690
| 1
|
https://github.com/nginx/nginx/blob/9b81d3b1bb615398eb993a5e8ba51fb3e0b4bf6d/src/http/ngx_http_request.c/#L3409
|
static ngx_int_t
ngx_http_post_action(ngx_http_request_t *r)
{
ngx_http_core_loc_conf_t *clcf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->post_action.data == NULL) {
return NGX_DECLINED;
}
if (r->post_action && r->uri_changes == 0) {
return NGX_DECLINED;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"post action: \"%V\"", &clcf->post_action);
r->main->count--;
r->http_version = NGX_HTTP_VERSION_9;
r->header_only = 1;
r->post_action = 1;
r->read_event_handler = ngx_http_block_reading;
if (clcf->post_action.data[0] == '/') {
ngx_http_internal_redirect(r, &clcf->post_action, NULL);
} else {
ngx_http_named_location(r, &clcf->post_action);
}
return NGX_OK;
}
|
['static void\nngx_http_upstream_init_request(ngx_http_request_t *r)\n{\n ngx_str_t *host;\n ngx_uint_t i;\n ngx_resolver_ctx_t *ctx, temp;\n ngx_http_cleanup_t *cln;\n ngx_http_upstream_t *u;\n ngx_http_core_loc_conf_t *clcf;\n ngx_http_upstream_srv_conf_t *uscf, **uscfp;\n ngx_http_upstream_main_conf_t *umcf;\n if (r->aio) {\n return;\n }\n u = r->upstream;\n#if (NGX_HTTP_CACHE)\n if (u->conf->cache) {\n ngx_int_t rc;\n rc = ngx_http_upstream_cache(r, u);\n if (rc == NGX_BUSY) {\n r->write_event_handler = ngx_http_upstream_init_request;\n return;\n }\n r->write_event_handler = ngx_http_request_empty_handler;\n if (rc == NGX_ERROR) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (rc == NGX_OK) {\n rc = ngx_http_upstream_cache_send(r, u);\n if (rc == NGX_DONE) {\n return;\n }\n if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n rc = NGX_DECLINED;\n r->cached = 0;\n u->buffer.start = NULL;\n u->cache_status = NGX_HTTP_CACHE_MISS;\n u->request_sent = 1;\n }\n if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) {\n rc = NGX_ERROR;\n }\n }\n if (rc != NGX_DECLINED) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n }\n#endif\n u->store = u->conf->store;\n if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {\n r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;\n r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;\n }\n if (r->request_body) {\n u->request_bufs = r->request_body->bufs;\n }\n if (u->create_request(r) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (ngx_http_upstream_set_local(r, u, u->conf->local) != NGX_OK) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n u->output.alignment = clcf->directio_alignment;\n u->output.pool = r->pool;\n u->output.bufs.num = 1;\n u->output.bufs.size = clcf->client_body_buffer_size;\n if (u->output.output_filter == NULL) {\n u->output.output_filter = ngx_chain_writer;\n u->output.filter_ctx = &u->writer;\n }\n u->writer.pool = r->pool;\n if (r->upstream_states == NULL) {\n r->upstream_states = ngx_array_create(r->pool, 1,\n sizeof(ngx_http_upstream_state_t));\n if (r->upstream_states == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n } else {\n u->state = ngx_array_push(r->upstream_states);\n if (u->state == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));\n }\n cln = ngx_http_cleanup_add(r, 0);\n if (cln == NULL) {\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n cln->handler = ngx_http_upstream_cleanup;\n cln->data = r;\n u->cleanup = &cln->handler;\n if (u->resolved == NULL) {\n uscf = u->conf->upstream;\n } else {\n#if (NGX_HTTP_SSL)\n u->ssl_name = u->resolved->host;\n#endif\n host = &u->resolved->host;\n umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);\n uscfp = umcf->upstreams.elts;\n for (i = 0; i < umcf->upstreams.nelts; i++) {\n uscf = uscfp[i];\n if (uscf->host.len == host->len\n && ((uscf->port == 0 && u->resolved->no_port)\n || uscf->port == u->resolved->port)\n && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)\n {\n goto found;\n }\n }\n if (u->resolved->sockaddr) {\n if (u->resolved->port == 0\n && u->resolved->sockaddr->sa_family != AF_UNIX)\n {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no port in upstream \\"%V\\"", host);\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n ngx_http_upstream_connect(r, u);\n return;\n }\n if (u->resolved->port == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no port in upstream \\"%V\\"", host);\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n temp.name = *host;\n ctx = ngx_resolve_start(clcf->resolver, &temp);\n if (ctx == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (ctx == NGX_NO_RESOLVER) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "no resolver defined to resolve %V", host);\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);\n return;\n }\n ctx->name = *host;\n ctx->handler = ngx_http_upstream_resolve_handler;\n ctx->data = r;\n ctx->timeout = clcf->resolver_timeout;\n u->resolved->ctx = ctx;\n if (ngx_resolve_name(ctx) != NGX_OK) {\n u->resolved->ctx = NULL;\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\nfound:\n if (uscf == NULL) {\n ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,\n "no upstream configuration");\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->upstream = uscf;\n#if (NGX_HTTP_SSL)\n u->ssl_name = uscf->host;\n#endif\n if (uscf->peer.init(r, uscf) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->peer.start_time = ngx_current_msec;\n if (u->conf->next_upstream_tries\n && u->peer.tries > u->conf->next_upstream_tries)\n {\n u->peer.tries = u->conf->next_upstream_tries;\n }\n ngx_http_upstream_connect(r, u);\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n ngx_http_upstream_t *u, ngx_int_t rc)\n{\n ngx_uint_t flush;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "finalize http upstream request: %i", rc);\n if (u->cleanup == NULL) {\n ngx_http_finalize_request(r, NGX_DONE);\n return;\n }\n *u->cleanup = NULL;\n u->cleanup = NULL;\n if (u->resolved && u->resolved->ctx) {\n ngx_resolve_name_done(u->resolved->ctx);\n u->resolved->ctx = NULL;\n }\n if (u->state && u->state->response_time) {\n u->state->response_time = ngx_current_msec - u->state->response_time;\n if (u->pipe && u->pipe->read_length) {\n u->state->bytes_received += u->pipe->read_length\n - u->pipe->preread_size;\n u->state->response_length = u->pipe->read_length;\n }\n }\n u->finalize_request(r, rc);\n if (u->peer.free && u->peer.sockaddr) {\n u->peer.free(&u->peer, u->peer.data, 0);\n u->peer.sockaddr = NULL;\n }\n if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n if (u->peer.connection->ssl) {\n u->peer.connection->ssl->no_wait_shutdown = 1;\n (void) ngx_ssl_shutdown(u->peer.connection);\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "close http upstream connection: %d",\n u->peer.connection->fd);\n if (u->peer.connection->pool) {\n ngx_destroy_pool(u->peer.connection->pool);\n }\n ngx_close_connection(u->peer.connection);\n }\n u->peer.connection = NULL;\n if (u->pipe && u->pipe->temp_file) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream temp fd: %d",\n u->pipe->temp_file->file.fd);\n }\n if (u->store && u->pipe && u->pipe->temp_file\n && u->pipe->temp_file->file.fd != NGX_INVALID_FILE)\n {\n if (ngx_delete_file(u->pipe->temp_file->file.name.data)\n == NGX_FILE_ERROR)\n {\n ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,\n ngx_delete_file_n " \\"%s\\" failed",\n u->pipe->temp_file->file.name.data);\n }\n }\n#if (NGX_HTTP_CACHE)\n if (r->cache) {\n if (u->cacheable) {\n if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n time_t valid;\n valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n if (valid) {\n r->cache->valid_sec = ngx_time() + valid;\n r->cache->error = rc;\n }\n }\n }\n ngx_http_file_cache_free(r->cache, u->pipe->temp_file);\n }\n#endif\n if (r->subrequest_in_memory\n && u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE)\n {\n u->buffer.last = u->buffer.pos;\n }\n r->read_event_handler = ngx_http_block_reading;\n if (rc == NGX_DECLINED) {\n return;\n }\n r->connection->log->action = "sending to client";\n if (!u->header_sent\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || (u->pipe && u->pipe->downstream_error))\n {\n ngx_http_finalize_request(r, rc);\n return;\n }\n flush = 0;\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {\n rc = NGX_ERROR;\n flush = 1;\n }\n if (r->header_only) {\n ngx_http_finalize_request(r, rc);\n return;\n }\n if (rc == 0) {\n rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n } else if (flush) {\n r->keepalive = 0;\n rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);\n }\n ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %i, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (r->background) {\n if (!r->logged) {\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n ngx_http_finalize_connection(r);\n return;\n }\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n if (!r->logged) {\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n r->read_event_handler = ngx_http_block_reading;\n r->write_event_handler = ngx_http_request_empty_handler;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'static ngx_int_t\nngx_http_post_action(ngx_http_request_t *r)\n{\n ngx_http_core_loc_conf_t *clcf;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->post_action.data == NULL) {\n return NGX_DECLINED;\n }\n if (r->post_action && r->uri_changes == 0) {\n return NGX_DECLINED;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "post action: \\"%V\\"", &clcf->post_action);\n r->main->count--;\n r->http_version = NGX_HTTP_VERSION_9;\n r->header_only = 1;\n r->post_action = 1;\n r->read_event_handler = ngx_http_block_reading;\n if (clcf->post_action.data[0] == \'/\') {\n ngx_http_internal_redirect(r, &clcf->post_action, NULL);\n } else {\n ngx_http_named_location(r, &clcf->post_action);\n }\n return NGX_OK;\n}']
|
1,691
| 0
|
https://github.com/libav/libav/blob/8f935b9271052be8f97d655081b94b68b6c23bfb/libavcodec/aacdec.c/#L1774
|
static void apply_ltp(AACContext *ac, SingleChannelElement *sce)
{
const LongTermPrediction *ltp = &sce->ics.ltp;
const uint16_t *offsets = sce->ics.swb_offset;
int i, sfb;
if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {
float *predTime = sce->ret;
float *predFreq = ac->buf_mdct;
int16_t num_samples = 2048;
if (ltp->lag < 1024)
num_samples = ltp->lag + 1024;
for (i = 0; i < num_samples; i++)
predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef;
memset(&predTime[i], 0, (2048 - i) * sizeof(float));
windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics);
if (sce->tns.present)
apply_tns(predFreq, &sce->tns, &sce->ics, 0);
for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)
if (ltp->used[sfb])
for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)
sce->coeffs[i] += predFreq[i];
}
}
|
['static void apply_ltp(AACContext *ac, SingleChannelElement *sce)\n{\n const LongTermPrediction *ltp = &sce->ics.ltp;\n const uint16_t *offsets = sce->ics.swb_offset;\n int i, sfb;\n if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) {\n float *predTime = sce->ret;\n float *predFreq = ac->buf_mdct;\n int16_t num_samples = 2048;\n if (ltp->lag < 1024)\n num_samples = ltp->lag + 1024;\n for (i = 0; i < num_samples; i++)\n predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef;\n memset(&predTime[i], 0, (2048 - i) * sizeof(float));\n windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics);\n if (sce->tns.present)\n apply_tns(predFreq, &sce->tns, &sce->ics, 0);\n for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++)\n if (ltp->used[sfb])\n for (i = offsets[sfb]; i < offsets[sfb + 1]; i++)\n sce->coeffs[i] += predFreq[i];\n }\n}']
|
1,692
| 0
|
https://github.com/openssl/openssl/blob/54d00677f305375eee65a0c9edb5f0980c5f020f/crypto/bn/bn_lib.c/#L232
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,\n BN_GENCB *cb)\n{\n int ok = 0;\n BIGNUM *Xp = NULL, *Xq = NULL;\n BN_CTX *ctx = NULL;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto error;\n BN_CTX_start(ctx);\n Xp = BN_CTX_get(ctx);\n Xq = BN_CTX_get(ctx);\n if (Xq == NULL)\n goto error;\n if (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))\n goto error;\n rsa->p = BN_new();\n rsa->q = BN_new();\n if (rsa->p == NULL || rsa->q == NULL)\n goto error;\n if (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,\n e, ctx, cb))\n goto error;\n if (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,\n e, ctx, cb))\n goto error;\n if (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, e, cb))\n goto error;\n ok = 1;\n error:\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n if (ok)\n return 1;\n return 0;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)\n{\n BIGNUM *t;\n int i;\n if ((nbits < 1024) || (nbits & 0xff))\n return 0;\n nbits >>= 1;\n if (!BN_priv_rand(Xp, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n for (i = 0; i < 1000; i++) {\n if (!BN_priv_rand(Xq, nbits, BN_RAND_TOP_TWO, BN_RAND_BOTTOM_ANY))\n goto err;\n if (!BN_sub(t, Xp, Xq))\n goto err;\n if (BN_num_bits(t) > (nbits - 100))\n break;\n }\n BN_CTX_end(ctx);\n if (i < 1000)\n return 1;\n return 0;\n err:\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_priv_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(PRIVATE, rnd, bits, top, bottom);\n}', 'static int bnrand(BNRAND_FLAG flag, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int b, ret = 0, bit, bytes, mask;\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n b = flag == NORMAL ? RAND_bytes(buf, bytes) : RAND_priv_bytes(buf, bytes);\n if (b <= 0)\n goto err;\n if (flag == TESTING) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return ret;\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,\n BIGNUM *Xp1, BIGNUM *Xp2,\n const BIGNUM *Xp,\n const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n int ret = 0;\n BN_CTX_start(ctx);\n if (Xp1 == NULL)\n Xp1 = BN_CTX_get(ctx);\n if (Xp2 == NULL)\n Xp2 = BN_CTX_get(ctx);\n if (Xp1 == NULL || Xp2 == NULL)\n goto error;\n if (!BN_priv_rand(Xp1, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto error;\n if (!BN_priv_rand(Xp2, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto error;\n if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb))\n goto error;\n ret = 1;\n error:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
1,693
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/apps/speed.c/#L2694
|
static int do_multi(int multi)
{
int n;
int fd[2];
int *fds;
static char sep[] = ":";
fds = malloc(multi * sizeof *fds);
for (n = 0; n < multi; ++n) {
if (pipe(fd) == -1) {
fprintf(stderr, "pipe failure\n");
exit(1);
}
fflush(stdout);
fflush(stderr);
if (fork()) {
close(fd[1]);
fds[n] = fd[0];
} else {
close(fd[0]);
close(1);
if (dup(fd[1]) == -1) {
fprintf(stderr, "dup failed\n");
exit(1);
}
close(fd[1]);
mr = 1;
usertime = 0;
free(fds);
return 0;
}
printf("Forked child %d\n", n);
}
for (n = 0; n < multi; ++n) {
FILE *f;
char buf[1024];
char *p;
f = fdopen(fds[n], "r");
while (fgets(buf, sizeof buf, f)) {
p = strchr(buf, '\n');
if (p)
*p = '\0';
if (buf[0] != '+') {
fprintf(stderr, "Don't understand line '%s' from child %d\n",
buf, n);
continue;
}
printf("Got: %s from %d\n", buf, n);
if (!strncmp(buf, "+F:", 3)) {
int alg;
int j;
p = buf + 3;
alg = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
for (j = 0; j < SIZE_NUM; ++j)
results[alg][j] += atof(sstrsep(&p, sep));
} else if (!strncmp(buf, "+F2:", 4)) {
int k;
double d;
p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
if (n)
rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
else
rsa_results[k][0] = d;
d = atof(sstrsep(&p, sep));
if (n)
rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
else
rsa_results[k][1] = d;
} else if (!strncmp(buf, "+F2:", 4)) {
int k;
double d;
p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
if (n)
rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);
else
rsa_results[k][0] = d;
d = atof(sstrsep(&p, sep));
if (n)
rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);
else
rsa_results[k][1] = d;
}
# ifndef OPENSSL_NO_DSA
else if (!strncmp(buf, "+F3:", 4)) {
int k;
double d;
p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
if (n)
dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);
else
dsa_results[k][0] = d;
d = atof(sstrsep(&p, sep));
if (n)
dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);
else
dsa_results[k][1] = d;
}
# endif
# ifndef OPENSSL_NO_ECDSA
else if (!strncmp(buf, "+F4:", 4)) {
int k;
double d;
p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
if (n)
ecdsa_results[k][0] =
1 / (1 / ecdsa_results[k][0] + 1 / d);
else
ecdsa_results[k][0] = d;
d = atof(sstrsep(&p, sep));
if (n)
ecdsa_results[k][1] =
1 / (1 / ecdsa_results[k][1] + 1 / d);
else
ecdsa_results[k][1] = d;
}
# endif
# ifndef OPENSSL_NO_ECDH
else if (!strncmp(buf, "+F5:", 4)) {
int k;
double d;
p = buf + 4;
k = atoi(sstrsep(&p, sep));
sstrsep(&p, sep);
d = atof(sstrsep(&p, sep));
if (n)
ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);
else
ecdh_results[k][0] = d;
}
# endif
else if (!strncmp(buf, "+H:", 3)) {
} else
fprintf(stderr, "Unknown type '%s' from child %d\n", buf, n);
}
fclose(f);
}
free(fds);
return 1;
}
|
['static int do_multi(int multi)\n{\n int n;\n int fd[2];\n int *fds;\n static char sep[] = ":";\n fds = malloc(multi * sizeof *fds);\n for (n = 0; n < multi; ++n) {\n if (pipe(fd) == -1) {\n fprintf(stderr, "pipe failure\\n");\n exit(1);\n }\n fflush(stdout);\n fflush(stderr);\n if (fork()) {\n close(fd[1]);\n fds[n] = fd[0];\n } else {\n close(fd[0]);\n close(1);\n if (dup(fd[1]) == -1) {\n fprintf(stderr, "dup failed\\n");\n exit(1);\n }\n close(fd[1]);\n mr = 1;\n usertime = 0;\n free(fds);\n return 0;\n }\n printf("Forked child %d\\n", n);\n }\n for (n = 0; n < multi; ++n) {\n FILE *f;\n char buf[1024];\n char *p;\n f = fdopen(fds[n], "r");\n while (fgets(buf, sizeof buf, f)) {\n p = strchr(buf, \'\\n\');\n if (p)\n *p = \'\\0\';\n if (buf[0] != \'+\') {\n fprintf(stderr, "Don\'t understand line \'%s\' from child %d\\n",\n buf, n);\n continue;\n }\n printf("Got: %s from %d\\n", buf, n);\n if (!strncmp(buf, "+F:", 3)) {\n int alg;\n int j;\n p = buf + 3;\n alg = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n for (j = 0; j < SIZE_NUM; ++j)\n results[alg][j] += atof(sstrsep(&p, sep));\n } else if (!strncmp(buf, "+F2:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n else\n rsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n else\n rsa_results[k][1] = d;\n } else if (!strncmp(buf, "+F2:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][0] = 1 / (1 / rsa_results[k][0] + 1 / d);\n else\n rsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n rsa_results[k][1] = 1 / (1 / rsa_results[k][1] + 1 / d);\n else\n rsa_results[k][1] = d;\n }\n# ifndef OPENSSL_NO_DSA\n else if (!strncmp(buf, "+F3:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n dsa_results[k][0] = 1 / (1 / dsa_results[k][0] + 1 / d);\n else\n dsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n dsa_results[k][1] = 1 / (1 / dsa_results[k][1] + 1 / d);\n else\n dsa_results[k][1] = d;\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n else if (!strncmp(buf, "+F4:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n ecdsa_results[k][0] =\n 1 / (1 / ecdsa_results[k][0] + 1 / d);\n else\n ecdsa_results[k][0] = d;\n d = atof(sstrsep(&p, sep));\n if (n)\n ecdsa_results[k][1] =\n 1 / (1 / ecdsa_results[k][1] + 1 / d);\n else\n ecdsa_results[k][1] = d;\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n else if (!strncmp(buf, "+F5:", 4)) {\n int k;\n double d;\n p = buf + 4;\n k = atoi(sstrsep(&p, sep));\n sstrsep(&p, sep);\n d = atof(sstrsep(&p, sep));\n if (n)\n ecdh_results[k][0] = 1 / (1 / ecdh_results[k][0] + 1 / d);\n else\n ecdh_results[k][0] = d;\n }\n# endif\n else if (!strncmp(buf, "+H:", 3)) {\n } else\n fprintf(stderr, "Unknown type \'%s\' from child %d\\n", buf, n);\n }\n fclose(f);\n }\n free(fds);\n return 1;\n}']
|
1,694
| 0
|
https://github.com/openssl/openssl/blob/972c87dfc7e765bd28a4964519c362f0d3a58ca4/crypto/bn/bn_lib.c/#L233
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(p);\n BN_CTX_start(ctx);\n b = BN_CTX_get(ctx);\n c = BN_CTX_get(ctx);\n u = BN_CTX_get(ctx);\n v = BN_CTX_get(ctx);\n if (v == NULL)\n goto err;\n if (!BN_GF2m_mod(u, a, p))\n goto err;\n if (BN_is_zero(u))\n goto err;\n if (!BN_copy(v, p))\n goto err;\n# if 0\n if (!BN_one(b))\n goto err;\n while (1) {\n while (!BN_is_odd(u)) {\n if (BN_is_zero(u))\n goto err;\n if (!BN_rshift1(u, u))\n goto err;\n if (BN_is_odd(b)) {\n if (!BN_GF2m_add(b, b, p))\n goto err;\n }\n if (!BN_rshift1(b, b))\n goto err;\n }\n if (BN_abs_is_word(u, 1))\n break;\n if (BN_num_bits(u) < BN_num_bits(v)) {\n tmp = u;\n u = v;\n v = tmp;\n tmp = b;\n b = c;\n c = tmp;\n }\n if (!BN_GF2m_add(u, u, v))\n goto err;\n if (!BN_GF2m_add(b, b, c))\n goto err;\n }\n# else\n {\n int i;\n int ubits = BN_num_bits(u);\n int vbits = BN_num_bits(v);\n int top = p->top;\n BN_ULONG *udp, *bdp, *vdp, *cdp;\n if (!bn_wexpand(u, top))\n goto err;\n udp = u->d;\n for (i = u->top; i < top; i++)\n udp[i] = 0;\n u->top = top;\n if (!bn_wexpand(b, top))\n goto err;\n bdp = b->d;\n bdp[0] = 1;\n for (i = 1; i < top; i++)\n bdp[i] = 0;\n b->top = top;\n if (!bn_wexpand(c, top))\n goto err;\n cdp = c->d;\n for (i = 0; i < top; i++)\n cdp[i] = 0;\n c->top = top;\n vdp = v->d;\n while (1) {\n while (ubits && !(udp[0] & 1)) {\n BN_ULONG u0, u1, b0, b1, mask;\n u0 = udp[0];\n b0 = bdp[0];\n mask = (BN_ULONG)0 - (b0 & 1);\n b0 ^= p->d[0] & mask;\n for (i = 0; i < top - 1; i++) {\n u1 = udp[i + 1];\n udp[i] = ((u0 >> 1) | (u1 << (BN_BITS2 - 1))) & BN_MASK2;\n u0 = u1;\n b1 = bdp[i + 1] ^ (p->d[i + 1] & mask);\n bdp[i] = ((b0 >> 1) | (b1 << (BN_BITS2 - 1))) & BN_MASK2;\n b0 = b1;\n }\n udp[i] = u0 >> 1;\n bdp[i] = b0 >> 1;\n ubits--;\n }\n if (ubits <= BN_BITS2) {\n if (udp[0] == 0)\n goto err;\n if (udp[0] == 1)\n break;\n }\n if (ubits < vbits) {\n i = ubits;\n ubits = vbits;\n vbits = i;\n tmp = u;\n u = v;\n v = tmp;\n tmp = b;\n b = c;\n c = tmp;\n udp = vdp;\n vdp = v->d;\n bdp = cdp;\n cdp = c->d;\n }\n for (i = 0; i < top; i++) {\n udp[i] ^= vdp[i];\n bdp[i] ^= cdp[i];\n }\n if (ubits == vbits) {\n BN_ULONG ul;\n int utop = (ubits - 1) / BN_BITS2;\n while ((ul = udp[utop]) == 0 && utop)\n utop--;\n ubits = utop * BN_BITS2 + BN_num_bits_word(ul);\n }\n }\n bn_correct_top(b);\n }\n# endif\n if (!BN_copy(r, b))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n# ifdef BN_DEBUG\n bn_correct_top(c);\n bn_correct_top(u);\n bn_correct_top(v);\n# endif\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)\n{\n int ret = 0;\n int arr[6];\n bn_check_top(a);\n bn_check_top(p);\n ret = BN_GF2m_poly2arr(p, arr, OSSL_NELEM(arr));\n if (!ret || ret > (int)OSSL_NELEM(arr)) {\n BNerr(BN_F_BN_GF2M_MOD, BN_R_INVALID_LENGTH);\n return 0;\n }\n ret = BN_GF2m_mod_arr(r, a, arr);\n bn_check_top(r);\n return ret;\n}', 'int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const int p[])\n{\n int j, k;\n int n, dN, d0, d1;\n BN_ULONG zz, *z;\n bn_check_top(a);\n if (!p[0]) {\n BN_zero(r);\n return 1;\n }\n if (a != r) {\n if (!bn_wexpand(r, a->top))\n return 0;\n for (j = 0; j < a->top; j++) {\n r->d[j] = a->d[j];\n }\n r->top = a->top;\n }\n z = r->d;\n dN = p[0] / BN_BITS2;\n for (j = r->top - 1; j > dN;) {\n zz = z[j];\n if (z[j] == 0) {\n j--;\n continue;\n }\n z[j] = 0;\n for (k = 1; p[k] != 0; k++) {\n n = p[0] - p[k];\n d0 = n % BN_BITS2;\n d1 = BN_BITS2 - d0;\n n /= BN_BITS2;\n z[j - n] ^= (zz >> d0);\n if (d0)\n z[j - n - 1] ^= (zz << d1);\n }\n n = dN;\n d0 = p[0] % BN_BITS2;\n d1 = BN_BITS2 - d0;\n z[j - n] ^= (zz >> d0);\n if (d0)\n z[j - n - 1] ^= (zz << d1);\n }\n while (j == dN) {\n d0 = p[0] % BN_BITS2;\n zz = z[dN] >> d0;\n if (zz == 0)\n break;\n d1 = BN_BITS2 - d0;\n if (d0)\n z[dN] = (z[dN] << d1) >> d1;\n else\n z[dN] = 0;\n z[0] ^= zz;\n for (k = 1; p[k] != 0; k++) {\n BN_ULONG tmp_ulong;\n n = p[k] / BN_BITS2;\n d0 = p[k] % BN_BITS2;\n d1 = BN_BITS2 - d0;\n z[n] ^= (zz << d0);\n if (d0 && (tmp_ulong = zz >> d1))\n z[n + 1] ^= tmp_ulong;\n }\n }\n bn_correct_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
1,695
| 0
|
https://github.com/libav/libav/blob/a158446b2842143a1ea0a284952571435c9ad3c4/ffmpeg.c/#L2878
|
static int opt_metadata(const char *opt, const char *arg)
{
char *mid= strchr(arg, '=');
if(!mid){
fprintf(stderr, "Missing =\n");
av_exit(1);
}
*mid++= 0;
metadata_count++;
metadata= av_realloc(metadata, sizeof(*metadata)*metadata_count);
metadata[metadata_count-1].key = av_strdup(arg);
metadata[metadata_count-1].value= av_strdup(mid);
return 0;
}
|
['static int opt_metadata(const char *opt, const char *arg)\n{\n char *mid= strchr(arg, \'=\');\n if(!mid){\n fprintf(stderr, "Missing =\\n");\n av_exit(1);\n }\n *mid++= 0;\n metadata_count++;\n metadata= av_realloc(metadata, sizeof(*metadata)*metadata_count);\n metadata[metadata_count-1].key = av_strdup(arg);\n metadata[metadata_count-1].value= av_strdup(mid);\n return 0;\n}']
|
1,696
| 0
|
https://github.com/openssl/openssl/blob/f586d97191ad9821faea026df68aceaba45d1800/apps/s_server.c/#L859
|
static int cert_status_cb(SSL *s, void *arg)
{
tlsextstatusctx *srctx = arg;
BIO *err = srctx->err;
char *host, *port, *path;
int use_ssl;
unsigned char *rspder = NULL;
int rspderlen;
STACK_OF(OPENSSL_STRING) *aia = NULL;
X509 *x = NULL;
X509_STORE_CTX inctx;
X509_OBJECT obj;
OCSP_REQUEST *req = NULL;
OCSP_RESPONSE *resp = NULL;
OCSP_CERTID *id = NULL;
STACK_OF(X509_EXTENSION) *exts;
int ret = SSL_TLSEXT_ERR_NOACK;
int i;
#if 0
STACK_OF(OCSP_RESPID) *ids;
SSL_get_tlsext_status_ids(s, &ids);
BIO_printf(err, "cert_status: received %d ids\n", sk_OCSP_RESPID_num(ids));
#endif
if (srctx->verbose)
BIO_puts(err, "cert_status: callback called\n");
x = SSL_get_certificate(s);
aia = X509_get1_ocsp(x);
if (aia)
{
if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),
&host, &port, &path, &use_ssl))
{
BIO_puts(err, "cert_status: can't parse AIA URL\n");
goto err;
}
if (srctx->verbose)
BIO_printf(err, "cert_status: AIA URL: %s\n",
sk_OPENSSL_STRING_value(aia, 0));
}
else
{
if (!srctx->host)
{
BIO_puts(srctx->err, "cert_status: no AIA and no default responder URL\n");
goto done;
}
host = srctx->host;
path = srctx->path;
port = srctx->port;
use_ssl = srctx->use_ssl;
}
if (!X509_STORE_CTX_init(&inctx,
SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),
NULL, NULL))
goto err;
if (X509_STORE_get_by_subject(&inctx,X509_LU_X509,
X509_get_issuer_name(x),&obj) <= 0)
{
BIO_puts(err, "cert_status: Can't retrieve issuer certificate.\n");
X509_STORE_CTX_cleanup(&inctx);
goto done;
}
req = OCSP_REQUEST_new();
if (!req)
goto err;
id = OCSP_cert_to_id(NULL, x, obj.data.x509);
X509_free(obj.data.x509);
X509_STORE_CTX_cleanup(&inctx);
if (!id)
goto err;
if (!OCSP_request_add0_id(req, id))
goto err;
id = NULL;
SSL_get_tlsext_status_exts(s, &exts);
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++)
{
X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
if (!OCSP_REQUEST_add_ext(req, ext, -1))
goto err;
}
resp = process_responder(err, req, host, path, port, use_ssl, NULL,
srctx->timeout);
if (!resp)
{
BIO_puts(err, "cert_status: error querying responder\n");
goto done;
}
rspderlen = i2d_OCSP_RESPONSE(resp, &rspder);
if (rspderlen <= 0)
goto err;
SSL_set_tlsext_status_ocsp_resp(s, rspder, rspderlen);
if (srctx->verbose)
{
BIO_puts(err, "cert_status: ocsp response sent:\n");
OCSP_RESPONSE_print(err, resp, 2);
}
ret = SSL_TLSEXT_ERR_OK;
done:
if (ret != SSL_TLSEXT_ERR_OK)
ERR_print_errors(err);
if (aia)
{
OPENSSL_free(host);
OPENSSL_free(path);
OPENSSL_free(port);
X509_email_free(aia);
}
if (id)
OCSP_CERTID_free(id);
if (req)
OCSP_REQUEST_free(req);
if (resp)
OCSP_RESPONSE_free(resp);
return ret;
err:
ret = SSL_TLSEXT_ERR_ALERT_FATAL;
goto done;
}
|
['static int cert_status_cb(SSL *s, void *arg)\n\t{\n\ttlsextstatusctx *srctx = arg;\n\tBIO *err = srctx->err;\n\tchar *host, *port, *path;\n\tint use_ssl;\n\tunsigned char *rspder = NULL;\n\tint rspderlen;\n\tSTACK_OF(OPENSSL_STRING) *aia = NULL;\n\tX509 *x = NULL;\n\tX509_STORE_CTX inctx;\n\tX509_OBJECT obj;\n\tOCSP_REQUEST *req = NULL;\n\tOCSP_RESPONSE *resp = NULL;\n\tOCSP_CERTID *id = NULL;\n\tSTACK_OF(X509_EXTENSION) *exts;\n\tint ret = SSL_TLSEXT_ERR_NOACK;\n\tint i;\n#if 0\nSTACK_OF(OCSP_RESPID) *ids;\nSSL_get_tlsext_status_ids(s, &ids);\nBIO_printf(err, "cert_status: received %d ids\\n", sk_OCSP_RESPID_num(ids));\n#endif\n\tif (srctx->verbose)\n\t\tBIO_puts(err, "cert_status: callback called\\n");\n\tx = SSL_get_certificate(s);\n\taia = X509_get1_ocsp(x);\n\tif (aia)\n\t\t{\n\t\tif (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),\n\t\t\t&host, &port, &path, &use_ssl))\n\t\t\t{\n\t\t\tBIO_puts(err, "cert_status: can\'t parse AIA URL\\n");\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (srctx->verbose)\n\t\t\tBIO_printf(err, "cert_status: AIA URL: %s\\n",\n\t\t\t\t\tsk_OPENSSL_STRING_value(aia, 0));\n\t\t}\n\telse\n\t\t{\n\t\tif (!srctx->host)\n\t\t\t{\n\t\t\tBIO_puts(srctx->err, "cert_status: no AIA and no default responder URL\\n");\n\t\t\tgoto done;\n\t\t\t}\n\t\thost = srctx->host;\n\t\tpath = srctx->path;\n\t\tport = srctx->port;\n\t\tuse_ssl = srctx->use_ssl;\n\t\t}\n\tif (!X509_STORE_CTX_init(&inctx,\n\t\t\t\tSSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),\n\t\t\t\tNULL, NULL))\n\t\tgoto err;\n\tif (X509_STORE_get_by_subject(&inctx,X509_LU_X509,\n\t\t\t\tX509_get_issuer_name(x),&obj) <= 0)\n\t\t{\n\t\tBIO_puts(err, "cert_status: Can\'t retrieve issuer certificate.\\n");\n\t\tX509_STORE_CTX_cleanup(&inctx);\n\t\tgoto done;\n\t\t}\n\treq = OCSP_REQUEST_new();\n\tif (!req)\n\t\tgoto err;\n\tid = OCSP_cert_to_id(NULL, x, obj.data.x509);\n\tX509_free(obj.data.x509);\n\tX509_STORE_CTX_cleanup(&inctx);\n\tif (!id)\n\t\tgoto err;\n\tif (!OCSP_request_add0_id(req, id))\n\t\tgoto err;\n\tid = NULL;\n\tSSL_get_tlsext_status_exts(s, &exts);\n\tfor (i = 0; i < sk_X509_EXTENSION_num(exts); i++)\n\t\t{\n\t\tX509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);\n\t\tif (!OCSP_REQUEST_add_ext(req, ext, -1))\n\t\t\tgoto err;\n\t\t}\n\tresp = process_responder(err, req, host, path, port, use_ssl, NULL,\n\t\t\t\t\tsrctx->timeout);\n\tif (!resp)\n\t\t{\n\t\tBIO_puts(err, "cert_status: error querying responder\\n");\n\t\tgoto done;\n\t\t}\n\trspderlen = i2d_OCSP_RESPONSE(resp, &rspder);\n\tif (rspderlen <= 0)\n\t\tgoto err;\n\tSSL_set_tlsext_status_ocsp_resp(s, rspder, rspderlen);\n\tif (srctx->verbose)\n\t\t{\n\t\tBIO_puts(err, "cert_status: ocsp response sent:\\n");\n\t\tOCSP_RESPONSE_print(err, resp, 2);\n\t\t}\n\tret = SSL_TLSEXT_ERR_OK;\n\tdone:\n\tif (ret != SSL_TLSEXT_ERR_OK)\n\t\tERR_print_errors(err);\n\tif (aia)\n\t\t{\n\t\tOPENSSL_free(host);\n\t\tOPENSSL_free(path);\n\t\tOPENSSL_free(port);\n\t\tX509_email_free(aia);\n\t\t}\n\tif (id)\n\t\tOCSP_CERTID_free(id);\n\tif (req)\n\t\tOCSP_REQUEST_free(req);\n\tif (resp)\n\t\tOCSP_RESPONSE_free(resp);\n\treturn ret;\n\terr:\n\tret = SSL_TLSEXT_ERR_ALERT_FATAL;\n\tgoto done;\n\t}', 'int BIO_puts(BIO *b, const char *in)\n\t{\n\tint i;\n\tlong (*cb)(BIO *,int,const char *,int,long,long);\n\tif ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))\n\t\t{\n\t\tBIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);\n\t\treturn(-2);\n\t\t}\n\tcb=b->callback;\n\tif ((cb != NULL) &&\n\t\t((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))\n\t\t\treturn(i);\n\tif (!b->init)\n\t\t{\n\t\tBIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);\n\t\treturn(-2);\n\t\t}\n\ti=b->method->bputs(b,in);\n\tif (i > 0) b->num_write+=(unsigned long)i;\n\tif (cb != NULL)\n\t\ti=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,\n\t\t\t0L,(long)i);\n\treturn(i);\n\t}', 'X509 *SSL_get_certificate(const SSL *s)\n\t{\n\tif (s->cert != NULL)\n\t\treturn(s->cert->key->x509);\n\telse\n\t\treturn(NULL);\n\t}']
|
1,697
| 0
|
https://github.com/openssl/openssl/blob/ff64702b3d83d4c77756e0fd7b624e2165dbbdf0/crypto/packet.c/#L52
|
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
if (!ossl_assert(pkt->subs != NULL && len != 0))
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {
size_t newlen;
size_t reflen;
reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
if (reflen > SIZE_MAX / 2) {
newlen = SIZE_MAX;
} else {
newlen = reflen * 2;
if (newlen < DEFAULT_BUF_SIZE)
newlen = DEFAULT_BUF_SIZE;
}
if (BUF_MEM_grow(pkt->buf, newlen) == 0)
return 0;
}
if (allocbytes != NULL)
*allocbytes = WPACKET_get_curr(pkt);
return 1;
}
|
['EXT_RETURN tls_construct_ctos_srp(SSL *s, WPACKET *pkt, unsigned int context,\n X509 *x, size_t chainidx)\n{\n if (s->srp_ctx.login == NULL)\n return EXT_RETURN_NOT_SENT;\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_srp)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u8(pkt)\n || !WPACKET_set_flags(pkt, WPACKET_FLAGS_NON_ZERO_LENGTH)\n || !WPACKET_memcpy(pkt, s->srp_ctx.login,\n strlen(s->srp_ctx.login))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_SRP,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n return EXT_RETURN_SENT;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n if ((sub = OPENSSL_zalloc(sizeof(*sub))) == NULL) {\n SSLerr(SSL_F_WPACKET_START_SUB_PACKET_LEN__, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n sub->packet_len = pkt->written;\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n if (dest != NULL)\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
|
1,698
| 0
|
https://github.com/libav/libav/blob/41874d0a5df35732367f0c675eac914c23d65aee/libavcodec/ra144.c/#L1596
|
void ff_eval_coefs(int *coefs, const int *refl)
{
int buffer[10];
int *b1 = buffer;
int *b2 = coefs;
int i, j;
for (i=0; i < 10; i++) {
b1[i] = refl[i] << 4;
for (j=0; j < i; j++)
b1[j] = ((refl[i] * b2[i-j-1]) >> 12) + b2[j];
FFSWAP(int *, b1, b2);
}
for (i=0; i < 10; i++)
coefs[i] >>= 4;
}
|
['void ff_eval_coefs(int *coefs, const int *refl)\n{\n int buffer[10];\n int *b1 = buffer;\n int *b2 = coefs;\n int i, j;\n for (i=0; i < 10; i++) {\n b1[i] = refl[i] << 4;\n for (j=0; j < i; j++)\n b1[j] = ((refl[i] * b2[i-j-1]) >> 12) + b2[j];\n FFSWAP(int *, b1, b2);\n }\n for (i=0; i < 10; i++)\n coefs[i] >>= 4;\n}']
|
1,699
| 0
|
https://github.com/openssl/openssl/blob/f345b1f39d9b4e4c9ef07e7522e9b2a870c9ca09/crypto/bn/bn_lib.c/#L233
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,700
| 0
|
https://github.com/openssl/openssl/blob/6d4c65835de4ed9aa0a37e3234055d075fe0bc58/crypto/bn/bn_ctx.c/#L355
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)\n\t{\n\tBN_CTX *ctx;\n\tBIGNUM k,kq,*K,*kinv=NULL,*r=NULL;\n\tint ret=0;\n\tif (!dsa->p || !dsa->q || !dsa->g)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);\n\t\treturn 0;\n\t\t}\n\tBN_init(&k);\n\tBN_init(&kq);\n\tif (ctx_in == NULL)\n\t\t{\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tctx=ctx_in;\n\tif ((r=BN_new()) == NULL) goto err;\n\tdo\n\t\tif (!BN_rand_range(&k, dsa->q)) goto err;\n\twhile (BN_is_zero(&k));\n\tif ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t{\n\t\tBN_set_flags(&k, BN_FLG_CONSTTIME);\n\t\t}\n\tif (dsa->flags & DSA_FLAG_CACHE_MONT_P)\n\t\t{\n\t\tif (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n\t\t\t\t\t\tCRYPTO_LOCK_DSA,\n\t\t\t\t\t\tdsa->p, ctx))\n\t\t\tgoto err;\n\t\t}\n\tif ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t{\n\t\tif (!BN_copy(&kq, &k)) goto err;\n\t\tif (!BN_add(&kq, &kq, dsa->q)) goto err;\n\t\tif (BN_num_bits(&kq) <= BN_num_bits(dsa->q))\n\t\t\t{\n\t\t\tif (!BN_add(&kq, &kq, dsa->q)) goto err;\n\t\t\t}\n\t\tK = &kq;\n\t\t}\n\telse\n\t\t{\n\t\tK = &k;\n\t\t}\n\tDSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx,\n\t\t\tdsa->method_mont_p);\n\tif (!BN_mod(r,r,dsa->q,ctx)) goto err;\n\tif ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;\n\tif (*kinvp != NULL) BN_clear_free(*kinvp);\n\t*kinvp=kinv;\n\tkinv=NULL;\n\tif (*rp != NULL) BN_clear_free(*rp);\n\t*rp=r;\n\tret=1;\nerr:\n\tif (!ret)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);\n\t\tif (r != NULL)\n\t\t\tBN_clear_free(r);\n\t\t}\n\tif (ctx_in == NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&k);\n\tBN_clear_free(&kq);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\treturn BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif (!d || !r || !val[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_nnmod(val[0],a,m,ctx))\n\t\t\tgoto err;\n\t\taa= val[0];\n\t\t}\n\telse\n\t\taa=a;\n\tif (BN_is_zero(aa))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val[i],val[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,bits,ret=0,window,wvalue;\n\tint top;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tint powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM tmp, am;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(OPENSSL_BN_ASM_MONT5)\n\tif (window==6 && bits<=1024) window=5;\n#endif\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*(top*numPowers +\n\t\t\t\t((2*top)>numPowers?(2*top):numPowers));\n#ifdef alloca\n\tif (powerbufLen < 3072)\n\t\tpowerbufFree = alloca(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n\telse\n#endif\n\tif ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n\tif (powerbufLen < 3072)\n\t\tpowerbufFree = NULL;\n#endif\n\ttmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0])*top*numPowers);\n\tam.d = tmp.d + top;\n\ttmp.top = am.top = 0;\n\ttmp.dmax = am.dmax = top;\n\ttmp.neg = am.neg = 0;\n\ttmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n \tif (!BN_to_montgomery(&tmp,BN_value_one(),mont,ctx))\tgoto err;\n#else\n\ttmp.d[0] = (0-m->d[0])&BN_MASK2;\n\tfor (i=1;i<top;i++)\n\t\ttmp.d[i] = (~m->d[i])&BN_MASK2;\n\ttmp.top = top;\n#endif\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(&am,a,m,ctx))\t\t\tgoto err;\n\t\tif (!BN_to_montgomery(&am,&am,mont,ctx))\tgoto err;\n\t\t}\n\telse\tif (!BN_to_montgomery(&am,a,mont,ctx))\t\tgoto err;\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window==5)\n\t{\n\tvoid bn_mul_mont_gather5(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *table,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num,int power);\n\tvoid bn_scatter5(const BN_ULONG *inp,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_gather5(BN_ULONG *out,size_t num,\n\t\t\tvoid *table,size_t power);\n\tBN_ULONG *np=mont->N.d, *n0=mont->n0;\n\tbn_scatter5(tmp.d,top,powerbuf,0);\n\tbn_scatter5(am.d,am.top,powerbuf,1);\n\tbn_mul_mont(tmp.d,am.d,am.d,np,n0,top);\n\tbn_scatter5(tmp.d,top,powerbuf,2);\n#if 0\n\tfor (i=3; i<32; i++)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n#else\n\tfor (i=4; i<32; i*=2)\n\t\t{\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n\tfor (i=3; i<8; i+=2)\n\t\t{\n\t\tint j;\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\tfor (j=2*i; j<32; j*=2)\n\t\t\t{\n\t\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\t\tbn_scatter5(tmp.d,top,powerbuf,j);\n\t\t\t}\n\t\t}\n\tfor (; i<16; i+=2)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_scatter5(tmp.d,top,powerbuf,2*i);\n\t\t}\n\tfor (; i<32; i+=2)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n#endif\n\tbits--;\n\tfor (wvalue=0, i=bits%5; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tbn_gather5(tmp.d,top,powerbuf,wvalue);\n\twhile (bits >= 0)\n\t\t{\n\t\tfor (wvalue=0, i=0; i<5; i++,bits--)\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_gather5(tmp.d,tmp.d,powerbuf,np,n0,top,wvalue);\n\t\t}\n\ttmp.top=top;\n\tbn_correct_top(&tmp);\n\t}\n else\n#endif\n\t{\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, numPowers)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(&tmp,&am,&am,mont,ctx))\tgoto err;\n\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2, numPowers)) goto err;\n\t\tfor (i=3; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(&tmp,&am,&tmp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n\tbits--;\n\tfor (wvalue=0, i=bits%window; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp,top,powerbuf,wvalue,numPowers)) goto err;\n \twhile (bits >= 0)\n \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,bits--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(&tmp,&tmp,&tmp,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(&tmp,&tmp,&am,mont,ctx)) goto err;\n \t\t}\n\t}\n\tif (!BN_from_montgomery(rr,&tmp,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tif (powerbufFree) OPENSSL_free(powerbufFree);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tBN_init(&tmod);\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *rv;\n\tint noinv;\n\trv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n\tif (noinv)\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\treturn rv;\n\t}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *pnoinv)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tif (pnoinv)\n\t\t*pnoinv = 0;\n\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (pnoinv)\n\t\t\t*pnoinv = 1;\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM local_A, local_B;\n\tBIGNUM *pA, *pB;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tint no_branch=0;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\tno_branch=1;\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (!no_branch && BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n\t\tgoto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (no_branch)\n\t\t{\n\t\tif (snum->top <= sdiv->top+1)\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\t\tsnum->top = sdiv->top + 2;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\t\tsnum->d[snum->top] = 0;\n\t\t\tsnum->top ++;\n\t\t\t}\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-no_branch;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (!no_branch)\n\t\t{\n\t\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t\t{\n\t\t\tbn_clear_top2max(&wnum);\n\t\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t\t*resp=1;\n\t\t\t}\n\t\telse\n\t\t\tres->top--;\n\t\t}\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tif (no_branch)\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.