Datasets:
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 | 0 | https://github.com/libav/libav/blob/54bc15d5ebfd07fd468743ba29f709ea19e840b9/libswscale/output.c/#L1339 | static void
yuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,
const int16_t **lumSrc, int lumFilterSize,
const int16_t *chrFilter, const int16_t **chrUSrc,
const int16_t **chrVSrc, int chrFilterSize,
const int16_t **alpSrc, uint8_t **dest,
int dstW, int y)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);
int i;
int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;
uint16_t **dest16 = (uint16_t**)dest;
int SH = 22 + 7 - desc->comp[0].depth_minus1;
for (i = 0; i < dstW; i++) {
int j;
int Y = 1 << 9;
int U = (1 << 9) - (128 << 19);
int V = (1 << 9) - (128 << 19);
int R, G, B, A;
for (j = 0; j < lumFilterSize; j++)
Y += lumSrc[j][i] * lumFilter[j];
for (j = 0; j < chrFilterSize; j++) {
U += chrUSrc[j][i] * chrFilter[j];
V += chrVSrc[j][i] * chrFilter[j];
}
Y >>= 10;
U >>= 10;
V >>= 10;
if (hasAlpha) {
A = 1 << 18;
for (j = 0; j < lumFilterSize; j++)
A += alpSrc[j][i] * lumFilter[j];
A >>= 19;
if (A & 0x100)
A = av_clip_uint8(A);
}
Y -= c->yuv2rgb_y_offset;
Y *= c->yuv2rgb_y_coeff;
Y += 1 << 21;
R = Y + V * c->yuv2rgb_v2r_coeff;
G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
B = Y + U * c->yuv2rgb_u2b_coeff;
if ((R | G | B) & 0xC0000000) {
R = av_clip_uintp2(R, 30);
G = av_clip_uintp2(G, 30);
B = av_clip_uintp2(B, 30);
}
if (SH != 22) {
dest16[0][i] = G >> SH;
dest16[1][i] = B >> SH;
dest16[2][i] = R >> SH;
if (hasAlpha)
dest16[3][i] = A;
} else {
dest[0][i] = G >> 22;
dest[1][i] = B >> 22;
dest[2][i] = R >> 22;
if (hasAlpha)
dest[3][i] = A;
}
}
if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {
for (i = 0; i < dstW; i++) {
dest16[0][i] = av_bswap16(dest16[0][i]);
dest16[1][i] = av_bswap16(dest16[1][i]);
dest16[2][i] = av_bswap16(dest16[2][i]);
if (hasAlpha)
dest16[3][i] = av_bswap16(dest16[3][i]);
}
}
} | ['static void\nyuv2gbrp_full_X_c(SwsContext *c, const int16_t *lumFilter,\n const int16_t **lumSrc, int lumFilterSize,\n const int16_t *chrFilter, const int16_t **chrUSrc,\n const int16_t **chrVSrc, int chrFilterSize,\n const int16_t **alpSrc, uint8_t **dest,\n int dstW, int y)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->dstFormat);\n int i;\n int hasAlpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) && alpSrc;\n uint16_t **dest16 = (uint16_t**)dest;\n int SH = 22 + 7 - desc->comp[0].depth_minus1;\n for (i = 0; i < dstW; i++) {\n int j;\n int Y = 1 << 9;\n int U = (1 << 9) - (128 << 19);\n int V = (1 << 9) - (128 << 19);\n int R, G, B, A;\n for (j = 0; j < lumFilterSize; j++)\n Y += lumSrc[j][i] * lumFilter[j];\n for (j = 0; j < chrFilterSize; j++) {\n U += chrUSrc[j][i] * chrFilter[j];\n V += chrVSrc[j][i] * chrFilter[j];\n }\n Y >>= 10;\n U >>= 10;\n V >>= 10;\n if (hasAlpha) {\n A = 1 << 18;\n for (j = 0; j < lumFilterSize; j++)\n A += alpSrc[j][i] * lumFilter[j];\n A >>= 19;\n if (A & 0x100)\n A = av_clip_uint8(A);\n }\n Y -= c->yuv2rgb_y_offset;\n Y *= c->yuv2rgb_y_coeff;\n Y += 1 << 21;\n R = Y + V * c->yuv2rgb_v2r_coeff;\n G = Y + V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;\n B = Y + U * c->yuv2rgb_u2b_coeff;\n if ((R | G | B) & 0xC0000000) {\n R = av_clip_uintp2(R, 30);\n G = av_clip_uintp2(G, 30);\n B = av_clip_uintp2(B, 30);\n }\n if (SH != 22) {\n dest16[0][i] = G >> SH;\n dest16[1][i] = B >> SH;\n dest16[2][i] = R >> SH;\n if (hasAlpha)\n dest16[3][i] = A;\n } else {\n dest[0][i] = G >> 22;\n dest[1][i] = B >> 22;\n dest[2][i] = R >> 22;\n if (hasAlpha)\n dest[3][i] = A;\n }\n }\n if (SH != 22 && (!isBE(c->dstFormat)) != (!HAVE_BIGENDIAN)) {\n for (i = 0; i < dstW; i++) {\n dest16[0][i] = av_bswap16(dest16[0][i]);\n dest16[1][i] = av_bswap16(dest16[1][i]);\n dest16[2][i] = av_bswap16(dest16[2][i]);\n if (hasAlpha)\n dest16[3][i] = av_bswap16(dest16[3][i]);\n }\n }\n}'] |
2 | 0 | https://github.com/openssl/openssl/blob/04485c5bc0dc7f49940e6d91b27cdcc7b83a8ab5/crypto/bn/bn_ctx.c/#L355 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)\n\t{\n\tBN_CTX *new_ctx = NULL;\n\tBIGNUM *tmp0, *tmp1;\n\tsize_t pow2 = 0;\n\tBIGNUM **heap = NULL;\n\tsize_t i;\n\tint ret = 0;\n\tif (num == 0)\n\t\treturn 1;\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\treturn 0;\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp0 = BN_CTX_get(ctx);\n\ttmp1 = BN_CTX_get(ctx);\n\tif (tmp0 == NULL || tmp1 == NULL) goto err;\n\tpow2 = 1;\n\twhile (num > pow2)\n\t\tpow2 <<= 1;\n\tpow2 <<= 1;\n\theap = OPENSSL_malloc(pow2 * sizeof heap[0]);\n\tif (heap == NULL) goto err;\n\theap[0] = NULL;\n\tfor (i = pow2/2 - 1; i > 0; i--)\n\t\theap[i] = NULL;\n\tfor (i = 0; i < num; i++)\n\t\theap[pow2/2 + i] = &points[i]->Z;\n\tfor (i = pow2/2 + num; i < pow2; i++)\n\t\theap[i] = NULL;\n\tfor (i = pow2/2 - 1; i > 0; i--)\n\t\t{\n\t\theap[i] = BN_new();\n\t\tif (heap[i] == NULL) goto err;\n\t\tif (heap[2*i] != NULL)\n\t\t\t{\n\t\t\tif ((heap[2*i + 1] == NULL) || BN_is_zero(heap[2*i + 1]))\n\t\t\t\t{\n\t\t\t\tif (!BN_copy(heap[i], heap[2*i])) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_zero(heap[2*i]))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(heap[i], heap[2*i + 1])) 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 (!group->meth->field_mul(group, heap[i],\n\t\t\t\t\t\theap[2*i], heap[2*i + 1], ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (!BN_is_zero(heap[1]))\n\t\t{\n\t\tif (!BN_mod_inverse(heap[1], heap[1], &group->field, ctx))\n\t\t\t{\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE, ERR_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (group->meth->field_encode != 0)\n\t\t{\n\t\tif (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;\n\t\tif (!group->meth->field_encode(group, heap[1], heap[1], ctx)) goto err;\n\t\t}\n\tfor (i = 2; i < pow2/2 + num; i += 2)\n\t\t{\n\t\tif ((heap[i + 1] != NULL) && !BN_is_zero(heap[i + 1]))\n\t\t\t{\n\t\t\tif (!group->meth->field_mul(group, tmp0, heap[i/2], heap[i + 1], ctx)) goto err;\n\t\t\tif (!group->meth->field_mul(group, tmp1, heap[i/2], heap[i], ctx)) goto err;\n\t\t\tif (!BN_copy(heap[i], tmp0)) goto err;\n\t\t\tif (!BN_copy(heap[i + 1], tmp1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_copy(heap[i], heap[i/2])) goto err;\n\t\t\t}\n\t\t}\n\tfor (i = 0; i < num; i++)\n\t\t{\n\t\tEC_POINT *p = points[i];\n\t\tif (!BN_is_zero(&p->Z))\n\t\t\t{\n\t\t\tif (!group->meth->field_sqr(group, tmp1, &p->Z, ctx)) goto err;\n\t\t\tif (!group->meth->field_mul(group, &p->X, &p->X, tmp1, ctx)) goto err;\n\t\t\tif (!group->meth->field_mul(group, tmp1, tmp1, &p->Z, ctx)) goto err;\n\t\t\tif (!group->meth->field_mul(group, &p->Y, &p->Y, tmp1, ctx)) goto err;\n\t\t\tif (group->meth->field_set_to_one != 0)\n\t\t\t\t{\n\t\t\t\tif (!group->meth->field_set_to_one(group, &p->Z, ctx)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_one(&p->Z)) goto err;\n\t\t\t\t}\n\t\t\tp->Z_is_one = 1;\n\t\t\t}\n\t\t}\n\tret = 1;\n err:\n\tBN_CTX_end(ctx);\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\tif (heap != NULL)\n\t\t{\n\t\tfor (i = pow2/2 - 1; i > 0; i--)\n\t\t\t{\n\t\t\tif (heap[i] != NULL)\n\t\t\t\tBN_clear_free(heap[i]);\n\t\t\t}\n\t\tOPENSSL_free(heap);\n\t\t}\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 *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}'] |
3 | 0 | https://github.com/openssl/openssl/blob/fff684168c7923aa85e6b4381d71d933396e32b0/crypto/rsa/rsa_sp800_56b_gen.c/#L125 | int rsa_fips186_4_gen_prob_primes(RSA *rsa, BIGNUM *p1, BIGNUM *p2,
BIGNUM *Xpout, const BIGNUM *Xp,
const BIGNUM *Xp1, const BIGNUM *Xp2,
BIGNUM *q1, BIGNUM *q2, BIGNUM *Xqout,
const BIGNUM *Xq, const BIGNUM *Xq1,
const BIGNUM *Xq2, int nbits,
const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)
{
int ret = 0, ok;
BIGNUM *Xpo = NULL, *Xqo = NULL, *tmp = NULL;
if (nbits < RSA_FIPS1864_MIN_KEYGEN_KEYSIZE) {
RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_INVALID_KEY_LENGTH);
return 0;
}
if (!rsa_check_public_exponent(e)) {
RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES,
RSA_R_PUB_EXPONENT_OUT_OF_RANGE);
goto err;
}
BN_CTX_start(ctx);
tmp = BN_CTX_get(ctx);
Xpo = (Xpout != NULL) ? Xpout : BN_CTX_get(ctx);
Xqo = (Xqout != NULL) ? Xqout : BN_CTX_get(ctx);
if (tmp == NULL || Xpo == NULL || Xqo == NULL)
goto err;
if (rsa->p == NULL)
rsa->p = BN_secure_new();
if (rsa->q == NULL)
rsa->q = BN_secure_new();
if (rsa->p == NULL || rsa->q == NULL)
goto err;
if (!bn_rsa_fips186_4_gen_prob_primes(rsa->p, Xpo, p1, p2, Xp, Xp1, Xp2,
nbits, e, ctx, cb))
goto err;
for(;;) {
if (!bn_rsa_fips186_4_gen_prob_primes(rsa->q, Xqo, q1, q2, Xq, Xq1,
Xq2, nbits, e, ctx, cb))
goto err;
ok = rsa_check_pminusq_diff(tmp, Xpo, Xqo, nbits);
if (ok < 0)
goto err;
if (ok == 0)
continue;
ok = rsa_check_pminusq_diff(tmp, rsa->p, rsa->q, nbits);
if (ok < 0)
goto err;
if (ok == 0)
continue;
break;
}
ret = 1;
err:
if (Xpo != Xpout)
BN_clear(Xpo);
if (Xqo != Xqout)
BN_clear(Xqo);
BN_clear(tmp);
BN_CTX_end(ctx);
return ret;
} | ['int rsa_fips186_4_gen_prob_primes(RSA *rsa, BIGNUM *p1, BIGNUM *p2,\n BIGNUM *Xpout, const BIGNUM *Xp,\n const BIGNUM *Xp1, const BIGNUM *Xp2,\n BIGNUM *q1, BIGNUM *q2, BIGNUM *Xqout,\n const BIGNUM *Xq, const BIGNUM *Xq1,\n const BIGNUM *Xq2, int nbits,\n const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n int ret = 0, ok;\n BIGNUM *Xpo = NULL, *Xqo = NULL, *tmp = NULL;\n if (nbits < RSA_FIPS1864_MIN_KEYGEN_KEYSIZE) {\n RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES, RSA_R_INVALID_KEY_LENGTH);\n return 0;\n }\n if (!rsa_check_public_exponent(e)) {\n RSAerr(RSA_F_RSA_FIPS186_4_GEN_PROB_PRIMES,\n RSA_R_PUB_EXPONENT_OUT_OF_RANGE);\n goto err;\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n Xpo = (Xpout != NULL) ? Xpout : BN_CTX_get(ctx);\n Xqo = (Xqout != NULL) ? Xqout : BN_CTX_get(ctx);\n if (tmp == NULL || Xpo == NULL || Xqo == NULL)\n goto err;\n if (rsa->p == NULL)\n rsa->p = BN_secure_new();\n if (rsa->q == NULL)\n rsa->q = BN_secure_new();\n if (rsa->p == NULL || rsa->q == NULL)\n goto err;\n if (!bn_rsa_fips186_4_gen_prob_primes(rsa->p, Xpo, p1, p2, Xp, Xp1, Xp2,\n nbits, e, ctx, cb))\n goto err;\n for(;;) {\n if (!bn_rsa_fips186_4_gen_prob_primes(rsa->q, Xqo, q1, q2, Xq, Xq1,\n Xq2, nbits, e, ctx, cb))\n goto err;\n ok = rsa_check_pminusq_diff(tmp, Xpo, Xqo, nbits);\n if (ok < 0)\n goto err;\n if (ok == 0)\n continue;\n ok = rsa_check_pminusq_diff(tmp, rsa->p, rsa->q, nbits);\n if (ok < 0)\n goto err;\n if (ok == 0)\n continue;\n break;\n }\n ret = 1;\nerr:\n if (Xpo != Xpout)\n BN_clear(Xpo);\n if (Xqo != Xqout)\n BN_clear(Xqo);\n BN_clear(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'int rsa_check_public_exponent(const BIGNUM *e)\n{\n int bitlen = BN_num_bits(e);\n return (BN_is_odd(e) && bitlen > 16 && bitlen < 257);\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_num_bits_word(BN_ULONG l)\n{\n BN_ULONG x, mask;\n int bits = (l != 0);\n#if BN_BITS2 > 32\n x = l >> 32;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 32 & mask;\n l ^= (x ^ l) & mask;\n#endif\n x = l >> 16;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 16 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 8;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 8 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 4;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 4 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 2;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 2 & mask;\n l ^= (x ^ l) & mask;\n x = l >> 1;\n mask = (0 - x) & BN_MASK2;\n mask = (0 - (mask >> (BN_BITS2 - 1)));\n bits += 1 & mask;\n return bits;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'void BN_clear(BIGNUM *a)\n{\n bn_check_top(a);\n if (a->d != NULL)\n OPENSSL_cleanse(a->d, sizeof(*a->d) * a->dmax);\n a->neg = 0;\n a->top = 0;\n a->flags &= ~BN_FLG_FIXED_TOP;\n}'] |
4 | 0 | https://github.com/openssl/openssl/blob/d91f45688c2d0bfcc5b3b57fb20cc80b010eef0b/ssl/s3_enc.c/#L518 | int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,
size_t len, size_t *secret_size)
{
static const unsigned char *salt[3] = {
#ifndef CHARSET_EBCDIC
(const unsigned char *)"A",
(const unsigned char *)"BB",
(const unsigned char *)"CCC",
#else
(const unsigned char *)"\x41",
(const unsigned char *)"\x42\x42",
(const unsigned char *)"\x43\x43\x43",
#endif
};
unsigned char buf[EVP_MAX_MD_SIZE];
EVP_MD_CTX *ctx = EVP_MD_CTX_new();
int i, ret = 1;
unsigned int n;
size_t ret_secret_size = 0;
if (ctx == NULL) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,
ERR_R_MALLOC_FAILURE);
return 0;
}
for (i = 0; i < 3; i++) {
if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0
|| EVP_DigestUpdate(ctx, salt[i],
strlen((const char *)salt[i])) <= 0
|| EVP_DigestUpdate(ctx, p, len) <= 0
|| EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),
SSL3_RANDOM_SIZE) <= 0
|| EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),
SSL3_RANDOM_SIZE) <= 0
|| EVP_DigestFinal_ex(ctx, buf, &n) <= 0
|| EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0
|| EVP_DigestUpdate(ctx, p, len) <= 0
|| EVP_DigestUpdate(ctx, buf, n) <= 0
|| EVP_DigestFinal_ex(ctx, out, &n) <= 0) {
SSLfatal(s, SSL_AD_INTERNAL_ERROR,
SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);
ret = 0;
break;
}
out += n;
ret_secret_size += n;
}
EVP_MD_CTX_free(ctx);
OPENSSL_cleanse(buf, sizeof(buf));
if (ret)
*secret_size = ret_secret_size;
return ret;
} | ['int ssl3_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p,\n size_t len, size_t *secret_size)\n{\n static const unsigned char *salt[3] = {\n#ifndef CHARSET_EBCDIC\n (const unsigned char *)"A",\n (const unsigned char *)"BB",\n (const unsigned char *)"CCC",\n#else\n (const unsigned char *)"\\x41",\n (const unsigned char *)"\\x42\\x42",\n (const unsigned char *)"\\x43\\x43\\x43",\n#endif\n };\n unsigned char buf[EVP_MAX_MD_SIZE];\n EVP_MD_CTX *ctx = EVP_MD_CTX_new();\n int i, ret = 1;\n unsigned int n;\n size_t ret_secret_size = 0;\n if (ctx == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_GENERATE_MASTER_SECRET,\n ERR_R_MALLOC_FAILURE);\n return 0;\n }\n for (i = 0; i < 3; i++) {\n if (EVP_DigestInit_ex(ctx, s->ctx->sha1, NULL) <= 0\n || EVP_DigestUpdate(ctx, salt[i],\n strlen((const char *)salt[i])) <= 0\n || EVP_DigestUpdate(ctx, p, len) <= 0\n || EVP_DigestUpdate(ctx, &(s->s3->client_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_DigestUpdate(ctx, &(s->s3->server_random[0]),\n SSL3_RANDOM_SIZE) <= 0\n || EVP_DigestFinal_ex(ctx, buf, &n) <= 0\n || EVP_DigestInit_ex(ctx, s->ctx->md5, NULL) <= 0\n || EVP_DigestUpdate(ctx, p, len) <= 0\n || EVP_DigestUpdate(ctx, buf, n) <= 0\n || EVP_DigestFinal_ex(ctx, out, &n) <= 0) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_SSL3_GENERATE_MASTER_SECRET, ERR_R_INTERNAL_ERROR);\n ret = 0;\n break;\n }\n out += n;\n ret_secret_size += n;\n }\n EVP_MD_CTX_free(ctx);\n OPENSSL_cleanse(buf, sizeof(buf));\n if (ret)\n *secret_size = ret_secret_size;\n return ret;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n 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}', 'void ossl_statem_fatal(SSL *s, int al, int func, int reason, const char *file,\n int line)\n{\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}'] |
5 | 0 | https://github.com/openssl/openssl/blob/c21869fb07ea02ffd46e817caeb47d85a85ee8ef/crypto/pem/pvkfmt.c/#L760 | static EVP_PKEY *do_PVK_body(const unsigned char **in,
unsigned int saltlen, unsigned int keylen,
pem_password_cb *cb, void *u)
{
EVP_PKEY *ret = NULL;
const unsigned char *p = *in;
unsigned int magic;
unsigned char *enctmp = NULL, *q;
EVP_CIPHER_CTX cctx;
EVP_CIPHER_CTX_init(&cctx);
if (saltlen)
{
char psbuf[PEM_BUFSIZE];
unsigned char keybuf[20];
int enctmplen, inlen;
if (cb)
inlen=cb(psbuf,PEM_BUFSIZE,0,u);
else
inlen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
if (inlen <= 0)
{
PEMerr(PEM_F_DO_PVK_BODY,PEM_R_BAD_PASSWORD_READ);
return NULL;
}
enctmp = OPENSSL_malloc(keylen + 8);
if (!enctmp)
{
PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE);
return NULL;
}
if (!derive_pvk_key(keybuf, p, saltlen,
(unsigned char *)psbuf, inlen))
return NULL;
p += saltlen;
memcpy(enctmp, p, 8);
p += 8;
inlen = keylen - 8;
q = enctmp + 8;
if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))
goto err;
if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))
goto err;
if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen))
goto err;
magic = read_ledword((const unsigned char **)&q);
if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC)
{
q = enctmp + 8;
memset(keybuf + 5, 0, 11);
if (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf,
NULL))
goto err;
OPENSSL_cleanse(keybuf, 20);
if (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))
goto err;
if (!EVP_DecryptFinal_ex(&cctx, q + enctmplen,
&enctmplen))
goto err;
magic = read_ledword((const unsigned char **)&q);
if (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC)
{
PEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_DECRYPT);
goto err;
}
}
else
OPENSSL_cleanse(keybuf, 20);
p = enctmp;
}
ret = b2i_PrivateKey(&p, keylen);
err:
EVP_CIPHER_CTX_cleanup(&cctx);
if (enctmp && saltlen)
OPENSSL_free(enctmp);
return ret;
} | ['EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)\n\t{\n\tunsigned char pvk_hdr[24], *buf = NULL;\n\tconst unsigned char *p;\n\tint buflen;\n\tEVP_PKEY *ret = NULL;\n\tunsigned int saltlen, keylen;\n\tif (BIO_read(in, pvk_hdr, 24) != 24)\n\t\t{\n\t\tPEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT);\n\t\treturn NULL;\n\t\t}\n\tp = pvk_hdr;\n\tif (!do_PVK_header(&p, 24, 0, &saltlen, &keylen))\n\t\treturn 0;\n\tbuflen = (int) keylen + saltlen;\n\tbuf = OPENSSL_malloc(buflen);\n\tif (!buf)\n\t\t{\n\t\tPEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE);\n\t\treturn 0;\n\t\t}\n\tp = buf;\n\tif (BIO_read(in, buf, buflen) != buflen)\n\t\t{\n\t\tPEMerr(PEM_F_B2I_PVK_BIO, PEM_R_PVK_DATA_TOO_SHORT);\n\t\tgoto err;\n\t\t}\n\tret = do_PVK_body(&p, saltlen, keylen, cb, u);\n\terr:\n\tif (buf)\n\t\t{\n\t\tOPENSSL_cleanse(buf, buflen);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn ret;\n\t}', 'static int do_PVK_header(const unsigned char **in, unsigned int length,\n\t\tint skip_magic,\n\t \tunsigned int *psaltlen, unsigned int *pkeylen)\n\t{\n\tconst unsigned char *p = *in;\n\tunsigned int pvk_magic, keytype, is_encrypted;\n\tif (skip_magic)\n\t\t{\n\t\tif (length < 20)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);\n\t\t\treturn 0;\n\t\t\t}\n\t\tlength -= 20;\n\t\t}\n\telse\n\t\t{\n\t\tif (length < 24)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);\n\t\t\treturn 0;\n\t\t\t}\n\t\tlength -= 24;\n\t\tpvk_magic = read_ledword(&p);\n\t\tif (pvk_magic != MS_PVKMAGIC)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER);\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\tp += 4;\n\tkeytype = read_ledword(&p);\n\tis_encrypted = read_ledword(&p);\n\t*psaltlen = read_ledword(&p);\n\t*pkeylen = read_ledword(&p);\n\tif (is_encrypted && !*psaltlen)\n\t\t{\n\t\tPEMerr(PEM_F_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER);\n\t\treturn 0;\n\t\t}\n\t*in = p;\n\treturn 1;\n\t}', 'static EVP_PKEY *do_PVK_body(const unsigned char **in,\n\t\tunsigned int saltlen, unsigned int keylen,\n\t\tpem_password_cb *cb, void *u)\n\t{\n\tEVP_PKEY *ret = NULL;\n\tconst unsigned char *p = *in;\n\tunsigned int magic;\n\tunsigned char *enctmp = NULL, *q;\n\tEVP_CIPHER_CTX cctx;\n\tEVP_CIPHER_CTX_init(&cctx);\n\tif (saltlen)\n\t\t{\n\t\tchar psbuf[PEM_BUFSIZE];\n\t\tunsigned char keybuf[20];\n\t\tint enctmplen, inlen;\n\t\tif (cb)\n\t\t\tinlen=cb(psbuf,PEM_BUFSIZE,0,u);\n\t\telse\n\t\t\tinlen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);\n\t\tif (inlen <= 0)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_DO_PVK_BODY,PEM_R_BAD_PASSWORD_READ);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tenctmp = OPENSSL_malloc(keylen + 8);\n\t\tif (!enctmp)\n\t\t\t{\n\t\t\tPEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tif (!derive_pvk_key(keybuf, p, saltlen,\n\t\t\t (unsigned char *)psbuf, inlen))\n\t\t\treturn NULL;\n\t\tp += saltlen;\n\t\tmemcpy(enctmp, p, 8);\n\t\tp += 8;\n\t\tinlen = keylen - 8;\n\t\tq = enctmp + 8;\n\t\tif (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf, NULL))\n\t\t\tgoto err;\n\t\tif (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))\n\t\t\tgoto err;\n\t\tif (!EVP_DecryptFinal_ex(&cctx, q + enctmplen, &enctmplen))\n\t\t\tgoto err;\n\t\tmagic = read_ledword((const unsigned char **)&q);\n\t\tif (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC)\n\t\t\t{\n\t\t\tq = enctmp + 8;\n\t\t\tmemset(keybuf + 5, 0, 11);\n\t\t\tif (!EVP_DecryptInit_ex(&cctx, EVP_rc4(), NULL, keybuf,\n\t\t\t\t\t\t\t\tNULL))\n\t\t\t\tgoto err;\n\t\t\tOPENSSL_cleanse(keybuf, 20);\n\t\t\tif (!EVP_DecryptUpdate(&cctx, q, &enctmplen, p, inlen))\n\t\t\t\tgoto err;\n\t\t\tif (!EVP_DecryptFinal_ex(&cctx, q + enctmplen,\n\t\t\t\t\t\t\t\t&enctmplen))\n\t\t\t\tgoto err;\n\t\t\tmagic = read_ledword((const unsigned char **)&q);\n\t\t\tif (magic != MS_RSA2MAGIC && magic != MS_DSS2MAGIC)\n\t\t\t\t{\n\t\t\t\tPEMerr(PEM_F_DO_PVK_BODY, PEM_R_BAD_DECRYPT);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\tOPENSSL_cleanse(keybuf, 20);\n\t\tp = enctmp;\n\t\t}\n\tret = b2i_PrivateKey(&p, keylen);\n\terr:\n\tEVP_CIPHER_CTX_cleanup(&cctx);\n\tif (enctmp && saltlen)\n\t\tOPENSSL_free(enctmp);\n\treturn ret;\n\t}'] |
6 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L359 | static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){
LOAD_LEFT_EDGE
LOAD_DOWN_LEFT_EDGE
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;
src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;
src[2+0*stride]=
src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;
src[3+0*stride]=
src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;
src[2+1*stride]=
src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;
src[3+1*stride]=
src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;
src[3+2*stride]=
src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;
src[0+3*stride]=
src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;
src[2+3*stride]=(l4 + l5 + 1)>>1;
src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;
} | ['static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_LEFT_EDGE\n LOAD_DOWN_LEFT_EDGE\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;\n src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;\n src[2+0*stride]=\n src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;\n src[3+0*stride]=\n src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;\n src[2+1*stride]=\n src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;\n src[3+1*stride]=\n src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;\n src[3+2*stride]=\n src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;\n src[0+3*stride]=\n src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;\n src[2+3*stride]=(l4 + l5 + 1)>>1;\n src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;\n}'] |
7 | 0 | https://github.com/libav/libav/blob/8d44cd2cd82e27e6b051fe0606dece3b0bec0bcd/libavformat/spdifenc.c/#L352 | static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
{
IEC61937Context *ctx = s->priv_data;
AACADTSHeaderInfo hdr;
GetBitContext gbc;
int ret;
init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
ret = ff_aac_parse_header(&gbc, &hdr);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
return AVERROR_INVALIDDATA;
}
ctx->pkt_offset = hdr.samples << 2;
switch (hdr.num_aac_frames) {
case 1:
ctx->data_type = IEC61937_MPEG2_AAC;
break;
case 2:
ctx->data_type = IEC61937_MPEG2_AAC_LSF_2048;
break;
case 4:
ctx->data_type = IEC61937_MPEG2_AAC_LSF_4096;
break;
default:
av_log(s, AV_LOG_ERROR, "%i samples in AAC frame not supported\n",
hdr.samples);
return AVERROR(EINVAL);
}
return 0;
} | ['static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)\n{\n IEC61937Context *ctx = s->priv_data;\n AACADTSHeaderInfo hdr;\n GetBitContext gbc;\n int ret;\n init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);\n ret = ff_aac_parse_header(&gbc, &hdr);\n if (ret < 0) {\n av_log(s, AV_LOG_ERROR, "Wrong AAC file format\\n");\n return AVERROR_INVALIDDATA;\n }\n ctx->pkt_offset = hdr.samples << 2;\n switch (hdr.num_aac_frames) {\n case 1:\n ctx->data_type = IEC61937_MPEG2_AAC;\n break;\n case 2:\n ctx->data_type = IEC61937_MPEG2_AAC_LSF_2048;\n break;\n case 4:\n ctx->data_type = IEC61937_MPEG2_AAC_LSF_4096;\n break;\n default:\n av_log(s, AV_LOG_ERROR, "%i samples in AAC frame not supported\\n",\n hdr.samples);\n return AVERROR(EINVAL);\n }\n return 0;\n}', 'static inline void init_get_bits(GetBitContext *s,\n const uint8_t *buffer, int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n s->buffer_end = buffer + buffer_size;\n#ifdef ALT_BITSTREAM_READER\n s->index = 0;\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3);\n s->bit_count = 32 + 8*((intptr_t)buffer & 3);\n skip_bits_long(s, 0);\n#endif\n}', 'int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)\n{\n int size, rdb, ch, sr;\n int aot, crc_abs;\n if(get_bits(gbc, 12) != 0xfff)\n return AAC_AC3_PARSE_ERROR_SYNC;\n skip_bits1(gbc);\n skip_bits(gbc, 2);\n crc_abs = get_bits1(gbc);\n aot = get_bits(gbc, 2);\n sr = get_bits(gbc, 4);\n if(!ff_mpeg4audio_sample_rates[sr])\n return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;\n skip_bits1(gbc);\n ch = get_bits(gbc, 3);\n skip_bits1(gbc);\n skip_bits1(gbc);\n skip_bits1(gbc);\n skip_bits1(gbc);\n size = get_bits(gbc, 13);\n if(size < AAC_ADTS_HEADER_SIZE)\n return AAC_AC3_PARSE_ERROR_FRAME_SIZE;\n skip_bits(gbc, 11);\n rdb = get_bits(gbc, 2);\n hdr->object_type = aot + 1;\n hdr->chan_config = ch;\n hdr->crc_absent = crc_abs;\n hdr->num_aac_frames = rdb + 1;\n hdr->sampling_index = sr;\n hdr->sample_rate = ff_mpeg4audio_sample_rates[sr];\n hdr->samples = (rdb + 1) * 1024;\n hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples;\n return size;\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 void skip_bits1(GetBitContext *s){\n skip_bits(s, 1);\n}', 'static inline void skip_bits(GetBitContext *s, int n){\n OPEN_READER(re, s);\n UPDATE_CACHE(re, s);\n LAST_SKIP_BITS(re, s, n);\n CLOSE_READER(re, s);\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef ALT_BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n index++;\n s->index = index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}'] |
8 | 1 | https://github.com/libav/libav/blob/63e8d9760f23a4edf81e9ae58c4f6d3baa6ff4dd/libavcodec/mpegaudiodec.c/#L681 | static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
int *dither_state, OUT_INT *samples, int incr)
{
register const MPA_INT *w, *w2, *p;
int j;
OUT_INT *samples2;
#if CONFIG_FLOAT
float sum, sum2;
#elif FRAC_BITS <= 15
int sum, sum2;
#else
int64_t sum, sum2;
#endif
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
} | ['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n int j;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,\n int *dither_state, OUT_INT *samples, int incr)\n{\n register const MPA_INT *w, *w2, *p;\n int j;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n}'] |
9 | 0 | https://github.com/libav/libav/blob/a92be9b856bd11b081041c43c25d442028fe9a63/libavcodec/smacker.c/#L610 | static int smka_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame_ptr, AVPacket *avpkt)
{
SmackerAudioContext *s = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
GetBitContext gb;
HuffContext h[4] = { { 0 } };
VLC vlc[4] = { { 0 } };
int16_t *samples;
uint8_t *samples8;
int val;
int i, res, ret;
int unp_size;
int bits, stereo;
int pred[2] = {0, 0};
if (buf_size <= 4) {
av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
return AVERROR(EINVAL);
}
unp_size = AV_RL32(buf);
init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
if(!get_bits1(&gb)){
av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
*got_frame_ptr = 0;
return 1;
}
stereo = get_bits1(&gb);
bits = get_bits1(&gb);
if (stereo ^ (avctx->channels != 1)) {
av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
return AVERROR(EINVAL);
}
if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {
av_log(avctx, AV_LOG_ERROR, "sample format mismatch\n");
return AVERROR(EINVAL);
}
s->frame.nb_samples = unp_size / (avctx->channels * (bits + 1));
if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
samples = (int16_t *)s->frame.data[0];
samples8 = s->frame.data[0];
for(i = 0; i < (1 << (bits + stereo)); i++) {
h[i].length = 256;
h[i].maxlength = 0;
h[i].current = 0;
h[i].bits = av_mallocz(256 * 4);
h[i].lengths = av_mallocz(256 * sizeof(int));
h[i].values = av_mallocz(256 * sizeof(int));
skip_bits1(&gb);
smacker_decode_tree(&gb, &h[i], 0, 0);
skip_bits1(&gb);
if(h[i].current > 1) {
res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
h[i].lengths, sizeof(int), sizeof(int),
h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
if(res < 0) {
av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
return -1;
}
}
}
if(bits) {
for(i = stereo; i >= 0; i--)
pred[i] = av_bswap16(get_bits(&gb, 16));
for(i = 0; i <= stereo; i++)
*samples++ = pred[i];
for(; i < unp_size / 2; i++) {
if(i & stereo) {
if(vlc[2].table)
res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
else
res = 0;
val = h[2].values[res];
if(vlc[3].table)
res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
else
res = 0;
val |= h[3].values[res] << 8;
pred[1] += sign_extend(val, 16);
*samples++ = av_clip_int16(pred[1]);
} else {
if(vlc[0].table)
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
else
res = 0;
val = h[0].values[res];
if(vlc[1].table)
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
else
res = 0;
val |= h[1].values[res] << 8;
pred[0] += sign_extend(val, 16);
*samples++ = av_clip_int16(pred[0]);
}
}
} else {
for(i = stereo; i >= 0; i--)
pred[i] = get_bits(&gb, 8);
for(i = 0; i <= stereo; i++)
*samples8++ = pred[i];
for(; i < unp_size; i++) {
if(i & stereo){
if(vlc[1].table)
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
else
res = 0;
pred[1] += sign_extend(h[1].values[res], 8);
*samples8++ = av_clip_uint8(pred[1]);
} else {
if(vlc[0].table)
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
else
res = 0;
pred[0] += sign_extend(h[0].values[res], 8);
*samples8++ = av_clip_uint8(pred[0]);
}
}
}
for(i = 0; i < 4; i++) {
if(vlc[i].table)
ff_free_vlc(&vlc[i]);
av_free(h[i].bits);
av_free(h[i].lengths);
av_free(h[i].values);
}
*got_frame_ptr = 1;
*(AVFrame *)data = s->frame;
return buf_size;
} | ['static int smka_decode_frame(AVCodecContext *avctx, void *data,\n int *got_frame_ptr, AVPacket *avpkt)\n{\n SmackerAudioContext *s = avctx->priv_data;\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n GetBitContext gb;\n HuffContext h[4] = { { 0 } };\n VLC vlc[4] = { { 0 } };\n int16_t *samples;\n uint8_t *samples8;\n int val;\n int i, res, ret;\n int unp_size;\n int bits, stereo;\n int pred[2] = {0, 0};\n if (buf_size <= 4) {\n av_log(avctx, AV_LOG_ERROR, "packet is too small\\n");\n return AVERROR(EINVAL);\n }\n unp_size = AV_RL32(buf);\n init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);\n if(!get_bits1(&gb)){\n av_log(avctx, AV_LOG_INFO, "Sound: no data\\n");\n *got_frame_ptr = 0;\n return 1;\n }\n stereo = get_bits1(&gb);\n bits = get_bits1(&gb);\n if (stereo ^ (avctx->channels != 1)) {\n av_log(avctx, AV_LOG_ERROR, "channels mismatch\\n");\n return AVERROR(EINVAL);\n }\n if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {\n av_log(avctx, AV_LOG_ERROR, "sample format mismatch\\n");\n return AVERROR(EINVAL);\n }\n s->frame.nb_samples = unp_size / (avctx->channels * (bits + 1));\n if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n samples = (int16_t *)s->frame.data[0];\n samples8 = s->frame.data[0];\n for(i = 0; i < (1 << (bits + stereo)); i++) {\n h[i].length = 256;\n h[i].maxlength = 0;\n h[i].current = 0;\n h[i].bits = av_mallocz(256 * 4);\n h[i].lengths = av_mallocz(256 * sizeof(int));\n h[i].values = av_mallocz(256 * sizeof(int));\n skip_bits1(&gb);\n smacker_decode_tree(&gb, &h[i], 0, 0);\n skip_bits1(&gb);\n if(h[i].current > 1) {\n res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,\n h[i].lengths, sizeof(int), sizeof(int),\n h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);\n if(res < 0) {\n av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\\n");\n return -1;\n }\n }\n }\n if(bits) {\n for(i = stereo; i >= 0; i--)\n pred[i] = av_bswap16(get_bits(&gb, 16));\n for(i = 0; i <= stereo; i++)\n *samples++ = pred[i];\n for(; i < unp_size / 2; i++) {\n if(i & stereo) {\n if(vlc[2].table)\n res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val = h[2].values[res];\n if(vlc[3].table)\n res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val |= h[3].values[res] << 8;\n pred[1] += sign_extend(val, 16);\n *samples++ = av_clip_int16(pred[1]);\n } else {\n if(vlc[0].table)\n res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val = h[0].values[res];\n if(vlc[1].table)\n res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);\n else\n res = 0;\n val |= h[1].values[res] << 8;\n pred[0] += sign_extend(val, 16);\n *samples++ = av_clip_int16(pred[0]);\n }\n }\n } else {\n for(i = stereo; i >= 0; i--)\n pred[i] = get_bits(&gb, 8);\n for(i = 0; i <= stereo; i++)\n *samples8++ = pred[i];\n for(; i < unp_size; i++) {\n if(i & stereo){\n if(vlc[1].table)\n res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);\n else\n res = 0;\n pred[1] += sign_extend(h[1].values[res], 8);\n *samples8++ = av_clip_uint8(pred[1]);\n } else {\n if(vlc[0].table)\n res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);\n else\n res = 0;\n pred[0] += sign_extend(h[0].values[res], 8);\n *samples8++ = av_clip_uint8(pred[0]);\n }\n }\n }\n for(i = 0; i < 4; i++) {\n if(vlc[i].table)\n ff_free_vlc(&vlc[i]);\n av_free(h[i].bits);\n av_free(h[i].lengths);\n av_free(h[i].values);\n }\n *got_frame_ptr = 1;\n *(AVFrame *)data = s->frame;\n return buf_size;\n}', 'static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size = (bit_size+7)>>3;\n if (buffer_size < 0 || bit_size < 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n }\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}'] |
10 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/test/exptest.c/#L177 | static int test_exp_mod_zero()
{
BIGNUM *a = NULL, *p = NULL, *m = NULL;
BIGNUM *r = NULL;
BN_ULONG one_word = 1;
BN_CTX *ctx = BN_CTX_new();
int ret = 1, failed = 0;
m = BN_new();
if (!m)
goto err;
BN_one(m);
a = BN_new();
if (!a)
goto err;
BN_one(a);
p = BN_new();
if (!p)
goto err;
BN_zero(p);
r = BN_new();
if (!r)
goto err;
if (!BN_rand(a, 1024, 0, 0))
goto err;
if (!BN_mod_exp(r, a, p, m, ctx))
goto err;
if (!a_is_zero_mod_one("BN_mod_exp", r, a))
failed = 1;
if (!BN_mod_exp_recp(r, a, p, m, ctx))
goto err;
if (!a_is_zero_mod_one("BN_mod_exp_recp", r, a))
failed = 1;
if (!BN_mod_exp_simple(r, a, p, m, ctx))
goto err;
if (!a_is_zero_mod_one("BN_mod_exp_simple", r, a))
failed = 1;
if (!BN_mod_exp_mont(r, a, p, m, ctx, NULL))
goto err;
if (!a_is_zero_mod_one("BN_mod_exp_mont", r, a))
failed = 1;
if (!BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)) {
goto err;
}
if (!a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a))
failed = 1;
if (!BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL))
goto err;
if (!BN_is_zero(r)) {
fprintf(stderr, "BN_mod_exp_mont_word failed:\n");
fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\n");
fprintf(stderr, "r = ");
BN_print_fp(stderr, r);
fprintf(stderr, "\n");
return 0;
}
ret = failed;
err:
BN_free(r);
BN_free(a);
BN_free(p);
BN_free(m);
BN_CTX_free(ctx);
return ret;
} | ['static int test_exp_mod_zero()\n{\n BIGNUM *a = NULL, *p = NULL, *m = NULL;\n BIGNUM *r = NULL;\n BN_ULONG one_word = 1;\n BN_CTX *ctx = BN_CTX_new();\n int ret = 1, failed = 0;\n m = BN_new();\n if (!m)\n goto err;\n BN_one(m);\n a = BN_new();\n if (!a)\n goto err;\n BN_one(a);\n p = BN_new();\n if (!p)\n goto err;\n BN_zero(p);\n r = BN_new();\n if (!r)\n goto err;\n if (!BN_rand(a, 1024, 0, 0))\n goto err;\n if (!BN_mod_exp(r, a, p, m, ctx))\n goto err;\n if (!a_is_zero_mod_one("BN_mod_exp", r, a))\n failed = 1;\n if (!BN_mod_exp_recp(r, a, p, m, ctx))\n goto err;\n if (!a_is_zero_mod_one("BN_mod_exp_recp", r, a))\n failed = 1;\n if (!BN_mod_exp_simple(r, a, p, m, ctx))\n goto err;\n if (!a_is_zero_mod_one("BN_mod_exp_simple", r, a))\n failed = 1;\n if (!BN_mod_exp_mont(r, a, p, m, ctx, NULL))\n goto err;\n if (!a_is_zero_mod_one("BN_mod_exp_mont", r, a))\n failed = 1;\n if (!BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)) {\n goto err;\n }\n if (!a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a))\n failed = 1;\n if (!BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL))\n goto err;\n if (!BN_is_zero(r)) {\n fprintf(stderr, "BN_mod_exp_mont_word failed:\\n");\n fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\\n");\n fprintf(stderr, "r = ");\n BN_print_fp(stderr, r);\n fprintf(stderr, "\\n");\n return 0;\n }\n ret = failed;\n err:\n BN_free(r);\n BN_free(a);\n BN_free(p);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'BN_CTX *BN_CTX_new(void)\n{\n BN_CTX *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n BN_POOL_init(&ret->pool);\n BN_STACK_init(&ret->stack);\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#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}', 'static void BN_POOL_init(BN_POOL *p)\n{\n p->head = p->current = p->tail = NULL;\n p->used = p->size = 0;\n}', 'static void BN_STACK_init(BN_STACK *st)\n{\n st->indexes = NULL;\n st->depth = st->size = 0;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\n return (ret);\n}', '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_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(0, rnd, bits, top, bottom);\n}', 'static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits < 0 || (bits == 1 && top > 0)) {\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n if (bits == 0) {\n BN_zero(rnd);\n return 1;\n }\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (pseudorand) {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n } else {\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n }\n if (pseudorand == 2) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\n}', 'void RAND_add(const void *buf, int num, double entropy)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth && meth->add)\n meth->add(buf, num, entropy);\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n if (!default_RAND_meth) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e = ENGINE_get_default_RAND();\n if (e) {\n default_RAND_meth = ENGINE_get_RAND(e);\n if (!default_RAND_meth) {\n ENGINE_finish(e);\n e = NULL;\n }\n }\n if (e)\n funct_ref = e;\n else\n#endif\n default_RAND_meth = RAND_OpenSSL();\n }\n return default_RAND_meth;\n}', 'ENGINE *ENGINE_get_default_RAND(void)\n{\n return engine_table_select(&rand_table, dummy_nid);\n}', 'ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)\n#else\nENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,\n int l)\n#endif\n{\n ENGINE *ret = NULL;\n ENGINE_PILE tmplate, *fnd = NULL;\n int initres, loop = 0;\n if (!(*table)) {\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "\n "registered!\\n", f, l, nid);\n#endif\n return NULL;\n }\n ERR_set_mark();\n CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n if (!int_table_check(table, 0))\n goto end;\n tmplate.nid = nid;\n fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);\n if (!fnd)\n goto end;\n if (fnd->funct && engine_unlocked_init(fnd->funct)) {\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n "ENGINE \'%s\' cached\\n", f, l, nid, fnd->funct->id);\n#endif\n ret = fnd->funct;\n goto end;\n }\n if (fnd->uptodate) {\n ret = fnd->funct;\n goto end;\n }\n trynext:\n ret = sk_ENGINE_value(fnd->sk, loop++);\n if (!ret) {\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "\n "registered implementations would initialise\\n", f, l, nid);\n#endif\n goto end;\n }\n if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))\n initres = engine_unlocked_init(ret);\n else\n initres = 0;\n if (initres) {\n if ((fnd->funct != ret) && engine_unlocked_init(ret)) {\n if (fnd->funct)\n engine_unlocked_finish(fnd->funct, 0);\n fnd->funct = ret;\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "\n "setting default to \'%s\'\\n", f, l, nid, ret->id);\n#endif\n }\n#ifdef ENGINE_TABLE_DEBUG\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n "newly initialised \'%s\'\\n", f, l, nid, ret->id);\n#endif\n goto end;\n }\n goto trynext;\n end:\n if (fnd)\n fnd->uptodate = 1;\n#ifdef ENGINE_TABLE_DEBUG\n if (ret)\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n "ENGINE \'%s\'\\n", f, l, nid, ret->id);\n else\n fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n "\'no matching ENGINE\'\\n", f, l, nid);\n#endif\n CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n ERR_pop_to_mark();\n return ret;\n}', 'RAND_METHOD *RAND_OpenSSL(void)\n{\n return (&rand_meth);\n}', 'int RAND_bytes(unsigned char *buf, int num)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth && meth->bytes)\n return meth->bytes(buf, num);\n return (-1);\n}', 'void CRYPTO_clear_free(void *str, size_t num)\n{\n if (str == NULL)\n return;\n if (num)\n OPENSSL_cleanse(str, num);\n CRYPTO_free(str);\n}', 'void CRYPTO_free(void *str)\n{\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0);\n free(str);\n CRYPTO_mem_debug_free(str, 1);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}', 'void BN_free(BIGNUM *a)\n{\n if (a == NULL)\n return;\n bn_check_top(a);\n if (!BN_get_flags(a, BN_FLG_STATIC_DATA))\n bn_free_d(a);\n if (a->flags & BN_FLG_MALLOCED)\n OPENSSL_free(a);\n else {\n#if OPENSSL_API_COMPAT < 0x00908000L\n a->flags |= BN_FLG_FREE;\n#endif\n a->d = NULL;\n }\n}', 'int BN_get_flags(const BIGNUM *b, int n)\n{\n return b->flags & n;\n}'] |
11 | 0 | https://github.com/libav/libav/blob/ab492ca2ab105aeb24d955f3f03756bdb3139ee1/libavcodec/mpeg12.c/#L198 | static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *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;
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;
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;
}
}
if (i > 63) {
av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
return -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, DCTELEM *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], TEX_VLC_BITS, 2, 0);\n if (level != 0) {\n i += run;\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)) - SHOW_SBITS(re, &s->gb, 1);\n SKIP_BITS(re, &s->gb, 1);\n } else {\n run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6);\n UPDATE_CACHE(re, &s->gb);\n level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8);\n if (level == -128) {\n level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8);\n } else if (level == 0) {\n level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8);\n }\n i += run;\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 if (i > 63) {\n av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\\n", s->mb_x, s->mb_y);\n return -1;\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}'] |
12 | 0 | https://github.com/openssl/openssl/blob/a21285b3636a8356f01027416b0cd43b016f58ca/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 dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,\n const EVP_MD *evpmd, const unsigned char *seed_in,\n size_t seed_len, int idx, unsigned char *seed_out,\n int *counter_ret, unsigned long *h_ret,\n BN_GENCB *cb)\n{\n int ok = -1;\n unsigned char *seed = NULL, *seed_tmp = NULL;\n unsigned char md[EVP_MAX_MD_SIZE];\n int mdsize;\n BIGNUM *r0, *W, *X, *c, *test;\n BIGNUM *g = NULL, *q = NULL, *p = NULL;\n BN_MONT_CTX *mont = NULL;\n int i, k, n = 0, m = 0, qsize = N >> 3;\n int counter = 0;\n int r = 0;\n BN_CTX *ctx = NULL;\n EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n unsigned int h = 2;\n if (mctx == NULL)\n goto err;\n if (evpmd == NULL) {\n if (N == 160)\n evpmd = EVP_sha1();\n else if (N == 224)\n evpmd = EVP_sha224();\n else\n evpmd = EVP_sha256();\n }\n mdsize = EVP_MD_size(evpmd);\n if (!ret->p || !ret->q || idx >= 0) {\n if (seed_len == 0)\n seed_len = mdsize;\n seed = OPENSSL_malloc(seed_len);\n if (seed_out)\n seed_tmp = seed_out;\n else\n seed_tmp = OPENSSL_malloc(seed_len);\n if (seed == NULL || seed_tmp == NULL)\n goto err;\n if (seed_in)\n memcpy(seed, seed_in, seed_len);\n }\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n r0 = BN_CTX_get(ctx);\n g = BN_CTX_get(ctx);\n W = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n c = BN_CTX_get(ctx);\n test = BN_CTX_get(ctx);\n if (test == NULL)\n goto err;\n if (ret->p && ret->q) {\n p = ret->p;\n q = ret->q;\n if (idx >= 0)\n memcpy(seed_tmp, seed, seed_len);\n goto g_only;\n } else {\n p = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n if (q == NULL)\n goto err;\n }\n if (!BN_lshift(test, BN_value_one(), L - 1))\n goto err;\n for (;;) {\n for (;;) {\n unsigned char *pmd;\n if (!BN_GENCB_call(cb, 0, m++))\n goto err;\n if (!seed_in) {\n if (RAND_bytes(seed, seed_len) <= 0)\n goto err;\n }\n if (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n goto err;\n if (mdsize > qsize)\n pmd = md + mdsize - qsize;\n else\n pmd = md;\n if (mdsize < qsize)\n memset(md + mdsize, 0, qsize - mdsize);\n pmd[0] |= 0x80;\n pmd[qsize - 1] |= 0x01;\n if (!BN_bin2bn(pmd, qsize, q))\n goto err;\n r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n seed_in ? 1 : 0, cb);\n if (r > 0)\n break;\n if (r != 0)\n goto err;\n if (seed_in) {\n ok = 0;\n DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_Q_NOT_PRIME);\n goto err;\n }\n }\n if (seed_out)\n memcpy(seed_out, seed, seed_len);\n if (!BN_GENCB_call(cb, 2, 0))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n counter = 0;\n n = (L - 1) / (mdsize << 3);\n for (;;) {\n if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))\n goto err;\n BN_zero(W);\n for (k = 0; k <= n; k++) {\n for (i = seed_len - 1; i >= 0; i--) {\n seed[i]++;\n if (seed[i] != 0)\n break;\n }\n if (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n goto err;\n if (!BN_bin2bn(md, mdsize, r0))\n goto err;\n if (!BN_lshift(r0, r0, (mdsize << 3) * k))\n goto err;\n if (!BN_add(W, W, r0))\n goto err;\n }\n if (!BN_mask_bits(W, L - 1))\n goto err;\n if (!BN_copy(X, W))\n goto err;\n if (!BN_add(X, X, test))\n goto err;\n if (!BN_lshift1(r0, q))\n goto err;\n if (!BN_mod(c, X, r0, ctx))\n goto err;\n if (!BN_sub(r0, c, BN_value_one()))\n goto err;\n if (!BN_sub(p, X, r0))\n goto err;\n if (BN_cmp(p, test) >= 0) {\n r = BN_is_prime_fasttest_ex(p, DSS_prime_checks, ctx, 1, cb);\n if (r > 0)\n goto end;\n if (r != 0)\n goto err;\n }\n counter++;\n if (counter >= (int)(4 * L))\n break;\n }\n if (seed_in) {\n ok = 0;\n DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_INVALID_PARAMETERS);\n goto err;\n }\n }\n end:\n if (!BN_GENCB_call(cb, 2, 1))\n goto err;\n g_only:\n if (!BN_sub(test, p, BN_value_one()))\n goto err;\n if (!BN_div(r0, NULL, test, q, ctx))\n goto err;\n if (idx < 0) {\n if (!BN_set_word(test, h))\n goto err;\n } else\n h = 1;\n if (!BN_MONT_CTX_set(mont, p, ctx))\n goto err;\n for (;;) {\n static const unsigned char ggen[4] = { 0x67, 0x67, 0x65, 0x6e };\n if (idx >= 0) {\n md[0] = idx & 0xff;\n md[1] = (h >> 8) & 0xff;\n md[2] = h & 0xff;\n if (!EVP_DigestInit_ex(mctx, evpmd, NULL))\n goto err;\n if (!EVP_DigestUpdate(mctx, seed_tmp, seed_len))\n goto err;\n if (!EVP_DigestUpdate(mctx, ggen, sizeof(ggen)))\n goto err;\n if (!EVP_DigestUpdate(mctx, md, 3))\n goto err;\n if (!EVP_DigestFinal_ex(mctx, md, NULL))\n goto err;\n if (!BN_bin2bn(md, mdsize, test))\n goto err;\n }\n if (!BN_mod_exp_mont(g, test, r0, p, ctx, mont))\n goto err;\n if (!BN_is_one(g))\n break;\n if (idx < 0 && !BN_add(test, test, BN_value_one()))\n goto err;\n h++;\n if (idx >= 0 && h > 0xffff)\n goto err;\n }\n if (!BN_GENCB_call(cb, 3, 1))\n goto err;\n ok = 1;\n err:\n if (ok == 1) {\n if (p != ret->p) {\n BN_free(ret->p);\n ret->p = BN_dup(p);\n }\n if (q != ret->q) {\n BN_free(ret->q);\n ret->q = BN_dup(q);\n }\n BN_free(ret->g);\n ret->g = BN_dup(g);\n if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {\n ok = -1;\n goto err;\n }\n if (counter_ret != NULL)\n *counter_ret = counter;\n if (h_ret != NULL)\n *h_ret = h;\n }\n OPENSSL_free(seed);\n if (seed_out != seed_tmp)\n OPENSSL_free(seed_tmp);\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n BN_MONT_CTX_free(mont);\n EVP_MD_CTX_free(mctx);\n return ok;\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}', '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_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}'] |
13 | 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 field_tests_default(int n)\n{\n BN_CTX *ctx = NULL;\n EC_GROUP *group = NULL;\n int nid = curves[n].nid;\n int ret = 0;\n TEST_info("Testing curve %s\\n", OBJ_nid2sn(nid));\n if (!TEST_ptr(group = EC_GROUP_new_by_curve_name(nid))\n || !TEST_ptr(ctx = BN_CTX_new())\n || !group_field_tests(group, ctx))\n goto err;\n ret = 1;\n err:\n if (group != NULL)\n EC_GROUP_free(group);\n if (ctx != NULL)\n BN_CTX_free(ctx);\n return ret;\n}', 'static int group_field_tests(const EC_GROUP *group, BN_CTX *ctx)\n{\n BIGNUM *a = NULL, *b = NULL, *c = NULL;\n int ret = 0;\n if (group->meth->field_inv == NULL || group->meth->field_mul == NULL)\n return 1;\n BN_CTX_start(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (!TEST_ptr(c = BN_CTX_get(ctx))\n || !TEST_true(group->meth->field_inv(group, b, BN_value_one(), ctx))\n || !TEST_true(BN_is_one(b))\n || !TEST_true(BN_pseudo_rand(a, BN_num_bits(group->field) - 1,\n BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n || !TEST_true(group->meth->field_inv(group, b, a, ctx))\n || (group->meth->field_encode &&\n !TEST_true(group->meth->field_encode(group, a, a, ctx)))\n || (group->meth->field_encode &&\n !TEST_true(group->meth->field_encode(group, b, b, ctx)))\n || !TEST_true(group->meth->field_mul(group, c, a, b, ctx))\n || (group->meth->field_decode &&\n !TEST_true(group->meth->field_decode(group, c, c, ctx)))\n || !TEST_true(BN_is_one(c)))\n goto err;\n BN_zero(a);\n if (!TEST_false(group->meth->field_inv(group, b, a, ctx))\n || !TEST_true(ERR_GET_LIB(ERR_peek_last_error()) == ERR_LIB_EC)\n || !TEST_true(ERR_GET_REASON(ERR_peek_last_error()) ==\n EC_R_CANNOT_INVERT)\n || !TEST_false(group->meth->field_inv(group, b, group->field, ctx))\n || !TEST_true(ERR_GET_LIB(ERR_peek_last_error()) == ERR_LIB_EC)\n || !TEST_true(ERR_GET_REASON(ERR_peek_last_error()) ==\n EC_R_CANNOT_INVERT))\n goto err;\n ERR_clear_error();\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', '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}'] |
14 | 0 | https://github.com/nginx/nginx/blob/e5b2d3c6b2a132bbbbac0249566f0da7ff12bc39/src/http/ngx_http_core_module.c/#L2169 | ngx_int_t
ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_str_t *uri, ngx_str_t *args)
{
ngx_http_core_srv_conf_t *cscf;
r->uri_changes--;
if (r->uri_changes == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"rewrite or internal redirection cycle "
"while internal redirect to \"%V\"", uri);
r->main->count++;
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_DONE;
}
r->uri = *uri;
if (args) {
r->args = *args;
} else {
r->args.len = 0;
r->args.data = NULL;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"internal redirect: \"%V?%V\"", uri, &r->args);
ngx_http_set_exten(r);
ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
r->loc_conf = cscf->ctx->loc_conf;
ngx_http_update_location_config(r);
#if (NGX_HTTP_CACHE)
r->cache = NULL;
#endif
r->internal = 1;
r->main->count++;
ngx_http_handler(r);
return NGX_DONE;
} | ['static ngx_int_t\nngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_uint_t status;\n ngx_http_upstream_next_t *un;\n status = u->headers_in.status_n;\n for (un = ngx_http_upstream_next_errors; un->status; un++) {\n if (status != un->status) {\n continue;\n }\n if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) {\n ngx_http_upstream_next(r, u, un->mask);\n return NGX_OK;\n }\n#if (NGX_HTTP_CACHE)\n if (u->cache_status == NGX_HTTP_CACHE_EXPIRED\n && (u->conf->cache_use_stale & un->mask))\n {\n ngx_int_t rc;\n rc = u->reinit_request(r);\n if (rc == NGX_OK) {\n u->cache_status = NGX_HTTP_CACHE_STALE;\n rc = ngx_http_upstream_cache_send(r, u);\n }\n ngx_http_upstream_finalize_request(r, u, rc);\n return NGX_OK;\n }\n#endif\n }\n return NGX_DECLINED;\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n ngx_http_upstream_t *u, ngx_int_t rc)\n{\n ngx_time_t *tp;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "finalize http upstream request: %i", rc);\n if (u->cleanup) {\n *u->cleanup = NULL;\n }\n if (u->state && u->state->response_sec) {\n tp = ngx_timeofday();\n u->state->response_sec = tp->sec - u->state->response_sec;\n u->state->response_msec = tp->msec - u->state->response_msec;\n if (u->pipe) {\n u->state->response_length = u->pipe->read_length;\n }\n }\n u->finalize_request(r, rc);\n if (u->peer.free) {\n u->peer.free(&u->peer, u->peer.data, 0);\n }\n if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n if (u->peer.connection->ssl) {\n u->peer.connection->ssl->no_wait_shutdown = 1;\n (void) ngx_ssl_shutdown(u->peer.connection);\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "close http upstream connection: %d",\n u->peer.connection->fd);\n ngx_close_connection(u->peer.connection);\n }\n u->peer.connection = NULL;\n if (u->pipe && u->pipe->temp_file) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream temp fd: %d",\n u->pipe->temp_file->file.fd);\n }\n#if (NGX_HTTP_CACHE)\n if (u->cacheable && r->cache) {\n time_t valid;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream cache fd: %d",\n r->cache->file.fd);\n if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n if (valid) {\n r->cache->valid_sec = ngx_time() + valid;\n r->cache->error = rc;\n }\n }\n ngx_http_file_cache_free(r, u->pipe->temp_file);\n }\n#endif\n if (u->header_sent\n && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))\n {\n rc = 0;\n }\n if (rc == NGX_DECLINED) {\n return;\n }\n r->connection->log->action = "sending to client";\n if (rc == 0) {\n rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n }\n ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n return;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n#if (NGX_DEBUG)\n if (r != c->data) {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n }\n#endif\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'static ngx_int_t\nngx_http_post_action(ngx_http_request_t *r)\n{\n ngx_http_core_loc_conf_t *clcf;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->post_action.data == NULL) {\n return NGX_DECLINED;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "post action: \\"%V\\"", &clcf->post_action);\n r->main->count--;\n r->http_version = NGX_HTTP_VERSION_9;\n r->header_only = 1;\n r->post_action = 1;\n r->read_event_handler = ngx_http_block_reading;\n if (clcf->post_action.data[0] == \'/\') {\n ngx_http_internal_redirect(r, &clcf->post_action, NULL);\n } else {\n ngx_http_named_location(r, &clcf->post_action);\n }\n return NGX_OK;\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internal redirect to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n r->args.len = 0;\n r->args.data = NULL;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}'] |
15 | 0 | https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_lib.c/#L447 | BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*a;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > b->max)
{
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return(NULL);
}
a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
if (A == NULL)
{
BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
return(NULL);
}
#if 1
B=b->d;
if (B != NULL)
{
#if 0
for (i=b->top&(~7); i>0; i-=8)
{
A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
A+=8;
B+=8;
}
switch (b->top&7)
{
case 7:
A[6]=B[6];
case 6:
A[5]=B[5];
case 5:
A[4]=B[4];
case 4:
A[3]=B[3];
case 3:
A[2]=B[2];
case 2:
A[1]=B[1];
case 1:
A[0]=B[0];
case 0:
;
}
#else
for (i=b->top>>2; i>0; i--,A+=4,B+=4)
{
BN_ULONG a0,a1,a2,a3;
a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
}
switch (b->top&3)
{
case 3: A[2]=B[2];
case 2: A[1]=B[1];
case 1: A[0]=B[0];
case 0: ;
}
#endif
Free(b->d);
}
b->d=a;
b->max=words;
A= &(b->d[b->top]);
for (i=(b->max - b->top)>>3; i>0; i--,A+=8)
{
A[0]=0; A[1]=0; A[2]=0; A[3]=0;
A[4]=0; A[5]=0; A[6]=0; A[7]=0;
}
for (i=(b->max - b->top)&7; i>0; i--,A++)
A[0]=0;
#else
memset(A,0,sizeof(BN_ULONG)*(words+1));
memcpy(A,b->d,sizeof(b->d[0])*b->top);
b->d=a;
b->max=words;
#endif
}
return(b);
} | ['static int RSA_eay_private_decrypt(int flen, unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM f,ret;\n\tint j,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tBN_init(&f);\n\tBN_init(&ret);\n\tctx=BN_CTX_new();\n\tif (ctx == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tif ((buf=(unsigned char *)Malloc(num)) == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (flen > num)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,(int)flen,&f) == NULL) goto err;\n\tif ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))\n\t\tRSA_blinding_on(rsa,ctx);\n\tif (rsa->flags & RSA_FLAG_BLINDING)\n\t\tif (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;\n\tif (\t(rsa->p != NULL) &&\n\t\t(rsa->q != NULL) &&\n\t\t(rsa->dmp1 != NULL) &&\n\t\t(rsa->dmq1 != NULL) &&\n\t\t(rsa->iqmp != NULL))\n\t\t{ if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }\n\telse\n\t\t{\n\t\tif (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL))\n\t\t\tgoto err;\n\t\t}\n\tif (rsa->flags & RSA_FLAG_BLINDING)\n\t\tif (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err;\n\tp=buf;\n\tj=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_2(to,num,buf,j,num);\n\t\tbreak;\n#ifndef NO_SHA\n case RSA_PKCS1_OAEP_PADDING:\n\t r=RSA_padding_check_PKCS1_OAEP(to,num,buf,j,num,NULL,0);\n break;\n#endif\n \tcase RSA_SSLV23_PADDING:\n\t\tr=RSA_padding_check_SSLv23(to,num,buf,j,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,j,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&f);\n\tBN_clear_free(&ret);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tFree(buf);\n\t\t}\n\treturn(r);\n\t}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n\t{\n\tunsigned int i,m;\n\tunsigned int n;\n\tBN_ULONG l;\n\tif (ret == NULL) ret=BN_new();\n\tif (ret == NULL) return(NULL);\n\tl=0;\n\tn=len;\n\tif (n == 0)\n\t\t{\n\t\tret->top=0;\n\t\treturn(ret);\n\t\t}\n\tif (bn_expand(ret,(int)(n+2)*8) == NULL)\n\t\treturn(NULL);\n\ti=((n-1)/BN_BYTES)+1;\n\tm=((n-1)%(BN_BYTES));\n\tret->top=i;\n\twhile (n-- > 0)\n\t\t{\n\t\tl=(l<<8L)| *(s++);\n\t\tif (m-- == 0)\n\t\t\t{\n\t\t\tret->d[--i]=l;\n\t\t\tl=0;\n\t\t\tm=BN_BYTES-1;\n\t\t\t}\n\t\t}\n\tbn_fix_top(ret);\n\treturn(ret);\n\t}', 'int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tbn_check_top(n);\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED);\n\t\treturn(0);\n\t\t}\n\treturn(BN_mod_mul(n,n,b->A,b->mod,ctx));\n\t}', 'int BN_mod_mul(BIGNUM *ret, BIGNUM *a, BIGNUM *b, BIGNUM *m, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint r=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tt= &(ctx->bn[ctx->tos++]);\n\tif (a == b)\n\t\t{ if (!BN_sqr(t,a,ctx)) goto err; }\n\telse\n\t\t{ if (!BN_mul(t,a,b,ctx)) goto err; }\n\tif (!BN_mod(ret,t,m,ctx)) goto err;\n\tr=1;\nerr:\n\tctx->tos--;\n\treturn(r);\n\t}', 'int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*a;\n\tconst BN_ULONG *B;\n\tint i;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n#if 0\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n#else\n\t\t\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t\t\t{\n\t\t\t\tBN_ULONG a0,a1,a2,a3;\n\t\t\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\t\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t\t\t}\n\t\t\tswitch (b->top&3)\n\t\t\t\t{\n\t\t\t\tcase 3:\tA[2]=B[2];\n\t\t\t\tcase 2:\tA[1]=B[1];\n\t\t\t\tcase 1:\tA[0]=B[0];\n\t\t\t\tcase 0:\t;\n\t\t\t\t}\n#endif\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tA= &(b->d[b->top]);\n\t\tfor (i=(b->max - b->top)>>3; i>0; i--,A+=8)\n\t\t\t{\n\t\t\tA[0]=0; A[1]=0; A[2]=0; A[3]=0;\n\t\t\tA[4]=0; A[5]=0; A[6]=0; A[7]=0;\n\t\t\t}\n\t\tfor (i=(b->max - b->top)&7; i>0; i--,A++)\n\t\t\tA[0]=0;\n#else\n\t\t\tmemset(A,0,sizeof(BN_ULONG)*(words+1));\n\t\t\tmemcpy(A,b->d,sizeof(b->d[0])*b->top);\n\t\t\tb->d=a;\n\t\t\tb->max=words;\n#endif\n\t\t}\n\treturn(b);\n\t}'] |
16 | 0 | https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n const EC_POINT *b, BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t;\n int ret = 0;\n if (EC_POINT_is_at_infinity(group, a)) {\n if (!EC_POINT_copy(r, b))\n return 0;\n return 1;\n }\n if (EC_POINT_is_at_infinity(group, b)) {\n if (!EC_POINT_copy(r, a))\n return 0;\n return 1;\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 x0 = BN_CTX_get(ctx);\n y0 = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n y1 = BN_CTX_get(ctx);\n x2 = BN_CTX_get(ctx);\n y2 = BN_CTX_get(ctx);\n s = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (a->Z_is_one) {\n if (!BN_copy(x0, a->X))\n goto err;\n if (!BN_copy(y0, a->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates(group, a, x0, y0, ctx))\n goto err;\n }\n if (b->Z_is_one) {\n if (!BN_copy(x1, b->X))\n goto err;\n if (!BN_copy(y1, b->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates(group, b, x1, y1, ctx))\n goto err;\n }\n if (BN_GF2m_cmp(x0, x1)) {\n if (!BN_GF2m_add(t, x0, x1))\n goto err;\n if (!BN_GF2m_add(s, y0, y1))\n goto err;\n if (!group->meth->field_div(group, s, s, t, ctx))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, t))\n goto err;\n } else {\n if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1)) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n ret = 1;\n goto err;\n }\n if (!group->meth->field_div(group, s, y1, x1, ctx))\n goto err;\n if (!BN_GF2m_add(s, s, x1))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n }\n if (!BN_GF2m_add(y2, x1, x2))\n goto err;\n if (!group->meth->field_mul(group, y2, y2, s, ctx))\n goto err;\n if (!BN_GF2m_add(y2, y2, x2))\n goto err;\n if (!BN_GF2m_add(y2, y2, y1))\n goto err;\n if (!EC_POINT_set_affine_coordinates(group, r, x2, y2, 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("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n 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}'] |
17 | 0 | https://github.com/libav/libav/blob/fb0c9d41d685abb58575c5482ca33b8cd457c5ec/libavcodec/h264.c/#L218 | void ff_h264_draw_horiz_band(H264Context *h, int y, int height)
{
AVCodecContext *avctx = h->avctx;
Picture *cur = &h->cur_pic;
Picture *last = h->ref_list[0][0].f.data[0] ? &h->ref_list[0][0] : NULL;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
int vshift = desc->log2_chroma_h;
const int field_pic = h->picture_structure != PICT_FRAME;
if (field_pic) {
height <<= 1;
y <<= 1;
}
height = FFMIN(height, avctx->height - y);
if (field_pic && h->first_field && !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD))
return;
if (avctx->draw_horiz_band) {
AVFrame *src;
int offset[AV_NUM_DATA_POINTERS];
int i;
if (cur->f.pict_type == AV_PICTURE_TYPE_B || h->low_delay ||
(avctx->slice_flags & SLICE_FLAG_CODED_ORDER))
src = &cur->f;
else if (last)
src = &last->f;
else
return;
offset[0] = y * src->linesize[0];
offset[1] =
offset[2] = (y >> vshift) * src->linesize[1];
for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
offset[i] = 0;
emms_c();
avctx->draw_horiz_band(avctx, src, offset,
y, h->picture_structure, height);
}
} | ['void ff_h264_draw_horiz_band(H264Context *h, int y, int height)\n{\n AVCodecContext *avctx = h->avctx;\n Picture *cur = &h->cur_pic;\n Picture *last = h->ref_list[0][0].f.data[0] ? &h->ref_list[0][0] : NULL;\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);\n int vshift = desc->log2_chroma_h;\n const int field_pic = h->picture_structure != PICT_FRAME;\n if (field_pic) {\n height <<= 1;\n y <<= 1;\n }\n height = FFMIN(height, avctx->height - y);\n if (field_pic && h->first_field && !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD))\n return;\n if (avctx->draw_horiz_band) {\n AVFrame *src;\n int offset[AV_NUM_DATA_POINTERS];\n int i;\n if (cur->f.pict_type == AV_PICTURE_TYPE_B || h->low_delay ||\n (avctx->slice_flags & SLICE_FLAG_CODED_ORDER))\n src = &cur->f;\n else if (last)\n src = &last->f;\n else\n return;\n offset[0] = y * src->linesize[0];\n offset[1] =\n offset[2] = (y >> vshift) * src->linesize[1];\n for (i = 3; i < AV_NUM_DATA_POINTERS; i++)\n offset[i] = 0;\n emms_c();\n avctx->draw_horiz_band(avctx, src, offset,\n y, h->picture_structure, height);\n }\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}'] |
18 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/asn1/asn1_lib.c/#L390 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, size_t len)
{
unsigned char *c;
const char *data=_data;
if (len < 0)
{
if (data == NULL)
return(0);
else
len=strlen(data);
}
if ((str->length < len) || (str->data == NULL))
{
c=str->data;
if (c == NULL)
str->data=OPENSSL_malloc(len+1);
else
str->data=OPENSSL_realloc(c,len+1);
if (str->data == NULL)
{
ASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);
str->data=c;
return(0);
}
}
str->length=len;
if (data != NULL)
{
memcpy(str->data,data,len);
str->data[len]='\0';
}
return(1);
} | ['static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)\n\t{\n\tASN1_TYPE *atmp = NULL;\n\tCONF_VALUE vtmp;\n\tunsigned char *rdata;\n\tlong rdlen;\n\tint no_unused = 1;\n\tif (!(atmp = ASN1_TYPE_new()))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tif (!str)\n\t\tstr = "";\n\tswitch(utype)\n\t\t{\n\t\tcase V_ASN1_NULL:\n\t\tif (str && *str)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tbreak;\n\t\tcase V_ASN1_BOOLEAN:\n\t\tif (format != ASN1_GEN_FORMAT_ASCII)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tvtmp.name = NULL;\n\t\tvtmp.section = NULL;\n\t\tvtmp.value = (char *)str;\n\t\tif (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tbreak;\n\t\tcase V_ASN1_INTEGER:\n\t\tcase V_ASN1_ENUMERATED:\n\t\tif (format != ASN1_GEN_FORMAT_ASCII)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tif (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str)))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tbreak;\n\t\tcase V_ASN1_OBJECT:\n\t\tif (format != ASN1_GEN_FORMAT_ASCII)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tif (!(atmp->value.object = OBJ_txt2obj(str, 0)))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tbreak;\n\t\tcase V_ASN1_UTCTIME:\n\t\tcase V_ASN1_GENERALIZEDTIME:\n\t\tif (format != ASN1_GEN_FORMAT_ASCII)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tif (!(atmp->value.asn1_string = ASN1_STRING_new()))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tif (!ASN1_STRING_set(atmp->value.asn1_string, str, -1))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tatmp->value.asn1_string->type = utype;\n\t\tif (!ASN1_TIME_check(atmp->value.asn1_string))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tbreak;\n\t\tcase V_ASN1_BMPSTRING:\n\t\tcase V_ASN1_PRINTABLESTRING:\n\t\tcase V_ASN1_IA5STRING:\n\t\tcase V_ASN1_T61STRING:\n\t\tcase V_ASN1_UTF8STRING:\n\t\tcase V_ASN1_VISIBLESTRING:\n\t\tcase V_ASN1_UNIVERSALSTRING:\n\t\tcase V_ASN1_GENERALSTRING:\n\t\tcase V_ASN1_NUMERICSTRING:\n\t\tif (format == ASN1_GEN_FORMAT_ASCII)\n\t\t\tformat = MBSTRING_ASC;\n\t\telse if (format == ASN1_GEN_FORMAT_UTF8)\n\t\t\tformat = MBSTRING_UTF8;\n\t\telse\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tif (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,\n\t\t\t\t\t\t-1, format, ASN1_tag2bit(utype)) <= 0)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto bad_str;\n\t\t\t}\n\t\tbreak;\n\t\tcase V_ASN1_BIT_STRING:\n\t\tcase V_ASN1_OCTET_STRING:\n\t\tif (!(atmp->value.asn1_string = ASN1_STRING_new()))\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tif (format == ASN1_GEN_FORMAT_HEX)\n\t\t\t{\n\t\t\tif (!(rdata = string_to_hex((char *)str, &rdlen)))\n\t\t\t\t{\n\t\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);\n\t\t\t\tgoto bad_str;\n\t\t\t\t}\n\t\t\tatmp->value.asn1_string->data = rdata;\n\t\t\tatmp->value.asn1_string->length = rdlen;\n\t\t\tatmp->value.asn1_string->type = utype;\n\t\t\t}\n\t\telse if (format == ASN1_GEN_FORMAT_ASCII)\n\t\t\tASN1_STRING_set(atmp->value.asn1_string, str, -1);\n\t\telse if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING))\n\t\t\t{\n\t\t\tif (!CONF_parse_list(str, \',\', 1, bitstr_cb, atmp->value.bit_string))\n\t\t\t\t{\n\t\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);\n\t\t\t\tgoto bad_str;\n\t\t\t\t}\n\t\t\tno_unused = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);\n\t\t\tgoto bad_form;\n\t\t\t}\n\t\tif ((utype == V_ASN1_BIT_STRING) && no_unused)\n\t\t\t{\n\t\t\tatmp->value.asn1_string->flags\n\t\t\t\t&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);\n \t\tatmp->value.asn1_string->flags\n\t\t\t\t|= ASN1_STRING_FLAG_BITS_LEFT;\n\t\t\t}\n\t\tbreak;\n\t\tdefault:\n\t\tASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);\n\t\tgoto bad_str;\n\t\tbreak;\n\t\t}\n\tatmp->type = utype;\n\treturn atmp;\n\tbad_str:\n\tERR_add_error_data(2, "string=", str);\n\tbad_form:\n\tASN1_TYPE_free(atmp);\n\treturn NULL;\n\t}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, size_t len)\n\t{\n\tunsigned char *c;\n\tconst char *data=_data;\n\tif (len < 0)\n\t\t{\n\t\tif (data == NULL)\n\t\t\treturn(0);\n\t\telse\n\t\t\tlen=strlen(data);\n\t\t}\n\tif ((str->length < len) || (str->data == NULL))\n\t\t{\n\t\tc=str->data;\n\t\tif (c == NULL)\n\t\t\tstr->data=OPENSSL_malloc(len+1);\n\t\telse\n\t\t\tstr->data=OPENSSL_realloc(c,len+1);\n\t\tif (str->data == NULL)\n\t\t\t{\n\t\t\tASN1err(ASN1_F_ASN1_STRING_SET,ERR_R_MALLOC_FAILURE);\n\t\t\tstr->data=c;\n\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\tstr->length=len;\n\tif (data != NULL)\n\t\t{\n\t\tmemcpy(str->data,data,len);\n\t\tstr->data[len]='\\0';\n\t\t}\n\treturn(1);\n\t}"] |
19 | 0 | https://github.com/libav/libav/blob/d9cf5f516974c64e01846ca685301014b38cf224/libavformat/mpegts.c/#L678 | static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
{
GetBitContext gb;
int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
int dts_flag = -1, cts_flag = -1;
int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;
init_get_bits(&gb, buf, buf_size*8);
if (sl->use_au_start)
au_start_flag = get_bits1(&gb);
if (sl->use_au_end)
au_end_flag = get_bits1(&gb);
if (!sl->use_au_start && !sl->use_au_end)
au_start_flag = au_end_flag = 1;
if (sl->ocr_len > 0)
ocr_flag = get_bits1(&gb);
if (sl->use_idle)
idle_flag = get_bits1(&gb);
if (sl->use_padding)
padding_flag = get_bits1(&gb);
if (padding_flag)
padding_bits = get_bits(&gb, 3);
if (!idle_flag && (!padding_flag || padding_bits != 0)) {
if (sl->packet_seq_num_len)
skip_bits_long(&gb, sl->packet_seq_num_len);
if (sl->degr_prior_len)
if (get_bits1(&gb))
skip_bits(&gb, sl->degr_prior_len);
if (ocr_flag)
skip_bits_long(&gb, sl->ocr_len);
if (au_start_flag) {
if (sl->use_rand_acc_pt)
get_bits1(&gb);
if (sl->au_seq_num_len > 0)
skip_bits_long(&gb, sl->au_seq_num_len);
if (sl->use_timestamps) {
dts_flag = get_bits1(&gb);
cts_flag = get_bits1(&gb);
}
}
if (sl->inst_bitrate_len)
inst_bitrate_flag = get_bits1(&gb);
if (dts_flag == 1)
dts = get_bits64(&gb, sl->timestamp_len);
if (cts_flag == 1)
cts = get_bits64(&gb, sl->timestamp_len);
if (sl->au_len > 0)
skip_bits_long(&gb, sl->au_len);
if (inst_bitrate_flag)
skip_bits_long(&gb, sl->inst_bitrate_len);
}
if (dts != AV_NOPTS_VALUE)
pes->dts = dts;
if (cts != AV_NOPTS_VALUE)
pes->pts = cts;
if (sl->timestamp_len && sl->timestamp_res)
avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);
return (get_bits_count(&gb) + 7) >> 3;
} | ['static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)\n{\n GetBitContext gb;\n int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;\n int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;\n int dts_flag = -1, cts_flag = -1;\n int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;\n init_get_bits(&gb, buf, buf_size*8);\n if (sl->use_au_start)\n au_start_flag = get_bits1(&gb);\n if (sl->use_au_end)\n au_end_flag = get_bits1(&gb);\n if (!sl->use_au_start && !sl->use_au_end)\n au_start_flag = au_end_flag = 1;\n if (sl->ocr_len > 0)\n ocr_flag = get_bits1(&gb);\n if (sl->use_idle)\n idle_flag = get_bits1(&gb);\n if (sl->use_padding)\n padding_flag = get_bits1(&gb);\n if (padding_flag)\n padding_bits = get_bits(&gb, 3);\n if (!idle_flag && (!padding_flag || padding_bits != 0)) {\n if (sl->packet_seq_num_len)\n skip_bits_long(&gb, sl->packet_seq_num_len);\n if (sl->degr_prior_len)\n if (get_bits1(&gb))\n skip_bits(&gb, sl->degr_prior_len);\n if (ocr_flag)\n skip_bits_long(&gb, sl->ocr_len);\n if (au_start_flag) {\n if (sl->use_rand_acc_pt)\n get_bits1(&gb);\n if (sl->au_seq_num_len > 0)\n skip_bits_long(&gb, sl->au_seq_num_len);\n if (sl->use_timestamps) {\n dts_flag = get_bits1(&gb);\n cts_flag = get_bits1(&gb);\n }\n }\n if (sl->inst_bitrate_len)\n inst_bitrate_flag = get_bits1(&gb);\n if (dts_flag == 1)\n dts = get_bits64(&gb, sl->timestamp_len);\n if (cts_flag == 1)\n cts = get_bits64(&gb, sl->timestamp_len);\n if (sl->au_len > 0)\n skip_bits_long(&gb, sl->au_len);\n if (inst_bitrate_flag)\n skip_bits_long(&gb, sl->inst_bitrate_len);\n }\n if (dts != AV_NOPTS_VALUE)\n pes->dts = dts;\n if (cts != AV_NOPTS_VALUE)\n pes->pts = cts;\n if (sl->timestamp_len && sl->timestamp_res)\n avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);\n return (get_bits_count(&gb) + 7) >> 3;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size <= 0) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}'] |
20 | 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_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *b = NULL;\n int ret = 0;\n BN_CTX_start(ctx);\n if ((b = BN_CTX_get(ctx)) == NULL)\n goto err;\n do {\n if (!BN_priv_rand(b, BN_num_bits(p) - 1,\n BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n goto err;\n } while (BN_is_zero(b));\n if (!BN_GF2m_mod_mul(r, a, b, p, ctx))\n goto err;\n if (!BN_GF2m_mod_inv_vartime(r, r, p, ctx))\n goto err;\n if (!BN_GF2m_mod_mul(r, r, b, p, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n const BIGNUM *p, BN_CTX *ctx)\n{\n int ret = 0;\n const int max = BN_num_bits(p) + 1;\n int *arr = NULL;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(p);\n if ((arr = OPENSSL_malloc(sizeof(*arr) * max)) == NULL)\n goto err;\n ret = BN_GF2m_poly2arr(p, arr, max);\n if (!ret || ret > max) {\n BNerr(BN_F_BN_GF2M_MOD_MUL, BN_R_INVALID_LENGTH);\n goto err;\n }\n ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);\n bn_check_top(r);\n err:\n OPENSSL_free(arr);\n return ret;\n}', 'static int BN_GF2m_mod_inv_vartime(BIGNUM *r, const BIGNUM *a,\n 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("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}', '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 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}'] |
21 | 0 | https://github.com/openssl/openssl/blob/924e5eda2c82d737cc5a1b9c37918aa6e34825da/apps/speed.c/#L2819 | 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\t{\n\tint n;\n\tint fd[2];\n\tint *fds;\n\tstatic char sep[]=":";\n\tfds=malloc(multi*sizeof *fds);\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tif (pipe(fd) == -1)\n\t\t\t{\n\t\t\tfprintf(stderr, "pipe failure\\n");\n\t\t\texit(1);\n\t\t\t}\n\t\tfflush(stdout);\n\t\tfflush(stderr);\n\t\tif(fork())\n\t\t\t{\n\t\t\tclose(fd[1]);\n\t\t\tfds[n]=fd[0];\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tclose(fd[0]);\n\t\t\tclose(1);\n\t\t\tif (dup(fd[1]) == -1)\n\t\t\t\t{\n\t\t\t\tfprintf(stderr, "dup failed\\n");\n\t\t\t\texit(1);\n\t\t\t\t}\n\t\t\tclose(fd[1]);\n\t\t\tmr=1;\n\t\t\tusertime=0;\n\t\t\tfree(fds);\n\t\t\treturn 0;\n\t\t\t}\n\t\tprintf("Forked child %d\\n",n);\n\t\t}\n\tfor(n=0 ; n < multi ; ++n)\n\t\t{\n\t\tFILE *f;\n\t\tchar buf[1024];\n\t\tchar *p;\n\t\tf=fdopen(fds[n],"r");\n\t\twhile(fgets(buf,sizeof buf,f))\n\t\t\t{\n\t\t\tp=strchr(buf,\'\\n\');\n\t\t\tif(p)\n\t\t\t\t*p=\'\\0\';\n\t\t\tif(buf[0] != \'+\')\n\t\t\t\t{\n\t\t\t\tfprintf(stderr,"Don\'t understand line \'%s\' from child %d\\n",\n\t\t\t\t\t\tbuf,n);\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\tprintf("Got: %s from %d\\n",buf,n);\n\t\t\tif(!strncmp(buf,"+F:",3))\n\t\t\t\t{\n\t\t\t\tint alg;\n\t\t\t\tint j;\n\t\t\t\tp=buf+3;\n\t\t\t\talg=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\tfor(j=0 ; j < SIZE_NUM ; ++j)\n\t\t\t\t\tresults[alg][j]+=atof(sstrsep(&p,sep));\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n\t\t\telse if(!strncmp(buf,"+F2:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\trsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\trsa_results[k][1]=d;\n\t\t\t\t}\n#ifndef OPENSSL_NO_DSA\n\t\t\telse if(!strncmp(buf,"+F3:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tdsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tdsa_results[k][1]=d;\n\t\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t\telse if(!strncmp(buf,"+F4:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][0]=1/(1/ecdsa_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][0]=d;\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdsa_results[k][1]=1/(1/ecdsa_results[k][1]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdsa_results[k][1]=d;\n\t\t\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\telse if(!strncmp(buf,"+F5:",4))\n\t\t\t\t{\n\t\t\t\tint k;\n\t\t\t\tdouble d;\n\t\t\t\tp=buf+4;\n\t\t\t\tk=atoi(sstrsep(&p,sep));\n\t\t\t\tsstrsep(&p,sep);\n\t\t\t\td=atof(sstrsep(&p,sep));\n\t\t\t\tif(n)\n\t\t\t\t\tecdh_results[k][0]=1/(1/ecdh_results[k][0]+1/d);\n\t\t\t\telse\n\t\t\t\t\tecdh_results[k][0]=d;\n\t\t\t\t}\n#endif\n\t\t\telse if(!strncmp(buf,"+H:",3))\n\t\t\t\t{\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tfprintf(stderr,"Unknown type \'%s\' from child %d\\n",buf,n);\n\t\t\t}\n\t\tfclose(f);\n\t\t}\n\tfree(fds);\n\treturn 1;\n\t}'] |
22 | 0 | https://github.com/openssl/openssl/blob/1586365835e8eb950e804a4f1e62cff9563061bb/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}', 'static void x509v3_cache_extensions(X509 *x)\n{\n\tBASIC_CONSTRAINTS *bs;\n\tASN1_BIT_STRING *usage;\n\tASN1_BIT_STRING *ns;\n\tEXTENDED_KEY_USAGE *extusage;\n\tX509_EXTENSION *ex;\n\tint i;\n\tif(x->ex_flags & EXFLAG_SET) return;\n#ifndef OPENSSL_NO_SHA\n\tX509_digest(x, EVP_sha1(), x->sha1_hash, NULL);\n#endif\n\tif(!X509_NAME_cmp(X509_get_subject_name(x), X509_get_issuer_name(x)))\n\t\t\t x->ex_flags |= EXFLAG_SS;\n\tif(!X509_get_version(x)) x->ex_flags |= EXFLAG_V1;\n\tif((bs=X509_get_ext_d2i(x, NID_basic_constraints, NULL, NULL))) {\n\t\tif(bs->ca) x->ex_flags |= EXFLAG_CA;\n\t\tif(bs->pathlen) {\n\t\t\tif((bs->pathlen->type == V_ASN1_NEG_INTEGER)\n\t\t\t\t\t\t|| !bs->ca) {\n\t\t\t\tx->ex_flags |= EXFLAG_INVALID;\n\t\t\t\tx->ex_pathlen = 0;\n\t\t\t} else x->ex_pathlen = ASN1_INTEGER_get(bs->pathlen);\n\t\t} else x->ex_pathlen = -1;\n\t\tBASIC_CONSTRAINTS_free(bs);\n\t\tx->ex_flags |= EXFLAG_BCONS;\n\t}\n\tif((usage=X509_get_ext_d2i(x, NID_key_usage, NULL, NULL))) {\n\t\tif(usage->length > 0) {\n\t\t\tx->ex_kusage = usage->data[0];\n\t\t\tif(usage->length > 1)\n\t\t\t\tx->ex_kusage |= usage->data[1] << 8;\n\t\t} else x->ex_kusage = 0;\n\t\tx->ex_flags |= EXFLAG_KUSAGE;\n\t\tASN1_BIT_STRING_free(usage);\n\t}\n\tx->ex_xkusage = 0;\n\tif((extusage=X509_get_ext_d2i(x, NID_ext_key_usage, NULL, NULL))) {\n\t\tx->ex_flags |= EXFLAG_XKUSAGE;\n\t\tfor(i = 0; i < sk_ASN1_OBJECT_num(extusage); i++) {\n\t\t\tswitch(OBJ_obj2nid(sk_ASN1_OBJECT_value(extusage,i))) {\n\t\t\t\tcase NID_server_auth:\n\t\t\t\tx->ex_xkusage |= XKU_SSL_SERVER;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_client_auth:\n\t\t\t\tx->ex_xkusage |= XKU_SSL_CLIENT;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_email_protect:\n\t\t\t\tx->ex_xkusage |= XKU_SMIME;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_code_sign:\n\t\t\t\tx->ex_xkusage |= XKU_CODE_SIGN;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_ms_sgc:\n\t\t\t\tcase NID_ns_sgc:\n\t\t\t\tx->ex_xkusage |= XKU_SGC;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_OCSP_sign:\n\t\t\t\tx->ex_xkusage |= XKU_OCSP_SIGN;\n\t\t\t\tbreak;\n\t\t\t\tcase NID_time_stamp:\n\t\t\t\tx->ex_xkusage |= XKU_TIMESTAMP;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tsk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free);\n\t}\n\tif((ns=X509_get_ext_d2i(x, NID_netscape_cert_type, NULL, NULL))) {\n\t\tif(ns->length > 0) x->ex_nscert = ns->data[0];\n\t\telse x->ex_nscert = 0;\n\t\tx->ex_flags |= EXFLAG_NSCERT;\n\t\tASN1_BIT_STRING_free(ns);\n\t}\n\tx->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);\n\tx->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);\n\tfor (i = 0; i < X509_get_ext_count(x); i++)\n\t\t{\n\t\tex = X509_get_ext(x, i);\n\t\tif (!X509_EXTENSION_get_critical(ex))\n\t\t\tcontinue;\n\t\tif (!X509_supported_extension(ex))\n\t\t\t{\n\t\t\tx->ex_flags |= EXFLAG_CRITICAL;\n\t\t\tbreak;\n\t\t\t}\n\t\t}\n\tx->ex_flags |= EXFLAG_SET;\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n\tX509_PURPOSE tmp;\n\tint idx;\n\tif((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n\t\treturn purpose - X509_PURPOSE_MIN;\n\ttmp.purpose = purpose;\n\tif(!xptable) return -1;\n\tidx = sk_X509_PURPOSE_find(xptable, &tmp);\n\tif(idx == -1) return -1;\n\treturn idx + X509_PURPOSE_COUNT;\n}', 'X509_PURPOSE * X509_PURPOSE_get0(int idx)\n{\n\tif(idx < 0) return NULL;\n\tif(idx < X509_PURPOSE_COUNT) return xstandard + idx;\n\treturn sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}'] |
23 | 0 | https://github.com/openssl/openssl/blob/1a50eedf2a1fbb1e0e009ad616d8be678e4c6340/crypto/bn/bn_ctx.c/#L276 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int ecp_nistz256_points_mul(const EC_GROUP *group,\n EC_POINT *r,\n const BIGNUM *scalar,\n size_t num,\n const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n int i = 0, ret = 0, no_precomp_for_generator = 0, p_is_infinity = 0;\n unsigned char p_str[33] = { 0 };\n const PRECOMP256_ROW *preComputedTable = NULL;\n const NISTZ256_PRE_COMP *pre_comp = NULL;\n const EC_POINT *generator = NULL;\n const BIGNUM **new_scalars = NULL;\n const EC_POINT **new_points = NULL;\n unsigned int idx = 0;\n const unsigned int window_size = 7;\n const unsigned int mask = (1 << (window_size + 1)) - 1;\n unsigned int wvalue;\n ALIGN32 union {\n P256_POINT p;\n P256_POINT_AFFINE a;\n } t, p;\n BIGNUM *tmp_scalar;\n if ((num + 1) == 0 || (num + 1) > OPENSSL_MALLOC_MAX_NELEMS(void *)) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n BN_CTX_start(ctx);\n if (scalar) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.nistz256;\n if (pre_comp) {\n EC_POINT *pre_comp_generator = EC_POINT_new(group);\n if (pre_comp_generator == NULL)\n goto err;\n if (!ecp_nistz256_set_from_affine(pre_comp_generator,\n group, pre_comp->precomp[0],\n ctx)) {\n EC_POINT_free(pre_comp_generator);\n goto err;\n }\n if (0 == EC_POINT_cmp(group, generator, pre_comp_generator, ctx))\n preComputedTable = (const PRECOMP256_ROW *)pre_comp->precomp;\n EC_POINT_free(pre_comp_generator);\n }\n if (preComputedTable == NULL && ecp_nistz256_is_affine_G(generator)) {\n preComputedTable = ecp_nistz256_precomputed;\n }\n if (preComputedTable) {\n if ((BN_num_bits(scalar) > 256)\n || BN_is_negative(scalar)) {\n if ((tmp_scalar = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_nnmod(tmp_scalar, scalar, group->order, ctx)) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_BN_LIB);\n goto err;\n }\n scalar = tmp_scalar;\n }\n for (i = 0; i < bn_get_top(scalar) * BN_BYTES; i += BN_BYTES) {\n BN_ULONG d = bn_get_words(scalar)[i / BN_BYTES];\n p_str[i + 0] = (unsigned char)d;\n p_str[i + 1] = (unsigned char)(d >> 8);\n p_str[i + 2] = (unsigned char)(d >> 16);\n p_str[i + 3] = (unsigned char)(d >>= 24);\n if (BN_BYTES == 8) {\n d >>= 8;\n p_str[i + 4] = (unsigned char)d;\n p_str[i + 5] = (unsigned char)(d >> 8);\n p_str[i + 6] = (unsigned char)(d >> 16);\n p_str[i + 7] = (unsigned char)(d >> 24);\n }\n }\n for (; i < 33; i++)\n p_str[i] = 0;\n#if defined(ECP_NISTZ256_AVX2)\n if (ecp_nistz_avx2_eligible()) {\n ecp_nistz256_avx2_mul_g(&p.p, p_str, preComputedTable);\n } else\n#endif\n {\n BN_ULONG infty;\n wvalue = (p_str[0] << 1) & mask;\n idx += window_size;\n wvalue = _booth_recode_w7(wvalue);\n ecp_nistz256_gather_w7(&p.a, preComputedTable[0],\n wvalue >> 1);\n ecp_nistz256_neg(p.p.Z, p.p.Y);\n copy_conditional(p.p.Y, p.p.Z, wvalue & 1);\n infty = (p.p.X[0] | p.p.X[1] | p.p.X[2] | p.p.X[3] |\n p.p.Y[0] | p.p.Y[1] | p.p.Y[2] | p.p.Y[3]);\n if (P256_LIMBS == 8)\n infty |= (p.p.X[4] | p.p.X[5] | p.p.X[6] | p.p.X[7] |\n p.p.Y[4] | p.p.Y[5] | p.p.Y[6] | p.p.Y[7]);\n infty = 0 - is_zero(infty);\n infty = ~infty;\n p.p.Z[0] = ONE[0] & infty;\n p.p.Z[1] = ONE[1] & infty;\n p.p.Z[2] = ONE[2] & infty;\n p.p.Z[3] = ONE[3] & infty;\n if (P256_LIMBS == 8) {\n p.p.Z[4] = ONE[4] & infty;\n p.p.Z[5] = ONE[5] & infty;\n p.p.Z[6] = ONE[6] & infty;\n p.p.Z[7] = ONE[7] & infty;\n }\n for (i = 1; i < 37; i++) {\n unsigned int off = (idx - 1) / 8;\n wvalue = p_str[off] | p_str[off + 1] << 8;\n wvalue = (wvalue >> ((idx - 1) % 8)) & mask;\n idx += window_size;\n wvalue = _booth_recode_w7(wvalue);\n ecp_nistz256_gather_w7(&t.a,\n preComputedTable[i], wvalue >> 1);\n ecp_nistz256_neg(t.p.Z, t.a.Y);\n copy_conditional(t.a.Y, t.p.Z, wvalue & 1);\n ecp_nistz256_point_add_affine(&p.p, &p.p, &t.a);\n }\n }\n } else {\n p_is_infinity = 1;\n no_precomp_for_generator = 1;\n }\n } else\n p_is_infinity = 1;\n if (no_precomp_for_generator) {\n new_scalars = OPENSSL_malloc((num + 1) * sizeof(BIGNUM *));\n if (new_scalars == NULL) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n new_points = OPENSSL_malloc((num + 1) * sizeof(EC_POINT *));\n if (new_points == NULL) {\n ECerr(EC_F_ECP_NISTZ256_POINTS_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n memcpy(new_scalars, scalars, num * sizeof(BIGNUM *));\n new_scalars[num] = scalar;\n memcpy(new_points, points, num * sizeof(EC_POINT *));\n new_points[num] = generator;\n scalars = new_scalars;\n points = new_points;\n num++;\n }\n if (num) {\n P256_POINT *out = &t.p;\n if (p_is_infinity)\n out = &p.p;\n if (!ecp_nistz256_windowed_mul(group, out, scalars, points, num, ctx))\n goto err;\n if (!p_is_infinity)\n ecp_nistz256_point_add(&p.p, &p.p, out);\n }\n if (!bn_set_words(r->X, p.p.X, P256_LIMBS) ||\n !bn_set_words(r->Y, p.p.Y, P256_LIMBS) ||\n !bn_set_words(r->Z, p.p.Z, P256_LIMBS)) {\n goto err;\n }\n r->Z_is_one = is_one(r->Z) & 1;\n ret = 1;\nerr:\n if (ctx)\n BN_CTX_end(ctx);\n OPENSSL_free(new_points);\n OPENSSL_free(new_scalars);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', '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}'] |
24 | 0 | https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L357 | static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){
LOAD_LEFT_EDGE
LOAD_DOWN_LEFT_EDGE
LOAD_TOP_EDGE
LOAD_TOP_RIGHT_EDGE
src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;
src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;
src[2+0*stride]=
src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;
src[3+0*stride]=
src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;
src[2+1*stride]=
src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;
src[3+1*stride]=
src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;
src[3+2*stride]=
src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;
src[0+3*stride]=
src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;
src[2+3*stride]=(l4 + l5 + 1)>>1;
src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;
} | ['static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){\n LOAD_LEFT_EDGE\n LOAD_DOWN_LEFT_EDGE\n LOAD_TOP_EDGE\n LOAD_TOP_RIGHT_EDGE\n src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3;\n src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3;\n src[2+0*stride]=\n src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3;\n src[3+0*stride]=\n src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3;\n src[2+1*stride]=\n src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3;\n src[3+1*stride]=\n src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3;\n src[3+2*stride]=\n src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2;\n src[0+3*stride]=\n src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2;\n src[2+3*stride]=(l4 + l5 + 1)>>1;\n src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2;\n}'] |
D2A: A Dataset Built for AI-Based Vulnerability Detection Methods Using Differential Analysis
This is an unofficial HuggingFace upload of the D2A dataset from "D2A: A Dataset Built for AI-Based Vulnerability Detection Methods Using Differential Analysis". "Test" splits have all labels as -1 as they are not provided.
Usage:
from datasets import load_dataset
# Use "code", "code_trace", "function", or "trace" to load the different variants.
dataset = load_dataset("claudios/D2A", "code")
D2A Leaderboard Data
This document describes D2A V1 Leaderboard data. You can download them from the Leaderboard section of the D2A Dataset page. To begin download directly you can click here.
Source files:
The files were created using the default security errors of datasets Libav, OpenSSL, Nginx, Httpd and Libtiff from D2A.
There are 4 directories corresponding to 4 tasks of the leaderboard. Each directory contains 3 csv files corresponding to the train (80%), dev (10%) and test (10%) split. The columns in the split files are identical except the test split which does not contain the label column.
Columns:
- id: A unique id for every example in a task.
- label: Values are 0 or 1.
- Value 0: No vulnerability/defect in the example.
- Value 1: Example contains some vulnerability/defect.
- trace: Bug trace or bug report generated by Infer static analyzer. Infer predictions contain a lot of False positives which is why even 0 label examples have a bug report.
- bug_function/code: Full source code of the function where the vulnerability originates.
- bug_url: URL of the file which contains the bug_function.
- functions: Full source code of all the functions in the bug trace, with the duplicates removed. This will include the function in bug_function.
Default Security Errors:
These are security errors enabled by default by Infer.
- BIABD_USE_AFTER_FREE
- BUFFER_OVERRUN_L1
- BUFFER_OVERRUN_L2
- BUFFER_OVERRUN_L3
- BUFFER_OVERRUN_R2
- BUFFER_OVERRUN_S2
- BUFFER_OVERRUN_T1
- INTEGER_OVERFLOW_L1
- INTEGER_OVERFLOW_L2
- INTEGER_OVERFLOW_R2
- MEMORY_LEAK
- NULL_DEREFERENCE
- RESOURCE_LEAK
- LAB_RESOURCE_LEAK
- UNINITIALIZED_VALUE
- USE_AFTER_DELETE
- USE_AFTER_FREE
- USE_AFTER_LIFETIME
Data Examples:
- Trace:
Offset: [4, +oo] (‚áê [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul`.
Showing all 12 steps of the trace
test/bntest.c:1798:10: Call
1796.
1797. /* Test that BN_mul never gives negative zero. */
1798. if (!BN_set_word(a, 1))
^
1799. goto err;
1800. BN_set_negative(a, 1);
crypto/bn/bn_lib.c:463:1: Parameter `*a->d`
461. }
462.
463. > int BN_set_word(BIGNUM *a, BN_ULONG w)
464. {
465. bn_check_top(a);
crypto/bn/bn_lib.c:466:9: Call
464. {
465. bn_check_top(a);
466. if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
^
467. return (0);
468. a->neg = 0;
crypto/bn/bn_lcl.h:676:1: Parameter `*a->d`
674. int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx);
675.
676. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
677. {
678. if (bits > (INT_MAX - BN_BITS2 + 1))
test/bntest.c:1802:10: Call
1800. BN_set_negative(a, 1);
1801. BN_zero(b);
1802. if (!BN_mul(c, a, b, ctx))
^
1803. goto err;
1804. if (!BN_is_zero(c) || BN_is_negative(c)) {
crypto/bn/bn_mul.c:828:1: Parameter `*b->d`
826. #endif /* BN_RECURSION */
827.
828. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
829. {
830. int ret = 0;
crypto/bn/bn_mul.c:909:17: Call
907. if (bn_wexpand(rr, k * 4) == NULL)
908. goto err;
909. bn_mul_part_recursive(rr->d, a->d, b->d,
^
910. j, al - j, bl - j, t->d);
911. } else { /* al <= j || bl <= j */
crypto/bn/bn_mul.c:480:1: Parameter `*b`
478. */
479. /* tnX may not be negative but less than n */
480. > void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
481. int tna, int tnb, BN_ULONG *t)
482. {
crypto/bn/bn_mul.c:488:9: Call
486.
487. if (n < 8) {
488. bn_mul_normal(r, a, n + tna, b, n + tnb);
^
489. return;
490. }
crypto/bn/bn_mul.c:983:1: <Length trace>
981. }
982.
983. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
984. {
985. BN_ULONG *rr;
crypto/bn/bn_mul.c:983:1: Parameter `*b`
981. }
982.
983. > void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
984. {
985. BN_ULONG *rr;
crypto/bn/bn_mul.c:1018:50: Array access: Offset: [4, +oo] (‚áê [0, +oo] + 4) Size: [0, 8388607] by call to `BN_mul`
1016. if (--nb <= 0)
1017. return;
1018. rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
^
1019. rr += 4;
1020. r += 4;
"
- Bug URL:
https://github.com/openssl/openssl/blob/0282aeb690d63fab73a07191b63300a2fe30d212/crypto/bn/bn_mul.c/#L1018
- Bug Function:
"void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
{
BN_ULONG *rr;
if (na < nb) {
int itmp;
BN_ULONG *ltmp;
itmp = na;
na = nb;
nb = itmp;
ltmp = a;
a = b;
b = ltmp;
}
rr = &(r[na]);
if (nb <= 0) {
(void)bn_mul_words(r, a, na, 0);
return;
} else
rr[0] = bn_mul_words(r, a, na, b[0]);
for (;;) {
if (--nb <= 0)
return;
rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);
if (--nb <= 0)
return;
rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);
if (--nb <= 0)
return;
rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);
if (--nb <= 0)
return;
rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);
rr += 4;
r += 4;
b += 4;
}
}"
- Functions:
[
'static int test_negzero() {
BIGNUM * a = BN_new();
BIGNUM * b = BN_new();
BIGNUM * c = BN_new();
BIGNUM * d = BN_new();
BIGNUM * numerator = NULL, * denominator = NULL;
int consttime, st = 0;
if (a == NULL || b == NULL || c == NULL || d == NULL) goto err;
if (!BN_set_word(a, 1)) goto err;
BN_set_negative(a, 1);
BN_zero(b);
if (!BN_mul(c, a, b, ctx)) goto err;
if (!BN_is_zero(c) || BN_is_negative(c)) {
fprintf(stderr, "Multiplication test failed!");
goto err;
}
for (consttime = 0; consttime < 2; consttime++) {
numerator = BN_new();
denominator = BN_new();
if (numerator == NULL || denominator == NULL) goto err;
if (consttime) {
BN_set_flags(numerator, BN_FLG_CONSTTIME);
BN_set_flags(denominator, BN_FLG_CONSTTIME);
}
if (!BN_set_word(numerator, 1) || !BN_set_word(denominator, 2)) goto err;
BN_set_negative(numerator, 1);
if (!BN_div(a, b, numerator, denominator, ctx)) goto err;
if (!BN_is_zero(a) || BN_is_negative(a)) {
fprintf(stderr, "Incorrect quotient (consttime = %d).", consttime);
goto err;
}
if (!BN_set_word(denominator, 1)) goto err;
if (!BN_div(a, b, numerator, denominator, ctx)) goto err;
if (!BN_is_zero(b) || BN_is_negative(b)) {
fprintf(stderr, "Incorrect remainder (consttime = %d).", consttime);
goto err;
}
BN_free(numerator);
BN_free(denominator);
numerator = denominator = NULL;
}
BN_zero(a);
BN_set_negative(a, 1);
if (BN_is_negative(a)) {
fprintf(stderr, "BN_set_negative produced a negative zero.");
goto err;
}
st = 1;
err: BN_free(a);
BN_free(b);
BN_free(c);
BN_free(d);
BN_free(numerator);
BN_free(denominator);
return st;
}',
'int BN_set_word(BIGNUM * a, BN_ULONG w) {
bn_check_top(a);
if (bn_expand(a, (int) sizeof(BN_ULONG) * 8) == NULL) return (0);
a -> neg = 0;
a -> d[0] = w;
a -> top = (w ? 1 : 0);
bn_check_top(a);
return (1);
}',
'static ossl_inline BIGNUM * bn_expand(BIGNUM * a, int bits) {
if (bits > (INT_MAX - BN_BITS2 + 1)) return NULL;
if (((bits + BN_BITS2 - 1) / BN_BITS2) <= (a) -> dmax) return a;
return bn_expand2((a), (bits + BN_BITS2 - 1) / BN_BITS2);
}',
'int BN_mul(BIGNUM * r,
const BIGNUM * a,
const BIGNUM * b, BN_CTX * ctx) {
int ret = 0;
int top, al, bl;
BIGNUM * rr;
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) int i;
#endif #ifdef BN_RECURSION BIGNUM * t = NULL;
int j = 0, k;
#endif bn_check_top(a);
bn_check_top(b);
bn_check_top(r);
al = a -> top;
bl = b -> top;
if ((al == 0) || (bl == 0)) {
BN_zero(r);
return (1);
}
top = al + bl;
BN_CTX_start(ctx);
if ((r == a) || (r == b)) {
if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
} else rr = r;
rr -> neg = a -> neg ^ b -> neg;
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) i = al - bl;
#endif #ifdef BN_MUL_COMBA
if (i == 0) {
#
if 0
if (al == 4) {
if (bn_wexpand(rr, 8) == NULL) goto err;
rr -> top = 8;
bn_mul_comba4(rr -> d, a -> d, b -> d);
goto end;
}
# endif
if (al == 8) {
if (bn_wexpand(rr, 16) == NULL) goto err;
rr -> top = 16;
bn_mul_comba8(rr -> d, a -> d, b -> d);
goto end;
}
}
#endif #ifdef BN_RECURSION
if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {
if (i >= -1 && i <= 1) {
if (i >= 0) {
j = BN_num_bits_word((BN_ULONG) al);
}
if (i == -1) {
j = BN_num_bits_word((BN_ULONG) bl);
}
j = 1 << (j - 1);
assert(j <= al || j <= bl);
k = j + j;
t = BN_CTX_get(ctx);
if (t == NULL) goto err;
if (al > j || bl > j) {
if (bn_wexpand(t, k * 4) == NULL) goto err;
if (bn_wexpand(rr, k * 4) == NULL) goto err;
bn_mul_part_recursive(rr -> d, a -> d, b -> d, j, al - j, bl - j, t -> d);
} else {
if (bn_wexpand(t, k * 2) == NULL) goto err;
if (bn_wexpand(rr, k * 2) == NULL) goto err;
bn_mul_recursive(rr -> d, a -> d, b -> d, j, al - j, bl - j, t -> d);
}
rr -> top = top;
goto end;
}
#
if 0
if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BIGNUM * tmp_bn = (BIGNUM * ) b;
if (bn_wexpand(tmp_bn, al) == NULL) goto err;
tmp_bn -> d[bl] = 0;
bl++;
i--;
} else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {
BIGNUM * tmp_bn = (BIGNUM * ) a;
if (bn_wexpand(tmp_bn, bl) == NULL) goto err;
tmp_bn -> d[al] = 0;
al++;
i++;
}
if (i == 0) {
j = BN_num_bits_word((BN_ULONG) al);
j = 1 << (j - 1);
k = j + j;
t = BN_CTX_get(ctx);
if (al == j) {
if (bn_wexpand(t, k * 2) == NULL) goto err;
if (bn_wexpand(rr, k * 2) == NULL) goto err;
bn_mul_recursive(rr -> d, a -> d, b -> d, al, t -> d);
} else {
if (bn_wexpand(t, k * 4) == NULL) goto err;
if (bn_wexpand(rr, k * 4) == NULL) goto err;
bn_mul_part_recursive(rr -> d, a -> d, b -> d, al - j, j, t -> d);
}
rr -> top = top;
goto end;
}
# endif
}
#endif
if (bn_wexpand(rr, top) == NULL) goto err;
rr -> top = top;
bn_mul_normal(rr -> d, a -> d, al, b -> d, bl);
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) end: #endif bn_correct_top(rr);
if (r != rr && BN_copy(r, rr) == NULL) goto err;
ret = 1;
err: bn_check_top(r);
BN_CTX_end(ctx);
return (ret);
}',
'void bn_mul_part_recursive(BN_ULONG * r, BN_ULONG * a, BN_ULONG * b, int n, int tna, int tnb, BN_ULONG * t) {
int i, j, n2 = n * 2;
int c1, c2, neg;
BN_ULONG ln, lo, * p;
if (n < 8) {
bn_mul_normal(r, a, n + tna, b, n + tnb);
return;
}
c1 = bn_cmp_part_words(a, & (a[n]), tna, n - tna);
c2 = bn_cmp_part_words( & (b[n]), b, tnb, tnb - n);
neg = 0;
switch (c1 * 3 + c2) {
case -4:
bn_sub_part_words(t, & (a[n]), a, tna, tna - n);
bn_sub_part_words( & (t[n]), b, & (b[n]), tnb, n - tnb);
break;
case -3:
case -2:
bn_sub_part_words(t, & (a[n]), a, tna, tna - n);
bn_sub_part_words( & (t[n]), & (b[n]), b, tnb, tnb - n);
neg = 1;
break;
case -1:
case 0:
case 1:
case 2:
bn_sub_part_words(t, a, & (a[n]), tna, n - tna);
bn_sub_part_words( & (t[n]), b, & (b[n]), tnb, n - tnb);
neg = 1;
break;
case 3:
case 4:
bn_sub_part_words(t, a, & (a[n]), tna, n - tna);
bn_sub_part_words( & (t[n]), & (b[n]), b, tnb, tnb - n);
break;
}
#
if 0
if (n == 4) {
bn_mul_comba4( & (t[n2]), t, & (t[n]));
bn_mul_comba4(r, a, b);
bn_mul_normal( & (r[n2]), & (a[n]), tn, & (b[n]), tn);
memset( & r[n2 + tn * 2], 0, sizeof( * r) * (n2 - tn * 2));
} else # endif
if (n == 8) {
bn_mul_comba8( & (t[n2]), t, & (t[n]));
bn_mul_comba8(r, a, b);
bn_mul_normal( & (r[n2]), & (a[n]), tna, & (b[n]), tnb);
memset( & r[n2 + tna + tnb], 0, sizeof( * r) * (n2 - tna - tnb));
} else {
p = & (t[n2 * 2]);
bn_mul_recursive( & (t[n2]), t, & (t[n]), n, 0, 0, p);
bn_mul_recursive(r, a, b, n, 0, 0, p);
i = n / 2;
if (tna > tnb) j = tna - i;
else j = tnb - i;
if (j == 0) {
bn_mul_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
memset( & r[n2 + i * 2], 0, sizeof( * r) * (n2 - i * 2));
} else if (j > 0) {
bn_mul_part_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
memset( & (r[n2 + tna + tnb]), 0, sizeof(BN_ULONG) * (n2 - tna - tnb));
} else {
memset( & r[n2], 0, sizeof( * r) * n2);
if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {
bn_mul_normal( & (r[n2]), & (a[n]), tna, & (b[n]), tnb);
} else {
for (;;) {
i /= 2;
if (i < tna || i < tnb) {
bn_mul_part_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
break;
} else if (i == tna || i == tnb) {
bn_mul_recursive( & (r[n2]), & (a[n]), & (b[n]), i, tna - i, tnb - i, p);
break;
}
}
}
}
}
c1 = (int)(bn_add_words(t, r, & (r[n2]), n2));
if (neg) {
c1 -= (int)(bn_sub_words( & (t[n2]), t, & (t[n2]), n2));
} else {
c1 += (int)(bn_add_words( & (t[n2]), & (t[n2]), t, n2));
}
c1 += (int)(bn_add_words( & (r[n]), & (r[n]), & (t[n2]), n2));
if (c1) {
p = & (r[n + n2]);
lo = * p;
ln = (lo + c1) & BN_MASK2;* p = ln;
if (ln < (BN_ULONG) c1) {
do {
p++;
lo = * p;
ln = (lo + 1) & BN_MASK2;* p = ln;
} while (ln == 0);
}
}
}',
'void bn_mul_normal(BN_ULONG * r, BN_ULONG * a, int na, BN_ULONG * b, int nb) {
BN_ULONG * rr;
if (na < nb) {
int itmp;
BN_ULONG * ltmp;
itmp = na;
na = nb;
nb = itmp;
ltmp = a;
a = b;
b = ltmp;
}
rr = & (r[na]);
if (nb <= 0) {
(void) bn_mul_words(r, a, na, 0);
return;
} else rr[0] = bn_mul_words(r, a, na, b[0]);
for (;;) {
if (--nb <= 0) return;
rr[1] = bn_mul_add_words( & (r[1]), a, na, b[1]);
if (--nb <= 0) return;
rr[2] = bn_mul_add_words( & (r[2]), a, na, b[2]);
if (--nb <= 0) return;
rr[3] = bn_mul_add_words( & (r[3]), a, na, b[3]);
if (--nb <= 0) return;
rr[4] = bn_mul_add_words( & (r[4]), a, na, b[4]);
rr += 4;
r += 4;
b += 4;
}
}'
]
- Downloads last month
- 198