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,301
| 0
|
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L907
|
PUT_HEVC_QPEL_HV(3, 1)
|
['QPEL(12)', 'PUT_HEVC_QPEL_HV(3, 1)']
|
1,302
| 0
|
https://github.com/openssl/openssl/blob/972c87dfc7e765bd28a4964519c362f0d3a58ca4/crypto/bn/bn_lib.c/#L295
|
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->top = b->top;
a->neg = b->neg;
bn_check_top(a);
return a;
}
|
['BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,\n const BIGNUM *x, const BIGNUM *a, const BIGNUM *u)\n{\n BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL, *k = NULL, *K = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL\n || a == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n return NULL;\n if ((tmp = BN_new()) == NULL ||\n (tmp2 = BN_new()) == NULL ||\n (tmp3 = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, g, x, N, bn_ctx))\n goto err;\n if ((k = srp_Calc_k(N, g)) == NULL)\n goto err;\n if (!BN_mod_mul(tmp2, tmp, k, N, bn_ctx))\n goto err;\n if (!BN_mod_sub(tmp, B, tmp2, N, bn_ctx))\n goto err;\n if (!BN_mul(tmp3, u, x, bn_ctx))\n goto err;\n if (!BN_add(tmp2, a, tmp3))\n goto err;\n K = BN_new();\n if (K != NULL && !BN_mod_exp(K, tmp, tmp2, N, bn_ctx)) {\n BN_free(K);\n K = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n BN_clear_free(tmp2);\n BN_clear_free(tmp3);\n BN_free(k);\n return K;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'static BIGNUM *srp_Calc_k(const BIGNUM *N, const BIGNUM *g)\n{\n return srp_Calc_xy(N, g, N);\n}', 'static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N)\n{\n unsigned char digest[SHA_DIGEST_LENGTH];\n unsigned char *tmp = NULL;\n int numN = BN_num_bytes(N);\n BIGNUM *res = NULL;\n if (x != N && BN_ucmp(x, N) >= 0)\n return NULL;\n if (y != N && BN_ucmp(y, N) >= 0)\n return NULL;\n if ((tmp = OPENSSL_malloc(numN * 2)) == NULL)\n goto err;\n if (BN_bn2binpad(x, tmp, numN) < 0\n || BN_bn2binpad(y, tmp + numN, numN) < 0\n || !EVP_Digest(tmp, numN * 2, digest, NULL, EVP_sha1(), NULL))\n goto err;\n res = BN_bin2bn(digest, sizeof(digest), NULL);\n err:\n OPENSSL_free(tmp);\n return res;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n int i = a->top - 1;\n bn_check_top(a);\n if (BN_is_zero(a))\n return 0;\n return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_sub(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return ret;\n}', '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->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,303
| 0
|
https://github.com/openssl/openssl/blob/f2d9a32cf47ed8c4e4d025a2258154f3dbe5eca6/crypto/lhash/lhash.c/#L243
|
char *lh_delete(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free((char *)nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)\n\t{\n\tint ret=0;\n\tSSL_SESSION *s;\n\tCRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);\n\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\ts=(SSL_SESSION *)lh_insert(ctx->sessions,(char *)c);\n\tif (s != NULL && s != c)\n\t\t{\n\t\tSSL_SESSION_list_remove(ctx,s);\n\t\tSSL_SESSION_free(s);\n\t\ts = NULL;\n\t\t}\n\tif (s == NULL)\n\t\tSSL_SESSION_list_add(ctx,c);\n\tif (s != NULL)\n\t\t{\n\t\tSSL_SESSION_free(s);\n\t\tret=0;\n\t\t}\n\telse\n\t\t{\n\t\tret=1;\n\t\tif (SSL_CTX_sess_get_cache_size(ctx) > 0)\n\t\t\t{\n\t\t\twhile (SSL_CTX_sess_number(ctx) >\n\t\t\t\tSSL_CTX_sess_get_cache_size(ctx))\n\t\t\t\t{\n\t\t\t\tif (!remove_session_lock(ctx,\n\t\t\t\t\tctx->session_cache_tail, 0))\n\t\t\t\t\tbreak;\n\t\t\t\telse\n\t\t\t\t\tctx->stats.sess_cache_full++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\treturn(ret);\n\t}', 'char *lh_insert(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\tif (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))\n\t\texpand(lh);\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tif ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn(NULL);\n\t\t\t}\n\t\tnn->data=data;\n\t\tnn->next=NULL;\n#ifndef NO_HASH_COMP\n\t\tnn->hash=hash;\n#endif\n\t\t*rn=nn;\n\t\tret=NULL;\n\t\tlh->num_insert++;\n\t\tlh->num_items++;\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\t(*rn)->data=data;\n\t\tlh->num_replace++;\n\t\t}\n\treturn(ret);\n\t}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
|
1,304
| 0
|
https://github.com/openssl/openssl/blob/95ed0e7c1f4206191c1b0288e352010e70e252db/crypto/x509/x509_req.c/#L126
|
int X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)
{
EVP_PKEY *xk = NULL;
int ok = 0;
xk = X509_REQ_get_pubkey(x);
switch (EVP_PKEY_cmp(xk, k)) {
case 1:
ok = 1;
break;
case 0:
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,
X509_R_KEY_VALUES_MISMATCH);
break;
case -1:
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_KEY_TYPE_MISMATCH);
break;
case -2:
#ifndef OPENSSL_NO_EC
if (k->type == EVP_PKEY_EC) {
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);
break;
}
#endif
#ifndef OPENSSL_NO_DH
if (k->type == EVP_PKEY_DH) {
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,
X509_R_CANT_CHECK_DH_KEY);
break;
}
#endif
X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_UNKNOWN_KEY_TYPE);
}
EVP_PKEY_free(xk);
return (ok);
}
|
['int X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)\n{\n EVP_PKEY *xk = NULL;\n int ok = 0;\n xk = X509_REQ_get_pubkey(x);\n switch (EVP_PKEY_cmp(xk, k)) {\n case 1:\n ok = 1;\n break;\n case 0:\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,\n X509_R_KEY_VALUES_MISMATCH);\n break;\n case -1:\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_KEY_TYPE_MISMATCH);\n break;\n case -2:\n#ifndef OPENSSL_NO_EC\n if (k->type == EVP_PKEY_EC) {\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);\n break;\n }\n#endif\n#ifndef OPENSSL_NO_DH\n if (k->type == EVP_PKEY_DH) {\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,\n X509_R_CANT_CHECK_DH_KEY);\n break;\n }\n#endif\n X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, X509_R_UNKNOWN_KEY_TYPE);\n }\n EVP_PKEY_free(xk);\n return (ok);\n}', 'EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)\n{\n if (req == NULL)\n return (NULL);\n return (X509_PUBKEY_get(req->req_info.pubkey));\n}', 'int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)\n{\n if (a->type != b->type)\n return -1;\n if (a->ameth) {\n int ret;\n if (a->ameth->param_cmp) {\n ret = a->ameth->param_cmp(a, b);\n if (ret <= 0)\n return ret;\n }\n if (a->ameth->pub_cmp)\n return a->ameth->pub_cmp(a, b);\n }\n return -2;\n}']
|
1,305
| 0
|
https://github.com/openssl/openssl/blob/0f3e6045898e9aa5d0249e61c874b1f153ae54fa/crypto/asn1/x_name.c/#L256
|
void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)
{
if (a == NULL) return;
ASN1_OBJECT_free(a->object);
ASN1_BIT_STRING_free(a->value);
Free(a);
}
|
['X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length)\n\t{\n\tint set=0,i;\n\tint idx=0;\n\tunsigned char *orig;\n\tM_ASN1_D2I_vars(a,X509_NAME *,X509_NAME_new);\n\torig= *pp;\n\tif (sk_X509_NAME_ENTRY_num(ret->entries) > 0)\n\t\t{\n\t\twhile (sk_X509_NAME_ENTRY_num(ret->entries) > 0)\n\t\t\tX509_NAME_ENTRY_free(\n\t\t\t\t sk_X509_NAME_ENTRY_pop(ret->entries));\n\t\t}\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tfor (;;)\n\t\t{\n\t\tif (M_ASN1_D2I_end_sequence()) break;\n\t\tM_ASN1_D2I_get_set_type(X509_NAME_ENTRY,ret->entries,\n\t\t\t\t\td2i_X509_NAME_ENTRY,\n\t\t\t\t\tX509_NAME_ENTRY_free);\n\t\tfor (; idx < sk_X509_NAME_ENTRY_num(ret->entries); idx++)\n\t\t\t{\n\t\t\tsk_X509_NAME_ENTRY_value(ret->entries,idx)->set=set;\n\t\t\t}\n\t\tset++;\n\t\t}\n\ti=(int)(c.p-orig);\n\tif (!BUF_MEM_grow(ret->bytes,i)) goto err;\n\tmemcpy(ret->bytes->data,orig,i);\n\tret->bytes->length=i;\n\tret->modified=0;\n\tM_ASN1_D2I_Finish(a,X509_NAME_free,ASN1_F_D2I_X509_NAME);\n\t}', 'void X509_NAME_ENTRY_free(X509_NAME_ENTRY *a)\n\t{\n\tif (a == NULL) return;\n\tASN1_OBJECT_free(a->object);\n\tASN1_BIT_STRING_free(a->value);\n\tFree(a);\n\t}']
|
1,306
| 0
|
https://github.com/openssl/openssl/blob/43a0449fe6ce18b750803be8a115a412a7235496/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\n const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)\n{\n BIGNUM *t;\n int found = 0;\n int i, j, c1 = 0;\n BN_CTX *ctx = NULL;\n prime_t *mods = NULL;\n int checks = BN_prime_checks_for_size(bits);\n if (bits < 2) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n } else if (bits == 2 && safe) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);\n if (mods == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n loop:\n if (add == NULL) {\n if (!probable_prime(ret, bits, mods))\n goto err;\n } else {\n if (safe) {\n if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))\n goto err;\n } else {\n if (!bn_probable_prime_dh(ret, bits, add, rem, ctx))\n goto err;\n }\n }\n if (!BN_GENCB_call(cb, 0, c1++))\n goto err;\n if (!safe) {\n i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);\n if (i == -1)\n goto err;\n if (i == 0)\n goto loop;\n } else {\n if (!BN_rshift1(t, ret))\n goto err;\n for (i = 0; i < checks; i++) {\n j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n if (!BN_GENCB_call(cb, 2, c1 - 1))\n goto err;\n }\n }\n found = 1;\n err:\n OPENSSL_free(mods);\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n bn_check_top(ret);\n return found;\n}', 'int bn_probable_prime_dh(BIGNUM *rnd, int bits,\n const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *t1;\n BN_CTX_start(ctx);\n if ((t1 = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_rand(rnd, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n goto err;\n if (!BN_mod(t1, rnd, add, ctx))\n goto err;\n if (!BN_sub(rnd, rnd, t1))\n goto err;\n if (rem == NULL) {\n if (!BN_add_word(rnd, 1))\n goto err;\n } else {\n if (!BN_add(rnd, rnd, rem))\n goto err;\n }\n loop:\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(rnd, (BN_ULONG)primes[i]);\n if (mod == (BN_ULONG)-1)\n goto err;\n if (mod <= 1) {\n if (!BN_add(rnd, rnd, add))\n goto err;\n goto loop;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(rnd);\n return (ret);\n}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n{\n return bnrand(0, rnd, bits, top, bottom);\n}', 'static int bnrand(int testing, BIGNUM *rnd, int bits, int top, int bottom)\n{\n unsigned char *buf = NULL;\n int ret = 0, bit, bytes, mask;\n time_t tim;\n if (bits == 0) {\n if (top != BN_RAND_TOP_ANY || bottom != BN_RAND_BOTTOM_ANY)\n goto toosmall;\n BN_zero(rnd);\n return 1;\n }\n if (bits < 0 || (bits == 1 && top > 0))\n goto toosmall;\n bytes = (bits + 7) / 8;\n bit = (bits - 1) % 8;\n mask = 0xff << (bit + 1);\n buf = OPENSSL_malloc(bytes);\n if (buf == NULL) {\n BNerr(BN_F_BNRAND, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n time(&tim);\n RAND_add(&tim, sizeof(tim), 0.0);\n if (RAND_bytes(buf, bytes) <= 0)\n goto err;\n if (testing) {\n int i;\n unsigned char c;\n for (i = 0; i < bytes; i++) {\n if (RAND_bytes(&c, 1) <= 0)\n goto err;\n if (c >= 128 && i > 0)\n buf[i] = buf[i - 1];\n else if (c < 42)\n buf[i] = 0;\n else if (c < 84)\n buf[i] = 255;\n }\n }\n if (top >= 0) {\n if (top) {\n if (bit == 0) {\n buf[0] = 1;\n buf[1] |= 0x80;\n } else {\n buf[0] |= (3 << (bit - 1));\n }\n } else {\n buf[0] |= (1 << bit);\n }\n }\n buf[0] &= ~mask;\n if (bottom)\n buf[bytes - 1] |= 1;\n if (!BN_bin2bn(buf, bytes, rnd))\n goto err;\n ret = 1;\n err:\n OPENSSL_clear_free(buf, bytes);\n bn_check_top(rnd);\n return (ret);\ntoosmall:\n BNerr(BN_F_BNRAND, BN_R_BITS_TOO_SMALL);\n return 0;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,307
| 0
|
https://github.com/libav/libav/blob/22a3212e32b696028e21f00871f3cb48c044029d/libavformat/utils.c/#L2597
|
void avformat_free_context(AVFormatContext *s)
{
int i;
AVStream *st;
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_metadata_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
#if FF_API_OLD_METADATA
av_free(st->filename);
#endif
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
#if FF_API_OLD_METADATA
av_freep(&s->programs[i]->provider_name);
av_freep(&s->programs[i]->name);
#endif
av_metadata_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
#if FF_API_OLD_METADATA
av_free(s->chapters[s->nb_chapters]->title);
#endif
av_metadata_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_metadata_free(&s->metadata);
av_freep(&s->key);
av_free(s);
}
|
['static int read_ffserver_streams(AVFormatContext *s, const char *filename)\n{\n int i, err;\n AVFormatContext *ic;\n int nopts = 0;\n err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL);\n if (err < 0)\n return err;\n s->nb_streams = 0;\n for(i=0;i<ic->nb_streams;i++) {\n AVStream *st;\n AVCodec *codec;\n s->nb_streams++;\n st = av_mallocz(sizeof(AVStream));\n memcpy(st, ic->streams[i], sizeof(AVStream));\n st->codec = avcodec_alloc_context();\n if (!st->codec) {\n print_error(filename, AVERROR(ENOMEM));\n ffmpeg_exit(1);\n }\n avcodec_copy_context(st->codec, ic->streams[i]->codec);\n s->streams[i] = st;\n codec = avcodec_find_encoder(st->codec->codec_id);\n if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n if (audio_stream_copy) {\n st->stream_copy = 1;\n } else\n choose_sample_fmt(st, codec);\n } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n if (video_stream_copy) {\n st->stream_copy = 1;\n } else\n choose_pixel_fmt(st, codec);\n }\n if(st->codec->flags & CODEC_FLAG_BITEXACT)\n nopts = 1;\n new_output_stream(s, nb_output_files);\n }\n if (!nopts)\n s->timestamp = av_gettime();\n av_close_input_file(ic);\n return 0;\n}', 'void av_close_input_file(AVFormatContext *s)\n{\n AVIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb;\n av_close_input_stream(s);\n if (pb)\n avio_close(pb);\n}', 'void av_close_input_stream(AVFormatContext *s)\n{\n flush_packet_queue(s);\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n avformat_free_context(s);\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_metadata_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n#if FF_API_OLD_METADATA\n av_free(st->filename);\n#endif\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n#if FF_API_OLD_METADATA\n av_freep(&s->programs[i]->provider_name);\n av_freep(&s->programs[i]->name);\n#endif\n av_metadata_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n#if FF_API_OLD_METADATA\n av_free(s->chapters[s->nb_chapters]->title);\n#endif\n av_metadata_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_metadata_free(&s->metadata);\n av_freep(&s->key);\n av_free(s);\n}']
|
1,308
| 0
|
https://github.com/openssl/openssl/blob/0818dbadf32d193973d84a0736c099166777c071/ssl/t1_lib.c/#L3962
|
DH *ssl_get_auto_dh(SSL *s)
{
int dh_secbits = 80;
if (s->cert->dh_tmp_auto == 2)
return DH_get_1024_160();
if (s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL | SSL_aPSK)) {
if (s->s3->tmp.new_cipher->strength_bits == 256)
dh_secbits = 128;
else
dh_secbits = 80;
} else {
CERT_PKEY *cpk = ssl_get_server_send_pkey(s);
dh_secbits = EVP_PKEY_security_bits(cpk->privatekey);
}
if (dh_secbits >= 128) {
DH *dhp = DH_new();
BIGNUM *p, *g;
if (dhp == NULL)
return NULL;
g = BN_new();
if (g != NULL)
BN_set_word(g, 2);
if (dh_secbits >= 192)
p = BN_get_rfc3526_prime_8192(NULL);
else
p = BN_get_rfc3526_prime_3072(NULL);
if (p == NULL || g == NULL || !DH_set0_pqg(dhp, p, NULL, g)) {
DH_free(dhp);
BN_free(p);
BN_free(g);
return NULL;
}
return dhp;
}
if (dh_secbits >= 112)
return DH_get_2048_224();
return DH_get_1024_160();
}
|
['DH *ssl_get_auto_dh(SSL *s)\n{\n int dh_secbits = 80;\n if (s->cert->dh_tmp_auto == 2)\n return DH_get_1024_160();\n if (s->s3->tmp.new_cipher->algorithm_auth & (SSL_aNULL | SSL_aPSK)) {\n if (s->s3->tmp.new_cipher->strength_bits == 256)\n dh_secbits = 128;\n else\n dh_secbits = 80;\n } else {\n CERT_PKEY *cpk = ssl_get_server_send_pkey(s);\n dh_secbits = EVP_PKEY_security_bits(cpk->privatekey);\n }\n if (dh_secbits >= 128) {\n DH *dhp = DH_new();\n BIGNUM *p, *g;\n if (dhp == NULL)\n return NULL;\n g = BN_new();\n if (g != NULL)\n BN_set_word(g, 2);\n if (dh_secbits >= 192)\n p = BN_get_rfc3526_prime_8192(NULL);\n else\n p = BN_get_rfc3526_prime_3072(NULL);\n if (p == NULL || g == NULL || !DH_set0_pqg(dhp, p, NULL, g)) {\n DH_free(dhp);\n BN_free(p);\n BN_free(g);\n return NULL;\n }\n return dhp;\n }\n if (dh_secbits >= 112)\n return DH_get_2048_224();\n return DH_get_1024_160();\n}', 'CERT_PKEY *ssl_get_server_send_pkey(SSL *s)\n{\n CERT *c;\n int i;\n c = s->cert;\n if (!s->s3 || !s->s3->tmp.new_cipher)\n return NULL;\n ssl_set_masks(s);\n i = ssl_get_server_cert_index(s);\n if (i < 0)\n return NULL;\n return &c->pkeys[i];\n}', 'static int ssl_get_server_cert_index(const SSL *s)\n{\n int idx;\n idx = ssl_cipher_get_cert_index(s->s3->tmp.new_cipher);\n if (idx == SSL_PKEY_RSA_ENC && !s->cert->pkeys[SSL_PKEY_RSA_ENC].x509)\n idx = SSL_PKEY_RSA_SIGN;\n if (idx == SSL_PKEY_GOST_EC) {\n if (s->cert->pkeys[SSL_PKEY_GOST12_512].x509)\n idx = SSL_PKEY_GOST12_512;\n else if (s->cert->pkeys[SSL_PKEY_GOST12_256].x509)\n idx = SSL_PKEY_GOST12_256;\n else if (s->cert->pkeys[SSL_PKEY_GOST01].x509)\n idx = SSL_PKEY_GOST01;\n else\n idx = -1;\n }\n if (idx == -1)\n SSLerr(SSL_F_SSL_GET_SERVER_CERT_INDEX, ERR_R_INTERNAL_ERROR);\n return idx;\n}', 'int ssl_cipher_get_cert_index(const SSL_CIPHER *c)\n{\n uint32_t alg_a;\n alg_a = c->algorithm_auth;\n if (alg_a & SSL_aECDSA)\n return SSL_PKEY_ECC;\n else if (alg_a & SSL_aDSS)\n return SSL_PKEY_DSA_SIGN;\n else if (alg_a & SSL_aRSA)\n return SSL_PKEY_RSA_ENC;\n else if (alg_a & SSL_aGOST12)\n return SSL_PKEY_GOST_EC;\n else if (alg_a & SSL_aGOST01)\n return SSL_PKEY_GOST01;\n return -1;\n}']
|
1,309
| 0
|
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bf/bf_skey.c/#L78
|
void BF_set_key(BF_KEY *key, size_t len, const unsigned char *data)
{
int i;
BF_LONG *p,ri,in[2];
const unsigned char *d,*end;
memcpy(key,&bf_init,sizeof(BF_KEY));
p=key->P;
if (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;
d=data;
end= &(data[len]);
for (i=0; i<(BF_ROUNDS+2); i++)
{
ri= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
ri<<=8;
ri|= *(d++);
if (d >= end) d=data;
p[i]^=ri;
}
in[0]=0L;
in[1]=0L;
for (i=0; i<(BF_ROUNDS+2); i+=2)
{
BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
p=key->S;
for (i=0; i<4*256; i+=2)
{
BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
}
|
['static int test(void)\n\t{\n\tunsigned char cbc_in[40],cbc_out[40],iv[8];\n\tint i,n,err=0;\n\tBF_KEY key;\n\tBF_LONG data[2];\n\tunsigned char out[8];\n\tBF_LONG len;\n#ifdef CHARSET_EBCDIC\n\tebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));\n#endif\n\tprintf("testing blowfish in raw ecb mode\\n");\n\tfor (n=0; n<2; n++)\n\t\t{\n#ifdef CHARSET_EBCDIC\n\t\tebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));\n#endif\n\t\tBF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);\n\t\tdata[0]=bf_plain[n][0];\n\t\tdata[1]=bf_plain[n][1];\n\t\tBF_encrypt(data,&key);\n\t\tif (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_encrypt error encrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)data[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)bf_cipher[n][i]);\n\t\t\terr=1;\n\t\t\tprintf("\\n");\n\t\t\t}\n\t\tBF_decrypt(&(data[0]),&key);\n\t\tif (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_encrypt error decrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)data[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<2; i++)\n\t\t\t\tprintf("%08lX ",(unsigned long)bf_plain[n][i]);\n\t\t\tprintf("\\n");\n\t\t\terr=1;\n\t\t\t}\n\t\t}\n\tprintf("testing blowfish in ecb mode\\n");\n\tfor (n=0; n<NUM_TESTS; n++)\n\t\t{\n\t\tBF_set_key(&key,8,ecb_data[n]);\n\t\tBF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT);\n\t\tif (memcmp(&(cipher_data[n][0]),out,8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_ecb_encrypt blowfish error encrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",out[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",cipher_data[n][i]);\n\t\t\terr=1;\n\t\t\tprintf("\\n");\n\t\t\t}\n\t\tBF_ecb_encrypt(out,out,&key,BF_DECRYPT);\n\t\tif (memcmp(&(plain_data[n][0]),out,8) != 0)\n\t\t\t{\n\t\t\tprintf("BF_ecb_encrypt error decrypting\\n");\n\t\t\tprintf("got :");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",out[i]);\n\t\t\tprintf("\\n");\n\t\t\tprintf("expected:");\n\t\t\tfor (i=0; i<8; i++)\n\t\t\t\tprintf("%02X ",plain_data[n][i]);\n\t\t\tprintf("\\n");\n\t\t\terr=1;\n\t\t\t}\n\t\t}\n\tprintf("testing blowfish set_key\\n");\n\tfor (n=1; n<KEY_TEST_NUM; n++)\n\t\t{\n\t\tBF_set_key(&key,n,key_test);\n\t\tBF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT);\n\t\tif (memcmp(out,&(key_out[i=n-1][0]),8) != 0)\n\t\t\t{\n\t\t\tprintf("blowfish setkey error\\n");\n\t\t\terr=1;\n\t\t\t}\n\t\t}\n\tprintf("testing blowfish in cbc mode\\n");\n\tlen=strlen(cbc_data)+1;\n\tBF_set_key(&key,16,cbc_key);\n\tmemset(cbc_in,0,sizeof cbc_in);\n\tmemset(cbc_out,0,sizeof cbc_out);\n\tmemcpy(iv,cbc_iv,sizeof iv);\n\tBF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len,\n\t\t&key,iv,BF_ENCRYPT);\n\tif (memcmp(cbc_out,cbc_ok,32) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("BF_cbc_encrypt encrypt error\\n");\n\t\tfor (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]);\n\t\t}\n\tmemcpy(iv,cbc_iv,8);\n\tBF_cbc_encrypt(cbc_out,cbc_in,len,\n\t\t&key,iv,BF_DECRYPT);\n\tif (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)\n\t\t{\n\t\tprintf("BF_cbc_encrypt decrypt error\\n");\n\t\terr=1;\n\t\t}\n\tprintf("testing blowfish in cfb64 mode\\n");\n\tBF_set_key(&key,16,cbc_key);\n\tmemset(cbc_in,0,40);\n\tmemset(cbc_out,0,40);\n\tmemcpy(iv,cbc_iv,8);\n\tn=0;\n\tBF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,\n\t\t&key,iv,&n,BF_ENCRYPT);\n\tBF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13,\n\t\t&key,iv,&n,BF_ENCRYPT);\n\tif (memcmp(cbc_out,cfb64_ok,(int)len) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("BF_cfb64_encrypt encrypt error\\n");\n\t\tfor (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);\n\t\t}\n\tn=0;\n\tmemcpy(iv,cbc_iv,8);\n\tBF_cfb64_encrypt(cbc_out,cbc_in,17,\n\t\t&key,iv,&n,BF_DECRYPT);\n\tBF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,\n\t\t&key,iv,&n,BF_DECRYPT);\n\tif (memcmp(cbc_in,cbc_data,(int)len) != 0)\n\t\t{\n\t\tprintf("BF_cfb64_encrypt decrypt error\\n");\n\t\terr=1;\n\t\t}\n\tprintf("testing blowfish in ofb64\\n");\n\tBF_set_key(&key,16,cbc_key);\n\tmemset(cbc_in,0,40);\n\tmemset(cbc_out,0,40);\n\tmemcpy(iv,cbc_iv,8);\n\tn=0;\n\tBF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n);\n\tBF_ofb64_encrypt((unsigned char *)&(cbc_data[13]),\n\t\t&(cbc_out[13]),len-13,&key,iv,&n);\n\tif (memcmp(cbc_out,ofb64_ok,(int)len) != 0)\n\t\t{\n\t\terr=1;\n\t\tprintf("BF_ofb64_encrypt encrypt error\\n");\n\t\tfor (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);\n\t\t}\n\tn=0;\n\tmemcpy(iv,cbc_iv,8);\n\tBF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n);\n\tBF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n);\n\tif (memcmp(cbc_in,cbc_data,(int)len) != 0)\n\t\t{\n\t\tprintf("BF_ofb64_encrypt decrypt error\\n");\n\t\terr=1;\n\t\t}\n\treturn(err);\n\t}', 'void BF_set_key(BF_KEY *key, size_t len, const unsigned char *data)\n\t{\n\tint i;\n\tBF_LONG *p,ri,in[2];\n\tconst unsigned char *d,*end;\n\tmemcpy(key,&bf_init,sizeof(BF_KEY));\n\tp=key->P;\n\tif (len > ((BF_ROUNDS+2)*4)) len=(BF_ROUNDS+2)*4;\n\td=data;\n\tend= &(data[len]);\n\tfor (i=0; i<(BF_ROUNDS+2); i++)\n\t\t{\n\t\tri= *(d++);\n\t\tif (d >= end) d=data;\n\t\tri<<=8;\n\t\tri|= *(d++);\n\t\tif (d >= end) d=data;\n\t\tri<<=8;\n\t\tri|= *(d++);\n\t\tif (d >= end) d=data;\n\t\tri<<=8;\n\t\tri|= *(d++);\n\t\tif (d >= end) d=data;\n\t\tp[i]^=ri;\n\t\t}\n\tin[0]=0L;\n\tin[1]=0L;\n\tfor (i=0; i<(BF_ROUNDS+2); i+=2)\n\t\t{\n\t\tBF_encrypt(in,key);\n\t\tp[i ]=in[0];\n\t\tp[i+1]=in[1];\n\t\t}\n\tp=key->S;\n\tfor (i=0; i<4*256; i+=2)\n\t\t{\n\t\tBF_encrypt(in,key);\n\t\tp[i ]=in[0];\n\t\tp[i+1]=in[1];\n\t\t}\n\t}']
|
1,310
| 0
|
https://github.com/openssl/openssl/blob/2864df8f9d3264e19b49a246e272fb513f4c1be3/crypto/bn/bn_ctx.c/#L270
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d;\n BIGNUM *val[TABLE_SIZE];\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_SIMPLE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul(d, val[0], val[0], m, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul(val[i], val[i - 1], d, m, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul(r, r, r, m, ctx))\n goto err;\n }\n if (!BN_mod_mul(r, r, val[wvalue >> 1], m, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n if (ctx == NULL)\n return;\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,311
| 0
|
https://github.com/libav/libav/blob/39bec05ed42e505d17877b0c23f16322f9b5883b/libavcodec/h264_mvpred.h/#L653
|
static void fill_decode_caches(H264Context *h, int mb_type)
{
int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
const uint8_t *left_block = h->left_block;
int i;
uint8_t *nnz;
uint8_t *nnz_cache;
topleft_xy = h->topleft_mb_xy;
top_xy = h->top_mb_xy;
topright_xy = h->topright_mb_xy;
left_xy[LTOP] = h->left_mb_xy[LTOP];
left_xy[LBOT] = h->left_mb_xy[LBOT];
topleft_type = h->topleft_type;
top_type = h->top_type;
topright_type = h->topright_type;
left_type[LTOP] = h->left_type[LTOP];
left_type[LBOT] = h->left_type[LBOT];
if (!IS_SKIP(mb_type)) {
if (IS_INTRA(mb_type)) {
int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
h->topleft_samples_available =
h->top_samples_available =
h->left_samples_available = 0xFFFF;
h->topright_samples_available = 0xEEEA;
if (!(top_type & type_mask)) {
h->topleft_samples_available = 0xB3FF;
h->top_samples_available = 0x33FF;
h->topright_samples_available = 0x26EA;
}
if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
if (IS_INTERLACED(mb_type)) {
if (!(left_type[LTOP] & type_mask)) {
h->topleft_samples_available &= 0xDFFF;
h->left_samples_available &= 0x5FFF;
}
if (!(left_type[LBOT] & type_mask)) {
h->topleft_samples_available &= 0xFF5F;
h->left_samples_available &= 0xFF5F;
}
} else {
int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride];
assert(left_xy[LTOP] == left_xy[LBOT]);
if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
h->topleft_samples_available &= 0xDF5F;
h->left_samples_available &= 0x5F5F;
}
}
} else {
if (!(left_type[LTOP] & type_mask)) {
h->topleft_samples_available &= 0xDF5F;
h->left_samples_available &= 0x5F5F;
}
}
if (!(topleft_type & type_mask))
h->topleft_samples_available &= 0x7FFF;
if (!(topright_type & type_mask))
h->topright_samples_available &= 0xFBFF;
if (IS_INTRA4x4(mb_type)) {
if (IS_INTRA4x4(top_type)) {
AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
} else {
h->intra4x4_pred_mode_cache[4 + 8 * 0] =
h->intra4x4_pred_mode_cache[5 + 8 * 0] =
h->intra4x4_pred_mode_cache[6 + 8 * 0] =
h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
}
for (i = 0; i < 2; i++) {
if (IS_INTRA4x4(left_type[LEFT(i)])) {
int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
} else {
h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
}
}
}
}
nnz_cache = h->non_zero_count_cache;
if (top_type) {
nnz = h->non_zero_count[top_xy];
AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
if (!h->chroma_y_shift) {
AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);
AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
} else {
AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);
AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
}
} else {
uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);
AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);
AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
}
for (i = 0; i < 2; i++) {
if (left_type[LEFT(i)]) {
nnz = h->non_zero_count[left_xy[LEFT(i)]];
nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
if (CHROMA444) {
nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
} else if (CHROMA422) {
nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
} else {
nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
}
} else {
nnz_cache[3 + 8 * 1 + 2 * 8 * i] =
nnz_cache[3 + 8 * 2 + 2 * 8 * i] =
nnz_cache[3 + 8 * 6 + 2 * 8 * i] =
nnz_cache[3 + 8 * 7 + 2 * 8 * i] =
nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64;
}
}
if (CABAC) {
if (top_type)
h->top_cbp = h->cbp_table[top_xy];
else
h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
if (left_type[LTOP]) {
h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
(((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
} else {
h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
}
}
if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {
int list;
int b_stride = h->b_stride;
for (list = 0; list < h->list_count; list++) {
int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
int8_t *ref = h->cur_pic.f.ref_index[list];
int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
int16_t(*mv)[2] = h->cur_pic.f.motion_val[list];
if (!USES_LIST(mb_type, list))
continue;
assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
if (USES_LIST(top_type, list)) {
const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
ref_cache[0 - 1 * 8] =
ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
ref_cache[2 - 1 * 8] =
ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
} else {
AV_ZERO128(mv_cache[0 - 1 * 8]);
AV_WN32A(&ref_cache[0 - 1 * 8],
((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
}
if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
for (i = 0; i < 2; i++) {
int cache_idx = -1 + i * 2 * 8;
if (USES_LIST(left_type[LEFT(i)], list)) {
const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
AV_COPY32(mv_cache[cache_idx],
mv[b_xy + b_stride * left_block[0 + i * 2]]);
AV_COPY32(mv_cache[cache_idx + 8],
mv[b_xy + b_stride * left_block[1 + i * 2]]);
ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
} else {
AV_ZERO32(mv_cache[cache_idx]);
AV_ZERO32(mv_cache[cache_idx + 8]);
ref_cache[cache_idx] =
ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
: PART_NOT_AVAILABLE;
}
}
} else {
if (USES_LIST(left_type[LTOP], list)) {
const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;
const int b8_xy = 4 * left_xy[LTOP] + 1;
AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
} else {
AV_ZERO32(mv_cache[-1]);
ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
: PART_NOT_AVAILABLE;
}
}
if (USES_LIST(topright_type, list)) {
const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
} else {
AV_ZERO32(mv_cache[4 - 1 * 8]);
ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
: PART_NOT_AVAILABLE;
}
if (ref_cache[4 - 1 * 8] < 0) {
if (USES_LIST(topleft_type, list)) {
const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +
(h->topleft_partition & 2 * b_stride);
const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);
AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
ref_cache[-1 - 1 * 8] = ref[b8_xy];
} else {
AV_ZERO32(mv_cache[-1 - 1 * 8]);
ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
: PART_NOT_AVAILABLE;
}
}
if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
continue;
if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
uint8_t(*mvd)[2] = h->mvd_table[list];
ref_cache[2 + 8 * 0] =
ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
AV_ZERO32(mv_cache[2 + 8 * 0]);
AV_ZERO32(mv_cache[2 + 8 * 2]);
if (CABAC) {
if (USES_LIST(top_type, list)) {
const int b_xy = h->mb2br_xy[top_xy];
AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
} else {
AV_ZERO64(mvd_cache[0 - 1 * 8]);
}
if (USES_LIST(left_type[LTOP], list)) {
const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
} else {
AV_ZERO16(mvd_cache[-1 + 0 * 8]);
AV_ZERO16(mvd_cache[-1 + 1 * 8]);
}
if (USES_LIST(left_type[LBOT], list)) {
const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
} else {
AV_ZERO16(mvd_cache[-1 + 2 * 8]);
AV_ZERO16(mvd_cache[-1 + 3 * 8]);
}
AV_ZERO16(mvd_cache[2 + 8 * 0]);
AV_ZERO16(mvd_cache[2 + 8 * 2]);
if (h->slice_type_nos == AV_PICTURE_TYPE_B) {
uint8_t *direct_cache = &h->direct_cache[scan8[0]];
uint8_t *direct_table = h->direct_table;
fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
if (IS_DIRECT(top_type)) {
AV_WN32A(&direct_cache[-1 * 8],
0x01010101u * (MB_TYPE_DIRECT2 >> 1));
} else if (IS_8X8(top_type)) {
int b8_xy = 4 * top_xy;
direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
} else {
AV_WN32A(&direct_cache[-1 * 8],
0x01010101 * (MB_TYPE_16x16 >> 1));
}
if (IS_DIRECT(left_type[LTOP]))
direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
else if (IS_8X8(left_type[LTOP]))
direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
else
direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
if (IS_DIRECT(left_type[LBOT]))
direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
else if (IS_8X8(left_type[LBOT]))
direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
else
direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
}
}
}
#define MAP_MVS \
MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \
MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \
MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \
MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \
MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \
MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \
MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \
MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \
MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \
MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
if (FRAME_MBAFF) {
if (MB_FIELD) {
#define MAP_F2F(idx, mb_type) \
if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
h->ref_cache[list][idx] <<= 1; \
h->mv_cache[list][idx][1] /= 2; \
h->mvd_cache[list][idx][1] >>= 1; \
}
MAP_MVS
} else {
#undef MAP_F2F
#define MAP_F2F(idx, mb_type) \
if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \
h->ref_cache[list][idx] >>= 1; \
h->mv_cache[list][idx][1] <<= 1; \
h->mvd_cache[list][idx][1] <<= 1; \
}
MAP_MVS
#undef MAP_F2F
}
}
}
}
h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
}
|
['static void fill_decode_caches(H264Context *h, int mb_type)\n{\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t *left_block = h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP] = h->left_type[LTOP];\n left_type[LBOT] = h->left_type[LBOT];\n if (!IS_SKIP(mb_type)) {\n if (IS_INTRA(mb_type)) {\n int type_mask = h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available =\n h->top_samples_available =\n h->left_samples_available = 0xFFFF;\n h->topright_samples_available = 0xEEEA;\n if (!(top_type & type_mask)) {\n h->topleft_samples_available = 0xB3FF;\n h->top_samples_available = 0x33FF;\n h->topright_samples_available = 0x26EA;\n }\n if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {\n if (IS_INTERLACED(mb_type)) {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDFFF;\n h->left_samples_available &= 0x5FFF;\n }\n if (!(left_type[LBOT] & type_mask)) {\n h->topleft_samples_available &= 0xFF5F;\n h->left_samples_available &= 0xFF5F;\n }\n } else {\n int left_typei = h->cur_pic.f.mb_type[left_xy[LTOP] + h->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n } else {\n if (!(left_type[LTOP] & type_mask)) {\n h->topleft_samples_available &= 0xDF5F;\n h->left_samples_available &= 0x5F5F;\n }\n }\n if (!(topleft_type & type_mask))\n h->topleft_samples_available &= 0x7FFF;\n if (!(topright_type & type_mask))\n h->topright_samples_available &= 0xFBFF;\n if (IS_INTRA4x4(mb_type)) {\n if (IS_INTRA4x4(top_type)) {\n AV_COPY32(h->intra4x4_pred_mode_cache + 4 + 8 * 0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n } else {\n h->intra4x4_pred_mode_cache[4 + 8 * 0] =\n h->intra4x4_pred_mode_cache[5 + 8 * 0] =\n h->intra4x4_pred_mode_cache[6 + 8 * 0] =\n h->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);\n }\n for (i = 0; i < 2; i++) {\n if (IS_INTRA4x4(left_type[LEFT(i)])) {\n int8_t *mode = h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];\n } else {\n h->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =\n h->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if (top_type) {\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);\n if (!h->chroma_y_shift) {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 7]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);\n } else {\n AV_COPY32(&nnz_cache[4 + 8 * 5], &nnz[4 * 5]);\n AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);\n }\n } else {\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty);\n AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty);\n AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);\n }\n for (i = 0; i < 2; i++) {\n if (left_type[LEFT(i)]) {\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];\n nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];\n if (CHROMA444) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];\n } else if (CHROMA422) {\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];\n } else {\n nnz_cache[3 + 8 * 6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];\n nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];\n }\n } else {\n nnz_cache[3 + 8 * 1 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 2 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 6 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 7 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 11 + 2 * 8 * i] =\n nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if (CABAC) {\n if (top_type)\n h->top_cbp = h->cbp_table[top_xy];\n else\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) |\n ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |\n (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)) {\n int list;\n int b_stride = h->b_stride;\n for (list = 0; list < h->list_count; list++) {\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = h->cur_pic.f.ref_index[list];\n int16_t(*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t(*mv)[2] = h->cur_pic.f.motion_val[list];\n if (!USES_LIST(mb_type, list))\n continue;\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;\n AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);\n ref_cache[0 - 1 * 8] =\n ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];\n ref_cache[2 - 1 * 8] =\n ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];\n } else {\n AV_ZERO128(mv_cache[0 - 1 * 8]);\n AV_WN32A(&ref_cache[0 - 1 * 8],\n ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);\n }\n if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {\n for (i = 0; i < 2; i++) {\n int cache_idx = -1 + i * 2 * 8;\n if (USES_LIST(left_type[LEFT(i)], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy = 4 * left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx],\n mv[b_xy + b_stride * left_block[0 + i * 2]]);\n AV_COPY32(mv_cache[cache_idx + 8],\n mv[b_xy + b_stride * left_block[1 + i * 2]]);\n ref_cache[cache_idx] = ref[b8_xy + (left_block[0 + i * 2] & ~1)];\n ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];\n } else {\n AV_ZERO32(mv_cache[cache_idx]);\n AV_ZERO32(mv_cache[cache_idx + 8]);\n ref_cache[cache_idx] =\n ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n } else {\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy = 4 * left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);\n ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];\n } else {\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if (USES_LIST(topright_type, list)) {\n const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;\n AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);\n ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];\n } else {\n AV_ZERO32(mv_cache[4 - 1 * 8]);\n ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n if (ref_cache[4 - 1 * 8] < 0) {\n if (USES_LIST(topleft_type, list)) {\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride +\n (h->topleft_partition & 2 * b_stride);\n const int b8_xy = 4 * topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);\n ref_cache[-1 - 1 * 8] = ref[b8_xy];\n } else {\n AV_ZERO32(mv_cache[-1 - 1 * 8]);\n ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED\n : PART_NOT_AVAILABLE;\n }\n }\n if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {\n uint8_t(*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t(*mvd)[2] = h->mvd_table[list];\n ref_cache[2 + 8 * 0] =\n ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2 + 8 * 0]);\n AV_ZERO32(mv_cache[2 + 8 * 2]);\n if (CABAC) {\n if (USES_LIST(top_type, list)) {\n const int b_xy = h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);\n } else {\n AV_ZERO64(mvd_cache[0 - 1 * 8]);\n }\n if (USES_LIST(left_type[LTOP], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 0 * 8]);\n AV_ZERO16(mvd_cache[-1 + 1 * 8]);\n }\n if (USES_LIST(left_type[LBOT], list)) {\n const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);\n } else {\n AV_ZERO16(mvd_cache[-1 + 2 * 8]);\n AV_ZERO16(mvd_cache[-1 + 3 * 8]);\n }\n AV_ZERO16(mvd_cache[2 + 8 * 0]);\n AV_ZERO16(mvd_cache[2 + 8 * 2]);\n if (h->slice_type_nos == AV_PICTURE_TYPE_B) {\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);\n if (IS_DIRECT(top_type)) {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101u * (MB_TYPE_DIRECT2 >> 1));\n } else if (IS_8X8(top_type)) {\n int b8_xy = 4 * top_xy;\n direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];\n direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];\n } else {\n AV_WN32A(&direct_cache[-1 * 8],\n 0x01010101 * (MB_TYPE_16x16 >> 1));\n }\n if (IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];\n else\n direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;\n if (IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;\n else if (IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];\n else\n direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;\n }\n }\n }\n#define MAP_MVS \\\n MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type) \\\n MAP_F2F(scan8[0] + 0 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 1 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 2 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 3 - 1 * 8, top_type) \\\n MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type) \\\n MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP]) \\\n MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT]) \\\n MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])\n if (FRAME_MBAFF) {\n if (MB_FIELD) {\n#define MAP_F2F(idx, mb_type) \\\n if (!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] <<= 1; \\\n h->mv_cache[list][idx][1] /= 2; \\\n h->mvd_cache[list][idx][1] >>= 1; \\\n }\n MAP_MVS\n } else {\n#undef MAP_F2F\n#define MAP_F2F(idx, mb_type) \\\n if (IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0) { \\\n h->ref_cache[list][idx] >>= 1; \\\n h->mv_cache[list][idx][1] <<= 1; \\\n h->mvd_cache[list][idx][1] <<= 1; \\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
|
1,312
| 0
|
https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/cook.c/#L344
|
static void decode_gain_info(BitstreamContext *bc, int *gaininfo)
{
int i, n;
while (bitstream_read_bit(bc)) {
}
n = bitstream_tell(bc) - 1;
i = 0;
while (n--) {
int index = bitstream_read(bc, 3);
int gain = bitstream_read_bit(bc) ? bitstream_read(bc, 4) - 7 : -1;
while (i <= index)
gaininfo[i++] = gain;
}
while (i <= 8)
gaininfo[i++] = 0;
}
|
['static void decode_gain_info(BitstreamContext *bc, int *gaininfo)\n{\n int i, n;\n while (bitstream_read_bit(bc)) {\n }\n n = bitstream_tell(bc) - 1;\n i = 0;\n while (n--) {\n int index = bitstream_read(bc, 3);\n int gain = bitstream_read_bit(bc) ? bitstream_read(bc, 4) - 7 : -1;\n while (i <= index)\n gaininfo[i++] = gain;\n }\n while (i <= 8)\n gaininfo[i++] = 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}']
|
1,313
| 0
|
https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/ssl/ssltest.c/#L453
|
static int cb_server_alpn(SSL *s, const unsigned char **out,
unsigned char *outlen, const unsigned char *in,
unsigned int inlen, void *arg)
{
unsigned char *protos;
unsigned short protos_len;
protos = next_protos_parse(&protos_len, alpn_server);
if (protos == NULL) {
fprintf(stderr, "failed to parser ALPN server protocol string: %s\n",
alpn_server);
abort();
}
if (SSL_select_next_proto
((unsigned char **)out, outlen, protos, protos_len, in,
inlen) != OPENSSL_NPN_NEGOTIATED) {
OPENSSL_free(protos);
return SSL_TLSEXT_ERR_NOACK;
}
alpn_selected = OPENSSL_malloc(*outlen);
memcpy(alpn_selected, *out, *outlen);
*out = alpn_selected;
OPENSSL_free(protos);
return SSL_TLSEXT_ERR_OK;
}
|
['static int cb_server_alpn(SSL *s, const unsigned char **out,\n unsigned char *outlen, const unsigned char *in,\n unsigned int inlen, void *arg)\n{\n unsigned char *protos;\n unsigned short protos_len;\n protos = next_protos_parse(&protos_len, alpn_server);\n if (protos == NULL) {\n fprintf(stderr, "failed to parser ALPN server protocol string: %s\\n",\n alpn_server);\n abort();\n }\n if (SSL_select_next_proto\n ((unsigned char **)out, outlen, protos, protos_len, in,\n inlen) != OPENSSL_NPN_NEGOTIATED) {\n OPENSSL_free(protos);\n return SSL_TLSEXT_ERR_NOACK;\n }\n alpn_selected = OPENSSL_malloc(*outlen);\n memcpy(alpn_selected, *out, *outlen);\n *out = alpn_selected;\n OPENSSL_free(protos);\n return SSL_TLSEXT_ERR_OK;\n}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n if (allow_customize)\n allow_customize = 0;\n if (malloc_debug_func != NULL) {\n if (allow_customize_debug)\n allow_customize_debug = 0;\n malloc_debug_func(NULL, num, file, line, 0);\n }\n ret = malloc_ex_func(num, file, line);\n#ifdef LEVITTE_DEBUG_MEM\n fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n if (malloc_debug_func != NULL)\n malloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}']
|
1,314
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L683
|
static int hex_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags, int dia_size)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
int x,y,d;
const int dec= dia_size & (dia_size-1);
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){
do{
x= best[0];
y= best[1];
CHECK_CLIPPED_MV(x -dia_size , y);
CHECK_CLIPPED_MV(x+ dia_size , y);
CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);
CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);
if(dia_size>1){
CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);
CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);
}
}while(best[0] != x || best[1] != y);
}
return dmin;
}
|
['static int hex_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags, int dia_size)\n{\n MotionEstContext * const c= &s->me;\n me_cmp_func cmpf, chroma_cmpf;\n LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n int x,y,d;\n const int dec= dia_size & (dia_size-1);\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n for(;dia_size; dia_size= dec ? dia_size-1 : dia_size>>1){\n do{\n x= best[0];\n y= best[1];\n CHECK_CLIPPED_MV(x -dia_size , y);\n CHECK_CLIPPED_MV(x+ dia_size , y);\n CHECK_CLIPPED_MV(x+( dia_size>>1), y+dia_size);\n CHECK_CLIPPED_MV(x+( dia_size>>1), y-dia_size);\n if(dia_size>1){\n CHECK_CLIPPED_MV(x+(-dia_size>>1), y+dia_size);\n CHECK_CLIPPED_MV(x+(-dia_size>>1), y-dia_size);\n }\n }while(best[0] != x || best[1] != y);\n }\n return dmin;\n}']
|
1,315
| 0
|
https://github.com/libav/libav/blob/1f09ab5e6665d0cae34fe4b378f16268e712e748/libavcodec/xan.c/#L100
|
static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,
int dest_len)
{
unsigned char byte = *src++;
unsigned char ival = byte + 0x16;
const unsigned char * ptr = src + byte*2;
unsigned char val = ival;
unsigned char *dest_end = dest + dest_len;
GetBitContext gb;
init_get_bits(&gb, ptr, 0);
while ( val != 0x16 ) {
val = src[val - 0x17 + get_bits1(&gb) * byte];
if ( val < 0x16 ) {
if (dest >= dest_end)
return 0;
*dest++ = val;
val = ival;
}
}
return 0;
}
|
['static int xan_huffman_decode(unsigned char *dest, const unsigned char *src,\n int dest_len)\n{\n unsigned char byte = *src++;\n unsigned char ival = byte + 0x16;\n const unsigned char * ptr = src + byte*2;\n unsigned char val = ival;\n unsigned char *dest_end = dest + dest_len;\n GetBitContext gb;\n init_get_bits(&gb, ptr, 0);\n while ( val != 0x16 ) {\n val = src[val - 0x17 + get_bits1(&gb) * byte];\n if ( val < 0x16 ) {\n if (dest >= dest_end)\n return 0;\n *dest++ = val;\n val = ival;\n }\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 LIBMPEG2_BITSTREAM_READER\n s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));\n s->bit_count = 16 + 8*((intptr_t)buffer&1);\n skip_bits_long(s, 0);\n#elif defined A32_BITSTREAM_READER\n s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));\n s->bit_count = 32 + 8*((intptr_t)buffer&3);\n skip_bits_long(s, 0);\n#endif\n}', 'static inline unsigned int get_bits1(GetBitContext *s){\n#ifdef ALT_BITSTREAM_READER\n int index= s->index;\n uint8_t result= s->buffer[ index>>3 ];\n#ifdef ALT_BITSTREAM_READER_LE\n result>>= (index&0x07);\n result&= 1;\n#else\n result<<= (index&0x07);\n result>>= 8 - 1;\n#endif\n index++;\n s->index= index;\n return result;\n#else\n return get_bits(s, 1);\n#endif\n}']
|
1,316
| 0
|
https://github.com/openssl/openssl/blob/14c6d27d63795ead1b70d97e3303731b433c0db8/crypto/ocsp/ocsp_res.c/#L247
|
int i2d_OCSP_RESPID(OCSP_RESPID *a, unsigned char **pp)
{
int v=0;
M_ASN1_I2D_vars(a);
switch (a->tag)
{
case V_OCSP_RESPID_NAME:
v = i2d_X509_NAME(a->value.byName,NULL);
ret += ASN1_object_size(1, v, V_OCSP_RESPID_NAME);
if (pp==NULL) return ret;
p=*pp;
ASN1_put_object(&p, 1, v,
V_OCSP_RESPID_NAME,
V_ASN1_CONTEXT_SPECIFIC);
i2d_X509_NAME(a->value.byName,&p);
break;
case V_OCSP_RESPID_KEY:
v = i2d_ASN1_OCTET_STRING(a->value.byKey,NULL);
ret += ASN1_object_size(1, v, V_OCSP_RESPID_KEY);
if (pp==NULL) return ret;
p=*pp;
ASN1_put_object(&p, 1, v,
V_OCSP_RESPID_KEY,
V_ASN1_CONTEXT_SPECIFIC);
i2d_ASN1_OCTET_STRING(a->value.byKey,&p);
break;
}
if (pp && *pp) *pp=p;
return(r);
}
|
['int i2d_OCSP_RESPID(OCSP_RESPID *a, unsigned char **pp)\n\t{\n\tint v=0;\n\tM_ASN1_I2D_vars(a);\n\tswitch (a->tag)\n\t\t{\n\t\tcase V_OCSP_RESPID_NAME:\n\t\t\tv = i2d_X509_NAME(a->value.byName,NULL);\n\t\t\tret += ASN1_object_size(1, v, V_OCSP_RESPID_NAME);\n\t\t if (pp==NULL) return ret;\n\t\t\tp=*pp;\n\t\t\tASN1_put_object(&p, 1, v,\n\t\t\t\t\tV_OCSP_RESPID_NAME,\n\t\t\t\t\tV_ASN1_CONTEXT_SPECIFIC);\n\t\t\ti2d_X509_NAME(a->value.byName,&p);\n\t\t break;\n\t\tcase V_OCSP_RESPID_KEY:\n\t\t\tv = i2d_ASN1_OCTET_STRING(a->value.byKey,NULL);\n\t\t\tret += ASN1_object_size(1, v, V_OCSP_RESPID_KEY);\n\t\t if (pp==NULL) return ret;\n\t\t\tp=*pp;\n\t\t\tASN1_put_object(&p, 1, v,\n\t\t\t\t\tV_OCSP_RESPID_KEY,\n\t\t\t\t\tV_ASN1_CONTEXT_SPECIFIC);\n\t\t\ti2d_ASN1_OCTET_STRING(a->value.byKey,&p);\n\t\t break;\n\t\t}\n\tif (pp && *pp) *pp=p;\n\treturn(r);\n\t}']
|
1,317
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L139
|
static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
}
|
['static void decode_mclms(WmallDecodeCtx *s)\n{\n s->mclms_order = (bitstream_read(&s->bc, 4) + 1) * 2;\n s->mclms_scaling = bitstream_read(&s->bc, 4);\n if (bitstream_read_bit(&s->bc)) {\n int i, send_coef_bits;\n int cbits = av_log2(s->mclms_scaling + 1);\n if (1 << cbits < s->mclms_scaling + 1)\n cbits++;\n send_coef_bits = bitstream_read(&s->bc, cbits) + 2;\n for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)\n s->mclms_coeffs[i] = bitstream_read(&s->bc, send_coef_bits);\n for (i = 0; i < s->num_channels; i++) {\n int c;\n for (c = 0; c < i; c++)\n s->mclms_coeffs_cur[i * s->num_channels + c] = bitstream_read(&s->bc, send_coef_bits);\n }\n }\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n if (!bc->bits_left)\n refill_64(bc);\n return get_val(bc, 1);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
1,318
| 0
|
https://github.com/libav/libav/blob/f77f640b3035d357a6c6ffcea243c7ea0d8ebc67/libavcodec/wmaprodec.c/#L844
|
static int decode_coeffs(WMAProDecodeCtx *s, int c)
{
static const uint32_t fval_tab[16] = {
0x00000000, 0x3f800000, 0x40000000, 0x40400000,
0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
0x41000000, 0x41100000, 0x41200000, 0x41300000,
0x41400000, 0x41500000, 0x41600000, 0x41700000,
};
int vlctable;
VLC* vlc;
WMAProChannelCtx* ci = &s->channel[c];
int rl_mode = 0;
int cur_coeff = 0;
int num_zeros = 0;
const uint16_t* run;
const float* level;
av_dlog(s->avctx, "decode coefficients for channel %i\n", c);
vlctable = get_bits1(&s->gb);
vlc = &coef_vlc[vlctable];
if (vlctable) {
run = coef1_run;
level = coef1_level;
} else {
run = coef0_run;
level = coef0_level;
}
while ((s->transmit_num_vec_coeffs || !rl_mode) &&
(cur_coeff + 3 < ci->num_vec_coeffs)) {
uint32_t vals[4];
int i;
unsigned int idx;
idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
if (idx == HUFF_VEC4_SIZE - 1) {
for (i = 0; i < 4; i += 2) {
idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
if (idx == HUFF_VEC2_SIZE - 1) {
uint32_t v0, v1;
v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
if (v0 == HUFF_VEC1_SIZE - 1)
v0 += ff_wma_get_large_val(&s->gb);
v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
if (v1 == HUFF_VEC1_SIZE - 1)
v1 += ff_wma_get_large_val(&s->gb);
vals[i ] = av_float2int(v0);
vals[i+1] = av_float2int(v1);
} else {
vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];
vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
}
}
} else {
vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];
vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
}
for (i = 0; i < 4; i++) {
if (vals[i]) {
uint32_t sign = get_bits1(&s->gb) - 1;
AV_WN32A(&ci->coeffs[cur_coeff], vals[i] ^ sign << 31);
num_zeros = 0;
} else {
ci->coeffs[cur_coeff] = 0;
rl_mode |= (++num_zeros > s->subframe_len >> 8);
}
++cur_coeff;
}
}
if (cur_coeff < s->subframe_len) {
memset(&ci->coeffs[cur_coeff], 0,
sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
level, run, 1, ci->coeffs,
cur_coeff, s->subframe_len,
s->subframe_len, s->esc_len, 0))
return AVERROR_INVALIDDATA;
}
return 0;
}
|
['static int decode_coeffs(WMAProDecodeCtx *s, int c)\n{\n static const uint32_t fval_tab[16] = {\n 0x00000000, 0x3f800000, 0x40000000, 0x40400000,\n 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,\n 0x41000000, 0x41100000, 0x41200000, 0x41300000,\n 0x41400000, 0x41500000, 0x41600000, 0x41700000,\n };\n int vlctable;\n VLC* vlc;\n WMAProChannelCtx* ci = &s->channel[c];\n int rl_mode = 0;\n int cur_coeff = 0;\n int num_zeros = 0;\n const uint16_t* run;\n const float* level;\n av_dlog(s->avctx, "decode coefficients for channel %i\\n", c);\n vlctable = get_bits1(&s->gb);\n vlc = &coef_vlc[vlctable];\n if (vlctable) {\n run = coef1_run;\n level = coef1_level;\n } else {\n run = coef0_run;\n level = coef0_level;\n }\n while ((s->transmit_num_vec_coeffs || !rl_mode) &&\n (cur_coeff + 3 < ci->num_vec_coeffs)) {\n uint32_t vals[4];\n int i;\n unsigned int idx;\n idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);\n if (idx == HUFF_VEC4_SIZE - 1) {\n for (i = 0; i < 4; i += 2) {\n idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);\n if (idx == HUFF_VEC2_SIZE - 1) {\n uint32_t v0, v1;\n v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);\n if (v0 == HUFF_VEC1_SIZE - 1)\n v0 += ff_wma_get_large_val(&s->gb);\n v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);\n if (v1 == HUFF_VEC1_SIZE - 1)\n v1 += ff_wma_get_large_val(&s->gb);\n vals[i ] = av_float2int(v0);\n vals[i+1] = av_float2int(v1);\n } else {\n vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];\n vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];\n }\n }\n } else {\n vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];\n vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];\n vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];\n vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];\n }\n for (i = 0; i < 4; i++) {\n if (vals[i]) {\n uint32_t sign = get_bits1(&s->gb) - 1;\n AV_WN32A(&ci->coeffs[cur_coeff], vals[i] ^ sign << 31);\n num_zeros = 0;\n } else {\n ci->coeffs[cur_coeff] = 0;\n rl_mode |= (++num_zeros > s->subframe_len >> 8);\n }\n ++cur_coeff;\n }\n }\n if (cur_coeff < s->subframe_len) {\n memset(&ci->coeffs[cur_coeff], 0,\n sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));\n if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,\n level, run, 1, ci->coeffs,\n cur_coeff, s->subframe_len,\n s->subframe_len, s->esc_len, 0))\n return AVERROR_INVALIDDATA;\n }\n return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
1,319
| 0
|
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/bn/bn_mul.c/#L99
|
BN_ULONG bn_sub_part_words(BN_ULONG *r,
const BN_ULONG *a, const BN_ULONG *b,
int cl, int dl)
{
BN_ULONG c, t;
assert(cl >= 0);
c = bn_sub_words(r, a, b, cl);
if (dl == 0)
return c;
r += cl;
a += cl;
b += cl;
if (dl < 0) {
for (;;) {
t = b[0];
r[0] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
t = b[1];
r[1] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
t = b[2];
r[2] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
t = b[3];
r[3] = (0 - t - c) & BN_MASK2;
if (t != 0)
c = 1;
if (++dl >= 0)
break;
b += 4;
r += 4;
}
} else {
int save_dl = dl;
while (c) {
t = a[0];
r[0] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
t = a[1];
r[1] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
t = a[2];
r[2] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
t = a[3];
r[3] = (t - c) & BN_MASK2;
if (t != 0)
c = 0;
if (--dl <= 0)
break;
save_dl = dl;
a += 4;
r += 4;
}
if (dl > 0) {
if (save_dl > dl) {
switch (save_dl - dl) {
case 1:
r[1] = a[1];
if (--dl <= 0)
break;
case 2:
r[2] = a[2];
if (--dl <= 0)
break;
case 3:
r[3] = a[3];
if (--dl <= 0)
break;
}
a += 4;
r += 4;
}
}
if (dl > 0) {
for (;;) {
r[0] = a[0];
if (--dl <= 0)
break;
r[1] = a[1];
if (--dl <= 0)
break;
r[2] = a[2];
if (--dl <= 0)
break;
r[3] = a[3];
if (--dl <= 0)
break;
a += 4;
r += 4;
}
}
}
return c;
}
|
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (!d || !r || !val1[0] || !val2[0])\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'const BIGNUM *BN_value_one(void)\n{\n static const BN_ULONG data_one = 1L;\n static const BIGNUM const_one =\n { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n return (&const_one);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return (1);\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n const BN_ULONG *a, const BN_ULONG *b,\n int cl, int dl)\n{\n BN_ULONG c, t;\n assert(cl >= 0);\n c = bn_sub_words(r, a, b, cl);\n if (dl == 0)\n return c;\n r += cl;\n a += cl;\n b += cl;\n if (dl < 0) {\n for (;;) {\n t = b[0];\n r[0] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[1];\n r[1] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[2];\n r[2] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n t = b[3];\n r[3] = (0 - t - c) & BN_MASK2;\n if (t != 0)\n c = 1;\n if (++dl >= 0)\n break;\n b += 4;\n r += 4;\n }\n } else {\n int save_dl = dl;\n while (c) {\n t = a[0];\n r[0] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[1];\n r[1] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[2];\n r[2] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n t = a[3];\n r[3] = (t - c) & BN_MASK2;\n if (t != 0)\n c = 0;\n if (--dl <= 0)\n break;\n save_dl = dl;\n a += 4;\n r += 4;\n }\n if (dl > 0) {\n if (save_dl > dl) {\n switch (save_dl - dl) {\n case 1:\n r[1] = a[1];\n if (--dl <= 0)\n break;\n case 2:\n r[2] = a[2];\n if (--dl <= 0)\n break;\n case 3:\n r[3] = a[3];\n if (--dl <= 0)\n break;\n }\n a += 4;\n r += 4;\n }\n }\n if (dl > 0) {\n for (;;) {\n r[0] = a[0];\n if (--dl <= 0)\n break;\n r[1] = a[1];\n if (--dl <= 0)\n break;\n r[2] = a[2];\n if (--dl <= 0)\n break;\n r[3] = a[3];\n if (--dl <= 0)\n break;\n a += 4;\n r += 4;\n }\n }\n }\n return c;\n}']
|
1,320
| 0
|
https://github.com/openssl/openssl/blob/9d5db9c9ab9b9f2f2a5ce9795405e8334cd2ce66/crypto/mem.c/#L312
|
void CRYPTO_free(void *str, const char *file, int line)
{
INCREMENT(free_count);
if (free_impl != NULL && free_impl != &CRYPTO_free) {
free_impl(str, file, line);
return;
}
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
if (call_malloc_debug) {
CRYPTO_mem_debug_free(str, 0, file, line);
free(str);
CRYPTO_mem_debug_free(str, 1, file, line);
} else {
free(str);
}
#else
free(str);
#endif
}
|
['static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,\n int utype, char *free_cont, const ASN1_ITEM *it)\n{\n ASN1_VALUE **opval = NULL;\n ASN1_STRING *stmp;\n ASN1_TYPE *typ = NULL;\n int ret = 0;\n const ASN1_PRIMITIVE_FUNCS *pf;\n ASN1_INTEGER **tint;\n pf = it->funcs;\n if (pf && pf->prim_c2i)\n return pf->prim_c2i(pval, cont, len, utype, free_cont, it);\n if (it->utype == V_ASN1_ANY) {\n if (!*pval) {\n typ = ASN1_TYPE_new();\n if (typ == NULL)\n goto err;\n *pval = (ASN1_VALUE *)typ;\n } else\n typ = (ASN1_TYPE *)*pval;\n if (utype != typ->type)\n ASN1_TYPE_set(typ, utype, NULL);\n opval = pval;\n pval = &typ->value.asn1_value;\n }\n switch (utype) {\n case V_ASN1_OBJECT:\n if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))\n goto err;\n break;\n case V_ASN1_NULL:\n if (len) {\n ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_NULL_IS_WRONG_LENGTH);\n goto err;\n }\n *pval = (ASN1_VALUE *)1;\n break;\n case V_ASN1_BOOLEAN:\n if (len != 1) {\n ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);\n goto err;\n } else {\n ASN1_BOOLEAN *tbool;\n tbool = (ASN1_BOOLEAN *)pval;\n *tbool = *cont;\n }\n break;\n case V_ASN1_BIT_STRING:\n if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len))\n goto err;\n break;\n case V_ASN1_INTEGER:\n case V_ASN1_ENUMERATED:\n tint = (ASN1_INTEGER **)pval;\n if (!c2i_ASN1_INTEGER(tint, &cont, len))\n goto err;\n (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);\n break;\n case V_ASN1_OCTET_STRING:\n case V_ASN1_NUMERICSTRING:\n case V_ASN1_PRINTABLESTRING:\n case V_ASN1_T61STRING:\n case V_ASN1_VIDEOTEXSTRING:\n case V_ASN1_IA5STRING:\n case V_ASN1_UTCTIME:\n case V_ASN1_GENERALIZEDTIME:\n case V_ASN1_GRAPHICSTRING:\n case V_ASN1_VISIBLESTRING:\n case V_ASN1_GENERALSTRING:\n case V_ASN1_UNIVERSALSTRING:\n case V_ASN1_BMPSTRING:\n case V_ASN1_UTF8STRING:\n case V_ASN1_OTHER:\n case V_ASN1_SET:\n case V_ASN1_SEQUENCE:\n default:\n if (utype == V_ASN1_BMPSTRING && (len & 1)) {\n ASN1err(ASN1_F_ASN1_EX_C2I, ASN1_R_BMPSTRING_IS_WRONG_LENGTH);\n goto err;\n }\n if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {\n ASN1err(ASN1_F_ASN1_EX_C2I,\n ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);\n goto err;\n }\n if (!*pval) {\n stmp = ASN1_STRING_type_new(utype);\n if (stmp == NULL) {\n ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n *pval = (ASN1_VALUE *)stmp;\n } else {\n stmp = (ASN1_STRING *)*pval;\n stmp->type = utype;\n }\n if (*free_cont) {\n OPENSSL_free(stmp->data);\n stmp->data = (unsigned char *)cont;\n stmp->length = len;\n *free_cont = 0;\n } else {\n if (!ASN1_STRING_set(stmp, cont, len)) {\n ASN1err(ASN1_F_ASN1_EX_C2I, ERR_R_MALLOC_FAILURE);\n ASN1_STRING_free(stmp);\n *pval = NULL;\n goto err;\n }\n }\n break;\n }\n if (typ && (utype == V_ASN1_NULL))\n typ->value.ptr = NULL;\n ret = 1;\n err:\n if (!ret) {\n ASN1_TYPE_free(typ);\n if (opval)\n *opval = NULL;\n }\n return ret;\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n unsigned char *c;\n const char *data = _data;\n if (len < 0) {\n if (data == NULL)\n return 0;\n else\n len = strlen(data);\n }\n if ((str->length <= len) || (str->data == NULL)) {\n c = str->data;\n str->data = OPENSSL_realloc(c, len + 1);\n if (str->data == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n str->data = c;\n return 0;\n }\n }\n str->length = len;\n if (data != NULL) {\n memcpy(str->data, data, len);\n str->data[len] = '\\0';\n }\n return 1;\n}", 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n INCREMENT(realloc_count);\n if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n return realloc_impl(str, num, file, line);\n FAILTEST();\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str, file, line);\n return NULL;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)(file); (void)(line);\n#endif\n return realloc(str, num);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n INCREMENT(free_count);\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
1,321
| 0
|
https://gitlab.com/libtiff/libtiff/blob/3334704ebcec6a8011fc5ef5d0904d6297a0b9ff/libtiff/tif_strip.c/#L65
|
uint32
TIFFNumberOfStrips(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
uint32 nstrips;
nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :
TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
nstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,
"TIFFNumberOfStrips");
return (nstrips);
}
|
['static int\ninitImage(void)\n{\n uint32 w, h;\n if (order)\n TIFFSetField(tif, TIFFTAG_FILLORDER, order);\n if (photo != (uint16) -1)\n TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photo);\n if (!TIFFRGBAImageBegin(&img, tif, stoponerr, title)) {\n TIFFError(filelist[fileindex], "%s", title);\n TIFFClose(tif);\n tif = NULL;\n return -1;\n }\n h = img.height;\n w = img.width;\n if (h > ymax) {\n w = (int)(w * ((float)ymax / h));\n h = ymax;\n }\n if (w > xmax) {\n h = (int)(h * ((float)xmax / w));\n w = xmax;\n }\n\tif (w != width || h != height) {\n\t\tuint32 rastersize =\n\t\t\t_TIFFMultiply32(tif, img.width, img.height, "allocating raster buffer");\n\t\tif (raster != NULL)\n\t\t\t_TIFFfree(raster), raster = NULL;\n\t\traster = (uint32*) _TIFFCheckMalloc(tif, rastersize, sizeof (uint32),\n\t\t\t\t\t\t "allocating raster buffer");\n\t\tif (raster == NULL) {\n\t\t\twidth = height = 0;\n\t\t\tTIFFError(filelist[fileindex], "No space for raster buffer");\n\t\t\tcleanup_and_exit();\n\t\t}\n\t\twidth = w;\n\t\theight = h;\n\t}\n\tTIFFRGBAImageGet(&img, raster, img.width, img.height);\n#if HOST_BIGENDIAN\n\tTIFFSwabArrayOfLong(raster,img.width*img.height);\n#endif\n\treturn 0;\n}', 'void\nTIFFClose(TIFF* tif)\n{\n\tTIFFCloseProc closeproc = tif->tif_closeproc;\n\tthandle_t fd = tif->tif_clientdata;\n\tTIFFCleanup(tif);\n\t(void) (*closeproc)(fd);\n}', 'void\nTIFFCleanup(TIFF* tif)\n{\n\tif (tif->tif_mode != O_RDONLY)\n\t\tTIFFFlush(tif);\n\t(*tif->tif_cleanup)(tif);\n\tTIFFFreeDirectory(tif);\n\tif (tif->tif_dirlist)\n\t\t_TIFFfree(tif->tif_dirlist);\n\twhile( tif->tif_clientinfo )\n\t{\n\t\tTIFFClientInfoLink *psLink = tif->tif_clientinfo;\n\t\ttif->tif_clientinfo = psLink->next;\n\t\t_TIFFfree( psLink->name );\n\t\t_TIFFfree( psLink );\n\t}\n\tif (tif->tif_rawdata && (tif->tif_flags&TIFF_MYBUFFER))\n\t\t_TIFFfree(tif->tif_rawdata);\n\tif (isMapped(tif))\n\t\tTIFFUnmapFileContents(tif, tif->tif_base, (toff_t)tif->tif_size);\n\tif (tif->tif_fields && tif->tif_nfields > 0) {\n\t\tuint32 i;\n\t\tfor (i = 0; i < tif->tif_nfields; i++) {\n\t\t\tTIFFField *fld = tif->tif_fields[i];\n\t\t\tif (fld->field_bit == FIELD_CUSTOM &&\n\t\t\t strncmp("Tag ", fld->field_name, 4) == 0) {\n\t\t\t\t_TIFFfree(fld->field_name);\n\t\t\t\t_TIFFfree(fld);\n\t\t\t}\n\t\t}\n\t\t_TIFFfree(tif->tif_fields);\n\t}\n if (tif->tif_nfieldscompat > 0) {\n uint32 i;\n for (i = 0; i < tif->tif_nfieldscompat; i++) {\n if (tif->tif_fieldscompat[i].allocated_size)\n _TIFFfree(tif->tif_fieldscompat[i].fields);\n }\n _TIFFfree(tif->tif_fieldscompat);\n }\n\t_TIFFfree(tif);\n}', 'int\nTIFFFlush(TIFF* tif)\n{\n if( tif->tif_mode == O_RDONLY )\n return 1;\n if (!TIFFFlushData(tif))\n return (0);\n if( (tif->tif_flags & TIFF_DIRTYSTRIP)\n && !(tif->tif_flags & TIFF_DIRTYDIRECT)\n && tif->tif_mode == O_RDWR )\n {\n if( TIFFForceStrileArrayWriting(tif) )\n return 1;\n }\n if ((tif->tif_flags & (TIFF_DIRTYDIRECT|TIFF_DIRTYSTRIP))\n && !TIFFRewriteDirectory(tif))\n return (0);\n return (1);\n}', 'int TIFFForceStrileArrayWriting(TIFF* tif)\n{\n static const char module[] = "TIFFForceStrileArrayWriting";\n const int isTiled = TIFFIsTiled(tif);\n if (tif->tif_mode == O_RDONLY)\n {\n TIFFErrorExt(tif->tif_clientdata, tif->tif_name,\n "File opened in read-only mode");\n return 0;\n }\n if( tif->tif_diroff == 0 )\n {\n TIFFErrorExt(tif->tif_clientdata, module,\n "Directory has not yet been written");\n return 0;\n }\n if( (tif->tif_flags & TIFF_DIRTYDIRECT) != 0 )\n {\n TIFFErrorExt(tif->tif_clientdata, module,\n "Directory has changes other than the strile arrays. "\n "TIFFRewriteDirectory() should be called instead");\n return 0;\n }\n if( !(tif->tif_flags & TIFF_DIRTYSTRIP) )\n {\n if( !(tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 &&\n tif->tif_dir.td_stripoffset_entry.tdir_count == 0 &&\n tif->tif_dir.td_stripoffset_entry.tdir_type == 0 &&\n tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 &&\n tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 &&\n tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 &&\n tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 &&\n tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0) )\n {\n TIFFErrorExt(tif->tif_clientdata, module,\n "Function not called together with "\n "TIFFDeferStrileArrayWriting()");\n return 0;\n }\n if (tif->tif_dir.td_stripoffset_p == NULL && !TIFFSetupStrips(tif))\n return 0;\n }\n if( _TIFFRewriteField( tif,\n isTiled ? TIFFTAG_TILEOFFSETS :\n TIFFTAG_STRIPOFFSETS,\n TIFF_LONG8,\n tif->tif_dir.td_nstrips,\n tif->tif_dir.td_stripoffset_p )\n && _TIFFRewriteField( tif,\n isTiled ? TIFFTAG_TILEBYTECOUNTS :\n TIFFTAG_STRIPBYTECOUNTS,\n TIFF_LONG8,\n tif->tif_dir.td_nstrips,\n tif->tif_dir.td_stripbytecount_p ) )\n {\n tif->tif_flags &= ~TIFF_DIRTYSTRIP;\n tif->tif_flags &= ~TIFF_BEENWRITING;\n return 1;\n }\n return 0;\n}', 'int\nTIFFSetupStrips(TIFF* tif)\n{\n\tTIFFDirectory* td = &tif->tif_dir;\n\tif (isTiled(tif))\n\t\ttd->td_stripsperimage =\n\t\t isUnspecified(tif, FIELD_TILEDIMENSIONS) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfTiles(tif);\n\telse\n\t\ttd->td_stripsperimage =\n\t\t isUnspecified(tif, FIELD_ROWSPERSTRIP) ?\n\t\t\ttd->td_samplesperpixel : TIFFNumberOfStrips(tif);\n\ttd->td_nstrips = td->td_stripsperimage;\n if( td->td_nstrips >= 0x80000000U / ((tif->tif_flags&TIFF_BIGTIFF)?0x8U:0x4U) )\n {\n TIFFErrorExt(tif->tif_clientdata, "TIFFSetupStrips",\n "Too large Strip/Tile Offsets/ByteCounts arrays");\n return 0;\n }\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\ttd->td_stripsperimage /= td->td_samplesperpixel;\n\ttd->td_stripoffset_p = (uint64 *)\n _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),\n "for \\"StripOffsets\\" array");\n\ttd->td_stripbytecount_p = (uint64 *)\n _TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),\n "for \\"StripByteCounts\\" array");\n\tif (td->td_stripoffset_p == NULL || td->td_stripbytecount_p == NULL)\n\t\treturn (0);\n\t_TIFFmemset(td->td_stripoffset_p, 0, td->td_nstrips*sizeof (uint64));\n\t_TIFFmemset(td->td_stripbytecount_p, 0, td->td_nstrips*sizeof (uint64));\n\tTIFFSetFieldBit(tif, FIELD_STRIPOFFSETS);\n\tTIFFSetFieldBit(tif, FIELD_STRIPBYTECOUNTS);\n\treturn (1);\n}', 'uint32\nTIFFNumberOfStrips(TIFF* tif)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint32 nstrips;\n\tnstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :\n\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));\n\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE)\n\t\tnstrips = _TIFFMultiply32(tif, nstrips, (uint32)td->td_samplesperpixel,\n\t\t "TIFFNumberOfStrips");\n\treturn (nstrips);\n}']
|
1,322
| 0
|
https://github.com/openssl/openssl/blob/c504a5e78386aa9f02462d18a90da759f9131321/crypto/lhash/lhash.c/#L368
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['int ssl3_connect(SSL *s)\n\t{\n\tBUF_MEM *buf=NULL;\n\tunsigned long Time=(unsigned long)time(NULL);\n\tlong num1;\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tint ret= -1;\n\tint new_state,state,skip=0;;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch(s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\t\ts->state=SSL_ST_CONNECT;\n\t\t\ts->ctx->stats.sess_connect_renegotiate++;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_CONNECT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_CONNECT:\n\t\tcase SSL_ST_OK|SSL_ST_CONNECT:\n\t\t\ts->server=0;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version & 0xff00 ) != 0x0300)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CONNECT, ERR_R_INTERNAL_ERROR);\n\t\t\t\tret = -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_CONNECT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\tbuf=NULL;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s)) { ret= -1; goto end; }\n\t\t\tif (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }\n\t\t\tssl3_init_finished_mac(s);\n\t\t\ts->state=SSL3_ST_CW_CLNT_HELLO_A;\n\t\t\ts->ctx->stats.sess_connect++;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CLNT_HELLO_A:\n\t\tcase SSL3_ST_CW_CLNT_HELLO_B:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tif (s->bbio != s->wbio)\n\t\t\t\ts->wbio=BIO_push(s->bbio,s->wbio);\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_HELLO_A:\n\t\tcase SSL3_ST_CR_SRVR_HELLO_B:\n\t\t\tret=ssl3_get_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_CR_FINISHED_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CR_CERT_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_A:\n\t\tcase SSL3_ST_CR_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithm_auth & SSL_aNULL) &&\n\t\t\t !(s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))\n\t\t\t\t{\n\t\t\t\tret=ssl3_get_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_CR_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_KEY_EXCH_A:\n\t\tcase SSL3_ST_CR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!ssl3_check_cert_and_algorithm(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_CERT_REQ_A:\n\t\tcase SSL3_ST_CR_CERT_REQ_B:\n\t\t\tret=ssl3_get_certificate_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CR_SRVR_DONE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_SRVR_DONE_A:\n\t\tcase SSL3_ST_CR_SRVR_DONE_B:\n\t\t\tret=ssl3_get_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req)\n\t\t\t\ts->state=SSL3_ST_CW_CERT_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_A:\n\t\tcase SSL3_ST_CW_CERT_B:\n\t\tcase SSL3_ST_CW_CERT_C:\n\t\tcase SSL3_ST_CW_CERT_D:\n\t\t\tret=ssl3_send_client_certificate(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_KEY_EXCH_A:\n\t\tcase SSL3_ST_CW_KEY_EXCH_B:\n\t\t\tret=ssl3_send_client_key_exchange(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->s3->tmp.cert_req == 1)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CERT_VRFY_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\t\ts->s3->change_cipher_spec=0;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CERT_VRFY_A:\n\t\tcase SSL3_ST_CW_CERT_VRFY_B:\n\t\t\tret=ssl3_send_client_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\ts->s3->change_cipher_spec=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_CHANGE_A:\n\t\tcase SSL3_ST_CW_CHANGE_B:\n\t\t\tret=ssl3_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n#ifdef OPENSSL_NO_COMP\n\t\t\ts->session->compress_meth=0;\n#else\n\t\t\tif (s->s3->tmp.new_compression == NULL)\n\t\t\t\ts->session->compress_meth=0;\n\t\t\telse\n\t\t\t\ts->session->compress_meth=\n\t\t\t\t\ts->s3->tmp.new_compression->id;\n#endif\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_CLIENT_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_FINISHED_A:\n\t\tcase SSL3_ST_CW_FINISHED_B:\n\t\t\tret=ssl3_send_finished(s,\n\t\t\t\tSSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->client_finished_label,\n\t\t\t\ts->method->ssl3_enc->client_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_CW_FLUSH;\n\t\t\ts->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;\n\t\t\tif (s->hit)\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\t\tif (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)\n\t\t\t\t\t{\n\t\t\t\t\ts->state=SSL_ST_OK;\n\t\t\t\t\ts->s3->flags|=SSL3_FLAGS_POP_BUFFER;\n\t\t\t\t\ts->s3->delay_buf_pop_ret=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CR_FINISHED_A:\n\t\tcase SSL3_ST_CR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,\n\t\t\t\tSSL3_ST_CR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_CW_CHANGE_A;\n\t\t\telse\n\t\t\t\ts->state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_CW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n\t\t\tif (s->init_buf != NULL)\n\t\t\t\t{\n\t\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\t\ts->init_buf=NULL;\n\t\t\t\t}\n\t\t\tif (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))\n\t\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\ts->new_session=0;\n\t\t\tssl_update_cache(s,SSL_SESS_CACHE_CLIENT);\n\t\t\tif (s->hit) s->ctx->stats.sess_hit++;\n\t\t\tret=1;\n\t\t\ts->handshake_func=ssl3_connect;\n\t\t\ts->ctx->stats.sess_connect_good++;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_CONNECT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (buf != NULL)\n\t\tBUF_MEM_free(buf);\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_CONNECT_EXIT,ret);\n\treturn(ret);\n\t}', 'int ssl3_get_server_hello(SSL *s)\n\t{\n\tSTACK_OF(SSL_CIPHER) *sk;\n\tSSL_CIPHER *c;\n\tunsigned char *p,*d;\n\tint i,al,ok;\n\tunsigned int j;\n\tlong n;\n#ifndef OPENSSL_NO_COMP\n\tSSL_COMP *comp;\n#endif\n\tn=s->method->ssl_get_message(s,\n\t\tSSL3_ST_CR_SRVR_HELLO_A,\n\t\tSSL3_ST_CR_SRVR_HELLO_B,\n\t\t-1,\n\t\t300,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif ( SSL_version(s) == DTLS1_VERSION)\n\t\t{\n\t\tif ( s->s3->tmp.message_type == DTLS1_MT_HELLO_VERIFY_REQUEST)\n\t\t\t{\n\t\t\tif ( s->d1->send_cookie == 0)\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.reuse_message = 1;\n\t\t\t\treturn 1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_MESSAGE_TYPE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif ( s->s3->tmp.message_type != SSL3_MT_SERVER_HELLO)\n\t\t{\n\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_MESSAGE_TYPE);\n\t\tgoto f_err;\n\t\t}\n\td=p=(unsigned char *)s->init_msg;\n\tif ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff)))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION);\n\t\ts->version=(s->version&0xff00)|p[1];\n\t\tal=SSL_AD_PROTOCOL_VERSION;\n\t\tgoto f_err;\n\t\t}\n\tp+=2;\n\tmemcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE);\n\tp+=SSL3_RANDOM_SIZE;\n\tj= *(p++);\n\tif ((j > sizeof s->session->session_id) || (j > SSL3_SESSION_ID_SIZE))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_LONG);\n\t\tgoto f_err;\n\t\t}\n\tif (j != 0 && j == s->session->session_id_length\n\t && memcmp(p,s->session->session_id,j) == 0)\n\t {\n\t if(s->sid_ctx_length != s->session->sid_ctx_length\n\t || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);\n\t\tgoto f_err;\n\t\t}\n\t s->hit=1;\n\t }\n\telse\n\t\t{\n\t\ts->hit=0;\n\t\tif (s->session->session_id_length > 0)\n\t\t\t{\n\t\t\tif (!ssl_get_new_session(s,0))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_INTERNAL_ERROR;\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\ts->session->session_id_length=j;\n\t\tmemcpy(s->session->session_id,p,j);\n\t\t}\n\tp+=j;\n\tc=ssl_get_cipher_by_char(s,p);\n\tif (c == NULL)\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED);\n\t\tgoto f_err;\n\t\t}\n\tp+=ssl_put_cipher_by_char(s,NULL,NULL);\n\tsk=ssl_get_ciphers_by_id(s);\n\ti=sk_SSL_CIPHER_find(sk,c);\n\tif (i < 0)\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED);\n\t\tgoto f_err;\n\t\t}\n\tif (s->session->cipher)\n\t\ts->session->cipher_id = s->session->cipher->id;\n\tif (s->hit && (s->session->cipher_id != c->id))\n\t\t{\n\t\tif (!(s->options &\n\t\t\tSSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG))\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\ts->s3->tmp.new_cipher=c;\n#ifdef OPENSSL_NO_COMP\n\tif (*(p++) != 0)\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);\n\t\tgoto f_err;\n\t\t}\n#else\n\tj= *(p++);\n\tif ((j == 0) || (s->options & SSL_OP_NO_COMPRESSION))\n\t\tcomp=NULL;\n\telse\n\t\tcomp=ssl3_comp_find(s->ctx->comp_methods,j);\n\tif ((j != 0) && (comp == NULL))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);\n\t\tgoto f_err;\n\t\t}\n\telse\n\t\t{\n\t\ts->s3->tmp.new_compression=comp;\n\t\t}\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n\tif (s->version > SSL3_VERSION)\n\t\t{\n\t\tif (!ssl_parse_serverhello_tlsext(s,&p,d,n, &al))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_PARSE_TLSEXT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (ssl_check_serverhello_tlsext(s) <= 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SERVERHELLO_TLSEXT);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n#endif\n\tif (p != (d+n))\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);\n\t\tgoto err;\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\treturn(-1);\n\t}', 'int ssl_check_serverhello_tlsext(SSL *s)\n\t{\n\tint ret=SSL_TLSEXT_ERR_NOACK;\n\tint al = SSL_AD_UNRECOGNIZED_NAME;\n#ifndef OPENSSL_NO_EC\n\tunsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey;\n\tunsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth;\n\tif ((s->tlsext_ecpointformatlist != NULL) && (s->tlsext_ecpointformatlist_length > 0) &&\n\t ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) || (alg_a & SSL_aECDSA)))\n\t\t{\n\t\tsize_t i;\n\t\tunsigned char *list;\n\t\tint found_uncompressed = 0;\n\t\tif ((s->session->tlsext_ecpointformatlist == NULL) || (s->session->tlsext_ecpointformatlist_length == 0))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT,SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);\n\t\t\treturn -1;\n\t\t\t}\n\t\tlist = s->session->tlsext_ecpointformatlist;\n\t\tfor (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++)\n\t\t\t{\n\t\t\tif (*(list++) == TLSEXT_ECPOINTFORMAT_uncompressed)\n\t\t\t\t{\n\t\t\t\tfound_uncompressed = 1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (!found_uncompressed)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT,SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);\n\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tret = SSL_TLSEXT_ERR_OK;\n#endif\n\tif (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0)\n\t\tret = s->ctx->tlsext_servername_callback(s, &al, s->ctx->tlsext_servername_arg);\n\telse if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0)\n\t\tret = s->initial_ctx->tlsext_servername_callback(s, &al, s->initial_ctx->tlsext_servername_arg);\n\tswitch (ret)\n\t\t{\n\t\tcase SSL_TLSEXT_ERR_ALERT_FATAL:\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t\treturn -1;\n\t\tcase SSL_TLSEXT_ERR_ALERT_WARNING:\n\t\t\tssl3_send_alert(s,SSL3_AL_WARNING,al);\n\t\t\treturn 1;\n\t\tcase SSL_TLSEXT_ERR_NOACK:\n\t\t\ts->servername_done=0;\n\t\t\tdefault:\n\t\treturn 1;\n\t\t}\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\ts->method->ssl_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,323
| 0
|
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int rsa_ossl_public_encrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret;\n int i, num = 0, r = -1;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n if (BN_ucmp(rsa->n, rsa->e) <= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS) {\n if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);\n return -1;\n }\n }\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n f = BN_CTX_get(ctx);\n ret = BN_CTX_get(ctx);\n num = BN_num_bytes(rsa->n);\n buf = OPENSSL_malloc(num);\n if (ret == NULL || buf == NULL) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n switch (padding) {\n case RSA_PKCS1_PADDING:\n i = RSA_padding_add_PKCS1_type_2(buf, num, from, flen);\n break;\n case RSA_PKCS1_OAEP_PADDING:\n i = RSA_padding_add_PKCS1_OAEP(buf, num, from, flen, NULL, 0);\n break;\n case RSA_SSLV23_PADDING:\n i = RSA_padding_add_SSLv23(buf, num, from, flen);\n break;\n case RSA_NO_PADDING:\n i = RSA_padding_add_none(buf, num, from, flen);\n break;\n default:\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (i <= 0)\n goto err;\n if (BN_bin2bn(buf, num, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_OSSL_PUBLIC_ENCRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,\n rsa->n, ctx))\n goto err;\n if (!rsa->meth->bn_mod_exp(ret, f, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n r = BN_bn2binpad(ret, to, num);\n err:\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n OPENSSL_clear_free(buf, num);\n return r;\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}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,\n const BIGNUM *mod, BN_CTX *ctx)\n{\n BN_MONT_CTX *ret;\n CRYPTO_THREAD_read_lock(lock);\n ret = *pmont;\n CRYPTO_THREAD_unlock(lock);\n if (ret)\n return ret;\n ret = BN_MONT_CTX_new();\n if (ret == NULL)\n return NULL;\n if (!BN_MONT_CTX_set(ret, mod, ctx)) {\n BN_MONT_CTX_free(ret);\n return NULL;\n }\n CRYPTO_THREAD_write_lock(lock);\n if (*pmont) {\n BN_MONT_CTX_free(ret);\n ret = *pmont;\n } else\n *pmont = ret;\n CRYPTO_THREAD_unlock(lock);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if (BN_is_one(&tmod))\n BN_zero(Ri);\n else if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n for (i = mont->RR.top, ret = mont->N.top; i < ret; i++)\n mont->RR.d[i] = 0;\n mont->RR.top = ret;\n mont->RR.flags |= BN_FLG_FIXED_TOP;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (BN_abs_is_word(n, 1) || BN_is_zero(n)) {\n if (pnoinv != NULL)\n *pnoinv = 1;\n return NULL;\n }\n if (pnoinv != NULL)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,324
| 0
|
https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/simple_idct.c/#L139
|
static inline void idct4col_add(uint8_t *dest, int line_size, const int16_t *col)
{
int c0, c1, c2, c3, a0, a1, a2, a3;
a0 = col[8*0];
a1 = col[8*1];
a2 = col[8*2];
a3 = col[8*3];
c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));
c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));
c1 = a1 * C1 + a3 * C2;
c3 = a1 * C2 - a3 * C1;
dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT));
dest += line_size;
dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT));
dest += line_size;
dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT));
dest += line_size;
dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT));
}
|
['void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr){\n Wmv2Context * const w= (Wmv2Context*)s;\n wmv2_add_block(w, block1[0], dest_y , s->linesize, 0);\n wmv2_add_block(w, block1[1], dest_y + 8 , s->linesize, 1);\n wmv2_add_block(w, block1[2], dest_y + 8*s->linesize, s->linesize, 2);\n wmv2_add_block(w, block1[3], dest_y + 8 + 8*s->linesize, s->linesize, 3);\n if(s->flags&CODEC_FLAG_GRAY) return;\n wmv2_add_block(w, block1[4], dest_cb , s->uvlinesize, 4);\n wmv2_add_block(w, block1[5], dest_cr , s->uvlinesize, 5);\n}', 'static void wmv2_add_block(Wmv2Context *w, int16_t *block1, uint8_t *dst, int stride, int n){\n MpegEncContext * const s= &w->s;\n if (s->block_last_index[n] >= 0) {\n switch(w->abt_type_table[n]){\n case 0:\n w->wdsp.idct_add(dst, stride, block1);\n break;\n case 1:\n ff_simple_idct84_add(dst , stride, block1);\n ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]);\n s->dsp.clear_block(w->abt_block2[n]);\n break;\n case 2:\n ff_simple_idct48_add(dst , stride, block1);\n ff_simple_idct48_add(dst + 4 , stride, w->abt_block2[n]);\n s->dsp.clear_block(w->abt_block2[n]);\n break;\n default:\n av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\\n");\n }\n }\n}', 'void ff_simple_idct84_add(uint8_t *dest, int line_size, int16_t *block)\n{\n int i;\n for(i=0; i<4; i++) {\n idctRowCondDC_8(block + i*8, 0);\n }\n for(i=0;i<8;i++) {\n idct4col_add(dest + i, line_size, block + i);\n }\n}', 'static inline void idct4col_add(uint8_t *dest, int line_size, const int16_t *col)\n{\n int c0, c1, c2, c3, a0, a1, a2, a3;\n a0 = col[8*0];\n a1 = col[8*1];\n a2 = col[8*2];\n a3 = col[8*3];\n c0 = (a0 + a2)*C3 + (1 << (C_SHIFT - 1));\n c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1));\n c1 = a1 * C1 + a3 * C2;\n c3 = a1 * C2 - a3 * C1;\n dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT));\n dest += line_size;\n dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT));\n dest += line_size;\n dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT));\n dest += line_size;\n dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT));\n}']
|
1,325
| 0
|
https://github.com/libav/libav/blob/f5968788bb3692f2fd503bb2ec1526b0369c7f92/libavcodec/h264.h/#L1154
|
static int fill_filter_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
const int mb_xy= h->mb_xy;
int top_xy, left_xy[2];
int top_type, left_type[2];
int i;
top_xy = mb_xy - (s->mb_stride << MB_FIELD);
left_xy[1] = left_xy[0] = mb_xy-1;
if(FRAME_MBAFF){
const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);
const int curr_mb_field_flag = IS_INTERLACED(mb_type);
if(s->mb_y&1){
if (left_mb_field_flag != curr_mb_field_flag) {
left_xy[0] -= s->mb_stride;
}
}else{
if(curr_mb_field_flag){
top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);
}
if (left_mb_field_flag != curr_mb_field_flag) {
left_xy[1] += s->mb_stride;
}
}
}
h->top_mb_xy = top_xy;
h->left_mb_xy[0] = left_xy[0];
h->left_mb_xy[1] = left_xy[1];
{
int qp_thresh = h->qp_thresh;
int qp = s->current_picture.qscale_table[mb_xy];
if(qp <= qp_thresh
&& (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh)
&& (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){
if(!FRAME_MBAFF)
return 1;
if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh)
&& (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh))
return 1;
}
}
if(h->deblocking_filter == 2){
h->top_type = top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;
h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;
h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;
}else{
h->top_type = top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0;
h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0;
h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0;
}
if(IS_INTRA(mb_type))
return 0;
AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]);
AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]);
*((uint32_t*)&h->non_zero_count_cache[0+8*5])= *((uint32_t*)&h->non_zero_count[mb_xy][16]);
*((uint32_t*)&h->non_zero_count_cache[4+8*3])= *((uint32_t*)&h->non_zero_count[mb_xy][20]);
AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]);
h->cbp= h->cbp_table[mb_xy];
{
int list;
for(list=0; list<h->list_count; list++){
int8_t *ref;
int y, b_stride;
int16_t (*mv_dst)[2];
int16_t (*mv_src)[2];
if(!USES_LIST(mb_type, list)){
fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4);
*(uint32_t*)&h->ref_cache[list][scan8[ 0]] =
*(uint32_t*)&h->ref_cache[list][scan8[ 2]] =
*(uint32_t*)&h->ref_cache[list][scan8[ 8]] =
*(uint32_t*)&h->ref_cache[list][scan8[10]] = ((LIST_NOT_USED)&0xFF)*0x01010101;
continue;
}
ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]];
{
int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
*(uint32_t*)&h->ref_cache[list][scan8[ 0]] =
*(uint32_t*)&h->ref_cache[list][scan8[ 2]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;
ref += h->b8_stride;
*(uint32_t*)&h->ref_cache[list][scan8[ 8]] =
*(uint32_t*)&h->ref_cache[list][scan8[10]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;
}
b_stride = h->b_stride;
mv_dst = &h->mv_cache[list][scan8[0]];
mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];
for(y=0; y<4; y++){
AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride);
}
}
}
if(top_type){
*(uint32_t*)&h->non_zero_count_cache[4+8*0]= *(uint32_t*)&h->non_zero_count[top_xy][4+3*8];
}
if(left_type[0]){
h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8];
h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8];
h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8];
h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8];
}
if(!CABAC && h->pps.transform_8x8_mode){
if(IS_8x8DCT(top_type)){
h->non_zero_count_cache[4+8*0]=
h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4;
h->non_zero_count_cache[6+8*0]=
h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8;
}
if(IS_8x8DCT(left_type[0])){
h->non_zero_count_cache[3+8*1]=
h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2;
}
if(IS_8x8DCT(left_type[1])){
h->non_zero_count_cache[3+8*3]=
h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8;
}
if(IS_8x8DCT(mb_type)){
h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]=
h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp & 1;
h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]=
h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp & 2;
h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]=
h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp & 4;
h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]=
h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp & 8;
}
}
if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){
int list;
for(list=0; list<h->list_count; list++){
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;
int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);
h->ref_cache[list][scan8[0] + 0 - 1*8]=
h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]];
h->ref_cache[list][scan8[0] + 2 - 1*8]=
h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]];
}else{
AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);
*(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((LIST_NOT_USED)&0xFF)*0x01010101;
}
if(!IS_INTERLACED(mb_type^left_type[0])){
if(USES_LIST(left_type[0], list)){
const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1;
int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*0];
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 8 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*1];
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 +16 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*2];
*(uint32_t*)h->mv_cache[list][scan8[0] - 1 +24 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*3];
h->ref_cache[list][scan8[0] - 1 + 0 ]=
h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*0]];
h->ref_cache[list][scan8[0] - 1 +16 ]=
h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*1]];
}else{
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0 ]=
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 8 ]=
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 +16 ]=
*(uint32_t*)h->mv_cache [list][scan8[0] - 1 +24 ]= 0;
h->ref_cache[list][scan8[0] - 1 + 0 ]=
h->ref_cache[list][scan8[0] - 1 + 8 ]=
h->ref_cache[list][scan8[0] - 1 + 16 ]=
h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED;
}
}
}
}
return 0;
}
|
['static int fill_filter_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int top_xy, left_xy[2];\n int top_type, left_type[2];\n int i;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n left_xy[1] = left_xy[0] = mb_xy-1;\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[0] -= s->mb_stride;\n }\n }else{\n if(curr_mb_field_flag){\n top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n }\n }\n }\n h->top_mb_xy = top_xy;\n h->left_mb_xy[0] = left_xy[0];\n h->left_mb_xy[1] = left_xy[1];\n {\n int qp_thresh = h->qp_thresh;\n int qp = s->current_picture.qscale_table[mb_xy];\n if(qp <= qp_thresh\n && (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh)\n && (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){\n if(!FRAME_MBAFF)\n return 1;\n if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh)\n && (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh))\n return 1;\n }\n }\n if(h->deblocking_filter == 2){\n h->top_type = top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;\n h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;\n }else{\n h->top_type = top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0;\n h->left_type[0]= left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1]= left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0;\n }\n if(IS_INTRA(mb_type))\n return 0;\n AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]);\n AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]);\n *((uint32_t*)&h->non_zero_count_cache[0+8*5])= *((uint32_t*)&h->non_zero_count[mb_xy][16]);\n *((uint32_t*)&h->non_zero_count_cache[4+8*3])= *((uint32_t*)&h->non_zero_count[mb_xy][20]);\n AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]);\n h->cbp= h->cbp_table[mb_xy];\n {\n int list;\n for(list=0; list<h->list_count; list++){\n int8_t *ref;\n int y, b_stride;\n int16_t (*mv_dst)[2];\n int16_t (*mv_src)[2];\n if(!USES_LIST(mb_type, list)){\n fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4);\n *(uint32_t*)&h->ref_cache[list][scan8[ 0]] =\n *(uint32_t*)&h->ref_cache[list][scan8[ 2]] =\n *(uint32_t*)&h->ref_cache[list][scan8[ 8]] =\n *(uint32_t*)&h->ref_cache[list][scan8[10]] = ((LIST_NOT_USED)&0xFF)*0x01010101;\n continue;\n }\n ref = &s->current_picture.ref_index[list][h->mb2b8_xy[mb_xy]];\n {\n int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);\n *(uint32_t*)&h->ref_cache[list][scan8[ 0]] =\n *(uint32_t*)&h->ref_cache[list][scan8[ 2]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;\n ref += h->b8_stride;\n *(uint32_t*)&h->ref_cache[list][scan8[ 8]] =\n *(uint32_t*)&h->ref_cache[list][scan8[10]] = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101;\n }\n b_stride = h->b_stride;\n mv_dst = &h->mv_cache[list][scan8[0]];\n mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];\n for(y=0; y<4; y++){\n AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride);\n }\n }\n }\n if(top_type){\n *(uint32_t*)&h->non_zero_count_cache[4+8*0]= *(uint32_t*)&h->non_zero_count[top_xy][4+3*8];\n }\n if(left_type[0]){\n h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8];\n h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8];\n h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8];\n h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8];\n }\n if(!CABAC && h->pps.transform_8x8_mode){\n if(IS_8x8DCT(top_type)){\n h->non_zero_count_cache[4+8*0]=\n h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4;\n h->non_zero_count_cache[6+8*0]=\n h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8;\n }\n if(IS_8x8DCT(left_type[0])){\n h->non_zero_count_cache[3+8*1]=\n h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2;\n }\n if(IS_8x8DCT(left_type[1])){\n h->non_zero_count_cache[3+8*3]=\n h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8;\n }\n if(IS_8x8DCT(mb_type)){\n h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]=\n h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp & 1;\n h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]=\n h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp & 2;\n h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]=\n h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp & 4;\n h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]=\n h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp & 8;\n }\n }\n if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){\n int list;\n for(list=0; list<h->list_count; list++){\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;\n int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);\n AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);\n h->ref_cache[list][scan8[0] + 0 - 1*8]=\n h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]];\n h->ref_cache[list][scan8[0] + 2 - 1*8]=\n h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]];\n }else{\n AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);\n *(uint32_t*)&h->ref_cache[list][scan8[0] + 0 - 1*8]= ((LIST_NOT_USED)&0xFF)*0x01010101;\n }\n if(!IS_INTERLACED(mb_type^left_type[0])){\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2b_xy[left_xy[0]] + 3;\n const int b8_xy= h->mb2b8_xy[left_xy[0]] + 1;\n int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 0 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*0];\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 + 8 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*1];\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 +16 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*2];\n *(uint32_t*)h->mv_cache[list][scan8[0] - 1 +24 ]= *(uint32_t*)s->current_picture.motion_val[list][b_xy + h->b_stride*3];\n h->ref_cache[list][scan8[0] - 1 + 0 ]=\n h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*0]];\n h->ref_cache[list][scan8[0] - 1 +16 ]=\n h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + h->b8_stride*1]];\n }else{\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 0 ]=\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 + 8 ]=\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 +16 ]=\n *(uint32_t*)h->mv_cache [list][scan8[0] - 1 +24 ]= 0;\n h->ref_cache[list][scan8[0] - 1 + 0 ]=\n h->ref_cache[list][scan8[0] - 1 + 8 ]=\n h->ref_cache[list][scan8[0] - 1 + 16 ]=\n h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED;\n }\n }\n }\n }\n return 0;\n}']
|
1,326
| 0
|
https://github.com/openssl/openssl/blob/5ea564f154ebe8bda2a0e091a312e2058edf437f/crypto/bn/bn_lib.c/#L716
|
int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
{
int i;
BN_ULONG aa, bb;
aa = a[n - 1];
bb = b[n - 1];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
for (i = n - 2; i >= 0; i--) {
aa = a[i];
bb = b[i];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
}
return (0);
}
|
['int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(r);\n } else {\n ret = BN_one(r);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n aa = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!aa || !val[0])\n goto err;\n BN_RECP_CTX_init(&recp);\n if (m->neg) {\n if (!BN_copy(aa, m))\n goto err;\n aa->neg = 0;\n if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n goto err;\n } else {\n if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n goto err;\n }\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n if (BN_is_zero(val[0])) {\n BN_zero(r);\n ret = 1;\n goto err;\n }\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n if (!BN_one(r))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start)\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n goto err;\n }\n if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_RECP_CTX_free(&recp);\n bn_check_top(r);\n return (ret);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *a;\n const BIGNUM *ca;\n BN_CTX_start(ctx);\n if ((a = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (y != NULL) {\n if (x == y) {\n if (!BN_sqr(a, x, ctx))\n goto err;\n } else {\n if (!BN_mul(a, x, y, ctx))\n goto err;\n }\n ca = a;\n } else\n ca = x;\n ret = BN_div_recp(NULL, r, ca, recp, ctx);\n err:\n BN_CTX_end(ctx);\n bn_check_top(r);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}']
|
1,327
| 0
|
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_mont.c/#L125
|
static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
{
BIGNUM *n;
BN_ULONG *ap, *np, *rp, n0, v, carry;
int nl, max, i;
n = &(mont->N);
nl = n->top;
if (nl == 0) {
ret->top = 0;
return 1;
}
max = (2 * nl);
if (bn_wexpand(r, max) == NULL)
return 0;
r->neg ^= n->neg;
np = n->d;
rp = r->d;
i = max - r->top;
if (i)
memset(&rp[r->top], 0, sizeof(*rp) * i);
r->top = max;
r->flags |= BN_FLG_FIXED_TOP;
n0 = mont->n0[0];
for (carry = 0, i = 0; i < nl; i++, rp++) {
v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
v = (v + carry + rp[nl]) & BN_MASK2;
carry |= (v != rp[nl]);
carry &= (v <= rp[nl]);
rp[nl] = v;
}
if (bn_wexpand(ret, nl) == NULL)
return 0;
ret->top = nl;
ret->flags |= BN_FLG_FIXED_TOP;
ret->neg = r->neg;
rp = ret->d;
ap = &(r->d[nl]);
carry -= bn_sub_words(rp, ap, np, nl);
for (i = 0; i < nl; i++) {
rp[i] = (carry & ap[i]) | (~carry & rp[i]);
ap[i] = 0;
}
return 1;
}
|
['static int file_modmul(STANZA *s)\n{\n BIGNUM *a = NULL, *b = NULL, *m = NULL, *mod_mul = NULL, *ret = NULL;\n int st = 0;\n if (!TEST_ptr(a = getBN(s, "A"))\n || !TEST_ptr(b = getBN(s, "B"))\n || !TEST_ptr(m = getBN(s, "M"))\n || !TEST_ptr(mod_mul = getBN(s, "ModMul"))\n || !TEST_ptr(ret = BN_new()))\n goto err;\n if (!TEST_true(BN_mod_mul(ret, a, b, m, ctx))\n || !equalBN("A * B (mod M)", mod_mul, ret))\n goto err;\n if (BN_is_odd(m)) {\n BN_MONT_CTX *mont = BN_MONT_CTX_new();\n BIGNUM *a_tmp = BN_new();\n BIGNUM *b_tmp = BN_new();\n if (mont == NULL || a_tmp == NULL || b_tmp == NULL\n || !TEST_true(BN_MONT_CTX_set(mont, m, ctx))\n || !TEST_true(BN_nnmod(a_tmp, a, m, ctx))\n || !TEST_true(BN_nnmod(b_tmp, b, m, ctx))\n || !TEST_true(BN_to_montgomery(a_tmp, a_tmp, mont, ctx))\n || !TEST_true(BN_to_montgomery(b_tmp, b_tmp, mont, ctx))\n || !TEST_true(BN_mod_mul_montgomery(ret, a_tmp, b_tmp,\n mont, ctx))\n || !TEST_true(BN_from_montgomery(ret, ret, mont, ctx))\n || !equalBN("A * B (mod M) (mont)", mod_mul, ret))\n st = 0;\n else\n st = 1;\n BN_MONT_CTX_free(mont);\n BN_free(a_tmp);\n BN_free(b_tmp);\n if (st == 0)\n goto err;\n }\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(m);\n BN_free(mod_mul);\n BN_free(ret);\n return st;\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}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n int ret = bn_mul_mont_fixed_top(r, a, b, mont, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'static int bn_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return 1;\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return 0;\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n i = max - r->top;\n if (i)\n memset(&rp[r->top], 0, sizeof(*rp) * i);\n r->top = max;\n r->flags |= BN_FLG_FIXED_TOP;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return 0;\n ret->top = nl;\n ret->flags |= BN_FLG_FIXED_TOP;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n carry -= bn_sub_words(rp, ap, np, nl);\n for (i = 0; i < nl; i++) {\n rp[i] = (carry & ap[i]) | (~carry & rp[i]);\n ap[i] = 0;\n }\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,328
| 0
|
https://github.com/openssl/openssl/blob/3208ff58ca59d143b49dd2f1c05fbc33cf35e64f/crypto/lhash/lhash.c/#L365
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['static int ssl3_get_certificate_request(SSL *s)\n\t{\n\tint ok,ret=0;\n\tunsigned long n,nc,l;\n\tunsigned int llen,ctype_num,i;\n\tX509_NAME *xn=NULL;\n\tunsigned char *p,*d,*q;\n\tSTACK_OF(X509_NAME) *ca_sk=NULL;\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_CR_CERT_REQ_A,\n\t\tSSL3_ST_CR_CERT_REQ_B,\n\t\t-1,\n\t\ts->max_cert_list,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\ts->s3->tmp.cert_req=0;\n\tif (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)\n\t\t{\n\t\ts->s3->tmp.reuse_message=1;\n\t\treturn(1);\n\t\t}\n\tif (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (s->version > SSL3_VERSION)\n\t\t{\n\t\tl=s->s3->tmp.new_cipher->algorithms;\n\t\tif (l & SSL_aNULL)\n\t\t\t{\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\td=p=(unsigned char *)s->init_msg;\n\tif ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tctype_num= *(p++);\n\tif (ctype_num > SSL3_CT_NUMBER)\n\t\tctype_num=SSL3_CT_NUMBER;\n\tfor (i=0; i<ctype_num; i++)\n\t\ts->s3->tmp.ctype[i]= p[i];\n\tp+=ctype_num;\n\tn2s(p,llen);\n#if 0\n{\nFILE *out;\nout=fopen("/tmp/vsign.der","w");\nfwrite(p,1,llen,out);\nfclose(out);\n}\n#endif\n\tif ((llen+ctype_num+2+1) != n)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);\n\t\tgoto err;\n\t\t}\n\tfor (nc=0; nc<llen; )\n\t\t{\n\t\tn2s(p,l);\n\t\tif ((l+nc+2) > llen)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))\n\t\t\t\tgoto cont;\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tq=p;\n\t\tif ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)\n\t\t\t{\n\t\t\tif (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)\n\t\t\t\tgoto cont;\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\tif (q != (p+l))\n\t\t\t{\n\t\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!sk_X509_NAME_push(ca_sk,xn))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto err;\n\t\t\t}\n\t\tp+=l;\n\t\tnc+=l+2;\n\t\t}\n\tif (0)\n\t\t{\ncont:\n\t\tERR_clear_error();\n\t\t}\n\ts->s3->tmp.cert_req=1;\n\ts->s3->tmp.ctype_num=ctype_num;\n\tif (s->s3->tmp.ca_names != NULL)\n\t\tsk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);\n\ts->s3->tmp.ca_names=ca_sk;\n\tca_sk=NULL;\n\tret=1;\nerr:\n\tif (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);\n\treturn(ret);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\ts->init_msg = s->init_buf->data + 4;\n\t\ts->init_num = (int)s->s3->tmp.message_size;\n\t\treturn s->init_num;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\tint skip_message;\n\t\tdo\n\t\t\t{\n\t\t\twhile (s->init_num < 4)\n\t\t\t\t{\n\t\t\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t\t4 - s->init_num, 0);\n\t\t\t\tif (i <= 0)\n\t\t\t\t\t{\n\t\t\t\t\ts->rwstate=SSL_READING;\n\t\t\t\t\t*ok = 0;\n\t\t\t\t\treturn i;\n\t\t\t\t\t}\n\t\t\t\ts->init_num+=i;\n\t\t\t\t}\n\t\t\tskip_message = 0;\n\t\t\tif (!s->server)\n\t\t\t\tif (p[0] == SSL3_MT_HELLO_REQUEST)\n\t\t\t\t\tif (p[1] == 0 && p[2] == 0 &&p[3] == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\ts->init_num = 0;\n\t\t\t\t\t\tskip_message = 1;\n\t\t\t\t\t\tif (s->msg_callback)\n\t\t\t\t\t\t\ts->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, 4, s, s->msg_callback_arg);\n\t\t\t\t\t\t}\n\t\t\t}\n\t\twhile (skip_message);\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif ((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t\t\t(st1 == SSL3_ST_SR_CERT_A) &&\n\t\t\t\t\t(stn == SSL3_ST_SR_CERT_B))\n\t\t\t{\n\t\t\tssl3_init_finished_mac(s);\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l > (INT_MAX-4))\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l+4))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_msg = s->init_buf->data + 4;\n\t\ts->init_num = 0;\n\t\t}\n\tp = s->init_msg;\n\tn = s->s3->tmp.message_size - s->init_num;\n\twhile (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n,0);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\ts->rwstate=SSL_READING;\n\t\t\t*ok = 0;\n\t\t\treturn i;\n\t\t\t}\n\t\ts->init_num += i;\n\t\tn -= i;\n\t\t}\n\tssl3_finish_mac(s, (unsigned char *)s->init_buf->data, s->init_num + 4);\n\tif (s->msg_callback)\n\t\ts->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, s->init_buf->data, (size_t)s->init_num + 4, s, s->msg_callback_arg);\n\t*ok=1;\n\treturn s->init_num;\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn((void *)ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,329
| 0
|
https://github.com/openssl/openssl/blob/803e4e93d478594172bf67384b66873e52d5d0b6/crypto/rsa/rsa_eay.c/#L386
|
static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
const RSA_METHOD *meth;
BIGNUM f,ret;
int i,num=0,r= -1;
unsigned char *p;
unsigned char *buf=NULL;
BN_CTX *ctx=NULL;
meth = ENGINE_get_RSA(rsa->engine);
BN_init(&f);
BN_init(&ret);
ctx=BN_CTX_new();
if (ctx == NULL) goto err;
num=BN_num_bytes(rsa->n);
buf=(unsigned char *)OPENSSL_malloc(num);
if (buf == NULL)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
goto err;
}
if (flen > num)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
goto err;
}
if (BN_bin2bn(from,flen,&f) == NULL) goto err;
if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
{
if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
goto err;
}
if (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
rsa->_method_mod_n)) goto err;
p=buf;
i=BN_bn2bin(&ret,p);
switch (padding)
{
case RSA_PKCS1_PADDING:
r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
break;
case RSA_NO_PADDING:
r=RSA_padding_check_none(to,num,buf,i,num);
break;
default:
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
goto err;
}
if (r < 0)
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
err:
if (ctx != NULL) BN_CTX_free(ctx);
BN_clear_free(&f);
BN_clear_free(&ret);
if (buf != NULL)
{
memset(buf,0,num);
OPENSSL_free(buf);
}
return(r);
}
|
['static int RSA_eay_public_decrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tconst RSA_METHOD *meth;\n\tBIGNUM f,ret;\n\tint i,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tmeth = ENGINE_get_RSA(rsa->engine);\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\tbuf=(unsigned char *)OPENSSL_malloc(num);\n\tif (buf == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_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_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,flen,&f) == NULL) goto err;\n\tif ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))\n\t\t{\n\t\tif ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))\n\t\t\t goto err;\n\t\t}\n\tif (!meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tp=buf;\n\ti=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,i,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_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\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'const RSA_METHOD *ENGINE_get_RSA(ENGINE *e)\n\t{\n\tif(e == NULL)\n\t\t{\n\t\tENGINEerr(ENGINE_F_ENGINE_GET_RSA,\n\t\t\tERR_R_PASSED_NULL_PARAMETER);\n\t\treturn NULL;\n\t\t}\n\treturn e->rsa_meth;\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'void BN_init(BIGNUM *a)\n\t{\n\tmemset(a,0,sizeof(BIGNUM));\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_func(num);\n#ifdef LEVITTE_DEBUG\n\tfprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n\treturn ret;\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\tassert(l != 0);\n\ti=(a->top-1)*BN_BITS2;\n\treturn(i+BN_num_bits_word(l));\n\t}']
|
1,330
| 0
|
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/record/rec_layer_s3.c/#L897
|
int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
unsigned int len)
{
int i;
SSL3_BUFFER *wb = s->rlayer.wbuf;
unsigned int currbuf = 0;
if ((s->rlayer.wpend_tot > (int)len)
|| ((s->rlayer.wpend_buf != buf) &&
!(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))
|| (s->rlayer.wpend_type != type)) {
SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY);
return (-1);
}
for (;;) {
if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0
&& currbuf < s->rlayer.numwpipes - 1) {
currbuf++;
continue;
}
clear_sys_error();
if (s->wbio != NULL) {
s->rwstate = SSL_WRITING;
i = BIO_write(s->wbio, (char *)
&(SSL3_BUFFER_get_buf(&wb[currbuf])
[SSL3_BUFFER_get_offset(&wb[currbuf])]),
(unsigned int)SSL3_BUFFER_get_left(&wb[currbuf]));
} else {
SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BIO_NOT_SET);
i = -1;
}
if (i == SSL3_BUFFER_get_left(&wb[currbuf])) {
SSL3_BUFFER_set_left(&wb[currbuf], 0);
SSL3_BUFFER_add_offset(&wb[currbuf], i);
if (currbuf + 1 < s->rlayer.numwpipes)
continue;
s->rwstate = SSL_NOTHING;
return (s->rlayer.wpend_ret);
} else if (i <= 0) {
if (SSL_IS_DTLS(s)) {
SSL3_BUFFER_set_left(&wb[currbuf], 0);
}
return (i);
}
SSL3_BUFFER_add_offset(&wb[currbuf], i);
SSL3_BUFFER_add_left(&wb[currbuf], -i);
}
}
|
['int dtls1_read_bytes(SSL *s, int type, int *recvd_type, unsigned char *buf,\n int len, int peek)\n{\n int al, i, j, ret;\n unsigned int n;\n SSL3_RECORD *rr;\n void (*cb) (const SSL *ssl, int type2, int val) = NULL;\n if (!SSL3_BUFFER_is_initialised(&s->rlayer.rbuf)) {\n if (!ssl3_setup_buffers(s))\n return (-1);\n }\n if ((type && (type != SSL3_RT_APPLICATION_DATA) &&\n (type != SSL3_RT_HANDSHAKE)) ||\n (peek && (type != SSL3_RT_APPLICATION_DATA))) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n if ((ret = have_handshake_fragment(s, type, buf, len)))\n return ret;\n#ifndef OPENSSL_NO_SCTP\n if ((!ossl_statem_get_in_handshake(s) && SSL_in_init(s)) ||\n (BIO_dgram_is_sctp(SSL_get_rbio(s))\n && ossl_statem_in_sctp_read_sock(s)\n && s->s3->in_read_app_data != 2))\n#else\n if (!ossl_statem_get_in_handshake(s) && SSL_in_init(s))\n#endif\n {\n i = s->handshake_func(s);\n if (i < 0)\n return (i);\n if (i == 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n return (-1);\n }\n }\n start:\n s->rwstate = SSL_NOTHING;\n rr = s->rlayer.rrec;\n if (SSL_is_init_finished(s) && SSL3_RECORD_get_length(rr) == 0) {\n pitem *item;\n item = pqueue_pop(s->rlayer.d->buffered_app_data.q);\n if (item) {\n#ifndef OPENSSL_NO_SCTP\n if (BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n DTLS1_RECORD_DATA *rdata = (DTLS1_RECORD_DATA *)item->data;\n BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SCTP_SET_RCVINFO,\n sizeof(rdata->recordinfo), &rdata->recordinfo);\n }\n#endif\n dtls1_copy_record(s, item);\n OPENSSL_free(item->data);\n pitem_free(item);\n }\n }\n if (dtls1_handle_timeout(s) > 0)\n goto start;\n if ((SSL3_RECORD_get_length(rr) == 0)\n || (s->rlayer.rstate == SSL_ST_READ_BODY)) {\n ret = dtls1_get_record(s);\n if (ret <= 0) {\n ret = dtls1_read_failed(s, ret);\n if (ret <= 0)\n return (ret);\n else\n goto start;\n }\n }\n if (s->s3->change_cipher_spec\n && (SSL3_RECORD_get_type(rr) != SSL3_RT_HANDSHAKE)) {\n if (dtls1_buffer_record(s, &(s->rlayer.d->buffered_app_data),\n SSL3_RECORD_get_seq_num(rr)) < 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n return -1;\n }\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {\n SSL3_RECORD_set_length(rr, 0);\n s->rwstate = SSL_NOTHING;\n return (0);\n }\n if (type == SSL3_RECORD_get_type(rr)\n || (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC\n && type == SSL3_RT_HANDSHAKE && recvd_type != NULL)) {\n if (SSL_in_init(s) && (type == SSL3_RT_APPLICATION_DATA) &&\n (s->enc_read_ctx == NULL)) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_APP_DATA_IN_HANDSHAKE);\n goto f_err;\n }\n if (recvd_type != NULL)\n *recvd_type = SSL3_RECORD_get_type(rr);\n if (len <= 0)\n return (len);\n if ((unsigned int)len > SSL3_RECORD_get_length(rr))\n n = SSL3_RECORD_get_length(rr);\n else\n n = (unsigned int)len;\n memcpy(buf, &(SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)]), n);\n if (!peek) {\n SSL3_RECORD_sub_length(rr, n);\n SSL3_RECORD_add_off(rr, n);\n if (SSL3_RECORD_get_length(rr) == 0) {\n s->rlayer.rstate = SSL_ST_READ_HEADER;\n SSL3_RECORD_set_off(rr, 0);\n }\n }\n#ifndef OPENSSL_NO_SCTP\n if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n SSL3_RECORD_get_type(rr) == SSL3_RT_APPLICATION_DATA &&\n ossl_statem_in_sctp_read_sock(s)) {\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(SSL_get_rbio(s));\n BIO_set_retry_read(SSL_get_rbio(s));\n }\n if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n s->d1->shutdown_received\n && !BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n return (0);\n }\n#endif\n return (n);\n }\n {\n unsigned int k, dest_maxlen = 0;\n unsigned char *dest = NULL;\n unsigned int *dest_len = NULL;\n if (SSL3_RECORD_get_type(rr) == SSL3_RT_HANDSHAKE) {\n dest_maxlen = sizeof s->rlayer.d->handshake_fragment;\n dest = s->rlayer.d->handshake_fragment;\n dest_len = &s->rlayer.d->handshake_fragment_len;\n } else if (SSL3_RECORD_get_type(rr) == SSL3_RT_ALERT) {\n dest_maxlen = sizeof(s->rlayer.d->alert_fragment);\n dest = s->rlayer.d->alert_fragment;\n dest_len = &s->rlayer.d->alert_fragment_len;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n else if (SSL3_RECORD_get_type(rr) == DTLS1_RT_HEARTBEAT) {\n if (dtls1_process_heartbeat(s, SSL3_RECORD_get_data(rr),\n SSL3_RECORD_get_length(rr)) < 0) {\n return -1;\n }\n SSL3_RECORD_set_length(rr, 0);\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(SSL_get_rbio(s));\n BIO_set_retry_read(SSL_get_rbio(s));\n return (-1);\n }\n#endif\n else if (SSL3_RECORD_get_type(rr) != SSL3_RT_CHANGE_CIPHER_SPEC) {\n if (SSL3_RECORD_get_type(rr) == SSL3_RT_APPLICATION_DATA) {\n BIO *bio;\n s->s3->in_read_app_data = 2;\n bio = SSL_get_rbio(s);\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(bio);\n BIO_set_retry_read(bio);\n return (-1);\n }\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n goto f_err;\n }\n if (dest_maxlen > 0) {\n if (SSL3_RECORD_get_length(rr) < dest_maxlen) {\n#ifdef DTLS1_AD_MISSING_HANDSHAKE_MESSAGE\n FIX ME;\n#endif\n s->rlayer.rstate = SSL_ST_READ_HEADER;\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n for (k = 0; k < dest_maxlen; k++) {\n dest[k] = SSL3_RECORD_get_data(rr)[SSL3_RECORD_get_off(rr)];\n SSL3_RECORD_add_off(rr, 1);\n SSL3_RECORD_add_length(rr, -1);\n }\n *dest_len = dest_maxlen;\n }\n }\n if ((!s->server) &&\n (s->rlayer.d->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n (s->rlayer.d->handshake_fragment[0] == SSL3_MT_HELLO_REQUEST) &&\n (s->session != NULL) && (s->session->cipher != NULL)) {\n s->rlayer.d->handshake_fragment_len = 0;\n if ((s->rlayer.d->handshake_fragment[1] != 0) ||\n (s->rlayer.d->handshake_fragment[2] != 0) ||\n (s->rlayer.d->handshake_fragment[3] != 0)) {\n al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_BAD_HELLO_REQUEST);\n goto f_err;\n }\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n s->rlayer.d->handshake_fragment, 4, s,\n s->msg_callback_arg);\n if (SSL_is_init_finished(s) &&\n !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) &&\n !s->s3->renegotiate) {\n s->d1->handshake_read_seq++;\n s->new_session = 1;\n ssl3_renegotiate(s);\n if (ssl3_renegotiate_check(s)) {\n i = s->handshake_func(s);\n if (i < 0)\n return (i);\n if (i == 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n return (-1);\n }\n if (!(s->mode & SSL_MODE_AUTO_RETRY)) {\n if (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0) {\n BIO *bio;\n s->rwstate = SSL_READING;\n bio = SSL_get_rbio(s);\n BIO_clear_retry_flags(bio);\n BIO_set_retry_read(bio);\n return (-1);\n }\n }\n }\n }\n goto start;\n }\n if (s->rlayer.d->alert_fragment_len >= DTLS1_AL_HEADER_LENGTH) {\n int alert_level = s->rlayer.d->alert_fragment[0];\n int alert_descr = s->rlayer.d->alert_fragment[1];\n s->rlayer.d->alert_fragment_len = 0;\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_ALERT,\n s->rlayer.d->alert_fragment, 2, s,\n s->msg_callback_arg);\n if (s->info_callback != NULL)\n cb = s->info_callback;\n else if (s->ctx->info_callback != NULL)\n cb = s->ctx->info_callback;\n if (cb != NULL) {\n j = (alert_level << 8) | alert_descr;\n cb(s, SSL_CB_READ_ALERT, j);\n }\n if (alert_level == SSL3_AL_WARNING) {\n s->s3->warn_alert = alert_descr;\n if (alert_descr == SSL_AD_CLOSE_NOTIFY) {\n#ifndef OPENSSL_NO_SCTP\n if (BIO_dgram_is_sctp(SSL_get_rbio(s)) &&\n BIO_dgram_sctp_msg_waiting(SSL_get_rbio(s))) {\n s->d1->shutdown_received = 1;\n s->rwstate = SSL_READING;\n BIO_clear_retry_flags(SSL_get_rbio(s));\n BIO_set_retry_read(SSL_get_rbio(s));\n return -1;\n }\n#endif\n s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n return (0);\n }\n#if 0\n if (alert_descr == DTLS1_AD_MISSING_HANDSHAKE_MESSAGE) {\n unsigned short seq;\n unsigned int frag_off;\n unsigned char *p = &(s->rlayer.d->alert_fragment[2]);\n n2s(p, seq);\n n2l3(p, frag_off);\n dtls1_retransmit_message(s,\n dtls1_get_queue_priority\n (frag->msg_header.seq, 0), frag_off,\n &found);\n if (!found && SSL_in_init(s)) {\n ssl3_send_alert(s, SSL3_AL_WARNING,\n DTLS1_AD_MISSING_HANDSHAKE_MESSAGE);\n }\n }\n#endif\n } else if (alert_level == SSL3_AL_FATAL) {\n char tmp[16];\n s->rwstate = SSL_NOTHING;\n s->s3->fatal_alert = alert_descr;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_AD_REASON_OFFSET + alert_descr);\n BIO_snprintf(tmp, sizeof tmp, "%d", alert_descr);\n ERR_add_error_data(2, "SSL alert number ", tmp);\n s->shutdown |= SSL_RECEIVED_SHUTDOWN;\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return (0);\n } else {\n al = SSL_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNKNOWN_ALERT_TYPE);\n goto f_err;\n }\n goto start;\n }\n if (s->shutdown & SSL_SENT_SHUTDOWN) {\n s->rwstate = SSL_NOTHING;\n SSL3_RECORD_set_length(rr, 0);\n return (0);\n }\n if (SSL3_RECORD_get_type(rr) == SSL3_RT_CHANGE_CIPHER_SPEC) {\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if ((s->rlayer.d->handshake_fragment_len >= DTLS1_HM_HEADER_LENGTH) &&\n !ossl_statem_get_in_handshake(s)) {\n struct hm_header_st msg_hdr;\n dtls1_get_message_header(rr->data, &msg_hdr);\n if (SSL3_RECORD_get_epoch(rr) != s->rlayer.d->r_epoch) {\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if (msg_hdr.type == SSL3_MT_FINISHED) {\n if (dtls1_check_timeout_num(s) < 0)\n return -1;\n dtls1_retransmit_buffered_messages(s);\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n if (SSL_is_init_finished(s) &&\n !(s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)) {\n ossl_statem_set_in_init(s, 1);\n s->renegotiate = 1;\n s->new_session = 1;\n }\n i = s->handshake_func(s);\n if (i < 0)\n return (i);\n if (i == 0) {\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);\n return (-1);\n }\n if (!(s->mode & SSL_MODE_AUTO_RETRY)) {\n if (SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0) {\n BIO *bio;\n s->rwstate = SSL_READING;\n bio = SSL_get_rbio(s);\n BIO_clear_retry_flags(bio);\n BIO_set_retry_read(bio);\n return (-1);\n }\n }\n goto start;\n }\n switch (SSL3_RECORD_get_type(rr)) {\n default:\n if (s->version == TLS1_VERSION) {\n SSL3_RECORD_set_length(rr, 0);\n goto start;\n }\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n goto f_err;\n case SSL3_RT_CHANGE_CIPHER_SPEC:\n case SSL3_RT_ALERT:\n case SSL3_RT_HANDSHAKE:\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, ERR_R_INTERNAL_ERROR);\n goto f_err;\n case SSL3_RT_APPLICATION_DATA:\n if (s->s3->in_read_app_data &&\n (s->s3->total_renegotiations != 0) &&\n ossl_statem_app_data_allowed(s)) {\n s->s3->in_read_app_data = 2;\n return (-1);\n } else {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS1_READ_BYTES, SSL_R_UNEXPECTED_RECORD);\n goto f_err;\n }\n }\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n return (-1);\n}', 'int dtls1_handle_timeout(SSL *s)\n{\n if (!dtls1_is_timer_expired(s)) {\n return 0;\n }\n dtls1_double_timeout(s);\n if (dtls1_check_timeout_num(s) < 0)\n return -1;\n s->d1->timeout.read_timeouts++;\n if (s->d1->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) {\n s->d1->timeout.read_timeouts = 1;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if (s->tlsext_hb_pending) {\n s->tlsext_hb_pending = 0;\n return dtls1_heartbeat(s);\n }\n#endif\n dtls1_start_timer(s);\n return dtls1_retransmit_buffered_messages(s);\n}', 'int dtls1_get_record(SSL *s)\n{\n int ssl_major, ssl_minor;\n int i, n;\n SSL3_RECORD *rr;\n unsigned char *p = NULL;\n unsigned short version;\n DTLS1_BITMAP *bitmap;\n unsigned int is_next_epoch;\n rr = RECORD_LAYER_get_rrec(&s->rlayer);\n if (dtls1_process_buffered_records(s) < 0)\n return -1;\n if (dtls1_get_processed_record(s))\n return 1;\n again:\n if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) ||\n (RECORD_LAYER_get_packet_length(&s->rlayer) < DTLS1_RT_HEADER_LENGTH)) {\n n = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH,\n SSL3_BUFFER_get_len(&s->rlayer.rbuf), 0, 1);\n if (n <= 0)\n return (n);\n if (RECORD_LAYER_get_packet_length(&s->rlayer) !=\n DTLS1_RT_HEADER_LENGTH) {\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);\n p = RECORD_LAYER_get_packet(&s->rlayer);\n if (s->msg_callback)\n s->msg_callback(0, 0, SSL3_RT_HEADER, p, DTLS1_RT_HEADER_LENGTH,\n s, s->msg_callback_arg);\n rr->type = *(p++);\n ssl_major = *(p++);\n ssl_minor = *(p++);\n version = (ssl_major << 8) | ssl_minor;\n n2s(p, rr->epoch);\n memcpy(&(RECORD_LAYER_get_read_sequence(&s->rlayer)[2]), p, 6);\n p += 6;\n n2s(p, rr->length);\n if (!s->first_packet) {\n if (version != s->version) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n }\n if ((version & 0xff00) != (s->version & 0xff00)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n }\n if (rr->length >\n RECORD_LAYER_get_packet_length(&s->rlayer) - DTLS1_RT_HEADER_LENGTH) {\n i = rr->length;\n n = ssl3_read_n(s, i, i, 1, 1);\n if (n != i) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n }\n RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER);\n bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);\n if (bitmap == NULL) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n#ifndef OPENSSL_NO_SCTP\n if (!BIO_dgram_is_sctp(SSL_get_rbio(s))) {\n#endif\n if (!dtls1_record_replay_check(s, bitmap)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n#ifndef OPENSSL_NO_SCTP\n }\n#endif\n if (rr->length == 0)\n goto again;\n if (is_next_epoch) {\n if ((SSL_in_init(s) || ossl_statem_get_in_handshake(s))) {\n if (dtls1_buffer_record\n (s, &(DTLS_RECORD_LAYER_get_unprocessed_rcds(&s->rlayer)),\n rr->seq_num) < 0)\n return -1;\n dtls1_record_bitmap_update(s, bitmap);\n }\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n if (!dtls1_process_record(s)) {\n rr->length = 0;\n RECORD_LAYER_reset_packet_length(&s->rlayer);\n goto again;\n }\n dtls1_record_bitmap_update(s, bitmap);\n return (1);\n}', 'int dtls1_process_buffered_records(SSL *s)\n{\n pitem *item;\n item = pqueue_peek(s->rlayer.d->unprocessed_rcds.q);\n if (item) {\n if (s->rlayer.d->unprocessed_rcds.epoch != s->rlayer.d->r_epoch)\n return (1);\n while (pqueue_peek(s->rlayer.d->unprocessed_rcds.q)) {\n dtls1_get_unprocessed_record(s);\n if (!dtls1_process_record(s))\n return (0);\n if (dtls1_buffer_record(s, &(s->rlayer.d->processed_rcds),\n SSL3_RECORD_get_seq_num(s->rlayer.rrec)) <\n 0)\n return -1;\n }\n }\n s->rlayer.d->processed_rcds.epoch = s->rlayer.d->r_epoch;\n s->rlayer.d->unprocessed_rcds.epoch = s->rlayer.d->r_epoch + 1;\n return (1);\n}', 'int dtls1_read_failed(SSL *s, int code)\n{\n if (code > 0) {\n SSLerr(SSL_F_DTLS1_READ_FAILED, ERR_R_INTERNAL_ERROR);\n return 1;\n }\n if (!dtls1_is_timer_expired(s)) {\n return code;\n }\n#ifndef OPENSSL_NO_HEARTBEATS\n if (!SSL_in_init(s) && !s->tlsext_hb_pending)\n#else\n if (!SSL_in_init(s))\n#endif\n {\n BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ);\n return code;\n }\n return dtls1_handle_timeout(s);\n}', 'int dtls1_retransmit_buffered_messages(SSL *s)\n{\n pqueue *sent = s->d1->sent_messages;\n piterator iter;\n pitem *item;\n hm_fragment *frag;\n int found = 0;\n iter = pqueue_iterator(sent);\n for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) {\n frag = (hm_fragment *)item->data;\n if (dtls1_retransmit_message(s, (unsigned short)\n dtls1_get_queue_priority\n (frag->msg_header.seq,\n frag->msg_header.is_ccs), &found) <= 0)\n return -1;\n }\n return 1;\n}', 'int dtls1_retransmit_message(SSL *s, unsigned short seq, int *found)\n{\n int ret;\n pitem *item;\n hm_fragment *frag;\n unsigned long header_length;\n unsigned char seq64be[8];\n struct dtls1_retransmit_state saved_state;\n memset(seq64be, 0, sizeof(seq64be));\n seq64be[6] = (unsigned char)(seq >> 8);\n seq64be[7] = (unsigned char)seq;\n item = pqueue_find(s->d1->sent_messages, seq64be);\n if (item == NULL) {\n SSLerr(SSL_F_DTLS1_RETRANSMIT_MESSAGE, ERR_R_INTERNAL_ERROR);\n *found = 0;\n return 0;\n }\n *found = 1;\n frag = (hm_fragment *)item->data;\n if (frag->msg_header.is_ccs)\n header_length = DTLS1_CCS_HEADER_LENGTH;\n else\n header_length = DTLS1_HM_HEADER_LENGTH;\n memcpy(s->init_buf->data, frag->fragment,\n frag->msg_header.msg_len + header_length);\n s->init_num = frag->msg_header.msg_len + header_length;\n dtls1_set_message_header_int(s, frag->msg_header.type,\n frag->msg_header.msg_len,\n frag->msg_header.seq, 0,\n frag->msg_header.frag_len);\n saved_state.enc_write_ctx = s->enc_write_ctx;\n saved_state.write_hash = s->write_hash;\n saved_state.compress = s->compress;\n saved_state.session = s->session;\n saved_state.epoch = DTLS_RECORD_LAYER_get_w_epoch(&s->rlayer);\n s->d1->retransmitting = 1;\n s->enc_write_ctx = frag->msg_header.saved_retransmit_state.enc_write_ctx;\n s->write_hash = frag->msg_header.saved_retransmit_state.write_hash;\n s->compress = frag->msg_header.saved_retransmit_state.compress;\n s->session = frag->msg_header.saved_retransmit_state.session;\n DTLS_RECORD_LAYER_set_saved_w_epoch(&s->rlayer,\n frag->msg_header.\n saved_retransmit_state.epoch);\n ret = dtls1_do_write(s, frag->msg_header.is_ccs ?\n SSL3_RT_CHANGE_CIPHER_SPEC : SSL3_RT_HANDSHAKE);\n s->enc_write_ctx = saved_state.enc_write_ctx;\n s->write_hash = saved_state.write_hash;\n s->compress = saved_state.compress;\n s->session = saved_state.session;\n DTLS_RECORD_LAYER_set_saved_w_epoch(&s->rlayer, saved_state.epoch);\n s->d1->retransmitting = 0;\n (void)BIO_flush(s->wbio);\n return ret;\n}', 'int dtls1_do_write(SSL *s, int type)\n{\n int ret;\n unsigned int curr_mtu;\n int retry = 1;\n unsigned int len, frag_off, mac_size, blocksize, used_len;\n if (!dtls1_query_mtu(s))\n return -1;\n if (s->d1->mtu < dtls1_min_mtu(s))\n return -1;\n if (s->init_off == 0 && type == SSL3_RT_HANDSHAKE)\n OPENSSL_assert(s->init_num ==\n (int)s->d1->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH);\n if (s->write_hash) {\n if (s->enc_write_ctx\n && (EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(s->enc_write_ctx)) &\n EVP_CIPH_FLAG_AEAD_CIPHER) != 0)\n mac_size = 0;\n else\n mac_size = EVP_MD_CTX_size(s->write_hash);\n } else\n mac_size = 0;\n if (s->enc_write_ctx &&\n (EVP_CIPHER_CTX_mode(s->enc_write_ctx) == EVP_CIPH_CBC_MODE))\n blocksize = 2 * EVP_CIPHER_CTX_block_size(s->enc_write_ctx);\n else\n blocksize = 0;\n frag_off = 0;\n s->rwstate = SSL_NOTHING;\n while (s->init_num > 0) {\n if (type == SSL3_RT_HANDSHAKE && s->init_off != 0) {\n if (frag_off > 0) {\n if (s->init_off <= DTLS1_HM_HEADER_LENGTH) {\n return -1;\n }\n s->init_off -= DTLS1_HM_HEADER_LENGTH;\n s->init_num += DTLS1_HM_HEADER_LENGTH;\n } else {\n frag_off = s->d1->w_msg_hdr.frag_off;\n }\n }\n used_len = BIO_wpending(s->wbio) + DTLS1_RT_HEADER_LENGTH\n + mac_size + blocksize;\n if (s->d1->mtu > used_len)\n curr_mtu = s->d1->mtu - used_len;\n else\n curr_mtu = 0;\n if (curr_mtu <= DTLS1_HM_HEADER_LENGTH) {\n ret = BIO_flush(s->wbio);\n if (ret <= 0) {\n s->rwstate = SSL_WRITING;\n return ret;\n }\n used_len = DTLS1_RT_HEADER_LENGTH + mac_size + blocksize;\n if (s->d1->mtu > used_len + DTLS1_HM_HEADER_LENGTH) {\n curr_mtu = s->d1->mtu - used_len;\n } else {\n return -1;\n }\n }\n if (((unsigned int)s->init_num) > curr_mtu)\n len = curr_mtu;\n else\n len = s->init_num;\n if (len > INT_MAX)\n len = INT_MAX;\n if (type == SSL3_RT_HANDSHAKE) {\n if (len < DTLS1_HM_HEADER_LENGTH) {\n return -1;\n }\n dtls1_fix_message_header(s, frag_off, len - DTLS1_HM_HEADER_LENGTH);\n dtls1_write_message_header(s,\n (unsigned char *)&s->init_buf->\n data[s->init_off]);\n }\n ret = dtls1_write_bytes(s, type, &s->init_buf->data[s->init_off], len);\n if (ret < 0) {\n if (retry && BIO_ctrl(SSL_get_wbio(s),\n BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0) {\n if (!(SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) {\n if (!dtls1_query_mtu(s))\n return -1;\n retry = 0;\n } else\n return -1;\n } else {\n return (-1);\n }\n } else {\n OPENSSL_assert(len == (unsigned int)ret);\n if (type == SSL3_RT_HANDSHAKE && !s->d1->retransmitting) {\n unsigned char *p =\n (unsigned char *)&s->init_buf->data[s->init_off];\n const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;\n int xlen;\n if (frag_off == 0 && s->version != DTLS1_BAD_VER) {\n *p++ = msg_hdr->type;\n l2n3(msg_hdr->msg_len, p);\n s2n(msg_hdr->seq, p);\n l2n3(0, p);\n l2n3(msg_hdr->msg_len, p);\n p -= DTLS1_HM_HEADER_LENGTH;\n xlen = ret;\n } else {\n p += DTLS1_HM_HEADER_LENGTH;\n xlen = ret - DTLS1_HM_HEADER_LENGTH;\n }\n if (!ssl3_finish_mac(s, p, xlen))\n return -1;\n }\n if (ret == s->init_num) {\n if (s->msg_callback)\n s->msg_callback(1, s->version, type, s->init_buf->data,\n (size_t)(s->init_off + s->init_num), s,\n s->msg_callback_arg);\n s->init_off = 0;\n s->init_num = 0;\n return (1);\n }\n s->init_off += ret;\n s->init_num -= ret;\n ret -= DTLS1_HM_HEADER_LENGTH;\n frag_off += ret;\n dtls1_fix_message_header(s, frag_off, 0);\n }\n }\n return (0);\n}', 'int dtls1_write_bytes(SSL *s, int type, const void *buf, int len)\n{\n int i;\n OPENSSL_assert(len <= SSL3_RT_MAX_PLAIN_LENGTH);\n s->rwstate = SSL_NOTHING;\n i = do_dtls1_write(s, type, buf, len, 0);\n return i;\n}', 'int do_dtls1_write(SSL *s, int type, const unsigned char *buf,\n unsigned int len, int create_empty_fragment)\n{\n unsigned char *p, *pseq;\n int i, mac_size, clear = 0;\n int prefix_len = 0;\n int eivlen;\n SSL3_RECORD wr;\n SSL3_BUFFER *wb;\n SSL_SESSION *sess;\n wb = &s->rlayer.wbuf[0];\n if (SSL3_BUFFER_get_left(wb) != 0) {\n OPENSSL_assert(0);\n return (ssl3_write_pending(s, type, buf, len));\n }\n if (s->s3->alert_dispatch) {\n i = s->method->ssl_dispatch_alert(s);\n if (i <= 0)\n return (i);\n }\n if (len == 0 && !create_empty_fragment)\n return 0;\n sess = s->session;\n if ((sess == NULL) ||\n (s->enc_write_ctx == NULL) || (EVP_MD_CTX_md(s->write_hash) == NULL))\n clear = 1;\n if (clear)\n mac_size = 0;\n else {\n mac_size = EVP_MD_CTX_size(s->write_hash);\n if (mac_size < 0)\n goto err;\n }\n p = SSL3_BUFFER_get_buf(wb) + prefix_len;\n *(p++) = type & 0xff;\n SSL3_RECORD_set_type(&wr, type);\n if (s->method->version == DTLS_ANY_VERSION &&\n s->max_proto_version != DTLS1_BAD_VER) {\n *(p++) = DTLS1_VERSION >> 8;\n *(p++) = DTLS1_VERSION & 0xff;\n } else {\n *(p++) = s->version >> 8;\n *(p++) = s->version & 0xff;\n }\n pseq = p;\n p += 10;\n if (s->enc_write_ctx) {\n int mode = EVP_CIPHER_CTX_mode(s->enc_write_ctx);\n if (mode == EVP_CIPH_CBC_MODE) {\n eivlen = EVP_CIPHER_CTX_iv_length(s->enc_write_ctx);\n if (eivlen <= 1)\n eivlen = 0;\n }\n else if (mode == EVP_CIPH_GCM_MODE)\n eivlen = EVP_GCM_TLS_EXPLICIT_IV_LEN;\n else if (mode == EVP_CIPH_CCM_MODE)\n eivlen = EVP_CCM_TLS_EXPLICIT_IV_LEN;\n else\n eivlen = 0;\n } else\n eivlen = 0;\n SSL3_RECORD_set_data(&wr, p + eivlen);\n SSL3_RECORD_set_length(&wr, (int)len);\n SSL3_RECORD_set_input(&wr, (unsigned char *)buf);\n if (s->compress != NULL) {\n if (!ssl3_do_compress(s, &wr)) {\n SSLerr(SSL_F_DO_DTLS1_WRITE, SSL_R_COMPRESSION_FAILURE);\n goto err;\n }\n } else {\n memcpy(SSL3_RECORD_get_data(&wr), SSL3_RECORD_get_input(&wr),\n SSL3_RECORD_get_length(&wr));\n SSL3_RECORD_reset_input(&wr);\n }\n if (mac_size != 0) {\n if (s->method->ssl3_enc->mac(s, &wr,\n &(p[SSL3_RECORD_get_length(&wr) + eivlen]),\n 1) < 0)\n goto err;\n SSL3_RECORD_add_length(&wr, mac_size);\n }\n SSL3_RECORD_set_data(&wr, p);\n SSL3_RECORD_reset_input(&wr);\n if (eivlen)\n SSL3_RECORD_add_length(&wr, eivlen);\n if (s->method->ssl3_enc->enc(s, &wr, 1, 1) < 1)\n goto err;\n s2n(s->rlayer.d->w_epoch, pseq);\n memcpy(pseq, &(s->rlayer.write_sequence[2]), 6);\n pseq += 6;\n s2n(SSL3_RECORD_get_length(&wr), pseq);\n if (s->msg_callback)\n s->msg_callback(1, 0, SSL3_RT_HEADER, pseq - DTLS1_RT_HEADER_LENGTH,\n DTLS1_RT_HEADER_LENGTH, s, s->msg_callback_arg);\n SSL3_RECORD_set_type(&wr, type);\n SSL3_RECORD_add_length(&wr, DTLS1_RT_HEADER_LENGTH);\n ssl3_record_sequence_update(&(s->rlayer.write_sequence[0]));\n if (create_empty_fragment) {\n return wr.length;\n }\n SSL3_BUFFER_set_left(wb, prefix_len + SSL3_RECORD_get_length(&wr));\n SSL3_BUFFER_set_offset(wb, 0);\n s->rlayer.wpend_tot = len;\n s->rlayer.wpend_buf = buf;\n s->rlayer.wpend_type = type;\n s->rlayer.wpend_ret = len;\n return ssl3_write_pending(s, type, buf, len);\n err:\n return -1;\n}', 'int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,\n unsigned int len)\n{\n int i;\n SSL3_BUFFER *wb = s->rlayer.wbuf;\n unsigned int currbuf = 0;\n if ((s->rlayer.wpend_tot > (int)len)\n || ((s->rlayer.wpend_buf != buf) &&\n !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))\n || (s->rlayer.wpend_type != type)) {\n SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY);\n return (-1);\n }\n for (;;) {\n if (SSL3_BUFFER_get_left(&wb[currbuf]) == 0\n && currbuf < s->rlayer.numwpipes - 1) {\n currbuf++;\n continue;\n }\n clear_sys_error();\n if (s->wbio != NULL) {\n s->rwstate = SSL_WRITING;\n i = BIO_write(s->wbio, (char *)\n &(SSL3_BUFFER_get_buf(&wb[currbuf])\n [SSL3_BUFFER_get_offset(&wb[currbuf])]),\n (unsigned int)SSL3_BUFFER_get_left(&wb[currbuf]));\n } else {\n SSLerr(SSL_F_SSL3_WRITE_PENDING, SSL_R_BIO_NOT_SET);\n i = -1;\n }\n if (i == SSL3_BUFFER_get_left(&wb[currbuf])) {\n SSL3_BUFFER_set_left(&wb[currbuf], 0);\n SSL3_BUFFER_add_offset(&wb[currbuf], i);\n if (currbuf + 1 < s->rlayer.numwpipes)\n continue;\n s->rwstate = SSL_NOTHING;\n return (s->rlayer.wpend_ret);\n } else if (i <= 0) {\n if (SSL_IS_DTLS(s)) {\n SSL3_BUFFER_set_left(&wb[currbuf], 0);\n }\n return (i);\n }\n SSL3_BUFFER_add_offset(&wb[currbuf], i);\n SSL3_BUFFER_add_left(&wb[currbuf], -i);\n }\n}']
|
1,331
| 0
|
https://github.com/libav/libav/blob/7ff018c1cb43a5fe5ee2049d325cdd785852067a/libavcodec/bitstream.h/#L237
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['void ff_rtp_send_h263_rfc2190(AVFormatContext *s1, const uint8_t *buf, int size,\n const uint8_t *mb_info, int mb_info_size)\n{\n RTPMuxContext *s = s1->priv_data;\n int len, sbits = 0, ebits = 0;\n BitstreamContext bc;\n struct H263Info info = { 0 };\n struct H263State state = { 0 };\n int mb_info_pos = 0, mb_info_count = mb_info_size / 12;\n const uint8_t *buf_base = buf;\n s->timestamp = s->cur_timestamp;\n bitstream_init(&bc, buf, size * 8);\n if (bitstream_read(&bc, 22) == 0x20) {\n info.tr = bitstream_read(&bc, 8);\n bitstream_skip(&bc, 2);\n bitstream_skip(&bc, 3);\n info.src = bitstream_read(&bc, 3);\n info.i = bitstream_read(&bc, 1);\n info.u = bitstream_read(&bc, 1);\n info.s = bitstream_read(&bc, 1);\n info.a = bitstream_read(&bc, 1);\n info.pb = bitstream_read(&bc, 1);\n }\n while (size > 0) {\n struct H263State packet_start_state = state;\n len = FFMIN(s->max_payload_size - 8, size);\n if (len < size) {\n const uint8_t *end = ff_h263_find_resync_marker_reverse(buf,\n buf + len);\n len = end - buf;\n if (len == s->max_payload_size - 8) {\n while (mb_info_pos < mb_info_count) {\n uint32_t pos = AV_RL32(&mb_info[12*mb_info_pos])/8;\n if (pos >= buf - buf_base)\n break;\n mb_info_pos++;\n }\n while (mb_info_pos + 1 < mb_info_count) {\n uint32_t pos = AV_RL32(&mb_info[12*(mb_info_pos + 1)])/8;\n if (pos >= end - buf_base)\n break;\n mb_info_pos++;\n }\n if (mb_info_pos < mb_info_count) {\n const uint8_t *ptr = &mb_info[12*mb_info_pos];\n uint32_t bit_pos = AV_RL32(ptr);\n uint32_t pos = (bit_pos + 7)/8;\n if (pos <= end - buf_base) {\n state.quant = ptr[4];\n state.gobn = ptr[5];\n state.mba = AV_RL16(&ptr[6]);\n state.hmv1 = (int8_t) ptr[8];\n state.vmv1 = (int8_t) ptr[9];\n state.hmv2 = (int8_t) ptr[10];\n state.vmv2 = (int8_t) ptr[11];\n ebits = 8 * pos - bit_pos;\n len = pos - (buf - buf_base);\n mb_info_pos++;\n } else {\n av_log(s1, AV_LOG_ERROR,\n "Unable to split H.263 packet, use -mb_info %d "\n "or lower.\\n", s->max_payload_size - 8);\n }\n } else {\n av_log(s1, AV_LOG_ERROR, "Unable to split H.263 packet, "\n "use -mb_info %d or -ps 1.\\n",\n s->max_payload_size - 8);\n }\n }\n }\n if (size > 2 && !buf[0] && !buf[1])\n send_mode_a(s1, &info, buf, len, ebits, len == size);\n else\n send_mode_b(s1, &info, &packet_start_state, buf, len, sbits,\n ebits, len == size);\n if (ebits) {\n sbits = 8 - ebits;\n len--;\n } else {\n sbits = 0;\n }\n buf += len;\n size -= len;\n ebits = 0;\n }\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
1,332
| 0
|
https://github.com/openssl/openssl/blob/260a16f33682a819414fcba6161708a5e6bdff50/test/handshake_helper.c/#L103
|
static void info_cb(const SSL *s, int where, int ret)
{
if (where & SSL_CB_ALERT) {
HANDSHAKE_EX_DATA *ex_data =
(HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
if (where & SSL_CB_WRITE) {
ex_data->alert_sent = ret;
if (strcmp(SSL_alert_type_string(ret), "F") == 0
|| strcmp(SSL_alert_desc_string(ret), "CN") == 0)
ex_data->num_fatal_alerts_sent++;
} else {
ex_data->alert_received = ret;
}
}
}
|
['static void info_cb(const SSL *s, int where, int ret)\n{\n if (where & SSL_CB_ALERT) {\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (where & SSL_CB_WRITE) {\n ex_data->alert_sent = ret;\n if (strcmp(SSL_alert_type_string(ret), "F") == 0\n || strcmp(SSL_alert_desc_string(ret), "CN") == 0)\n ex_data->num_fatal_alerts_sent++;\n } else {\n ex_data->alert_received = ret;\n }\n }\n}', 'void *SSL_get_ex_data(const SSL *s, int idx)\n{\n return CRYPTO_get_ex_data(&s->ex_data, idx);\n}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n{\n if (ad->sk == NULL || idx >= sk_void_num(ad->sk))\n return NULL;\n return sk_void_value(ad->sk, idx);\n}']
|
1,333
| 0
|
https://github.com/openssl/openssl/blob/9c4fe782607d8542c5f55ef1b5c687fef1da5d75/crypto/lhash/lhash.c/#L240
|
void *lh_delete(LHASH *lh, const void *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
void *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['int ssl3_accept(SSL *s)\n\t{\n\tBUF_MEM *buf;\n\tunsigned long l,Time=time(NULL);\n\tvoid (*cb)(const SSL *ssl,int type,int val)=NULL;\n\tlong num1;\n\tint ret= -1;\n\tint new_state,state,skip=0;\n\tRAND_add(&Time,sizeof(Time),0);\n\tERR_clear_error();\n\tclear_sys_error();\n\tif (s->info_callback != NULL)\n\t\tcb=s->info_callback;\n\telse if (s->ctx->info_callback != NULL)\n\t\tcb=s->ctx->info_callback;\n\ts->in_handshake++;\n\tif (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);\n\tif (s->cert == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_ACCEPT,SSL_R_NO_CERTIFICATE_SET);\n\t\treturn(-1);\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tstate=s->state;\n\t\tswitch (s->state)\n\t\t\t{\n\t\tcase SSL_ST_RENEGOTIATE:\n\t\t\ts->new_session=1;\n\t\tcase SSL_ST_BEFORE:\n\t\tcase SSL_ST_ACCEPT:\n\t\tcase SSL_ST_BEFORE|SSL_ST_ACCEPT:\n\t\tcase SSL_ST_OK|SSL_ST_ACCEPT:\n\t\t\ts->server=1;\n\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);\n\t\t\tif ((s->version>>8) != 3)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_ACCEPT, ERR_R_INTERNAL_ERROR);\n\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\ts->type=SSL_ST_ACCEPT;\n\t\t\tif (s->init_buf == NULL)\n\t\t\t\t{\n\t\t\t\tif ((buf=BUF_MEM_new()) == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))\n\t\t\t\t\t{\n\t\t\t\t\tret= -1;\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_buf=buf;\n\t\t\t\t}\n\t\t\tif (!ssl3_setup_buffers(s))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\ts->init_num=0;\n\t\t\tif (s->state != SSL_ST_RENEGOTIATE)\n\t\t\t\t{\n\t\t\t\tif (!ssl_init_wbio_buffer(s,1)) { ret= -1; goto end; }\n\t\t\t\tssl3_init_finished_mac(s);\n\t\t\t\ts->state=SSL3_ST_SR_CLNT_HELLO_A;\n\t\t\t\ts->ctx->stats.sess_accept++;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->ctx->stats.sess_accept_renegotiate++;\n\t\t\t\ts->state=SSL3_ST_SW_HELLO_REQ_A;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_A:\n\t\tcase SSL3_ST_SW_HELLO_REQ_B:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_send_hello_request(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SW_HELLO_REQ_C;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_HELLO_REQ_C:\n\t\t\ts->state=SSL_ST_OK;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CLNT_HELLO_A:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_B:\n\t\tcase SSL3_ST_SR_CLNT_HELLO_C:\n\t\t\ts->shutdown=0;\n\t\t\tret=ssl3_get_client_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->new_session = 2;\n\t\t\ts->state=SSL3_ST_SW_SRVR_HELLO_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_HELLO_A:\n\t\tcase SSL3_ST_SW_SRVR_HELLO_B:\n\t\t\tret=ssl3_send_server_hello(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CERT_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_A:\n\t\tcase SSL3_ST_SW_CERT_B:\n\t\t\tif (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))\n\t\t\t\t{\n\t\t\t\tret=ssl3_send_server_certificate(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_KEY_EXCH_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_KEY_EXCH_A:\n\t\tcase SSL3_ST_SW_KEY_EXCH_B:\n\t\t\tl=s->s3->tmp.new_cipher->algorithms;\n\t\t\tif ((s->options & SSL_OP_EPHEMERAL_RSA)\n#ifndef OPENSSL_NO_KRB5\n\t\t\t\t&& !(l & SSL_KRB5)\n#endif\n\t\t\t\t)\n\t\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\telse\n\t\t\t\ts->s3->tmp.use_rsa_tmp=0;\n\t\t\tif (s->s3->tmp.use_rsa_tmp\n\t\t\t || (l & SSL_kECDHE)\n\t\t\t || (l & (SSL_DH|SSL_kFZA))\n\t\t\t || ((l & SSL_kRSA)\n\t\t\t\t&& (s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL\n\t\t\t\t || (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher)\n\t\t\t\t\t&& EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey)*8 > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher)\n\t\t\t\t\t)\n\t\t\t\t )\n\t\t\t\t)\n\t\t\t )\n\t\t\t\t{\n\t\t\t\tret=ssl3_send_server_key_exchange(s);\n\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tskip=1;\n\t\t\ts->state=SSL3_ST_SW_CERT_REQ_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CERT_REQ_A:\n\t\tcase SSL3_ST_SW_CERT_REQ_B:\n\t\t\tif (\n\t\t\t\t!(s->verify_mode & SSL_VERIFY_PEER) ||\n\t\t\t\t((s->session->peer != NULL) &&\n\t\t\t\t (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||\n\t\t\t\t((s->s3->tmp.new_cipher->algorithms & SSL_aNULL) &&\n\t\t\t\t !(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) ||\n (s->s3->tmp.new_cipher->algorithms & SSL_aKRB5))\n\t\t\t\t{\n\t\t\t\tskip=1;\n\t\t\t\ts->s3->tmp.cert_request=0;\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->s3->tmp.cert_request=1;\n\t\t\t\tret=ssl3_send_certificate_request(s);\n\t\t\t\tif (ret <= 0) goto end;\n#ifndef NETSCAPE_HANG_BUG\n\t\t\t\ts->state=SSL3_ST_SW_SRVR_DONE_A;\n#else\n\t\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n#endif\n\t\t\t\ts->init_num=0;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_SRVR_DONE_A:\n\t\tcase SSL3_ST_SW_SRVR_DONE_B:\n\t\t\tret=ssl3_send_server_done(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_CERT_A;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FLUSH:\n\t\t\tnum1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);\n\t\t\tif (num1 > 0)\n\t\t\t\t{\n\t\t\t\ts->rwstate=SSL_WRITING;\n\t\t\t\tnum1=BIO_flush(s->wbio);\n\t\t\t\tif (num1 <= 0) { ret= -1; goto end; }\n\t\t\t\ts->rwstate=SSL_NOTHING;\n\t\t\t\t}\n\t\t\ts->state=s->s3->tmp.next_state;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_A:\n\t\tcase SSL3_ST_SR_CERT_B:\n\t\t\tret = ssl3_check_client_hello(s);\n\t\t\tif (ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif (ret == 2)\n\t\t\t\ts->state = SSL3_ST_SR_CLNT_HELLO_C;\n\t\t\telse {\n\t\t\t\tif (s->s3->tmp.cert_request)\n\t\t\t\t\t{\n\t\t\t\t\tret=ssl3_get_client_certificate(s);\n\t\t\t\t\tif (ret <= 0) goto end;\n\t\t\t\t\t}\n\t\t\t\ts->init_num=0;\n\t\t\t\ts->state=SSL3_ST_SR_KEY_EXCH_A;\n\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_KEY_EXCH_A:\n\t\tcase SSL3_ST_SR_KEY_EXCH_B:\n\t\t\tret=ssl3_get_client_key_exchange(s);\n\t\t\tif (ret <= 0)\n\t\t\t\tgoto end;\n\t\t\tif (ret == 2)\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\t\ts->init_num = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\ts->state=SSL3_ST_SR_CERT_VRFY_A;\n\t\t\t\ts->init_num=0;\n\t\t\t\ts->method->ssl3_enc->cert_verify_mac(s,\n\t\t\t\t &(s->s3->finish_dgst1),\n\t\t\t\t &(s->s3->tmp.cert_verify_md[0]));\n\t\t\t\ts->method->ssl3_enc->cert_verify_mac(s,\n\t\t\t\t &(s->s3->finish_dgst2),\n\t\t\t\t &(s->s3->tmp.cert_verify_md[MD5_DIGEST_LENGTH]));\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_CERT_VRFY_A:\n\t\tcase SSL3_ST_SR_CERT_VRFY_B:\n\t\t\tret=ssl3_get_cert_verify(s);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SR_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SR_FINISHED_A:\n\t\tcase SSL3_ST_SR_FINISHED_B:\n\t\t\tret=ssl3_get_finished(s,SSL3_ST_SR_FINISHED_A,\n\t\t\t\tSSL3_ST_SR_FINISHED_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\tif (s->hit)\n\t\t\t\ts->state=SSL_ST_OK;\n\t\t\telse\n\t\t\t\ts->state=SSL3_ST_SW_CHANGE_A;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_CHANGE_A:\n\t\tcase SSL3_ST_SW_CHANGE_B:\n\t\t\ts->session->cipher=s->s3->tmp.new_cipher;\n\t\t\tif (!s->method->ssl3_enc->setup_key_block(s))\n\t\t\t\t{ ret= -1; goto end; }\n\t\t\tret=ssl3_send_change_cipher_spec(s,\n\t\t\t\tSSL3_ST_SW_CHANGE_A,SSL3_ST_SW_CHANGE_B);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FINISHED_A;\n\t\t\ts->init_num=0;\n\t\t\tif (!s->method->ssl3_enc->change_cipher_state(s,\n\t\t\t\tSSL3_CHANGE_CIPHER_SERVER_WRITE))\n\t\t\t\t{\n\t\t\t\tret= -1;\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tbreak;\n\t\tcase SSL3_ST_SW_FINISHED_A:\n\t\tcase SSL3_ST_SW_FINISHED_B:\n\t\t\tret=ssl3_send_finished(s,\n\t\t\t\tSSL3_ST_SW_FINISHED_A,SSL3_ST_SW_FINISHED_B,\n\t\t\t\ts->method->ssl3_enc->server_finished_label,\n\t\t\t\ts->method->ssl3_enc->server_finished_label_len);\n\t\t\tif (ret <= 0) goto end;\n\t\t\ts->state=SSL3_ST_SW_FLUSH;\n\t\t\tif (s->hit)\n\t\t\t\ts->s3->tmp.next_state=SSL3_ST_SR_FINISHED_A;\n\t\t\telse\n\t\t\t\ts->s3->tmp.next_state=SSL_ST_OK;\n\t\t\ts->init_num=0;\n\t\t\tbreak;\n\t\tcase SSL_ST_OK:\n\t\t\tssl3_cleanup_key_block(s);\n\t\t\tBUF_MEM_free(s->init_buf);\n\t\t\ts->init_buf=NULL;\n\t\t\tssl_free_wbio_buffer(s);\n\t\t\ts->init_num=0;\n\t\t\tif (s->new_session == 2)\n\t\t\t\t{\n\t\t\t\ts->new_session=0;\n\t\t\t\tssl_update_cache(s,SSL_SESS_CACHE_SERVER);\n\t\t\t\ts->ctx->stats.sess_accept_good++;\n\t\t\t\ts->handshake_func=ssl3_accept;\n\t\t\t\tif (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);\n\t\t\t\t}\n\t\t\tret = 1;\n\t\t\tgoto end;\n\t\tdefault:\n\t\t\tSSLerr(SSL_F_SSL3_ACCEPT,SSL_R_UNKNOWN_STATE);\n\t\t\tret= -1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (!s->s3->tmp.reuse_message && !skip)\n\t\t\t{\n\t\t\tif (s->debug)\n\t\t\t\t{\n\t\t\t\tif ((ret=BIO_flush(s->wbio)) <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tif ((cb != NULL) && (s->state != state))\n\t\t\t\t{\n\t\t\t\tnew_state=s->state;\n\t\t\t\ts->state=state;\n\t\t\t\tcb(s,SSL_CB_ACCEPT_LOOP,1);\n\t\t\t\ts->state=new_state;\n\t\t\t\t}\n\t\t\t}\n\t\tskip=0;\n\t\t}\nend:\n\ts->in_handshake--;\n\tif (cb != NULL)\n\t\tcb(s,SSL_CB_ACCEPT_EXIT,ret);\n\treturn(ret);\n\t}', 'int ssl3_send_server_key_exchange(SSL *s)\n\t{\n#ifndef OPENSSL_NO_RSA\n\tunsigned char *q;\n\tint j,num;\n\tRSA *rsa;\n\tunsigned char md_buf[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];\n\tunsigned int u;\n#endif\n#ifndef OPENSSL_NO_DH\n\tDH *dh=NULL,*dhp;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh=NULL, *ecdhp;\n\tunsigned char *encodedPoint = NULL;\n\tint encodedlen = 0;\n\tint curve_id = 0;\n\tBN_CTX *bn_ctx = NULL;\n#endif\n\tEVP_PKEY *pkey;\n\tunsigned char *p,*d;\n\tint al,i;\n\tunsigned long type;\n\tint n;\n\tCERT *cert;\n\tBIGNUM *r[4];\n\tint nr[4],kn;\n\tBUF_MEM *buf;\n\tEVP_MD_CTX md_ctx;\n\tEVP_MD_CTX_init(&md_ctx);\n\tif (s->state == SSL3_ST_SW_KEY_EXCH_A)\n\t\t{\n\t\ttype=s->s3->tmp.new_cipher->algorithms & SSL_MKEY_MASK;\n\t\tcert=s->cert;\n\t\tbuf=s->init_buf;\n\t\tr[0]=r[1]=r[2]=r[3]=NULL;\n\t\tn=0;\n#ifndef OPENSSL_NO_RSA\n\t\tif (type & SSL_kRSA)\n\t\t\t{\n\t\t\trsa=cert->rsa_tmp;\n\t\t\tif ((rsa == NULL) && (s->cert->rsa_tmp_cb != NULL))\n\t\t\t\t{\n\t\t\t\trsa=s->cert->rsa_tmp_cb(s,\n\t\t\t\t SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),\n\t\t\t\t SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));\n\t\t\t\tif(rsa == NULL)\n\t\t\t\t{\n\t\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ERROR_GENERATING_TMP_RSA_KEY);\n\t\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t\tRSA_up_ref(rsa);\n\t\t\t\tcert->rsa_tmp=rsa;\n\t\t\t\t}\n\t\t\tif (rsa == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tr[0]=rsa->n;\n\t\t\tr[1]=rsa->e;\n\t\t\ts->s3->tmp.use_rsa_tmp=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DH\n\t\t\tif (type & SSL_kEDH)\n\t\t\t{\n\t\t\tdhp=cert->dh_tmp;\n\t\t\tif ((dhp == NULL) && (s->cert->dh_tmp_cb != NULL))\n\t\t\t\tdhp=s->cert->dh_tmp_cb(s,\n\t\t\t\t SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),\n\t\t\t\t SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));\n\t\t\tif (dhp == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tif (s->s3->tmp.dh != NULL)\n\t\t\t\t{\n\t\t\t\tDH_free(dh);\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif ((dh=DHparams_dup(dhp)) == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\ts->s3->tmp.dh=dh;\n\t\t\tif ((dhp->pub_key == NULL ||\n\t\t\t dhp->priv_key == NULL ||\n\t\t\t (s->options & SSL_OP_SINGLE_DH_USE)))\n\t\t\t\t{\n\t\t\t\tif(!DH_generate_key(dh))\n\t\t\t\t {\n\t\t\t\t SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,\n\t\t\t\t\t ERR_R_DH_LIB);\n\t\t\t\t goto err;\n\t\t\t\t }\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tdh->pub_key=BN_dup(dhp->pub_key);\n\t\t\t\tdh->priv_key=BN_dup(dhp->priv_key);\n\t\t\t\tif ((dh->pub_key == NULL) ||\n\t\t\t\t\t(dh->priv_key == NULL))\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tr[0]=dh->p;\n\t\t\tr[1]=dh->g;\n\t\t\tr[2]=dh->pub_key;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\tif (type & SSL_kECDHE)\n\t\t\t{\n\t\t\tconst EC_GROUP *group;\n\t\t\tecdhp=cert->ecdh_tmp;\n\t\t\tif ((ecdhp == NULL) && (s->cert->ecdh_tmp_cb != NULL))\n\t\t\t\t{\n\t\t\t\tecdhp=s->cert->ecdh_tmp_cb(s,\n\t\t\t\t SSL_C_IS_EXPORT(s->s3->tmp.new_cipher),\n\t\t\t\t SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher));\n\t\t\t\t}\n\t\t\tif (ecdhp == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_MISSING_TMP_ECDH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tif (s->s3->tmp.ecdh != NULL)\n\t\t\t\t{\n\t\t\t\tEC_KEY_free(s->s3->tmp.ecdh);\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (ecdhp == NULL)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (!EC_KEY_up_ref(ecdhp))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tecdh = ecdhp;\n\t\t\ts->s3->tmp.ecdh=ecdh;\n\t\t\tif ((EC_KEY_get0_public_key(ecdh) == NULL) ||\n\t\t\t (EC_KEY_get0_private_key(ecdh) == NULL) ||\n\t\t\t (s->options & SSL_OP_SINGLE_ECDH_USE))\n\t\t\t\t{\n\t\t\t\tif(!EC_KEY_generate_key(ecdh))\n\t\t\t\t {\n\t\t\t\t SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);\n\t\t\t\t goto err;\n\t\t\t\t }\n\t\t\t\t}\n\t\t\tif (((group = EC_KEY_get0_group(ecdh)) == NULL) ||\n\t\t\t (EC_KEY_get0_public_key(ecdh) == NULL) ||\n\t\t\t (EC_KEY_get0_private_key(ecdh) == NULL))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) &&\n\t\t\t (EC_GROUP_get_degree(group) > 163))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif ((curve_id =\n\t\t\t nid2curve_id(EC_GROUP_get_curve_name(group)))\n\t\t\t == 0)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tencodedlen = EC_POINT_point2oct(group,\n\t\t\t EC_KEY_get0_public_key(ecdh),\n\t\t\t POINT_CONVERSION_UNCOMPRESSED,\n\t\t\t NULL, 0, NULL);\n\t\t\tencodedPoint = (unsigned char *)\n\t\t\t OPENSSL_malloc(encodedlen*sizeof(unsigned char));\n\t\t\tbn_ctx = BN_CTX_new();\n\t\t\tif ((encodedPoint == NULL) || (bn_ctx == NULL))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tencodedlen = EC_POINT_point2oct(group,\n\t\t\t EC_KEY_get0_public_key(ecdh),\n\t\t\t POINT_CONVERSION_UNCOMPRESSED,\n\t\t\t encodedPoint, encodedlen, bn_ctx);\n\t\t\tif (encodedlen == 0)\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_R_ECDH_LIB);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tBN_CTX_free(bn_ctx); bn_ctx=NULL;\n\t\t\tn = 3 + encodedlen;\n\t\t\tr[0]=NULL;\n\t\t\tr[1]=NULL;\n\t\t\tr[2]=NULL;\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tfor (i=0; r[i] != NULL; i++)\n\t\t\t{\n\t\t\tnr[i]=BN_num_bytes(r[i]);\n\t\t\tn+=2+nr[i];\n\t\t\t}\n\t\tif (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))\n\t\t\t{\n\t\t\tif ((pkey=ssl_get_sign_pkey(s,s->s3->tmp.new_cipher))\n\t\t\t\t== NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\tkn=EVP_PKEY_size(pkey);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey=NULL;\n\t\t\tkn=0;\n\t\t\t}\n\t\tif (!BUF_MEM_grow_clean(buf,n+4+kn))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF);\n\t\t\tgoto err;\n\t\t\t}\n\t\td=(unsigned char *)s->init_buf->data;\n\t\tp= &(d[4]);\n\t\tfor (i=0; r[i] != NULL; i++)\n\t\t\t{\n\t\t\ts2n(nr[i],p);\n\t\t\tBN_bn2bin(r[i],p);\n\t\t\tp+=nr[i];\n\t\t\t}\n#ifndef OPENSSL_NO_ECDH\n\t\tif (type & SSL_kECDHE)\n\t\t\t{\n\t\t\t*p = NAMED_CURVE_TYPE;\n\t\t\tp += 1;\n\t\t\t*p = curve_id;\n\t\t\tp += 1;\n\t\t\t*p = encodedlen;\n\t\t\tp += 1;\n\t\t\tmemcpy((unsigned char*)p,\n\t\t\t (unsigned char *)encodedPoint,\n\t\t\t encodedlen);\n\t\t\tOPENSSL_free(encodedPoint);\n\t\t\tp += encodedlen;\n\t\t\t}\n#endif\n\t\tif (pkey != NULL)\n\t\t\t{\n#ifndef OPENSSL_NO_RSA\n\t\t\tif (pkey->type == EVP_PKEY_RSA)\n\t\t\t\t{\n\t\t\t\tq=md_buf;\n\t\t\t\tj=0;\n\t\t\t\tfor (num=2; num > 0; num--)\n\t\t\t\t\t{\n\t\t\t\t\tEVP_DigestInit_ex(&md_ctx,(num == 2)\n\t\t\t\t\t\t?s->ctx->md5:s->ctx->sha1, NULL);\n\t\t\t\t\tEVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\t\tEVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\t\tEVP_DigestUpdate(&md_ctx,&(d[4]),n);\n\t\t\t\t\tEVP_DigestFinal_ex(&md_ctx,q,\n\t\t\t\t\t\t(unsigned int *)&i);\n\t\t\t\t\tq+=i;\n\t\t\t\t\tj+=i;\n\t\t\t\t\t}\n\t\t\t\tif (RSA_sign(NID_md5_sha1, md_buf, j,\n\t\t\t\t\t&(p[2]), &u, pkey->pkey.rsa) <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_RSA);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\ts2n(u,p);\n\t\t\t\tn+=u+2;\n\t\t\t\t}\n\t\t\telse\n#endif\n#if !defined(OPENSSL_NO_DSA)\n\t\t\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\t\t{\n\t\t\t\tEVP_SignInit_ex(&md_ctx,EVP_dss1(), NULL);\n\t\t\t\tEVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_SignUpdate(&md_ctx,&(d[4]),n);\n\t\t\t\tif (!EVP_SignFinal(&md_ctx,&(p[2]),\n\t\t\t\t\t(unsigned int *)&i,pkey))\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_DSA);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\ts2n(i,p);\n\t\t\t\tn+=i+2;\n\t\t\t\t}\n\t\t\telse\n#endif\n#if !defined(OPENSSL_NO_ECDSA)\n\t\t\t\tif (pkey->type == EVP_PKEY_EC)\n\t\t\t\t{\n\t\t\t\tEVP_SignInit_ex(&md_ctx,EVP_ecdsa(), NULL);\n\t\t\t\tEVP_SignUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_SignUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);\n\t\t\t\tEVP_SignUpdate(&md_ctx,&(d[4]),n);\n\t\t\t\tif (!EVP_SignFinal(&md_ctx,&(p[2]),\n\t\t\t\t\t(unsigned int *)&i,pkey))\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_ECDSA);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\ts2n(i,p);\n\t\t\t\tn+=i+2;\n\t\t\t\t}\n\t\t\telse\n#endif\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,SSL_R_UNKNOWN_PKEY_TYPE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t*(d++)=SSL3_MT_SERVER_KEY_EXCHANGE;\n\t\tl2n3(n,d);\n\t\ts->init_num=n+4;\n\t\ts->init_off=0;\n\t\t}\n\ts->state = SSL3_ST_SW_KEY_EXCH_B;\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(ssl3_do_write(s,SSL3_RT_HANDSHAKE));\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n#ifndef OPENSSL_NO_ECDH\n\tif (encodedPoint != NULL) OPENSSL_free(encodedPoint);\n\tBN_CTX_free(bn_ctx);\n#endif\n\tEVP_MD_CTX_cleanup(&md_ctx);\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (s->version == SSL3_VERSION && desc == SSL_AD_PROTOCOL_VERSION)\n\t\tdesc = SSL_AD_HANDSHAKE_FAILURE;\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\ts->method->ssl_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = (SSL_SESSION *)lh_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']
|
1,334
| 0
|
https://github.com/openssl/openssl/blob/ddc6a5c8f5900959bdbdfee79e1625a3f7808acd/include/internal/constant_time_locl.h/#L159
|
static ossl_inline unsigned int constant_time_is_zero(unsigned int a)
{
return constant_time_msb(~a & (a - 1));
}
|
['static int tls_process_cke_rsa(SSL *s, PACKET *pkt, int *al)\n{\n#ifndef OPENSSL_NO_RSA\n unsigned char rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];\n int decrypt_len;\n unsigned char decrypt_good, version_good;\n size_t j, padding_len;\n PACKET enc_premaster;\n RSA *rsa = NULL;\n unsigned char *rsa_decrypt = NULL;\n int ret = 0;\n rsa = EVP_PKEY_get0_RSA(s->cert->pkeys[SSL_PKEY_RSA].privatekey);\n if (rsa == NULL) {\n *al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, SSL_R_MISSING_RSA_CERTIFICATE);\n return 0;\n }\n if (s->version == SSL3_VERSION || s->version == DTLS1_BAD_VER) {\n enc_premaster = *pkt;\n } else {\n if (!PACKET_get_length_prefixed_2(pkt, &enc_premaster)\n || PACKET_remaining(pkt) != 0) {\n *al = SSL_AD_DECODE_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, SSL_R_LENGTH_MISMATCH);\n return 0;\n }\n }\n if (RSA_size(rsa) < SSL_MAX_MASTER_KEY_LENGTH) {\n *al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, RSA_R_KEY_SIZE_TOO_SMALL);\n return 0;\n }\n rsa_decrypt = OPENSSL_malloc(RSA_size(rsa));\n if (rsa_decrypt == NULL) {\n *al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n if (ssl_randbytes(s, rand_premaster_secret, sizeof(rand_premaster_secret)) <= 0)\n goto err;\n decrypt_len = (int)RSA_private_decrypt((int)PACKET_remaining(&enc_premaster),\n PACKET_data(&enc_premaster),\n rsa_decrypt, rsa, RSA_NO_PADDING);\n if (decrypt_len < 0)\n goto err;\n if (decrypt_len < 11 + SSL_MAX_MASTER_KEY_LENGTH) {\n *al = SSL_AD_DECRYPT_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, SSL_R_DECRYPTION_FAILED);\n goto err;\n }\n padding_len = decrypt_len - SSL_MAX_MASTER_KEY_LENGTH;\n decrypt_good = constant_time_eq_int_8(rsa_decrypt[0], 0) &\n constant_time_eq_int_8(rsa_decrypt[1], 2);\n for (j = 2; j < padding_len - 1; j++) {\n decrypt_good &= ~constant_time_is_zero_8(rsa_decrypt[j]);\n }\n decrypt_good &= constant_time_is_zero_8(rsa_decrypt[padding_len - 1]);\n version_good =\n constant_time_eq_8(rsa_decrypt[padding_len],\n (unsigned)(s->client_version >> 8));\n version_good &=\n constant_time_eq_8(rsa_decrypt[padding_len + 1],\n (unsigned)(s->client_version & 0xff));\n if (s->options & SSL_OP_TLS_ROLLBACK_BUG) {\n unsigned char workaround_good;\n workaround_good = constant_time_eq_8(rsa_decrypt[padding_len],\n (unsigned)(s->version >> 8));\n workaround_good &=\n constant_time_eq_8(rsa_decrypt[padding_len + 1],\n (unsigned)(s->version & 0xff));\n version_good |= workaround_good;\n }\n decrypt_good &= version_good;\n for (j = 0; j < sizeof(rand_premaster_secret); j++) {\n rsa_decrypt[padding_len + j] =\n constant_time_select_8(decrypt_good,\n rsa_decrypt[padding_len + j],\n rand_premaster_secret[j]);\n }\n if (!ssl_generate_master_secret(s, rsa_decrypt + padding_len,\n sizeof(rand_premaster_secret), 0)) {\n *al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n ret = 1;\n err:\n OPENSSL_free(rsa_decrypt);\n return ret;\n#else\n *al = SSL_AD_INTERNAL_ERROR;\n SSLerr(SSL_F_TLS_PROCESS_CKE_RSA, ERR_R_INTERNAL_ERROR);\n return 0;\n#endif\n}', 'int ssl_randbytes(SSL *s, unsigned char *rnd, size_t size)\n{\n if (s->drbg != NULL)\n return RAND_DRBG_generate(s->drbg, rnd, size, 0, NULL, 0);\n return RAND_bytes(rnd, (int)size);\n}', 'int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,\n int prediction_resistance,\n const unsigned char *adin, size_t adinlen)\n{\n if (drbg->state == DRBG_ERROR) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_IN_ERROR_STATE);\n return 0;\n }\n if (drbg->state == DRBG_UNINITIALISED) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_NOT_INSTANTIATED);\n return 0;\n }\n if (outlen > drbg->max_request) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_REQUEST_TOO_LARGE_FOR_DRBG);\n return 0;\n }\n if (adinlen > drbg->max_adin) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_ADDITIONAL_INPUT_TOO_LONG);\n return 0;\n }\n if (drbg->reseed_counter >= drbg->reseed_interval)\n drbg->state = DRBG_RESEED;\n if (drbg->state == DRBG_RESEED || prediction_resistance) {\n if (!RAND_DRBG_reseed(drbg, adin, adinlen)) {\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_RESEED_ERROR);\n return 0;\n }\n adin = NULL;\n adinlen = 0;\n }\n if (!ctr_generate(drbg, out, outlen, adin, adinlen)) {\n drbg->state = DRBG_ERROR;\n RANDerr(RAND_F_RAND_DRBG_GENERATE, RAND_R_GENERATE_ERROR);\n return 0;\n }\n if (drbg->reseed_counter >= drbg->reseed_interval)\n drbg->state = DRBG_RESEED;\n else\n drbg->reseed_counter++;\n return 1;\n}', 'static ossl_inline unsigned char constant_time_is_zero_8(unsigned int a)\n{\n return (unsigned char)(constant_time_is_zero(a));\n}', 'static ossl_inline unsigned int constant_time_is_zero(unsigned int a)\n{\n return constant_time_msb(~a & (a - 1));\n}']
|
1,335
| 0
|
https://github.com/libav/libav/blob/b845f5e97b655de0a191f736594777fec9754cf5/libavcodec/mpegvideo.c/#L2211
|
void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur,
Picture *last, int y, int h, int picture_structure,
int first_field, int draw_edges, int low_delay,
int v_edge_pos, int h_edge_pos)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
int hshift = desc->log2_chroma_w;
int vshift = desc->log2_chroma_h;
const int field_pic = picture_structure != PICT_FRAME;
if(field_pic){
h <<= 1;
y <<= 1;
}
if (!avctx->hwaccel &&
!(avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) &&
draw_edges &&
cur->reference &&
!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
int *linesize = cur->f.linesize;
int sides = 0, edge_h;
if (y==0) sides |= EDGE_TOP;
if (y + h >= v_edge_pos)
sides |= EDGE_BOTTOM;
edge_h= FFMIN(h, v_edge_pos - y);
dsp->draw_edges(cur->f.data[0] + y * linesize[0],
linesize[0], h_edge_pos, edge_h,
EDGE_WIDTH, EDGE_WIDTH, sides);
dsp->draw_edges(cur->f.data[1] + (y >> vshift) * linesize[1],
linesize[1], h_edge_pos >> hshift, edge_h >> vshift,
EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);
dsp->draw_edges(cur->f.data[2] + (y >> vshift) * linesize[2],
linesize[2], h_edge_pos >> hshift, edge_h >> vshift,
EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);
}
h = FFMIN(h, avctx->height - y);
if(field_pic && first_field && !(avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;
if (avctx->draw_horiz_band) {
AVFrame *src;
int offset[AV_NUM_DATA_POINTERS];
int i;
if(cur->f.pict_type == AV_PICTURE_TYPE_B || low_delay ||
(avctx->slice_flags & SLICE_FLAG_CODED_ORDER))
src = &cur->f;
else if (last)
src = &last->f;
else
return;
if (cur->f.pict_type == AV_PICTURE_TYPE_B &&
picture_structure == PICT_FRAME &&
avctx->codec_id != AV_CODEC_ID_SVQ3) {
for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
offset[i] = 0;
}else{
offset[0]= y * src->linesize[0];
offset[1]=
offset[2]= (y >> vshift) * src->linesize[1];
for (i = 3; i < AV_NUM_DATA_POINTERS; i++)
offset[i] = 0;
}
emms_c();
avctx->draw_horiz_band(avctx, src, offset,
y, picture_structure, h);
}
}
|
['void ff_draw_horiz_band(AVCodecContext *avctx, DSPContext *dsp, Picture *cur,\n Picture *last, int y, int h, int picture_structure,\n int first_field, int draw_edges, int low_delay,\n int v_edge_pos, int h_edge_pos)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);\n int hshift = desc->log2_chroma_w;\n int vshift = desc->log2_chroma_h;\n const int field_pic = picture_structure != PICT_FRAME;\n if(field_pic){\n h <<= 1;\n y <<= 1;\n }\n if (!avctx->hwaccel &&\n !(avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) &&\n draw_edges &&\n cur->reference &&\n !(avctx->flags & CODEC_FLAG_EMU_EDGE)) {\n int *linesize = cur->f.linesize;\n int sides = 0, edge_h;\n if (y==0) sides |= EDGE_TOP;\n if (y + h >= v_edge_pos)\n sides |= EDGE_BOTTOM;\n edge_h= FFMIN(h, v_edge_pos - y);\n dsp->draw_edges(cur->f.data[0] + y * linesize[0],\n linesize[0], h_edge_pos, edge_h,\n EDGE_WIDTH, EDGE_WIDTH, sides);\n dsp->draw_edges(cur->f.data[1] + (y >> vshift) * linesize[1],\n linesize[1], h_edge_pos >> hshift, edge_h >> vshift,\n EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);\n dsp->draw_edges(cur->f.data[2] + (y >> vshift) * linesize[2],\n linesize[2], h_edge_pos >> hshift, edge_h >> vshift,\n EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, sides);\n }\n h = FFMIN(h, avctx->height - y);\n if(field_pic && first_field && !(avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return;\n if (avctx->draw_horiz_band) {\n AVFrame *src;\n int offset[AV_NUM_DATA_POINTERS];\n int i;\n if(cur->f.pict_type == AV_PICTURE_TYPE_B || low_delay ||\n (avctx->slice_flags & SLICE_FLAG_CODED_ORDER))\n src = &cur->f;\n else if (last)\n src = &last->f;\n else\n return;\n if (cur->f.pict_type == AV_PICTURE_TYPE_B &&\n picture_structure == PICT_FRAME &&\n avctx->codec_id != AV_CODEC_ID_SVQ3) {\n for (i = 0; i < AV_NUM_DATA_POINTERS; i++)\n offset[i] = 0;\n }else{\n offset[0]= y * src->linesize[0];\n offset[1]=\n offset[2]= (y >> vshift) * src->linesize[1];\n for (i = 3; i < AV_NUM_DATA_POINTERS; i++)\n offset[i] = 0;\n }\n emms_c();\n avctx->draw_horiz_band(avctx, src, offset,\n y, picture_structure, h);\n }\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
|
1,336
| 0
|
https://github.com/libav/libav/blob/ab492ca2ab105aeb24d955f3f03756bdb3139ee1/libavcodec/aacdec.c/#L1310
|
static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
GetBitContext *gb, const float sf[120],
int pulse_present, const Pulse *pulse,
const IndividualChannelStream *ics,
enum BandType band_type[120])
{
int i, k, g, idx = 0;
const int c = 1024 / ics->num_windows;
const uint16_t *offsets = ics->swb_offset;
float *coef_base = coef;
for (g = 0; g < ics->num_windows; g++)
memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float) * (c - offsets[ics->max_sfb]));
for (g = 0; g < ics->num_window_groups; g++) {
unsigned g_len = ics->group_len[g];
for (i = 0; i < ics->max_sfb; i++, idx++) {
const unsigned cbt_m1 = band_type[idx] - 1;
float *cfo = coef + offsets[i];
int off_len = offsets[i + 1] - offsets[i];
int group;
if (cbt_m1 >= INTENSITY_BT2 - 1) {
for (group = 0; group < g_len; group++, cfo+=128) {
memset(cfo, 0, off_len * sizeof(float));
}
} else if (cbt_m1 == NOISE_BT - 1) {
for (group = 0; group < g_len; group++, cfo+=128) {
float scale;
float band_energy;
for (k = 0; k < off_len; k++) {
ac->random_state = lcg_random(ac->random_state);
cfo[k] = ac->random_state;
}
band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len);
scale = sf[idx] / sqrtf(band_energy);
ac->dsp.vector_fmul_scalar(cfo, cfo, scale, off_len);
}
} else {
const float *vq = ff_aac_codebook_vector_vals[cbt_m1];
const uint16_t *cb_vector_idx = ff_aac_codebook_vector_idx[cbt_m1];
VLC_TYPE (*vlc_tab)[2] = vlc_spectral[cbt_m1].table;
OPEN_READER(re, gb);
switch (cbt_m1 >> 1) {
case 0:
for (group = 0; group < g_len; group++, cfo+=128) {
float *cf = cfo;
int len = off_len;
do {
int code;
unsigned cb_idx;
UPDATE_CACHE(re, gb);
GET_VLC(code, re, gb, vlc_tab, 8, 2);
cb_idx = cb_vector_idx[code];
cf = VMUL4(cf, vq, cb_idx, sf + idx);
} while (len -= 4);
}
break;
case 1:
for (group = 0; group < g_len; group++, cfo+=128) {
float *cf = cfo;
int len = off_len;
do {
int code;
unsigned nnz;
unsigned cb_idx;
uint32_t bits;
UPDATE_CACHE(re, gb);
GET_VLC(code, re, gb, vlc_tab, 8, 2);
cb_idx = cb_vector_idx[code];
nnz = cb_idx >> 8 & 15;
bits = nnz ? GET_CACHE(re, gb) : 0;
LAST_SKIP_BITS(re, gb, nnz);
cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx);
} while (len -= 4);
}
break;
case 2:
for (group = 0; group < g_len; group++, cfo+=128) {
float *cf = cfo;
int len = off_len;
do {
int code;
unsigned cb_idx;
UPDATE_CACHE(re, gb);
GET_VLC(code, re, gb, vlc_tab, 8, 2);
cb_idx = cb_vector_idx[code];
cf = VMUL2(cf, vq, cb_idx, sf + idx);
} while (len -= 2);
}
break;
case 3:
case 4:
for (group = 0; group < g_len; group++, cfo+=128) {
float *cf = cfo;
int len = off_len;
do {
int code;
unsigned nnz;
unsigned cb_idx;
unsigned sign;
UPDATE_CACHE(re, gb);
GET_VLC(code, re, gb, vlc_tab, 8, 2);
cb_idx = cb_vector_idx[code];
nnz = cb_idx >> 8 & 15;
sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0;
LAST_SKIP_BITS(re, gb, nnz);
cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx);
} while (len -= 2);
}
break;
default:
for (group = 0; group < g_len; group++, cfo+=128) {
float *cf = cfo;
uint32_t *icf = (uint32_t *) cf;
int len = off_len;
do {
int code;
unsigned nzt, nnz;
unsigned cb_idx;
uint32_t bits;
int j;
UPDATE_CACHE(re, gb);
GET_VLC(code, re, gb, vlc_tab, 8, 2);
if (!code) {
*icf++ = 0;
*icf++ = 0;
continue;
}
cb_idx = cb_vector_idx[code];
nnz = cb_idx >> 12;
nzt = cb_idx >> 8;
bits = SHOW_UBITS(re, gb, nnz) << (32-nnz);
LAST_SKIP_BITS(re, gb, nnz);
for (j = 0; j < 2; j++) {
if (nzt & 1<<j) {
uint32_t b;
int n;
UPDATE_CACHE(re, gb);
b = GET_CACHE(re, gb);
b = 31 - av_log2(~b);
if (b > 8) {
av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
return -1;
}
SKIP_BITS(re, gb, b + 1);
b += 4;
n = (1 << b) + SHOW_UBITS(re, gb, b);
LAST_SKIP_BITS(re, gb, b);
*icf++ = cbrt_tab[n] | (bits & 1U<<31);
bits <<= 1;
} else {
unsigned v = ((const uint32_t*)vq)[cb_idx & 15];
*icf++ = (bits & 1U<<31) | v;
bits <<= !!v;
}
cb_idx >>= 4;
}
} while (len -= 2);
ac->dsp.vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
}
}
CLOSE_READER(re, gb);
}
}
coef += g_len << 7;
}
if (pulse_present) {
idx = 0;
for (i = 0; i < pulse->num_pulse; i++) {
float co = coef_base[ pulse->pos[i] ];
while (offsets[idx + 1] <= pulse->pos[i])
idx++;
if (band_type[idx] != NOISE_BT && sf[idx]) {
float ico = -pulse->amp[i];
if (co) {
co /= sf[idx];
ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);
}
coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx];
}
}
}
return 0;
}
|
['static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],\n GetBitContext *gb, const float sf[120],\n int pulse_present, const Pulse *pulse,\n const IndividualChannelStream *ics,\n enum BandType band_type[120])\n{\n int i, k, g, idx = 0;\n const int c = 1024 / ics->num_windows;\n const uint16_t *offsets = ics->swb_offset;\n float *coef_base = coef;\n for (g = 0; g < ics->num_windows; g++)\n memset(coef + g * 128 + offsets[ics->max_sfb], 0, sizeof(float) * (c - offsets[ics->max_sfb]));\n for (g = 0; g < ics->num_window_groups; g++) {\n unsigned g_len = ics->group_len[g];\n for (i = 0; i < ics->max_sfb; i++, idx++) {\n const unsigned cbt_m1 = band_type[idx] - 1;\n float *cfo = coef + offsets[i];\n int off_len = offsets[i + 1] - offsets[i];\n int group;\n if (cbt_m1 >= INTENSITY_BT2 - 1) {\n for (group = 0; group < g_len; group++, cfo+=128) {\n memset(cfo, 0, off_len * sizeof(float));\n }\n } else if (cbt_m1 == NOISE_BT - 1) {\n for (group = 0; group < g_len; group++, cfo+=128) {\n float scale;\n float band_energy;\n for (k = 0; k < off_len; k++) {\n ac->random_state = lcg_random(ac->random_state);\n cfo[k] = ac->random_state;\n }\n band_energy = ac->dsp.scalarproduct_float(cfo, cfo, off_len);\n scale = sf[idx] / sqrtf(band_energy);\n ac->dsp.vector_fmul_scalar(cfo, cfo, scale, off_len);\n }\n } else {\n const float *vq = ff_aac_codebook_vector_vals[cbt_m1];\n const uint16_t *cb_vector_idx = ff_aac_codebook_vector_idx[cbt_m1];\n VLC_TYPE (*vlc_tab)[2] = vlc_spectral[cbt_m1].table;\n OPEN_READER(re, gb);\n switch (cbt_m1 >> 1) {\n case 0:\n for (group = 0; group < g_len; group++, cfo+=128) {\n float *cf = cfo;\n int len = off_len;\n do {\n int code;\n unsigned cb_idx;\n UPDATE_CACHE(re, gb);\n GET_VLC(code, re, gb, vlc_tab, 8, 2);\n cb_idx = cb_vector_idx[code];\n cf = VMUL4(cf, vq, cb_idx, sf + idx);\n } while (len -= 4);\n }\n break;\n case 1:\n for (group = 0; group < g_len; group++, cfo+=128) {\n float *cf = cfo;\n int len = off_len;\n do {\n int code;\n unsigned nnz;\n unsigned cb_idx;\n uint32_t bits;\n UPDATE_CACHE(re, gb);\n GET_VLC(code, re, gb, vlc_tab, 8, 2);\n cb_idx = cb_vector_idx[code];\n nnz = cb_idx >> 8 & 15;\n bits = nnz ? GET_CACHE(re, gb) : 0;\n LAST_SKIP_BITS(re, gb, nnz);\n cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx);\n } while (len -= 4);\n }\n break;\n case 2:\n for (group = 0; group < g_len; group++, cfo+=128) {\n float *cf = cfo;\n int len = off_len;\n do {\n int code;\n unsigned cb_idx;\n UPDATE_CACHE(re, gb);\n GET_VLC(code, re, gb, vlc_tab, 8, 2);\n cb_idx = cb_vector_idx[code];\n cf = VMUL2(cf, vq, cb_idx, sf + idx);\n } while (len -= 2);\n }\n break;\n case 3:\n case 4:\n for (group = 0; group < g_len; group++, cfo+=128) {\n float *cf = cfo;\n int len = off_len;\n do {\n int code;\n unsigned nnz;\n unsigned cb_idx;\n unsigned sign;\n UPDATE_CACHE(re, gb);\n GET_VLC(code, re, gb, vlc_tab, 8, 2);\n cb_idx = cb_vector_idx[code];\n nnz = cb_idx >> 8 & 15;\n sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0;\n LAST_SKIP_BITS(re, gb, nnz);\n cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx);\n } while (len -= 2);\n }\n break;\n default:\n for (group = 0; group < g_len; group++, cfo+=128) {\n float *cf = cfo;\n uint32_t *icf = (uint32_t *) cf;\n int len = off_len;\n do {\n int code;\n unsigned nzt, nnz;\n unsigned cb_idx;\n uint32_t bits;\n int j;\n UPDATE_CACHE(re, gb);\n GET_VLC(code, re, gb, vlc_tab, 8, 2);\n if (!code) {\n *icf++ = 0;\n *icf++ = 0;\n continue;\n }\n cb_idx = cb_vector_idx[code];\n nnz = cb_idx >> 12;\n nzt = cb_idx >> 8;\n bits = SHOW_UBITS(re, gb, nnz) << (32-nnz);\n LAST_SKIP_BITS(re, gb, nnz);\n for (j = 0; j < 2; j++) {\n if (nzt & 1<<j) {\n uint32_t b;\n int n;\n UPDATE_CACHE(re, gb);\n b = GET_CACHE(re, gb);\n b = 31 - av_log2(~b);\n if (b > 8) {\n av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\\n");\n return -1;\n }\n SKIP_BITS(re, gb, b + 1);\n b += 4;\n n = (1 << b) + SHOW_UBITS(re, gb, b);\n LAST_SKIP_BITS(re, gb, b);\n *icf++ = cbrt_tab[n] | (bits & 1U<<31);\n bits <<= 1;\n } else {\n unsigned v = ((const uint32_t*)vq)[cb_idx & 15];\n *icf++ = (bits & 1U<<31) | v;\n bits <<= !!v;\n }\n cb_idx >>= 4;\n }\n } while (len -= 2);\n ac->dsp.vector_fmul_scalar(cfo, cfo, sf[idx], off_len);\n }\n }\n CLOSE_READER(re, gb);\n }\n }\n coef += g_len << 7;\n }\n if (pulse_present) {\n idx = 0;\n for (i = 0; i < pulse->num_pulse; i++) {\n float co = coef_base[ pulse->pos[i] ];\n while (offsets[idx + 1] <= pulse->pos[i])\n idx++;\n if (band_type[idx] != NOISE_BT && sf[idx]) {\n float ico = -pulse->amp[i];\n if (co) {\n co /= sf[idx];\n ico = co / sqrtf(sqrtf(fabsf(co))) + (co > 0 ? -ico : ico);\n }\n coef_base[ pulse->pos[i] ] = cbrtf(fabsf(ico)) * ico * sf[idx];\n }\n }\n }\n return 0;\n}']
|
1,337
| 0
|
https://github.com/libav/libav/blob/c41b9842ceac42bedfd74a7ba2d02add82f818a9/libavcodec/rv40.c/#L508
|
static void rv40_loop_filter(RV34DecContext *r, int row)
{
MpegEncContext *s = &r->s;
int mb_pos, mb_x;
int i, j, k;
uint8_t *Y, *C;
int alpha, beta, betaY, betaC;
int q;
int mbtype[4];
int mb_strong[4];
int clip[4];
int cbp[4];
int uvcbp[4][2];
int mvmasks[4];
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
r->cbp_chroma[mb_pos] = 0xFF;
}
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int y_h_deblock, y_v_deblock;
int c_v_deblock[2], c_h_deblock[2];
int clip_left;
int avail[4];
int y_to_deblock, c_to_deblock[2];
q = s->current_picture_ptr->f.qscale_table[mb_pos];
alpha = rv40_alpha_tab[q];
beta = rv40_beta_tab [q];
betaY = betaC = beta * 3;
if(s->width * s->height <= 176*144)
betaY += beta;
avail[0] = 1;
avail[1] = row;
avail[2] = mb_x;
avail[3] = row < s->mb_height - 1;
for(i = 0; i < 4; i++){
if(avail[i]){
int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;
mvmasks[i] = r->deblock_coefs[pos];
mbtype [i] = s->current_picture_ptr->f.mb_type[pos];
cbp [i] = r->cbp_luma[pos];
uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;
uvcbp[i][1] = r->cbp_chroma[pos] >> 4;
}else{
mvmasks[i] = 0;
mbtype [i] = mbtype[0];
cbp [i] = 0;
uvcbp[i][0] = uvcbp[i][1] = 0;
}
mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);
clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];
}
y_to_deblock = mvmasks[POS_CUR]
| (mvmasks[POS_BOTTOM] << 16);
y_h_deblock = y_to_deblock
| ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)
| ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);
y_v_deblock = y_to_deblock
| ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)
| ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);
if(!mb_x)
y_v_deblock &= ~MASK_Y_LEFT_COL;
if(!row)
y_h_deblock &= ~MASK_Y_TOP_ROW;
if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))
y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);
for(i = 0; i < 2; i++){
c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];
c_v_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)
| ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);
c_h_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)
| (uvcbp[POS_CUR][i] << 2);
if(!mb_x)
c_v_deblock[i] &= ~MASK_C_LEFT_COL;
if(!row)
c_h_deblock[i] &= ~MASK_C_TOP_ROW;
if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])
c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);
}
for(j = 0; j < 16; j += 4){
Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
int dither = j ? ij : i*4;
if(y_h_deblock & (MASK_BOTTOM << ij)){
rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,
s->linesize, dither,
y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,
clip_cur, alpha, beta, betaY,
0, 0, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){
if(!i)
clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
else
clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 0, 1);
}
if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,
alpha, beta, betaY, 0, 1, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){
clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 1, 1);
}
}
}
for(k = 0; k < 2; k++){
for(j = 0; j < 2; j++){
C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + j*2;
int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
if(c_h_deblock[k] & (MASK_CUR << (ij+2))){
int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,
clip_bot,
clip_cur,
alpha, beta, betaC, 1, 0, 0);
}
if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){
if(!i)
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
else
clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 0, 1);
}
if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){
int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,
clip_cur,
clip_top,
alpha, beta, betaC, 1, 1, 0);
}
if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 1, 1);
}
}
}
}
}
}
|
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n int mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n int y_to_deblock, c_to_deblock[2];\n q = s->current_picture_ptr->f.qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->f.mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,\n s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur, alpha, beta, betaY,\n 0, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0, 1);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0, 1);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1, 0);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1, 1);\n }\n }\n }\n }\n }\n}']
|
1,338
| 0
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\n const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)\n{\n BIGNUM *t;\n int found = 0;\n int i, j, c1 = 0;\n BN_CTX *ctx = NULL;\n prime_t *mods = NULL;\n int checks = BN_prime_checks_for_size(bits);\n if (bits < 2) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n } else if (bits == 2 && safe) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);\n if (mods == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n loop:\n if (add == NULL) {\n if (!probable_prime(ret, bits, mods))\n goto err;\n } else {\n if (safe) {\n if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))\n goto err;\n } else {\n if (!bn_probable_prime_dh(ret, bits, add, rem, ctx))\n goto err;\n }\n }\n if (!BN_GENCB_call(cb, 0, c1++))\n goto err;\n if (!safe) {\n i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);\n if (i == -1)\n goto err;\n if (i == 0)\n goto loop;\n } else {\n if (!BN_rshift1(t, ret))\n goto err;\n for (i = 0; i < checks; i++) {\n j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n if (!BN_GENCB_call(cb, 2, c1 - 1))\n goto err;\n }\n }\n found = 1;\n err:\n OPENSSL_free(mods);\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n bn_check_top(ret);\n return found;\n}', 'static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,\n const BIGNUM *rem, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *t1, *qadd, *q;\n bits--;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n qadd = BN_CTX_get(ctx);\n if (qadd == NULL)\n goto err;\n if (!BN_rshift1(qadd, padd))\n goto err;\n if (!BN_rand(q, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n goto err;\n if (!BN_mod(t1, q, qadd, ctx))\n goto err;\n if (!BN_sub(q, q, t1))\n goto err;\n if (rem == NULL) {\n if (!BN_add_word(q, 1))\n goto err;\n } else {\n if (!BN_rshift1(t1, rem))\n goto err;\n if (!BN_add(q, q, t1))\n goto err;\n }\n if (!BN_lshift1(p, q))\n goto err;\n if (!BN_add_word(p, 1))\n goto err;\n loop:\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG pmod = BN_mod_word(p, (BN_ULONG)primes[i]);\n BN_ULONG qmod = BN_mod_word(q, (BN_ULONG)primes[i]);\n if (pmod == (BN_ULONG)-1 || qmod == (BN_ULONG)-1)\n goto err;\n if (pmod == 0 || qmod == 0) {\n if (!BN_add(p, p, padd))\n goto err;\n if (!BN_add(q, q, qadd))\n goto err;\n goto loop;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(p);\n return ret;\n}', 'int BN_lshift1(BIGNUM *r, const BIGNUM *a)\n{\n register BN_ULONG *ap, *rp, t, c;\n int i;\n bn_check_top(r);\n bn_check_top(a);\n if (r != a) {\n r->neg = a->neg;\n if (bn_wexpand(r, a->top + 1) == NULL)\n return 0;\n r->top = a->top;\n } else {\n if (bn_wexpand(r, a->top + 1) == NULL)\n return 0;\n }\n ap = a->d;\n rp = r->d;\n c = 0;\n for (i = 0; i < a->top; i++) {\n t = *(ap++);\n *(rp++) = ((t << 1) | c) & BN_MASK2;\n c = (t & BN_TBIT) ? 1 : 0;\n }\n if (c) {\n *rp = 1;\n r->top++;\n }\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,339
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/motion_est_template.c/#L629
|
static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
{
MotionEstContext * const c= &s->me;
me_cmp_func cmpf, chroma_cmpf;
int dia_size;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(dia_size=1; dia_size<=4; dia_size++){
int dir;
const int x= best[0];
const int y= best[1];
if(dia_size&(dia_size-1)) continue;
if( x + dia_size > xmax
|| x - dia_size < xmin
|| y + dia_size > ymax
|| y - dia_size < ymin)
continue;
for(dir= 0; dir<dia_size; dir+=2){
int d;
CHECK_MV(x + dir , y + dia_size - dir);
CHECK_MV(x + dia_size - dir, y - dir );
CHECK_MV(x - dir , y - dia_size + dir);
CHECK_MV(x - dia_size + dir, y + dir );
}
if(x!=best[0] || y!=best[1])
dia_size=0;
#if 0
{
int dx, dy, i;
static int stats[8*8];
dx= FFABS(x-best[0]);
dy= FFABS(y-best[1]);
if(dy>dx){
dx^=dy; dy^=dx; dx^=dy;
}
stats[dy*8 + dx] ++;
if(256*256*256*64 % (stats[0]+1)==0){
for(i=0; i<64; i++){
if((i&7)==0) printf("\n");
printf("%8d ", stats[i]);
}
printf("\n");
}
}
#endif
}
return dmin;
}
|
['static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,\n int src_index, int ref_index, int const penalty_factor,\n int size, int h, int flags)\n{\n MotionEstContext * const c= &s->me;\n me_cmp_func cmpf, chroma_cmpf;\n int dia_size;\n LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n for(dia_size=1; dia_size<=4; dia_size++){\n int dir;\n const int x= best[0];\n const int y= best[1];\n if(dia_size&(dia_size-1)) continue;\n if( x + dia_size > xmax\n || x - dia_size < xmin\n || y + dia_size > ymax\n || y - dia_size < ymin)\n continue;\n for(dir= 0; dir<dia_size; dir+=2){\n int d;\n CHECK_MV(x + dir , y + dia_size - dir);\n CHECK_MV(x + dia_size - dir, y - dir );\n CHECK_MV(x - dir , y - dia_size + dir);\n CHECK_MV(x - dia_size + dir, y + dir );\n }\n if(x!=best[0] || y!=best[1])\n dia_size=0;\n#if 0\n{\nint dx, dy, i;\nstatic int stats[8*8];\ndx= FFABS(x-best[0]);\ndy= FFABS(y-best[1]);\nif(dy>dx){\n dx^=dy; dy^=dx; dx^=dy;\n}\nstats[dy*8 + dx] ++;\nif(256*256*256*64 % (stats[0]+1)==0){\n for(i=0; i<64; i++){\n if((i&7)==0) printf("\\n");\n printf("%8d ", stats[i]);\n }\n printf("\\n");\n}\n}\n#endif\n }\n return dmin;\n}']
|
1,340
| 0
|
https://github.com/openssl/openssl/blob/4ebb5293fc7ae1fbb7c5cd8bbe114049bcd8685e/engines/e_4758_cca.c/#L451
|
static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
UI_METHOD *ui_method, void *callback_data)
{
RSA *rtmp = NULL;
EVP_PKEY *res = NULL;
unsigned char* keyToken = NULL;
unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];
long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
long returnCode;
long reasonCode;
long exitDataLength = 0;
long ruleArrayLength = 0;
unsigned char exitData[8];
unsigned char ruleArray[8];
unsigned char keyLabel[64];
long keyLabelLength = strlen(key_id);
unsigned char modulus[256];
long modulusFieldLength = sizeof(modulus);
long modulusLength = 0;
unsigned char exponent[256];
long exponentLength = sizeof(exponent);
if (keyLabelLength > sizeof(keyLabel))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return NULL;
}
memset(keyLabel,' ', sizeof(keyLabel));
memcpy(keyLabel, key_id, keyLabelLength);
keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
if (!keyToken)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
ERR_R_MALLOC_FAILURE);
goto err;
}
keyRecordRead(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, keyLabel,
&keyTokenLength, keyToken+sizeof(long));
if (returnCode)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
publicKeyExtract(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);
if (returnCode)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
if (!getModulusAndExponent(pubKeyToken, &exponentLength,
exponent, &modulusLength, &modulusFieldLength,
modulus))
{
CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
goto err;
}
(*(long*)keyToken) = keyTokenLength;
rtmp = RSA_new_method(e);
RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
rtmp->flags |= RSA_FLAG_EXT_PKEY;
res = EVP_PKEY_new();
EVP_PKEY_assign_RSA(res, rtmp);
return res;
err:
if (keyToken)
OPENSSL_free(keyToken);
if (res)
EVP_PKEY_free(res);
if (rtmp)
RSA_free(rtmp);
return NULL;
}
|
["static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,\n\t\t\tUI_METHOD *ui_method, void *callback_data)\n\t{\n\tRSA *rtmp = NULL;\n\tEVP_PKEY *res = NULL;\n\tunsigned char* keyToken = NULL;\n\tunsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];\n\tlong pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;\n\tlong keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;\n\tlong returnCode;\n\tlong reasonCode;\n\tlong exitDataLength = 0;\n\tlong ruleArrayLength = 0;\n\tunsigned char exitData[8];\n\tunsigned char ruleArray[8];\n\tunsigned char keyLabel[64];\n\tlong keyLabelLength = strlen(key_id);\n\tunsigned char modulus[256];\n\tlong modulusFieldLength = sizeof(modulus);\n\tlong modulusLength = 0;\n\tunsigned char exponent[256];\n\tlong exponentLength = sizeof(exponent);\n\tif (keyLabelLength > sizeof(keyLabel))\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\tCCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n\t\treturn NULL;\n\t\t}\n\tmemset(keyLabel,' ', sizeof(keyLabel));\n\tmemcpy(keyLabel, key_id, keyLabelLength);\n\tkeyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));\n\tif (!keyToken)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tkeyRecordRead(&returnCode, &reasonCode, &exitDataLength,\n\t\texitData, &ruleArrayLength, ruleArray, keyLabel,\n\t\t&keyTokenLength, keyToken+sizeof(long));\n\tif (returnCode)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\tCCA4758_R_FAILED_LOADING_PRIVATE_KEY);\n\t\tgoto err;\n\t\t}\n\tpublicKeyExtract(&returnCode, &reasonCode, &exitDataLength,\n\t\texitData, &ruleArrayLength, ruleArray, &keyTokenLength,\n\t\tkeyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);\n\tif (returnCode)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\tCCA4758_R_FAILED_LOADING_PRIVATE_KEY);\n\t\tgoto err;\n\t\t}\n\tif (!getModulusAndExponent(pubKeyToken, &exponentLength,\n\t\t\texponent, &modulusLength, &modulusFieldLength,\n\t\t\tmodulus))\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\tCCA4758_R_FAILED_LOADING_PRIVATE_KEY);\n\t\tgoto err;\n\t\t}\n\t(*(long*)keyToken) = keyTokenLength;\n\trtmp = RSA_new_method(e);\n\tRSA_set_ex_data(rtmp, hndidx, (char *)keyToken);\n\trtmp->e = BN_bin2bn(exponent, exponentLength, NULL);\n\trtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);\n\trtmp->flags |= RSA_FLAG_EXT_PKEY;\n\tres = EVP_PKEY_new();\n\tEVP_PKEY_assign_RSA(res, rtmp);\n\treturn res;\nerr:\n\tif (keyToken)\n\t\tOPENSSL_free(keyToken);\n\tif (res)\n\t\tEVP_PKEY_free(res);\n\tif (rtmp)\n\t\tRSA_free(rtmp);\n\treturn NULL;\n\t}", 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n if(ret && (num > 2048))\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'static int getModulusAndExponent(const unsigned char*token, long *exponentLength,\n\t\tunsigned char *exponent, long *modulusLength, long *modulusFieldLength,\n\t\tunsigned char *modulus)\n\t{\n\tunsigned long len;\n\tif (*token++ != (char)0x1E)\n\t\treturn 0;\n\tif (*token++)\n\t\treturn 0;\n\tlen = *token++;\n\tlen = len << 8;\n\tlen |= (unsigned char)*token++;\n\ttoken += 4;\n\tif (*token++ == (char)0x04)\n\t\t{\n\t\tif (*token++)\n\t\t\treturn 0;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\ttoken+=2;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\t*exponentLength = len;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\t*modulusLength = len;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\t*modulusFieldLength = len;\n\t\tmemcpy(exponent, token, *exponentLength);\n\t\ttoken+= *exponentLength;\n\t\tmemcpy(modulus, token, *modulusFieldLength);\n\t\treturn 1;\n\t\t}\n\treturn 0;\n\t}', 'RSA *RSA_new_method(ENGINE *engine)\n\t{\n\tRSA *ret;\n\tret=(RSA *)OPENSSL_malloc(sizeof(RSA));\n\tif (ret == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tret->meth = RSA_get_default_method();\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_RSA();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_RSA(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD,\n\t\t\t\tERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\tret->pad=0;\n\tret->version=0;\n\tret->n=NULL;\n\tret->e=NULL;\n\tret->d=NULL;\n\tret->p=NULL;\n\tret->q=NULL;\n\tret->dmp1=NULL;\n\tret->dmq1=NULL;\n\tret->iqmp=NULL;\n\tret->references=1;\n\tret->_method_mod_n=NULL;\n\tret->_method_mod_p=NULL;\n\tret->_method_mod_q=NULL;\n\tret->blinding=NULL;\n\tret->bignum_data=NULL;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']
|
1,341
| 0
|
https://github.com/libav/libav/blob/1e8b9738fa70e20967ddb542d2f9d5552fc51ec6/libavcodec/h264_loopfilter.c/#L161
|
static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix,
int stride,
const int16_t bS[7], int bsi,
int qp, int a, int b,
int intra)
{
const unsigned int index_a = qp + a;
const int alpha = alpha_table[index_a];
const int beta = beta_table[qp + b];
if (alpha ==0 || beta == 0) return;
if( bS[0] < 4 || !intra ) {
int8_t tc[4];
tc[0] = tc0_table[index_a][bS[0*bsi]];
tc[1] = tc0_table[index_a][bS[1*bsi]];
tc[2] = tc0_table[index_a][bS[2*bsi]];
tc[3] = tc0_table[index_a][bS[3*bsi]];
h->h264dsp.h264_h_loop_filter_luma_mbaff(pix, stride, alpha, beta, tc);
} else {
h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta);
}
}
|
['void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {\n const int mb_xy= mb_x + mb_y*h->mb_stride;\n const int mb_type = h->cur_pic.mb_type[mb_xy];\n const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;\n int first_vertical_edge_done = 0;\n av_unused int dir;\n int chroma = !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY));\n int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);\n int a = h->slice_alpha_c0_offset - qp_bd_offset;\n int b = h->slice_beta_offset - qp_bd_offset;\n if (FRAME_MBAFF(h)\n && IS_INTERLACED(mb_type^h->left_type[LTOP])\n && h->left_type[LTOP]) {\n DECLARE_ALIGNED(8, int16_t, bS)[8];\n int qp[2];\n int bqp[2];\n int rqp[2];\n int mb_qp, mbn0_qp, mbn1_qp;\n int i;\n first_vertical_edge_done = 1;\n if( IS_INTRA(mb_type) ) {\n AV_WN64A(&bS[0], 0x0004000400040004ULL);\n AV_WN64A(&bS[4], 0x0004000400040004ULL);\n } else {\n static const uint8_t offset[2][2][8]={\n {\n {3+4*0, 3+4*0, 3+4*0, 3+4*0, 3+4*1, 3+4*1, 3+4*1, 3+4*1},\n {3+4*2, 3+4*2, 3+4*2, 3+4*2, 3+4*3, 3+4*3, 3+4*3, 3+4*3},\n },{\n {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},\n {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},\n }\n };\n const uint8_t *off= offset[MB_FIELD(h)][mb_y&1];\n for( i = 0; i < 8; i++ ) {\n int j= MB_FIELD(h) ? i>>2 : i&1;\n int mbn_xy = h->left_mb_xy[LEFT(j)];\n int mbn_type= h->left_type[LEFT(j)];\n if( IS_INTRA( mbn_type ) )\n bS[i] = 4;\n else{\n bS[i] = 1 + !!(h->non_zero_count_cache[12+8*(i>>1)] |\n ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ?\n (h->cbp_table[mbn_xy] & (((MB_FIELD(h) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12))\n :\n h->non_zero_count[mbn_xy][ off[i] ]));\n }\n }\n }\n mb_qp = h->cur_pic.qscale_table[mb_xy];\n mbn0_qp = h->cur_pic.qscale_table[h->left_mb_xy[0]];\n mbn1_qp = h->cur_pic.qscale_table[h->left_mb_xy[1]];\n qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;\n bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) +\n get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1;\n rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) +\n get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1;\n qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;\n bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) +\n get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1;\n rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) +\n get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1;\n tprintf(h->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);\n { int i; for (i = 0; i < 8; i++) tprintf(h->avctx, " bS[%d]:%d", i, bS[i]); tprintf(h->avctx, "\\n"); }\n if (MB_FIELD(h)) {\n filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1], a, b, 1 );\n if (chroma){\n if (CHROMA444(h)) {\n filter_mb_mbaff_edgev ( h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );\n } else if (CHROMA422(h)) {\n filter_mb_mbaff_edgecv(h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1);\n filter_mb_mbaff_edgecv(h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1);\n filter_mb_mbaff_edgecv(h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1);\n filter_mb_mbaff_edgecv(h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1);\n }else{\n filter_mb_mbaff_edgecv( h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1 );\n filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );\n filter_mb_mbaff_edgecv( h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1 );\n filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );\n }\n }\n }else{\n filter_mb_mbaff_edgev ( h, img_y , 2* linesize, bS , 2, qp [0], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_y + linesize, 2* linesize, bS+1, 2, qp [1], a, b, 1 );\n if (chroma){\n if (CHROMA444(h)) {\n filter_mb_mbaff_edgev ( h, img_cb, 2*uvlinesize, bS , 2, bqp[0], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_cr, 2*uvlinesize, bS , 2, rqp[0], a, b, 1 );\n filter_mb_mbaff_edgev ( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );\n }else{\n filter_mb_mbaff_edgecv( h, img_cb, 2*uvlinesize, bS , 2, bqp[0], a, b, 1 );\n filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );\n filter_mb_mbaff_edgecv( h, img_cr, 2*uvlinesize, bS , 2, rqp[0], a, b, 1 );\n filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );\n }\n }\n }\n }\n#if CONFIG_SMALL\n for( dir = 0; dir < 2; dir++ )\n filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, a, b, chroma, dir);\n#else\n filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, a, b, chroma, 0);\n filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, a, b, chroma, 1);\n#endif\n}', 'static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix,\n int stride,\n const int16_t bS[7], int bsi,\n int qp, int a, int b,\n int intra)\n{\n const unsigned int index_a = qp + a;\n const int alpha = alpha_table[index_a];\n const int beta = beta_table[qp + b];\n if (alpha ==0 || beta == 0) return;\n if( bS[0] < 4 || !intra ) {\n int8_t tc[4];\n tc[0] = tc0_table[index_a][bS[0*bsi]];\n tc[1] = tc0_table[index_a][bS[1*bsi]];\n tc[2] = tc0_table[index_a][bS[2*bsi]];\n tc[3] = tc0_table[index_a][bS[3*bsi]];\n h->h264dsp.h264_h_loop_filter_luma_mbaff(pix, stride, alpha, beta, tc);\n } else {\n h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta);\n }\n}']
|
1,342
| 0
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n BIGNUM **verifier, const BIGNUM *N,\n const BIGNUM *g)\n{\n int result = 0;\n BIGNUM *x = NULL;\n BN_CTX *bn_ctx = BN_CTX_new();\n unsigned char tmp2[MAX_LEN];\n BIGNUM *salttmp = NULL;\n if ((user == NULL) ||\n (pass == NULL) ||\n (salt == NULL) ||\n (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n goto err;\n if (*salt == NULL) {\n if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n goto err;\n salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n } else {\n salttmp = *salt;\n }\n x = SRP_Calc_x(salttmp, user, pass);\n *verifier = BN_new();\n if (*verifier == NULL)\n goto err;\n if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n BN_clear_free(*verifier);\n goto err;\n }\n result = 1;\n *salt = salttmp;\n err:\n if (salt != NULL && *salt != salttmp)\n BN_clear_free(salttmp);\n BN_clear_free(x);\n BN_CTX_free(bn_ctx);\n return result;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
1,343
| 0
|
https://github.com/libav/libav/blob/f40f329e9219a8dd7e585345a8ea294fa66562b9/libavcodec/mpegaudiodec.c/#L870
|
void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
INTFLOAT sb_samples[SBLIMIT])
{
register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p;
int j, offset;
OUT_INT *samples2;
#if CONFIG_FLOAT
float sum, sum2;
#elif FRAC_BITS <= 15
int32_t tmp[32];
int sum, sum2;
#else
int64_t sum, sum2;
#endif
offset = *synth_buf_offset;
synth_buf = synth_buf_ptr + offset;
#if FRAC_BITS <= 15 && !CONFIG_FLOAT
dct32(tmp, sb_samples);
for(j=0;j<32;j++) {
synth_buf[j] = av_clip_int16(tmp[j]);
}
#else
dct32(synth_buf, sb_samples);
#endif
memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
samples2 = samples + 31 * incr;
w = window;
w2 = window + 31;
sum = *dither_state;
p = synth_buf + 16;
SUM8(MACS, sum, w, p);
p = synth_buf + 48;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
samples += incr;
w++;
for(j=1;j<16;j++) {
sum2 = 0;
p = synth_buf + 16 + j;
SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);
p = synth_buf + 48 - j;
SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);
*samples = round_sample(&sum);
samples += incr;
sum += sum2;
*samples2 = round_sample(&sum);
samples2 -= incr;
w++;
w2--;
}
p = synth_buf + 32;
SUM8(MLSS, sum, w + 32, p);
*samples = round_sample(&sum);
*dither_state= sum;
offset = (offset - 32) & 511;
*synth_buf_offset = offset;
}
|
['static 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 RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n register const MPA_INT *w, *w2, *p;\n int j, offset;\n OUT_INT *samples2;\n#if CONFIG_FLOAT\n float sum, sum2;\n#elif FRAC_BITS <= 15\n int32_t tmp[32];\n int sum, sum2;\n#else\n int64_t sum, sum2;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));\n samples2 = samples + 31 * incr;\n w = window;\n w2 = window + 31;\n sum = *dither_state;\n p = synth_buf + 16;\n SUM8(MACS, sum, w, p);\n p = synth_buf + 48;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n w++;\n for(j=1;j<16;j++) {\n sum2 = 0;\n p = synth_buf + 16 + j;\n SUM8P2(sum, MACS, sum2, MLSS, w, w2, p);\n p = synth_buf + 48 - j;\n SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p);\n *samples = round_sample(&sum);\n samples += incr;\n sum += sum2;\n *samples2 = round_sample(&sum);\n samples2 -= incr;\n w++;\n w2--;\n }\n p = synth_buf + 32;\n SUM8(MLSS, sum, w + 32, p);\n *samples = round_sample(&sum);\n *dither_state= sum;\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}']
|
1,344
| 0
|
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/asn1/asn1_lib.c/#L172
|
static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,
int max)
{
const unsigned char *p = *pp;
unsigned long ret = 0;
unsigned int i;
if (max-- < 1)
return (0);
if (*p == 0x80) {
*inf = 1;
ret = 0;
p++;
} else {
*inf = 0;
i = *p & 0x7f;
if (*(p++) & 0x80) {
if (max < (int)i)
return 0;
while (i && *p == 0) {
p++;
i--;
}
if (i > sizeof(long))
return 0;
while (i-- > 0) {
ret <<= 8L;
ret |= *(p++);
}
} else
ret = i;
}
if (ret > LONG_MAX)
return 0;
*pp = p;
*rl = (long)ret;
return (1);
}
|
['void *PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,\n const char *pass, int passlen,\n ASN1_OCTET_STRING *oct, int zbuf)\n{\n unsigned char *out;\n const unsigned char *p;\n void *ret;\n int outlen;\n if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length,\n &out, &outlen, 0)) {\n PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,\n PKCS12_R_PKCS12_PBE_CRYPT_ERROR);\n return NULL;\n }\n p = out;\n#ifdef DEBUG_DECRYPT\n {\n FILE *op;\n char fname[30];\n static int fnm = 1;\n sprintf(fname, "DER%d", fnm++);\n op = fopen(fname, "wb");\n fwrite(p, 1, outlen, op);\n fclose(op);\n }\n#endif\n ret = ASN1_item_d2i(NULL, &p, outlen, it);\n if (zbuf)\n OPENSSL_cleanse(out, outlen);\n if (!ret)\n PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, PKCS12_R_DECODE_ERROR);\n OPENSSL_free(out);\n return ret;\n}', 'unsigned char *PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,\n int passlen, unsigned char *in, int inlen,\n unsigned char **data, int *datalen, int en_de)\n{\n unsigned char *out = NULL;\n int outlen, i;\n EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();\n if (ctx == NULL) {\n PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen,\n algor->parameter, ctx, en_de)) {\n PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,\n PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR);\n goto err;\n }\n if ((out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(ctx)))\n == NULL) {\n PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EVP_CipherUpdate(ctx, out, &i, in, inlen)) {\n OPENSSL_free(out);\n out = NULL;\n PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT, ERR_R_EVP_LIB);\n goto err;\n }\n outlen = i;\n if (!EVP_CipherFinal_ex(ctx, out + i, &i)) {\n OPENSSL_free(out);\n out = NULL;\n PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,\n PKCS12_R_PKCS12_CIPHERFINAL_ERROR);\n goto err;\n }\n outlen += i;\n if (datalen)\n *datalen = outlen;\n if (data)\n *data = out;\n err:\n EVP_CIPHER_CTX_free(ctx);\n return out;\n}', 'ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,\n const unsigned char **in, long len,\n const ASN1_ITEM *it)\n{\n ASN1_TLC c;\n ASN1_VALUE *ptmpval = NULL;\n if (!pval)\n pval = &ptmpval;\n asn1_tlc_clear_nc(&c);\n if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)\n return *pval;\n return NULL;\n}', 'int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,\n const ASN1_ITEM *it,\n int tag, int aclass, char opt, ASN1_TLC *ctx)\n{\n int rv;\n rv = asn1_item_embed_d2i(pval, in, len, it, tag, aclass, opt, ctx);\n if (rv <= 0)\n ASN1_item_ex_free(pval, it);\n return rv;\n}', 'static int asn1_item_embed_d2i(ASN1_VALUE **pval, const unsigned char **in,\n long len, const ASN1_ITEM *it,\n int tag, int aclass, char opt, ASN1_TLC *ctx)\n{\n const ASN1_TEMPLATE *tt, *errtt = NULL;\n const ASN1_EXTERN_FUNCS *ef;\n const ASN1_AUX *aux = it->funcs;\n ASN1_aux_cb *asn1_cb;\n const unsigned char *p = NULL, *q;\n unsigned char oclass;\n char seq_eoc, seq_nolen, cst, isopt;\n long tmplen;\n int i;\n int otag;\n int ret = 0;\n ASN1_VALUE **pchptr;\n if (!pval)\n return 0;\n if (aux && aux->asn1_cb)\n asn1_cb = aux->asn1_cb;\n else\n asn1_cb = 0;\n switch (it->itype) {\n case ASN1_ITYPE_PRIMITIVE:\n if (it->templates) {\n if ((tag != -1) || opt) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I,\n ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);\n goto err;\n }\n return asn1_template_ex_d2i(pval, in, len,\n it->templates, opt, ctx);\n }\n return asn1_d2i_ex_primitive(pval, in, len, it,\n tag, aclass, opt, ctx);\n case ASN1_ITYPE_MSTRING:\n p = *in;\n ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,\n &p, len, -1, 0, 1, ctx);\n if (!ret) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n }\n if (oclass != V_ASN1_UNIVERSAL) {\n if (opt)\n return -1;\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);\n goto err;\n }\n if (!(ASN1_tag2bit(otag) & it->utype)) {\n if (opt)\n return -1;\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MSTRING_WRONG_TAG);\n goto err;\n }\n return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);\n case ASN1_ITYPE_EXTERN:\n ef = it->funcs;\n return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);\n case ASN1_ITYPE_CHOICE:\n if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))\n goto auxerr;\n if (*pval) {\n i = asn1_get_choice_selector(pval, it);\n if ((i >= 0) && (i < it->tcount)) {\n tt = it->templates + i;\n pchptr = asn1_get_field_ptr(pval, tt);\n asn1_template_free(pchptr, tt);\n asn1_set_choice_selector(pval, -1, it);\n }\n } else if (!ASN1_item_ex_new(pval, it)) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n }\n p = *in;\n for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {\n pchptr = asn1_get_field_ptr(pval, tt);\n ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);\n if (ret == -1)\n continue;\n if (ret > 0)\n break;\n errtt = tt;\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n }\n if (i == it->tcount) {\n if (opt) {\n ASN1_item_ex_free(pval, it);\n return -1;\n }\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);\n goto err;\n }\n asn1_set_choice_selector(pval, i, it);\n if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))\n goto auxerr;\n *in = p;\n return 1;\n case ASN1_ITYPE_NDEF_SEQUENCE:\n case ASN1_ITYPE_SEQUENCE:\n p = *in;\n tmplen = len;\n if (tag == -1) {\n tag = V_ASN1_SEQUENCE;\n aclass = V_ASN1_UNIVERSAL;\n }\n ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,\n &p, len, tag, aclass, opt, ctx);\n if (!ret) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n } else if (ret == -1)\n return -1;\n if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {\n len = tmplen - (p - *in);\n seq_nolen = 1;\n }\n else\n seq_nolen = seq_eoc;\n if (!cst) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);\n goto err;\n }\n if (!*pval && !ASN1_item_ex_new(pval, it)) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ERR_R_NESTED_ASN1_ERROR);\n goto err;\n }\n if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))\n goto auxerr;\n for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {\n if (tt->flags & ASN1_TFLG_ADB_MASK) {\n const ASN1_TEMPLATE *seqtt;\n ASN1_VALUE **pseqval;\n seqtt = asn1_do_adb(pval, tt, 1);\n pseqval = asn1_get_field_ptr(pval, seqtt);\n asn1_template_free(pseqval, seqtt);\n }\n }\n for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {\n const ASN1_TEMPLATE *seqtt;\n ASN1_VALUE **pseqval;\n seqtt = asn1_do_adb(pval, tt, 1);\n if (!seqtt)\n goto err;\n pseqval = asn1_get_field_ptr(pval, seqtt);\n if (!len)\n break;\n q = p;\n if (asn1_check_eoc(&p, len)) {\n if (!seq_eoc) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_UNEXPECTED_EOC);\n goto err;\n }\n len -= p - q;\n seq_eoc = 0;\n q = p;\n break;\n }\n if (i == (it->tcount - 1))\n isopt = 0;\n else\n isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);\n ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);\n if (!ret) {\n errtt = seqtt;\n goto err;\n } else if (ret == -1) {\n asn1_template_free(pseqval, seqtt);\n continue;\n }\n len -= p - q;\n }\n if (seq_eoc && !asn1_check_eoc(&p, len)) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_MISSING_EOC);\n goto err;\n }\n if (!seq_nolen && len) {\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);\n goto err;\n }\n for (; i < it->tcount; tt++, i++) {\n const ASN1_TEMPLATE *seqtt;\n seqtt = asn1_do_adb(pval, tt, 1);\n if (!seqtt)\n goto err;\n if (seqtt->flags & ASN1_TFLG_OPTIONAL) {\n ASN1_VALUE **pseqval;\n pseqval = asn1_get_field_ptr(pval, seqtt);\n asn1_template_free(pseqval, seqtt);\n } else {\n errtt = seqtt;\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_FIELD_MISSING);\n goto err;\n }\n }\n if (!asn1_enc_save(pval, *in, p - *in, it))\n goto auxerr;\n if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))\n goto auxerr;\n *in = p;\n return 1;\n default:\n return 0;\n }\n auxerr:\n ASN1err(ASN1_F_ASN1_ITEM_EMBED_D2I, ASN1_R_AUX_ERROR);\n err:\n if (errtt)\n ERR_add_error_data(4, "Field=", errtt->field_name,\n ", Type=", it->sname);\n else\n ERR_add_error_data(2, "Type=", it->sname);\n return 0;\n}', 'static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,\n char *inf, char *cst,\n const unsigned char **in, long len,\n int exptag, int expclass, char opt, ASN1_TLC *ctx)\n{\n int i;\n int ptag, pclass;\n long plen;\n const unsigned char *p, *q;\n p = *in;\n q = p;\n if (ctx && ctx->valid) {\n i = ctx->ret;\n plen = ctx->plen;\n pclass = ctx->pclass;\n ptag = ctx->ptag;\n p += ctx->hdrlen;\n } else {\n i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);\n if (ctx) {\n ctx->ret = i;\n ctx->plen = plen;\n ctx->pclass = pclass;\n ctx->ptag = ptag;\n ctx->hdrlen = p - q;\n ctx->valid = 1;\n if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {\n ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);\n asn1_tlc_clear(ctx);\n return 0;\n }\n }\n }\n if (i & 0x80) {\n ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);\n asn1_tlc_clear(ctx);\n return 0;\n }\n if (exptag >= 0) {\n if ((exptag != ptag) || (expclass != pclass)) {\n if (opt)\n return -1;\n asn1_tlc_clear(ctx);\n ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);\n return 0;\n }\n asn1_tlc_clear(ctx);\n }\n if (i & 1)\n plen = len - (p - q);\n if (inf)\n *inf = i & 1;\n if (cst)\n *cst = i & V_ASN1_CONSTRUCTED;\n if (olen)\n *olen = plen;\n if (oclass)\n *oclass = pclass;\n if (otag)\n *otag = ptag;\n *in = p;\n return 1;\n}', 'int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,\n int *pclass, long omax)\n{\n int i, ret;\n long l;\n const unsigned char *p = *pp;\n int tag, xclass, inf;\n long max = omax;\n if (!max)\n goto err;\n ret = (*p & V_ASN1_CONSTRUCTED);\n xclass = (*p & V_ASN1_PRIVATE);\n i = *p & V_ASN1_PRIMITIVE_TAG;\n if (i == V_ASN1_PRIMITIVE_TAG) {\n p++;\n if (--max == 0)\n goto err;\n l = 0;\n while (*p & 0x80) {\n l <<= 7L;\n l |= *(p++) & 0x7f;\n if (--max == 0)\n goto err;\n if (l > (INT_MAX >> 7L))\n goto err;\n }\n l <<= 7L;\n l |= *(p++) & 0x7f;\n tag = (int)l;\n if (--max == 0)\n goto err;\n } else {\n tag = i;\n p++;\n if (--max == 0)\n goto err;\n }\n *ptag = tag;\n *pclass = xclass;\n if (!asn1_get_length(&p, &inf, plength, (int)max))\n goto err;\n if (inf && !(ret & V_ASN1_CONSTRUCTED))\n goto err;\n if (*plength > (omax - (p - *pp))) {\n ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_TOO_LONG);\n ret |= 0x80;\n }\n *pp = p;\n return (ret | inf);\n err:\n ASN1err(ASN1_F_ASN1_GET_OBJECT, ASN1_R_HEADER_TOO_LONG);\n return (0x80);\n}', 'static int asn1_get_length(const unsigned char **pp, int *inf, long *rl,\n int max)\n{\n const unsigned char *p = *pp;\n unsigned long ret = 0;\n unsigned int i;\n if (max-- < 1)\n return (0);\n if (*p == 0x80) {\n *inf = 1;\n ret = 0;\n p++;\n } else {\n *inf = 0;\n i = *p & 0x7f;\n if (*(p++) & 0x80) {\n if (max < (int)i)\n return 0;\n while (i && *p == 0) {\n p++;\n i--;\n }\n if (i > sizeof(long))\n return 0;\n while (i-- > 0) {\n ret <<= 8L;\n ret |= *(p++);\n }\n } else\n ret = i;\n }\n if (ret > LONG_MAX)\n return 0;\n *pp = p;\n *rl = (long)ret;\n return (1);\n}']
|
1,345
| 0
|
https://github.com/libav/libav/blob/ad1161799e096c4bae885f100f27f886755d479a/libavcodec/metasound.c/#L322
|
static av_cold int metasound_decode_init(AVCodecContext *avctx)
{
int isampf, ibps;
TwinVQContext *tctx = avctx->priv_data;
uint32_t tag;
const MetasoundProps *props = codec_props;
if (!avctx->extradata || avctx->extradata_size < 16) {
av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
return AVERROR_INVALIDDATA;
}
tag = AV_RL32(avctx->extradata + 12);
for (;;) {
if (!props->tag) {
av_log(avctx, AV_LOG_ERROR, "Could not find tag %08X\n", tag);
return AVERROR_INVALIDDATA;
}
if (props->tag == tag) {
avctx->sample_rate = props->sample_rate;
avctx->channels = props->channels;
avctx->bit_rate = props->bit_rate * 1000;
isampf = avctx->sample_rate / 1000;
break;
}
props++;
}
if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {
av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
avctx->channels);
return AVERROR_INVALIDDATA;
}
avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO
: AV_CH_LAYOUT_STEREO;
ibps = avctx->bit_rate / (1000 * avctx->channels);
switch ((avctx->channels << 16) + (isampf << 8) + ibps) {
case (1 << 16) + ( 8 << 8) + 8:
tctx->mtab = &ff_metasound_mode0808;
break;
case (2 << 16) + ( 8 << 8) + 8:
tctx->mtab = &ff_metasound_mode0808s;
break;
case (1 << 16) + (11 << 8) + 10:
tctx->mtab = &ff_metasound_mode1110;
break;
case (2 << 16) + (11 << 8) + 10:
tctx->mtab = &ff_metasound_mode1110s;
break;
case (1 << 16) + (16 << 8) + 16:
tctx->mtab = &ff_metasound_mode1616;
break;
case (2 << 16) + (16 << 8) + 16:
tctx->mtab = &ff_metasound_mode1616s;
break;
case (1 << 16) + (22 << 8) + 24:
tctx->mtab = &ff_metasound_mode2224;
break;
case (2 << 16) + (22 << 8) + 24:
tctx->mtab = &ff_metasound_mode2224s;
break;
case (1 << 16) + (44 << 8) + 32:
tctx->mtab = &ff_metasound_mode4432;
break;
case (2 << 16) + (44 << 8) + 32:
tctx->mtab = &ff_metasound_mode4432s;
break;
case (1 << 16) + (44 << 8) + 40:
tctx->mtab = &ff_metasound_mode4440;
break;
case (2 << 16) + (44 << 8) + 40:
tctx->mtab = &ff_metasound_mode4440s;
break;
case (1 << 16) + (44 << 8) + 48:
tctx->mtab = &ff_metasound_mode4448;
break;
case (2 << 16) + (44 << 8) + 48:
tctx->mtab = &ff_metasound_mode4448s;
break;
default:
av_log(avctx, AV_LOG_ERROR,
"This version does not support %d kHz - %d kbit/s/ch mode.\n",
isampf, ibps);
return AVERROR(ENOSYS);
}
tctx->codec = TWINVQ_CODEC_METASOUND;
tctx->read_bitstream = metasound_read_bitstream;
tctx->dec_bark_env = dec_bark_env;
tctx->decode_ppc = decode_ppc;
tctx->frame_size = avctx->bit_rate * tctx->mtab->size
/ avctx->sample_rate;
return ff_twinvq_decode_init(avctx);
}
|
['static av_cold int metasound_decode_init(AVCodecContext *avctx)\n{\n int isampf, ibps;\n TwinVQContext *tctx = avctx->priv_data;\n uint32_t tag;\n const MetasoundProps *props = codec_props;\n if (!avctx->extradata || avctx->extradata_size < 16) {\n av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\\n");\n return AVERROR_INVALIDDATA;\n }\n tag = AV_RL32(avctx->extradata + 12);\n for (;;) {\n if (!props->tag) {\n av_log(avctx, AV_LOG_ERROR, "Could not find tag %08X\\n", tag);\n return AVERROR_INVALIDDATA;\n }\n if (props->tag == tag) {\n avctx->sample_rate = props->sample_rate;\n avctx->channels = props->channels;\n avctx->bit_rate = props->bit_rate * 1000;\n isampf = avctx->sample_rate / 1000;\n break;\n }\n props++;\n }\n if (avctx->channels <= 0 || avctx->channels > TWINVQ_CHANNELS_MAX) {\n av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\\n",\n avctx->channels);\n return AVERROR_INVALIDDATA;\n }\n avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO\n : AV_CH_LAYOUT_STEREO;\n ibps = avctx->bit_rate / (1000 * avctx->channels);\n switch ((avctx->channels << 16) + (isampf << 8) + ibps) {\n case (1 << 16) + ( 8 << 8) + 8:\n tctx->mtab = &ff_metasound_mode0808;\n break;\n case (2 << 16) + ( 8 << 8) + 8:\n tctx->mtab = &ff_metasound_mode0808s;\n break;\n case (1 << 16) + (11 << 8) + 10:\n tctx->mtab = &ff_metasound_mode1110;\n break;\n case (2 << 16) + (11 << 8) + 10:\n tctx->mtab = &ff_metasound_mode1110s;\n break;\n case (1 << 16) + (16 << 8) + 16:\n tctx->mtab = &ff_metasound_mode1616;\n break;\n case (2 << 16) + (16 << 8) + 16:\n tctx->mtab = &ff_metasound_mode1616s;\n break;\n case (1 << 16) + (22 << 8) + 24:\n tctx->mtab = &ff_metasound_mode2224;\n break;\n case (2 << 16) + (22 << 8) + 24:\n tctx->mtab = &ff_metasound_mode2224s;\n break;\n case (1 << 16) + (44 << 8) + 32:\n tctx->mtab = &ff_metasound_mode4432;\n break;\n case (2 << 16) + (44 << 8) + 32:\n tctx->mtab = &ff_metasound_mode4432s;\n break;\n case (1 << 16) + (44 << 8) + 40:\n tctx->mtab = &ff_metasound_mode4440;\n break;\n case (2 << 16) + (44 << 8) + 40:\n tctx->mtab = &ff_metasound_mode4440s;\n break;\n case (1 << 16) + (44 << 8) + 48:\n tctx->mtab = &ff_metasound_mode4448;\n break;\n case (2 << 16) + (44 << 8) + 48:\n tctx->mtab = &ff_metasound_mode4448s;\n break;\n default:\n av_log(avctx, AV_LOG_ERROR,\n "This version does not support %d kHz - %d kbit/s/ch mode.\\n",\n isampf, ibps);\n return AVERROR(ENOSYS);\n }\n tctx->codec = TWINVQ_CODEC_METASOUND;\n tctx->read_bitstream = metasound_read_bitstream;\n tctx->dec_bark_env = dec_bark_env;\n tctx->decode_ppc = decode_ppc;\n tctx->frame_size = avctx->bit_rate * tctx->mtab->size\n / avctx->sample_rate;\n return ff_twinvq_decode_init(avctx);\n}']
|
1,346
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/svq1enc.c/#L196
|
static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){
int count, y, x, i, j, split, best_mean, best_score, best_count;
int best_vector[6];
int block_sum[7]= {0, 0, 0, 0, 0, 0};
int w= 2<<((level+2)>>1);
int h= 2<<((level+1)>>1);
int size=w*h;
int16_t block[7][256];
const int8_t *codebook_sum, *codebook;
const uint16_t (*mean_vlc)[2];
const uint8_t (*multistage_vlc)[2];
best_score=0;
if(intra){
codebook_sum= svq1_intra_codebook_sum[level];
codebook= ff_svq1_intra_codebooks[level];
mean_vlc= ff_svq1_intra_mean_vlc;
multistage_vlc= ff_svq1_intra_multistage_vlc[level];
for(y=0; y<h; y++){
for(x=0; x<w; x++){
int v= src[x + y*stride];
block[0][x + w*y]= v;
best_score += v*v;
block_sum[0] += v;
}
}
}else{
codebook_sum= svq1_inter_codebook_sum[level];
codebook= ff_svq1_inter_codebooks[level];
mean_vlc= ff_svq1_inter_mean_vlc + 256;
multistage_vlc= ff_svq1_inter_multistage_vlc[level];
for(y=0; y<h; y++){
for(x=0; x<w; x++){
int v= src[x + y*stride] - ref[x + y*stride];
block[0][x + w*y]= v;
best_score += v*v;
block_sum[0] += v;
}
}
}
best_count=0;
best_score -= ((block_sum[0]*block_sum[0])>>(level+3));
best_mean= (block_sum[0] + (size>>1)) >> (level+3);
if(level<4){
for(count=1; count<7; count++){
int best_vector_score= INT_MAX;
int best_vector_sum=-999, best_vector_mean=-999;
const int stage= count-1;
const int8_t *vector;
for(i=0; i<16; i++){
int sum= codebook_sum[stage*16 + i];
int sqr, diff, score;
vector = codebook + stage*size*16 + i*size;
sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);
diff= block_sum[stage] - sum;
score= sqr - ((diff*(int64_t)diff)>>(level+3));
if(score < best_vector_score){
int mean= (diff + (size>>1)) >> (level+3);
assert(mean >-300 && mean<300);
mean= av_clip(mean, intra?0:-256, 255);
best_vector_score= score;
best_vector[stage]= i;
best_vector_sum= sum;
best_vector_mean= mean;
}
}
assert(best_vector_mean != -999);
vector= codebook + stage*size*16 + best_vector[stage]*size;
for(j=0; j<size; j++){
block[stage+1][j] = block[stage][j] - vector[j];
}
block_sum[stage+1]= block_sum[stage] - best_vector_sum;
best_vector_score +=
lambda*(+ 1 + 4*count
+ multistage_vlc[1+count][1]
+ mean_vlc[best_vector_mean][1]);
if(best_vector_score < best_score){
best_score= best_vector_score;
best_count= count;
best_mean= best_vector_mean;
}
}
}
split=0;
if(best_score > threshold && level){
int score=0;
int offset= (level&1) ? stride*h/2 : w/2;
PutBitContext backup[6];
for(i=level-1; i>=0; i--){
backup[i]= s->reorder_pb[i];
}
score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra);
score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra);
score += lambda;
if(score < best_score){
best_score= score;
split=1;
}else{
for(i=level-1; i>=0; i--){
s->reorder_pb[i]= backup[i];
}
}
}
if (level > 0)
put_bits(&s->reorder_pb[level], 1, split);
if(!split){
assert((best_mean >= 0 && best_mean<256) || !intra);
assert(best_mean >= -256 && best_mean<256);
assert(best_count >=0 && best_count<7);
assert(level<4 || best_count==0);
put_bits(&s->reorder_pb[level],
multistage_vlc[1 + best_count][1],
multistage_vlc[1 + best_count][0]);
put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1],
mean_vlc[best_mean][0]);
for (i = 0; i < best_count; i++){
assert(best_vector[i]>=0 && best_vector[i]<16);
put_bits(&s->reorder_pb[level], 4, best_vector[i]);
}
for(y=0; y<h; y++){
for(x=0; x<w; x++){
decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean;
}
}
}
return best_score;
}
|
['static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){\n int count, y, x, i, j, split, best_mean, best_score, best_count;\n int best_vector[6];\n int block_sum[7]= {0, 0, 0, 0, 0, 0};\n int w= 2<<((level+2)>>1);\n int h= 2<<((level+1)>>1);\n int size=w*h;\n int16_t block[7][256];\n const int8_t *codebook_sum, *codebook;\n const uint16_t (*mean_vlc)[2];\n const uint8_t (*multistage_vlc)[2];\n best_score=0;\n if(intra){\n codebook_sum= svq1_intra_codebook_sum[level];\n codebook= ff_svq1_intra_codebooks[level];\n mean_vlc= ff_svq1_intra_mean_vlc;\n multistage_vlc= ff_svq1_intra_multistage_vlc[level];\n for(y=0; y<h; y++){\n for(x=0; x<w; x++){\n int v= src[x + y*stride];\n block[0][x + w*y]= v;\n best_score += v*v;\n block_sum[0] += v;\n }\n }\n }else{\n codebook_sum= svq1_inter_codebook_sum[level];\n codebook= ff_svq1_inter_codebooks[level];\n mean_vlc= ff_svq1_inter_mean_vlc + 256;\n multistage_vlc= ff_svq1_inter_multistage_vlc[level];\n for(y=0; y<h; y++){\n for(x=0; x<w; x++){\n int v= src[x + y*stride] - ref[x + y*stride];\n block[0][x + w*y]= v;\n best_score += v*v;\n block_sum[0] += v;\n }\n }\n }\n best_count=0;\n best_score -= ((block_sum[0]*block_sum[0])>>(level+3));\n best_mean= (block_sum[0] + (size>>1)) >> (level+3);\n if(level<4){\n for(count=1; count<7; count++){\n int best_vector_score= INT_MAX;\n int best_vector_sum=-999, best_vector_mean=-999;\n const int stage= count-1;\n const int8_t *vector;\n for(i=0; i<16; i++){\n int sum= codebook_sum[stage*16 + i];\n int sqr, diff, score;\n vector = codebook + stage*size*16 + i*size;\n sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size);\n diff= block_sum[stage] - sum;\n score= sqr - ((diff*(int64_t)diff)>>(level+3));\n if(score < best_vector_score){\n int mean= (diff + (size>>1)) >> (level+3);\n assert(mean >-300 && mean<300);\n mean= av_clip(mean, intra?0:-256, 255);\n best_vector_score= score;\n best_vector[stage]= i;\n best_vector_sum= sum;\n best_vector_mean= mean;\n }\n }\n assert(best_vector_mean != -999);\n vector= codebook + stage*size*16 + best_vector[stage]*size;\n for(j=0; j<size; j++){\n block[stage+1][j] = block[stage][j] - vector[j];\n }\n block_sum[stage+1]= block_sum[stage] - best_vector_sum;\n best_vector_score +=\n lambda*(+ 1 + 4*count\n + multistage_vlc[1+count][1]\n + mean_vlc[best_vector_mean][1]);\n if(best_vector_score < best_score){\n best_score= best_vector_score;\n best_count= count;\n best_mean= best_vector_mean;\n }\n }\n }\n split=0;\n if(best_score > threshold && level){\n int score=0;\n int offset= (level&1) ? stride*h/2 : w/2;\n PutBitContext backup[6];\n for(i=level-1; i>=0; i--){\n backup[i]= s->reorder_pb[i];\n }\n score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra);\n score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra);\n score += lambda;\n if(score < best_score){\n best_score= score;\n split=1;\n }else{\n for(i=level-1; i>=0; i--){\n s->reorder_pb[i]= backup[i];\n }\n }\n }\n if (level > 0)\n put_bits(&s->reorder_pb[level], 1, split);\n if(!split){\n assert((best_mean >= 0 && best_mean<256) || !intra);\n assert(best_mean >= -256 && best_mean<256);\n assert(best_count >=0 && best_count<7);\n assert(level<4 || best_count==0);\n put_bits(&s->reorder_pb[level],\n multistage_vlc[1 + best_count][1],\n multistage_vlc[1 + best_count][0]);\n put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1],\n mean_vlc[best_mean][0]);\n for (i = 0; i < best_count; i++){\n assert(best_vector[i]>=0 && best_vector[i]<16);\n put_bits(&s->reorder_pb[level], 4, best_vector[i]);\n }\n for(y=0; y<h; y++){\n for(x=0; x<w; x++){\n decoded[x + y*stride]= src[x + y*stride] - block[best_count][x + w*y] + best_mean;\n }\n }\n }\n return best_score;\n}']
|
1,347
| 0
|
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_ctx.c/#L276
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,\n const BIGNUM *Xp, const BIGNUM *Xp1,\n const BIGNUM *Xp2, const BIGNUM *e, BN_CTX *ctx,\n BN_GENCB *cb)\n{\n int ret = 0;\n BIGNUM *t, *p1p2, *pm1;\n if (!BN_is_odd(e))\n return 0;\n BN_CTX_start(ctx);\n if (p1 == NULL)\n p1 = BN_CTX_get(ctx);\n if (p2 == NULL)\n p2 = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n p1p2 = BN_CTX_get(ctx);\n pm1 = BN_CTX_get(ctx);\n if (pm1 == NULL)\n goto err;\n if (!bn_x931_derive_pi(p1, Xp1, ctx, cb))\n goto err;\n if (!bn_x931_derive_pi(p2, Xp2, ctx, cb))\n goto err;\n if (!BN_mul(p1p2, p1, p2, ctx))\n goto err;\n if (!BN_mod_inverse(p, p2, p1, ctx))\n goto err;\n if (!BN_mul(p, p, p2, ctx))\n goto err;\n if (!BN_mod_inverse(t, p1, p2, ctx))\n goto err;\n if (!BN_mul(t, t, p1, ctx))\n goto err;\n if (!BN_sub(p, p, t))\n goto err;\n if (p->neg && !BN_add(p, p, p1p2))\n goto err;\n if (!BN_mod_sub(p, p, Xp, p1p2, ctx))\n goto err;\n if (!BN_add(p, p, Xp))\n goto err;\n for (;;) {\n int i = 1;\n BN_GENCB_call(cb, 0, i++);\n if (!BN_copy(pm1, p))\n goto err;\n if (!BN_sub_word(pm1, 1))\n goto err;\n if (!BN_gcd(t, pm1, e, ctx))\n goto err;\n if (BN_is_one(t)) {\n int r = BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb);\n if (r < 0)\n goto err;\n if (r)\n break;\n }\n if (!BN_add(p, p, p1p2))\n goto err;\n }\n BN_GENCB_call(cb, 3, 0);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx,\n BN_GENCB *cb)\n{\n int i = 0, is_prime;\n if (!BN_copy(pi, Xpi))\n return 0;\n if (!BN_is_odd(pi) && !BN_add_word(pi, 1))\n return 0;\n for (;;) {\n i++;\n BN_GENCB_call(cb, 0, i);\n is_prime = BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb);\n if (is_prime < 0)\n return 0;\n if (is_prime)\n break;\n if (!BN_add_word(pi, 2))\n return 0;\n }\n BN_GENCB_call(cb, 2, i);\n return 1;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,348
| 0
|
https://github.com/libav/libav/blob/ab492ca2ab105aeb24d955f3f03756bdb3139ee1/libavcodec/wmaprodec.c/#L940
|
static int decode_scale_factors(WMAProDecodeCtx* s)
{
int i;
for (i = 0; i < s->channels_for_cur_subframe; i++) {
int c = s->channel_indexes_for_cur_subframe[i];
int* sf;
int* sf_end;
s->channel[c].scale_factors = s->channel[c].saved_scale_factors[!s->channel[c].scale_factor_idx];
sf_end = s->channel[c].scale_factors + s->num_bands;
if (s->channel[c].reuse_sf) {
const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx];
int b;
for (b = 0; b < s->num_bands; b++)
s->channel[c].scale_factors[b] =
s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++];
}
if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) {
if (!s->channel[c].reuse_sf) {
int val;
s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;
val = 45 / s->channel[c].scale_factor_step;
for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {
val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH) - 60;
*sf = val;
}
} else {
int i;
for (i = 0; i < s->num_bands; i++) {
int idx;
int skip;
int val;
int sign;
idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH);
if (!idx) {
uint32_t code = get_bits(&s->gb, 14);
val = code >> 6;
sign = (code & 1) - 1;
skip = (code & 0x3f) >> 1;
} else if (idx == 1) {
break;
} else {
skip = scale_rl_run[idx];
val = scale_rl_level[idx];
sign = get_bits1(&s->gb)-1;
}
i += skip;
if (i >= s->num_bands) {
av_log(s->avctx, AV_LOG_ERROR,
"invalid scale factor coding\n");
return AVERROR_INVALIDDATA;
}
s->channel[c].scale_factors[i] += (val ^ sign) - sign;
}
}
s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx;
s->channel[c].table_idx = s->table_idx;
s->channel[c].reuse_sf = 1;
}
s->channel[c].max_scale_factor = s->channel[c].scale_factors[0];
for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) {
s->channel[c].max_scale_factor =
FFMAX(s->channel[c].max_scale_factor, *sf);
}
}
return 0;
}
|
['static int decode_scale_factors(WMAProDecodeCtx* s)\n{\n int i;\n for (i = 0; i < s->channels_for_cur_subframe; i++) {\n int c = s->channel_indexes_for_cur_subframe[i];\n int* sf;\n int* sf_end;\n s->channel[c].scale_factors = s->channel[c].saved_scale_factors[!s->channel[c].scale_factor_idx];\n sf_end = s->channel[c].scale_factors + s->num_bands;\n if (s->channel[c].reuse_sf) {\n const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx];\n int b;\n for (b = 0; b < s->num_bands; b++)\n s->channel[c].scale_factors[b] =\n s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++];\n }\n if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) {\n if (!s->channel[c].reuse_sf) {\n int val;\n s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;\n val = 45 / s->channel[c].scale_factor_step;\n for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {\n val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH) - 60;\n *sf = val;\n }\n } else {\n int i;\n for (i = 0; i < s->num_bands; i++) {\n int idx;\n int skip;\n int val;\n int sign;\n idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH);\n if (!idx) {\n uint32_t code = get_bits(&s->gb, 14);\n val = code >> 6;\n sign = (code & 1) - 1;\n skip = (code & 0x3f) >> 1;\n } else if (idx == 1) {\n break;\n } else {\n skip = scale_rl_run[idx];\n val = scale_rl_level[idx];\n sign = get_bits1(&s->gb)-1;\n }\n i += skip;\n if (i >= s->num_bands) {\n av_log(s->avctx, AV_LOG_ERROR,\n "invalid scale factor coding\\n");\n return AVERROR_INVALIDDATA;\n }\n s->channel[c].scale_factors[i] += (val ^ sign) - sign;\n }\n }\n s->channel[c].scale_factor_idx = !s->channel[c].scale_factor_idx;\n s->channel[c].table_idx = s->table_idx;\n s->channel[c].reuse_sf = 1;\n }\n s->channel[c].max_scale_factor = s->channel[c].scale_factors[0];\n for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) {\n s->channel[c].max_scale_factor =\n FFMAX(s->channel[c].max_scale_factor, *sf);\n }\n }\n return 0;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index>>3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
1,349
| 0
|
https://github.com/libav/libav/blob/cc20fbcd39c7b60602edae4f7deb092ecfd3c975/libavcodec/vp9dsp.c/#L1611
|
static av_always_inline void loop_filter(uint8_t *dst, ptrdiff_t stride,
int E, int I, int H,
ptrdiff_t stridea, ptrdiff_t strideb,
int wd)
{
int i;
for (i = 0; i < 8; i++, dst += stridea) {
int p7, p6, p5, p4;
int p3 = dst[strideb * -4], p2 = dst[strideb * -3];
int p1 = dst[strideb * -2], p0 = dst[strideb * -1];
int q0 = dst[strideb * +0], q1 = dst[strideb * +1];
int q2 = dst[strideb * +2], q3 = dst[strideb * +3];
int q4, q5, q6, q7;
int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I &&
FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I &&
FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I &&
FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E;
int flat8out, flat8in;
if (!fm)
continue;
if (wd >= 16) {
p7 = dst[strideb * -8];
p6 = dst[strideb * -7];
p5 = dst[strideb * -6];
p4 = dst[strideb * -5];
q4 = dst[strideb * +4];
q5 = dst[strideb * +5];
q6 = dst[strideb * +6];
q7 = dst[strideb * +7];
flat8out = FFABS(p7 - p0) <= 1 && FFABS(p6 - p0) <= 1 &&
FFABS(p5 - p0) <= 1 && FFABS(p4 - p0) <= 1 &&
FFABS(q4 - q0) <= 1 && FFABS(q5 - q0) <= 1 &&
FFABS(q6 - q0) <= 1 && FFABS(q7 - q0) <= 1;
}
if (wd >= 8)
flat8in = FFABS(p3 - p0) <= 1 && FFABS(p2 - p0) <= 1 &&
FFABS(p1 - p0) <= 1 && FFABS(q1 - q0) <= 1 &&
FFABS(q2 - q0) <= 1 && FFABS(q3 - q0) <= 1;
if (wd >= 16 && flat8out && flat8in) {
dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 +
p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;
dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 +
p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;
dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 +
p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;
dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 +
p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;
dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 +
p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;
dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 +
p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;
dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 +
q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;
dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 +
q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4;
dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 +
q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4;
dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 +
q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4;
dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 +
q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4;
dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 +
q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 +
q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 +
q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
} else if (wd >= 8 && flat8in) {
dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;
dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;
dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;
dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;
dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;
dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;
} else {
int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H;
if (hev) {
int f = av_clip_int8(3 * (q0 - p0) + av_clip_int8(p1 - q1));
int f1 = FFMIN(f + 4, 127) >> 3;
int f2 = FFMIN(f + 3, 127) >> 3;
dst[strideb * -1] = av_clip_uint8(p0 + f2);
dst[strideb * +0] = av_clip_uint8(q0 - f1);
} else {
int f = av_clip_int8(3 * (q0 - p0));
int f1 = FFMIN(f + 4, 127) >> 3;
int f2 = FFMIN(f + 3, 127) >> 3;
dst[strideb * -1] = av_clip_uint8(p0 + f2);
dst[strideb * +0] = av_clip_uint8(q0 - f1);
f = (f1 + 1) >> 1;
dst[strideb * -2] = av_clip_uint8(p1 + f);
dst[strideb * +1] = av_clip_uint8(q1 - f);
}
}
}
}
|
['static av_always_inline void loop_filter(uint8_t *dst, ptrdiff_t stride,\n int E, int I, int H,\n ptrdiff_t stridea, ptrdiff_t strideb,\n int wd)\n{\n int i;\n for (i = 0; i < 8; i++, dst += stridea) {\n int p7, p6, p5, p4;\n int p3 = dst[strideb * -4], p2 = dst[strideb * -3];\n int p1 = dst[strideb * -2], p0 = dst[strideb * -1];\n int q0 = dst[strideb * +0], q1 = dst[strideb * +1];\n int q2 = dst[strideb * +2], q3 = dst[strideb * +3];\n int q4, q5, q6, q7;\n int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I &&\n FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I &&\n FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I &&\n FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E;\n int flat8out, flat8in;\n if (!fm)\n continue;\n if (wd >= 16) {\n p7 = dst[strideb * -8];\n p6 = dst[strideb * -7];\n p5 = dst[strideb * -6];\n p4 = dst[strideb * -5];\n q4 = dst[strideb * +4];\n q5 = dst[strideb * +5];\n q6 = dst[strideb * +6];\n q7 = dst[strideb * +7];\n flat8out = FFABS(p7 - p0) <= 1 && FFABS(p6 - p0) <= 1 &&\n FFABS(p5 - p0) <= 1 && FFABS(p4 - p0) <= 1 &&\n FFABS(q4 - q0) <= 1 && FFABS(q5 - q0) <= 1 &&\n FFABS(q6 - q0) <= 1 && FFABS(q7 - q0) <= 1;\n }\n if (wd >= 8)\n flat8in = FFABS(p3 - p0) <= 1 && FFABS(p2 - p0) <= 1 &&\n FFABS(p1 - p0) <= 1 && FFABS(q1 - q0) <= 1 &&\n FFABS(q2 - q0) <= 1 && FFABS(q3 - q0) <= 1;\n if (wd >= 16 && flat8out && flat8in) {\n dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 +\n p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;\n dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 +\n p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;\n dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 +\n p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;\n dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 +\n p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;\n dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 +\n p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;\n dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 +\n p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;\n dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 +\n q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;\n dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 +\n q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4;\n dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 +\n q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4;\n dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 +\n q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 +\n q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 +\n q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 +\n q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;\n dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 +\n q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;\n } else if (wd >= 8 && flat8in) {\n dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;\n dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;\n dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;\n dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;\n dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;\n dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;\n } else {\n int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H;\n if (hev) {\n int f = av_clip_int8(3 * (q0 - p0) + av_clip_int8(p1 - q1));\n int f1 = FFMIN(f + 4, 127) >> 3;\n int f2 = FFMIN(f + 3, 127) >> 3;\n dst[strideb * -1] = av_clip_uint8(p0 + f2);\n dst[strideb * +0] = av_clip_uint8(q0 - f1);\n } else {\n int f = av_clip_int8(3 * (q0 - p0));\n int f1 = FFMIN(f + 4, 127) >> 3;\n int f2 = FFMIN(f + 3, 127) >> 3;\n dst[strideb * -1] = av_clip_uint8(p0 + f2);\n dst[strideb * +0] = av_clip_uint8(q0 - f1);\n f = (f1 + 1) >> 1;\n dst[strideb * -2] = av_clip_uint8(p1 + f);\n dst[strideb * +1] = av_clip_uint8(q1 - f);\n }\n }\n }\n}']
|
1,350
| 0
|
https://github.com/libav/libav/blob/ab492ca2ab105aeb24d955f3f03756bdb3139ee1/libavcodec/golomb.h/#L313
|
static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){
unsigned int buf;
int log;
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf=GET_CACHE(re, gb);
log= av_log2(buf);
if(log - k >= 32-MIN_CACHE_BITS+(MIN_CACHE_BITS==32) && 32-log < limit){
buf >>= log - k;
buf += (30-log)<<k;
LAST_SKIP_BITS(re, gb, 32 + k - log);
CLOSE_READER(re, gb);
return buf;
}else{
int i;
for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
LAST_SKIP_BITS(re, gb, 1);
UPDATE_CACHE(re, gb);
}
SKIP_BITS(re, gb, 1);
if(i < limit - 1){
if(k){
buf = SHOW_UBITS(re, gb, k);
LAST_SKIP_BITS(re, gb, k);
}else{
buf=0;
}
CLOSE_READER(re, gb);
return buf + (i<<k);
}else if(i == limit - 1){
buf = SHOW_UBITS(re, gb, esc_len);
LAST_SKIP_BITS(re, gb, esc_len);
CLOSE_READER(re, gb);
return buf + 1;
}else
return -1;
}
}
|
['static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int esc_len){\n unsigned int buf;\n int log;\n OPEN_READER(re, gb);\n UPDATE_CACHE(re, gb);\n buf=GET_CACHE(re, gb);\n log= av_log2(buf);\n if(log - k >= 32-MIN_CACHE_BITS+(MIN_CACHE_BITS==32) && 32-log < limit){\n buf >>= log - k;\n buf += (30-log)<<k;\n LAST_SKIP_BITS(re, gb, 32 + k - log);\n CLOSE_READER(re, gb);\n return buf;\n }else{\n int i;\n for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {\n LAST_SKIP_BITS(re, gb, 1);\n UPDATE_CACHE(re, gb);\n }\n SKIP_BITS(re, gb, 1);\n if(i < limit - 1){\n if(k){\n buf = SHOW_UBITS(re, gb, k);\n LAST_SKIP_BITS(re, gb, k);\n }else{\n buf=0;\n }\n CLOSE_READER(re, gb);\n return buf + (i<<k);\n }else if(i == limit - 1){\n buf = SHOW_UBITS(re, gb, esc_len);\n LAST_SKIP_BITS(re, gb, esc_len);\n CLOSE_READER(re, gb);\n return buf + 1;\n }else\n return -1;\n }\n}']
|
1,351
| 0
|
https://github.com/libav/libav/blob/e6e7bfc11e93fe3499c576fa9466cb2e913b5965/libavcodec/vb.c/#L66
|
static void vb_decode_palette(VBDecContext *c, int data_size)
{
int start, size, i;
start = bytestream2_get_byte(&c->stream);
size = (bytestream2_get_byte(&c->stream) - 1) & 0xFF;
if(start + size > 255){
av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n");
return;
}
if(size*3+2 > data_size){
av_log(c->avctx, AV_LOG_ERROR, "Palette data runs beyond chunk size\n");
return;
}
for(i = start; i <= start + size; i++)
c->pal[i] = bytestream2_get_be24(&c->stream);
}
|
['static void vb_decode_palette(VBDecContext *c, int data_size)\n{\n int start, size, i;\n start = bytestream2_get_byte(&c->stream);\n size = (bytestream2_get_byte(&c->stream) - 1) & 0xFF;\n if(start + size > 255){\n av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\\n");\n return;\n }\n if(size*3+2 > data_size){\n av_log(c->avctx, AV_LOG_ERROR, "Palette data runs beyond chunk size\\n");\n return;\n }\n for(i = start; i <= start + size; i++)\n c->pal[i] = bytestream2_get_be24(&c->stream);\n}', 'DEF (byte, 1, AV_RB8 , AV_WB8 )']
|
1,352
| 0
|
https://github.com/openssl/openssl/blob/e7d961e994620dd5dee6d80794a07fb9de1bab66/ssl/packet.c/#L48
|
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
if (!ossl_assert(pkt->subs != NULL && len != 0))
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {
size_t newlen;
size_t reflen;
reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
if (reflen > SIZE_MAX / 2) {
newlen = SIZE_MAX;
} else {
newlen = reflen * 2;
if (newlen < DEFAULT_BUF_SIZE)
newlen = DEFAULT_BUF_SIZE;
}
if (BUF_MEM_grow(pkt->buf, newlen) == 0)
return 0;
}
if (allocbytes != NULL)
*allocbytes = WPACKET_get_curr(pkt);
return 1;
}
|
['int tls_construct_server_certificate(SSL *s, WPACKET *pkt)\n{\n CERT_PKEY *cpk = s->s3->tmp.cert;\n if (cpk == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_SERVER_CERTIFICATE, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (SSL_IS_TLS13(s) && !WPACKET_put_bytes_u8(pkt, 0)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n SSL_F_TLS_CONSTRUCT_SERVER_CERTIFICATE, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!ssl3_output_cert_chain(s, pkt, cpk)) {\n return 0;\n }\n return 1;\n}', 'unsigned long ssl3_output_cert_chain(SSL *s, WPACKET *pkt, CERT_PKEY *cpk)\n{\n if (!WPACKET_start_sub_packet_u24(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_OUTPUT_CERT_CHAIN,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!ssl_add_cert_chain(s, pkt, cpk))\n return 0;\n if (!WPACKET_close(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_SSL3_OUTPUT_CERT_CHAIN,\n ERR_R_INTERNAL_ERROR);\n return 0;\n }\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
|
1,353
| 0
|
https://github.com/openssl/openssl/blob/3b5873567d24bf0d8bc2a175848e716e295d6c94/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n BIGNUM *i, *j, *k, *l, *m;\n BN_CTX *ctx;\n int ret = 1, ex_primes = 0, idx;\n RSA_PRIME_INFO *pinfo;\n if (key->p == NULL || key->q == NULL || key->n == NULL\n || key->e == NULL || key->d == NULL) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_VALUE_MISSING);\n return 0;\n }\n if (key->version == RSA_ASN1_VERSION_MULTI\n && (ex_primes = sk_RSA_PRIME_INFO_num(key->prime_infos)) <= 0) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_INVALID_MULTI_PRIME_KEY);\n return 0;\n }\n i = BN_new();\n j = BN_new();\n k = BN_new();\n l = BN_new();\n m = BN_new();\n ctx = BN_CTX_new();\n if (i == NULL || j == NULL || k == NULL || l == NULL\n || m == NULL || ctx == NULL) {\n ret = -1;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (BN_is_one(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (!BN_is_odd(key->e)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_BAD_E_VALUE);\n }\n if (BN_is_prime_ex(key->p, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_P_NOT_PRIME);\n }\n if (BN_is_prime_ex(key->q, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_Q_NOT_PRIME);\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (BN_is_prime_ex(pinfo->r, BN_prime_checks, NULL, cb) != 1) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_R_NOT_PRIME);\n }\n }\n if (!BN_mul(i, key->p, key->q, ctx)) {\n ret = -1;\n goto err;\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_mul(i, i, pinfo->r, ctx)) {\n ret = -1;\n goto err;\n }\n }\n if (BN_cmp(i, key->n) != 0) {\n ret = 0;\n if (ex_primes)\n RSAerr(RSA_F_RSA_CHECK_KEY_EX,\n RSA_R_N_DOES_NOT_EQUAL_PRODUCT_OF_PRIMES);\n else\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n }\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_sub(j, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, i, j, ctx)) {\n ret = -1;\n goto err;\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_sub(k, pinfo->r, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mul(l, l, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_gcd(m, m, k, ctx)) {\n ret = -1;\n goto err;\n }\n }\n if (!BN_div(k, NULL, l, m, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_mod_mul(i, key->d, key->e, k, ctx)) {\n ret = -1;\n goto err;\n }\n if (!BN_is_one(i)) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n }\n if (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL) {\n if (!BN_sub(i, key->p, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmp1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMP1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_sub(i, key->q, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, key->dmq1) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, key->q, key->p, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, key->iqmp) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_IQMP_NOT_INVERSE_OF_Q);\n }\n }\n for (idx = 0; idx < ex_primes; idx++) {\n pinfo = sk_RSA_PRIME_INFO_value(key->prime_infos, idx);\n if (!BN_sub(i, pinfo->r, BN_value_one())) {\n ret = -1;\n goto err;\n }\n if (!BN_mod(j, key->d, i, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(j, pinfo->d) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_EXPONENT_NOT_CONGRUENT_TO_D);\n }\n if (!BN_mod_inverse(i, pinfo->pp, pinfo->r, ctx)) {\n ret = -1;\n goto err;\n }\n if (BN_cmp(i, pinfo->t) != 0) {\n ret = 0;\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_MP_COEFFICIENT_NOT_INVERSE_OF_R);\n }\n }\n err:\n BN_free(i);\n BN_free(j);\n BN_free(k);\n BN_free(l);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n bn_correct_top(rr);\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', '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_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,354
| 0
|
https://github.com/openssl/openssl/blob/f4675379275c304dbfa593cc573b4e4c4eb54bd4/crypto/bn/bn_lib.c/#L233
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,\n const ECDSA_SIG *sig, EC_KEY *eckey)\n{\n int ret = -1, i;\n BN_CTX *ctx;\n const BIGNUM *order;\n BIGNUM *u1, *u2, *m, *X;\n EC_POINT *point = NULL;\n const EC_GROUP *group;\n const EC_POINT *pub_key;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL ||\n (pub_key = EC_KEY_get0_public_key(eckey)) == NULL || sig == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_MISSING_PARAMETERS);\n return -1;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return -1;\n }\n ctx = BN_CTX_new();\n if (ctx == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);\n return -1;\n }\n BN_CTX_start(ctx);\n u1 = BN_CTX_get(ctx);\n u2 = BN_CTX_get(ctx);\n m = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n if (X == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||\n BN_ucmp(sig->r, order) >= 0 || BN_is_zero(sig->s) ||\n BN_is_negative(sig->s) || BN_ucmp(sig->s, order) >= 0) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, EC_R_BAD_SIGNATURE);\n ret = 0;\n goto err;\n }\n if (EC_GROUP_do_inverse_ord(group, u2, sig->s, ctx) == 0) {\n if (!BN_mod_inverse(u2, sig->s, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n }\n i = BN_num_bits(order);\n if (8 * dgst_len > i)\n dgst_len = (i + 7) / 8;\n if (!BN_bin2bn(dgst, dgst_len, m)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((8 * dgst_len > i) && !BN_rshift(m, m, 8 - (i & 0x7))) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(u1, m, u2, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_mod_mul(u2, sig->r, u2, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n if ((point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!EC_POINT_mul(group, point, u1, pub_key, u2, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==\n NID_X9_62_prime_field) {\n if (!EC_POINT_get_affine_coordinates_GFp(group, point, X, NULL, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n }\n#ifndef OPENSSL_NO_EC2M\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, point, X, NULL, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_EC_LIB);\n goto err;\n }\n }\n#endif\n if (!BN_nnmod(u1, X, order, ctx)) {\n ECerr(EC_F_OSSL_ECDSA_VERIFY_SIG, ERR_R_BN_LIB);\n goto err;\n }\n ret = (BN_ucmp(u1, sig->r) == 0);\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n EC_POINT_free(point);\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n if (group->meth->mul == 0)\n return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n return group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n const EC_POINT *generator = NULL;\n EC_POINT *tmp = NULL;\n size_t totalnum;\n size_t blocksize = 0, numblocks = 0;\n size_t pre_points_per_block = 0;\n size_t i, j;\n int k;\n int r_is_inverted = 0;\n int r_is_at_infinity = 1;\n size_t *wsize = NULL;\n signed char **wNAF = NULL;\n size_t *wNAF_len = NULL;\n size_t max_len = 0;\n size_t num_val;\n EC_POINT **val = NULL;\n EC_POINT **v;\n EC_POINT ***val_sub = NULL;\n const EC_PRE_COMP *pre_comp = NULL;\n int num_scalar = 0;\n int ret = 0;\n if ((scalar != NULL) && (num == 0)) {\n return ec_mul_consttime(group, r, scalar, NULL, ctx);\n }\n if ((scalar == NULL) && (num == 1)) {\n return ec_mul_consttime(group, r, scalars[0], points[0], ctx);\n }\n if (group->meth != r->meth) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if ((scalar == NULL) && (num == 0)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n for (i = 0; i < num; i++) {\n if (group->meth != points[i]->meth) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n }\n if (scalar != NULL) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.ec;\n if (pre_comp && pre_comp->numblocks\n && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n 0)) {\n blocksize = pre_comp->blocksize;\n numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n if (numblocks > pre_comp->numblocks)\n numblocks = pre_comp->numblocks;\n pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n pre_comp = NULL;\n numblocks = 1;\n num_scalar = 1;\n }\n }\n totalnum = num + numblocks;\n wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));\n wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));\n wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));\n val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));\n if (wNAF != NULL)\n wNAF[0] = NULL;\n if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n num_val = 0;\n for (i = 0; i < num + num_scalar; i++) {\n size_t bits;\n bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n wsize[i] = EC_window_bits_for_scalar_size(bits);\n num_val += (size_t)1 << (wsize[i] - 1);\n wNAF[i + 1] = NULL;\n wNAF[i] =\n bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n &wNAF_len[i]);\n if (wNAF[i] == NULL)\n goto err;\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n }\n if (numblocks) {\n if (pre_comp == NULL) {\n if (num_scalar != 1) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n signed char *tmp_wNAF = NULL;\n size_t tmp_len = 0;\n if (num_scalar != 0) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n wsize[num] = pre_comp->w;\n tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n if (!tmp_wNAF)\n goto err;\n if (tmp_len <= max_len) {\n numblocks = 1;\n totalnum = num + 1;\n wNAF[num] = tmp_wNAF;\n wNAF[num + 1] = NULL;\n wNAF_len[num] = tmp_len;\n val_sub[num] = pre_comp->points;\n } else {\n signed char *pp;\n EC_POINT **tmp_points;\n if (tmp_len < numblocks * blocksize) {\n numblocks = (tmp_len + blocksize - 1) / blocksize;\n if (numblocks > pre_comp->numblocks) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n totalnum = num + numblocks;\n }\n pp = tmp_wNAF;\n tmp_points = pre_comp->points;\n for (i = num; i < totalnum; i++) {\n if (i < totalnum - 1) {\n wNAF_len[i] = blocksize;\n if (tmp_len < blocksize) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n tmp_len -= blocksize;\n } else\n wNAF_len[i] = tmp_len;\n wNAF[i + 1] = NULL;\n wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n if (wNAF[i] == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n memcpy(wNAF[i], pp, wNAF_len[i]);\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n if (*tmp_points == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n val_sub[i] = tmp_points;\n tmp_points += pre_points_per_block;\n pp += blocksize;\n }\n OPENSSL_free(tmp_wNAF);\n }\n }\n }\n val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));\n if (val == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n val[num_val] = NULL;\n v = val;\n for (i = 0; i < num + num_scalar; i++) {\n val_sub[i] = v;\n for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n *v = EC_POINT_new(group);\n if (*v == NULL)\n goto err;\n v++;\n }\n }\n if (!(v == val + num_val)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if ((tmp = EC_POINT_new(group)) == NULL)\n goto err;\n for (i = 0; i < num + num_scalar; i++) {\n if (i < num) {\n if (!EC_POINT_copy(val_sub[i][0], points[i]))\n goto err;\n } else {\n if (!EC_POINT_copy(val_sub[i][0], generator))\n goto err;\n }\n if (wsize[i] > 1) {\n if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n goto err;\n for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n if (!EC_POINT_add\n (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n goto err;\n }\n }\n }\n if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n goto err;\n r_is_at_infinity = 1;\n for (k = max_len - 1; k >= 0; k--) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n }\n for (i = 0; i < totalnum; i++) {\n if (wNAF_len[i] > (size_t)k) {\n int digit = wNAF[i][k];\n int is_neg;\n if (digit) {\n is_neg = digit < 0;\n if (is_neg)\n digit = -digit;\n if (is_neg != r_is_inverted) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n r_is_inverted = !r_is_inverted;\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n goto err;\n r_is_at_infinity = 0;\n } else {\n if (!EC_POINT_add\n (group, r, r, val_sub[i][digit >> 1], ctx))\n goto err;\n }\n }\n }\n }\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (r_is_inverted)\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_free(new_ctx);\n EC_POINT_free(tmp);\n OPENSSL_free(wsize);\n OPENSSL_free(wNAF_len);\n if (wNAF != NULL) {\n signed char **w;\n for (w = wNAF; *w != NULL; w++)\n OPENSSL_free(*w);\n OPENSSL_free(wNAF);\n }\n if (val != NULL) {\n for (v = val; *v != NULL; v++)\n EC_POINT_clear_free(*v);\n OPENSSL_free(val);\n }\n OPENSSL_free(val_sub);\n return ret;\n}', 'static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int i, order_bits, group_top, kbit, pbit, Z_is_one;\n EC_POINT *s = NULL;\n BIGNUM *k = NULL;\n BIGNUM *lambda = NULL;\n BN_CTX *new_ctx = NULL;\n int ret = 0;\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)\n goto err;\n if ((group->order == NULL) || (group->field == NULL))\n goto err;\n order_bits = BN_num_bits(group->order);\n s = EC_POINT_new(group);\n if (s == NULL)\n goto err;\n if (point == NULL) {\n if (group->generator == NULL)\n goto err;\n if (!EC_POINT_copy(s, group->generator))\n goto err;\n } else {\n if (!EC_POINT_copy(s, point))\n goto err;\n }\n EC_POINT_BN_set_flags(s, BN_FLG_CONSTTIME);\n BN_CTX_start(ctx);\n lambda = BN_CTX_get(ctx);\n k = BN_CTX_get(ctx);\n if (k == NULL)\n goto err;\n group_top = bn_get_top(group->order);\n if ((bn_wexpand(k, group_top + 1) == NULL)\n || (bn_wexpand(lambda, group_top + 1) == NULL))\n goto err;\n if (!BN_copy(k, scalar))\n goto err;\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if ((BN_num_bits(k) > order_bits) || (BN_is_negative(k))) {\n if (!BN_nnmod(k, k, group->order, ctx))\n goto err;\n }\n if (!BN_add(lambda, k, group->order))\n goto err;\n BN_set_flags(lambda, BN_FLG_CONSTTIME);\n if (!BN_add(k, lambda, group->order))\n goto err;\n kbit = BN_is_bit_set(lambda, order_bits);\n BN_consttime_swap(kbit, k, lambda, group_top + 1);\n group_top = bn_get_top(group->field);\n if ((bn_wexpand(s->X, group_top) == NULL)\n || (bn_wexpand(s->Y, group_top) == NULL)\n || (bn_wexpand(s->Z, group_top) == NULL)\n || (bn_wexpand(r->X, group_top) == NULL)\n || (bn_wexpand(r->Y, group_top) == NULL)\n || (bn_wexpand(r->Z, group_top) == NULL))\n goto err;\n if (!EC_POINT_copy(r, s))\n goto err;\n EC_POINT_BN_set_flags(r, BN_FLG_CONSTTIME);\n if (!EC_POINT_dbl(group, s, s, ctx))\n goto err;\n pbit = 0;\n#define EC_POINT_CSWAP(c, a, b, w, t) do { \\\n BN_consttime_swap(c, (a)->X, (b)->X, w); \\\n BN_consttime_swap(c, (a)->Y, (b)->Y, w); \\\n BN_consttime_swap(c, (a)->Z, (b)->Z, w); \\\n t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \\\n (a)->Z_is_one ^= (t); \\\n (b)->Z_is_one ^= (t); \\\n} while(0)\n for (i = order_bits - 1; i >= 0; i--) {\n kbit = BN_is_bit_set(k, i) ^ pbit;\n EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);\n if (!EC_POINT_add(group, s, r, s, ctx))\n goto err;\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n pbit ^= kbit;\n }\n EC_POINT_CSWAP(pbit, r, s, group_top, Z_is_one);\n#undef EC_POINT_CSWAP\n ret = 1;\n err:\n EC_POINT_free(s);\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,355
| 0
|
https://github.com/libav/libav/blob/0e5f33f2426dae28725b14468b61cbad052da240/libavcodec/h264.h/#L898
|
static void fill_decode_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
int topleft_xy, top_xy, topright_xy, left_xy[2];
int topleft_type, top_type, topright_type, left_type[2];
const uint8_t * left_block= h->left_block;
int i;
topleft_xy = h->topleft_mb_xy ;
top_xy = h->top_mb_xy ;
topright_xy = h->topright_mb_xy;
left_xy[0] = h->left_mb_xy[0] ;
left_xy[1] = h->left_mb_xy[1] ;
topleft_type = h->topleft_type ;
top_type = h->top_type ;
topright_type= h->topright_type ;
left_type[0] = h->left_type[0] ;
left_type[1] = h->left_type[1] ;
if(!IS_SKIP(mb_type)){
if(IS_INTRA(mb_type)){
int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
h->topleft_samples_available=
h->top_samples_available=
h->left_samples_available= 0xFFFF;
h->topright_samples_available= 0xEEEA;
if(!(top_type & type_mask)){
h->topleft_samples_available= 0xB3FF;
h->top_samples_available= 0x33FF;
h->topright_samples_available= 0x26EA;
}
if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){
if(IS_INTERLACED(mb_type)){
if(!(left_type[0] & type_mask)){
h->topleft_samples_available&= 0xDFFF;
h->left_samples_available&= 0x5FFF;
}
if(!(left_type[1] & type_mask)){
h->topleft_samples_available&= 0xFF5F;
h->left_samples_available&= 0xFF5F;
}
}else{
int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num
? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0;
assert(left_xy[0] == left_xy[1]);
if(!((left_typei & type_mask) && (left_type[0] & type_mask))){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
}else{
if(!(left_type[0] & type_mask)){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
if(!(topleft_type & type_mask))
h->topleft_samples_available&= 0x7FFF;
if(!(topright_type & type_mask))
h->topright_samples_available&= 0xFBFF;
if(IS_INTRA4x4(mb_type)){
if(IS_INTRA4x4(top_type)){
h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4];
h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];
h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];
h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];
}else{
int pred;
if(!(top_type & type_mask))
pred= -1;
else{
pred= 2;
}
h->intra4x4_pred_mode_cache[4+8*0]=
h->intra4x4_pred_mode_cache[5+8*0]=
h->intra4x4_pred_mode_cache[6+8*0]=
h->intra4x4_pred_mode_cache[7+8*0]= pred;
}
for(i=0; i<2; i++){
if(IS_INTRA4x4(left_type[i])){
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];
}else{
int pred;
if(!(left_type[i] & type_mask))
pred= -1;
else{
pred= 2;
}
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;
}
}
}
}
if(top_type){
AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]);
h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8];
h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8];
h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8];
h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8];
}else {
h->non_zero_count_cache[1+8*0]=
h->non_zero_count_cache[2+8*0]=
h->non_zero_count_cache[1+8*3]=
h->non_zero_count_cache[2+8*3]=
AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040);
}
for (i=0; i<2; i++) {
if(left_type[i]){
h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]];
h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]];
h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]];
h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]];
}else{
h->non_zero_count_cache[3+8*1 + 2*8*i]=
h->non_zero_count_cache[3+8*2 + 2*8*i]=
h->non_zero_count_cache[0+8*1 + 8*i]=
h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
}
}
if( CABAC ) {
if(top_type) {
h->top_cbp = h->cbp_table[top_xy];
} else if(IS_INTRA(mb_type)) {
h->top_cbp = 0x1CF;
} else {
h->top_cbp = 0x00F;
}
if (left_type[0]) {
h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0;
} else if(IS_INTRA(mb_type)) {
h->left_cbp = 0x1CF;
} else {
h->left_cbp = 0x00F;
}
if (left_type[0]) {
h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1;
}
if (left_type[1]) {
h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3;
}
}
}
#if 1
if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
int list;
for(list=0; list<h->list_count; list++){
if(!USES_LIST(mb_type, list)){
continue;
}
assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
h->mv_cache_clean[list]= 0;
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;
AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);
h->ref_cache[list][scan8[0] + 0 - 1*8]=
h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0];
h->ref_cache[list][scan8[0] + 2 - 1*8]=
h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1];
}else{
AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);
AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);
}
for(i=0; i<2; i++){
int cache_idx = scan8[0] - 1 + i*2*8;
if(USES_LIST(left_type[i], list)){
const int b_xy= h->mb2b_xy[left_xy[i]] + 3;
const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1;
AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]);
AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]);
h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)];
h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)];
}else{
AV_ZERO32(h->mv_cache [list][cache_idx ]);
AV_ZERO32(h->mv_cache [list][cache_idx+8]);
h->ref_cache[list][cache_idx ]=
h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if(USES_LIST(topleft_type, list)){
const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride);
const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (h->topleft_partition & h->b8_stride);
AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]);
h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];
}else{
AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]);
h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
if(USES_LIST(topright_type, list)){
const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;
const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride;
AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]);
h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy];
}else{
AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]);
h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
continue;
if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) {
h->ref_cache[list][scan8[5 ]+1] =
h->ref_cache[list][scan8[7 ]+1] =
h->ref_cache[list][scan8[13]+1] =
h->ref_cache[list][scan8[4 ]] =
h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;
AV_ZERO32(h->mv_cache [list][scan8[5 ]+1]);
AV_ZERO32(h->mv_cache [list][scan8[7 ]+1]);
AV_ZERO32(h->mv_cache [list][scan8[13]+1]);
AV_ZERO32(h->mv_cache [list][scan8[4 ]]);
AV_ZERO32(h->mv_cache [list][scan8[12]]);
if( CABAC ) {
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
AV_COPY128(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]);
}else{
AV_ZERO128(h->mvd_cache[list][scan8[0] + 0 - 1*8]);
}
if(USES_LIST(left_type[0], list)){
const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy + h->b_stride*left_block[0]]);
AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy + h->b_stride*left_block[1]]);
}else{
AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 0*8]);
AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 1*8]);
}
if(USES_LIST(left_type[1], list)){
const int b_xy= h->mb2b_xy[left_xy[1]] + 3;
AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy + h->b_stride*left_block[2]]);
AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy + h->b_stride*left_block[3]]);
}else{
AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 2*8]);
AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 3*8]);
}
AV_ZERO32(h->mvd_cache [list][scan8[5 ]+1]);
AV_ZERO32(h->mvd_cache [list][scan8[7 ]+1]);
AV_ZERO32(h->mvd_cache [list][scan8[13]+1]);
AV_ZERO32(h->mvd_cache [list][scan8[4 ]]);
AV_ZERO32(h->mvd_cache [list][scan8[12]]);
if(h->slice_type_nos == FF_B_TYPE){
fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1);
if(IS_DIRECT(top_type)){
AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_DIRECT2>>1));
}else if(IS_8X8(top_type)){
int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride;
h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy];
h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1];
}else{
AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1));
}
if(IS_DIRECT(left_type[0]))
h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[0]))
h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)];
else
h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1;
if(IS_DIRECT(left_type[1]))
h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[1]))
h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)];
else
h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1;
}
}
}
if(FRAME_MBAFF){
#define MAP_MVS\
MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\
MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\
MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\
MAP_F2F(scan8[0] - 1 + 3*8, left_type[1])
if(MB_FIELD){
#define MAP_F2F(idx, mb_type)\
if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] <<= 1;\
h->mv_cache[list][idx][1] /= 2;\
h->mvd_cache[list][idx][1] /= 2;\
}
MAP_MVS
#undef MAP_F2F
}else{
#define MAP_F2F(idx, mb_type)\
if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] >>= 1;\
h->mv_cache[list][idx][1] <<= 1;\
h->mvd_cache[list][idx][1] <<= 1;\
}
MAP_MVS
#undef MAP_F2F
}
}
}
}
#endif
h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]);
}
|
['int ff_h264_decode_mb_cabac(H264Context *h) {\n MpegEncContext * const s = &h->s;\n int mb_xy;\n int mb_type, partition_count, cbp = 0;\n int dct8x8_allowed= h->pps.transform_8x8_mode;\n mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride;\n tprintf(s->avctx, "pic:%d mb:%d/%d\\n", h->frame_num, s->mb_x, s->mb_y);\n if( h->slice_type_nos != FF_I_TYPE ) {\n int skip;\n if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped )\n skip = h->next_mb_skipped;\n else\n skip = decode_cabac_mb_skip( h, s->mb_x, s->mb_y );\n if( skip ) {\n if( FRAME_MBAFF && (s->mb_y&1)==0 ){\n s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP;\n h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 );\n if(!h->next_mb_skipped)\n h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n }\n decode_mb_skip(h);\n h->cbp_table[mb_xy] = 0;\n h->chroma_pred_mode_table[mb_xy] = 0;\n h->last_qscale_diff = 0;\n return 0;\n }\n }\n if(FRAME_MBAFF){\n if( (s->mb_y&1) == 0 )\n h->mb_mbaff =\n h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h);\n }\n h->prev_mb_skipped = 0;\n fill_decode_neighbors(h, -(MB_FIELD));\n if( h->slice_type_nos == FF_B_TYPE ) {\n int ctx = 0;\n assert(h->slice_type_nos == FF_B_TYPE);\n if( !IS_DIRECT( h->left_type[0]-1 ) )\n ctx++;\n if( !IS_DIRECT( h->top_type-1 ) )\n ctx++;\n if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+ctx] ) ){\n mb_type= 0;\n }else if( !get_cabac_noinline( &h->cabac, &h->cabac_state[27+3] ) ) {\n mb_type= 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n }else{\n int bits;\n bits = get_cabac_noinline( &h->cabac, &h->cabac_state[27+4] ) << 3;\n bits|= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 2;\n bits|= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] ) << 1;\n bits|= get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n if( bits < 8 ){\n mb_type= bits + 3;\n }else if( bits == 13 ){\n mb_type= decode_cabac_intra_mb_type(h, 32, 0);\n goto decode_intra_mb;\n }else if( bits == 14 ){\n mb_type= 11;\n }else if( bits == 15 ){\n mb_type= 22;\n }else{\n bits= ( bits<<1 ) | get_cabac_noinline( &h->cabac, &h->cabac_state[27+5] );\n mb_type= bits - 4;\n }\n }\n partition_count= b_mb_type_info[mb_type].partition_count;\n mb_type= b_mb_type_info[mb_type].type;\n } else if( h->slice_type_nos == FF_P_TYPE ) {\n if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) {\n if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) {\n mb_type= 3 * get_cabac_noinline( &h->cabac, &h->cabac_state[16] );\n } else {\n mb_type= 2 - get_cabac_noinline( &h->cabac, &h->cabac_state[17] );\n }\n partition_count= p_mb_type_info[mb_type].partition_count;\n mb_type= p_mb_type_info[mb_type].type;\n } else {\n mb_type= decode_cabac_intra_mb_type(h, 17, 0);\n goto decode_intra_mb;\n }\n } else {\n mb_type= decode_cabac_intra_mb_type(h, 3, 1);\n if(h->slice_type == FF_SI_TYPE && mb_type)\n mb_type--;\n assert(h->slice_type_nos == FF_I_TYPE);\ndecode_intra_mb:\n partition_count = 0;\n cbp= i_mb_type_info[mb_type].cbp;\n h->intra16x16_pred_mode= i_mb_type_info[mb_type].pred_mode;\n mb_type= i_mb_type_info[mb_type].type;\n }\n if(MB_FIELD)\n mb_type |= MB_TYPE_INTERLACED;\n h->slice_table[ mb_xy ]= h->slice_num;\n if(IS_INTRA_PCM(mb_type)) {\n const uint8_t *ptr;\n ptr= h->cabac.bytestream;\n if(h->cabac.low&0x1) ptr--;\n if(CABAC_BITS==16){\n if(h->cabac.low&0x1FF) ptr--;\n }\n memcpy(h->mb, ptr, 256); ptr+=256;\n if(CHROMA){\n memcpy(h->mb+128, ptr, 128); ptr+=128;\n }\n ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n h->cbp_table[mb_xy] = 0x1ef;\n h->chroma_pred_mode_table[mb_xy] = 0;\n s->current_picture.qscale_table[mb_xy]= 0;\n memset(h->non_zero_count[mb_xy], 16, 32);\n s->current_picture.mb_type[mb_xy]= mb_type;\n h->last_qscale_diff = 0;\n return 0;\n }\n if(MB_MBAFF){\n h->ref_count[0] <<= 1;\n h->ref_count[1] <<= 1;\n }\n fill_decode_caches(h, mb_type);\n if( IS_INTRA( mb_type ) ) {\n int i, pred_mode;\n if( IS_INTRA4x4( mb_type ) ) {\n if( dct8x8_allowed && get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ) ) {\n mb_type |= MB_TYPE_8x8DCT;\n for( i = 0; i < 16; i+=4 ) {\n int pred = pred_intra_mode( h, i );\n int mode = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n fill_rectangle( &h->intra4x4_pred_mode_cache[ scan8[i] ], 2, 2, 8, mode, 1 );\n }\n } else {\n for( i = 0; i < 16; i++ ) {\n int pred = pred_intra_mode( h, i );\n h->intra4x4_pred_mode_cache[ scan8[i] ] = decode_cabac_mb_intra4x4_pred_mode( h, pred );\n }\n }\n ff_h264_write_back_intra_pred_mode(h);\n if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1;\n } else {\n h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode );\n if( h->intra16x16_pred_mode < 0 ) return -1;\n }\n if(CHROMA){\n h->chroma_pred_mode_table[mb_xy] =\n pred_mode = decode_cabac_mb_chroma_pre_mode( h );\n pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode );\n if( pred_mode < 0 ) return -1;\n h->chroma_pred_mode= pred_mode;\n }\n } else if( partition_count == 4 ) {\n int i, j, sub_partition_count[4], list, ref[2][4];\n if( h->slice_type_nos == FF_B_TYPE ) {\n for( i = 0; i < 4; i++ ) {\n h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h );\n sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |\n h->sub_mb_type[2] | h->sub_mb_type[3]) ) {\n ff_h264_pred_direct_motion(h, &mb_type);\n h->ref_cache[0][scan8[4]] =\n h->ref_cache[1][scan8[4]] =\n h->ref_cache[0][scan8[12]] =\n h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE;\n for( i = 0; i < 4; i++ )\n fill_rectangle( &h->direct_cache[scan8[4*i]], 2, 2, 8, (h->sub_mb_type[i]>>1)&0xFF, 1 );\n }\n } else {\n for( i = 0; i < 4; i++ ) {\n h->sub_mb_type[i] = decode_cabac_p_mb_sub_type( h );\n sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count;\n h->sub_mb_type[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].type;\n }\n }\n for( list = 0; list < h->list_count; list++ ) {\n for( i = 0; i < 4; i++ ) {\n if(IS_DIRECT(h->sub_mb_type[i])) continue;\n if(IS_DIR(h->sub_mb_type[i], 0, list)){\n if( h->ref_count[list] > 1 ){\n ref[list][i] = decode_cabac_mb_ref( h, list, 4*i );\n if(ref[list][i] >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref[list][i], h->ref_count[list]);\n return -1;\n }\n }else\n ref[list][i] = 0;\n } else {\n ref[list][i] = -1;\n }\n h->ref_cache[list][ scan8[4*i]+1 ]=\n h->ref_cache[list][ scan8[4*i]+8 ]=h->ref_cache[list][ scan8[4*i]+9 ]= ref[list][i];\n }\n }\n if(dct8x8_allowed)\n dct8x8_allowed = get_dct8x8_allowed(h);\n for(list=0; list<h->list_count; list++){\n for(i=0; i<4; i++){\n h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ];\n if(IS_DIRECT(h->sub_mb_type[i])){\n fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4);\n continue;\n }\n if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){\n const int sub_mb_type= h->sub_mb_type[i];\n const int block_width= (sub_mb_type & (MB_TYPE_16x16|MB_TYPE_16x8)) ? 2 : 1;\n for(j=0; j<sub_partition_count[i]; j++){\n int mpx, mpy;\n int mx, my;\n const int index= 4*i + block_width*j;\n int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];\n int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy);\n mx = mpx + decode_cabac_mb_mvd( h, list, index, 0 );\n my = mpy + decode_cabac_mb_mvd( h, list, index, 1 );\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n mpx= abs(mpx-mx);\n mpy= abs(mpy-my);\n if(IS_SUB_8X8(sub_mb_type)){\n mv_cache[ 1 ][0]=\n mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;\n mv_cache[ 1 ][1]=\n mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;\n mvd_cache[ 1 ][0]=\n mvd_cache[ 8 ][0]= mvd_cache[ 9 ][0]= mpx;\n mvd_cache[ 1 ][1]=\n mvd_cache[ 8 ][1]= mvd_cache[ 9 ][1]= mpy;\n }else if(IS_SUB_8X4(sub_mb_type)){\n mv_cache[ 1 ][0]= mx;\n mv_cache[ 1 ][1]= my;\n mvd_cache[ 1 ][0]= mpx;\n mvd_cache[ 1 ][1]= mpy;\n }else if(IS_SUB_4X8(sub_mb_type)){\n mv_cache[ 8 ][0]= mx;\n mv_cache[ 8 ][1]= my;\n mvd_cache[ 8 ][0]= mpx;\n mvd_cache[ 8 ][1]= mpy;\n }\n mv_cache[ 0 ][0]= mx;\n mv_cache[ 0 ][1]= my;\n mvd_cache[ 0 ][0]= mpx;\n mvd_cache[ 0 ][1]= mpy;\n }\n }else{\n uint32_t *p= (uint32_t *)&h->mv_cache[list][ scan8[4*i] ][0];\n uint32_t *pd= (uint32_t *)&h->mvd_cache[list][ scan8[4*i] ][0];\n p[0] = p[1] = p[8] = p[9] = 0;\n pd[0]= pd[1]= pd[8]= pd[9]= 0;\n }\n }\n }\n } else if( IS_DIRECT(mb_type) ) {\n ff_h264_pred_direct_motion(h, &mb_type);\n fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4);\n fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n } else {\n int list, mx, my, i, mpx, mpy;\n if(IS_16X16(mb_type)){\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref(h, list, 0);\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1);\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy);\n mx = mpx + decode_cabac_mb_mvd( h, list, 0, 0 );\n my = mpy + decode_cabac_mb_mvd( h, list, 0, 1 );\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(abs(mx-mpx),abs(my-mpy)), 4);\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }else\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4);\n }\n }\n else if(IS_16X8(mb_type)){\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref( h, list, 8*i );\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 16*i ], 4, 2, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy);\n mx = mpx + decode_cabac_mb_mvd( h, list, 8*i, 0 );\n my = mpy + decode_cabac_mb_mvd( h, list, 8*i, 1 );\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(abs(mx-mpx),abs(my-mpy)), 4);\n fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);\n }\n }\n }\n }else{\n assert(IS_8X16(mb_type));\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n int ref;\n if(h->ref_count[list] > 1){\n ref= decode_cabac_mb_ref( h, list, 4*i );\n if(ref >= (unsigned)h->ref_count[list]){\n av_log(s->avctx, AV_LOG_ERROR, "Reference %d >= %d\\n", ref, h->ref_count[list]);\n return -1;\n }\n }else\n ref=0;\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, ref, 1);\n }else\n fill_rectangle(&h->ref_cache[list][ scan8[0] + 2*i ], 2, 4, 8, (LIST_NOT_USED&0xFF), 1);\n }\n }\n for(list=0; list<h->list_count; list++){\n for(i=0; i<2; i++){\n if(IS_DIR(mb_type, i, list)){\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy);\n mx = mpx + decode_cabac_mb_mvd( h, list, 4*i, 0 );\n my = mpy + decode_cabac_mb_mvd( h, list, 4*i, 1 );\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(abs(mx-mpx),abs(my-mpy)), 4);\n fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);\n }else{\n fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);\n }\n }\n }\n }\n }\n if( IS_INTER( mb_type ) ) {\n h->chroma_pred_mode_table[mb_xy] = 0;\n write_back_motion( h, mb_type );\n }\n if( !IS_INTRA16x16( mb_type ) ) {\n cbp = decode_cabac_mb_cbp_luma( h );\n if(CHROMA)\n cbp |= decode_cabac_mb_cbp_chroma( h ) << 4;\n }\n h->cbp_table[mb_xy] = h->cbp = cbp;\n if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) {\n mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] );\n }\n s->current_picture.mb_type[mb_xy]= mb_type;\n if( cbp || IS_INTRA16x16( mb_type ) ) {\n const uint8_t *scan, *scan8x8, *dc_scan;\n const uint32_t *qmul;\n if(IS_INTERLACED(mb_type)){\n scan8x8= s->qscale ? h->field_scan8x8 : h->field_scan8x8_q0;\n scan= s->qscale ? h->field_scan : h->field_scan_q0;\n dc_scan= luma_dc_field_scan;\n }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\n dc_scan= luma_dc_zigzag_scan;\n }\n if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){\n int val = 1;\n int ctx= 2;\n while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n ctx= 3;\n val++;\n if(val > 102){\n av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\\n", s->mb_x, s->mb_y);\n return -1;\n }\n }\n if( val&0x01 )\n val= (val + 1)>>1 ;\n else\n val= -((val + 1)>>1);\n h->last_qscale_diff = val;\n s->qscale += val;\n if(((unsigned)s->qscale) > 51){\n if(s->qscale<0) s->qscale+= 52;\n else s->qscale-= 52;\n }\n h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n }else\n h->last_qscale_diff=0;\n if( IS_INTRA16x16( mb_type ) ) {\n int i;\n decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16);\n if( cbp&15 ) {\n qmul = h->dequant4_coeff[0][s->qscale];\n for( i = 0; i < 16; i++ ) {\n decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15);\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1);\n }\n } else {\n int i8x8, i4x4;\n for( i8x8 = 0; i8x8 < 4; i8x8++ ) {\n if( cbp & (1<<i8x8) ) {\n if( IS_8x8DCT(mb_type) ) {\n decode_cabac_residual(h, h->mb + 64*i8x8, 5, 4*i8x8,\n scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64);\n } else {\n qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale];\n for( i4x4 = 0; i4x4 < 4; i4x4++ ) {\n const int index = 4*i8x8 + i4x4;\n decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, qmul, 16);\n }\n }\n } else {\n uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ];\n nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0;\n }\n }\n }\n if( cbp&0x30 ){\n int c;\n for( c = 0; c < 2; c++ ) {\n decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4);\n }\n }\n if( cbp&0x20 ) {\n int c, i;\n for( c = 0; c < 2; c++ ) {\n qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]];\n for( i = 0; i < 4; i++ ) {\n const int index = 16 + 4 * c + i;\n decode_cabac_residual(h, h->mb + 16*index, 4, index, scan + 1, qmul, 15);\n }\n }\n } else {\n uint8_t * const nnz= &h->non_zero_count_cache[0];\n nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n }\n } else {\n uint8_t * const nnz= &h->non_zero_count_cache[0];\n fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1);\n nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] =\n nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0;\n h->last_qscale_diff = 0;\n }\n s->current_picture.qscale_table[mb_xy]= s->qscale;\n write_back_non_zero_count(h);\n if(MB_MBAFF){\n h->ref_count[0] >>= 1;\n h->ref_count[1] >>= 1;\n }\n return 0;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n static const uint8_t left_block_options[4][16]={\n {0,1,2,3,7,10,8,11,7+0*8, 7+1*8, 7+2*8, 7+3*8, 2+0*8, 2+3*8, 2+1*8, 2+2*8},\n {2,2,3,3,8,11,8,11,7+2*8, 7+2*8, 7+3*8, 7+3*8, 2+1*8, 2+2*8, 2+1*8, 2+2*8},\n {0,0,1,1,7,10,7,10,7+0*8, 7+0*8, 7+1*8, 7+1*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8},\n {0,2,0,2,7,10,7,10,7+0*8, 7+2*8, 7+0*8, 7+2*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[1] = left_xy[0] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1);\n topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1);\n top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[1] = left_xy[0] = mb_xy - 1;\n if (curr_mb_field_flag) {\n left_xy[1] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[0] = left_xy[0];\n h->left_mb_xy[1] = left_xy[1];\n h->topleft_type = h->slice_table[topleft_xy ] == h->slice_num ? s->current_picture.mb_type[topleft_xy] : 0;\n h->top_type = h->slice_table[top_xy ] == h->slice_num ? s->current_picture.mb_type[top_xy] : 0;\n h->topright_type= h->slice_table[topright_xy] == h->slice_num ? s->current_picture.mb_type[topright_xy]: 0;\n h->left_type[0] = h->slice_table[left_xy[0] ] == h->slice_num ? s->current_picture.mb_type[left_xy[0]] : 0;\n h->left_type[1] = h->slice_table[left_xy[1] ] == h->slice_num ? s->current_picture.mb_type[left_xy[1]] : 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[2];\n int topleft_type, top_type, topright_type, left_type[2];\n const uint8_t * left_block= h->left_block;\n int i;\n topleft_xy = h->topleft_mb_xy ;\n top_xy = h->top_mb_xy ;\n topright_xy = h->topright_mb_xy;\n left_xy[0] = h->left_mb_xy[0] ;\n left_xy[1] = h->left_mb_xy[1] ;\n topleft_type = h->topleft_type ;\n top_type = h->top_type ;\n topright_type= h->topright_type ;\n left_type[0] = h->left_type[0] ;\n left_type[1] = h->left_type[1] ;\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[1] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = h->slice_table[left_xy[0] + s->mb_stride ] == h->slice_num\n ? s->current_picture.mb_type[left_xy[0] + s->mb_stride] : 0;\n assert(left_xy[0] == left_xy[1]);\n if(!((left_typei & type_mask) && (left_type[0] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[0] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n h->intra4x4_pred_mode_cache[4+8*0]= h->intra4x4_pred_mode[top_xy][4];\n h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];\n h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];\n h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];\n }else{\n int pred;\n if(!(top_type & type_mask))\n pred= -1;\n else{\n pred= 2;\n }\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= pred;\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[i])){\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];\n }else{\n int pred;\n if(!(left_type[i] & type_mask))\n pred= -1;\n else{\n pred= 2;\n }\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;\n }\n }\n }\n }\n if(top_type){\n AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]);\n h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8];\n h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8];\n h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8];\n h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8];\n }else {\n h->non_zero_count_cache[1+8*0]=\n h->non_zero_count_cache[2+8*0]=\n h->non_zero_count_cache[1+8*3]=\n h->non_zero_count_cache[2+8*3]=\n AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040);\n }\n for (i=0; i<2; i++) {\n if(left_type[i]){\n h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]];\n h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]];\n h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]];\n h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]];\n }else{\n h->non_zero_count_cache[3+8*1 + 2*8*i]=\n h->non_zero_count_cache[3+8*2 + 2*8*i]=\n h->non_zero_count_cache[0+8*1 + 8*i]=\n h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else if(IS_INTRA(mb_type)) {\n h->top_cbp = 0x1CF;\n } else {\n h->top_cbp = 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp = h->cbp_table[left_xy[0]] & 0x1f0;\n } else if(IS_INTRA(mb_type)) {\n h->left_cbp = 0x1CF;\n } else {\n h->left_cbp = 0x00F;\n }\n if (left_type[0]) {\n h->left_cbp |= ((h->cbp_table[left_xy[0]]>>((left_block[0]&(~1))+1))&0x1) << 1;\n }\n if (left_type[1]) {\n h->left_cbp |= ((h->cbp_table[left_xy[1]]>>((left_block[2]&(~1))+1))&0x1) << 3;\n }\n }\n }\n#if 1\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n for(list=0; list<h->list_count; list++){\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n h->mv_cache_clean[list]= 0;\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[top_xy] + h->b8_stride;\n AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);\n h->ref_cache[list][scan8[0] + 0 - 1*8]=\n h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][b8_xy + 0];\n h->ref_cache[list][scan8[0] + 2 - 1*8]=\n h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][b8_xy + 1];\n }else{\n AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);\n AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n for(i=0; i<2; i++){\n int cache_idx = scan8[0] - 1 + i*2*8;\n if(USES_LIST(left_type[i], list)){\n const int b_xy= h->mb2b_xy[left_xy[i]] + 3;\n const int b8_xy= h->mb2b8_xy[left_xy[i]] + 1;\n AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]);\n AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]);\n h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[0+i*2]>>1)];\n h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + h->b8_stride*(left_block[1+i*2]>>1)];\n }else{\n AV_ZERO32(h->mv_cache [list][cache_idx ]);\n AV_ZERO32(h->mv_cache [list][cache_idx+8]);\n h->ref_cache[list][cache_idx ]=\n h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride);\n const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (h->topleft_partition & h->b8_stride);\n AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]);\n h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride;\n const int b8_xy= h->mb2b8_xy[topright_xy] + h->b8_stride;\n AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][b8_xy];\n }else{\n AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]);\n h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) {\n h->ref_cache[list][scan8[5 ]+1] =\n h->ref_cache[list][scan8[7 ]+1] =\n h->ref_cache[list][scan8[13]+1] =\n h->ref_cache[list][scan8[4 ]] =\n h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;\n AV_ZERO32(h->mv_cache [list][scan8[5 ]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[7 ]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[13]+1]);\n AV_ZERO32(h->mv_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mv_cache [list][scan8[12]]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;\n AV_COPY128(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]);\n }else{\n AV_ZERO128(h->mvd_cache[list][scan8[0] + 0 - 1*8]);\n }\n if(USES_LIST(left_type[0], list)){\n const int b_xy= h->mb2b_xy[left_xy[0]] + 3;\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy + h->b_stride*left_block[0]]);\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy + h->b_stride*left_block[1]]);\n }else{\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 0*8]);\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 1*8]);\n }\n if(USES_LIST(left_type[1], list)){\n const int b_xy= h->mb2b_xy[left_xy[1]] + 3;\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy + h->b_stride*left_block[2]]);\n AV_COPY32(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy + h->b_stride*left_block[3]]);\n }else{\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 2*8]);\n AV_ZERO32(h->mvd_cache [list][scan8[0] - 1 + 3*8]);\n }\n AV_ZERO32(h->mvd_cache [list][scan8[5 ]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[7 ]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[13]+1]);\n AV_ZERO32(h->mvd_cache [list][scan8[4 ]]);\n AV_ZERO32(h->mvd_cache [list][scan8[12]]);\n if(h->slice_type_nos == FF_B_TYPE){\n fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = h->mb2b8_xy[top_xy] + h->b8_stride;\n h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy];\n h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 1];\n }else{\n AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[0]))\n h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[h->mb2b8_xy[left_xy[0]] + 1 + h->b8_stride*(left_block[0]>>1)];\n else\n h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[1]))\n h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[h->mb2b8_xy[left_xy[1]] + 1 + h->b8_stride*(left_block[2]>>1)];\n else\n h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[1])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] /= 2;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n#endif\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]);\n}']
|
1,356
| 0
|
https://gitlab.com/libtiff/libtiff/blob/9c243a11a35d118d00ef8947d244ac55c4145640/libtiff/tif_getimage.c/#L2461
|
static int
setupMap(TIFFRGBAImage* img)
{
int32 x, range;
range = (int32)((1L<<img->bitspersample)-1);
if( img->bitspersample == 16 )
range = (int32) 255;
img->Map = (TIFFRGBValue*) _TIFFmalloc((range+1) * sizeof (TIFFRGBValue));
if (img->Map == NULL) {
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif),
"No space for photometric conversion table");
return (0);
}
if (img->photometric == PHOTOMETRIC_MINISWHITE) {
for (x = 0; x <= range; x++)
img->Map[x] = (TIFFRGBValue) (((range - x) * 255) / range);
} else {
for (x = 0; x <= range; x++)
img->Map[x] = (TIFFRGBValue) ((x * 255) / range);
}
if (img->bitspersample <= 16 &&
(img->photometric == PHOTOMETRIC_MINISBLACK ||
img->photometric == PHOTOMETRIC_MINISWHITE)) {
if (!makebwmap(img))
return (0);
_TIFFfree(img->Map);
img->Map = NULL;
}
return (1);
}
|
['static int\nsetupMap(TIFFRGBAImage* img)\n{\n int32 x, range;\n range = (int32)((1L<<img->bitspersample)-1);\n if( img->bitspersample == 16 )\n range = (int32) 255;\n img->Map = (TIFFRGBValue*) _TIFFmalloc((range+1) * sizeof (TIFFRGBValue));\n if (img->Map == NULL) {\n\t\tTIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif),\n\t\t\t"No space for photometric conversion table");\n\t\treturn (0);\n }\n if (img->photometric == PHOTOMETRIC_MINISWHITE) {\n\tfor (x = 0; x <= range; x++)\n\t img->Map[x] = (TIFFRGBValue) (((range - x) * 255) / range);\n } else {\n\tfor (x = 0; x <= range; x++)\n\t img->Map[x] = (TIFFRGBValue) ((x * 255) / range);\n }\n if (img->bitspersample <= 16 &&\n\t(img->photometric == PHOTOMETRIC_MINISBLACK ||\n\t img->photometric == PHOTOMETRIC_MINISWHITE)) {\n\tif (!makebwmap(img))\n\t return (0);\n\t_TIFFfree(img->Map);\n\timg->Map = NULL;\n }\n return (1);\n}', 'void*\n_TIFFmalloc(tmsize_t s)\n{\n if (s == 0)\n return ((void *) NULL);\n\treturn (malloc((size_t) s));\n}']
|
1,357
| 0
|
https://github.com/openssl/openssl/blob/09977dd095f3c655c99b9e1810a213f7eafa7364/crypto/bn/bn_lib.c/#L342
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = A = OPENSSL_zalloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
}
|
['BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *ret = in;\n int err = 1;\n int r;\n BIGNUM *A, *b, *q, *t, *x, *y;\n int e, i, j;\n if (!BN_is_odd(p) || BN_abs_is_word(p, 1)) {\n if (BN_abs_is_word(p, 2)) {\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_set_word(ret, BN_is_bit_set(a, 0))) {\n if (ret != in)\n BN_free(ret);\n return NULL;\n }\n bn_check_top(ret);\n return ret;\n }\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n return (NULL);\n }\n if (BN_is_zero(a) || BN_is_one(a)) {\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_set_word(ret, BN_is_one(a))) {\n if (ret != in)\n BN_free(ret);\n return NULL;\n }\n bn_check_top(ret);\n return ret;\n }\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto end;\n if (ret == NULL)\n ret = BN_new();\n if (ret == NULL)\n goto end;\n if (!BN_nnmod(A, a, p, ctx))\n goto end;\n e = 1;\n while (!BN_is_bit_set(p, e))\n e++;\n if (e == 1) {\n if (!BN_rshift(q, p, 2))\n goto end;\n q->neg = 0;\n if (!BN_add_word(q, 1))\n goto end;\n if (!BN_mod_exp(ret, A, q, p, ctx))\n goto end;\n err = 0;\n goto vrfy;\n }\n if (e == 2) {\n if (!BN_mod_lshift1_quick(t, A, p))\n goto end;\n if (!BN_rshift(q, p, 3))\n goto end;\n q->neg = 0;\n if (!BN_mod_exp(b, t, q, p, ctx))\n goto end;\n if (!BN_mod_sqr(y, b, p, ctx))\n goto end;\n if (!BN_mod_mul(t, t, y, p, ctx))\n goto end;\n if (!BN_sub_word(t, 1))\n goto end;\n if (!BN_mod_mul(x, A, b, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, t, p, ctx))\n goto end;\n if (!BN_copy(ret, x))\n goto end;\n err = 0;\n goto vrfy;\n }\n if (!BN_copy(q, p))\n goto end;\n q->neg = 0;\n i = 2;\n do {\n if (i < 22) {\n if (!BN_set_word(y, i))\n goto end;\n } else {\n if (!BN_pseudo_rand(y, BN_num_bits(p), 0, 0))\n goto end;\n if (BN_ucmp(y, p) >= 0) {\n if (!(p->neg ? BN_add : BN_sub) (y, y, p))\n goto end;\n }\n if (BN_is_zero(y))\n if (!BN_set_word(y, i))\n goto end;\n }\n r = BN_kronecker(y, q, ctx);\n if (r < -1)\n goto end;\n if (r == 0) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n goto end;\n }\n }\n while (r == 1 && ++i < 82);\n if (r != -1) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_TOO_MANY_ITERATIONS);\n goto end;\n }\n if (!BN_rshift(q, q, e))\n goto end;\n if (!BN_mod_exp(y, y, q, p, ctx))\n goto end;\n if (BN_is_one(y)) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_P_IS_NOT_PRIME);\n goto end;\n }\n if (!BN_rshift1(t, q))\n goto end;\n if (BN_is_zero(t)) {\n if (!BN_nnmod(t, A, p, ctx))\n goto end;\n if (BN_is_zero(t)) {\n BN_zero(ret);\n err = 0;\n goto end;\n } else if (!BN_one(x))\n goto end;\n } else {\n if (!BN_mod_exp(x, A, t, p, ctx))\n goto end;\n if (BN_is_zero(x)) {\n BN_zero(ret);\n err = 0;\n goto end;\n }\n }\n if (!BN_mod_sqr(b, x, p, ctx))\n goto end;\n if (!BN_mod_mul(b, b, A, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, A, p, ctx))\n goto end;\n while (1) {\n if (BN_is_one(b)) {\n if (!BN_copy(ret, x))\n goto end;\n err = 0;\n goto vrfy;\n }\n i = 1;\n if (!BN_mod_sqr(t, b, p, ctx))\n goto end;\n while (!BN_is_one(t)) {\n i++;\n if (i == e) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n goto end;\n }\n if (!BN_mod_mul(t, t, t, p, ctx))\n goto end;\n }\n if (!BN_copy(t, y))\n goto end;\n for (j = e - i - 1; j > 0; j--) {\n if (!BN_mod_sqr(t, t, p, ctx))\n goto end;\n }\n if (!BN_mod_mul(y, t, t, p, ctx))\n goto end;\n if (!BN_mod_mul(x, x, t, p, ctx))\n goto end;\n if (!BN_mod_mul(b, b, y, p, ctx))\n goto end;\n e = i;\n }\n vrfy:\n if (!err) {\n if (!BN_mod_sqr(x, ret, p, ctx))\n err = 1;\n if (!err && 0 != BN_cmp(x, A)) {\n BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);\n err = 1;\n }\n }\n end:\n if (err) {\n if (ret != in)\n BN_clear_free(ret);\n ret = NULL;\n }\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if(((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n res->neg = (num->neg ^ divisor->neg);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--, resp--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = A = OPENSSL_zalloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
|
1,358
| 0
|
https://github.com/libav/libav/blob/26f027fba1c5ab482fa2488fbe0fa36c8bb33b69/libavcodec/mp3_header_compress_bsf.c/#L53
|
static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
uint8_t **poutbuf, int *poutbuf_size,
const uint8_t *buf, int buf_size, int keyframe){
uint32_t header, extraheader;
int mode_extension, header_size;
if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){
av_log(avctx, AV_LOG_ERROR, "not standards compliant\n");
return -1;
}
header = AV_RB32(buf);
mode_extension= (header>>4)&3;
if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){
output_unchanged:
*poutbuf= (uint8_t *) buf;
*poutbuf_size= buf_size;
av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header);
return 0;
}
if(avctx->extradata_size == 0){
avctx->extradata_size=15;
avctx->extradata= av_malloc(avctx->extradata_size);
strcpy(avctx->extradata, "FFCMP3 0.0");
memcpy(avctx->extradata+11, buf, 4);
}
if(avctx->extradata_size != 15){
av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n");
return -1;
}
extraheader = AV_RB32(avctx->extradata+11);
if((extraheader&MP3_MASK) != (header&MP3_MASK))
goto output_unchanged;
header_size= (header&0x10000) ? 4 : 6;
*poutbuf_size= buf_size - header_size;
*poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);
if(avctx->channels==2){
if((header & (3<<19)) != 3<<19){
(*poutbuf)[1] &= 0x3F;
(*poutbuf)[1] |= mode_extension<<6;
FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);
}else{
(*poutbuf)[1] &= 0x8F;
(*poutbuf)[1] |= mode_extension<<4;
}
}
return 1;
}
|
['static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,\n uint8_t **poutbuf, int *poutbuf_size,\n const uint8_t *buf, int buf_size, int keyframe){\n uint32_t header, extraheader;\n int mode_extension, header_size;\n if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){\n av_log(avctx, AV_LOG_ERROR, "not standards compliant\\n");\n return -1;\n }\n header = AV_RB32(buf);\n mode_extension= (header>>4)&3;\n if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){\noutput_unchanged:\n *poutbuf= (uint8_t *) buf;\n *poutbuf_size= buf_size;\n av_log(avctx, AV_LOG_INFO, "cannot compress %08X\\n", header);\n return 0;\n }\n if(avctx->extradata_size == 0){\n avctx->extradata_size=15;\n avctx->extradata= av_malloc(avctx->extradata_size);\n strcpy(avctx->extradata, "FFCMP3 0.0");\n memcpy(avctx->extradata+11, buf, 4);\n }\n if(avctx->extradata_size != 15){\n av_log(avctx, AV_LOG_ERROR, "Extradata invalid\\n");\n return -1;\n }\n extraheader = AV_RB32(avctx->extradata+11);\n if((extraheader&MP3_MASK) != (header&MP3_MASK))\n goto output_unchanged;\n header_size= (header&0x10000) ? 4 : 6;\n *poutbuf_size= buf_size - header_size;\n *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);\n memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE);\n if(avctx->channels==2){\n if((header & (3<<19)) != 3<<19){\n (*poutbuf)[1] &= 0x3F;\n (*poutbuf)[1] |= mode_extension<<6;\n FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]);\n }else{\n (*poutbuf)[1] &= 0x8F;\n (*poutbuf)[1] |= mode_extension<<4;\n }\n }\n return 1;\n}', 'static av_always_inline av_const uint32_t av_bswap32(uint32_t x)\n{\n return AV_BSWAP32C(x);\n}', 'static inline int ff_mpa_check_header(uint32_t header){\n if ((header & 0xffe00000) != 0xffe00000)\n return -1;\n if ((header & (3<<17)) == 0)\n return -1;\n if ((header & (0xf<<12)) == 0xf<<12)\n return -1;\n if ((header & (3<<10)) == 3<<10)\n return -1;\n return 0;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if (size > (INT_MAX - 32) || !size)\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size + 32);\n if (!ptr)\n return ptr;\n diff = ((-(long)ptr - 1) & 31) + 1;\n ptr = (char *)ptr + diff;\n ((char *)ptr)[-1] = diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr, 32, size))\n ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n ptr = memalign(32, size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,359
| 0
|
https://github.com/libav/libav/blob/5150dd532b142d7032854a362228dd40142a8e94/libavcodec/imgconvert.c/#L1417
|
static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
int width, int height)
{
uint8_t *src_m1, *src_0, *src_p1, *src_p2;
int y;
uint8_t *buf;
buf = (uint8_t*)av_malloc(width);
src_m1 = src1;
memcpy(buf,src_m1,width);
src_0=&src_m1[src_wrap];
src_p1=&src_0[src_wrap];
src_p2=&src_p1[src_wrap];
for(y=0;y<(height-2);y+=2) {
deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);
src_m1 = src_p1;
src_0 = src_p2;
src_p1 += 2*src_wrap;
src_p2 += 2*src_wrap;
}
deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
av_free(buf);
}
|
['static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,\n int width, int height)\n{\n uint8_t *src_m1, *src_0, *src_p1, *src_p2;\n int y;\n uint8_t *buf;\n buf = (uint8_t*)av_malloc(width);\n src_m1 = src1;\n memcpy(buf,src_m1,width);\n src_0=&src_m1[src_wrap];\n src_p1=&src_0[src_wrap];\n src_p2=&src_p1[src_wrap];\n for(y=0;y<(height-2);y+=2) {\n deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);\n src_m1 = src_p1;\n src_0 = src_p2;\n src_p1 += 2*src_wrap;\n src_p2 += 2*src_wrap;\n }\n deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);\n av_free(buf);\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
1,360
| 0
|
https://github.com/openssl/openssl/blob/f4001a0d192a2462bcedbaadf95e778ddc352ebb/crypto/bn/bn_ctx.c/#L355
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e, BN_GENCB *cb)\n\t{\n\tint ok = 0;\n\tBIGNUM *Xp = NULL, *Xq = NULL;\n\tBN_CTX *ctx = NULL;\n#ifdef OPENSSL_FIPS\n\tif (bits < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS)\n\t {\n\t FIPSerr(FIPS_F_RSA_X931_GENERATE_KEY_EX,FIPS_R_KEY_TOO_SHORT);\n\t return 0;\n\t }\n\tif (bits & 0xff)\n\t {\n\t FIPSerr(FIPS_F_RSA_X931_GENERATE_KEY_EX,FIPS_R_INVALID_KEY_LENGTH);\n\t return 0;\n\t }\n\tif(FIPS_selftest_failed())\n\t {\n\t FIPSerr(FIPS_F_RSA_X931_GENERATE_KEY_EX,FIPS_R_FIPS_SELFTEST_FAILED);\n\t return 0;\n\t }\n#endif\n\tctx = BN_CTX_new();\n\tif (!ctx)\n\t\tgoto error;\n\tBN_CTX_start(ctx);\n\tXp = BN_CTX_get(ctx);\n\tXq = BN_CTX_get(ctx);\n\tif (!BN_X931_generate_Xpq(Xp, Xq, bits, ctx))\n\t\tgoto error;\n\trsa->p = BN_new();\n\trsa->q = BN_new();\n\tif (!rsa->p || !rsa->q)\n\t\tgoto error;\n\tif (!BN_X931_generate_prime_ex(rsa->p, NULL, NULL, NULL, NULL, Xp,\n\t\t\t\t\te, ctx, cb))\n\t\tgoto error;\n\tif (!BN_X931_generate_prime_ex(rsa->q, NULL, NULL, NULL, NULL, Xq,\n\t\t\t\t\te, ctx, cb))\n\t\tgoto error;\n\tif (!RSA_X931_derive_ex(rsa, NULL, NULL, NULL, NULL,\n\t\t\t\tNULL, NULL, NULL, NULL, NULL, NULL, e, cb))\n\t\tgoto error;\n#ifdef OPENSSL_FIPS\n\tif(!fips_check_rsa(rsa))\n\t goto error;\n#endif\n\tok = 1;\n\terror:\n\tif (ctx)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (ok)\n\t\treturn 1;\n\treturn 0;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint i;\n\tif ((nbits < 1024) || (nbits & 0xff))\n\t\treturn 0;\n\tnbits >>= 1;\n\tif (!BN_rand(Xp, nbits, 1, 0))\n\t\treturn 0;\n\tBN_CTX_start(ctx);\n\tt = BN_CTX_get(ctx);\n\tfor (i = 0; i < 1000; i++)\n\t\t{\n\t\tif (!BN_rand(Xq, nbits, 1, 0))\n\t\t\treturn 0;\n\t\tBN_sub(t, Xp, Xq);\n\t\tif (BN_num_bits(t) > (nbits - 100))\n\t\t\tbreak;\n\t\t}\n\tBN_CTX_end(ctx);\n\tif (i < 1000)\n\t\treturn 1;\n\treturn 0;\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,361
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/idea/i_skey.c/#L92
|
void idea_set_encrypt_key(unsigned char *key, IDEA_KEY_SCHEDULE *ks)
{
int i;
register IDEA_INT *kt,*kf,r0,r1,r2;
kt= &(ks->data[0][0]);
n2s(key,kt[0]); n2s(key,kt[1]); n2s(key,kt[2]); n2s(key,kt[3]);
n2s(key,kt[4]); n2s(key,kt[5]); n2s(key,kt[6]); n2s(key,kt[7]);
kf=kt;
kt+=8;
for (i=0; i<6; i++)
{
r2= kf[1];
r1= kf[2];
*(kt++)= ((r2<<9) | (r1>>7))&0xffff;
r0= kf[3];
*(kt++)= ((r1<<9) | (r0>>7))&0xffff;
r1= kf[4];
*(kt++)= ((r0<<9) | (r1>>7))&0xffff;
r0= kf[5];
*(kt++)= ((r1<<9) | (r0>>7))&0xffff;
r1= kf[6];
*(kt++)= ((r0<<9) | (r1>>7))&0xffff;
r0= kf[7];
*(kt++)= ((r1<<9) | (r0>>7))&0xffff;
r1= kf[0];
if (i >= 5) break;
*(kt++)= ((r0<<9) | (r1>>7))&0xffff;
*(kt++)= ((r1<<9) | (r2>>7))&0xffff;
kf+=8;
}
}
|
['void idea_set_encrypt_key(unsigned char *key, IDEA_KEY_SCHEDULE *ks)\n\t{\n\tint i;\n\tregister IDEA_INT *kt,*kf,r0,r1,r2;\n\tkt= &(ks->data[0][0]);\n\tn2s(key,kt[0]); n2s(key,kt[1]); n2s(key,kt[2]); n2s(key,kt[3]);\n\tn2s(key,kt[4]); n2s(key,kt[5]); n2s(key,kt[6]); n2s(key,kt[7]);\n\tkf=kt;\n\tkt+=8;\n\tfor (i=0; i<6; i++)\n\t\t{\n\t\tr2= kf[1];\n\t\tr1= kf[2];\n\t\t*(kt++)= ((r2<<9) | (r1>>7))&0xffff;\n\t\tr0= kf[3];\n\t\t*(kt++)= ((r1<<9) | (r0>>7))&0xffff;\n\t\tr1= kf[4];\n\t\t*(kt++)= ((r0<<9) | (r1>>7))&0xffff;\n\t\tr0= kf[5];\n\t\t*(kt++)= ((r1<<9) | (r0>>7))&0xffff;\n\t\tr1= kf[6];\n\t\t*(kt++)= ((r0<<9) | (r1>>7))&0xffff;\n\t\tr0= kf[7];\n\t\t*(kt++)= ((r1<<9) | (r0>>7))&0xffff;\n\t\tr1= kf[0];\n\t\tif (i >= 5) break;\n\t\t*(kt++)= ((r0<<9) | (r1>>7))&0xffff;\n\t\t*(kt++)= ((r1<<9) | (r2>>7))&0xffff;\n\t\tkf+=8;\n\t\t}\n\t}']
|
1,362
| 0
|
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_ctx.c/#L276
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,\n const BIGNUM *a2, const BIGNUM *p2, const BIGNUM *m,\n BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, b, bits1, bits2, ret =\n 0, wpos1, wpos2, window1, window2, wvalue1, wvalue2;\n int r_is_one = 1;\n BIGNUM *d, *r;\n const BIGNUM *a_mod_m;\n BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n bn_check_top(a1);\n bn_check_top(p1);\n bn_check_top(a2);\n bn_check_top(p2);\n bn_check_top(m);\n if (!(m->d[0] & 1)) {\n BNerr(BN_F_BN_MOD_EXP2_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits1 = BN_num_bits(p1);\n bits2 = BN_num_bits(p2);\n if ((bits1 == 0) && (bits2 == 0)) {\n ret = BN_one(rr);\n return ret;\n }\n bits = (bits1 > bits2) ? bits1 : bits2;\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val1[0] = BN_CTX_get(ctx);\n val2[0] = BN_CTX_get(ctx);\n if (val2[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n window1 = BN_window_bits_for_exponent_size(bits1);\n window2 = BN_window_bits_for_exponent_size(bits2);\n if (a1->neg || BN_ucmp(a1, m) >= 0) {\n if (!BN_mod(val1[0], a1, m, ctx))\n goto err;\n a_mod_m = val1[0];\n } else\n a_mod_m = a1;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val1[0], a_mod_m, mont, ctx))\n goto err;\n if (window1 > 1) {\n if (!BN_mod_mul_montgomery(d, val1[0], val1[0], mont, ctx))\n goto err;\n j = 1 << (window1 - 1);\n for (i = 1; i < j; i++) {\n if (((val1[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val1[i], val1[i - 1], d, mont, ctx))\n goto err;\n }\n }\n if (a2->neg || BN_ucmp(a2, m) >= 0) {\n if (!BN_mod(val2[0], a2, m, ctx))\n goto err;\n a_mod_m = val2[0];\n } else\n a_mod_m = a2;\n if (BN_is_zero(a_mod_m)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val2[0], a_mod_m, mont, ctx))\n goto err;\n if (window2 > 1) {\n if (!BN_mod_mul_montgomery(d, val2[0], val2[0], mont, ctx))\n goto err;\n j = 1 << (window2 - 1);\n for (i = 1; i < j; i++) {\n if (((val2[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val2[i], val2[i - 1], d, mont, ctx))\n goto err;\n }\n }\n r_is_one = 1;\n wvalue1 = 0;\n wvalue2 = 0;\n wpos1 = 0;\n wpos2 = 0;\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (b = bits - 1; b >= 0; b--) {\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!wvalue1)\n if (BN_is_bit_set(p1, b)) {\n i = b - window1 + 1;\n while (!BN_is_bit_set(p1, i))\n i++;\n wpos1 = i;\n wvalue1 = 1;\n for (i = b - 1; i >= wpos1; i--) {\n wvalue1 <<= 1;\n if (BN_is_bit_set(p1, i))\n wvalue1++;\n }\n }\n if (!wvalue2)\n if (BN_is_bit_set(p2, b)) {\n i = b - window2 + 1;\n while (!BN_is_bit_set(p2, i))\n i++;\n wpos2 = i;\n wvalue2 = 1;\n for (i = b - 1; i >= wpos2; i--) {\n wvalue2 <<= 1;\n if (BN_is_bit_set(p2, i))\n wvalue2++;\n }\n }\n if (wvalue1 && b == wpos1) {\n if (!BN_mod_mul_montgomery(r, r, val1[wvalue1 >> 1], mont, ctx))\n goto err;\n wvalue1 = 0;\n r_is_one = 0;\n }\n if (wvalue2 && b == wpos2) {\n if (!BN_mod_mul_montgomery(r, r, val2[wvalue2 >> 1], mont, ctx))\n goto err;\n wvalue2 = 0;\n r_is_one = 0;\n }\n }\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n int ret = bn_mul_mont_fixed_top(r, a, b, mont, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!bn_sqr_fixed_top(tmp, a, ctx))\n goto err;\n } else {\n if (!bn_mul_fixed_top(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!bn_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,363
| 0
|
https://github.com/openssl/openssl/blob/5bdae1675c8b450bed091b9605ae9d10d61adfc7/crypto/rsa/rsa_eay.c/#L399
|
static int RSA_eay_public_decrypt(int flen, unsigned char *from,
unsigned char *to, RSA *rsa, int padding)
{
BIGNUM f,ret;
int i,num=0,r= -1;
unsigned char *p;
unsigned char *buf=NULL;
BN_CTX *ctx=NULL;
BN_init(&f);
BN_init(&ret);
ctx=BN_CTX_new();
if (ctx == NULL) goto err;
num=BN_num_bytes(rsa->n);
buf=(unsigned char *)Malloc(num);
if (buf == NULL)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
goto err;
}
if (flen > num)
{
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);
goto err;
}
if (BN_bin2bn(from,flen,&f) == NULL) goto err;
if ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))
{
if ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)
if (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))
goto err;
}
if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
rsa->_method_mod_n)) goto err;
p=buf;
i=BN_bn2bin(&ret,p);
switch (padding)
{
case RSA_PKCS1_PADDING:
r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
break;
case RSA_NO_PADDING:
r=RSA_padding_check_none(to,num,buf,i,num);
break;
default:
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);
goto err;
}
if (r < 0)
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
err:
if (ctx != NULL) BN_CTX_free(ctx);
BN_clear_free(&f);
BN_clear_free(&ret);
if (buf != NULL)
{
memset(buf,0,num);
Free(buf);
}
return(r);
}
|
['static int RSA_eay_public_decrypt(int flen, unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM f,ret;\n\tint i,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\tbuf=(unsigned char *)Malloc(num);\n\tif (buf == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_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_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,flen,&f) == NULL) goto err;\n\tif ((rsa->_method_mod_n == NULL) && (rsa->flags & RSA_FLAG_CACHE_PUBLIC))\n\t\t{\n\t\tif ((rsa->_method_mod_n=BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_n,rsa->n,ctx))\n\t\t\t goto err;\n\t\t}\n\tif (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tp=buf;\n\ti=BN_bn2bin(&ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,i,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_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}', 'void BN_init(BIGNUM *a)\n\t{\n\tmemset(a,0,sizeof(BIGNUM));\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tif (a->top == 0) return(0);\n\tl=a->d[a->top-1];\n\ti=(a->top-1)*BN_BITS2;\n\tif (l == 0)\n\t\t{\n#if !defined(NO_STDIO) && !defined(WIN16)\n\t\tfprintf(stderr,"BAD TOP VALUE\\n");\n#endif\n\t\tabort();\n\t\t}\n\treturn(i+BN_num_bits_word(l));\n\t}']
|
1,364
| 0
|
https://github.com/openssl/openssl/blob/eaf6c61c9f378bec0132d4cae556eee563f545b5/crypto/x509v3/v3_utl.c/#L498
|
static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)
{
STACK *ret = NULL;
X509_NAME_ENTRY *ne;
ASN1_IA5STRING *email;
GENERAL_NAME *gen;
int i;
i = -1;
while((i = X509_NAME_get_index_by_NID(name,
NID_pkcs9_emailAddress, i)) >= 0) {
ne = X509_NAME_get_entry(name, i);
email = X509_NAME_ENTRY_get_data(ne);
if(!append_ia5(&ret, email)) return NULL;
}
for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
{
gen = sk_GENERAL_NAME_value(gens, i);
if(gen->type != GEN_EMAIL) continue;
if(!append_ia5(&ret, gen->d.ia5)) return NULL;
}
return ret;
}
|
['static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens)\n{\n\tSTACK *ret = NULL;\n\tX509_NAME_ENTRY *ne;\n\tASN1_IA5STRING *email;\n\tGENERAL_NAME *gen;\n\tint i;\n\ti = -1;\n\twhile((i = X509_NAME_get_index_by_NID(name,\n\t\t\t\t\t NID_pkcs9_emailAddress, i)) >= 0) {\n\t\tne = X509_NAME_get_entry(name, i);\n\t\temail = X509_NAME_ENTRY_get_data(ne);\n\t\tif(!append_ia5(&ret, email)) return NULL;\n\t}\n\tfor(i = 0; i < sk_GENERAL_NAME_num(gens); i++)\n\t{\n\t\tgen = sk_GENERAL_NAME_value(gens, i);\n\t\tif(gen->type != GEN_EMAIL) continue;\n\t\tif(!append_ia5(&ret, gen->d.ia5)) return NULL;\n\t}\n\treturn ret;\n}', 'int X509_NAME_get_index_by_NID(X509_NAME *name, int nid, int lastpos)\n\t{\n\tASN1_OBJECT *obj;\n\tobj=OBJ_nid2obj(nid);\n\tif (obj == NULL) return(-2);\n\treturn(X509_NAME_get_index_by_OBJ(name,obj,lastpos));\n\t}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n\t{\n\tADDED_OBJ ad,*adp;\n\tASN1_OBJECT ob;\n\tif ((n >= 0) && (n < NUM_NID))\n\t\t{\n\t\tif ((n != NID_undef) && (nid_objs[n].nid == NID_undef))\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\treturn((ASN1_OBJECT *)&(nid_objs[n]));\n\t\t}\n\telse if (added == NULL)\n\t\treturn(NULL);\n\telse\n\t\t{\n\t\tad.type=ADDED_NID;\n\t\tad.obj= &ob;\n\t\tob.nid=n;\n\t\tadp=(ADDED_OBJ *)lh_retrieve(added,&ad);\n\t\tif (adp != NULL)\n\t\t\treturn(adp->obj);\n\t\telse\n\t\t\t{\n\t\t\tOBJerr(OBJ_F_OBJ_NID2OBJ,OBJ_R_UNKNOWN_NID);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\t}\n\t}', 'X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc)\n\t{\n\tif(name == NULL || sk_X509_NAME_ENTRY_num(name->entries) <= loc\n\t || loc < 0)\n\t\treturn(NULL);\n\telse\n\t\treturn(sk_X509_NAME_ENTRY_value(name->entries,loc));\n\t}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(st == NULL) return NULL;\n\treturn st->data[i];\n}', 'ASN1_STRING *X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne)\n\t{\n\tif (ne == NULL) return(NULL);\n\treturn(ne->value);\n\t}', 'static int append_ia5(STACK **sk, ASN1_IA5STRING *email)\n{\n\tchar *emtmp;\n\tif(email->type != V_ASN1_IA5STRING) return 1;\n\tif(!email->data || !email->length) return 1;\n\tif(!*sk) *sk = sk_new(sk_strcmp);\n\tif(!*sk) return 0;\n\tif(sk_find(*sk, (char *)email->data) != -1) return 1;\n\temtmp = BUF_strdup((char *)email->data);\n\tif(!emtmp || !sk_push(*sk, emtmp)) {\n\t\tX509_email_free(*sk);\n\t\t*sk = NULL;\n\t\treturn 0;\n\t}\n\treturn 1;\n}']
|
1,365
| 0
|
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/x509v3/v3_sxnet.c/#L177
|
int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,
int userlen)
{
ASN1_INTEGER *izone;
if ((izone = ASN1_INTEGER_new()) == NULL
|| !ASN1_INTEGER_set(izone, lzone)) {
X509V3err(X509V3_F_SXNET_ADD_ID_ULONG, ERR_R_MALLOC_FAILURE);
ASN1_INTEGER_free(izone);
return 0;
}
return SXNET_add_id_INTEGER(psx, izone, user, userlen);
}
|
['int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, char *user,\n int userlen)\n{\n ASN1_INTEGER *izone;\n if ((izone = ASN1_INTEGER_new()) == NULL\n || !ASN1_INTEGER_set(izone, lzone)) {\n X509V3err(X509V3_F_SXNET_ADD_ID_ULONG, ERR_R_MALLOC_FAILURE);\n ASN1_INTEGER_free(izone);\n return 0;\n }\n return SXNET_add_id_INTEGER(psx, izone, user, userlen);\n}', 'IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n{\n ASN1_STRING *ret;\n ret = OPENSSL_zalloc(sizeof(*ret));\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->type = type;\n return (ret);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)\n{\n return ASN1_INTEGER_set_int64(a, v);\n}', 'int ASN1_INTEGER_set_int64(ASN1_INTEGER *a, int64_t r)\n{\n return asn1_string_set_int64(a, r, V_ASN1_INTEGER);\n}', 'static int asn1_string_set_int64(ASN1_STRING *a, int64_t r, int itype)\n{\n unsigned char tbuf[sizeof(r)];\n size_t l;\n a->type = itype;\n if (r < 0) {\n l = asn1_put_uint64(tbuf, -r);\n a->type |= V_ASN1_NEG;\n } else {\n l = asn1_put_uint64(tbuf, r);\n a->type &= ~V_ASN1_NEG;\n }\n if (l == 0)\n return 0;\n return ASN1_STRING_set(a, tbuf, l);\n}', 'static size_t asn1_put_uint64(unsigned char *b, uint64_t r)\n{\n if (r >= 0x100) {\n unsigned char *p;\n uint64_t rtmp = r;\n size_t i = 0;\n while (rtmp) {\n rtmp >>= 8;\n i++;\n }\n p = b + i - 1;\n do {\n *p-- = r & 0xFF;\n r >>= 8;\n } while (p >= b);\n return i;\n }\n b[0] = (unsigned char)r;\n return 1;\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n unsigned char *c;\n const char *data = _data;\n if (len < 0) {\n if (data == NULL)\n return (0);\n else\n len = strlen(data);\n }\n if ((str->length < len) || (str->data == NULL)) {\n c = str->data;\n str->data = OPENSSL_realloc(c, len + 1);\n if (str->data == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n str->data = c;\n return (0);\n }\n }\n str->length = len;\n if (data != NULL) {\n memcpy(str->data, data, len);\n str->data[len] = '\\0';\n }\n return (1);\n}", 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *zone, char *user,\n int userlen)\n{\n SXNET *sx = NULL;\n SXNETID *id = NULL;\n if (!psx || !zone || !user) {\n X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER,\n X509V3_R_INVALID_NULL_ARGUMENT);\n return 0;\n }\n if (userlen == -1)\n userlen = strlen(user);\n if (userlen > 64) {\n X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, X509V3_R_USER_TOO_LONG);\n return 0;\n }\n if (*psx == NULL) {\n if ((sx = SXNET_new()) == NULL)\n goto err;\n if (!ASN1_INTEGER_set(sx->version, 0))\n goto err;\n *psx = sx;\n } else\n sx = *psx;\n if (SXNET_get_id_INTEGER(sx, zone)) {\n X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, X509V3_R_DUPLICATE_ZONE_ID);\n return 0;\n }\n if ((id = SXNETID_new()) == NULL)\n goto err;\n if (userlen == -1)\n userlen = strlen(user);\n if (!ASN1_OCTET_STRING_set(id->user, (unsigned char *)user, userlen))\n goto err;\n if (!sk_SXNETID_push(sx->ids, id))\n goto err;\n id->zone = zone;\n return 1;\n err:\n X509V3err(X509V3_F_SXNET_ADD_ID_INTEGER, ERR_R_MALLOC_FAILURE);\n SXNETID_free(id);\n SXNET_free(sx);\n *psx = NULL;\n return 0;\n}']
|
1,366
| 0
|
https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/des/des_enc.c/#L144
|
void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)
{
register DES_LONG l,r,t,u;
#ifdef DES_PTR
register const unsigned char *des_SP=(const unsigned char *)des_SPtrans;
#endif
#ifndef DES_UNROLL
register int i;
#endif
register DES_LONG *s;
r=data[0];
l=data[1];
IP(r,l);
r=ROTATE(r,29)&0xffffffffL;
l=ROTATE(l,29)&0xffffffffL;
s=(DES_LONG *)ks;
if (enc)
{
#ifdef DES_UNROLL
D_ENCRYPT(l,r, 0);
D_ENCRYPT(r,l, 2);
D_ENCRYPT(l,r, 4);
D_ENCRYPT(r,l, 6);
D_ENCRYPT(l,r, 8);
D_ENCRYPT(r,l,10);
D_ENCRYPT(l,r,12);
D_ENCRYPT(r,l,14);
D_ENCRYPT(l,r,16);
D_ENCRYPT(r,l,18);
D_ENCRYPT(l,r,20);
D_ENCRYPT(r,l,22);
D_ENCRYPT(l,r,24);
D_ENCRYPT(r,l,26);
D_ENCRYPT(l,r,28);
D_ENCRYPT(r,l,30);
#else
for (i=0; i<32; i+=8)
{
D_ENCRYPT(l,r,i+0);
D_ENCRYPT(r,l,i+2);
D_ENCRYPT(l,r,i+4);
D_ENCRYPT(r,l,i+6);
}
#endif
}
else
{
#ifdef DES_UNROLL
D_ENCRYPT(l,r,30);
D_ENCRYPT(r,l,28);
D_ENCRYPT(l,r,26);
D_ENCRYPT(r,l,24);
D_ENCRYPT(l,r,22);
D_ENCRYPT(r,l,20);
D_ENCRYPT(l,r,18);
D_ENCRYPT(r,l,16);
D_ENCRYPT(l,r,14);
D_ENCRYPT(r,l,12);
D_ENCRYPT(l,r,10);
D_ENCRYPT(r,l, 8);
D_ENCRYPT(l,r, 6);
D_ENCRYPT(r,l, 4);
D_ENCRYPT(l,r, 2);
D_ENCRYPT(r,l, 0);
#else
for (i=30; i>0; i-=8)
{
D_ENCRYPT(l,r,i-0);
D_ENCRYPT(r,l,i-2);
D_ENCRYPT(l,r,i-4);
D_ENCRYPT(r,l,i-6);
}
#endif
}
l=ROTATE(l,3)&0xffffffffL;
r=ROTATE(r,3)&0xffffffffL;
FP(r,l);
data[0]=l;
data[1]=r;
l=r=t=u=0;
}
|
['void des_string_to_2keys(const char *str, des_cblock *key1, des_cblock *key2)\n\t{\n\tdes_key_schedule ks;\n\tint i,length;\n\tregister unsigned char j;\n\tmemset(key1,0,8);\n\tmemset(key2,0,8);\n\tlength=strlen(str);\n#ifdef OLD_STR_TO_KEY\n\tif (length <= 8)\n\t\t{\n\t\tfor (i=0; i<length; i++)\n\t\t\t{\n\t\t\t(*key2)[i]=(*key1)[i]=(str[i]<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tfor (i=0; i<length; i++)\n\t\t\t{\n\t\t\tif ((i/8)&1)\n\t\t\t\t(*key2)[i%8]^=(str[i]<<1);\n\t\t\telse\n\t\t\t\t(*key1)[i%8]^=(str[i]<<1);\n\t\t\t}\n\t\t}\n#else\n\tfor (i=0; i<length; i++)\n\t\t{\n\t\tj=str[i];\n\t\tif ((i%32) < 16)\n\t\t\t{\n\t\t\tif ((i%16) < 8)\n\t\t\t\t(*key1)[i%8]^=(j<<1);\n\t\t\telse\n\t\t\t\t(*key2)[i%8]^=(j<<1);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tj=((j<<4)&0xf0)|((j>>4)&0x0f);\n\t\t\tj=((j<<2)&0xcc)|((j>>2)&0x33);\n\t\t\tj=((j<<1)&0xaa)|((j>>1)&0x55);\n\t\t\tif ((i%16) < 8)\n\t\t\t\t(*key1)[7-(i%8)]^=j;\n\t\t\telse\n\t\t\t\t(*key2)[7-(i%8)]^=j;\n\t\t\t}\n\t\t}\n\tif (length <= 8) memcpy(key2,key1,8);\n#endif\n\tdes_set_odd_parity(key1);\n\tdes_set_odd_parity(key2);\n\ti=des_check_key;\n\tdes_check_key=0;\n\tdes_set_key(key1,ks);\n\tdes_cbc_cksum((unsigned char*)str,key1,length,ks,key1);\n\tdes_set_key(key2,ks);\n\tdes_cbc_cksum((unsigned char*)str,key2,length,ks,key2);\n\tdes_check_key=i;\n\tmemset(ks,0,sizeof(ks));\n\tdes_set_odd_parity(key1);\n\tdes_set_odd_parity(key2);\n\t}', 'DES_LONG des_cbc_cksum(const unsigned char *in, des_cblock *output,\n\t\tlong length,\n\t\tdes_key_schedule schedule, const_des_cblock *ivec)\n\t{\n\tregister DES_LONG tout0,tout1,tin0,tin1;\n\tregister long l=length;\n\tDES_LONG tin[2];\n\tunsigned char *out = &(*output)[0];\n\tconst unsigned char *iv = &(*ivec)[0];\n\tc2l(iv,tout0);\n\tc2l(iv,tout1);\n\tfor (; l>0; l-=8)\n\t\t{\n\t\tif (l >= 8)\n\t\t\t{\n\t\t\tc2l(in,tin0);\n\t\t\tc2l(in,tin1);\n\t\t\t}\n\t\telse\n\t\t\tc2ln(in,tin0,tin1,l);\n\t\ttin0^=tout0; tin[0]=tin0;\n\t\ttin1^=tout1; tin[1]=tin1;\n\t\tdes_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT);\n\t\ttout0=tin[0];\n\t\ttout1=tin[1];\n\t\t}\n\tif (out != NULL)\n\t\t{\n\t\tl2c(tout0,out);\n\t\tl2c(tout1,out);\n\t\t}\n\ttout0=tin0=tin1=tin[0]=tin[1]=0;\n\treturn(tout1);\n\t}', 'void des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)\n\t{\n\tregister DES_LONG l,r,t,u;\n#ifdef DES_PTR\n\tregister const unsigned char *des_SP=(const unsigned char *)des_SPtrans;\n#endif\n#ifndef DES_UNROLL\n\tregister int i;\n#endif\n\tregister DES_LONG *s;\n\tr=data[0];\n\tl=data[1];\n\tIP(r,l);\n\tr=ROTATE(r,29)&0xffffffffL;\n\tl=ROTATE(l,29)&0xffffffffL;\n\ts=(DES_LONG *)ks;\n\tif (enc)\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r, 0);\n\t\tD_ENCRYPT(r,l, 2);\n\t\tD_ENCRYPT(l,r, 4);\n\t\tD_ENCRYPT(r,l, 6);\n\t\tD_ENCRYPT(l,r, 8);\n\t\tD_ENCRYPT(r,l,10);\n\t\tD_ENCRYPT(l,r,12);\n\t\tD_ENCRYPT(r,l,14);\n\t\tD_ENCRYPT(l,r,16);\n\t\tD_ENCRYPT(r,l,18);\n\t\tD_ENCRYPT(l,r,20);\n\t\tD_ENCRYPT(r,l,22);\n\t\tD_ENCRYPT(l,r,24);\n\t\tD_ENCRYPT(r,l,26);\n\t\tD_ENCRYPT(l,r,28);\n\t\tD_ENCRYPT(r,l,30);\n#else\n\t\tfor (i=0; i<32; i+=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i+0);\n\t\t\tD_ENCRYPT(r,l,i+2);\n\t\t\tD_ENCRYPT(l,r,i+4);\n\t\t\tD_ENCRYPT(r,l,i+6);\n\t\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n#ifdef DES_UNROLL\n\t\tD_ENCRYPT(l,r,30);\n\t\tD_ENCRYPT(r,l,28);\n\t\tD_ENCRYPT(l,r,26);\n\t\tD_ENCRYPT(r,l,24);\n\t\tD_ENCRYPT(l,r,22);\n\t\tD_ENCRYPT(r,l,20);\n\t\tD_ENCRYPT(l,r,18);\n\t\tD_ENCRYPT(r,l,16);\n\t\tD_ENCRYPT(l,r,14);\n\t\tD_ENCRYPT(r,l,12);\n\t\tD_ENCRYPT(l,r,10);\n\t\tD_ENCRYPT(r,l, 8);\n\t\tD_ENCRYPT(l,r, 6);\n\t\tD_ENCRYPT(r,l, 4);\n\t\tD_ENCRYPT(l,r, 2);\n\t\tD_ENCRYPT(r,l, 0);\n#else\n\t\tfor (i=30; i>0; i-=8)\n\t\t\t{\n\t\t\tD_ENCRYPT(l,r,i-0);\n\t\t\tD_ENCRYPT(r,l,i-2);\n\t\t\tD_ENCRYPT(l,r,i-4);\n\t\t\tD_ENCRYPT(r,l,i-6);\n\t\t\t}\n#endif\n\t\t}\n\tl=ROTATE(l,3)&0xffffffffL;\n\tr=ROTATE(r,3)&0xffffffffL;\n\tFP(r,l);\n\tdata[0]=l;\n\tdata[1]=r;\n\tl=r=t=u=0;\n\t}']
|
1,367
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_sqr.c/#L120
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,\n const unsigned char *buf, size_t len,\n BN_CTX *ctx)\n{\n point_conversion_form_t form;\n int y_bit;\n BN_CTX *new_ctx = NULL;\n BIGNUM *x, *y, *yxi;\n size_t field_len, enc_len;\n int ret = 0;\n if (len == 0) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);\n return 0;\n }\n form = buf[0];\n y_bit = form & 1;\n form = form & ~1U;\n if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)\n && (form != POINT_CONVERSION_UNCOMPRESSED)\n && (form != POINT_CONVERSION_HYBRID)) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if (form == 0) {\n if (len != 1) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n return EC_POINT_set_to_infinity(group, point);\n }\n field_len = (EC_GROUP_get_degree(group) + 7) / 8;\n enc_len =\n (form ==\n POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;\n if (len != enc_len) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n yxi = BN_CTX_get(ctx);\n if (yxi == NULL)\n goto err;\n if (!BN_bin2bn(buf + 1, field_len, x))\n goto err;\n if (BN_ucmp(x, group->field) >= 0) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n if (form == POINT_CONVERSION_COMPRESSED) {\n if (!EC_POINT_set_compressed_coordinates_GF2m\n (group, point, x, y_bit, ctx))\n goto err;\n } else {\n if (!BN_bin2bn(buf + 1 + field_len, field_len, y))\n goto err;\n if (BN_ucmp(y, group->field) >= 0) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n if (form == POINT_CONVERSION_HYBRID) {\n if (!group->meth->field_div(group, yxi, y, x, ctx))\n goto err;\n if (y_bit != BN_is_odd(yxi)) {\n ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n }\n if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx))\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n unsigned int i, m;\n unsigned int n;\n BN_ULONG l;\n BIGNUM *bn = NULL;\n if (ret == NULL)\n ret = bn = BN_new();\n if (ret == NULL)\n return NULL;\n bn_check_top(ret);\n for ( ; len > 0 && *s == 0; s++, len--)\n continue;\n n = len;\n if (n == 0) {\n ret->top = 0;\n return ret;\n }\n i = ((n - 1) / BN_BYTES) + 1;\n m = ((n - 1) % (BN_BYTES));\n if (bn_wexpand(ret, (int)i) == NULL) {\n BN_free(bn);\n return NULL;\n }\n ret->top = i;\n ret->neg = 0;\n l = 0;\n while (n--) {\n l = (l << 8L) | *(s++);\n if (m-- == 0) {\n ret->d[--i] = l;\n l = 0;\n m = BN_BYTES - 1;\n }\n }\n bn_correct_top(ret);\n return ret;\n}', 'int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,\n EC_POINT *point, const BIGNUM *x,\n int y_bit, BN_CTX *ctx)\n{\n if (group->meth->point_set_compressed_coordinates == 0\n && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,\n ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n if (group->meth != point->meth) {\n ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,\n EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {\n if (group->meth->field_type == NID_X9_62_prime_field)\n return ec_GFp_simple_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n else\n return ec_GF2m_simple_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n }\n return group->meth->point_set_compressed_coordinates(group, point, x,\n y_bit, ctx);\n}', 'int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n if (!BN_sqr(r, a, ctx))\n return 0;\n return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
1,368
| 0
|
https://github.com/openssl/openssl/blob/3ba25ee86a3758cc659c954b59718d8397030768/crypto/lhash/lhash.c/#L363
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr)\n\t{\n\tSSL **sslp,*ssl;\n\tBIO_SSL *bs;\n\tBIO *dbio,*bio;\n\tlong ret=1;\n\tbs=(BIO_SSL *)b->ptr;\n\tssl=bs->ssl;\n\tif ((ssl == NULL) && (cmd != BIO_C_SET_SSL))\n\t\treturn(0);\n\tswitch (cmd)\n\t\t{\n\tcase BIO_CTRL_RESET:\n\t\tSSL_shutdown(ssl);\n\t\tif (ssl->handshake_func == ssl->method->ssl_connect)\n\t\t\tSSL_set_connect_state(ssl);\n\t\telse if (ssl->handshake_func == ssl->method->ssl_accept)\n\t\t\tSSL_set_accept_state(ssl);\n\t\tSSL_clear(ssl);\n\t\tif (b->next_bio != NULL)\n\t\t\tret=BIO_ctrl(b->next_bio,cmd,num,ptr);\n\t\telse if (ssl->rbio != NULL)\n\t\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\telse\n\t\t\tret=1;\n\t\tbreak;\n\tcase BIO_CTRL_INFO:\n\t\tret=0;\n\t\tbreak;\n\tcase BIO_C_SSL_MODE:\n\t\tif (num)\n\t\t\tSSL_set_connect_state(ssl);\n\t\telse\n\t\t\tSSL_set_accept_state(ssl);\n\t\tbreak;\n\tcase BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:\n\t\tret=bs->renegotiate_timeout;\n\t\tif (num < 60) num=5;\n\t\tbs->renegotiate_timeout=(unsigned long)num;\n\t\tbs->last_time=(unsigned long)time(NULL);\n\t\tbreak;\n\tcase BIO_C_SET_SSL_RENEGOTIATE_BYTES:\n\t\tret=bs->renegotiate_count;\n\t\tif ((long)num >=512)\n\t\t\tbs->renegotiate_count=(unsigned long)num;\n\t\tbreak;\n\tcase BIO_C_GET_SSL_NUM_RENEGOTIATES:\n\t\tret=bs->num_renegotiates;\n\t\tbreak;\n\tcase BIO_C_SET_SSL:\n\t\tif (ssl != NULL)\n\t\t\tssl_free(b);\n\t\tb->shutdown=(int)num;\n\t\tssl=(SSL *)ptr;\n\t\t((BIO_SSL *)b->ptr)->ssl=ssl;\n\t\tbio=SSL_get_rbio(ssl);\n\t\tif (bio != NULL)\n\t\t\t{\n\t\t\tif (b->next_bio != NULL)\n\t\t\t\tBIO_push(bio,b->next_bio);\n\t\t\tb->next_bio=bio;\n\t\t\tCRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO);\n\t\t\t}\n\t\tb->init=1;\n\t\tbreak;\n\tcase BIO_C_GET_SSL:\n\t\tif (ptr != NULL)\n\t\t\t{\n\t\t\tsslp=(SSL **)ptr;\n\t\t\t*sslp=ssl;\n\t\t\t}\n\t\telse\n\t\t\tret=0;\n\t\tbreak;\n\tcase BIO_CTRL_GET_CLOSE:\n\t\tret=b->shutdown;\n\t\tbreak;\n\tcase BIO_CTRL_SET_CLOSE:\n\t\tb->shutdown=(int)num;\n\t\tbreak;\n\tcase BIO_CTRL_WPENDING:\n\t\tret=BIO_ctrl(ssl->wbio,cmd,num,ptr);\n\t\tbreak;\n\tcase BIO_CTRL_PENDING:\n\t\tret=SSL_pending(ssl);\n\t\tif (ret == 0)\n\t\t\tret=BIO_pending(ssl->rbio);\n\t\tbreak;\n\tcase BIO_CTRL_FLUSH:\n\t\tBIO_clear_retry_flags(b);\n\t\tret=BIO_ctrl(ssl->wbio,cmd,num,ptr);\n\t\tBIO_copy_next_retry(b);\n\t\tbreak;\n\tcase BIO_CTRL_PUSH:\n\t\tif ((b->next_bio != NULL) && (b->next_bio != ssl->rbio))\n\t\t\t{\n\t\t\tSSL_set_bio(ssl,b->next_bio,b->next_bio);\n\t\t\tCRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO);\n\t\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_POP:\n\t\tif (ssl->rbio != ssl->wbio)\n\t\t\t{\n\t\t\tBIO_free_all(ssl->wbio);\n\t\t\t}\n\t\tssl->wbio=NULL;\n\t\tssl->rbio=NULL;\n\t\tbreak;\n\tcase BIO_C_DO_STATE_MACHINE:\n\t\tBIO_clear_retry_flags(b);\n\t\tb->retry_reason=0;\n\t\tret=(int)SSL_do_handshake(ssl);\n\t\tswitch (SSL_get_error(ssl,(int)ret))\n\t\t\t{\n\t\tcase SSL_ERROR_WANT_READ:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tbreak;\n\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tbreak;\n\t\tcase SSL_ERROR_WANT_CONNECT:\n\t\t\tBIO_set_flags(b,\n\t\t\t\tBIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);\n\t\t\tb->retry_reason=b->next_bio->retry_reason;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_DUP:\n\t\tdbio=(BIO *)ptr;\n\t\tif (((BIO_SSL *)dbio->ptr)->ssl != NULL)\n\t\t\tSSL_free(((BIO_SSL *)dbio->ptr)->ssl);\n\t\t((BIO_SSL *)dbio->ptr)->ssl=SSL_dup(ssl);\n\t\t((BIO_SSL *)dbio->ptr)->renegotiate_count=\n\t\t\t((BIO_SSL *)b->ptr)->renegotiate_count;\n\t\t((BIO_SSL *)dbio->ptr)->byte_count=\n\t\t\t((BIO_SSL *)b->ptr)->byte_count;\n\t\t((BIO_SSL *)dbio->ptr)->renegotiate_timeout=\n\t\t\t((BIO_SSL *)b->ptr)->renegotiate_timeout;\n\t\t((BIO_SSL *)dbio->ptr)->last_time=\n\t\t\t((BIO_SSL *)b->ptr)->last_time;\n\t\tret=(((BIO_SSL *)dbio->ptr)->ssl != NULL);\n\t\tbreak;\n\tcase BIO_C_GET_FD:\n\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\tbreak;\n\tcase BIO_CTRL_SET_CALLBACK:\n\t\t{\n#if 0\n\t\tBIOerr(SSL_F_SSL_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\tret = -1;\n#else\n\t\tret=0;\n#endif\n\t\t}\n\t\tbreak;\n\tcase BIO_CTRL_GET_CALLBACK:\n\t\t{\n\t\tvoid (**fptr)();\n\t\tfptr=(void (**)())ptr;\n\t\t*fptr=SSL_get_info_callback(ssl);\n\t\t}\n\t\tbreak;\n\tdefault:\n\t\tret=BIO_ctrl(ssl->rbio,cmd,num,ptr);\n\t\tbreak;\n\t\t}\n\treturn(ret);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tint state;\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#else\n\tif (s->new_session)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR);\n\t\treturn 0;\n\t\t}\n#endif\n\tstate=s->state;\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n#if 0\n\ts->read_ahead=s->ctx->read_ahead;\n#endif\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->first_packet=0;\n#if 1\n\tif ((s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tconst void *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn((void *)ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)OPENSSL_realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,369
| 0
|
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/camellia/camellia.c/#L362
|
int Camellia_Ekeygen(int keyBitLength, const u8 *rawKey, KEY_TABLE_TYPE k)
{
register u32 s0,s1,s2,s3;
k[0] = s0 = GETU32(rawKey);
k[1] = s1 = GETU32(rawKey+4);
k[2] = s2 = GETU32(rawKey+8);
k[3] = s3 = GETU32(rawKey+12);
if (keyBitLength != 128)
{
k[8] = s0 = GETU32(rawKey+16);
k[9] = s1 = GETU32(rawKey+20);
if (keyBitLength == 192)
{
k[10] = s2 = ~s0;
k[11] = s3 = ~s1;
}
else
{
k[10] = s2 = GETU32(rawKey+24);
k[11] = s3 = GETU32(rawKey+28);
}
s0 ^= k[0], s1 ^= k[1], s2 ^= k[2], s3 ^= k[3];
}
Camellia_Feistel(s0,s1,s2,s3,SIGMA+0);
Camellia_Feistel(s2,s3,s0,s1,SIGMA+2);
s0 ^= k[0], s1 ^= k[1], s2 ^= k[2], s3 ^= k[3];
Camellia_Feistel(s0,s1,s2,s3,SIGMA+4);
Camellia_Feistel(s2,s3,s0,s1,SIGMA+6);
if (keyBitLength == 128)
{
k[ 4] = s0, k[ 5] = s1, k[ 6] = s2, k[ 7] = s3;
RotLeft128(s0,s1,s2,s3,15);
k[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;
RotLeft128(s0,s1,s2,s3,15);
k[16] = s0, k[17] = s1, k[18] = s2, k[19] = s3;
RotLeft128(s0,s1,s2,s3,15);
k[24] = s0, k[25] = s1;
RotLeft128(s0,s1,s2,s3,15);
k[28] = s0, k[29] = s1, k[30] = s2, k[31] = s3;
RotLeft128(s1,s2,s3,s0,2);
k[40] = s1, k[41] = s2, k[42] = s3, k[43] = s0;
RotLeft128(s1,s2,s3,s0,17);
k[48] = s1, k[49] = s2, k[50] = s3, k[51] = s0;
s0 = k[ 0], s1 = k[ 1], s2 = k[ 2], s3 = k[ 3];
RotLeft128(s0,s1,s2,s3,15);
k[ 8] = s0, k[ 9] = s1, k[10] = s2, k[11] = s3;
RotLeft128(s0,s1,s2,s3,30);
k[20] = s0, k[21] = s1, k[22] = s2, k[23] = s3;
RotLeft128(s0,s1,s2,s3,15);
k[26] = s2, k[27] = s3;
RotLeft128(s0,s1,s2,s3,17);
k[32] = s0, k[33] = s1, k[34] = s2, k[35] = s3;
RotLeft128(s0,s1,s2,s3,17);
k[36] = s0, k[37] = s1, k[38] = s2, k[39] = s3;
RotLeft128(s0,s1,s2,s3,17);
k[44] = s0, k[45] = s1, k[46] = s2, k[47] = s3;
return 3;
}
else
{
k[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;
s0 ^= k[8], s1 ^= k[9], s2 ^=k[10], s3 ^=k[11];
Camellia_Feistel(s0,s1,s2,s3,(SIGMA+8));
Camellia_Feistel(s2,s3,s0,s1,(SIGMA+10));
k[ 4] = s0, k[ 5] = s1, k[ 6] = s2, k[ 7] = s3;
RotLeft128(s0,s1,s2,s3,30);
k[20] = s0, k[21] = s1, k[22] = s2, k[23] = s3;
RotLeft128(s0,s1,s2,s3,30);
k[40] = s0, k[41] = s1, k[42] = s2, k[43] = s3;
RotLeft128(s1,s2,s3,s0,19);
k[64] = s1, k[65] = s2, k[66] = s3, k[67] = s0;
s0 = k[ 8], s1 = k[ 9], s2 = k[10], s3 = k[11];
RotLeft128(s0,s1,s2,s3,15);
k[ 8] = s0, k[ 9] = s1, k[10] = s2, k[11] = s3;
RotLeft128(s0,s1,s2,s3,15);
k[16] = s0, k[17] = s1, k[18] = s2, k[19] = s3;
RotLeft128(s0,s1,s2,s3,30);
k[36] = s0, k[37] = s1, k[38] = s2, k[39] = s3;
RotLeft128(s1,s2,s3,s0,2);
k[52] = s1, k[53] = s2, k[54] = s3, k[55] = s0;
s0 = k[12], s1 = k[13], s2 = k[14], s3 = k[15];
RotLeft128(s0,s1,s2,s3,15);
k[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;
RotLeft128(s0,s1,s2,s3,30);
k[28] = s0, k[29] = s1, k[30] = s2, k[31] = s3;
k[48] = s1, k[49] = s2, k[50] = s3, k[51] = s0;
RotLeft128(s1,s2,s3,s0,17);
k[56] = s1, k[57] = s2, k[58] = s3, k[59] = s0;
s0 = k[ 0], s1 = k[ 1], s2 = k[ 2], s3 = k[ 3];
RotLeft128(s1,s2,s3,s0,13);
k[24] = s1, k[25] = s2, k[26] = s3, k[27] = s0;
RotLeft128(s1,s2,s3,s0,15);
k[32] = s1, k[33] = s2, k[34] = s3, k[35] = s0;
RotLeft128(s1,s2,s3,s0,17);
k[44] = s1, k[45] = s2, k[46] = s3, k[47] = s0;
RotLeft128(s2,s3,s0,s1,2);
k[60] = s2, k[61] = s3, k[62] = s0, k[63] = s1;
return 4;
}
}
|
['int MAIN(int argc, char **argv)\n\t{\n#ifndef OPENSSL_NO_ENGINE\n\tENGINE *e = NULL;\n#endif\n\tunsigned char *buf=NULL,*buf2=NULL;\n\tint mret=1;\n\tlong count=0,save_count=0;\n\tint i,j,k;\n#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n\tlong rsa_count;\n#endif\n#ifndef OPENSSL_NO_RSA\n\tunsigned rsa_num;\n#endif\n\tunsigned char md[EVP_MAX_MD_SIZE];\n#ifndef OPENSSL_NO_MD2\n\tunsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tunsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD4\n\tunsigned char md4[MD4_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD5\n\tunsigned char md5[MD5_DIGEST_LENGTH];\n\tunsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA\n\tunsigned char sha[SHA_DIGEST_LENGTH];\n#ifndef OPENSSL_NO_SHA256\n\tunsigned char sha256[SHA256_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA512\n\tunsigned char sha512[SHA512_DIGEST_LENGTH];\n#endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n\tunsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tunsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_KEY rc4_ks;\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_KEY rc5_ks;\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_KEY rc2_ks;\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tIDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef OPENSSL_NO_SEED\n\tSEED_KEY_SCHEDULE seed_ks;\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_KEY bf_ks;\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_KEY cast_ks;\n#endif\n\tstatic const unsigned char key16[16]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n#ifndef OPENSSL_NO_AES\n\tstatic const unsigned char key24[24]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tstatic const unsigned char key32[32]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,\n\t\t 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tstatic const unsigned char ckey24[24]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tstatic const unsigned char ckey32[32]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,\n\t\t 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};\n#endif\n#ifndef OPENSSL_NO_AES\n#define MAX_BLOCK_SIZE 128\n#else\n#define MAX_BLOCK_SIZE 64\n#endif\n\tunsigned char DES_iv[8];\n\tunsigned char iv[2*MAX_BLOCK_SIZE/8];\n#ifndef OPENSSL_NO_DES\n\tDES_cblock *buf_as_des_cblock = NULL;\n\tstatic DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};\n\tstatic DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tDES_key_schedule sch;\n\tDES_key_schedule sch2;\n\tDES_key_schedule sch3;\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_KEY aes_ks1, aes_ks2, aes_ks3;\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tCAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n#endif\n#define\tD_MD2\t\t0\n#define\tD_MDC2\t\t1\n#define\tD_MD4\t\t2\n#define\tD_MD5\t\t3\n#define\tD_HMAC\t\t4\n#define\tD_SHA1\t\t5\n#define D_RMD160\t6\n#define\tD_RC4\t\t7\n#define\tD_CBC_DES\t8\n#define\tD_EDE3_DES\t9\n#define\tD_CBC_IDEA\t10\n#define\tD_CBC_SEED\t11\n#define\tD_CBC_RC2\t12\n#define\tD_CBC_RC5\t13\n#define\tD_CBC_BF\t14\n#define\tD_CBC_CAST\t15\n#define D_CBC_128_AES\t16\n#define D_CBC_192_AES\t17\n#define D_CBC_256_AES\t18\n#define D_CBC_128_CML 19\n#define D_CBC_192_CML 20\n#define D_CBC_256_CML 21\n#define D_EVP\t\t22\n#define D_SHA256\t23\n#define D_SHA512\t24\n#define D_WHIRLPOOL\t25\n#define D_IGE_128_AES 26\n#define D_IGE_192_AES 27\n#define D_IGE_256_AES 28\n\tdouble d=0.0;\n\tlong c[ALGOR_NUM][SIZE_NUM];\n#define\tR_DSA_512\t0\n#define\tR_DSA_1024\t1\n#define\tR_DSA_2048\t2\n#define\tR_RSA_512\t0\n#define\tR_RSA_1024\t1\n#define\tR_RSA_2048\t2\n#define\tR_RSA_4096\t3\n#define R_EC_P160 0\n#define R_EC_P192 1\n#define R_EC_P224 2\n#define R_EC_P256 3\n#define R_EC_P384 4\n#define R_EC_P521 5\n#define R_EC_K163 6\n#define R_EC_K233 7\n#define R_EC_K283 8\n#define R_EC_K409 9\n#define R_EC_K571 10\n#define R_EC_B163 11\n#define R_EC_B233 12\n#define R_EC_B283 13\n#define R_EC_B409 14\n#define R_EC_B571 15\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa_key[RSA_NUM];\n\tlong rsa_c[RSA_NUM][2];\n\tstatic unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};\n\tstatic unsigned char *rsa_data[RSA_NUM]=\n\t\t{test512,test1024,test2048,test4096};\n\tstatic int rsa_data_length[RSA_NUM]={\n\t\tsizeof(test512),sizeof(test1024),\n\t\tsizeof(test2048),sizeof(test4096)};\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsa_key[DSA_NUM];\n\tlong dsa_c[DSA_NUM][2];\n\tstatic unsigned int dsa_bits[DSA_NUM]={512,1024,2048};\n#endif\n#ifndef OPENSSL_NO_EC\n\tstatic unsigned int test_curves[EC_NUM] =\n\t{\n\tNID_secp160r1,\n\tNID_X9_62_prime192v1,\n\tNID_secp224r1,\n\tNID_X9_62_prime256v1,\n\tNID_secp384r1,\n\tNID_secp521r1,\n\tNID_sect163k1,\n\tNID_sect233k1,\n\tNID_sect283k1,\n\tNID_sect409k1,\n\tNID_sect571k1,\n\tNID_sect163r2,\n\tNID_sect233r1,\n\tNID_sect283r1,\n\tNID_sect409r1,\n\tNID_sect571r1\n\t};\n\tstatic const char * test_curves_names[EC_NUM] =\n\t{\n\t"secp160r1",\n\t"nistp192",\n\t"nistp224",\n\t"nistp256",\n\t"nistp384",\n\t"nistp521",\n\t"nistk163",\n\t"nistk233",\n\t"nistk283",\n\t"nistk409",\n\t"nistk571",\n\t"nistb163",\n\t"nistb233",\n\t"nistb283",\n\t"nistb409",\n\t"nistb571"\n\t};\n\tstatic int test_curves_bits[EC_NUM] =\n {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tunsigned char ecdsasig[256];\n\tunsigned int ecdsasiglen;\n\tEC_KEY *ecdsa[EC_NUM];\n\tlong ecdsa_c[EC_NUM][2];\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tEC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n\tunsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n\tint secret_size_a, secret_size_b;\n\tint ecdh_checks = 0;\n\tint secret_idx = 0;\n\tlong ecdh_c[EC_NUM][2];\n#endif\n\tint rsa_doit[RSA_NUM];\n\tint dsa_doit[DSA_NUM];\n#ifndef OPENSSL_NO_ECDSA\n\tint ecdsa_doit[EC_NUM];\n#endif\n#ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n#endif\n\tint doit[ALGOR_NUM];\n\tint pr_header=0;\n\tconst EVP_CIPHER *evp_cipher=NULL;\n\tconst EVP_MD *evp_md=NULL;\n\tint decrypt=0;\n#ifdef HAVE_FORK\n\tint multi=0;\n#endif\n#ifndef TIMES\n\tusertime=-1;\n#endif\n\tapps_startup();\n\tmemset(results, 0, sizeof(results));\n#ifndef OPENSSL_NO_DSA\n\tmemset(dsa_key,0,sizeof(dsa_key));\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t\t{\n\t\tecdh_a[i] = NULL;\n\t\tecdh_b[i] = NULL;\n\t\t}\n#endif\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_key,0,sizeof(rsa_key));\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_key[i]=NULL;\n#endif\n\tif ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_DES\n\tbuf_as_des_cblock = (DES_cblock *)buf;\n#endif\n\tif ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tmemset(c,0,sizeof(c));\n\tmemset(DES_iv,0,sizeof(DES_iv));\n\tmemset(iv,0,sizeof(iv));\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tdoit[i]=0;\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_doit[i]=0;\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tdsa_doit[i]=0;\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++)\n\t\tecdsa_doit[i]=0;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t\tecdh_doit[i]=0;\n#endif\n\tj=0;\n\targc--;\n\targv++;\n\twhile (argc)\n\t\t{\n\t\tif\t((argc > 0) && (strcmp(*argv,"-elapsed") == 0))\n\t\t\t{\n\t\t\tusertime = 0;\n\t\t\tj--;\n\t\t\t}\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-evp") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no EVP given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tevp_cipher=EVP_get_cipherbyname(*argv);\n\t\t\tif(!evp_cipher)\n\t\t\t\t{\n\t\t\t\tevp_md=EVP_get_digestbyname(*argv);\n\t\t\t\t}\n\t\t\tif(!evp_cipher && !evp_md)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"%s is an unknown cipher or digest\\n",*argv);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdoit[D_EVP]=1;\n\t\t\t}\n\t\telse if (argc > 0 && !strcmp(*argv,"-decrypt"))\n\t\t\t{\n\t\t\tdecrypt=1;\n\t\t\tj--;\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-engine") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no engine given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n e = setup_engine(bio_err, *argv, 0);\n\t\t\tj--;\n\t\t\t}\n#endif\n#ifdef HAVE_FORK\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-multi") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no multi count given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tmulti=atoi(argv[0]);\n\t\t\tif(multi <= 0)\n\t\t\t {\n\t\t\t\tBIO_printf(bio_err,"bad multi count\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tj--;\n\t\t\t}\n#endif\n\t\telse if (argc > 0 && !strcmp(*argv,"-mr"))\n\t\t\t{\n\t\t\tmr=1;\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#ifndef OPENSSL_NO_MD2\n\t\tif\t(strcmp(*argv,"md2") == 0) doit[D_MD2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tif (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tif (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SHA\n\t\t\tif (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha") == 0)\tdoit[D_SHA1]=1,\n\t\t\t\t\t\t\tdoit[D_SHA256]=1,\n\t\t\t\t\t\t\tdoit[D_SHA512]=1;\n\t\telse\n#ifndef OPENSSL_NO_SHA256\n\t\t\tif (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\t\tif (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;\n\t\telse\n#endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n\t\t\tif (strcmp(*argv,"whirlpool") == 0) doit[D_WHIRLPOOL]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\t\t\tif (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tif (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;\n\t\telse\tif (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;\n\t\telse if (strcmp(*argv,"aes-128-ige") == 0) doit[D_IGE_128_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-192-ige") == 0) doit[D_IGE_192_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-256-ige") == 0) doit[D_IGE_256_AES]=1;\n else\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tif (strcmp(*argv,"camellia-128-cbc") == 0) doit[D_CBC_128_CML]=1;\n\t\telse if (strcmp(*argv,"camellia-192-cbc") == 0) doit[D_CBC_192_CML]=1;\n\t\telse if (strcmp(*argv,"camellia-256-cbc") == 0) doit[D_CBC_256_CML]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n#if 0\n\t\t\tif (strcmp(*argv,"rsaref") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#ifndef RSA_NULL\n\t\t\tif (strcmp(*argv,"openssl") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_method(RSA_PKCS1_SSLeay());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#endif\n\t\t if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;\n\t\telse if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;\n\t\telse if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;\n\t\telse if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;\n\t\telse if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;\n\t\telse\n#ifndef OPENSSL_NO_RC2\n\t\t if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;\n\t\telse if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;\n\t\telse if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;\n\t\telse if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SEED\n\t\t if (strcmp(*argv,"seed-cbc") == 0) doit[D_CBC_SEED]=1;\n\t\telse if (strcmp(*argv,"seed") == 0) doit[D_CBC_SEED]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAST\n\t\t if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_DES]=1;\n\t\t\tdoit[D_EDE3_DES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_128_AES]=1;\n\t\t\tdoit[D_CBC_192_AES]=1;\n\t\t\tdoit[D_CBC_256_AES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tif (strcmp(*argv,"camellia") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_128_CML]=1;\n\t\t\tdoit[D_CBC_192_CML]=1;\n\t\t\tdoit[D_CBC_256_CML]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tif (strcmp(*argv,"rsa") == 0)\n\t\t\t{\n\t\t\trsa_doit[R_RSA_512]=1;\n\t\t\trsa_doit[R_RSA_1024]=1;\n\t\t\trsa_doit[R_RSA_2048]=1;\n\t\t\trsa_doit[R_RSA_4096]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tif (strcmp(*argv,"dsa") == 0)\n\t\t\t{\n\t\t\tdsa_doit[R_DSA_512]=1;\n\t\t\tdsa_doit[R_DSA_1024]=1;\n\t\t\tdsa_doit[R_DSA_2048]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;\n\t\telse if (strcmp(*argv,"ecdsap192") == 0) ecdsa_doit[R_EC_P192]=2;\n\t\telse if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;\n\t\telse if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;\n\t\telse if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;\n\t\telse if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;\n\t\telse if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;\n\t\telse if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;\n\t\telse if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;\n\t\telse if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;\n\t\telse if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;\n\t\telse if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;\n\t\telse if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;\n\t\telse if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;\n\t\telse if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;\n\t\telse if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;\n\t\telse if (strcmp(*argv,"ecdsa") == 0)\n\t\t\t{\n\t\t\tfor (i=0; i < EC_NUM; i++)\n\t\t\t\tecdsa_doit[i]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;\n\t\telse if (strcmp(*argv,"ecdhp192") == 0) ecdh_doit[R_EC_P192]=2;\n\t\telse if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;\n\t\telse if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;\n\t\telse if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;\n\t\telse if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;\n\t\telse if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;\n\t\telse if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;\n\t\telse if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;\n\t\telse if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;\n\t\telse if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;\n\t\telse if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;\n\t\telse if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;\n\t\telse if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;\n\t\telse if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;\n\t\telse if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;\n\t\telse if (strcmp(*argv,"ecdh") == 0)\n\t\t\t{\n\t\t\tfor (i=0; i < EC_NUM; i++)\n\t\t\t\tecdh_doit[i]=1;\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Error: bad option or value\\n");\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available values:\\n");\n#ifndef OPENSSL_NO_MD2\n\t\t\tBIO_printf(bio_err,"md2 ");\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tBIO_printf(bio_err,"mdc2 ");\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tBIO_printf(bio_err,"md4 ");\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tBIO_printf(bio_err,"md5 ");\n#ifndef OPENSSL_NO_HMAC\n\t\t\tBIO_printf(bio_err,"hmac ");\n#endif\n#endif\n#ifndef OPENSSL_NO_SHA1\n\t\t\tBIO_printf(bio_err,"sha1 ");\n#endif\n#ifndef OPENSSL_NO_SHA256\n\t\t\tBIO_printf(bio_err,"sha256 ");\n#endif\n#ifndef OPENSSL_NO_SHA512\n\t\t\tBIO_printf(bio_err,"sha512 ");\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n\t\t\tBIO_printf(bio_err,"whirlpool");\n#endif\n#ifndef OPENSSL_NO_RIPEMD160\n\t\t\tBIO_printf(bio_err,"rmd160");\n#endif\n#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160) || \\\n !defined(OPENSSL_NO_WHIRLPOOL)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea-cbc ");\n#endif\n#ifndef OPENSSL_NO_SEED\n\t\t\tBIO_printf(bio_err,"seed-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t\tBIO_printf(bio_err,"rc5-cbc ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"bf-cbc");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des-cbc des-ede3 ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");\n\t\t\tBIO_printf(bio_err,"aes-128-ige aes-192-ige aes-256-ige ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tBIO_printf(bio_err,"rc4");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\\n");\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tBIO_printf(bio_err,"dsa512 dsa1024 dsa2048\\n");\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t\tBIO_printf(bio_err,"ecdsap160 ecdsap192 ecdsap224 ecdsap256 ecdsap384 ecdsap521\\n");\n\t\t\tBIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n\t\t\tBIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n\t\t\tBIO_printf(bio_err,"ecdsa\\n");\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\tBIO_printf(bio_err,"ecdhp160 ecdhp192 ecdhp224 ecdhp256 ecdhp384 ecdhp521\\n");\n\t\t\tBIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n\t\t\tBIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n\t\t\tBIO_printf(bio_err,"ecdh\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea ");\n#endif\n#ifndef OPENSSL_NO_SEED\n\t\t\tBIO_printf(bio_err,"seed ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2 ");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\t\t\tBIO_printf(bio_err,"camellia ");\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"blowfish");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \\\n !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \\\n !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \\\n !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available options:\\n");\n#if defined(TIMES) || defined(USE_TOD)\n\t\t\tBIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\\n");\n#endif\n#ifndef OPENSSL_NO_ENGINE\n\t\t\tBIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"-evp e use EVP e.\\n");\n\t\t\tBIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\\n");\n\t\t\tBIO_printf(bio_err,"-mr produce machine readable output.\\n");\n#ifdef HAVE_FORK\n\t\t\tBIO_printf(bio_err,"-multi n run n benchmarks in parallel.\\n");\n#endif\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\tj++;\n\t\t}\n#ifdef HAVE_FORK\n\tif(multi && do_multi(multi))\n\t\tgoto show_res;\n#endif\n\tif (j == 0)\n\t\t{\n\t\tfor (i=0; i<ALGOR_NUM; i++)\n\t\t\t{\n\t\t\tif (i != D_EVP)\n\t\t\t\tdoit[i]=1;\n\t\t\t}\n\t\tfor (i=0; i<RSA_NUM; i++)\n\t\t\trsa_doit[i]=1;\n\t\tfor (i=0; i<DSA_NUM; i++)\n\t\t\tdsa_doit[i]=1;\n\t\t}\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tif (doit[i]) pr_header++;\n\tif (usertime == 0 && !mr)\n\t\tBIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\\n");\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\t{\n\t\tconst unsigned char *p;\n\t\tp=rsa_data[i];\n\t\trsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);\n\t\tif (rsa_key[i] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"internal error loading RSA key number %d\\n",i);\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,mr ? "+RK:%d:"\n\t\t\t\t : "Loaded RSA key, %d bit modulus and e= 0x",\n\t\t\t\t BN_num_bits(rsa_key[i]->n));\n\t\t\tBN_print(bio_err,rsa_key[i]->e);\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t}\n#endif\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_key[0]=get_dsa512();\n\tdsa_key[1]=get_dsa1024();\n\tdsa_key[2]=get_dsa2048();\n#endif\n#ifndef OPENSSL_NO_DES\n\tDES_set_key_unchecked(&key,&sch);\n\tDES_set_key_unchecked(&key2,&sch2);\n\tDES_set_key_unchecked(&key3,&sch3);\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_set_encrypt_key(key16,128,&aes_ks1);\n\tAES_set_encrypt_key(key24,192,&aes_ks2);\n\tAES_set_encrypt_key(key32,256,&aes_ks3);\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tCamellia_set_key(key16,128,&camellia_ks1);\n\tCamellia_set_key(ckey24,192,&camellia_ks2);\n\tCamellia_set_key(ckey32,256,&camellia_ks3);\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tidea_set_encrypt_key(key16,&idea_ks);\n#endif\n#ifndef OPENSSL_NO_SEED\n\tSEED_set_key(key16,&seed_ks);\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_set_key(&rc4_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_set_key(&rc2_ks,16,key16,128);\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_set_key(&rc5_ks,16,key16,12);\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_set_key(&bf_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_set_key(&cast_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_c,0,sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n#ifndef OPENSSL_NO_DES\n\tBIO_printf(bio_err,"First we calculate the approximate speed ...\\n");\n\tcount=10;\n\tdo\t{\n\t\tlong it;\n\t\tcount*=2;\n\t\tTime_F(START);\n\t\tfor (it=count; it; it--)\n\t\t\tDES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,\n\t\t\t\t&sch,DES_ENCRYPT);\n\t\td=Time_F(STOP);\n\t\t} while (d <3);\n\tsave_count=count;\n\tc[D_MD2][0]=count/10;\n\tc[D_MDC2][0]=count/10;\n\tc[D_MD4][0]=count;\n\tc[D_MD5][0]=count;\n\tc[D_HMAC][0]=count;\n\tc[D_SHA1][0]=count;\n\tc[D_RMD160][0]=count;\n\tc[D_RC4][0]=count*5;\n\tc[D_CBC_DES][0]=count;\n\tc[D_EDE3_DES][0]=count/3;\n\tc[D_CBC_IDEA][0]=count;\n\tc[D_CBC_SEED][0]=count;\n\tc[D_CBC_RC2][0]=count;\n\tc[D_CBC_RC5][0]=count;\n\tc[D_CBC_BF][0]=count;\n\tc[D_CBC_CAST][0]=count;\n\tc[D_CBC_128_AES][0]=count;\n\tc[D_CBC_192_AES][0]=count;\n\tc[D_CBC_256_AES][0]=count;\n\tc[D_CBC_128_CML][0]=count;\n\tc[D_CBC_192_CML][0]=count;\n\tc[D_CBC_256_CML][0]=count;\n\tc[D_SHA256][0]=count;\n\tc[D_SHA512][0]=count;\n\tc[D_WHIRLPOOL][0]=count;\n\tc[D_IGE_128_AES][0]=count;\n\tc[D_IGE_192_AES][0]=count;\n\tc[D_IGE_256_AES][0]=count;\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tc[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];\n\t\tc[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];\n\t\tc[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];\n\t\tc[D_WHIRLPOOL][i]=c[D_WHIRLPOOL][0]*4*lengths[0]/lengths[i];\n\t\t}\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tlong l0,l1;\n\t\tl0=(long)lengths[i-1];\n\t\tl1=(long)lengths[i];\n\t\tc[D_RC4][i]=c[D_RC4][i-1]*l0/l1;\n\t\tc[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;\n\t\tc[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;\n\t\tc[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;\n\t\tc[D_CBC_SEED][i]=c[D_CBC_SEED][i-1]*l0/l1;\n\t\tc[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;\n\t\tc[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;\n\t\tc[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;\n\t\tc[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;\n\t\tc[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;\n\t\tc[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;\n\t\tc[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;\n \t\tc[D_CBC_128_CML][i]=c[D_CBC_128_CML][i-1]*l0/l1;\n\t\tc[D_CBC_192_CML][i]=c[D_CBC_192_CML][i-1]*l0/l1;\n\t\tc[D_CBC_256_CML][i]=c[D_CBC_256_CML][i-1]*l0/l1;\n\t\tc[D_IGE_128_AES][i]=c[D_IGE_128_AES][i-1]*l0/l1;\n\t\tc[D_IGE_192_AES][i]=c[D_IGE_192_AES][i-1]*l0/l1;\n\t\tc[D_IGE_256_AES][i]=c[D_IGE_256_AES][i-1]*l0/l1;\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\trsa_c[R_RSA_512][0]=count/2000;\n\trsa_c[R_RSA_512][1]=count/400;\n\tfor (i=1; i<RSA_NUM; i++)\n\t\t{\n\t\trsa_c[i][0]=rsa_c[i-1][0]/8;\n\t\trsa_c[i][1]=rsa_c[i-1][1]/4;\n\t\tif ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n\t\t\trsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (rsa_c[i][0] == 0)\n\t\t\t\t{\n\t\t\t\trsa_c[i][0]=1;\n\t\t\t\trsa_c[i][1]=20;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_c[R_DSA_512][0]=count/1000;\n\tdsa_c[R_DSA_512][1]=count/1000/2;\n\tfor (i=1; i<DSA_NUM; i++)\n\t\t{\n\t\tdsa_c[i][0]=dsa_c[i-1][0]/4;\n\t\tdsa_c[i][1]=dsa_c[i-1][1]/4;\n\t\tif ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n\t\t\tdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (dsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tdsa_c[i][0]=1;\n\t\t\t\tdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tecdsa_c[R_EC_P160][0]=count/1000;\n\tecdsa_c[R_EC_P160][1]=count/1000/2;\n\tfor (i=R_EC_P192; i<=R_EC_P521; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdsa_c[R_EC_K163][0]=count/1000;\n\tecdsa_c[R_EC_K163][1]=count/1000/2;\n\tfor (i=R_EC_K233; i<=R_EC_K571; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdsa_c[R_EC_B163][0]=count/1000;\n\tecdsa_c[R_EC_B163][1]=count/1000/2;\n\tfor (i=R_EC_B233; i<=R_EC_B571; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tecdh_c[R_EC_P160][0]=count/1000;\n\tecdh_c[R_EC_P160][1]=count/1000;\n\tfor (i=R_EC_P192; i<=R_EC_P521; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdh_c[R_EC_K163][0]=count/1000;\n\tecdh_c[R_EC_K163][1]=count/1000;\n\tfor (i=R_EC_K233; i<=R_EC_K571; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdh_c[R_EC_B163][0]=count/1000;\n\tecdh_c[R_EC_B163][1]=count/1000;\n\tfor (i=R_EC_B233; i<=R_EC_B571; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#define COND(d)\t(count < (d))\n#define COUNT(d) (d)\n#else\n# error "You cannot disable DES on systems without SIGALRM."\n#endif\n#else\n#define COND(c)\t(run)\n#define COUNT(d) (count)\n#ifndef _WIN32\n\tsignal(SIGALRM,sig_done);\n#endif\n#endif\n#ifndef OPENSSL_NO_MD2\n\tif (doit[D_MD2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD2],c[D_MD2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tif (doit[D_MDC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MDC2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MDC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD4\n\tif (doit[D_MD4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD4],c[D_MD4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD4][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD5\n\tif (doit[D_MD5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD5],c[D_MD5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD5][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n\tif (doit[D_HMAC])\n\t\t{\n\t\tHMAC_CTX hctx;\n\t\tHMAC_CTX_init(&hctx);\n\t\tHMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",\n\t\t\t16,EVP_md5(), NULL);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_HMAC][j]); count++)\n\t\t\t\t{\n\t\t\t\tHMAC_Init_ex(&hctx,NULL,0,NULL,NULL);\n\t\t\t\tHMAC_Update(&hctx,buf,lengths[j]);\n\t\t\t\tHMAC_Final(&hctx,&(hmac[0]),NULL);\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_HMAC,j,count,d);\n\t\t\t}\n\t\tHMAC_CTX_cleanup(&hctx);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA\n\tif (doit[D_SHA1])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA1][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA1,j,count,d);\n\t\t\t}\n\t\t}\n#ifndef OPENSSL_NO_SHA256\n\tif (doit[D_SHA256])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA256][j]); count++)\n\t\t\t\tSHA256(buf,lengths[j],sha256);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA256,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA512\n\tif (doit[D_SHA512])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA512][j]); count++)\n\t\t\t\tSHA512(buf,lengths[j],sha512);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA512,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n\tif (doit[D_WHIRLPOOL])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_WHIRLPOOL],c[D_WHIRLPOOL][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_WHIRLPOOL][j]); count++)\n\t\t\t\tWHIRLPOOL(buf,lengths[j],whirlpool);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_WHIRLPOOL,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tif (doit[D_RMD160])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RMD160][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RMD160,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC4\n\tif (doit[D_RC4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RC4],c[D_RC4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RC4][j]); count++)\n\t\t\t\tRC4(&rc4_ks,(unsigned int)lengths[j],\n\t\t\t\t\tbuf,buf);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RC4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DES\n\tif (doit[D_CBC_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_DES][j]); count++)\n\t\t\t\tDES_ncbc_encrypt(buf,buf,lengths[j],&sch,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_DES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_EDE3_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)\n\t\t\t\tDES_ede3_cbc_encrypt(buf,buf,lengths[j],\n\t\t\t\t\t\t &sch,&sch2,&sch3,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_EDE3_DES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_AES\n\tif (doit[D_CBC_128_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks1,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_128_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_192_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks2,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_192_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_256_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks3,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_256_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_IGE_128_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_IGE_128_AES],c[D_IGE_128_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_IGE_128_AES][j]); count++)\n\t\t\t\tAES_ige_encrypt(buf,buf2,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks1,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_IGE_128_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_IGE_192_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_IGE_192_AES],c[D_IGE_192_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_IGE_192_AES][j]); count++)\n\t\t\t\tAES_ige_encrypt(buf,buf2,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks2,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_IGE_192_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_IGE_256_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_IGE_256_AES],c[D_IGE_256_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_IGE_256_AES][j]); count++)\n\t\t\t\tAES_ige_encrypt(buf,buf2,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks3,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_IGE_256_AES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n\tif (doit[D_CBC_128_CML])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_128_CML],c[D_CBC_128_CML][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_128_CML][j]); count++)\n\t\t\t\tCamellia_cbc_encrypt(buf,buf,\n\t\t\t\t (unsigned long)lengths[j],&camellia_ks1,\n\t\t\t\t iv,CAMELLIA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_128_CML,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_192_CML])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_192_CML],c[D_CBC_192_CML][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_192_CML][j]); count++)\n\t\t\t\tCamellia_cbc_encrypt(buf,buf,\n\t\t\t\t (unsigned long)lengths[j],&camellia_ks2,\n\t\t\t\t iv,CAMELLIA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_192_CML,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_256_CML])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_256_CML],c[D_CBC_256_CML][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_256_CML][j]); count++)\n\t\t\t\tCamellia_cbc_encrypt(buf,buf,\n\t\t\t\t (unsigned long)lengths[j],&camellia_ks3,\n\t\t\t\t iv,CAMELLIA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_256_CML,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tif (doit[D_CBC_IDEA])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)\n\t\t\t\tidea_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&idea_ks,\n\t\t\t\t\tiv,IDEA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_IDEA,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SEED\n\tif (doit[D_CBC_SEED])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_SEED],c[D_CBC_SEED][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_SEED][j]); count++)\n\t\t\t\tSEED_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&seed_ks,iv,1);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_SEED,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC2\n\tif (doit[D_CBC_RC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)\n\t\t\t\tRC2_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc2_ks,\n\t\t\t\t\tiv,RC2_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC5\n\tif (doit[D_CBC_RC5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)\n\t\t\t\tRC5_32_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc5_ks,\n\t\t\t\t\tiv,RC5_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_BF\n\tif (doit[D_CBC_BF])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_BF][j]); count++)\n\t\t\t\tBF_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&bf_ks,\n\t\t\t\t\tiv,BF_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_BF,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_CAST\n\tif (doit[D_CBC_CAST])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)\n\t\t\t\tCAST_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&cast_ks,\n\t\t\t\t\tiv,CAST_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_CAST,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n\tif (doit[D_EVP])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (evp_cipher)\n\t\t\t\t{\n\t\t\t\tEVP_CIPHER_CTX ctx;\n\t\t\t\tint outl;\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_cipher->nid);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tEVP_CIPHER_CTX_init(&ctx);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\tEVP_CIPHER_CTX_set_padding(&ctx, 0);\n\t\t\t\tTime_F(START);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\telse\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tEVP_CIPHER_CTX_cleanup(&ctx);\n\t\t\t\t}\n\t\t\tif (evp_md)\n\t\t\t\t{\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_md->type);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\tEVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\t}\n\t\t\tprint_result(D_EVP,j,count,d);\n\t\t\t}\n\t\t}\n\tRAND_pseudo_bytes(buf,36);\n#ifndef OPENSSL_NO_RSA\n\tfor (j=0; j<RSA_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!rsa_doit[j]) continue;\n\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("private","rsa",\n\t\t\t\trsa_c[j][0],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\t&rsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit private RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n#if 1\n\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("public","rsa",\n\t\t\t\trsa_c[j][1],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\trsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit public RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][1]=d/(double)count;\n\t\t\t}\n#endif\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<RSA_NUM; j++)\n\t\t\t\trsa_doit[j]=0;\n\t\t\t}\n\t\t}\n#endif\n\tRAND_pseudo_bytes(buf,20);\n#ifndef OPENSSL_NO_DSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<DSA_NUM; j++)\n\t\t{\n\t\tunsigned int kk;\n\t\tint ret;\n\t\tif (!dsa_doit[j]) continue;\n\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t&kk,dsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("sign","dsa",\n\t\t\t\tdsa_c[j][0],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\t&kk,dsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA signs in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\tkk,dsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tdsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("verify","dsa",\n\t\t\t\tdsa_c[j][1],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\tkk,dsa_key[j]);\n\t\t\t\tif (ret <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA verify in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][1]=d/(double)count;\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<DSA_NUM; j++)\n\t\t\t\tdsa_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<EC_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!ecdsa_doit[j]) continue;\n\t\tecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n\t\tif (ecdsa[j] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"ECDSA failure.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n#if 1\n\t\t\tEC_KEY_precompute_mult(ecdsa[j], NULL);\n#endif\n\t\t\tEC_KEY_generate_key(ecdsa[j]);\n\t\t\tret = ECDSA_sign(0, buf, 20, ecdsasig,\n\t\t\t\t&ecdsasiglen, ecdsa[j]);\n\t\t\tif (ret == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\trsa_count=1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tpkey_print_message("sign","ecdsa",\n\t\t\t\t\tecdsa_c[j][0],\n\t\t\t\t\ttest_curves_bits[j],\n\t\t\t\t\tECDSA_SECONDS);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(ecdsa_c[j][0]);\n\t\t\t\t\tcount++)\n\t\t\t\t\t{\n\t\t\t\t\tret=ECDSA_sign(0, buf, 20,\n\t\t\t\t\t\tecdsasig, &ecdsasiglen,\n\t\t\t\t\t\tecdsa[j]);\n\t\t\t\t\tif (ret == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err, "ECDSA sign failure\\n");\n\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\tcount=1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tBIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\\n" :\n\t\t\t\t\t"%ld %d bit ECDSA signs in %.2fs \\n",\n\t\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\tecdsa_results[j][0]=d/(double)count;\n\t\t\t\trsa_count=count;\n\t\t\t\t}\n\t\t\tret=ECDSA_verify(0, buf, 20, ecdsasig,\n\t\t\t\tecdsasiglen, ecdsa[j]);\n\t\t\tif (ret != 1)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tecdsa_doit[j] = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tpkey_print_message("verify","ecdsa",\n\t\t\t\tecdsa_c[j][1],\n\t\t\t\ttest_curves_bits[j],\n\t\t\t\tECDSA_SECONDS);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(ecdsa_c[j][1]); count++)\n\t\t\t\t\t{\n\t\t\t\t\tret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n\t\t\t\t\tif (ret != 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err, "ECDSA verify failure\\n");\n\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\tcount=1;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tBIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\\n"\n\t\t\t\t\t\t: "%ld %d bit ECDSA verify in %.2fs\\n",\n\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\tecdsa_results[j][1]=d/(double)count;\n\t\t\t\t}\n\t\t\tif (rsa_count <= 1)\n\t\t\t\t{\n\t\t\t\tfor (j++; j<EC_NUM; j++)\n\t\t\t\tecdsa_doit[j]=0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<EC_NUM; j++)\n\t\t{\n\t\tif (!ecdh_doit[j]) continue;\n\t\tecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n\t\tecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n\t\tif ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"ECDH failure.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!EC_KEY_generate_key(ecdh_a[j]) ||\n\t\t\t\t!EC_KEY_generate_key(ecdh_b[j]))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDH key generation failure.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\trsa_count=1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tint field_size, outlen;\n\t\t\t\tvoid *(*kdf)(const void *in, size_t inlen, void *out, size_t *xoutlen);\n\t\t\t\tfield_size = EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n\t\t\t\tif (field_size <= 24 * 8)\n\t\t\t\t\t{\n\t\t\t\t\toutlen = KDF1_SHA1_len;\n\t\t\t\t\tkdf = KDF1_SHA1;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\toutlen = (field_size+7)/8;\n\t\t\t\t\tkdf = NULL;\n\t\t\t\t\t}\n\t\t\t\tsecret_size_a = ECDH_compute_key(secret_a, outlen,\n\t\t\t\t\tEC_KEY_get0_public_key(ecdh_b[j]),\n\t\t\t\t\tecdh_a[j], kdf);\n\t\t\t\tsecret_size_b = ECDH_compute_key(secret_b, outlen,\n\t\t\t\t\tEC_KEY_get0_public_key(ecdh_a[j]),\n\t\t\t\t\tecdh_b[j], kdf);\n\t\t\t\tif (secret_size_a != secret_size_b)\n\t\t\t\t\tecdh_checks = 0;\n\t\t\t\telse\n\t\t\t\t\tecdh_checks = 1;\n\t\t\t\tfor (secret_idx = 0;\n\t\t\t\t (secret_idx < secret_size_a)\n\t\t\t\t\t&& (ecdh_checks == 1);\n\t\t\t\t secret_idx++)\n\t\t\t\t\t{\n\t\t\t\t\tif (secret_a[secret_idx] != secret_b[secret_idx])\n\t\t\t\t\tecdh_checks = 0;\n\t\t\t\t\t}\n\t\t\t\tif (ecdh_checks == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"ECDH computations don\'t match.\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\trsa_count=1;\n\t\t\t\t\t}\n\t\t\t\tpkey_print_message("","ecdh",\n\t\t\t\tecdh_c[j][0],\n\t\t\t\ttest_curves_bits[j],\n\t\t\t\tECDH_SECONDS);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(ecdh_c[j][0]); count++)\n\t\t\t\t\t{\n\t\t\t\t\tECDH_compute_key(secret_a, outlen,\n\t\t\t\t\tEC_KEY_get0_public_key(ecdh_b[j]),\n\t\t\t\t\tecdh_a[j], kdf);\n\t\t\t\t\t}\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tBIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\\n" :"%ld %d-bit ECDH ops in %.2fs\\n",\n\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\tecdh_results[j][0]=d/(double)count;\n\t\t\t\trsa_count=count;\n\t\t\t\t}\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<EC_NUM; j++)\n\t\t\tecdh_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifdef HAVE_FORK\nshow_res:\n#endif\n\tif(!mr)\n\t\t{\n\t\tfprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_BUILT_ON));\n\t\tprintf("options:");\n\t\tprintf("%s ",BN_options());\n#ifndef OPENSSL_NO_MD2\n\t\tprintf("%s ",MD2_options());\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\tprintf("%s ",RC4_options());\n#endif\n#ifndef OPENSSL_NO_DES\n\t\tprintf("%s ",DES_options());\n#endif\n#ifndef OPENSSL_NO_AES\n\t\tprintf("%s ",AES_options());\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\tprintf("%s ",idea_options());\n#endif\n#ifndef OPENSSL_NO_BF\n\t\tprintf("%s ",BF_options());\n#endif\n\t\tfprintf(stdout,"\\n%s\\n",SSLeay_version(SSLEAY_CFLAGS));\n\t\t}\n\tif (pr_header)\n\t\t{\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+H");\n\t\telse\n\t\t\t{\n\t\t\tfprintf(stdout,"The \'numbers\' are in 1000s of bytes per second processed.\\n");\n\t\t\tfprintf(stdout,"type ");\n\t\t\t}\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\tfprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tfor (k=0; k<ALGOR_NUM; k++)\n\t\t{\n\t\tif (!doit[k]) continue;\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F:%d:%s",k,names[k]);\n\t\telse\n\t\t\tfprintf(stdout,"%-13s",names[k]);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (results[k][j] > 10000 && !mr)\n\t\t\t\tfprintf(stdout," %11.2fk",results[k][j]/1e3);\n\t\t\telse\n\t\t\t\tfprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);\n\t\t\t}\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\tj=1;\n\tfor (k=0; k<RSA_NUM; k++)\n\t\t{\n\t\tif (!rsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F2:%u:%u:%f:%f\\n",\n\t\t\t\tk,rsa_bits[k],rsa_results[k][0],\n\t\t\t\trsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n\t\t\t\trsa_bits[k],rsa_results[k][0],rsa_results[k][1],\n\t\t\t\t1.0/rsa_results[k][0],1.0/rsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tj=1;\n\tfor (k=0; k<DSA_NUM; k++)\n\t\t{\n\t\tif (!dsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F3:%u:%u:%f:%f\\n",\n\t\t\t\tk,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n\t\t\t\tdsa_bits[k],dsa_results[k][0],dsa_results[k][1],\n\t\t\t\t1.0/dsa_results[k][0],1.0/dsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tj=1;\n\tfor (k=0; k<EC_NUM; k++)\n\t\t{\n\t\tif (!ecdsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%30ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif (mr)\n\t\t\tfprintf(stdout,"+F4:%u:%u:%f:%f\\n",\n\t\t\t\tk, test_curves_bits[k],\n\t\t\t\tecdsa_results[k][0],ecdsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,\n\t\t\t\t"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\ttest_curves_bits[k],\n\t\t\t\ttest_curves_names[k],\n\t\t\t\tecdsa_results[k][0],ecdsa_results[k][1],\n\t\t\t\t1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tj=1;\n\tfor (k=0; k<EC_NUM; k++)\n\t\t{\n\t\tif (!ecdh_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%30sop op/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif (mr)\n\t\t\tfprintf(stdout,"+F5:%u:%u:%f:%f\\n",\n\t\t\t\tk, test_curves_bits[k],\n\t\t\t\tecdh_results[k][0], 1.0/ecdh_results[k][0]);\n\t\telse\n\t\t\tfprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n\t\t\t\ttest_curves_bits[k],\n\t\t\t\ttest_curves_names[k],\n\t\t\t\tecdh_results[k][0], 1.0/ecdh_results[k][0]);\n\t\t}\n#endif\n\tmret=0;\nend:\n\tERR_print_errors(bio_err);\n\tif (buf != NULL) OPENSSL_free(buf);\n\tif (buf2 != NULL) OPENSSL_free(buf2);\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\tif (rsa_key[i] != NULL)\n\t\t\tRSA_free(rsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_DSA\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tif (dsa_key[i] != NULL)\n\t\t\tDSA_free(dsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++)\n\t\tif (ecdsa[i] != NULL)\n\t\t\tEC_KEY_free(ecdsa[i]);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t{\n\t\tif (ecdh_a[i] != NULL)\n\t\t\tEC_KEY_free(ecdh_a[i]);\n\t\tif (ecdh_b[i] != NULL)\n\t\t\tEC_KEY_free(ecdh_b[i]);\n\t}\n#endif\n\tapps_shutdown();\n\tOPENSSL_EXIT(mret);\n\t}', 'int Camellia_set_key(const unsigned char *userKey, const int bits,\n\tCAMELLIA_KEY *key)\n\t{\n\tif(!userKey || !key)\n\t\treturn -1;\n\tif(bits != 128 && bits != 192 && bits != 256)\n\t\treturn -2;\n\tkey->grand_rounds = Camellia_Ekeygen(bits , userKey, key->u.rd_key);\n\treturn 0;\n\t}', 'int Camellia_Ekeygen(int keyBitLength, const u8 *rawKey, KEY_TABLE_TYPE k)\n\t{\n\tregister u32 s0,s1,s2,s3;\n\tk[0] = s0 = GETU32(rawKey);\n\tk[1] = s1 = GETU32(rawKey+4);\n\tk[2] = s2 = GETU32(rawKey+8);\n\tk[3] = s3 = GETU32(rawKey+12);\n\tif (keyBitLength != 128)\n\t\t{\n\t\tk[8] = s0 = GETU32(rawKey+16);\n\t\tk[9] = s1 = GETU32(rawKey+20);\n\t\tif (keyBitLength == 192)\n\t\t\t{\n\t\t\tk[10] = s2 = ~s0;\n\t\t\tk[11] = s3 = ~s1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tk[10] = s2 = GETU32(rawKey+24);\n\t\t\tk[11] = s3 = GETU32(rawKey+28);\n\t\t\t}\n\t\ts0 ^= k[0], s1 ^= k[1], s2 ^= k[2], s3 ^= k[3];\n\t\t}\n\tCamellia_Feistel(s0,s1,s2,s3,SIGMA+0);\n\tCamellia_Feistel(s2,s3,s0,s1,SIGMA+2);\n\ts0 ^= k[0], s1 ^= k[1], s2 ^= k[2], s3 ^= k[3];\n\tCamellia_Feistel(s0,s1,s2,s3,SIGMA+4);\n\tCamellia_Feistel(s2,s3,s0,s1,SIGMA+6);\n\tif (keyBitLength == 128)\n\t\t{\n\t\tk[ 4] = s0, k[ 5] = s1, k[ 6] = s2, k[ 7] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[16] = s0, k[17] = s1, k[18] = s2, k[19] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[24] = s0, k[25] = s1;\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[28] = s0, k[29] = s1, k[30] = s2, k[31] = s3;\n\t\tRotLeft128(s1,s2,s3,s0,2);\n\t\tk[40] = s1, k[41] = s2, k[42] = s3, k[43] = s0;\n\t\tRotLeft128(s1,s2,s3,s0,17);\n\t\tk[48] = s1, k[49] = s2, k[50] = s3, k[51] = s0;\n\t\ts0 = k[ 0], s1 = k[ 1], s2 = k[ 2], s3 = k[ 3];\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[ 8] = s0, k[ 9] = s1, k[10] = s2, k[11] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,30);\n\t\tk[20] = s0, k[21] = s1, k[22] = s2, k[23] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[26] = s2, k[27] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,17);\n\t\tk[32] = s0, k[33] = s1, k[34] = s2, k[35] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,17);\n\t\tk[36] = s0, k[37] = s1, k[38] = s2, k[39] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,17);\n\t\tk[44] = s0, k[45] = s1, k[46] = s2, k[47] = s3;\n\t\treturn 3;\n\t\t}\n\telse\n\t\t{\n\t\tk[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;\n\t\ts0 ^= k[8], s1 ^= k[9], s2 ^=k[10], s3 ^=k[11];\n\t\tCamellia_Feistel(s0,s1,s2,s3,(SIGMA+8));\n\t\tCamellia_Feistel(s2,s3,s0,s1,(SIGMA+10));\n\t\tk[ 4] = s0, k[ 5] = s1, k[ 6] = s2, k[ 7] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,30);\n\t\tk[20] = s0, k[21] = s1, k[22] = s2, k[23] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,30);\n\t\tk[40] = s0, k[41] = s1, k[42] = s2, k[43] = s3;\n\t\tRotLeft128(s1,s2,s3,s0,19);\n\t\tk[64] = s1, k[65] = s2, k[66] = s3, k[67] = s0;\n\t\ts0 = k[ 8], s1 = k[ 9], s2 = k[10], s3 = k[11];\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[ 8] = s0, k[ 9] = s1, k[10] = s2, k[11] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[16] = s0, k[17] = s1, k[18] = s2, k[19] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,30);\n\t\tk[36] = s0, k[37] = s1, k[38] = s2, k[39] = s3;\n\t\tRotLeft128(s1,s2,s3,s0,2);\n\t\tk[52] = s1, k[53] = s2, k[54] = s3, k[55] = s0;\n\t\ts0 = k[12], s1 = k[13], s2 = k[14], s3 = k[15];\n\t\tRotLeft128(s0,s1,s2,s3,15);\n\t\tk[12] = s0, k[13] = s1, k[14] = s2, k[15] = s3;\n\t\tRotLeft128(s0,s1,s2,s3,30);\n\t\tk[28] = s0, k[29] = s1, k[30] = s2, k[31] = s3;\n\t\tk[48] = s1, k[49] = s2, k[50] = s3, k[51] = s0;\n\t\tRotLeft128(s1,s2,s3,s0,17);\n\t\tk[56] = s1, k[57] = s2, k[58] = s3, k[59] = s0;\n\t\ts0 = k[ 0], s1 = k[ 1], s2 = k[ 2], s3 = k[ 3];\n\t\tRotLeft128(s1,s2,s3,s0,13);\n\t\tk[24] = s1, k[25] = s2, k[26] = s3, k[27] = s0;\n\t\tRotLeft128(s1,s2,s3,s0,15);\n\t\tk[32] = s1, k[33] = s2, k[34] = s3, k[35] = s0;\n\t\tRotLeft128(s1,s2,s3,s0,17);\n\t\tk[44] = s1, k[45] = s2, k[46] = s3, k[47] = s0;\n\t\tRotLeft128(s2,s3,s0,s1,2);\n\t\tk[60] = s2, k[61] = s3, k[62] = s0, k[63] = s1;\n\t\treturn 4;\n\t\t}\n\t}']
|
1,370
| 0
|
https://github.com/openssl/openssl/blob/a8140a42f5ee9e4e1423b5b6b319dc4657659f6f/crypto/bn/bn_exp.c/#L389
|
int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
{
int i, j, bits, ret = 0, wstart, wend, window, wvalue;
int start = 1;
BIGNUM *d, *r;
const BIGNUM *aa;
BIGNUM *val[TABLE_SIZE];
BN_MONT_CTX *mont = NULL;
if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0
|| BN_get_flags(a, BN_FLG_CONSTTIME) != 0
|| BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {
return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
}
bn_check_top(a);
bn_check_top(p);
bn_check_top(m);
if (!BN_is_odd(m)) {
BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);
return 0;
}
bits = BN_num_bits(p);
if (bits == 0) {
if (BN_abs_is_word(m, 1)) {
ret = 1;
BN_zero(rr);
} else {
ret = BN_one(rr);
}
return ret;
}
BN_CTX_start(ctx);
d = BN_CTX_get(ctx);
r = BN_CTX_get(ctx);
val[0] = BN_CTX_get(ctx);
if (val[0] == NULL)
goto err;
if (in_mont != NULL)
mont = in_mont;
else {
if ((mont = BN_MONT_CTX_new()) == NULL)
goto err;
if (!BN_MONT_CTX_set(mont, m, ctx))
goto err;
}
if (a->neg || BN_ucmp(a, m) >= 0) {
if (!BN_nnmod(val[0], a, m, ctx))
goto err;
aa = val[0];
} else
aa = a;
if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))
goto err;
window = BN_window_bits_for_exponent_size(bits);
if (window > 1) {
if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))
goto err;
j = 1 << (window - 1);
for (i = 1; i < j; i++) {
if (((val[i] = BN_CTX_get(ctx)) == NULL) ||
!bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))
goto err;
}
}
start = 1;
wvalue = 0;
wstart = bits - 1;
wend = 0;
#if 1
j = m->top;
if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {
if (bn_wexpand(r, j) == NULL)
goto err;
r->d[0] = (0 - m->d[0]) & BN_MASK2;
for (i = 1; i < j; i++)
r->d[i] = (~m->d[i]) & BN_MASK2;
r->top = j;
r->flags |= BN_FLG_FIXED_TOP;
} else
#endif
if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))
goto err;
for (;;) {
if (BN_is_bit_set(p, wstart) == 0) {
if (!start) {
if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))
goto err;
}
if (wstart == 0)
break;
wstart--;
continue;
}
j = wstart;
wvalue = 1;
wend = 0;
for (i = 1; i < window; i++) {
if (wstart - i < 0)
break;
if (BN_is_bit_set(p, wstart - i)) {
wvalue <<= (i - wend);
wvalue |= 1;
wend = i;
}
}
j = wend + 1;
if (!start)
for (i = 0; i < j; i++) {
if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))
goto err;
}
if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))
goto err;
wstart -= wend + 1;
wvalue = 0;
start = 0;
if (wstart < 0)
break;
}
#if defined(SPARC_T4_MONT)
if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {
j = mont->N.top;
val[0]->d[0] = 1;
for (i = 1; i < j; i++)
val[0]->d[i] = 0;
val[0]->top = j;
if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))
goto err;
} else
#endif
if (!BN_from_montgomery(rr, r, mont, ctx))
goto err;
ret = 1;
err:
if (in_mont == NULL)
BN_MONT_CTX_free(mont);
BN_CTX_end(ctx);
bn_check_top(rr);
return ret;
}
|
['static int srp_Verify_N_and_g(const BIGNUM *N, const BIGNUM *g)\n{\n BN_CTX *bn_ctx = BN_CTX_new();\n BIGNUM *p = BN_new();\n BIGNUM *r = BN_new();\n int ret =\n g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&\n BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n p != NULL && BN_rshift1(p, N) &&\n BN_is_prime_ex(p, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n r != NULL &&\n BN_mod_exp(r, g, p, N, bn_ctx) &&\n BN_add_word(r, 1) && BN_cmp(r, N) == 0;\n BN_free(r);\n BN_free(p);\n BN_CTX_free(bn_ctx);\n return ret;\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n BN_GENCB *cb)\n{\n return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *w, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, status, ret = -1;\n BN_CTX *ctx = NULL;\n if (BN_cmp(w, BN_value_one()) <= 0)\n return 0;\n if (BN_is_odd(w)) {\n if (BN_is_word(w, 3))\n return 1;\n } else {\n return BN_is_word(w, 2);\n }\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG mod = BN_mod_word(w, primes[i]);\n if (mod == (BN_ULONG)-1)\n return -1;\n if (mod == 0)\n return BN_is_word(w, primes[i]);\n }\n if (!BN_GENCB_call(cb, 1, -1))\n return -1;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n ret = bn_miller_rabin_is_prime(w, checks, ctx, cb, 0, &status);\n if (!ret)\n goto err;\n ret = (status == BN_PRIMETEST_PROBABLY_PRIME);\nerr:\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n return ret;\n}', 'int bn_miller_rabin_is_prime(const BIGNUM *w, int iterations, BN_CTX *ctx,\n BN_GENCB *cb, int enhanced, int *status)\n{\n int i, j, a, ret = 0;\n BIGNUM *g, *w1, *w3, *x, *m, *z, *b;\n BN_MONT_CTX *mont = NULL;\n if (!BN_is_odd(w))\n return 0;\n BN_CTX_start(ctx);\n g = BN_CTX_get(ctx);\n w1 = BN_CTX_get(ctx);\n w3 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n m = BN_CTX_get(ctx);\n z = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (!(b != NULL\n && BN_copy(w1, w)\n && BN_sub_word(w1, 1)\n && BN_copy(w3, w)\n && BN_sub_word(w3, 3)))\n goto err;\n if (BN_is_zero(w3) || BN_is_negative(w3))\n goto err;\n a = 1;\n while (!BN_is_bit_set(w1, a))\n a++;\n if (!BN_rshift(m, w1, a))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL || !BN_MONT_CTX_set(mont, w, ctx))\n goto err;\n if (iterations == BN_prime_checks)\n iterations = BN_prime_checks_for_size(BN_num_bits(w));\n for (i = 0; i < iterations; ++i) {\n if (!BN_priv_rand_range(b, w3) || !BN_add_word(b, 2))\n goto err;\n if (enhanced) {\n if (!BN_gcd(g, b, w, ctx))\n goto err;\n if (!BN_is_one(g)) {\n *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n ret = 1;\n goto err;\n }\n }\n if (!BN_mod_exp_mont(z, b, m, w, ctx, mont))\n goto err;\n if (BN_is_one(z) || BN_cmp(z, w1) == 0)\n goto outer_loop;\n for (j = 1; j < a ; ++j) {\n if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n goto err;\n if (BN_cmp(z, w1) == 0)\n goto outer_loop;\n if (BN_is_one(z))\n goto composite;\n }\n if (!BN_copy(x, z) || !BN_mod_mul(z, x, x, w, ctx))\n goto err;\n if (BN_is_one(z))\n goto composite;\n if (!BN_copy(x, z))\n goto err;\ncomposite:\n if (enhanced) {\n if (!BN_sub_word(x, 1) || !BN_gcd(g, x, w, ctx))\n goto err;\n if (BN_is_one(g))\n *status = BN_PRIMETEST_COMPOSITE_NOT_POWER_OF_PRIME;\n else\n *status = BN_PRIMETEST_COMPOSITE_WITH_FACTOR;\n } else {\n *status = BN_PRIMETEST_COMPOSITE;\n }\n ret = 1;\n goto err;\nouter_loop: ;\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n *status = BN_PRIMETEST_PROBABLY_PRIME;\n ret = 1;\nerr:\n BN_clear(g);\n BN_clear(w1);\n BN_clear(w3);\n BN_clear(x);\n BN_clear(m);\n BN_clear(z);\n BN_clear(b);\n BN_CTX_end(ctx);\n BN_MONT_CTX_free(mont);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n BN_ULONG *ap, *rp, t, c;\n int i, j;\n bn_check_top(r);\n bn_check_top(a);\n if (BN_is_zero(a)) {\n BN_zero(r);\n return 1;\n }\n i = a->top;\n ap = a->d;\n j = i - (ap[i - 1] == 1);\n if (a != r) {\n if (bn_wexpand(r, j) == NULL)\n return 0;\n r->neg = a->neg;\n }\n rp = r->d;\n t = ap[--i];\n c = (t & 1) ? BN_TBIT : 0;\n if (t >>= 1)\n rp[i] = t;\n while (i > 0) {\n t = ap[--i];\n rp[i] = ((t >> 1) & BN_MASK2) | c;\n c = (t & 1) ? BN_TBIT : 0;\n }\n r->top = j;\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return 1;\n}']
|
1,371
| 0
|
https://github.com/nginx/nginx/blob/70f7141074896fb1ff3e5fc08407ea0f64f2076b/src/core/ngx_sha1.c/#L250
|
static const u_char *
ngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)
{
uint32_t a, b, c, d, e, temp;
uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;
uint32_t words[80];
ngx_uint_t i;
const u_char *p;
p = data;
a = ctx->a;
b = ctx->b;
c = ctx->c;
d = ctx->d;
e = ctx->e;
do {
saved_a = a;
saved_b = b;
saved_c = c;
saved_d = d;
saved_e = e;
for (i = 0; i < 16; i++) {
words[i] = GET(i);
}
for (i = 16; i < 80; i++) {
words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]
^ words[i - 16]);
}
STEP(F1, a, b, c, d, e, words[0], 0x5a827999);
STEP(F1, a, b, c, d, e, words[1], 0x5a827999);
STEP(F1, a, b, c, d, e, words[2], 0x5a827999);
STEP(F1, a, b, c, d, e, words[3], 0x5a827999);
STEP(F1, a, b, c, d, e, words[4], 0x5a827999);
STEP(F1, a, b, c, d, e, words[5], 0x5a827999);
STEP(F1, a, b, c, d, e, words[6], 0x5a827999);
STEP(F1, a, b, c, d, e, words[7], 0x5a827999);
STEP(F1, a, b, c, d, e, words[8], 0x5a827999);
STEP(F1, a, b, c, d, e, words[9], 0x5a827999);
STEP(F1, a, b, c, d, e, words[10], 0x5a827999);
STEP(F1, a, b, c, d, e, words[11], 0x5a827999);
STEP(F1, a, b, c, d, e, words[12], 0x5a827999);
STEP(F1, a, b, c, d, e, words[13], 0x5a827999);
STEP(F1, a, b, c, d, e, words[14], 0x5a827999);
STEP(F1, a, b, c, d, e, words[15], 0x5a827999);
STEP(F1, a, b, c, d, e, words[16], 0x5a827999);
STEP(F1, a, b, c, d, e, words[17], 0x5a827999);
STEP(F1, a, b, c, d, e, words[18], 0x5a827999);
STEP(F1, a, b, c, d, e, words[19], 0x5a827999);
STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);
STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);
STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);
STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);
STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);
STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);
a += saved_a;
b += saved_b;
c += saved_c;
d += saved_d;
e += saved_e;
p += 64;
} while (size -= 64);
ctx->a = a;
ctx->b = b;
ctx->c = c;
ctx->d = d;
ctx->e = e;
return p;
}
|
['static const u_char *\nngx_sha1_body(ngx_sha1_t *ctx, const u_char *data, size_t size)\n{\n uint32_t a, b, c, d, e, temp;\n uint32_t saved_a, saved_b, saved_c, saved_d, saved_e;\n uint32_t words[80];\n ngx_uint_t i;\n const u_char *p;\n p = data;\n a = ctx->a;\n b = ctx->b;\n c = ctx->c;\n d = ctx->d;\n e = ctx->e;\n do {\n saved_a = a;\n saved_b = b;\n saved_c = c;\n saved_d = d;\n saved_e = e;\n for (i = 0; i < 16; i++) {\n words[i] = GET(i);\n }\n for (i = 16; i < 80; i++) {\n words[i] = ROTATE(1, words[i - 3] ^ words[i - 8] ^ words[i - 14]\n ^ words[i - 16]);\n }\n STEP(F1, a, b, c, d, e, words[0], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[1], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[2], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[3], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[4], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[5], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[6], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[7], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[8], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[9], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[10], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[11], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[12], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[13], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[14], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[15], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[16], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[17], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[18], 0x5a827999);\n STEP(F1, a, b, c, d, e, words[19], 0x5a827999);\n STEP(F2, a, b, c, d, e, words[20], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[21], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[22], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[23], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[24], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[25], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[26], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[27], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[28], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[29], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[30], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[31], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[32], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[33], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[34], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[35], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[36], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[37], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[38], 0x6ed9eba1);\n STEP(F2, a, b, c, d, e, words[39], 0x6ed9eba1);\n STEP(F3, a, b, c, d, e, words[40], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[41], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[42], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[43], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[44], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[45], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[46], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[47], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[48], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[49], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[50], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[51], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[52], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[53], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[54], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[55], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[56], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[57], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[58], 0x8f1bbcdc);\n STEP(F3, a, b, c, d, e, words[59], 0x8f1bbcdc);\n STEP(F2, a, b, c, d, e, words[60], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[61], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[62], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[63], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[64], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[65], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[66], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[67], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[68], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[69], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[70], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[71], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[72], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[73], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[74], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[75], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[76], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[77], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[78], 0xca62c1d6);\n STEP(F2, a, b, c, d, e, words[79], 0xca62c1d6);\n a += saved_a;\n b += saved_b;\n c += saved_c;\n d += saved_d;\n e += saved_e;\n p += 64;\n } while (size -= 64);\n ctx->a = a;\n ctx->b = b;\n ctx->c = c;\n ctx->d = d;\n ctx->e = e;\n return p;\n}']
|
1,372
| 0
|
https://github.com/openssl/openssl/blob/f4675379275c304dbfa593cc573b4e4c4eb54bd4/crypto/bn/bn_lib.c/#L233
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['static\nECDSA_SIG *SM2_sig_gen(const EC_KEY *key, const BIGNUM *e)\n{\n const BIGNUM *dA = EC_KEY_get0_private_key(key);\n const EC_GROUP *group = EC_KEY_get0_group(key);\n const BIGNUM *order = EC_GROUP_get0_order(group);\n ECDSA_SIG *sig = NULL;\n EC_POINT *kG = NULL;\n BN_CTX *ctx = NULL;\n BIGNUM *k = NULL;\n BIGNUM *rk = NULL;\n BIGNUM *r = NULL;\n BIGNUM *s = NULL;\n BIGNUM *x1 = NULL;\n BIGNUM *tmp = NULL;\n kG = EC_POINT_new(group);\n if (kG == NULL)\n goto done;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto done;\n BN_CTX_start(ctx);\n k = BN_CTX_get(ctx);\n rk = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto done;\n r = BN_new();\n s = BN_new();\n if (r == NULL || s == NULL)\n goto done;\n for (;;) {\n BN_priv_rand_range(k, order);\n if (EC_POINT_mul(group, kG, k, NULL, NULL, ctx) == 0)\n goto done;\n if (EC_POINT_get_affine_coordinates_GFp(group, kG, x1, NULL, ctx) == 0)\n goto done;\n if (BN_mod_add(r, e, x1, order, ctx) == 0)\n goto done;\n if (BN_is_zero(r))\n continue;\n BN_add(rk, r, k);\n if (BN_cmp(rk, order) == 0)\n continue;\n BN_add(s, dA, BN_value_one());\n BN_mod_inverse(s, s, order, ctx);\n BN_mod_mul(tmp, dA, r, order, ctx);\n BN_sub(tmp, k, tmp);\n BN_mod_mul(s, s, tmp, order, ctx);\n sig = ECDSA_SIG_new();\n if (sig == NULL)\n goto done;\n ECDSA_SIG_set0(sig, r, s);\n break;\n }\n done:\n if (sig == NULL) {\n BN_free(r);\n BN_free(s);\n }\n BN_CTX_free(ctx);\n EC_POINT_free(kG);\n return sig;\n}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n if (group->meth->mul == 0)\n return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n return group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n}', 'int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n if (!BN_add(r, a, b))\n return 0;\n return BN_nnmod(r, r, m, ctx);\n}', 'int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int ret, r_neg, cmp_res;\n bn_check_top(a);\n bn_check_top(b);\n if (a->neg == b->neg) {\n r_neg = a->neg;\n ret = BN_uadd(r, a, b);\n } else {\n cmp_res = BN_ucmp(a, b);\n if (cmp_res > 0) {\n r_neg = a->neg;\n ret = BN_usub(r, a, b);\n } else if (cmp_res < 0) {\n r_neg = b->neg;\n ret = BN_usub(r, b, a);\n } else {\n r_neg = 0;\n BN_zero(r);\n ret = 1;\n }\n }\n r->neg = r_neg;\n bn_check_top(r);\n return ret;\n}', 'int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n int max, min, dif;\n const BN_ULONG *ap, *bp;\n BN_ULONG *rp, carry, t1, t2;\n bn_check_top(a);\n bn_check_top(b);\n if (a->top < b->top) {\n const BIGNUM *tmp;\n tmp = a;\n a = b;\n b = tmp;\n }\n max = a->top;\n min = b->top;\n dif = max - min;\n if (bn_wexpand(r, max + 1) == NULL)\n return 0;\n r->top = max;\n ap = a->d;\n bp = b->d;\n rp = r->d;\n carry = bn_add_words(rp, ap, bp, min);\n rp += min;\n ap += min;\n while (dif) {\n dif--;\n t1 = *(ap++);\n t2 = (t1 + carry) & BN_MASK2;\n *(rp++) = t2;\n carry &= (t2 == 0);\n }\n *rp = carry;\n r->top += carry;\n r->neg = 0;\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,373
| 0
|
https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/ssl/packet_locl.h/#L36
|
static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
pkt->curr += len;
pkt->remaining -= len;
}
|
['static int test_PACKET_get_sub_packet(unsigned char buf[BUF_LEN])\n{\n PACKET pkt, subpkt;\n unsigned long i;\n if ( !PACKET_buf_init(&pkt, buf, BUF_LEN)\n || !PACKET_get_sub_packet(&pkt, &subpkt, 4)\n || !PACKET_get_net_4(&subpkt, &i)\n || i != 0x02040608UL\n || PACKET_remaining(&subpkt)\n || !PACKET_forward(&pkt, BUF_LEN - 8)\n || !PACKET_get_sub_packet(&pkt, &subpkt, 4)\n || !PACKET_get_net_4(&subpkt, &i)\n || i != 0xf8fafcfeUL\n || PACKET_remaining(&subpkt)\n || PACKET_get_sub_packet(&pkt, &subpkt, 4)) {\n fprintf(stderr, "test_PACKET_get_sub_packet() failed\\n");\n return 0;\n }\n return 1;\n}', 'static ossl_inline void packet_forward(PACKET *pkt, size_t len)\n{\n pkt->curr += len;\n pkt->remaining -= len;\n}']
|
1,374
| 0
|
https://github.com/libav/libav/blob/ab3554e1a7c04a5ea30f9c905de92348478ef7c8/libavfilter/avfilter.c/#L704
|
int avfilter_init_str(AVFilterContext *filter, const char *args)
{
AVDictionary *options = NULL;
AVDictionaryEntry *e;
int ret = 0;
if (args && *args) {
if (!filter->filter->priv_class) {
av_log(filter, AV_LOG_ERROR, "This filter does not take any "
"options, but options were provided: %s.\n", args);
return AVERROR(EINVAL);
}
#if FF_API_OLD_FILTER_OPTS
if (!strcmp(filter->filter->name, "scale") &&
strchr(args, ':') && strchr(args, ':') < strchr(args, '=')) {
char *copy = av_strdup(args);
char *p;
av_log(filter, AV_LOG_WARNING, "The <w>:<h>:flags=<flags> option "
"syntax is deprecated. Use either <w>:<h>:<flags> or "
"w=<w>:h=<h>:flags=<flags>.\n");
if (!copy) {
ret = AVERROR(ENOMEM);
goto fail;
}
p = strrchr(copy, ':');
if (p) {
*p++ = 0;
ret = av_dict_parse_string(&options, p, "=", ":", 0);
}
if (ret >= 0)
ret = process_unnamed_options(filter, &options, copy);
av_freep(©);
if (ret < 0)
goto fail;
} else
#endif
if (strchr(args, '=')) {
ret = av_dict_parse_string(&options, args, "=", ":", 0);
if (ret < 0)
goto fail;
#if FF_API_OLD_FILTER_OPTS
} else if (!strcmp(filter->filter->name, "format") ||
!strcmp(filter->filter->name, "noformat") ||
!strcmp(filter->filter->name, "frei0r") ||
!strcmp(filter->filter->name, "frei0r_src") ||
!strcmp(filter->filter->name, "ocv")) {
char *copy = av_strdup(args);
char *p = copy;
int nb_leading = 0;
if (!copy) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (!strcmp(filter->filter->name, "frei0r") ||
!strcmp(filter->filter->name, "ocv"))
nb_leading = 1;
else if (!strcmp(filter->filter->name, "frei0r_src"))
nb_leading = 3;
while (nb_leading--) {
p = strchr(p, ':');
if (!p) {
p = copy + strlen(copy);
break;
}
p++;
}
if (strchr(p, ':')) {
av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "
"'|' to separate the list items.\n");
}
while ((p = strchr(p, ':')))
*p++ = '|';
ret = process_unnamed_options(filter, &options, copy);
av_freep(©);
if (ret < 0)
goto fail;
#endif
} else {
ret = process_unnamed_options(filter, &options, args);
if (ret < 0)
goto fail;
}
}
ret = avfilter_init_dict(filter, &options);
if (ret < 0)
goto fail;
if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {
av_log(filter, AV_LOG_ERROR, "No such option: %s.\n", e->key);
ret = AVERROR_OPTION_NOT_FOUND;
goto fail;
}
fail:
av_dict_free(&options);
return ret;
}
|
['int avfilter_init_str(AVFilterContext *filter, const char *args)\n{\n AVDictionary *options = NULL;\n AVDictionaryEntry *e;\n int ret = 0;\n if (args && *args) {\n if (!filter->filter->priv_class) {\n av_log(filter, AV_LOG_ERROR, "This filter does not take any "\n "options, but options were provided: %s.\\n", args);\n return AVERROR(EINVAL);\n }\n#if FF_API_OLD_FILTER_OPTS\n if (!strcmp(filter->filter->name, "scale") &&\n strchr(args, \':\') && strchr(args, \':\') < strchr(args, \'=\')) {\n char *copy = av_strdup(args);\n char *p;\n av_log(filter, AV_LOG_WARNING, "The <w>:<h>:flags=<flags> option "\n "syntax is deprecated. Use either <w>:<h>:<flags> or "\n "w=<w>:h=<h>:flags=<flags>.\\n");\n if (!copy) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n p = strrchr(copy, \':\');\n if (p) {\n *p++ = 0;\n ret = av_dict_parse_string(&options, p, "=", ":", 0);\n }\n if (ret >= 0)\n ret = process_unnamed_options(filter, &options, copy);\n av_freep(©);\n if (ret < 0)\n goto fail;\n } else\n#endif\n if (strchr(args, \'=\')) {\n ret = av_dict_parse_string(&options, args, "=", ":", 0);\n if (ret < 0)\n goto fail;\n#if FF_API_OLD_FILTER_OPTS\n } else if (!strcmp(filter->filter->name, "format") ||\n !strcmp(filter->filter->name, "noformat") ||\n !strcmp(filter->filter->name, "frei0r") ||\n !strcmp(filter->filter->name, "frei0r_src") ||\n !strcmp(filter->filter->name, "ocv")) {\n char *copy = av_strdup(args);\n char *p = copy;\n int nb_leading = 0;\n if (!copy) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n if (!strcmp(filter->filter->name, "frei0r") ||\n !strcmp(filter->filter->name, "ocv"))\n nb_leading = 1;\n else if (!strcmp(filter->filter->name, "frei0r_src"))\n nb_leading = 3;\n while (nb_leading--) {\n p = strchr(p, \':\');\n if (!p) {\n p = copy + strlen(copy);\n break;\n }\n p++;\n }\n if (strchr(p, \':\')) {\n av_log(filter, AV_LOG_WARNING, "This syntax is deprecated. Use "\n "\'|\' to separate the list items.\\n");\n }\n while ((p = strchr(p, \':\')))\n *p++ = \'|\';\n ret = process_unnamed_options(filter, &options, copy);\n av_freep(©);\n if (ret < 0)\n goto fail;\n#endif\n } else {\n ret = process_unnamed_options(filter, &options, args);\n if (ret < 0)\n goto fail;\n }\n }\n ret = avfilter_init_dict(filter, &options);\n if (ret < 0)\n goto fail;\n if ((e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX))) {\n av_log(filter, AV_LOG_ERROR, "No such option: %s.\\n", e->key);\n ret = AVERROR_OPTION_NOT_FOUND;\n goto fail;\n }\nfail:\n av_dict_free(&options);\n return ret;\n}', 'char *av_strdup(const char *s)\n{\n char *ptr = NULL;\n if (s) {\n int len = strlen(s) + 1;\n ptr = av_realloc(NULL, len);\n if (ptr)\n memcpy(ptr, s, len);\n }\n return ptr;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n if (size > (INT_MAX - 16))\n return NULL;\n#if HAVE_ALIGNED_MALLOC\n return _aligned_realloc(ptr, size, 32);\n#else\n return realloc(ptr, size);\n#endif\n}']
|
1,375
| 0
|
https://github.com/openssl/openssl/blob/92eb4c551d7433ba1e74e77001dab2e256f8a870/crypto/bn/bn_ctx.c/#L355
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int RSA_eay_public_decrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM *f,*ret;\n\tint i,num=0,r= -1;\n\tunsigned char *p;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n#ifdef OPENSSL_FIPS\n\tif(FIPS_selftest_failed())\n\t\t{\n\t\tFIPSerr(FIPS_F_RSA_EAY_PUBLIC_ENCRYPT,FIPS_R_FIPS_SELFTEST_FAILED);\n\t\tgoto err;\n\t\t}\n\tif (FIPS_mode() && (BN_num_bits(rsa->n) < OPENSSL_RSA_FIPS_MIN_MODULUS_BITS))\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_KEY_SIZE_TOO_SMALL);\n\t\treturn -1;\n\t\t}\n#endif\n\tif (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_MODULUS_TOO_LARGE);\n\t\treturn -1;\n\t\t}\n\tif (BN_ucmp(rsa->n, rsa->e) <= 0)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);\n\t\treturn -1;\n\t\t}\n\tif (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)\n\t\t{\n\t\tif (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_BAD_E_VALUE);\n\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif((ctx = BN_CTX_new()) == NULL) goto err;\n\tBN_CTX_start(ctx);\n\tf = BN_CTX_get(ctx);\n\tret = BN_CTX_get(ctx);\n\tnum=BN_num_bytes(rsa->n);\n\tbuf = OPENSSL_malloc(num);\n\tif(!f || !ret || !buf)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_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_PUBLIC_DECRYPT,RSA_R_DATA_GREATER_THAN_MOD_LEN);\n\t\tgoto err;\n\t\t}\n\tif (BN_bin2bn(from,flen,f) == NULL) goto err;\n\tif (BN_ucmp(f, rsa->n) >= 0)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n\t\tgoto err;\n\t\t}\n\tif (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n\t\tif (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx))\n\t\t\tgoto err;\n\tif (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tif ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12))\n\t\tif (!BN_sub(ret, rsa->n, ret)) goto err;\n\tp=buf;\n\ti=BN_bn2bin(ret,p);\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\tr=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_X931_PADDING:\n\t\tr=RSA_padding_check_X931(to,num,buf,i,num);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\tr=RSA_padding_check_none(to,num,buf,i,num);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (r < 0)\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\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}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint got_write_lock = 0;\n\tBN_MONT_CTX *ret;\n\tCRYPTO_r_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\tCRYPTO_r_unlock(lock);\n\t\tCRYPTO_w_lock(lock);\n\t\tgot_write_lock = 1;\n\t\tif (!*pmont)\n\t\t\t{\n\t\t\tret = BN_MONT_CTX_new();\n\t\t\tif (ret && !BN_MONT_CTX_set(ret, mod, ctx))\n\t\t\t\tBN_MONT_CTX_free(ret);\n\t\t\telse\n\t\t\t\t*pmont = ret;\n\t\t\t}\n\t\t}\n\tret = *pmont;\n\tif (got_write_lock)\n\t\tCRYPTO_w_unlock(lock);\n\telse\n\t\tCRYPTO_r_unlock(lock);\n\treturn ret;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tBN_init(&tmod);\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *rv;\n\tint noinv;\n\trv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n\tif (noinv)\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\treturn rv;\n\t}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx, int *pnoinv)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tif (pnoinv)\n\t\t*pnoinv = 0;\n\tif ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_mod_inverse_no_branch(in, a, n, ctx);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tif (!BN_nnmod(B, B, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (pnoinv)\n\t\t\t*pnoinv = 1;\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM local_A, local_B;\n\tBIGNUM *pA, *pB;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tX = BN_CTX_get(ctx);\n\tD = BN_CTX_get(ctx);\n\tM = BN_CTX_get(ctx);\n\tY = BN_CTX_get(ctx);\n\tT = BN_CTX_get(ctx);\n\tif (T == NULL) goto err;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_one(X);\n\tBN_zero(Y);\n\tif (BN_copy(B,a) == NULL) goto err;\n\tif (BN_copy(A,n) == NULL) goto err;\n\tA->neg = 0;\n\tif (B->neg || (BN_ucmp(B, A) >= 0))\n\t\t{\n\t\tpB = &local_B;\n\t\tBN_with_flags(pB, B, BN_FLG_CONSTTIME);\n\t\tif (!BN_nnmod(B, pB, A, ctx)) goto err;\n\t\t}\n\tsign = -1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tpA = &local_A;\n\t\tBN_with_flags(pA, A, BN_FLG_CONSTTIME);\n\t\tif (!BN_div(D,M,pA,B,ctx)) goto err;\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=tmp;\n\t\tsign = -sign;\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n\t\tgoto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
1,376
| 0
|
https://github.com/libav/libav/blob/58ef4ecff834f47f5a4c2a6bd4385b1999a30930/libavcodec/h264.h/#L935
|
static void fill_decode_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
const uint8_t * left_block= h->left_block;
int i;
uint8_t *nnz;
uint8_t *nnz_cache;
topleft_xy = h->topleft_mb_xy;
top_xy = h->top_mb_xy;
topright_xy = h->topright_mb_xy;
left_xy[LTOP] = h->left_mb_xy[LTOP];
left_xy[LBOT] = h->left_mb_xy[LBOT];
topleft_type = h->topleft_type;
top_type = h->top_type;
topright_type = h->topright_type;
left_type[LTOP]= h->left_type[LTOP];
left_type[LBOT]= h->left_type[LBOT];
if(!IS_SKIP(mb_type)){
if(IS_INTRA(mb_type)){
int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
h->topleft_samples_available=
h->top_samples_available=
h->left_samples_available= 0xFFFF;
h->topright_samples_available= 0xEEEA;
if(!(top_type & type_mask)){
h->topleft_samples_available= 0xB3FF;
h->top_samples_available= 0x33FF;
h->topright_samples_available= 0x26EA;
}
if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){
if(IS_INTERLACED(mb_type)){
if(!(left_type[LTOP] & type_mask)){
h->topleft_samples_available&= 0xDFFF;
h->left_samples_available&= 0x5FFF;
}
if(!(left_type[LBOT] & type_mask)){
h->topleft_samples_available&= 0xFF5F;
h->left_samples_available&= 0xFF5F;
}
}else{
int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];
assert(left_xy[LTOP] == left_xy[LBOT]);
if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
}else{
if(!(left_type[LTOP] & type_mask)){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
if(!(topleft_type & type_mask))
h->topleft_samples_available&= 0x7FFF;
if(!(topright_type & type_mask))
h->topright_samples_available&= 0xFBFF;
if(IS_INTRA4x4(mb_type)){
if(IS_INTRA4x4(top_type)){
AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
}else{
h->intra4x4_pred_mode_cache[4+8*0]=
h->intra4x4_pred_mode_cache[5+8*0]=
h->intra4x4_pred_mode_cache[6+8*0]=
h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);
}
for(i=0; i<2; i++){
if(IS_INTRA4x4(left_type[LEFT(i)])){
int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
}else{
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);
}
}
}
}
nnz_cache = h->non_zero_count_cache;
if(top_type){
nnz = h->non_zero_count[top_xy];
AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);
if(CHROMA444){
AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);
AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);
}else{
AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);
AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);
}
}else{
uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
AV_WN32A(&nnz_cache[4+8* 0], top_empty);
AV_WN32A(&nnz_cache[4+8* 5], top_empty);
AV_WN32A(&nnz_cache[4+8*10], top_empty);
}
for (i=0; i<2; i++) {
if(left_type[LEFT(i)]){
nnz = h->non_zero_count[left_xy[LEFT(i)]];
nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];
nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];
if(CHROMA444){
nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];
nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];
nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];
nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];
}else{
nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];
nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];
}
}else{
nnz_cache[3+8* 1 + 2*8*i]=
nnz_cache[3+8* 2 + 2*8*i]=
nnz_cache[3+8* 6 + 2*8*i]=
nnz_cache[3+8* 7 + 2*8*i]=
nnz_cache[3+8*11 + 2*8*i]=
nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
}
}
if( CABAC ) {
if(top_type) {
h->top_cbp = h->cbp_table[top_xy];
} else {
h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
if (left_type[LTOP]) {
h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)
| ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)
| (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);
} else {
h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
}
}
if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
int list;
int b_stride = h->b_stride;
for(list=0; list<h->list_count; list++){
int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
int8_t *ref = s->current_picture.f.ref_index[list];
int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
int16_t (*mv)[2] = s->current_picture.f.motion_val[list];
if(!USES_LIST(mb_type, list)){
continue;
}
assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);
ref_cache[0 - 1*8]=
ref_cache[1 - 1*8]= ref[4*top_xy + 2];
ref_cache[2 - 1*8]=
ref_cache[3 - 1*8]= ref[4*top_xy + 3];
}else{
AV_ZERO128(mv_cache[0 - 1*8]);
AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);
}
if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
for(i=0; i<2; i++){
int cache_idx = -1 + i*2*8;
if(USES_LIST(left_type[LEFT(i)], list)){
const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;
const int b8_xy= 4*left_xy[LEFT(i)] + 1;
AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);
AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);
ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];
ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];
}else{
AV_ZERO32(mv_cache[cache_idx ]);
AV_ZERO32(mv_cache[cache_idx+8]);
ref_cache[cache_idx ]=
ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
}else{
if(USES_LIST(left_type[LTOP], list)){
const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
const int b8_xy= 4*left_xy[LTOP] + 1;
AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);
ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];
}else{
AV_ZERO32(mv_cache[-1]);
ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if(USES_LIST(topright_type, list)){
const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;
AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);
ref_cache[4 - 1*8]= ref[4*topright_xy + 2];
}else{
AV_ZERO32(mv_cache[4 - 1*8]);
ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
if(ref_cache[4 - 1*8] < 0){
if(USES_LIST(topleft_type, list)){
const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);
const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);
ref_cache[-1 - 1*8]= ref[b8_xy];
}else{
AV_ZERO32(mv_cache[-1 - 1*8]);
ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
continue;
if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){
uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
uint8_t (*mvd)[2] = h->mvd_table[list];
ref_cache[2+8*0] =
ref_cache[2+8*2] = PART_NOT_AVAILABLE;
AV_ZERO32(mv_cache[2+8*0]);
AV_ZERO32(mv_cache[2+8*2]);
if( CABAC ) {
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2br_xy[top_xy];
AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);
}else{
AV_ZERO64(mvd_cache[0 - 1*8]);
}
if(USES_LIST(left_type[LTOP], list)){
const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;
AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);
AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);
}else{
AV_ZERO16(mvd_cache[-1 + 0*8]);
AV_ZERO16(mvd_cache[-1 + 1*8]);
}
if(USES_LIST(left_type[LBOT], list)){
const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;
AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);
AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);
}else{
AV_ZERO16(mvd_cache[-1 + 2*8]);
AV_ZERO16(mvd_cache[-1 + 3*8]);
}
AV_ZERO16(mvd_cache[2+8*0]);
AV_ZERO16(mvd_cache[2+8*2]);
if(h->slice_type_nos == AV_PICTURE_TYPE_B){
uint8_t *direct_cache = &h->direct_cache[scan8[0]];
uint8_t *direct_table = h->direct_table;
fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);
if(IS_DIRECT(top_type)){
AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
}else if(IS_8X8(top_type)){
int b8_xy = 4*top_xy;
direct_cache[0 - 1*8]= direct_table[b8_xy + 2];
direct_cache[2 - 1*8]= direct_table[b8_xy + 3];
}else{
AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));
}
if(IS_DIRECT(left_type[LTOP]))
direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[LTOP]))
direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];
else
direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;
if(IS_DIRECT(left_type[LBOT]))
direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[LBOT]))
direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];
else
direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;
}
}
}
if(FRAME_MBAFF){
#define MAP_MVS\
MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\
MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\
MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\
MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])
if(MB_FIELD){
#define MAP_F2F(idx, mb_type)\
if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] <<= 1;\
h->mv_cache[list][idx][1] /= 2;\
h->mvd_cache[list][idx][1] >>=1;\
}
MAP_MVS
#undef MAP_F2F
}else{
#define MAP_F2F(idx, mb_type)\
if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] >>= 1;\
h->mv_cache[list][idx][1] <<= 1;\
h->mvd_cache[list][idx][1] <<= 1;\
}
MAP_MVS
#undef MAP_F2F
}
}
}
}
h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
}
|
['static void av_unused decode_mb_skip(H264Context *h){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int mb_type=0;\n memset(h->non_zero_count[mb_xy], 0, 48);\n if(MB_FIELD)\n mb_type|= MB_TYPE_INTERLACED;\n if( h->slice_type_nos == AV_PICTURE_TYPE_B )\n {\n mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;\n if(h->direct_spatial_mv_pred){\n fill_decode_neighbors(h, mb_type);\n fill_decode_caches(h, mb_type);\n }\n ff_h264_pred_direct_motion(h, &mb_type);\n mb_type|= MB_TYPE_SKIP;\n }\n else\n {\n mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP;\n fill_decode_neighbors(h, mb_type);\n pred_pskip_motion(h);\n }\n write_back_motion(h, mb_type);\n s->current_picture.f.mb_type[mb_xy] = mb_type;\n s->current_picture.f.qscale_table[mb_xy] = s->qscale;\n h->slice_table[ mb_xy ]= h->slice_num;\n h->prev_mb_skipped= 1;\n}', 'static void fill_decode_neighbors(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n const int mb_xy= h->mb_xy;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n static const uint8_t left_block_options[4][32]={\n {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},\n {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},\n {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},\n {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1);\n topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1);\n top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy ] >> 7) & 1) - 1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = s->current_picture.f.mb_type[topleft_xy];\n h->top_type = s->current_picture.f.mb_type[top_xy];\n h->topright_type = s->current_picture.f.mb_type[topright_xy];\n h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];\n h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];\n if(FMO){\n if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }else{\n if(h->slice_table[topleft_xy ] != h->slice_num){\n h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t * left_block= h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP]= h->left_type[LTOP];\n left_type[LBOT]= h->left_type[LBOT];\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[LBOT] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n }else{\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[LEFT(i)])){\n int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];\n }else{\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if(top_type){\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);\n if(CHROMA444){\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);\n }else{\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);\n }\n }else{\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n for (i=0; i<2; i++) {\n if(left_type[LEFT(i)]){\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];\n nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];\n if(CHROMA444){\n nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];\n nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];\n nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];\n nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];\n }else{\n nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];\n nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];\n }\n }else{\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else {\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)\n | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)\n | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n int b_stride = h->b_stride;\n for(list=0; list<h->list_count; list++){\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = s->current_picture.f.ref_index[list];\n int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t (*mv)[2] = s->current_picture.f.motion_val[list];\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;\n AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);\n ref_cache[0 - 1*8]=\n ref_cache[1 - 1*8]= ref[4*top_xy + 2];\n ref_cache[2 - 1*8]=\n ref_cache[3 - 1*8]= ref[4*top_xy + 3];\n }else{\n AV_ZERO128(mv_cache[0 - 1*8]);\n AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){\n for(i=0; i<2; i++){\n int cache_idx = -1 + i*2*8;\n if(USES_LIST(left_type[LEFT(i)], list)){\n const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy= 4*left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);\n AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);\n ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];\n ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];\n }else{\n AV_ZERO32(mv_cache[cache_idx ]);\n AV_ZERO32(mv_cache[cache_idx+8]);\n ref_cache[cache_idx ]=\n ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n }else{\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy= 4*left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);\n ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];\n }else{\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;\n AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);\n ref_cache[4 - 1*8]= ref[4*topright_xy + 2];\n }else{\n AV_ZERO32(mv_cache[4 - 1*8]);\n ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(ref_cache[4 - 1*8] < 0){\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);\n const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);\n ref_cache[-1 - 1*8]= ref[b8_xy];\n }else{\n AV_ZERO32(mv_cache[-1 - 1*8]);\n ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){\n uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t (*mvd)[2] = h->mvd_table[list];\n ref_cache[2+8*0] =\n ref_cache[2+8*2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2+8*0]);\n AV_ZERO32(mv_cache[2+8*2]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);\n }else{\n AV_ZERO64(mvd_cache[0 - 1*8]);\n }\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 0*8]);\n AV_ZERO16(mvd_cache[-1 + 1*8]);\n }\n if(USES_LIST(left_type[LBOT], list)){\n const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 2*8]);\n AV_ZERO16(mvd_cache[-1 + 3*8]);\n }\n AV_ZERO16(mvd_cache[2+8*0]);\n AV_ZERO16(mvd_cache[2+8*2]);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = 4*top_xy;\n direct_cache[0 - 1*8]= direct_table[b8_xy + 2];\n direct_cache[2 - 1*8]= direct_table[b8_xy + 3];\n }else{\n AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];\n else\n direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];\n else\n direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] >>=1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
|
1,377
| 0
|
https://github.com/openssl/openssl/blob/6bc62a620e715f7580651ca932eab052aa527886/crypto/bn/bn_ctx.c/#L268
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int test_check_private_exponent(void)\n{\n int ret = 0;\n RSA *key = NULL;\n BN_CTX *ctx = NULL;\n BIGNUM *p = NULL, *q = NULL, *e = NULL, *d = NULL, *n = NULL;\n ret = TEST_ptr(key = RSA_new())\n && TEST_ptr(ctx = BN_CTX_new())\n && TEST_ptr(p = BN_new())\n && TEST_ptr(q = BN_new())\n && TEST_ptr(e = BN_new())\n && TEST_ptr(d = BN_new())\n && TEST_ptr(n = BN_new())\n && TEST_true(BN_set_word(p, 15))\n && TEST_true(BN_set_word(q, 17))\n && TEST_true(BN_set_word(e, 5))\n && TEST_true(BN_set_word(d, 157))\n && TEST_true(BN_set_word(n, 15*17))\n && TEST_true(RSA_set0_factors(key, p, q))\n && TEST_true(RSA_set0_key(key, n, e, d))\n && TEST_false(rsa_check_private_exponent(key, 8, ctx))\n && TEST_true(BN_set_word(d, 45))\n && TEST_true(rsa_check_private_exponent(key, 8, ctx))\n && TEST_false(rsa_check_private_exponent(key, 16, ctx))\n && TEST_true(BN_set_word(d, 16))\n && TEST_false(rsa_check_private_exponent(key, 8, ctx))\n && TEST_true(BN_set_word(d, 46))\n && TEST_false(rsa_check_private_exponent(key, 8, ctx));\n RSA_free(key);\n BN_CTX_free(ctx);\n return ret;\n}', 'int rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)\n{\n int ret;\n BIGNUM *r, *p1, *q1, *lcm, *p1q1, *gcd;\n if (BN_num_bits(rsa->d) <= (nbits >> 1))\n return 0;\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n p1 = BN_CTX_get(ctx);\n q1 = BN_CTX_get(ctx);\n lcm = BN_CTX_get(ctx);\n p1q1 = BN_CTX_get(ctx);\n gcd = BN_CTX_get(ctx);\n ret = (gcd != NULL\n && (rsa_get_lcm(ctx, rsa->p, rsa->q, lcm, gcd, p1, q1, p1q1) == 1)\n && (BN_cmp(rsa->d, lcm) < 0)\n && BN_mod_mul(r, rsa->e, rsa->d, lcm, ctx)\n && BN_is_one(r));\n BN_clear(p1);\n BN_clear(q1);\n BN_clear(lcm);\n BN_clear(gcd);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'int rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q,\n BIGNUM *lcm, BIGNUM *gcd, BIGNUM *p1, BIGNUM *q1,\n BIGNUM *p1q1)\n{\n return BN_sub(p1, p, BN_value_one())\n && BN_sub(q1, q, BN_value_one())\n && BN_mul(p1q1, p1, q1, ctx)\n && BN_gcd(gcd, p1, q1, ctx)\n && BN_div(lcm, NULL, p1q1, gcd, ctx);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,378
| 1
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_mont.c/#L114
|
static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
{
BIGNUM *n;
BN_ULONG *ap, *np, *rp, n0, v, carry;
int nl, max, i;
n = &(mont->N);
nl = n->top;
if (nl == 0) {
ret->top = 0;
return 1;
}
max = (2 * nl);
if (bn_wexpand(r, max) == NULL)
return 0;
r->neg ^= n->neg;
np = n->d;
rp = r->d;
i = max - r->top;
if (i)
memset(&rp[r->top], 0, sizeof(*rp) * i);
r->top = max;
n0 = mont->n0[0];
for (carry = 0, i = 0; i < nl; i++, rp++) {
v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);
v = (v + carry + rp[nl]) & BN_MASK2;
carry |= (v != rp[nl]);
carry &= (v <= rp[nl]);
rp[nl] = v;
}
if (bn_wexpand(ret, nl) == NULL)
return 0;
ret->top = nl;
ret->neg = r->neg;
rp = ret->d;
ap = &(r->d[nl]);
carry -= bn_sub_words(rp, ap, np, nl);
for (i = 0; i < nl; i++) {
rp[i] = (carry & ap[i]) | (~carry & rp[i]);
ap[i] = 0;
}
bn_correct_top(r);
bn_correct_top(ret);
bn_check_top(ret);
return 1;
}
|
['int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return 1;\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return 0;\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n i = max - r->top;\n if (i)\n memset(&rp[r->top], 0, sizeof(*rp) * i);\n r->top = max;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return 0;\n ret->top = nl;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n carry -= bn_sub_words(rp, ap, np, nl);\n for (i = 0; i < nl; i++) {\n rp[i] = (carry & ap[i]) | (~carry & rp[i]);\n ap[i] = 0;\n }\n bn_correct_top(r);\n bn_correct_top(ret);\n bn_check_top(ret);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,379
| 0
|
https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/mpegaudiodec.c/#L715
|
static void dct32(INTFLOAT *out, const INTFLOAT *tab)
{
INTFLOAT tmp0, tmp1;
INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,
val8 , val9 , val10, val11, val12, val13, val14, val15,
val16, val17, val18, val19, val20, val21, val22, val23,
val24, val25, val26, val27, val28, val29, val30, val31;
BF0( 0, 31, COS0_0 , 1);
BF0(15, 16, COS0_15, 5);
BF( 0, 15, COS1_0 , 1);
BF(16, 31,-COS1_0 , 1);
BF0( 7, 24, COS0_7 , 1);
BF0( 8, 23, COS0_8 , 1);
BF( 7, 8, COS1_7 , 4);
BF(23, 24,-COS1_7 , 4);
BF( 0, 7, COS2_0 , 1);
BF( 8, 15,-COS2_0 , 1);
BF(16, 23, COS2_0 , 1);
BF(24, 31,-COS2_0 , 1);
BF0( 3, 28, COS0_3 , 1);
BF0(12, 19, COS0_12, 2);
BF( 3, 12, COS1_3 , 1);
BF(19, 28,-COS1_3 , 1);
BF0( 4, 27, COS0_4 , 1);
BF0(11, 20, COS0_11, 2);
BF( 4, 11, COS1_4 , 1);
BF(20, 27,-COS1_4 , 1);
BF( 3, 4, COS2_3 , 3);
BF(11, 12,-COS2_3 , 3);
BF(19, 20, COS2_3 , 3);
BF(27, 28,-COS2_3 , 3);
BF( 0, 3, COS3_0 , 1);
BF( 4, 7,-COS3_0 , 1);
BF( 8, 11, COS3_0 , 1);
BF(12, 15,-COS3_0 , 1);
BF(16, 19, COS3_0 , 1);
BF(20, 23,-COS3_0 , 1);
BF(24, 27, COS3_0 , 1);
BF(28, 31,-COS3_0 , 1);
BF0( 1, 30, COS0_1 , 1);
BF0(14, 17, COS0_14, 3);
BF( 1, 14, COS1_1 , 1);
BF(17, 30,-COS1_1 , 1);
BF0( 6, 25, COS0_6 , 1);
BF0( 9, 22, COS0_9 , 1);
BF( 6, 9, COS1_6 , 2);
BF(22, 25,-COS1_6 , 2);
BF( 1, 6, COS2_1 , 1);
BF( 9, 14,-COS2_1 , 1);
BF(17, 22, COS2_1 , 1);
BF(25, 30,-COS2_1 , 1);
BF0( 2, 29, COS0_2 , 1);
BF0(13, 18, COS0_13, 3);
BF( 2, 13, COS1_2 , 1);
BF(18, 29,-COS1_2 , 1);
BF0( 5, 26, COS0_5 , 1);
BF0(10, 21, COS0_10, 1);
BF( 5, 10, COS1_5 , 2);
BF(21, 26,-COS1_5 , 2);
BF( 2, 5, COS2_2 , 1);
BF(10, 13,-COS2_2 , 1);
BF(18, 21, COS2_2 , 1);
BF(26, 29,-COS2_2 , 1);
BF( 1, 2, COS3_1 , 2);
BF( 5, 6,-COS3_1 , 2);
BF( 9, 10, COS3_1 , 2);
BF(13, 14,-COS3_1 , 2);
BF(17, 18, COS3_1 , 2);
BF(21, 22,-COS3_1 , 2);
BF(25, 26, COS3_1 , 2);
BF(29, 30,-COS3_1 , 2);
BF1( 0, 1, 2, 3);
BF2( 4, 5, 6, 7);
BF1( 8, 9, 10, 11);
BF2(12, 13, 14, 15);
BF1(16, 17, 18, 19);
BF2(20, 21, 22, 23);
BF1(24, 25, 26, 27);
BF2(28, 29, 30, 31);
ADD( 8, 12);
ADD(12, 10);
ADD(10, 14);
ADD(14, 9);
ADD( 9, 13);
ADD(13, 11);
ADD(11, 15);
out[ 0] = val0;
out[16] = val1;
out[ 8] = val2;
out[24] = val3;
out[ 4] = val4;
out[20] = val5;
out[12] = val6;
out[28] = val7;
out[ 2] = val8;
out[18] = val9;
out[10] = val10;
out[26] = val11;
out[ 6] = val12;
out[22] = val13;
out[14] = val14;
out[30] = val15;
ADD(24, 28);
ADD(28, 26);
ADD(26, 30);
ADD(30, 25);
ADD(25, 29);
ADD(29, 27);
ADD(27, 31);
out[ 1] = val16 + val24;
out[17] = val17 + val25;
out[ 9] = val18 + val26;
out[25] = val19 + val27;
out[ 5] = val20 + val28;
out[21] = val21 + val29;
out[13] = val22 + val30;
out[29] = val23 + val31;
out[ 3] = val24 + val20;
out[19] = val25 + val21;
out[11] = val26 + val22;
out[27] = val27 + val23;
out[ 7] = val28 + val18;
out[23] = val29 + val19;
out[15] = val30 + val17;
out[31] = val31;
}
|
['static void mpc_synth(MPCContext *c, int16_t *out)\n{\n int dither_state = 0;\n int i, ch;\n OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE], *samples_ptr;\n for(ch = 0; ch < 2; ch++){\n samples_ptr = samples + ch;\n for(i = 0; i < SAMPLES_PER_BAND; i++) {\n ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]),\n ff_mpa_synth_window, &dither_state,\n samples_ptr, 2,\n c->sb_samples[ch][i]);\n samples_ptr += 64;\n }\n }\n for(i = 0; i < MPC_FRAME_SIZE*2; i++)\n *out++=samples[i];\n}', 'void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,\n MPA_INT *window, int *dither_state,\n OUT_INT *samples, int incr,\n INTFLOAT sb_samples[SBLIMIT])\n{\n register MPA_INT *synth_buf;\n int offset;\n#if FRAC_BITS <= 15\n int32_t tmp[32];\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15 && !CONFIG_FLOAT\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void dct32(INTFLOAT *out, const INTFLOAT *tab)\n{\n INTFLOAT tmp0, tmp1;\n INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,\n val8 , val9 , val10, val11, val12, val13, val14, val15,\n val16, val17, val18, val19, val20, val21, val22, val23,\n val24, val25, val26, val27, val28, val29, val30, val31;\n BF0( 0, 31, COS0_0 , 1);\n BF0(15, 16, COS0_15, 5);\n BF( 0, 15, COS1_0 , 1);\n BF(16, 31,-COS1_0 , 1);\n BF0( 7, 24, COS0_7 , 1);\n BF0( 8, 23, COS0_8 , 1);\n BF( 7, 8, COS1_7 , 4);\n BF(23, 24,-COS1_7 , 4);\n BF( 0, 7, COS2_0 , 1);\n BF( 8, 15,-COS2_0 , 1);\n BF(16, 23, COS2_0 , 1);\n BF(24, 31,-COS2_0 , 1);\n BF0( 3, 28, COS0_3 , 1);\n BF0(12, 19, COS0_12, 2);\n BF( 3, 12, COS1_3 , 1);\n BF(19, 28,-COS1_3 , 1);\n BF0( 4, 27, COS0_4 , 1);\n BF0(11, 20, COS0_11, 2);\n BF( 4, 11, COS1_4 , 1);\n BF(20, 27,-COS1_4 , 1);\n BF( 3, 4, COS2_3 , 3);\n BF(11, 12,-COS2_3 , 3);\n BF(19, 20, COS2_3 , 3);\n BF(27, 28,-COS2_3 , 3);\n BF( 0, 3, COS3_0 , 1);\n BF( 4, 7,-COS3_0 , 1);\n BF( 8, 11, COS3_0 , 1);\n BF(12, 15,-COS3_0 , 1);\n BF(16, 19, COS3_0 , 1);\n BF(20, 23,-COS3_0 , 1);\n BF(24, 27, COS3_0 , 1);\n BF(28, 31,-COS3_0 , 1);\n BF0( 1, 30, COS0_1 , 1);\n BF0(14, 17, COS0_14, 3);\n BF( 1, 14, COS1_1 , 1);\n BF(17, 30,-COS1_1 , 1);\n BF0( 6, 25, COS0_6 , 1);\n BF0( 9, 22, COS0_9 , 1);\n BF( 6, 9, COS1_6 , 2);\n BF(22, 25,-COS1_6 , 2);\n BF( 1, 6, COS2_1 , 1);\n BF( 9, 14,-COS2_1 , 1);\n BF(17, 22, COS2_1 , 1);\n BF(25, 30,-COS2_1 , 1);\n BF0( 2, 29, COS0_2 , 1);\n BF0(13, 18, COS0_13, 3);\n BF( 2, 13, COS1_2 , 1);\n BF(18, 29,-COS1_2 , 1);\n BF0( 5, 26, COS0_5 , 1);\n BF0(10, 21, COS0_10, 1);\n BF( 5, 10, COS1_5 , 2);\n BF(21, 26,-COS1_5 , 2);\n BF( 2, 5, COS2_2 , 1);\n BF(10, 13,-COS2_2 , 1);\n BF(18, 21, COS2_2 , 1);\n BF(26, 29,-COS2_2 , 1);\n BF( 1, 2, COS3_1 , 2);\n BF( 5, 6,-COS3_1 , 2);\n BF( 9, 10, COS3_1 , 2);\n BF(13, 14,-COS3_1 , 2);\n BF(17, 18, COS3_1 , 2);\n BF(21, 22,-COS3_1 , 2);\n BF(25, 26, COS3_1 , 2);\n BF(29, 30,-COS3_1 , 2);\n BF1( 0, 1, 2, 3);\n BF2( 4, 5, 6, 7);\n BF1( 8, 9, 10, 11);\n BF2(12, 13, 14, 15);\n BF1(16, 17, 18, 19);\n BF2(20, 21, 22, 23);\n BF1(24, 25, 26, 27);\n BF2(28, 29, 30, 31);\n ADD( 8, 12);\n ADD(12, 10);\n ADD(10, 14);\n ADD(14, 9);\n ADD( 9, 13);\n ADD(13, 11);\n ADD(11, 15);\n out[ 0] = val0;\n out[16] = val1;\n out[ 8] = val2;\n out[24] = val3;\n out[ 4] = val4;\n out[20] = val5;\n out[12] = val6;\n out[28] = val7;\n out[ 2] = val8;\n out[18] = val9;\n out[10] = val10;\n out[26] = val11;\n out[ 6] = val12;\n out[22] = val13;\n out[14] = val14;\n out[30] = val15;\n ADD(24, 28);\n ADD(28, 26);\n ADD(26, 30);\n ADD(30, 25);\n ADD(25, 29);\n ADD(29, 27);\n ADD(27, 31);\n out[ 1] = val16 + val24;\n out[17] = val17 + val25;\n out[ 9] = val18 + val26;\n out[25] = val19 + val27;\n out[ 5] = val20 + val28;\n out[21] = val21 + val29;\n out[13] = val22 + val30;\n out[29] = val23 + val31;\n out[ 3] = val24 + val20;\n out[19] = val25 + val21;\n out[11] = val26 + val22;\n out[27] = val27 + val23;\n out[ 7] = val28 + val18;\n out[23] = val29 + val19;\n out[15] = val30 + val17;\n out[31] = val31;\n}']
|
1,380
| 0
|
https://github.com/openssl/openssl/blob/d4b009d5f88875ac0e3ac0b2b9689ed16a4c88dc/crypto/x509v3/v3_addr.c/#L1091
|
static void *v2i_IPAddrBlocks(const struct v3_ext_method *method,
struct v3_ext_ctx *ctx,
STACK_OF(CONF_VALUE) *values)
{
static const char v4addr_chars[] = "0123456789.";
static const char v6addr_chars[] = "0123456789.:abcdefABCDEF";
IPAddrBlocks *addr = NULL;
char *s = NULL, *t;
int i;
if ((addr = sk_IPAddressFamily_new(IPAddressFamily_cmp)) == NULL) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
return NULL;
}
for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN];
unsigned afi, *safi = NULL, safi_;
const char *addr_chars = NULL;
int prefixlen, i1, i2, delim, length;
if (!name_cmp(val->name, "IPv4")) {
afi = IANA_AFI_IPV4;
} else if (!name_cmp(val->name, "IPv6")) {
afi = IANA_AFI_IPV6;
} else if (!name_cmp(val->name, "IPv4-SAFI")) {
afi = IANA_AFI_IPV4;
safi = &safi_;
} else if (!name_cmp(val->name, "IPv6-SAFI")) {
afi = IANA_AFI_IPV6;
safi = &safi_;
} else {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_EXTENSION_NAME_ERROR);
X509V3_conf_err(val);
goto err;
}
switch (afi) {
case IANA_AFI_IPV4:
addr_chars = v4addr_chars;
break;
case IANA_AFI_IPV6:
addr_chars = v6addr_chars;
break;
}
length = length_from_afi(afi);
if (safi != NULL) {
*safi = strtoul(val->value, &t, 0);
t += strspn(t, " \t");
if (*safi > 0xFF || *t++ != ':') {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_SAFI);
X509V3_conf_err(val);
goto err;
}
t += strspn(t, " \t");
s = OPENSSL_strdup(t);
} else {
s = OPENSSL_strdup(val->value);
}
if (s == NULL) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
goto err;
}
if (strcmp(s, "inherit") == 0) {
if (!v3_addr_add_inherit(addr, afi, safi)) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_INVALID_INHERITANCE);
X509V3_conf_err(val);
goto err;
}
OPENSSL_free(s);
s = NULL;
continue;
}
i1 = strspn(s, addr_chars);
i2 = i1 + strspn(s + i1, " \t");
delim = s[i2++];
s[i1] = '\0';
if (a2i_ipadd(min, s) != length) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
X509V3_conf_err(val);
goto err;
}
switch (delim) {
case '/':
prefixlen = (int)strtoul(s + i2, &t, 10);
if (t == s + i2 || *t != '\0') {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_EXTENSION_VALUE_ERROR);
X509V3_conf_err(val);
goto err;
}
if (!v3_addr_add_prefix(addr, afi, safi, min, prefixlen)) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
goto err;
}
break;
case '-':
i1 = i2 + strspn(s + i2, " \t");
i2 = i1 + strspn(s + i1, addr_chars);
if (i1 == i2 || s[i2] != '\0') {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_EXTENSION_VALUE_ERROR);
X509V3_conf_err(val);
goto err;
}
if (a2i_ipadd(max, s + i1) != length) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_INVALID_IPADDRESS);
X509V3_conf_err(val);
goto err;
}
if (memcmp(min, max, length_from_afi(afi)) > 0) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_EXTENSION_VALUE_ERROR);
X509V3_conf_err(val);
goto err;
}
if (!v3_addr_add_range(addr, afi, safi, min, max)) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
goto err;
}
break;
case '\0':
if (!v3_addr_add_prefix(addr, afi, safi, min, length * 8)) {
X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
goto err;
}
break;
default:
X509V3err(X509V3_F_V2I_IPADDRBLOCKS,
X509V3_R_EXTENSION_VALUE_ERROR);
X509V3_conf_err(val);
goto err;
}
OPENSSL_free(s);
s = NULL;
}
if (!v3_addr_canonize(addr))
goto err;
return addr;
err:
OPENSSL_free(s);
sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
return NULL;
}
|
['static void *v2i_IPAddrBlocks(const struct v3_ext_method *method,\n struct v3_ext_ctx *ctx,\n STACK_OF(CONF_VALUE) *values)\n{\n static const char v4addr_chars[] = "0123456789.";\n static const char v6addr_chars[] = "0123456789.:abcdefABCDEF";\n IPAddrBlocks *addr = NULL;\n char *s = NULL, *t;\n int i;\n if ((addr = sk_IPAddressFamily_new(IPAddressFamily_cmp)) == NULL) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n for (i = 0; i < sk_CONF_VALUE_num(values); i++) {\n CONF_VALUE *val = sk_CONF_VALUE_value(values, i);\n unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN];\n unsigned afi, *safi = NULL, safi_;\n const char *addr_chars = NULL;\n int prefixlen, i1, i2, delim, length;\n if (!name_cmp(val->name, "IPv4")) {\n afi = IANA_AFI_IPV4;\n } else if (!name_cmp(val->name, "IPv6")) {\n afi = IANA_AFI_IPV6;\n } else if (!name_cmp(val->name, "IPv4-SAFI")) {\n afi = IANA_AFI_IPV4;\n safi = &safi_;\n } else if (!name_cmp(val->name, "IPv6-SAFI")) {\n afi = IANA_AFI_IPV6;\n safi = &safi_;\n } else {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_EXTENSION_NAME_ERROR);\n X509V3_conf_err(val);\n goto err;\n }\n switch (afi) {\n case IANA_AFI_IPV4:\n addr_chars = v4addr_chars;\n break;\n case IANA_AFI_IPV6:\n addr_chars = v6addr_chars;\n break;\n }\n length = length_from_afi(afi);\n if (safi != NULL) {\n *safi = strtoul(val->value, &t, 0);\n t += strspn(t, " \\t");\n if (*safi > 0xFF || *t++ != \':\') {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_SAFI);\n X509V3_conf_err(val);\n goto err;\n }\n t += strspn(t, " \\t");\n s = OPENSSL_strdup(t);\n } else {\n s = OPENSSL_strdup(val->value);\n }\n if (s == NULL) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (strcmp(s, "inherit") == 0) {\n if (!v3_addr_add_inherit(addr, afi, safi)) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_INVALID_INHERITANCE);\n X509V3_conf_err(val);\n goto err;\n }\n OPENSSL_free(s);\n s = NULL;\n continue;\n }\n i1 = strspn(s, addr_chars);\n i2 = i1 + strspn(s + i1, " \\t");\n delim = s[i2++];\n s[i1] = \'\\0\';\n if (a2i_ipadd(min, s) != length) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);\n X509V3_conf_err(val);\n goto err;\n }\n switch (delim) {\n case \'/\':\n prefixlen = (int)strtoul(s + i2, &t, 10);\n if (t == s + i2 || *t != \'\\0\') {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_EXTENSION_VALUE_ERROR);\n X509V3_conf_err(val);\n goto err;\n }\n if (!v3_addr_add_prefix(addr, afi, safi, min, prefixlen)) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n break;\n case \'-\':\n i1 = i2 + strspn(s + i2, " \\t");\n i2 = i1 + strspn(s + i1, addr_chars);\n if (i1 == i2 || s[i2] != \'\\0\') {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_EXTENSION_VALUE_ERROR);\n X509V3_conf_err(val);\n goto err;\n }\n if (a2i_ipadd(max, s + i1) != length) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_INVALID_IPADDRESS);\n X509V3_conf_err(val);\n goto err;\n }\n if (memcmp(min, max, length_from_afi(afi)) > 0) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_EXTENSION_VALUE_ERROR);\n X509V3_conf_err(val);\n goto err;\n }\n if (!v3_addr_add_range(addr, afi, safi, min, max)) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n break;\n case \'\\0\':\n if (!v3_addr_add_prefix(addr, afi, safi, min, length * 8)) {\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n break;\n default:\n X509V3err(X509V3_F_V2I_IPADDRBLOCKS,\n X509V3_R_EXTENSION_VALUE_ERROR);\n X509V3_conf_err(val);\n goto err;\n }\n OPENSSL_free(s);\n s = NULL;\n }\n if (!v3_addr_canonize(addr))\n goto err;\n return addr;\n err:\n OPENSSL_free(s);\n sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);\n return NULL;\n}', 'DEFINE_STACK_OF(IPAddressFamily)', '_STACK *sk_new(int (*c) (const void *, const void *))\n{\n _STACK *ret;\n if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL)\n goto err;\n if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL)\n goto err;\n ret->comp = c;\n ret->num_alloc = MIN_NODES;\n return (ret);\n err:\n OPENSSL_free(ret);\n return (NULL);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int sk_num(const _STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}']
|
1,381
| 0
|
https://github.com/openssl/openssl/blob/4b8515baa6edef1a771f9e4e3fbc0395b4a629e8/crypto/bn/bn_ctx.c/#L273
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int test_mod()\n{\n BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL;\n int st = 0, i;\n if (!TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_ptr(c = BN_new())\n || !TEST_ptr(d = BN_new())\n || !TEST_ptr(e = BN_new()))\n goto err;\n BN_bntest_rand(a, 1024, 0, 0);\n for (i = 0; i < NUM0; i++) {\n BN_bntest_rand(b, 450 + i * 10, 0, 0);\n a->neg = rand_neg();\n b->neg = rand_neg();\n BN_mod(c, a, b, ctx);\n BN_div(d, e, a, b, ctx);\n BN_sub(e, e, c);\n if (!TEST_BN_eq_zero(e))\n goto err;\n }\n st = 1;\nerr:\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n BN_free(e);\n return st;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'void BN_CTX_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}']
|
1,382
| 0
|
https://github.com/nginx/nginx/blob/492844dbb18035617b6c220c4a857d9333c6ea61/src/http/modules/ngx_http_autoindex_module.c/#L887
|
static ngx_buf_t *
ngx_http_autoindex_xml(ngx_http_request_t *r, ngx_array_t *entries)
{
size_t len;
ngx_tm_t tm;
ngx_buf_t *b;
ngx_str_t type;
ngx_uint_t i;
ngx_http_autoindex_entry_t *entry;
static u_char head[] = "<?xml version=\"1.0\"?>" CRLF "<list>" CRLF;
static u_char tail[] = "</list>" CRLF;
len = sizeof(head) - 1 + sizeof(tail) - 1;
entry = entries->elts;
for (i = 0; i < entries->nelts; i++) {
entry[i].escape = ngx_escape_html(NULL, entry[i].name.data,
entry[i].name.len);
len += sizeof("<directory></directory>" CRLF) - 1
+ entry[i].name.len + entry[i].escape
+ sizeof(" mtime=\"1986-12-31T10:00:00Z\"") - 1;
if (entry[i].file) {
len += sizeof(" size=\"\"") - 1 + NGX_OFF_T_LEN;
}
}
b = ngx_create_temp_buf(r->pool, len);
if (b == NULL) {
return NULL;
}
b->last = ngx_cpymem(b->last, head, sizeof(head) - 1);
for (i = 0; i < entries->nelts; i++) {
*b->last++ = '<';
if (entry[i].dir) {
ngx_str_set(&type, "directory");
} else if (entry[i].file) {
ngx_str_set(&type, "file");
} else {
ngx_str_set(&type, "other");
}
b->last = ngx_cpymem(b->last, type.data, type.len);
b->last = ngx_cpymem(b->last, " mtime=\"", sizeof(" mtime=\"") - 1);
ngx_gmtime(entry[i].mtime, &tm);
b->last = ngx_sprintf(b->last, "%4d-%02d-%02dT%02d:%02d:%02dZ",
tm.ngx_tm_year, tm.ngx_tm_mon,
tm.ngx_tm_mday, tm.ngx_tm_hour,
tm.ngx_tm_min, tm.ngx_tm_sec);
if (entry[i].file) {
b->last = ngx_cpymem(b->last, "\" size=\"",
sizeof("\" size=\"") - 1);
b->last = ngx_sprintf(b->last, "%O", entry[i].size);
}
*b->last++ = '"'; *b->last++ = '>';
if (entry[i].escape) {
b->last = (u_char *) ngx_escape_html(b->last, entry[i].name.data,
entry[i].name.len);
} else {
b->last = ngx_cpymem(b->last, entry[i].name.data,
entry[i].name.len);
}
*b->last++ = '<'; *b->last++ = '/';
b->last = ngx_cpymem(b->last, type.data, type.len);
*b->last++ = '>';
*b->last++ = CR; *b->last++ = LF;
}
b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);
return b;
}
|
['static ngx_buf_t *\nngx_http_autoindex_xml(ngx_http_request_t *r, ngx_array_t *entries)\n{\n size_t len;\n ngx_tm_t tm;\n ngx_buf_t *b;\n ngx_str_t type;\n ngx_uint_t i;\n ngx_http_autoindex_entry_t *entry;\n static u_char head[] = "<?xml version=\\"1.0\\"?>" CRLF "<list>" CRLF;\n static u_char tail[] = "</list>" CRLF;\n len = sizeof(head) - 1 + sizeof(tail) - 1;\n entry = entries->elts;\n for (i = 0; i < entries->nelts; i++) {\n entry[i].escape = ngx_escape_html(NULL, entry[i].name.data,\n entry[i].name.len);\n len += sizeof("<directory></directory>" CRLF) - 1\n + entry[i].name.len + entry[i].escape\n + sizeof(" mtime=\\"1986-12-31T10:00:00Z\\"") - 1;\n if (entry[i].file) {\n len += sizeof(" size=\\"\\"") - 1 + NGX_OFF_T_LEN;\n }\n }\n b = ngx_create_temp_buf(r->pool, len);\n if (b == NULL) {\n return NULL;\n }\n b->last = ngx_cpymem(b->last, head, sizeof(head) - 1);\n for (i = 0; i < entries->nelts; i++) {\n *b->last++ = \'<\';\n if (entry[i].dir) {\n ngx_str_set(&type, "directory");\n } else if (entry[i].file) {\n ngx_str_set(&type, "file");\n } else {\n ngx_str_set(&type, "other");\n }\n b->last = ngx_cpymem(b->last, type.data, type.len);\n b->last = ngx_cpymem(b->last, " mtime=\\"", sizeof(" mtime=\\"") - 1);\n ngx_gmtime(entry[i].mtime, &tm);\n b->last = ngx_sprintf(b->last, "%4d-%02d-%02dT%02d:%02d:%02dZ",\n tm.ngx_tm_year, tm.ngx_tm_mon,\n tm.ngx_tm_mday, tm.ngx_tm_hour,\n tm.ngx_tm_min, tm.ngx_tm_sec);\n if (entry[i].file) {\n b->last = ngx_cpymem(b->last, "\\" size=\\"",\n sizeof("\\" size=\\"") - 1);\n b->last = ngx_sprintf(b->last, "%O", entry[i].size);\n }\n *b->last++ = \'"\'; *b->last++ = \'>\';\n if (entry[i].escape) {\n b->last = (u_char *) ngx_escape_html(b->last, entry[i].name.data,\n entry[i].name.len);\n } else {\n b->last = ngx_cpymem(b->last, entry[i].name.data,\n entry[i].name.len);\n }\n *b->last++ = \'<\'; *b->last++ = \'/\';\n b->last = ngx_cpymem(b->last, type.data, type.len);\n *b->last++ = \'>\';\n *b->last++ = CR; *b->last++ = LF;\n }\n b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);\n return b;\n}']
|
1,383
| 0
|
https://github.com/openssl/openssl/blob/0bde1089f895718db2fe2637fda4a0c2ed6df904/crypto/lhash/lhash.c/#L356
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)Realloc(lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['static int ssl3_get_client_hello(SSL *s)\n\t{\n\tint i,j,ok,al,ret= -1;\n\tlong n;\n\tunsigned long id;\n\tunsigned char *p,*d,*q;\n\tSSL_CIPHER *c;\n\tSSL_COMP *comp=NULL;\n\tSTACK_OF(SSL_CIPHER) *ciphers=NULL;\n\tif (s->state == SSL3_ST_SR_CLNT_HELLO_A)\n\t\t{\n\t\ts->first_packet=1;\n\t\ts->state=SSL3_ST_SR_CLNT_HELLO_B;\n\t\t}\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_CLNT_HELLO_B,\n\t\tSSL3_ST_SR_CLNT_HELLO_C,\n\t\tSSL3_MT_CLIENT_HELLO,\n\t\tSSL3_RT_MAX_PLAIN_LENGTH,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\td=p=(unsigned char *)s->init_buf->data;\n\ts->client_version=(((int)p[0])<<8)|(int)p[1];\n\tp+=2;\n\tmemcpy(s->s3->client_random,p,SSL3_RANDOM_SIZE);\n\tp+=SSL3_RANDOM_SIZE;\n\tj= *(p++);\n\ts->hit=0;\n\tif (j == 0)\n\t\t{\n\t\tif (!ssl_get_new_session(s,1))\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\t{\n\t\ti=ssl_get_prev_session(s,p,j);\n\t\tif (i == 1)\n\t\t\t{\n\t\t\ts->hit=1;\n\t\t\t}\n\t\telse if (i == -1)\n\t\t\tgoto err;\n\t\telse\n\t\t\t{\n\t\t\tif (!ssl_get_new_session(s,1))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tp+=j;\n\tn2s(p,i);\n\tif ((i == 0) && (j != 0))\n\t\t{\n\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\tif ((i+p) > (d+n))\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\tgoto f_err;\n\t\t}\n\tif ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))\n\t\t== NULL))\n\t\t{\n\t\tgoto err;\n\t\t}\n\tp+=i;\n\tif ((s->hit) && (i > 0))\n\t\t{\n\t\tj=0;\n\t\tid=s->session->cipher->id;\n#ifdef CIPHER_DEBUG\n\t\tprintf("client sent %d ciphers\\n",sk_num(ciphers));\n#endif\n\t\tfor (i=0; i<sk_SSL_CIPHER_num(ciphers); i++)\n\t\t\t{\n\t\t\tc=sk_SSL_CIPHER_value(ciphers,i);\n#ifdef CIPHER_DEBUG\n\t\t\tprintf("client [%2d of %2d]:%s\\n",\n\t\t\t\ti,sk_num(ciphers),SSL_CIPHER_get_name(c));\n#endif\n\t\t\tif (c->id == id)\n\t\t\t\t{\n\t\t\t\tj=1;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tif ((s->options & SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG) && (sk_SSL_CIPHER_num(ciphers) == 1))\n\t\t\t\t{\n\t\t\t\ts->session->cipher=sk_SSL_CIPHER_value(ciphers,\n\t\t\t\t\t\t\t\t 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_REQUIRED_CIPHER_MISSING);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\ti= *(p++);\n\tq=p;\n\tfor (j=0; j<i; j++)\n\t\t{\n\t\tif (p[j] == 0) break;\n\t\t}\n\tp+=i;\n\tif (j >= i)\n\t\t{\n\t\tal=SSL_AD_DECODE_ERROR;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_COMPRESSION_SPECIFIED);\n\t\tgoto f_err;\n\t\t}\n\ts->s3->tmp.new_compression=NULL;\n\tif (s->ctx->comp_methods != NULL)\n\t\t{\n\t\tint m,nn,o,v,done=0;\n\t\tnn=sk_SSL_COMP_num(s->ctx->comp_methods);\n\t\tfor (m=0; m<nn; m++)\n\t\t\t{\n\t\t\tcomp=sk_SSL_COMP_value(s->ctx->comp_methods,m);\n\t\t\tv=comp->id;\n\t\t\tfor (o=0; o<i; o++)\n\t\t\t\t{\n\t\t\t\tif (v == q[o])\n\t\t\t\t\t{\n\t\t\t\t\tdone=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tif (done) break;\n\t\t\t}\n\t\tif (done)\n\t\t\ts->s3->tmp.new_compression=comp;\n\t\telse\n\t\t\tcomp=NULL;\n\t\t}\n\tif (s->version == SSL3_VERSION)\n\t\t{\n\t\tif (p > (d+n))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_LENGTH_MISMATCH);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\tif (!s->hit)\n\t\t{\n\t\ts->session->compress_meth=(comp == NULL)?0:comp->id;\n\t\tif (s->session->ciphers != NULL)\n\t\t\tsk_SSL_CIPHER_free(s->session->ciphers);\n\t\ts->session->ciphers=ciphers;\n\t\tif (ciphers == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_CIPHERS_PASSED);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tciphers=NULL;\n\t\tc=ssl3_choose_cipher(s,s->session->ciphers,\n\t\t\t\t ssl_get_ciphers_by_id(s));\n\t\tif (c == NULL)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_HELLO,SSL_R_NO_SHARED_CIPHER);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.new_cipher=c;\n\t\t}\n\telse\n\t\t{\n#ifdef REUSE_CIPHER_BUG\n\t\tSTACK_OF(SSL_CIPHER) *sk;\n\t\tSSL_CIPHER *nc=NULL;\n\t\tSSL_CIPHER *ec=NULL;\n\t\tif (s->options & SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG)\n\t\t\t{\n\t\t\tsk=s->session->ciphers;\n\t\t\tfor (i=0; i<sk_SSL_CIPHER_num(sk); i++)\n\t\t\t\t{\n\t\t\t\tc=sk_SSL_CIPHER_value(sk,i);\n\t\t\t\tif (c->algorithms & SSL_eNULL)\n\t\t\t\t\tnc=c;\n\t\t\t\tif (SSL_C_IS_EXPORT(c))\n\t\t\t\t\tec=c;\n\t\t\t\t}\n\t\t\tif (nc != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=nc;\n\t\t\telse if (ec != NULL)\n\t\t\t\ts->s3->tmp.new_cipher=ec;\n\t\t\telse\n\t\t\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t\t}\n\t\telse\n#endif\n\t\ts->s3->tmp.new_cipher=s->session->cipher;\n\t\t}\n\tret=1;\n\tif (0)\n\t\t{\nf_err:\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n\t\t}\nerr:\n\tif (ciphers != NULL) sk_SSL_CIPHER_free(ciphers);\n\treturn(ret);\n\t}', 'int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)\n\t{\n\tSSL_SESSION *ret=NULL,data;\n\tint fatal = 0;\n\tdata.ssl_version=s->version;\n\tdata.session_id_length=len;\n\tif (len > SSL_MAX_SSL_SESSION_ID_LENGTH)\n\t\tgoto err;\n\tmemcpy(data.session_id,session_id,len);\n\tif (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))\n\t\t{\n\t\tCRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data);\n\t\tif (ret != NULL)\n\t\t CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);\n\t\tCRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\t}\n\tif (ret == NULL)\n\t\t{\n\t\tint copy=1;\n\t\ts->ctx->stats.sess_miss++;\n\t\tret=NULL;\n\t\tif (s->ctx->get_session_cb != NULL\n\t\t && (ret=s->ctx->get_session_cb(s,session_id,len,©))\n\t\t != NULL)\n\t\t\t{\n\t\t\ts->ctx->stats.sess_cb_hit++;\n\t\t\tif (copy)\n\t\t\t\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);\n\t\t\tSSL_CTX_add_session(s->ctx,ret);\n\t\t\t}\n\t\tif (ret == NULL)\n\t\t\tgoto err;\n\t\t}\n\tif((s->verify_mode&SSL_VERIFY_PEER)\n\t && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length\n\t || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))\n\t {\n\t\tif (s->sid_ctx_length == 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);\n\t\t\tfatal = 1;\n\t\t\tgoto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n#if 0\n\t\t\tSSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);\n#endif\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (ret->cipher == NULL)\n\t\t{\n\t\tunsigned char buf[5],*p;\n\t\tunsigned long l;\n\t\tp=buf;\n\t\tl=ret->cipher_id;\n\t\tl2n(l,p);\n\t\tif ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)\n\t\t\tret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));\n\t\telse\n\t\t\tret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));\n\t\tif (ret->cipher == NULL)\n\t\t\tgoto err;\n\t\t}\n#if 0\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);\n#endif\n\tif ((long)(ret->time+ret->timeout) < (long)time(NULL))\n\t\t{\n\t\ts->ctx->stats.sess_timeout++;\n\t\tSSL_CTX_remove_session(s->ctx,ret);\n\t\tgoto err;\n\t\t}\n\ts->ctx->stats.sess_hit++;\n\tif (s->session != NULL)\n\t\tSSL_SESSION_free(s->session);\n\ts->session=ret;\n\ts->verify_result = s->session->verify_result;\n\treturn(1);\n err:\n\tif (ret != NULL)\n\t\tSSL_SESSION_free(ret);\n\tif (fatal)\n\t\treturn -1;\n\telse\n\t\treturn 0;\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)Realloc(lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,384
| 0
|
https://github.com/openssl/openssl/blob/0a52d38b31ee56479c80509716c3bd46b764190a/crypto/bn/bn_asm.c/#L396
|
BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
{
BN_ULONG t1,t2;
int c=0;
assert(n >= 0);
if (n <= 0) return((BN_ULONG)0);
for (;;)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
t1=a[1]; t2=b[1];
r[1]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
t1=a[2]; t2=b[2];
r[2]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
t1=a[3]; t2=b[3];
r[3]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
if (--n <= 0) break;
a+=4;
b+=4;
r+=4;
}
return(c);
}
|
['int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1,ts=0;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *aa;\n\tBIGNUM val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tif (d == NULL || r == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tBN_init(&val[0]);\n\tts=1;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_nnmod(&(val[0]),a,m,ctx))\n\t\t\tgoto err;\n\t\taa= &(val[0]);\n\t\t}\n\telse\n\t\taa=a;\n\tif (BN_is_zero(aa))\n\t\t{\n\t\tret = BN_zero(rr);\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tBN_init(&(val[i]));\n\t\t\tif (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tts=i;\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'BIGNUM *BN_value_one(void)\n\t{\n\tstatic BN_ULONG data_one=1L;\n\tstatic BIGNUM const_one={&data_one,1,1,0};\n\treturn(&const_one);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint j,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tbn_wexpand(tmp_bn,al);\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tbn_wexpand(tmp_bn,bl);\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n\t int tna, int tnb, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1,c2,neg,zero;\n\tBN_ULONG ln,lo,*p;\n# ifdef BN_COUNT\n\tfprintf(stderr," bn_mul_part_recursive (%d+%d) * (%d+%d)\\n",\n\t\ttna, n, tnb, n);\n# endif\n\tif (n < 8)\n\t\t{\n\t\tbn_mul_normal(r,a,n+tna,b,n+tnb);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_part_words(a,&(a[n]),tna,n-tna);\n\tc2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\tcase -2:\n\t\tbn_sub_part_words(t, &(a[n]),a, tna,tna-n);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\tcase 2:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\tcase 4:\n\t\tbn_sub_part_words(t, a, &(a[n]),tna,n-tna);\n\t\tbn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n);\n\t\tbreak;\n\t\t}\n# if 0\n\tif (n == 4)\n\t\t{\n\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n# endif\n\tif (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\n\t\tmemset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p);\n\t\tbn_mul_recursive(r,a,b,n,0,0,p);\n\t\ti=n/2;\n\t\tif (tna > tnb)\n\t\t\tj = tna - i;\n\t\telse\n\t\t\tj = tnb - i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\tmemset(&(r[n2+tna+tnb]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tna-tnb));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n\t\t\t\t&& tnb < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tna && i < tnb)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i <= tna && i <= tnb)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,tna-i,tnb-i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tint n,i;\n\tn = cl-1;\n\tif (dl < 0)\n\t\t{\n\t\tfor (i=dl; i<0; i++)\n\t\t\t{\n\t\t\tif (b[n-i] != 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif (dl > 0)\n\t\t{\n\t\tfor (i=dl; i>0; i--)\n\t\t\t{\n\t\t\tif (a[n+i] != 0)\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\treturn bn_cmp_words(a,b,cl);\n\t}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n\tconst BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tBN_ULONG c, t;\n\tassert(cl >= 0);\n\tc = bn_sub_words(r, a, b, cl);\n\tif (dl == 0)\n\t\treturn c;\n\tr += cl;\n\ta += cl;\n\tb += cl;\n\tif (dl < 0)\n\t\t{\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl < 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt = b[0];\n\t\t\tr[0] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[1];\n\t\t\tr[1] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[2];\n\t\t\tr[2] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[3];\n\t\t\tr[3] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tb += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tint save_dl = dl;\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\twhile(c)\n\t\t\t{\n\t\t\tt = a[0];\n\t\t\tr[0] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[1];\n\t\t\tr[1] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[2];\n\t\t\tr[2] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[3];\n\t\t\tr[3] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tsave_dl = dl;\n\t\t\ta += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c == 0)\\n", cl, dl);\n#endif\n\t\t\tif (save_dl > dl)\n\t\t\t\t{\n\t\t\t\tswitch (save_dl - dl)\n\t\t\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tr[1] = a[1];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 2:\n\t\t\t\t\tr[2] = a[2];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 3:\n\t\t\t\t\tr[3] = a[3];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\t\t}\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, copy)\\n", cl, dl);\n#endif\n\t\t\tfor(;;)\n\t\t\t\t{\n\t\t\t\tr[0] = a[0];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[1] = a[1];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[2] = a[2];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[3] = a[3];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn c;\n\t}', 'BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n\tfor (;;)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tif (--n <= 0) break;\n\t\ta+=4;\n\t\tb+=4;\n\t\tr+=4;\n\t\t}\n\treturn(c);\n\t}']
|
1,385
| 0
|
https://github.com/libav/libav/blob/dad7a9c7c0ae8ebc56f2e3a24e6fa4da5c2cd491/libavcodec/bitstream.h/#L237
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['static int\nflac_header (AVFormatContext * s, int idx)\n{\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n AVStream *st = s->streams[idx];\n BitstreamContext bc;\n int mdt;\n if (os->buf[os->pstart] == 0xff)\n return 0;\n bitstream_init8(&bc, os->buf + os->pstart, os->psize);\n bitstream_skip(&bc, 1);\n mdt = bitstream_read(&bc, 7);\n if (mdt == OGG_FLAC_METADATA_TYPE_STREAMINFO) {\n uint8_t *streaminfo_start = os->buf + os->pstart + 5 + 4 + 4 + 4;\n uint32_t samplerate;\n bitstream_skip(&bc, 4 * 8);\n if (bitstream_read(&bc, 8) != 1)\n return -1;\n bitstream_skip(&bc, 8 + 16);\n bitstream_skip(&bc, 4 * 8);\n if (bitstream_read(&bc, 32) != FLAC_STREAMINFO_SIZE)\n return -1;\n st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codecpar->codec_id = AV_CODEC_ID_FLAC;\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n st->codecpar->extradata =\n av_malloc(FLAC_STREAMINFO_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);\n memcpy(st->codecpar->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE);\n st->codecpar->extradata_size = FLAC_STREAMINFO_SIZE;\n samplerate = AV_RB24(st->codecpar->extradata + 10) >> 4;\n if (!samplerate)\n return AVERROR_INVALIDDATA;\n avpriv_set_pts_info(st, 64, 1, samplerate);\n } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {\n ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 4, os->psize - 4);\n }\n return 1;\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n unsigned byte_size)\n{\n if (byte_size > INT_MAX / 8)\n return AVERROR_INVALIDDATA;\n return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n <= bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n skip_remaining(bc, bc->bits_left);\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
1,386
| 0
|
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L333
|
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->top = b->top;
a->neg = b->neg;
bn_check_top(a);
return a;
}
|
['static int dsa_do_verify(const unsigned char *dgst, int dgst_len,\n DSA_SIG *sig, DSA *dsa)\n{\n BN_CTX *ctx;\n BIGNUM *u1, *u2, *t1;\n BN_MONT_CTX *mont = NULL;\n const BIGNUM *r, *s;\n int ret = -1, i;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS);\n return -1;\n }\n i = BN_num_bits(dsa->q);\n if (i != 160 && i != 224 && i != 256) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE);\n return -1;\n }\n if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n u1 = BN_new();\n u2 = BN_new();\n t1 = BN_new();\n ctx = BN_CTX_new();\n if (u1 == NULL || u2 == NULL || t1 == NULL || ctx == NULL)\n goto err;\n DSA_SIG_get0(sig, &r, &s);\n if (BN_is_zero(r) || BN_is_negative(r) ||\n BN_ucmp(r, dsa->q) >= 0) {\n ret = 0;\n goto err;\n }\n if (BN_is_zero(s) || BN_is_negative(s) ||\n BN_ucmp(s, dsa->q) >= 0) {\n ret = 0;\n goto err;\n }\n if ((BN_mod_inverse(u2, s, dsa->q, ctx)) == NULL)\n goto err;\n if (dgst_len > (i >> 3))\n dgst_len = (i >> 3);\n if (BN_bin2bn(dgst, dgst_len, u1) == NULL)\n goto err;\n if (!BN_mod_mul(u1, u1, u2, dsa->q, ctx))\n goto err;\n if (!BN_mod_mul(u2, r, u2, dsa->q, ctx))\n goto err;\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx);\n if (!mont)\n goto err;\n }\n if (dsa->meth->dsa_mod_exp != NULL) {\n if (!dsa->meth->dsa_mod_exp(dsa, t1, dsa->g, u1, dsa->pub_key, u2,\n dsa->p, ctx, mont))\n goto err;\n } else {\n if (!BN_mod_exp2_mont(t1, dsa->g, u1, dsa->pub_key, u2, dsa->p, ctx,\n mont))\n goto err;\n }\n if (!BN_mod(u1, t1, dsa->q, ctx))\n goto err;\n ret = (BN_ucmp(u1, r) == 0);\n err:\n if (ret < 0)\n DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB);\n BN_CTX_free(ctx);\n BN_free(u1);\n BN_free(u2);\n BN_free(t1);\n return (ret);\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'BIGNUM *BN_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->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
1,387
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L765
|
int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
{
int i;
BN_ULONG aa, bb;
aa = a[n - 1];
bb = b[n - 1];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
for (i = n - 2; i >= 0; i--) {
aa = a[i];
bb = b[i];
if (aa != bb)
return ((aa > bb) ? 1 : -1);
}
return (0);
}
|
['int 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 (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 }\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_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n int do_trial_division, BN_GENCB *cb)\n{\n int i, j, ret = -1;\n int k;\n BN_CTX *ctx = NULL;\n BIGNUM *A1, *A1_odd, *check;\n BN_MONT_CTX *mont = NULL;\n const BIGNUM *A = NULL;\n if (BN_cmp(a, BN_value_one()) <= 0)\n return 0;\n if (checks == BN_prime_checks)\n checks = BN_prime_checks_for_size(BN_num_bits(a));\n if (!BN_is_odd(a))\n return BN_is_word(a, 2);\n if (do_trial_division) {\n for (i = 1; i < NUMPRIMES; i++)\n if (BN_mod_word(a, primes[i]) == 0)\n return 0;\n if (!BN_GENCB_call(cb, 1, -1))\n goto err;\n }\n if (ctx_passed != NULL)\n ctx = ctx_passed;\n else if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n if (a->neg) {\n BIGNUM *t;\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n BN_copy(t, a);\n t->neg = 0;\n A = t;\n } else\n A = a;\n A1 = BN_CTX_get(ctx);\n A1_odd = BN_CTX_get(ctx);\n check = BN_CTX_get(ctx);\n if (check == NULL)\n goto err;\n if (!BN_copy(A1, A))\n goto err;\n if (!BN_sub_word(A1, 1))\n goto err;\n if (BN_is_zero(A1)) {\n ret = 0;\n goto err;\n }\n k = 1;\n while (!BN_is_bit_set(A1, k))\n k++;\n if (!BN_rshift(A1_odd, A1, k))\n goto err;\n mont = BN_MONT_CTX_new();\n if (mont == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, A, ctx))\n goto err;\n for (i = 0; i < checks; i++) {\n if (!BN_pseudo_rand_range(check, A1))\n goto err;\n if (!BN_add_word(check, 1))\n goto err;\n j = witness(check, A, A1, A1_odd, k, ctx, mont);\n if (j == -1)\n goto err;\n if (j) {\n ret = 0;\n goto err;\n }\n if (!BN_GENCB_call(cb, 1, i))\n goto err;\n }\n ret = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n if (ctx_passed == NULL)\n BN_CTX_free(ctx);\n }\n BN_MONT_CTX_free(mont);\n return (ret);\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n 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 mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (!d || !r || !val[0])\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return (1);\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, int cl, int dl)\n{\n int n, i;\n n = cl - 1;\n if (dl < 0) {\n for (i = dl; i < 0; i++) {\n if (b[n - i] != 0)\n return -1;\n }\n }\n if (dl > 0) {\n for (i = dl; i > 0; i--) {\n if (a[n + i] != 0)\n return 1;\n }\n }\n return bn_cmp_words(a, b, cl);\n}', 'int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)\n{\n int i;\n BN_ULONG aa, bb;\n aa = a[n - 1];\n bb = b[n - 1];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n for (i = n - 2; i >= 0; i--) {\n aa = a[i];\n bb = b[i];\n if (aa != bb)\n return ((aa > bb) ? 1 : -1);\n }\n return (0);\n}']
|
1,388
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/lhash/lhash.c/#L370
|
static void contract(LHASH *lh)
{
LHASH_NODE **n,*n1,*np;
np=lh->b[lh->p+lh->pmax-1];
lh->b[lh->p+lh->pmax-1]=NULL;
if (lh->p == 0)
{
n=(LHASH_NODE **)Realloc((char *)lh->b,
(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
if (n == NULL)
{
lh->error++;
return;
}
lh->num_contract_reallocs++;
lh->num_alloc_nodes/=2;
lh->pmax/=2;
lh->p=lh->pmax-1;
lh->b=n;
}
else
lh->p--;
lh->num_nodes--;
lh->num_contracts++;
n1=lh->b[(int)lh->p];
if (n1 == NULL)
lh->b[(int)lh->p]=np;
else
{
while (n1->next != NULL)
n1=n1->next;
n1->next=np;
}
}
|
['static int ssl3_get_server_done(SSL *s)\n\t{\n\tint ok,ret=0;\n\tlong n;\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_CR_SRVR_DONE_A,\n\t\tSSL3_ST_CR_SRVR_DONE_B,\n\t\tSSL3_MT_SERVER_DONE,\n\t\t30,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tif (n > 0)\n\t\t{\n\t\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);\n\t\tSSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);\n\t\t}\n\tret=1;\n\treturn(ret);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,\n\t\t\t(char *)&(p[s->init_num]),\n\t\t\t4-s->init_num);\n\t\tif (i < (4-s->init_num))\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\tif (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,\n\t\t\t(char *)&(p[s->init_num]),(int)n);\n\t\tif (i != (int)n)\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\t}\n\t*ok=1;\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,(char *)c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}', 'static void contract(LHASH *lh)\n\t{\n\tLHASH_NODE **n,*n1,*np;\n\tnp=lh->b[lh->p+lh->pmax-1];\n\tlh->b[lh->p+lh->pmax-1]=NULL;\n\tif (lh->p == 0)\n\t\t{\n\t\tn=(LHASH_NODE **)Realloc((char *)lh->b,\n\t\t\t(unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));\n\t\tif (n == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn;\n\t\t\t}\n\t\tlh->num_contract_reallocs++;\n\t\tlh->num_alloc_nodes/=2;\n\t\tlh->pmax/=2;\n\t\tlh->p=lh->pmax-1;\n\t\tlh->b=n;\n\t\t}\n\telse\n\t\tlh->p--;\n\tlh->num_nodes--;\n\tlh->num_contracts++;\n\tn1=lh->b[(int)lh->p];\n\tif (n1 == NULL)\n\t\tlh->b[(int)lh->p]=np;\n\telse\n\t\t{\n\t\twhile (n1->next != NULL)\n\t\t\tn1=n1->next;\n\t\tn1->next=np;\n\t\t}\n\t}']
|
1,389
| 0
|
https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_lib.c/#L377
|
BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*B,*a;
int i,j;
bn_check_top(b);
if (words > b->max)
{
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return(NULL);
}
a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
if (A == NULL)
{
BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
return(NULL);
}
memset(A,0x5c,sizeof(BN_ULONG)*(words+1));
#if 1
B=b->d;
if (B != NULL)
{
for (i=b->top&(~7); i>0; i-=8)
{
A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
A+=8;
B+=8;
}
switch (b->top&7)
{
case 7:
A[6]=B[6];
case 6:
A[5]=B[5];
case 5:
A[4]=B[4];
case 4:
A[3]=B[3];
case 3:
A[2]=B[2];
case 2:
A[1]=B[1];
case 1:
A[0]=B[0];
case 0:
;
}
Free(b->d);
}
b->d=a;
b->max=words;
B= &(b->d[b->top]);
j=(b->max - b->top) & ~7;
for (i=0; i<j; i+=8)
{
B[0]=0; B[1]=0; B[2]=0; B[3]=0;
B[4]=0; B[5]=0; B[6]=0; B[7]=0;
B+=8;
}
j=(b->max - b->top) & 7;
for (i=0; i<j; i++)
{
B[0]=0;
B++;
}
#else
memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
#endif
}
return(b);
}
|
['int BN_mod_exp_simple(BIGNUM *r, BIGNUM *a, BIGNUM *p, BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;\n\tint start=1;\n\tBIGNUM *d;\n\tBIGNUM val[TABLE_SIZE];\n\td= &(ctx->bn[ctx->tos++]);\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tBN_one(r);\n\t\treturn(1);\n\t\t}\n\tBN_init(&(val[0]));\n\tts=1;\n\tif (!BN_mod(&(val[0]),a,m,ctx)) goto err;\n\tif (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))\n\t\tgoto err;\n\tif (bits <= 17)\n\t\twindow=1;\n\telse if (bits >= 256)\n\t\twindow=5;\n\telse if (bits >= 128)\n\t\twindow=4;\n\telse\n\t\twindow=3;\n\tj=1<<(window-1);\n\tfor (i=1; i<j; i++)\n\t\t{\n\t\tBN_init(&(val[i]));\n\t\tif (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))\n\t\t\tgoto err;\n\t\t}\n\tts=i;\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul(r,r,r,m,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul(r,r,r,m,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tfor (i=0; i<ts; i++)\n\t\tBN_clear_free(&(val[i]));\n\treturn(ret);\n\t}', 'int BN_mod(BIGNUM *rem, BIGNUM *m, BIGNUM *d, BN_CTX *ctx)\n\t{\n#if 0\n\tint i,nm,nd;\n\tBIGNUM *dv;\n\tif (BN_ucmp(m,d) < 0)\n\t\treturn((BN_copy(rem,m) == NULL)?0:1);\n\tdv= &(ctx->bn[ctx->tos]);\n\tif (!BN_copy(rem,m)) return(0);\n\tnm=BN_num_bits(rem);\n\tnd=BN_num_bits(d);\n\tif (!BN_lshift(dv,d,nm-nd)) return(0);\n\tfor (i=nm-nd; i>=0; i--)\n\t\t{\n\t\tif (BN_cmp(rem,dv) >= 0)\n\t\t\t{\n\t\t\tif (!BN_sub(rem,rem,dv)) return(0);\n\t\t\t}\n\t\tif (!BN_rshift1(dv,dv)) return(0);\n\t\t}\n\treturn(1);\n#else\n\treturn(BN_div(NULL,rem,m,d,ctx));\n#endif\n\t}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, BIGNUM *num, BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,j,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\ttmp= &(ctx->bn[ctx->tos]);\n\ttmp->neg=0;\n\tsnum= &(ctx->bn[ctx->tos+1]);\n\tsdiv= &(ctx->bn[ctx->tos+2]);\n\tif (dv == NULL)\n\t\tres= &(ctx->bn[ctx->tos+3]);\n\telse\tres=dv;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tBN_lshift(sdiv,divisor,norm_shift);\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tBN_lshift(snum,num,norm_shift);\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\tBN_init(&wnum);\n\twnum.d=\t &(snum->d[loop]);\n\twnum.top= div_n;\n\twnum.max= snum->max+1;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tif (!BN_usub(&wnum,&wnum,sdiv)) goto err;\n\t\t*resp=1;\n\t\tres->d[res->top-1]=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tresp--;\n\tfor (i=0; i<loop-1; i++)\n\t\t{\n\t\tBN_ULONG q,n0,n1;\n\t\tBN_ULONG l0;\n\t\twnum.d--; wnum.top++;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\tq=bn_div_words(n0,n1,d0);\n\t\t{\n#ifdef BN_LLONG\n\t\tBN_ULLONG t1,t2,rem;\n\t\tt1=((BN_ULLONG)n0<<BN_BITS2)|n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\trem=t1-(BN_ULLONG)q*d0;\n\t\t\tif ((rem>>BN_BITS2) ||\n\t\t\t\t(t2 <= ((BN_ULLONG)(rem<<BN_BITS2)+wnump[-2])))\n\t\t\t\tbreak;\n\t\t\tq--;\n\t\t\t}\n#else\n\t\tBN_ULONG t1l,t1h,t2l,t2h,t3l,t3h,ql,qh,t3t;\n\t\tt1h=n0;\n\t\tt1l=n1;\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\tt3t=LBITS(d0); t3h=HBITS(d0);\n\t\t\tmul64(t3t,t3h,ql,qh);\n\t\t\tt3l=(t1l-t3t)&BN_MASK2;\n\t\t\tif (t3l > t1l) t3h++;\n\t\t\tt3h=(t1h-t3h)&BN_MASK2;\n\t\t\tif (t3h) break;\n\t\t\tif (t2h < t3l) break;\n\t\t\tif ((t2h == t3l) && (t2l <= wnump[-2])) break;\n\t\t\tq--;\n\t\t\t}\n#endif\n\t\t}\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\tfor (j=div_n+1; j>0; j--)\n\t\t\tif (tmp->d[j-1]) break;\n\t\ttmp->top=j;\n\t\tj=wnum.top;\n\t\tBN_sub(&wnum,&wnum,tmp);\n\t\tsnum->top=snum->top+wnum.top-j;\n\t\tif (wnum.neg)\n\t\t\t{\n\t\t\tq--;\n\t\t\tj=wnum.top;\n\t\t\tBN_add(&wnum,&wnum,sdiv);\n\t\t\tsnum->top+=wnum.top-j;\n\t\t\t}\n\t\t*(resp--)=q;\n\t\twnump--;\n\t\t}\n\tif (rm != NULL)\n\t\t{\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\trm->neg=num->neg;\n\t\t}\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mod_mul(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_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*B,*a;\n\tint i,j;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\nmemset(A,0x5c,sizeof(BN_ULONG)*(words+1));\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tB= &(b->d[b->top]);\n\t\tj=(b->max - b->top) & ~7;\n\t\tfor (i=0; i<j; i+=8)\n\t\t\t{\n\t\t\tB[0]=0; B[1]=0; B[2]=0; B[3]=0;\n\t\t\tB[4]=0; B[5]=0; B[6]=0; B[7]=0;\n\t\t\tB+=8;\n\t\t\t}\n\t\tj=(b->max - b->top) & 7;\n\t\tfor (i=0; i<j; i++)\n\t\t\t{\n\t\t\tB[0]=0;\n\t\t\tB++;\n\t\t\t}\n#else\n\t\t\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\t\t}\n\treturn(b);\n\t}']
|
1,390
| 0
|
https://github.com/openssl/openssl/blob/e02c519cd32a55e6ad39a0cfbeeda775f9115f28/crypto/bn/bn_mul.c/#L657
|
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;
}
}
|
['int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x_, int y_bit,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *x, *y;\n int ret = 0;\n ERR_clear_error();\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n y_bit = (y_bit != 0);\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n x = BN_CTX_get(ctx);\n y = BN_CTX_get(ctx);\n if (y == NULL)\n goto err;\n if (!BN_nnmod(x, x_, group->field, ctx))\n goto err;\n if (group->meth->field_decode == 0) {\n if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n goto err;\n if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n goto err;\n } else {\n if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n goto err;\n if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n goto err;\n }\n if (group->a_is_minus3) {\n if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n goto err;\n if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n goto err;\n if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n goto err;\n if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n goto err;\n } else {\n if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n goto err;\n }\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n }\n if (group->meth->field_decode) {\n if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n goto err;\n if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n goto err;\n } else {\n if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n goto err;\n }\n if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n unsigned long err = ERR_peek_last_error();\n if (ERR_GET_LIB(err) == ERR_LIB_BN\n && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n ERR_clear_error();\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n } else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_BN_LIB);\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n if (BN_is_zero(y)) {\n int kron;\n kron = BN_kronecker(x, group->field, ctx);\n if (kron == -2)\n goto err;\n if (kron == 1)\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSION_BIT);\n else\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n EC_R_INVALID_COMPRESSED_POINT);\n goto err;\n }\n if (!BN_usub(y, group->field, y))\n goto err;\n }\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = bn_mul_fixed_top(r, a, b, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return 1;\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n rr->neg = a->neg ^ b->neg;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return ret;\n}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,\n int tna, int tnb, BN_ULONG *t)\n{\n int i, j, n2 = n * 2;\n int c1, c2, neg;\n BN_ULONG ln, lo, *p;\n if (n < 8) {\n bn_mul_normal(r, a, n + tna, b, n + tnb);\n return;\n }\n c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n neg = 0;\n switch (c1 * 3 + c2) {\n case -4:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n break;\n case -3:\n case -2:\n bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n neg = 1;\n break;\n case -1:\n case 0:\n case 1:\n case 2:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n neg = 1;\n break;\n case 3:\n case 4:\n bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n break;\n }\n# if 0\n if (n == 4) {\n bn_mul_comba4(&(t[n2]), t, &(t[n]));\n bn_mul_comba4(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tn, &(b[n]), tn);\n memset(&r[n2 + tn * 2], 0, sizeof(*r) * (n2 - tn * 2));\n } else\n# endif\n if (n == 8) {\n bn_mul_comba8(&(t[n2]), t, &(t[n]));\n bn_mul_comba8(r, a, b);\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n memset(&r[n2 + tna + tnb], 0, sizeof(*r) * (n2 - tna - tnb));\n } else {\n p = &(t[n2 * 2]);\n bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n bn_mul_recursive(r, a, b, n, 0, 0, p);\n i = n / 2;\n if (tna > tnb)\n j = tna - i;\n else\n j = tnb - i;\n if (j == 0) {\n bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&r[n2 + i * 2], 0, sizeof(*r) * (n2 - i * 2));\n } else if (j > 0) {\n bn_mul_part_recursive(&(r[n2]), &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n memset(&(r[n2 + tna + tnb]), 0,\n sizeof(BN_ULONG) * (n2 - tna - tnb));\n } else {\n memset(&r[n2], 0, sizeof(*r) * n2);\n if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL\n && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n bn_mul_normal(&(r[n2]), &(a[n]), tna, &(b[n]), tnb);\n } else {\n for (;;) {\n i /= 2;\n if (i < tna || i < tnb) {\n bn_mul_part_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n } else if (i == tna || i == tnb) {\n bn_mul_recursive(&(r[n2]),\n &(a[n]), &(b[n]),\n i, tna - i, tnb - i, p);\n break;\n }\n }\n }\n }\n }\n c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n if (neg) {\n c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n } else {\n c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n }\n c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n if (c1) {\n p = &(r[n + n2]);\n lo = *p;\n ln = (lo + c1) & BN_MASK2;\n *p = ln;\n if (ln < (BN_ULONG)c1) {\n do {\n p++;\n lo = *p;\n ln = (lo + 1) & BN_MASK2;\n *p = ln;\n } while (ln == 0);\n }\n }\n}', 'void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)\n{\n BN_ULONG *rr;\n if (na < nb) {\n int itmp;\n BN_ULONG *ltmp;\n itmp = na;\n na = nb;\n nb = itmp;\n ltmp = a;\n a = b;\n b = ltmp;\n }\n rr = &(r[na]);\n if (nb <= 0) {\n (void)bn_mul_words(r, a, na, 0);\n return;\n } else\n rr[0] = bn_mul_words(r, a, na, b[0]);\n for (;;) {\n if (--nb <= 0)\n return;\n rr[1] = bn_mul_add_words(&(r[1]), a, na, b[1]);\n if (--nb <= 0)\n return;\n rr[2] = bn_mul_add_words(&(r[2]), a, na, b[2]);\n if (--nb <= 0)\n return;\n rr[3] = bn_mul_add_words(&(r[3]), a, na, b[3]);\n if (--nb <= 0)\n return;\n rr[4] = bn_mul_add_words(&(r[4]), a, na, b[4]);\n rr += 4;\n r += 4;\n b += 4;\n }\n}']
|
1,391
| 0
|
https://github.com/openssl/openssl/blob/6fda11ae5a06e28fd9463e5afb60735d074904b3/providers/common/ciphers/aes.c/#L287
|
IMPLEMENT_new_ctx(cbc, CBC, 128)
|
['IMPLEMENT_new_ctx(cbc, CBC, 128)', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#if !defined(OPENSSL_NO_CRYPTO_MDEBUG) && !defined(FIPS_MODE)\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
1,392
| 0
|
https://github.com/openssl/openssl/blob/d4b009d5f88875ac0e3ac0b2b9689ed16a4c88dc/crypto/lhash/lhash.c/#L209
|
void *lh_delete(_LHASH *lh, const void *data)
{
unsigned long hash;
LHASH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return (NULL);
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return (ret);
}
|
['static void int_thread_del_item(const ERR_STATE *d)\n{\n ERR_STATE *p = NULL;\n LHASH_OF(ERR_STATE) *hash;\n CRYPTO_w_lock(CRYPTO_LOCK_ERR);\n hash = int_thread_get(0, 0);\n if (hash) {\n p = lh_ERR_STATE_delete(hash, d);\n if (int_thread_hash_references == 1\n && int_thread_hash\n && lh_ERR_STATE_num_items(int_thread_hash) == 0) {\n int_thread_hash_references = 0;\n lh_ERR_STATE_free(int_thread_hash);\n int_thread_hash = NULL;\n hash = NULL;\n }\n }\n CRYPTO_w_unlock(CRYPTO_LOCK_ERR);\n int_thread_release(&hash);\n ERR_STATE_free(p);\n}', 'DEFINE_LHASH_OF(ERR_STATE)', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n unsigned long hash;\n LHASH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}']
|
1,393
| 0
|
https://github.com/openssl/openssl/blob/84cf97af0691290d53c0a51807fa15f0843219ef/crypto/bn/bn_ctx.c/#L328
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n const int p[], BN_CTX *ctx)\n{\n int ret = 0, i, n;\n BIGNUM *u;\n bn_check_top(a);\n bn_check_top(b);\n if (BN_is_zero(b))\n return (BN_one(r));\n if (BN_abs_is_word(b, 1))\n return (BN_copy(r, a) != NULL);\n BN_CTX_start(ctx);\n if ((u = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_GF2m_mod_arr(u, a, p))\n goto err;\n n = BN_num_bits(b) - 1;\n for (i = n - 1; i >= 0; i--) {\n if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx))\n goto err;\n if (BN_is_bit_set(b, i)) {\n if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx))\n goto err;\n }\n }\n if (!BN_copy(r, u))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *s;\n bn_check_top(a);\n BN_CTX_start(ctx);\n if ((s = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!bn_wexpand(s, 2 * a->top))\n goto err;\n for (i = a->top - 1; i >= 0; i--) {\n s->d[2 * i + 1] = SQR1(a->d[i]);\n s->d[2 * i] = SQR0(a->d[i]);\n }\n s->top = 2 * a->top;\n bn_correct_top(s);\n if (!BN_GF2m_mod_arr(r, s, p))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
1,394
| 0
|
https://gitlab.com/libtiff/libtiff/blob/d85a64b6d6379c9f9b8de6ff3a26e380b0fc3e18/libtiff/tif_swab.c/#L296
|
void
TIFFReverseBits(uint8* cp, tmsize_t n)
{
for (; n > 8; n -= 8) {
cp[0] = TIFFBitRevTable[cp[0]];
cp[1] = TIFFBitRevTable[cp[1]];
cp[2] = TIFFBitRevTable[cp[2]];
cp[3] = TIFFBitRevTable[cp[3]];
cp[4] = TIFFBitRevTable[cp[4]];
cp[5] = TIFFBitRevTable[cp[5]];
cp[6] = TIFFBitRevTable[cp[6]];
cp[7] = TIFFBitRevTable[cp[7]];
cp += 8;
}
while (n-- > 0)
*cp = TIFFBitRevTable[*cp], cp++;
}
|
['DECLAREreadFunc(readContigTilesIntoBuffer)\n{\n\tint status = 1;\n\ttsize_t tilesize = TIFFTileSize(in);\n\ttdata_t tilebuf;\n\tuint32 imagew = TIFFScanlineSize(in);\n\tuint32 tilew = TIFFTileRowSize(in);\n\tint iskew = imagew - tilew;\n\tuint8* bufp = (uint8*) buf;\n\tuint32 tw, tl;\n\tuint32 row;\n\t(void) spp;\n\ttilebuf = _TIFFmalloc(tilesize);\n\tif (tilebuf == 0)\n\t\treturn 0;\n\t_TIFFmemset(tilebuf, 0, tilesize);\n\t(void) TIFFGetField(in, TIFFTAG_TILEWIDTH, &tw);\n\t(void) TIFFGetField(in, TIFFTAG_TILELENGTH, &tl);\n\tfor (row = 0; row < imagelength; row += tl) {\n\t\tuint32 nrow = (row+tl > imagelength) ? imagelength-row : tl;\n\t\tuint32 colb = 0;\n\t\tuint32 col;\n\t\tfor (col = 0; col < imagewidth; col += tw) {\n\t\t\tif (TIFFReadTile(in, tilebuf, col, row, 0, 0) < 0\n\t\t\t && !ignore) {\n\t\t\t\tTIFFError(TIFFFileName(in),\n\t\t\t\t "Error, can\'t read tile at %lu %lu",\n\t\t\t\t (unsigned long) col,\n\t\t\t\t (unsigned long) row);\n\t\t\t\tstatus = 0;\n\t\t\t\tgoto done;\n\t\t\t}\n\t\t\tif (colb + tilew > imagew) {\n\t\t\t\tuint32 width = imagew - colb;\n\t\t\t\tuint32 oskew = tilew - width;\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t tilebuf, nrow, width,\n\t\t\t\t oskew + iskew, oskew );\n\t\t\t} else\n\t\t\t\tcpStripToTile(bufp + colb,\n\t\t\t\t tilebuf, nrow, tilew,\n\t\t\t\t iskew, 0);\n\t\t\tcolb += tilew;\n\t\t}\n\t\tbufp += imagew * nrow;\n\t}\ndone:\n\t_TIFFfree(tilebuf);\n\treturn status;\n}', 'tmsize_t\nTIFFReadTile(TIFF* tif, void* buf, uint32 x, uint32 y, uint32 z, uint16 s)\n{\n\tif (!TIFFCheckRead(tif, 1) || !TIFFCheckTile(tif, x, y, z, s))\n\t\treturn ((tmsize_t)(-1));\n\treturn (TIFFReadEncodedTile(tif,\n\t TIFFComputeTile(tif, x, y, z, s), buf, (tmsize_t)(-1)));\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n if (!_TIFFFillStriles( tif ) || !tif->tif_dir.td_stripbytecount)\n return 0;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata) {\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\t\ttif->tif_rawdata = NULL;\n\t\t\t\ttif->tif_rawdatasize = 0;\n\t\t\t}\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t\ttif->tif_flags |= TIFF_BUFFERMMAP;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (tif->tif_flags&TIFF_BUFFERMMAP) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'void\nTIFFReverseBits(uint8* cp, tmsize_t n)\n{\n\tfor (; n > 8; n -= 8) {\n\t\tcp[0] = TIFFBitRevTable[cp[0]];\n\t\tcp[1] = TIFFBitRevTable[cp[1]];\n\t\tcp[2] = TIFFBitRevTable[cp[2]];\n\t\tcp[3] = TIFFBitRevTable[cp[3]];\n\t\tcp[4] = TIFFBitRevTable[cp[4]];\n\t\tcp[5] = TIFFBitRevTable[cp[5]];\n\t\tcp[6] = TIFFBitRevTable[cp[6]];\n\t\tcp[7] = TIFFBitRevTable[cp[7]];\n\t\tcp += 8;\n\t}\n\twhile (n-- > 0)\n\t\t*cp = TIFFBitRevTable[*cp], cp++;\n}']
|
1,395
| 1
|
https://github.com/libav/libav/blob/a1e98f198e9db4e5ddfc2f777014179d3d7bc4d2/libavformat/spdifdec.c/#L60
|
static int spdif_get_offset_and_codec(AVFormatContext *s,
enum IEC61937DataType data_type,
const char *buf, int *offset,
enum CodecID *codec)
{
AACADTSHeaderInfo aac_hdr;
GetBitContext gbc;
switch (data_type & 0xff) {
case IEC61937_AC3:
*offset = AC3_FRAME_SIZE << 2;
*codec = CODEC_ID_AC3;
break;
case IEC61937_MPEG1_LAYER1:
*offset = spdif_mpeg_pkt_offset[1][0];
*codec = CODEC_ID_MP1;
break;
case IEC61937_MPEG1_LAYER23:
*offset = spdif_mpeg_pkt_offset[1][0];
*codec = CODEC_ID_MP3;
break;
case IEC61937_MPEG2_EXT:
*offset = 4608;
*codec = CODEC_ID_MP3;
break;
case IEC61937_MPEG2_AAC:
init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8);
if (avpriv_aac_parse_header(&gbc, &aac_hdr)) {
if (s)
av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n");
return AVERROR_INVALIDDATA;
}
*offset = aac_hdr.samples << 2;
*codec = CODEC_ID_AAC;
break;
case IEC61937_MPEG2_LAYER1_LSF:
*offset = spdif_mpeg_pkt_offset[0][0];
*codec = CODEC_ID_MP1;
break;
case IEC61937_MPEG2_LAYER2_LSF:
*offset = spdif_mpeg_pkt_offset[0][1];
*codec = CODEC_ID_MP2;
break;
case IEC61937_MPEG2_LAYER3_LSF:
*offset = spdif_mpeg_pkt_offset[0][2];
*codec = CODEC_ID_MP3;
break;
case IEC61937_DTS1:
*offset = 2048;
*codec = CODEC_ID_DTS;
break;
case IEC61937_DTS2:
*offset = 4096;
*codec = CODEC_ID_DTS;
break;
case IEC61937_DTS3:
*offset = 8192;
*codec = CODEC_ID_DTS;
break;
default:
if (s) {
av_log(s, AV_LOG_WARNING, "Data type 0x%04x", data_type);
av_log_missing_feature(s, " in IEC 61937 is", 1);
}
return AVERROR_PATCHWELCOME;
}
return 0;
}
|
['static int spdif_get_offset_and_codec(AVFormatContext *s,\n enum IEC61937DataType data_type,\n const char *buf, int *offset,\n enum CodecID *codec)\n{\n AACADTSHeaderInfo aac_hdr;\n GetBitContext gbc;\n switch (data_type & 0xff) {\n case IEC61937_AC3:\n *offset = AC3_FRAME_SIZE << 2;\n *codec = CODEC_ID_AC3;\n break;\n case IEC61937_MPEG1_LAYER1:\n *offset = spdif_mpeg_pkt_offset[1][0];\n *codec = CODEC_ID_MP1;\n break;\n case IEC61937_MPEG1_LAYER23:\n *offset = spdif_mpeg_pkt_offset[1][0];\n *codec = CODEC_ID_MP3;\n break;\n case IEC61937_MPEG2_EXT:\n *offset = 4608;\n *codec = CODEC_ID_MP3;\n break;\n case IEC61937_MPEG2_AAC:\n init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8);\n if (avpriv_aac_parse_header(&gbc, &aac_hdr)) {\n if (s)\n av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\\n");\n return AVERROR_INVALIDDATA;\n }\n *offset = aac_hdr.samples << 2;\n *codec = CODEC_ID_AAC;\n break;\n case IEC61937_MPEG2_LAYER1_LSF:\n *offset = spdif_mpeg_pkt_offset[0][0];\n *codec = CODEC_ID_MP1;\n break;\n case IEC61937_MPEG2_LAYER2_LSF:\n *offset = spdif_mpeg_pkt_offset[0][1];\n *codec = CODEC_ID_MP2;\n break;\n case IEC61937_MPEG2_LAYER3_LSF:\n *offset = spdif_mpeg_pkt_offset[0][2];\n *codec = CODEC_ID_MP3;\n break;\n case IEC61937_DTS1:\n *offset = 2048;\n *codec = CODEC_ID_DTS;\n break;\n case IEC61937_DTS2:\n *offset = 4096;\n *codec = CODEC_ID_DTS;\n break;\n case IEC61937_DTS3:\n *offset = 8192;\n *codec = CODEC_ID_DTS;\n break;\n default:\n if (s) {\n av_log(s, AV_LOG_WARNING, "Data type 0x%04x", data_type);\n av_log_missing_feature(s, " in IEC 61937 is", 1);\n }\n return AVERROR_PATCHWELCOME;\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 s->index = 0;\n}', 'int avpriv_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(!avpriv_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 = avpriv_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 return AV_BSWAP32C(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 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}']
|
1,396
| 0
|
https://github.com/libav/libav/blob/d0540fd02171a6233d2016b199d013299debf7e3/libavcodec/svq3.c/#L216
|
static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)
{
const int qmul = svq3_dequant_coeff[qp];
#define stride 16
int i;
int temp[16];
static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };
for (i = 0; i < 4; i++) {
const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);
const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);
const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];
const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];
temp[4 * i + 0] = z0 + z3;
temp[4 * i + 1] = z1 + z2;
temp[4 * i + 2] = z1 - z2;
temp[4 * i + 3] = z0 - z3;
}
for (i = 0; i < 4; i++) {
const int offset = x_offset[i];
const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);
const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);
const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];
const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];
output[stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;
output[stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;
output[stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;
output[stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;
}
}
|
['static av_always_inline void hl_decode_mb_predict_luma(SVQ3Context *s,\n int mb_type,\n const int *block_offset,\n int linesize,\n uint8_t *dest_y)\n{\n int i;\n int qscale = s->qscale;\n if (IS_INTRA4x4(mb_type)) {\n for (i = 0; i < 16; i++) {\n uint8_t *const ptr = dest_y + block_offset[i];\n const int dir = s->intra4x4_pred_mode_cache[scan8[i]];\n uint8_t *topright;\n int nnz, tr;\n if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {\n const int topright_avail = (s->topright_samples_available << i) & 0x8000;\n assert(s->mb_y || linesize <= block_offset[i]);\n if (!topright_avail) {\n tr = ptr[3 - linesize] * 0x01010101u;\n topright = (uint8_t *)&tr;\n } else\n topright = ptr + 4 - linesize;\n } else\n topright = NULL;\n s->hpc.pred4x4[dir](ptr, topright, linesize);\n nnz = s->non_zero_count_cache[scan8[i]];\n if (nnz) {\n svq3_add_idct_c(ptr, s->mb + i * 16, linesize, qscale, 0);\n }\n }\n } else {\n s->hpc.pred16x16[s->intra16x16_pred_mode](dest_y, linesize);\n svq3_luma_dc_dequant_idct_c(s->mb, s->mb_luma_dc[0], qscale);\n }\n}', 'static void svq3_luma_dc_dequant_idct_c(int16_t *output, int16_t *input, int qp)\n{\n const int qmul = svq3_dequant_coeff[qp];\n#define stride 16\n int i;\n int temp[16];\n static const uint8_t x_offset[4] = { 0, 1 * stride, 4 * stride, 5 * stride };\n for (i = 0; i < 4; i++) {\n const int z0 = 13 * (input[4 * i + 0] + input[4 * i + 2]);\n const int z1 = 13 * (input[4 * i + 0] - input[4 * i + 2]);\n const int z2 = 7 * input[4 * i + 1] - 17 * input[4 * i + 3];\n const int z3 = 17 * input[4 * i + 1] + 7 * input[4 * i + 3];\n temp[4 * i + 0] = z0 + z3;\n temp[4 * i + 1] = z1 + z2;\n temp[4 * i + 2] = z1 - z2;\n temp[4 * i + 3] = z0 - z3;\n }\n for (i = 0; i < 4; i++) {\n const int offset = x_offset[i];\n const int z0 = 13 * (temp[4 * 0 + i] + temp[4 * 2 + i]);\n const int z1 = 13 * (temp[4 * 0 + i] - temp[4 * 2 + i]);\n const int z2 = 7 * temp[4 * 1 + i] - 17 * temp[4 * 3 + i];\n const int z3 = 17 * temp[4 * 1 + i] + 7 * temp[4 * 3 + i];\n output[stride * 0 + offset] = (z0 + z3) * qmul + 0x80000 >> 20;\n output[stride * 2 + offset] = (z1 + z2) * qmul + 0x80000 >> 20;\n output[stride * 8 + offset] = (z1 - z2) * qmul + 0x80000 >> 20;\n output[stride * 10 + offset] = (z0 - z3) * qmul + 0x80000 >> 20;\n }\n}']
|
1,397
| 0
|
https://github.com/libav/libav/blob/0bf511d579c7b21f1244eec688abf571ca1235bd/libswscale/swscale.c/#L72
|
static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW,
const uint8_t *_src, const int16_t *filter,
const int32_t *filterPos, int filterSize)
{
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);
int i;
int32_t *dst = (int32_t *) _dst;
const uint16_t *src = (const uint16_t *) _src;
int bits = desc->comp[0].depth_minus1;
int sh = bits - 4;
for (i = 0; i < dstW; i++) {
int j;
int srcPos = filterPos[i];
int val = 0;
for (j = 0; j < filterSize; j++) {
val += src[srcPos + j] * filter[filterSize * i + j];
}
dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
}
}
|
['static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW,\n const uint8_t *_src, const int16_t *filter,\n const int32_t *filterPos, int filterSize)\n{\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat);\n int i;\n int32_t *dst = (int32_t *) _dst;\n const uint16_t *src = (const uint16_t *) _src;\n int bits = desc->comp[0].depth_minus1;\n int sh = bits - 4;\n for (i = 0; i < dstW; i++) {\n int j;\n int srcPos = filterPos[i];\n int val = 0;\n for (j = 0; j < filterSize; j++) {\n val += src[srcPos + j] * filter[filterSize * i + j];\n }\n dst[i] = FFMIN(val >> sh, (1 << 19) - 1);\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}']
|
1,398
| 0
|
https://github.com/openssl/openssl/blob/6fda11ae5a06e28fd9463e5afb60735d074904b3/crypto/evp/evp_enc.c/#L475
|
int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)
{
PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;
int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |
(diff > (0 - (PTRDIFF_T)len)));
return overlapped;
}
|
['static int kek_unwrap_key(unsigned char *out, size_t *outlen,\n const unsigned char *in, size_t inlen,\n EVP_CIPHER_CTX *ctx)\n{\n size_t blocklen = EVP_CIPHER_CTX_block_size(ctx);\n unsigned char *tmp;\n int outl, rv = 0;\n if (inlen < 2 * blocklen) {\n return 0;\n }\n if (inlen % blocklen) {\n return 0;\n }\n if ((tmp = OPENSSL_malloc(inlen)) == NULL) {\n CMSerr(CMS_F_KEK_UNWRAP_KEY, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n if (!EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,\n in + inlen - 2 * blocklen, blocklen * 2)\n || !EVP_DecryptUpdate(ctx, tmp, &outl,\n tmp + inlen - blocklen, blocklen)\n || !EVP_DecryptUpdate(ctx, tmp, &outl, in, inlen - blocklen)\n || !EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, NULL)\n || !EVP_DecryptUpdate(ctx, tmp, &outl, tmp, inlen))\n goto err;\n if (((tmp[1] ^ tmp[4]) & (tmp[2] ^ tmp[5]) & (tmp[3] ^ tmp[6])) != 0xff) {\n goto err;\n }\n if (inlen < (size_t)(tmp[0] - 4)) {\n goto err;\n }\n *outlen = (size_t)tmp[0];\n memcpy(out, tmp + 4, *outlen);\n rv = 1;\n err:\n OPENSSL_clear_free(tmp, inlen);\n return rv;\n}', 'int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,\n const unsigned char *in, int inl)\n{\n int fix_len, cmpl = inl, ret;\n unsigned int b;\n size_t soutl;\n int blocksize;\n if (ctx->encrypt) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_INVALID_OPERATION);\n return 0;\n }\n if (ctx->cipher == NULL || ctx->cipher->prov == NULL)\n goto legacy;\n blocksize = EVP_CIPHER_CTX_block_size(ctx);\n if (ctx->cipher->cupdate == NULL || blocksize < 1) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_UPDATE_ERROR);\n return 0;\n }\n ret = ctx->cipher->cupdate(ctx->provctx, out, &soutl,\n inl + (blocksize == 1 ? 0 : blocksize), in,\n (size_t)inl);\n if (ret) {\n if (soutl > INT_MAX) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_UPDATE_ERROR);\n return 0;\n }\n *outl = soutl;\n }\n return ret;\n legacy:\n b = ctx->cipher->block_size;\n if (EVP_CIPHER_CTX_test_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS))\n cmpl = (cmpl + 7) / 8;\n if (inl <= 0) {\n *outl = 0;\n return inl == 0;\n }\n if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {\n if (b == 1 && is_partially_overlapping(out, in, cmpl)) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n return 0;\n }\n fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);\n if (fix_len < 0) {\n *outl = 0;\n return 0;\n } else\n *outl = fix_len;\n return 1;\n }\n if (ctx->flags & EVP_CIPH_NO_PADDING)\n return evp_EncryptDecryptUpdate(ctx, out, outl, in, inl);\n OPENSSL_assert(b <= sizeof(ctx->final));\n if (ctx->final_used) {\n if (((PTRDIFF_T)out == (PTRDIFF_T)in)\n || is_partially_overlapping(out, in, b)) {\n EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_PARTIALLY_OVERLAPPING);\n return 0;\n }\n memcpy(out, ctx->final, b);\n out += b;\n fix_len = 1;\n } else\n fix_len = 0;\n if (!evp_EncryptDecryptUpdate(ctx, out, outl, in, inl))\n return 0;\n if (b > 1 && !ctx->buf_len) {\n *outl -= b;\n ctx->final_used = 1;\n memcpy(ctx->final, &out[*outl], b);\n } else\n ctx->final_used = 0;\n if (fix_len)\n *outl += b;\n return 1;\n}', 'int is_partially_overlapping(const void *ptr1, const void *ptr2, int len)\n{\n PTRDIFF_T diff = (PTRDIFF_T)ptr1-(PTRDIFF_T)ptr2;\n int overlapped = (len > 0) & (diff != 0) & ((diff < (PTRDIFF_T)len) |\n (diff > (0 - (PTRDIFF_T)len)));\n return overlapped;\n}']
|
1,399
| 0
|
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L907
|
PUT_HEVC_QPEL_HV(3, 1)
|
['QPEL(48)', 'PUT_HEVC_QPEL_HV(3, 1)']
|
1,400
| 0
|
https://github.com/openssl/openssl/blob/33af4421f2ae5e4d0da3a121f51820f4b49a724c/crypto/asn1/t_x509.c/#L413
|
int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
{
char *v;
int gmt=0;
int i;
int y=0,M=0,d=0,h=0,m=0,s=0;
char *f = NULL;
int f_len = 0;
i=tm->length;
v=(char *)tm->data;
if (i < 12) goto err;
if (v[i-1] == 'Z') gmt=1;
for (i=0; i<12; i++)
if ((v[i] > '9') || (v[i] < '0')) goto err;
y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
M= (v[4]-'0')*10+(v[5]-'0');
if ((M > 12) || (M < 1)) goto err;
d= (v[6]-'0')*10+(v[7]-'0');
h= (v[8]-'0')*10+(v[9]-'0');
m= (v[10]-'0')*10+(v[11]-'0');
if ( (v[12] >= '0') && (v[12] <= '9') &&
(v[13] >= '0') && (v[13] <= '9'))
{
s= (v[12]-'0')*10+(v[13]-'0');
if (v[14] == '.')
{
int l = tm->length;
f = &v[14];
f_len = 1;
while (14 + f_len < l && f[f_len] >= '0' && f[f_len] <= '9')
++f_len;
}
}
if (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s",
mon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0)
return(0);
else
return(1);
err:
BIO_write(bp,"Bad time value",14);
return(0);
}
|
['static int i2r_ocsp_crlid(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind)\n{\n\tOCSP_CRLID *a = in;\n\tif (a->crlUrl)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlUrl: ", ind, "")) goto err;\n\t\tif (!ASN1_STRING_print(bp, (ASN1_STRING*)a->crlUrl)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\tif (a->crlNum)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlNum: ", ind, "")) goto err;\n\t\tif (!i2a_ASN1_INTEGER(bp, a->crlNum)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\tif (a->crlTime)\n\t {\n\t\tif (!BIO_printf(bp, "%*scrlTime: ", ind, "")) goto err;\n\t\tif (!ASN1_GENERALIZEDTIME_print(bp, a->crlTime)) goto err;\n\t\tif (!BIO_write(bp, "\\n", 1)) goto err;\n\t\t}\n\treturn 1;\n\terr:\n\treturn 0;\n}', "int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)\n\t{\n\tint i,n;\n\tchar buf[80];\n\tconst char *p;\n\tif (v == NULL) return(0);\n\tn=0;\n\tp=(const char *)v->data;\n\tfor (i=0; i<v->length; i++)\n\t\t{\n\t\tif ((p[i] > '~') || ((p[i] < ' ') &&\n\t\t\t(p[i] != '\\n') && (p[i] != '\\r')))\n\t\t\tbuf[n]='.';\n\t\telse\n\t\t\tbuf[n]=p[i];\n\t\tn++;\n\t\tif (n >= 80)\n\t\t\t{\n\t\t\tif (BIO_write(bp,buf,n) <= 0)\n\t\t\t\treturn(0);\n\t\t\tn=0;\n\t\t\t}\n\t\t}\n\tif (n > 0)\n\t\tif (BIO_write(bp,buf,n) <= 0)\n\t\t\treturn(0);\n\treturn(1);\n\t}", 'int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)\n\t{\n\tchar *v;\n\tint gmt=0;\n\tint i;\n\tint y=0,M=0,d=0,h=0,m=0,s=0;\n\tchar *f = NULL;\n\tint f_len = 0;\n\ti=tm->length;\n\tv=(char *)tm->data;\n\tif (i < 12) goto err;\n\tif (v[i-1] == \'Z\') gmt=1;\n\tfor (i=0; i<12; i++)\n\t\tif ((v[i] > \'9\') || (v[i] < \'0\')) goto err;\n\ty= (v[0]-\'0\')*1000+(v[1]-\'0\')*100 + (v[2]-\'0\')*10+(v[3]-\'0\');\n\tM= (v[4]-\'0\')*10+(v[5]-\'0\');\n\tif ((M > 12) || (M < 1)) goto err;\n\td= (v[6]-\'0\')*10+(v[7]-\'0\');\n\th= (v[8]-\'0\')*10+(v[9]-\'0\');\n\tm= (v[10]-\'0\')*10+(v[11]-\'0\');\n\tif (\t(v[12] >= \'0\') && (v[12] <= \'9\') &&\n\t\t(v[13] >= \'0\') && (v[13] <= \'9\'))\n\t\t{\n\t\ts= (v[12]-\'0\')*10+(v[13]-\'0\');\n\t\tif (v[14] == \'.\')\n\t\t\t{\n\t\t\tint l = tm->length;\n\t\t\tf = &v[14];\n\t\t\tf_len = 1;\n\t\t\twhile (14 + f_len < l && f[f_len] >= \'0\' && f[f_len] <= \'9\')\n\t\t\t\t++f_len;\n\t\t\t}\n\t\t}\n\tif (BIO_printf(bp,"%s %2d %02d:%02d:%02d%.*s %d%s",\n\t\tmon[M-1],d,h,m,s,f_len,f,y,(gmt)?" GMT":"") <= 0)\n\t\treturn(0);\n\telse\n\t\treturn(1);\nerr:\n\tBIO_write(bp,"Bad time value",14);\n\treturn(0);\n\t}']
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.