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 |
|---|---|---|---|---|
35,001 | 0 | https://github.com/openssl/openssl/blob/9d5cceac6fb0eca8945f630afff1a2288aa6332a/crypto/asn1/asn1_lib.c/#L222 | static void asn1_put_length(unsigned char **pp, int length)
{
unsigned char *p= *pp;
int i,l;
if (length <= 127)
*(p++)=(unsigned char)length;
else
{
l=length;
for (i=0; l > 0; i++)
l>>=8;
*(p++)=i|0x80;
l=i;
while (i-- > 0)
{
p[i]=length&0xff;
length>>=8;
}
p+=l;
}
*pp=p;
} | ['static int request_certificate(SSL *s)\n\t{\n\tunsigned char *p,*p2,*buf2;\n\tunsigned char *ccd;\n\tint i,j,ctype,ret= -1;\n\tX509 *x509=NULL;\n\tSTACK_OF(X509) *sk=NULL;\n\tccd=s->s2->tmp.ccl;\n\tif (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_A)\n\t\t{\n\t\tp=(unsigned char *)s->init_buf->data;\n\t\t*(p++)=SSL2_MT_REQUEST_CERTIFICATE;\n\t\t*(p++)=SSL2_AT_MD5_WITH_RSA_ENCRYPTION;\n\t\tRAND_bytes(ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);\n\t\tmemcpy(p,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);\n\t\ts->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_B;\n\t\ts->init_num=SSL2_MIN_CERT_CHALLENGE_LENGTH+2;\n\t\ts->init_off=0;\n\t\t}\n\tif (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_B)\n\t\t{\n\t\ti=ssl2_do_write(s);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tret=i;\n\t\t\tgoto end;\n\t\t\t}\n\t\ts->init_num=0;\n\t\ts->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_C;\n\t\t}\n\tif (s->state == SSL2_ST_SEND_REQUEST_CERTIFICATE_C)\n\t\t{\n\t\tp=(unsigned char *)s->init_buf->data;\n\t\ti=ssl2_read(s,(char *)&(p[s->init_num]),6-s->init_num);\n\t\tif (i < 3)\n\t\t\t{\n\t\t\tret=ssl2_part_read(s,SSL_F_REQUEST_CERTIFICATE,i);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((*p == SSL2_MT_ERROR) && (i >= 3))\n\t\t\t{\n\t\t\tn2s(p,i);\n\t\t\tif (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)\n\t\t\t\t{\n\t\t\t\tssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);\n\t\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tret=1;\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((*(p++) != SSL2_MT_CLIENT_CERTIFICATE) || (i < 6))\n\t\t\t{\n\t\t\tssl2_return_error(s,SSL2_PE_UNDEFINED_ERROR);\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_SHORT_READ);\n\t\t\tgoto end;\n\t\t\t}\n\t\tctype= *(p++);\n\t\tif (ctype != SSL2_AT_MD5_WITH_RSA_ENCRYPTION)\n\t\t\t{\n\t\t\tssl2_return_error(s,SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE);\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_BAD_RESPONSE_ARGUMENT);\n\t\t\tgoto end;\n\t\t\t}\n\t\tn2s(p,i); s->s2->tmp.clen=i;\n\t\tn2s(p,i); s->s2->tmp.rlen=i;\n\t\ts->state=SSL2_ST_SEND_REQUEST_CERTIFICATE_D;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tj=s->s2->tmp.clen+s->s2->tmp.rlen-s->init_num;\n\ti=ssl2_read(s,(char *)&(p[s->init_num]),j);\n\tif (i < j)\n\t\t{\n\t\tret=ssl2_part_read(s,SSL_F_REQUEST_CERTIFICATE,i);\n\t\tgoto end;\n\t\t}\n\tx509=(X509 *)d2i_X509(NULL,&p,(long)s->s2->tmp.clen);\n\tif (x509 == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_X509_LIB);\n\t\tgoto msg_end;\n\t\t}\n\tif (((sk=sk_X509_new_null()) == NULL) || (!sk_X509_push(sk,x509)))\n\t\t{\n\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\tgoto msg_end;\n\t\t}\n\ti=ssl_verify_cert_chain(s,sk);\n\tif (i)\n\t\t{\n\t\tEVP_MD_CTX ctx;\n\t\tEVP_PKEY *pkey=NULL;\n\t\tEVP_VerifyInit(&ctx,s->ctx->rsa_md5);\n\t\tEVP_VerifyUpdate(&ctx,s->s2->key_material,\n\t\t\t(unsigned int)s->s2->key_material_length);\n\t\tEVP_VerifyUpdate(&ctx,ccd,SSL2_MIN_CERT_CHALLENGE_LENGTH);\n\t\ti=i2d_X509(s->session->sess_cert->pkeys[SSL_PKEY_RSA_ENC].x509,NULL);\n\t\tbuf2=(unsigned char *)Malloc((unsigned int)i);\n\t\tif (buf2 == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto msg_end;\n\t\t\t}\n\t\tp2=buf2;\n\t\ti=i2d_X509(s->session->sess_cert->pkeys[SSL_PKEY_RSA_ENC].x509,&p2);\n\t\tEVP_VerifyUpdate(&ctx,buf2,(unsigned int)i);\n\t\tFree(buf2);\n\t\tpkey=X509_get_pubkey(x509);\n\t\tif (pkey == NULL) goto end;\n\t\ti=EVP_VerifyFinal(&ctx,p,s->s2->tmp.rlen,pkey);\n\t\tEVP_PKEY_free(pkey);\n\t\tmemset(&ctx,0,sizeof(ctx));\n\t\tif (i)\n\t\t\t{\n\t\t\tif (s->session->peer != NULL)\n\t\t\t\tX509_free(s->session->peer);\n\t\t\ts->session->peer=x509;\n\t\t\tCRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);\n\t\t\tret=1;\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tSSLerr(SSL_F_REQUEST_CERTIFICATE,SSL_R_BAD_CHECKSUM);\n\t\t\tgoto msg_end;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\nmsg_end:\n\t\tssl2_return_error(s,SSL2_PE_BAD_CERTIFICATE);\n\t\t}\nend:\n\tsk_X509_free(sk);\n\tX509_free(x509);\n\treturn(ret);\n\t}', 'int i2d_X509(X509 *a, unsigned char **pp)\n\t{\n\tM_ASN1_I2D_vars(a);\n\tM_ASN1_I2D_len(a->cert_info,\ti2d_X509_CINF);\n\tM_ASN1_I2D_len(a->sig_alg,\ti2d_X509_ALGOR);\n\tM_ASN1_I2D_len(a->signature,\ti2d_ASN1_BIT_STRING);\n\tM_ASN1_I2D_seq_total();\n\tM_ASN1_I2D_put(a->cert_info,\ti2d_X509_CINF);\n\tM_ASN1_I2D_put(a->sig_alg,\ti2d_X509_ALGOR);\n\tM_ASN1_I2D_put(a->signature,\ti2d_ASN1_BIT_STRING);\n\tM_ASN1_I2D_finish();\n\t}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMATIVE_TAG;\n\t\twhile (tag > 0x7f)\n\t\t\t{\n\t\t\t*(p++)=(tag&0x7f)|0x80;\n\t\t\ttag>>=7;\n\t\t\t}\n\t\t*(p++)=(tag&0x7f);\n\t\t}\n\tif ((constructed == 2) && (length == 0))\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}', 'static void asn1_put_length(unsigned char **pp, int length)\n\t{\n\tunsigned char *p= *pp;\n\tint i,l;\n\tif (length <= 127)\n\t\t*(p++)=(unsigned char)length;\n\telse\n\t\t{\n\t\tl=length;\n\t\tfor (i=0; l > 0; i++)\n\t\t\tl>>=8;\n\t\t*(p++)=i|0x80;\n\t\tl=i;\n\t\twhile (i-- > 0)\n\t\t\t{\n\t\t\tp[i]=length&0xff;\n\t\t\tlength>>=8;\n\t\t\t}\n\t\tp+=l;\n\t\t}\n\t*pp=p;\n\t}'] |
35,002 | 0 | https://github.com/openssl/openssl/blob/a5fcd09e7552dedf87d5a1ff5d07a0397bc057cb/crypto/asn1/asn1_lib.c/#L198 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
int xclass)
{
unsigned char *p= *pp;
int i;
i=(constructed)?V_ASN1_CONSTRUCTED:0;
i|=(xclass&V_ASN1_PRIVATE);
if (tag < 31)
*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);
else
{
*(p++)=i|V_ASN1_PRIMITIVE_TAG;
while (tag > 0x7f)
{
*(p++)=(tag&0x7f)|0x80;
tag>>=7;
}
*(p++)=(tag&0x7f);
}
if ((constructed == 2) && (length == 0))
*(p++)=0x80;
else
asn1_put_length(&p,length);
*pp=p;
} | ['X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)\n\t{\n\tunsigned char *p;\n\tASN1_OCTET_STRING *os1,*os2;\n\tASN1_STRING *seq;\n\tX509_ATTRIBUTE *ret;\n\tunsigned char *data;\n\tint i,total;\n\tif (signed_seq2string_nid == -1)\n\t\tsigned_seq2string_nid=\n\t\t\tOBJ_create("1.9.9999","OID_example","Our example OID");\n\tos1=ASN1_OCTET_STRING_new();\n\tos2=ASN1_OCTET_STRING_new();\n\tASN1_OCTET_STRING_set(os1,str1,strlen(str1));\n\tASN1_OCTET_STRING_set(os2,str1,strlen(str1));\n\ti =i2d_ASN1_OCTET_STRING(os1,NULL);\n\ti+=i2d_ASN1_OCTET_STRING(os2,NULL);\n\ttotal=ASN1_object_size(1,i,V_ASN1_SEQUENCE);\n\tdata=malloc(total);\n\tp=data;\n\tASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);\n\ti2d_ASN1_OCTET_STRING(os1,&p);\n\ti2d_ASN1_OCTET_STRING(os2,&p);\n\tseq=ASN1_STRING_new();\n\tASN1_STRING_set(seq,data,total);\n\tfree(data);\n\tASN1_OCTET_STRING_free(os1);\n\tASN1_OCTET_STRING_free(os2);\n\tret=X509_ATTRIBUTE_create(signed_seq2string_nid,\n\t\tV_ASN1_SEQUENCE,(char *)seq);\n\treturn(ret);\n\t}', 'ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void)\n{ return M_ASN1_OCTET_STRING_new(); }', 'ASN1_STRING *ASN1_STRING_type_new(int type)\n\t{\n\tASN1_STRING *ret;\n\tret=(ASN1_STRING *)Malloc(sizeof(ASN1_STRING));\n\tif (ret == NULL)\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->length=0;\n\tret->type=type;\n\tret->data=NULL;\n\tret->flags=0;\n\treturn(ret);\n\t}', 'int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)\n{ return M_ASN1_OCTET_STRING_set(x, d, len); }', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n\t{\n\tunsigned char *c;\n\tconst char *data=_data;\n\tif (len < 0)\n\t\t{\n\t\tif (data == NULL)\n\t\t\treturn(0);\n\t\telse\n\t\t\tlen=strlen(data);\n\t\t}\n\tif ((str->length < len) || (str->data == NULL))\n\t\t{\n\t\tc=str->data;\n\t\tif (c == NULL)\n\t\t\tstr->data=Malloc(len+1);\n\t\telse\n\t\t\tstr->data=Realloc(c,len+1);\n\t\tif (str->data == NULL)\n\t\t\t{\n\t\t\tstr->data=c;\n\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\tstr->length=len;\n\tif (data != NULL)\n\t\t{\n\t\tmemcpy(str->data,data,len);\n\t\tstr->data[len]='\\0';\n\t\t}\n\treturn(1);\n\t}", 'int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)\n{ return M_i2d_ASN1_OCTET_STRING(a, pp); }', 'int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)\n\t{\n\tint ret,r,constructed;\n\tunsigned char *p;\n\tif (a == NULL) return(0);\n\tif (tag == V_ASN1_BIT_STRING)\n\t\treturn(i2d_ASN1_BIT_STRING(a,pp));\n\tret=a->length;\n\tr=ASN1_object_size(0,ret,tag);\n\tif (pp == NULL) return(r);\n\tp= *pp;\n\tif ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))\n\t\tconstructed=1;\n\telse\n\t\tconstructed=0;\n\tASN1_put_object(&p,constructed,ret,tag,xclass);\n\tmemcpy(p,a->data,a->length);\n\tp+=a->length;\n\t*pp= p;\n\treturn(r);\n\t}', 'int ASN1_object_size(int constructed, int length, int tag)\n\t{\n\tint ret;\n\tret=length;\n\tret++;\n\tif (tag >= 31)\n\t\t{\n\t\twhile (tag > 0)\n\t\t\t{\n\t\t\ttag>>=7;\n\t\t\tret++;\n\t\t\t}\n\t\t}\n\tif ((length == 0) && (constructed == 2))\n\t\tret+=2;\n\tret++;\n\tif (length > 127)\n\t\t{\n\t\twhile (length > 0)\n\t\t\t{\n\t\t\tlength>>=8;\n\t\t\tret++;\n\t\t\t}\n\t\t}\n\treturn(ret);\n\t}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMITIVE_TAG;\n\t\twhile (tag > 0x7f)\n\t\t\t{\n\t\t\t*(p++)=(tag&0x7f)|0x80;\n\t\t\ttag>>=7;\n\t\t\t}\n\t\t*(p++)=(tag&0x7f);\n\t\t}\n\tif ((constructed == 2) && (length == 0))\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}'] |
35,003 | 0 | https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/vc1dec.c/#L2624 | static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
int coded, int codingset)
{
GetBitContext *gb = &v->s.gb;
MpegEncContext *s = &v->s;
int dc_pred_dir = 0;
int i;
int16_t *dc_val;
int16_t *ac_val, *ac_val2;
int dcdiff;
if (n < 4) {
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
} else {
dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
}
if (dcdiff < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n");
return -1;
}
if (dcdiff) {
if (dcdiff == 119 ) {
if (v->pq == 1) dcdiff = get_bits(gb, 10);
else if (v->pq == 2) dcdiff = get_bits(gb, 9);
else dcdiff = get_bits(gb, 8);
} else {
if (v->pq == 1)
dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;
else if (v->pq == 2)
dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;
}
if (get_bits1(gb))
dcdiff = -dcdiff;
}
dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);
*dc_val = dcdiff;
if (n < 4) {
block[0] = dcdiff * s->y_dc_scale;
} else {
block[0] = dcdiff * s->c_dc_scale;
}
if (!coded) {
goto not_coded;
}
i = 1;
{
int last = 0, skip, value;
const uint8_t *zz_table;
int scale;
int k;
scale = v->pq * 2 + v->halfpq;
if (v->s.ac_pred) {
if (!dc_pred_dir)
zz_table = v->zz_8x8[2];
else
zz_table = v->zz_8x8[3];
} else
zz_table = v->zz_8x8[1];
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
ac_val2 = ac_val;
if (dc_pred_dir)
ac_val -= 16;
else
ac_val -= 16 * s->block_wrap[n];
while (!last) {
vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);
i += skip;
if (i > 63)
break;
block[zz_table[i++]] = value;
}
if (s->ac_pred) {
if (dc_pred_dir) {
for (k = 1; k < 8; k++)
block[k << v->left_blk_sh] += ac_val[k];
} else {
for (k = 1; k < 8; k++)
block[k << v->top_blk_sh] += ac_val[k + 8];
}
}
for (k = 1; k < 8; k++) {
ac_val2[k] = block[k << v->left_blk_sh];
ac_val2[k + 8] = block[k << v->top_blk_sh];
}
for (k = 1; k < 64; k++)
if (block[k]) {
block[k] *= scale;
if (!v->pquantizer)
block[k] += (block[k] < 0) ? -v->pq : v->pq;
}
if (s->ac_pred) i = 63;
}
not_coded:
if (!coded) {
int k, scale;
ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
ac_val2 = ac_val;
i = 0;
scale = v->pq * 2 + v->halfpq;
memset(ac_val2, 0, 16 * 2);
if (dc_pred_dir) {
ac_val -= 16;
if (s->ac_pred)
memcpy(ac_val2, ac_val, 8 * 2);
} else {
ac_val -= 16 * s->block_wrap[n];
if (s->ac_pred)
memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
}
if (s->ac_pred) {
if (dc_pred_dir) {
for (k = 1; k < 8; k++) {
block[k << v->left_blk_sh] = ac_val[k] * scale;
if (!v->pquantizer && block[k << v->left_blk_sh])
block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq;
}
} else {
for (k = 1; k < 8; k++) {
block[k << v->top_blk_sh] = ac_val[k + 8] * scale;
if (!v->pquantizer && block[k << v->top_blk_sh])
block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq;
}
}
i = 63;
}
}
s->block_last_index[n] = i;
return 0;
} | ['static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,\n int coded, int codingset)\n{\n GetBitContext *gb = &v->s.gb;\n MpegEncContext *s = &v->s;\n int dc_pred_dir = 0;\n int i;\n int16_t *dc_val;\n int16_t *ac_val, *ac_val2;\n int dcdiff;\n if (n < 4) {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n } else {\n dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);\n }\n if (dcdiff < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\\n");\n return -1;\n }\n if (dcdiff) {\n if (dcdiff == 119 ) {\n if (v->pq == 1) dcdiff = get_bits(gb, 10);\n else if (v->pq == 2) dcdiff = get_bits(gb, 9);\n else dcdiff = get_bits(gb, 8);\n } else {\n if (v->pq == 1)\n dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3;\n else if (v->pq == 2)\n dcdiff = (dcdiff << 1) + get_bits1(gb) - 1;\n }\n if (get_bits1(gb))\n dcdiff = -dcdiff;\n }\n dcdiff += vc1_i_pred_dc(&v->s, v->overlap, v->pq, n, &dc_val, &dc_pred_dir);\n *dc_val = dcdiff;\n if (n < 4) {\n block[0] = dcdiff * s->y_dc_scale;\n } else {\n block[0] = dcdiff * s->c_dc_scale;\n }\n if (!coded) {\n goto not_coded;\n }\n i = 1;\n {\n int last = 0, skip, value;\n const uint8_t *zz_table;\n int scale;\n int k;\n scale = v->pq * 2 + v->halfpq;\n if (v->s.ac_pred) {\n if (!dc_pred_dir)\n zz_table = v->zz_8x8[2];\n else\n zz_table = v->zz_8x8[3];\n } else\n zz_table = v->zz_8x8[1];\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n ac_val2 = ac_val;\n if (dc_pred_dir)\n ac_val -= 16;\n else\n ac_val -= 16 * s->block_wrap[n];\n while (!last) {\n vc1_decode_ac_coeff(v, &last, &skip, &value, codingset);\n i += skip;\n if (i > 63)\n break;\n block[zz_table[i++]] = value;\n }\n if (s->ac_pred) {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++)\n block[k << v->left_blk_sh] += ac_val[k];\n } else {\n for (k = 1; k < 8; k++)\n block[k << v->top_blk_sh] += ac_val[k + 8];\n }\n }\n for (k = 1; k < 8; k++) {\n ac_val2[k] = block[k << v->left_blk_sh];\n ac_val2[k + 8] = block[k << v->top_blk_sh];\n }\n for (k = 1; k < 64; k++)\n if (block[k]) {\n block[k] *= scale;\n if (!v->pquantizer)\n block[k] += (block[k] < 0) ? -v->pq : v->pq;\n }\n if (s->ac_pred) i = 63;\n }\nnot_coded:\n if (!coded) {\n int k, scale;\n ac_val = s->ac_val[0][0] + s->block_index[n] * 16;\n ac_val2 = ac_val;\n i = 0;\n scale = v->pq * 2 + v->halfpq;\n memset(ac_val2, 0, 16 * 2);\n if (dc_pred_dir) {\n ac_val -= 16;\n if (s->ac_pred)\n memcpy(ac_val2, ac_val, 8 * 2);\n } else {\n ac_val -= 16 * s->block_wrap[n];\n if (s->ac_pred)\n memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);\n }\n if (s->ac_pred) {\n if (dc_pred_dir) {\n for (k = 1; k < 8; k++) {\n block[k << v->left_blk_sh] = ac_val[k] * scale;\n if (!v->pquantizer && block[k << v->left_blk_sh])\n block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq;\n }\n } else {\n for (k = 1; k < 8; k++) {\n block[k << v->top_blk_sh] = ac_val[k + 8] * scale;\n if (!v->pquantizer && block[k << v->top_blk_sh])\n block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq;\n }\n }\n i = 63;\n }\n }\n s->block_last_index[n] = i;\n return 0;\n}', 'static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,\n int *value, int codingset)\n{\n GetBitContext *gb = &v->s.gb;\n int index, escape, run = 0, level = 0, lst = 0;\n index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);\n if (index != ff_vc1_ac_sizes[codingset] - 1) {\n run = vc1_index_decode_table[codingset][index][0];\n level = vc1_index_decode_table[codingset][index][1];\n lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0;\n if (get_bits1(gb))\n level = -level;\n } else {\n escape = decode210(gb);\n if (escape != 2) {\n index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);\n run = vc1_index_decode_table[codingset][index][0];\n level = vc1_index_decode_table[codingset][index][1];\n lst = index >= vc1_last_decode_table[codingset];\n if (escape == 0) {\n if (lst)\n level += vc1_last_delta_level_table[codingset][run];\n else\n level += vc1_delta_level_table[codingset][run];\n } else {\n if (lst)\n run += vc1_last_delta_run_table[codingset][level] + 1;\n else\n run += vc1_delta_run_table[codingset][level] + 1;\n }\n if (get_bits1(gb))\n level = -level;\n } else {\n int sign;\n lst = get_bits1(gb);\n if (v->s.esc3_level_length == 0) {\n if (v->pq < 8 || v->dquantfrm) {\n v->s.esc3_level_length = get_bits(gb, 3);\n if (!v->s.esc3_level_length)\n v->s.esc3_level_length = get_bits(gb, 2) + 8;\n } else {\n v->s.esc3_level_length = get_unary(gb, 1, 6) + 2;\n }\n v->s.esc3_run_length = 3 + get_bits(gb, 2);\n }\n run = get_bits(gb, v->s.esc3_run_length);\n sign = get_bits1(gb);\n level = get_bits(gb, v->s.esc3_level_length);\n if (sign)\n level = -level;\n }\n }\n *last = lst;\n *skip = run;\n *value = level;\n}'] |
35,004 | 0 | https://github.com/libav/libav/blob/a20639017bfca0490bb1799575714f22bf470b4f/libavcodec/aacsbr.c/#L185 | static void sbr_make_f_tablelim(SpectralBandReplication *sbr)
{
int k;
if (sbr->bs_limiter_bands > 0) {
static const float bands_warped[3] = { 1.32715174233856803909f,
1.18509277094158210129f,
1.11987160404675912501f };
const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1];
int16_t patch_borders[7];
uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim;
patch_borders[0] = sbr->kx[1];
for (k = 1; k <= sbr->num_patches; k++)
patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1];
memcpy(sbr->f_tablelim, sbr->f_tablelow,
(sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0]));
if (sbr->num_patches > 1)
memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1,
(sbr->num_patches - 1) * sizeof(patch_borders[0]));
qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0],
sizeof(sbr->f_tablelim[0]),
qsort_comparison_function_int16);
sbr->n_lim = sbr->n[0] + sbr->num_patches - 1;
while (out < sbr->f_tablelim + sbr->n_lim) {
if (*in >= *out * lim_bands_per_octave_warped) {
*++out = *in++;
} else if (*in == *out ||
!in_table_int16(patch_borders, sbr->num_patches, *in)) {
in++;
sbr->n_lim--;
} else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) {
*out = *in++;
sbr->n_lim--;
} else {
*++out = *in++;
}
}
} else {
sbr->f_tablelim[0] = sbr->f_tablelow[0];
sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]];
sbr->n_lim = 1;
}
} | ['static int aac_decode_frame(AVCodecContext *avctx, void *data,\n int *data_size, AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n AACContext *ac = avctx->priv_data;\n ChannelElement *che = NULL, *che_prev = NULL;\n GetBitContext gb;\n enum RawDataBlockType elem_type, elem_type_prev = TYPE_END;\n int err, elem_id, data_size_tmp;\n int buf_consumed;\n int samples = 1024, multiplier;\n int buf_offset;\n init_get_bits(&gb, buf, buf_size * 8);\n if (show_bits(&gb, 12) == 0xfff) {\n if (parse_adts_frame_header(ac, &gb) < 0) {\n av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\\n");\n return -1;\n }\n if (ac->m4ac.sampling_index > 12) {\n av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\\n", ac->m4ac.sampling_index);\n return -1;\n }\n }\n memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame));\n while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {\n elem_id = get_bits(&gb, 4);\n if (elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {\n av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\\n", elem_type, elem_id);\n return -1;\n }\n switch (elem_type) {\n case TYPE_SCE:\n err = decode_ics(ac, &che->ch[0], &gb, 0, 0);\n break;\n case TYPE_CPE:\n err = decode_cpe(ac, &gb, che);\n break;\n case TYPE_CCE:\n err = decode_cce(ac, &gb, che);\n break;\n case TYPE_LFE:\n err = decode_ics(ac, &che->ch[0], &gb, 0, 0);\n break;\n case TYPE_DSE:\n err = skip_data_stream_element(ac, &gb);\n break;\n case TYPE_PCE: {\n enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];\n memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));\n if ((err = decode_pce(ac, new_che_pos, &gb)))\n break;\n if (ac->output_configured > OC_TRIAL_PCE)\n av_log(avctx, AV_LOG_ERROR,\n "Not evaluating a further program_config_element as this construct is dubious at best.\\n");\n else\n err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE);\n break;\n }\n case TYPE_FIL:\n if (elem_id == 15)\n elem_id += get_bits(&gb, 8) - 1;\n if (get_bits_left(&gb) < 8 * elem_id) {\n av_log(avctx, AV_LOG_ERROR, overread_err);\n return -1;\n }\n while (elem_id > 0)\n elem_id -= decode_extension_payload(ac, &gb, elem_id, che_prev, elem_type_prev);\n err = 0;\n break;\n default:\n err = -1;\n break;\n }\n che_prev = che;\n elem_type_prev = elem_type;\n if (err)\n return err;\n if (get_bits_left(&gb) < 3) {\n av_log(avctx, AV_LOG_ERROR, overread_err);\n return -1;\n }\n }\n spectral_to_sample(ac);\n multiplier = (ac->m4ac.sbr == 1) ? ac->m4ac.ext_sample_rate > ac->m4ac.sample_rate : 0;\n samples <<= multiplier;\n if (ac->output_configured < OC_LOCKED) {\n avctx->sample_rate = ac->m4ac.sample_rate << multiplier;\n avctx->frame_size = samples;\n }\n data_size_tmp = samples * avctx->channels * sizeof(int16_t);\n if (*data_size < data_size_tmp) {\n av_log(avctx, AV_LOG_ERROR,\n "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\\n",\n *data_size, data_size_tmp);\n return -1;\n }\n *data_size = data_size_tmp;\n ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels);\n if (ac->output_configured)\n ac->output_configured = OC_LOCKED;\n buf_consumed = (get_bits_count(&gb) + 7) >> 3;\n for (buf_offset = buf_consumed; buf_offset < buf_size; buf_offset++)\n if (buf[buf_offset])\n break;\n return buf_size > buf_offset ? buf_consumed : buf_size;\n}', 'static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)\n{\n int size;\n AACADTSHeaderInfo hdr_info;\n size = ff_aac_parse_header(gb, &hdr_info);\n if (size > 0) {\n if (ac->output_configured != OC_LOCKED && hdr_info.chan_config) {\n enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];\n memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));\n ac->m4ac.chan_config = hdr_info.chan_config;\n if (set_default_channel_config(ac, new_che_pos, hdr_info.chan_config))\n return -7;\n if (output_configure(ac, ac->che_pos, new_che_pos, hdr_info.chan_config, OC_TRIAL_FRAME))\n return -7;\n } else if (ac->output_configured != OC_LOCKED) {\n ac->output_configured = OC_NONE;\n }\n if (ac->output_configured != OC_LOCKED) {\n ac->m4ac.sbr = -1;\n ac->m4ac.ps = -1;\n }\n ac->m4ac.sample_rate = hdr_info.sample_rate;\n ac->m4ac.sampling_index = hdr_info.sampling_index;\n ac->m4ac.object_type = hdr_info.object_type;\n if (!ac->avctx->sample_rate)\n ac->avctx->sample_rate = hdr_info.sample_rate;\n if (hdr_info.num_aac_frames == 1) {\n if (!hdr_info.crc_absent)\n skip_bits(gb, 16);\n } else {\n av_log_missing_feature(ac->avctx, "More than one AAC RDB per ADTS frame is", 0);\n return -1;\n }\n }\n return size;\n}', 'static int decode_extension_payload(AACContext *ac, GetBitContext *gb, int cnt,\n ChannelElement *che, enum RawDataBlockType elem_type)\n{\n int crc_flag = 0;\n int res = cnt;\n switch (get_bits(gb, 4)) {\n case EXT_SBR_DATA_CRC:\n crc_flag++;\n case EXT_SBR_DATA:\n if (!che) {\n av_log(ac->avctx, AV_LOG_ERROR, "SBR was found before the first channel element.\\n");\n return res;\n } else if (!ac->m4ac.sbr) {\n av_log(ac->avctx, AV_LOG_ERROR, "SBR signaled to be not-present but was found in the bitstream.\\n");\n skip_bits_long(gb, 8 * cnt - 4);\n return res;\n } else if (ac->m4ac.sbr == -1 && ac->output_configured == OC_LOCKED) {\n av_log(ac->avctx, AV_LOG_ERROR, "Implicit SBR was found with a first occurrence after the first frame.\\n");\n skip_bits_long(gb, 8 * cnt - 4);\n return res;\n } else if (ac->m4ac.ps == -1 && ac->output_configured < OC_LOCKED && ac->avctx->channels == 1) {\n ac->m4ac.sbr = 1;\n ac->m4ac.ps = 1;\n output_configure(ac, ac->che_pos, ac->che_pos, ac->m4ac.chan_config, ac->output_configured);\n } else {\n ac->m4ac.sbr = 1;\n }\n res = ff_decode_sbr_extension(ac, &che->sbr, gb, crc_flag, cnt, elem_type);\n break;\n case EXT_DYNAMIC_RANGE:\n res = decode_dynamic_range(&ac->che_drc, gb, cnt);\n break;\n case EXT_FILL:\n case EXT_FILL_DATA:\n case EXT_DATA_ELEMENT:\n default:\n skip_bits_long(gb, 8 * cnt - 4);\n break;\n };\n return res;\n}', 'int ff_decode_sbr_extension(AACContext *ac, SpectralBandReplication *sbr,\n GetBitContext *gb_host, int crc, int cnt, int id_aac)\n{\n unsigned int num_sbr_bits = 0, num_align_bits;\n unsigned bytes_read;\n GetBitContext gbc = *gb_host, *gb = &gbc;\n skip_bits_long(gb_host, cnt*8 - 4);\n sbr->reset = 0;\n if (!sbr->sample_rate)\n sbr->sample_rate = 2 * ac->m4ac.sample_rate;\n if (!ac->m4ac.ext_sample_rate)\n ac->m4ac.ext_sample_rate = 2 * ac->m4ac.sample_rate;\n if (crc) {\n skip_bits(gb, 10);\n num_sbr_bits += 10;\n }\n sbr->kx[0] = sbr->kx[1];\n sbr->m[0] = sbr->m[1];\n num_sbr_bits++;\n if (get_bits1(gb))\n num_sbr_bits += read_sbr_header(sbr, gb);\n if (sbr->reset)\n sbr_reset(ac, sbr);\n if (sbr->start)\n num_sbr_bits += read_sbr_data(ac, sbr, gb, id_aac);\n num_align_bits = ((cnt << 3) - 4 - num_sbr_bits) & 7;\n bytes_read = ((num_sbr_bits + num_align_bits + 4) >> 3);\n if (bytes_read > cnt) {\n av_log(ac->avctx, AV_LOG_ERROR,\n "Expected to read %d SBR bytes actually read %d.\\n", cnt, bytes_read);\n }\n return cnt;\n}', 'static unsigned int read_sbr_header(SpectralBandReplication *sbr, GetBitContext *gb)\n{\n unsigned int cnt = get_bits_count(gb);\n uint8_t bs_header_extra_1;\n uint8_t bs_header_extra_2;\n int old_bs_limiter_bands = sbr->bs_limiter_bands;\n SpectrumParameters old_spectrum_params;\n sbr->start = 1;\n memcpy(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters));\n sbr->bs_amp_res_header = get_bits1(gb);\n sbr->spectrum_params.bs_start_freq = get_bits(gb, 4);\n sbr->spectrum_params.bs_stop_freq = get_bits(gb, 4);\n sbr->spectrum_params.bs_xover_band = get_bits(gb, 3);\n skip_bits(gb, 2);\n bs_header_extra_1 = get_bits1(gb);\n bs_header_extra_2 = get_bits1(gb);\n if (bs_header_extra_1) {\n sbr->spectrum_params.bs_freq_scale = get_bits(gb, 2);\n sbr->spectrum_params.bs_alter_scale = get_bits1(gb);\n sbr->spectrum_params.bs_noise_bands = get_bits(gb, 2);\n } else {\n sbr->spectrum_params.bs_freq_scale = 2;\n sbr->spectrum_params.bs_alter_scale = 1;\n sbr->spectrum_params.bs_noise_bands = 2;\n }\n if (memcmp(&old_spectrum_params, &sbr->spectrum_params, sizeof(SpectrumParameters)))\n sbr->reset = 1;\n if (bs_header_extra_2) {\n sbr->bs_limiter_bands = get_bits(gb, 2);\n sbr->bs_limiter_gains = get_bits(gb, 2);\n sbr->bs_interpol_freq = get_bits1(gb);\n sbr->bs_smoothing_mode = get_bits1(gb);\n } else {\n sbr->bs_limiter_bands = 2;\n sbr->bs_limiter_gains = 2;\n sbr->bs_interpol_freq = 1;\n sbr->bs_smoothing_mode = 1;\n }\n if (sbr->bs_limiter_bands != old_bs_limiter_bands && !sbr->reset)\n sbr_make_f_tablelim(sbr);\n return get_bits_count(gb) - cnt;\n}', 'static void sbr_make_f_tablelim(SpectralBandReplication *sbr)\n{\n int k;\n if (sbr->bs_limiter_bands > 0) {\n static const float bands_warped[3] = { 1.32715174233856803909f,\n 1.18509277094158210129f,\n 1.11987160404675912501f };\n const float lim_bands_per_octave_warped = bands_warped[sbr->bs_limiter_bands - 1];\n int16_t patch_borders[7];\n uint16_t *in = sbr->f_tablelim + 1, *out = sbr->f_tablelim;\n patch_borders[0] = sbr->kx[1];\n for (k = 1; k <= sbr->num_patches; k++)\n patch_borders[k] = patch_borders[k-1] + sbr->patch_num_subbands[k-1];\n memcpy(sbr->f_tablelim, sbr->f_tablelow,\n (sbr->n[0] + 1) * sizeof(sbr->f_tablelow[0]));\n if (sbr->num_patches > 1)\n memcpy(sbr->f_tablelim + sbr->n[0] + 1, patch_borders + 1,\n (sbr->num_patches - 1) * sizeof(patch_borders[0]));\n qsort(sbr->f_tablelim, sbr->num_patches + sbr->n[0],\n sizeof(sbr->f_tablelim[0]),\n qsort_comparison_function_int16);\n sbr->n_lim = sbr->n[0] + sbr->num_patches - 1;\n while (out < sbr->f_tablelim + sbr->n_lim) {\n if (*in >= *out * lim_bands_per_octave_warped) {\n *++out = *in++;\n } else if (*in == *out ||\n !in_table_int16(patch_borders, sbr->num_patches, *in)) {\n in++;\n sbr->n_lim--;\n } else if (!in_table_int16(patch_borders, sbr->num_patches, *out)) {\n *out = *in++;\n sbr->n_lim--;\n } else {\n *++out = *in++;\n }\n }\n } else {\n sbr->f_tablelim[0] = sbr->f_tablelow[0];\n sbr->f_tablelim[1] = sbr->f_tablelow[sbr->n[0]];\n sbr->n_lim = 1;\n }\n}'] |
35,005 | 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;
} | ['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}', 'int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)\n{\n if (!BN_lshift1(r, a))\n return 0;\n bn_check_top(r);\n if (BN_cmp(r, m) >= 0)\n return BN_sub(r, r, m);\n return 1;\n}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, j, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l, tmp;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n rb = n % BN_BITS2;\n lb = BN_BITS2 - rb;\n if (nw >= a->top || a->top == 0) {\n BN_zero(r);\n return (1);\n }\n i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n if (r != a) {\n if (bn_wexpand(r, i) == NULL)\n return (0);\n r->neg = a->neg;\n } else {\n if (n == 0)\n return 1;\n }\n f = &(a->d[nw]);\n t = r->d;\n j = a->top - nw;\n r->top = i;\n if (rb == 0) {\n for (i = j; i != 0; i--)\n *(t++) = *(f++);\n } else {\n l = *(f++);\n for (i = j - 1; i != 0; i--) {\n tmp = (l >> rb) & BN_MASK2;\n l = *(f++);\n *(t++) = (tmp | (l << lb)) & BN_MASK2;\n }\n if ((l = (l >> rb) & BN_MASK2))\n *(t) = l;\n }\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return (1);\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 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_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}'] |
35,006 | 0 | https://github.com/libav/libav/blob/0ebe3b8e2bf74503d7c9cc383e29254a3cb06d55/libavformat/rtmpproto.c/#L243 | static void rtmp_calc_digest(const uint8_t *src, int len, int gap,
const uint8_t *key, int keylen, uint8_t *dst)
{
struct AVSHA *sha;
uint8_t hmac_buf[64+32] = {0};
int i;
sha = av_mallocz(av_sha_size);
if (keylen < 64) {
memcpy(hmac_buf, key, keylen);
} else {
av_sha_init(sha, 256);
av_sha_update(sha,key, keylen);
av_sha_final(sha, hmac_buf);
}
for (i = 0; i < 64; i++)
hmac_buf[i] ^= HMAC_IPAD_VAL;
av_sha_init(sha, 256);
av_sha_update(sha, hmac_buf, 64);
if (gap <= 0) {
av_sha_update(sha, src, len);
} else {
av_sha_update(sha, src, gap);
av_sha_update(sha, src + gap + 32, len - gap - 32);
}
av_sha_final(sha, hmac_buf + 64);
for (i = 0; i < 64; i++)
hmac_buf[i] ^= HMAC_IPAD_VAL ^ HMAC_OPAD_VAL;
av_sha_init(sha, 256);
av_sha_update(sha, hmac_buf, 64+32);
av_sha_final(sha, dst);
av_free(sha);
} | ['static void rtmp_calc_digest(const uint8_t *src, int len, int gap,\n const uint8_t *key, int keylen, uint8_t *dst)\n{\n struct AVSHA *sha;\n uint8_t hmac_buf[64+32] = {0};\n int i;\n sha = av_mallocz(av_sha_size);\n if (keylen < 64) {\n memcpy(hmac_buf, key, keylen);\n } else {\n av_sha_init(sha, 256);\n av_sha_update(sha,key, keylen);\n av_sha_final(sha, hmac_buf);\n }\n for (i = 0; i < 64; i++)\n hmac_buf[i] ^= HMAC_IPAD_VAL;\n av_sha_init(sha, 256);\n av_sha_update(sha, hmac_buf, 64);\n if (gap <= 0) {\n av_sha_update(sha, src, len);\n } else {\n av_sha_update(sha, src, gap);\n av_sha_update(sha, src + gap + 32, len - gap - 32);\n }\n av_sha_final(sha, hmac_buf + 64);\n for (i = 0; i < 64; i++)\n hmac_buf[i] ^= HMAC_IPAD_VAL ^ HMAC_OPAD_VAL;\n av_sha_init(sha, 256);\n av_sha_update(sha, hmac_buf, 64+32);\n av_sha_final(sha, dst);\n av_free(sha);\n}', 'void *av_mallocz(unsigned int size)\n{\n void *ptr = av_malloc(size);\n if (ptr)\n memset(ptr, 0, size);\n return ptr;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'int av_sha_init(AVSHA* ctx, int bits)\n{\n ctx->digest_len = bits >> 5;\n switch (bits) {\n case 160:\n ctx->state[0] = 0x67452301;\n ctx->state[1] = 0xEFCDAB89;\n ctx->state[2] = 0x98BADCFE;\n ctx->state[3] = 0x10325476;\n ctx->state[4] = 0xC3D2E1F0;\n ctx->transform = sha1_transform;\n break;\n case 224:\n ctx->state[0] = 0xC1059ED8;\n ctx->state[1] = 0x367CD507;\n ctx->state[2] = 0x3070DD17;\n ctx->state[3] = 0xF70E5939;\n ctx->state[4] = 0xFFC00B31;\n ctx->state[5] = 0x68581511;\n ctx->state[6] = 0x64F98FA7;\n ctx->state[7] = 0xBEFA4FA4;\n ctx->transform = sha256_transform;\n break;\n case 256:\n ctx->state[0] = 0x6A09E667;\n ctx->state[1] = 0xBB67AE85;\n ctx->state[2] = 0x3C6EF372;\n ctx->state[3] = 0xA54FF53A;\n ctx->state[4] = 0x510E527F;\n ctx->state[5] = 0x9B05688C;\n ctx->state[6] = 0x1F83D9AB;\n ctx->state[7] = 0x5BE0CD19;\n ctx->transform = sha256_transform;\n break;\n default:\n return -1;\n }\n ctx->count = 0;\n return 0;\n}'] |
35,007 | 0 | https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/motion_est_template.c/#L806 | static int full_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;
LOAD_COMMON
LOAD_COMMON2
int map_generation= c->map_generation;
int x,y, d;
const int dia_size= c->dia_size&0xFF;
cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1];
for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){
for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){
CHECK_MV(x, y);
}
}
x= best[0];
y= best[1];
d= dmin;
CHECK_CLIPPED_MV(x , y);
CHECK_CLIPPED_MV(x+1, y);
CHECK_CLIPPED_MV(x, y+1);
CHECK_CLIPPED_MV(x-1, y);
CHECK_CLIPPED_MV(x, y-1);
best[0]= x;
best[1]= y;
return d;
} | ['static int full_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 LOAD_COMMON\n LOAD_COMMON2\n int map_generation= c->map_generation;\n int x,y, d;\n const int dia_size= c->dia_size&0xFF;\n cmpf= s->dsp.me_cmp[size];\n chroma_cmpf= s->dsp.me_cmp[size+1];\n for(y=FFMAX(-dia_size, ymin); y<=FFMIN(dia_size,ymax); y++){\n for(x=FFMAX(-dia_size, xmin); x<=FFMIN(dia_size,xmax); x++){\n CHECK_MV(x, y);\n }\n }\n x= best[0];\n y= best[1];\n d= dmin;\n CHECK_CLIPPED_MV(x , y);\n CHECK_CLIPPED_MV(x+1, y);\n CHECK_CLIPPED_MV(x, y+1);\n CHECK_CLIPPED_MV(x-1, y);\n CHECK_CLIPPED_MV(x, y-1);\n best[0]= x;\n best[1]= y;\n return d;\n}'] |
35,008 | 0 | https://github.com/openssl/openssl/blob/00a357ab203b4153eee970ffb33f0f22ef59f734/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_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field,\n\tBN_CTX *ctx)\n\t{\n#ifndef NO_32_BIT_TYPE\n\tint\ttmp_int;\n\tint\tcarry = 0;\n\tregister BN_ULONG *a_d, *r_d;\n\tBN_ULONG t_d[BN_NIST_256_TOP];\n\tBN_ULONG t_d2[BN_NIST_256_TOP];\n\tBN_32_BIT_BUF(8) BN_32_BIT_BUF(9)\n\tBN_32_BIT_BUF(10) BN_32_BIT_BUF(11)\n\tBN_32_BIT_BUF(12) BN_32_BIT_BUF(13)\n\tBN_32_BIT_BUF(14) BN_32_BIT_BUF(15)\n\tif (!_is_set_256_data)\n\t\t{\n\t\tCRYPTO_w_lock(CRYPTO_LOCK_BN);\n\t\tif (!_is_set_256_data)\n\t\t\t_init_256_data();\n\t\tCRYPTO_w_unlock(CRYPTO_LOCK_BN);\n\t\t}\n\ttmp_int = BN_ucmp(field, a);\n\tif (tmp_int == 0)\n\t\treturn BN_zero(r);\n\telse if (tmp_int > 0)\n\t\treturn (r == a)? 1 : (BN_copy(r ,a) != NULL);\n\tif (r != a)\n\t\tif (!BN_ncopy(r, a, BN_NIST_256_TOP))\n\t\t\treturn 0;\n\ttmp_int = a->top-1;\n\ta_d = a->d;\n\tr_d = r->d;\n\tswitch (tmp_int)\n\t\t{\n\t\tBN_CASE_32_BIT(15, a_d)\n\t\tBN_CASE_32_BIT(14, a_d)\n\t\tBN_CASE_32_BIT(13, a_d)\n\t\tBN_CASE_32_BIT(12, a_d)\n\t\tBN_CASE_32_BIT(11, a_d)\n\t\tBN_CASE_32_BIT(10, a_d)\n\t\tBN_CASE_32_BIT(9, a_d)\n\t\tBN_CASE_32_BIT(8, a_d)\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn BN_usub(r, a, field);\n\t\t}\n\tBN_256_SET(t_d,15,14,13,12,11,0,0,0)\n\tBN_256_SET(t_d2,0,15,14,13,12,0,0,0)\n\tif (bn_add_words(t_d, t_d, t_d2, BN_NIST_256_TOP))\n\t\tcarry = 2;\n\t\t{\n\t\tregister BN_ULONG *ap,t,c;\n\t\tap = t_d;\n\t\tc=0;\n\t\tfor (tmp_int=BN_NIST_256_TOP; tmp_int != 0; --tmp_int)\n\t\t\t{\n\t\t\tt= *ap;\n\t\t\t*(ap++)=((t<<1)|c)&BN_MASK2;\n\t\t\tc=(t & BN_TBIT)?1:0;\n\t\t\t}\n\t\tif (c)\n\t\t\t++carry;\n\t\t}\n\tif (bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t++carry;\n\tBN_256_SET(t_d,15,14,0,0,0,10,9,8)\n\tif (bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t++carry;\n\tBN_256_SET(t_d,8,13,15,14,13,11,10,9)\n\tif (bn_add_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t++carry;\n\tBN_256_SET(t_d,10,8,0,0,0,13,12,11)\n\tif (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t--carry;\n\tBN_256_SET(t_d,11,9,0,0,15,14,13,12)\n\tif (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t--carry;\n\tBN_256_SET(t_d,12,0,10,9,8,15,14,13)\n\tif (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t--carry;\n\tBN_256_SET(t_d,13,0,11,10,9,0,15,14)\n\tif (bn_sub_words(r_d, r_d, t_d, BN_NIST_256_TOP))\n\t\t--carry;\n\tif (carry)\n\t\t{\n\t\tif (carry > 0)\n\t\t\tbn_sub_words(r_d, r_d, _256_data + BN_NIST_256_TOP *\n\t\t\t\t--carry, BN_NIST_256_TOP);\n\t\telse\n\t\t\t{\n\t\t\tcarry = -carry;\n\t\t\tbn_add_words(r_d, r_d, _256_data + BN_NIST_256_TOP *\n\t\t\t\t--carry, BN_NIST_256_TOP);\n\t\t\t}\n\t\t}\n\tr->top = BN_NIST_256_TOP;\n#if 1\n\tbn_clear_top2max(r);\n#endif\n\tbn_fix_top(r);\n\tif (BN_ucmp(r, field) >= 0)\n\t\t{\n\t\tbn_sub_words(r_d, r_d, _nist_p_256, BN_NIST_256_TOP);\n\t\tbn_fix_top(r);\n\t\t}\n\treturn 1;\n#else\n\treturn 0;\n#endif\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}'] |
35,009 | 0 | https://github.com/openssl/openssl/blob/9f5671c7e9f30dfa53b1a2b553f234c2761ceb66/ssl/record/ssl3_record.c/#L1186 | int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)
{
unsigned char *mac_sec, *seq;
const EVP_MD_CTX *hash;
unsigned char *p, rec_char;
size_t md_size;
size_t npad;
int t;
if (sending) {
mac_sec = &(ssl->s3->write_mac_secret[0]);
seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);
hash = ssl->write_hash;
} else {
mac_sec = &(ssl->s3->read_mac_secret[0]);
seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);
hash = ssl->read_hash;
}
t = EVP_MD_CTX_size(hash);
if (t < 0)
return 0;
md_size = t;
npad = (48 / md_size) * md_size;
if (!sending &&
EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&
ssl3_cbc_record_digest_supported(hash)) {
unsigned char header[75];
size_t j = 0;
memcpy(header + j, mac_sec, md_size);
j += md_size;
memcpy(header + j, ssl3_pad_1, npad);
j += npad;
memcpy(header + j, seq, 8);
j += 8;
header[j++] = rec->type;
header[j++] = (unsigned char)(rec->length >> 8);
header[j++] = (unsigned char)(rec->length & 0xff);
if (ssl3_cbc_digest_record(hash,
md, &md_size,
header, rec->input,
rec->length + md_size, rec->orig_len,
mac_sec, md_size, 1) <= 0)
return 0;
} else {
unsigned int md_size_u;
EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();
if (md_ctx == NULL)
return 0;
rec_char = rec->type;
p = md;
s2n(rec->length, p);
if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
|| EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
|| EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0
|| EVP_DigestUpdate(md_ctx, seq, 8) <= 0
|| EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0
|| EVP_DigestUpdate(md_ctx, md, 2) <= 0
|| EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0
|| EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0
|| EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0
|| EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0
|| EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0
|| EVP_DigestUpdate(md_ctx, md, md_size) <= 0
|| EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {
EVP_MD_CTX_reset(md_ctx);
return 0;
}
EVP_MD_CTX_free(md_ctx);
}
ssl3_record_sequence_update(seq);
return 1;
} | ['int n_ssl3_mac(SSL *ssl, SSL3_RECORD *rec, unsigned char *md, int sending)\n{\n unsigned char *mac_sec, *seq;\n const EVP_MD_CTX *hash;\n unsigned char *p, rec_char;\n size_t md_size;\n size_t npad;\n int t;\n if (sending) {\n mac_sec = &(ssl->s3->write_mac_secret[0]);\n seq = RECORD_LAYER_get_write_sequence(&ssl->rlayer);\n hash = ssl->write_hash;\n } else {\n mac_sec = &(ssl->s3->read_mac_secret[0]);\n seq = RECORD_LAYER_get_read_sequence(&ssl->rlayer);\n hash = ssl->read_hash;\n }\n t = EVP_MD_CTX_size(hash);\n if (t < 0)\n return 0;\n md_size = t;\n npad = (48 / md_size) * md_size;\n if (!sending &&\n EVP_CIPHER_CTX_mode(ssl->enc_read_ctx) == EVP_CIPH_CBC_MODE &&\n ssl3_cbc_record_digest_supported(hash)) {\n unsigned char header[75];\n size_t j = 0;\n memcpy(header + j, mac_sec, md_size);\n j += md_size;\n memcpy(header + j, ssl3_pad_1, npad);\n j += npad;\n memcpy(header + j, seq, 8);\n j += 8;\n header[j++] = rec->type;\n header[j++] = (unsigned char)(rec->length >> 8);\n header[j++] = (unsigned char)(rec->length & 0xff);\n if (ssl3_cbc_digest_record(hash,\n md, &md_size,\n header, rec->input,\n rec->length + md_size, rec->orig_len,\n mac_sec, md_size, 1) <= 0)\n return 0;\n } else {\n unsigned int md_size_u;\n EVP_MD_CTX *md_ctx = EVP_MD_CTX_new();\n if (md_ctx == NULL)\n return 0;\n rec_char = rec->type;\n p = md;\n s2n(rec->length, p);\n if (EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0\n || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0\n || EVP_DigestUpdate(md_ctx, ssl3_pad_1, npad) <= 0\n || EVP_DigestUpdate(md_ctx, seq, 8) <= 0\n || EVP_DigestUpdate(md_ctx, &rec_char, 1) <= 0\n || EVP_DigestUpdate(md_ctx, md, 2) <= 0\n || EVP_DigestUpdate(md_ctx, rec->input, rec->length) <= 0\n || EVP_DigestFinal_ex(md_ctx, md, NULL) <= 0\n || EVP_MD_CTX_copy_ex(md_ctx, hash) <= 0\n || EVP_DigestUpdate(md_ctx, mac_sec, md_size) <= 0\n || EVP_DigestUpdate(md_ctx, ssl3_pad_2, npad) <= 0\n || EVP_DigestUpdate(md_ctx, md, md_size) <= 0\n || EVP_DigestFinal_ex(md_ctx, md, &md_size_u) <= 0) {\n EVP_MD_CTX_reset(md_ctx);\n return 0;\n }\n EVP_MD_CTX_free(md_ctx);\n }\n ssl3_record_sequence_update(seq);\n return 1;\n}', 'const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx)\n{\n if (!ctx)\n return NULL;\n return ctx->digest;\n}', 'int EVP_MD_size(const EVP_MD *md)\n{\n if (!md) {\n EVPerr(EVP_F_EVP_MD_SIZE, EVP_R_MESSAGE_DIGEST_IS_NULL);\n return -1;\n }\n return md->md_size;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)\n{\n unsigned char *tmp_buf;\n if ((in == NULL) || (in->digest == NULL)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, EVP_R_INPUT_NOT_INITIALIZED);\n return 0;\n }\n#ifndef OPENSSL_NO_ENGINE\n if (in->engine && !ENGINE_init(in->engine)) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_ENGINE_LIB);\n return 0;\n }\n#endif\n if (out->digest == in->digest) {\n tmp_buf = out->md_data;\n EVP_MD_CTX_set_flags(out, EVP_MD_CTX_FLAG_REUSE);\n } else\n tmp_buf = NULL;\n EVP_MD_CTX_reset(out);\n memcpy(out, in, sizeof(*out));\n out->md_data = NULL;\n out->pctx = NULL;\n if (in->md_data && out->digest->ctx_size) {\n if (tmp_buf)\n out->md_data = tmp_buf;\n else {\n out->md_data = OPENSSL_malloc(out->digest->ctx_size);\n if (out->md_data == NULL) {\n EVPerr(EVP_F_EVP_MD_CTX_COPY_EX, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n }\n memcpy(out->md_data, in->md_data, out->digest->ctx_size);\n }\n out->update = in->update;\n if (in->pctx) {\n out->pctx = EVP_PKEY_CTX_dup(in->pctx);\n if (!out->pctx) {\n EVP_MD_CTX_reset(out);\n return 0;\n }\n }\n if (out->digest->copy)\n return out->digest->copy(out, in);\n return 1;\n}', 'int ENGINE_init(ENGINE *e)\n{\n int ret;\n if (e == NULL) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!RUN_ONCE(&engine_lock_init, do_engine_lock_init)) {\n ENGINEerr(ENGINE_F_ENGINE_INIT, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n CRYPTO_THREAD_write_lock(global_engine_lock);\n ret = engine_unlocked_init(e);\n CRYPTO_THREAD_unlock(global_engine_lock);\n return ret;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}'] |
35,010 | 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_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#if defined(MSDOS) && !defined(WIN32)\n\t\t1024*30,\n#else\n\t\t1024*100,\n#endif\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_buf->data;\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\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}'] |
35,011 | 0 | https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/rsa/rsa_pmeth.c/#L284 | static int pkey_rsa_verify(EVP_PKEY_CTX *ctx,
const unsigned char *sig, size_t siglen,
const unsigned char *tbs, size_t tbslen)
{
RSA_PKEY_CTX *rctx = ctx->data;
RSA *rsa = ctx->pkey->pkey.rsa;
size_t rslen;
if (rctx->md) {
if (rctx->pad_mode == RSA_PKCS1_PADDING)
return RSA_verify(EVP_MD_type(rctx->md), tbs, tbslen,
sig, siglen, rsa);
if (rctx->pad_mode == RSA_X931_PADDING) {
if (pkey_rsa_verifyrecover(ctx, NULL, &rslen, sig, siglen) <= 0)
return 0;
} else if (rctx->pad_mode == RSA_PKCS1_PSS_PADDING) {
int ret;
if (!setup_tbuf(rctx, ctx))
return -1;
ret = RSA_public_decrypt(siglen, sig, rctx->tbuf,
rsa, RSA_NO_PADDING);
if (ret <= 0)
return 0;
ret = RSA_verify_PKCS1_PSS_mgf1(rsa, tbs,
rctx->md, rctx->mgf1md,
rctx->tbuf, rctx->saltlen);
if (ret <= 0)
return 0;
return 1;
} else
return -1;
} else {
if (!setup_tbuf(rctx, ctx))
return -1;
rslen = RSA_public_decrypt(siglen, sig, rctx->tbuf,
rsa, rctx->pad_mode);
if (rslen == 0)
return 0;
}
if ((rslen != tbslen) || memcmp(tbs, rctx->tbuf, rslen))
return 0;
return 1;
} | ['static int pkey_rsa_verify(EVP_PKEY_CTX *ctx,\n const unsigned char *sig, size_t siglen,\n const unsigned char *tbs, size_t tbslen)\n{\n RSA_PKEY_CTX *rctx = ctx->data;\n RSA *rsa = ctx->pkey->pkey.rsa;\n size_t rslen;\n if (rctx->md) {\n if (rctx->pad_mode == RSA_PKCS1_PADDING)\n return RSA_verify(EVP_MD_type(rctx->md), tbs, tbslen,\n sig, siglen, rsa);\n if (rctx->pad_mode == RSA_X931_PADDING) {\n if (pkey_rsa_verifyrecover(ctx, NULL, &rslen, sig, siglen) <= 0)\n return 0;\n } else if (rctx->pad_mode == RSA_PKCS1_PSS_PADDING) {\n int ret;\n if (!setup_tbuf(rctx, ctx))\n return -1;\n ret = RSA_public_decrypt(siglen, sig, rctx->tbuf,\n rsa, RSA_NO_PADDING);\n if (ret <= 0)\n return 0;\n ret = RSA_verify_PKCS1_PSS_mgf1(rsa, tbs,\n rctx->md, rctx->mgf1md,\n rctx->tbuf, rctx->saltlen);\n if (ret <= 0)\n return 0;\n return 1;\n } else\n return -1;\n } else {\n if (!setup_tbuf(rctx, ctx))\n return -1;\n rslen = RSA_public_decrypt(siglen, sig, rctx->tbuf,\n rsa, rctx->pad_mode);\n if (rslen == 0)\n return 0;\n }\n if ((rslen != tbslen) || memcmp(tbs, rctx->tbuf, rslen))\n return 0;\n return 1;\n}', 'static int pkey_rsa_verifyrecover(EVP_PKEY_CTX *ctx,\n unsigned char *rout, size_t *routlen,\n const unsigned char *sig, size_t siglen)\n{\n int ret;\n RSA_PKEY_CTX *rctx = ctx->data;\n if (rctx->md) {\n if (rctx->pad_mode == RSA_X931_PADDING) {\n if (!setup_tbuf(rctx, ctx))\n return -1;\n ret = RSA_public_decrypt(siglen, sig,\n rctx->tbuf, ctx->pkey->pkey.rsa,\n RSA_X931_PADDING);\n if (ret < 1)\n return 0;\n ret--;\n if (rctx->tbuf[ret] != RSA_X931_hash_id(EVP_MD_type(rctx->md))) {\n RSAerr(RSA_F_PKEY_RSA_VERIFYRECOVER,\n RSA_R_ALGORITHM_MISMATCH);\n return 0;\n }\n if (ret != EVP_MD_size(rctx->md)) {\n RSAerr(RSA_F_PKEY_RSA_VERIFYRECOVER,\n RSA_R_INVALID_DIGEST_LENGTH);\n return 0;\n }\n if (rout)\n memcpy(rout, rctx->tbuf, ret);\n } else if (rctx->pad_mode == RSA_PKCS1_PADDING) {\n size_t sltmp;\n ret = int_rsa_verify(EVP_MD_type(rctx->md),\n NULL, 0, rout, &sltmp,\n sig, siglen, ctx->pkey->pkey.rsa);\n if (ret <= 0)\n return 0;\n ret = sltmp;\n } else\n return -1;\n } else\n ret = RSA_public_decrypt(siglen, sig, rout, ctx->pkey->pkey.rsa,\n rctx->pad_mode);\n if (ret < 0)\n return ret;\n *routlen = ret;\n return 1;\n}', 'static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk)\n{\n if (ctx->tbuf)\n return 1;\n ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey));\n if (ctx->tbuf == NULL)\n return 0;\n return 1;\n}', 'int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to,\n RSA *rsa, int padding)\n{\n return (rsa->meth->rsa_pub_dec(flen, from, to, rsa, padding));\n}'] |
35,012 | 0 | https://github.com/nginx/nginx/blob/e5b2d3c6b2a132bbbbac0249566f0da7ff12bc39/src/http/ngx_http_core_module.c/#L2169 | ngx_int_t
ngx_http_internal_redirect(ngx_http_request_t *r,
ngx_str_t *uri, ngx_str_t *args)
{
ngx_http_core_srv_conf_t *cscf;
r->uri_changes--;
if (r->uri_changes == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"rewrite or internal redirection cycle "
"while internal redirect to \"%V\"", uri);
r->main->count++;
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
return NGX_DONE;
}
r->uri = *uri;
if (args) {
r->args = *args;
} else {
r->args.len = 0;
r->args.data = NULL;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"internal redirect: \"%V?%V\"", uri, &r->args);
ngx_http_set_exten(r);
ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
r->loc_conf = cscf->ctx->loc_conf;
ngx_http_update_location_config(r);
#if (NGX_HTTP_CACHE)
r->cache = NULL;
#endif
r->internal = 1;
r->main->count++;
ngx_http_handler(r);
return NGX_DONE;
} | ['static void\nngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ssize_t n;\n ngx_int_t rc;\n ngx_connection_t *c;\n c = u->peer.connection;\n ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http upstream process header");\n c->log->action = "reading response header from upstream";\n if (c->read->timedout) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);\n return;\n }\n if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n if (u->buffer.start == NULL) {\n u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);\n if (u->buffer.start == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n u->buffer.pos = u->buffer.start;\n u->buffer.last = u->buffer.start;\n u->buffer.end = u->buffer.start + u->conf->buffer_size;\n u->buffer.temporary = 1;\n u->buffer.tag = u->output.tag;\n if (ngx_list_init(&u->headers_in.headers, r->pool, 8,\n sizeof(ngx_table_elt_t))\n != NGX_OK)\n {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n#if (NGX_HTTP_CACHE)\n if (r->cache) {\n u->buffer.pos += r->cache->header_start;\n u->buffer.last = u->buffer.pos;\n }\n#endif\n }\n for ( ;; ) {\n n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);\n if (n == NGX_AGAIN) {\n#if 0\n ngx_add_timer(rev, u->read_timeout);\n#endif\n if (ngx_handle_read_event(c->read, 0) != NGX_OK) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n return;\n }\n if (n == 0) {\n ngx_log_error(NGX_LOG_ERR, c->log, 0,\n "upstream prematurely closed connection");\n }\n if (n == NGX_ERROR || n == 0) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);\n return;\n }\n u->buffer.last += n;\n#if 0\n u->valid_header_in = 0;\n u->peer.cached = 0;\n#endif\n rc = u->process_header(r);\n if (rc == NGX_AGAIN) {\n if (u->buffer.pos == u->buffer.end) {\n ngx_log_error(NGX_LOG_ERR, c->log, 0,\n "upstream sent too big header");\n ngx_http_upstream_next(r, u,\n NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n return;\n }\n continue;\n }\n break;\n }\n if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {\n ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);\n return;\n }\n if (rc == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST) {\n if (r->subrequest_in_memory) {\n u->buffer.last = u->buffer.pos;\n }\n if (ngx_http_upstream_test_next(r, u) == NGX_OK) {\n return;\n }\n if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) {\n return;\n }\n }\n if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {\n return;\n }\n if (!r->subrequest_in_memory) {\n ngx_http_upstream_send_response(r, u);\n return;\n }\n if (u->input_filter == NULL) {\n u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;\n u->input_filter = ngx_http_upstream_non_buffered_filter;\n u->input_filter_ctx = r;\n }\n if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return;\n }\n n = u->buffer.last - u->buffer.pos;\n if (n) {\n u->buffer.last -= n;\n u->state->response_length += n;\n if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {\n ngx_http_upstream_finalize_request(r, u, NGX_ERROR);\n return;\n }\n if (u->length == 0) {\n ngx_http_upstream_finalize_request(r, u, 0);\n return;\n }\n }\n u->read_event_handler = ngx_http_upstream_process_body_in_memory;\n ngx_http_upstream_process_body_in_memory(r, u);\n}', 'static ngx_int_t\nngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)\n{\n ngx_uint_t status;\n ngx_http_upstream_next_t *un;\n status = u->headers_in.status_n;\n for (un = ngx_http_upstream_next_errors; un->status; un++) {\n if (status != un->status) {\n continue;\n }\n if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) {\n ngx_http_upstream_next(r, u, un->mask);\n return NGX_OK;\n }\n#if (NGX_HTTP_CACHE)\n if (u->cache_status == NGX_HTTP_CACHE_EXPIRED\n && (u->conf->cache_use_stale & un->mask))\n {\n ngx_int_t rc;\n rc = u->reinit_request(r);\n if (rc == NGX_OK) {\n u->cache_status = NGX_HTTP_CACHE_STALE;\n rc = ngx_http_upstream_cache_send(r, u);\n }\n ngx_http_upstream_finalize_request(r, u, rc);\n return NGX_OK;\n }\n#endif\n }\n return NGX_DECLINED;\n}', 'static ngx_int_t\nngx_http_upstream_intercept_errors(ngx_http_request_t *r,\n ngx_http_upstream_t *u)\n{\n ngx_int_t status;\n ngx_uint_t i;\n ngx_table_elt_t *h;\n ngx_http_err_page_t *err_page;\n ngx_http_core_loc_conf_t *clcf;\n status = u->headers_in.status_n;\n if (status == NGX_HTTP_NOT_FOUND && u->conf->intercept_404) {\n ngx_http_upstream_finalize_request(r, u, NGX_HTTP_NOT_FOUND);\n return NGX_OK;\n }\n if (!u->conf->intercept_errors) {\n return NGX_DECLINED;\n }\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->error_pages == NULL) {\n return NGX_DECLINED;\n }\n err_page = clcf->error_pages->elts;\n for (i = 0; i < clcf->error_pages->nelts; i++) {\n if (err_page[i].status == status) {\n if (status == NGX_HTTP_UNAUTHORIZED\n && u->headers_in.www_authenticate)\n {\n h = ngx_list_push(&r->headers_out.headers);\n if (h == NULL) {\n ngx_http_upstream_finalize_request(r, u,\n NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_OK;\n }\n *h = *u->headers_in.www_authenticate;\n r->headers_out.www_authenticate = h;\n }\n ngx_http_upstream_finalize_request(r, u, status);\n return NGX_OK;\n }\n }\n return NGX_DECLINED;\n}', 'static void\nngx_http_upstream_finalize_request(ngx_http_request_t *r,\n ngx_http_upstream_t *u, ngx_int_t rc)\n{\n ngx_time_t *tp;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "finalize http upstream request: %i", rc);\n if (u->cleanup) {\n *u->cleanup = NULL;\n }\n if (u->state && u->state->response_sec) {\n tp = ngx_timeofday();\n u->state->response_sec = tp->sec - u->state->response_sec;\n u->state->response_msec = tp->msec - u->state->response_msec;\n if (u->pipe) {\n u->state->response_length = u->pipe->read_length;\n }\n }\n u->finalize_request(r, rc);\n if (u->peer.free) {\n u->peer.free(&u->peer, u->peer.data, 0);\n }\n if (u->peer.connection) {\n#if (NGX_HTTP_SSL)\n if (u->peer.connection->ssl) {\n u->peer.connection->ssl->no_wait_shutdown = 1;\n (void) ngx_ssl_shutdown(u->peer.connection);\n }\n#endif\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "close http upstream connection: %d",\n u->peer.connection->fd);\n ngx_close_connection(u->peer.connection);\n }\n u->peer.connection = NULL;\n if (u->pipe && u->pipe->temp_file) {\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream temp fd: %d",\n u->pipe->temp_file->file.fd);\n }\n#if (NGX_HTTP_CACHE)\n if (u->cacheable && r->cache) {\n time_t valid;\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "http upstream cache fd: %d",\n r->cache->file.fd);\n if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {\n valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);\n if (valid) {\n r->cache->valid_sec = ngx_time() + valid;\n r->cache->error = rc;\n }\n }\n ngx_http_file_cache_free(r, u->pipe->temp_file);\n }\n#endif\n if (u->header_sent\n && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))\n {\n rc = 0;\n }\n if (rc == NGX_DECLINED) {\n return;\n }\n r->connection->log->action = "sending to client";\n if (rc == 0) {\n rc = ngx_http_send_special(r, NGX_HTTP_LAST);\n }\n ngx_http_finalize_request(r, rc);\n}', 'void\nngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)\n{\n ngx_connection_t *c;\n ngx_http_request_t *pr;\n ngx_http_core_loc_conf_t *clcf;\n c = r->connection;\n ngx_log_debug5(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize request: %d, \\"%V?%V\\" a:%d, c:%d",\n rc, &r->uri, &r->args, r == c->data, r->main->count);\n if (rc == NGX_DONE) {\n ngx_http_finalize_connection(r);\n return;\n }\n if (rc == NGX_OK && r->filter_finalize) {\n c->error = 1;\n return;\n }\n if (rc == NGX_DECLINED) {\n r->content_handler = NULL;\n r->write_event_handler = ngx_http_core_run_phases;\n ngx_http_core_run_phases(r);\n return;\n }\n if (r != r->main && r->post_subrequest) {\n rc = r->post_subrequest->handler(r, r->post_subrequest->data, rc);\n }\n if (rc == NGX_ERROR\n || rc == NGX_HTTP_REQUEST_TIME_OUT\n || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST\n || c->error)\n {\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (r->main->blocked) {\n r->write_event_handler = ngx_http_request_finalizer;\n }\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (rc >= NGX_HTTP_SPECIAL_RESPONSE\n || rc == NGX_HTTP_CREATED\n || rc == NGX_HTTP_NO_CONTENT)\n {\n if (rc == NGX_HTTP_CLOSE) {\n ngx_http_terminate_request(r, rc);\n return;\n }\n if (r == r->main) {\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n ngx_del_timer(c->write);\n }\n }\n c->read->handler = ngx_http_request_handler;\n c->write->handler = ngx_http_request_handler;\n ngx_http_finalize_request(r, ngx_http_special_response_handler(r, rc));\n return;\n }\n if (r != r->main) {\n if (r->buffered || r->postponed) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n#if (NGX_DEBUG)\n if (r != c->data) {\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n }\n#endif\n pr = r->parent;\n if (r == c->data) {\n r->main->count--;\n if (!r->logged) {\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->log_subrequest) {\n ngx_http_log_request(r);\n }\n r->logged = 1;\n } else {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "subrequest: \\"%V?%V\\" logged again",\n &r->uri, &r->args);\n }\n r->done = 1;\n if (pr->postponed && pr->postponed->request == r) {\n pr->postponed = pr->postponed->next;\n }\n c->data = pr;\n } else {\n r->write_event_handler = ngx_http_request_finalizer;\n if (r->waited) {\n r->done = 1;\n }\n }\n if (ngx_http_post_request(pr, NULL) != NGX_OK) {\n r->main->count++;\n ngx_http_terminate_request(r, 0);\n return;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,\n "http wake parent request: \\"%V?%V\\"",\n &pr->uri, &pr->args);\n return;\n }\n if (r->buffered || c->buffered || r->postponed || r->blocked) {\n if (ngx_http_set_write_handler(r) != NGX_OK) {\n ngx_http_terminate_request(r, 0);\n }\n return;\n }\n if (r != c->data) {\n ngx_log_error(NGX_LOG_ALERT, c->log, 0,\n "http finalize non-active request: \\"%V?%V\\"",\n &r->uri, &r->args);\n return;\n }\n r->done = 1;\n if (!r->post_action) {\n r->request_complete = 1;\n }\n if (ngx_http_post_action(r) == NGX_OK) {\n return;\n }\n if (c->read->timer_set) {\n ngx_del_timer(c->read);\n }\n if (c->write->timer_set) {\n c->write->delayed = 0;\n ngx_del_timer(c->write);\n }\n if (c->read->eof) {\n ngx_http_close_request(r, 0);\n return;\n }\n ngx_http_finalize_connection(r);\n}', 'static ngx_int_t\nngx_http_post_action(ngx_http_request_t *r)\n{\n ngx_http_core_loc_conf_t *clcf;\n clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);\n if (clcf->post_action.data == NULL) {\n return NGX_DECLINED;\n }\n ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "post action: \\"%V\\"", &clcf->post_action);\n r->main->count--;\n r->http_version = NGX_HTTP_VERSION_9;\n r->header_only = 1;\n r->post_action = 1;\n r->read_event_handler = ngx_http_block_reading;\n if (clcf->post_action.data[0] == \'/\') {\n ngx_http_internal_redirect(r, &clcf->post_action, NULL);\n } else {\n ngx_http_named_location(r, &clcf->post_action);\n }\n return NGX_OK;\n}', 'ngx_int_t\nngx_http_internal_redirect(ngx_http_request_t *r,\n ngx_str_t *uri, ngx_str_t *args)\n{\n ngx_http_core_srv_conf_t *cscf;\n r->uri_changes--;\n if (r->uri_changes == 0) {\n ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,\n "rewrite or internal redirection cycle "\n "while internal redirect to \\"%V\\"", uri);\n r->main->count++;\n ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);\n return NGX_DONE;\n }\n r->uri = *uri;\n if (args) {\n r->args = *args;\n } else {\n r->args.len = 0;\n r->args.data = NULL;\n }\n ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,\n "internal redirect: \\"%V?%V\\"", uri, &r->args);\n ngx_http_set_exten(r);\n ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);\n cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);\n r->loc_conf = cscf->ctx->loc_conf;\n ngx_http_update_location_config(r);\n#if (NGX_HTTP_CACHE)\n r->cache = NULL;\n#endif\n r->internal = 1;\n r->main->count++;\n ngx_http_handler(r);\n return NGX_DONE;\n}'] |
35,013 | 0 | https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_lib.c/#L779 | int bn_cmp_words(BN_ULONG *a, 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 test_mul(BIO *bp)\n\t{\n\tBIGNUM a,b,c,d,e;\n\tint i;\n\tint j;\n\tBN_CTX ctx;\n\tBN_CTX_init(&ctx);\n\tBN_init(&a);\n\tBN_init(&b);\n\tBN_init(&c);\n\tBN_init(&d);\n\tBN_init(&e);\n\tBN_rand(&a,200,0,0);\n\tfor (i=0; i<100; i++)\n\t\t{\n\t\tBN_rand(&b,250+i,0,0);\n\t\tBN_rand(&b,200,0,0);\n\t\ta.neg=rand_neg();\n\t\tb.neg=rand_neg();\n\t\tif (bp == NULL)\n\t\t\tfor (j=0; j<100; j++)\n\t\t\t\tBN_mul(&c,&a,&b,&ctx);\n\t\tBN_mul(&c,&a,&b,&ctx);\n\t\tif (bp != NULL)\n\t\t\t{\n\t\t\tif (!results)\n\t\t\t\t{\n\t\t\t\tBN_print(bp,&a);\n\t\t\t\tBIO_puts(bp," * ");\n\t\t\t\tBN_print(bp,&b);\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,&c);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_div(&d,&e,&c,&a,&ctx);\n\t\tBN_sub(&d,&d,&b);\n\t\tif(!BN_is_zero(&d) || !BN_is_zero(&e))\n\t\t {\n\t\t BIO_puts(bp,"Multiplication test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\t}\n\tBN_free(&a);\n\tBN_free(&b);\n\tBN_free(&c);\n\tBN_free(&d);\n\tBN_free(&e);\n\tBN_CTX_free(&ctx);\n\treturn(1);\n\t}', 'int BN_rand(BIGNUM *rnd, int bits, int top, int bottom)\n\t{\n\tunsigned char *buf=NULL;\n\tint ret=0,bit,bytes,mask;\n\ttime_t tim;\n\tbytes=(bits+7)/8;\n\tbit=(bits-1)%8;\n\tmask=0xff<<bit;\n\tbuf=(unsigned char *)Malloc(bytes);\n\tif (buf == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\ttime(&tim);\n\tRAND_seed(&tim,sizeof(tim));\n\tRAND_bytes(buf,(int)bytes);\n\tif (top)\n\t\t{\n\t\tif (bit == 0)\n\t\t\t{\n\t\t\tbuf[0]=1;\n\t\t\tbuf[1]|=0x80;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf[0]|=(3<<(bit-1));\n\t\t\tbuf[0]&= ~(mask<<1);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tbuf[0]|=(1<<bit);\n\t\tbuf[0]&= ~(mask<<1);\n\t\t}\n\tif (bottom)\n\t\tbuf[bytes-1]|=1;\n\tif (!BN_bin2bn(buf,bytes,rnd)) goto err;\n\tret=1;\nerr:\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,bytes);\n\t\tFree(buf);\n\t\t}\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,\n\t int n, BN_ULONG *t)\n\t{\n\tint i,j,n2=n*2;\n\tunsigned int c1;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_part_recursive %d * %d\\n",tn+n,tn+n);\n#endif\n\tif (n < 8)\n\t\t{\n\t\ti=tn+n;\n\t\tbn_mul_normal(r,a,i,b,i);\n\t\treturn;\n\t\t}\n\tbn_sub_words(t, a, &(a[n]),n);\n\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n if (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\tmemset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));\n\t\t}\n\telse\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\ti=n/2;\n\t\tj=tn-i;\n\t\tif (j == 0)\n\t\t\t{\n\t\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);\n\t\t\tmemset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));\n\t\t\t}\n\t\telse if (j > 0)\n\t\t\t\t{\n\t\t\t\tbn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),\n\t\t\t\t\tj,i,p);\n\t\t\t\tmemset(&(r[n2+tn*2]),0,\n\t\t\t\t\tsizeof(BN_ULONG)*(n2-tn*2));\n\t\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemset(&(r[n2]),0,sizeof(BN_ULONG)*n2);\n\t\t\tif (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t\t\t{\n\t\t\t\tbn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tfor (;;)\n\t\t\t\t\t{\n\t\t\t\t\ti/=2;\n\t\t\t\t\tif (i < tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_part_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ttn-i,i,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\telse if (i == tn)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tbn_mul_recursive(&(r[n2]),\n\t\t\t\t\t\t\t&(a[n]),&(b[n]),\n\t\t\t\t\t\t\ti,p);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n\t BN_ULONG *t)\n\t{\n\tint n=n2/2,c1,c2;\n\tunsigned int neg,zero;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_recursive %d * %d\\n",n2,n2);\n#endif\n#ifdef BN_MUL_COMBA\n if (n2 == 8)\n\t\t{\n\t\tbn_mul_comba8(r,a,b);\n\t\treturn;\n\t\t}\n#endif\n\tif (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t{\n\t\tbn_mul_normal(r,a,n2,b,n2);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_words(a,&(a[n]),n);\n\tc2=bn_cmp_words(&(b[n]),b,n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\t\tbreak;\n\tcase -2:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\t\tbreak;\n\tcase 2:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\t\tbreak;\n\tcase 4:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tbreak;\n\t\t}\n#ifdef BN_MUL_COMBA\n\tif (n == 4)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,8*sizeof(BN_ULONG));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse if (n == 8)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,16*sizeof(BN_ULONG));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tif (!zero)\n\t\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\telse\n\t\t\tmemset(&(t[n2]),0,n2*sizeof(BN_ULONG));\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'int bn_cmp_words(BN_ULONG *a, BN_ULONG *b, int n)\n\t{\n\tint i;\n\tBN_ULONG aa,bb;\n\taa=a[n-1];\n\tbb=b[n-1];\n\tif (aa != bb) return((aa > bb)?1:-1);\n\tfor (i=n-2; i>=0; i--)\n\t\t{\n\t\taa=a[i];\n\t\tbb=b[i];\n\t\tif (aa != bb) return((aa > bb)?1:-1);\n\t\t}\n\treturn(0);\n\t}'] |
35,014 | 0 | https://github.com/openssl/openssl/blob/b8d243956296458d1782af0d6e7ecfe6deae038a/crypto/mem.c/#L151 | void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,
const char *file, int line)
{
void *ret = NULL;
if (str == NULL)
return CRYPTO_malloc(num, file, line);
if (num == 0) {
CRYPTO_clear_free(str, old_len, file, line);
return NULL;
}
if (num < old_len) {
OPENSSL_cleanse((char*)str + num, old_len - num);
return str;
}
ret = CRYPTO_malloc(num, file, line);
if (ret != NULL) {
memcpy(ret, str, old_len);
CRYPTO_clear_free(str, old_len, file, line);
}
return ret;
} | ['static int dtls_get_reassembled_message(SSL *s, long *len)\n{\n unsigned char wire[DTLS1_HM_HEADER_LENGTH];\n unsigned long mlen, frag_off, frag_len;\n int i, al, recvd_type;\n struct hm_header_st msg_hdr;\n int ok;\n redo:\n if ((frag_len = dtls1_retrieve_buffered_fragment(s, &ok)) || ok) {\n if (ok)\n s->init_num = frag_len;\n *len = frag_len;\n return ok;\n }\n i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, &recvd_type, wire,\n DTLS1_HM_HEADER_LENGTH, 0);\n if (i <= 0) {\n s->rwstate = SSL_READING;\n *len = i;\n return 0;\n }\n if (recvd_type == SSL3_RT_CHANGE_CIPHER_SPEC) {\n if (wire[0] != SSL3_MT_CCS) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE,\n SSL_R_BAD_CHANGE_CIPHER_SPEC);\n goto f_err;\n }\n memcpy(s->init_buf->data, wire, i);\n s->init_num = i - 1;\n s->init_msg = s->init_buf->data + 1;\n s->s3->tmp.message_type = SSL3_MT_CHANGE_CIPHER_SPEC;\n s->s3->tmp.message_size = i - 1;\n *len = i - 1;\n return 1;\n }\n if (i != DTLS1_HM_HEADER_LENGTH) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL_R_UNEXPECTED_MESSAGE);\n goto f_err;\n }\n dtls1_get_message_header(wire, &msg_hdr);\n mlen = msg_hdr.msg_len;\n frag_off = msg_hdr.frag_off;\n frag_len = msg_hdr.frag_len;\n if (frag_len > RECORD_LAYER_get_rrec_length(&s->rlayer)) {\n al = SSL3_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL_R_BAD_LENGTH);\n goto f_err;\n }\n if (msg_hdr.seq != s->d1->handshake_read_seq) {\n *len = dtls1_process_out_of_seq_message(s, &msg_hdr, &ok);\n return ok;\n }\n if (frag_len && frag_len < mlen) {\n *len = dtls1_reassemble_fragment(s, &msg_hdr, &ok);\n return ok;\n }\n if (!s->server && s->d1->r_msg_hdr.frag_off == 0 &&\n wire[0] == SSL3_MT_HELLO_REQUEST) {\n if (wire[1] == 0 && wire[2] == 0 && wire[3] == 0) {\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n wire, DTLS1_HM_HEADER_LENGTH, s,\n s->msg_callback_arg);\n s->init_num = 0;\n goto redo;\n } else {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE,\n SSL_R_UNEXPECTED_MESSAGE);\n goto f_err;\n }\n }\n if ((al = dtls1_preprocess_fragment(s, &msg_hdr)))\n goto f_err;\n if (frag_len > 0) {\n unsigned char *p =\n (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,\n &p[frag_off], frag_len, 0);\n if (i <= 0) {\n s->rwstate = SSL_READING;\n *len = i;\n return 0;\n }\n } else\n i = 0;\n if (i != (int)frag_len) {\n al = SSL3_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_DTLS_GET_REASSEMBLED_MESSAGE, SSL3_AD_ILLEGAL_PARAMETER);\n goto f_err;\n }\n *len = s->init_num = frag_len;\n return 1;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n s->init_num = 0;\n *len = -1;\n return 0;\n}', 'static int dtls1_retrieve_buffered_fragment(SSL *s, int *ok)\n{\n pitem *item;\n hm_fragment *frag;\n int al;\n *ok = 0;\n do {\n item = pqueue_peek(s->d1->buffered_messages);\n if (item == NULL)\n return 0;\n frag = (hm_fragment *)item->data;\n if (frag->msg_header.seq < s->d1->handshake_read_seq) {\n pqueue_pop(s->d1->buffered_messages);\n dtls1_hm_fragment_free(frag);\n pitem_free(item);\n item = NULL;\n frag = NULL;\n }\n } while (item == NULL);\n if (frag->reassembly != NULL)\n return 0;\n if (s->d1->handshake_read_seq == frag->msg_header.seq) {\n unsigned long frag_len = frag->msg_header.frag_len;\n pqueue_pop(s->d1->buffered_messages);\n al = dtls1_preprocess_fragment(s, &frag->msg_header);\n if (al == 0) {\n unsigned char *p =\n (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;\n memcpy(&p[frag->msg_header.frag_off], frag->fragment,\n frag->msg_header.frag_len);\n }\n dtls1_hm_fragment_free(frag);\n pitem_free(item);\n if (al == 0) {\n *ok = 1;\n return frag_len;\n }\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n s->init_num = 0;\n *ok = 0;\n return -1;\n } else\n return 0;\n}', 'static int dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr)\n{\n size_t frag_off, frag_len, msg_len;\n msg_len = msg_hdr->msg_len;\n frag_off = msg_hdr->frag_off;\n frag_len = msg_hdr->frag_len;\n if ((frag_off + frag_len) > msg_len\n || msg_len > dtls1_max_handshake_message_len(s)) {\n SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n return SSL_AD_ILLEGAL_PARAMETER;\n }\n if (s->d1->r_msg_hdr.frag_off == 0) {\n if (!BUF_MEM_grow_clean(s->init_buf, msg_len + DTLS1_HM_HEADER_LENGTH)) {\n SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, ERR_R_BUF_LIB);\n return SSL_AD_INTERNAL_ERROR;\n }\n s->s3->tmp.message_size = msg_len;\n s->d1->r_msg_hdr.msg_len = msg_len;\n s->s3->tmp.message_type = msg_hdr->type;\n s->d1->r_msg_hdr.type = msg_hdr->type;\n s->d1->r_msg_hdr.seq = msg_hdr->seq;\n } else if (msg_len != s->d1->r_msg_hdr.msg_len) {\n SSLerr(SSL_F_DTLS1_PREPROCESS_FRAGMENT, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n return SSL_AD_ILLEGAL_PARAMETER;\n }\n return 0;\n}', 'size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n{\n char *ret;\n size_t n;\n if (str->length >= len) {\n if (str->data != NULL)\n memset(&str->data[len], 0, str->length - len);\n str->length = len;\n return (len);\n }\n if (str->max >= len) {\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n return (len);\n }\n if (len > LIMIT_BEFORE_EXPANSION) {\n BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n n = (len + 3) / 3 * 4;\n if ((str->flags & BUF_MEM_FLAG_SECURE))\n ret = sec_alloc_realloc(str, n);\n else\n ret = OPENSSL_clear_realloc(str->data, str->max, n);\n if (ret == NULL) {\n BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n len = 0;\n } else {\n str->data = ret;\n str->max = n;\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n }\n return (len);\n}', 'void *CRYPTO_clear_realloc(void *str, size_t old_len, size_t num,\n const char *file, int line)\n{\n void *ret = NULL;\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_clear_free(str, old_len, file, line);\n return NULL;\n }\n if (num < old_len) {\n OPENSSL_cleanse((char*)str + num, old_len - num);\n return str;\n }\n ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL) {\n memcpy(ret, str, old_len);\n CRYPTO_clear_free(str, old_len, file, line);\n }\n return ret;\n}'] |
35,015 | 0 | https://github.com/openssl/openssl/blob/a8140a42f5ee9e4e1423b5b6b319dc4657659f6f/crypto/bn/bn_lib.c/#L973 | void bn_correct_top(BIGNUM *a)
{
BN_ULONG *ftl;
int tmp_top = a->top;
if (tmp_top > 0) {
for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {
ftl--;
if (*ftl != 0)
break;
}
a->top = tmp_top;
}
if (a->top == 0)
a->neg = 0;
a->flags &= ~BN_FLG_FIXED_TOP;
bn_pollute(a);
} | ['int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)\n{\n#ifdef FIPS_MODE\n return rsa_sp800_56b_check_public(key)\n && rsa_sp800_56b_check_private(key)\n && rsa_sp800_56b_check_keypair(key, NULL, -1, RSA_bits(key));\n#else\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);\n if (ex_primes <= 0\n || (ex_primes + 2) > rsa_multip_cap(BN_num_bits(key->n))) {\n RSAerr(RSA_F_RSA_CHECK_KEY_EX, RSA_R_INVALID_MULTI_PRIME_KEY);\n return 0;\n }\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#endif\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_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}', '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_correct_top(BIGNUM *a)\n{\n BN_ULONG *ftl;\n int tmp_top = a->top;\n if (tmp_top > 0) {\n for (ftl = &(a->d[tmp_top]); tmp_top > 0; tmp_top--) {\n ftl--;\n if (*ftl != 0)\n break;\n }\n a->top = tmp_top;\n }\n if (a->top == 0)\n a->neg = 0;\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_pollute(a);\n}'] |
35,016 | 0 | https://github.com/libav/libav/blob/f5a2c9816e0b58edf2a87297be8d648631fc3432/libavcodec/h264.c/#L949 | static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
MpegEncContext * const s = &h->s;
Picture * const ref1 = &h->ref_list[1][0];
int j, old_ref, rfield;
int start= mbafi ? 16 : 0;
int end = mbafi ? 16+2*h->ref_count[list] : h->ref_count[list];
int interl= mbafi || s->picture_structure != PICT_FRAME;
memset(map[list], 0, sizeof(map[list]));
for(rfield=0; rfield<2; rfield++){
for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
int poc = ref1->ref_poc[colfield][list][old_ref];
if (!interl)
poc |= 3;
else if( interl && (poc&3) == 3)
poc= (poc&~3) + rfield + 1;
for(j=start; j<end; j++){
if(4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3) == poc){
int cur_ref= mbafi ? (j-16)^field : j;
map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
if(rfield == field)
map[list][old_ref] = cur_ref;
break;
}
}
}
}
} | ['static inline void direct_ref_list_init(H264Context * const h){\n MpegEncContext * const s = &h->s;\n Picture * const ref1 = &h->ref_list[1][0];\n Picture * const cur = s->current_picture_ptr;\n int list, j, field;\n int sidx= (s->picture_structure&1)^1;\n int ref1sidx= (ref1->reference&1)^1;\n for(list=0; list<2; list++){\n cur->ref_count[sidx][list] = h->ref_count[list];\n for(j=0; j<h->ref_count[list]; j++)\n cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);\n }\n if(s->picture_structure == PICT_FRAME){\n memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));\n memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0]));\n }\n cur->mbaff= FRAME_MBAFF;\n if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)\n return;\n for(list=0; list<2; list++){\n fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);\n for(field=0; field<2; field++)\n fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);\n }\n}', 'static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){\n MpegEncContext * const s = &h->s;\n Picture * const ref1 = &h->ref_list[1][0];\n int j, old_ref, rfield;\n int start= mbafi ? 16 : 0;\n int end = mbafi ? 16+2*h->ref_count[list] : h->ref_count[list];\n int interl= mbafi || s->picture_structure != PICT_FRAME;\n memset(map[list], 0, sizeof(map[list]));\n for(rfield=0; rfield<2; rfield++){\n for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){\n int poc = ref1->ref_poc[colfield][list][old_ref];\n if (!interl)\n poc |= 3;\n else if( interl && (poc&3) == 3)\n poc= (poc&~3) + rfield + 1;\n for(j=start; j<end; j++){\n if(4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3) == poc){\n int cur_ref= mbafi ? (j-16)^field : j;\n map[list][2*old_ref + (rfield^field) + 16] = cur_ref;\n if(rfield == field)\n map[list][old_ref] = cur_ref;\n break;\n }\n }\n }\n }\n}'] |
35,017 | 0 | https://github.com/openssl/openssl/blob/6fc1748ec65c94c195d02b59556434e36a5f7651/crypto/buffer/buffer.c/#L116 | size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
{
char *ret;
size_t n;
if (str->length >= len) {
if (str->data != NULL)
memset(&str->data[len], 0, str->length - len);
str->length = len;
return (len);
}
if (str->max >= len) {
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return (len);
}
if (len > LIMIT_BEFORE_EXPANSION) {
BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
return 0;
}
n = (len + 3) / 3 * 4;
if ((str->flags & BUF_MEM_FLAG_SECURE))
ret = sec_alloc_realloc(str, n);
else
ret = OPENSSL_clear_realloc(str->data, str->max, n);
if (ret == NULL) {
BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
len = 0;
} else {
str->data = ret;
str->max = n;
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
}
return (len);
} | ['static SUB_STATE_RETURN read_state_machine(SSL *s)\n{\n OSSL_STATEM *st = &s->statem;\n int ret, mt;\n unsigned long len = 0;\n int (*transition) (SSL *s, int mt);\n PACKET pkt;\n MSG_PROCESS_RETURN(*process_message) (SSL *s, PACKET *pkt);\n WORK_STATE(*post_process_message) (SSL *s, WORK_STATE wst);\n unsigned long (*max_message_size) (SSL *s);\n void (*cb) (const SSL *ssl, int type, int val) = NULL;\n cb = get_callback(s);\n if (s->server) {\n transition = ossl_statem_server_read_transition;\n process_message = ossl_statem_server_process_message;\n max_message_size = ossl_statem_server_max_message_size;\n post_process_message = ossl_statem_server_post_process_message;\n } else {\n transition = ossl_statem_client_read_transition;\n process_message = ossl_statem_client_process_message;\n max_message_size = ossl_statem_client_max_message_size;\n post_process_message = ossl_statem_client_post_process_message;\n }\n if (st->read_state_first_init) {\n s->first_packet = 1;\n st->read_state_first_init = 0;\n }\n while (1) {\n switch (st->read_state) {\n case READ_STATE_HEADER:\n if (SSL_IS_DTLS(s)) {\n ret = dtls_get_message(s, &mt, &len);\n } else {\n ret = tls_get_message_header(s, &mt);\n }\n if (ret == 0) {\n return SUB_STATE_ERROR;\n }\n if (cb != NULL) {\n if (s->server)\n cb(s, SSL_CB_ACCEPT_LOOP, 1);\n else\n cb(s, SSL_CB_CONNECT_LOOP, 1);\n }\n if (!transition(s, mt)) {\n ossl_statem_set_error(s);\n return SUB_STATE_ERROR;\n }\n if (s->s3->tmp.message_size > max_message_size(s)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);\n SSLerr(SSL_F_READ_STATE_MACHINE, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n return SUB_STATE_ERROR;\n }\n st->read_state = READ_STATE_BODY;\n case READ_STATE_BODY:\n if (!SSL_IS_DTLS(s)) {\n ret = tls_get_message_body(s, &len);\n if (ret == 0) {\n return SUB_STATE_ERROR;\n }\n }\n s->first_packet = 0;\n if (!PACKET_buf_init(&pkt, s->init_msg, len)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n return SUB_STATE_ERROR;\n }\n ret = process_message(s, &pkt);\n s->init_num = 0;\n if (ret == MSG_PROCESS_ERROR) {\n return SUB_STATE_ERROR;\n }\n if (ret == MSG_PROCESS_FINISHED_READING) {\n if (SSL_IS_DTLS(s)) {\n dtls1_stop_timer(s);\n }\n return SUB_STATE_FINISHED;\n }\n if (ret == MSG_PROCESS_CONTINUE_PROCESSING) {\n st->read_state = READ_STATE_POST_PROCESS;\n st->read_state_work = WORK_MORE_A;\n } else {\n st->read_state = READ_STATE_HEADER;\n }\n break;\n case READ_STATE_POST_PROCESS:\n st->read_state_work = post_process_message(s, st->read_state_work);\n switch (st->read_state_work) {\n default:\n return SUB_STATE_ERROR;\n case WORK_FINISHED_CONTINUE:\n st->read_state = READ_STATE_HEADER;\n break;\n case WORK_FINISHED_STOP:\n if (SSL_IS_DTLS(s)) {\n dtls1_stop_timer(s);\n }\n return SUB_STATE_FINISHED;\n }\n break;\n default:\n ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);\n SSLerr(SSL_F_READ_STATE_MACHINE, ERR_R_INTERNAL_ERROR);\n ossl_statem_set_error(s);\n return SUB_STATE_ERROR;\n }\n }\n}', 'int tls_get_message_header(SSL *s, int *mt)\n{\n int skip_message, i, recvd_type, al;\n unsigned char *p;\n unsigned long l;\n p = (unsigned char *)s->init_buf->data;\n do {\n while (s->init_num < SSL3_HM_HEADER_LENGTH) {\n i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, &recvd_type,\n &p[s->init_num],\n SSL3_HM_HEADER_LENGTH - s->init_num,\n 0);\n if (i <= 0) {\n s->rwstate = SSL_READING;\n return 0;\n }\n if (recvd_type == SSL3_RT_CHANGE_CIPHER_SPEC) {\n if (s->init_num != 0 || i != 1 || p[0] != SSL3_MT_CCS) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER,\n SSL_R_BAD_CHANGE_CIPHER_SPEC);\n goto f_err;\n }\n s->s3->tmp.message_type = *mt = SSL3_MT_CHANGE_CIPHER_SPEC;\n s->init_num = i - 1;\n s->s3->tmp.message_size = i;\n return 1;\n } else if (recvd_type != SSL3_RT_HANDSHAKE) {\n al = SSL_AD_UNEXPECTED_MESSAGE;\n SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, SSL_R_CCS_RECEIVED_EARLY);\n goto f_err;\n }\n s->init_num += i;\n }\n skip_message = 0;\n if (!s->server)\n if (p[0] == SSL3_MT_HELLO_REQUEST)\n if (p[1] == 0 && p[2] == 0 && p[3] == 0) {\n s->init_num = 0;\n skip_message = 1;\n if (s->msg_callback)\n s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE,\n p, SSL3_HM_HEADER_LENGTH, s,\n s->msg_callback_arg);\n }\n } while (skip_message);\n *mt = *p;\n s->s3->tmp.message_type = *(p++);\n if (RECORD_LAYER_is_sslv2_record(&s->rlayer)) {\n l = RECORD_LAYER_get_rrec_length(&s->rlayer)\n + SSL3_HM_HEADER_LENGTH;\n if (l && !BUF_MEM_grow_clean(s->init_buf, (int)l)) {\n SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB);\n goto err;\n }\n s->s3->tmp.message_size = l;\n s->init_msg = s->init_buf->data;\n s->init_num = SSL3_HM_HEADER_LENGTH;\n } else {\n n2l3(p, l);\n if (l > (INT_MAX - SSL3_HM_HEADER_LENGTH)) {\n al = SSL_AD_ILLEGAL_PARAMETER;\n SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, SSL_R_EXCESSIVE_MESSAGE_SIZE);\n goto f_err;\n }\n if (l && !BUF_MEM_grow_clean(s->init_buf,\n (int)l + SSL3_HM_HEADER_LENGTH)) {\n SSLerr(SSL_F_TLS_GET_MESSAGE_HEADER, ERR_R_BUF_LIB);\n goto err;\n }\n s->s3->tmp.message_size = l;\n s->init_msg = s->init_buf->data + SSL3_HM_HEADER_LENGTH;\n s->init_num = 0;\n }\n return 1;\n f_err:\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n err:\n return 0;\n}', 'size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n{\n char *ret;\n size_t n;\n if (str->length >= len) {\n if (str->data != NULL)\n memset(&str->data[len], 0, str->length - len);\n str->length = len;\n return (len);\n }\n if (str->max >= len) {\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n return (len);\n }\n if (len > LIMIT_BEFORE_EXPANSION) {\n BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n n = (len + 3) / 3 * 4;\n if ((str->flags & BUF_MEM_FLAG_SECURE))\n ret = sec_alloc_realloc(str, n);\n else\n ret = OPENSSL_clear_realloc(str->data, str->max, n);\n if (ret == NULL) {\n BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n len = 0;\n } else {\n str->data = ret;\n str->max = n;\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n }\n return (len);\n}'] |
35,018 | 0 | https://github.com/openssl/openssl/blob/23dd0c9f8dc6f7edf4b872d13e5644dfbbee585b/crypto/x509/by_file.c/#L185 | int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
{
int ret = 0;
BIO *in = NULL;
int i, count = 0;
X509_CRL *x = NULL;
if (file == NULL)
return (1);
in = BIO_new(BIO_s_file());
if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB);
goto err;
}
if (type == X509_FILETYPE_PEM) {
for (;;) {
x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);
if (x == NULL) {
if ((ERR_GET_REASON(ERR_peek_last_error()) ==
PEM_R_NO_START_LINE) && (count > 0)) {
ERR_clear_error();
break;
} else {
X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_PEM_LIB);
goto err;
}
}
i = X509_STORE_add_crl(ctx->store_ctx, x);
if (!i)
goto err;
count++;
X509_CRL_free(x);
x = NULL;
}
ret = count;
} else if (type == X509_FILETYPE_ASN1) {
x = d2i_X509_CRL_bio(in, NULL);
if (x == NULL) {
X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB);
goto err;
}
i = X509_STORE_add_crl(ctx->store_ctx, x);
if (!i)
goto err;
ret = i;
} else {
X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE);
goto err;
}
err:
X509_CRL_free(x);
BIO_free(in);
return (ret);
} | ['int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)\n{\n int ret = 0;\n BIO *in = NULL;\n int i, count = 0;\n X509_CRL *x = NULL;\n if (file == NULL)\n return (1);\n in = BIO_new(BIO_s_file());\n if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {\n X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB);\n goto err;\n }\n if (type == X509_FILETYPE_PEM) {\n for (;;) {\n x = PEM_read_bio_X509_CRL(in, NULL, NULL, NULL);\n if (x == NULL) {\n if ((ERR_GET_REASON(ERR_peek_last_error()) ==\n PEM_R_NO_START_LINE) && (count > 0)) {\n ERR_clear_error();\n break;\n } else {\n X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_PEM_LIB);\n goto err;\n }\n }\n i = X509_STORE_add_crl(ctx->store_ctx, x);\n if (!i)\n goto err;\n count++;\n X509_CRL_free(x);\n x = NULL;\n }\n ret = count;\n } else if (type == X509_FILETYPE_ASN1) {\n x = d2i_X509_CRL_bio(in, NULL);\n if (x == NULL) {\n X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB);\n goto err;\n }\n i = X509_STORE_add_crl(ctx->store_ctx, x);\n if (!i)\n goto err;\n ret = i;\n } else {\n X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE);\n goto err;\n }\n err:\n X509_CRL_free(x);\n BIO_free(in);\n return (ret);\n}', 'const BIO_METHOD *BIO_s_file(void)\n{\n return (&methods_filep);\n}', 'BIO *BIO_new(const BIO_METHOD *method)\n{\n BIO *ret = OPENSSL_malloc(sizeof(*ret));\n if (ret == NULL) {\n BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n if (!BIO_set(ret, method)) {\n OPENSSL_free(ret);\n ret = NULL;\n }\n return (ret);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)\n{\n long ret;\n long (*cb) (BIO *, int, const char *, int, long, long);\n if (b == NULL)\n return (0);\n if ((b->method == NULL) || (b->method->ctrl == NULL)) {\n BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);\n return (-2);\n }\n cb = b->callback;\n if ((cb != NULL) &&\n ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))\n return (ret);\n ret = b->method->ctrl(b, cmd, larg, parg);\n if (cb != NULL)\n ret = cb(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, cmd, larg, ret);\n return (ret);\n}', 'IMPLEMENT_ASN1_FUNCTIONS(X509_CRL)', 'void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)\n{\n asn1_item_embed_free(&val, it, 0);\n}'] |
35,019 | 0 | https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/lhash/lhash.c/#L122 | void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return NULL;
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return ret;
} | ['static int test_ssl_clear(int idx)\n{\n SSL_CTX *cctx = NULL, *sctx = NULL;\n SSL *clientssl = NULL, *serverssl = NULL;\n int testresult = 0;\n#ifdef OPENSSL_NO_TLS1_2\n if (idx == 1)\n return 1;\n#endif\n if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),\n TLS_client_method(), &sctx,\n &cctx, cert, privkey))\n || (idx == 1\n && !TEST_true(SSL_CTX_set_max_proto_version(cctx,\n TLS1_2_VERSION)))\n || !TEST_true(create_ssl_objects(sctx, cctx, &serverssl,\n &clientssl, NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl, clientssl,\n SSL_ERROR_NONE)))\n goto end;\n SSL_shutdown(clientssl);\n SSL_shutdown(serverssl);\n SSL_free(serverssl);\n serverssl = NULL;\n if (!TEST_true(SSL_clear(clientssl)))\n goto end;\n if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,\n NULL, NULL))\n || !TEST_true(create_ssl_connection(serverssl, clientssl,\n SSL_ERROR_NONE))\n || !TEST_true(SSL_session_reused(clientssl)))\n goto end;\n SSL_shutdown(clientssl);\n SSL_shutdown(serverssl);\n testresult = 1;\n end:\n SSL_free(serverssl);\n SSL_free(clientssl);\n SSL_CTX_free(sctx);\n SSL_CTX_free(cctx);\n return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n SSL *serverssl = NULL, *clientssl = NULL;\n BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n if (*sssl != NULL)\n serverssl = *sssl;\n else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n goto error;\n if (*cssl != NULL)\n clientssl = *cssl;\n else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n goto error;\n if (SSL_is_dtls(clientssl)) {\n if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n goto error;\n } else {\n if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n goto error;\n }\n if (s_to_c_fbio != NULL\n && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n goto error;\n if (c_to_s_fbio != NULL\n && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n goto error;\n BIO_set_mem_eof_return(s_to_c_bio, -1);\n BIO_set_mem_eof_return(c_to_s_bio, -1);\n SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n BIO_up_ref(s_to_c_bio);\n BIO_up_ref(c_to_s_bio);\n SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n *sssl = serverssl;\n *cssl = clientssl;\n return 1;\n error:\n SSL_free(serverssl);\n SSL_free(clientssl);\n BIO_free(s_to_c_bio);\n BIO_free(c_to_s_bio);\n BIO_free(s_to_c_fbio);\n BIO_free(c_to_s_fbio);\n return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL)\n goto err;\n if (RAND_get_rand_method() == RAND_OpenSSL()) {\n s->drbg = RAND_DRBG_new(NID_aes_128_ctr, RAND_DRBG_FLAG_CTR_USE_DF,\n RAND_DRBG_get0_global());\n if (s->drbg == NULL\n || RAND_DRBG_instantiate(s->drbg, NULL, 0) == 0) {\n CRYPTO_THREAD_lock_free(s->lock);\n goto err;\n }\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->references = 1;\n s->max_early_data = ctx->max_early_data;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof s->sid_ctx))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n BIO_free_all(s->rbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n RAND_DRBG_free(s->drbg);\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return 1;\n } else\n return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret)\n SSL_SESSION_free(r);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return NULL;\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return ret;\n}'] |
35,020 | 0 | https://github.com/openssl/openssl/blob/54d00677f305375eee65a0c9edb5f0980c5f020f/crypto/bn/bn_lib.c/#L860 | int BN_is_odd(const BIGNUM *a)
{
return (a->top > 0) && (a->d[0] & 1);
} | ['int ec_GFp_simple_oct2point(const EC_GROUP *group, EC_POINT *point,\n const unsigned char *buf, size_t len, BN_CTX *ctx)\n{\n point_conversion_form_t form;\n int y_bit;\n BN_CTX *new_ctx = NULL;\n BIGNUM *x, *y;\n size_t field_len, enc_len;\n int ret = 0;\n if (len == 0) {\n ECerr(EC_F_EC_GFP_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_GFP_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_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n if (form == 0) {\n if (len != 1) {\n ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n return 0;\n }\n return EC_POINT_set_to_infinity(group, point);\n }\n field_len = BN_num_bytes(group->field);\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_GFP_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 if (y == 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_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n if (form == POINT_CONVERSION_COMPRESSED) {\n if (!EC_POINT_set_compressed_coordinates(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_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n if (form == POINT_CONVERSION_HYBRID) {\n if (y_bit != BN_is_odd(y)) {\n ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n goto err;\n }\n }\n if (!EC_POINT_set_affine_coordinates(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_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n return (a->top > 0) && (a->d[0] & 1);\n}'] |
35,021 | 0 | https://github.com/openssl/openssl/blob/b90506e995d44dee0ef4dd0324b56b59154256c2/ssl/packet.c/#L46 | int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
assert(pkt->subs != NULL && len != 0);
if (pkt->subs == NULL || len == 0)
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->buf->length - pkt->written < len) {
size_t newlen;
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;
}
*allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;
return 1;
} | ['int tls_construct_client_hello(SSL *s, WPACKET *pkt)\n{\n unsigned char *p;\n int i;\n int protverr;\n int al = SSL_AD_HANDSHAKE_FAILURE;\n#ifndef OPENSSL_NO_COMP\n SSL_COMP *comp;\n#endif\n SSL_SESSION *sess = s->session;\n if (!WPACKET_set_max_size(pkt, SSL3_RT_MAX_PLAIN_LENGTH)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n protverr = ssl_set_client_hello_version(s);\n if (protverr != 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, protverr);\n return 0;\n }\n if ((sess == NULL) || !ssl_version_supported(s, sess->ssl_version) ||\n (!sess->session_id_length && !sess->tlsext_tick) ||\n (sess->not_resumable)) {\n if (!ssl_get_new_session(s, 0))\n return 0;\n }\n p = s->s3->client_random;\n if (SSL_IS_DTLS(s)) {\n size_t idx;\n i = 1;\n for (idx = 0; idx < sizeof(s->s3->client_random); idx++) {\n if (p[idx]) {\n i = 0;\n break;\n }\n }\n } else\n i = 1;\n if (i && ssl_fill_hello_random(s, 0, p, sizeof(s->s3->client_random)) <= 0)\n return 0;\n if (!WPACKET_put_bytes_u16(pkt, s->client_version)\n || !WPACKET_memcpy(pkt, s->s3->client_random, SSL3_RANDOM_SIZE)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (s->new_session)\n i = 0;\n else\n i = s->session->session_id_length;\n if (i > (int)sizeof(s->session->session_id)\n || !WPACKET_start_sub_packet_u8(pkt)\n || (i != 0 && !WPACKET_memcpy(pkt, s->session->session_id, i))\n || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (SSL_IS_DTLS(s)) {\n if (s->d1->cookie_len > sizeof(s->d1->cookie)\n || !WPACKET_sub_memcpy_u8(pkt, s->d1->cookie,\n s->d1->cookie_len)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n if (!WPACKET_start_sub_packet_u16(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), pkt))\n return 0;\n if (!WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (!WPACKET_start_sub_packet_u8(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n#ifndef OPENSSL_NO_COMP\n if (ssl_allow_compression(s) && s->ctx->comp_methods) {\n int compnum = sk_SSL_COMP_num(s->ctx->comp_methods);\n for (i = 0; i < compnum; i++) {\n comp = sk_SSL_COMP_value(s->ctx->comp_methods, i);\n if (!WPACKET_put_bytes_u8(pkt, comp->id)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n }\n }\n#endif\n if (!WPACKET_put_bytes_u8(pkt, 0) || !WPACKET_close(pkt)) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (ssl_prepare_clienthello_tlsext(s) <= 0) {\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, SSL_R_CLIENTHELLO_TLSEXT);\n return 0;\n }\n if (!WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_set_flags(pkt, WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH)\n || !ssl_add_clienthello_tlsext(s, pkt, &al)\n || !WPACKET_close(pkt)) {\n ssl3_send_alert(s, SSL3_AL_FATAL, al);\n SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_HELLO, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n return 1;\n}', 'int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len)\n{\n unsigned char *dest;\n if (len == 0)\n return 1;\n if (!WPACKET_allocate_bytes(pkt, len, &dest))\n return 0;\n memcpy(dest, src, len);\n return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n assert(pkt->subs != NULL);\n if (pkt->subs == NULL)\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - (unsigned char *)pkt->buf->data;\n return 1;\n}', 'int WPACKET_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 assert(pkt->subs != NULL && len != 0);\n if (pkt->subs == NULL || len == 0)\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf->length - pkt->written < len) {\n size_t newlen;\n 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 *allocbytes = (unsigned char *)pkt->buf->data + pkt->curr;\n return 1;\n}'] |
35,022 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250 | int BN_num_bits(const BIGNUM *a)
{
int i = a->top - 1;
bn_check_top(a);
if (BN_is_zero(a)) return 0;
return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
} | ['static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)\n\t{\n\tBN_CTX *ctx;\n\tBIGNUM k,kq,*K,*kinv=NULL,*r=NULL;\n\tint ret=0;\n\tif (!dsa->p || !dsa->q || !dsa->g)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);\n\t\treturn 0;\n\t\t}\n\tBN_init(&k);\n\tBN_init(&kq);\n\tif (ctx_in == NULL)\n\t\t{\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\t\t}\n\telse\n\t\tctx=ctx_in;\n\tif ((r=BN_new()) == NULL) goto err;\n\tdo\n\t\tif (!BN_rand_range(&k, dsa->q)) goto err;\n\twhile (BN_is_zero(&k));\n\tif ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t{\n\t\tBN_set_flags(&k, BN_FLG_CONSTTIME);\n\t\t}\n\tif (dsa->flags & DSA_FLAG_CACHE_MONT_P)\n\t\t{\n\t\tif (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n\t\t\t\t\t\tCRYPTO_LOCK_DSA,\n\t\t\t\t\t\tdsa->p, ctx))\n\t\t\tgoto err;\n\t\t}\n\tif ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)\n\t\t{\n\t\tif (!BN_copy(&kq, &k)) goto err;\n\t\tif (!BN_add(&kq, &kq, dsa->q)) goto err;\n\t\tif (BN_num_bits(&kq) <= BN_num_bits(dsa->q))\n\t\t\t{\n\t\t\tif (!BN_add(&kq, &kq, dsa->q)) goto err;\n\t\t\t}\n\t\tK = &kq;\n\t\t}\n\telse\n\t\t{\n\t\tK = &k;\n\t\t}\n\tDSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx,\n\t\t\tdsa->method_mont_p);\n\tif (!BN_mod(r,r,dsa->q,ctx)) goto err;\n\tif ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;\n\tif (*kinvp != NULL) BN_clear_free(*kinvp);\n\t*kinvp=kinv;\n\tkinv=NULL;\n\tif (*rp != NULL) BN_clear_free(*rp);\n\t*rp=r;\n\tret=1;\nerr:\n\tif (!ret)\n\t\t{\n\t\tDSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);\n\t\tif (r != NULL)\n\t\t\tBN_clear_free(r);\n\t\t}\n\tif (ctx_in == NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&k);\n\tBN_clear_free(&kq);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *d,*r;\n\tconst BIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_MONT_CTX *mont=NULL;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\treturn BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\td = BN_CTX_get(ctx);\n\tr = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif (!d || !r || !val[0]) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_nnmod(val[0],a,m,ctx))\n\t\t\tgoto err;\n\t\taa= val[0];\n\t\t}\n\telse\n\t\taa=a;\n\tif (BN_is_zero(aa))\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\tif (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err;\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err;\n\t\tj=1<<(window-1);\n\t\tfor (i=1; i<j; i++)\n\t\t\t{\n\t\t\tif(((val[i] = BN_CTX_get(ctx)) == NULL) ||\n\t\t\t\t\t!BN_mod_mul_montgomery(val[i],val[i-1],\n\t\t\t\t\t\td,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tstart=1;\n\twvalue=0;\n\twstart=bits-1;\n\twend=0;\n\tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,bits,ret=0,idx,window,wvalue;\n\tsize_t top;\n \tBIGNUM *r;\n\tconst BIGNUM *aa;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tsize_t powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM *computeTemp=NULL, *am=NULL;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tr = BN_CTX_get(ctx);\n\tif (r == NULL) goto err;\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*top*numPowers;\n\tif ((powerbufFree=OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n \tif (!BN_to_montgomery(r,BN_value_one(),mont,ctx)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(r, top, powerbuf, 0, numPowers)) goto err;\n\tcomputeTemp = BN_CTX_get(ctx);\n\tam = BN_CTX_get(ctx);\n\tif (computeTemp==NULL || am==NULL) goto err;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(am,a,m,ctx))\n\t\t\tgoto err;\n\t\taa= am;\n\t\t}\n\telse\n\t\taa=a;\n\tif (!BN_to_montgomery(am,aa,mont,ctx)) goto err;\n\tif (!BN_copy(computeTemp, am)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tfor (i=2; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(computeTemp,am,computeTemp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(computeTemp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n \tbits = ((bits+window-1)/window)*window;\n \tidx=bits-1;\n \twhile (idx >= 0)\n \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,idx--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r,r,r,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,idx);\n \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(computeTemp, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(r,r,computeTemp,mont,ctx)) goto err;\n \t\t}\n\tif (!BN_from_montgomery(rr,r,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tOPENSSL_free(powerbufFree);\n\t\t}\n \tif (am!=NULL) BN_clear(am);\n \tif (computeTemp!=NULL) BN_clear(computeTemp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_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_copy(BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\ta->neg=b->neg;\n\tbn_check_top(a);\n\treturn(a);\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}'] |
35,023 | 0 | https://github.com/openssl/openssl/blob/54b5fd537f7a7ac1874359fd42a4721b6839f7a1/apps/apps.c/#L1470 | char *make_config_name()
{
const char *t=X509_get_default_cert_area();
size_t len;
char *p;
len=strlen(t)+strlen(OPENSSL_CONF)+2;
p=OPENSSL_malloc(len);
BUF_strlcpy(p,t,len);
#ifndef OPENSSL_SYS_VMS
BUF_strlcat(p,"/",len);
#endif
BUF_strlcat(p,OPENSSL_CONF,len);
return p;
} | ['char *make_config_name()\n\t{\n\tconst char *t=X509_get_default_cert_area();\n\tsize_t len;\n\tchar *p;\n\tlen=strlen(t)+strlen(OPENSSL_CONF)+2;\n\tp=OPENSSL_malloc(len);\n\tBUF_strlcpy(p,t,len);\n#ifndef OPENSSL_SYS_VMS\n\tBUF_strlcat(p,"/",len);\n#endif\n\tBUF_strlcat(p,OPENSSL_CONF,len);\n\treturn p;\n\t}', 'const char *X509_get_default_cert_area(void)\n\t{ return(X509_CERT_AREA); }', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'size_t BUF_strlcat(char *dst, const char *src, size_t size)\n\t{\n\tsize_t l = 0;\n\tfor(; size > 0 && *dst; size--, dst++)\n\t\tl++;\n\treturn l + BUF_strlcpy(dst, src, size);\n\t}'] |
35,024 | 0 | https://github.com/libav/libav/blob/89fa2b5616274194d90bde0aeebf6adbd1245193/libavcodec/vc1dec.c/#L3677 | static int vc1_decode_p_mb(VC1Context *v)
{
MpegEncContext *s = &v->s;
GetBitContext *gb = &s->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp;
int mqdiff, mquant;
int ttmb = v->ttfrm;
int mb_has_coeffs = 1;
int dmv_x, dmv_y;
int index, index1;
int val, sign;
int first_block = 1;
int dst_idx, off;
int skipped, fourmv;
int block_cbp = 0, pat, block_tt = 0, block_intra = 0;
mquant = v->pq;
if (v->mv_type_is_raw)
fourmv = get_bits1(gb);
else
fourmv = v->mv_type_mb_plane[mb_pos];
if (v->skip_is_raw)
skipped = get_bits1(gb);
else
skipped = v->s.mbskip_table[mb_pos];
if (!fourmv) {
if (!skipped) {
GET_MVDATA(dmv_x, dmv_y);
if (s->mb_intra) {
s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
}
s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
if (s->mb_intra && !mb_has_coeffs) {
GET_MQUANT();
s->ac_pred = get_bits1(gb);
cbp = 0;
} else if (mb_has_coeffs) {
if (s->mb_intra)
s->ac_pred = get_bits1(gb);
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
} else {
mquant = v->pq;
cbp = 0;
}
s->current_picture.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,
VC1_TTMB_VLC_BITS, 2);
if (!s->mb_intra) vc1_mc_1mv(v, 0);
dst_idx = 0;
for (i = 0; i < 6; i++) {
s->dc_val[0][s->block_index[i]] = 0;
dst_idx += i >> 2;
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
v->mb_type[0][s->block_index[i]] = s->mb_intra;
if (s->mb_intra) {
v->a_avail = v->c_avail = 0;
if (i == 2 || i == 3 || !s->first_slice_line)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
vc1_decode_intra_block(v, s->block[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
if (v->rangeredfrm)
for (j = 0; j < 64; j++)
s->block[i][j] <<= 1;
s->idsp.put_signed_pixels_clamped(s->block[i],
s->dest[dst_idx] + off,
i & 4 ? s->uvlinesize
: s->linesize);
if (v->pq >= 9 && v->overlap) {
if (v->c_avail)
v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
if (v->a_avail)
v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
}
block_cbp |= 0xF << (i << 2);
block_intra |= 1 << i;
} else if (val) {
pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block,
s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,
(i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
block_cbp |= pat << (i << 2);
if (!v->ttmbf && ttmb < 8)
ttmb = -1;
first_block = 0;
}
}
} else {
s->mb_intra = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
s->dc_val[0][s->block_index[i]] = 0;
}
s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
s->current_picture.qscale_table[mb_pos] = 0;
vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);
vc1_mc_1mv(v, 0);
}
} else {
if (!skipped ) {
int intra_count = 0, coded_inter = 0;
int is_intra[6], is_coded[6];
cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
val = ((cbp >> (5 - i)) & 1);
s->dc_val[0][s->block_index[i]] = 0;
s->mb_intra = 0;
if (i < 4) {
dmv_x = dmv_y = 0;
s->mb_intra = 0;
mb_has_coeffs = 0;
if (val) {
GET_MVDATA(dmv_x, dmv_y);
}
vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
if (!s->mb_intra)
vc1_mc_4mv_luma(v, i, 0, 0);
intra_count += s->mb_intra;
is_intra[i] = s->mb_intra;
is_coded[i] = mb_has_coeffs;
}
if (i & 4) {
is_intra[i] = (intra_count >= 3);
is_coded[i] = val;
}
if (i == 4)
vc1_mc_4mv_chroma(v, 0);
v->mb_type[0][s->block_index[i]] = is_intra[i];
if (!coded_inter)
coded_inter = !is_intra[i] && is_coded[i];
}
dst_idx = 0;
if (!intra_count && !coded_inter)
goto end;
GET_MQUANT();
s->current_picture.qscale_table[mb_pos] = mquant;
{
int intrapred = 0;
for (i = 0; i < 6; i++)
if (is_intra[i]) {
if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])
|| ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {
intrapred = 1;
break;
}
}
if (intrapred)
s->ac_pred = get_bits1(gb);
else
s->ac_pred = 0;
}
if (!v->ttmbf && coded_inter)
ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
dst_idx += i >> 2;
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
s->mb_intra = is_intra[i];
if (is_intra[i]) {
v->a_avail = v->c_avail = 0;
if (i == 2 || i == 3 || !s->first_slice_line)
v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[0][s->block_index[i] - 1];
vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant,
(i & 4) ? v->codingset2 : v->codingset);
if ((i>3) && (s->flags & CODEC_FLAG_GRAY))
continue;
v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
if (v->rangeredfrm)
for (j = 0; j < 64; j++)
s->block[i][j] <<= 1;
s->idsp.put_signed_pixels_clamped(s->block[i],
s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize
: s->linesize);
if (v->pq >= 9 && v->overlap) {
if (v->c_avail)
v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
if (v->a_avail)
v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);
}
block_cbp |= 0xF << (i << 2);
block_intra |= 1 << i;
} else if (is_coded[i]) {
pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
first_block, s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize : s->linesize,
(i & 4) && (s->flags & CODEC_FLAG_GRAY),
&block_tt);
block_cbp |= pat << (i << 2);
if (!v->ttmbf && ttmb < 8)
ttmb = -1;
first_block = 0;
}
}
} else {
s->mb_intra = 0;
s->current_picture.qscale_table[mb_pos] = 0;
for (i = 0; i < 6; i++) {
v->mb_type[0][s->block_index[i]] = 0;
s->dc_val[0][s->block_index[i]] = 0;
}
for (i = 0; i < 4; i++) {
vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
vc1_mc_4mv_luma(v, i, 0, 0);
}
vc1_mc_4mv_chroma(v, 0);
s->current_picture.qscale_table[mb_pos] = 0;
}
}
end:
v->cbp[s->mb_x] = block_cbp;
v->ttblk[s->mb_x] = block_tt;
v->is_intra[s->mb_x] = block_intra;
return 0;
} | ['static int vc1_decode_p_mb(VC1Context *v)\n{\n MpegEncContext *s = &v->s;\n GetBitContext *gb = &s->gb;\n int i, j;\n int mb_pos = s->mb_x + s->mb_y * s->mb_stride;\n int cbp;\n int mqdiff, mquant;\n int ttmb = v->ttfrm;\n int mb_has_coeffs = 1;\n int dmv_x, dmv_y;\n int index, index1;\n int val, sign;\n int first_block = 1;\n int dst_idx, off;\n int skipped, fourmv;\n int block_cbp = 0, pat, block_tt = 0, block_intra = 0;\n mquant = v->pq;\n if (v->mv_type_is_raw)\n fourmv = get_bits1(gb);\n else\n fourmv = v->mv_type_mb_plane[mb_pos];\n if (v->skip_is_raw)\n skipped = get_bits1(gb);\n else\n skipped = v->s.mbskip_table[mb_pos];\n if (!fourmv) {\n if (!skipped) {\n GET_MVDATA(dmv_x, dmv_y);\n if (s->mb_intra) {\n s->current_picture.motion_val[1][s->block_index[0]][0] = 0;\n s->current_picture.motion_val[1][s->block_index[0]][1] = 0;\n }\n s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;\n vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n if (s->mb_intra && !mb_has_coeffs) {\n GET_MQUANT();\n s->ac_pred = get_bits1(gb);\n cbp = 0;\n } else if (mb_has_coeffs) {\n if (s->mb_intra)\n s->ac_pred = get_bits1(gb);\n cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);\n GET_MQUANT();\n } else {\n mquant = v->pq;\n cbp = 0;\n }\n s->current_picture.qscale_table[mb_pos] = mquant;\n if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)\n ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table,\n VC1_TTMB_VLC_BITS, 2);\n if (!s->mb_intra) vc1_mc_1mv(v, 0);\n dst_idx = 0;\n for (i = 0; i < 6; i++) {\n s->dc_val[0][s->block_index[i]] = 0;\n dst_idx += i >> 2;\n val = ((cbp >> (5 - i)) & 1);\n off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);\n v->mb_type[0][s->block_index[i]] = s->mb_intra;\n if (s->mb_intra) {\n v->a_avail = v->c_avail = 0;\n if (i == 2 || i == 3 || !s->first_slice_line)\n v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];\n if (i == 1 || i == 3 || s->mb_x)\n v->c_avail = v->mb_type[0][s->block_index[i] - 1];\n vc1_decode_intra_block(v, s->block[i], i, val, mquant,\n (i & 4) ? v->codingset2 : v->codingset);\n if ((i>3) && (s->flags & CODEC_FLAG_GRAY))\n continue;\n v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);\n if (v->rangeredfrm)\n for (j = 0; j < 64; j++)\n s->block[i][j] <<= 1;\n s->idsp.put_signed_pixels_clamped(s->block[i],\n s->dest[dst_idx] + off,\n i & 4 ? s->uvlinesize\n : s->linesize);\n if (v->pq >= 9 && v->overlap) {\n if (v->c_avail)\n v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n if (v->a_avail)\n v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n }\n block_cbp |= 0xF << (i << 2);\n block_intra |= 1 << i;\n } else if (val) {\n pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block,\n s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize,\n (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);\n block_cbp |= pat << (i << 2);\n if (!v->ttmbf && ttmb < 8)\n ttmb = -1;\n first_block = 0;\n }\n }\n } else {\n s->mb_intra = 0;\n for (i = 0; i < 6; i++) {\n v->mb_type[0][s->block_index[i]] = 0;\n s->dc_val[0][s->block_index[i]] = 0;\n }\n s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;\n s->current_picture.qscale_table[mb_pos] = 0;\n vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n vc1_mc_1mv(v, 0);\n }\n } else {\n if (!skipped ) {\n int intra_count = 0, coded_inter = 0;\n int is_intra[6], is_coded[6];\n cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);\n for (i = 0; i < 6; i++) {\n val = ((cbp >> (5 - i)) & 1);\n s->dc_val[0][s->block_index[i]] = 0;\n s->mb_intra = 0;\n if (i < 4) {\n dmv_x = dmv_y = 0;\n s->mb_intra = 0;\n mb_has_coeffs = 0;\n if (val) {\n GET_MVDATA(dmv_x, dmv_y);\n }\n vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n if (!s->mb_intra)\n vc1_mc_4mv_luma(v, i, 0, 0);\n intra_count += s->mb_intra;\n is_intra[i] = s->mb_intra;\n is_coded[i] = mb_has_coeffs;\n }\n if (i & 4) {\n is_intra[i] = (intra_count >= 3);\n is_coded[i] = val;\n }\n if (i == 4)\n vc1_mc_4mv_chroma(v, 0);\n v->mb_type[0][s->block_index[i]] = is_intra[i];\n if (!coded_inter)\n coded_inter = !is_intra[i] && is_coded[i];\n }\n dst_idx = 0;\n if (!intra_count && !coded_inter)\n goto end;\n GET_MQUANT();\n s->current_picture.qscale_table[mb_pos] = mquant;\n {\n int intrapred = 0;\n for (i = 0; i < 6; i++)\n if (is_intra[i]) {\n if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]])\n || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) {\n intrapred = 1;\n break;\n }\n }\n if (intrapred)\n s->ac_pred = get_bits1(gb);\n else\n s->ac_pred = 0;\n }\n if (!v->ttmbf && coded_inter)\n ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);\n for (i = 0; i < 6; i++) {\n dst_idx += i >> 2;\n off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);\n s->mb_intra = is_intra[i];\n if (is_intra[i]) {\n v->a_avail = v->c_avail = 0;\n if (i == 2 || i == 3 || !s->first_slice_line)\n v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];\n if (i == 1 || i == 3 || s->mb_x)\n v->c_avail = v->mb_type[0][s->block_index[i] - 1];\n vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant,\n (i & 4) ? v->codingset2 : v->codingset);\n if ((i>3) && (s->flags & CODEC_FLAG_GRAY))\n continue;\n v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);\n if (v->rangeredfrm)\n for (j = 0; j < 64; j++)\n s->block[i][j] <<= 1;\n s->idsp.put_signed_pixels_clamped(s->block[i],\n s->dest[dst_idx] + off,\n (i & 4) ? s->uvlinesize\n : s->linesize);\n if (v->pq >= 9 && v->overlap) {\n if (v->c_avail)\n v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n if (v->a_avail)\n v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize);\n }\n block_cbp |= 0xF << (i << 2);\n block_intra |= 1 << i;\n } else if (is_coded[i]) {\n pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,\n first_block, s->dest[dst_idx] + off,\n (i & 4) ? s->uvlinesize : s->linesize,\n (i & 4) && (s->flags & CODEC_FLAG_GRAY),\n &block_tt);\n block_cbp |= pat << (i << 2);\n if (!v->ttmbf && ttmb < 8)\n ttmb = -1;\n first_block = 0;\n }\n }\n } else {\n s->mb_intra = 0;\n s->current_picture.qscale_table[mb_pos] = 0;\n for (i = 0; i < 6; i++) {\n v->mb_type[0][s->block_index[i]] = 0;\n s->dc_val[0][s->block_index[i]] = 0;\n }\n for (i = 0; i < 4; i++) {\n vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);\n vc1_mc_4mv_luma(v, i, 0, 0);\n }\n vc1_mc_4mv_chroma(v, 0);\n s->current_picture.qscale_table[mb_pos] = 0;\n }\n }\nend:\n v->cbp[s->mb_x] = block_cbp;\n v->ttblk[s->mb_x] = block_tt;\n v->is_intra[s->mb_x] = block_intra;\n return 0;\n}'] |
35,025 | 0 | https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavformat/avidec.c/#L896 | static int avi_read_idx1(AVFormatContext *s, int size)
{
AVIContext *avi = s->priv_data;
ByteIOContext *pb = s->pb;
int nb_index_entries, i;
AVStream *st;
AVIStream *ast;
unsigned int index, tag, flags, pos, len;
unsigned last_pos= -1;
nb_index_entries = size / 16;
if (nb_index_entries <= 0)
return -1;
for(i = 0; i < nb_index_entries; i++) {
tag = get_le32(pb);
flags = get_le32(pb);
pos = get_le32(pb);
len = get_le32(pb);
#if defined(DEBUG_SEEK)
av_log(NULL, AV_LOG_DEBUG, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",
i, tag, flags, pos, len);
#endif
if(i==0 && pos > avi->movi_list)
avi->movi_list= 0;
pos += avi->movi_list;
index = ((tag & 0xff) - '0') * 10;
index += ((tag >> 8) & 0xff) - '0';
if (index >= s->nb_streams)
continue;
st = s->streams[index];
ast = st->priv_data;
#if defined(DEBUG_SEEK)
av_log(NULL, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\n", len, ast->cum_len);
#endif
if(last_pos == pos)
avi->non_interleaved= 1;
else
av_add_index_entry(st, pos, ast->cum_len / FFMAX(1, ast->sample_size), len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);
if(ast->sample_size)
ast->cum_len += len;
else
ast->cum_len ++;
last_pos= pos;
}
return 0;
} | ['static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)\n{\n AVIContext *avi = s->priv_data;\n ByteIOContext *pb = s->pb;\n uint32_t tag, tag1, handler;\n int codec_type, stream_index, frame_period, bit_rate;\n unsigned int size, nb_frames;\n int i;\n AVStream *st;\n AVIStream *ast = NULL;\n char str_track[4];\n int avih_width=0, avih_height=0;\n int amv_file_format=0;\n avi->stream_index= -1;\n if (get_riff(avi, pb) < 0)\n return -1;\n avi->fsize = url_fsize(pb);\n if(avi->fsize<=0)\n avi->fsize= avi->riff_end;\n stream_index = -1;\n codec_type = -1;\n frame_period = 0;\n for(;;) {\n if (url_feof(pb))\n goto fail;\n tag = get_le32(pb);\n size = get_le32(pb);\n#ifdef DEBUG\n print_tag("tag", tag, size);\n#endif\n switch(tag) {\n case MKTAG(\'L\', \'I\', \'S\', \'T\'):\n tag1 = get_le32(pb);\n#ifdef DEBUG\n print_tag("list", tag1, 0);\n#endif\n if (tag1 == MKTAG(\'m\', \'o\', \'v\', \'i\')) {\n avi->movi_list = url_ftell(pb) - 4;\n if(size) avi->movi_end = avi->movi_list + size + (size & 1);\n else avi->movi_end = url_fsize(pb);\n#ifdef DEBUG\n printf("movi end=%"PRIx64"\\n", avi->movi_end);\n#endif\n goto end_of_header;\n }\n break;\n case MKTAG(\'d\', \'m\', \'l\', \'h\'):\n avi->is_odml = 1;\n url_fskip(pb, size + (size & 1));\n break;\n case MKTAG(\'a\', \'m\', \'v\', \'h\'):\n amv_file_format=1;\n case MKTAG(\'a\', \'v\', \'i\', \'h\'):\n frame_period = get_le32(pb);\n bit_rate = get_le32(pb) * 8;\n get_le32(pb);\n avi->non_interleaved |= get_le32(pb) & AVIF_MUSTUSEINDEX;\n url_fskip(pb, 2 * 4);\n get_le32(pb);\n get_le32(pb);\n avih_width=get_le32(pb);\n avih_height=get_le32(pb);\n url_fskip(pb, size - 10 * 4);\n break;\n case MKTAG(\'s\', \'t\', \'r\', \'h\'):\n tag1 = get_le32(pb);\n handler = get_le32(pb);\n if(tag1 == MKTAG(\'p\', \'a\', \'d\', \'s\')){\n url_fskip(pb, size - 8);\n break;\n }else{\n stream_index++;\n st = av_new_stream(s, stream_index);\n if (!st)\n goto fail;\n ast = av_mallocz(sizeof(AVIStream));\n if (!ast)\n goto fail;\n st->priv_data = ast;\n }\n if(amv_file_format)\n tag1 = stream_index ? MKTAG(\'a\',\'u\',\'d\',\'s\') : MKTAG(\'v\',\'i\',\'d\',\'s\');\n#ifdef DEBUG\n print_tag("strh", tag1, -1);\n#endif\n if(tag1 == MKTAG(\'i\', \'a\', \'v\', \'s\') || tag1 == MKTAG(\'i\', \'v\', \'a\', \'s\')){\n int64_t dv_dur;\n if (s->nb_streams != 1)\n goto fail;\n if (handler != MKTAG(\'d\', \'v\', \'s\', \'d\') &&\n handler != MKTAG(\'d\', \'v\', \'h\', \'d\') &&\n handler != MKTAG(\'d\', \'v\', \'s\', \'l\'))\n goto fail;\n ast = s->streams[0]->priv_data;\n av_freep(&s->streams[0]->codec->extradata);\n av_freep(&s->streams[0]);\n s->nb_streams = 0;\n if (ENABLE_DV_DEMUXER) {\n avi->dv_demux = dv_init_demux(s);\n if (!avi->dv_demux)\n goto fail;\n }\n s->streams[0]->priv_data = ast;\n url_fskip(pb, 3 * 4);\n ast->scale = get_le32(pb);\n ast->rate = get_le32(pb);\n url_fskip(pb, 4);\n dv_dur = get_le32(pb);\n if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) {\n dv_dur *= AV_TIME_BASE;\n s->duration = av_rescale(dv_dur, ast->scale, ast->rate);\n }\n stream_index = s->nb_streams - 1;\n url_fskip(pb, size - 9*4);\n break;\n }\n assert(stream_index < s->nb_streams);\n st->codec->stream_codec_tag= handler;\n get_le32(pb);\n get_le16(pb);\n get_le16(pb);\n get_le32(pb);\n ast->scale = get_le32(pb);\n ast->rate = get_le32(pb);\n if(!(ast->scale && ast->rate)){\n av_log(s, AV_LOG_WARNING, "scale/rate is %u/%u which is invalid. (This file has been generated by broken software.)\\n", ast->scale, ast->rate);\n if(frame_period){\n ast->rate = 1000000;\n ast->scale = frame_period;\n }else{\n ast->rate = 25;\n ast->scale = 1;\n }\n }\n av_set_pts_info(st, 64, ast->scale, ast->rate);\n ast->cum_len=get_le32(pb);\n nb_frames = get_le32(pb);\n st->start_time = 0;\n st->duration = nb_frames;\n get_le32(pb);\n get_le32(pb);\n ast->sample_size = get_le32(pb);\n ast->cum_len *= FFMAX(1, ast->sample_size);\n switch(tag1) {\n case MKTAG(\'v\', \'i\', \'d\', \'s\'):\n codec_type = CODEC_TYPE_VIDEO;\n ast->sample_size = 0;\n break;\n case MKTAG(\'a\', \'u\', \'d\', \'s\'):\n codec_type = CODEC_TYPE_AUDIO;\n break;\n case MKTAG(\'t\', \'x\', \'t\', \'s\'):\n codec_type = CODEC_TYPE_DATA;\n break;\n case MKTAG(\'d\', \'a\', \'t\', \'s\'):\n codec_type = CODEC_TYPE_DATA;\n break;\n default:\n av_log(s, AV_LOG_ERROR, "unknown stream type %X\\n", tag1);\n goto fail;\n }\n ast->frame_offset= ast->cum_len;\n url_fskip(pb, size - 12 * 4);\n break;\n case MKTAG(\'s\', \'t\', \'r\', \'f\'):\n if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) {\n url_fskip(pb, size);\n } else {\n st = s->streams[stream_index];\n switch(codec_type) {\n case CODEC_TYPE_VIDEO:\n if(amv_file_format){\n st->codec->width=avih_width;\n st->codec->height=avih_height;\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_id = CODEC_ID_AMV;\n url_fskip(pb, size);\n break;\n }\n get_le32(pb);\n st->codec->width = get_le32(pb);\n st->codec->height = get_le32(pb);\n get_le16(pb);\n st->codec->bits_per_sample= get_le16(pb);\n tag1 = get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n if (tag1 == MKTAG(\'D\', \'X\', \'S\', \'B\')) {\n st->codec->codec_type = CODEC_TYPE_SUBTITLE;\n st->codec->codec_tag = tag1;\n st->codec->codec_id = CODEC_ID_XSUB;\n break;\n }\n if(size > 10*4 && size<(1<<30)){\n st->codec->extradata_size= size - 10*4;\n st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);\n get_buffer(pb, st->codec->extradata, st->codec->extradata_size);\n }\n if(st->codec->extradata_size & 1)\n get_byte(pb);\n if (st->codec->extradata_size && (st->codec->bits_per_sample <= 8)) {\n st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl));\n#ifdef WORDS_BIGENDIAN\n for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)\n st->codec->palctrl->palette[i] = bswap_32(((uint32_t*)st->codec->extradata)[i]);\n#else\n memcpy(st->codec->palctrl->palette, st->codec->extradata,\n FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));\n#endif\n st->codec->palctrl->palette_changed = 1;\n }\n#ifdef DEBUG\n print_tag("video", tag1, 0);\n#endif\n st->codec->codec_type = CODEC_TYPE_VIDEO;\n st->codec->codec_tag = tag1;\n st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1);\n st->need_parsing = AVSTREAM_PARSE_HEADERS;\n break;\n case CODEC_TYPE_AUDIO:\n get_wav_header(pb, st->codec, size);\n if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){\n av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\\n", ast->sample_size, st->codec->block_align);\n ast->sample_size= st->codec->block_align;\n }\n if (size%2)\n url_fskip(pb, 1);\n st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS;\n if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size)\n st->need_parsing = AVSTREAM_PARSE_NONE;\n if (st->codec->stream_codec_tag == ff_get_fourcc("Axan")){\n st->codec->codec_id = CODEC_ID_XAN_DPCM;\n st->codec->codec_tag = 0;\n }\n if (amv_file_format)\n st->codec->codec_id = CODEC_ID_ADPCM_IMA_AMV;\n break;\n default:\n st->codec->codec_type = CODEC_TYPE_DATA;\n st->codec->codec_id= CODEC_ID_NONE;\n st->codec->codec_tag= 0;\n url_fskip(pb, size);\n break;\n }\n }\n break;\n case MKTAG(\'i\', \'n\', \'d\', \'x\'):\n i= url_ftell(pb);\n if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){\n read_braindead_odml_indx(s, 0);\n }\n url_fseek(pb, i+size, SEEK_SET);\n break;\n case MKTAG(\'v\', \'p\', \'r\', \'p\'):\n if(stream_index < (unsigned)s->nb_streams && size > 9*4){\n AVRational active, active_aspect;\n st = s->streams[stream_index];\n get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n get_le32(pb);\n active_aspect.den= get_le16(pb);\n active_aspect.num= get_le16(pb);\n active.num = get_le32(pb);\n active.den = get_le32(pb);\n get_le32(pb);\n if(active_aspect.num && active_aspect.den && active.num && active.den){\n st->codec->sample_aspect_ratio= av_div_q(active_aspect, active);\n }\n size -= 9*4;\n }\n url_fseek(pb, size, SEEK_CUR);\n break;\n case MKTAG(\'I\', \'N\', \'A\', \'M\'):\n avi_read_tag(pb, s->title, sizeof(s->title), size);\n break;\n case MKTAG(\'I\', \'A\', \'R\', \'T\'):\n avi_read_tag(pb, s->author, sizeof(s->author), size);\n break;\n case MKTAG(\'I\', \'C\', \'O\', \'P\'):\n avi_read_tag(pb, s->copyright, sizeof(s->copyright), size);\n break;\n case MKTAG(\'I\', \'C\', \'M\', \'T\'):\n avi_read_tag(pb, s->comment, sizeof(s->comment), size);\n break;\n case MKTAG(\'I\', \'G\', \'N\', \'R\'):\n avi_read_tag(pb, s->genre, sizeof(s->genre), size);\n break;\n case MKTAG(\'I\', \'P\', \'R\', \'D\'):\n avi_read_tag(pb, s->album, sizeof(s->album), size);\n break;\n case MKTAG(\'I\', \'P\', \'R\', \'T\'):\n avi_read_tag(pb, str_track, sizeof(str_track), size);\n sscanf(str_track, "%d", &s->track);\n break;\n default:\n if(size > 1000000){\n av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, "\n "I will ignore it and try to continue anyway.\\n");\n avi->movi_list = url_ftell(pb) - 4;\n avi->movi_end = url_fsize(pb);\n goto end_of_header;\n }\n size += (size & 1);\n url_fskip(pb, size);\n break;\n }\n }\n end_of_header:\n if (stream_index != s->nb_streams - 1) {\n fail:\n return -1;\n }\n if(!avi->index_loaded && !url_is_streamed(pb))\n avi_load_index(s);\n avi->index_loaded = 1;\n avi->non_interleaved |= guess_ni_flag(s);\n if(avi->non_interleaved) {\n av_log(s, AV_LOG_INFO, "non-interleaved AVI\\n");\n clean_index(s);\n }\n return 0;\n}', 'static int avi_load_index(AVFormatContext *s)\n{\n AVIContext *avi = s->priv_data;\n ByteIOContext *pb = s->pb;\n uint32_t tag, size;\n offset_t pos= url_ftell(pb);\n url_fseek(pb, avi->movi_end, SEEK_SET);\n#ifdef DEBUG_SEEK\n printf("movi_end=0x%"PRIx64"\\n", avi->movi_end);\n#endif\n for(;;) {\n if (url_feof(pb))\n break;\n tag = get_le32(pb);\n size = get_le32(pb);\n#ifdef DEBUG_SEEK\n printf("tag=%c%c%c%c size=0x%x\\n",\n tag & 0xff,\n (tag >> 8) & 0xff,\n (tag >> 16) & 0xff,\n (tag >> 24) & 0xff,\n size);\n#endif\n switch(tag) {\n case MKTAG(\'i\', \'d\', \'x\', \'1\'):\n if (avi_read_idx1(s, size) < 0)\n goto skip;\n else\n goto the_end;\n break;\n default:\n skip:\n size += (size & 1);\n url_fskip(pb, size);\n break;\n }\n }\n the_end:\n url_fseek(pb, pos, SEEK_SET);\n return 0;\n}', 'static int avi_read_idx1(AVFormatContext *s, int size)\n{\n AVIContext *avi = s->priv_data;\n ByteIOContext *pb = s->pb;\n int nb_index_entries, i;\n AVStream *st;\n AVIStream *ast;\n unsigned int index, tag, flags, pos, len;\n unsigned last_pos= -1;\n nb_index_entries = size / 16;\n if (nb_index_entries <= 0)\n return -1;\n for(i = 0; i < nb_index_entries; i++) {\n tag = get_le32(pb);\n flags = get_le32(pb);\n pos = get_le32(pb);\n len = get_le32(pb);\n#if defined(DEBUG_SEEK)\n av_log(NULL, AV_LOG_DEBUG, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/",\n i, tag, flags, pos, len);\n#endif\n if(i==0 && pos > avi->movi_list)\n avi->movi_list= 0;\n pos += avi->movi_list;\n index = ((tag & 0xff) - \'0\') * 10;\n index += ((tag >> 8) & 0xff) - \'0\';\n if (index >= s->nb_streams)\n continue;\n st = s->streams[index];\n ast = st->priv_data;\n#if defined(DEBUG_SEEK)\n av_log(NULL, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\\n", len, ast->cum_len);\n#endif\n if(last_pos == pos)\n avi->non_interleaved= 1;\n else\n av_add_index_entry(st, pos, ast->cum_len / FFMAX(1, ast->sample_size), len, 0, (flags&AVIIF_INDEX) ? AVINDEX_KEYFRAME : 0);\n if(ast->sample_size)\n ast->cum_len += len;\n else\n ast->cum_len ++;\n last_pos= pos;\n }\n return 0;\n}'] |
35,026 | 0 | https://github.com/openssl/openssl/blob/4718f449a3ecd5efac62b22d0fa9a759a7895dbc/test/handshake_helper.c/#L117 | static int select_server_ctx(SSL *s, void *arg, int ignore)
{
const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
HANDSHAKE_EX_DATA *ex_data =
(HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));
if (servername == NULL) {
ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
return SSL_TLSEXT_ERR_NOACK;
}
if (strcmp(servername, "server2") == 0) {
SSL_CTX *new_ctx = (SSL_CTX*)arg;
SSL_set_SSL_CTX(s, new_ctx);
SSL_clear_options(s, 0xFFFFFFFFL);
SSL_set_options(s, SSL_CTX_get_options(new_ctx));
ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;
return SSL_TLSEXT_ERR_OK;
} else if (strcmp(servername, "server1") == 0) {
ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
return SSL_TLSEXT_ERR_OK;
} else if (ignore) {
ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;
return SSL_TLSEXT_ERR_NOACK;
} else {
return SSL_TLSEXT_ERR_ALERT_FATAL;
}
} | ['static int select_server_ctx(SSL *s, void *arg, int ignore)\n{\n const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);\n HANDSHAKE_EX_DATA *ex_data =\n (HANDSHAKE_EX_DATA*)(SSL_get_ex_data(s, ex_data_idx));\n if (servername == NULL) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n }\n if (strcmp(servername, "server2") == 0) {\n SSL_CTX *new_ctx = (SSL_CTX*)arg;\n SSL_set_SSL_CTX(s, new_ctx);\n SSL_clear_options(s, 0xFFFFFFFFL);\n SSL_set_options(s, SSL_CTX_get_options(new_ctx));\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER2;\n return SSL_TLSEXT_ERR_OK;\n } else if (strcmp(servername, "server1") == 0) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_OK;\n } else if (ignore) {\n ex_data->servername = SSL_TEST_SERVERNAME_SERVER1;\n return SSL_TLSEXT_ERR_NOACK;\n } else {\n return SSL_TLSEXT_ERR_ALERT_FATAL;\n }\n}', 'const char *SSL_get_servername(const SSL *s, const int type)\n{\n if (type != TLSEXT_NAMETYPE_host_name)\n return NULL;\n return s->session && !s->ext.hostname ?\n s->session->ext.hostname : s->ext.hostname;\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}'] |
35,027 | 0 | https://github.com/openssl/openssl/blob/260a16f33682a819414fcba6161708a5e6bdff50/crypto/lhash/lhash.c/#L157 | void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return NULL;
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return ret;
} | ['static int test_max_fragment_len_ext(int idx_tst)\n{\n SSL_CTX *ctx;\n SSL *con = NULL;\n int testresult = 0, MFL_mode = 0;\n BIO *rbio, *wbio;\n ctx = SSL_CTX_new(TLS_method());\n if (!TEST_ptr(ctx))\n goto end;\n if (!TEST_true(SSL_CTX_set_tlsext_max_fragment_length(\n ctx, max_fragment_len_test[idx_tst])))\n goto end;\n con = SSL_new(ctx);\n if (!TEST_ptr(con))\n goto end;\n rbio = BIO_new(BIO_s_mem());\n wbio = BIO_new(BIO_s_mem());\n if (!TEST_ptr(rbio)|| !TEST_ptr(wbio)) {\n BIO_free(rbio);\n BIO_free(wbio);\n goto end;\n }\n SSL_set_bio(con, rbio, wbio);\n SSL_set_connect_state(con);\n if (!TEST_int_le(SSL_connect(con), 0)) {\n goto end;\n }\n if (!TEST_true(get_MFL_from_client_hello(wbio, &MFL_mode)))\n goto end;\n if (!TEST_true(max_fragment_len_test[idx_tst] == MFL_mode))\n goto end;\n testresult = 1;\nend:\n SSL_free(con);\n SSL_CTX_free(ctx);\n return testresult;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return NULL;\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return NULL;\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->references = 1;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n OPENSSL_free(s);\n s = NULL;\n goto err;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->dane.flags = ctx->dane.flags;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->max_early_data = ctx->max_early_data;\n s->recv_max_early_data = ctx->recv_max_early_data;\n s->num_tickets = ctx->num_tickets;\n s->pha_enabled = ctx->pha_enabled;\n s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n if (s->tls13_ciphersuites == NULL)\n goto err;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->record_padding_cb = ctx->record_padding_cb;\n s->record_padding_arg = ctx->record_padding_arg;\n s->block_padding = ctx->block_padding;\n s->sid_ctx_length = ctx->sid_ctx_length;\n if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n goto err;\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->ext.debug_cb = 0;\n s->ext.debug_arg = NULL;\n s->ext.ticket_expected = 0;\n s->ext.status_type = ctx->ext.status_type;\n s->ext.status_expected = 0;\n s->ext.ocsp.ids = NULL;\n s->ext.ocsp.exts = NULL;\n s->ext.ocsp.resp = NULL;\n s->ext.ocsp.resp_len = 0;\n SSL_CTX_up_ref(ctx);\n s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n if (ctx->ext.ecpointformats) {\n s->ext.ecpointformats =\n OPENSSL_memdup(ctx->ext.ecpointformats,\n ctx->ext.ecpointformats_len);\n if (!s->ext.ecpointformats)\n goto err;\n s->ext.ecpointformats_len =\n ctx->ext.ecpointformats_len;\n }\n if (ctx->ext.supportedgroups) {\n s->ext.supportedgroups =\n OPENSSL_memdup(ctx->ext.supportedgroups,\n ctx->ext.supportedgroups_len\n * sizeof(*ctx->ext.supportedgroups));\n if (!s->ext.supportedgroups)\n goto err;\n s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n s->ext.npn = NULL;\n#endif\n if (s->ctx->ext.alpn) {\n s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n if (s->ext.alpn == NULL)\n goto err;\n memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n s->ext.alpn_len = s->ctx->ext.alpn_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n s->key_update = SSL_KEY_UPDATE_NONE;\n s->allow_early_data_cb = ctx->allow_early_data_cb;\n s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->async_cb = ctx->async_cb;\n s->async_cb_arg = ctx->async_cb_arg;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n RECORD_LAYER_release(&s->rlayer);\n ssl_free_wbio_buffer(s);\n BIO_free_all(s->wbio);\n s->wbio = NULL;\n BIO_free_all(s->rbio);\n s->rbio = NULL;\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n sk_SSL_CIPHER_free(s->tls13_ciphersuites);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n SSL_SESSION_free(s->psksession);\n OPENSSL_free(s->psksession_id);\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->ext.hostname);\n SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->ext.ecpointformats);\n OPENSSL_free(s->ext.supportedgroups);\n#endif\n sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->ext.scts);\n#endif\n OPENSSL_free(s->ext.ocsp.resp);\n OPENSSL_free(s->ext.alpn);\n OPENSSL_free(s->ext.tls13_cookie);\n OPENSSL_free(s->clienthello);\n OPENSSL_free(s->pha_context);\n EVP_MD_CTX_free(s->pha_dgst);\n sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n sk_X509_NAME_pop_free(s->client_ca_names, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return 1;\n } else\n return 0;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) != NULL) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, r);\n SSL_SESSION_list_remove(ctx, r);\n }\n c->not_resumable = 1;\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, c);\n if (ret)\n SSL_SESSION_free(r);\n } else\n ret = 0;\n return ret;\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return NULL;\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return ret;\n}'] |
35,028 | 0 | https://github.com/libav/libav/blob/32a15a2441c4bfc83b2934f617d64d196492bdde/libavfilter/vf_pad.c/#L233 | static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int w, int h)
{
PadContext *pad = inlink->dst->priv;
AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0], perms,
w + (pad->w - pad->in_w),
h + (pad->h - pad->in_h));
int plane;
for (plane = 0; plane < 4 && picref->data[plane]; plane++) {
int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0;
int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0;
picref->data[plane] += (pad->x >> hsub) * pad->line_step[plane] +
(pad->y >> vsub) * picref->linesize[plane];
}
return picref;
} | ['static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int w, int h)\n{\n PadContext *pad = inlink->dst->priv;\n AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0], perms,\n w + (pad->w - pad->in_w),\n h + (pad->h - pad->in_h));\n int plane;\n for (plane = 0; plane < 4 && picref->data[plane]; plane++) {\n int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0;\n int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0;\n picref->data[plane] += (pad->x >> hsub) * pad->line_step[plane] +\n (pad->y >> vsub) * picref->linesize[plane];\n }\n return picref;\n}', 'AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)\n{\n AVFilterBufferRef *ret = NULL;\n FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " perms:%d w:%d h:%d\\n", perms, w, h);\n if(link_dpad(link).get_video_buffer)\n ret = link_dpad(link).get_video_buffer(link, perms, w, h);\n if(!ret)\n ret = avfilter_default_get_video_buffer(link, perms, w, h);\n if (ret)\n ret->type = AVMEDIA_TYPE_VIDEO;\n FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " returning "); ff_dprintf_picref(NULL, ret, 1);\n return ret;\n}', 'void ff_dprintf_link(void *ctx, AVFilterLink *link, int end)\n{\n dprintf(ctx,\n "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",\n link, link->w, link->h,\n av_pix_fmt_descriptors[link->format].name,\n link->src ? link->src->filter->name : "",\n link->dst ? link->dst->filter->name : "",\n end ? "\\n" : "");\n}', 'void ff_dprintf_picref(void *ctx, AVFilterBufferRef *picref, int end)\n{\n dprintf(ctx,\n "picref[%p data[%p, %p, %p, %p] linesize[%d, %d, %d, %d] pts:%"PRId64" pos:%"PRId64" a:%d/%d s:%dx%d]%s",\n picref,\n picref->data [0], picref->data [1], picref->data [2], picref->data [3],\n picref->linesize[0], picref->linesize[1], picref->linesize[2], picref->linesize[3],\n picref->pts, picref->pos,\n picref->video->pixel_aspect.num, picref->video->pixel_aspect.den, picref->video->w, picref->video->h,\n end ? "\\n" : "");\n}'] |
35,029 | 0 | https://github.com/libav/libav/blob/a2fb4bcb0189f6421608e0dec1a38c65910763f6/libavcodec/wmavoice.c/#L835 | static void dequant_lsps(double *lsps, int num,
const uint16_t *values,
const uint16_t *sizes,
int n_stages, const uint8_t *table,
const double *mul_q,
const double *base_q)
{
int n, m;
memset(lsps, 0, num * sizeof(*lsps));
for (n = 0; n < n_stages; n++) {
const uint8_t *t_off = &table[values[n] * num];
double base = base_q[n], mul = mul_q[n];
for (m = 0; m < num; m++)
lsps[m] += base + mul * t_off[m];
table += sizes[n] * num;
}
} | ['static int synth_superframe(AVCodecContext *ctx, int *got_frame_ptr)\n{\n WMAVoiceContext *s = ctx->priv_data;\n GetBitContext *gb = &s->gb, s_gb;\n int n, res, n_samples = 480;\n double lsps[MAX_FRAMES][MAX_LSPS];\n const double *mean_lsf = s->lsps == 16 ?\n wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode];\n float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12];\n float synth[MAX_LSPS + MAX_SFRAMESIZE];\n float *samples;\n memcpy(synth, s->synth_history,\n s->lsps * sizeof(*synth));\n memcpy(excitation, s->excitation_history,\n s->history_nsamples * sizeof(*excitation));\n if (s->sframe_cache_size > 0) {\n gb = &s_gb;\n init_get_bits(gb, s->sframe_cache, s->sframe_cache_size);\n s->sframe_cache_size = 0;\n }\n if ((res = check_bits_for_superframe(gb, s)) == 1) {\n *got_frame_ptr = 0;\n return 1;\n }\n if (!get_bits1(gb)) {\n av_log_missing_feature(ctx, "WMAPro-in-WMAVoice support", 1);\n return -1;\n }\n if (get_bits1(gb)) {\n if ((n_samples = get_bits(gb, 12)) > 480) {\n av_log(ctx, AV_LOG_ERROR,\n "Superframe encodes >480 samples (%d), not allowed\\n",\n n_samples);\n return -1;\n }\n }\n if (s->has_residual_lsps) {\n double prev_lsps[MAX_LSPS], a1[MAX_LSPS * 2], a2[MAX_LSPS * 2];\n for (n = 0; n < s->lsps; n++)\n prev_lsps[n] = s->prev_lsps[n] - mean_lsf[n];\n if (s->lsps == 10) {\n dequant_lsp10r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);\n } else\n dequant_lsp16r(gb, lsps[2], prev_lsps, a1, a2, s->lsp_q_mode);\n for (n = 0; n < s->lsps; n++) {\n lsps[0][n] = mean_lsf[n] + (a1[n] - a2[n * 2]);\n lsps[1][n] = mean_lsf[n] + (a1[s->lsps + n] - a2[n * 2 + 1]);\n lsps[2][n] += mean_lsf[n];\n }\n for (n = 0; n < 3; n++)\n stabilize_lsps(lsps[n], s->lsps);\n }\n s->frame.nb_samples = 480;\n if ((res = ctx->get_buffer(ctx, &s->frame)) < 0) {\n av_log(ctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return res;\n }\n s->frame.nb_samples = n_samples;\n samples = (float *)s->frame.data[0];\n for (n = 0; n < 3; n++) {\n if (!s->has_residual_lsps) {\n int m;\n if (s->lsps == 10) {\n dequant_lsp10i(gb, lsps[n]);\n } else\n dequant_lsp16i(gb, lsps[n]);\n for (m = 0; m < s->lsps; m++)\n lsps[n][m] += mean_lsf[m];\n stabilize_lsps(lsps[n], s->lsps);\n }\n if ((res = synth_frame(ctx, gb, n,\n &samples[n * MAX_FRAMESIZE],\n lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1],\n &excitation[s->history_nsamples + n * MAX_FRAMESIZE],\n &synth[s->lsps + n * MAX_FRAMESIZE]))) {\n *got_frame_ptr = 0;\n return res;\n }\n }\n if (get_bits1(gb)) {\n res = get_bits(gb, 4);\n skip_bits(gb, 10 * (res + 1));\n }\n *got_frame_ptr = 1;\n memcpy(s->prev_lsps, lsps[2],\n s->lsps * sizeof(*s->prev_lsps));\n memcpy(s->synth_history, &synth[MAX_SFRAMESIZE],\n s->lsps * sizeof(*synth));\n memcpy(s->excitation_history, &excitation[MAX_SFRAMESIZE],\n s->history_nsamples * sizeof(*excitation));\n if (s->do_apf)\n memmove(s->zero_exc_pf, &s->zero_exc_pf[MAX_SFRAMESIZE],\n s->history_nsamples * sizeof(*s->zero_exc_pf));\n return 0;\n}', 'static void dequant_lsp16r(GetBitContext *gb,\n double *i_lsps, const double *old,\n double *a1, double *a2, int q_mode)\n{\n static const uint16_t vec_sizes[3] = { 128, 128, 128 };\n static const double mul_lsf[3] = {\n 1.2232979501e-3, 1.4062241527e-3, 1.6114744851e-3\n };\n static const double base_lsf[3] = {\n M_PI * -5.5830e-2, M_PI * -5.2908e-2, M_PI * -5.4776e-2\n };\n const float (*ipol_tab)[2][16] = q_mode ?\n wmavoice_lsp16_intercoeff_b : wmavoice_lsp16_intercoeff_a;\n uint16_t interpol, v[3];\n int n;\n dequant_lsp16i(gb, i_lsps);\n interpol = get_bits(gb, 5);\n v[0] = get_bits(gb, 7);\n v[1] = get_bits(gb, 7);\n v[2] = get_bits(gb, 7);\n for (n = 0; n < 16; n++) {\n double delta = old[n] - i_lsps[n];\n a1[n] = ipol_tab[interpol][0][n] * delta + i_lsps[n];\n a1[16 + n] = ipol_tab[interpol][1][n] * delta + i_lsps[n];\n }\n dequant_lsps( a2, 10, v, vec_sizes, 1,\n wmavoice_dq_lsp16r1, mul_lsf, base_lsf);\n dequant_lsps(&a2[10], 10, &v[1], &vec_sizes[1], 1,\n wmavoice_dq_lsp16r2, &mul_lsf[1], &base_lsf[1]);\n dequant_lsps(&a2[20], 12, &v[2], &vec_sizes[2], 1,\n wmavoice_dq_lsp16r3, &mul_lsf[2], &base_lsf[2]);\n}', 'static void dequant_lsp16i(GetBitContext *gb, double *lsps)\n{\n static const uint16_t vec_sizes[5] = { 256, 64, 128, 64, 128 };\n static const double mul_lsf[5] = {\n 3.3439586280e-3, 6.9908173703e-4,\n 3.3216608306e-3, 1.0334960326e-3,\n 3.1899104283e-3\n };\n static const double base_lsf[5] = {\n M_PI * -1.27576e-1, M_PI * -2.4292e-2,\n M_PI * -1.28094e-1, M_PI * -3.2128e-2,\n M_PI * -1.29816e-1\n };\n uint16_t v[5];\n v[0] = get_bits(gb, 8);\n v[1] = get_bits(gb, 6);\n v[2] = get_bits(gb, 7);\n v[3] = get_bits(gb, 6);\n v[4] = get_bits(gb, 7);\n dequant_lsps( lsps, 5, v, vec_sizes, 2,\n wmavoice_dq_lsp16i1, mul_lsf, base_lsf);\n dequant_lsps(&lsps[5], 5, &v[2], &vec_sizes[2], 2,\n wmavoice_dq_lsp16i2, &mul_lsf[2], &base_lsf[2]);\n dequant_lsps(&lsps[10], 6, &v[4], &vec_sizes[4], 1,\n wmavoice_dq_lsp16i3, &mul_lsf[4], &base_lsf[4]);\n}', 'static void dequant_lsps(double *lsps, int num,\n const uint16_t *values,\n const uint16_t *sizes,\n int n_stages, const uint8_t *table,\n const double *mul_q,\n const double *base_q)\n{\n int n, m;\n memset(lsps, 0, num * sizeof(*lsps));\n for (n = 0; n < n_stages; n++) {\n const uint8_t *t_off = &table[values[n] * num];\n double base = base_q[n], mul = mul_q[n];\n for (m = 0; m < num; m++)\n lsps[m] += base + mul * t_off[m];\n table += sizes[n] * num;\n }\n}'] |
35,030 | 0 | https://github.com/libav/libav/blob/6cecd63005b29a1dc3a5104e6ac85fd112705122/libavcodec/mlpdec.c/#L1073 | static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
MLPDecodeContext *m = avctx->priv_data;
GetBitContext gb;
unsigned int length, substr;
unsigned int substream_start;
unsigned int header_size = 4;
unsigned int substr_header_size = 0;
uint8_t substream_parity_present[MAX_SUBSTREAMS];
uint16_t substream_data_len[MAX_SUBSTREAMS];
uint8_t parity_bits;
if (buf_size < 4)
return 0;
length = (AV_RB16(buf) & 0xfff) * 2;
if (length > buf_size)
return -1;
init_get_bits(&gb, (buf + 4), (length - 4) * 8);
m->is_major_sync_unit = 0;
if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {
if (read_major_sync(m, &gb) < 0)
goto error;
m->is_major_sync_unit = 1;
header_size += 28;
}
if (!m->params_valid) {
av_log(m->avctx, AV_LOG_WARNING,
"Stream parameters not seen; skipping frame.\n");
*data_size = 0;
return length;
}
substream_start = 0;
for (substr = 0; substr < m->num_substreams; substr++) {
int extraword_present, checkdata_present, end, nonrestart_substr;
extraword_present = get_bits1(&gb);
nonrestart_substr = get_bits1(&gb);
checkdata_present = get_bits1(&gb);
skip_bits1(&gb);
end = get_bits(&gb, 12) * 2;
substr_header_size += 2;
if (extraword_present) {
if (m->avctx->codec_id == CODEC_ID_MLP) {
av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\n");
goto error;
}
skip_bits(&gb, 16);
substr_header_size += 2;
}
if (!(nonrestart_substr ^ m->is_major_sync_unit)) {
av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n");
goto error;
}
if (end + header_size + substr_header_size > length) {
av_log(m->avctx, AV_LOG_ERROR,
"Indicated length of substream %d data goes off end of "
"packet.\n", substr);
end = length - header_size - substr_header_size;
}
if (end < substream_start) {
av_log(avctx, AV_LOG_ERROR,
"Indicated end offset of substream %d data "
"is smaller than calculated start offset.\n",
substr);
goto error;
}
if (substr > m->max_decoded_substream)
continue;
substream_parity_present[substr] = checkdata_present;
substream_data_len[substr] = end - substream_start;
substream_start = end;
}
parity_bits = ff_mlp_calculate_parity(buf, 4);
parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);
if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
av_log(avctx, AV_LOG_ERROR, "Parity check failed.\n");
goto error;
}
buf += header_size + substr_header_size;
for (substr = 0; substr <= m->max_decoded_substream; substr++) {
SubStream *s = &m->substream[substr];
init_get_bits(&gb, buf, substream_data_len[substr] * 8);
m->matrix_changed = 0;
memset(m->filter_changed, 0, sizeof(m->filter_changed));
s->blockpos = 0;
do {
unsigned int ch;
if (get_bits1(&gb)) {
if (get_bits1(&gb)) {
if (read_restart_header(m, &gb, buf, substr) < 0)
goto next_substr;
s->restart_seen = 1;
}
if (!s->restart_seen) {
goto next_substr;
}
if (read_decoding_params(m, &gb, substr) < 0)
goto next_substr;
}
if (m->matrix_changed > 1) {
av_log(m->avctx, AV_LOG_ERROR, "Matrices may change only once per access unit.\n");
goto next_substr;
}
for (ch = 0; ch < s->max_channel; ch++)
if (m->filter_changed[ch][FIR] > 1 ||
m->filter_changed[ch][IIR] > 1) {
av_log(m->avctx, AV_LOG_ERROR, "Filters may change only once per access unit.\n");
goto next_substr;
}
if (!s->restart_seen) {
goto next_substr;
}
if (read_block_data(m, &gb, substr) < 0)
return -1;
if (get_bits_count(&gb) >= substream_data_len[substr] * 8)
goto substream_length_mismatch;
} while (!get_bits1(&gb));
skip_bits(&gb, (-get_bits_count(&gb)) & 15);
if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {
int shorten_by;
if (get_bits(&gb, 16) != 0xD234)
return -1;
shorten_by = get_bits(&gb, 16);
if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)
s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);
else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)
return -1;
if (substr == m->max_decoded_substream)
av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n");
}
if (substream_parity_present[substr]) {
uint8_t parity, checksum;
if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)
goto substream_length_mismatch;
parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);
checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);
if ((get_bits(&gb, 8) ^ parity) != 0xa9 )
av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\n", substr);
if ( get_bits(&gb, 8) != checksum)
av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\n" , substr);
}
if (substream_data_len[substr] * 8 != get_bits_count(&gb)) {
goto substream_length_mismatch;
}
next_substr:
if (!s->restart_seen) {
av_log(m->avctx, AV_LOG_ERROR,
"No restart header present in substream %d.\n", substr);
}
buf += substream_data_len[substr];
}
rematrix_channels(m, m->max_decoded_substream);
if (output_data(m, m->max_decoded_substream, data, data_size) < 0)
return -1;
return length;
substream_length_mismatch:
av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr);
return -1;
error:
m->params_valid = 0;
return -1;
} | ['static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n MLPDecodeContext *m = avctx->priv_data;\n GetBitContext gb;\n unsigned int length, substr;\n unsigned int substream_start;\n unsigned int header_size = 4;\n unsigned int substr_header_size = 0;\n uint8_t substream_parity_present[MAX_SUBSTREAMS];\n uint16_t substream_data_len[MAX_SUBSTREAMS];\n uint8_t parity_bits;\n if (buf_size < 4)\n return 0;\n length = (AV_RB16(buf) & 0xfff) * 2;\n if (length > buf_size)\n return -1;\n init_get_bits(&gb, (buf + 4), (length - 4) * 8);\n m->is_major_sync_unit = 0;\n if (show_bits_long(&gb, 31) == (0xf8726fba >> 1)) {\n if (read_major_sync(m, &gb) < 0)\n goto error;\n m->is_major_sync_unit = 1;\n header_size += 28;\n }\n if (!m->params_valid) {\n av_log(m->avctx, AV_LOG_WARNING,\n "Stream parameters not seen; skipping frame.\\n");\n *data_size = 0;\n return length;\n }\n substream_start = 0;\n for (substr = 0; substr < m->num_substreams; substr++) {\n int extraword_present, checkdata_present, end, nonrestart_substr;\n extraword_present = get_bits1(&gb);\n nonrestart_substr = get_bits1(&gb);\n checkdata_present = get_bits1(&gb);\n skip_bits1(&gb);\n end = get_bits(&gb, 12) * 2;\n substr_header_size += 2;\n if (extraword_present) {\n if (m->avctx->codec_id == CODEC_ID_MLP) {\n av_log(m->avctx, AV_LOG_ERROR, "There must be no extraword for MLP.\\n");\n goto error;\n }\n skip_bits(&gb, 16);\n substr_header_size += 2;\n }\n if (!(nonrestart_substr ^ m->is_major_sync_unit)) {\n av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\\n");\n goto error;\n }\n if (end + header_size + substr_header_size > length) {\n av_log(m->avctx, AV_LOG_ERROR,\n "Indicated length of substream %d data goes off end of "\n "packet.\\n", substr);\n end = length - header_size - substr_header_size;\n }\n if (end < substream_start) {\n av_log(avctx, AV_LOG_ERROR,\n "Indicated end offset of substream %d data "\n "is smaller than calculated start offset.\\n",\n substr);\n goto error;\n }\n if (substr > m->max_decoded_substream)\n continue;\n substream_parity_present[substr] = checkdata_present;\n substream_data_len[substr] = end - substream_start;\n substream_start = end;\n }\n parity_bits = ff_mlp_calculate_parity(buf, 4);\n parity_bits ^= ff_mlp_calculate_parity(buf + header_size, substr_header_size);\n if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {\n av_log(avctx, AV_LOG_ERROR, "Parity check failed.\\n");\n goto error;\n }\n buf += header_size + substr_header_size;\n for (substr = 0; substr <= m->max_decoded_substream; substr++) {\n SubStream *s = &m->substream[substr];\n init_get_bits(&gb, buf, substream_data_len[substr] * 8);\n m->matrix_changed = 0;\n memset(m->filter_changed, 0, sizeof(m->filter_changed));\n s->blockpos = 0;\n do {\n unsigned int ch;\n if (get_bits1(&gb)) {\n if (get_bits1(&gb)) {\n if (read_restart_header(m, &gb, buf, substr) < 0)\n goto next_substr;\n s->restart_seen = 1;\n }\n if (!s->restart_seen) {\n goto next_substr;\n }\n if (read_decoding_params(m, &gb, substr) < 0)\n goto next_substr;\n }\n if (m->matrix_changed > 1) {\n av_log(m->avctx, AV_LOG_ERROR, "Matrices may change only once per access unit.\\n");\n goto next_substr;\n }\n for (ch = 0; ch < s->max_channel; ch++)\n if (m->filter_changed[ch][FIR] > 1 ||\n m->filter_changed[ch][IIR] > 1) {\n av_log(m->avctx, AV_LOG_ERROR, "Filters may change only once per access unit.\\n");\n goto next_substr;\n }\n if (!s->restart_seen) {\n goto next_substr;\n }\n if (read_block_data(m, &gb, substr) < 0)\n return -1;\n if (get_bits_count(&gb) >= substream_data_len[substr] * 8)\n goto substream_length_mismatch;\n } while (!get_bits1(&gb));\n skip_bits(&gb, (-get_bits_count(&gb)) & 15);\n if (substream_data_len[substr] * 8 - get_bits_count(&gb) >= 32) {\n int shorten_by;\n if (get_bits(&gb, 16) != 0xD234)\n return -1;\n shorten_by = get_bits(&gb, 16);\n if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000)\n s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos);\n else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234)\n return -1;\n if (substr == m->max_decoded_substream)\n av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\\n");\n }\n if (substream_parity_present[substr]) {\n uint8_t parity, checksum;\n if (substream_data_len[substr] * 8 - get_bits_count(&gb) != 16)\n goto substream_length_mismatch;\n parity = ff_mlp_calculate_parity(buf, substream_data_len[substr] - 2);\n checksum = ff_mlp_checksum8 (buf, substream_data_len[substr] - 2);\n if ((get_bits(&gb, 8) ^ parity) != 0xa9 )\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d parity check failed.\\n", substr);\n if ( get_bits(&gb, 8) != checksum)\n av_log(m->avctx, AV_LOG_ERROR, "Substream %d checksum failed.\\n" , substr);\n }\n if (substream_data_len[substr] * 8 != get_bits_count(&gb)) {\n goto substream_length_mismatch;\n }\nnext_substr:\n if (!s->restart_seen) {\n av_log(m->avctx, AV_LOG_ERROR,\n "No restart header present in substream %d.\\n", substr);\n }\n buf += substream_data_len[substr];\n }\n rematrix_channels(m, m->max_decoded_substream);\n if (output_data(m, m->max_decoded_substream, data, data_size) < 0)\n return -1;\n return length;\nsubstream_length_mismatch:\n av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\\n", substr);\n return -1;\nerror:\n m->params_valid = 0;\n return -1;\n}'] |
35,031 | 0 | https://github.com/libav/libav/blob/74d127b537d18cc9a2bf2b556900705f7b2af2be/ffmpeg.c/#L3425 | static void new_video_stream(AVFormatContext *oc, int file_idx)
{
AVStream *st;
AVCodecContext *video_enc;
enum CodecID codec_id;
AVCodec *codec= NULL;
st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);
if(!video_stream_copy){
if (video_codec_name) {
codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
codec = avcodec_find_encoder_by_name(video_codec_name);
output_codecs[nb_output_codecs-1] = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
codec = avcodec_find_encoder(codec_id);
}
}
avcodec_get_context_defaults3(st->codec, codec);
bitstream_filters[file_idx] =
grow_array(bitstream_filters[file_idx],
sizeof(*bitstream_filters[file_idx]),
&nb_bitstream_filters[file_idx], oc->nb_streams);
bitstream_filters[file_idx][oc->nb_streams - 1]= video_bitstream_filters;
video_bitstream_filters= NULL;
avcodec_thread_init(st->codec, thread_count);
video_enc = st->codec;
if(video_codec_tag)
video_enc->codec_tag= video_codec_tag;
if( (video_global_header&1)
|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){
video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
if(video_global_header&2){
video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;
}
if (video_stream_copy) {
st->stream_copy = 1;
video_enc->codec_type = AVMEDIA_TYPE_VIDEO;
video_enc->sample_aspect_ratio =
st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
} else {
const char *p;
int i;
AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
video_enc->codec_id = codec_id;
set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
if (codec && codec->supported_framerates && !force_fps)
fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
video_enc->time_base.den = fps.num;
video_enc->time_base.num = fps.den;
video_enc->width = frame_width;
video_enc->height = frame_height;
video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);
video_enc->pix_fmt = frame_pix_fmt;
st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
choose_pixel_fmt(st, codec);
if (intra_only)
video_enc->gop_size = 0;
if (video_qscale || same_quality) {
video_enc->flags |= CODEC_FLAG_QSCALE;
video_enc->global_quality=
st->quality = FF_QP2LAMBDA * video_qscale;
}
if(intra_matrix)
video_enc->intra_matrix = intra_matrix;
if(inter_matrix)
video_enc->inter_matrix = inter_matrix;
p= video_rc_override_string;
for(i=0; p; i++){
int start, end, q;
int e=sscanf(p, "%d,%d,%d", &start, &end, &q);
if(e!=3){
fprintf(stderr, "error parsing rc_override\n");
ffmpeg_exit(1);
}
video_enc->rc_override=
av_realloc(video_enc->rc_override,
sizeof(RcOverride)*(i+1));
video_enc->rc_override[i].start_frame= start;
video_enc->rc_override[i].end_frame = end;
if(q>0){
video_enc->rc_override[i].qscale= q;
video_enc->rc_override[i].quality_factor= 1.0;
}
else{
video_enc->rc_override[i].qscale= 0;
video_enc->rc_override[i].quality_factor= -q/100.0;
}
p= strchr(p, '/');
if(p) p++;
}
video_enc->rc_override_count=i;
if (!video_enc->rc_initial_buffer_occupancy)
video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;
video_enc->me_threshold= me_threshold;
video_enc->intra_dc_precision= intra_dc_precision - 8;
if (do_psnr)
video_enc->flags|= CODEC_FLAG_PSNR;
if (do_pass) {
if (do_pass == 1) {
video_enc->flags |= CODEC_FLAG_PASS1;
} else {
video_enc->flags |= CODEC_FLAG_PASS2;
}
}
}
if (video_language) {
av_metadata_set2(&st->metadata, "language", video_language, 0);
av_freep(&video_language);
}
video_disable = 0;
av_freep(&video_codec_name);
video_stream_copy = 0;
frame_pix_fmt = PIX_FMT_NONE;
} | ['static int opt_new_stream(const char *opt, const char *arg)\n{\n AVFormatContext *oc;\n int file_idx = nb_output_files - 1;\n if (nb_output_files <= 0) {\n fprintf(stderr, "At least one output file must be specified\\n");\n ffmpeg_exit(1);\n }\n oc = output_files[file_idx];\n if (!strcmp(opt, "newvideo" )) new_video_stream (oc, file_idx);\n else if (!strcmp(opt, "newaudio" )) new_audio_stream (oc, file_idx);\n else if (!strcmp(opt, "newsubtitle")) new_subtitle_stream(oc, file_idx);\n else av_assert0(0);\n return 0;\n}', 'static void new_video_stream(AVFormatContext *oc, int file_idx)\n{\n AVStream *st;\n AVCodecContext *video_enc;\n enum CodecID codec_id;\n AVCodec *codec= NULL;\n st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n ffmpeg_exit(1);\n }\n output_codecs = grow_array(output_codecs, sizeof(*output_codecs), &nb_output_codecs, nb_output_codecs + 1);\n if(!video_stream_copy){\n if (video_codec_name) {\n codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,\n avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);\n codec = avcodec_find_encoder_by_name(video_codec_name);\n output_codecs[nb_output_codecs-1] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);\n codec = avcodec_find_encoder(codec_id);\n }\n }\n avcodec_get_context_defaults3(st->codec, codec);\n bitstream_filters[file_idx] =\n grow_array(bitstream_filters[file_idx],\n sizeof(*bitstream_filters[file_idx]),\n &nb_bitstream_filters[file_idx], oc->nb_streams);\n bitstream_filters[file_idx][oc->nb_streams - 1]= video_bitstream_filters;\n video_bitstream_filters= NULL;\n avcodec_thread_init(st->codec, thread_count);\n video_enc = st->codec;\n if(video_codec_tag)\n video_enc->codec_tag= video_codec_tag;\n if( (video_global_header&1)\n || (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))){\n video_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if(video_global_header&2){\n video_enc->flags2 |= CODEC_FLAG2_LOCAL_HEADER;\n avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags2|= CODEC_FLAG2_LOCAL_HEADER;\n }\n if (video_stream_copy) {\n st->stream_copy = 1;\n video_enc->codec_type = AVMEDIA_TYPE_VIDEO;\n video_enc->sample_aspect_ratio =\n st->sample_aspect_ratio = av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);\n } else {\n const char *p;\n int i;\n AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};\n video_enc->codec_id = codec_id;\n set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);\n if (codec && codec->supported_framerates && !force_fps)\n fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];\n video_enc->time_base.den = fps.num;\n video_enc->time_base.num = fps.den;\n video_enc->width = frame_width;\n video_enc->height = frame_height;\n video_enc->sample_aspect_ratio = av_d2q(frame_aspect_ratio*video_enc->height/video_enc->width, 255);\n video_enc->pix_fmt = frame_pix_fmt;\n st->sample_aspect_ratio = video_enc->sample_aspect_ratio;\n choose_pixel_fmt(st, codec);\n if (intra_only)\n video_enc->gop_size = 0;\n if (video_qscale || same_quality) {\n video_enc->flags |= CODEC_FLAG_QSCALE;\n video_enc->global_quality=\n st->quality = FF_QP2LAMBDA * video_qscale;\n }\n if(intra_matrix)\n video_enc->intra_matrix = intra_matrix;\n if(inter_matrix)\n video_enc->inter_matrix = inter_matrix;\n p= video_rc_override_string;\n for(i=0; p; i++){\n int start, end, q;\n int e=sscanf(p, "%d,%d,%d", &start, &end, &q);\n if(e!=3){\n fprintf(stderr, "error parsing rc_override\\n");\n ffmpeg_exit(1);\n }\n video_enc->rc_override=\n av_realloc(video_enc->rc_override,\n sizeof(RcOverride)*(i+1));\n video_enc->rc_override[i].start_frame= start;\n video_enc->rc_override[i].end_frame = end;\n if(q>0){\n video_enc->rc_override[i].qscale= q;\n video_enc->rc_override[i].quality_factor= 1.0;\n }\n else{\n video_enc->rc_override[i].qscale= 0;\n video_enc->rc_override[i].quality_factor= -q/100.0;\n }\n p= strchr(p, \'/\');\n if(p) p++;\n }\n video_enc->rc_override_count=i;\n if (!video_enc->rc_initial_buffer_occupancy)\n video_enc->rc_initial_buffer_occupancy = video_enc->rc_buffer_size*3/4;\n video_enc->me_threshold= me_threshold;\n video_enc->intra_dc_precision= intra_dc_precision - 8;\n if (do_psnr)\n video_enc->flags|= CODEC_FLAG_PSNR;\n if (do_pass) {\n if (do_pass == 1) {\n video_enc->flags |= CODEC_FLAG_PASS1;\n } else {\n video_enc->flags |= CODEC_FLAG_PASS2;\n }\n }\n }\n if (video_language) {\n av_metadata_set2(&st->metadata, "language", video_language, 0);\n av_freep(&video_language);\n }\n video_disable = 0;\n av_freep(&video_codec_name);\n video_stream_copy = 0;\n frame_pix_fmt = PIX_FMT_NONE;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n#if FF_API_MAX_STREAMS\n if (s->nb_streams >= MAX_STREAMS){\n av_log(s, AV_LOG_ERROR, "Too many streams\\n");\n return NULL;\n }\n#else\n AVStream **streams;\n if (s->nb_streams >= INT_MAX/sizeof(*streams))\n return NULL;\n streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));\n if (!streams)\n return NULL;\n s->streams = streams;\n#endif\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n if (!(st->info = av_mallocz(sizeof(*st->info)))) {\n av_free(st);\n return NULL;\n }\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n st->probe_packets = MAX_PROBE_PACKETS;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}'] |
35,032 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_ctx.c/#L353 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int gost_do_verify(const unsigned char *dgst, int dgst_len,\n\tDSA_SIG *sig, DSA *dsa)\n\t{\n\tBIGNUM *md, *tmp=NULL;\n\tBIGNUM *q2=NULL;\n\tBIGNUM *u=NULL,*v=NULL,*z1=NULL,*z2=NULL;\n\tBIGNUM *tmp2=NULL,*tmp3=NULL;\n\tint ok;\n\tBN_CTX *ctx = BN_CTX_new();\n\tBN_CTX_start(ctx);\n\tif (BN_cmp(sig->s,dsa->q)>=1||\n\t\tBN_cmp(sig->r,dsa->q)>=1)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n\t\treturn 0;\n\t\t}\n\tmd=hashsum2bn(dgst);\n\ttmp=BN_CTX_get(ctx);\n\tv=BN_CTX_get(ctx);\n\tq2=BN_CTX_get(ctx);\n\tz1=BN_CTX_get(ctx);\n\tz2=BN_CTX_get(ctx);\n\ttmp2=BN_CTX_get(ctx);\n\ttmp3=BN_CTX_get(ctx);\n\tu = BN_CTX_get(ctx);\n\tBN_mod(tmp,md,dsa->q,ctx);\n\tif (BN_is_zero(tmp))\n\t\t{\n\t\tBN_one(md);\n\t\t}\n\tBN_copy(q2,dsa->q);\n\tBN_sub_word(q2,2);\n\tBN_mod_exp(v,md,q2,dsa->q,ctx);\n\tBN_mod_mul(z1,sig->s,v,dsa->q,ctx);\n\tBN_sub(tmp,dsa->q,sig->r);\n\tBN_mod_mul(z2,tmp,v,dsa->p,ctx);\n\tBN_mod_exp(tmp,dsa->g,z1,dsa->p,ctx);\n\tBN_mod_exp(tmp2,dsa->pub_key,z2,dsa->p,ctx);\n\tBN_mod_mul(tmp3,tmp,tmp2,dsa->p,ctx);\n\tBN_mod(u,tmp3,dsa->q,ctx);\n\tok= BN_cmp(u,sig->r);\n\tBN_free(md);\n\tBN_CTX_end(ctx);\n\tBN_CTX_free(ctx);\n\tif (ok!=0)\n\t\t{\n\t\tGOSTerr(GOST_F_GOST_DO_VERIFY,GOST_R_SIGNATURE_MISMATCH);\n\t\t}\n\treturn (ok==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_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i;\n\tsize_t loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp, div_n+1)) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tBN_MONT_CTX *mont = NULL;\n\tint b, bits, ret=0;\n\tint r_is_one;\n\tBN_ULONG w, next_w;\n\tBIGNUM *d, *r, *t;\n\tBIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n\t\t(BN_mul_word(r, (w)) && \\\n\t\t( \\\n\t\t\t(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\t\t(BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbn_check_top(p);\n\tbn_check_top(m);\n\tif (!BN_is_odd(m))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tif (m->top == 1)\n\t\ta %= m->d[0];\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\tif (a == 0)\n\t\t{\n\t\tBN_zero(rr);\n\t\tret = 1;\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\tt = BN_CTX_get(ctx);\n\tif (d == NULL || r == NULL || t == 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\tr_is_one = 1;\n\tw = a;\n\tfor (b = bits-2; b >= 0; b--)\n\t\t{\n\t\tnext_w = w*w;\n\t\tif ((next_w/w) != w)\n\t\t\t{\n\t\t\tif (r_is_one)\n\t\t\t\t{\n\t\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\t\tr_is_one = 0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t\t}\n\t\t\tnext_w = 1;\n\t\t\t}\n\t\tw = next_w;\n\t\tif (!r_is_one)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(r, r, r, mont, ctx)) goto err;\n\t\t\t}\n\t\tif (BN_is_bit_set(p, b))\n\t\t\t{\n\t\t\tnext_w = w*a;\n\t\t\tif ((next_w/a) != w)\n\t\t\t\t{\n\t\t\t\tif (r_is_one)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\t\t\tr_is_one = 0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t\t\t}\n\t\t\t\tnext_w = a;\n\t\t\t\t}\n\t\t\tw = next_w;\n\t\t\t}\n\t\t}\n\tif (w != 1)\n\t\t{\n\t\tif (r_is_one)\n\t\t\t{\n\t\t\tif (!BN_TO_MONTGOMERY_WORD(r, w, mont)) goto err;\n\t\t\tr_is_one = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_MOD_MUL_WORD(r, w, m)) goto err;\n\t\t\t}\n\t\t}\n\tif (r_is_one)\n\t\t{\n\t\tif (!BN_one(rr)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_from_montgomery(rr, r, mont, ctx)) goto err;\n\t\t}\n\tret = 1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tBN_CTX_end(ctx);\n\tbn_check_top(rr);\n\treturn(ret);\n\t}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n\tBN_CTX *ctx)\n\t{\n\tBIGNUM *t;\n\tint ret=0;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(m);\n\tBN_CTX_start(ctx);\n\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\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_nnmod(r,t,m,ctx)) goto err;\n\tbn_check_top(r);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n\t{\n\tint max,al;\n\tint ret = 0;\n\tBIGNUM *tmp,*rr;\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_sqr %d * %d\\n",a->top,a->top);\n#endif\n\tbn_check_top(a);\n\tal=a->top;\n\tif (al <= 0)\n\t\t{\n\t\tr->top=0;\n\t\treturn 1;\n\t\t}\n\tBN_CTX_start(ctx);\n\trr=(a != r) ? r : BN_CTX_get(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tif (!rr || !tmp) goto err;\n\tmax = 2 * al;\n\tif (bn_wexpand(rr,max) == NULL) goto err;\n\tif (al == 4)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[8];\n\t\tbn_sqr_normal(rr->d,a->d,4,t);\n#else\n\t\tbn_sqr_comba4(rr->d,a->d);\n#endif\n\t\t}\n\telse if (al == 8)\n\t\t{\n#ifndef BN_SQR_COMBA\n\t\tBN_ULONG t[16];\n\t\tbn_sqr_normal(rr->d,a->d,8,t);\n#else\n\t\tbn_sqr_comba8(rr->d,a->d);\n#endif\n\t\t}\n\telse\n\t\t{\n#if defined(BN_RECURSION)\n\t\tif (al < BN_SQR_RECURSIVE_SIZE_NORMAL)\n\t\t\t{\n\t\t\tBN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL*2];\n\t\t\tbn_sqr_normal(rr->d,a->d,al,t);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tint j,k;\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,k*2) == NULL) goto err;\n\t\t\t\tbn_sqr_recursive(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\t\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (bn_wexpand(tmp,max) == NULL) goto err;\n\t\tbn_sqr_normal(rr->d,a->d,al,tmp->d);\n#endif\n\t\t}\n\trr->neg=0;\n\tif(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n\t\trr->top = max - 1;\n\telse\n\t\trr->top = max;\n\tif (rr != r) BN_copy(r,rr);\n\tret = 1;\n err:\n\tbn_check_top(rr);\n\tbn_check_top(tmp);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}'] |
35,033 | 0 | https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_ctx.c/#L273 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int test_mod_exp(int round)\n{\n BN_CTX *ctx;\n unsigned char c;\n int ret = 0;\n BIGNUM *r_mont = NULL;\n BIGNUM *r_mont_const = NULL;\n BIGNUM *r_recp = NULL;\n BIGNUM *r_simple = NULL;\n BIGNUM *a = NULL;\n BIGNUM *b = NULL;\n BIGNUM *m = NULL;\n if (!TEST_ptr(ctx = BN_CTX_new()))\n goto err;\n if (!TEST_ptr(r_mont = BN_new())\n || !TEST_ptr(r_mont_const = BN_new())\n || !TEST_ptr(r_recp = BN_new())\n || !TEST_ptr(r_simple = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(b = BN_new())\n || !TEST_ptr(m = BN_new()))\n goto err;\n RAND_bytes(&c, 1);\n c = (c % BN_BITS) - BN_BITS2;\n BN_rand(a, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY);\n RAND_bytes(&c, 1);\n c = (c % BN_BITS) - BN_BITS2;\n BN_rand(b, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY);\n RAND_bytes(&c, 1);\n c = (c % BN_BITS) - BN_BITS2;\n BN_rand(m, NUM_BITS + c, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD);\n if (!TEST_true(BN_mod(a, a, m, ctx))\n || !TEST_true(BN_mod(b, b, m, ctx))\n || !TEST_true(BN_mod_exp_mont(r_mont, a, b, m, ctx, NULL))\n || !TEST_true(BN_mod_exp_recp(r_recp, a, b, m, ctx))\n || !TEST_true(BN_mod_exp_simple(r_simple, a, b, m, ctx))\n || !TEST_true(BN_mod_exp_mont_consttime(r_mont_const, a, b, m, ctx, NULL)))\n goto err;\n if (!TEST_BN_eq(r_simple, r_mont)\n || !TEST_BN_eq(r_simple, r_recp)\n || !TEST_BN_eq(r_simple, r_mont_const)) {\n if (BN_cmp(r_simple, r_mont) != 0)\n TEST_info("simple and mont results differ");\n if (BN_cmp(r_simple, r_mont_const) != 0)\n TEST_info("simple and mont const time results differ");\n if (BN_cmp(r_simple, r_recp) != 0)\n TEST_info("simple and recp results differ");\n BN_print_var(a);\n BN_print_var(b);\n BN_print_var(m);\n BN_print_var(r_simple);\n BN_print_var(r_recp);\n BN_print_var(r_mont);\n BN_print_var(r_mont_const);\n goto err;\n }\n ret = 1;\n err:\n BN_free(r_mont);\n BN_free(r_mont_const);\n BN_free(r_recp);\n BN_free(r_simple);\n BN_free(a);\n BN_free(b);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n 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}'] |
35,034 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/bn/bn_asm.c/#L623 | void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
{
#ifdef BN_LLONG
BN_ULLONG t;
#else
BN_ULONG bl,bh;
#endif
BN_ULONG t1,t2;
BN_ULONG c1,c2,c3;
c1=0;
c2=0;
c3=0;
mul_add_c(a[0],b[0],c1,c2,c3);
r[0]=c1;
c1=0;
mul_add_c(a[0],b[1],c2,c3,c1);
mul_add_c(a[1],b[0],c2,c3,c1);
r[1]=c2;
c2=0;
mul_add_c(a[2],b[0],c3,c1,c2);
mul_add_c(a[1],b[1],c3,c1,c2);
mul_add_c(a[0],b[2],c3,c1,c2);
r[2]=c3;
c3=0;
mul_add_c(a[0],b[3],c1,c2,c3);
mul_add_c(a[1],b[2],c1,c2,c3);
mul_add_c(a[2],b[1],c1,c2,c3);
mul_add_c(a[3],b[0],c1,c2,c3);
r[3]=c1;
c1=0;
mul_add_c(a[3],b[1],c2,c3,c1);
mul_add_c(a[2],b[2],c2,c3,c1);
mul_add_c(a[1],b[3],c2,c3,c1);
r[4]=c2;
c2=0;
mul_add_c(a[2],b[3],c3,c1,c2);
mul_add_c(a[3],b[2],c3,c1,c2);
r[5]=c3;
c3=0;
mul_add_c(a[3],b[3],c1,c2,c3);
r[6]=c1;
r[7]=c2;
} | ['int BN_is_prime(BIGNUM *a, int checks, void (*callback)(P_I_I_P),\n\t BN_CTX *ctx_passed, char *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef BN_RECURSION_MONT\n\tif (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)\n#endif\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->use_word=1;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.max=mod->max;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\t{\n#if 1\n\t\t\tBN_sub_word(&Ri,1);\n#else\n\t\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\t\t}\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tmont->use_word=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if 1\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n#else\n\t\tBN_lshift(R,BN_value_one(),mont->ri);\n#endif\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n#if 1\n\t\tBN_sub_word(&Ri,1);\n#else\n\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n#if 1\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n#else\n\tBN_lshift(mont->RR,BN_value_one(),mont->ri*2);\n#endif\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tint i,n;\n\tif (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);\n\tn=sizeof(BN_ULONG)/BN_BYTES;\n\ta->neg=0;\n\ta->top=0;\n\ta->d[0]=(BN_ULONG)w&BN_MASK2;\n\tif (a->d[0] != 0) a->top=1;\n\tfor (i=1; i<n; i++)\n\t\t{\n#ifndef SIXTY_FOUR_BIT\n\t\tw>>=BN_BITS4;\n\t\tw>>=BN_BITS4;\n#endif\n\t\ta->d[i]=(BN_ULONG)w&BN_MASK2;\n\t\tif (a->d[i] != 0) a->top=i+1;\n\t\t}\n\treturn(1);\n\t}', 'int BN_set_bit(BIGNUM *a, int n)\n\t{\n\tint i,j,k;\n\ti=n/BN_BITS2;\n\tj=n%BN_BITS2;\n\tif (a->top <= i)\n\t\t{\n\t\tif (bn_wexpand(a,i+1) == NULL) return(0);\n\t\tfor(k=a->top; k<i+1; k++)\n\t\t\ta->d[k]=0;\n\t\ta->top=i+1;\n\t\t}\n\ta->d[i]|=(1L<<j);\n\treturn(1);\n\t}', 'static int witness(BIGNUM *a, BIGNUM *n, BN_CTX *ctx, BN_CTX *ctx2,\n\t BN_MONT_CTX *mont)\n\t{\n\tint k,i,ret= -1,good;\n\tBIGNUM *d,*dd,*tmp,*d1,*d2,*n1;\n\tBIGNUM *mont_one,*mont_n1,*mont_a;\n\td1= &(ctx->bn[ctx->tos]);\n\td2= &(ctx->bn[ctx->tos+1]);\n\tn1= &(ctx->bn[ctx->tos+2]);\n\tctx->tos+=3;\n\tmont_one= &(ctx2->bn[ctx2->tos]);\n\tmont_n1= &(ctx2->bn[ctx2->tos+1]);\n\tmont_a= &(ctx2->bn[ctx2->tos+2]);\n\tctx2->tos+=3;\n\td=d1;\n\tdd=d2;\n\tif (!BN_one(d)) goto err;\n\tif (!BN_sub(n1,n,d)) goto err;\n\tk=BN_num_bits(n1);\n\tif (!BN_to_montgomery(mont_one,BN_value_one(),mont,ctx2)) goto err;\n\tif (!BN_to_montgomery(mont_n1,n1,mont,ctx2)) goto err;\n\tif (!BN_to_montgomery(mont_a,a,mont,ctx2)) goto err;\n\tBN_copy(d,mont_one);\n\tfor (i=k-1; i>=0; i--)\n\t\t{\n\t\tif (\t(BN_cmp(d,mont_one) != 0) &&\n\t\t\t(BN_cmp(d,mont_n1) != 0))\n\t\t\tgood=1;\n\t\telse\n\t\t\tgood=0;\n\t\tBN_mod_mul_montgomery(dd,d,d,mont,ctx2);\n\t\tif (good && (BN_cmp(dd,mont_one) == 0))\n\t\t\t{\n\t\t\tret=1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (BN_is_bit_set(n1,i))\n\t\t\t{\n\t\t\tBN_mod_mul_montgomery(d,dd,mont_a,mont,ctx2);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttmp=d;\n\t\t\td=dd;\n\t\t\tdd=tmp;\n\t\t\t}\n\t\t}\n\tif (BN_cmp(d,mont_one) == 0)\n\t\ti=0;\n\telse\ti=1;\n\tret=i;\nerr:\n\tctx->tos-=3;\n\tctx2->tos-=3;\n\treturn(ret);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_MONT_CTX *mont,\n\t BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp,*tmp2;\n tmp= &(ctx->bn[ctx->tos]);\n tmp2= &(ctx->bn[ctx->tos]);\n\tctx->tos+=2;\n\tbn_check_top(tmp);\n\tbn_check_top(tmp2);\n\tif (a == b)\n\t\t{\n#if 0\n\t\tbn_wexpand(tmp,a->top*2);\n\t\tbn_wexpand(tmp2,a->top*4);\n\t\tbn_sqr_recursive(tmp->d,a->d,a->top,tmp2->d);\n\t\ttmp->top=a->top*2;\n\t\tif (tmp->d[tmp->top-1] == 0)\n\t\t\ttmp->top--;\n#else\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n\tctx->tos-=2;\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint i,j,k;\n#endif\n#ifdef BN_COUNT\nprintf("BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tr->neg=a->neg^b->neg;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tif ((r == a) || (r == b))\n\t\trr= &(ctx->bn[ctx->tos+1]);\n\telse\n\t\trr=r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tif (al == bl)\n\t\t{\n# ifdef BN_MUL_COMBA\n if (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) return(0);\n\t\t\tr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n# endif\n#ifdef BN_RECURSION\n\t\tif (al < BN_MULL_SIZE_NORMAL)\n#endif\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\t\trr->top=top;\n\t\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\t\tgoto end;\n\t\t\t}\n# ifdef BN_RECURSION\n\t\tgoto symetric;\n# endif\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\telse if ((al < BN_MULL_SIZE_NORMAL) || (bl < BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (bn_wexpand(rr,top) == NULL) return(0);\n\t\trr->top=top;\n\t\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n\t\tgoto end;\n\t\t}\n\telse\n\t\t{\n\t\ti=(al-bl);\n\t\tif ((i == 1) && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(b,al);\n\t\t\tb->d[bl]=0;\n\t\t\tbl++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\telse if ((i == -1) && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tbn_wexpand(a,bl);\n\t\t\ta->d[al]=0;\n\t\t\tal++;\n\t\t\tgoto symetric;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) return(0);\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#ifdef BN_RECURSION\n\tif (0)\n\t\t{\nsymetric:\n\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\tj=1<<(j-1);\n\t\tk=j+j;\n\t\tt= &(ctx->bn[ctx->tos]);\n\t\tif (al == j)\n\t\t\t{\n\t\t\tbn_wexpand(t,k*2);\n\t\t\tbn_wexpand(rr,k*2);\n\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbn_wexpand(a,k);\n\t\t\tbn_wexpand(b,k);\n\t\t\tbn_wexpand(t,k*4);\n\t\t\tbn_wexpand(rr,k*4);\n\t\t\tfor (i=a->top; i<k; i++)\n\t\t\t\ta->d[i]=0;\n\t\t\tfor (i=b->top; i<k; i++)\n\t\t\t\tb->d[i]=0;\n\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t}\n\t\trr->top=top;\n\t\t}\n#endif\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\treturn(1);\n\t}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n\t BN_ULONG *t)\n\t{\n\tint n=n2/2,c1,c2;\n\tunsigned int neg,zero;\n\tBN_ULONG ln,lo,*p;\n#ifdef BN_COUNT\nprintf(" bn_mul_recursive %d * %d\\n",n2,n2);\n#endif\n#ifdef BN_MUL_COMBA\n if (n2 == 8)\n\t\t{\n\t\tbn_mul_comba8(r,a,b);\n\t\treturn;\n\t\t}\n#endif\n\tif (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t{\n\t\tbn_mul_normal(r,a,n2,b,n2);\n\t\treturn;\n\t\t}\n\tc1=bn_cmp_words(a,&(a[n]),n);\n\tc2=bn_cmp_words(&(b[n]),b,n);\n\tzero=neg=0;\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\t\tbreak;\n\tcase -2:\n\t\tbn_sub_words(t, &(a[n]),a, n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\t\tbreak;\n\tcase 2:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),b, &(b[n]),n);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\t\tbreak;\n\tcase 4:\n\t\tbn_sub_words(t, a, &(a[n]),n);\n\t\tbn_sub_words(&(t[n]),&(b[n]),b, n);\n\t\tbreak;\n\t\t}\n#ifdef BN_MUL_COMBA\n\tif (n == 4)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,8*sizeof(BN_ULONG));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse if (n == 8)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,16*sizeof(BN_ULONG));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tif (!zero)\n\t\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);\n\t\telse\n\t\t\tmemset(&(t[n2]),0,n2*sizeof(BN_ULONG));\n\t\tbn_mul_recursive(r,a,b,n,p);\n\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)\n\t{\n#ifdef BN_LLONG\n\tBN_ULLONG t;\n#else\n\tBN_ULONG bl,bh;\n#endif\n\tBN_ULONG t1,t2;\n\tBN_ULONG c1,c2,c3;\n\tc1=0;\n\tc2=0;\n\tc3=0;\n\tmul_add_c(a[0],b[0],c1,c2,c3);\n\tr[0]=c1;\n\tc1=0;\n\tmul_add_c(a[0],b[1],c2,c3,c1);\n\tmul_add_c(a[1],b[0],c2,c3,c1);\n\tr[1]=c2;\n\tc2=0;\n\tmul_add_c(a[2],b[0],c3,c1,c2);\n\tmul_add_c(a[1],b[1],c3,c1,c2);\n\tmul_add_c(a[0],b[2],c3,c1,c2);\n\tr[2]=c3;\n\tc3=0;\n\tmul_add_c(a[0],b[3],c1,c2,c3);\n\tmul_add_c(a[1],b[2],c1,c2,c3);\n\tmul_add_c(a[2],b[1],c1,c2,c3);\n\tmul_add_c(a[3],b[0],c1,c2,c3);\n\tr[3]=c1;\n\tc1=0;\n\tmul_add_c(a[3],b[1],c2,c3,c1);\n\tmul_add_c(a[2],b[2],c2,c3,c1);\n\tmul_add_c(a[1],b[3],c2,c3,c1);\n\tr[4]=c2;\n\tc2=0;\n\tmul_add_c(a[2],b[3],c3,c1,c2);\n\tmul_add_c(a[3],b[2],c3,c1,c2);\n\tr[5]=c3;\n\tc3=0;\n\tmul_add_c(a[3],b[3],c1,c2,c3);\n\tr[6]=c1;\n\tr[7]=c2;\n\t}'] |
35,035 | 0 | https://github.com/libav/libav/blob/fd7f59639c43f0ab6b83ad2c1ceccafc553d7845/libavcodec/aac.c/#L1553 | static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {
AACContext * ac = avccontext->priv_data;
GetBitContext gb;
enum RawDataBlockType elem_type;
int err, elem_id, data_size_tmp;
init_get_bits(&gb, buf, buf_size*8);
if (show_bits(&gb, 12) == 0xfff) {
if ((err = parse_adts_frame_header(ac, &gb)) < 0) {
av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
return -1;
}
}
while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
elem_id = get_bits(&gb, 4);
err = -1;
if(elem_type == TYPE_SCE && elem_id == 1 &&
!ac->che[TYPE_SCE][elem_id] && ac->che[TYPE_LFE][0]) {
ac->che[TYPE_SCE][elem_id] = ac->che[TYPE_LFE][0];
ac->che[TYPE_LFE][0] = NULL;
}
if(elem_type < TYPE_DSE) {
if(!ac->che[elem_type][elem_id])
return -1;
if(elem_type != TYPE_CCE)
ac->che[elem_type][elem_id]->coup.coupling_point = 4;
}
switch (elem_type) {
case TYPE_SCE:
err = decode_ics(ac, &ac->che[TYPE_SCE][elem_id]->ch[0], &gb, 0, 0);
break;
case TYPE_CPE:
err = decode_cpe(ac, &gb, elem_id);
break;
case TYPE_CCE:
err = decode_cce(ac, &gb, ac->che[TYPE_CCE][elem_id]);
break;
case TYPE_LFE:
err = decode_ics(ac, &ac->che[TYPE_LFE][elem_id]->ch[0], &gb, 0, 0);
break;
case TYPE_DSE:
skip_data_stream_element(&gb);
err = 0;
break;
case TYPE_PCE:
{
enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
if((err = decode_pce(ac, new_che_pos, &gb)))
break;
err = output_configure(ac, ac->che_pos, new_che_pos);
break;
}
case TYPE_FIL:
if (elem_id == 15)
elem_id += get_bits(&gb, 8) - 1;
while (elem_id > 0)
elem_id -= decode_extension_payload(ac, &gb, elem_id);
err = 0;
break;
default:
err = -1;
break;
}
if(err)
return err;
}
spectral_to_sample(ac);
if (!ac->is_saved) {
ac->is_saved = 1;
*data_size = 0;
return buf_size;
}
data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);
if(*data_size < data_size_tmp) {
av_log(avccontext, AV_LOG_ERROR,
"Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n",
*data_size, data_size_tmp);
return -1;
}
*data_size = data_size_tmp;
ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 1024, avccontext->channels);
return buf_size;
} | ['static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {\n AACContext * ac = avccontext->priv_data;\n GetBitContext gb;\n enum RawDataBlockType elem_type;\n int err, elem_id, data_size_tmp;\n init_get_bits(&gb, buf, buf_size*8);\n if (show_bits(&gb, 12) == 0xfff) {\n if ((err = parse_adts_frame_header(ac, &gb)) < 0) {\n av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\\n");\n return -1;\n }\n }\n while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {\n elem_id = get_bits(&gb, 4);\n err = -1;\n if(elem_type == TYPE_SCE && elem_id == 1 &&\n !ac->che[TYPE_SCE][elem_id] && ac->che[TYPE_LFE][0]) {\n ac->che[TYPE_SCE][elem_id] = ac->che[TYPE_LFE][0];\n ac->che[TYPE_LFE][0] = NULL;\n }\n if(elem_type < TYPE_DSE) {\n if(!ac->che[elem_type][elem_id])\n return -1;\n if(elem_type != TYPE_CCE)\n ac->che[elem_type][elem_id]->coup.coupling_point = 4;\n }\n switch (elem_type) {\n case TYPE_SCE:\n err = decode_ics(ac, &ac->che[TYPE_SCE][elem_id]->ch[0], &gb, 0, 0);\n break;\n case TYPE_CPE:\n err = decode_cpe(ac, &gb, elem_id);\n break;\n case TYPE_CCE:\n err = decode_cce(ac, &gb, ac->che[TYPE_CCE][elem_id]);\n break;\n case TYPE_LFE:\n err = decode_ics(ac, &ac->che[TYPE_LFE][elem_id]->ch[0], &gb, 0, 0);\n break;\n case TYPE_DSE:\n skip_data_stream_element(&gb);\n err = 0;\n break;\n case TYPE_PCE:\n {\n enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];\n memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));\n if((err = decode_pce(ac, new_che_pos, &gb)))\n break;\n err = output_configure(ac, ac->che_pos, new_che_pos);\n break;\n }\n case TYPE_FIL:\n if (elem_id == 15)\n elem_id += get_bits(&gb, 8) - 1;\n while (elem_id > 0)\n elem_id -= decode_extension_payload(ac, &gb, elem_id);\n err = 0;\n break;\n default:\n err = -1;\n break;\n }\n if(err)\n return err;\n }\n spectral_to_sample(ac);\n if (!ac->is_saved) {\n ac->is_saved = 1;\n *data_size = 0;\n return buf_size;\n }\n data_size_tmp = 1024 * avccontext->channels * sizeof(int16_t);\n if(*data_size < data_size_tmp) {\n av_log(avccontext, AV_LOG_ERROR,\n "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\\n",\n *data_size, data_size_tmp);\n return -1;\n }\n *data_size = data_size_tmp;\n ac->dsp.float_to_int16_interleave(data, (const float **)ac->output_data, 1024, avccontext->channels);\n return buf_size;\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 show_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 return tmp;\n}'] |
35,036 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/asn1/ameth_lib.c/#L243 | int EVP_PKEY_asn1_add_alias(int to, int from)
{
EVP_PKEY_ASN1_METHOD *ameth;
ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);
if (ameth == NULL)
return 0;
ameth->pkey_base_id = to;
if (!EVP_PKEY_asn1_add0(ameth)) {
EVP_PKEY_asn1_free(ameth);
return 0;
}
return 1;
} | ['int EVP_PKEY_asn1_add_alias(int to, int from)\n{\n EVP_PKEY_ASN1_METHOD *ameth;\n ameth = EVP_PKEY_asn1_new(from, ASN1_PKEY_ALIAS, NULL, NULL);\n if (ameth == NULL)\n return 0;\n ameth->pkey_base_id = to;\n if (!EVP_PKEY_asn1_add0(ameth)) {\n EVP_PKEY_asn1_free(ameth);\n return 0;\n }\n return 1;\n}', 'EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,\n const char *pem_str, const char *info)\n{\n EVP_PKEY_ASN1_METHOD *ameth = OPENSSL_zalloc(sizeof(*ameth));\n if (ameth == NULL)\n return NULL;\n ameth->pkey_id = id;\n ameth->pkey_base_id = id;\n ameth->pkey_flags = flags | ASN1_PKEY_DYNAMIC;\n if (info) {\n ameth->info = OPENSSL_strdup(info);\n if (!ameth->info)\n goto err;\n }\n if (pem_str) {\n ameth->pem_str = OPENSSL_strdup(pem_str);\n if (!ameth->pem_str)\n goto err;\n }\n return ameth;\n err:\n EVP_PKEY_asn1_free(ameth);\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#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth)\n{\n if (app_methods == NULL) {\n app_methods = sk_EVP_PKEY_ASN1_METHOD_new(ameth_cmp);\n if (app_methods == NULL)\n return 0;\n }\n if (!sk_EVP_PKEY_ASN1_METHOD_push(app_methods, ameth))\n return 0;\n sk_EVP_PKEY_ASN1_METHOD_sort(app_methods);\n return 1;\n}', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n if (str == NULL)\n return CRYPTO_malloc(num, file, line);\n if (num == 0) {\n CRYPTO_free(str);\n return NULL;\n }\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n void *ret;\n CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n ret = realloc(str, num);\n CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n return ret;\n }\n#else\n (void)file;\n (void)line;\n#endif\n return realloc(str, num);\n}', 'void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)\n{\n if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {\n OPENSSL_free(ameth->pem_str);\n OPENSSL_free(ameth->info);\n OPENSSL_free(ameth);\n }\n}'] |
35,037 | 0 | https://github.com/openssl/openssl/blob/54d00677f305375eee65a0c9edb5f0980c5f020f/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;
}
} | ['static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_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}'] |
35,038 | 0 | https://github.com/libav/libav/blob/7c44d716e76cbd1c29369563a8b384addd5e7c03/ffmpeg.c/#L3649 | static void new_data_stream(AVFormatContext *oc, int file_idx)
{
AVStream *st;
AVCodec *codec=NULL;
AVCodecContext *data_enc;
st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
new_output_stream(oc, file_idx);
data_enc = st->codec;
if (!data_stream_copy) {
fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\n");
ffmpeg_exit(1);
}
avcodec_get_context_defaults3(st->codec, codec);
data_enc->codec_type = AVMEDIA_TYPE_DATA;
if (data_codec_tag)
data_enc->codec_tag= data_codec_tag;
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[AVMEDIA_TYPE_DATA]->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
if (data_stream_copy) {
st->stream_copy = 1;
}
data_disable = 0;
av_freep(&data_codec_name);
data_stream_copy = 0;
} | ['static void new_data_stream(AVFormatContext *oc, int file_idx)\n{\n AVStream *st;\n AVCodec *codec=NULL;\n AVCodecContext *data_enc;\n st = av_new_stream(oc, oc->nb_streams < nb_streamid_map ? streamid_map[oc->nb_streams] : 0);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n ffmpeg_exit(1);\n }\n new_output_stream(oc, file_idx);\n data_enc = st->codec;\n if (!data_stream_copy) {\n fprintf(stderr, "Data stream encoding not supported yet (only streamcopy)\\n");\n ffmpeg_exit(1);\n }\n avcodec_get_context_defaults3(st->codec, codec);\n data_enc->codec_type = AVMEDIA_TYPE_DATA;\n if (data_codec_tag)\n data_enc->codec_tag= data_codec_tag;\n if (oc->oformat->flags & AVFMT_GLOBALHEADER) {\n data_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[AVMEDIA_TYPE_DATA]->flags |= CODEC_FLAG_GLOBAL_HEADER;\n }\n if (data_stream_copy) {\n st->stream_copy = 1;\n }\n data_disable = 0;\n av_freep(&data_codec_name);\n data_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n AVStream **streams;\n if (s->nb_streams >= INT_MAX/sizeof(*streams))\n return NULL;\n streams = av_realloc(s->streams, (s->nb_streams + 1) * sizeof(*streams));\n if (!streams)\n return NULL;\n s->streams = streams;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n if (!(st->info = av_mallocz(sizeof(*st->info)))) {\n av_free(st);\n return NULL;\n }\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n st->probe_packets = MAX_PROBE_PACKETS;\n av_set_pts_info(st, 33, 1, 90000);\n st->last_IP_pts = AV_NOPTS_VALUE;\n for(i=0; i<MAX_REORDER_DELAY+1; i++)\n st->pts_buffer[i]= AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n st->sample_aspect_ratio = (AVRational){0,1};\n s->streams[s->nb_streams++] = st;\n return st;\n}'] |
35,039 | 0 | https://github.com/libav/libav/blob/ec2ac9271c91633e5d88551867a7f03bb81852f1/libavcodec/adpcm.c/#L1140 | static int adpcm_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
ADPCMDecodeContext *c = avctx->priv_data;
ADPCMChannelStatus *cs;
int n, m, channel, i;
short *samples;
const uint8_t *src;
int st;
int count1, count2;
int nb_samples, coded_samples, out_bps, out_size;
nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);
if (nb_samples <= 0) {
av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
return AVERROR_INVALIDDATA;
}
out_bps = av_get_bytes_per_sample(avctx->sample_fmt);
out_size = nb_samples * avctx->channels * out_bps;
if (*data_size < out_size) {
av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n");
return AVERROR(EINVAL);
}
if (coded_samples) {
if (coded_samples != nb_samples)
av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
nb_samples = coded_samples;
out_size = nb_samples * avctx->channels * out_bps;
}
samples = data;
src = buf;
st = avctx->channels == 2 ? 1 : 0;
switch(avctx->codec->id) {
case CODEC_ID_ADPCM_IMA_QT:
for (channel = 0; channel < avctx->channels; channel++) {
int16_t predictor;
int step_index;
cs = &(c->status[channel]);
predictor = AV_RB16(src);
step_index = predictor & 0x7F;
predictor &= 0xFF80;
src += 2;
if (cs->step_index == step_index) {
int diff = (int)predictor - cs->predictor;
if (diff < 0)
diff = - diff;
if (diff > 0x7f)
goto update;
} else {
update:
cs->step_index = step_index;
cs->predictor = predictor;
}
if (cs->step_index > 88){
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
cs->step_index = 88;
}
samples = (short*)data + channel;
for (m = 0; m < 32; m++) {
*samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3);
samples += avctx->channels;
*samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4 , 3);
samples += avctx->channels;
src ++;
}
}
break;
case CODEC_ID_ADPCM_IMA_WAV:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
for(i=0; i<avctx->channels; i++){
cs = &(c->status[i]);
cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src);
cs->step_index = *src++;
if (cs->step_index > 88){
av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index);
cs->step_index = 88;
}
if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]);
}
for (n = (nb_samples - 1) / 8; n > 0; n--) {
for (i = 0; i < avctx->channels; i++) {
cs = &c->status[i];
for (m = 0; m < 4; m++) {
uint8_t v = *src++;
*samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
samples += avctx->channels;
*samples = adpcm_ima_expand_nibble(cs, v >> 4 , 3);
samples += avctx->channels;
}
samples -= 8 * avctx->channels - 1;
}
samples += 7 * avctx->channels;
}
break;
case CODEC_ID_ADPCM_4XM:
for (i = 0; i < avctx->channels; i++)
c->status[i].predictor= (int16_t)bytestream_get_le16(&src);
for (i = 0; i < avctx->channels; i++) {
c->status[i].step_index= (int16_t)bytestream_get_le16(&src);
c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
}
for (i = 0; i < avctx->channels; i++) {
samples = (short*)data + i;
cs = &c->status[i];
for (n = nb_samples >> 1; n > 0; n--, src++) {
uint8_t v = *src;
*samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
samples += avctx->channels;
*samples = adpcm_ima_expand_nibble(cs, v >> 4 , 4);
samples += avctx->channels;
}
}
break;
case CODEC_ID_ADPCM_MS:
{
int block_predictor;
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
block_predictor = av_clip(*src++, 0, 6);
c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
if (st) {
block_predictor = av_clip(*src++, 0, 6);
c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
}
c->status[0].idelta = (int16_t)bytestream_get_le16(&src);
if (st){
c->status[1].idelta = (int16_t)bytestream_get_le16(&src);
}
c->status[0].sample1 = bytestream_get_le16(&src);
if (st) c->status[1].sample1 = bytestream_get_le16(&src);
c->status[0].sample2 = bytestream_get_le16(&src);
if (st) c->status[1].sample2 = bytestream_get_le16(&src);
*samples++ = c->status[0].sample2;
if (st) *samples++ = c->status[1].sample2;
*samples++ = c->status[0].sample1;
if (st) *samples++ = c->status[1].sample1;
for(n = (nb_samples - 2) >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 );
*samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);
}
break;
}
case CODEC_ID_ADPCM_IMA_DK4:
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
for (channel = 0; channel < avctx->channels; channel++) {
cs = &c->status[channel];
cs->predictor = (int16_t)bytestream_get_le16(&src);
cs->step_index = *src++;
src++;
*samples++ = cs->predictor;
}
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
uint8_t v = *src;
*samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
}
break;
case CODEC_ID_ADPCM_IMA_DK3:
{
unsigned char last_byte = 0;
unsigned char nibble;
int decode_top_nibble_next = 0;
int end_of_packet = 0;
int diff_channel;
if (avctx->block_align != 0 && buf_size > avctx->block_align)
buf_size = avctx->block_align;
c->status[0].predictor = (int16_t)AV_RL16(src + 10);
c->status[1].predictor = (int16_t)AV_RL16(src + 12);
c->status[0].step_index = src[14];
c->status[1].step_index = src[15];
src += 16;
diff_channel = c->status[1].predictor;
while (1) {
DK3_GET_NEXT_NIBBLE();
adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
DK3_GET_NEXT_NIBBLE();
adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
diff_channel = (diff_channel + c->status[1].predictor) / 2;
*samples++ = c->status[0].predictor + c->status[1].predictor;
*samples++ = c->status[0].predictor - c->status[1].predictor;
DK3_GET_NEXT_NIBBLE();
adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
diff_channel = (diff_channel + c->status[1].predictor) / 2;
*samples++ = c->status[0].predictor + c->status[1].predictor;
*samples++ = c->status[0].predictor - c->status[1].predictor;
}
break;
}
case CODEC_ID_ADPCM_IMA_ISS:
for (channel = 0; channel < avctx->channels; channel++) {
cs = &c->status[channel];
cs->predictor = (int16_t)bytestream_get_le16(&src);
cs->step_index = *src++;
src++;
}
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
uint8_t v1, v2;
uint8_t v = *src;
if (st) {
v1 = v >> 4;
v2 = v & 0x0F;
} else {
v2 = v >> 4;
v1 = v & 0x0F;
}
*samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
}
break;
case CODEC_ID_ADPCM_IMA_WS:
while (src < buf + buf_size) {
uint8_t v = *src++;
*samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
}
break;
case CODEC_ID_ADPCM_XA:
while (buf_size >= 128) {
xa_decode(samples, src, &c->status[0], &c->status[1],
avctx->channels);
src += 128;
samples += 28 * 8;
buf_size -= 128;
}
break;
case CODEC_ID_ADPCM_IMA_EA_EACS:
src += 4;
for (i=0; i<=st; i++)
c->status[i].step_index = bytestream_get_le32(&src);
for (i=0; i<=st; i++)
c->status[i].predictor = bytestream_get_le32(&src);
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);
}
break;
case CODEC_ID_ADPCM_IMA_EA_SEAD:
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);
*samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);
}
break;
case CODEC_ID_ADPCM_EA:
{
int32_t previous_left_sample, previous_right_sample;
int32_t current_left_sample, current_right_sample;
int32_t next_left_sample, next_right_sample;
int32_t coeff1l, coeff2l, coeff1r, coeff2r;
uint8_t shift_left, shift_right;
src += 4;
current_left_sample = (int16_t)bytestream_get_le16(&src);
previous_left_sample = (int16_t)bytestream_get_le16(&src);
current_right_sample = (int16_t)bytestream_get_le16(&src);
previous_right_sample = (int16_t)bytestream_get_le16(&src);
for (count1 = 0; count1 < nb_samples / 28; count1++) {
coeff1l = ea_adpcm_table[ *src >> 4 ];
coeff2l = ea_adpcm_table[(*src >> 4 ) + 4];
coeff1r = ea_adpcm_table[*src & 0x0F];
coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];
src++;
shift_left = (*src >> 4 ) + 8;
shift_right = (*src & 0x0F) + 8;
src++;
for (count2 = 0; count2 < 28; count2++) {
next_left_sample = (int32_t)((*src & 0xF0) << 24) >> shift_left;
next_right_sample = (int32_t)((*src & 0x0F) << 28) >> shift_right;
src++;
next_left_sample = (next_left_sample +
(current_left_sample * coeff1l) +
(previous_left_sample * coeff2l) + 0x80) >> 8;
next_right_sample = (next_right_sample +
(current_right_sample * coeff1r) +
(previous_right_sample * coeff2r) + 0x80) >> 8;
previous_left_sample = current_left_sample;
current_left_sample = av_clip_int16(next_left_sample);
previous_right_sample = current_right_sample;
current_right_sample = av_clip_int16(next_right_sample);
*samples++ = (unsigned short)current_left_sample;
*samples++ = (unsigned short)current_right_sample;
}
}
if (src - buf == buf_size - 2)
src += 2;
break;
}
case CODEC_ID_ADPCM_EA_MAXIS_XA:
{
int coeff[2][2], shift[2];
for(channel = 0; channel < avctx->channels; channel++) {
for (i=0; i<2; i++)
coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];
shift[channel] = (*src & 0x0F) + 8;
src++;
}
for (count1 = 0; count1 < nb_samples / 2; count1++) {
for(i = 4; i >= 0; i-=4) {
for(channel = 0; channel < avctx->channels; channel++) {
int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel];
sample = (sample +
c->status[channel].sample1 * coeff[channel][0] +
c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
c->status[channel].sample2 = c->status[channel].sample1;
c->status[channel].sample1 = av_clip_int16(sample);
*samples++ = c->status[channel].sample1;
}
}
src+=avctx->channels;
}
src = buf + buf_size;
break;
}
case CODEC_ID_ADPCM_EA_R1:
case CODEC_ID_ADPCM_EA_R2:
case CODEC_ID_ADPCM_EA_R3: {
const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;
int32_t previous_sample, current_sample, next_sample;
int32_t coeff1, coeff2;
uint8_t shift;
unsigned int channel;
uint16_t *samplesC;
const uint8_t *srcC;
const uint8_t *src_end = buf + buf_size;
int count = 0;
src += 4;
for (channel=0; channel<avctx->channels; channel++) {
int32_t offset = (big_endian ? bytestream_get_be32(&src)
: bytestream_get_le32(&src))
+ (avctx->channels-channel-1) * 4;
if ((offset < 0) || (offset >= src_end - src - 4)) break;
srcC = src + offset;
samplesC = samples + channel;
if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {
current_sample = (int16_t)bytestream_get_le16(&srcC);
previous_sample = (int16_t)bytestream_get_le16(&srcC);
} else {
current_sample = c->status[channel].predictor;
previous_sample = c->status[channel].prev_sample;
}
for (count1 = 0; count1 < nb_samples / 28; count1++) {
if (*srcC == 0xEE) {
srcC++;
if (srcC > src_end - 30*2) break;
current_sample = (int16_t)bytestream_get_be16(&srcC);
previous_sample = (int16_t)bytestream_get_be16(&srcC);
for (count2=0; count2<28; count2++) {
*samplesC = (int16_t)bytestream_get_be16(&srcC);
samplesC += avctx->channels;
}
} else {
coeff1 = ea_adpcm_table[ *srcC>>4 ];
coeff2 = ea_adpcm_table[(*srcC>>4) + 4];
shift = (*srcC++ & 0x0F) + 8;
if (srcC > src_end - 14) break;
for (count2=0; count2<28; count2++) {
if (count2 & 1)
next_sample = (int32_t)((*srcC++ & 0x0F) << 28) >> shift;
else
next_sample = (int32_t)((*srcC & 0xF0) << 24) >> shift;
next_sample += (current_sample * coeff1) +
(previous_sample * coeff2);
next_sample = av_clip_int16(next_sample >> 8);
previous_sample = current_sample;
current_sample = next_sample;
*samplesC = current_sample;
samplesC += avctx->channels;
}
}
}
if (!count) {
count = count1;
} else if (count != count1) {
av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
count = FFMAX(count, count1);
}
if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {
c->status[channel].predictor = current_sample;
c->status[channel].prev_sample = previous_sample;
}
}
out_size = count * 28 * avctx->channels * out_bps;
src = src_end;
break;
}
case CODEC_ID_ADPCM_EA_XAS:
for (channel=0; channel<avctx->channels; channel++) {
int coeff[2][4], shift[4];
short *s2, *s = &samples[channel];
for (n=0; n<4; n++, s+=32*avctx->channels) {
for (i=0; i<2; i++)
coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i];
shift[n] = (src[2]&0x0F) + 8;
for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels)
s2[0] = (src[0]&0xF0) + (src[1]<<8);
}
for (m=2; m<32; m+=2) {
s = &samples[m*avctx->channels + channel];
for (n=0; n<4; n++, src++, s+=32*avctx->channels) {
for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {
int level = (int32_t)((*src & (0xF0>>i)) << (24+i)) >> shift[n];
int pred = s2[-1*avctx->channels] * coeff[0][n]
+ s2[-2*avctx->channels] * coeff[1][n];
s2[0] = av_clip_int16((level + pred + 0x80) >> 8);
}
}
}
}
break;
case CODEC_ID_ADPCM_IMA_AMV:
case CODEC_ID_ADPCM_IMA_SMJPEG:
c->status[0].predictor = (int16_t)bytestream_get_le16(&src);
c->status[0].step_index = bytestream_get_le16(&src);
if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
src+=4;
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
char hi, lo;
lo = *src & 0x0F;
hi = *src >> 4;
if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)
FFSWAP(char, hi, lo);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
lo, 3);
*samples++ = adpcm_ima_expand_nibble(&c->status[0],
hi, 3);
}
break;
case CODEC_ID_ADPCM_CT:
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
uint8_t v = *src;
*samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );
*samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
}
break;
case CODEC_ID_ADPCM_SBPRO_4:
case CODEC_ID_ADPCM_SBPRO_3:
case CODEC_ID_ADPCM_SBPRO_2:
if (!c->status[0].step_index) {
*samples++ = 128 * (*src++ - 0x80);
if (st)
*samples++ = 128 * (*src++ - 0x80);
c->status[0].step_index = 1;
nb_samples--;
}
if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 4, 4, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
src[0] & 0x0F, 4, 0);
}
} else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {
for (n = nb_samples / 3; n > 0; n--, src++) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 5 , 3, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
(src[0] >> 2) & 0x07, 3, 0);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] & 0x03, 2, 0);
}
} else {
for (n = nb_samples >> (2 - st); n > 0; n--, src++) {
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
src[0] >> 6 , 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
(src[0] >> 4) & 0x03, 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
(src[0] >> 2) & 0x03, 2, 2);
*samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
src[0] & 0x03, 2, 2);
}
}
break;
case CODEC_ID_ADPCM_SWF:
{
GetBitContext gb;
const int *table;
int k0, signmask, nb_bits, count;
int size = buf_size*8;
init_get_bits(&gb, buf, size);
nb_bits = get_bits(&gb, 2)+2;
table = swf_index_tables[nb_bits-2];
k0 = 1 << (nb_bits-2);
signmask = 1 << (nb_bits-1);
while (get_bits_count(&gb) <= size - 22*avctx->channels) {
for (i = 0; i < avctx->channels; i++) {
*samples++ = c->status[i].predictor = get_sbits(&gb, 16);
c->status[i].step_index = get_bits(&gb, 6);
}
for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
int i;
for (i = 0; i < avctx->channels; i++) {
int delta = get_bits(&gb, nb_bits);
int step = ff_adpcm_step_table[c->status[i].step_index];
long vpdiff = 0;
int k = k0;
do {
if (delta & k)
vpdiff += step;
step >>= 1;
k >>= 1;
} while(k);
vpdiff += step;
if (delta & signmask)
c->status[i].predictor -= vpdiff;
else
c->status[i].predictor += vpdiff;
c->status[i].step_index += table[delta & (~signmask)];
c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
c->status[i].predictor = av_clip_int16(c->status[i].predictor);
*samples++ = c->status[i].predictor;
}
}
}
src += buf_size;
break;
}
case CODEC_ID_ADPCM_YAMAHA:
for (n = nb_samples >> (1 - st); n > 0; n--, src++) {
uint8_t v = *src;
*samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
*samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );
}
break;
case CODEC_ID_ADPCM_THP:
{
int table[2][16];
int prev[2][2];
int ch;
src += 4;
src += 4;
for (i = 0; i < 32; i++)
table[0][i] = (int16_t)bytestream_get_be16(&src);
for (i = 0; i < 4; i++)
prev[0][i] = (int16_t)bytestream_get_be16(&src);
for (ch = 0; ch <= st; ch++) {
samples = (unsigned short *) data + ch;
for (i = 0; i < nb_samples / 14; i++) {
int index = (*src >> 4) & 7;
unsigned int exp = 28 - (*src++ & 15);
int factor1 = table[ch][index * 2];
int factor2 = table[ch][index * 2 + 1];
for (n = 0; n < 14; n++) {
int32_t sampledat;
if(n&1) sampledat= *src++ <<28;
else sampledat= (*src&0xF0)<<24;
sampledat = ((prev[ch][0]*factor1
+ prev[ch][1]*factor2) >> 11) + (sampledat>>exp);
*samples = av_clip_int16(sampledat);
prev[ch][1] = prev[ch][0];
prev[ch][0] = *samples++;
samples += st;
}
}
}
break;
}
default:
return -1;
}
*data_size = out_size;
return src - buf;
} | ['static int adpcm_decode_frame(AVCodecContext *avctx,\n void *data, int *data_size,\n AVPacket *avpkt)\n{\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n ADPCMDecodeContext *c = avctx->priv_data;\n ADPCMChannelStatus *cs;\n int n, m, channel, i;\n short *samples;\n const uint8_t *src;\n int st;\n int count1, count2;\n int nb_samples, coded_samples, out_bps, out_size;\n nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples);\n if (nb_samples <= 0) {\n av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\\n");\n return AVERROR_INVALIDDATA;\n }\n out_bps = av_get_bytes_per_sample(avctx->sample_fmt);\n out_size = nb_samples * avctx->channels * out_bps;\n if (*data_size < out_size) {\n av_log(avctx, AV_LOG_ERROR, "output buffer is too small\\n");\n return AVERROR(EINVAL);\n }\n if (coded_samples) {\n if (coded_samples != nb_samples)\n av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\\n");\n nb_samples = coded_samples;\n out_size = nb_samples * avctx->channels * out_bps;\n }\n samples = data;\n src = buf;\n st = avctx->channels == 2 ? 1 : 0;\n switch(avctx->codec->id) {\n case CODEC_ID_ADPCM_IMA_QT:\n for (channel = 0; channel < avctx->channels; channel++) {\n int16_t predictor;\n int step_index;\n cs = &(c->status[channel]);\n predictor = AV_RB16(src);\n step_index = predictor & 0x7F;\n predictor &= 0xFF80;\n src += 2;\n if (cs->step_index == step_index) {\n int diff = (int)predictor - cs->predictor;\n if (diff < 0)\n diff = - diff;\n if (diff > 0x7f)\n goto update;\n } else {\n update:\n cs->step_index = step_index;\n cs->predictor = predictor;\n }\n if (cs->step_index > 88){\n av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\\n", cs->step_index);\n cs->step_index = 88;\n }\n samples = (short*)data + channel;\n for (m = 0; m < 32; m++) {\n *samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3);\n samples += avctx->channels;\n *samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4 , 3);\n samples += avctx->channels;\n src ++;\n }\n }\n break;\n case CODEC_ID_ADPCM_IMA_WAV:\n if (avctx->block_align != 0 && buf_size > avctx->block_align)\n buf_size = avctx->block_align;\n for(i=0; i<avctx->channels; i++){\n cs = &(c->status[i]);\n cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src);\n cs->step_index = *src++;\n if (cs->step_index > 88){\n av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\\n", cs->step_index);\n cs->step_index = 88;\n }\n if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\\n", src[-1]);\n }\n for (n = (nb_samples - 1) / 8; n > 0; n--) {\n for (i = 0; i < avctx->channels; i++) {\n cs = &c->status[i];\n for (m = 0; m < 4; m++) {\n uint8_t v = *src++;\n *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);\n samples += avctx->channels;\n *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 3);\n samples += avctx->channels;\n }\n samples -= 8 * avctx->channels - 1;\n }\n samples += 7 * avctx->channels;\n }\n break;\n case CODEC_ID_ADPCM_4XM:\n for (i = 0; i < avctx->channels; i++)\n c->status[i].predictor= (int16_t)bytestream_get_le16(&src);\n for (i = 0; i < avctx->channels; i++) {\n c->status[i].step_index= (int16_t)bytestream_get_le16(&src);\n c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);\n }\n for (i = 0; i < avctx->channels; i++) {\n samples = (short*)data + i;\n cs = &c->status[i];\n for (n = nb_samples >> 1; n > 0; n--, src++) {\n uint8_t v = *src;\n *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);\n samples += avctx->channels;\n *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 4);\n samples += avctx->channels;\n }\n }\n break;\n case CODEC_ID_ADPCM_MS:\n {\n int block_predictor;\n if (avctx->block_align != 0 && buf_size > avctx->block_align)\n buf_size = avctx->block_align;\n block_predictor = av_clip(*src++, 0, 6);\n c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];\n c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];\n if (st) {\n block_predictor = av_clip(*src++, 0, 6);\n c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];\n c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];\n }\n c->status[0].idelta = (int16_t)bytestream_get_le16(&src);\n if (st){\n c->status[1].idelta = (int16_t)bytestream_get_le16(&src);\n }\n c->status[0].sample1 = bytestream_get_le16(&src);\n if (st) c->status[1].sample1 = bytestream_get_le16(&src);\n c->status[0].sample2 = bytestream_get_le16(&src);\n if (st) c->status[1].sample2 = bytestream_get_le16(&src);\n *samples++ = c->status[0].sample2;\n if (st) *samples++ = c->status[1].sample2;\n *samples++ = c->status[0].sample1;\n if (st) *samples++ = c->status[1].sample1;\n for(n = (nb_samples - 2) >> (1 - st); n > 0; n--, src++) {\n *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 );\n *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F);\n }\n break;\n }\n case CODEC_ID_ADPCM_IMA_DK4:\n if (avctx->block_align != 0 && buf_size > avctx->block_align)\n buf_size = avctx->block_align;\n for (channel = 0; channel < avctx->channels; channel++) {\n cs = &c->status[channel];\n cs->predictor = (int16_t)bytestream_get_le16(&src);\n cs->step_index = *src++;\n src++;\n *samples++ = cs->predictor;\n }\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n uint8_t v = *src;\n *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3);\n *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);\n }\n break;\n case CODEC_ID_ADPCM_IMA_DK3:\n {\n unsigned char last_byte = 0;\n unsigned char nibble;\n int decode_top_nibble_next = 0;\n int end_of_packet = 0;\n int diff_channel;\n if (avctx->block_align != 0 && buf_size > avctx->block_align)\n buf_size = avctx->block_align;\n c->status[0].predictor = (int16_t)AV_RL16(src + 10);\n c->status[1].predictor = (int16_t)AV_RL16(src + 12);\n c->status[0].step_index = src[14];\n c->status[1].step_index = src[15];\n src += 16;\n diff_channel = c->status[1].predictor;\n while (1) {\n DK3_GET_NEXT_NIBBLE();\n adpcm_ima_expand_nibble(&c->status[0], nibble, 3);\n DK3_GET_NEXT_NIBBLE();\n adpcm_ima_expand_nibble(&c->status[1], nibble, 3);\n diff_channel = (diff_channel + c->status[1].predictor) / 2;\n *samples++ = c->status[0].predictor + c->status[1].predictor;\n *samples++ = c->status[0].predictor - c->status[1].predictor;\n DK3_GET_NEXT_NIBBLE();\n adpcm_ima_expand_nibble(&c->status[0], nibble, 3);\n diff_channel = (diff_channel + c->status[1].predictor) / 2;\n *samples++ = c->status[0].predictor + c->status[1].predictor;\n *samples++ = c->status[0].predictor - c->status[1].predictor;\n }\n break;\n }\n case CODEC_ID_ADPCM_IMA_ISS:\n for (channel = 0; channel < avctx->channels; channel++) {\n cs = &c->status[channel];\n cs->predictor = (int16_t)bytestream_get_le16(&src);\n cs->step_index = *src++;\n src++;\n }\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n uint8_t v1, v2;\n uint8_t v = *src;\n if (st) {\n v1 = v >> 4;\n v2 = v & 0x0F;\n } else {\n v2 = v >> 4;\n v1 = v & 0x0F;\n }\n *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);\n *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);\n }\n break;\n case CODEC_ID_ADPCM_IMA_WS:\n while (src < buf + buf_size) {\n uint8_t v = *src++;\n *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3);\n *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);\n }\n break;\n case CODEC_ID_ADPCM_XA:\n while (buf_size >= 128) {\n xa_decode(samples, src, &c->status[0], &c->status[1],\n avctx->channels);\n src += 128;\n samples += 28 * 8;\n buf_size -= 128;\n }\n break;\n case CODEC_ID_ADPCM_IMA_EA_EACS:\n src += 4;\n for (i=0; i<=st; i++)\n c->status[i].step_index = bytestream_get_le32(&src);\n for (i=0; i<=st; i++)\n c->status[i].predictor = bytestream_get_le32(&src);\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n *samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3);\n *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3);\n }\n break;\n case CODEC_ID_ADPCM_IMA_EA_SEAD:\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6);\n *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6);\n }\n break;\n case CODEC_ID_ADPCM_EA:\n {\n int32_t previous_left_sample, previous_right_sample;\n int32_t current_left_sample, current_right_sample;\n int32_t next_left_sample, next_right_sample;\n int32_t coeff1l, coeff2l, coeff1r, coeff2r;\n uint8_t shift_left, shift_right;\n src += 4;\n current_left_sample = (int16_t)bytestream_get_le16(&src);\n previous_left_sample = (int16_t)bytestream_get_le16(&src);\n current_right_sample = (int16_t)bytestream_get_le16(&src);\n previous_right_sample = (int16_t)bytestream_get_le16(&src);\n for (count1 = 0; count1 < nb_samples / 28; count1++) {\n coeff1l = ea_adpcm_table[ *src >> 4 ];\n coeff2l = ea_adpcm_table[(*src >> 4 ) + 4];\n coeff1r = ea_adpcm_table[*src & 0x0F];\n coeff2r = ea_adpcm_table[(*src & 0x0F) + 4];\n src++;\n shift_left = (*src >> 4 ) + 8;\n shift_right = (*src & 0x0F) + 8;\n src++;\n for (count2 = 0; count2 < 28; count2++) {\n next_left_sample = (int32_t)((*src & 0xF0) << 24) >> shift_left;\n next_right_sample = (int32_t)((*src & 0x0F) << 28) >> shift_right;\n src++;\n next_left_sample = (next_left_sample +\n (current_left_sample * coeff1l) +\n (previous_left_sample * coeff2l) + 0x80) >> 8;\n next_right_sample = (next_right_sample +\n (current_right_sample * coeff1r) +\n (previous_right_sample * coeff2r) + 0x80) >> 8;\n previous_left_sample = current_left_sample;\n current_left_sample = av_clip_int16(next_left_sample);\n previous_right_sample = current_right_sample;\n current_right_sample = av_clip_int16(next_right_sample);\n *samples++ = (unsigned short)current_left_sample;\n *samples++ = (unsigned short)current_right_sample;\n }\n }\n if (src - buf == buf_size - 2)\n src += 2;\n break;\n }\n case CODEC_ID_ADPCM_EA_MAXIS_XA:\n {\n int coeff[2][2], shift[2];\n for(channel = 0; channel < avctx->channels; channel++) {\n for (i=0; i<2; i++)\n coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i];\n shift[channel] = (*src & 0x0F) + 8;\n src++;\n }\n for (count1 = 0; count1 < nb_samples / 2; count1++) {\n for(i = 4; i >= 0; i-=4) {\n for(channel = 0; channel < avctx->channels; channel++) {\n int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel];\n sample = (sample +\n c->status[channel].sample1 * coeff[channel][0] +\n c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;\n c->status[channel].sample2 = c->status[channel].sample1;\n c->status[channel].sample1 = av_clip_int16(sample);\n *samples++ = c->status[channel].sample1;\n }\n }\n src+=avctx->channels;\n }\n src = buf + buf_size;\n break;\n }\n case CODEC_ID_ADPCM_EA_R1:\n case CODEC_ID_ADPCM_EA_R2:\n case CODEC_ID_ADPCM_EA_R3: {\n const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3;\n int32_t previous_sample, current_sample, next_sample;\n int32_t coeff1, coeff2;\n uint8_t shift;\n unsigned int channel;\n uint16_t *samplesC;\n const uint8_t *srcC;\n const uint8_t *src_end = buf + buf_size;\n int count = 0;\n src += 4;\n for (channel=0; channel<avctx->channels; channel++) {\n int32_t offset = (big_endian ? bytestream_get_be32(&src)\n : bytestream_get_le32(&src))\n + (avctx->channels-channel-1) * 4;\n if ((offset < 0) || (offset >= src_end - src - 4)) break;\n srcC = src + offset;\n samplesC = samples + channel;\n if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) {\n current_sample = (int16_t)bytestream_get_le16(&srcC);\n previous_sample = (int16_t)bytestream_get_le16(&srcC);\n } else {\n current_sample = c->status[channel].predictor;\n previous_sample = c->status[channel].prev_sample;\n }\n for (count1 = 0; count1 < nb_samples / 28; count1++) {\n if (*srcC == 0xEE) {\n srcC++;\n if (srcC > src_end - 30*2) break;\n current_sample = (int16_t)bytestream_get_be16(&srcC);\n previous_sample = (int16_t)bytestream_get_be16(&srcC);\n for (count2=0; count2<28; count2++) {\n *samplesC = (int16_t)bytestream_get_be16(&srcC);\n samplesC += avctx->channels;\n }\n } else {\n coeff1 = ea_adpcm_table[ *srcC>>4 ];\n coeff2 = ea_adpcm_table[(*srcC>>4) + 4];\n shift = (*srcC++ & 0x0F) + 8;\n if (srcC > src_end - 14) break;\n for (count2=0; count2<28; count2++) {\n if (count2 & 1)\n next_sample = (int32_t)((*srcC++ & 0x0F) << 28) >> shift;\n else\n next_sample = (int32_t)((*srcC & 0xF0) << 24) >> shift;\n next_sample += (current_sample * coeff1) +\n (previous_sample * coeff2);\n next_sample = av_clip_int16(next_sample >> 8);\n previous_sample = current_sample;\n current_sample = next_sample;\n *samplesC = current_sample;\n samplesC += avctx->channels;\n }\n }\n }\n if (!count) {\n count = count1;\n } else if (count != count1) {\n av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\\n");\n count = FFMAX(count, count1);\n }\n if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) {\n c->status[channel].predictor = current_sample;\n c->status[channel].prev_sample = previous_sample;\n }\n }\n out_size = count * 28 * avctx->channels * out_bps;\n src = src_end;\n break;\n }\n case CODEC_ID_ADPCM_EA_XAS:\n for (channel=0; channel<avctx->channels; channel++) {\n int coeff[2][4], shift[4];\n short *s2, *s = &samples[channel];\n for (n=0; n<4; n++, s+=32*avctx->channels) {\n for (i=0; i<2; i++)\n coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i];\n shift[n] = (src[2]&0x0F) + 8;\n for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels)\n s2[0] = (src[0]&0xF0) + (src[1]<<8);\n }\n for (m=2; m<32; m+=2) {\n s = &samples[m*avctx->channels + channel];\n for (n=0; n<4; n++, src++, s+=32*avctx->channels) {\n for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) {\n int level = (int32_t)((*src & (0xF0>>i)) << (24+i)) >> shift[n];\n int pred = s2[-1*avctx->channels] * coeff[0][n]\n + s2[-2*avctx->channels] * coeff[1][n];\n s2[0] = av_clip_int16((level + pred + 0x80) >> 8);\n }\n }\n }\n }\n break;\n case CODEC_ID_ADPCM_IMA_AMV:\n case CODEC_ID_ADPCM_IMA_SMJPEG:\n c->status[0].predictor = (int16_t)bytestream_get_le16(&src);\n c->status[0].step_index = bytestream_get_le16(&src);\n if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)\n src+=4;\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n char hi, lo;\n lo = *src & 0x0F;\n hi = *src >> 4;\n if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV)\n FFSWAP(char, hi, lo);\n *samples++ = adpcm_ima_expand_nibble(&c->status[0],\n lo, 3);\n *samples++ = adpcm_ima_expand_nibble(&c->status[0],\n hi, 3);\n }\n break;\n case CODEC_ID_ADPCM_CT:\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n uint8_t v = *src;\n *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 );\n *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);\n }\n break;\n case CODEC_ID_ADPCM_SBPRO_4:\n case CODEC_ID_ADPCM_SBPRO_3:\n case CODEC_ID_ADPCM_SBPRO_2:\n if (!c->status[0].step_index) {\n *samples++ = 128 * (*src++ - 0x80);\n if (st)\n *samples++ = 128 * (*src++ - 0x80);\n c->status[0].step_index = 1;\n nb_samples--;\n }\n if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) {\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n src[0] >> 4, 4, 0);\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],\n src[0] & 0x0F, 4, 0);\n }\n } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) {\n for (n = nb_samples / 3; n > 0; n--, src++) {\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n src[0] >> 5 , 3, 0);\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n (src[0] >> 2) & 0x07, 3, 0);\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n src[0] & 0x03, 2, 0);\n }\n } else {\n for (n = nb_samples >> (2 - st); n > 0; n--, src++) {\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n src[0] >> 6 , 2, 2);\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],\n (src[0] >> 4) & 0x03, 2, 2);\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],\n (src[0] >> 2) & 0x03, 2, 2);\n *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],\n src[0] & 0x03, 2, 2);\n }\n }\n break;\n case CODEC_ID_ADPCM_SWF:\n {\n GetBitContext gb;\n const int *table;\n int k0, signmask, nb_bits, count;\n int size = buf_size*8;\n init_get_bits(&gb, buf, size);\n nb_bits = get_bits(&gb, 2)+2;\n table = swf_index_tables[nb_bits-2];\n k0 = 1 << (nb_bits-2);\n signmask = 1 << (nb_bits-1);\n while (get_bits_count(&gb) <= size - 22*avctx->channels) {\n for (i = 0; i < avctx->channels; i++) {\n *samples++ = c->status[i].predictor = get_sbits(&gb, 16);\n c->status[i].step_index = get_bits(&gb, 6);\n }\n for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {\n int i;\n for (i = 0; i < avctx->channels; i++) {\n int delta = get_bits(&gb, nb_bits);\n int step = ff_adpcm_step_table[c->status[i].step_index];\n long vpdiff = 0;\n int k = k0;\n do {\n if (delta & k)\n vpdiff += step;\n step >>= 1;\n k >>= 1;\n } while(k);\n vpdiff += step;\n if (delta & signmask)\n c->status[i].predictor -= vpdiff;\n else\n c->status[i].predictor += vpdiff;\n c->status[i].step_index += table[delta & (~signmask)];\n c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);\n c->status[i].predictor = av_clip_int16(c->status[i].predictor);\n *samples++ = c->status[i].predictor;\n }\n }\n }\n src += buf_size;\n break;\n }\n case CODEC_ID_ADPCM_YAMAHA:\n for (n = nb_samples >> (1 - st); n > 0; n--, src++) {\n uint8_t v = *src;\n *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);\n *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 );\n }\n break;\n case CODEC_ID_ADPCM_THP:\n {\n int table[2][16];\n int prev[2][2];\n int ch;\n src += 4;\n src += 4;\n for (i = 0; i < 32; i++)\n table[0][i] = (int16_t)bytestream_get_be16(&src);\n for (i = 0; i < 4; i++)\n prev[0][i] = (int16_t)bytestream_get_be16(&src);\n for (ch = 0; ch <= st; ch++) {\n samples = (unsigned short *) data + ch;\n for (i = 0; i < nb_samples / 14; i++) {\n int index = (*src >> 4) & 7;\n unsigned int exp = 28 - (*src++ & 15);\n int factor1 = table[ch][index * 2];\n int factor2 = table[ch][index * 2 + 1];\n for (n = 0; n < 14; n++) {\n int32_t sampledat;\n if(n&1) sampledat= *src++ <<28;\n else sampledat= (*src&0xF0)<<24;\n sampledat = ((prev[ch][0]*factor1\n + prev[ch][1]*factor2) >> 11) + (sampledat>>exp);\n *samples = av_clip_int16(sampledat);\n prev[ch][1] = prev[ch][0];\n prev[ch][0] = *samples++;\n samples += st;\n }\n }\n }\n break;\n }\n default:\n return -1;\n }\n *data_size = out_size;\n return src - buf;\n}'] |
35,040 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/objects/o_names.c/#L97 | int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
int (*cmp_func) (const char *, const char *),
void (*free_func) (const char *, int, const char *))
{
int ret;
int i;
NAME_FUNCS *name_funcs;
if (name_funcs_stack == NULL) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
name_funcs_stack = sk_NAME_FUNCS_new_null();
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
}
if (name_funcs_stack == NULL) {
return (0);
}
ret = names_type_num;
names_type_num++;
for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
if (name_funcs == NULL) {
OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
return (0);
}
name_funcs->hash_func = lh_strhash;
name_funcs->cmp_func = OPENSSL_strcmp;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
}
name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
if (hash_func != NULL)
name_funcs->hash_func = hash_func;
if (cmp_func != NULL)
name_funcs->cmp_func = cmp_func;
if (free_func != NULL)
name_funcs->free_func = free_func;
return (ret);
} | ['int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),\n int (*cmp_func) (const char *, const char *),\n void (*free_func) (const char *, int, const char *))\n{\n int ret;\n int i;\n NAME_FUNCS *name_funcs;\n if (name_funcs_stack == NULL) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs_stack = sk_NAME_FUNCS_new_null();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n }\n if (name_funcs_stack == NULL) {\n return (0);\n }\n ret = names_type_num;\n names_type_num++;\n for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n if (name_funcs == NULL) {\n OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);\n return (0);\n }\n name_funcs->hash_func = lh_strhash;\n name_funcs->cmp_func = OPENSSL_strcmp;\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n }\n name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);\n if (hash_func != NULL)\n name_funcs->hash_func = hash_func;\n if (cmp_func != NULL)\n name_funcs->cmp_func = cmp_func;\n if (free_func != NULL)\n name_funcs->free_func = free_func;\n return (ret);\n}', 'int CRYPTO_mem_ctrl(int mode)\n{\n#ifndef CRYPTO_MDEBUG\n return mode - mode;\n#else\n int ret = mh_mode;\n CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);\n switch (mode) {\n default:\n break;\n case CRYPTO_MEM_CHECK_ON:\n mh_mode = CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_OFF:\n mh_mode = 0;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_DISABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n CRYPTO_THREADID cur;\n CRYPTO_THREADID_current(&cur);\n if (!num_disable\n || CRYPTO_THREADID_cmp(&disabling_threadid, &cur)) {\n CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);\n CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2);\n CRYPTO_w_lock(CRYPTO_LOCK_MALLOC);\n mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;\n CRYPTO_THREADID_cpy(&disabling_threadid, &cur);\n }\n num_disable++;\n }\n break;\n case CRYPTO_MEM_CHECK_ENABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n if (num_disable) {\n num_disable--;\n if (num_disable == 0) {\n mh_mode |= CRYPTO_MEM_CHECK_ENABLE;\n CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2);\n }\n }\n }\n break;\n }\n CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC);\n return (ret);\n#endif\n}', '_STACK *sk_new_null(void)\n{\n return sk_new((int (*)(const void *, const void *))0);\n}', '_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#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'int sk_num(const _STACK *st)\n{\n if (st == NULL)\n return -1;\n return st->num;\n}', 'int sk_push(_STACK *st, void *data)\n{\n return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n char **s;\n if (st == NULL)\n return 0;\n if (st->num_alloc <= st->num + 1) {\n s = OPENSSL_realloc((char *)st->data,\n (unsigned int)sizeof(char *) * st->num_alloc * 2);\n if (s == NULL)\n return (0);\n st->data = s;\n st->num_alloc *= 2;\n }\n if ((loc >= (int)st->num) || (loc < 0))\n st->data[st->num] = data;\n else {\n memmove(&(st->data[loc + 1]),\n &(st->data[loc]), sizeof(char *) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return (st->num);\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}'] |
35,041 | 0 | https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/x509v3/v3_sxnet.c/#L257 | ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)
{
ASN1_INTEGER *izone;
ASN1_OCTET_STRING *oct;
if ((izone = ASN1_INTEGER_new()) == NULL
|| !ASN1_INTEGER_set(izone, lzone)) {
X509V3err(X509V3_F_SXNET_GET_ID_ULONG, ERR_R_MALLOC_FAILURE);
ASN1_INTEGER_free(izone);
return NULL;
}
oct = SXNET_get_id_INTEGER(sx, izone);
ASN1_INTEGER_free(izone);
return oct;
} | ['ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone)\n{\n ASN1_INTEGER *izone;\n ASN1_OCTET_STRING *oct;\n if ((izone = ASN1_INTEGER_new()) == NULL\n || !ASN1_INTEGER_set(izone, lzone)) {\n X509V3err(X509V3_F_SXNET_GET_ID_ULONG, ERR_R_MALLOC_FAILURE);\n ASN1_INTEGER_free(izone);\n return NULL;\n }\n oct = SXNET_get_id_INTEGER(sx, izone);\n ASN1_INTEGER_free(izone);\n return oct;\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}', 'void ASN1_STRING_free(ASN1_STRING *a)\n{\n if (a == NULL)\n return;\n if (!(a->flags & ASN1_STRING_FLAG_NDEF))\n OPENSSL_free(a->data);\n if (!(a->flags & ASN1_STRING_FLAG_EMBED))\n OPENSSL_free(a);\n}'] |
35,042 | 0 | https://github.com/openssl/openssl/blob/535bc8faf69dc4ff39e2ee99195b268cf99b9569/crypto/x509/x509_vfy.c/#L626 | static int check_chain_extensions(X509_STORE_CTX *ctx)
{
int i, ok = 0, must_be_ca, plen = 0;
X509 *x;
int (*cb) (int xok, X509_STORE_CTX *xctx);
int proxy_path_length = 0;
int purpose;
int allow_proxy_certs;
cb = ctx->verify_cb;
must_be_ca = -1;
if (ctx->parent) {
allow_proxy_certs = 0;
purpose = X509_PURPOSE_CRL_SIGN;
} else {
allow_proxy_certs =
! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
allow_proxy_certs = 1;
purpose = ctx->param->purpose;
}
for (i = 0; i < ctx->last_untrusted; i++) {
int ret;
x = sk_X509_value(ctx->chain, i);
if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
&& (x->ex_flags & EXFLAG_CRITICAL)) {
ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) {
ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
ret = X509_check_ca(x);
switch (must_be_ca) {
case -1:
if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1) && (ret != 0)) {
ret = 0;
ctx->error = X509_V_ERR_INVALID_CA;
} else
ret = 1;
break;
case 0:
if (ret != 0) {
ret = 0;
ctx->error = X509_V_ERR_INVALID_NON_CA;
} else
ret = 1;
break;
default:
if ((ret == 0)
|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1))) {
ret = 0;
ctx->error = X509_V_ERR_INVALID_CA;
} else
ret = 1;
break;
}
if (ret == 0) {
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
if (ctx->param->purpose > 0) {
ret = X509_check_purpose(x, purpose, must_be_ca > 0);
if ((ret == 0)
|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1))) {
ctx->error = X509_V_ERR_INVALID_PURPOSE;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
}
if ((i > 1) && !(x->ex_flags & EXFLAG_SI)
&& (x->ex_pathlen != -1)
&& (plen > (x->ex_pathlen + proxy_path_length + 1))) {
ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
if (!(x->ex_flags & EXFLAG_SI))
plen++;
if (x->ex_flags & EXFLAG_PROXY) {
if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) {
ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
proxy_path_length++;
must_be_ca = 0;
} else
must_be_ca = 1;
}
ok = 1;
end:
return ok;
} | ['static int check_chain_extensions(X509_STORE_CTX *ctx)\n{\n int i, ok = 0, must_be_ca, plen = 0;\n X509 *x;\n int (*cb) (int xok, X509_STORE_CTX *xctx);\n int proxy_path_length = 0;\n int purpose;\n int allow_proxy_certs;\n cb = ctx->verify_cb;\n must_be_ca = -1;\n if (ctx->parent) {\n allow_proxy_certs = 0;\n purpose = X509_PURPOSE_CRL_SIGN;\n } else {\n allow_proxy_certs =\n ! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);\n if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))\n allow_proxy_certs = 1;\n purpose = ctx->param->purpose;\n }\n for (i = 0; i < ctx->last_untrusted; i++) {\n int ret;\n x = sk_X509_value(ctx->chain, i);\n if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)\n && (x->ex_flags & EXFLAG_CRITICAL)) {\n ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) {\n ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n ret = X509_check_ca(x);\n switch (must_be_ca) {\n case -1:\n if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1) && (ret != 0)) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_CA;\n } else\n ret = 1;\n break;\n case 0:\n if (ret != 0) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_NON_CA;\n } else\n ret = 1;\n break;\n default:\n if ((ret == 0)\n || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1))) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_CA;\n } else\n ret = 1;\n break;\n }\n if (ret == 0) {\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (ctx->param->purpose > 0) {\n ret = X509_check_purpose(x, purpose, must_be_ca > 0);\n if ((ret == 0)\n || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1))) {\n ctx->error = X509_V_ERR_INVALID_PURPOSE;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n }\n if ((i > 1) && !(x->ex_flags & EXFLAG_SI)\n && (x->ex_pathlen != -1)\n && (plen > (x->ex_pathlen + proxy_path_length + 1))) {\n ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (!(x->ex_flags & EXFLAG_SI))\n plen++;\n if (x->ex_flags & EXFLAG_PROXY) {\n if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) {\n ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n proxy_path_length++;\n must_be_ca = 0;\n } else\n must_be_ca = 1;\n }\n ok = 1;\n end:\n return ok;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}', 'int X509_check_ca(X509 *x)\n{\n if (!(x->ex_flags & EXFLAG_SET)) {\n CRYPTO_w_lock(CRYPTO_LOCK_X509);\n x509v3_cache_extensions(x);\n CRYPTO_w_unlock(CRYPTO_LOCK_X509);\n }\n return check_ca(x);\n}'] |
35,043 | 0 | https://github.com/openssl/openssl/blob/4845aeba4c49e1bd65259a5014d7e3ab38657d42/ssl/ssl_ciph.c/#L470 | DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)
{
SSL_COMP *comp = NULL;
COMP_METHOD *method = COMP_zlib();
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);
if (COMP_get_type(method) != NID_undef && ssl_comp_methods != NULL) {
comp = OPENSSL_malloc(sizeof(*comp));
if (comp != NULL) {
comp->method = method;
comp->id = SSL_COMP_ZLIB_IDX;
comp->name = COMP_get_name(method);
sk_SSL_COMP_push(ssl_comp_methods, comp);
sk_SSL_COMP_sort(ssl_comp_methods);
}
}
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
return 1;
} | ['DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)', 'DEFINE_RUN_ONCE_STATIC(do_load_builtin_compressions)\n{\n SSL_COMP *comp = NULL;\n COMP_METHOD *method = COMP_zlib();\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);\n ssl_comp_methods = sk_SSL_COMP_new(sk_comp_cmp);\n if (COMP_get_type(method) != NID_undef && ssl_comp_methods != NULL) {\n comp = OPENSSL_malloc(sizeof(*comp));\n if (comp != NULL) {\n comp->method = method;\n comp->id = SSL_COMP_ZLIB_IDX;\n comp->name = COMP_get_name(method);\n sk_SSL_COMP_push(ssl_comp_methods, comp);\n sk_SSL_COMP_sort(ssl_comp_methods);\n }\n }\n CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);\n return 1;\n}', 'COMP_METHOD *COMP_zlib(void)\n{\n COMP_METHOD *meth = &zlib_method_nozlib;\n#ifdef ZLIB_SHARED\n# ifndef LIBZ\n# if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)\n# define LIBZ "ZLIB1"\n# elif defined(OPENSSL_SYS_VMS)\n# define LIBZ "LIBZ"\n# else\n# define LIBZ "z"\n# endif\n# endif\n if (!zlib_loaded) {\n zlib_dso = DSO_load(NULL, LIBZ, NULL, 0);\n if (zlib_dso != NULL) {\n p_compress = (compress_ft) DSO_bind_func(zlib_dso, "compress");\n p_inflateEnd\n = (inflateEnd_ft) DSO_bind_func(zlib_dso, "inflateEnd");\n p_inflate = (inflate_ft) DSO_bind_func(zlib_dso, "inflate");\n p_inflateInit_\n = (inflateInit__ft) DSO_bind_func(zlib_dso, "inflateInit_");\n p_deflateEnd\n = (deflateEnd_ft) DSO_bind_func(zlib_dso, "deflateEnd");\n p_deflate = (deflate_ft) DSO_bind_func(zlib_dso, "deflate");\n p_deflateInit_\n = (deflateInit__ft) DSO_bind_func(zlib_dso, "deflateInit_");\n p_zError = (zError__ft) DSO_bind_func(zlib_dso, "zError");\n if (p_compress && p_inflateEnd && p_inflate\n && p_inflateInit_ && p_deflateEnd\n && p_deflate && p_deflateInit_ && p_zError)\n zlib_loaded++;\n if (!OPENSSL_init_crypto(OPENSSL_INIT_ZLIB, NULL)) {\n comp_zlib_cleanup_int();\n return meth;\n }\n if (zlib_loaded)\n meth = &zlib_stateful_method;\n }\n }\n#endif\n#if defined(ZLIB)\n meth = &zlib_stateful_method;\n#endif\n return meth;\n}', 'int CRYPTO_mem_ctrl(int mode)\n{\n#ifdef OPENSSL_NO_CRYPTO_MDEBUG\n return mode - mode;\n#else\n int ret = mh_mode;\n if (!RUN_ONCE(&memdbg_init, do_memdbg_init))\n return -1;\n CRYPTO_THREAD_write_lock(memdbg_lock);\n switch (mode) {\n default:\n break;\n case CRYPTO_MEM_CHECK_ON:\n mh_mode = CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_OFF:\n mh_mode = 0;\n num_disable = 0;\n break;\n case CRYPTO_MEM_CHECK_DISABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n CRYPTO_THREAD_ID cur = CRYPTO_THREAD_get_current_id();\n if (!num_disable\n || !CRYPTO_THREAD_compare_id(disabling_threadid, cur)) {\n CRYPTO_THREAD_unlock(memdbg_lock);\n CRYPTO_THREAD_write_lock(long_memdbg_lock);\n CRYPTO_THREAD_write_lock(memdbg_lock);\n mh_mode &= ~CRYPTO_MEM_CHECK_ENABLE;\n disabling_threadid = cur;\n }\n num_disable++;\n }\n break;\n case CRYPTO_MEM_CHECK_ENABLE:\n if (mh_mode & CRYPTO_MEM_CHECK_ON) {\n if (num_disable) {\n num_disable--;\n if (num_disable == 0) {\n mh_mode |= CRYPTO_MEM_CHECK_ENABLE;\n CRYPTO_THREAD_unlock(long_memdbg_lock);\n }\n }\n }\n break;\n }\n CRYPTO_THREAD_unlock(memdbg_lock);\n return ret;\n#endif\n}', 'OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c)\n{\n return OPENSSL_sk_new_reserve(c, 0);\n}', 'int COMP_get_type(const COMP_METHOD *meth)\n{\n return meth->type;\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}', 'const char *COMP_get_name(const COMP_METHOD *meth)\n{\n return meth->name;\n}', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n if (st == NULL)\n return -1;\n return OPENSSL_sk_insert(st, data, st->num);\n}', 'int OPENSSL_sk_insert(OPENSSL_STACK *st, const void *data, int loc)\n{\n if (st == NULL || st->num == max_nodes)\n return 0;\n if (!sk_reserve(st, 1, 0))\n return 0;\n if ((loc >= st->num) || (loc < 0)) {\n st->data[st->num] = data;\n } else {\n memmove(&st->data[loc + 1], &st->data[loc],\n sizeof(st->data[0]) * (st->num - loc));\n st->data[loc] = data;\n }\n st->num++;\n st->sorted = 0;\n return st->num;\n}'] |
35,044 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L709 | int BN_cmp(const BIGNUM *a, const BIGNUM *b)
{
int i;
int gt,lt;
BN_ULONG t1,t2;
if ((a == NULL) || (b == NULL))
{
if (a != NULL)
return(-1);
else if (b != NULL)
return(1);
else
return(0);
}
bn_check_top(a);
bn_check_top(b);
if (a->neg != b->neg)
{
if (a->neg)
return(-1);
else return(1);
}
if (a->neg == 0)
{ gt=1; lt= -1; }
else { gt= -1; lt=1; }
if (a->top > b->top) return(gt);
if (a->top < b->top) return(lt);
for (i=a->top-1; i>=0; i--)
{
t1=a->d[i];
t2=b->d[i];
if (t1 > t2) return(gt);
if (t1 < t2) return(lt);
}
return(0);
} | ['int ec_GFp_simple_group_set_curve(EC_GROUP *group,\n\tconst BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBN_CTX *new_ctx = NULL;\n\tBIGNUM *tmp_a;\n\tif (BN_num_bits(p) <= 2 || !BN_is_odd(p))\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE, EC_R_INVALID_FIELD);\n\t\treturn 0;\n\t\t}\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\treturn 0;\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp_a = BN_CTX_get(ctx);\n\tif (tmp_a == NULL) goto err;\n\tif (!BN_copy(&group->field, p)) goto err;\n\tBN_set_negative(&group->field, 0);\n\tif (!BN_nnmod(tmp_a, a, p, ctx)) goto err;\n\tif (group->meth->field_encode)\n\t\t{ if (!group->meth->field_encode(group, &group->a, tmp_a, ctx)) goto err; }\n\telse\n\t\tif (!BN_copy(&group->a, tmp_a)) goto err;\n\tif (!BN_nnmod(&group->b, b, p, ctx)) goto err;\n\tif (group->meth->field_encode)\n\t\tif (!group->meth->field_encode(group, &group->b, &group->b, ctx)) goto err;\n\tif (!BN_add_word(tmp_a, 3)) goto err;\n\tgroup->a_is_minus3 = (0 == BN_cmp(tmp_a, &group->field));\n\tret = 1;\n err:\n\tBN_CTX_end(ctx);\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\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;\n\tsize_t loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tsize_t num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp, div_n+1)) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'int BN_add_word(BIGNUM *a, BN_ULONG w)\n\t{\n\tBN_ULONG l;\n\tint i;\n\tbn_check_top(a);\n\tw &= BN_MASK2;\n\tif (!w) return 1;\n\tif(BN_is_zero(a)) return BN_set_word(a, w);\n\tif (a->neg)\n\t\t{\n\t\ta->neg=0;\n\t\ti=BN_sub_word(a,w);\n\t\tif (!BN_is_zero(a))\n\t\t\ta->neg=!(a->neg);\n\t\treturn(i);\n\t\t}\n\tif (((BN_ULONG)(a->d[a->top - 1] + 1) == 0) &&\n\t\t\t(bn_wexpand(a,a->top+1) == NULL))\n\t\treturn(0);\n\ti=0;\n\tfor (;;)\n\t\t{\n\t\tif (i >= a->top)\n\t\t\tl=w;\n\t\telse\n\t\t\tl=(a->d[i]+w)&BN_MASK2;\n\t\ta->d[i]=l;\n\t\tif (w > l)\n\t\t\tw=1;\n\t\telse\n\t\t\tbreak;\n\t\ti++;\n\t\t}\n\tif (i >= a->top)\n\t\ta->top++;\n\tbn_check_top(a);\n\treturn(1);\n\t}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tint gt,lt;\n\tBN_ULONG t1,t2;\n\tif ((a == NULL) || (b == NULL))\n\t\t{\n\t\tif (a != NULL)\n\t\t\treturn(-1);\n\t\telse if (b != NULL)\n\t\t\treturn(1);\n\t\telse\n\t\t\treturn(0);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->neg != b->neg)\n\t\t{\n\t\tif (a->neg)\n\t\t\treturn(-1);\n\t\telse\treturn(1);\n\t\t}\n\tif (a->neg == 0)\n\t\t{ gt=1; lt= -1; }\n\telse\t{ gt= -1; lt=1; }\n\tif (a->top > b->top) return(gt);\n\tif (a->top < b->top) return(lt);\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tt1=a->d[i];\n\t\tt2=b->d[i];\n\t\tif (t1 > t2) return(gt);\n\t\tif (t1 < t2) return(lt);\n\t\t}\n\treturn(0);\n\t}'] |
35,045 | 0 | https://github.com/libav/libav/blob/452a398fd6bdca3f301c5c8af3bc241bc16a777e/libavcodec/ra288.c/#L132 | static int eval_lpc_coeffs(const float *in, float *tgt, int n)
{
int x, y;
double f0, f1, f2;
if (in[n] == 0)
return -1;
if ((f0 = *in) <= 0)
return -1;
in--;
for (x=1; x <= n; x++) {
f1 = in[x+1];
for (y=0; y < x - 1; y++)
f1 += in[x-y]*tgt[y];
tgt[x-1] = f2 = -f1/f0;
for (y=0; y < x >> 1; y++) {
float temp = tgt[y] + tgt[x-y-2]*f2;
tgt[x-y-2] += tgt[y]*f2;
tgt[y] = temp;
}
if ((f0 += f1*f2) < 0)
return -1;
}
return 0;
} | ['static void backward_filter(RA288Context *ractx)\n{\n float temp1[37];\n float temp2[11];\n float history[8];\n int i;\n for (i=0 ; i < 8; i++)\n history[i] = ractx->lhist[7-i];\n do_hybrid_window(36, 40, 35, ractx->output, temp1, ractx->sp_hist,\n ractx->sp_rec, syn_window);\n if (!eval_lpc_coeffs(temp1, ractx->sp_lpc, 36))\n colmult(ractx->sp_lpc, ractx->sp_lpc, syn_bw_tab, 36);\n do_hybrid_window(10, 8, 20, history, temp2, ractx->gain_hist,\n ractx->gain_rec, gain_window);\n if (!eval_lpc_coeffs(temp2, ractx->gain_lpc, 10))\n colmult(ractx->gain_lpc, ractx->gain_lpc, gain_bw_tab, 10);\n}', 'static int eval_lpc_coeffs(const float *in, float *tgt, int n)\n{\n int x, y;\n double f0, f1, f2;\n if (in[n] == 0)\n return -1;\n if ((f0 = *in) <= 0)\n return -1;\n in--;\n for (x=1; x <= n; x++) {\n f1 = in[x+1];\n for (y=0; y < x - 1; y++)\n f1 += in[x-y]*tgt[y];\n tgt[x-1] = f2 = -f1/f0;\n for (y=0; y < x >> 1; y++) {\n float temp = tgt[y] + tgt[x-y-2]*f2;\n tgt[x-y-2] += tgt[y]*f2;\n tgt[y] = temp;\n }\n if ((f0 += f1*f2) < 0)\n return -1;\n }\n return 0;\n}'] |
35,046 | 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_key_exchange(SSL *s)\n\t{\n\tint i,al,ok;\n\tlong n;\n\tunsigned long l;\n\tunsigned char *p;\n#ifndef NO_RSA\n\tRSA *rsa=NULL;\n\tEVP_PKEY *pkey=NULL;\n#endif\n#ifndef NO_DH\n\tBIGNUM *pub=NULL;\n\tDH *dh_srvr;\n#endif\n\tn=ssl3_get_message(s,\n\t\tSSL3_ST_SR_KEY_EXCH_A,\n\t\tSSL3_ST_SR_KEY_EXCH_B,\n\t\tSSL3_MT_CLIENT_KEY_EXCHANGE,\n\t\t400,\n\t\t&ok);\n\tif (!ok) return((int)n);\n\tp=(unsigned char *)s->init_buf->data;\n\tl=s->s3->tmp.new_cipher->algorithms;\n#ifndef NO_RSA\n\tif (l & SSL_kRSA)\n\t\t{\n\t\tif (s->s3->tmp.use_rsa_tmp)\n\t\t\t{\n\t\t\tif ((s->cert != NULL) && (s->cert->rsa_tmp != NULL))\n\t\t\t\trsa=s->cert->rsa_tmp;\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_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_RSA_PKEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey=s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey;\n\t\t\tif (\t(pkey == NULL) ||\n\t\t\t\t(pkey->type != EVP_PKEY_RSA) ||\n\t\t\t\t(pkey->pkey.rsa == NULL))\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_RSA_CERTIFICATE);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\trsa=pkey->pkey.rsa;\n\t\t\t}\n\t\tif (s->version > SSL3_VERSION)\n\t\t\t{\n\t\t\tn2s(p,i);\n\t\t\tif (n != i+2)\n\t\t\t\t{\n\t\t\t\tif (!(s->options & SSL_OP_TLS_D5_BUG))\n\t\t\t\t\t{\n\t\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);\n\t\t\t\t\tgoto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\tp-=2;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tn=i;\n\t\t\t}\n\t\ti=RSA_private_decrypt((int)n,p,p,rsa,RSA_PKCS1_PADDING);\n#if 0\n\t\tif ((i != SSL_MAX_MASTER_KEY_LENGTH) ||\n\t\t\t((p[0] != (s->client_version>>8)) ||\n\t\t\t (p[1] != (s->client_version & 0xff))))\n\t\t\t{\n\t\t\tint bad=1;\n\t\t\tif ((i == SSL_MAX_MASTER_KEY_LENGTH) &&\n\t\t\t\t(p[0] == (s->version>>8)) &&\n\t\t\t\t(p[1] == 0))\n\t\t\t\t{\n\t\t\t\tif (s->options & SSL_OP_TLS_ROLLBACK_BUG)\n\t\t\t\t\tbad=0;\n\t\t\t\t}\n\t\t\tif (bad)\n\t\t\t\t{\n\t\t\t\tp[0]=(s->version>>8);\n\t\t\t\tp[1]=(s->version & 0xff);\n\t\t\t\tRAND_pseudo_bytes(&(p[2]),SSL_MAX_MASTER_KEY_LENGTH-2);\n\t\t\t\ti=SSL_MAX_MASTER_KEY_LENGTH;\n\t\t\t\t}\n\t\t\t}\n#else\n\t\tif (i != SSL_MAX_MASTER_KEY_LENGTH)\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif ((p[0] != (s->client_version>>8)) || (p[1] != (s->client_version & 0xff)))\n\t\t\t{\n\t\t\tal=SSL_AD_DECODE_ERROR;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER);\n\t\t\tgoto f_err;\n\t\t\t}\n#endif\n\t\ts->session->master_key_length=\n\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\ts->session->master_key,\n\t\t\t\tp,i);\n\t\tmemset(p,0,i);\n\t\t}\n\telse\n#endif\n#ifndef NO_DH\n\t\tif (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t{\n\t\tn2s(p,i);\n\t\tif (n != i+2)\n\t\t\t{\n\t\t\tif (!(s->options & SSL_OP_SSLEAY_080_CLIENT_DH_BUG))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tp-=2;\n\t\t\t\ti=(int)n;\n\t\t\t\t}\n\t\t\t}\n\t\tif (n == 0L)\n\t\t\t{\n\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_DECODE_DH_CERTS);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (s->s3->tmp.dh == NULL)\n\t\t\t\t{\n\t\t\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_MISSING_TMP_DH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tdh_srvr=s->s3->tmp.dh;\n\t\t\t}\n\t\tpub=BN_bin2bn(p,i,NULL);\n\t\tif (pub == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BN_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ti=DH_compute_key(p,pub,dh_srvr);\n\t\tif (i <= 0)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tDH_free(s->s3->tmp.dh);\n\t\ts->s3->tmp.dh=NULL;\n\t\tBN_clear_free(pub);\n\t\tpub=NULL;\n\t\ts->session->master_key_length=\n\t\t\ts->method->ssl3_enc->generate_master_secret(s,\n\t\t\t\ts->session->master_key,p,i);\n\t\t}\n\telse\n#endif\n\t\t{\n\t\tal=SSL_AD_HANDSHAKE_FAILURE;\n\t\tSSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_UNKNOWN_CIPHER_TYPE);\n\t\tgoto f_err;\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\n#if !defined(NO_DH) || !defined(NO_RSA)\nerr:\n#endif\n\treturn(-1);\n\t}', 'long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok)\n\t{\n\tunsigned char *p;\n\tunsigned long l;\n\tlong n;\n\tint i,al;\n\tif (s->s3->tmp.reuse_message)\n\t\t{\n\t\ts->s3->tmp.reuse_message=0;\n\t\tif ((mt >= 0) && (s->s3->tmp.message_type != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t*ok=1;\n\t\treturn((int)s->s3->tmp.message_size);\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tif (s->state == st1)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],\n\t\t\t\t 4-s->init_num);\n\t\tif (i < (4-s->init_num))\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\tif ((mt >= 0) && (*p != mt))\n\t\t\t{\n\t\t\tal=SSL_AD_UNEXPECTED_MESSAGE;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_UNEXPECTED_MESSAGE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif((mt < 0) && (*p == SSL3_MT_CLIENT_HELLO) &&\n\t\t\t\t\t(st1 == SSL3_ST_SR_CERT_A) &&\n\t\t\t\t\t(stn == SSL3_ST_SR_CERT_B))\n\t\t\t{\n\t\t\tssl3_init_finished_mac(s);\n\t\t\tssl3_finish_mac(s, p + s->init_num, i);\n\t\t\t}\n\t\ts->s3->tmp.message_type= *(p++);\n\t\tn2l3(p,l);\n\t\tif (l > (unsigned long)max)\n\t\t\t{\n\t\t\tal=SSL_AD_ILLEGAL_PARAMETER;\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\tif (l && !BUF_MEM_grow(s->init_buf,(int)l))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\ts->s3->tmp.message_size=l;\n\t\ts->state=stn;\n\t\ts->init_num=0;\n\t\t}\n\tp=(unsigned char *)s->init_buf->data;\n\tn=s->s3->tmp.message_size;\n\tif (n > 0)\n\t\t{\n\t\ti=ssl3_read_bytes(s,SSL3_RT_HANDSHAKE,&p[s->init_num],n);\n\t\tif (i != (int)n)\n\t\t\t{\n\t\t\t*ok=0;\n\t\t\treturn(ssl3_part_read(s,i));\n\t\t\t}\n\t\t}\n\t*ok=1;\n\treturn(n);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,al);\nerr:\n\t*ok=0;\n\treturn(-1);\n\t}', 'void ssl3_send_alert(SSL *s, int level, int desc)\n\t{\n\tdesc=s->method->ssl3_enc->alert_value(desc);\n\tif (desc < 0) return;\n\tif ((level == 2) && (s->session != NULL))\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\ts->s3->alert_dispatch=1;\n\ts->s3->send_alert[0]=level;\n\ts->s3->send_alert[1]=desc;\n\tif (s->s3->wbuf.left == 0)\n\t\tssl3_dispatch_alert(s);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,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}'] |
35,047 | 0 | https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/buffer/buffer.c/#L118 | size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
{
char *ret;
size_t n;
if (str->length >= len) {
if (str->data != NULL)
memset(&str->data[len], 0, str->length - len);
str->length = len;
return len;
}
if (str->max >= len) {
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
return len;
}
if (len > LIMIT_BEFORE_EXPANSION) {
BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
return 0;
}
n = (len + 3) / 3 * 4;
if ((str->flags & BUF_MEM_FLAG_SECURE))
ret = sec_alloc_realloc(str, n);
else
ret = OPENSSL_clear_realloc(str->data, str->max, n);
if (ret == NULL) {
BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
len = 0;
} else {
str->data = ret;
str->max = n;
memset(&str->data[str->length], 0, len - str->length);
str->length = len;
}
return len;
} | ["static int str_copy(CONF *conf, char *section, char **pto, char *from)\n{\n int q, r, rr = 0, to = 0, len = 0;\n char *s, *e, *rp, *p, *rrp, *np, *cp, v;\n BUF_MEM *buf;\n if ((buf = BUF_MEM_new()) == NULL)\n return 0;\n len = strlen(from) + 1;\n if (!BUF_MEM_grow(buf, len))\n goto err;\n for (;;) {\n if (IS_QUOTE(conf, *from)) {\n q = *from;\n from++;\n while (!IS_EOF(conf, *from) && (*from != q)) {\n if (IS_ESC(conf, *from)) {\n from++;\n if (IS_EOF(conf, *from))\n break;\n }\n buf->data[to++] = *(from++);\n }\n if (*from == q)\n from++;\n } else if (IS_DQUOTE(conf, *from)) {\n q = *from;\n from++;\n while (!IS_EOF(conf, *from)) {\n if (*from == q) {\n if (*(from + 1) == q) {\n from++;\n } else {\n break;\n }\n }\n buf->data[to++] = *(from++);\n }\n if (*from == q)\n from++;\n } else if (IS_ESC(conf, *from)) {\n from++;\n v = *(from++);\n if (IS_EOF(conf, v))\n break;\n else if (v == 'r')\n v = '\\r';\n else if (v == 'n')\n v = '\\n';\n else if (v == 'b')\n v = '\\b';\n else if (v == 't')\n v = '\\t';\n buf->data[to++] = v;\n } else if (IS_EOF(conf, *from))\n break;\n else if (*from == '$') {\n size_t newsize;\n rrp = NULL;\n s = &(from[1]);\n if (*s == '{')\n q = '}';\n else if (*s == '(')\n q = ')';\n else\n q = 0;\n if (q)\n s++;\n cp = section;\n e = np = s;\n while (IS_ALPHA_NUMERIC(conf, *e))\n e++;\n if ((e[0] == ':') && (e[1] == ':')) {\n cp = np;\n rrp = e;\n rr = *e;\n *rrp = '\\0';\n e += 2;\n np = e;\n while (IS_ALPHA_NUMERIC(conf, *e))\n e++;\n }\n r = *e;\n *e = '\\0';\n rp = e;\n if (q) {\n if (r != q) {\n CONFerr(CONF_F_STR_COPY, CONF_R_NO_CLOSE_BRACE);\n goto err;\n }\n e++;\n }\n p = _CONF_get_string(conf, cp, np);\n if (rrp != NULL)\n *rrp = rr;\n *rp = r;\n if (p == NULL) {\n CONFerr(CONF_F_STR_COPY, CONF_R_VARIABLE_HAS_NO_VALUE);\n goto err;\n }\n newsize = strlen(p) + buf->length - (e - from);\n if (newsize > MAX_CONF_VALUE_LENGTH) {\n CONFerr(CONF_F_STR_COPY, CONF_R_VARIABLE_EXPANSION_TOO_LONG);\n goto err;\n }\n if (!BUF_MEM_grow_clean(buf, newsize)) {\n CONFerr(CONF_F_STR_COPY, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n while (*p)\n buf->data[to++] = *(p++);\n len -= e - from;\n from = e;\n *rp = r;\n } else\n buf->data[to++] = *(from++);\n }\n buf->data[to] = '\\0';\n OPENSSL_free(*pto);\n *pto = buf->data;\n OPENSSL_free(buf);\n return 1;\n err:\n BUF_MEM_free(buf);\n return 0;\n}", 'size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)\n{\n char *ret;\n size_t n;\n if (str->length >= len) {\n if (str->data != NULL)\n memset(&str->data[len], 0, str->length - len);\n str->length = len;\n return len;\n }\n if (str->max >= len) {\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n return len;\n }\n if (len > LIMIT_BEFORE_EXPANSION) {\n BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n n = (len + 3) / 3 * 4;\n if ((str->flags & BUF_MEM_FLAG_SECURE))\n ret = sec_alloc_realloc(str, n);\n else\n ret = OPENSSL_clear_realloc(str->data, str->max, n);\n if (ret == NULL) {\n BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);\n len = 0;\n } else {\n str->data = ret;\n str->max = n;\n memset(&str->data[str->length], 0, len - str->length);\n str->length = len;\n }\n return len;\n}'] |
35,048 | 0 | https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/lhash/lhash.c/#L273 | static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)
{
int i;
LHASH_NODE *a, *n;
if (lh == NULL)
return;
for (i = lh->num_nodes - 1; i >= 0; i--) {
a = lh->b[i];
while (a != NULL) {
n = a->next;
if (use_arg)
func_arg(a->data, arg);
else
func(a->data);
a = n;
}
}
} | ['static void engine_unregister_all_pkey_meths(void)\n{\n engine_table_cleanup(&pkey_meth_table);\n}', 'void engine_table_cleanup(ENGINE_TABLE **table)\n{\n CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n if (*table) {\n lh_ENGINE_PILE_doall(&(*table)->piles,\n LHASH_DOALL_FN(int_cleanup_cb));\n lh_ENGINE_PILE_free(&(*table)->piles);\n *table = NULL;\n }\n CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n}', 'void lh_doall(_LHASH *lh, LHASH_DOALL_FN_TYPE func)\n{\n doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)0, NULL);\n}', 'static void doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,\n LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg)\n{\n int i;\n LHASH_NODE *a, *n;\n if (lh == NULL)\n return;\n for (i = lh->num_nodes - 1; i >= 0; i--) {\n a = lh->b[i];\n while (a != NULL) {\n n = a->next;\n if (use_arg)\n func_arg(a->data, arg);\n else\n func(a->data);\n a = n;\n }\n }\n}'] |
35,049 | 0 | https://github.com/openssl/openssl/blob/81eae077ce679c1d7d29e19991bf055e4888a2fc/crypto/poly1305/poly1305.c/#L486 | void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)
{
#ifdef POLY1305_ASM
poly1305_blocks_f poly1305_blocks = ctx->func.blocks;
#endif
size_t rem, num;
if ((num = ctx->num)) {
rem = POLY1305_BLOCK_SIZE - num;
if (len >= rem) {
memcpy(ctx->data + num, inp, rem);
poly1305_blocks(ctx->opaque, ctx->data, POLY1305_BLOCK_SIZE, 1);
inp += rem;
len -= rem;
} else {
memcpy(ctx->data + num, inp, len);
ctx->num = num + len;
return;
}
}
rem = len % POLY1305_BLOCK_SIZE;
len -= rem;
if (len >= POLY1305_BLOCK_SIZE) {
poly1305_blocks(ctx->opaque, inp, len, 1);
inp += len;
}
if (rem)
memcpy(ctx->data, inp, rem);
ctx->num = rem;
} | ['static int chacha20_poly1305_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg,\n void *ptr)\n{\n EVP_CHACHA_AEAD_CTX *actx = aead_data(ctx);\n switch(type) {\n case EVP_CTRL_INIT:\n if (actx == NULL)\n actx = ctx->cipher_data\n = OPENSSL_zalloc(sizeof(*actx) + Poly1305_ctx_size());\n if (actx == NULL) {\n EVPerr(EVP_F_CHACHA20_POLY1305_CTRL, EVP_R_INITIALIZATION_ERROR);\n return 0;\n }\n actx->len.aad = 0;\n actx->len.text = 0;\n actx->aad = 0;\n actx->mac_inited = 0;\n actx->tag_len = 0;\n actx->nonce_len = 12;\n actx->tls_payload_length = NO_TLS_PAYLOAD_LENGTH;\n return 1;\n case EVP_CTRL_COPY:\n if (actx) {\n if ((((EVP_CIPHER_CTX *)ptr)->cipher_data =\n BUF_memdup(actx,sizeof(*actx) + Poly1305_ctx_size()))\n == NULL) {\n EVPerr(EVP_F_CHACHA20_POLY1305_CTRL, EVP_R_COPY_ERROR);\n return 0;\n }\n }\n return 1;\n case EVP_CTRL_AEAD_SET_IVLEN:\n if (arg <= 0 || arg > CHACHA_CTR_SIZE)\n return 0;\n actx->nonce_len = arg;\n return 1;\n case EVP_CTRL_AEAD_SET_IV_FIXED:\n if (arg != 12)\n return 0;\n actx->nonce[0] = actx->key.counter[1]\n = CHACHA_U8TOU32((unsigned char *)ptr);\n actx->nonce[1] = actx->key.counter[2]\n = CHACHA_U8TOU32((unsigned char *)ptr+4);\n actx->nonce[2] = actx->key.counter[3]\n = CHACHA_U8TOU32((unsigned char *)ptr+8);\n return 1;\n case EVP_CTRL_AEAD_SET_TAG:\n if (arg <= 0 || arg > POLY1305_BLOCK_SIZE)\n return 0;\n if (ptr != NULL) {\n memcpy(actx->tag, ptr, arg);\n actx->tag_len = arg;\n }\n return 1;\n case EVP_CTRL_AEAD_GET_TAG:\n if (arg <= 0 || arg > POLY1305_BLOCK_SIZE || !ctx->encrypt)\n return 0;\n memcpy(ptr, actx->tag, arg);\n return 1;\n case EVP_CTRL_AEAD_TLS1_AAD:\n if (arg != EVP_AEAD_TLS1_AAD_LEN)\n return 0;\n {\n unsigned int len;\n unsigned char *aad = ptr, temp[POLY1305_BLOCK_SIZE];\n len = aad[EVP_AEAD_TLS1_AAD_LEN - 2] << 8 |\n aad[EVP_AEAD_TLS1_AAD_LEN - 1];\n if (!ctx->encrypt) {\n len -= POLY1305_BLOCK_SIZE;\n memcpy(temp, aad, EVP_AEAD_TLS1_AAD_LEN - 2);\n aad = temp;\n temp[EVP_AEAD_TLS1_AAD_LEN - 2] = (unsigned char)(len >> 8);\n temp[EVP_AEAD_TLS1_AAD_LEN - 1] = (unsigned char)len;\n }\n actx->tls_payload_length = len;\n actx->key.counter[1] = actx->nonce[0];\n actx->key.counter[2] = actx->nonce[1] ^ CHACHA_U8TOU32(aad);\n actx->key.counter[3] = actx->nonce[2] ^ CHACHA_U8TOU32(aad+4);\n actx->mac_inited = 0;\n chacha20_poly1305_cipher(ctx, NULL, aad, EVP_AEAD_TLS1_AAD_LEN);\n return POLY1305_BLOCK_SIZE;\n }\n case EVP_CTRL_AEAD_SET_MAC_KEY:\n return 1;\n default:\n return -1;\n }\n}', 'static int chacha20_poly1305_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,\n const unsigned char *in, size_t len)\n{\n EVP_CHACHA_AEAD_CTX *actx = aead_data(ctx);\n size_t rem, plen = actx->tls_payload_length;\n static const unsigned char zero[POLY1305_BLOCK_SIZE] = { 0 };\n if (!actx->mac_inited) {\n actx->key.counter[0] = 0;\n memset(actx->key.buf, 0, sizeof(actx->key.buf));\n ChaCha20_ctr32(actx->key.buf, actx->key.buf, CHACHA_BLK_SIZE,\n actx->key.key.d, actx->key.counter);\n Poly1305_Init(POLY1305_ctx(actx), actx->key.buf);\n actx->key.counter[0] = 1;\n actx->key.partial_len = 0;\n actx->len.aad = actx->len.text = 0;\n actx->mac_inited = 1;\n }\n if (in) {\n if (out == NULL) {\n Poly1305_Update(POLY1305_ctx(actx), in, len);\n actx->len.aad += len;\n actx->aad = 1;\n return len;\n } else {\n if (actx->aad) {\n if ((rem = (size_t)actx->len.aad % POLY1305_BLOCK_SIZE))\n Poly1305_Update(POLY1305_ctx(actx), zero,\n POLY1305_BLOCK_SIZE - rem);\n actx->aad = 0;\n }\n actx->tls_payload_length = NO_TLS_PAYLOAD_LENGTH;\n if (plen == NO_TLS_PAYLOAD_LENGTH)\n plen = len;\n else if (len != plen + POLY1305_BLOCK_SIZE)\n return -1;\n if (ctx->encrypt) {\n chacha_cipher(ctx, out, in, plen);\n Poly1305_Update(POLY1305_ctx(actx), out, plen);\n in += plen;\n out += plen;\n actx->len.text += plen;\n } else {\n Poly1305_Update(POLY1305_ctx(actx), in, plen);\n chacha_cipher(ctx, out, in, plen);\n in += plen;\n out += plen;\n actx->len.text += plen;\n }\n }\n }\n if (in == NULL\n || plen != len) {\n const union {\n long one;\n char little;\n } is_endian = { 1 };\n unsigned char temp[POLY1305_BLOCK_SIZE];\n if (actx->aad) {\n if ((rem = (size_t)actx->len.aad % POLY1305_BLOCK_SIZE))\n Poly1305_Update(POLY1305_ctx(actx), zero,\n POLY1305_BLOCK_SIZE - rem);\n actx->aad = 0;\n }\n if ((rem = (size_t)actx->len.text % POLY1305_BLOCK_SIZE))\n Poly1305_Update(POLY1305_ctx(actx), zero,\n POLY1305_BLOCK_SIZE - rem);\n if (is_endian.little) {\n Poly1305_Update(POLY1305_ctx(actx),\n (unsigned char *)&actx->len, POLY1305_BLOCK_SIZE);\n } else {\n temp[0] = (unsigned char)(actx->len.aad);\n temp[1] = (unsigned char)(actx->len.aad>>8);\n temp[2] = (unsigned char)(actx->len.aad>>16);\n temp[3] = (unsigned char)(actx->len.aad>>24);\n temp[4] = (unsigned char)(actx->len.aad>>32);\n temp[5] = (unsigned char)(actx->len.aad>>40);\n temp[6] = (unsigned char)(actx->len.aad>>48);\n temp[7] = (unsigned char)(actx->len.aad>>56);\n temp[8] = (unsigned char)(actx->len.text);\n temp[9] = (unsigned char)(actx->len.text>>8);\n temp[10] = (unsigned char)(actx->len.text>>16);\n temp[11] = (unsigned char)(actx->len.text>>24);\n temp[12] = (unsigned char)(actx->len.text>>32);\n temp[13] = (unsigned char)(actx->len.text>>40);\n temp[14] = (unsigned char)(actx->len.text>>48);\n temp[15] = (unsigned char)(actx->len.text>>56);\n Poly1305_Update(POLY1305_ctx(actx), temp, POLY1305_BLOCK_SIZE);\n }\n Poly1305_Final(POLY1305_ctx(actx), ctx->encrypt ? actx->tag\n : temp);\n actx->mac_inited = 0;\n if (in != NULL && len != plen) {\n if (ctx->encrypt) {\n memcpy(out, actx->tag, POLY1305_BLOCK_SIZE);\n } else {\n if (CRYPTO_memcmp(temp, in, POLY1305_BLOCK_SIZE)) {\n memset(out, 0, plen);\n return -1;\n }\n }\n }\n else if (!ctx->encrypt) {\n if (CRYPTO_memcmp(temp, actx->tag, actx->tag_len))\n return -1;\n }\n }\n return len;\n}', 'void Poly1305_Update(POLY1305 *ctx, const unsigned char *inp, size_t len)\n{\n#ifdef POLY1305_ASM\n poly1305_blocks_f poly1305_blocks = ctx->func.blocks;\n#endif\n size_t rem, num;\n if ((num = ctx->num)) {\n rem = POLY1305_BLOCK_SIZE - num;\n if (len >= rem) {\n memcpy(ctx->data + num, inp, rem);\n poly1305_blocks(ctx->opaque, ctx->data, POLY1305_BLOCK_SIZE, 1);\n inp += rem;\n len -= rem;\n } else {\n memcpy(ctx->data + num, inp, len);\n ctx->num = num + len;\n return;\n }\n }\n rem = len % POLY1305_BLOCK_SIZE;\n len -= rem;\n if (len >= POLY1305_BLOCK_SIZE) {\n poly1305_blocks(ctx->opaque, inp, len, 1);\n inp += len;\n }\n if (rem)\n memcpy(ctx->data, inp, rem);\n ctx->num = rem;\n}'] |
35,050 | 0 | https://github.com/apache/httpd/blob/db5f097737f7307f4a9d0dc83120cf431a1486c3/server/util_expr_scan.c/#L2199 | static void ap_expr_yyensure_buffer_stack (yyscan_t yyscanner)
{
int num_to_alloc;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
if (!yyg->yy_buffer_stack) {
num_to_alloc = 1;
yyg->yy_buffer_stack = (struct yy_buffer_state**)ap_expr_yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
YY_FATAL_ERROR( "out of dynamic memory in ap_expr_yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
yyg->yy_buffer_stack_max = num_to_alloc;
yyg->yy_buffer_stack_top = 0;
return;
}
if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
int grow_size = 8 ;
num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
yyg->yy_buffer_stack = (struct yy_buffer_state**)ap_expr_yyrealloc
(yyg->yy_buffer_stack,
num_to_alloc * sizeof(struct yy_buffer_state*)
, yyscanner);
if ( ! yyg->yy_buffer_stack )
YY_FATAL_ERROR( "out of dynamic memory in ap_expr_yyensure_buffer_stack()" );
memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
yyg->yy_buffer_stack_max = num_to_alloc;
}
} | ['AP_DECLARE(const char *) ap_expr_parse(apr_pool_t *pool, apr_pool_t *ptemp,\n ap_expr_info_t *info, const char *expr,\n ap_expr_lookup_fn_t *lookup_fn)\n{\n ap_expr_parse_ctx_t ctx;\n int rc;\n ctx.pool = pool;\n ctx.ptemp = ptemp;\n ctx.inputbuf = expr;\n ctx.inputlen = strlen(expr);\n ctx.inputptr = ctx.inputbuf;\n ctx.expr = NULL;\n ctx.error = NULL;\n ctx.error2 = NULL;\n ctx.flags = info->flags;\n ctx.scan_del = \'\\0\';\n ctx.scan_buf[0] = \'\\0\';\n ctx.scan_ptr = ctx.scan_buf;\n ctx.lookup_fn = lookup_fn ? lookup_fn : ap_expr_lookup_default;\n ctx.at_start = 1;\n ap_expr_yylex_init(&ctx.scanner);\n ap_expr_yyset_extra(&ctx, ctx.scanner);\n rc = ap_expr_yyparse(&ctx);\n ap_expr_yylex_destroy(ctx.scanner);\n if (ctx.error) {\n if (ctx.error2)\n return apr_psprintf(pool, "%s: %s", ctx.error, ctx.error2);\n else\n return ctx.error;\n }\n else if (ctx.error2) {\n return ctx.error2;\n }\n if (rc)\n return "syntax error";\n#ifdef AP_EXPR_DEBUG\n if (ctx.expr)\n expr_dump_tree(ctx.expr, NULL, APLOG_NOTICE, 2);\n#endif\n info->root_node = ctx.expr;\n return NULL;\n}', 'int ap_expr_yylex_init(yyscan_t* ptr_yy_globals)\n{\n if (ptr_yy_globals == NULL){\n errno = EINVAL;\n return 1;\n }\n *ptr_yy_globals = (yyscan_t) ap_expr_yyalloc ( sizeof( struct yyguts_t ), NULL );\n if (*ptr_yy_globals == NULL){\n errno = ENOMEM;\n return 1;\n }\n memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));\n return yy_init_globals ( *ptr_yy_globals );\n}', 'static int yy_init_globals (yyscan_t yyscanner)\n{\n struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;\n yyg->yy_buffer_stack = 0;\n yyg->yy_buffer_stack_top = 0;\n yyg->yy_buffer_stack_max = 0;\n yyg->yy_c_buf_p = (char *) 0;\n yyg->yy_init = 0;\n yyg->yy_start = 0;\n yyg->yy_start_stack_ptr = 0;\n yyg->yy_start_stack_depth = 0;\n yyg->yy_start_stack = NULL;\n#ifdef YY_STDINIT\n yyin = stdin;\n yyout = stdout;\n#else\n yyin = (FILE *) 0;\n yyout = (FILE *) 0;\n#endif\n return 0;\n}', 'int\nyyparse (ap_expr_parse_ctx_t *ctx)\n#else\nint\nyyparse (ctx)\n ap_expr_parse_ctx_t *ctx;\n#endif\n#endif\n{\nint yychar;\n#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__\n# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \\\n _Pragma ("GCC diagnostic push") \\\n _Pragma ("GCC diagnostic ignored \\"-Wuninitialized\\"")\\\n _Pragma ("GCC diagnostic ignored \\"-Wmaybe-uninitialized\\"")\n# define YY_IGNORE_MAYBE_UNINITIALIZED_END \\\n _Pragma ("GCC diagnostic pop")\n#else\nstatic YYSTYPE yyval_default;\n# define YY_INITIAL_VALUE(Value) = Value\n#endif\n#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n# define YY_IGNORE_MAYBE_UNINITIALIZED_END\n#endif\n#ifndef YY_INITIAL_VALUE\n# define YY_INITIAL_VALUE(Value)\n#endif\nYYSTYPE yylval YY_INITIAL_VALUE(yyval_default);\n int yynerrs;\n int yystate;\n int yyerrstatus;\n yytype_int16 yyssa[YYINITDEPTH];\n yytype_int16 *yyss;\n yytype_int16 *yyssp;\n YYSTYPE yyvsa[YYINITDEPTH];\n YYSTYPE *yyvs;\n YYSTYPE *yyvsp;\n YYSIZE_T yystacksize;\n int yyn;\n int yyresult;\n int yytoken = 0;\n YYSTYPE yyval;\n#if YYERROR_VERBOSE\n char yymsgbuf[128];\n char *yymsg = yymsgbuf;\n YYSIZE_T yymsg_alloc = sizeof yymsgbuf;\n#endif\n#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))\n int yylen = 0;\n yyssp = yyss = yyssa;\n yyvsp = yyvs = yyvsa;\n yystacksize = YYINITDEPTH;\n YYDPRINTF ((stderr, "Starting parse\\n"));\n yystate = 0;\n yyerrstatus = 0;\n yynerrs = 0;\n yychar = YYEMPTY;\n goto yysetstate;\n yynewstate:\n yyssp++;\n yysetstate:\n *yyssp = yystate;\n if (yyss + yystacksize - 1 <= yyssp)\n {\n YYSIZE_T yysize = yyssp - yyss + 1;\n#ifdef yyoverflow\n {\n\tYYSTYPE *yyvs1 = yyvs;\n\tyytype_int16 *yyss1 = yyss;\n\tyyoverflow (YY_("memory exhausted"),\n\t\t &yyss1, yysize * sizeof (*yyssp),\n\t\t &yyvs1, yysize * sizeof (*yyvsp),\n\t\t &yystacksize);\n\tyyss = yyss1;\n\tyyvs = yyvs1;\n }\n#else\n# ifndef YYSTACK_RELOCATE\n goto yyexhaustedlab;\n# else\n if (YYMAXDEPTH <= yystacksize)\n\tgoto yyexhaustedlab;\n yystacksize *= 2;\n if (YYMAXDEPTH < yystacksize)\n\tyystacksize = YYMAXDEPTH;\n {\n\tyytype_int16 *yyss1 = yyss;\n\tunion yyalloc *yyptr =\n\t (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));\n\tif (! yyptr)\n\t goto yyexhaustedlab;\n\tYYSTACK_RELOCATE (yyss_alloc, yyss);\n\tYYSTACK_RELOCATE (yyvs_alloc, yyvs);\n# undef YYSTACK_RELOCATE\n\tif (yyss1 != yyssa)\n\t YYSTACK_FREE (yyss1);\n }\n# endif\n#endif\n yyssp = yyss + yysize - 1;\n yyvsp = yyvs + yysize - 1;\n YYDPRINTF ((stderr, "Stack size increased to %lu\\n",\n\t\t (unsigned long int) yystacksize));\n if (yyss + yystacksize - 1 <= yyssp)\n\tYYABORT;\n }\n YYDPRINTF ((stderr, "Entering state %d\\n", yystate));\n if (yystate == YYFINAL)\n YYACCEPT;\n goto yybackup;\nyybackup:\n yyn = yypact[yystate];\n if (yypact_value_is_default (yyn))\n goto yydefault;\n if (yychar == YYEMPTY)\n {\n YYDPRINTF ((stderr, "Reading a token: "));\n yychar = YYLEX;\n }\n if (yychar <= YYEOF)\n {\n yychar = yytoken = YYEOF;\n YYDPRINTF ((stderr, "Now at end of input.\\n"));\n }\n else\n {\n yytoken = YYTRANSLATE (yychar);\n YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);\n }\n yyn += yytoken;\n if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)\n goto yydefault;\n yyn = yytable[yyn];\n if (yyn <= 0)\n {\n if (yytable_value_is_error (yyn))\n goto yyerrlab;\n yyn = -yyn;\n goto yyreduce;\n }\n if (yyerrstatus)\n yyerrstatus--;\n YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);\n yychar = YYEMPTY;\n yystate = yyn;\n YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n *++yyvsp = yylval;\n YY_IGNORE_MAYBE_UNINITIALIZED_END\n goto yynewstate;\nyydefault:\n yyn = yydefact[yystate];\n if (yyn == 0)\n goto yyerrlab;\n goto yyreduce;\nyyreduce:\n yylen = yyr2[yyn];\n yyval = yyvsp[1-yylen];\n YY_REDUCE_PRINT (yyn);\n switch (yyn)\n {\n case 2:\n#line 112 "util_expr_parse.y"\n { ctx->expr = (yyvsp[(2) - (2)].exVal); }\n break;\n case 3:\n#line 113 "util_expr_parse.y"\n { ctx->expr = (yyvsp[(2) - (2)].exVal); }\n break;\n case 4:\n#line 114 "util_expr_parse.y"\n { YYABORT; }\n break;\n case 5:\n#line 117 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_True, NULL, NULL, ctx); }\n break;\n case 6:\n#line 118 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_False, NULL, NULL, ctx); }\n break;\n case 7:\n#line 119 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_Not, (yyvsp[(2) - (2)].exVal), NULL, ctx); }\n break;\n case 8:\n#line 120 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_Or, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 9:\n#line 121 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_And, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 10:\n#line 122 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_Comp, (yyvsp[(1) - (1)].exVal), NULL, ctx); }\n break;\n case 11:\n#line 123 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_unary_op_make( (yyvsp[(1) - (2)].cpVal), (yyvsp[(2) - (2)].exVal), ctx); }\n break;\n case 12:\n#line 124 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_binary_op_make((yyvsp[(2) - (3)].cpVal), (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 13:\n#line 125 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(2) - (3)].exVal); }\n break;\n case 14:\n#line 126 "util_expr_parse.y"\n { YYABORT; }\n break;\n case 15:\n#line 129 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_EQ, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 16:\n#line 130 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_NE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 17:\n#line 131 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_LT, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 18:\n#line 132 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_LE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 19:\n#line 133 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_GT, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 20:\n#line 134 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_GE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 21:\n#line 135 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_STR_EQ, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 22:\n#line 136 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_STR_NE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 23:\n#line 137 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_STR_LT, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 24:\n#line 138 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_STR_LE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 25:\n#line 139 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_STR_GT, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 26:\n#line 140 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_STR_GE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 27:\n#line 141 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_IN, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 28:\n#line 142 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_REG, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 29:\n#line 143 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_NRE, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 30:\n#line 146 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 31:\n#line 147 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(2) - (3)].exVal); }\n break;\n case 32:\n#line 150 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_ListElement, (yyvsp[(1) - (1)].exVal), NULL, ctx); }\n break;\n case 33:\n#line 151 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_ListElement, (yyvsp[(3) - (3)].exVal), (yyvsp[(1) - (3)].exVal), ctx); }\n break;\n case 34:\n#line 154 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_Concat, (yyvsp[(1) - (2)].exVal), (yyvsp[(2) - (2)].exVal), ctx); }\n break;\n case 35:\n#line 155 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 36:\n#line 156 "util_expr_parse.y"\n { YYABORT; }\n break;\n case 37:\n#line 159 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_String, (yyvsp[(1) - (1)].cpVal), NULL, ctx); }\n break;\n case 38:\n#line 160 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 39:\n#line 161 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 40:\n#line 164 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_var_make((yyvsp[(2) - (3)].cpVal), ctx); }\n break;\n case 41:\n#line 165 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_str_func_make((yyvsp[(2) - (5)].cpVal), (yyvsp[(4) - (5)].exVal), ctx); }\n break;\n case 42:\n#line 168 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_Digit, (yyvsp[(1) - (1)].cpVal), NULL, ctx); }\n break;\n case 43:\n#line 169 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_Concat, (yyvsp[(1) - (3)].exVal), (yyvsp[(3) - (3)].exVal), ctx); }\n break;\n case 44:\n#line 170 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 45:\n#line 171 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 46:\n#line 172 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(1) - (1)].exVal); }\n break;\n case 47:\n#line 173 "util_expr_parse.y"\n { (yyval.exVal) = (yyvsp[(2) - (3)].exVal); }\n break;\n case 48:\n#line 174 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_make(op_String, "", NULL, ctx); }\n break;\n case 49:\n#line 177 "util_expr_parse.y"\n {\n ap_regex_t *regex;\n if ((regex = ap_pregcomp(ctx->pool, (yyvsp[(1) - (1)].cpVal),\n AP_REG_EXTENDED|AP_REG_NOSUB)) == NULL) {\n ctx->error = "Failed to compile regular expression";\n YYERROR;\n }\n (yyval.exVal) = ap_expr_make(op_Regex, regex, NULL, ctx);\n }\n break;\n case 50:\n#line 186 "util_expr_parse.y"\n {\n ap_regex_t *regex;\n if ((regex = ap_pregcomp(ctx->pool, (yyvsp[(1) - (1)].cpVal),\n AP_REG_EXTENDED|AP_REG_NOSUB|AP_REG_ICASE)) == NULL) {\n ctx->error = "Failed to compile regular expression";\n YYERROR;\n }\n (yyval.exVal) = ap_expr_make(op_Regex, regex, NULL, ctx);\n }\n break;\n case 51:\n#line 197 "util_expr_parse.y"\n {\n int *n = apr_palloc(ctx->pool, sizeof(int));\n *n = (yyvsp[(1) - (1)].num);\n (yyval.exVal) = ap_expr_make(op_RegexBackref, n, NULL, ctx);\n }\n break;\n case 52:\n#line 204 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_list_func_make((yyvsp[(1) - (4)].cpVal), (yyvsp[(3) - (4)].exVal), ctx); }\n break;\n case 53:\n#line 207 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_str_func_make((yyvsp[(1) - (4)].cpVal), (yyvsp[(3) - (4)].exVal), ctx); }\n break;\n case 54:\n#line 208 "util_expr_parse.y"\n { (yyval.exVal) = ap_expr_str_func_make((yyvsp[(1) - (4)].cpVal), (yyvsp[(3) - (4)].exVal), ctx); }\n break;\n#line 1849 "util_expr_parse.c"\n default: break;\n }\n YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);\n YYPOPSTACK (yylen);\n yylen = 0;\n YY_STACK_PRINT (yyss, yyssp);\n *++yyvsp = yyval;\n yyn = yyr1[yyn];\n yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;\n if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)\n yystate = yytable[yystate];\n else\n yystate = yydefgoto[yyn - YYNTOKENS];\n goto yynewstate;\nyyerrlab:\n yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);\n if (!yyerrstatus)\n {\n ++yynerrs;\n#if ! YYERROR_VERBOSE\n yyerror (ctx, YY_("syntax error"));\n#else\n# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \\\n yyssp, yytoken)\n {\n char const *yymsgp = YY_("syntax error");\n int yysyntax_error_status;\n yysyntax_error_status = YYSYNTAX_ERROR;\n if (yysyntax_error_status == 0)\n yymsgp = yymsg;\n else if (yysyntax_error_status == 1)\n {\n if (yymsg != yymsgbuf)\n YYSTACK_FREE (yymsg);\n yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);\n if (!yymsg)\n {\n yymsg = yymsgbuf;\n yymsg_alloc = sizeof yymsgbuf;\n yysyntax_error_status = 2;\n }\n else\n {\n yysyntax_error_status = YYSYNTAX_ERROR;\n yymsgp = yymsg;\n }\n }\n yyerror (ctx, yymsgp);\n if (yysyntax_error_status == 2)\n goto yyexhaustedlab;\n }\n# undef YYSYNTAX_ERROR\n#endif\n }\n if (yyerrstatus == 3)\n {\n if (yychar <= YYEOF)\n\t{\n\t if (yychar == YYEOF)\n\t YYABORT;\n\t}\n else\n\t{\n\t yydestruct ("Error: discarding",\n\t\t yytoken, &yylval, ctx);\n\t yychar = YYEMPTY;\n\t}\n }\n goto yyerrlab1;\nyyerrorlab:\n if ( 0)\n goto yyerrorlab;\n YYPOPSTACK (yylen);\n yylen = 0;\n YY_STACK_PRINT (yyss, yyssp);\n yystate = *yyssp;\n goto yyerrlab1;\nyyerrlab1:\n yyerrstatus = 3;\n for (;;)\n {\n yyn = yypact[yystate];\n if (!yypact_value_is_default (yyn))\n\t{\n\t yyn += YYTERROR;\n\t if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)\n\t {\n\t yyn = yytable[yyn];\n\t if (0 < yyn)\n\t\tbreak;\n\t }\n\t}\n if (yyssp == yyss)\n\tYYABORT;\n yydestruct ("Error: popping",\n\t\t yystos[yystate], yyvsp, ctx);\n YYPOPSTACK (1);\n yystate = *yyssp;\n YY_STACK_PRINT (yyss, yyssp);\n }\n YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN\n *++yyvsp = yylval;\n YY_IGNORE_MAYBE_UNINITIALIZED_END\n YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);\n yystate = yyn;\n goto yynewstate;\nyyacceptlab:\n yyresult = 0;\n goto yyreturn;\nyyabortlab:\n yyresult = 1;\n goto yyreturn;\n#if !defined yyoverflow || YYERROR_VERBOSE\nyyexhaustedlab:\n yyerror (ctx, YY_("memory exhausted"));\n yyresult = 2;\n#endif\nyyreturn:\n if (yychar != YYEMPTY)\n {\n yytoken = YYTRANSLATE (yychar);\n yydestruct ("Cleanup: discarding lookahead",\n yytoken, &yylval, ctx);\n }\n YYPOPSTACK (yylen);\n YY_STACK_PRINT (yyss, yyssp);\n while (yyssp != yyss)\n {\n yydestruct ("Cleanup: popping",\n\t\t yystos[*yyssp], yyvsp, ctx);\n YYPOPSTACK (1);\n }\n#ifndef yyoverflow\n if (yyss != yyssa)\n YYSTACK_FREE (yyss);\n#endif\n#if YYERROR_VERBOSE\n if (yymsg != yymsgbuf)\n YYSTACK_FREE (yymsg);\n#endif\n return YYID (yyresult);\n}', 'YY_DECL\n{\n\tregister yy_state_type yy_current_state;\n\tregister char *yy_cp, *yy_bp;\n\tregister int yy_act;\n struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;\n#line 93 "util_expr_scan.l"\n char regex_buf[MAX_STRING_LEN];\n char *regex_ptr = NULL;\n char regex_del = \'\\0\';\n if (yyextra->at_start) {\n yyextra->at_start = 0;\n if (yyextra->flags & AP_EXPR_FLAG_STRING_RESULT) {\n BEGIN(str);\n return T_EXPR_STRING;\n }\n else {\n return T_EXPR_BOOL;\n }\n }\n#line 901 "util_expr_scan.c"\n yylval = yylval_param;\n\tif ( !yyg->yy_init )\n\t\t{\n\t\tyyg->yy_init = 1;\n#ifdef YY_USER_INIT\n\t\tYY_USER_INIT;\n#endif\n\t\tif ( ! yyg->yy_start )\n\t\t\tyyg->yy_start = 1;\n\t\tif ( ! yyin )\n\t\t\tyyin = stdin;\n\t\tif ( ! yyout )\n\t\t\tyyout = stdout;\n\t\tif ( ! YY_CURRENT_BUFFER ) {\n\t\t\tap_expr_yyensure_buffer_stack (yyscanner);\n\t\t\tYY_CURRENT_BUFFER_LVALUE =\n\t\t\t\tap_expr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);\n\t\t}\n\t\tap_expr_yy_load_buffer_state(yyscanner );\n\t\t}\n\twhile ( 1 )\n\t\t{\n\t\tyy_cp = yyg->yy_c_buf_p;\n\t\t*yy_cp = yyg->yy_hold_char;\n\t\tyy_bp = yy_cp;\n\t\tyy_current_state = yyg->yy_start;\nyy_match:\n\t\tdo\n\t\t\t{\n\t\t\tregister YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];\n\t\t\tif ( yy_accept[yy_current_state] )\n\t\t\t\t{\n\t\t\t\tyyg->yy_last_accepting_state = yy_current_state;\n\t\t\t\tyyg->yy_last_accepting_cpos = yy_cp;\n\t\t\t\t}\n\t\t\twhile ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )\n\t\t\t\t{\n\t\t\t\tyy_current_state = (int) yy_def[yy_current_state];\n\t\t\t\tif ( yy_current_state >= 124 )\n\t\t\t\t\tyy_c = yy_meta[(unsigned int) yy_c];\n\t\t\t\t}\n\t\t\tyy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];\n\t\t\t++yy_cp;\n\t\t\t}\n\t\twhile ( yy_current_state != 123 );\n\t\tyy_cp = yyg->yy_last_accepting_cpos;\n\t\tyy_current_state = yyg->yy_last_accepting_state;\nyy_find_action:\n\t\tyy_act = yy_accept[yy_current_state];\n\t\tYY_DO_BEFORE_ACTION;\ndo_action:\n\t\tswitch ( yy_act )\n\t{\n\t\t\tcase 0:\n\t\t\t*yy_cp = yyg->yy_hold_char;\n\t\t\tyy_cp = yyg->yy_last_accepting_cpos;\n\t\t\tyy_current_state = yyg->yy_last_accepting_state;\n\t\t\tgoto yy_find_action;\ncase 1:\nYY_RULE_SETUP\n#line 118 "util_expr_scan.l"\n{\n}\n\tYY_BREAK\ncase 2:\nYY_RULE_SETUP\n#line 125 "util_expr_scan.l"\n{\n str_ptr = str_buf;\n str_del = yytext[0];\n BEGIN(str);\n return T_STR_BEGIN;\n}\n\tYY_BREAK\ncase 3:\nYY_RULE_SETUP\n#line 131 "util_expr_scan.l"\n{\n if (yytext[0] == str_del) {\n if (YY_START == var) {\n PERROR("Unterminated variable in string");\n }\n else if (str_ptr == str_buf) {\n BEGIN(INITIAL);\n return T_STR_END;\n }\n else {\n *str_ptr = \'\\0\';\n yylval->cpVal = apr_pstrdup(yyextra->pool, str_buf);\n yyless(0);\n str_ptr = str_buf;\n return T_STRING;\n }\n }\n else {\n STR_APPEND(yytext[0]);\n }\n}\n\tYY_BREAK\ncase 4:\nYY_RULE_SETUP\n#line 153 "util_expr_scan.l"\n{\n PERROR("Unterminated string or variable");\n}\n\tYY_BREAK\ncase YY_STATE_EOF(var):\ncase YY_STATE_EOF(vararg):\n#line 156 "util_expr_scan.l"\n{\n PERROR("Unterminated string or variable");\n}\n\tYY_BREAK\ncase YY_STATE_EOF(str):\n#line 159 "util_expr_scan.l"\n{\n if (!(yyextra->flags & AP_EXPR_FLAG_STRING_RESULT)) {\n PERROR("Unterminated string or variable");\n }\n else {\n *str_ptr = \'\\0\';\n yylval->cpVal = apr_pstrdup(yyextra->pool, str_buf);\n str_ptr = str_buf;\n BEGIN(INITIAL);\n return T_STRING;\n }\n}\n\tYY_BREAK\ncase 5:\nYY_RULE_SETUP\n#line 172 "util_expr_scan.l"\n{\n int result;\n (void)sscanf(yytext+1, "%o", &result);\n if (result > 0xff) {\n PERROR("Escape sequence out of bound");\n }\n else {\n STR_APPEND(result);\n }\n}\n\tYY_BREAK\ncase 6:\nYY_RULE_SETUP\n#line 183 "util_expr_scan.l"\n{\n PERROR("Bad escape sequence");\n}\n\tYY_BREAK\ncase 7:\nYY_RULE_SETUP\n#line 186 "util_expr_scan.l"\n{ STR_APPEND(\'\\n\'); }\n\tYY_BREAK\ncase 8:\nYY_RULE_SETUP\n#line 187 "util_expr_scan.l"\n{ STR_APPEND(\'\\r\'); }\n\tYY_BREAK\ncase 9:\nYY_RULE_SETUP\n#line 188 "util_expr_scan.l"\n{ STR_APPEND(\'\\t\'); }\n\tYY_BREAK\ncase 10:\nYY_RULE_SETUP\n#line 189 "util_expr_scan.l"\n{ STR_APPEND(\'\\b\'); }\n\tYY_BREAK\ncase 11:\nYY_RULE_SETUP\n#line 190 "util_expr_scan.l"\n{ STR_APPEND(\'\\f\'); }\n\tYY_BREAK\ncase 12:\nYY_RULE_SETUP\n#line 191 "util_expr_scan.l"\n{ STR_APPEND(yytext[1]); }\n\tYY_BREAK\ncase 13:\nYY_RULE_SETUP\n#line 194 "util_expr_scan.l"\n{\n if (str_ptr != str_buf) {\n *str_ptr = \'\\0\';\n yylval->cpVal = apr_pstrdup(yyextra->pool, str_buf);\n str_ptr = str_buf;\n yyless(0);\n return T_STRING;\n }\n else {\n yylval->num = yytext[1] - \'0\';\n return T_REGEX_BACKREF;\n }\n}\n\tYY_BREAK\ncase 14:\nYY_RULE_SETUP\n#line 209 "util_expr_scan.l"\n{\n char *cp = yytext;\n while (*cp != \'\\0\') {\n STR_APPEND(*cp);\n cp++;\n }\n}\n\tYY_BREAK\ncase 15:\nYY_RULE_SETUP\n#line 218 "util_expr_scan.l"\n{\n if (str_ptr != str_buf) {\n *str_ptr = \'\\0\';\n yylval->cpVal = apr_pstrdup(yyextra->pool, str_buf);\n yyless(0);\n str_ptr = str_buf;\n return T_STRING;\n }\n else {\n yy_push_state(var, yyscanner);\n return T_VAR_BEGIN;\n }\n}\n\tYY_BREAK\ncase 16:\nYY_RULE_SETUP\n#line 233 "util_expr_scan.l"\n{\n STR_APPEND(yytext[0]);\n}\n\tYY_BREAK\ncase 17:\nYY_RULE_SETUP\n#line 237 "util_expr_scan.l"\n{\n STR_APPEND(yytext[0]);\n}\n\tYY_BREAK\ncase 18:\nYY_RULE_SETUP\n#line 241 "util_expr_scan.l"\n{\n yy_push_state(var, yyscanner);\n return T_VAR_BEGIN;\n}\n\tYY_BREAK\ncase 19:\nYY_RULE_SETUP\n#line 246 "util_expr_scan.l"\n{\n yylval->num = yytext[1] - \'0\';\n return T_REGEX_BACKREF;\n}\n\tYY_BREAK\ncase 20:\nYY_RULE_SETUP\n#line 254 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, yytext);\n return T_ID;\n}\n\tYY_BREAK\ncase 21:\nYY_RULE_SETUP\n#line 259 "util_expr_scan.l"\n{\n yy_pop_state(yyscanner);\n return T_VAR_END;\n}\n\tYY_BREAK\ncase 22:\nYY_RULE_SETUP\n#line 264 "util_expr_scan.l"\n{\n BEGIN(vararg);\n return yytext[0];\n}\n\tYY_BREAK\ncase 23:\nYY_RULE_SETUP\n#line 269 "util_expr_scan.l"\n{\n char *msg = apr_psprintf(yyextra->pool,\n "Invalid character in variable name \'%c\'", yytext[0]);\n PERROR(msg);\n}\n\tYY_BREAK\ncase 24:\nYY_RULE_SETUP\n#line 275 "util_expr_scan.l"\n{\n if (str_ptr != str_buf) {\n *str_ptr = \'\\0\';\n yylval->cpVal = apr_pstrdup(yyextra->pool, str_buf);\n str_ptr = str_buf;\n yyless(0);\n return T_STRING;\n }\n else {\n yy_pop_state(yyscanner);\n return T_VAR_END;\n }\n}\n\tYY_BREAK\ncase 25:\nYY_RULE_SETUP\n#line 293 "util_expr_scan.l"\n{\n regex_del = yytext[1];\n regex_ptr = regex_buf;\n BEGIN(regex);\n}\n\tYY_BREAK\ncase 26:\nYY_RULE_SETUP\n#line 298 "util_expr_scan.l"\n{\n regex_del = yytext[0];\n regex_ptr = regex_buf;\n BEGIN(regex);\n}\n\tYY_BREAK\ncase 27:\nYY_RULE_SETUP\n#line 303 "util_expr_scan.l"\n{\n if (yytext[0] == regex_del) {\n *regex_ptr = \'\\0\';\n BEGIN(regex_flags);\n }\n else {\n *regex_ptr++ = yytext[0];\n if (regex_ptr >= regex_buf + sizeof(regex_buf))\n PERROR("Regexp too long");\n }\n}\n\tYY_BREAK\ncase 28:\nYY_RULE_SETUP\n#line 314 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, regex_buf);\n BEGIN(INITIAL);\n return T_REGEX_I;\n}\n\tYY_BREAK\ncase 29:\nYY_RULE_SETUP\n#line 319 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, regex_buf);\n yyless(0);\n BEGIN(INITIAL);\n return T_REGEX;\n}\n\tYY_BREAK\ncase YY_STATE_EOF(regex_flags):\n#line 325 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, regex_buf);\n BEGIN(INITIAL);\n return T_REGEX;\n}\n\tYY_BREAK\ncase 30:\nYY_RULE_SETUP\n#line 334 "util_expr_scan.l"\n{ return T_OP_STR_EQ; }\n\tYY_BREAK\ncase 31:\nYY_RULE_SETUP\n#line 335 "util_expr_scan.l"\n{ return T_OP_STR_NE; }\n\tYY_BREAK\ncase 32:\nYY_RULE_SETUP\n#line 336 "util_expr_scan.l"\n{ return T_OP_STR_LT; }\n\tYY_BREAK\ncase 33:\nYY_RULE_SETUP\n#line 337 "util_expr_scan.l"\n{ return T_OP_STR_LE; }\n\tYY_BREAK\ncase 34:\nYY_RULE_SETUP\n#line 338 "util_expr_scan.l"\n{ return T_OP_STR_GT; }\n\tYY_BREAK\ncase 35:\nYY_RULE_SETUP\n#line 339 "util_expr_scan.l"\n{ return T_OP_STR_GE; }\n\tYY_BREAK\ncase 36:\nYY_RULE_SETUP\n#line 340 "util_expr_scan.l"\n{ return T_OP_REG; }\n\tYY_BREAK\ncase 37:\nYY_RULE_SETUP\n#line 341 "util_expr_scan.l"\n{ return T_OP_NRE; }\n\tYY_BREAK\ncase 38:\nYY_RULE_SETUP\n#line 342 "util_expr_scan.l"\n{ return T_OP_AND; }\n\tYY_BREAK\ncase 39:\nYY_RULE_SETUP\n#line 343 "util_expr_scan.l"\n{ return T_OP_AND; }\n\tYY_BREAK\ncase 40:\nYY_RULE_SETUP\n#line 344 "util_expr_scan.l"\n{ return T_OP_OR; }\n\tYY_BREAK\ncase 41:\nYY_RULE_SETUP\n#line 345 "util_expr_scan.l"\n{ return T_OP_OR; }\n\tYY_BREAK\ncase 42:\nYY_RULE_SETUP\n#line 346 "util_expr_scan.l"\n{ return T_OP_NOT; }\n\tYY_BREAK\ncase 43:\nYY_RULE_SETUP\n#line 347 "util_expr_scan.l"\n{ return T_OP_NOT; }\n\tYY_BREAK\ncase 44:\nYY_RULE_SETUP\n#line 348 "util_expr_scan.l"\n{ return T_OP_CONCAT; }\n\tYY_BREAK\ncase 45:\nYY_RULE_SETUP\n#line 349 "util_expr_scan.l"\n{ return T_OP_IN; }\n\tYY_BREAK\ncase 46:\nYY_RULE_SETUP\n#line 350 "util_expr_scan.l"\n{ return T_OP_EQ; }\n\tYY_BREAK\ncase 47:\nYY_RULE_SETUP\n#line 351 "util_expr_scan.l"\n{ return T_OP_NE; }\n\tYY_BREAK\ncase 48:\nYY_RULE_SETUP\n#line 352 "util_expr_scan.l"\n{ return T_OP_GE; }\n\tYY_BREAK\ncase 49:\nYY_RULE_SETUP\n#line 353 "util_expr_scan.l"\n{ return T_OP_LE; }\n\tYY_BREAK\ncase 50:\nYY_RULE_SETUP\n#line 354 "util_expr_scan.l"\n{ return T_OP_GT; }\n\tYY_BREAK\ncase 51:\nYY_RULE_SETUP\n#line 355 "util_expr_scan.l"\n{ return T_OP_LT; }\n\tYY_BREAK\ncase 52:\nYY_RULE_SETUP\n#line 358 "util_expr_scan.l"\n{ return T_OP_LT; }\n\tYY_BREAK\ncase 53:\nYY_RULE_SETUP\n#line 359 "util_expr_scan.l"\n{ return T_OP_LE; }\n\tYY_BREAK\ncase 54:\nYY_RULE_SETUP\n#line 360 "util_expr_scan.l"\n{ return T_OP_GT; }\n\tYY_BREAK\ncase 55:\nYY_RULE_SETUP\n#line 361 "util_expr_scan.l"\n{ return T_OP_GE; }\n\tYY_BREAK\ncase 56:\nYY_RULE_SETUP\n#line 362 "util_expr_scan.l"\n{ return T_OP_NE; }\n\tYY_BREAK\ncase 57:\nYY_RULE_SETUP\n#line 363 "util_expr_scan.l"\n{ return T_OP_EQ; }\n\tYY_BREAK\ncase 58:\nYY_RULE_SETUP\n#line 364 "util_expr_scan.l"\n{ return T_OP_IN; }\n\tYY_BREAK\ncase 59:\nYY_RULE_SETUP\n#line 366 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, yytext + 1);\n return T_OP_UNARY;\n}\n\tYY_BREAK\ncase 60:\nYY_RULE_SETUP\n#line 371 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, yytext + 1);\n return T_OP_BINARY;\n}\n\tYY_BREAK\ncase 61:\nYY_RULE_SETUP\n#line 379 "util_expr_scan.l"\n{ return T_TRUE; }\n\tYY_BREAK\ncase 62:\nYY_RULE_SETUP\n#line 380 "util_expr_scan.l"\n{ return T_FALSE; }\n\tYY_BREAK\ncase 63:\nYY_RULE_SETUP\n#line 385 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, yytext);\n return T_DIGIT;\n}\n\tYY_BREAK\ncase 64:\nYY_RULE_SETUP\n#line 393 "util_expr_scan.l"\n{\n yylval->cpVal = apr_pstrdup(yyextra->pool, yytext);\n return T_ID;\n}\n\tYY_BREAK\ncase 65:\nYY_RULE_SETUP\n#line 401 "util_expr_scan.l"\n{\n return yytext[0];\n}\n\tYY_BREAK\ncase 66:\nYY_RULE_SETUP\n#line 408 "util_expr_scan.l"\n{\n char *msg = apr_psprintf(yyextra->pool, "Parse error near \'%c\'", yytext[0]);\n PERROR(msg);\n}\n\tYY_BREAK\ncase 67:\nYY_RULE_SETUP\n#line 413 "util_expr_scan.l"\nYY_FATAL_ERROR( "flex scanner jammed" );\n\tYY_BREAK\n#line 1538 "util_expr_scan.c"\ncase YY_STATE_EOF(INITIAL):\ncase YY_STATE_EOF(regex):\n\tyyterminate();\n\tcase YY_END_OF_BUFFER:\n\t\t{\n\t\tint yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;\n\t\t*yy_cp = yyg->yy_hold_char;\n\t\tYY_RESTORE_YY_MORE_OFFSET\n\t\tif ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )\n\t\t\t{\n\t\t\tyyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;\n\t\t\tYY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;\n\t\t\tYY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;\n\t\t\t}\n\t\tif ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )\n\t\t\t{\n\t\t\tyy_state_type yy_next_state;\n\t\t\tyyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;\n\t\t\tyy_current_state = yy_get_previous_state( yyscanner );\n\t\t\tyy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);\n\t\t\tyy_bp = yyg->yytext_ptr + YY_MORE_ADJ;\n\t\t\tif ( yy_next_state )\n\t\t\t\t{\n\t\t\t\tyy_cp = ++yyg->yy_c_buf_p;\n\t\t\t\tyy_current_state = yy_next_state;\n\t\t\t\tgoto yy_match;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tyy_cp = yyg->yy_last_accepting_cpos;\n\t\t\t\tyy_current_state = yyg->yy_last_accepting_state;\n\t\t\t\tgoto yy_find_action;\n\t\t\t\t}\n\t\t\t}\n\t\telse switch ( yy_get_next_buffer( yyscanner ) )\n\t\t\t{\n\t\t\tcase EOB_ACT_END_OF_FILE:\n\t\t\t\t{\n\t\t\t\tyyg->yy_did_buffer_switch_on_eof = 0;\n\t\t\t\tif ( ap_expr_yywrap(yyscanner ) )\n\t\t\t\t\t{\n\t\t\t\t\tyyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;\n\t\t\t\t\tyy_act = YY_STATE_EOF(YY_START);\n\t\t\t\t\tgoto do_action;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif ( ! yyg->yy_did_buffer_switch_on_eof )\n\t\t\t\t\t\tYY_NEW_FILE;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\tcase EOB_ACT_CONTINUE_SCAN:\n\t\t\t\tyyg->yy_c_buf_p =\n\t\t\t\t\tyyg->yytext_ptr + yy_amount_of_matched_text;\n\t\t\t\tyy_current_state = yy_get_previous_state( yyscanner );\n\t\t\t\tyy_cp = yyg->yy_c_buf_p;\n\t\t\t\tyy_bp = yyg->yytext_ptr + YY_MORE_ADJ;\n\t\t\t\tgoto yy_match;\n\t\t\tcase EOB_ACT_LAST_MATCH:\n\t\t\t\tyyg->yy_c_buf_p =\n\t\t\t\t&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];\n\t\t\t\tyy_current_state = yy_get_previous_state( yyscanner );\n\t\t\t\tyy_cp = yyg->yy_c_buf_p;\n\t\t\t\tyy_bp = yyg->yytext_ptr + YY_MORE_ADJ;\n\t\t\t\tgoto yy_find_action;\n\t\t\t}\n\t\tbreak;\n\t\t}\n\tdefault:\n\t\tYY_FATAL_ERROR(\n\t\t\t"fatal flex scanner internal error--no action found" );\n\t}\n\t\t}\n}', 'static void ap_expr_yyensure_buffer_stack (yyscan_t yyscanner)\n{\n\tint num_to_alloc;\n struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;\n\tif (!yyg->yy_buffer_stack) {\n\t\tnum_to_alloc = 1;\n\t\tyyg->yy_buffer_stack = (struct yy_buffer_state**)ap_expr_yyalloc\n\t\t\t\t\t\t\t\t(num_to_alloc * sizeof(struct yy_buffer_state*)\n\t\t\t\t\t\t\t\t, yyscanner);\n\t\tif ( ! yyg->yy_buffer_stack )\n\t\t\tYY_FATAL_ERROR( "out of dynamic memory in ap_expr_yyensure_buffer_stack()" );\n\t\tmemset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));\n\t\tyyg->yy_buffer_stack_max = num_to_alloc;\n\t\tyyg->yy_buffer_stack_top = 0;\n\t\treturn;\n\t}\n\tif (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){\n\t\tint grow_size = 8 ;\n\t\tnum_to_alloc = yyg->yy_buffer_stack_max + grow_size;\n\t\tyyg->yy_buffer_stack = (struct yy_buffer_state**)ap_expr_yyrealloc\n\t\t\t\t\t\t\t\t(yyg->yy_buffer_stack,\n\t\t\t\t\t\t\t\tnum_to_alloc * sizeof(struct yy_buffer_state*)\n\t\t\t\t\t\t\t\t, yyscanner);\n\t\tif ( ! yyg->yy_buffer_stack )\n\t\t\tYY_FATAL_ERROR( "out of dynamic memory in ap_expr_yyensure_buffer_stack()" );\n\t\tmemset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));\n\t\tyyg->yy_buffer_stack_max = num_to_alloc;\n\t}\n}'] |
35,051 | 0 | https://github.com/libav/libav/blob/baf35bb4bc4fe7a2a4113c50989d11dd9ef81e76/libavcodec/faanidct.c/#L58 | static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){
int i;
FLOAT av_unused tmp0;
FLOAT s04, d04, s17, d17, s26, d26, s53, d53;
FLOAT os07, os16, os25, os34;
FLOAT od07, od16, od25, od34;
for(i=0; i<y*8; i+=y){
s17= temp[1*x + i] + temp[7*x + i];
d17= temp[1*x + i] - temp[7*x + i];
s53= temp[5*x + i] + temp[3*x + i];
d53= temp[5*x + i] - temp[3*x + i];
od07= s17 + s53;
od25= (s17 - s53)*(2*A4);
#if 0
tmp0= (d17 + d53)*(2*A2);
od34= d17*( 2*B6) - tmp0;
od16= d53*(-2*B2) + tmp0;
#else
od34= d17*(2*(B6-A2)) - d53*(2*A2);
od16= d53*(2*(A2-B2)) + d17*(2*A2);
#endif
od16 -= od07;
od25 -= od16;
od34 += od25;
s26 = temp[2*x + i] + temp[6*x + i];
d26 = temp[2*x + i] - temp[6*x + i];
d26*= 2*A4;
d26-= s26;
s04= temp[0*x + i] + temp[4*x + i];
d04= temp[0*x + i] - temp[4*x + i];
os07= s04 + s26;
os34= s04 - s26;
os16= d04 + d26;
os25= d04 - d26;
if(type==0){
temp[0*x + i]= os07 + od07;
temp[7*x + i]= os07 - od07;
temp[1*x + i]= os16 + od16;
temp[6*x + i]= os16 - od16;
temp[2*x + i]= os25 + od25;
temp[5*x + i]= os25 - od25;
temp[3*x + i]= os34 - od34;
temp[4*x + i]= os34 + od34;
}else if(type==1){
data[0*x + i]= lrintf(os07 + od07);
data[7*x + i]= lrintf(os07 - od07);
data[1*x + i]= lrintf(os16 + od16);
data[6*x + i]= lrintf(os16 - od16);
data[2*x + i]= lrintf(os25 + od25);
data[5*x + i]= lrintf(os25 - od25);
data[3*x + i]= lrintf(os34 - od34);
data[4*x + i]= lrintf(os34 + od34);
}else if(type==2){
dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));
dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));
dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));
dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));
dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));
dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));
dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));
dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));
}else{
dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));
dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));
dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));
dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));
dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));
dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));
dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));
dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));
}
}
} | ['void ff_faanidct_put(uint8_t *dest, int line_size, int16_t block[64]){\n FLOAT temp[64];\n int i;\n emms_c();\n for(i=0; i<64; i++)\n temp[i] = block[i] * prescale[i];\n p8idct(block, temp, NULL, 0, 1, 8, 0);\n p8idct(NULL , temp, dest, line_size, 8, 1, 3);\n}', 'static inline void p8idct(int16_t data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){\n int i;\n FLOAT av_unused tmp0;\n FLOAT s04, d04, s17, d17, s26, d26, s53, d53;\n FLOAT os07, os16, os25, os34;\n FLOAT od07, od16, od25, od34;\n for(i=0; i<y*8; i+=y){\n s17= temp[1*x + i] + temp[7*x + i];\n d17= temp[1*x + i] - temp[7*x + i];\n s53= temp[5*x + i] + temp[3*x + i];\n d53= temp[5*x + i] - temp[3*x + i];\n od07= s17 + s53;\n od25= (s17 - s53)*(2*A4);\n#if 0\n tmp0= (d17 + d53)*(2*A2);\n od34= d17*( 2*B6) - tmp0;\n od16= d53*(-2*B2) + tmp0;\n#else\n od34= d17*(2*(B6-A2)) - d53*(2*A2);\n od16= d53*(2*(A2-B2)) + d17*(2*A2);\n#endif\n od16 -= od07;\n od25 -= od16;\n od34 += od25;\n s26 = temp[2*x + i] + temp[6*x + i];\n d26 = temp[2*x + i] - temp[6*x + i];\n d26*= 2*A4;\n d26-= s26;\n s04= temp[0*x + i] + temp[4*x + i];\n d04= temp[0*x + i] - temp[4*x + i];\n os07= s04 + s26;\n os34= s04 - s26;\n os16= d04 + d26;\n os25= d04 - d26;\n if(type==0){\n temp[0*x + i]= os07 + od07;\n temp[7*x + i]= os07 - od07;\n temp[1*x + i]= os16 + od16;\n temp[6*x + i]= os16 - od16;\n temp[2*x + i]= os25 + od25;\n temp[5*x + i]= os25 - od25;\n temp[3*x + i]= os34 - od34;\n temp[4*x + i]= os34 + od34;\n }else if(type==1){\n data[0*x + i]= lrintf(os07 + od07);\n data[7*x + i]= lrintf(os07 - od07);\n data[1*x + i]= lrintf(os16 + od16);\n data[6*x + i]= lrintf(os16 - od16);\n data[2*x + i]= lrintf(os25 + od25);\n data[5*x + i]= lrintf(os25 - od25);\n data[3*x + i]= lrintf(os34 - od34);\n data[4*x + i]= lrintf(os34 + od34);\n }else if(type==2){\n dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));\n dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));\n dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));\n dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));\n dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));\n dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));\n dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));\n dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));\n }else{\n dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));\n dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));\n dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));\n dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));\n dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));\n dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));\n dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));\n dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));\n }\n }\n}'] |
35,052 | 0 | https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_ctx.c/#L276 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!bn_to_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, &am, mont, ctx))\n goto err;\n } else if (!bn_to_mont_fixed_top(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', '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_mont_fixed_top(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return bn_mul_mont_fixed_top(r, a, &(mont->RR), mont, ctx);\n}', 'int bn_mul_mont_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n int num = mont->N.top;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n r->flags |= BN_FLG_FIXED_TOP;\n return 1;\n }\n }\n#endif\n if ((a->top + b->top) > 2 * num)\n return 0;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(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}', '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}'] |
35,053 | 0 | https://github.com/libav/libav/blob/0a6aff69366cb60d252ae46bd1d21d4b2074fa71/libavformat/utils.c/#L2682 | void avformat_free_context(AVFormatContext *s)
{
int i;
AVStream *st;
av_opt_free(s);
if (s->iformat && s->iformat->priv_class && s->priv_data)
av_opt_free(s->priv_data);
for(i=0;i<s->nb_streams;i++) {
st = s->streams[i];
if (st->parser) {
av_parser_close(st->parser);
av_free_packet(&st->cur_pkt);
}
av_dict_free(&st->metadata);
av_free(st->index_entries);
av_free(st->codec->extradata);
av_free(st->codec->subtitle_header);
av_free(st->codec);
av_free(st->priv_data);
av_free(st->info);
av_free(st);
}
for(i=s->nb_programs-1; i>=0; i--) {
av_dict_free(&s->programs[i]->metadata);
av_freep(&s->programs[i]->stream_index);
av_freep(&s->programs[i]);
}
av_freep(&s->programs);
av_freep(&s->priv_data);
while(s->nb_chapters--) {
av_dict_free(&s->chapters[s->nb_chapters]->metadata);
av_free(s->chapters[s->nb_chapters]);
}
av_freep(&s->chapters);
av_dict_free(&s->metadata);
av_freep(&s->streams);
av_free(s);
} | ['static int seg_write_header(AVFormatContext *s)\n{\n SegmentContext *seg = s->priv_data;\n AVFormatContext *oc;\n int ret, i;\n seg->number = 0;\n seg->offset_time = 0;\n seg->recording_time = seg->time * 1000000;\n if (seg->list)\n if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE,\n &s->interrupt_callback, NULL)) < 0)\n return ret;\n for (i = 0; i< s->nb_streams; i++)\n seg->has_video +=\n (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO);\n if (seg->has_video > 1)\n av_log(s, AV_LOG_WARNING,\n "More than a single video stream present, "\n "expect issues decoding it.\\n");\n oc = avformat_alloc_context();\n if (!oc) {\n ret = AVERROR(ENOMEM);\n goto fail;\n }\n oc->oformat = av_guess_format(seg->format, s->filename, NULL);\n if (!oc->oformat) {\n ret = AVERROR_MUXER_NOT_FOUND;\n goto fail;\n }\n if (oc->oformat->flags & AVFMT_NOFILE) {\n av_log(s, AV_LOG_ERROR, "format %s not supported.\\n",\n oc->oformat->name);\n ret = AVERROR(EINVAL);\n goto fail;\n }\n seg->avf = oc;\n oc->streams = s->streams;\n oc->nb_streams = s->nb_streams;\n if (av_get_frame_filename(oc->filename, sizeof(oc->filename),\n s->filename, seg->number++) < 0) {\n ret = AVERROR(EINVAL);\n goto fail;\n }\n if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,\n &s->interrupt_callback, NULL)) < 0)\n goto fail;\n if ((ret = avformat_write_header(oc, NULL)) < 0) {\n avio_close(oc->pb);\n goto fail;\n }\n if (seg->list) {\n avio_printf(seg->pb, "%s\\n", oc->filename);\n avio_flush(seg->pb);\n }\nfail:\n if (ret) {\n oc->streams = NULL;\n oc->nb_streams = 0;\n if (seg->list)\n avio_close(seg->pb);\n avformat_free_context(oc);\n }\n return ret;\n}', 'void avformat_free_context(AVFormatContext *s)\n{\n int i;\n AVStream *st;\n av_opt_free(s);\n if (s->iformat && s->iformat->priv_class && s->priv_data)\n av_opt_free(s->priv_data);\n for(i=0;i<s->nb_streams;i++) {\n st = s->streams[i];\n if (st->parser) {\n av_parser_close(st->parser);\n av_free_packet(&st->cur_pkt);\n }\n av_dict_free(&st->metadata);\n av_free(st->index_entries);\n av_free(st->codec->extradata);\n av_free(st->codec->subtitle_header);\n av_free(st->codec);\n av_free(st->priv_data);\n av_free(st->info);\n av_free(st);\n }\n for(i=s->nb_programs-1; i>=0; i--) {\n av_dict_free(&s->programs[i]->metadata);\n av_freep(&s->programs[i]->stream_index);\n av_freep(&s->programs[i]);\n }\n av_freep(&s->programs);\n av_freep(&s->priv_data);\n while(s->nb_chapters--) {\n av_dict_free(&s->chapters[s->nb_chapters]->metadata);\n av_free(s->chapters[s->nb_chapters]);\n }\n av_freep(&s->chapters);\n av_dict_free(&s->metadata);\n av_freep(&s->streams);\n av_free(s);\n}'] |
35,054 | 0 | https://github.com/openssl/openssl/blob/6b5d39e82d9919f204dae3acae3769e00df71b4d/crypto/bn/bn_ctx.c/#L149 | void BN_CTX_end(BN_CTX *ctx)
{
if (ctx == NULL) return;
assert(ctx->depth > 0);
if (ctx->depth == 0)
BN_CTX_start(ctx);
ctx->too_many = 0;
ctx->depth--;
if (ctx->depth < BN_CTX_NUM_POS)
ctx->tos = ctx->pos[ctx->depth];
} | ['int RSA_check_key(const RSA *key)\n\t{\n\tBIGNUM *i, *j, *k, *l, *m;\n\tBN_CTX *ctx;\n\tint r;\n\tint ret=1;\n\ti = BN_new();\n\tj = BN_new();\n\tk = BN_new();\n\tl = BN_new();\n\tm = BN_new();\n\tctx = BN_CTX_new();\n\tif (i == NULL || j == NULL || k == NULL || l == NULL ||\n\t\tm == NULL || ctx == NULL)\n\t\t{\n\t\tret = -1;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tr = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL);\n\tif (r != 1)\n\t\t{\n\t\tret = r;\n\t\tif (r != 0)\n\t\t\tgoto err;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_P_NOT_PRIME);\n\t\t}\n\tr = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL);\n\tif (r != 1)\n\t\t{\n\t\tret = r;\n\t\tif (r != 0)\n\t\t\tgoto err;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_Q_NOT_PRIME);\n\t\t}\n\tr = BN_mul(i, key->p, key->q, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tif (BN_cmp(i, key->n) != 0)\n\t\t{\n\t\tret = 0;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_N_DOES_NOT_EQUAL_P_Q);\n\t\t}\n\tr = BN_sub(i, key->p, BN_value_one());\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_sub(j, key->q, BN_value_one());\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_mul(l, i, j, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_gcd(m, i, j, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_div(k, NULL, l, m, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tr = BN_mod_mul(i, key->d, key->e, k, ctx);\n\tif (!r) { ret = -1; goto err; }\n\tif (!BN_is_one(i))\n\t\t{\n\t\tret = 0;\n\t\tRSAerr(RSA_F_RSA_CHECK_KEY, RSA_R_D_E_NOT_CONGRUENT_TO_1);\n\t\t}\n\tif (key->dmp1 != NULL && key->dmq1 != NULL && key->iqmp != NULL)\n\t\t{\n\t\tr = BN_sub(i, key->p, BN_value_one());\n\t\tif (!r) { ret = -1; goto err; }\n\t\tr = BN_mod(j, key->d, i, ctx);\n\t\tif (!r) { ret = -1; goto err; }\n\t\tif (BN_cmp(j, key->dmp1) != 0)\n\t\t\t{\n\t\t\tret = 0;\n\t\t\tRSAerr(RSA_F_RSA_CHECK_KEY,\n\t\t\t\tRSA_R_DMP1_NOT_CONGRUENT_TO_D);\n\t\t\t}\n\t\tr = BN_sub(i, key->q, BN_value_one());\n\t\tif (!r) { ret = -1; goto err; }\n\t\tr = BN_mod(j, key->d, i, ctx);\n\t\tif (!r) { ret = -1; goto err; }\n\t\tif (BN_cmp(j, key->dmq1) != 0)\n\t\t\t{\n\t\t\tret = 0;\n\t\t\tRSAerr(RSA_F_RSA_CHECK_KEY,\n\t\t\t\tRSA_R_DMQ1_NOT_CONGRUENT_TO_D);\n\t\t\t}\n\t\tif(!BN_mod_inverse(i, key->q, key->p, ctx))\n\t\t\t{\n\t\t\tret = -1;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (BN_cmp(i, key->iqmp) != 0)\n\t\t\t{\n\t\t\tret = 0;\n\t\t\tRSAerr(RSA_F_RSA_CHECK_KEY,\n\t\t\t\tRSA_R_IQMP_NOT_INVERSE_OF_Q);\n\t\t\t}\n\t\t}\n err:\n\tif (i != NULL) BN_free(i);\n\tif (j != NULL) BN_free(j);\n\tif (k != NULL) BN_free(k);\n\tif (l != NULL) BN_free(l);\n\tif (m != NULL) BN_free(m);\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\treturn (ret);\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 BN_CTX_init(BN_CTX *ctx)\n\t{\n\tint i;\n\tctx->tos = 0;\n\tctx->flags = 0;\n\tctx->depth = 0;\n\tctx->too_many = 0;\n\tfor (i = 0; i < BN_CTX_NUM; i++)\n\t\tBN_init(&(ctx->bn[i]));\n\t}', 'int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),\n\tBN_CTX *ctx_passed, void *cb_arg)\n\t{\n\treturn BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);\n\t}', 'int BN_is_prime_fasttest(const BIGNUM *a, int checks,\n\t\tvoid (*callback)(int,int,void *),\n\t\tBN_CTX *ctx_passed, void *cb_arg,\n\t\tint do_trial_division)\n\t{\n\tint i, j, ret = -1;\n\tint k;\n\tBN_CTX *ctx = NULL;\n\tBIGNUM *A1, *A1_odd, *check;\n\tBN_MONT_CTX *mont = NULL;\n\tconst BIGNUM *A = NULL;\n\tif (checks == BN_prime_checks)\n\t\tchecks = BN_prime_checks_for_size(BN_num_bits(a));\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (do_trial_division)\n\t\t{\n\t\tfor (i = 1; i < NUMPRIMES; i++)\n\t\t\tif (BN_mod_word(a, primes[i]) == 0)\n\t\t\t\treturn 0;\n\t\tif (callback != NULL) callback(1, -1, cb_arg);\n\t\t}\n\tif (ctx_passed != NULL)\n\t\tctx = ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL)\n\t\t\tgoto err;\n\tBN_CTX_start(ctx);\n\tif (a->neg)\n\t\t{\n\t\tBIGNUM *t;\n\t\tif ((t = BN_CTX_get(ctx)) == NULL) goto err;\n\t\tBN_copy(t, a);\n\t\tt->neg = 0;\n\t\tA = t;\n\t\t}\n\telse\n\t\tA = a;\n\tA1 = BN_CTX_get(ctx);\n\tA1_odd = BN_CTX_get(ctx);\n\tcheck = BN_CTX_get(ctx);\n\tif (check == NULL) goto err;\n\tif (!BN_copy(A1, A))\n\t\tgoto err;\n\tif (!BN_sub_word(A1, 1))\n\t\tgoto err;\n\tif (BN_is_zero(A1))\n\t\t{\n\t\tret = 0;\n\t\tgoto err;\n\t\t}\n\tk = 1;\n\twhile (!BN_is_bit_set(A1, k))\n\t\tk++;\n\tif (!BN_rshift(A1_odd, A1, k))\n\t\tgoto err;\n\tmont = BN_MONT_CTX_new();\n\tif (mont == NULL)\n\t\tgoto err;\n\tif (!BN_MONT_CTX_set(mont, A, ctx))\n\t\tgoto err;\n\tfor (i = 0; i < checks; i++)\n\t\t{\n\t\tif (!BN_pseudo_rand(check, BN_num_bits(A1), 0, 0))\n\t\t\tgoto err;\n\t\tif (BN_cmp(check, A1) >= 0)\n\t\t\tif (!BN_sub(check, check, A1))\n\t\t\t\tgoto err;\n\t\tif (!BN_add_word(check, 1))\n\t\t\tgoto err;\n\t\tj = witness(check, A, A1, A1_odd, k, ctx, mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,i,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tif (ctx_passed == NULL)\n\t\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (mont != NULL)\n\t\tBN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->pos[ctx->depth] = ctx->tos;\n\tctx->depth++;\n\t}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n\t{\n\tif (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)\n\t\t{\n\t\tif (!ctx->too_many)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\t\tctx->too_many = 1;\n\t\t\t}\n\t\treturn NULL;\n\t\t}\n\treturn (&(ctx->bn[ctx->tos++]));\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\tBN_sub_word(&Ri,1);\n\t\telse\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(mod);\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n\t\tBN_sub_word(&Ri,1);\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n\tconst BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;\n\tBIGNUM *ret=NULL;\n\tint sign;\n\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\twhile (!BN_is_zero(B))\n\t\t{\n\t\tBIGNUM *tmp;\n\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t{\n\t\t\tif (!BN_one(D)) goto err;\n\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t}\n\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t{\n\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\tif (BN_ucmp(A,T) < 0)\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\n\t\t\t\t{\n\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_set_word(D,2)) 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_set_word(D,3)) goto err;\n\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t}\n\t\ttmp=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (BN_is_one(D))\n\t\t\t{\n\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (BN_is_word(D,2))\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t}\n\t\t\telse if (D->top == 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t}\n\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t}\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 (BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tif (ctx == NULL) return;\n\tassert(ctx->depth > 0);\n\tif (ctx->depth == 0)\n\t\tBN_CTX_start(ctx);\n\tctx->too_many = 0;\n\tctx->depth--;\n\tif (ctx->depth < BN_CTX_NUM_POS)\n\t\tctx->tos = ctx->pos[ctx->depth];\n\t}'] |
35,055 | 0 | https://github.com/openssl/openssl/blob/1fac96e4d6484a517f2ebe99b72016726391723c/crypto/bn/bn_lib.c/#L496 | BIGNUM *BN_dup(BIGNUM *a)
{
BIGNUM *r;
bn_check_top(a);
r=BN_new();
if (r == NULL) return(NULL);
return((BIGNUM *)BN_copy(r,a));
} | ['BIGNUM *BN_dup(BIGNUM *a)\n\t{\n\tBIGNUM *r;\n\tbn_check_top(a);\n\tr=BN_new();\n\tif (r == NULL) return(NULL);\n\treturn((BIGNUM *)BN_copy(r,a));\n\t}', 'BIGNUM *BN_new(void)\n\t{\n\tBIGNUM *ret;\n\tif ((ret=(BIGNUM *)Malloc(sizeof(BIGNUM))) == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->flags=BN_FLG_MALLOCED;\n\tret->top=0;\n\tret->neg=0;\n\tret->max=0;\n\tret->d=NULL;\n\treturn(ret);\n\t}'] |
35,056 | 0 | https://github.com/openssl/openssl/blob/028bac0670c167f154438742eb4d0fbed73df209/crypto/x509/x509_lu.c/#L320 | int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
X509_OBJECT *ret)
{
X509_STORE *ctx=vs->ctx;
X509_LOOKUP *lu;
X509_OBJECT stmp,*tmp;
int i,j;
CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);
tmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name);
CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
if (tmp == NULL || type == X509_LU_CRL)
{
for (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)
{
lu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);
j=X509_LOOKUP_by_subject(lu,type,name,&stmp);
if (j < 0)
{
vs->current_method=j;
return j;
}
else if (j)
{
tmp= &stmp;
break;
}
}
vs->current_method=0;
if (tmp == NULL)
return 0;
}
ret->type=tmp->type;
ret->data.ptr=tmp->data.ptr;
X509_OBJECT_up_ref_count(ret);
return 1;
} | ['int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,\n\t X509_OBJECT *ret)\n\t{\n\tX509_STORE *ctx=vs->ctx;\n\tX509_LOOKUP *lu;\n\tX509_OBJECT stmp,*tmp;\n\tint i,j;\n\tCRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n\ttmp=X509_OBJECT_retrieve_by_subject(ctx->objs,type,name);\n\tCRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\n\tif (tmp == NULL || type == X509_LU_CRL)\n\t\t{\n\t\tfor (i=vs->current_method; i<sk_X509_LOOKUP_num(ctx->get_cert_methods); i++)\n\t\t\t{\n\t\t\tlu=sk_X509_LOOKUP_value(ctx->get_cert_methods,i);\n\t\t\tj=X509_LOOKUP_by_subject(lu,type,name,&stmp);\n\t\t\tif (j < 0)\n\t\t\t\t{\n\t\t\t\tvs->current_method=j;\n\t\t\t\treturn j;\n\t\t\t\t}\n\t\t\telse if (j)\n\t\t\t\t{\n\t\t\t\ttmp= &stmp;\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tvs->current_method=0;\n\t\tif (tmp == NULL)\n\t\t\treturn 0;\n\t\t}\n\tret->type=tmp->type;\n\tret->data.ptr=tmp->data.ptr;\n\tX509_OBJECT_up_ref_count(ret);\n\treturn 1;\n\t}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tCRYPTO_THREADID id;\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tCRYPTO_THREADID_current(&id);\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_THREADID_hash(&id), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tif (dynlock_lock_callback != NULL)\n\t\t\t{\n\t\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t\t= CRYPTO_get_dynlock_value(type);\n\t\t\tOPENSSL_assert(pointer != NULL);\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\tCRYPTO_destroy_dynlockid(type);\n\t\t\t}\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}', 'X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, int type,\n\t X509_NAME *name)\n\t{\n\tint idx;\n\tidx = X509_OBJECT_idx_by_subject(h, type, name);\n\tif (idx==-1) return NULL;\n\treturn sk_X509_OBJECT_value(h, idx);\n\t}', 'int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,\n\t X509_NAME *name)\n\t{\n\treturn x509_object_idx_cnt(h, type, name, NULL);\n\t}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}', 'int sk_num(const _STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', 'int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, X509_NAME *name,\n\t X509_OBJECT *ret)\n\t{\n\tif ((ctx->method == NULL) || (ctx->method->get_by_subject == NULL))\n\t\treturn X509_LU_FAIL;\n\tif (ctx->skip) return 0;\n\treturn ctx->method->get_by_subject(ctx,type,name,ret);\n\t}'] |
35,057 | 0 | https://github.com/nginx/nginx/blob/e4ecddfdb0d2ffc872658e36028971ad9a873726/src/core/ngx_string.c/#L244 | u_char *
ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)
{
u_char *p, zero, *last;
int d;
float f, scale;
size_t len, slen;
int64_t i64;
uint64_t ui64;
ngx_msec_t ms;
ngx_uint_t width, sign, hex, max_width, frac_width, i;
ngx_str_t *v;
ngx_variable_value_t *vv;
if (max == 0) {
return buf;
}
last = buf + max;
while (*fmt && buf < last) {
if (*fmt == '%') {
i64 = 0;
ui64 = 0;
zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
width = 0;
sign = 1;
hex = 0;
max_width = 0;
frac_width = 0;
slen = (size_t) -1;
while (*fmt >= '0' && *fmt <= '9') {
width = width * 10 + *fmt++ - '0';
}
for ( ;; ) {
switch (*fmt) {
case 'u':
sign = 0;
fmt++;
continue;
case 'm':
max_width = 1;
fmt++;
continue;
case 'X':
hex = 2;
sign = 0;
fmt++;
continue;
case 'x':
hex = 1;
sign = 0;
fmt++;
continue;
case '.':
fmt++;
while (*fmt >= '0' && *fmt <= '9') {
frac_width = frac_width * 10 + *fmt++ - '0';
}
break;
case '*':
slen = va_arg(args, size_t);
fmt++;
continue;
default:
break;
}
break;
}
switch (*fmt) {
case 'V':
v = va_arg(args, ngx_str_t *);
len = v->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, v->data, len);
fmt++;
continue;
case 'v':
vv = va_arg(args, ngx_variable_value_t *);
len = vv->len;
len = (buf + len < last) ? len : (size_t) (last - buf);
buf = ngx_cpymem(buf, vv->data, len);
fmt++;
continue;
case 's':
p = va_arg(args, u_char *);
if (slen == (size_t) -1) {
while (*p && buf < last) {
*buf++ = *p++;
}
} else {
len = (buf + slen < last) ? slen : (size_t) (last - buf);
buf = ngx_cpymem(buf, p, len);
}
fmt++;
continue;
case 'O':
i64 = (int64_t) va_arg(args, off_t);
sign = 1;
break;
case 'P':
i64 = (int64_t) va_arg(args, ngx_pid_t);
sign = 1;
break;
case 'T':
i64 = (int64_t) va_arg(args, time_t);
sign = 1;
break;
case 'M':
ms = (ngx_msec_t) va_arg(args, ngx_msec_t);
if ((ngx_msec_int_t) ms == -1) {
sign = 1;
i64 = -1;
} else {
sign = 0;
ui64 = (uint64_t) ms;
}
break;
case 'z':
if (sign) {
i64 = (int64_t) va_arg(args, ssize_t);
} else {
ui64 = (uint64_t) va_arg(args, size_t);
}
break;
case 'i':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_uint_t);
}
if (max_width) {
width = NGX_INT_T_LEN;
}
break;
case 'd':
if (sign) {
i64 = (int64_t) va_arg(args, int);
} else {
ui64 = (uint64_t) va_arg(args, u_int);
}
break;
case 'l':
if (sign) {
i64 = (int64_t) va_arg(args, long);
} else {
ui64 = (uint64_t) va_arg(args, u_long);
}
break;
case 'D':
if (sign) {
i64 = (int64_t) va_arg(args, int32_t);
} else {
ui64 = (uint64_t) va_arg(args, uint32_t);
}
break;
case 'L':
if (sign) {
i64 = va_arg(args, int64_t);
} else {
ui64 = va_arg(args, uint64_t);
}
break;
case 'A':
if (sign) {
i64 = (int64_t) va_arg(args, ngx_atomic_int_t);
} else {
ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);
}
if (max_width) {
width = NGX_ATOMIC_T_LEN;
}
break;
case 'f':
f = (float) va_arg(args, double);
if (f < 0) {
*buf++ = '-';
f = -f;
}
ui64 = (int64_t) f;
buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
if (frac_width) {
if (buf < last) {
*buf++ = '.';
}
scale = 1.0;
for (i = 0; i < frac_width; i++) {
scale *= 10.0;
}
ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);
buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);
}
fmt++;
continue;
#if !(NGX_WIN32)
case 'r':
i64 = (int64_t) va_arg(args, rlim_t);
sign = 1;
break;
#endif
case 'p':
ui64 = (uintptr_t) va_arg(args, void *);
hex = 2;
sign = 0;
zero = '0';
width = NGX_PTR_SIZE * 2;
break;
case 'c':
d = va_arg(args, int);
*buf++ = (u_char) (d & 0xff);
fmt++;
continue;
case 'Z':
*buf++ = '\0';
fmt++;
continue;
case 'N':
#if (NGX_WIN32)
*buf++ = CR;
#endif
*buf++ = LF;
fmt++;
continue;
case '%':
*buf++ = '%';
fmt++;
continue;
default:
*buf++ = *fmt++;
continue;
}
if (sign) {
if (i64 < 0) {
*buf++ = '-';
ui64 = (uint64_t) -i64;
} else {
ui64 = (uint64_t) i64;
}
}
buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);
fmt++;
} else {
*buf++ = *fmt++;
}
}
return buf;
} | ['static ngx_int_t\nngx_add_inherited_sockets(ngx_cycle_t *cycle)\n{\n u_char *p, *v, *inherited;\n ngx_int_t s;\n ngx_listening_t *ls;\n inherited = (u_char *) getenv(NGINX_VAR);\n if (inherited == NULL) {\n return NGX_OK;\n }\n ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0,\n "using inherited sockets from \\"%s\\"", inherited);\n if (ngx_array_init(&cycle->listening, cycle->pool, 10,\n sizeof(ngx_listening_t))\n != NGX_OK)\n {\n return NGX_ERROR;\n }\n for (p = inherited, v = p; *p; p++) {\n if (*p == \':\' || *p == \';\') {\n s = ngx_atoi(v, p - v);\n if (s == NGX_ERROR) {\n ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,\n "invalid socket number \\"%s\\" in " NGINX_VAR\n " environment variable, ignoring the rest"\n " of the variable", v);\n break;\n }\n v = p + 1;\n ls = ngx_array_push(&cycle->listening);\n if (ls == NULL) {\n return NGX_ERROR;\n }\n ngx_memzero(ls, sizeof(ngx_listening_t));\n ls->fd = (ngx_socket_t) s;\n }\n }\n ngx_inherited = 1;\n return ngx_set_inherited_sockets(cycle);\n}', "ngx_int_t\nngx_atoi(u_char *line, size_t n)\n{\n ngx_int_t value;\n if (n == 0) {\n return NGX_ERROR;\n }\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n if (value < 0) {\n return NGX_ERROR;\n } else {\n return value;\n }\n}", 'void\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, ...)\n#else\nvoid\nngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,\n const char *fmt, va_list args)\n#endif\n{\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_list args;\n#endif\n u_char errstr[NGX_MAX_ERROR_STR], *p, *last;\n if (log->file->fd == NGX_INVALID_FILE) {\n return;\n }\n last = errstr + NGX_MAX_ERROR_STR;\n ngx_memcpy(errstr, ngx_cached_err_log_time.data,\n ngx_cached_err_log_time.len);\n p = errstr + ngx_cached_err_log_time.len;\n p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);\n p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",\n ngx_log_pid, ngx_log_tid);\n if (log->connection) {\n p = ngx_snprintf(p, last - p, "*%uA ", log->connection);\n }\n#if (NGX_HAVE_VARIADIC_MACROS)\n va_start(args, fmt);\n p = ngx_vsnprintf(p, last - p, fmt, args);\n va_end(args);\n#else\n p = ngx_vsnprintf(p, last - p, fmt, args);\n#endif\n if (err) {\n if (p > last - 50) {\n p = last - 50;\n *p++ = \'.\';\n *p++ = \'.\';\n *p++ = \'.\';\n }\n#if (NGX_WIN32)\n p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000)\n ? " (%d: " : " (%Xd: ", err);\n#else\n p = ngx_snprintf(p, last - p, " (%d: ", err);\n#endif\n p = ngx_strerror_r(err, p, last - p);\n if (p < last) {\n *p++ = \')\';\n }\n }\n if (level != NGX_LOG_DEBUG && log->handler) {\n p = log->handler(log, p, last - p);\n }\n if (p > last - NGX_LINEFEED_SIZE) {\n p = last - NGX_LINEFEED_SIZE;\n }\n ngx_linefeed(p);\n (void) ngx_write_fd(log->file->fd, errstr, p - errstr);\n}', 'u_char * ngx_cdecl\nngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)\n{\n u_char *p;\n va_list args;\n va_start(args, fmt);\n p = ngx_vsnprintf(buf, max, fmt, args);\n va_end(args);\n return p;\n}', "u_char *\nngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args)\n{\n u_char *p, zero, *last;\n int d;\n float f, scale;\n size_t len, slen;\n int64_t i64;\n uint64_t ui64;\n ngx_msec_t ms;\n ngx_uint_t width, sign, hex, max_width, frac_width, i;\n ngx_str_t *v;\n ngx_variable_value_t *vv;\n if (max == 0) {\n return buf;\n }\n last = buf + max;\n while (*fmt && buf < last) {\n if (*fmt == '%') {\n i64 = 0;\n ui64 = 0;\n zero = (u_char) ((*++fmt == '0') ? '0' : ' ');\n width = 0;\n sign = 1;\n hex = 0;\n max_width = 0;\n frac_width = 0;\n slen = (size_t) -1;\n while (*fmt >= '0' && *fmt <= '9') {\n width = width * 10 + *fmt++ - '0';\n }\n for ( ;; ) {\n switch (*fmt) {\n case 'u':\n sign = 0;\n fmt++;\n continue;\n case 'm':\n max_width = 1;\n fmt++;\n continue;\n case 'X':\n hex = 2;\n sign = 0;\n fmt++;\n continue;\n case 'x':\n hex = 1;\n sign = 0;\n fmt++;\n continue;\n case '.':\n fmt++;\n while (*fmt >= '0' && *fmt <= '9') {\n frac_width = frac_width * 10 + *fmt++ - '0';\n }\n break;\n case '*':\n slen = va_arg(args, size_t);\n fmt++;\n continue;\n default:\n break;\n }\n break;\n }\n switch (*fmt) {\n case 'V':\n v = va_arg(args, ngx_str_t *);\n len = v->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, v->data, len);\n fmt++;\n continue;\n case 'v':\n vv = va_arg(args, ngx_variable_value_t *);\n len = vv->len;\n len = (buf + len < last) ? len : (size_t) (last - buf);\n buf = ngx_cpymem(buf, vv->data, len);\n fmt++;\n continue;\n case 's':\n p = va_arg(args, u_char *);\n if (slen == (size_t) -1) {\n while (*p && buf < last) {\n *buf++ = *p++;\n }\n } else {\n len = (buf + slen < last) ? slen : (size_t) (last - buf);\n buf = ngx_cpymem(buf, p, len);\n }\n fmt++;\n continue;\n case 'O':\n i64 = (int64_t) va_arg(args, off_t);\n sign = 1;\n break;\n case 'P':\n i64 = (int64_t) va_arg(args, ngx_pid_t);\n sign = 1;\n break;\n case 'T':\n i64 = (int64_t) va_arg(args, time_t);\n sign = 1;\n break;\n case 'M':\n ms = (ngx_msec_t) va_arg(args, ngx_msec_t);\n if ((ngx_msec_int_t) ms == -1) {\n sign = 1;\n i64 = -1;\n } else {\n sign = 0;\n ui64 = (uint64_t) ms;\n }\n break;\n case 'z':\n if (sign) {\n i64 = (int64_t) va_arg(args, ssize_t);\n } else {\n ui64 = (uint64_t) va_arg(args, size_t);\n }\n break;\n case 'i':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_uint_t);\n }\n if (max_width) {\n width = NGX_INT_T_LEN;\n }\n break;\n case 'd':\n if (sign) {\n i64 = (int64_t) va_arg(args, int);\n } else {\n ui64 = (uint64_t) va_arg(args, u_int);\n }\n break;\n case 'l':\n if (sign) {\n i64 = (int64_t) va_arg(args, long);\n } else {\n ui64 = (uint64_t) va_arg(args, u_long);\n }\n break;\n case 'D':\n if (sign) {\n i64 = (int64_t) va_arg(args, int32_t);\n } else {\n ui64 = (uint64_t) va_arg(args, uint32_t);\n }\n break;\n case 'L':\n if (sign) {\n i64 = va_arg(args, int64_t);\n } else {\n ui64 = va_arg(args, uint64_t);\n }\n break;\n case 'A':\n if (sign) {\n i64 = (int64_t) va_arg(args, ngx_atomic_int_t);\n } else {\n ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);\n }\n if (max_width) {\n width = NGX_ATOMIC_T_LEN;\n }\n break;\n case 'f':\n f = (float) va_arg(args, double);\n if (f < 0) {\n *buf++ = '-';\n f = -f;\n }\n ui64 = (int64_t) f;\n buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);\n if (frac_width) {\n if (buf < last) {\n *buf++ = '.';\n }\n scale = 1.0;\n for (i = 0; i < frac_width; i++) {\n scale *= 10.0;\n }\n ui64 = (uint64_t) ((f - (int64_t) ui64) * scale);\n buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);\n }\n fmt++;\n continue;\n#if !(NGX_WIN32)\n case 'r':\n i64 = (int64_t) va_arg(args, rlim_t);\n sign = 1;\n break;\n#endif\n case 'p':\n ui64 = (uintptr_t) va_arg(args, void *);\n hex = 2;\n sign = 0;\n zero = '0';\n width = NGX_PTR_SIZE * 2;\n break;\n case 'c':\n d = va_arg(args, int);\n *buf++ = (u_char) (d & 0xff);\n fmt++;\n continue;\n case 'Z':\n *buf++ = '\\0';\n fmt++;\n continue;\n case 'N':\n#if (NGX_WIN32)\n *buf++ = CR;\n#endif\n *buf++ = LF;\n fmt++;\n continue;\n case '%':\n *buf++ = '%';\n fmt++;\n continue;\n default:\n *buf++ = *fmt++;\n continue;\n }\n if (sign) {\n if (i64 < 0) {\n *buf++ = '-';\n ui64 = (uint64_t) -i64;\n } else {\n ui64 = (uint64_t) i64;\n }\n }\n buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);\n fmt++;\n } else {\n *buf++ = *fmt++;\n }\n }\n return buf;\n}"] |
35,058 | 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_MONT_CTX_set(BN_MONT_CTX *mont, BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tBIGNUM Ri,*R;\n\tBN_init(&Ri);\n\tR= &(mont->RR);\n\tBN_copy(&(mont->N),mod);\n#ifdef BN_RECURSION_MONT\n\tif (mont->N.top < BN_MONT_CTX_SET_SIZE_WORD)\n#endif\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\tmont->use_word=1;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,BN_BITS2);\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.d=buf;\n\t\ttmod.top=1;\n\t\ttmod.max=mod->max;\n\t\ttmod.neg=mod->neg;\n\t\tif ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,BN_BITS2);\n\t\tif (!BN_is_zero(&Ri))\n\t\t\t{\n#if 1\n\t\t\tBN_sub_word(&Ri,1);\n#else\n\t\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBN_set_word(&Ri,BN_MASK2);\n\t\t\t}\n\t\tBN_div(&Ri,NULL,&Ri,&tmod,ctx);\n\t\tmont->n0=Ri.d[0];\n\t\tBN_free(&Ri);\n\t\t}\n#ifdef BN_RECURSION_MONT\n\telse\n\t\t{\n\t\tmont->use_word=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if 1\n\t\tBN_zero(R);\n\t\tBN_set_bit(R,mont->ri);\n#else\n\t\tBN_lshift(R,BN_value_one(),mont->ri);\n#endif\n\t\tif ((BN_mod_inverse(&Ri,R,mod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tBN_lshift(&Ri,&Ri,mont->ri);\n#if 1\n\t\tBN_sub_word(&Ri,1);\n#else\n\t\tBN_usub(&Ri,&Ri,BN_value_one());\n#endif\n\t\tBN_div(&(mont->Ni),NULL,&Ri,mod,ctx);\n\t\tBN_free(&Ri);\n\t\t}\n#endif\n#if 1\n\tBN_zero(&(mont->RR));\n\tBN_set_bit(&(mont->RR),mont->ri*2);\n#else\n\tBN_lshift(mont->RR,BN_value_one(),mont->ri*2);\n#endif\n\tBN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx);\n\treturn(1);\nerr:\n\treturn(0);\n\t}', 'BIGNUM *BN_mod_inverse(BIGNUM *in, BIGNUM *a, BIGNUM *n, BN_CTX *ctx)\n\t{\n\tBIGNUM *A,*B,*X,*Y,*M,*D,*R;\n\tBIGNUM *T,*ret=NULL;\n\tint sign;\n\tbn_check_top(a);\n\tbn_check_top(n);\n\tA= &(ctx->bn[ctx->tos]);\n\tB= &(ctx->bn[ctx->tos+1]);\n\tX= &(ctx->bn[ctx->tos+2]);\n\tD= &(ctx->bn[ctx->tos+3]);\n\tM= &(ctx->bn[ctx->tos+4]);\n\tY= &(ctx->bn[ctx->tos+5]);\n\tctx->tos+=6;\n\tif (in == NULL)\n\t\tR=BN_new();\n\telse\n\t\tR=in;\n\tif (R == NULL) goto err;\n\tBN_zero(X);\n\tBN_one(Y);\n\tif (BN_copy(A,a) == NULL) goto err;\n\tif (BN_copy(B,n) == NULL) goto err;\n\tsign=1;\n\twhile (!BN_is_zero(B))\n\t\t{\n\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\tT=A;\n\t\tA=B;\n\t\tB=M;\n\t\tif (!BN_mul(T,D,X,ctx)) goto err;\n\t\tif (!BN_add(T,T,Y)) goto err;\n\t\tM=Y;\n\t\tY=X;\n\t\tX=T;\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{ if (!BN_mod(R,Y,n,ctx)) goto err; }\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tctx->tos-=6;\n\treturn(ret);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A,*B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t{\n\t\tA[0]=B[0];\n\t\tA[1]=B[1];\n\t\tA[2]=B[2];\n\t\tA[3]=B[3];\n\t\tA[4]=B[4];\n\t\tA[5]=B[5];\n\t\tA[6]=B[6];\n\t\tA[7]=B[7];\n\t\tA+=8;\n\t\tB+=8;\n\t\t}\n\tswitch (b->top&7)\n\t\t{\n\tcase 7:\n\t\tA[6]=B[6];\n\tcase 6:\n\t\tA[5]=B[5];\n\tcase 5:\n\t\tA[4]=B[4];\n\tcase 4:\n\t\tA[3]=B[3];\n\tcase 3:\n\t\tA[2]=B[2];\n\tcase 2:\n\t\tA[1]=B[1];\n\tcase 1:\n\t\tA[0]=B[0];\n case 0:\n\t\t;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*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}'] |
35,059 | 0 | https://github.com/openssl/openssl/blob/e51329d3815df95bf0ff66925c3961794f4c66d1/crypto/lhash/lhash.c/#L123 | void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
unsigned long hash;
OPENSSL_LH_NODE *nn, **rn;
void *ret;
lh->error = 0;
rn = getrn(lh, data, &hash);
if (*rn == NULL) {
lh->num_no_delete++;
return (NULL);
} else {
nn = *rn;
*rn = nn->next;
ret = nn->data;
OPENSSL_free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
contract(lh);
return (ret);
} | ['static SSL *doConnection(SSL *scon, const char *host, SSL_CTX *ctx)\n{\n BIO *conn;\n SSL *serverCon;\n int width, i;\n fd_set readfds;\n if ((conn = BIO_new(BIO_s_connect())) == NULL)\n return (NULL);\n BIO_set_conn_hostname(conn, host);\n if (scon == NULL)\n serverCon = SSL_new(ctx);\n else {\n serverCon = scon;\n SSL_set_connect_state(serverCon);\n }\n SSL_set_bio(serverCon, conn, conn);\n for (;;) {\n i = SSL_connect(serverCon);\n if (BIO_sock_should_retry(i)) {\n BIO_printf(bio_err, "DELAY\\n");\n i = SSL_get_fd(serverCon);\n width = i + 1;\n FD_ZERO(&readfds);\n openssl_fdset(i, &readfds);\n select(width, (void *)&readfds, NULL, NULL, NULL);\n continue;\n }\n break;\n }\n if (i <= 0) {\n BIO_printf(bio_err, "ERROR\\n");\n if (verify_error != X509_V_OK)\n BIO_printf(bio_err, "verify error:%s\\n",\n X509_verify_cert_error_string(verify_error));\n else\n ERR_print_errors(bio_err);\n if (scon == NULL)\n SSL_free(serverCon);\n return NULL;\n }\n return serverCon;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n SSL *s;\n if (ctx == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n return (NULL);\n }\n if (ctx->method == NULL) {\n SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n return (NULL);\n }\n s = OPENSSL_zalloc(sizeof(*s));\n if (s == NULL)\n goto err;\n s->lock = CRYPTO_THREAD_lock_new();\n if (s->lock == NULL) {\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(s);\n return NULL;\n }\n RECORD_LAYER_init(&s->rlayer, s);\n s->options = ctx->options;\n s->min_proto_version = ctx->min_proto_version;\n s->max_proto_version = ctx->max_proto_version;\n s->mode = ctx->mode;\n s->max_cert_list = ctx->max_cert_list;\n s->references = 1;\n s->cert = ssl_cert_dup(ctx->cert);\n if (s->cert == NULL)\n goto err;\n RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n s->msg_callback = ctx->msg_callback;\n s->msg_callback_arg = ctx->msg_callback_arg;\n s->verify_mode = ctx->verify_mode;\n s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n s->sid_ctx_length = ctx->sid_ctx_length;\n OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n s->verify_callback = ctx->default_verify_callback;\n s->generate_session_id = ctx->generate_session_id;\n s->param = X509_VERIFY_PARAM_new();\n if (s->param == NULL)\n goto err;\n X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n s->quiet_shutdown = ctx->quiet_shutdown;\n s->max_send_fragment = ctx->max_send_fragment;\n s->split_send_fragment = ctx->split_send_fragment;\n s->max_pipelines = ctx->max_pipelines;\n if (s->max_pipelines > 1)\n RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n if (ctx->default_read_buf_len > 0)\n SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n SSL_CTX_up_ref(ctx);\n s->ctx = ctx;\n s->tlsext_debug_cb = 0;\n s->tlsext_debug_arg = NULL;\n s->tlsext_ticket_expected = 0;\n s->tlsext_status_type = ctx->tlsext_status_type;\n s->tlsext_status_expected = 0;\n s->tlsext_ocsp_ids = NULL;\n s->tlsext_ocsp_exts = NULL;\n s->tlsext_ocsp_resp = NULL;\n s->tlsext_ocsp_resplen = -1;\n SSL_CTX_up_ref(ctx);\n s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n if (ctx->tlsext_ecpointformatlist) {\n s->tlsext_ecpointformatlist =\n OPENSSL_memdup(ctx->tlsext_ecpointformatlist,\n ctx->tlsext_ecpointformatlist_length);\n if (!s->tlsext_ecpointformatlist)\n goto err;\n s->tlsext_ecpointformatlist_length =\n ctx->tlsext_ecpointformatlist_length;\n }\n if (ctx->tlsext_ellipticcurvelist) {\n s->tlsext_ellipticcurvelist =\n OPENSSL_memdup(ctx->tlsext_ellipticcurvelist,\n ctx->tlsext_ellipticcurvelist_length);\n if (!s->tlsext_ellipticcurvelist)\n goto err;\n s->tlsext_ellipticcurvelist_length =\n ctx->tlsext_ellipticcurvelist_length;\n }\n# endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n s->next_proto_negotiated = NULL;\n# endif\n if (s->ctx->alpn_client_proto_list) {\n s->alpn_client_proto_list =\n OPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n if (s->alpn_client_proto_list == NULL)\n goto err;\n memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n s->ctx->alpn_client_proto_list_len);\n s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n }\n s->verified_chain = NULL;\n s->verify_result = X509_V_OK;\n s->default_passwd_callback = ctx->default_passwd_callback;\n s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n s->method = ctx->method;\n if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'void SSL_free(SSL *s)\n{\n int i;\n if (s == NULL)\n return;\n CRYPTO_atomic_add(&s->references, -1, &i, s->lock);\n REF_PRINT_COUNT("SSL", s);\n if (i > 0)\n return;\n REF_ASSERT_ISNT(i < 0);\n X509_VERIFY_PARAM_free(s->param);\n dane_final(&s->dane);\n CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n if (s->bbio != NULL) {\n if (s->bbio == s->wbio) {\n s->wbio = BIO_pop(s->wbio);\n }\n BIO_free(s->bbio);\n s->bbio = NULL;\n }\n BIO_free_all(s->rbio);\n if (s->wbio != s->rbio)\n BIO_free_all(s->wbio);\n BUF_MEM_free(s->init_buf);\n sk_SSL_CIPHER_free(s->cipher_list);\n sk_SSL_CIPHER_free(s->cipher_list_by_id);\n if (s->session != NULL) {\n ssl_clear_bad_session(s);\n SSL_SESSION_free(s->session);\n }\n clear_ciphers(s);\n ssl_cert_free(s->cert);\n OPENSSL_free(s->tlsext_hostname);\n SSL_CTX_free(s->initial_ctx);\n#ifndef OPENSSL_NO_EC\n OPENSSL_free(s->tlsext_ecpointformatlist);\n OPENSSL_free(s->tlsext_ellipticcurvelist);\n#endif\n sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n SCT_LIST_free(s->scts);\n OPENSSL_free(s->tlsext_scts);\n#endif\n OPENSSL_free(s->tlsext_ocsp_resp);\n OPENSSL_free(s->alpn_client_proto_list);\n sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);\n sk_X509_pop_free(s->verified_chain, X509_free);\n if (s->method != NULL)\n s->method->ssl_free(s);\n RECORD_LAYER_release(&s->rlayer);\n SSL_CTX_free(s->ctx);\n ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n OPENSSL_free(s->next_proto_negotiated);\n#endif\n#ifndef OPENSSL_NO_SRTP\n sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n CRYPTO_THREAD_lock_free(s->lock);\n OPENSSL_free(s);\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->ctx, s->session);\n return (1);\n } else\n return (0);\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n ret = 1;\n r = lh_SSL_SESSION_delete(ctx->sessions, c);\n SSL_SESSION_list_remove(ctx, c);\n }\n if (lck)\n CRYPTO_THREAD_unlock(ctx->lock);\n if (ret) {\n r->not_resumable = 1;\n if (ctx->remove_session_cb != NULL)\n ctx->remove_session_cb(ctx, r);\n SSL_SESSION_free(r);\n }\n } else\n ret = 0;\n return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n unsigned long hash;\n OPENSSL_LH_NODE *nn, **rn;\n void *ret;\n lh->error = 0;\n rn = getrn(lh, data, &hash);\n if (*rn == NULL) {\n lh->num_no_delete++;\n return (NULL);\n } else {\n nn = *rn;\n *rn = nn->next;\n ret = nn->data;\n OPENSSL_free(nn);\n lh->num_delete++;\n }\n lh->num_items--;\n if ((lh->num_nodes > MIN_NODES) &&\n (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n contract(lh);\n return (ret);\n}'] |
35,060 | 1 | https://github.com/libav/libav/blob/63e8d9760f23a4edf81e9ae58c4f6d3baa6ff4dd/libavcodec/dct32.c/#L233 | 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 int j;\n#endif\n offset = *synth_buf_offset;\n synth_buf = synth_buf_ptr + offset;\n#if FRAC_BITS <= 15\n dct32(tmp, sb_samples);\n for(j=0;j<32;j++) {\n synth_buf[j] = av_clip_int16(tmp[j]);\n }\n#else\n dct32(synth_buf, sb_samples);\n#endif\n apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);\n offset = (offset - 32) & 511;\n *synth_buf_offset = offset;\n}', 'static void 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}'] |
35,061 | 0 | https://github.com/apache/httpd/blob/97706643cdb638339e23c653aad8c2e8e7c2830e/server/util.c/#L796 | AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line)
{
const char *str = *line, *strend;
char *res;
char quote;
while (apr_isspace(*str))
++str;
if (!*str) {
*line = str;
return "";
}
if ((quote = *str) == '"' || quote == '\'') {
strend = str + 1;
while (*strend && *strend != quote) {
if (*strend == '\\' && strend[1] &&
(strend[1] == quote || strend[1] == '\\')) {
strend += 2;
}
else {
++strend;
}
}
res = substring_conf(p, str + 1, strend - str - 1, quote);
if (*strend == quote)
++strend;
}
else {
strend = str;
while (*strend && !apr_isspace(*strend))
++strend;
res = substring_conf(p, str, strend - str, 0);
}
while (apr_isspace(*strend))
++strend;
*line = strend;
return res;
} | ['static authz_status\nforward_dns_check_authorization(request_rec *r,\n const char *require_line,\n const void *parsed_require_line)\n{\n const char *err = NULL;\n const ap_expr_info_t *expr = parsed_require_line;\n const char *require, *t;\n char *w;\n require = ap_expr_str_exec(r, expr, &err);\n if (err) {\n ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(03354)\n "Can\'t evaluate require expression: %s", err);\n return AUTHZ_DENIED;\n }\n t = require;\n while ((w = ap_getword_conf(r->pool, &t)) && w[0]) {\n apr_sockaddr_t *sa;\n apr_status_t rv;\n char *hash_ptr;\n if ((hash_ptr = ap_strchr(w, \'#\'))) {\n if (hash_ptr == w) {\n break;\n }\n *hash_ptr = \'\\0\';\n }\n rv = apr_sockaddr_info_get(&sa, w, APR_UNSPEC, 0, 0, r->pool);\n if (rv == APR_SUCCESS) {\n while (sa) {\n int match = apr_sockaddr_equal(sa, r->useragent_addr);\n ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03355)\n "access check for %s as \'%s\': %s",\n r->useragent_ip, w, match? "yes": "no");\n if (match) {\n return AUTHZ_GRANTED;\n }\n sa = sa->next;\n }\n }\n else {\n ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(03356)\n "No sockaddr info for \\"%s\\"", w);\n }\n if (hash_ptr) {\n break;\n }\n }\n return AUTHZ_DENIED;\n}', 'AP_DECLARE(const char *) ap_expr_str_exec(request_rec *r,\n const ap_expr_info_t *info,\n const char **err)\n{\n return ap_expr_str_exec_re(r, info, 0, NULL, NULL, err);\n}', 'AP_DECLARE(const char *) ap_expr_str_exec_re(request_rec *r,\n const ap_expr_info_t *info,\n apr_size_t nmatch,\n ap_regmatch_t *pmatch,\n const char **source,\n const char **err)\n{\n ap_expr_eval_ctx_t ctx;\n int dont_vary, rc;\n const char *tmp_source, *vary_this;\n ap_regmatch_t tmp_pmatch[AP_MAX_REG_MATCH];\n const char *result;\n AP_DEBUG_ASSERT(info->flags & AP_EXPR_FLAG_STRING_RESULT);\n if (info->root_node->node_op == op_String) {\n *err = NULL;\n return (const char *)info->root_node->node_arg1;\n }\n tmp_source = NULL;\n vary_this = NULL;\n dont_vary = (info->flags & AP_EXPR_FLAG_DONT_VARY);\n ctx.r = r;\n ctx.c = r->connection;\n ctx.s = r->server;\n ctx.p = r->pool;\n ctx.err = err;\n ctx.info = info;\n ctx.re_nmatch = nmatch;\n ctx.re_pmatch = pmatch;\n ctx.re_source = source;\n ctx.vary_this = dont_vary ? NULL : &vary_this;\n ctx.data = NULL;\n ctx.result_string = &result;\n if (!pmatch) {\n ctx.re_nmatch = AP_MAX_REG_MATCH;\n ctx.re_pmatch = tmp_pmatch;\n ctx.re_source = &tmp_source;\n }\n rc = ap_expr_exec_ctx(&ctx);\n if (rc > 0)\n return result;\n else if (rc < 0)\n return NULL;\n else\n ap_assert(0);\n return NULL;\n}', 'AP_DECLARE(char *) ap_getword_conf(apr_pool_t *p, const char **line)\n{\n const char *str = *line, *strend;\n char *res;\n char quote;\n while (apr_isspace(*str))\n ++str;\n if (!*str) {\n *line = str;\n return "";\n }\n if ((quote = *str) == \'"\' || quote == \'\\\'\') {\n strend = str + 1;\n while (*strend && *strend != quote) {\n if (*strend == \'\\\\\' && strend[1] &&\n (strend[1] == quote || strend[1] == \'\\\\\')) {\n strend += 2;\n }\n else {\n ++strend;\n }\n }\n res = substring_conf(p, str + 1, strend - str - 1, quote);\n if (*strend == quote)\n ++strend;\n }\n else {\n strend = str;\n while (*strend && !apr_isspace(*strend))\n ++strend;\n res = substring_conf(p, str, strend - str, 0);\n }\n while (apr_isspace(*strend))\n ++strend;\n *line = strend;\n return res;\n}'] |
35,062 | 0 | https://github.com/libav/libav/blob/f8f7ad758d0e1f36915467567f4d75541d98c12f/libavcodec/vp3.c/#L1995 | static int vp3_decode_frame(AVCodecContext *avctx,
void *data, int *got_frame,
AVPacket *avpkt)
{
AVFrame *frame = data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
Vp3DecodeContext *s = avctx->priv_data;
GetBitContext gb;
int i, ret;
init_get_bits(&gb, buf, buf_size * 8);
if (s->theora && get_bits1(&gb)) {
av_log(avctx, AV_LOG_ERROR,
"Header packet passed to frame decoder, skipping\n");
return -1;
}
s->keyframe = !get_bits1(&gb);
if (!s->theora)
skip_bits(&gb, 1);
for (i = 0; i < 3; i++)
s->last_qps[i] = s->qps[i];
s->nqps = 0;
do {
s->qps[s->nqps++] = get_bits(&gb, 6);
} while (s->theora >= 0x030200 && s->nqps < 3 && get_bits1(&gb));
for (i = s->nqps; i < 3; i++)
s->qps[i] = -1;
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\n",
s->keyframe ? "key" : "", avctx->frame_number + 1, s->qps[0]);
s->skip_loop_filter = !s->filter_limit_values[s->qps[0]] ||
avctx->skip_loop_filter >= (s->keyframe ? AVDISCARD_ALL
: AVDISCARD_NONKEY);
if (s->qps[0] != s->last_qps[0])
init_loop_filter(s);
for (i = 0; i < s->nqps; i++)
if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])
init_dequantizer(s, i);
if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)
return buf_size;
s->current_frame.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I
: AV_PICTURE_TYPE_P;
if (ff_thread_get_buffer(avctx, &s->current_frame, AV_GET_BUFFER_FLAG_REF) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
goto error;
}
if (!s->edge_emu_buffer)
s->edge_emu_buffer = av_malloc(9 * FFABS(s->current_frame.f->linesize[0]));
if (s->keyframe) {
if (!s->theora) {
skip_bits(&gb, 4);
skip_bits(&gb, 4);
if (s->version) {
s->version = get_bits(&gb, 5);
if (avctx->frame_number == 0)
av_log(s->avctx, AV_LOG_DEBUG,
"VP version: %d\n", s->version);
}
}
if (s->version || s->theora) {
if (get_bits1(&gb))
av_log(s->avctx, AV_LOG_ERROR,
"Warning, unsupported keyframe coding type?!\n");
skip_bits(&gb, 2);
}
} else {
if (!s->golden_frame.f->data[0]) {
av_log(s->avctx, AV_LOG_WARNING,
"vp3: first frame not a keyframe\n");
s->golden_frame.f->pict_type = AV_PICTURE_TYPE_I;
if (ff_thread_get_buffer(avctx, &s->golden_frame,
AV_GET_BUFFER_FLAG_REF) < 0) {
av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
goto error;
}
ff_thread_release_buffer(avctx, &s->last_frame);
if ((ret = ff_thread_ref_frame(&s->last_frame,
&s->golden_frame)) < 0)
goto error;
ff_thread_report_progress(&s->last_frame, INT_MAX, 0);
}
}
memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment));
ff_thread_finish_setup(avctx);
if (unpack_superblocks(s, &gb)) {
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n");
goto error;
}
if (unpack_modes(s, &gb)) {
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\n");
goto error;
}
if (unpack_vectors(s, &gb)) {
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\n");
goto error;
}
if (unpack_block_qpis(s, &gb)) {
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\n");
goto error;
}
if (unpack_dct_coeffs(s, &gb)) {
av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\n");
goto error;
}
for (i = 0; i < 3; i++) {
int height = s->height >> (i && s->chroma_y_shift);
if (s->flipped_image)
s->data_offset[i] = 0;
else
s->data_offset[i] = (height - 1) * s->current_frame.f->linesize[i];
}
s->last_slice_end = 0;
for (i = 0; i < s->c_superblock_height; i++)
render_slice(s, i);
for (i = 0; i < 3; i++) {
int row = (s->height >> (3 + (i && s->chroma_y_shift))) - 1;
apply_loop_filter(s, i, row, row + 1);
}
vp3_draw_horiz_band(s, s->height);
if ((ret = av_frame_ref(data, s->current_frame.f)) < 0)
return ret;
frame->crop_left = s->offset_x;
frame->crop_right = avctx->coded_width - avctx->width - s->offset_x;
frame->crop_top = s->offset_y;
frame->crop_bottom = avctx->coded_height - avctx->height - s->offset_y;
*got_frame = 1;
if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) {
ret = update_frames(avctx);
if (ret < 0)
return ret;
}
return buf_size;
error:
ff_thread_report_progress(&s->current_frame, INT_MAX, 0);
if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME))
av_frame_unref(s->current_frame.f);
return -1;
} | ['static int vp3_decode_frame(AVCodecContext *avctx,\n void *data, int *got_frame,\n AVPacket *avpkt)\n{\n AVFrame *frame = data;\n const uint8_t *buf = avpkt->data;\n int buf_size = avpkt->size;\n Vp3DecodeContext *s = avctx->priv_data;\n GetBitContext gb;\n int i, ret;\n init_get_bits(&gb, buf, buf_size * 8);\n if (s->theora && get_bits1(&gb)) {\n av_log(avctx, AV_LOG_ERROR,\n "Header packet passed to frame decoder, skipping\\n");\n return -1;\n }\n s->keyframe = !get_bits1(&gb);\n if (!s->theora)\n skip_bits(&gb, 1);\n for (i = 0; i < 3; i++)\n s->last_qps[i] = s->qps[i];\n s->nqps = 0;\n do {\n s->qps[s->nqps++] = get_bits(&gb, 6);\n } while (s->theora >= 0x030200 && s->nqps < 3 && get_bits1(&gb));\n for (i = s->nqps; i < 3; i++)\n s->qps[i] = -1;\n if (s->avctx->debug & FF_DEBUG_PICT_INFO)\n av_log(s->avctx, AV_LOG_INFO, " VP3 %sframe #%d: Q index = %d\\n",\n s->keyframe ? "key" : "", avctx->frame_number + 1, s->qps[0]);\n s->skip_loop_filter = !s->filter_limit_values[s->qps[0]] ||\n avctx->skip_loop_filter >= (s->keyframe ? AVDISCARD_ALL\n : AVDISCARD_NONKEY);\n if (s->qps[0] != s->last_qps[0])\n init_loop_filter(s);\n for (i = 0; i < s->nqps; i++)\n if (s->qps[i] != s->last_qps[i] || s->qps[0] != s->last_qps[0])\n init_dequantizer(s, i);\n if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe)\n return buf_size;\n s->current_frame.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I\n : AV_PICTURE_TYPE_P;\n if (ff_thread_get_buffer(avctx, &s->current_frame, AV_GET_BUFFER_FLAG_REF) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n goto error;\n }\n if (!s->edge_emu_buffer)\n s->edge_emu_buffer = av_malloc(9 * FFABS(s->current_frame.f->linesize[0]));\n if (s->keyframe) {\n if (!s->theora) {\n skip_bits(&gb, 4);\n skip_bits(&gb, 4);\n if (s->version) {\n s->version = get_bits(&gb, 5);\n if (avctx->frame_number == 0)\n av_log(s->avctx, AV_LOG_DEBUG,\n "VP version: %d\\n", s->version);\n }\n }\n if (s->version || s->theora) {\n if (get_bits1(&gb))\n av_log(s->avctx, AV_LOG_ERROR,\n "Warning, unsupported keyframe coding type?!\\n");\n skip_bits(&gb, 2);\n }\n } else {\n if (!s->golden_frame.f->data[0]) {\n av_log(s->avctx, AV_LOG_WARNING,\n "vp3: first frame not a keyframe\\n");\n s->golden_frame.f->pict_type = AV_PICTURE_TYPE_I;\n if (ff_thread_get_buffer(avctx, &s->golden_frame,\n AV_GET_BUFFER_FLAG_REF) < 0) {\n av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n goto error;\n }\n ff_thread_release_buffer(avctx, &s->last_frame);\n if ((ret = ff_thread_ref_frame(&s->last_frame,\n &s->golden_frame)) < 0)\n goto error;\n ff_thread_report_progress(&s->last_frame, INT_MAX, 0);\n }\n }\n memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment));\n ff_thread_finish_setup(avctx);\n if (unpack_superblocks(s, &gb)) {\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\\n");\n goto error;\n }\n if (unpack_modes(s, &gb)) {\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_modes\\n");\n goto error;\n }\n if (unpack_vectors(s, &gb)) {\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_vectors\\n");\n goto error;\n }\n if (unpack_block_qpis(s, &gb)) {\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_block_qpis\\n");\n goto error;\n }\n if (unpack_dct_coeffs(s, &gb)) {\n av_log(s->avctx, AV_LOG_ERROR, "error in unpack_dct_coeffs\\n");\n goto error;\n }\n for (i = 0; i < 3; i++) {\n int height = s->height >> (i && s->chroma_y_shift);\n if (s->flipped_image)\n s->data_offset[i] = 0;\n else\n s->data_offset[i] = (height - 1) * s->current_frame.f->linesize[i];\n }\n s->last_slice_end = 0;\n for (i = 0; i < s->c_superblock_height; i++)\n render_slice(s, i);\n for (i = 0; i < 3; i++) {\n int row = (s->height >> (3 + (i && s->chroma_y_shift))) - 1;\n apply_loop_filter(s, i, row, row + 1);\n }\n vp3_draw_horiz_band(s, s->height);\n if ((ret = av_frame_ref(data, s->current_frame.f)) < 0)\n return ret;\n frame->crop_left = s->offset_x;\n frame->crop_right = avctx->coded_width - avctx->width - s->offset_x;\n frame->crop_top = s->offset_y;\n frame->crop_bottom = avctx->coded_height - avctx->height - s->offset_y;\n *got_frame = 1;\n if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) {\n ret = update_frames(avctx);\n if (ret < 0)\n return ret;\n }\n return buf_size;\nerror:\n ff_thread_report_progress(&s->current_frame, INT_MAX, 0);\n if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME))\n av_frame_unref(s->current_frame.f);\n return -1;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}'] |
35,063 | 0 | https://github.com/libav/libav/blob/e3ec6fe7bb2a622a863e3912181717a659eb1bad/libavcodec/h264_loopfilter.c/#L160 | static av_always_inline void filter_mb_mbaff_edgev(const 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(const H264Context *h, H264SliceContext *sl,\n int mb_x, int mb_y,\n uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,\n unsigned int linesize, unsigned int uvlinesize)\n{\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 int chroma = !(CONFIG_GRAY && (h->flags&CODEC_FLAG_GRAY));\n int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8);\n int a = 52 + sl->slice_alpha_c0_offset - qp_bd_offset;\n int b = 52 + sl->slice_beta_offset - qp_bd_offset;\n if (FRAME_MBAFF(h)\n && IS_INTERLACED(mb_type ^ sl->left_type[LTOP])\n && sl->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(sl)][mb_y&1];\n for( i = 0; i < 8; i++ ) {\n int j= MB_FIELD(sl) ? i>>2 : i&1;\n int mbn_xy = sl->left_mb_xy[LEFT(j)];\n int mbn_type = sl->left_type[LEFT(j)];\n if( IS_INTRA( mbn_type ) )\n bS[i] = 4;\n else{\n bS[i] = 1 + !!(sl->non_zero_count_cache[12+8*(i>>1)] |\n ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ?\n (h->cbp_table[mbn_xy] & (((MB_FIELD(sl) ? (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[sl->left_mb_xy[0]];\n mbn1_qp = h->cur_pic.qscale_table[sl->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(sl)) {\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 {\n int dir;\n for (dir = 0; dir < 2; dir++)\n filter_mb_dir(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize,\n uvlinesize, mb_xy, mb_type, mvy_limit,\n dir ? 0 : first_vertical_edge_done, a, b,\n chroma, dir);\n }\n#else\n filter_mb_dir(h, sl, 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, sl, 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(const 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}'] |
35,064 | 0 | https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/bn/bn_ctx.c/#L437 | static void BN_POOL_release(BN_POOL *p, unsigned int num)
{
unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;
p->used -= num;
while (num--) {
bn_check_top(p->current->vals + offset);
if (!offset) {
offset = BN_CTX_POOL_SIZE - 1;
p->current = p->current->prev;
} else
offset--;
}
} | ['int ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a,\n const EC_POINT *b, BN_CTX *ctx)\n{\n int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *,\n const BIGNUM *, BN_CTX *);\n int (*field_sqr) (const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);\n BN_CTX *new_ctx = NULL;\n BIGNUM *tmp1, *tmp2, *Za23, *Zb23;\n const BIGNUM *tmp1_, *tmp2_;\n int ret = -1;\n if (EC_POINT_is_at_infinity(group, a)) {\n return EC_POINT_is_at_infinity(group, b) ? 0 : 1;\n }\n if (EC_POINT_is_at_infinity(group, b))\n return 1;\n if (a->Z_is_one && b->Z_is_one) {\n return ((BN_cmp(a->X, b->X) == 0) && BN_cmp(a->Y, b->Y) == 0) ? 0 : 1;\n }\n field_mul = group->meth->field_mul;\n field_sqr = group->meth->field_sqr;\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return -1;\n }\n BN_CTX_start(ctx);\n tmp1 = BN_CTX_get(ctx);\n tmp2 = BN_CTX_get(ctx);\n Za23 = BN_CTX_get(ctx);\n Zb23 = BN_CTX_get(ctx);\n if (Zb23 == NULL)\n goto end;\n if (!b->Z_is_one) {\n if (!field_sqr(group, Zb23, b->Z, ctx))\n goto end;\n if (!field_mul(group, tmp1, a->X, Zb23, ctx))\n goto end;\n tmp1_ = tmp1;\n } else\n tmp1_ = a->X;\n if (!a->Z_is_one) {\n if (!field_sqr(group, Za23, a->Z, ctx))\n goto end;\n if (!field_mul(group, tmp2, b->X, Za23, ctx))\n goto end;\n tmp2_ = tmp2;\n } else\n tmp2_ = b->X;\n if (BN_cmp(tmp1_, tmp2_) != 0) {\n ret = 1;\n goto end;\n }\n if (!b->Z_is_one) {\n if (!field_mul(group, Zb23, Zb23, b->Z, ctx))\n goto end;\n if (!field_mul(group, tmp1, a->Y, Zb23, ctx))\n goto end;\n } else\n tmp1_ = a->Y;\n if (!a->Z_is_one) {\n if (!field_mul(group, Za23, Za23, a->Z, ctx))\n goto end;\n if (!field_mul(group, tmp2, b->Y, Za23, ctx))\n goto end;\n } else\n tmp2_ = b->Y;\n if (BN_cmp(tmp1_, tmp2_) != 0) {\n ret = 1;\n goto end;\n }\n ret = 0;\n end:\n BN_CTX_end(ctx);\n if (new_ctx != NULL)\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)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static void BN_POOL_release(BN_POOL *p, unsigned int num)\n{\n unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE;\n p->used -= num;\n while (num--) {\n bn_check_top(p->current->vals + offset);\n if (!offset) {\n offset = BN_CTX_POOL_SIZE - 1;\n p->current = p->current->prev;\n } else\n offset--;\n }\n}'] |
35,065 | 0 | https://github.com/openssl/openssl/blob/4af5836b55442f31795eff6c8c81ea7a1b8cf94b/crypto/sparse_array.c/#L213 | int OPENSSL_SA_set(OPENSSL_SA *sa, size_t posn, void *val)
{
int i, level = 1;
size_t n = posn;
void **p;
if (sa == NULL)
return 0;
for (level = 1; level <= SA_BLOCK_MAX_LEVELS; level++)
if ((n >>= OPENSSL_SA_BLOCK_BITS) == 0)
break;
for (;sa->levels < level; sa->levels++) {
p = alloc_node();
if (p == NULL)
return 0;
p[0] = sa->nodes;
sa->nodes = p;
}
if (sa->top < posn)
sa->top = posn;
p = sa->nodes;
for (level = sa->levels - 1; level > 0; level--) {
i = (posn >> (OPENSSL_SA_BLOCK_BITS * level)) & SA_BLOCK_MASK;
if (p[i] == NULL && (p[i] = alloc_node()) == NULL)
return 0;
p = p[i];
}
p += posn & SA_BLOCK_MASK;
if (val == NULL && *p != NULL)
sa->nelem--;
else if (val != NULL && *p == NULL)
sa->nelem++;
*p = val;
return 1;
} | ['static int test_sparse_array_doall(void)\n{\n static const struct index_cases_st cases[] = {\n { 22, "A", 1 }, { 1021, "b", 0 }, { 3, "c", 0 }, { INT_MAX, "d", 1 },\n { (size_t)-1, "H", 0 }, { (size_t)-2, "i", 1 }, { 666666666, "s", 1 },\n { 1234567890, "t", 0 },\n };\n struct doall_st doall_data;\n size_t i;\n SPARSE_ARRAY_OF(char) *sa = NULL;\n int res = 0;\n if (!TEST_ptr(sa = ossl_sa_char_new()))\n goto err;\n doall_data.num_cases = OSSL_NELEM(cases);\n doall_data.cases = cases;\n doall_data.all = 1;\n doall_data.sa = NULL;\n for (i = 0; i < OSSL_NELEM(cases); i++)\n if (!TEST_true(ossl_sa_char_set(sa, cases[i].n, cases[i].v))) {\n TEST_note("failed at iteration %zu", i + 1);\n goto err;\n }\n ossl_sa_char_doall_arg(sa, &leaf_check_all, &doall_data);\n if (doall_data.res == 0) {\n TEST_info("while checking all elements");\n goto err;\n }\n doall_data.all = 0;\n doall_data.sa = sa;\n ossl_sa_char_doall_arg(sa, &leaf_delete, &doall_data);\n if (doall_data.res == 0) {\n TEST_info("while deleting selected elements");\n goto err;\n }\n ossl_sa_char_doall_arg(sa, &leaf_check_all, &doall_data);\n if (doall_data.res == 0) {\n TEST_info("while checking for deleted elements");\n goto err;\n }\n res = 1;\nerr:\n ossl_sa_char_free(sa);\n return res;\n}', 'DEFINE_SPARSE_ARRAY_OF(char)', 'int OPENSSL_SA_set(OPENSSL_SA *sa, size_t posn, void *val)\n{\n int i, level = 1;\n size_t n = posn;\n void **p;\n if (sa == NULL)\n return 0;\n for (level = 1; level <= SA_BLOCK_MAX_LEVELS; level++)\n if ((n >>= OPENSSL_SA_BLOCK_BITS) == 0)\n break;\n for (;sa->levels < level; sa->levels++) {\n p = alloc_node();\n if (p == NULL)\n return 0;\n p[0] = sa->nodes;\n sa->nodes = p;\n }\n if (sa->top < posn)\n sa->top = posn;\n p = sa->nodes;\n for (level = sa->levels - 1; level > 0; level--) {\n i = (posn >> (OPENSSL_SA_BLOCK_BITS * level)) & SA_BLOCK_MASK;\n if (p[i] == NULL && (p[i] = alloc_node()) == NULL)\n return 0;\n p = p[i];\n }\n p += posn & SA_BLOCK_MASK;\n if (val == NULL && *p != NULL)\n sa->nelem--;\n else if (val != NULL && *p == NULL)\n sa->nelem++;\n *p = val;\n return 1;\n}'] |
35,066 | 0 | https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/test/ectest.c/#L953 | static void char2_field_tests(void)
{
BN_CTX *ctx = NULL;
BIGNUM *p, *a, *b;
EC_GROUP *group;
EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 =
NULL, *C2_K571 = NULL;
EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 =
NULL, *C2_B571 = NULL;
EC_POINT *P, *Q, *R;
BIGNUM *x, *y, *z, *cof;
unsigned char buf[100];
size_t i, len;
int k;
ctx = BN_CTX_new();
if (!ctx)
ABORT;
p = BN_new();
a = BN_new();
b = BN_new();
if (!p || !a || !b)
ABORT;
if (!BN_hex2bn(&p, "13"))
ABORT;
if (!BN_hex2bn(&a, "3"))
ABORT;
if (!BN_hex2bn(&b, "1"))
ABORT;
group = EC_GROUP_new(EC_GF2m_simple_method());
if (!group)
ABORT;
if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx))
ABORT;
{
EC_GROUP *tmp;
tmp = EC_GROUP_new(EC_GROUP_method_of(group));
if (!tmp)
ABORT;
if (!EC_GROUP_copy(tmp, group))
ABORT;
EC_GROUP_free(group);
group = tmp;
}
if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx))
ABORT;
fprintf(stdout,
"Curve defined by Weierstrass equation\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x");
BN_print_fp(stdout, p);
fprintf(stdout, ")\n a = 0x");
BN_print_fp(stdout, a);
fprintf(stdout, "\n b = 0x");
BN_print_fp(stdout, b);
fprintf(stdout, "\n(0x... means binary polynomial)\n");
P = EC_POINT_new(group);
Q = EC_POINT_new(group);
R = EC_POINT_new(group);
if (!P || !Q || !R)
ABORT;
if (!EC_POINT_set_to_infinity(group, P))
ABORT;
if (!EC_POINT_is_at_infinity(group, P))
ABORT;
buf[0] = 0;
if (!EC_POINT_oct2point(group, Q, buf, 1, ctx))
ABORT;
if (!EC_POINT_add(group, P, P, Q, ctx))
ABORT;
if (!EC_POINT_is_at_infinity(group, P))
ABORT;
x = BN_new();
y = BN_new();
z = BN_new();
cof = BN_new();
if (!x || !y || !z || !cof)
ABORT;
if (!BN_hex2bn(&x, "6"))
ABORT;
# ifdef OPENSSL_EC_BIN_PT_COMP
if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx))
ABORT;
# else
if (!BN_hex2bn(&y, "8"))
ABORT;
if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx))
ABORT;
# endif
if (EC_POINT_is_on_curve(group, Q, ctx) <= 0) {
# ifdef OPENSSL_EC_BIN_PT_COMP
if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx))
ABORT;
# endif
fprintf(stderr, "Point is not on curve: x = 0x");
BN_print_fp(stderr, x);
fprintf(stderr, ", y = 0x");
BN_print_fp(stderr, y);
fprintf(stderr, "\n");
ABORT;
}
fprintf(stdout, "A cyclic subgroup:\n");
k = 100;
do {
if (k-- == 0)
ABORT;
if (EC_POINT_is_at_infinity(group, P))
fprintf(stdout, " point at infinity\n");
else {
if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx))
ABORT;
fprintf(stdout, " x = 0x");
BN_print_fp(stdout, x);
fprintf(stdout, ", y = 0x");
BN_print_fp(stdout, y);
fprintf(stdout, "\n");
}
if (!EC_POINT_copy(R, P))
ABORT;
if (!EC_POINT_add(group, P, P, Q, ctx))
ABORT;
}
while (!EC_POINT_is_at_infinity(group, P));
if (!EC_POINT_add(group, P, Q, R, ctx))
ABORT;
if (!EC_POINT_is_at_infinity(group, P))
ABORT;
# ifdef OPENSSL_EC_BIN_PT_COMP
len =
EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf,
sizeof buf, ctx);
if (len == 0)
ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx))
ABORT;
if (0 != EC_POINT_cmp(group, P, Q, ctx))
ABORT;
fprintf(stdout, "Generator as octet string, compressed form:\n ");
for (i = 0; i < len; i++)
fprintf(stdout, "%02X", buf[i]);
# endif
len =
EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf,
sizeof buf, ctx);
if (len == 0)
ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx))
ABORT;
if (0 != EC_POINT_cmp(group, P, Q, ctx))
ABORT;
fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n ");
for (i = 0; i < len; i++)
fprintf(stdout, "%02X", buf[i]);
# ifdef OPENSSL_EC_BIN_PT_COMP
len =
EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf,
ctx);
if (len == 0)
ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx))
ABORT;
if (0 != EC_POINT_cmp(group, P, Q, ctx))
ABORT;
fprintf(stdout, "\nGenerator as octet string, hybrid form:\n ");
for (i = 0; i < len; i++)
fprintf(stdout, "%02X", buf[i]);
# endif
fprintf(stdout, "\n");
if (!EC_POINT_invert(group, P, ctx))
ABORT;
if (0 != EC_POINT_cmp(group, P, R, ctx))
ABORT;
CHAR2_CURVE_TEST
("NIST curve K-163",
"0800000000000000000000000000000000000000C9",
"1",
"1",
"02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8",
"0289070FB05D38FF58321F2E800536D538CCDAA3D9",
1, "04000000000000000000020108A2E0CC0D99F8A5EF", "2", 163, C2_K163);
CHAR2_CURVE_TEST
("NIST curve B-163",
"0800000000000000000000000000000000000000C9",
"1",
"020A601907B8C953CA1481EB10512F78744A3205FD",
"03F0EBA16286A2D57EA0991168D4994637E8343E36",
"00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1",
1, "040000000000000000000292FE77E70C12A4234C33", "2", 163, C2_B163);
CHAR2_CURVE_TEST
("NIST curve K-233",
"020000000000000000000000000000000000000004000000000000000001",
"0",
"1",
"017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126",
"01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3",
0,
"008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF",
"4", 233, C2_K233);
CHAR2_CURVE_TEST
("NIST curve B-233",
"020000000000000000000000000000000000000004000000000000000001",
"000000000000000000000000000000000000000000000000000000000001",
"0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD",
"00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B",
"01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052",
1,
"01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7",
"2", 233, C2_B233);
CHAR2_CURVE_TEST
("NIST curve K-283",
"0800000000000000000000000000000000000000000000000000000000000000000010A1",
"0",
"1",
"0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836",
"01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259",
0,
"01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61",
"4", 283, C2_K283);
CHAR2_CURVE_TEST
("NIST curve B-283",
"0800000000000000000000000000000000000000000000000000000000000000000010A1",
"000000000000000000000000000000000000000000000000000000000000000000000001",
"027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5",
"05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053",
"03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4",
1,
"03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307",
"2", 283, C2_B283);
CHAR2_CURVE_TEST
("NIST curve K-409",
"02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",
"0",
"1",
"0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746",
"01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B",
1,
"007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF",
"4", 409, C2_K409);
CHAR2_CURVE_TEST
("NIST curve B-409",
"02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F",
"015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7",
"0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706",
1,
"010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173",
"2", 409, C2_B409);
CHAR2_CURVE_TEST
("NIST curve K-571",
"80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",
"0",
"1",
"026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972",
"0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3",
0,
"020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001",
"4", 571, C2_K571);
CHAR2_CURVE_TEST
("NIST curve B-571",
"80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A",
"0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19",
"037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B",
1,
"03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47",
"2", 571, C2_B571);
if (!EC_POINT_copy(Q, P))
ABORT;
if (EC_POINT_is_at_infinity(group, Q))
ABORT;
if (!EC_POINT_dbl(group, P, P, ctx))
ABORT;
if (EC_POINT_is_on_curve(group, P, ctx) <= 0)
ABORT;
if (!EC_POINT_invert(group, Q, ctx))
ABORT;
if (!EC_POINT_add(group, R, P, Q, ctx))
ABORT;
if (!EC_POINT_add(group, R, R, Q, ctx))
ABORT;
if (!EC_POINT_is_at_infinity(group, R))
ABORT;
{
const EC_POINT *points[3];
const BIGNUM *scalars[3];
if (EC_POINT_is_at_infinity(group, Q))
ABORT;
points[0] = Q;
points[1] = Q;
points[2] = Q;
if (!BN_add(y, z, BN_value_one()))
ABORT;
if (BN_is_odd(y))
ABORT;
if (!BN_rshift1(y, y))
ABORT;
scalars[0] = y;
scalars[1] = y;
fprintf(stdout, "combined multiplication ...");
fflush(stdout);
if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))
ABORT;
if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))
ABORT;
if (0 != EC_POINT_cmp(group, P, R, ctx))
ABORT;
if (0 != EC_POINT_cmp(group, R, Q, ctx))
ABORT;
fprintf(stdout, ".");
fflush(stdout);
if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0))
ABORT;
if (!BN_add(z, z, y))
ABORT;
BN_set_negative(z, 1);
scalars[0] = y;
scalars[1] = z;
if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))
ABORT;
if (!EC_POINT_is_at_infinity(group, P))
ABORT;
fprintf(stdout, ".");
fflush(stdout);
if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0))
ABORT;
if (!BN_add(z, x, y))
ABORT;
BN_set_negative(z, 1);
scalars[0] = x;
scalars[1] = y;
scalars[2] = z;
if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx))
ABORT;
if (!EC_POINT_is_at_infinity(group, P))
ABORT;
fprintf(stdout, " ok\n\n");
}
BN_CTX_free(ctx);
BN_free(p);
BN_free(a);
BN_free(b);
EC_GROUP_free(group);
EC_POINT_free(P);
EC_POINT_free(Q);
EC_POINT_free(R);
BN_free(x);
BN_free(y);
BN_free(z);
BN_free(cof);
EC_GROUP_free(C2_K163);
EC_GROUP_free(C2_B163);
EC_GROUP_free(C2_K233);
EC_GROUP_free(C2_B233);
EC_GROUP_free(C2_K283);
EC_GROUP_free(C2_B283);
EC_GROUP_free(C2_K409);
EC_GROUP_free(C2_B409);
EC_GROUP_free(C2_K571);
EC_GROUP_free(C2_B571);
} | ['static void char2_field_tests(void)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *p, *a, *b;\n EC_GROUP *group;\n EC_GROUP *C2_K163 = NULL, *C2_K233 = NULL, *C2_K283 = NULL, *C2_K409 =\n NULL, *C2_K571 = NULL;\n EC_GROUP *C2_B163 = NULL, *C2_B233 = NULL, *C2_B283 = NULL, *C2_B409 =\n NULL, *C2_B571 = NULL;\n EC_POINT *P, *Q, *R;\n BIGNUM *x, *y, *z, *cof;\n unsigned char buf[100];\n size_t i, len;\n int k;\n ctx = BN_CTX_new();\n if (!ctx)\n ABORT;\n p = BN_new();\n a = BN_new();\n b = BN_new();\n if (!p || !a || !b)\n ABORT;\n if (!BN_hex2bn(&p, "13"))\n ABORT;\n if (!BN_hex2bn(&a, "3"))\n ABORT;\n if (!BN_hex2bn(&b, "1"))\n ABORT;\n group = EC_GROUP_new(EC_GF2m_simple_method());\n if (!group)\n ABORT;\n if (!EC_GROUP_set_curve_GF2m(group, p, a, b, ctx))\n ABORT;\n {\n EC_GROUP *tmp;\n tmp = EC_GROUP_new(EC_GROUP_method_of(group));\n if (!tmp)\n ABORT;\n if (!EC_GROUP_copy(tmp, group))\n ABORT;\n EC_GROUP_free(group);\n group = tmp;\n }\n if (!EC_GROUP_get_curve_GF2m(group, p, a, b, ctx))\n ABORT;\n fprintf(stdout,\n "Curve defined by Weierstrass equation\\n y^2 + x*y = x^3 + a*x^2 + b (mod 0x");\n BN_print_fp(stdout, p);\n fprintf(stdout, ")\\n a = 0x");\n BN_print_fp(stdout, a);\n fprintf(stdout, "\\n b = 0x");\n BN_print_fp(stdout, b);\n fprintf(stdout, "\\n(0x... means binary polynomial)\\n");\n P = EC_POINT_new(group);\n Q = EC_POINT_new(group);\n R = EC_POINT_new(group);\n if (!P || !Q || !R)\n ABORT;\n if (!EC_POINT_set_to_infinity(group, P))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n buf[0] = 0;\n if (!EC_POINT_oct2point(group, Q, buf, 1, ctx))\n ABORT;\n if (!EC_POINT_add(group, P, P, Q, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n x = BN_new();\n y = BN_new();\n z = BN_new();\n cof = BN_new();\n if (!x || !y || !z || !cof)\n ABORT;\n if (!BN_hex2bn(&x, "6"))\n ABORT;\n# ifdef OPENSSL_EC_BIN_PT_COMP\n if (!EC_POINT_set_compressed_coordinates_GF2m(group, Q, x, 1, ctx))\n ABORT;\n# else\n if (!BN_hex2bn(&y, "8"))\n ABORT;\n if (!EC_POINT_set_affine_coordinates_GF2m(group, Q, x, y, ctx))\n ABORT;\n# endif\n if (EC_POINT_is_on_curve(group, Q, ctx) <= 0) {\n# ifdef OPENSSL_EC_BIN_PT_COMP\n if (!EC_POINT_get_affine_coordinates_GF2m(group, Q, x, y, ctx))\n ABORT;\n# endif\n fprintf(stderr, "Point is not on curve: x = 0x");\n BN_print_fp(stderr, x);\n fprintf(stderr, ", y = 0x");\n BN_print_fp(stderr, y);\n fprintf(stderr, "\\n");\n ABORT;\n }\n fprintf(stdout, "A cyclic subgroup:\\n");\n k = 100;\n do {\n if (k-- == 0)\n ABORT;\n if (EC_POINT_is_at_infinity(group, P))\n fprintf(stdout, " point at infinity\\n");\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, P, x, y, ctx))\n ABORT;\n fprintf(stdout, " x = 0x");\n BN_print_fp(stdout, x);\n fprintf(stdout, ", y = 0x");\n BN_print_fp(stdout, y);\n fprintf(stdout, "\\n");\n }\n if (!EC_POINT_copy(R, P))\n ABORT;\n if (!EC_POINT_add(group, P, P, Q, ctx))\n ABORT;\n }\n while (!EC_POINT_is_at_infinity(group, P));\n if (!EC_POINT_add(group, P, Q, R, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n# ifdef OPENSSL_EC_BIN_PT_COMP\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf,\n sizeof buf, ctx);\n if (len == 0)\n ABORT;\n if (!EC_POINT_oct2point(group, P, buf, len, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, Q, ctx))\n ABORT;\n fprintf(stdout, "Generator as octet string, compressed form:\\n ");\n for (i = 0; i < len; i++)\n fprintf(stdout, "%02X", buf[i]);\n# endif\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf,\n sizeof buf, ctx);\n if (len == 0)\n ABORT;\n if (!EC_POINT_oct2point(group, P, buf, len, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, Q, ctx))\n ABORT;\n fprintf(stdout, "\\nGenerator as octet string, uncompressed form:\\n ");\n for (i = 0; i < len; i++)\n fprintf(stdout, "%02X", buf[i]);\n# ifdef OPENSSL_EC_BIN_PT_COMP\n len =\n EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf,\n ctx);\n if (len == 0)\n ABORT;\n if (!EC_POINT_oct2point(group, P, buf, len, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, Q, ctx))\n ABORT;\n fprintf(stdout, "\\nGenerator as octet string, hybrid form:\\n ");\n for (i = 0; i < len; i++)\n fprintf(stdout, "%02X", buf[i]);\n# endif\n fprintf(stdout, "\\n");\n if (!EC_POINT_invert(group, P, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, R, ctx))\n ABORT;\n CHAR2_CURVE_TEST\n ("NIST curve K-163",\n "0800000000000000000000000000000000000000C9",\n "1",\n "1",\n "02FE13C0537BBC11ACAA07D793DE4E6D5E5C94EEE8",\n "0289070FB05D38FF58321F2E800536D538CCDAA3D9",\n 1, "04000000000000000000020108A2E0CC0D99F8A5EF", "2", 163, C2_K163);\n CHAR2_CURVE_TEST\n ("NIST curve B-163",\n "0800000000000000000000000000000000000000C9",\n "1",\n "020A601907B8C953CA1481EB10512F78744A3205FD",\n "03F0EBA16286A2D57EA0991168D4994637E8343E36",\n "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1",\n 1, "040000000000000000000292FE77E70C12A4234C33", "2", 163, C2_B163);\n CHAR2_CURVE_TEST\n ("NIST curve K-233",\n "020000000000000000000000000000000000000004000000000000000001",\n "0",\n "1",\n "017232BA853A7E731AF129F22FF4149563A419C26BF50A4C9D6EEFAD6126",\n "01DB537DECE819B7F70F555A67C427A8CD9BF18AEB9B56E0C11056FAE6A3",\n 0,\n "008000000000000000000000000000069D5BB915BCD46EFB1AD5F173ABDF",\n "4", 233, C2_K233);\n CHAR2_CURVE_TEST\n ("NIST curve B-233",\n "020000000000000000000000000000000000000004000000000000000001",\n "000000000000000000000000000000000000000000000000000000000001",\n "0066647EDE6C332C7F8C0923BB58213B333B20E9CE4281FE115F7D8F90AD",\n "00FAC9DFCBAC8313BB2139F1BB755FEF65BC391F8B36F8F8EB7371FD558B",\n "01006A08A41903350678E58528BEBF8A0BEFF867A7CA36716F7E01F81052",\n 1,\n "01000000000000000000000000000013E974E72F8A6922031D2603CFE0D7",\n "2", 233, C2_B233);\n CHAR2_CURVE_TEST\n ("NIST curve K-283",\n "0800000000000000000000000000000000000000000000000000000000000000000010A1",\n "0",\n "1",\n "0503213F78CA44883F1A3B8162F188E553CD265F23C1567A16876913B0C2AC2458492836",\n "01CCDA380F1C9E318D90F95D07E5426FE87E45C0E8184698E45962364E34116177DD2259",\n 0,\n "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE9AE2ED07577265DFF7F94451E061E163C61",\n "4", 283, C2_K283);\n CHAR2_CURVE_TEST\n ("NIST curve B-283",\n "0800000000000000000000000000000000000000000000000000000000000000000010A1",\n "000000000000000000000000000000000000000000000000000000000000000000000001",\n "027B680AC8B8596DA5A4AF8A19A0303FCA97FD7645309FA2A581485AF6263E313B79A2F5",\n "05F939258DB7DD90E1934F8C70B0DFEC2EED25B8557EAC9C80E2E198F8CDBECD86B12053",\n "03676854FE24141CB98FE6D4B20D02B4516FF702350EDDB0826779C813F0DF45BE8112F4",\n 1,\n "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEF90399660FC938A90165B042A7CEFADB307",\n "2", 283, C2_B283);\n CHAR2_CURVE_TEST\n ("NIST curve K-409",\n "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",\n "0",\n "1",\n "0060F05F658F49C1AD3AB1890F7184210EFD0987E307C84C27ACCFB8F9F67CC2C460189EB5AAAA62EE222EB1B35540CFE9023746",\n "01E369050B7C4E42ACBA1DACBF04299C3460782F918EA427E6325165E9EA10E3DA5F6C42E9C55215AA9CA27A5863EC48D8E0286B",\n 1,\n "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5F83B2D4EA20400EC4557D5ED3E3E7CA5B4B5C83B8E01E5FCF",\n "4", 409, C2_K409);\n CHAR2_CURVE_TEST\n ("NIST curve B-409",\n "02000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000001",\n "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",\n "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422EF1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F",\n "015D4860D088DDB3496B0C6064756260441CDE4AF1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7",\n "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706",\n 1,\n "010000000000000000000000000000000000000000000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173",\n "2", 409, C2_B409);\n CHAR2_CURVE_TEST\n ("NIST curve K-571",\n "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",\n "0",\n "1",\n "026EB7A859923FBC82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E647DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972",\n "0349DC807F4FBF374F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA74FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3",\n 0,\n "020000000000000000000000000000000000000000000000000000000000000000000000131850E1F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001",\n "4", 571, C2_K571);\n CHAR2_CURVE_TEST\n ("NIST curve B-571",\n "80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000425",\n "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",\n "02F40E7E2221F295DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA59332BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A",\n "0303001D34B856296C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19",\n "037BF27342DA639B6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A576291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B",\n 1,\n "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47",\n "2", 571, C2_B571);\n if (!EC_POINT_copy(Q, P))\n ABORT;\n if (EC_POINT_is_at_infinity(group, Q))\n ABORT;\n if (!EC_POINT_dbl(group, P, P, ctx))\n ABORT;\n if (EC_POINT_is_on_curve(group, P, ctx) <= 0)\n ABORT;\n if (!EC_POINT_invert(group, Q, ctx))\n ABORT;\n if (!EC_POINT_add(group, R, P, Q, ctx))\n ABORT;\n if (!EC_POINT_add(group, R, R, Q, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, R))\n ABORT;\n {\n const EC_POINT *points[3];\n const BIGNUM *scalars[3];\n if (EC_POINT_is_at_infinity(group, Q))\n ABORT;\n points[0] = Q;\n points[1] = Q;\n points[2] = Q;\n if (!BN_add(y, z, BN_value_one()))\n ABORT;\n if (BN_is_odd(y))\n ABORT;\n if (!BN_rshift1(y, y))\n ABORT;\n scalars[0] = y;\n scalars[1] = y;\n fprintf(stdout, "combined multiplication ...");\n fflush(stdout);\n if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n ABORT;\n if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, P, R, ctx))\n ABORT;\n if (0 != EC_POINT_cmp(group, R, Q, ctx))\n ABORT;\n fprintf(stdout, ".");\n fflush(stdout);\n if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0))\n ABORT;\n if (!BN_add(z, z, y))\n ABORT;\n BN_set_negative(z, 1);\n scalars[0] = y;\n scalars[1] = z;\n if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n fprintf(stdout, ".");\n fflush(stdout);\n if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0))\n ABORT;\n if (!BN_add(z, x, y))\n ABORT;\n BN_set_negative(z, 1);\n scalars[0] = x;\n scalars[1] = y;\n scalars[2] = z;\n if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx))\n ABORT;\n if (!EC_POINT_is_at_infinity(group, P))\n ABORT;\n fprintf(stdout, " ok\\n\\n");\n }\n BN_CTX_free(ctx);\n BN_free(p);\n BN_free(a);\n BN_free(b);\n EC_GROUP_free(group);\n EC_POINT_free(P);\n EC_POINT_free(Q);\n EC_POINT_free(R);\n BN_free(x);\n BN_free(y);\n BN_free(z);\n BN_free(cof);\n EC_GROUP_free(C2_K163);\n EC_GROUP_free(C2_B163);\n EC_GROUP_free(C2_K233);\n EC_GROUP_free(C2_B233);\n EC_GROUP_free(C2_K283);\n EC_GROUP_free(C2_B283);\n EC_GROUP_free(C2_K409);\n EC_GROUP_free(C2_B409);\n EC_GROUP_free(C2_K571);\n EC_GROUP_free(C2_B571);\n}', 'BN_CTX *BN_CTX_new(void)\n{\n BN_CTX *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_CTX_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n BN_POOL_init(&ret->pool);\n BN_STACK_init(&ret->stack);\n return ret;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (num <= 0)\n return NULL;\n allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)file;\n (void)line;\n ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n if (ret && (num > 2048)) {\n extern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n }\n#endif\n return ret;\n}', 'static void BN_POOL_init(BN_POOL *p)\n{\n p->head = p->current = p->tail = NULL;\n p->used = p->size = 0;\n}', 'static void BN_STACK_init(BN_STACK *st)\n{\n st->indexes = NULL;\n st->depth = st->size = 0;\n}', 'BIGNUM *BN_new(void)\n{\n BIGNUM *ret;\n if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n BNerr(BN_F_BN_NEW, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n ret->flags = BN_FLG_MALLOCED;\n bn_check_top(ret);\n return (ret);\n}'] |
35,067 | 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 int fic_decode_slice(AVCodecContext *avctx, void *tdata)\n{\n FICContext *ctx = avctx->priv_data;\n FICThreadContext *tctx = tdata;\n BitstreamContext bc;\n uint8_t *src = tctx->src;\n int slice_h = tctx->slice_h;\n int src_size = tctx->src_size;\n int y_off = tctx->y_off;\n int x, y, p;\n bitstream_init8(&bc, src, src_size);\n for (p = 0; p < 3; p++) {\n int stride = ctx->frame->linesize[p];\n uint8_t* dst = ctx->frame->data[p] + (y_off >> !!p) * stride;\n for (y = 0; y < (slice_h >> !!p); y += 8) {\n for (x = 0; x < (ctx->aligned_width >> !!p); x += 8) {\n int ret;\n if ((ret = fic_decode_block(ctx, &bc, dst + x, stride, tctx->block)) != 0)\n return ret;\n }\n dst += 8 * stride;\n }\n }\n return 0;\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n unsigned byte_size)\n{\n if (byte_size > INT_MAX / 8)\n return AVERROR_INVALIDDATA;\n return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static int fic_decode_block(FICContext *ctx, BitstreamContext *bc,\n uint8_t *dst, int stride, int16_t *block)\n{\n int i, num_coeff;\n if (bitstream_read_bit(bc)) {\n ctx->frame->key_frame = 0;\n ctx->frame->pict_type = AV_PICTURE_TYPE_P;\n return 0;\n }\n memset(block, 0, sizeof(*block) * 64);\n num_coeff = bitstream_read(bc, 7);\n if (num_coeff > 64)\n return AVERROR_INVALIDDATA;\n for (i = 0; i < num_coeff; i++)\n block[ff_zigzag_direct[i]] = get_se_golomb(bc) *\n ctx->qmat[ff_zigzag_direct[i]];\n fic_idct_put(dst, stride, block);\n return 0;\n}', 'static inline unsigned bitstream_read_bit(BitstreamContext *bc)\n{\n if (!bc->bits_left)\n refill_64(bc);\n return get_val(bc, 1);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}'] |
35,068 | 0 | https://github.com/libav/libav/blob/e5b0fc170f85b00f7dd0ac514918fb5c95253d39/libavcodec/bitstream.h/#L139 | static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
} | ['static int decode_skip_count(BitstreamContext *bc)\n{\n int value;\n value = bitstream_read_bit(bc);\n if (value)\n return 0;\n value = bitstream_read(bc, 3);\n if (value)\n return value;\n value = bitstream_read(bc, 8);\n if (value)\n return value + 7;\n value = bitstream_read(bc, 15);\n if (value)\n return value + 262;\n return -1;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}'] |
35,069 | 0 | https://github.com/libav/libav/blob/0fdc9f81a00f0f32eb93c324bad65d8014deb4dd/libavcodec/bitstream.h/#L139 | static inline uint64_t get_val(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);
bc->bits >>= n;
#else
uint64_t ret = bc->bits >> (64 - n);
bc->bits <<= n;
#endif
bc->bits_left -= n;
return ret;
} | ['static int ivi_dec_tile_data_size(BitstreamContext *bc)\n{\n int len;\n len = 0;\n if (bitstream_read_bit(bc)) {\n len = bitstream_read(bc, 8);\n if (len == 255)\n len = bitstream_read(bc, 24);\n }\n bitstream_align(bc);\n return len;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}'] |
35,070 | 0 | https://github.com/openssl/openssl/blob/a68d8c7b77a3d46d591b89cfd0ecd2a2242e4613/crypto/ec/ecx_meth.c/#L114 | static int ecx_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
{
const X25519_KEY *xkey = pkey->pkey.ptr;
unsigned char *penc;
if (xkey == NULL) {
ECerr(EC_F_ECX_PUB_ENCODE, EC_R_INVALID_KEY);
return 0;
}
penc = OPENSSL_memdup(xkey->pubkey, X25519_KEYLEN);
if (penc == NULL) {
ECerr(EC_F_ECX_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!X509_PUBKEY_set0_param(pk, OBJ_nid2obj(NID_X25519), V_ASN1_UNDEF,
NULL, penc, X25519_KEYLEN)) {
OPENSSL_free(penc);
ECerr(EC_F_ECX_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
return 0;
}
return 1;
} | ['static int ecx_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)\n{\n const X25519_KEY *xkey = pkey->pkey.ptr;\n unsigned char *penc;\n if (xkey == NULL) {\n ECerr(EC_F_ECX_PUB_ENCODE, EC_R_INVALID_KEY);\n return 0;\n }\n penc = OPENSSL_memdup(xkey->pubkey, X25519_KEYLEN);\n if (penc == NULL) {\n ECerr(EC_F_ECX_PUB_ENCODE, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n if (!X509_PUBKEY_set0_param(pk, OBJ_nid2obj(NID_X25519), V_ASN1_UNDEF,\n NULL, penc, X25519_KEYLEN)) {\n OPENSSL_free(penc);\n ECerr(EC_F_ECX_PUB_ENCODE, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n return 1;\n}', 'void *CRYPTO_memdup(const void *data, size_t siz, const char* file, int line)\n{\n void *ret;\n if (data == NULL || siz >= INT_MAX)\n return NULL;\n ret = CRYPTO_malloc(siz, file, line);\n if (ret == NULL) {\n CRYPTOerr(CRYPTO_F_CRYPTO_MEMDUP, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n return memcpy(ret, data, siz);\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}', 'ASN1_OBJECT *OBJ_nid2obj(int n)\n{\n ADDED_OBJ ad, *adp;\n ASN1_OBJECT ob;\n if ((n >= 0) && (n < NUM_NID)) {\n if ((n != NID_undef) && (nid_objs[n].nid == NID_undef)) {\n OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);\n return (NULL);\n }\n return ((ASN1_OBJECT *)&(nid_objs[n]));\n } else if (added == NULL)\n return (NULL);\n else {\n ad.type = ADDED_NID;\n ad.obj = &ob;\n ob.nid = n;\n adp = lh_ADDED_OBJ_retrieve(added, &ad);\n if (adp != NULL)\n return (adp->obj);\n else {\n OBJerr(OBJ_F_OBJ_NID2OBJ, OBJ_R_UNKNOWN_NID);\n return (NULL);\n }\n }\n}'] |
35,071 | 0 | https://github.com/openssl/openssl/blob/5f50d597f2c9106824ea48f47e318f7b2d13a867/crypto/bn/bn_asm.c/#L405 | BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
{
BN_ULONG t1,t2;
int c=0;
assert(n >= 0);
if (n <= 0) return((BN_ULONG)0);
#ifndef OPENSSL_SMALL_FOOTPRINT
while (n&~3)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[1]; t2=b[1];
r[1]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[2]; t2=b[2];
r[2]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
t1=a[3]; t2=b[3];
r[3]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
a+=4; b+=4; r+=4; n-=4;
}
#endif
while (n)
{
t1=a[0]; t2=b[0];
r[0]=(t1-t2-c)&BN_MASK2;
if (t1 != t2) c=(t1 < t2);
a++; b++; r++; n--;
}
return(c);
} | ['void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,\n\t BN_ULONG *t)\n\t{\n\tint i,n;\n\tint c1,c2;\n\tint neg,oneg,zero;\n\tBN_ULONG ll,lc,*lp,*mp;\n# ifdef BN_COUNT\n\tfprintf(stderr," bn_mul_high %d * %d\\n",n2,n2);\n# endif\n\tn=n2/2;\n\tneg=zero=0;\n\tc1=bn_cmp_words(&(a[0]),&(a[n]),n);\n\tc2=bn_cmp_words(&(b[n]),&(b[0]),n);\n\tswitch (c1*3+c2)\n\t\t{\n\tcase -4:\n\t\tbn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);\n\t\tbn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);\n\t\tbreak;\n\tcase -3:\n\t\tzero=1;\n\t\tbreak;\n\tcase -2:\n\t\tbn_sub_words(&(r[0]),&(a[n]),&(a[0]),n);\n\t\tbn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);\n\t\tneg=1;\n\t\tbreak;\n\tcase -1:\n\tcase 0:\n\tcase 1:\n\t\tzero=1;\n\t\tbreak;\n\tcase 2:\n\t\tbn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);\n\t\tbn_sub_words(&(r[n]),&(b[0]),&(b[n]),n);\n\t\tneg=1;\n\t\tbreak;\n\tcase 3:\n\t\tzero=1;\n\t\tbreak;\n\tcase 4:\n\t\tbn_sub_words(&(r[0]),&(a[0]),&(a[n]),n);\n\t\tbn_sub_words(&(r[n]),&(b[n]),&(b[0]),n);\n\t\tbreak;\n\t\t}\n\toneg=neg;\n# ifdef BN_MUL_COMBA\n\tif (n == 8)\n\t\t{\n\t\tbn_mul_comba8(&(t[0]),&(r[0]),&(r[n]));\n\t\tbn_mul_comba8(r,&(a[n]),&(b[n]));\n\t\t}\n\telse\n# endif\n\t\t{\n\t\tbn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,0,0,&(t[n2]));\n\t\tbn_mul_recursive(r,&(a[n]),&(b[n]),n,0,0,&(t[n2]));\n\t\t}\n\tif (l != NULL)\n\t\t{\n\t\tlp= &(t[n2+n]);\n\t\tc1=(int)(bn_add_words(lp,&(r[0]),&(l[0]),n));\n\t\t}\n\telse\n\t\t{\n\t\tc1=0;\n\t\tlp= &(r[0]);\n\t\t}\n\tif (neg)\n\t\tneg=(int)(bn_sub_words(&(t[n2]),lp,&(t[0]),n));\n\telse\n\t\t{\n\t\tbn_add_words(&(t[n2]),lp,&(t[0]),n);\n\t\tneg=0;\n\t\t}\n\tif (l != NULL)\n\t\t{\n\t\tbn_sub_words(&(t[n2+n]),&(l[n]),&(t[n2]),n);\n\t\t}\n\telse\n\t\t{\n\t\tlp= &(t[n2+n]);\n\t\tmp= &(t[n2]);\n\t\tfor (i=0; i<n; i++)\n\t\t\tlp[i]=((~mp[i])+1)&BN_MASK2;\n\t\t}\n\tif (l != NULL)\n\t\t{\n\t\tlp= &(t[n2]);\n\t\tc1= (int)(bn_add_words(lp,&(t[n2+n]),&(l[0]),n));\n\t\t}\n\telse\n\t\t{\n\t\tlp= &(t[n2+n]);\n\t\tc1=0;\n\t\t}\n\tc1+=(int)(bn_add_words(&(t[n2]),lp, &(r[0]),n));\n\tif (oneg)\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),&(t[n2]),&(t[0]),n));\n\telse\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),&(t[0]),n));\n\tc2 =(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n2+n]),n));\n\tc2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(r[n]),n));\n\tif (oneg)\n\t\tc2-=(int)(bn_sub_words(&(r[0]),&(r[0]),&(t[n]),n));\n\telse\n\t\tc2+=(int)(bn_add_words(&(r[0]),&(r[0]),&(t[n]),n));\n\tif (c1 != 0)\n\t\t{\n\t\ti=0;\n\t\tif (c1 > 0)\n\t\t\t{\n\t\t\tlc=c1;\n\t\t\tdo\t{\n\t\t\t\tll=(r[i]+lc)&BN_MASK2;\n\t\t\t\tr[i++]=ll;\n\t\t\t\tlc=(lc > ll);\n\t\t\t\t} while (lc);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tlc= -c1;\n\t\t\tdo\t{\n\t\t\t\tll=r[i];\n\t\t\t\tr[i++]=(ll-lc)&BN_MASK2;\n\t\t\t\tlc=(lc > ll);\n\t\t\t\t} while (lc);\n\t\t\t}\n\t\t}\n\tif (c2 != 0)\n\t\t{\n\t\ti=n;\n\t\tif (c2 > 0)\n\t\t\t{\n\t\t\tlc=c2;\n\t\t\tdo\t{\n\t\t\t\tll=(r[i]+lc)&BN_MASK2;\n\t\t\t\tr[i++]=ll;\n\t\t\t\tlc=(lc > ll);\n\t\t\t\t} while (lc);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tlc= -c2;\n\t\t\tdo\t{\n\t\t\t\tll=r[i];\n\t\t\t\tr[i++]=(ll-lc)&BN_MASK2;\n\t\t\t\tlc=(lc > ll);\n\t\t\t\t} while (lc);\n\t\t\t}\n\t\t}\n\t}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n\tint dna, int dnb, BN_ULONG *t)\n\t{\n\tint n=n2/2,c1,c2;\n\tint tna=n+dna, tnb=n+dnb;\n\tunsigned int neg,zero;\n\tBN_ULONG ln,lo,*p;\n# ifdef BN_COUNT\n\tfprintf(stderr," bn_mul_recursive %d * %d\\n",n2,n2);\n# endif\n# ifdef BN_MUL_COMBA\n# if 0\n\tif (n2 == 4)\n\t\t{\n\t\tbn_mul_comba4(r,a,b);\n\t\treturn;\n\t\t}\n# endif\n\tif (n2 == 8 && dna == 0 && dnb == 0)\n\t\t{\n\t\tbn_mul_comba8(r,a,b);\n\t\treturn;\n\t\t}\n# endif\n\tif (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)\n\t\t{\n\t\tbn_mul_normal(r,a,n2+dna,b,n2+dnb);\n\t\tif ((dna + dnb) < 0)\n\t\t\tmemset(&r[2*n2 + dna + dnb], 0,\n\t\t\t\tsizeof(BN_ULONG) * -(dna + dnb));\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\t\tbreak;\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\t\tbreak;\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\t\tbreak;\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# ifdef BN_MUL_COMBA\n\tif (n == 4 && dna == 0 && dnb == 0)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba4(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,8*sizeof(BN_ULONG));\n\t\tbn_mul_comba4(r,a,b);\n\t\tbn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse if (n == 8 && dna == 0 && dnb == 0)\n\t\t{\n\t\tif (!zero)\n\t\t\tbn_mul_comba8(&(t[n2]),t,&(t[n]));\n\t\telse\n\t\t\tmemset(&(t[n2]),0,16*sizeof(BN_ULONG));\n\t\tbn_mul_comba8(r,a,b);\n\t\tbn_mul_comba8(&(r[n2]),&(a[n]),&(b[n]));\n\t\t}\n\telse\n# endif\n\t\t{\n\t\tp= &(t[n2*2]);\n\t\tif (!zero)\n\t\t\tbn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p);\n\t\telse\n\t\t\tmemset(&(t[n2]),0,n2*sizeof(BN_ULONG));\n\t\tbn_mul_recursive(r,a,b,n,0,0,p);\n\t\tbn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,dna,dnb,p);\n\t\t}\n\tc1=(int)(bn_add_words(t,r,&(r[n2]),n2));\n\tif (neg)\n\t\t{\n\t\tc1-=(int)(bn_sub_words(&(t[n2]),t,&(t[n2]),n2));\n\t\t}\n\telse\n\t\t{\n\t\tc1+=(int)(bn_add_words(&(t[n2]),&(t[n2]),t,n2));\n\t\t}\n\tc1+=(int)(bn_add_words(&(r[n]),&(r[n]),&(t[n2]),n2));\n\tif (c1)\n\t\t{\n\t\tp= &(r[n+n2]);\n\t\tlo= *p;\n\t\tln=(lo+c1)&BN_MASK2;\n\t\t*p=ln;\n\t\tif (ln < (BN_ULONG)c1)\n\t\t\t{\n\t\t\tdo\t{\n\t\t\t\tp++;\n\t\t\t\tlo= *p;\n\t\t\t\tln=(lo+1)&BN_MASK2;\n\t\t\t\t*p=ln;\n\t\t\t\t} while (ln == 0);\n\t\t\t}\n\t\t}\n\t}', 'int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tint n,i;\n\tn = cl-1;\n\tif (dl < 0)\n\t\t{\n\t\tfor (i=dl; i<0; i++)\n\t\t\t{\n\t\t\tif (b[n-i] != 0)\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\tif (dl > 0)\n\t\t{\n\t\tfor (i=dl; i>0; i--)\n\t\t\t{\n\t\t\tif (a[n+i] != 0)\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t}\n\treturn bn_cmp_words(a,b,cl);\n\t}', 'BN_ULONG bn_sub_part_words(BN_ULONG *r,\n\tconst BN_ULONG *a, const BN_ULONG *b,\n\tint cl, int dl)\n\t{\n\tBN_ULONG c, t;\n\tassert(cl >= 0);\n\tc = bn_sub_words(r, a, b, cl);\n\tif (dl == 0)\n\t\treturn c;\n\tr += cl;\n\ta += cl;\n\tb += cl;\n\tif (dl < 0)\n\t\t{\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl < 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\tfor (;;)\n\t\t\t{\n\t\t\tt = b[0];\n\t\t\tr[0] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[1];\n\t\t\tr[1] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[2];\n\t\t\tr[2] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tt = b[3];\n\t\t\tr[3] = (0-t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=1;\n\t\t\tif (++dl >= 0) break;\n\t\t\tb += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tint save_dl = dl;\n#ifdef BN_COUNT\n\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c = %d)\\n", cl, dl, c);\n#endif\n\t\twhile(c)\n\t\t\t{\n\t\t\tt = a[0];\n\t\t\tr[0] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[1];\n\t\t\tr[1] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[2];\n\t\t\tr[2] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tt = a[3];\n\t\t\tr[3] = (t-c)&BN_MASK2;\n\t\t\tif (t != 0) c=0;\n\t\t\tif (--dl <= 0) break;\n\t\t\tsave_dl = dl;\n\t\t\ta += 4;\n\t\t\tr += 4;\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c == 0)\\n", cl, dl);\n#endif\n\t\t\tif (save_dl > dl)\n\t\t\t\t{\n\t\t\t\tswitch (save_dl - dl)\n\t\t\t\t\t{\n\t\t\t\tcase 1:\n\t\t\t\t\tr[1] = a[1];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 2:\n\t\t\t\t\tr[2] = a[2];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tcase 3:\n\t\t\t\t\tr[3] = a[3];\n\t\t\t\t\tif (--dl <= 0) break;\n\t\t\t\t\t}\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\tif (dl > 0)\n\t\t\t{\n#ifdef BN_COUNT\n\t\t\tfprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, copy)\\n", cl, dl);\n#endif\n\t\t\tfor(;;)\n\t\t\t\t{\n\t\t\t\tr[0] = a[0];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[1] = a[1];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[2] = a[2];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\tr[3] = a[3];\n\t\t\t\tif (--dl <= 0) break;\n\t\t\t\ta += 4;\n\t\t\t\tr += 4;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\treturn c;\n\t}', 'BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)\n {\n\tBN_ULONG t1,t2;\n\tint c=0;\n\tassert(n >= 0);\n\tif (n <= 0) return((BN_ULONG)0);\n#ifndef OPENSSL_SMALL_FOOTPRINT\n\twhile (n&~3)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[1]; t2=b[1];\n\t\tr[1]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[2]; t2=b[2];\n\t\tr[2]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\tt1=a[3]; t2=b[3];\n\t\tr[3]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta+=4; b+=4; r+=4; n-=4;\n\t\t}\n#endif\n\twhile (n)\n\t\t{\n\t\tt1=a[0]; t2=b[0];\n\t\tr[0]=(t1-t2-c)&BN_MASK2;\n\t\tif (t1 != t2) c=(t1 < t2);\n\t\ta++; b++; r++; n--;\n\t\t}\n\treturn(c);\n\t}'] |
35,072 | 0 | https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L904 | PUT_HEVC_QPEL_HV(2, 1) | ['QPEL(48)', 'PUT_HEVC_QPEL_HV(2, 1)'] |
35,073 | 0 | https://github.com/openssl/openssl/blob/54b5fd537f7a7ac1874359fd42a4721b6839f7a1/crypto/x509/x509_req.c/#L205 | STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
{
X509_ATTRIBUTE *attr;
ASN1_TYPE *ext = NULL;
int idx, *pnid;
const unsigned char *p;
if ((req == NULL) || (req->req_info == NULL) || !ext_nids)
return(NULL);
for (pnid = ext_nids; *pnid != NID_undef; pnid++)
{
idx = X509_REQ_get_attr_by_NID(req, *pnid, -1);
if (idx == -1)
continue;
attr = X509_REQ_get_attr(req, idx);
if(attr->single) ext = attr->value.single;
else if(sk_ASN1_TYPE_num(attr->value.set))
ext = sk_ASN1_TYPE_value(attr->value.set, 0);
break;
}
if(!ext || (ext->type != V_ASN1_SEQUENCE))
return NULL;
p = ext->value.sequence->data;
return (STACK_OF(X509_EXTENSION) *)
ASN1_item_d2i(NULL, &p, ext->value.sequence->length,
ASN1_ITEM_rptr(X509_EXTENSIONS));
} | ['STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)\n\t{\n\tX509_ATTRIBUTE *attr;\n\tASN1_TYPE *ext = NULL;\n\tint idx, *pnid;\n\tconst unsigned char *p;\n\tif ((req == NULL) || (req->req_info == NULL) || !ext_nids)\n\t\treturn(NULL);\n\tfor (pnid = ext_nids; *pnid != NID_undef; pnid++)\n\t\t{\n\t\tidx = X509_REQ_get_attr_by_NID(req, *pnid, -1);\n\t\tif (idx == -1)\n\t\t\tcontinue;\n\t\tattr = X509_REQ_get_attr(req, idx);\n\t\tif(attr->single) ext = attr->value.single;\n\t\telse if(sk_ASN1_TYPE_num(attr->value.set))\n\t\t\text = sk_ASN1_TYPE_value(attr->value.set, 0);\n\t\tbreak;\n\t\t}\n\tif(!ext || (ext->type != V_ASN1_SEQUENCE))\n\t\treturn NULL;\n\tp = ext->value.sequence->data;\n\treturn (STACK_OF(X509_EXTENSION) *)\n\t\tASN1_item_d2i(NULL, &p, ext->value.sequence->length,\n\t\t\t\tASN1_ITEM_rptr(X509_EXTENSIONS));\n}', 'int X509_REQ_get_attr_by_NID(const X509_REQ *req, int nid,\n\t\t\t int lastpos)\n{\n\treturn X509at_get_attr_by_NID(req->req_info->attributes, nid, lastpos);\n}', 'int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,\n\t\t\t int lastpos)\n{\n\tASN1_OBJECT *obj;\n\tobj=OBJ_nid2obj(nid);\n\tif (obj == NULL) return(-2);\n\treturn(X509at_get_attr_by_OBJ(x,obj,lastpos));\n}', '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}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_flags[es->top]=0;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}', 'X509_ATTRIBUTE *X509_REQ_get_attr(const X509_REQ *req, int loc)\n{\n\treturn X509at_get_attr(req->req_info->attributes, loc);\n}', 'X509_ATTRIBUTE *X509at_get_attr(const STACK_OF(X509_ATTRIBUTE) *x, int loc)\n{\n\tif (x == NULL || sk_X509_ATTRIBUTE_num(x) <= loc || loc < 0)\n\t\treturn NULL;\n\telse\n\t\treturn sk_X509_ATTRIBUTE_value(x,loc);\n}'] |
35,074 | 0 | https://github.com/openssl/openssl/blob/85bcf27cccd8f5f569886479ad96a0c33444404c/crypto/evp/e_aes.c/#L2563 | static int aes_ocb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
const unsigned char *in, size_t len)
{
unsigned char *buf;
int *buf_len;
int written_len = 0;
size_t trailing_len;
EVP_AES_OCB_CTX *octx = ctx->cipher_data;
if (!octx->iv_set)
return -1;
if (!octx->key_set)
return -1;
if (in)
{
if (out == NULL)
{
buf = octx->aad_buf;
buf_len = &(octx->aad_buf_len);
}
else
{
buf = octx->data_buf;
buf_len = &(octx->data_buf_len);
}
if(*buf_len)
{
unsigned int remaining;
remaining = 16 - (*buf_len);
if(remaining > len)
{
memcpy(buf+(*buf_len), in, len);
*(buf_len)+=len;
return 0;
}
memcpy(buf+(*buf_len), in, remaining);
len -= remaining;
in += remaining;
if (out == NULL)
{
if(!CRYPTO_ocb128_aad(&octx->ocb, buf, 16))
return -1;
}
else if (ctx->encrypt)
{
if(!CRYPTO_ocb128_encrypt(&octx->ocb, buf, out, 16))
return -1;
}
else
{
if(!CRYPTO_ocb128_decrypt(&octx->ocb, buf, out, 16))
return -1;
}
written_len = 16;
*buf_len = 0;
}
trailing_len = len % 16;
if(len != trailing_len)
{
if (out == NULL)
{
if(!CRYPTO_ocb128_aad(&octx->ocb, in, len-trailing_len))
return -1;
}
else if (ctx->encrypt)
{
if(!CRYPTO_ocb128_encrypt(&octx->ocb, in, out, len-trailing_len))
return -1;
}
else
{
if(!CRYPTO_ocb128_decrypt(&octx->ocb, in, out, len-trailing_len))
return -1;
}
written_len += len-trailing_len;
in += len-trailing_len;
}
if(trailing_len)
{
memcpy(buf, in, trailing_len);
*buf_len = trailing_len;
}
return written_len;
}
else
{
if(octx->data_buf_len)
{
if (ctx->encrypt)
{
if(!CRYPTO_ocb128_encrypt(&octx->ocb, octx->data_buf, out,
octx->data_buf_len))
return -1;
}
else
{
if(!CRYPTO_ocb128_decrypt(&octx->ocb, octx->data_buf, out,
octx->data_buf_len))
return -1;
}
written_len = octx->data_buf_len;
octx->data_buf_len = 0;
}
if(octx->aad_buf_len)
{
if(!CRYPTO_ocb128_aad(&octx->ocb, octx->aad_buf, octx->aad_buf_len))
return -1;
octx->aad_buf_len = 0;
}
if (!ctx->encrypt)
{
if (octx->taglen < 0)
return -1;
if (CRYPTO_ocb128_finish(&octx->ocb,
octx->tag, octx->taglen) != 0)
return -1;
octx->iv_set = 0;
return written_len;
}
if(CRYPTO_ocb128_tag(&octx->ocb, octx->tag, 16) != 1)
return -1;
octx->iv_set = 0;
return written_len;
}
} | ['static int aes_ocb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,\n\t\tconst unsigned char *in, size_t len)\n\t{\n\tunsigned char *buf;\n\tint *buf_len;\n\tint written_len = 0;\n\tsize_t trailing_len;\n\tEVP_AES_OCB_CTX *octx = ctx->cipher_data;\n\tif (!octx->iv_set)\n\t\treturn -1;\n\tif (!octx->key_set)\n\t\treturn -1;\n\tif (in)\n\t\t{\n\t\tif (out == NULL)\n\t\t\t{\n\t\t\tbuf = octx->aad_buf;\n\t\t\tbuf_len = &(octx->aad_buf_len);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tbuf = octx->data_buf;\n\t\t\tbuf_len = &(octx->data_buf_len);\n\t\t\t}\n\t\tif(*buf_len)\n\t\t\t{\n\t\t\tunsigned int remaining;\n\t\t\tremaining = 16 - (*buf_len);\n\t\t\tif(remaining > len)\n\t\t\t\t{\n\t\t\t\tmemcpy(buf+(*buf_len), in, len);\n\t\t\t\t*(buf_len)+=len;\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\tmemcpy(buf+(*buf_len), in, remaining);\n\t\t\tlen -= remaining;\n\t\t\tin += remaining;\n\t\t\tif (out == NULL)\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_aad(&octx->ocb, buf, 16))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\telse if (ctx->encrypt)\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_encrypt(&octx->ocb, buf, out, 16))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_decrypt(&octx->ocb, buf, out, 16))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\twritten_len = 16;\n\t\t\t*buf_len = 0;\n\t\t\t}\n\t\ttrailing_len = len % 16;\n\t\tif(len != trailing_len)\n\t\t\t{\n\t\t\tif (out == NULL)\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_aad(&octx->ocb, in, len-trailing_len))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\telse if (ctx->encrypt)\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_encrypt(&octx->ocb, in, out, len-trailing_len))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_decrypt(&octx->ocb, in, out, len-trailing_len))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\twritten_len += len-trailing_len;\n\t\t\tin += len-trailing_len;\n\t\t\t}\n\t\tif(trailing_len)\n\t\t\t{\n\t\t\tmemcpy(buf, in, trailing_len);\n\t\t\t*buf_len = trailing_len;\n\t\t\t}\n\t\treturn written_len;\n\t\t}\n\telse\n\t\t{\n\t\tif(octx->data_buf_len)\n\t\t\t{\n\t\t\tif (ctx->encrypt)\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_encrypt(&octx->ocb, octx->data_buf, out,\n\t\t\t\t\t\toctx->data_buf_len))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif(!CRYPTO_ocb128_decrypt(&octx->ocb, octx->data_buf, out,\n\t\t\t\t\t\toctx->data_buf_len))\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\twritten_len = octx->data_buf_len;\n\t\t\toctx->data_buf_len = 0;\n\t\t\t}\n\t\tif(octx->aad_buf_len)\n\t\t\t{\n\t\t\tif(!CRYPTO_ocb128_aad(&octx->ocb, octx->aad_buf, octx->aad_buf_len))\n\t\t\t\treturn -1;\n\t\t\toctx->aad_buf_len = 0;\n\t\t\t}\n\t\tif (!ctx->encrypt)\n\t\t\t{\n\t\t\tif (octx->taglen < 0)\n\t\t\t\treturn -1;\n\t\t\tif (CRYPTO_ocb128_finish(&octx->ocb,\n\t\t\t\t\toctx->tag, octx->taglen) != 0)\n\t\t\t\treturn -1;\n\t\t\toctx->iv_set = 0;\n\t\t\treturn written_len;\n\t\t\t}\n\t\tif(CRYPTO_ocb128_tag(&octx->ocb, octx->tag, 16) != 1)\n\t\t\treturn -1;\n\t\toctx->iv_set = 0;\n\t\treturn written_len;\n\t\t}\n\t}'] |
35,075 | 0 | https://github.com/openssl/openssl/blob/ff64702b3d83d4c77756e0fd7b624e2165dbbdf0/crypto/packet.c/#L52 | int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
if (!ossl_assert(pkt->subs != NULL && len != 0))
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {
size_t newlen;
size_t reflen;
reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
if (reflen > SIZE_MAX / 2) {
newlen = SIZE_MAX;
} else {
newlen = reflen * 2;
if (newlen < DEFAULT_BUF_SIZE)
newlen = DEFAULT_BUF_SIZE;
}
if (BUF_MEM_grow(pkt->buf, newlen) == 0)
return 0;
}
if (allocbytes != NULL)
*allocbytes = WPACKET_get_curr(pkt);
return 1;
} | ['EXT_RETURN tls_construct_ctos_psk(SSL *s, WPACKET *pkt, unsigned int context,\n X509 *x, size_t chainidx)\n{\n#ifndef OPENSSL_NO_TLS1_3\n uint32_t now, agesec, agems = 0;\n size_t reshashsize = 0, pskhashsize = 0, binderoffset, msglen;\n unsigned char *resbinder = NULL, *pskbinder = NULL, *msgstart = NULL;\n const EVP_MD *handmd = NULL, *mdres = NULL, *mdpsk = NULL;\n int dores = 0;\n s->ext.tick_identity = 0;\n if (s->session->ssl_version != TLS1_3_VERSION\n || (s->session->ext.ticklen == 0 && s->psksession == NULL))\n return EXT_RETURN_NOT_SENT;\n if (s->hello_retry_request == SSL_HRR_PENDING)\n handmd = ssl_handshake_md(s);\n if (s->session->ext.ticklen != 0) {\n if (s->session->cipher == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n mdres = ssl_md(s->session->cipher->algorithm2);\n if (mdres == NULL) {\n goto dopsksess;\n }\n if (s->hello_retry_request == SSL_HRR_PENDING && mdres != handmd) {\n goto dopsksess;\n }\n now = (uint32_t)time(NULL);\n agesec = now - (uint32_t)s->session->time;\n if (agesec > 0)\n agesec--;\n if (s->session->ext.tick_lifetime_hint < agesec) {\n goto dopsksess;\n }\n agems = agesec * (uint32_t)1000;\n if (agesec != 0 && agems / (uint32_t)1000 != agesec) {\n goto dopsksess;\n }\n agems += s->session->ext.tick_age_add;\n reshashsize = EVP_MD_size(mdres);\n s->ext.tick_identity++;\n dores = 1;\n }\n dopsksess:\n if (!dores && s->psksession == NULL)\n return EXT_RETURN_NOT_SENT;\n if (s->psksession != NULL) {\n mdpsk = ssl_md(s->psksession->cipher->algorithm2);\n if (mdpsk == NULL) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n SSL_R_BAD_PSK);\n return EXT_RETURN_FAIL;\n }\n if (s->hello_retry_request == SSL_HRR_PENDING && mdpsk != handmd) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n SSL_R_BAD_PSK);\n return EXT_RETURN_FAIL;\n }\n pskhashsize = EVP_MD_size(mdpsk);\n }\n if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_psk)\n || !WPACKET_start_sub_packet_u16(pkt)\n || !WPACKET_start_sub_packet_u16(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n if (dores) {\n if (!WPACKET_sub_memcpy_u16(pkt, s->session->ext.tick,\n s->session->ext.ticklen)\n || !WPACKET_put_bytes_u32(pkt, agems)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n }\n if (s->psksession != NULL) {\n if (!WPACKET_sub_memcpy_u16(pkt, s->psksession_id,\n s->psksession_id_len)\n || !WPACKET_put_bytes_u32(pkt, 0)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n s->ext.tick_identity++;\n }\n if (!WPACKET_close(pkt)\n || !WPACKET_get_total_written(pkt, &binderoffset)\n || !WPACKET_start_sub_packet_u16(pkt)\n || (dores\n && !WPACKET_sub_allocate_bytes_u8(pkt, reshashsize, &resbinder))\n || (s->psksession != NULL\n && !WPACKET_sub_allocate_bytes_u8(pkt, pskhashsize, &pskbinder))\n || !WPACKET_close(pkt)\n || !WPACKET_close(pkt)\n || !WPACKET_get_total_written(pkt, &msglen)\n || !WPACKET_fill_lengths(pkt)) {\n SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_CTOS_PSK,\n ERR_R_INTERNAL_ERROR);\n return EXT_RETURN_FAIL;\n }\n msgstart = WPACKET_get_curr(pkt) - msglen;\n if (dores\n && tls_psk_do_binder(s, mdres, msgstart, binderoffset, NULL,\n resbinder, s->session, 1, 0) != 1) {\n return EXT_RETURN_FAIL;\n }\n if (s->psksession != NULL\n && tls_psk_do_binder(s, mdpsk, msgstart, binderoffset, NULL,\n pskbinder, s->psksession, 1, 1) != 1) {\n return EXT_RETURN_FAIL;\n }\n return EXT_RETURN_SENT;\n#else\n return EXT_RETURN_NOT_SENT;\n#endif\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n WPACKET_SUB *sub;\n unsigned char *lenchars;\n if (!ossl_assert(pkt->subs != NULL))\n return 0;\n if ((sub = OPENSSL_zalloc(sizeof(*sub))) == NULL) {\n SSLerr(SSL_F_WPACKET_START_SUB_PACKET_LEN__, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n sub->packet_len = pkt->written;\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n return 1;\n}', 'int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,\n size_t lenbytes)\n{\n if (!WPACKET_start_sub_packet_len__(pkt, lenbytes)\n || !WPACKET_memcpy(pkt, src, len)\n || !WPACKET_close(pkt))\n return 0;\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->buf != NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}'] |
35,076 | 0 | https://github.com/apache/httpd/blob/671710004dbfb9793554faf4fa8247f021d66814/srclib/pcre/pcre.c/#L5345 | pcre *
pcre_compile(const char *pattern, int options, const char **errorptr,
int *erroroffset, const unsigned char *tables)
{
real_pcre *re;
int length = 1 + LINK_SIZE;
int c, firstbyte, reqbyte;
int bracount = 0;
int branch_extra = 0;
int branch_newextra;
int item_count = -1;
int name_count = 0;
int max_name_size = 0;
int lastitemlength = 0;
#ifdef SUPPORT_UTF8
BOOL utf8;
BOOL class_utf8;
#endif
BOOL inescq = FALSE;
unsigned int brastackptr = 0;
size_t size;
uschar *code;
const uschar *codestart;
const uschar *ptr;
compile_data compile_block;
int brastack[BRASTACK_SIZE];
uschar bralenstack[BRASTACK_SIZE];
if (errorptr == NULL) return NULL;
*errorptr = NULL;
if (erroroffset == NULL)
{
*errorptr = ERR16;
return NULL;
}
*erroroffset = 0;
#ifdef SUPPORT_UTF8
utf8 = (options & PCRE_UTF8) != 0;
if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
(*erroroffset = valid_utf8((uschar *)pattern, -1)) >= 0)
{
*errorptr = ERR44;
return NULL;
}
#else
if ((options & PCRE_UTF8) != 0)
{
*errorptr = ERR32;
return NULL;
}
#endif
if ((options & ~PUBLIC_OPTIONS) != 0)
{
*errorptr = ERR17;
return NULL;
}
if (tables == NULL) tables = pcre_default_tables;
compile_block.lcc = tables + lcc_offset;
compile_block.fcc = tables + fcc_offset;
compile_block.cbits = tables + cbits_offset;
compile_block.ctypes = tables + ctypes_offset;
compile_block.top_backref = 0;
compile_block.backref_map = 0;
DPRINTF(("------------------------------------------------------------------\n"));
DPRINTF(("%s\n", pattern));
ptr = (const uschar *)(pattern - 1);
while ((c = *(++ptr)) != 0)
{
int min, max;
int class_optcount;
int bracket_length;
int duplength;
if (inescq)
{
if ((options & PCRE_AUTO_CALLOUT) != 0) length += 2 + 2*LINK_SIZE;
goto NORMAL_CHAR;
}
if ((options & PCRE_EXTENDED) != 0)
{
if ((compile_block.ctypes[c] & ctype_space) != 0) continue;
if (c == '#')
{
while ((c = *(++ptr)) != 0 && c != NEWLINE) ;
if (c == 0) break;
continue;
}
}
item_count++;
if ((options & PCRE_AUTO_CALLOUT) != 0 &&
c != '*' && c != '+' && c != '?' &&
(c != '{' || !is_counted_repeat(ptr + 1)))
length += 2 + 2*LINK_SIZE;
switch(c)
{
case '\\':
c = check_escape(&ptr, errorptr, bracount, options, FALSE);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
lastitemlength = 1;
if (c >= 0)
{
length += 2;
#ifdef SUPPORT_UTF8
if (utf8 && c > 127)
{
int i;
for (i = 0; i < sizeof(utf8_table1)/sizeof(int); i++)
if (c <= utf8_table1[i]) break;
length += i;
lastitemlength += i;
}
#endif
continue;
}
if (-c == ESC_Q)
{
inescq = TRUE;
continue;
}
#ifndef SUPPORT_UCP
if (-c == ESC_X)
{
*errorptr = ERR45;
goto PCRE_ERROR_RETURN;
}
#endif
else if (-c == ESC_P || -c == ESC_p)
{
#ifdef SUPPORT_UCP
BOOL negated;
length += 2;
lastitemlength = 2;
if (get_ucp(&ptr, &negated, errorptr) < 0) goto PCRE_ERROR_RETURN;
continue;
#else
*errorptr = ERR45;
goto PCRE_ERROR_RETURN;
#endif
}
length++;
if (c <= -ESC_REF)
{
int refnum = -c - ESC_REF;
compile_block.backref_map |= (refnum < 32)? (1 << refnum) : 1;
if (refnum > compile_block.top_backref)
compile_block.top_backref = refnum;
length += 2;
if (ptr[1] == '{' && is_counted_repeat(ptr+2))
{
ptr = read_repeat_counts(ptr+2, &min, &max, errorptr);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
if ((min == 0 && (max == 1 || max == -1)) ||
(min == 1 && max == -1))
length++;
else length += 5;
if (ptr[1] == '?') ptr++;
}
}
continue;
case '^':
case '.':
case '$':
length++;
lastitemlength = 1;
continue;
case '*':
case '+':
case '?':
length++;
goto POSESSIVE;
case '{':
if (!is_counted_repeat(ptr+1)) goto NORMAL_CHAR;
ptr = read_repeat_counts(ptr+1, &min, &max, errorptr);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
if ((min == 0 && (max == 1 || max == -1)) ||
(min == 1 && max == -1))
length++;
else
{
if (min != 1)
{
length -= lastitemlength;
if (min > 0) length += 3 + lastitemlength;
}
length += lastitemlength + ((max > 0)? 3 : 1);
}
if (ptr[1] == '?') ptr++;
POSESSIVE:
if (ptr[1] == '+')
{
ptr++;
length += 2 + 2*LINK_SIZE;
}
continue;
case '|':
length += 1 + LINK_SIZE + branch_extra;
continue;
case '[':
if (*(++ptr) == '^')
{
class_optcount = 10;
ptr++;
}
else class_optcount = 0;
#ifdef SUPPORT_UTF8
class_utf8 = FALSE;
#endif
if (*ptr != 0) do
{
if (inescq)
{
if (*ptr != '\\' || ptr[1] != 'E') goto GET_ONE_CHARACTER;
inescq = FALSE;
ptr += 1;
continue;
}
if (*ptr == '\\')
{
c = check_escape(&ptr, errorptr, bracount, options, TRUE);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
if (-c == ESC_b) c = '\b';
else if (-c == ESC_X) c = 'X';
else if (-c == ESC_Q)
{
inescq = TRUE;
continue;
}
if (c >= 0) goto NON_SPECIAL_CHARACTER;
else
{
class_optcount = 10;
#ifdef SUPPORT_UTF8
if (-c == ESC_p || -c == ESC_P)
{
if (!class_utf8)
{
class_utf8 = TRUE;
length += LINK_SIZE + 2;
}
length += 2;
}
#endif
}
}
else if (*ptr == '[' && check_posix_syntax(ptr, &ptr, &compile_block))
{
ptr++;
class_optcount = 10;
}
else
{
int d;
GET_ONE_CHARACTER:
#ifdef SUPPORT_UTF8
if (utf8)
{
int extra = 0;
GETCHARLEN(c, ptr, extra);
ptr += extra;
}
else c = *ptr;
#else
c = *ptr;
#endif
NON_SPECIAL_CHARACTER:
class_optcount++;
d = -1;
if (ptr[1] == '-')
{
uschar const *hyptr = ptr++;
if (ptr[1] == '\\')
{
ptr++;
d = check_escape(&ptr, errorptr, bracount, options, TRUE);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
if (-d == ESC_b) d = '\b';
else if (-d == ESC_X) d = 'X';
}
else if (ptr[1] != 0 && ptr[1] != ']')
{
ptr++;
#ifdef SUPPORT_UTF8
if (utf8)
{
int extra = 0;
GETCHARLEN(d, ptr, extra);
ptr += extra;
}
else
#endif
d = *ptr;
}
if (d < 0) ptr = hyptr;
}
if (d >= 0)
{
class_optcount = 10;
if (d < c)
{
*errorptr = ERR8;
goto PCRE_ERROR_RETURN;
}
#ifdef SUPPORT_UTF8
if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))
{
uschar buffer[6];
if (!class_utf8)
{
class_utf8 = TRUE;
length += LINK_SIZE + 2;
}
#ifdef SUPPORT_UCP
if ((options & PCRE_CASELESS) != 0)
{
int occ, ocd;
int cc = c;
int origd = d;
while (get_othercase_range(&cc, origd, &occ, &ocd))
{
if (occ >= c && ocd <= d) continue;
if (occ < c && ocd >= c - 1)
{
c = occ;
continue;
}
if (ocd > d && occ <= d + 1)
{
d = ocd;
continue;
}
length += 1 + ord2utf8(occ, buffer) +
((occ == ocd)? 0 : ord2utf8(ocd, buffer));
}
}
#endif
length += 1 + ord2utf8(c, buffer) + ord2utf8(d, buffer);
}
#endif
}
else
{
#ifdef SUPPORT_UTF8
if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))
{
uschar buffer[6];
class_optcount = 10;
if (!class_utf8)
{
class_utf8 = TRUE;
length += LINK_SIZE + 2;
}
#ifdef SUPPORT_UCP
length += (((options & PCRE_CASELESS) != 0)? 2 : 1) *
(1 + ord2utf8(c, buffer));
#else
length += 1 + ord2utf8(c, buffer);
#endif
}
#endif
}
}
}
while (*(++ptr) != 0 && (inescq || *ptr != ']'));
if (*ptr == 0)
{
*errorptr = ERR6;
goto PCRE_ERROR_RETURN;
}
if (class_optcount == 1) length += 3; else
{
length += 33;
if (*ptr != 0 && ptr[1] == '{' && is_counted_repeat(ptr+2))
{
ptr = read_repeat_counts(ptr+2, &min, &max, errorptr);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
if ((min == 0 && (max == 1 || max == -1)) ||
(min == 1 && max == -1))
length++;
else length += 5;
if (ptr[1] == '+')
{
ptr++;
length += 2 + 2*LINK_SIZE;
}
else if (ptr[1] == '?') ptr++;
}
}
continue;
case '(':
branch_newextra = 0;
bracket_length = 1 + LINK_SIZE;
if (ptr[1] == '?')
{
int set, unset;
int *optset;
switch (c = ptr[2])
{
case '#':
ptr += 3;
while (*ptr != 0 && *ptr != ')') ptr++;
if (*ptr == 0)
{
*errorptr = ERR18;
goto PCRE_ERROR_RETURN;
}
continue;
case ':':
case '=':
case '!':
case '>':
ptr += 2;
break;
case 'R':
ptr++;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
ptr += 2;
if (c != 'R')
while ((digitab[*(++ptr)] & ctype_digit) != 0);
if (*ptr != ')')
{
*errorptr = ERR29;
goto PCRE_ERROR_RETURN;
}
length += 1 + LINK_SIZE;
if (ptr[1] == '+' || ptr[1] == '*' || ptr[1] == '?' || ptr[1] == '{')
{
length += 2 + 2 * LINK_SIZE;
duplength = 5 + 3 * LINK_SIZE;
goto HANDLE_QUANTIFIED_BRACKETS;
}
continue;
case 'C':
ptr += 2;
while ((digitab[*(++ptr)] & ctype_digit) != 0);
if (*ptr != ')')
{
*errorptr = ERR39;
goto PCRE_ERROR_RETURN;
}
length += 2 + 2*LINK_SIZE;
continue;
case 'P':
ptr += 3;
if (*ptr == '<')
{
const uschar *p;
p = ++ptr;
while ((compile_block.ctypes[*ptr] & ctype_word) != 0) ptr++;
if (*ptr != '>')
{
*errorptr = ERR42;
goto PCRE_ERROR_RETURN;
}
name_count++;
if (ptr - p > max_name_size) max_name_size = (ptr - p);
break;
}
if (*ptr == '=' || *ptr == '>')
{
while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0);
if (*ptr != ')')
{
*errorptr = ERR42;
goto PCRE_ERROR_RETURN;
}
break;
}
*errorptr = ERR41;
goto PCRE_ERROR_RETURN;
case '<':
ptr += 3;
if (*ptr == '=' || *ptr == '!')
{
branch_newextra = 1 + LINK_SIZE;
length += 1 + LINK_SIZE;
break;
}
*errorptr = ERR24;
goto PCRE_ERROR_RETURN;
case '(':
if (ptr[3] == 'R' && ptr[4] == ')')
{
ptr += 4;
length += 3;
}
else if ((digitab[ptr[3]] & ctype_digit) != 0)
{
ptr += 4;
length += 3;
while ((digitab[*ptr] & ctype_digit) != 0) ptr++;
if (*ptr != ')')
{
*errorptr = ERR26;
goto PCRE_ERROR_RETURN;
}
}
else
{
ptr++;
if (ptr[2] != '?' ||
(ptr[3] != '=' && ptr[3] != '!' && ptr[3] != '<') )
{
ptr += 2;
*errorptr = ERR28;
goto PCRE_ERROR_RETURN;
}
}
break;
default:
set = unset = 0;
optset = &set;
ptr += 2;
for (;; ptr++)
{
c = *ptr;
switch (c)
{
case 'i':
*optset |= PCRE_CASELESS;
continue;
case 'm':
*optset |= PCRE_MULTILINE;
continue;
case 's':
*optset |= PCRE_DOTALL;
continue;
case 'x':
*optset |= PCRE_EXTENDED;
continue;
case 'X':
*optset |= PCRE_EXTRA;
continue;
case 'U':
*optset |= PCRE_UNGREEDY;
continue;
case '-':
optset = &unset;
continue;
case ')':
if (item_count == 0)
{
options = (options | set) & (~unset);
set = unset = 0;
item_count--;
}
case ':':
if (((set|unset) & PCRE_IMS) != 0)
{
length += 4;
branch_newextra = 2;
if (((set|unset) & PCRE_CASELESS) != 0) options |= PCRE_ICHANGED;
}
goto END_OPTIONS;
default:
*errorptr = ERR12;
goto PCRE_ERROR_RETURN;
}
}
END_OPTIONS:
if (c == ')')
{
if (branch_newextra == 2 &&
(branch_extra == 0 || branch_extra == 1+LINK_SIZE))
branch_extra += branch_newextra;
continue;
}
}
}
else if ((options & PCRE_NO_AUTO_CAPTURE) == 0)
{
bracount++;
if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;
}
if (brastackptr >= sizeof(brastack)/sizeof(int))
{
*errorptr = ERR19;
goto PCRE_ERROR_RETURN;
}
bralenstack[brastackptr] = branch_extra;
branch_extra = branch_newextra;
brastack[brastackptr++] = length;
length += bracket_length;
continue;
case ')':
length += 1 + LINK_SIZE;
if (brastackptr > 0)
{
duplength = length - brastack[--brastackptr];
branch_extra = bralenstack[brastackptr];
}
else duplength = 0;
HANDLE_QUANTIFIED_BRACKETS:
if ((c = ptr[1]) == '{' && is_counted_repeat(ptr+2))
{
ptr = read_repeat_counts(ptr+2, &min, &max, errorptr);
if (*errorptr != NULL) goto PCRE_ERROR_RETURN;
}
else if (c == '*') { min = 0; max = -1; ptr++; }
else if (c == '+') { min = 1; max = -1; ptr++; }
else if (c == '?') { min = 0; max = 1; ptr++; }
else { min = 1; max = 1; }
if (min == 0)
{
length++;
if (max > 0) length += (max - 1) * (duplength + 3 + 2*LINK_SIZE);
}
else
{
length += (min - 1) * duplength;
if (max > min)
length += (max - min) * (duplength + 3 + 2*LINK_SIZE)
- (2 + 2*LINK_SIZE);
}
if (ptr[1] == '+')
{
ptr++;
length += 2 + 2*LINK_SIZE;
}
continue;
default:
NORMAL_CHAR:
if (inescq && c == '\\' && ptr[1] == 'E')
{
inescq = FALSE;
ptr++;
continue;
}
length += 2;
lastitemlength = 1;
#ifdef SUPPORT_UTF8
if (utf8 && (c & 0xc0) == 0xc0)
{
while ((ptr[1] & 0xc0) == 0x80)
{
lastitemlength++;
length++;
ptr++;
}
}
#endif
continue;
}
}
length += 2 + LINK_SIZE;
if ((options & PCRE_AUTO_CALLOUT) != 0)
length += 2 + 2*LINK_SIZE;
if (length > MAX_PATTERN_SIZE)
{
*errorptr = ERR20;
return NULL;
}
size = length + sizeof(real_pcre) + name_count * (max_name_size + 3);
re = (real_pcre *)(pcre_malloc)(size);
if (re == NULL)
{
*errorptr = ERR21;
return NULL;
}
re->magic_number = MAGIC_NUMBER;
re->size = size;
re->options = options;
re->dummy1 = re->dummy2 = 0;
re->name_table_offset = sizeof(real_pcre);
re->name_entry_size = max_name_size + 3;
re->name_count = name_count;
re->tables = (tables == pcre_default_tables)? NULL : tables;
re->nullpad = NULL;
compile_block.names_found = 0;
compile_block.name_entry_size = max_name_size + 3;
compile_block.name_table = (uschar *)re + re->name_table_offset;
codestart = compile_block.name_table + re->name_entry_size * re->name_count;
compile_block.start_code = codestart;
compile_block.start_pattern = (const uschar *)pattern;
compile_block.req_varyopt = 0;
compile_block.nopartial = FALSE;
ptr = (const uschar *)pattern;
code = (uschar *)codestart;
*code = OP_BRA;
bracount = 0;
(void)compile_regex(options, options & PCRE_IMS, &bracount, &code, &ptr,
errorptr, FALSE, 0, &firstbyte, &reqbyte, NULL, &compile_block);
re->top_bracket = bracount;
re->top_backref = compile_block.top_backref;
if (compile_block.nopartial) re->options |= PCRE_NOPARTIAL;
if (*errorptr == NULL && *ptr != 0) *errorptr = ERR22;
*code++ = OP_END;
#ifndef DEBUG
if (code - codestart > length) *errorptr = ERR23;
#endif
if (re->top_backref > re->top_bracket) *errorptr = ERR15;
if (*errorptr != NULL)
{
(pcre_free)(re);
PCRE_ERROR_RETURN:
*erroroffset = ptr - (const uschar *)pattern;
return NULL;
}
if ((options & PCRE_ANCHORED) == 0)
{
int temp_options = options;
if (is_anchored(codestart, &temp_options, 0, compile_block.backref_map))
re->options |= PCRE_ANCHORED;
else
{
if (firstbyte < 0)
firstbyte = find_firstassertedchar(codestart, &temp_options, FALSE);
if (firstbyte >= 0)
{
int ch = firstbyte & 255;
re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&
compile_block.fcc[ch] == ch)? ch : firstbyte;
re->options |= PCRE_FIRSTSET;
}
else if (is_startline(codestart, 0, compile_block.backref_map))
re->options |= PCRE_STARTLINE;
}
}
if (reqbyte >= 0 &&
((re->options & PCRE_ANCHORED) == 0 || (reqbyte & REQ_VARY) != 0))
{
int ch = reqbyte & 255;
re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&
compile_block.fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;
re->options |= PCRE_REQCHSET;
}
#ifdef DEBUG
printf("Length = %d top_bracket = %d top_backref = %d\n",
length, re->top_bracket, re->top_backref);
if (re->options != 0)
{
printf("%s%s%s%s%s%s%s%s%s%s\n",
((re->options & PCRE_NOPARTIAL) != 0)? "nopartial " : "",
((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",
((re->options & PCRE_CASELESS) != 0)? "caseless " : "",
((re->options & PCRE_ICHANGED) != 0)? "case state changed " : "",
((re->options & PCRE_EXTENDED) != 0)? "extended " : "",
((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",
((re->options & PCRE_DOTALL) != 0)? "dotall " : "",
((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",
((re->options & PCRE_EXTRA) != 0)? "extra " : "",
((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : "");
}
if ((re->options & PCRE_FIRSTSET) != 0)
{
int ch = re->first_byte & 255;
const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)? "" : " (caseless)";
if (isprint(ch)) printf("First char = %c%s\n", ch, caseless);
else printf("First char = \\x%02x%s\n", ch, caseless);
}
if ((re->options & PCRE_REQCHSET) != 0)
{
int ch = re->req_byte & 255;
const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)? "" : " (caseless)";
if (isprint(ch)) printf("Req char = %c%s\n", ch, caseless);
else printf("Req char = \\x%02x%s\n", ch, caseless);
}
print_internals(re, stdout);
if (code - codestart > length)
{
*errorptr = ERR23;
(pcre_free)(re);
*erroroffset = ptr - (uschar *)pattern;
return NULL;
}
#endif
return (pcre *)re;
} | ['pcre *\npcre_compile(const char *pattern, int options, const char **errorptr,\n int *erroroffset, const unsigned char *tables)\n{\nreal_pcre *re;\nint length = 1 + LINK_SIZE;\nint c, firstbyte, reqbyte;\nint bracount = 0;\nint branch_extra = 0;\nint branch_newextra;\nint item_count = -1;\nint name_count = 0;\nint max_name_size = 0;\nint lastitemlength = 0;\n#ifdef SUPPORT_UTF8\nBOOL utf8;\nBOOL class_utf8;\n#endif\nBOOL inescq = FALSE;\nunsigned int brastackptr = 0;\nsize_t size;\nuschar *code;\nconst uschar *codestart;\nconst uschar *ptr;\ncompile_data compile_block;\nint brastack[BRASTACK_SIZE];\nuschar bralenstack[BRASTACK_SIZE];\nif (errorptr == NULL) return NULL;\n*errorptr = NULL;\nif (erroroffset == NULL)\n {\n *errorptr = ERR16;\n return NULL;\n }\n*erroroffset = 0;\n#ifdef SUPPORT_UTF8\nutf8 = (options & PCRE_UTF8) != 0;\nif (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&\n (*erroroffset = valid_utf8((uschar *)pattern, -1)) >= 0)\n {\n *errorptr = ERR44;\n return NULL;\n }\n#else\nif ((options & PCRE_UTF8) != 0)\n {\n *errorptr = ERR32;\n return NULL;\n }\n#endif\nif ((options & ~PUBLIC_OPTIONS) != 0)\n {\n *errorptr = ERR17;\n return NULL;\n }\nif (tables == NULL) tables = pcre_default_tables;\ncompile_block.lcc = tables + lcc_offset;\ncompile_block.fcc = tables + fcc_offset;\ncompile_block.cbits = tables + cbits_offset;\ncompile_block.ctypes = tables + ctypes_offset;\ncompile_block.top_backref = 0;\ncompile_block.backref_map = 0;\nDPRINTF(("------------------------------------------------------------------\\n"));\nDPRINTF(("%s\\n", pattern));\nptr = (const uschar *)(pattern - 1);\nwhile ((c = *(++ptr)) != 0)\n {\n int min, max;\n int class_optcount;\n int bracket_length;\n int duplength;\n if (inescq)\n {\n if ((options & PCRE_AUTO_CALLOUT) != 0) length += 2 + 2*LINK_SIZE;\n goto NORMAL_CHAR;\n }\n if ((options & PCRE_EXTENDED) != 0)\n {\n if ((compile_block.ctypes[c] & ctype_space) != 0) continue;\n if (c == \'#\')\n {\n while ((c = *(++ptr)) != 0 && c != NEWLINE) ;\n if (c == 0) break;\n continue;\n }\n }\n item_count++;\n if ((options & PCRE_AUTO_CALLOUT) != 0 &&\n c != \'*\' && c != \'+\' && c != \'?\' &&\n (c != \'{\' || !is_counted_repeat(ptr + 1)))\n length += 2 + 2*LINK_SIZE;\n switch(c)\n {\n case \'\\\\\':\n c = check_escape(&ptr, errorptr, bracount, options, FALSE);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n lastitemlength = 1;\n if (c >= 0)\n {\n length += 2;\n#ifdef SUPPORT_UTF8\n if (utf8 && c > 127)\n {\n int i;\n for (i = 0; i < sizeof(utf8_table1)/sizeof(int); i++)\n if (c <= utf8_table1[i]) break;\n length += i;\n lastitemlength += i;\n }\n#endif\n continue;\n }\n if (-c == ESC_Q)\n {\n inescq = TRUE;\n continue;\n }\n#ifndef SUPPORT_UCP\n if (-c == ESC_X)\n {\n *errorptr = ERR45;\n goto PCRE_ERROR_RETURN;\n }\n#endif\n else if (-c == ESC_P || -c == ESC_p)\n {\n#ifdef SUPPORT_UCP\n BOOL negated;\n length += 2;\n lastitemlength = 2;\n if (get_ucp(&ptr, &negated, errorptr) < 0) goto PCRE_ERROR_RETURN;\n continue;\n#else\n *errorptr = ERR45;\n goto PCRE_ERROR_RETURN;\n#endif\n }\n length++;\n if (c <= -ESC_REF)\n {\n int refnum = -c - ESC_REF;\n compile_block.backref_map |= (refnum < 32)? (1 << refnum) : 1;\n if (refnum > compile_block.top_backref)\n compile_block.top_backref = refnum;\n length += 2;\n if (ptr[1] == \'{\' && is_counted_repeat(ptr+2))\n {\n ptr = read_repeat_counts(ptr+2, &min, &max, errorptr);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if ((min == 0 && (max == 1 || max == -1)) ||\n (min == 1 && max == -1))\n length++;\n else length += 5;\n if (ptr[1] == \'?\') ptr++;\n }\n }\n continue;\n case \'^\':\n case \'.\':\n case \'$\':\n length++;\n lastitemlength = 1;\n continue;\n case \'*\':\n case \'+\':\n case \'?\':\n length++;\n goto POSESSIVE;\n case \'{\':\n if (!is_counted_repeat(ptr+1)) goto NORMAL_CHAR;\n ptr = read_repeat_counts(ptr+1, &min, &max, errorptr);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if ((min == 0 && (max == 1 || max == -1)) ||\n (min == 1 && max == -1))\n length++;\n else\n {\n if (min != 1)\n {\n length -= lastitemlength;\n if (min > 0) length += 3 + lastitemlength;\n }\n length += lastitemlength + ((max > 0)? 3 : 1);\n }\n if (ptr[1] == \'?\') ptr++;\n POSESSIVE:\n if (ptr[1] == \'+\')\n {\n ptr++;\n length += 2 + 2*LINK_SIZE;\n }\n continue;\n case \'|\':\n length += 1 + LINK_SIZE + branch_extra;\n continue;\n case \'[\':\n if (*(++ptr) == \'^\')\n {\n class_optcount = 10;\n ptr++;\n }\n else class_optcount = 0;\n#ifdef SUPPORT_UTF8\n class_utf8 = FALSE;\n#endif\n if (*ptr != 0) do\n {\n if (inescq)\n {\n if (*ptr != \'\\\\\' || ptr[1] != \'E\') goto GET_ONE_CHARACTER;\n inescq = FALSE;\n ptr += 1;\n continue;\n }\n if (*ptr == \'\\\\\')\n {\n c = check_escape(&ptr, errorptr, bracount, options, TRUE);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if (-c == ESC_b) c = \'\\b\';\n else if (-c == ESC_X) c = \'X\';\n else if (-c == ESC_Q)\n {\n inescq = TRUE;\n continue;\n }\n if (c >= 0) goto NON_SPECIAL_CHARACTER;\n else\n {\n class_optcount = 10;\n#ifdef SUPPORT_UTF8\n if (-c == ESC_p || -c == ESC_P)\n {\n if (!class_utf8)\n {\n class_utf8 = TRUE;\n length += LINK_SIZE + 2;\n }\n length += 2;\n }\n#endif\n }\n }\n else if (*ptr == \'[\' && check_posix_syntax(ptr, &ptr, &compile_block))\n {\n ptr++;\n class_optcount = 10;\n }\n else\n {\n int d;\n GET_ONE_CHARACTER:\n#ifdef SUPPORT_UTF8\n if (utf8)\n {\n int extra = 0;\n GETCHARLEN(c, ptr, extra);\n ptr += extra;\n }\n else c = *ptr;\n#else\n c = *ptr;\n#endif\n NON_SPECIAL_CHARACTER:\n class_optcount++;\n d = -1;\n if (ptr[1] == \'-\')\n {\n uschar const *hyptr = ptr++;\n if (ptr[1] == \'\\\\\')\n {\n ptr++;\n d = check_escape(&ptr, errorptr, bracount, options, TRUE);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if (-d == ESC_b) d = \'\\b\';\n else if (-d == ESC_X) d = \'X\';\n }\n else if (ptr[1] != 0 && ptr[1] != \']\')\n {\n ptr++;\n#ifdef SUPPORT_UTF8\n if (utf8)\n {\n int extra = 0;\n GETCHARLEN(d, ptr, extra);\n ptr += extra;\n }\n else\n#endif\n d = *ptr;\n }\n if (d < 0) ptr = hyptr;\n }\n if (d >= 0)\n {\n class_optcount = 10;\n if (d < c)\n {\n *errorptr = ERR8;\n goto PCRE_ERROR_RETURN;\n }\n#ifdef SUPPORT_UTF8\n if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))\n {\n uschar buffer[6];\n if (!class_utf8)\n {\n class_utf8 = TRUE;\n length += LINK_SIZE + 2;\n }\n#ifdef SUPPORT_UCP\n if ((options & PCRE_CASELESS) != 0)\n {\n int occ, ocd;\n int cc = c;\n int origd = d;\n while (get_othercase_range(&cc, origd, &occ, &ocd))\n {\n if (occ >= c && ocd <= d) continue;\n if (occ < c && ocd >= c - 1)\n {\n c = occ;\n continue;\n }\n if (ocd > d && occ <= d + 1)\n {\n d = ocd;\n continue;\n }\n length += 1 + ord2utf8(occ, buffer) +\n ((occ == ocd)? 0 : ord2utf8(ocd, buffer));\n }\n }\n#endif\n length += 1 + ord2utf8(c, buffer) + ord2utf8(d, buffer);\n }\n#endif\n }\n else\n {\n#ifdef SUPPORT_UTF8\n if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))\n {\n uschar buffer[6];\n class_optcount = 10;\n if (!class_utf8)\n {\n class_utf8 = TRUE;\n length += LINK_SIZE + 2;\n }\n#ifdef SUPPORT_UCP\n length += (((options & PCRE_CASELESS) != 0)? 2 : 1) *\n (1 + ord2utf8(c, buffer));\n#else\n length += 1 + ord2utf8(c, buffer);\n#endif\n }\n#endif\n }\n }\n }\n while (*(++ptr) != 0 && (inescq || *ptr != \']\'));\n if (*ptr == 0)\n {\n *errorptr = ERR6;\n goto PCRE_ERROR_RETURN;\n }\n if (class_optcount == 1) length += 3; else\n {\n length += 33;\n if (*ptr != 0 && ptr[1] == \'{\' && is_counted_repeat(ptr+2))\n {\n ptr = read_repeat_counts(ptr+2, &min, &max, errorptr);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n if ((min == 0 && (max == 1 || max == -1)) ||\n (min == 1 && max == -1))\n length++;\n else length += 5;\n if (ptr[1] == \'+\')\n {\n ptr++;\n length += 2 + 2*LINK_SIZE;\n }\n else if (ptr[1] == \'?\') ptr++;\n }\n }\n continue;\n case \'(\':\n branch_newextra = 0;\n bracket_length = 1 + LINK_SIZE;\n if (ptr[1] == \'?\')\n {\n int set, unset;\n int *optset;\n switch (c = ptr[2])\n {\n case \'#\':\n ptr += 3;\n while (*ptr != 0 && *ptr != \')\') ptr++;\n if (*ptr == 0)\n {\n *errorptr = ERR18;\n goto PCRE_ERROR_RETURN;\n }\n continue;\n case \':\':\n case \'=\':\n case \'!\':\n case \'>\':\n ptr += 2;\n break;\n case \'R\':\n ptr++;\n case \'0\': case \'1\': case \'2\': case \'3\': case \'4\':\n case \'5\': case \'6\': case \'7\': case \'8\': case \'9\':\n ptr += 2;\n if (c != \'R\')\n while ((digitab[*(++ptr)] & ctype_digit) != 0);\n if (*ptr != \')\')\n {\n *errorptr = ERR29;\n goto PCRE_ERROR_RETURN;\n }\n length += 1 + LINK_SIZE;\n if (ptr[1] == \'+\' || ptr[1] == \'*\' || ptr[1] == \'?\' || ptr[1] == \'{\')\n {\n length += 2 + 2 * LINK_SIZE;\n duplength = 5 + 3 * LINK_SIZE;\n goto HANDLE_QUANTIFIED_BRACKETS;\n }\n continue;\n case \'C\':\n ptr += 2;\n while ((digitab[*(++ptr)] & ctype_digit) != 0);\n if (*ptr != \')\')\n {\n *errorptr = ERR39;\n goto PCRE_ERROR_RETURN;\n }\n length += 2 + 2*LINK_SIZE;\n continue;\n case \'P\':\n ptr += 3;\n if (*ptr == \'<\')\n {\n const uschar *p;\n p = ++ptr;\n while ((compile_block.ctypes[*ptr] & ctype_word) != 0) ptr++;\n if (*ptr != \'>\')\n {\n *errorptr = ERR42;\n goto PCRE_ERROR_RETURN;\n }\n name_count++;\n if (ptr - p > max_name_size) max_name_size = (ptr - p);\n break;\n }\n if (*ptr == \'=\' || *ptr == \'>\')\n {\n while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0);\n if (*ptr != \')\')\n {\n *errorptr = ERR42;\n goto PCRE_ERROR_RETURN;\n }\n break;\n }\n *errorptr = ERR41;\n goto PCRE_ERROR_RETURN;\n case \'<\':\n ptr += 3;\n if (*ptr == \'=\' || *ptr == \'!\')\n {\n branch_newextra = 1 + LINK_SIZE;\n length += 1 + LINK_SIZE;\n break;\n }\n *errorptr = ERR24;\n goto PCRE_ERROR_RETURN;\n case \'(\':\n if (ptr[3] == \'R\' && ptr[4] == \')\')\n {\n ptr += 4;\n length += 3;\n }\n else if ((digitab[ptr[3]] & ctype_digit) != 0)\n {\n ptr += 4;\n length += 3;\n while ((digitab[*ptr] & ctype_digit) != 0) ptr++;\n if (*ptr != \')\')\n {\n *errorptr = ERR26;\n goto PCRE_ERROR_RETURN;\n }\n }\n else\n {\n ptr++;\n if (ptr[2] != \'?\' ||\n (ptr[3] != \'=\' && ptr[3] != \'!\' && ptr[3] != \'<\') )\n {\n ptr += 2;\n *errorptr = ERR28;\n goto PCRE_ERROR_RETURN;\n }\n }\n break;\n default:\n set = unset = 0;\n optset = &set;\n ptr += 2;\n for (;; ptr++)\n {\n c = *ptr;\n switch (c)\n {\n case \'i\':\n *optset |= PCRE_CASELESS;\n continue;\n case \'m\':\n *optset |= PCRE_MULTILINE;\n continue;\n case \'s\':\n *optset |= PCRE_DOTALL;\n continue;\n case \'x\':\n *optset |= PCRE_EXTENDED;\n continue;\n case \'X\':\n *optset |= PCRE_EXTRA;\n continue;\n case \'U\':\n *optset |= PCRE_UNGREEDY;\n continue;\n case \'-\':\n optset = &unset;\n continue;\n case \')\':\n if (item_count == 0)\n {\n options = (options | set) & (~unset);\n set = unset = 0;\n item_count--;\n }\n case \':\':\n if (((set|unset) & PCRE_IMS) != 0)\n {\n length += 4;\n branch_newextra = 2;\n if (((set|unset) & PCRE_CASELESS) != 0) options |= PCRE_ICHANGED;\n }\n goto END_OPTIONS;\n default:\n *errorptr = ERR12;\n goto PCRE_ERROR_RETURN;\n }\n }\n END_OPTIONS:\n if (c == \')\')\n {\n if (branch_newextra == 2 &&\n (branch_extra == 0 || branch_extra == 1+LINK_SIZE))\n branch_extra += branch_newextra;\n continue;\n }\n }\n }\n else if ((options & PCRE_NO_AUTO_CAPTURE) == 0)\n {\n bracount++;\n if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;\n }\n if (brastackptr >= sizeof(brastack)/sizeof(int))\n {\n *errorptr = ERR19;\n goto PCRE_ERROR_RETURN;\n }\n bralenstack[brastackptr] = branch_extra;\n branch_extra = branch_newextra;\n brastack[brastackptr++] = length;\n length += bracket_length;\n continue;\n case \')\':\n length += 1 + LINK_SIZE;\n if (brastackptr > 0)\n {\n duplength = length - brastack[--brastackptr];\n branch_extra = bralenstack[brastackptr];\n }\n else duplength = 0;\n HANDLE_QUANTIFIED_BRACKETS:\n if ((c = ptr[1]) == \'{\' && is_counted_repeat(ptr+2))\n {\n ptr = read_repeat_counts(ptr+2, &min, &max, errorptr);\n if (*errorptr != NULL) goto PCRE_ERROR_RETURN;\n }\n else if (c == \'*\') { min = 0; max = -1; ptr++; }\n else if (c == \'+\') { min = 1; max = -1; ptr++; }\n else if (c == \'?\') { min = 0; max = 1; ptr++; }\n else { min = 1; max = 1; }\n if (min == 0)\n {\n length++;\n if (max > 0) length += (max - 1) * (duplength + 3 + 2*LINK_SIZE);\n }\n else\n {\n length += (min - 1) * duplength;\n if (max > min)\n length += (max - min) * (duplength + 3 + 2*LINK_SIZE)\n - (2 + 2*LINK_SIZE);\n }\n if (ptr[1] == \'+\')\n {\n ptr++;\n length += 2 + 2*LINK_SIZE;\n }\n continue;\n default:\n NORMAL_CHAR:\n if (inescq && c == \'\\\\\' && ptr[1] == \'E\')\n {\n inescq = FALSE;\n ptr++;\n continue;\n }\n length += 2;\n lastitemlength = 1;\n#ifdef SUPPORT_UTF8\n if (utf8 && (c & 0xc0) == 0xc0)\n {\n while ((ptr[1] & 0xc0) == 0x80)\n {\n lastitemlength++;\n length++;\n ptr++;\n }\n }\n#endif\n continue;\n }\n }\nlength += 2 + LINK_SIZE;\nif ((options & PCRE_AUTO_CALLOUT) != 0)\n length += 2 + 2*LINK_SIZE;\nif (length > MAX_PATTERN_SIZE)\n {\n *errorptr = ERR20;\n return NULL;\n }\nsize = length + sizeof(real_pcre) + name_count * (max_name_size + 3);\nre = (real_pcre *)(pcre_malloc)(size);\nif (re == NULL)\n {\n *errorptr = ERR21;\n return NULL;\n }\nre->magic_number = MAGIC_NUMBER;\nre->size = size;\nre->options = options;\nre->dummy1 = re->dummy2 = 0;\nre->name_table_offset = sizeof(real_pcre);\nre->name_entry_size = max_name_size + 3;\nre->name_count = name_count;\nre->tables = (tables == pcre_default_tables)? NULL : tables;\nre->nullpad = NULL;\ncompile_block.names_found = 0;\ncompile_block.name_entry_size = max_name_size + 3;\ncompile_block.name_table = (uschar *)re + re->name_table_offset;\ncodestart = compile_block.name_table + re->name_entry_size * re->name_count;\ncompile_block.start_code = codestart;\ncompile_block.start_pattern = (const uschar *)pattern;\ncompile_block.req_varyopt = 0;\ncompile_block.nopartial = FALSE;\nptr = (const uschar *)pattern;\ncode = (uschar *)codestart;\n*code = OP_BRA;\nbracount = 0;\n(void)compile_regex(options, options & PCRE_IMS, &bracount, &code, &ptr,\n errorptr, FALSE, 0, &firstbyte, &reqbyte, NULL, &compile_block);\nre->top_bracket = bracount;\nre->top_backref = compile_block.top_backref;\nif (compile_block.nopartial) re->options |= PCRE_NOPARTIAL;\nif (*errorptr == NULL && *ptr != 0) *errorptr = ERR22;\n*code++ = OP_END;\n#ifndef DEBUG\nif (code - codestart > length) *errorptr = ERR23;\n#endif\nif (re->top_backref > re->top_bracket) *errorptr = ERR15;\nif (*errorptr != NULL)\n {\n (pcre_free)(re);\n PCRE_ERROR_RETURN:\n *erroroffset = ptr - (const uschar *)pattern;\n return NULL;\n }\nif ((options & PCRE_ANCHORED) == 0)\n {\n int temp_options = options;\n if (is_anchored(codestart, &temp_options, 0, compile_block.backref_map))\n re->options |= PCRE_ANCHORED;\n else\n {\n if (firstbyte < 0)\n firstbyte = find_firstassertedchar(codestart, &temp_options, FALSE);\n if (firstbyte >= 0)\n {\n int ch = firstbyte & 255;\n re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&\n compile_block.fcc[ch] == ch)? ch : firstbyte;\n re->options |= PCRE_FIRSTSET;\n }\n else if (is_startline(codestart, 0, compile_block.backref_map))\n re->options |= PCRE_STARTLINE;\n }\n }\nif (reqbyte >= 0 &&\n ((re->options & PCRE_ANCHORED) == 0 || (reqbyte & REQ_VARY) != 0))\n {\n int ch = reqbyte & 255;\n re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&\n compile_block.fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;\n re->options |= PCRE_REQCHSET;\n }\n#ifdef DEBUG\nprintf("Length = %d top_bracket = %d top_backref = %d\\n",\n length, re->top_bracket, re->top_backref);\nif (re->options != 0)\n {\n printf("%s%s%s%s%s%s%s%s%s%s\\n",\n ((re->options & PCRE_NOPARTIAL) != 0)? "nopartial " : "",\n ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",\n ((re->options & PCRE_CASELESS) != 0)? "caseless " : "",\n ((re->options & PCRE_ICHANGED) != 0)? "case state changed " : "",\n ((re->options & PCRE_EXTENDED) != 0)? "extended " : "",\n ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",\n ((re->options & PCRE_DOTALL) != 0)? "dotall " : "",\n ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",\n ((re->options & PCRE_EXTRA) != 0)? "extra " : "",\n ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : "");\n }\nif ((re->options & PCRE_FIRSTSET) != 0)\n {\n int ch = re->first_byte & 255;\n const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)? "" : " (caseless)";\n if (isprint(ch)) printf("First char = %c%s\\n", ch, caseless);\n else printf("First char = \\\\x%02x%s\\n", ch, caseless);\n }\nif ((re->options & PCRE_REQCHSET) != 0)\n {\n int ch = re->req_byte & 255;\n const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)? "" : " (caseless)";\n if (isprint(ch)) printf("Req char = %c%s\\n", ch, caseless);\n else printf("Req char = \\\\x%02x%s\\n", ch, caseless);\n }\nprint_internals(re, stdout);\nif (code - codestart > length)\n {\n *errorptr = ERR23;\n (pcre_free)(re);\n *erroroffset = ptr - (uschar *)pattern;\n return NULL;\n }\n#endif\nreturn (pcre *)re;\n}'] |
35,077 | 0 | https://github.com/openssl/openssl/blob/a00ae6c46e0d7907a7c9f9e85334e968aa5fd338/apps/speed.c/#L1922 | int MAIN(int argc, char **argv)
{
unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;
unsigned char *buf = NULL, *buf2 = NULL;
int mret = 1;
long count = 0, save_count = 0;
int i, j, k;
#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)
long rsa_count;
#endif
#ifndef OPENSSL_NO_RSA
unsigned rsa_num;
#endif
unsigned char md[EVP_MAX_MD_SIZE];
#ifndef OPENSSL_NO_MD2
unsigned char md2[MD2_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_MDC2
unsigned char mdc2[MDC2_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_MD4
unsigned char md4[MD4_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_MD5
unsigned char md5[MD5_DIGEST_LENGTH];
unsigned char hmac[MD5_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_SHA
unsigned char sha[SHA_DIGEST_LENGTH];
# ifndef OPENSSL_NO_SHA256
unsigned char sha256[SHA256_DIGEST_LENGTH];
# endif
# ifndef OPENSSL_NO_SHA512
unsigned char sha512[SHA512_DIGEST_LENGTH];
# endif
#endif
#ifndef OPENSSL_NO_WHIRLPOOL
unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_RMD160
unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_RC4
RC4_KEY rc4_ks;
#endif
#ifndef OPENSSL_NO_RC5
RC5_32_KEY rc5_ks;
#endif
#ifndef OPENSSL_NO_RC2
RC2_KEY rc2_ks;
#endif
#ifndef OPENSSL_NO_IDEA
IDEA_KEY_SCHEDULE idea_ks;
#endif
#ifndef OPENSSL_NO_SEED
SEED_KEY_SCHEDULE seed_ks;
#endif
#ifndef OPENSSL_NO_BF
BF_KEY bf_ks;
#endif
#ifndef OPENSSL_NO_CAST
CAST_KEY cast_ks;
#endif
static const unsigned char key16[16] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
};
#ifndef OPENSSL_NO_AES
static const unsigned char key24[24] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
};
static const unsigned char key32[32] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
};
#endif
#ifndef OPENSSL_NO_CAMELLIA
static const unsigned char ckey24[24] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34
};
static const unsigned char ckey32[32] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,
0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,
0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56
};
#endif
#ifndef OPENSSL_NO_AES
# define MAX_BLOCK_SIZE 128
#else
# define MAX_BLOCK_SIZE 64
#endif
unsigned char DES_iv[8];
unsigned char iv[2 * MAX_BLOCK_SIZE / 8];
#ifndef OPENSSL_NO_DES
static DES_cblock key =
{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };
static DES_cblock key2 =
{ 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };
static DES_cblock key3 =
{ 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };
DES_key_schedule sch;
DES_key_schedule sch2;
DES_key_schedule sch3;
#endif
#ifndef OPENSSL_NO_AES
AES_KEY aes_ks1, aes_ks2, aes_ks3;
#endif
#ifndef OPENSSL_NO_CAMELLIA
CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;
#endif
#define D_MD2 0
#define D_MDC2 1
#define D_MD4 2
#define D_MD5 3
#define D_HMAC 4
#define D_SHA1 5
#define D_RMD160 6
#define D_RC4 7
#define D_CBC_DES 8
#define D_EDE3_DES 9
#define D_CBC_IDEA 10
#define D_CBC_SEED 11
#define D_CBC_RC2 12
#define D_CBC_RC5 13
#define D_CBC_BF 14
#define D_CBC_CAST 15
#define D_CBC_128_AES 16
#define D_CBC_192_AES 17
#define D_CBC_256_AES 18
#define D_CBC_128_CML 19
#define D_CBC_192_CML 20
#define D_CBC_256_CML 21
#define D_EVP 22
#define D_SHA256 23
#define D_SHA512 24
#define D_WHIRLPOOL 25
#define D_IGE_128_AES 26
#define D_IGE_192_AES 27
#define D_IGE_256_AES 28
#define D_GHASH 29
double d = 0.0;
long c[ALGOR_NUM][SIZE_NUM];
#ifndef OPENSSL_SYS_WIN32
#endif
#define R_DSA_512 0
#define R_DSA_1024 1
#define R_DSA_2048 2
#define R_RSA_512 0
#define R_RSA_1024 1
#define R_RSA_2048 2
#define R_RSA_3072 3
#define R_RSA_4096 4
#define R_RSA_7680 5
#define R_RSA_15360 6
#define R_EC_P160 0
#define R_EC_P192 1
#define R_EC_P224 2
#define R_EC_P256 3
#define R_EC_P384 4
#define R_EC_P521 5
#define R_EC_K163 6
#define R_EC_K233 7
#define R_EC_K283 8
#define R_EC_K409 9
#define R_EC_K571 10
#define R_EC_B163 11
#define R_EC_B233 12
#define R_EC_B283 13
#define R_EC_B409 14
#define R_EC_B571 15
#ifndef OPENSSL_NO_RSA
RSA *rsa_key[RSA_NUM];
long rsa_c[RSA_NUM][2];
static unsigned int rsa_bits[RSA_NUM] = {
512, 1024, 2048, 3072, 4096, 7680, 15360
};
static unsigned char *rsa_data[RSA_NUM] = {
test512, test1024, test2048, test3072, test4096, test7680, test15360
};
static int rsa_data_length[RSA_NUM] = {
sizeof(test512), sizeof(test1024),
sizeof(test2048), sizeof(test3072),
sizeof(test4096), sizeof(test7680),
sizeof(test15360)
};
#endif
#ifndef OPENSSL_NO_DSA
DSA *dsa_key[DSA_NUM];
long dsa_c[DSA_NUM][2];
static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };
#endif
#ifndef OPENSSL_NO_EC
static unsigned int test_curves[EC_NUM] = {
NID_secp160r1,
NID_X9_62_prime192v1,
NID_secp224r1,
NID_X9_62_prime256v1,
NID_secp384r1,
NID_secp521r1,
NID_sect163k1,
NID_sect233k1,
NID_sect283k1,
NID_sect409k1,
NID_sect571k1,
NID_sect163r2,
NID_sect233r1,
NID_sect283r1,
NID_sect409r1,
NID_sect571r1
};
static const char *test_curves_names[EC_NUM] = {
"secp160r1",
"nistp192",
"nistp224",
"nistp256",
"nistp384",
"nistp521",
"nistk163",
"nistk233",
"nistk283",
"nistk409",
"nistk571",
"nistb163",
"nistb233",
"nistb283",
"nistb409",
"nistb571"
};
static int test_curves_bits[EC_NUM] = {
160, 192, 224, 256, 384, 521,
163, 233, 283, 409, 571,
163, 233, 283, 409, 571
};
#endif
#ifndef OPENSSL_NO_ECDSA
unsigned char ecdsasig[256];
unsigned int ecdsasiglen;
EC_KEY *ecdsa[EC_NUM];
long ecdsa_c[EC_NUM][2];
#endif
#ifndef OPENSSL_NO_ECDH
EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];
unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];
int secret_size_a, secret_size_b;
int ecdh_checks = 0;
int secret_idx = 0;
long ecdh_c[EC_NUM][2];
#endif
int rsa_doit[RSA_NUM];
int dsa_doit[DSA_NUM];
#ifndef OPENSSL_NO_ECDSA
int ecdsa_doit[EC_NUM];
#endif
#ifndef OPENSSL_NO_ECDH
int ecdh_doit[EC_NUM];
#endif
int doit[ALGOR_NUM];
int pr_header = 0;
const EVP_CIPHER *evp_cipher = NULL;
const EVP_MD *evp_md = NULL;
int decrypt = 0;
#ifndef NO_FORK
int multi = 0;
#endif
int multiblock = 0;
int misalign = MAX_MISALIGNMENT + 1;
#ifndef TIMES
usertime = -1;
#endif
apps_startup();
memset(results, 0, sizeof(results));
#ifndef OPENSSL_NO_DSA
memset(dsa_key, 0, sizeof(dsa_key));
#endif
#ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa[i] = NULL;
#endif
#ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++) {
ecdh_a[i] = NULL;
ecdh_b[i] = NULL;
}
#endif
if (bio_err == NULL)
if ((bio_err = BIO_new(BIO_s_file())) != NULL)
BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
if (!load_config(bio_err, NULL))
goto end;
#ifndef OPENSSL_NO_RSA
memset(rsa_key, 0, sizeof(rsa_key));
for (i = 0; i < RSA_NUM; i++)
rsa_key[i] = NULL;
#endif
if ((buf_malloc =
(unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
BIO_printf(bio_err, "out of memory\n");
goto end;
}
if ((buf2_malloc =
(unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {
BIO_printf(bio_err, "out of memory\n");
goto end;
}
misalign = 0;
buf = buf_malloc;
buf2 = buf2_malloc;
memset(c, 0, sizeof(c));
memset(DES_iv, 0, sizeof(DES_iv));
memset(iv, 0, sizeof(iv));
for (i = 0; i < ALGOR_NUM; i++)
doit[i] = 0;
for (i = 0; i < RSA_NUM; i++)
rsa_doit[i] = 0;
for (i = 0; i < DSA_NUM; i++)
dsa_doit[i] = 0;
#ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 0;
#endif
#ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 0;
#endif
j = 0;
argc--;
argv++;
while (argc) {
if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {
usertime = 0;
j--;
} else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no EVP given\n");
goto end;
}
evp_cipher = EVP_get_cipherbyname(*argv);
if (!evp_cipher) {
evp_md = EVP_get_digestbyname(*argv);
}
if (!evp_cipher && !evp_md) {
BIO_printf(bio_err, "%s is an unknown cipher or digest\n",
*argv);
goto end;
}
doit[D_EVP] = 1;
} else if (argc > 0 && !strcmp(*argv, "-decrypt")) {
decrypt = 1;
j--;
}
#ifndef OPENSSL_NO_ENGINE
else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no engine given\n");
goto end;
}
setup_engine(bio_err, *argv, 0);
j--;
}
#endif
#ifndef NO_FORK
else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no multi count given\n");
goto end;
}
multi = atoi(argv[0]);
if (multi <= 0) {
BIO_printf(bio_err, "bad multi count\n");
goto end;
}
j--;
}
#endif
else if (argc > 0 && !strcmp(*argv, "-mr")) {
mr = 1;
j--;
} else if (argc > 0 && !strcmp(*argv, "-mb")) {
multiblock = 1;
j--;
} else if (argc > 0 && !strcmp(*argv, "-misalign")) {
argc--;
argv++;
if (argc == 0) {
BIO_printf(bio_err, "no misalignment given\n");
goto end;
}
misalign = atoi(argv[0]);
if (misalign < 0 || misalign > MAX_MISALIGNMENT) {
BIO_printf(bio_err,
"misalignment is outsize permitted range 0-%d\n",
MAX_MISALIGNMENT);
goto end;
}
buf = buf_malloc + misalign;
buf2 = buf2_malloc + misalign;
j--;
} else
#ifndef OPENSSL_NO_MD2
if (strcmp(*argv, "md2") == 0)
doit[D_MD2] = 1;
else
#endif
#ifndef OPENSSL_NO_MDC2
if (strcmp(*argv, "mdc2") == 0)
doit[D_MDC2] = 1;
else
#endif
#ifndef OPENSSL_NO_MD4
if (strcmp(*argv, "md4") == 0)
doit[D_MD4] = 1;
else
#endif
#ifndef OPENSSL_NO_MD5
if (strcmp(*argv, "md5") == 0)
doit[D_MD5] = 1;
else
#endif
#ifndef OPENSSL_NO_MD5
if (strcmp(*argv, "hmac") == 0)
doit[D_HMAC] = 1;
else
#endif
#ifndef OPENSSL_NO_SHA
if (strcmp(*argv, "sha1") == 0)
doit[D_SHA1] = 1;
else if (strcmp(*argv, "sha") == 0)
doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;
else
# ifndef OPENSSL_NO_SHA256
if (strcmp(*argv, "sha256") == 0)
doit[D_SHA256] = 1;
else
# endif
# ifndef OPENSSL_NO_SHA512
if (strcmp(*argv, "sha512") == 0)
doit[D_SHA512] = 1;
else
# endif
#endif
#ifndef OPENSSL_NO_WHIRLPOOL
if (strcmp(*argv, "whirlpool") == 0)
doit[D_WHIRLPOOL] = 1;
else
#endif
#ifndef OPENSSL_NO_RMD160
if (strcmp(*argv, "ripemd") == 0)
doit[D_RMD160] = 1;
else if (strcmp(*argv, "rmd160") == 0)
doit[D_RMD160] = 1;
else if (strcmp(*argv, "ripemd160") == 0)
doit[D_RMD160] = 1;
else
#endif
#ifndef OPENSSL_NO_RC4
if (strcmp(*argv, "rc4") == 0)
doit[D_RC4] = 1;
else
#endif
#ifndef OPENSSL_NO_DES
if (strcmp(*argv, "des-cbc") == 0)
doit[D_CBC_DES] = 1;
else if (strcmp(*argv, "des-ede3") == 0)
doit[D_EDE3_DES] = 1;
else
#endif
#ifndef OPENSSL_NO_AES
if (strcmp(*argv, "aes-128-cbc") == 0)
doit[D_CBC_128_AES] = 1;
else if (strcmp(*argv, "aes-192-cbc") == 0)
doit[D_CBC_192_AES] = 1;
else if (strcmp(*argv, "aes-256-cbc") == 0)
doit[D_CBC_256_AES] = 1;
else if (strcmp(*argv, "aes-128-ige") == 0)
doit[D_IGE_128_AES] = 1;
else if (strcmp(*argv, "aes-192-ige") == 0)
doit[D_IGE_192_AES] = 1;
else if (strcmp(*argv, "aes-256-ige") == 0)
doit[D_IGE_256_AES] = 1;
else
#endif
#ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv, "camellia-128-cbc") == 0)
doit[D_CBC_128_CML] = 1;
else if (strcmp(*argv, "camellia-192-cbc") == 0)
doit[D_CBC_192_CML] = 1;
else if (strcmp(*argv, "camellia-256-cbc") == 0)
doit[D_CBC_256_CML] = 1;
else
#endif
#ifndef OPENSSL_NO_RSA
# if 0
if (strcmp(*argv, "rsaref") == 0) {
RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
j--;
} else
# endif
# ifndef RSA_NULL
if (strcmp(*argv, "openssl") == 0) {
RSA_set_default_method(RSA_PKCS1_SSLeay());
j--;
} else
# endif
#endif
if (strcmp(*argv, "dsa512") == 0)
dsa_doit[R_DSA_512] = 2;
else if (strcmp(*argv, "dsa1024") == 0)
dsa_doit[R_DSA_1024] = 2;
else if (strcmp(*argv, "dsa2048") == 0)
dsa_doit[R_DSA_2048] = 2;
else if (strcmp(*argv, "rsa512") == 0)
rsa_doit[R_RSA_512] = 2;
else if (strcmp(*argv, "rsa1024") == 0)
rsa_doit[R_RSA_1024] = 2;
else if (strcmp(*argv, "rsa2048") == 0)
rsa_doit[R_RSA_2048] = 2;
else if (strcmp(*argv, "rsa3072") == 0)
rsa_doit[R_RSA_3072] = 2;
else if (strcmp(*argv, "rsa4096") == 0)
rsa_doit[R_RSA_4096] = 2;
else if (strcmp(*argv, "rsa7680") == 0)
rsa_doit[R_RSA_7680] = 2;
else if (strcmp(*argv, "rsa15360") == 0)
rsa_doit[R_RSA_15360] = 2;
else
#ifndef OPENSSL_NO_RC2
if (strcmp(*argv, "rc2-cbc") == 0)
doit[D_CBC_RC2] = 1;
else if (strcmp(*argv, "rc2") == 0)
doit[D_CBC_RC2] = 1;
else
#endif
#ifndef OPENSSL_NO_RC5
if (strcmp(*argv, "rc5-cbc") == 0)
doit[D_CBC_RC5] = 1;
else if (strcmp(*argv, "rc5") == 0)
doit[D_CBC_RC5] = 1;
else
#endif
#ifndef OPENSSL_NO_IDEA
if (strcmp(*argv, "idea-cbc") == 0)
doit[D_CBC_IDEA] = 1;
else if (strcmp(*argv, "idea") == 0)
doit[D_CBC_IDEA] = 1;
else
#endif
#ifndef OPENSSL_NO_SEED
if (strcmp(*argv, "seed-cbc") == 0)
doit[D_CBC_SEED] = 1;
else if (strcmp(*argv, "seed") == 0)
doit[D_CBC_SEED] = 1;
else
#endif
#ifndef OPENSSL_NO_BF
if (strcmp(*argv, "bf-cbc") == 0)
doit[D_CBC_BF] = 1;
else if (strcmp(*argv, "blowfish") == 0)
doit[D_CBC_BF] = 1;
else if (strcmp(*argv, "bf") == 0)
doit[D_CBC_BF] = 1;
else
#endif
#ifndef OPENSSL_NO_CAST
if (strcmp(*argv, "cast-cbc") == 0)
doit[D_CBC_CAST] = 1;
else if (strcmp(*argv, "cast") == 0)
doit[D_CBC_CAST] = 1;
else if (strcmp(*argv, "cast5") == 0)
doit[D_CBC_CAST] = 1;
else
#endif
#ifndef OPENSSL_NO_DES
if (strcmp(*argv, "des") == 0) {
doit[D_CBC_DES] = 1;
doit[D_EDE3_DES] = 1;
} else
#endif
#ifndef OPENSSL_NO_AES
if (strcmp(*argv, "aes") == 0) {
doit[D_CBC_128_AES] = 1;
doit[D_CBC_192_AES] = 1;
doit[D_CBC_256_AES] = 1;
} else if (strcmp(*argv, "ghash") == 0) {
doit[D_GHASH] = 1;
} else
#endif
#ifndef OPENSSL_NO_CAMELLIA
if (strcmp(*argv, "camellia") == 0) {
doit[D_CBC_128_CML] = 1;
doit[D_CBC_192_CML] = 1;
doit[D_CBC_256_CML] = 1;
} else
#endif
#ifndef OPENSSL_NO_RSA
if (strcmp(*argv, "rsa") == 0) {
rsa_doit[R_RSA_512] = 1;
rsa_doit[R_RSA_1024] = 1;
rsa_doit[R_RSA_2048] = 1;
rsa_doit[R_RSA_3072] = 1;
rsa_doit[R_RSA_4096] = 1;
rsa_doit[R_RSA_7680] = 1;
rsa_doit[R_RSA_15360] = 1;
} else
#endif
#ifndef OPENSSL_NO_DSA
if (strcmp(*argv, "dsa") == 0) {
dsa_doit[R_DSA_512] = 1;
dsa_doit[R_DSA_1024] = 1;
dsa_doit[R_DSA_2048] = 1;
} else
#endif
#ifndef OPENSSL_NO_ECDSA
if (strcmp(*argv, "ecdsap160") == 0)
ecdsa_doit[R_EC_P160] = 2;
else if (strcmp(*argv, "ecdsap192") == 0)
ecdsa_doit[R_EC_P192] = 2;
else if (strcmp(*argv, "ecdsap224") == 0)
ecdsa_doit[R_EC_P224] = 2;
else if (strcmp(*argv, "ecdsap256") == 0)
ecdsa_doit[R_EC_P256] = 2;
else if (strcmp(*argv, "ecdsap384") == 0)
ecdsa_doit[R_EC_P384] = 2;
else if (strcmp(*argv, "ecdsap521") == 0)
ecdsa_doit[R_EC_P521] = 2;
else if (strcmp(*argv, "ecdsak163") == 0)
ecdsa_doit[R_EC_K163] = 2;
else if (strcmp(*argv, "ecdsak233") == 0)
ecdsa_doit[R_EC_K233] = 2;
else if (strcmp(*argv, "ecdsak283") == 0)
ecdsa_doit[R_EC_K283] = 2;
else if (strcmp(*argv, "ecdsak409") == 0)
ecdsa_doit[R_EC_K409] = 2;
else if (strcmp(*argv, "ecdsak571") == 0)
ecdsa_doit[R_EC_K571] = 2;
else if (strcmp(*argv, "ecdsab163") == 0)
ecdsa_doit[R_EC_B163] = 2;
else if (strcmp(*argv, "ecdsab233") == 0)
ecdsa_doit[R_EC_B233] = 2;
else if (strcmp(*argv, "ecdsab283") == 0)
ecdsa_doit[R_EC_B283] = 2;
else if (strcmp(*argv, "ecdsab409") == 0)
ecdsa_doit[R_EC_B409] = 2;
else if (strcmp(*argv, "ecdsab571") == 0)
ecdsa_doit[R_EC_B571] = 2;
else if (strcmp(*argv, "ecdsa") == 0) {
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 1;
} else
#endif
#ifndef OPENSSL_NO_ECDH
if (strcmp(*argv, "ecdhp160") == 0)
ecdh_doit[R_EC_P160] = 2;
else if (strcmp(*argv, "ecdhp192") == 0)
ecdh_doit[R_EC_P192] = 2;
else if (strcmp(*argv, "ecdhp224") == 0)
ecdh_doit[R_EC_P224] = 2;
else if (strcmp(*argv, "ecdhp256") == 0)
ecdh_doit[R_EC_P256] = 2;
else if (strcmp(*argv, "ecdhp384") == 0)
ecdh_doit[R_EC_P384] = 2;
else if (strcmp(*argv, "ecdhp521") == 0)
ecdh_doit[R_EC_P521] = 2;
else if (strcmp(*argv, "ecdhk163") == 0)
ecdh_doit[R_EC_K163] = 2;
else if (strcmp(*argv, "ecdhk233") == 0)
ecdh_doit[R_EC_K233] = 2;
else if (strcmp(*argv, "ecdhk283") == 0)
ecdh_doit[R_EC_K283] = 2;
else if (strcmp(*argv, "ecdhk409") == 0)
ecdh_doit[R_EC_K409] = 2;
else if (strcmp(*argv, "ecdhk571") == 0)
ecdh_doit[R_EC_K571] = 2;
else if (strcmp(*argv, "ecdhb163") == 0)
ecdh_doit[R_EC_B163] = 2;
else if (strcmp(*argv, "ecdhb233") == 0)
ecdh_doit[R_EC_B233] = 2;
else if (strcmp(*argv, "ecdhb283") == 0)
ecdh_doit[R_EC_B283] = 2;
else if (strcmp(*argv, "ecdhb409") == 0)
ecdh_doit[R_EC_B409] = 2;
else if (strcmp(*argv, "ecdhb571") == 0)
ecdh_doit[R_EC_B571] = 2;
else if (strcmp(*argv, "ecdh") == 0) {
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 1;
} else
#endif
{
BIO_printf(bio_err, "Error: bad option or value\n");
BIO_printf(bio_err, "\n");
BIO_printf(bio_err, "Available values:\n");
#ifndef OPENSSL_NO_MD2
BIO_printf(bio_err, "md2 ");
#endif
#ifndef OPENSSL_NO_MDC2
BIO_printf(bio_err, "mdc2 ");
#endif
#ifndef OPENSSL_NO_MD4
BIO_printf(bio_err, "md4 ");
#endif
#ifndef OPENSSL_NO_MD5
BIO_printf(bio_err, "md5 ");
# ifndef OPENSSL_NO_HMAC
BIO_printf(bio_err, "hmac ");
# endif
#endif
#ifndef OPENSSL_NO_SHA1
BIO_printf(bio_err, "sha1 ");
#endif
#ifndef OPENSSL_NO_SHA256
BIO_printf(bio_err, "sha256 ");
#endif
#ifndef OPENSSL_NO_SHA512
BIO_printf(bio_err, "sha512 ");
#endif
#ifndef OPENSSL_NO_WHIRLPOOL
BIO_printf(bio_err, "whirlpool");
#endif
#ifndef OPENSSL_NO_RMD160
BIO_printf(bio_err, "rmd160");
#endif
#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
!defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
!defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \
!defined(OPENSSL_NO_WHIRLPOOL)
BIO_printf(bio_err, "\n");
#endif
#ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err, "idea-cbc ");
#endif
#ifndef OPENSSL_NO_SEED
BIO_printf(bio_err, "seed-cbc ");
#endif
#ifndef OPENSSL_NO_RC2
BIO_printf(bio_err, "rc2-cbc ");
#endif
#ifndef OPENSSL_NO_RC5
BIO_printf(bio_err, "rc5-cbc ");
#endif
#ifndef OPENSSL_NO_BF
BIO_printf(bio_err, "bf-cbc");
#endif
#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \
!defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
BIO_printf(bio_err, "\n");
#endif
#ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "des-cbc des-ede3 ");
#endif
#ifndef OPENSSL_NO_AES
BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");
BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");
#endif
#ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err, "\n");
BIO_printf(bio_err,
"camellia-128-cbc camellia-192-cbc camellia-256-cbc ");
#endif
#ifndef OPENSSL_NO_RC4
BIO_printf(bio_err, "rc4");
#endif
BIO_printf(bio_err, "\n");
#ifndef OPENSSL_NO_RSA
BIO_printf(bio_err,
"rsa512 rsa1024 rsa2048 rsa3072 rsa4096\n");
BIO_printf(bio_err, "rsa7680 rsa15360\n");
#endif
#ifndef OPENSSL_NO_DSA
BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\n");
#endif
#ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "
"ecdsap256 ecdsap384 ecdsap521\n");
BIO_printf(bio_err,
"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\n");
BIO_printf(bio_err,
"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\n");
BIO_printf(bio_err, "ecdsa\n");
#endif
#ifndef OPENSSL_NO_ECDH
BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "
"ecdhp256 ecdhp384 ecdhp521\n");
BIO_printf(bio_err,
"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\n");
BIO_printf(bio_err,
"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\n");
BIO_printf(bio_err, "ecdh\n");
#endif
#ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err, "idea ");
#endif
#ifndef OPENSSL_NO_SEED
BIO_printf(bio_err, "seed ");
#endif
#ifndef OPENSSL_NO_RC2
BIO_printf(bio_err, "rc2 ");
#endif
#ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "des ");
#endif
#ifndef OPENSSL_NO_AES
BIO_printf(bio_err, "aes ");
#endif
#ifndef OPENSSL_NO_CAMELLIA
BIO_printf(bio_err, "camellia ");
#endif
#ifndef OPENSSL_NO_RSA
BIO_printf(bio_err, "rsa ");
#endif
#ifndef OPENSSL_NO_BF
BIO_printf(bio_err, "blowfish");
#endif
#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \
!defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \
!defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \
!defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)
BIO_printf(bio_err, "\n");
#endif
BIO_printf(bio_err, "\n");
BIO_printf(bio_err, "Available options:\n");
#if defined(TIMES) || defined(USE_TOD)
BIO_printf(bio_err, "-elapsed "
"measure time in real time instead of CPU user time.\n");
#endif
#ifndef OPENSSL_NO_ENGINE
BIO_printf(bio_err,
"-engine e "
"use engine e, possibly a hardware device.\n");
#endif
BIO_printf(bio_err, "-evp e " "use EVP e.\n");
BIO_printf(bio_err,
"-decrypt "
"time decryption instead of encryption (only EVP).\n");
BIO_printf(bio_err,
"-mr "
"produce machine readable output.\n");
BIO_printf(bio_err,
"-mb "
"perform multi-block benchmark (for specific ciphers)\n");
BIO_printf(bio_err,
"-misalign n "
"perform benchmark with misaligned data\n");
#ifndef NO_FORK
BIO_printf(bio_err,
"-multi n " "run n benchmarks in parallel.\n");
#endif
goto end;
}
argc--;
argv++;
j++;
}
#ifndef NO_FORK
if (multi && do_multi(multi))
goto show_res;
#endif
if (j == 0) {
for (i = 0; i < ALGOR_NUM; i++) {
if (i != D_EVP)
doit[i] = 1;
}
for (i = 0; i < RSA_NUM; i++)
rsa_doit[i] = 1;
for (i = 0; i < DSA_NUM; i++)
dsa_doit[i] = 1;
#ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
ecdsa_doit[i] = 1;
#endif
#ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++)
ecdh_doit[i] = 1;
#endif
}
for (i = 0; i < ALGOR_NUM; i++)
if (doit[i])
pr_header++;
if (usertime == 0 && !mr)
BIO_printf(bio_err,
"You have chosen to measure elapsed time "
"instead of user CPU time.\n");
#ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++) {
const unsigned char *p;
p = rsa_data[i];
rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);
if (rsa_key[i] == NULL) {
BIO_printf(bio_err, "internal error loading RSA key number %d\n",
i);
goto end;
}
# if 0
else {
BIO_printf(bio_err,
mr ? "+RK:%d:"
: "Loaded RSA key, %d bit modulus and e= 0x",
BN_num_bits(rsa_key[i]->n));
BN_print(bio_err, rsa_key[i]->e);
BIO_printf(bio_err, "\n");
}
# endif
}
#endif
#ifndef OPENSSL_NO_DSA
dsa_key[0] = get_dsa512();
dsa_key[1] = get_dsa1024();
dsa_key[2] = get_dsa2048();
#endif
#ifndef OPENSSL_NO_DES
DES_set_key_unchecked(&key, &sch);
DES_set_key_unchecked(&key2, &sch2);
DES_set_key_unchecked(&key3, &sch3);
#endif
#ifndef OPENSSL_NO_AES
AES_set_encrypt_key(key16, 128, &aes_ks1);
AES_set_encrypt_key(key24, 192, &aes_ks2);
AES_set_encrypt_key(key32, 256, &aes_ks3);
#endif
#ifndef OPENSSL_NO_CAMELLIA
Camellia_set_key(key16, 128, &camellia_ks1);
Camellia_set_key(ckey24, 192, &camellia_ks2);
Camellia_set_key(ckey32, 256, &camellia_ks3);
#endif
#ifndef OPENSSL_NO_IDEA
idea_set_encrypt_key(key16, &idea_ks);
#endif
#ifndef OPENSSL_NO_SEED
SEED_set_key(key16, &seed_ks);
#endif
#ifndef OPENSSL_NO_RC4
RC4_set_key(&rc4_ks, 16, key16);
#endif
#ifndef OPENSSL_NO_RC2
RC2_set_key(&rc2_ks, 16, key16, 128);
#endif
#ifndef OPENSSL_NO_RC5
RC5_32_set_key(&rc5_ks, 16, key16, 12);
#endif
#ifndef OPENSSL_NO_BF
BF_set_key(&bf_ks, 16, key16);
#endif
#ifndef OPENSSL_NO_CAST
CAST_set_key(&cast_ks, 16, key16);
#endif
#ifndef OPENSSL_NO_RSA
memset(rsa_c, 0, sizeof(rsa_c));
#endif
#ifndef SIGALRM
# ifndef OPENSSL_NO_DES
BIO_printf(bio_err, "First we calculate the approximate speed ...\n");
count = 10;
do {
long it;
count *= 2;
Time_F(START);
for (it = count; it; it--)
DES_ecb_encrypt((DES_cblock *)buf,
(DES_cblock *)buf, &sch, DES_ENCRYPT);
d = Time_F(STOP);
} while (d < 3);
save_count = count;
c[D_MD2][0] = count / 10;
c[D_MDC2][0] = count / 10;
c[D_MD4][0] = count;
c[D_MD5][0] = count;
c[D_HMAC][0] = count;
c[D_SHA1][0] = count;
c[D_RMD160][0] = count;
c[D_RC4][0] = count * 5;
c[D_CBC_DES][0] = count;
c[D_EDE3_DES][0] = count / 3;
c[D_CBC_IDEA][0] = count;
c[D_CBC_SEED][0] = count;
c[D_CBC_RC2][0] = count;
c[D_CBC_RC5][0] = count;
c[D_CBC_BF][0] = count;
c[D_CBC_CAST][0] = count;
c[D_CBC_128_AES][0] = count;
c[D_CBC_192_AES][0] = count;
c[D_CBC_256_AES][0] = count;
c[D_CBC_128_CML][0] = count;
c[D_CBC_192_CML][0] = count;
c[D_CBC_256_CML][0] = count;
c[D_SHA256][0] = count;
c[D_SHA512][0] = count;
c[D_WHIRLPOOL][0] = count;
c[D_IGE_128_AES][0] = count;
c[D_IGE_192_AES][0] = count;
c[D_IGE_256_AES][0] = count;
c[D_GHASH][0] = count;
for (i = 1; i < SIZE_NUM; i++) {
long l0, l1;
l0 = (long)lengths[0];
l1 = (long)lengths[i];
c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;
c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;
c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;
c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;
c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;
c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;
c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;
c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;
c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;
c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;
l0 = (long)lengths[i - 1];
c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;
c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;
c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;
c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;
c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;
c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;
c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;
c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;
c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;
c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;
c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;
c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;
c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;
c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;
c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;
c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;
c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;
c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;
}
# ifndef OPENSSL_NO_RSA
rsa_c[R_RSA_512][0] = count / 2000;
rsa_c[R_RSA_512][1] = count / 400;
for (i = 1; i < RSA_NUM; i++) {
rsa_c[i][0] = rsa_c[i - 1][0] / 8;
rsa_c[i][1] = rsa_c[i - 1][1] / 4;
if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
rsa_doit[i] = 0;
else {
if (rsa_c[i][0] == 0) {
rsa_c[i][0] = 1;
rsa_c[i][1] = 20;
}
}
}
# endif
# ifndef OPENSSL_NO_DSA
dsa_c[R_DSA_512][0] = count / 1000;
dsa_c[R_DSA_512][1] = count / 1000 / 2;
for (i = 1; i < DSA_NUM; i++) {
dsa_c[i][0] = dsa_c[i - 1][0] / 4;
dsa_c[i][1] = dsa_c[i - 1][1] / 4;
if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
dsa_doit[i] = 0;
else {
if (dsa_c[i] == 0) {
dsa_c[i][0] = 1;
dsa_c[i][1] = 1;
}
}
}
# endif
# ifndef OPENSSL_NO_ECDSA
ecdsa_c[R_EC_P160][0] = count / 1000;
ecdsa_c[R_EC_P160][1] = count / 1000 / 2;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
ecdsa_c[R_EC_K163][0] = count / 1000;
ecdsa_c[R_EC_K163][1] = count / 1000 / 2;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
ecdsa_c[R_EC_B163][0] = count / 1000;
ecdsa_c[R_EC_B163][1] = count / 1000 / 2;
for (i = R_EC_B233; i <= R_EC_B571; i++) {
ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;
ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;
if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))
ecdsa_doit[i] = 0;
else {
if (ecdsa_c[i] == 0) {
ecdsa_c[i][0] = 1;
ecdsa_c[i][1] = 1;
}
}
}
# endif
# ifndef OPENSSL_NO_ECDH
ecdh_c[R_EC_P160][0] = count / 1000;
ecdh_c[R_EC_P160][1] = count / 1000;
for (i = R_EC_P192; i <= R_EC_P521; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
ecdh_c[R_EC_K163][0] = count / 1000;
ecdh_c[R_EC_K163][1] = count / 1000;
for (i = R_EC_K233; i <= R_EC_K571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
ecdh_c[R_EC_B163][0] = count / 1000;
ecdh_c[R_EC_B163][1] = count / 1000;
for (i = R_EC_B233; i <= R_EC_B571; i++) {
ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;
ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;
if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))
ecdh_doit[i] = 0;
else {
if (ecdh_c[i] == 0) {
ecdh_c[i][0] = 1;
ecdh_c[i][1] = 1;
}
}
}
# endif
# define COND(d) (count < (d))
# define COUNT(d) (d)
# else
# error "You cannot disable DES on systems without SIGALRM."
# endif
#else
# define COND(c) (run && count<0x7fffffff)
# define COUNT(d) (count)
# ifndef _WIN32
signal(SIGALRM, sig_done);
# endif
#endif
#ifndef OPENSSL_NO_MD2
if (doit[D_MD2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD2], c[D_MD2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD2][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,
EVP_md2(), NULL);
d = Time_F(STOP);
print_result(D_MD2, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_MDC2
if (doit[D_MDC2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,
EVP_mdc2(), NULL);
d = Time_F(STOP);
print_result(D_MDC2, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_MD4
if (doit[D_MD4]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD4], c[D_MD4][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD4][j]); count++)
EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),
NULL, EVP_md4(), NULL);
d = Time_F(STOP);
print_result(D_MD4, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_MD5
if (doit[D_MD5]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_MD5], c[D_MD5][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_MD5][j]); count++)
MD5(buf, lengths[j], md5);
d = Time_F(STOP);
print_result(D_MD5, j, count, d);
}
}
#endif
#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
if (doit[D_HMAC]) {
HMAC_CTX hctx;
HMAC_CTX_init(&hctx);
HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",
16, EVP_md5(), NULL);
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {
HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);
HMAC_Update(&hctx, buf, lengths[j]);
HMAC_Final(&hctx, &(hmac[0]), NULL);
}
d = Time_F(STOP);
print_result(D_HMAC, j, count, d);
}
HMAC_CTX_cleanup(&hctx);
}
#endif
#ifndef OPENSSL_NO_SHA
if (doit[D_SHA1]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)
# if 0
EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,
EVP_sha1(), NULL);
# else
SHA1(buf, lengths[j], sha);
# endif
d = Time_F(STOP);
print_result(D_SHA1, j, count, d);
}
}
# ifndef OPENSSL_NO_SHA256
if (doit[D_SHA256]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)
SHA256(buf, lengths[j], sha256);
d = Time_F(STOP);
print_result(D_SHA256, j, count, d);
}
}
# endif
# ifndef OPENSSL_NO_SHA512
if (doit[D_SHA512]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)
SHA512(buf, lengths[j], sha512);
d = Time_F(STOP);
print_result(D_SHA512, j, count, d);
}
}
# endif
#endif
#ifndef OPENSSL_NO_WHIRLPOOL
if (doit[D_WHIRLPOOL]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)
WHIRLPOOL(buf, lengths[j], whirlpool);
d = Time_F(STOP);
print_result(D_WHIRLPOOL, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_RMD160
if (doit[D_RMD160]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)
EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,
EVP_ripemd160(), NULL);
d = Time_F(STOP);
print_result(D_RMD160, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_RC4
if (doit[D_RC4]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_RC4], c[D_RC4][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_RC4][j]); count++)
RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);
d = Time_F(STOP);
print_result(D_RC4, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_DES
if (doit[D_CBC_DES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)
DES_ncbc_encrypt(buf, buf, lengths[j], &sch,
&DES_iv, DES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_DES, j, count, d);
}
}
if (doit[D_EDE3_DES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)
DES_ede3_cbc_encrypt(buf, buf, lengths[j],
&sch, &sch2, &sch3,
&DES_iv, DES_ENCRYPT);
d = Time_F(STOP);
print_result(D_EDE3_DES, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_AES
if (doit[D_CBC_128_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks1,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_128_AES, j, count, d);
}
}
if (doit[D_CBC_192_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks2,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_192_AES, j, count, d);
}
}
if (doit[D_CBC_256_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)
AES_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &aes_ks3,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_256_AES, j, count, d);
}
}
if (doit[D_IGE_128_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks1,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_128_AES, j, count, d);
}
}
if (doit[D_IGE_192_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks2,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_192_AES, j, count, d);
}
}
if (doit[D_IGE_256_AES]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)
AES_ige_encrypt(buf, buf2,
(unsigned long)lengths[j], &aes_ks3,
iv, AES_ENCRYPT);
d = Time_F(STOP);
print_result(D_IGE_256_AES, j, count, d);
}
}
if (doit[D_GHASH]) {
GCM128_CONTEXT *ctx =
CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);
CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)
CRYPTO_gcm128_aad(ctx, buf, lengths[j]);
d = Time_F(STOP);
print_result(D_GHASH, j, count, d);
}
CRYPTO_gcm128_release(ctx);
}
#endif
#ifndef OPENSSL_NO_CAMELLIA
if (doit[D_CBC_128_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks1,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_128_CML, j, count, d);
}
}
if (doit[D_CBC_192_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks2,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_192_CML, j, count, d);
}
}
if (doit[D_CBC_256_CML]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],
lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)
Camellia_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &camellia_ks3,
iv, CAMELLIA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_256_CML, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_IDEA
if (doit[D_CBC_IDEA]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)
idea_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &idea_ks,
iv, IDEA_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_IDEA, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_SEED
if (doit[D_CBC_SEED]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)
SEED_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &seed_ks, iv, 1);
d = Time_F(STOP);
print_result(D_CBC_SEED, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_RC2
if (doit[D_CBC_RC2]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)
RC2_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &rc2_ks,
iv, RC2_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_RC2, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_RC5
if (doit[D_CBC_RC5]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)
RC5_32_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &rc5_ks,
iv, RC5_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_RC5, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_BF
if (doit[D_CBC_BF]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)
BF_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &bf_ks,
iv, BF_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_BF, j, count, d);
}
}
#endif
#ifndef OPENSSL_NO_CAST
if (doit[D_CBC_CAST]) {
for (j = 0; j < SIZE_NUM; j++) {
print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);
Time_F(START);
for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)
CAST_cbc_encrypt(buf, buf,
(unsigned long)lengths[j], &cast_ks,
iv, CAST_ENCRYPT);
d = Time_F(STOP);
print_result(D_CBC_CAST, j, count, d);
}
}
#endif
if (doit[D_EVP]) {
#ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK
if (multiblock && evp_cipher) {
if (!
(EVP_CIPHER_flags(evp_cipher) &
EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {
fprintf(stderr, "%s is not multi-block capable\n",
OBJ_nid2ln(evp_cipher->nid));
goto end;
}
multiblock_speed(evp_cipher);
mret = 0;
goto end;
}
#endif
for (j = 0; j < SIZE_NUM; j++) {
if (evp_cipher) {
EVP_CIPHER_CTX ctx;
int outl;
names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);
print_message(names[D_EVP], save_count, lengths[j]);
EVP_CIPHER_CTX_init(&ctx);
if (decrypt)
EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
else
EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);
EVP_CIPHER_CTX_set_padding(&ctx, 0);
Time_F(START);
if (decrypt)
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]);
count++)
EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
else
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]);
count++)
EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);
if (decrypt)
EVP_DecryptFinal_ex(&ctx, buf, &outl);
else
EVP_EncryptFinal_ex(&ctx, buf, &outl);
d = Time_F(STOP);
EVP_CIPHER_CTX_cleanup(&ctx);
}
if (evp_md) {
names[D_EVP] = OBJ_nid2ln(evp_md->type);
print_message(names[D_EVP], save_count, lengths[j]);
Time_F(START);
for (count = 0, run = 1;
COND(save_count * 4 * lengths[0] / lengths[j]); count++)
EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);
d = Time_F(STOP);
}
print_result(D_EVP, j, count, d);
}
}
#ifndef OPENSSL_SYS_WIN32
#endif
RAND_pseudo_bytes(buf, 36);
#ifndef OPENSSL_NO_RSA
for (j = 0; j < RSA_NUM; j++) {
int ret;
if (!rsa_doit[j])
continue;
ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err,
"RSA sign failure. No RSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("private", "rsa",
rsa_c[j][0], rsa_bits[j], RSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {
ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,
&rsa_num, rsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err, "RSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R1:%ld:%d:%.2f\n"
: "%ld %d bit private RSA's in %.2fs\n",
count, rsa_bits[j], d);
rsa_results[j][0] = d / (double)count;
rsa_count = count;
}
# if 1
ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err,
"RSA verify failure. No RSA verify will be done.\n");
ERR_print_errors(bio_err);
rsa_doit[j] = 0;
} else {
pkey_print_message("public", "rsa",
rsa_c[j][1], rsa_bits[j], RSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {
ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,
rsa_num, rsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err, "RSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R2:%ld:%d:%.2f\n"
: "%ld %d bit public RSA's in %.2fs\n",
count, rsa_bits[j], d);
rsa_results[j][1] = d / (double)count;
}
# endif
if (rsa_count <= 1) {
for (j++; j < RSA_NUM; j++)
rsa_doit[j] = 0;
}
}
#endif
RAND_pseudo_bytes(buf, 20);
#ifndef OPENSSL_NO_DSA
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < DSA_NUM; j++) {
unsigned int kk;
int ret;
if (!dsa_doit[j])
continue;
ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err,
"DSA sign failure. No DSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "dsa",
dsa_c[j][0], dsa_bits[j], DSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {
ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);
if (ret == 0) {
BIO_printf(bio_err, "DSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R3:%ld:%d:%.2f\n"
: "%ld %d bit DSA signs in %.2fs\n",
count, dsa_bits[j], d);
dsa_results[j][0] = d / (double)count;
rsa_count = count;
}
ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err,
"DSA verify failure. No DSA verify will be done.\n");
ERR_print_errors(bio_err);
dsa_doit[j] = 0;
} else {
pkey_print_message("verify", "dsa",
dsa_c[j][1], dsa_bits[j], DSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {
ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);
if (ret <= 0) {
BIO_printf(bio_err, "DSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R4:%ld:%d:%.2f\n"
: "%ld %d bit DSA verify in %.2fs\n",
count, dsa_bits[j], d);
dsa_results[j][1] = d / (double)count;
}
if (rsa_count <= 1) {
for (j++; j < DSA_NUM; j++)
dsa_doit[j] = 0;
}
}
if (rnd_fake)
RAND_cleanup();
#endif
#ifndef OPENSSL_NO_ECDSA
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < EC_NUM; j++) {
int ret;
if (!ecdsa_doit[j])
continue;
ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if (ecdsa[j] == NULL) {
BIO_printf(bio_err, "ECDSA failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
# if 1
EC_KEY_precompute_mult(ecdsa[j], NULL);
# endif
EC_KEY_generate_key(ecdsa[j]);
ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);
if (ret == 0) {
BIO_printf(bio_err,
"ECDSA sign failure. No ECDSA sign will be done.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
pkey_print_message("sign", "ecdsa",
ecdsa_c[j][0],
test_curves_bits[j], ECDSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {
ret = ECDSA_sign(0, buf, 20,
ecdsasig, &ecdsasiglen, ecdsa[j]);
if (ret == 0) {
BIO_printf(bio_err, "ECDSA sign failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R5:%ld:%d:%.2f\n" :
"%ld %d bit ECDSA signs in %.2fs \n",
count, test_curves_bits[j], d);
ecdsa_results[j][0] = d / (double)count;
rsa_count = count;
}
ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);
if (ret != 1) {
BIO_printf(bio_err,
"ECDSA verify failure. No ECDSA verify will be done.\n");
ERR_print_errors(bio_err);
ecdsa_doit[j] = 0;
} else {
pkey_print_message("verify", "ecdsa",
ecdsa_c[j][1],
test_curves_bits[j], ECDSA_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {
ret =
ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,
ecdsa[j]);
if (ret != 1) {
BIO_printf(bio_err, "ECDSA verify failure\n");
ERR_print_errors(bio_err);
count = 1;
break;
}
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R6:%ld:%d:%.2f\n"
: "%ld %d bit ECDSA verify in %.2fs\n",
count, test_curves_bits[j], d);
ecdsa_results[j][1] = d / (double)count;
}
if (rsa_count <= 1) {
for (j++; j < EC_NUM; j++)
ecdsa_doit[j] = 0;
}
}
}
if (rnd_fake)
RAND_cleanup();
#endif
#ifndef OPENSSL_NO_ECDH
if (RAND_status() != 1) {
RAND_seed(rnd_seed, sizeof rnd_seed);
rnd_fake = 1;
}
for (j = 0; j < EC_NUM; j++) {
if (!ecdh_doit[j])
continue;
ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);
ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);
if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {
BIO_printf(bio_err, "ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
if (!EC_KEY_generate_key(ecdh_a[j]) ||
!EC_KEY_generate_key(ecdh_b[j])) {
BIO_printf(bio_err, "ECDH key generation failure.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
} else {
int field_size, outlen;
void *(*kdf) (const void *in, size_t inlen, void *out,
size_t *xoutlen);
field_size =
EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));
if (field_size <= 24 * 8) {
outlen = KDF1_SHA1_len;
kdf = KDF1_SHA1;
} else {
outlen = (field_size + 7) / 8;
kdf = NULL;
}
secret_size_a =
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
secret_size_b =
ECDH_compute_key(secret_b, outlen,
EC_KEY_get0_public_key(ecdh_a[j]),
ecdh_b[j], kdf);
if (secret_size_a != secret_size_b)
ecdh_checks = 0;
else
ecdh_checks = 1;
for (secret_idx = 0; (secret_idx < secret_size_a)
&& (ecdh_checks == 1); secret_idx++) {
if (secret_a[secret_idx] != secret_b[secret_idx])
ecdh_checks = 0;
}
if (ecdh_checks == 0) {
BIO_printf(bio_err, "ECDH computations don't match.\n");
ERR_print_errors(bio_err);
rsa_count = 1;
}
pkey_print_message("", "ecdh",
ecdh_c[j][0],
test_curves_bits[j], ECDH_SECONDS);
Time_F(START);
for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {
ECDH_compute_key(secret_a, outlen,
EC_KEY_get0_public_key(ecdh_b[j]),
ecdh_a[j], kdf);
}
d = Time_F(STOP);
BIO_printf(bio_err,
mr ? "+R7:%ld:%d:%.2f\n" :
"%ld %d-bit ECDH ops in %.2fs\n", count,
test_curves_bits[j], d);
ecdh_results[j][0] = d / (double)count;
rsa_count = count;
}
}
if (rsa_count <= 1) {
for (j++; j < EC_NUM; j++)
ecdh_doit[j] = 0;
}
}
if (rnd_fake)
RAND_cleanup();
#endif
#ifndef NO_FORK
show_res:
#endif
if (!mr) {
fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_VERSION));
fprintf(stdout, "%s\n", SSLeay_version(SSLEAY_BUILT_ON));
printf("options:");
printf("%s ", BN_options());
#ifndef OPENSSL_NO_MD2
printf("%s ", MD2_options());
#endif
#ifndef OPENSSL_NO_RC4
printf("%s ", RC4_options());
#endif
#ifndef OPENSSL_NO_DES
printf("%s ", DES_options());
#endif
#ifndef OPENSSL_NO_AES
printf("%s ", AES_options());
#endif
#ifndef OPENSSL_NO_IDEA
printf("%s ", idea_options());
#endif
#ifndef OPENSSL_NO_BF
printf("%s ", BF_options());
#endif
fprintf(stdout, "\n%s\n", SSLeay_version(SSLEAY_CFLAGS));
}
if (pr_header) {
if (mr)
fprintf(stdout, "+H");
else {
fprintf(stdout,
"The 'numbers' are in 1000s of bytes per second processed.\n");
fprintf(stdout, "type ");
}
for (j = 0; j < SIZE_NUM; j++)
fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);
fprintf(stdout, "\n");
}
for (k = 0; k < ALGOR_NUM; k++) {
if (!doit[k])
continue;
if (mr)
fprintf(stdout, "+F:%d:%s", k, names[k]);
else
fprintf(stdout, "%-13s", names[k]);
for (j = 0; j < SIZE_NUM; j++) {
if (results[k][j] > 10000 && !mr)
fprintf(stdout, " %11.2fk", results[k][j] / 1e3);
else
fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);
}
fprintf(stdout, "\n");
}
#ifndef OPENSSL_NO_RSA
j = 1;
for (k = 0; k < RSA_NUM; k++) {
if (!rsa_doit[k])
continue;
if (j && !mr) {
printf("%18ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F2:%u:%u:%f:%f\n",
k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);
else
fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
rsa_bits[k], rsa_results[k][0], rsa_results[k][1],
1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_DSA
j = 1;
for (k = 0; k < DSA_NUM; k++) {
if (!dsa_doit[k])
continue;
if (j && !mr) {
printf("%18ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F3:%u:%u:%f:%f\n",
k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);
else
fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
dsa_bits[k], dsa_results[k][0], dsa_results[k][1],
1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_ECDSA
j = 1;
for (k = 0; k < EC_NUM; k++) {
if (!ecdsa_doit[k])
continue;
if (j && !mr) {
printf("%30ssign verify sign/s verify/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F4:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdsa_results[k][0], ecdsa_results[k][1]);
else
fprintf(stdout,
"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdsa_results[k][0], ecdsa_results[k][1],
1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);
}
#endif
#ifndef OPENSSL_NO_ECDH
j = 1;
for (k = 0; k < EC_NUM; k++) {
if (!ecdh_doit[k])
continue;
if (j && !mr) {
printf("%30sop op/s\n", " ");
j = 0;
}
if (mr)
fprintf(stdout, "+F5:%u:%u:%f:%f\n",
k, test_curves_bits[k],
ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
else
fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\n",
test_curves_bits[k],
test_curves_names[k],
ecdh_results[k][0], 1.0 / ecdh_results[k][0]);
}
#endif
mret = 0;
end:
ERR_print_errors(bio_err);
if (buf_malloc != NULL)
OPENSSL_free(buf_malloc);
if (buf2_malloc != NULL)
OPENSSL_free(buf2_malloc);
#ifndef OPENSSL_NO_RSA
for (i = 0; i < RSA_NUM; i++)
if (rsa_key[i] != NULL)
RSA_free(rsa_key[i]);
#endif
#ifndef OPENSSL_NO_DSA
for (i = 0; i < DSA_NUM; i++)
if (dsa_key[i] != NULL)
DSA_free(dsa_key[i]);
#endif
#ifndef OPENSSL_NO_ECDSA
for (i = 0; i < EC_NUM; i++)
if (ecdsa[i] != NULL)
EC_KEY_free(ecdsa[i]);
#endif
#ifndef OPENSSL_NO_ECDH
for (i = 0; i < EC_NUM; i++) {
if (ecdh_a[i] != NULL)
EC_KEY_free(ecdh_a[i]);
if (ecdh_b[i] != NULL)
EC_KEY_free(ecdh_b[i]);
}
#endif
apps_shutdown();
OPENSSL_EXIT(mret);
} | ['int MAIN(int argc, char **argv)\n{\n unsigned char *buf_malloc = NULL, *buf2_malloc = NULL;\n unsigned char *buf = NULL, *buf2 = NULL;\n int mret = 1;\n long count = 0, save_count = 0;\n int i, j, k;\n#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n long rsa_count;\n#endif\n#ifndef OPENSSL_NO_RSA\n unsigned rsa_num;\n#endif\n unsigned char md[EVP_MAX_MD_SIZE];\n#ifndef OPENSSL_NO_MD2\n unsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MDC2\n unsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD4\n unsigned char md4[MD4_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD5\n unsigned char md5[MD5_DIGEST_LENGTH];\n unsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA\n unsigned char sha[SHA_DIGEST_LENGTH];\n# ifndef OPENSSL_NO_SHA256\n unsigned char sha256[SHA256_DIGEST_LENGTH];\n# endif\n# ifndef OPENSSL_NO_SHA512\n unsigned char sha512[SHA512_DIGEST_LENGTH];\n# endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n unsigned char whirlpool[WHIRLPOOL_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RMD160\n unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RC4\n RC4_KEY rc4_ks;\n#endif\n#ifndef OPENSSL_NO_RC5\n RC5_32_KEY rc5_ks;\n#endif\n#ifndef OPENSSL_NO_RC2\n RC2_KEY rc2_ks;\n#endif\n#ifndef OPENSSL_NO_IDEA\n IDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef OPENSSL_NO_SEED\n SEED_KEY_SCHEDULE seed_ks;\n#endif\n#ifndef OPENSSL_NO_BF\n BF_KEY bf_ks;\n#endif\n#ifndef OPENSSL_NO_CAST\n CAST_KEY cast_ks;\n#endif\n static const unsigned char key16[16] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12\n };\n#ifndef OPENSSL_NO_AES\n static const unsigned char key24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char key32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n static const unsigned char ckey24[24] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34\n };\n static const unsigned char ckey32[32] = {\n 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,\n 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12,\n 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34,\n 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56\n };\n#endif\n#ifndef OPENSSL_NO_AES\n# define MAX_BLOCK_SIZE 128\n#else\n# define MAX_BLOCK_SIZE 64\n#endif\n unsigned char DES_iv[8];\n unsigned char iv[2 * MAX_BLOCK_SIZE / 8];\n#ifndef OPENSSL_NO_DES\n static DES_cblock key =\n { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 };\n static DES_cblock key2 =\n { 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12 };\n static DES_cblock key3 =\n { 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34 };\n DES_key_schedule sch;\n DES_key_schedule sch2;\n DES_key_schedule sch3;\n#endif\n#ifndef OPENSSL_NO_AES\n AES_KEY aes_ks1, aes_ks2, aes_ks3;\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n CAMELLIA_KEY camellia_ks1, camellia_ks2, camellia_ks3;\n#endif\n#define D_MD2 0\n#define D_MDC2 1\n#define D_MD4 2\n#define D_MD5 3\n#define D_HMAC 4\n#define D_SHA1 5\n#define D_RMD160 6\n#define D_RC4 7\n#define D_CBC_DES 8\n#define D_EDE3_DES 9\n#define D_CBC_IDEA 10\n#define D_CBC_SEED 11\n#define D_CBC_RC2 12\n#define D_CBC_RC5 13\n#define D_CBC_BF 14\n#define D_CBC_CAST 15\n#define D_CBC_128_AES 16\n#define D_CBC_192_AES 17\n#define D_CBC_256_AES 18\n#define D_CBC_128_CML 19\n#define D_CBC_192_CML 20\n#define D_CBC_256_CML 21\n#define D_EVP 22\n#define D_SHA256 23\n#define D_SHA512 24\n#define D_WHIRLPOOL 25\n#define D_IGE_128_AES 26\n#define D_IGE_192_AES 27\n#define D_IGE_256_AES 28\n#define D_GHASH 29\n double d = 0.0;\n long c[ALGOR_NUM][SIZE_NUM];\n#ifndef OPENSSL_SYS_WIN32\n#endif\n#define R_DSA_512 0\n#define R_DSA_1024 1\n#define R_DSA_2048 2\n#define R_RSA_512 0\n#define R_RSA_1024 1\n#define R_RSA_2048 2\n#define R_RSA_3072 3\n#define R_RSA_4096 4\n#define R_RSA_7680 5\n#define R_RSA_15360 6\n#define R_EC_P160 0\n#define R_EC_P192 1\n#define R_EC_P224 2\n#define R_EC_P256 3\n#define R_EC_P384 4\n#define R_EC_P521 5\n#define R_EC_K163 6\n#define R_EC_K233 7\n#define R_EC_K283 8\n#define R_EC_K409 9\n#define R_EC_K571 10\n#define R_EC_B163 11\n#define R_EC_B233 12\n#define R_EC_B283 13\n#define R_EC_B409 14\n#define R_EC_B571 15\n#ifndef OPENSSL_NO_RSA\n RSA *rsa_key[RSA_NUM];\n long rsa_c[RSA_NUM][2];\n static unsigned int rsa_bits[RSA_NUM] = {\n 512, 1024, 2048, 3072, 4096, 7680, 15360\n };\n static unsigned char *rsa_data[RSA_NUM] = {\n test512, test1024, test2048, test3072, test4096, test7680, test15360\n };\n static int rsa_data_length[RSA_NUM] = {\n sizeof(test512), sizeof(test1024),\n sizeof(test2048), sizeof(test3072),\n sizeof(test4096), sizeof(test7680),\n sizeof(test15360)\n };\n#endif\n#ifndef OPENSSL_NO_DSA\n DSA *dsa_key[DSA_NUM];\n long dsa_c[DSA_NUM][2];\n static unsigned int dsa_bits[DSA_NUM] = { 512, 1024, 2048 };\n#endif\n#ifndef OPENSSL_NO_EC\n static unsigned int test_curves[EC_NUM] = {\n NID_secp160r1,\n NID_X9_62_prime192v1,\n NID_secp224r1,\n NID_X9_62_prime256v1,\n NID_secp384r1,\n NID_secp521r1,\n NID_sect163k1,\n NID_sect233k1,\n NID_sect283k1,\n NID_sect409k1,\n NID_sect571k1,\n NID_sect163r2,\n NID_sect233r1,\n NID_sect283r1,\n NID_sect409r1,\n NID_sect571r1\n };\n static const char *test_curves_names[EC_NUM] = {\n "secp160r1",\n "nistp192",\n "nistp224",\n "nistp256",\n "nistp384",\n "nistp521",\n "nistk163",\n "nistk233",\n "nistk283",\n "nistk409",\n "nistk571",\n "nistb163",\n "nistb233",\n "nistb283",\n "nistb409",\n "nistb571"\n };\n static int test_curves_bits[EC_NUM] = {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n#endif\n#ifndef OPENSSL_NO_ECDSA\n unsigned char ecdsasig[256];\n unsigned int ecdsasiglen;\n EC_KEY *ecdsa[EC_NUM];\n long ecdsa_c[EC_NUM][2];\n#endif\n#ifndef OPENSSL_NO_ECDH\n EC_KEY *ecdh_a[EC_NUM], *ecdh_b[EC_NUM];\n unsigned char secret_a[MAX_ECDH_SIZE], secret_b[MAX_ECDH_SIZE];\n int secret_size_a, secret_size_b;\n int ecdh_checks = 0;\n int secret_idx = 0;\n long ecdh_c[EC_NUM][2];\n#endif\n int rsa_doit[RSA_NUM];\n int dsa_doit[DSA_NUM];\n#ifndef OPENSSL_NO_ECDSA\n int ecdsa_doit[EC_NUM];\n#endif\n#ifndef OPENSSL_NO_ECDH\n int ecdh_doit[EC_NUM];\n#endif\n int doit[ALGOR_NUM];\n int pr_header = 0;\n const EVP_CIPHER *evp_cipher = NULL;\n const EVP_MD *evp_md = NULL;\n int decrypt = 0;\n#ifndef NO_FORK\n int multi = 0;\n#endif\n int multiblock = 0;\n int misalign = MAX_MISALIGNMENT + 1;\n#ifndef TIMES\n usertime = -1;\n#endif\n apps_startup();\n memset(results, 0, sizeof(results));\n#ifndef OPENSSL_NO_DSA\n memset(dsa_key, 0, sizeof(dsa_key));\n#endif\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa[i] = NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n ecdh_a[i] = NULL;\n ecdh_b[i] = NULL;\n }\n#endif\n if (bio_err == NULL)\n if ((bio_err = BIO_new(BIO_s_file())) != NULL)\n BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT);\n if (!load_config(bio_err, NULL))\n goto end;\n#ifndef OPENSSL_NO_RSA\n memset(rsa_key, 0, sizeof(rsa_key));\n for (i = 0; i < RSA_NUM; i++)\n rsa_key[i] = NULL;\n#endif\n if ((buf_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n if ((buf2_malloc =\n (unsigned char *)OPENSSL_malloc(BUFSIZE + misalign)) == NULL) {\n BIO_printf(bio_err, "out of memory\\n");\n goto end;\n }\n misalign = 0;\n buf = buf_malloc;\n buf2 = buf2_malloc;\n memset(c, 0, sizeof(c));\n memset(DES_iv, 0, sizeof(DES_iv));\n memset(iv, 0, sizeof(iv));\n for (i = 0; i < ALGOR_NUM; i++)\n doit[i] = 0;\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 0;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 0;\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 0;\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 0;\n#endif\n j = 0;\n argc--;\n argv++;\n while (argc) {\n if ((argc > 0) && (strcmp(*argv, "-elapsed") == 0)) {\n usertime = 0;\n j--;\n } else if ((argc > 0) && (strcmp(*argv, "-evp") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no EVP given\\n");\n goto end;\n }\n evp_cipher = EVP_get_cipherbyname(*argv);\n if (!evp_cipher) {\n evp_md = EVP_get_digestbyname(*argv);\n }\n if (!evp_cipher && !evp_md) {\n BIO_printf(bio_err, "%s is an unknown cipher or digest\\n",\n *argv);\n goto end;\n }\n doit[D_EVP] = 1;\n } else if (argc > 0 && !strcmp(*argv, "-decrypt")) {\n decrypt = 1;\n j--;\n }\n#ifndef OPENSSL_NO_ENGINE\n else if ((argc > 0) && (strcmp(*argv, "-engine") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no engine given\\n");\n goto end;\n }\n setup_engine(bio_err, *argv, 0);\n j--;\n }\n#endif\n#ifndef NO_FORK\n else if ((argc > 0) && (strcmp(*argv, "-multi") == 0)) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no multi count given\\n");\n goto end;\n }\n multi = atoi(argv[0]);\n if (multi <= 0) {\n BIO_printf(bio_err, "bad multi count\\n");\n goto end;\n }\n j--;\n }\n#endif\n else if (argc > 0 && !strcmp(*argv, "-mr")) {\n mr = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-mb")) {\n multiblock = 1;\n j--;\n } else if (argc > 0 && !strcmp(*argv, "-misalign")) {\n argc--;\n argv++;\n if (argc == 0) {\n BIO_printf(bio_err, "no misalignment given\\n");\n goto end;\n }\n misalign = atoi(argv[0]);\n if (misalign < 0 || misalign > MAX_MISALIGNMENT) {\n BIO_printf(bio_err,\n "misalignment is outsize permitted range 0-%d\\n",\n MAX_MISALIGNMENT);\n goto end;\n }\n buf = buf_malloc + misalign;\n buf2 = buf2_malloc + misalign;\n j--;\n } else\n#ifndef OPENSSL_NO_MD2\n if (strcmp(*argv, "md2") == 0)\n doit[D_MD2] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MDC2\n if (strcmp(*argv, "mdc2") == 0)\n doit[D_MDC2] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MD4\n if (strcmp(*argv, "md4") == 0)\n doit[D_MD4] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "md5") == 0)\n doit[D_MD5] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_MD5\n if (strcmp(*argv, "hmac") == 0)\n doit[D_HMAC] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_SHA\n if (strcmp(*argv, "sha1") == 0)\n doit[D_SHA1] = 1;\n else if (strcmp(*argv, "sha") == 0)\n doit[D_SHA1] = 1, doit[D_SHA256] = 1, doit[D_SHA512] = 1;\n else\n# ifndef OPENSSL_NO_SHA256\n if (strcmp(*argv, "sha256") == 0)\n doit[D_SHA256] = 1;\n else\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (strcmp(*argv, "sha512") == 0)\n doit[D_SHA512] = 1;\n else\n# endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n if (strcmp(*argv, "whirlpool") == 0)\n doit[D_WHIRLPOOL] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RMD160\n if (strcmp(*argv, "ripemd") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "rmd160") == 0)\n doit[D_RMD160] = 1;\n else if (strcmp(*argv, "ripemd160") == 0)\n doit[D_RMD160] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RC4\n if (strcmp(*argv, "rc4") == 0)\n doit[D_RC4] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des-cbc") == 0)\n doit[D_CBC_DES] = 1;\n else if (strcmp(*argv, "des-ede3") == 0)\n doit[D_EDE3_DES] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes-128-cbc") == 0)\n doit[D_CBC_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-cbc") == 0)\n doit[D_CBC_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-cbc") == 0)\n doit[D_CBC_256_AES] = 1;\n else if (strcmp(*argv, "aes-128-ige") == 0)\n doit[D_IGE_128_AES] = 1;\n else if (strcmp(*argv, "aes-192-ige") == 0)\n doit[D_IGE_192_AES] = 1;\n else if (strcmp(*argv, "aes-256-ige") == 0)\n doit[D_IGE_256_AES] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia-128-cbc") == 0)\n doit[D_CBC_128_CML] = 1;\n else if (strcmp(*argv, "camellia-192-cbc") == 0)\n doit[D_CBC_192_CML] = 1;\n else if (strcmp(*argv, "camellia-256-cbc") == 0)\n doit[D_CBC_256_CML] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RSA\n# if 0\n if (strcmp(*argv, "rsaref") == 0) {\n RSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n j--;\n } else\n# endif\n# ifndef RSA_NULL\n if (strcmp(*argv, "openssl") == 0) {\n RSA_set_default_method(RSA_PKCS1_SSLeay());\n j--;\n } else\n# endif\n#endif\n if (strcmp(*argv, "dsa512") == 0)\n dsa_doit[R_DSA_512] = 2;\n else if (strcmp(*argv, "dsa1024") == 0)\n dsa_doit[R_DSA_1024] = 2;\n else if (strcmp(*argv, "dsa2048") == 0)\n dsa_doit[R_DSA_2048] = 2;\n else if (strcmp(*argv, "rsa512") == 0)\n rsa_doit[R_RSA_512] = 2;\n else if (strcmp(*argv, "rsa1024") == 0)\n rsa_doit[R_RSA_1024] = 2;\n else if (strcmp(*argv, "rsa2048") == 0)\n rsa_doit[R_RSA_2048] = 2;\n else if (strcmp(*argv, "rsa3072") == 0)\n rsa_doit[R_RSA_3072] = 2;\n else if (strcmp(*argv, "rsa4096") == 0)\n rsa_doit[R_RSA_4096] = 2;\n else if (strcmp(*argv, "rsa7680") == 0)\n rsa_doit[R_RSA_7680] = 2;\n else if (strcmp(*argv, "rsa15360") == 0)\n rsa_doit[R_RSA_15360] = 2;\n else\n#ifndef OPENSSL_NO_RC2\n if (strcmp(*argv, "rc2-cbc") == 0)\n doit[D_CBC_RC2] = 1;\n else if (strcmp(*argv, "rc2") == 0)\n doit[D_CBC_RC2] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_RC5\n if (strcmp(*argv, "rc5-cbc") == 0)\n doit[D_CBC_RC5] = 1;\n else if (strcmp(*argv, "rc5") == 0)\n doit[D_CBC_RC5] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_IDEA\n if (strcmp(*argv, "idea-cbc") == 0)\n doit[D_CBC_IDEA] = 1;\n else if (strcmp(*argv, "idea") == 0)\n doit[D_CBC_IDEA] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_SEED\n if (strcmp(*argv, "seed-cbc") == 0)\n doit[D_CBC_SEED] = 1;\n else if (strcmp(*argv, "seed") == 0)\n doit[D_CBC_SEED] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_BF\n if (strcmp(*argv, "bf-cbc") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "blowfish") == 0)\n doit[D_CBC_BF] = 1;\n else if (strcmp(*argv, "bf") == 0)\n doit[D_CBC_BF] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_CAST\n if (strcmp(*argv, "cast-cbc") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast") == 0)\n doit[D_CBC_CAST] = 1;\n else if (strcmp(*argv, "cast5") == 0)\n doit[D_CBC_CAST] = 1;\n else\n#endif\n#ifndef OPENSSL_NO_DES\n if (strcmp(*argv, "des") == 0) {\n doit[D_CBC_DES] = 1;\n doit[D_EDE3_DES] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_AES\n if (strcmp(*argv, "aes") == 0) {\n doit[D_CBC_128_AES] = 1;\n doit[D_CBC_192_AES] = 1;\n doit[D_CBC_256_AES] = 1;\n } else if (strcmp(*argv, "ghash") == 0) {\n doit[D_GHASH] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n if (strcmp(*argv, "camellia") == 0) {\n doit[D_CBC_128_CML] = 1;\n doit[D_CBC_192_CML] = 1;\n doit[D_CBC_256_CML] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_RSA\n if (strcmp(*argv, "rsa") == 0) {\n rsa_doit[R_RSA_512] = 1;\n rsa_doit[R_RSA_1024] = 1;\n rsa_doit[R_RSA_2048] = 1;\n rsa_doit[R_RSA_3072] = 1;\n rsa_doit[R_RSA_4096] = 1;\n rsa_doit[R_RSA_7680] = 1;\n rsa_doit[R_RSA_15360] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_DSA\n if (strcmp(*argv, "dsa") == 0) {\n dsa_doit[R_DSA_512] = 1;\n dsa_doit[R_DSA_1024] = 1;\n dsa_doit[R_DSA_2048] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_ECDSA\n if (strcmp(*argv, "ecdsap160") == 0)\n ecdsa_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdsap192") == 0)\n ecdsa_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdsap224") == 0)\n ecdsa_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdsap256") == 0)\n ecdsa_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdsap384") == 0)\n ecdsa_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdsap521") == 0)\n ecdsa_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdsak163") == 0)\n ecdsa_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdsak233") == 0)\n ecdsa_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdsak283") == 0)\n ecdsa_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdsak409") == 0)\n ecdsa_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdsak571") == 0)\n ecdsa_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdsab163") == 0)\n ecdsa_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdsab233") == 0)\n ecdsa_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdsab283") == 0)\n ecdsa_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdsab409") == 0)\n ecdsa_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdsab571") == 0)\n ecdsa_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdsa") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n } else\n#endif\n#ifndef OPENSSL_NO_ECDH\n if (strcmp(*argv, "ecdhp160") == 0)\n ecdh_doit[R_EC_P160] = 2;\n else if (strcmp(*argv, "ecdhp192") == 0)\n ecdh_doit[R_EC_P192] = 2;\n else if (strcmp(*argv, "ecdhp224") == 0)\n ecdh_doit[R_EC_P224] = 2;\n else if (strcmp(*argv, "ecdhp256") == 0)\n ecdh_doit[R_EC_P256] = 2;\n else if (strcmp(*argv, "ecdhp384") == 0)\n ecdh_doit[R_EC_P384] = 2;\n else if (strcmp(*argv, "ecdhp521") == 0)\n ecdh_doit[R_EC_P521] = 2;\n else if (strcmp(*argv, "ecdhk163") == 0)\n ecdh_doit[R_EC_K163] = 2;\n else if (strcmp(*argv, "ecdhk233") == 0)\n ecdh_doit[R_EC_K233] = 2;\n else if (strcmp(*argv, "ecdhk283") == 0)\n ecdh_doit[R_EC_K283] = 2;\n else if (strcmp(*argv, "ecdhk409") == 0)\n ecdh_doit[R_EC_K409] = 2;\n else if (strcmp(*argv, "ecdhk571") == 0)\n ecdh_doit[R_EC_K571] = 2;\n else if (strcmp(*argv, "ecdhb163") == 0)\n ecdh_doit[R_EC_B163] = 2;\n else if (strcmp(*argv, "ecdhb233") == 0)\n ecdh_doit[R_EC_B233] = 2;\n else if (strcmp(*argv, "ecdhb283") == 0)\n ecdh_doit[R_EC_B283] = 2;\n else if (strcmp(*argv, "ecdhb409") == 0)\n ecdh_doit[R_EC_B409] = 2;\n else if (strcmp(*argv, "ecdhb571") == 0)\n ecdh_doit[R_EC_B571] = 2;\n else if (strcmp(*argv, "ecdh") == 0) {\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n } else\n#endif\n {\n BIO_printf(bio_err, "Error: bad option or value\\n");\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available values:\\n");\n#ifndef OPENSSL_NO_MD2\n BIO_printf(bio_err, "md2 ");\n#endif\n#ifndef OPENSSL_NO_MDC2\n BIO_printf(bio_err, "mdc2 ");\n#endif\n#ifndef OPENSSL_NO_MD4\n BIO_printf(bio_err, "md4 ");\n#endif\n#ifndef OPENSSL_NO_MD5\n BIO_printf(bio_err, "md5 ");\n# ifndef OPENSSL_NO_HMAC\n BIO_printf(bio_err, "hmac ");\n# endif\n#endif\n#ifndef OPENSSL_NO_SHA1\n BIO_printf(bio_err, "sha1 ");\n#endif\n#ifndef OPENSSL_NO_SHA256\n BIO_printf(bio_err, "sha256 ");\n#endif\n#ifndef OPENSSL_NO_SHA512\n BIO_printf(bio_err, "sha512 ");\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n BIO_printf(bio_err, "whirlpool");\n#endif\n#ifndef OPENSSL_NO_RMD160\n BIO_printf(bio_err, "rmd160");\n#endif\n#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RMD160) || \\\n !defined(OPENSSL_NO_WHIRLPOOL)\n BIO_printf(bio_err, "\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea-cbc ");\n#endif\n#ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC5\n BIO_printf(bio_err, "rc5-cbc ");\n#endif\n#ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "bf-cbc");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n BIO_printf(bio_err, "\\n");\n#endif\n#ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des-cbc des-ede3 ");\n#endif\n#ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes-128-cbc aes-192-cbc aes-256-cbc ");\n BIO_printf(bio_err, "aes-128-ige aes-192-ige aes-256-ige ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err,\n "camellia-128-cbc camellia-192-cbc camellia-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC4\n BIO_printf(bio_err, "rc4");\n#endif\n BIO_printf(bio_err, "\\n");\n#ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err,\n "rsa512 rsa1024 rsa2048 rsa3072 rsa4096\\n");\n BIO_printf(bio_err, "rsa7680 rsa15360\\n");\n#endif\n#ifndef OPENSSL_NO_DSA\n BIO_printf(bio_err, "dsa512 dsa1024 dsa2048\\n");\n#endif\n#ifndef OPENSSL_NO_ECDSA\n BIO_printf(bio_err, "ecdsap160 ecdsap192 ecdsap224 "\n "ecdsap256 ecdsap384 ecdsap521\\n");\n BIO_printf(bio_err,\n "ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n BIO_printf(bio_err,\n "ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n BIO_printf(bio_err, "ecdsa\\n");\n#endif\n#ifndef OPENSSL_NO_ECDH\n BIO_printf(bio_err, "ecdhp160 ecdhp192 ecdhp224 "\n "ecdhp256 ecdhp384 ecdhp521\\n");\n BIO_printf(bio_err,\n "ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n BIO_printf(bio_err,\n "ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n BIO_printf(bio_err, "ecdh\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n BIO_printf(bio_err, "idea ");\n#endif\n#ifndef OPENSSL_NO_SEED\n BIO_printf(bio_err, "seed ");\n#endif\n#ifndef OPENSSL_NO_RC2\n BIO_printf(bio_err, "rc2 ");\n#endif\n#ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "des ");\n#endif\n#ifndef OPENSSL_NO_AES\n BIO_printf(bio_err, "aes ");\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n BIO_printf(bio_err, "camellia ");\n#endif\n#ifndef OPENSSL_NO_RSA\n BIO_printf(bio_err, "rsa ");\n#endif\n#ifndef OPENSSL_NO_BF\n BIO_printf(bio_err, "blowfish");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_SEED) || \\\n !defined(OPENSSL_NO_RC2) || !defined(OPENSSL_NO_DES) || \\\n !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_BF) || \\\n !defined(OPENSSL_NO_AES) || !defined(OPENSSL_NO_CAMELLIA)\n BIO_printf(bio_err, "\\n");\n#endif\n BIO_printf(bio_err, "\\n");\n BIO_printf(bio_err, "Available options:\\n");\n#if defined(TIMES) || defined(USE_TOD)\n BIO_printf(bio_err, "-elapsed "\n "measure time in real time instead of CPU user time.\\n");\n#endif\n#ifndef OPENSSL_NO_ENGINE\n BIO_printf(bio_err,\n "-engine e "\n "use engine e, possibly a hardware device.\\n");\n#endif\n BIO_printf(bio_err, "-evp e " "use EVP e.\\n");\n BIO_printf(bio_err,\n "-decrypt "\n "time decryption instead of encryption (only EVP).\\n");\n BIO_printf(bio_err,\n "-mr "\n "produce machine readable output.\\n");\n BIO_printf(bio_err,\n "-mb "\n "perform multi-block benchmark (for specific ciphers)\\n");\n BIO_printf(bio_err,\n "-misalign n "\n "perform benchmark with misaligned data\\n");\n#ifndef NO_FORK\n BIO_printf(bio_err,\n "-multi n " "run n benchmarks in parallel.\\n");\n#endif\n goto end;\n }\n argc--;\n argv++;\n j++;\n }\n#ifndef NO_FORK\n if (multi && do_multi(multi))\n goto show_res;\n#endif\n if (j == 0) {\n for (i = 0; i < ALGOR_NUM; i++) {\n if (i != D_EVP)\n doit[i] = 1;\n }\n for (i = 0; i < RSA_NUM; i++)\n rsa_doit[i] = 1;\n for (i = 0; i < DSA_NUM; i++)\n dsa_doit[i] = 1;\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n ecdsa_doit[i] = 1;\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++)\n ecdh_doit[i] = 1;\n#endif\n }\n for (i = 0; i < ALGOR_NUM; i++)\n if (doit[i])\n pr_header++;\n if (usertime == 0 && !mr)\n BIO_printf(bio_err,\n "You have chosen to measure elapsed time "\n "instead of user CPU time.\\n");\n#ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++) {\n const unsigned char *p;\n p = rsa_data[i];\n rsa_key[i] = d2i_RSAPrivateKey(NULL, &p, rsa_data_length[i]);\n if (rsa_key[i] == NULL) {\n BIO_printf(bio_err, "internal error loading RSA key number %d\\n",\n i);\n goto end;\n }\n# if 0\n else {\n BIO_printf(bio_err,\n mr ? "+RK:%d:"\n : "Loaded RSA key, %d bit modulus and e= 0x",\n BN_num_bits(rsa_key[i]->n));\n BN_print(bio_err, rsa_key[i]->e);\n BIO_printf(bio_err, "\\n");\n }\n# endif\n }\n#endif\n#ifndef OPENSSL_NO_DSA\n dsa_key[0] = get_dsa512();\n dsa_key[1] = get_dsa1024();\n dsa_key[2] = get_dsa2048();\n#endif\n#ifndef OPENSSL_NO_DES\n DES_set_key_unchecked(&key, &sch);\n DES_set_key_unchecked(&key2, &sch2);\n DES_set_key_unchecked(&key3, &sch3);\n#endif\n#ifndef OPENSSL_NO_AES\n AES_set_encrypt_key(key16, 128, &aes_ks1);\n AES_set_encrypt_key(key24, 192, &aes_ks2);\n AES_set_encrypt_key(key32, 256, &aes_ks3);\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n Camellia_set_key(key16, 128, &camellia_ks1);\n Camellia_set_key(ckey24, 192, &camellia_ks2);\n Camellia_set_key(ckey32, 256, &camellia_ks3);\n#endif\n#ifndef OPENSSL_NO_IDEA\n idea_set_encrypt_key(key16, &idea_ks);\n#endif\n#ifndef OPENSSL_NO_SEED\n SEED_set_key(key16, &seed_ks);\n#endif\n#ifndef OPENSSL_NO_RC4\n RC4_set_key(&rc4_ks, 16, key16);\n#endif\n#ifndef OPENSSL_NO_RC2\n RC2_set_key(&rc2_ks, 16, key16, 128);\n#endif\n#ifndef OPENSSL_NO_RC5\n RC5_32_set_key(&rc5_ks, 16, key16, 12);\n#endif\n#ifndef OPENSSL_NO_BF\n BF_set_key(&bf_ks, 16, key16);\n#endif\n#ifndef OPENSSL_NO_CAST\n CAST_set_key(&cast_ks, 16, key16);\n#endif\n#ifndef OPENSSL_NO_RSA\n memset(rsa_c, 0, sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n# ifndef OPENSSL_NO_DES\n BIO_printf(bio_err, "First we calculate the approximate speed ...\\n");\n count = 10;\n do {\n long it;\n count *= 2;\n Time_F(START);\n for (it = count; it; it--)\n DES_ecb_encrypt((DES_cblock *)buf,\n (DES_cblock *)buf, &sch, DES_ENCRYPT);\n d = Time_F(STOP);\n } while (d < 3);\n save_count = count;\n c[D_MD2][0] = count / 10;\n c[D_MDC2][0] = count / 10;\n c[D_MD4][0] = count;\n c[D_MD5][0] = count;\n c[D_HMAC][0] = count;\n c[D_SHA1][0] = count;\n c[D_RMD160][0] = count;\n c[D_RC4][0] = count * 5;\n c[D_CBC_DES][0] = count;\n c[D_EDE3_DES][0] = count / 3;\n c[D_CBC_IDEA][0] = count;\n c[D_CBC_SEED][0] = count;\n c[D_CBC_RC2][0] = count;\n c[D_CBC_RC5][0] = count;\n c[D_CBC_BF][0] = count;\n c[D_CBC_CAST][0] = count;\n c[D_CBC_128_AES][0] = count;\n c[D_CBC_192_AES][0] = count;\n c[D_CBC_256_AES][0] = count;\n c[D_CBC_128_CML][0] = count;\n c[D_CBC_192_CML][0] = count;\n c[D_CBC_256_CML][0] = count;\n c[D_SHA256][0] = count;\n c[D_SHA512][0] = count;\n c[D_WHIRLPOOL][0] = count;\n c[D_IGE_128_AES][0] = count;\n c[D_IGE_192_AES][0] = count;\n c[D_IGE_256_AES][0] = count;\n c[D_GHASH][0] = count;\n for (i = 1; i < SIZE_NUM; i++) {\n long l0, l1;\n l0 = (long)lengths[0];\n l1 = (long)lengths[i];\n c[D_MD2][i] = c[D_MD2][0] * 4 * l0 / l1;\n c[D_MDC2][i] = c[D_MDC2][0] * 4 * l0 / l1;\n c[D_MD4][i] = c[D_MD4][0] * 4 * l0 / l1;\n c[D_MD5][i] = c[D_MD5][0] * 4 * l0 / l1;\n c[D_HMAC][i] = c[D_HMAC][0] * 4 * l0 / l1;\n c[D_SHA1][i] = c[D_SHA1][0] * 4 * l0 / l1;\n c[D_RMD160][i] = c[D_RMD160][0] * 4 * l0 / l1;\n c[D_SHA256][i] = c[D_SHA256][0] * 4 * l0 / l1;\n c[D_SHA512][i] = c[D_SHA512][0] * 4 * l0 / l1;\n c[D_WHIRLPOOL][i] = c[D_WHIRLPOOL][0] * 4 * l0 / l1;\n l0 = (long)lengths[i - 1];\n c[D_RC4][i] = c[D_RC4][i - 1] * l0 / l1;\n c[D_CBC_DES][i] = c[D_CBC_DES][i - 1] * l0 / l1;\n c[D_EDE3_DES][i] = c[D_EDE3_DES][i - 1] * l0 / l1;\n c[D_CBC_IDEA][i] = c[D_CBC_IDEA][i - 1] * l0 / l1;\n c[D_CBC_SEED][i] = c[D_CBC_SEED][i - 1] * l0 / l1;\n c[D_CBC_RC2][i] = c[D_CBC_RC2][i - 1] * l0 / l1;\n c[D_CBC_RC5][i] = c[D_CBC_RC5][i - 1] * l0 / l1;\n c[D_CBC_BF][i] = c[D_CBC_BF][i - 1] * l0 / l1;\n c[D_CBC_CAST][i] = c[D_CBC_CAST][i - 1] * l0 / l1;\n c[D_CBC_128_AES][i] = c[D_CBC_128_AES][i - 1] * l0 / l1;\n c[D_CBC_192_AES][i] = c[D_CBC_192_AES][i - 1] * l0 / l1;\n c[D_CBC_256_AES][i] = c[D_CBC_256_AES][i - 1] * l0 / l1;\n c[D_CBC_128_CML][i] = c[D_CBC_128_CML][i - 1] * l0 / l1;\n c[D_CBC_192_CML][i] = c[D_CBC_192_CML][i - 1] * l0 / l1;\n c[D_CBC_256_CML][i] = c[D_CBC_256_CML][i - 1] * l0 / l1;\n c[D_IGE_128_AES][i] = c[D_IGE_128_AES][i - 1] * l0 / l1;\n c[D_IGE_192_AES][i] = c[D_IGE_192_AES][i - 1] * l0 / l1;\n c[D_IGE_256_AES][i] = c[D_IGE_256_AES][i - 1] * l0 / l1;\n }\n# ifndef OPENSSL_NO_RSA\n rsa_c[R_RSA_512][0] = count / 2000;\n rsa_c[R_RSA_512][1] = count / 400;\n for (i = 1; i < RSA_NUM; i++) {\n rsa_c[i][0] = rsa_c[i - 1][0] / 8;\n rsa_c[i][1] = rsa_c[i - 1][1] / 4;\n if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n rsa_doit[i] = 0;\n else {\n if (rsa_c[i][0] == 0) {\n rsa_c[i][0] = 1;\n rsa_c[i][1] = 20;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_DSA\n dsa_c[R_DSA_512][0] = count / 1000;\n dsa_c[R_DSA_512][1] = count / 1000 / 2;\n for (i = 1; i < DSA_NUM; i++) {\n dsa_c[i][0] = dsa_c[i - 1][0] / 4;\n dsa_c[i][1] = dsa_c[i - 1][1] / 4;\n if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n dsa_doit[i] = 0;\n else {\n if (dsa_c[i] == 0) {\n dsa_c[i][0] = 1;\n dsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDSA\n ecdsa_c[R_EC_P160][0] = count / 1000;\n ecdsa_c[R_EC_P160][1] = count / 1000 / 2;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_K163][0] = count / 1000;\n ecdsa_c[R_EC_K163][1] = count / 1000 / 2;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n ecdsa_c[R_EC_B163][0] = count / 1000;\n ecdsa_c[R_EC_B163][1] = count / 1000 / 2;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdsa_c[i][0] = ecdsa_c[i - 1][0] / 2;\n ecdsa_c[i][1] = ecdsa_c[i - 1][1] / 2;\n if ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n ecdsa_doit[i] = 0;\n else {\n if (ecdsa_c[i] == 0) {\n ecdsa_c[i][0] = 1;\n ecdsa_c[i][1] = 1;\n }\n }\n }\n# endif\n# ifndef OPENSSL_NO_ECDH\n ecdh_c[R_EC_P160][0] = count / 1000;\n ecdh_c[R_EC_P160][1] = count / 1000;\n for (i = R_EC_P192; i <= R_EC_P521; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_K163][0] = count / 1000;\n ecdh_c[R_EC_K163][1] = count / 1000;\n for (i = R_EC_K233; i <= R_EC_K571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n ecdh_c[R_EC_B163][0] = count / 1000;\n ecdh_c[R_EC_B163][1] = count / 1000;\n for (i = R_EC_B233; i <= R_EC_B571; i++) {\n ecdh_c[i][0] = ecdh_c[i - 1][0] / 2;\n ecdh_c[i][1] = ecdh_c[i - 1][1] / 2;\n if ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n ecdh_doit[i] = 0;\n else {\n if (ecdh_c[i] == 0) {\n ecdh_c[i][0] = 1;\n ecdh_c[i][1] = 1;\n }\n }\n }\n# endif\n# define COND(d) (count < (d))\n# define COUNT(d) (d)\n# else\n# error "You cannot disable DES on systems without SIGALRM."\n# endif\n#else\n# define COND(c) (run && count<0x7fffffff)\n# define COUNT(d) (count)\n# ifndef _WIN32\n signal(SIGALRM, sig_done);\n# endif\n#endif\n#ifndef OPENSSL_NO_MD2\n if (doit[D_MD2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD2], c[D_MD2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(md2[0]), NULL,\n EVP_md2(), NULL);\n d = Time_F(STOP);\n print_result(D_MD2, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_MDC2\n if (doit[D_MDC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MDC2], c[D_MDC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MDC2][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(mdc2[0]), NULL,\n EVP_mdc2(), NULL);\n d = Time_F(STOP);\n print_result(D_MDC2, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_MD4\n if (doit[D_MD4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD4], c[D_MD4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD4][j]); count++)\n EVP_Digest(&(buf[0]), (unsigned long)lengths[j], &(md4[0]),\n NULL, EVP_md4(), NULL);\n d = Time_F(STOP);\n print_result(D_MD4, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_MD5\n if (doit[D_MD5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_MD5], c[D_MD5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_MD5][j]); count++)\n MD5(buf, lengths[j], md5);\n d = Time_F(STOP);\n print_result(D_MD5, j, count, d);\n }\n }\n#endif\n#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n if (doit[D_HMAC]) {\n HMAC_CTX hctx;\n HMAC_CTX_init(&hctx);\n HMAC_Init_ex(&hctx, (unsigned char *)"This is a key...",\n 16, EVP_md5(), NULL);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_HMAC], c[D_HMAC][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_HMAC][j]); count++) {\n HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL);\n HMAC_Update(&hctx, buf, lengths[j]);\n HMAC_Final(&hctx, &(hmac[0]), NULL);\n }\n d = Time_F(STOP);\n print_result(D_HMAC, j, count, d);\n }\n HMAC_CTX_cleanup(&hctx);\n }\n#endif\n#ifndef OPENSSL_NO_SHA\n if (doit[D_SHA1]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA1], c[D_SHA1][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA1][j]); count++)\n# if 0\n EVP_Digest(buf, (unsigned long)lengths[j], &(sha[0]), NULL,\n EVP_sha1(), NULL);\n# else\n SHA1(buf, lengths[j], sha);\n# endif\n d = Time_F(STOP);\n print_result(D_SHA1, j, count, d);\n }\n }\n# ifndef OPENSSL_NO_SHA256\n if (doit[D_SHA256]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA256], c[D_SHA256][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA256][j]); count++)\n SHA256(buf, lengths[j], sha256);\n d = Time_F(STOP);\n print_result(D_SHA256, j, count, d);\n }\n }\n# endif\n# ifndef OPENSSL_NO_SHA512\n if (doit[D_SHA512]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_SHA512], c[D_SHA512][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_SHA512][j]); count++)\n SHA512(buf, lengths[j], sha512);\n d = Time_F(STOP);\n print_result(D_SHA512, j, count, d);\n }\n }\n# endif\n#endif\n#ifndef OPENSSL_NO_WHIRLPOOL\n if (doit[D_WHIRLPOOL]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_WHIRLPOOL], c[D_WHIRLPOOL][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_WHIRLPOOL][j]); count++)\n WHIRLPOOL(buf, lengths[j], whirlpool);\n d = Time_F(STOP);\n print_result(D_WHIRLPOOL, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RMD160\n if (doit[D_RMD160]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RMD160], c[D_RMD160][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RMD160][j]); count++)\n EVP_Digest(buf, (unsigned long)lengths[j], &(rmd160[0]), NULL,\n EVP_ripemd160(), NULL);\n d = Time_F(STOP);\n print_result(D_RMD160, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RC4\n if (doit[D_RC4]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_RC4], c[D_RC4][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_RC4][j]); count++)\n RC4(&rc4_ks, (unsigned int)lengths[j], buf, buf);\n d = Time_F(STOP);\n print_result(D_RC4, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_DES\n if (doit[D_CBC_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_DES], c[D_CBC_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_DES][j]); count++)\n DES_ncbc_encrypt(buf, buf, lengths[j], &sch,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_DES, j, count, d);\n }\n }\n if (doit[D_EDE3_DES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_EDE3_DES], c[D_EDE3_DES][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_EDE3_DES][j]); count++)\n DES_ede3_cbc_encrypt(buf, buf, lengths[j],\n &sch, &sch2, &sch3,\n &DES_iv, DES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_EDE3_DES, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_AES\n if (doit[D_CBC_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_AES], c[D_CBC_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_AES, j, count, d);\n }\n }\n if (doit[D_CBC_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_AES], c[D_CBC_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_AES, j, count, d);\n }\n }\n if (doit[D_CBC_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_AES], c[D_CBC_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_AES][j]); count++)\n AES_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_AES, j, count, d);\n }\n }\n if (doit[D_IGE_128_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_128_AES], c[D_IGE_128_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_128_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks1,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_128_AES, j, count, d);\n }\n }\n if (doit[D_IGE_192_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_192_AES], c[D_IGE_192_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_192_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks2,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_192_AES, j, count, d);\n }\n }\n if (doit[D_IGE_256_AES]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_IGE_256_AES], c[D_IGE_256_AES][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_IGE_256_AES][j]); count++)\n AES_ige_encrypt(buf, buf2,\n (unsigned long)lengths[j], &aes_ks3,\n iv, AES_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_IGE_256_AES, j, count, d);\n }\n }\n if (doit[D_GHASH]) {\n GCM128_CONTEXT *ctx =\n CRYPTO_gcm128_new(&aes_ks1, (block128_f) AES_encrypt);\n CRYPTO_gcm128_setiv(ctx, (unsigned char *)"0123456789ab", 12);\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_GHASH], c[D_GHASH][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_GHASH][j]); count++)\n CRYPTO_gcm128_aad(ctx, buf, lengths[j]);\n d = Time_F(STOP);\n print_result(D_GHASH, j, count, d);\n }\n CRYPTO_gcm128_release(ctx);\n }\n#endif\n#ifndef OPENSSL_NO_CAMELLIA\n if (doit[D_CBC_128_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_128_CML], c[D_CBC_128_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_128_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks1,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_128_CML, j, count, d);\n }\n }\n if (doit[D_CBC_192_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_192_CML], c[D_CBC_192_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_192_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks2,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_192_CML, j, count, d);\n }\n }\n if (doit[D_CBC_256_CML]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_256_CML], c[D_CBC_256_CML][j],\n lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_256_CML][j]); count++)\n Camellia_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &camellia_ks3,\n iv, CAMELLIA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_256_CML, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_IDEA\n if (doit[D_CBC_IDEA]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_IDEA], c[D_CBC_IDEA][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_IDEA][j]); count++)\n idea_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &idea_ks,\n iv, IDEA_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_IDEA, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_SEED\n if (doit[D_CBC_SEED]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_SEED], c[D_CBC_SEED][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_SEED][j]); count++)\n SEED_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &seed_ks, iv, 1);\n d = Time_F(STOP);\n print_result(D_CBC_SEED, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RC2\n if (doit[D_CBC_RC2]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC2], c[D_CBC_RC2][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC2][j]); count++)\n RC2_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc2_ks,\n iv, RC2_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC2, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_RC5\n if (doit[D_CBC_RC5]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_RC5], c[D_CBC_RC5][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_RC5][j]); count++)\n RC5_32_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &rc5_ks,\n iv, RC5_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_RC5, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_BF\n if (doit[D_CBC_BF]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_BF], c[D_CBC_BF][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_BF][j]); count++)\n BF_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &bf_ks,\n iv, BF_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_BF, j, count, d);\n }\n }\n#endif\n#ifndef OPENSSL_NO_CAST\n if (doit[D_CBC_CAST]) {\n for (j = 0; j < SIZE_NUM; j++) {\n print_message(names[D_CBC_CAST], c[D_CBC_CAST][j], lengths[j]);\n Time_F(START);\n for (count = 0, run = 1; COND(c[D_CBC_CAST][j]); count++)\n CAST_cbc_encrypt(buf, buf,\n (unsigned long)lengths[j], &cast_ks,\n iv, CAST_ENCRYPT);\n d = Time_F(STOP);\n print_result(D_CBC_CAST, j, count, d);\n }\n }\n#endif\n if (doit[D_EVP]) {\n#ifdef EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK\n if (multiblock && evp_cipher) {\n if (!\n (EVP_CIPHER_flags(evp_cipher) &\n EVP_CIPH_FLAG_TLS1_1_MULTIBLOCK)) {\n fprintf(stderr, "%s is not multi-block capable\\n",\n OBJ_nid2ln(evp_cipher->nid));\n goto end;\n }\n multiblock_speed(evp_cipher);\n mret = 0;\n goto end;\n }\n#endif\n for (j = 0; j < SIZE_NUM; j++) {\n if (evp_cipher) {\n EVP_CIPHER_CTX ctx;\n int outl;\n names[D_EVP] = OBJ_nid2ln(evp_cipher->nid);\n print_message(names[D_EVP], save_count, lengths[j]);\n EVP_CIPHER_CTX_init(&ctx);\n if (decrypt)\n EVP_DecryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n else\n EVP_EncryptInit_ex(&ctx, evp_cipher, NULL, key16, iv);\n EVP_CIPHER_CTX_set_padding(&ctx, 0);\n Time_F(START);\n if (decrypt)\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_DecryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n else\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]);\n count++)\n EVP_EncryptUpdate(&ctx, buf, &outl, buf, lengths[j]);\n if (decrypt)\n EVP_DecryptFinal_ex(&ctx, buf, &outl);\n else\n EVP_EncryptFinal_ex(&ctx, buf, &outl);\n d = Time_F(STOP);\n EVP_CIPHER_CTX_cleanup(&ctx);\n }\n if (evp_md) {\n names[D_EVP] = OBJ_nid2ln(evp_md->type);\n print_message(names[D_EVP], save_count, lengths[j]);\n Time_F(START);\n for (count = 0, run = 1;\n COND(save_count * 4 * lengths[0] / lengths[j]); count++)\n EVP_Digest(buf, lengths[j], &(md[0]), NULL, evp_md, NULL);\n d = Time_F(STOP);\n }\n print_result(D_EVP, j, count, d);\n }\n }\n#ifndef OPENSSL_SYS_WIN32\n#endif\n RAND_pseudo_bytes(buf, 36);\n#ifndef OPENSSL_NO_RSA\n for (j = 0; j < RSA_NUM; j++) {\n int ret;\n if (!rsa_doit[j])\n continue;\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2, &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "RSA sign failure. No RSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("private", "rsa",\n rsa_c[j][0], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][0]); count++) {\n ret = RSA_sign(NID_md5_sha1, buf, 36, buf2,\n &rsa_num, rsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "RSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R1:%ld:%d:%.2f\\n"\n : "%ld %d bit private RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n# if 1\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2, rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "RSA verify failure. No RSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_doit[j] = 0;\n } else {\n pkey_print_message("public", "rsa",\n rsa_c[j][1], rsa_bits[j], RSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(rsa_c[j][1]); count++) {\n ret = RSA_verify(NID_md5_sha1, buf, 36, buf2,\n rsa_num, rsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "RSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R2:%ld:%d:%.2f\\n"\n : "%ld %d bit public RSA\'s in %.2fs\\n",\n count, rsa_bits[j], d);\n rsa_results[j][1] = d / (double)count;\n }\n# endif\n if (rsa_count <= 1) {\n for (j++; j < RSA_NUM; j++)\n rsa_doit[j] = 0;\n }\n }\n#endif\n RAND_pseudo_bytes(buf, 20);\n#ifndef OPENSSL_NO_DSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < DSA_NUM; j++) {\n unsigned int kk;\n int ret;\n if (!dsa_doit[j])\n continue;\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "DSA sign failure. No DSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "dsa",\n dsa_c[j][0], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][0]); count++) {\n ret = DSA_sign(EVP_PKEY_DSA, buf, 20, buf2, &kk, dsa_key[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "DSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R3:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA signs in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err,\n "DSA verify failure. No DSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n dsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "dsa",\n dsa_c[j][1], dsa_bits[j], DSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(dsa_c[j][1]); count++) {\n ret = DSA_verify(EVP_PKEY_DSA, buf, 20, buf2, kk, dsa_key[j]);\n if (ret <= 0) {\n BIO_printf(bio_err, "DSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R4:%ld:%d:%.2f\\n"\n : "%ld %d bit DSA verify in %.2fs\\n",\n count, dsa_bits[j], d);\n dsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < DSA_NUM; j++)\n dsa_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDSA\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n int ret;\n if (!ecdsa_doit[j])\n continue;\n ecdsa[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if (ecdsa[j] == NULL) {\n BIO_printf(bio_err, "ECDSA failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n# if 1\n EC_KEY_precompute_mult(ecdsa[j], NULL);\n# endif\n EC_KEY_generate_key(ecdsa[j]);\n ret = ECDSA_sign(0, buf, 20, ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err,\n "ECDSA sign failure. No ECDSA sign will be done.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n pkey_print_message("sign", "ecdsa",\n ecdsa_c[j][0],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][0]); count++) {\n ret = ECDSA_sign(0, buf, 20,\n ecdsasig, &ecdsasiglen, ecdsa[j]);\n if (ret == 0) {\n BIO_printf(bio_err, "ECDSA sign failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R5:%ld:%d:%.2f\\n" :\n "%ld %d bit ECDSA signs in %.2fs \\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n ret = ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err,\n "ECDSA verify failure. No ECDSA verify will be done.\\n");\n ERR_print_errors(bio_err);\n ecdsa_doit[j] = 0;\n } else {\n pkey_print_message("verify", "ecdsa",\n ecdsa_c[j][1],\n test_curves_bits[j], ECDSA_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdsa_c[j][1]); count++) {\n ret =\n ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen,\n ecdsa[j]);\n if (ret != 1) {\n BIO_printf(bio_err, "ECDSA verify failure\\n");\n ERR_print_errors(bio_err);\n count = 1;\n break;\n }\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R6:%ld:%d:%.2f\\n"\n : "%ld %d bit ECDSA verify in %.2fs\\n",\n count, test_curves_bits[j], d);\n ecdsa_results[j][1] = d / (double)count;\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdsa_doit[j] = 0;\n }\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDH\n if (RAND_status() != 1) {\n RAND_seed(rnd_seed, sizeof rnd_seed);\n rnd_fake = 1;\n }\n for (j = 0; j < EC_NUM; j++) {\n if (!ecdh_doit[j])\n continue;\n ecdh_a[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n ecdh_b[j] = EC_KEY_new_by_curve_name(test_curves[j]);\n if ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL)) {\n BIO_printf(bio_err, "ECDH failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n if (!EC_KEY_generate_key(ecdh_a[j]) ||\n !EC_KEY_generate_key(ecdh_b[j])) {\n BIO_printf(bio_err, "ECDH key generation failure.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n } else {\n int field_size, outlen;\n void *(*kdf) (const void *in, size_t inlen, void *out,\n size_t *xoutlen);\n field_size =\n EC_GROUP_get_degree(EC_KEY_get0_group(ecdh_a[j]));\n if (field_size <= 24 * 8) {\n outlen = KDF1_SHA1_len;\n kdf = KDF1_SHA1;\n } else {\n outlen = (field_size + 7) / 8;\n kdf = NULL;\n }\n secret_size_a =\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n secret_size_b =\n ECDH_compute_key(secret_b, outlen,\n EC_KEY_get0_public_key(ecdh_a[j]),\n ecdh_b[j], kdf);\n if (secret_size_a != secret_size_b)\n ecdh_checks = 0;\n else\n ecdh_checks = 1;\n for (secret_idx = 0; (secret_idx < secret_size_a)\n && (ecdh_checks == 1); secret_idx++) {\n if (secret_a[secret_idx] != secret_b[secret_idx])\n ecdh_checks = 0;\n }\n if (ecdh_checks == 0) {\n BIO_printf(bio_err, "ECDH computations don\'t match.\\n");\n ERR_print_errors(bio_err);\n rsa_count = 1;\n }\n pkey_print_message("", "ecdh",\n ecdh_c[j][0],\n test_curves_bits[j], ECDH_SECONDS);\n Time_F(START);\n for (count = 0, run = 1; COND(ecdh_c[j][0]); count++) {\n ECDH_compute_key(secret_a, outlen,\n EC_KEY_get0_public_key(ecdh_b[j]),\n ecdh_a[j], kdf);\n }\n d = Time_F(STOP);\n BIO_printf(bio_err,\n mr ? "+R7:%ld:%d:%.2f\\n" :\n "%ld %d-bit ECDH ops in %.2fs\\n", count,\n test_curves_bits[j], d);\n ecdh_results[j][0] = d / (double)count;\n rsa_count = count;\n }\n }\n if (rsa_count <= 1) {\n for (j++; j < EC_NUM; j++)\n ecdh_doit[j] = 0;\n }\n }\n if (rnd_fake)\n RAND_cleanup();\n#endif\n#ifndef NO_FORK\n show_res:\n#endif\n if (!mr) {\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout, "%s\\n", SSLeay_version(SSLEAY_BUILT_ON));\n printf("options:");\n printf("%s ", BN_options());\n#ifndef OPENSSL_NO_MD2\n printf("%s ", MD2_options());\n#endif\n#ifndef OPENSSL_NO_RC4\n printf("%s ", RC4_options());\n#endif\n#ifndef OPENSSL_NO_DES\n printf("%s ", DES_options());\n#endif\n#ifndef OPENSSL_NO_AES\n printf("%s ", AES_options());\n#endif\n#ifndef OPENSSL_NO_IDEA\n printf("%s ", idea_options());\n#endif\n#ifndef OPENSSL_NO_BF\n printf("%s ", BF_options());\n#endif\n fprintf(stdout, "\\n%s\\n", SSLeay_version(SSLEAY_CFLAGS));\n }\n if (pr_header) {\n if (mr)\n fprintf(stdout, "+H");\n else {\n fprintf(stdout,\n "The \'numbers\' are in 1000s of bytes per second processed.\\n");\n fprintf(stdout, "type ");\n }\n for (j = 0; j < SIZE_NUM; j++)\n fprintf(stdout, mr ? ":%d" : "%7d bytes", lengths[j]);\n fprintf(stdout, "\\n");\n }\n for (k = 0; k < ALGOR_NUM; k++) {\n if (!doit[k])\n continue;\n if (mr)\n fprintf(stdout, "+F:%d:%s", k, names[k]);\n else\n fprintf(stdout, "%-13s", names[k]);\n for (j = 0; j < SIZE_NUM; j++) {\n if (results[k][j] > 10000 && !mr)\n fprintf(stdout, " %11.2fk", results[k][j] / 1e3);\n else\n fprintf(stdout, mr ? ":%.2f" : " %11.2f ", results[k][j]);\n }\n fprintf(stdout, "\\n");\n }\n#ifndef OPENSSL_NO_RSA\n j = 1;\n for (k = 0; k < RSA_NUM; k++) {\n if (!rsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F2:%u:%u:%f:%f\\n",\n k, rsa_bits[k], rsa_results[k][0], rsa_results[k][1]);\n else\n fprintf(stdout, "rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n rsa_bits[k], rsa_results[k][0], rsa_results[k][1],\n 1.0 / rsa_results[k][0], 1.0 / rsa_results[k][1]);\n }\n#endif\n#ifndef OPENSSL_NO_DSA\n j = 1;\n for (k = 0; k < DSA_NUM; k++) {\n if (!dsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%18ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F3:%u:%u:%f:%f\\n",\n k, dsa_bits[k], dsa_results[k][0], dsa_results[k][1]);\n else\n fprintf(stdout, "dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\\n",\n dsa_bits[k], dsa_results[k][0], dsa_results[k][1],\n 1.0 / dsa_results[k][0], 1.0 / dsa_results[k][1]);\n }\n#endif\n#ifndef OPENSSL_NO_ECDSA\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdsa_doit[k])\n continue;\n if (j && !mr) {\n printf("%30ssign verify sign/s verify/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F4:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdsa_results[k][0], ecdsa_results[k][1]);\n else\n fprintf(stdout,\n "%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdsa_results[k][0], ecdsa_results[k][1],\n 1.0 / ecdsa_results[k][0], 1.0 / ecdsa_results[k][1]);\n }\n#endif\n#ifndef OPENSSL_NO_ECDH\n j = 1;\n for (k = 0; k < EC_NUM; k++) {\n if (!ecdh_doit[k])\n continue;\n if (j && !mr) {\n printf("%30sop op/s\\n", " ");\n j = 0;\n }\n if (mr)\n fprintf(stdout, "+F5:%u:%u:%f:%f\\n",\n k, test_curves_bits[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n else\n fprintf(stdout, "%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n test_curves_bits[k],\n test_curves_names[k],\n ecdh_results[k][0], 1.0 / ecdh_results[k][0]);\n }\n#endif\n mret = 0;\n end:\n ERR_print_errors(bio_err);\n if (buf_malloc != NULL)\n OPENSSL_free(buf_malloc);\n if (buf2_malloc != NULL)\n OPENSSL_free(buf2_malloc);\n#ifndef OPENSSL_NO_RSA\n for (i = 0; i < RSA_NUM; i++)\n if (rsa_key[i] != NULL)\n RSA_free(rsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_DSA\n for (i = 0; i < DSA_NUM; i++)\n if (dsa_key[i] != NULL)\n DSA_free(dsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n for (i = 0; i < EC_NUM; i++)\n if (ecdsa[i] != NULL)\n EC_KEY_free(ecdsa[i]);\n#endif\n#ifndef OPENSSL_NO_ECDH\n for (i = 0; i < EC_NUM; i++) {\n if (ecdh_a[i] != NULL)\n EC_KEY_free(ecdh_a[i]);\n if (ecdh_b[i] != NULL)\n EC_KEY_free(ecdh_b[i]);\n }\n#endif\n apps_shutdown();\n OPENSSL_EXIT(mret);\n}'] |
35,078 | 0 | https://github.com/libav/libav/blob/0bf511d579c7b21f1244eec688abf571ca1235bd/libavcodec/utils.c/#L552 | void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)
{
int i;
InternalBuffer *buf, *last;
AVCodecInternal *avci = s->internal;
assert(s->codec_type == AVMEDIA_TYPE_VIDEO);
assert(pic->type == FF_BUFFER_TYPE_INTERNAL);
assert(avci->buffer_count);
if (avci->buffer) {
buf = NULL;
for (i = 0; i < avci->buffer_count; i++) {
buf = &avci->buffer[i];
if (buf->data[0] == pic->data[0])
break;
}
assert(i < avci->buffer_count);
avci->buffer_count--;
last = &avci->buffer[avci->buffer_count];
if (buf != last)
FFSWAP(InternalBuffer, *buf, *last);
}
for (i = 0; i < AV_NUM_DATA_POINTERS; i++)
pic->data[i] = NULL;
if (s->debug & FF_DEBUG_BUFFERS)
av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "
"buffers used\n", pic, avci->buffer_count);
} | ['void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)\n{\n int i;\n InternalBuffer *buf, *last;\n AVCodecInternal *avci = s->internal;\n assert(s->codec_type == AVMEDIA_TYPE_VIDEO);\n assert(pic->type == FF_BUFFER_TYPE_INTERNAL);\n assert(avci->buffer_count);\n if (avci->buffer) {\n buf = NULL;\n for (i = 0; i < avci->buffer_count; i++) {\n buf = &avci->buffer[i];\n if (buf->data[0] == pic->data[0])\n break;\n }\n assert(i < avci->buffer_count);\n avci->buffer_count--;\n last = &avci->buffer[avci->buffer_count];\n if (buf != last)\n FFSWAP(InternalBuffer, *buf, *last);\n }\n for (i = 0; i < AV_NUM_DATA_POINTERS; i++)\n pic->data[i] = NULL;\n if (s->debug & FF_DEBUG_BUFFERS)\n av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d "\n "buffers used\\n", pic, avci->buffer_count);\n}'] |
35,079 | 0 | https://github.com/libav/libav/blob/b066d90211072c7532e17c0c54d8475f10fc97ad/libavcodec/ansi.c/#L227 | static int execute_code(AVCodecContext * avctx, int c)
{
AnsiContext *s = avctx->priv_data;
int ret, i, width, height;
switch(c) {
case 'A':
s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);
break;
case 'B':
s->y = FFMIN(s->y + (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), avctx->height - s->font_height);
break;
case 'C':
s->x = FFMIN(s->x + (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), avctx->width - FONT_WIDTH);
break;
case 'D':
s->x = FFMAX(s->x - (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), 0);
break;
case 'H':
case 'f':
s->y = s->nb_args > 0 ? av_clip((s->args[0] - 1)*s->font_height, 0, avctx->height - s->font_height) : 0;
s->x = s->nb_args > 1 ? av_clip((s->args[1] - 1)*FONT_WIDTH, 0, avctx->width - FONT_WIDTH) : 0;
break;
case 'h':
case 'l':
if (s->nb_args < 2)
s->args[0] = DEFAULT_SCREEN_MODE;
switch(s->args[0]) {
case 0: case 1: case 4: case 5: case 13: case 19:
s->font = ff_cga_font;
s->font_height = 8;
width = 40<<3;
height = 25<<3;
break;
case 2: case 3:
s->font = ff_vga16_font;
s->font_height = 16;
width = 80<<3;
height = 25<<4;
break;
case 6: case 14:
s->font = ff_cga_font;
s->font_height = 8;
width = 80<<3;
height = 25<<3;
break;
case 7:
break;
case 15: case 16:
s->font = ff_cga_font;
s->font_height = 8;
width = 80<<3;
height = 43<<3;
break;
case 17: case 18:
s->font = ff_cga_font;
s->font_height = 8;
width = 80<<3;
height = 60<<4;
break;
default:
avpriv_request_sample(avctx, "Unsupported screen mode");
}
if (width != avctx->width || height != avctx->height) {
av_frame_unref(s->frame);
avcodec_set_dimensions(avctx, width, height);
ret = ff_get_buffer(avctx, s->frame, AV_GET_BUFFER_FLAG_REF);
if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
s->frame->pict_type = AV_PICTURE_TYPE_I;
s->frame->palette_has_changed = 1;
memcpy(s->frame->data[1], ff_cga_palette, 16 * 4);
erase_screen(avctx);
} else if (c == 'l') {
erase_screen(avctx);
}
break;
case 'J':
switch (s->args[0]) {
case 0:
erase_line(avctx, s->x, avctx->width - s->x);
if (s->y < avctx->height - s->font_height)
memset(s->frame->data[0] + (s->y + s->font_height)*s->frame->linesize[0],
DEFAULT_BG_COLOR, (avctx->height - s->y - s->font_height)*s->frame->linesize[0]);
break;
case 1:
erase_line(avctx, 0, s->x);
if (s->y > 0)
memset(s->frame->data[0], DEFAULT_BG_COLOR, s->y * s->frame->linesize[0]);
break;
case 2:
erase_screen(avctx);
}
break;
case 'K':
switch(s->args[0]) {
case 0:
erase_line(avctx, s->x, avctx->width - s->x);
break;
case 1:
erase_line(avctx, 0, s->x);
break;
case 2:
erase_line(avctx, 0, avctx->width);
}
break;
case 'm':
if (s->nb_args == 0) {
s->nb_args = 1;
s->args[0] = 0;
}
for (i = 0; i < FFMIN(s->nb_args, MAX_NB_ARGS); i++) {
int m = s->args[i];
if (m == 0) {
s->attributes = 0;
s->fg = DEFAULT_FG_COLOR;
s->bg = DEFAULT_BG_COLOR;
} else if (m == 1 || m == 2 || m == 4 || m == 5 || m == 7 || m == 8) {
s->attributes |= 1 << (m - 1);
} else if (m >= 30 && m <= 38) {
s->fg = ansi_to_cga[m - 30];
} else if (m == 39) {
s->fg = ansi_to_cga[DEFAULT_FG_COLOR];
} else if (m >= 40 && m <= 47) {
s->bg = ansi_to_cga[m - 40];
} else if (m == 49) {
s->fg = ansi_to_cga[DEFAULT_BG_COLOR];
} else {
avpriv_request_sample(avctx, "Unsupported rendition parameter");
}
}
break;
case 'n':
case 'R':
break;
case 's':
s->sx = s->x;
s->sy = s->y;
break;
case 'u':
s->x = av_clip(s->sx, 0, avctx->width - FONT_WIDTH);
s->y = av_clip(s->sy, 0, avctx->height - s->font_height);
break;
default:
avpriv_request_sample(avctx, "Unknown escape code");
break;
}
return 0;
} | ['static int execute_code(AVCodecContext * avctx, int c)\n{\n AnsiContext *s = avctx->priv_data;\n int ret, i, width, height;\n switch(c) {\n case \'A\':\n s->y = FFMAX(s->y - (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), 0);\n break;\n case \'B\':\n s->y = FFMIN(s->y + (s->nb_args > 0 ? s->args[0]*s->font_height : s->font_height), avctx->height - s->font_height);\n break;\n case \'C\':\n s->x = FFMIN(s->x + (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), avctx->width - FONT_WIDTH);\n break;\n case \'D\':\n s->x = FFMAX(s->x - (s->nb_args > 0 ? s->args[0]*FONT_WIDTH : FONT_WIDTH), 0);\n break;\n case \'H\':\n case \'f\':\n s->y = s->nb_args > 0 ? av_clip((s->args[0] - 1)*s->font_height, 0, avctx->height - s->font_height) : 0;\n s->x = s->nb_args > 1 ? av_clip((s->args[1] - 1)*FONT_WIDTH, 0, avctx->width - FONT_WIDTH) : 0;\n break;\n case \'h\':\n case \'l\':\n if (s->nb_args < 2)\n s->args[0] = DEFAULT_SCREEN_MODE;\n switch(s->args[0]) {\n case 0: case 1: case 4: case 5: case 13: case 19:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 40<<3;\n height = 25<<3;\n break;\n case 2: case 3:\n s->font = ff_vga16_font;\n s->font_height = 16;\n width = 80<<3;\n height = 25<<4;\n break;\n case 6: case 14:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 80<<3;\n height = 25<<3;\n break;\n case 7:\n break;\n case 15: case 16:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 80<<3;\n height = 43<<3;\n break;\n case 17: case 18:\n s->font = ff_cga_font;\n s->font_height = 8;\n width = 80<<3;\n height = 60<<4;\n break;\n default:\n avpriv_request_sample(avctx, "Unsupported screen mode");\n }\n if (width != avctx->width || height != avctx->height) {\n av_frame_unref(s->frame);\n avcodec_set_dimensions(avctx, width, height);\n ret = ff_get_buffer(avctx, s->frame, AV_GET_BUFFER_FLAG_REF);\n if (ret < 0) {\n av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n return ret;\n }\n s->frame->pict_type = AV_PICTURE_TYPE_I;\n s->frame->palette_has_changed = 1;\n memcpy(s->frame->data[1], ff_cga_palette, 16 * 4);\n erase_screen(avctx);\n } else if (c == \'l\') {\n erase_screen(avctx);\n }\n break;\n case \'J\':\n switch (s->args[0]) {\n case 0:\n erase_line(avctx, s->x, avctx->width - s->x);\n if (s->y < avctx->height - s->font_height)\n memset(s->frame->data[0] + (s->y + s->font_height)*s->frame->linesize[0],\n DEFAULT_BG_COLOR, (avctx->height - s->y - s->font_height)*s->frame->linesize[0]);\n break;\n case 1:\n erase_line(avctx, 0, s->x);\n if (s->y > 0)\n memset(s->frame->data[0], DEFAULT_BG_COLOR, s->y * s->frame->linesize[0]);\n break;\n case 2:\n erase_screen(avctx);\n }\n break;\n case \'K\':\n switch(s->args[0]) {\n case 0:\n erase_line(avctx, s->x, avctx->width - s->x);\n break;\n case 1:\n erase_line(avctx, 0, s->x);\n break;\n case 2:\n erase_line(avctx, 0, avctx->width);\n }\n break;\n case \'m\':\n if (s->nb_args == 0) {\n s->nb_args = 1;\n s->args[0] = 0;\n }\n for (i = 0; i < FFMIN(s->nb_args, MAX_NB_ARGS); i++) {\n int m = s->args[i];\n if (m == 0) {\n s->attributes = 0;\n s->fg = DEFAULT_FG_COLOR;\n s->bg = DEFAULT_BG_COLOR;\n } else if (m == 1 || m == 2 || m == 4 || m == 5 || m == 7 || m == 8) {\n s->attributes |= 1 << (m - 1);\n } else if (m >= 30 && m <= 38) {\n s->fg = ansi_to_cga[m - 30];\n } else if (m == 39) {\n s->fg = ansi_to_cga[DEFAULT_FG_COLOR];\n } else if (m >= 40 && m <= 47) {\n s->bg = ansi_to_cga[m - 40];\n } else if (m == 49) {\n s->fg = ansi_to_cga[DEFAULT_BG_COLOR];\n } else {\n avpriv_request_sample(avctx, "Unsupported rendition parameter");\n }\n }\n break;\n case \'n\':\n case \'R\':\n break;\n case \'s\':\n s->sx = s->x;\n s->sy = s->y;\n break;\n case \'u\':\n s->x = av_clip(s->sx, 0, avctx->width - FONT_WIDTH);\n s->y = av_clip(s->sy, 0, avctx->height - s->font_height);\n break;\n default:\n avpriv_request_sample(avctx, "Unknown escape code");\n break;\n }\n return 0;\n}'] |
35,080 | 0 | https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_ctx.c/#L273 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static int dsa_builtin_keygen(DSA *dsa)\n{\n int ok = 0;\n BN_CTX *ctx = NULL;\n BIGNUM *pub_key = NULL, *priv_key = NULL;\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n if (dsa->priv_key == NULL) {\n if ((priv_key = BN_secure_new()) == NULL)\n goto err;\n } else\n priv_key = dsa->priv_key;\n do\n if (!BN_priv_rand_range(priv_key, dsa->q))\n goto err;\n while (BN_is_zero(priv_key)) ;\n if (dsa->pub_key == NULL) {\n if ((pub_key = BN_new()) == NULL)\n goto err;\n } else\n pub_key = dsa->pub_key;\n {\n BIGNUM *prk = BN_new();\n if (prk == NULL)\n goto err;\n BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);\n if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) {\n BN_free(prk);\n goto err;\n }\n BN_free(prk);\n }\n dsa->priv_key = priv_key;\n dsa->pub_key = pub_key;\n ok = 1;\n err:\n if (pub_key != dsa->pub_key)\n BN_free(pub_key);\n if (priv_key != dsa->priv_key)\n BN_free(priv_key);\n BN_CTX_free(ctx);\n return (ok);\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 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}', '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_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}', '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}'] |
35,081 | 0 | https://github.com/libav/libav/blob/0e5f33f2426dae28725b14468b61cbad052da240/libavcodec/h264.h/#L974 | 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}'] |
35,082 | 0 | https://github.com/openssl/openssl/blob/05ec6a25f80ac8edfb7d7cb764d2dd68156a6965/crypto/x509/x509_obj.c/#L56 | char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
{
X509_NAME_ENTRY *ne;
int i;
int n, lold, l, l1, l2, num, j, type;
const char *s;
char *p;
unsigned char *q;
BUF_MEM *b = NULL;
static const char hex[17] = "0123456789ABCDEF";
int gs_doit[4];
char tmp_buf[80];
#ifdef CHARSET_EBCDIC
unsigned char ebcdic_buf[1024];
#endif
if (buf == NULL) {
if ((b = BUF_MEM_new()) == NULL)
goto err;
if (!BUF_MEM_grow(b, 200))
goto err;
b->data[0] = '\0';
len = 200;
} else if (len == 0) {
return NULL;
}
if (a == NULL) {
if (b) {
buf = b->data;
OPENSSL_free(b);
}
strncpy(buf, "NO X509_NAME", len);
buf[len - 1] = '\0';
return buf;
}
len--;
l = 0;
for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
ne = sk_X509_NAME_ENTRY_value(a->entries, i);
n = OBJ_obj2nid(ne->object);
if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
s = tmp_buf;
}
l1 = strlen(s);
type = ne->value->type;
num = ne->value->length;
if (num > NAME_ONELINE_MAX) {
X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
goto end;
}
q = ne->value->data;
#ifdef CHARSET_EBCDIC
if (type == V_ASN1_GENERALSTRING ||
type == V_ASN1_VISIBLESTRING ||
type == V_ASN1_PRINTABLESTRING ||
type == V_ASN1_TELETEXSTRING ||
type == V_ASN1_IA5STRING) {
if (num > (int)sizeof(ebcdic_buf))
num = sizeof(ebcdic_buf);
ascii2ebcdic(ebcdic_buf, q, num);
q = ebcdic_buf;
}
#endif
if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
for (j = 0; j < num; j++)
if (q[j] != 0)
gs_doit[j & 3] = 1;
if (gs_doit[0] | gs_doit[1] | gs_doit[2])
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
else {
gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
gs_doit[3] = 1;
}
} else
gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
for (l2 = j = 0; j < num; j++) {
if (!gs_doit[j & 3])
continue;
l2++;
#ifndef CHARSET_EBCDIC
if ((q[j] < ' ') || (q[j] > '~'))
l2 += 3;
#else
if ((os_toascii[q[j]] < os_toascii[' ']) ||
(os_toascii[q[j]] > os_toascii['~']))
l2 += 3;
#endif
}
lold = l;
l += 1 + l1 + 1 + l2;
if (l > NAME_ONELINE_MAX) {
X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
goto end;
}
if (b != NULL) {
if (!BUF_MEM_grow(b, l + 1))
goto err;
p = &(b->data[lold]);
} else if (l > len) {
break;
} else
p = &(buf[lold]);
*(p++) = '/';
memcpy(p, s, (unsigned int)l1);
p += l1;
*(p++) = '=';
#ifndef CHARSET_EBCDIC
q = ne->value->data;
#endif
for (j = 0; j < num; j++) {
if (!gs_doit[j & 3])
continue;
#ifndef CHARSET_EBCDIC
n = q[j];
if ((n < ' ') || (n > '~')) {
*(p++) = '\\';
*(p++) = 'x';
*(p++) = hex[(n >> 4) & 0x0f];
*(p++) = hex[n & 0x0f];
} else
*(p++) = n;
#else
n = os_toascii[q[j]];
if ((n < os_toascii[' ']) || (n > os_toascii['~'])) {
*(p++) = '\\';
*(p++) = 'x';
*(p++) = hex[(n >> 4) & 0x0f];
*(p++) = hex[n & 0x0f];
} else
*(p++) = q[j];
#endif
}
*p = '\0';
}
if (b != NULL) {
p = b->data;
OPENSSL_free(b);
} else
p = buf;
if (i == 0)
*p = '\0';
return (p);
err:
X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
end:
BUF_MEM_free(b);
return (NULL);
} | ['static int app_verify_callback(X509_STORE_CTX *ctx, void *arg)\n{\n int ok = 1;\n struct app_verify_arg *cb_arg = arg;\n if (cb_arg->app_verify) {\n char *s = NULL, buf[256];\n X509 *c = X509_STORE_CTX_get0_cert(ctx);\n printf("In app_verify_callback, allowing cert. ");\n printf("Arg is: %s\\n", cb_arg->string);\n printf("Finished printing do we have a context? 0x%p a cert? 0x%p\\n",\n (void *)ctx, (void *)c);\n if (c)\n s = X509_NAME_oneline(X509_get_subject_name(c), buf, 256);\n if (s != NULL) {\n printf("cert depth=%d %s\\n",\n X509_STORE_CTX_get_error_depth(ctx), buf);\n }\n return (1);\n }\n ok = X509_verify_cert(ctx);\n return (ok);\n}', 'char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)\n{\n X509_NAME_ENTRY *ne;\n int i;\n int n, lold, l, l1, l2, num, j, type;\n const char *s;\n char *p;\n unsigned char *q;\n BUF_MEM *b = NULL;\n static const char hex[17] = "0123456789ABCDEF";\n int gs_doit[4];\n char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n unsigned char ebcdic_buf[1024];\n#endif\n if (buf == NULL) {\n if ((b = BUF_MEM_new()) == NULL)\n goto err;\n if (!BUF_MEM_grow(b, 200))\n goto err;\n b->data[0] = \'\\0\';\n len = 200;\n } else if (len == 0) {\n return NULL;\n }\n if (a == NULL) {\n if (b) {\n buf = b->data;\n OPENSSL_free(b);\n }\n strncpy(buf, "NO X509_NAME", len);\n buf[len - 1] = \'\\0\';\n return buf;\n }\n len--;\n l = 0;\n for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n n = OBJ_obj2nid(ne->object);\n if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n s = tmp_buf;\n }\n l1 = strlen(s);\n type = ne->value->type;\n num = ne->value->length;\n if (num > NAME_ONELINE_MAX) {\n X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n goto end;\n }\n q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n if (type == V_ASN1_GENERALSTRING ||\n type == V_ASN1_VISIBLESTRING ||\n type == V_ASN1_PRINTABLESTRING ||\n type == V_ASN1_TELETEXSTRING ||\n type == V_ASN1_IA5STRING) {\n if (num > (int)sizeof(ebcdic_buf))\n num = sizeof(ebcdic_buf);\n ascii2ebcdic(ebcdic_buf, q, num);\n q = ebcdic_buf;\n }\n#endif\n if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n for (j = 0; j < num; j++)\n if (q[j] != 0)\n gs_doit[j & 3] = 1;\n if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n else {\n gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n gs_doit[3] = 1;\n }\n } else\n gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n for (l2 = j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n l2++;\n#ifndef CHARSET_EBCDIC\n if ((q[j] < \' \') || (q[j] > \'~\'))\n l2 += 3;\n#else\n if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n (os_toascii[q[j]] > os_toascii[\'~\']))\n l2 += 3;\n#endif\n }\n lold = l;\n l += 1 + l1 + 1 + l2;\n if (l > NAME_ONELINE_MAX) {\n X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n goto end;\n }\n if (b != NULL) {\n if (!BUF_MEM_grow(b, l + 1))\n goto err;\n p = &(b->data[lold]);\n } else if (l > len) {\n break;\n } else\n p = &(buf[lold]);\n *(p++) = \'/\';\n memcpy(p, s, (unsigned int)l1);\n p += l1;\n *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n q = ne->value->data;\n#endif\n for (j = 0; j < num; j++) {\n if (!gs_doit[j & 3])\n continue;\n#ifndef CHARSET_EBCDIC\n n = q[j];\n if ((n < \' \') || (n > \'~\')) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = n;\n#else\n n = os_toascii[q[j]];\n if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n *(p++) = \'\\\\\';\n *(p++) = \'x\';\n *(p++) = hex[(n >> 4) & 0x0f];\n *(p++) = hex[n & 0x0f];\n } else\n *(p++) = q[j];\n#endif\n }\n *p = \'\\0\';\n }\n if (b != NULL) {\n p = b->data;\n OPENSSL_free(b);\n } else\n p = buf;\n if (i == 0)\n *p = \'\\0\';\n return (p);\n err:\n X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n end:\n BUF_MEM_free(b);\n return (NULL);\n}'] |
35,083 | 1 | https://gitlab.com/libtiff/libtiff/blob/b9b93f661ed56fda222ce686a6e6ef03ee84bc3d/libtiff/tif_write.c/#L238 | tmsize_t
TIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)
{
static const char module[] = "TIFFWriteEncodedStrip";
TIFFDirectory *td = &tif->tif_dir;
uint16 sample;
if (!WRITECHECKSTRIPS(tif, module))
return ((tmsize_t) -1);
if (strip >= td->td_nstrips) {
if (td->td_planarconfig == PLANARCONFIG_SEPARATE) {
TIFFErrorExt(tif->tif_clientdata, module,
"Can not grow image by strips when using separate planes");
return ((tmsize_t) -1);
}
if (!TIFFGrowStrips(tif, 1, module))
return ((tmsize_t) -1);
td->td_stripsperimage =
TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);
}
if (!BUFFERCHECK(tif))
return ((tmsize_t) -1);
tif->tif_flags |= TIFF_BUF4WRITE;
tif->tif_curstrip = strip;
if( !_TIFFReserveLargeEnoughWriteBuffer(tif, strip) ) {
return ((tmsize_t)(-1));
}
tif->tif_rawcc = 0;
tif->tif_rawcp = tif->tif_rawdata;
if (td->td_stripsperimage == 0) {
TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");
return ((tmsize_t) -1);
}
tif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupencode)(tif))
return ((tmsize_t) -1);
tif->tif_flags |= TIFF_CODERSETUP;
}
tif->tif_flags &= ~TIFF_POSTENCODE;
if( td->td_compression == COMPRESSION_NONE )
{
tif->tif_postdecode( tif, (uint8*) data, cc );
if (!isFillOrder(tif, td->td_fillorder) &&
(tif->tif_flags & TIFF_NOBITREV) == 0)
TIFFReverseBits((uint8*) data, cc);
if (cc > 0 &&
!TIFFAppendToStrip(tif, strip, (uint8*) data, cc))
return ((tmsize_t) -1);
return (cc);
}
sample = (uint16)(strip / td->td_stripsperimage);
if (!(*tif->tif_preencode)(tif, sample))
return ((tmsize_t) -1);
tif->tif_postdecode( tif, (uint8*) data, cc );
if (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))
return ((tmsize_t) -1);
if (!(*tif->tif_postencode)(tif))
return ((tmsize_t) -1);
if (!isFillOrder(tif, td->td_fillorder) &&
(tif->tif_flags & TIFF_NOBITREV) == 0)
TIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);
if (tif->tif_rawcc > 0 &&
!TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))
return ((tmsize_t) -1);
tif->tif_rawcc = 0;
tif->tif_rawcp = tif->tif_rawdata;
return (cc);
} | ['static int\nwriteSelections(TIFF *in, TIFF **out, struct crop_mask *crop,\n struct image_data *image, struct dump_opts *dump,\n struct buffinfo seg_buffs[], char *mp, char *filename,\n unsigned int *page, unsigned int total_pages)\n {\n int i, page_count;\n int autoindex = 0;\n unsigned char *crop_buff = NULL;\n switch (crop->exp_mode)\n {\n case ONE_FILE_COMPOSITE:\n autoindex = 0;\n crop_buff = seg_buffs[0].buffer;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n page_count = total_pages;\n if (writeCroppedImage(in, *out, image, dump,\n crop->combined_width,\n crop->combined_length,\n crop_buff, *page, total_pages))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n\t break;\n case ONE_FILE_SEPARATED:\n autoindex = 0;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n page_count = crop->selections * total_pages;\n for (i = 0; i < crop->selections; i++)\n {\n crop_buff = seg_buffs[i].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->regionlist[i].width,\n crop->regionlist[i].length,\n crop_buff, *page, page_count))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n\t }\n break;\n case FILE_PER_IMAGE_COMPOSITE:\n autoindex = 1;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n crop_buff = seg_buffs[0].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->combined_width,\n crop->combined_length,\n crop_buff, *page, total_pages))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n break;\n case FILE_PER_IMAGE_SEPARATED:\n autoindex = 1;\n page_count = crop->selections;\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n for (i = 0; i < crop->selections; i++)\n {\n crop_buff = seg_buffs[i].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->regionlist[i].width,\n crop->regionlist[i].length,\n crop_buff, *page, page_count))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n }\n break;\n case FILE_PER_SELECTION:\n autoindex = 1;\n\t page_count = 1;\n for (i = 0; i < crop->selections; i++)\n {\n if (update_output_file (out, mp, autoindex, filename, page))\n return (1);\n crop_buff = seg_buffs[i].buffer;\n if (writeCroppedImage(in, *out, image, dump,\n crop->regionlist[i].width,\n crop->regionlist[i].length,\n crop_buff, *page, page_count))\n {\n TIFFError("writeRegions", "Unable to write new image");\n return (-1);\n }\n }\n\t break;\n default: return (1);\n }\n return (0);\n }', 'static int\nupdate_output_file (TIFF **tiffout, char *mode, int autoindex,\n char *outname, unsigned int *page)\n {\n static int findex = 0;\n size_t basename_len;\n char *sep;\n char export_ext[16];\n char exportname[PATH_MAX];\n if (autoindex && (*tiffout != NULL))\n {\n TIFFClose (*tiffout);\n *tiffout = NULL;\n }\n memcpy (export_ext, ".tiff", 6);\n memset (exportname, \'\\0\', sizeof(exportname));\n #define FILENUM_MAX_LENGTH (1+6+1+4+1)\n strncpy (exportname, outname, sizeof(exportname) - FILENUM_MAX_LENGTH);\n if (*tiffout == NULL)\n {\n if (autoindex)\n {\n findex++;\n if ((sep = strstr(exportname, ".tif")) || (sep = strstr(exportname, ".TIF")))\n {\n strncpy (export_ext, sep, 5);\n *sep = \'\\0\';\n }\n else\n memcpy (export_ext, ".tiff", 5);\n export_ext[5] = \'\\0\';\n basename_len = strlen(exportname);\n if (findex > MAX_EXPORT_PAGES)\n {\n TIFFError("update_output_file", "Maximum of %d pages per file exceeded", MAX_EXPORT_PAGES);\n return 1;\n }\n snprintf(exportname + basename_len, sizeof(exportname) - basename_len, "-%03d%.5s", findex, export_ext);\n }\n exportname[sizeof(exportname) - 1] = \'\\0\';\n *tiffout = TIFFOpen(exportname, mode);\n if (*tiffout == NULL)\n {\n TIFFError("update_output_file", "Unable to open output file %s", exportname);\n return 1;\n }\n *page = 0;\n return 0;\n }\n else\n (*page)++;\n return 0;\n }', 'static int\nwriteCroppedImage(TIFF *in, TIFF *out, struct image_data *image,\n struct dump_opts *dump, uint32 width, uint32 length,\n unsigned char *crop_buff, int pagenum, int total_pages)\n {\n uint16 bps, spp;\n uint16 input_compression, input_photometric;\n uint16 input_planar;\n struct cpTag* p;\n input_compression = image->compression;\n input_photometric = image->photometric;\n spp = image->spp;\n bps = image->bps;\n TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);\n TIFFSetField(out, TIFFTAG_IMAGELENGTH, length);\n TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bps);\n TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);\n#ifdef DEBUG2\n TIFFError("writeCroppedImage", "Input compression: %s",\n\t (input_compression == COMPRESSION_OJPEG) ? "Old Jpeg" :\n\t ((input_compression == COMPRESSION_JPEG) ? "New Jpeg" : "Non Jpeg"));\n#endif\n if (compression != (uint16)-1)\n TIFFSetField(out, TIFFTAG_COMPRESSION, compression);\n else\n {\n if (input_compression == COMPRESSION_OJPEG)\n {\n compression = COMPRESSION_JPEG;\n jpegcolormode = JPEGCOLORMODE_RAW;\n TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n }\n else\n CopyField(TIFFTAG_COMPRESSION, compression);\n }\n if (compression == COMPRESSION_JPEG)\n {\n if ((input_photometric == PHOTOMETRIC_PALETTE) ||\n (input_photometric == PHOTOMETRIC_MASK))\n {\n TIFFError ("writeCroppedImage",\n "JPEG compression cannot be used with %s image data",\n \t (input_photometric == PHOTOMETRIC_PALETTE) ?\n "palette" : "mask");\n return (-1);\n }\n if ((input_photometric == PHOTOMETRIC_RGB) &&\n\t(jpegcolormode == JPEGCOLORMODE_RGB))\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n else\n\tTIFFSetField(out, TIFFTAG_PHOTOMETRIC, input_photometric);\n }\n else\n {\n if (compression == COMPRESSION_SGILOG || compression == COMPRESSION_SGILOG24)\n {\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\tPHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n }\n else\n {\n if (input_compression == COMPRESSION_SGILOG ||\n input_compression == COMPRESSION_SGILOG24)\n {\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, spp == 1 ?\n\t\t\t PHOTOMETRIC_LOGL : PHOTOMETRIC_LOGLUV);\n }\n else\n TIFFSetField(out, TIFFTAG_PHOTOMETRIC, image->photometric);\n }\n }\n if (((input_photometric == PHOTOMETRIC_LOGL) ||\n (input_photometric == PHOTOMETRIC_LOGLUV)) &&\n ((compression != COMPRESSION_SGILOG) &&\n (compression != COMPRESSION_SGILOG24)))\n {\n TIFFError("writeCroppedImage",\n "LogL and LogLuv source data require SGI_LOG or SGI_LOG24 compression");\n return (-1);\n }\n if (fillorder != 0)\n TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);\n else\n CopyTag(TIFFTAG_FILLORDER, 1, TIFF_SHORT);\n TIFFSetField(out, TIFFTAG_ORIENTATION, image->orientation);\n if (outtiled == -1)\n outtiled = TIFFIsTiled(in);\n if (outtiled) {\n if (tilewidth == (uint32) 0)\n TIFFGetField(in, TIFFTAG_TILEWIDTH, &tilewidth);\n if (tilelength == (uint32) 0)\n TIFFGetField(in, TIFFTAG_TILELENGTH, &tilelength);\n if (tilewidth == 0 || tilelength == 0)\n TIFFDefaultTileSize(out, &tilewidth, &tilelength);\n TIFFSetField(out, TIFFTAG_TILEWIDTH, tilewidth);\n TIFFSetField(out, TIFFTAG_TILELENGTH, tilelength);\n } else {\n\tif (rowsperstrip == (uint32) 0)\n {\n\t if (!TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rowsperstrip))\n\t rowsperstrip = TIFFDefaultStripSize(out, rowsperstrip);\n if (compression != COMPRESSION_JPEG)\n {\n \t if (rowsperstrip > length)\n\t rowsperstrip = length;\n\t }\n\t }\n\telse\n if (rowsperstrip == (uint32) -1)\n\t rowsperstrip = length;\n\tTIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rowsperstrip);\n\t}\n TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &input_planar);\n if (config != (uint16) -1)\n TIFFSetField(out, TIFFTAG_PLANARCONFIG, config);\n else\n CopyField(TIFFTAG_PLANARCONFIG, config);\n if (spp <= 4)\n CopyTag(TIFFTAG_TRANSFERFUNCTION, 4, TIFF_SHORT);\n CopyTag(TIFFTAG_COLORMAP, 4, TIFF_SHORT);\n switch (compression) {\n case COMPRESSION_JPEG:\n if (((bps % 8) == 0) || ((bps % 12) == 0))\n\t {\n TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality);\n\t TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n }\n else\n {\n\t TIFFError("writeCroppedImage",\n "JPEG compression requires 8 or 12 bits per sample");\n return (-1);\n }\n\t break;\n case COMPRESSION_LZW:\n case COMPRESSION_ADOBE_DEFLATE:\n case COMPRESSION_DEFLATE:\n\tif (predictor != (uint16)-1)\n TIFFSetField(out, TIFFTAG_PREDICTOR, predictor);\n\telse\n\t CopyField(TIFFTAG_PREDICTOR, predictor);\n\tbreak;\n case COMPRESSION_CCITTFAX3:\n case COMPRESSION_CCITTFAX4:\n if (bps != 1)\n {\n\t TIFFError("writeCroppedImage",\n "Group 3/4 compression is not usable with bps > 1");\n return (-1);\n\t }\n\tif (compression == COMPRESSION_CCITTFAX3) {\n if (g3opts != (uint32) -1)\n\t TIFFSetField(out, TIFFTAG_GROUP3OPTIONS, g3opts);\n\t else\n\t CopyField(TIFFTAG_GROUP3OPTIONS, g3opts);\n\t} else {\n\t CopyTag(TIFFTAG_GROUP4OPTIONS, 1, TIFF_LONG);\n }\n CopyTag(TIFFTAG_BADFAXLINES, 1, TIFF_LONG);\n CopyTag(TIFFTAG_CLEANFAXDATA, 1, TIFF_LONG);\n CopyTag(TIFFTAG_CONSECUTIVEBADFAXLINES, 1, TIFF_LONG);\n CopyTag(TIFFTAG_FAXRECVPARAMS, 1, TIFF_LONG);\n CopyTag(TIFFTAG_FAXRECVTIME, 1, TIFF_LONG);\n CopyTag(TIFFTAG_FAXSUBADDRESS, 1, TIFF_ASCII);\n break;\n case COMPRESSION_NONE:\n break;\n default: break;\n }\n { uint32 len32;\n void** data;\n if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &len32, &data))\n TIFFSetField(out, TIFFTAG_ICCPROFILE, len32, data);\n }\n { uint16 ninks;\n const char* inknames;\n if (TIFFGetField(in, TIFFTAG_NUMBEROFINKS, &ninks)) {\n TIFFSetField(out, TIFFTAG_NUMBEROFINKS, ninks);\n if (TIFFGetField(in, TIFFTAG_INKNAMES, &inknames)) {\n\t int inknameslen = strlen(inknames) + 1;\n\t const char* cp = inknames;\n\t while (ninks > 1) {\n\t cp = strchr(cp, \'\\0\');\n\t if (cp) {\n\t cp++;\n\t inknameslen += (strlen(cp) + 1);\n\t }\n\t ninks--;\n }\n\t TIFFSetField(out, TIFFTAG_INKNAMES, inknameslen, inknames);\n }\n }\n }\n {\n unsigned short pg0, pg1;\n if (TIFFGetField(in, TIFFTAG_PAGENUMBER, &pg0, &pg1)) {\n TIFFSetField(out, TIFFTAG_PAGENUMBER, pagenum, total_pages);\n }\n }\n for (p = tags; p < &tags[NTAGS]; p++)\n\t\tCopyTag(p->tag, p->count, p->type);\n if (outtiled)\n {\n if (config == PLANARCONFIG_CONTIG)\n {\n if (writeBufferToContigTiles (out, crop_buff, length, width, spp, dump))\n TIFFError("","Unable to write contiguous tile data for page %d", pagenum);\n }\n else\n {\n if (writeBufferToSeparateTiles (out, crop_buff, length, width, spp, dump))\n TIFFError("","Unable to write separate tile data for page %d", pagenum);\n }\n }\n else\n {\n if (config == PLANARCONFIG_CONTIG)\n {\n if (writeBufferToContigStrips (out, crop_buff, length))\n TIFFError("","Unable to write contiguous strip data for page %d", pagenum);\n }\n else\n {\n if (writeBufferToSeparateStrips(out, crop_buff, length, width, spp, dump))\n TIFFError("","Unable to write separate strip data for page %d", pagenum);\n }\n }\n if (!TIFFWriteDirectory(out))\n {\n TIFFError("","Failed to write IFD for page number %d", pagenum);\n return (-1);\n }\n return (0);\n }', 'static int writeBufferToContigStrips(TIFF* out, uint8* buf, uint32 imagelength)\n {\n uint32 row, nrows, rowsperstrip;\n tstrip_t strip = 0;\n tsize_t stripsize;\n TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);\n for (row = 0; row < imagelength; row += rowsperstrip)\n {\n nrows = (row + rowsperstrip > imagelength) ?\n\t imagelength - row : rowsperstrip;\n stripsize = TIFFVStripSize(out, nrows);\n if (TIFFWriteEncodedStrip(out, strip++, buf, stripsize) < 0)\n {\n TIFFError(TIFFFileName(out), "Error, can\'t write strip %u", strip - 1);\n return 1;\n }\n buf += stripsize;\n }\n return 0;\n }', 'tmsize_t\nTIFFWriteEncodedStrip(TIFF* tif, uint32 strip, void* data, tmsize_t cc)\n{\n\tstatic const char module[] = "TIFFWriteEncodedStrip";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tuint16 sample;\n\tif (!WRITECHECKSTRIPS(tif, module))\n\t\treturn ((tmsize_t) -1);\n\tif (strip >= td->td_nstrips) {\n\t\tif (td->td_planarconfig == PLANARCONFIG_SEPARATE) {\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t "Can not grow image by strips when using separate planes");\n\t\t\treturn ((tmsize_t) -1);\n\t\t}\n\t\tif (!TIFFGrowStrips(tif, 1, module))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttd->td_stripsperimage =\n\t\t TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip);\n\t}\n\tif (!BUFFERCHECK(tif))\n\t\treturn ((tmsize_t) -1);\n tif->tif_flags |= TIFF_BUF4WRITE;\n\ttif->tif_curstrip = strip;\n\tif( !_TIFFReserveLargeEnoughWriteBuffer(tif, strip) ) {\n return ((tmsize_t)(-1));\n }\n tif->tif_rawcc = 0;\n tif->tif_rawcp = tif->tif_rawdata;\n if (td->td_stripsperimage == 0) {\n TIFFErrorExt(tif->tif_clientdata, module, "Zero strips per image");\n return ((tmsize_t) -1);\n }\n\ttif->tif_row = (strip % td->td_stripsperimage) * td->td_rowsperstrip;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupencode)(tif))\n\t\t\treturn ((tmsize_t) -1);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_flags &= ~TIFF_POSTENCODE;\n if( td->td_compression == COMPRESSION_NONE )\n {\n tif->tif_postdecode( tif, (uint8*) data, cc );\n if (!isFillOrder(tif, td->td_fillorder) &&\n (tif->tif_flags & TIFF_NOBITREV) == 0)\n TIFFReverseBits((uint8*) data, cc);\n if (cc > 0 &&\n !TIFFAppendToStrip(tif, strip, (uint8*) data, cc))\n return ((tmsize_t) -1);\n return (cc);\n }\n\tsample = (uint16)(strip / td->td_stripsperimage);\n\tif (!(*tif->tif_preencode)(tif, sample))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_postdecode( tif, (uint8*) data, cc );\n\tif (!(*tif->tif_encodestrip)(tif, (uint8*) data, cc, sample))\n\t\treturn ((tmsize_t) -1);\n\tif (!(*tif->tif_postencode)(tif))\n\t\treturn ((tmsize_t) -1);\n\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\tTIFFReverseBits(tif->tif_rawdata, tif->tif_rawcc);\n\tif (tif->tif_rawcc > 0 &&\n\t !TIFFAppendToStrip(tif, strip, tif->tif_rawdata, tif->tif_rawcc))\n\t\treturn ((tmsize_t) -1);\n\ttif->tif_rawcc = 0;\n\ttif->tif_rawcp = tif->tif_rawdata;\n\treturn (cc);\n}'] |
35,084 | 0 | https://github.com/openssl/openssl/blob/5dfc369ffcdc4722482c818e6ba6cf6e704c2cb5/crypto/bn/bn_prime.c/#L195 | int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),
BN_CTX *ctx_passed, char *cb_arg)
{
int i,j,c2=0,ret= -1;
BIGNUM *check;
BN_CTX *ctx=NULL,*ctx2=NULL;
BN_MONT_CTX *mont=NULL;
if (!BN_is_odd(a))
return(0);
if (ctx_passed != NULL)
ctx=ctx_passed;
else
if ((ctx=BN_CTX_new()) == NULL) goto err;
if ((ctx2=BN_CTX_new()) == NULL) goto err;
if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
check= &(ctx->bn[ctx->tos++]);
if (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;
for (i=0; i<checks; i++)
{
if (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;
j=witness(check,a,ctx,ctx2,mont);
if (j == -1) goto err;
if (j)
{
ret=0;
goto err;
}
if (callback != NULL) callback(1,c2++,cb_arg);
}
ret=1;
err:
ctx->tos--;
if ((ctx_passed == NULL) && (ctx != NULL))
BN_CTX_free(ctx);
if (ctx2 != NULL)
BN_CTX_free(ctx2);
if (mont != NULL) BN_MONT_CTX_free(mont);
return(ret);
} | ['int BN_is_prime(BIGNUM *a, int checks, void (*callback)(int,int,char *),\n\t BN_CTX *ctx_passed, char *cb_arg)\n\t{\n\tint i,j,c2=0,ret= -1;\n\tBIGNUM *check;\n\tBN_CTX *ctx=NULL,*ctx2=NULL;\n\tBN_MONT_CTX *mont=NULL;\n\tif (!BN_is_odd(a))\n\t\treturn(0);\n\tif (ctx_passed != NULL)\n\t\tctx=ctx_passed;\n\telse\n\t\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tif ((ctx2=BN_CTX_new()) == NULL) goto err;\n\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\tcheck= &(ctx->bn[ctx->tos++]);\n\tif (!BN_MONT_CTX_set(mont,a,ctx2)) goto err;\n\tfor (i=0; i<checks; i++)\n\t\t{\n\t\tif (!BN_rand(check,BN_num_bits(a)-1,0,0)) goto err;\n\t\tj=witness(check,a,ctx,ctx2,mont);\n\t\tif (j == -1) goto err;\n\t\tif (j)\n\t\t\t{\n\t\t\tret=0;\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (callback != NULL) callback(1,c2++,cb_arg);\n\t\t}\n\tret=1;\nerr:\n\tctx->tos--;\n\tif ((ctx_passed == NULL) && (ctx != NULL))\n\t\tBN_CTX_free(ctx);\n\tif (ctx2 != NULL)\n\t\tBN_CTX_free(ctx2);\n\tif (mont != NULL) BN_MONT_CTX_free(mont);\n\treturn(ret);\n\t}', 'BN_CTX *BN_CTX_new(void)\n\t{\n\tBN_CTX *ret;\n\tret=(BN_CTX *)Malloc(sizeof(BN_CTX));\n\tif (ret == NULL)\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tBN_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_new(void)\n\t{\n\tBN_MONT_CTX *ret;\n\tif ((ret=(BN_MONT_CTX *)Malloc(sizeof(BN_MONT_CTX))) == NULL)\n\t\treturn(NULL);\n\tBN_MONT_CTX_init(ret);\n\tret->flags=BN_FLG_MALLOCED;\n\treturn(ret);\n\t}'] |
35,085 | 0 | https://github.com/openssl/openssl/blob/95dc05bc6d0dfe0f3f3681f5e27afbc3f7a35eea/crypto/lhash/lhash.c/#L254 | char *lh_delete(LHASH *lh, char *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
char *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free((char *)nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
} | ['int MAIN(int argc, char **argv)\n\t{\n\tint ret=1;\n\tX509_REQ *req=NULL;\n\tX509 *x=NULL,*xca=NULL;\n\tEVP_PKEY *Upkey=NULL,*CApkey=NULL;\n\tint i,num,badops=0;\n\tBIO *out=NULL;\n\tBIO *STDout=NULL;\n\tint informat,outformat,keyformat,CAformat,CAkeyformat;\n\tchar *infile=NULL,*outfile=NULL,*keyfile=NULL,*CAfile=NULL;\n\tchar *CAkeyfile=NULL,*CAserial=NULL;\n\tint text=0,serial=0,hash=0,subject=0,issuer=0,startdate=0,enddate=0;\n\tint noout=0,sign_flag=0,CA_flag=0,CA_createserial=0;\n\tint C=0;\n\tint x509req=0,days=DEF_DAYS,modulus=0;\n\tchar **pp;\n\tX509_STORE *ctx=NULL;\n\tX509_REQ *rq=NULL;\n\tint fingerprint=0;\n\tchar buf[256];\n\tconst EVP_MD *md_alg,*digest=EVP_md5();\n\treqfile=0;\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tSTDout=BIO_new_fp(stdout,BIO_NOCLOSE);\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tkeyformat=FORMAT_PEM;\n\tCAformat=FORMAT_PEM;\n\tCAkeyformat=FORMAT_PEM;\n\tctx=X509_STORE_new();\n\tif (ctx == NULL) goto end;\n\tX509_STORE_set_verify_cb_func(ctx,callb);\n\targc--;\n\targv++;\n\tnum=0;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,"-inform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-req") == 0)\n\t\t\treqfile=1;\n\t\telse if (strcmp(*argv,"-CAform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAkeyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-days") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tdays=atoi(*(++argv));\n\t\t\tif (days == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"bad number of days\\n");\n\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-signkey") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyfile= *(++argv);\n\t\t\tsign_flag= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CA") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\tCA_flag= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAkey") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAkeyfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAserial") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAserial= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-C") == 0)\n\t\t\tC= ++num;\n\t\telse if (strcmp(*argv,"-serial") == 0)\n\t\t\tserial= ++num;\n\t\telse if (strcmp(*argv,"-modulus") == 0)\n\t\t\tmodulus= ++num;\n\t\telse if (strcmp(*argv,"-x509toreq") == 0)\n\t\t\tx509req= ++num;\n\t\telse if (strcmp(*argv,"-text") == 0)\n\t\t\ttext= ++num;\n\t\telse if (strcmp(*argv,"-hash") == 0)\n\t\t\thash= ++num;\n\t\telse if (strcmp(*argv,"-subject") == 0)\n\t\t\tsubject= ++num;\n\t\telse if (strcmp(*argv,"-issuer") == 0)\n\t\t\tissuer= ++num;\n\t\telse if (strcmp(*argv,"-fingerprint") == 0)\n\t\t\tfingerprint= ++num;\n\t\telse if (strcmp(*argv,"-dates") == 0)\n\t\t\t{\n\t\t\tstartdate= ++num;\n\t\t\tenddate= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-startdate") == 0)\n\t\t\tstartdate= ++num;\n\t\telse if (strcmp(*argv,"-enddate") == 0)\n\t\t\tenddate= ++num;\n\t\telse if (strcmp(*argv,"-noout") == 0)\n\t\t\tnoout= ++num;\n\t\telse if (strcmp(*argv,"-CAcreateserial") == 0)\n\t\t\tCA_createserial= ++num;\n\t\telse if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)\n\t\t\t{\n\t\t\tdigest=md_alg;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\nbad:\n\t\tfor (pp=x509_usage; (*pp != NULL); pp++)\n\t\t\tBIO_printf(bio_err,*pp);\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n\tX509V3_add_standard_extensions();\n\tif (!X509_STORE_set_default_paths(ctx))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM))\n\t\t{ CAkeyfile=CAfile; }\n\telse if ((CA_flag) && (CAkeyfile == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"need to specify a CAkey if using the CA command\\n");\n\t\tgoto end;\n\t\t}\n\tif (reqfile)\n\t\t{\n\t\tEVP_PKEY *pkey;\n\t\tX509_CINF *ci;\n\t\tBIO *in;\n\t\tif (!sign_flag && !CA_flag)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"We need a private key to sign with\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tin=BIO_new(BIO_s_file());\n\t\tif (in == NULL)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (infile == NULL)\n\t\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(infile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\treq=PEM_read_bio_X509_REQ(in,NULL,NULL);\n\t\tBIO_free(in);\n\t\tif (req == NULL) { perror(infile); goto end; }\n\t\tif (\t(req->req_info == NULL) ||\n\t\t\t(req->req_info->pubkey == NULL) ||\n\t\t\t(req->req_info->pubkey->public_key == NULL) ||\n\t\t\t(req->req_info->pubkey->public_key->data == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"The certificate request appears to corrupted\\n");\n\t\t\tBIO_printf(bio_err,"It does not contain a public key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((pkey=X509_REQ_get_pubkey(req)) == NULL)\n\t {\n\t BIO_printf(bio_err,"error unpacking public key\\n");\n\t goto end;\n\t }\n\t\ti=X509_REQ_verify(req,pkey);\n\t\tEVP_PKEY_free(pkey);\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Signature verification error\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t if (i == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Signature did not match the certificate request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\tBIO_printf(bio_err,"Signature ok\\n");\n\t\tX509_NAME_oneline(req->req_info->subject,buf,256);\n\t\tBIO_printf(bio_err,"subject=%s\\n",buf);\n\t\tif ((x=X509_new()) == NULL) goto end;\n\t\tci=x->cert_info;\n\t\tif (!ASN1_INTEGER_set(X509_get_serialNumber(x),0)) goto end;\n\t\tif (!X509_set_issuer_name(x,req->req_info->subject)) goto end;\n\t\tif (!X509_set_subject_name(x,req->req_info->subject)) goto end;\n\t\tX509_gmtime_adj(X509_get_notBefore(x),0);\n\t X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);\n#if 0\n\t\tX509_PUBKEY_free(ci->key);\n\t\tci->key=req->req_info->pubkey;\n\t req->req_info->pubkey=NULL;\n#else\n\t\tpkey = X509_REQ_get_pubkey(req);\n\t\tX509_set_pubkey(x,pkey);\n\t\tEVP_PKEY_free(pkey);\n#endif\n\t\t}\n\telse\n\t\tx=load_cert(infile,informat);\n\tif (x == NULL) goto end;\n\tif (CA_flag)\n\t\t{\n\t\txca=load_cert(CAfile,CAformat);\n\t\tif (xca == NULL) goto end;\n\t\t}\n\tif (!noout || text)\n\t\t{\n\t\tOBJ_create("2.99999.3",\n\t\t\t"SET.ex3","SET x509v3 extension 3");\n\t\tout=BIO_new(BIO_s_file());\n\t\tif (out == NULL)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (outfile == NULL)\n\t\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(outfile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (num)\n\t\t{\n\t\tfor (i=1; i<=num; i++)\n\t\t\t{\n\t\t\tif (issuer == i)\n\t\t\t\t{\n\t\t\t\tX509_NAME_oneline(X509_get_issuer_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"issuer= %s\\n",buf);\n\t\t\t\t}\n\t\t\telse if (subject == i)\n\t\t\t\t{\n\t\t\t\tX509_NAME_oneline(X509_get_subject_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"subject=%s\\n",buf);\n\t\t\t\t}\n\t\t\telse if (serial == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"serial=");\n\t\t\t\ti2a_ASN1_INTEGER(STDout,x->cert_info->serialNumber);\n\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (hash == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"%08lx\\n",X509_subject_name_hash(x));\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif (modulus == i)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY *pkey;\n\t\t\t\tpkey=X509_get_pubkey(x);\n\t\t\t\tif (pkey == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Modulus=unavailable\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(STDout,"Modulus=");\n#ifndef NO_RSA\n\t\t\t\tif (pkey->type == EVP_PKEY_RSA)\n\t\t\t\t\tBN_print(STDout,pkey->pkey.rsa->n);\n\t\t\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\t\t\tBN_print(STDout,pkey->pkey.dsa->pub_key);\n\t\t\t\telse\n#endif\n\t\t\t\t\tBIO_printf(STDout,"Wrong Algorithm type");\n\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\tEVP_PKEY_free(pkey);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif (C == i)\n\t\t\t\t{\n\t\t\t\tunsigned char *d;\n\t\t\t\tchar *m;\n\t\t\t\tint y,z;\n\t\t\t\tX509_NAME_oneline(X509_get_subject_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"/* subject:%s */\\n",buf);\n\t\t\t\tm=X509_NAME_oneline(\n\t\t\t\t\tX509_get_issuer_name(x),buf,256);\n\t\t\t\tBIO_printf(STDout,"/* issuer :%s */\\n",buf);\n\t\t\t\tz=i2d_X509(x,NULL);\n\t\t\t\tm=Malloc(z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tz=i2d_X509_NAME(X509_get_subject_name(x),&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_subject_name[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f) BIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tz=i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x),&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_public_key[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f)\n\t\t\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tz=i2d_X509(x,&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_certificate[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f)\n\t\t\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tFree(m);\n\t\t\t\t}\n\t\t\telse if (text == i)\n\t\t\t\t{\n\t\t\t\tX509_print(out,x);\n\t\t\t\t}\n\t\t\telse if (startdate == i)\n\t\t\t\t{\n\t\t\t\tBIO_puts(STDout,"notBefore=");\n\t\t\t\tASN1_TIME_print(STDout,X509_get_notBefore(x));\n\t\t\t\tBIO_puts(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (enddate == i)\n\t\t\t\t{\n\t\t\t\tBIO_puts(STDout,"notAfter=");\n\t\t\t\tASN1_TIME_print(STDout,X509_get_notAfter(x));\n\t\t\t\tBIO_puts(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (fingerprint == i)\n\t\t\t\t{\n\t\t\t\tint j;\n\t\t\t\tunsigned int n;\n\t\t\t\tunsigned char md[EVP_MAX_MD_SIZE];\n\t\t\t\tif (!X509_digest(x,EVP_md5(),md,&n))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(STDout,"MD5 Fingerprint=");\n\t\t\t\tfor (j=0; j<(int)n; j++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"%02X%c",md[j],\n\t\t\t\t\t\t(j+1 == (int)n)\n\t\t\t\t\t\t?\'\\n\':\':\');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if ((sign_flag == i) && (x509req == 0))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"Getting Private key\\n");\n\t\t\t\tif (Upkey == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tUpkey=load_key(keyfile,keyformat);\n\t\t\t\t\tif (Upkey == NULL) goto end;\n\t\t\t\t\t}\n#ifndef NO_DSA\n\t\t if (Upkey->type == EVP_PKEY_DSA)\n\t\t digest=EVP_dss1();\n#endif\n\t\t\t\tif (!sign(x,Upkey,days,digest)) goto end;\n\t\t\t\t}\n\t\t\telse if (CA_flag == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"Getting CA Private Key\\n");\n\t\t\t\tif (CAkeyfile != NULL)\n\t\t\t\t\t{\n\t\t\t\t\tCApkey=load_key(CAkeyfile,CAkeyformat);\n\t\t\t\t\tif (CApkey == NULL) goto end;\n\t\t\t\t\t}\n#ifndef NO_DSA\n\t\t if (CApkey->type == EVP_PKEY_DSA)\n\t\t digest=EVP_dss1();\n#endif\n\t\t\t\tif (!x509_certify(ctx,CAfile,digest,x,xca,\n\t\t\t\t\tCApkey,\n\t\t\t\t\tCAserial,CA_createserial,days))\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\telse if (x509req == i)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY *pk;\n\t\t\t\tBIO_printf(bio_err,"Getting request Private Key\\n");\n\t\t\t\tif (keyfile == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"no request key file specified\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tpk=load_key(keyfile,FORMAT_PEM);\n\t\t\t\t\tif (pk == NULL) goto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(bio_err,"Generating certificate request\\n");\n\t\t\t\trq=X509_to_X509_REQ(x,pk,EVP_md5());\n\t\t\t\tEVP_PKEY_free(pk);\n\t\t\t\tif (rq == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!noout)\n\t\t\t\t\t{\n\t\t\t\t\tX509_REQ_print(out,rq);\n\t\t\t\t\tPEM_write_bio_X509_REQ(out,rq);\n\t\t\t\t\t}\n\t\t\t\tnoout=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (noout)\n\t\t{\n\t\tret=0;\n\t\tgoto end;\n\t\t}\n\tif \t(outformat == FORMAT_ASN1)\n\t\ti=i2d_X509_bio(out,x);\n\telse if (outformat == FORMAT_PEM)\n\t\ti=PEM_write_bio_X509(out,x);\n\telse if (outformat == FORMAT_NETSCAPE)\n\t\t{\n\t\tASN1_HEADER ah;\n\t\tASN1_OCTET_STRING os;\n\t\tos.data=(unsigned char *)CERT_HDR;\n\t\tos.length=strlen(CERT_HDR);\n\t\tah.header= &os;\n\t\tah.data=(char *)x;\n\t\tah.meth=X509_asn1_meth();\n\t\ti=ASN1_i2d_bio(i2d_ASN1_HEADER,out,(unsigned char *)&ah);\n\t\t}\n\telse\t{\n\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\tgoto end;\n\t\t}\n\tif (!i) {\n\t\tBIO_printf(bio_err,"unable to write certificate\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tret=0;\nend:\n\tOBJ_cleanup();\n\tif (out != NULL) BIO_free(out);\n\tif (STDout != NULL) BIO_free(STDout);\n\tif (ctx != NULL) X509_STORE_free(ctx);\n\tif (req != NULL) X509_REQ_free(req);\n\tif (x != NULL) X509_free(x);\n\tif (xca != NULL) X509_free(xca);\n\tif (Upkey != NULL) EVP_PKEY_free(Upkey);\n\tif (CApkey != NULL) EVP_PKEY_free(CApkey);\n\tif (rq != NULL) X509_REQ_free(rq);\n\tX509V3_EXT_cleanup();\n\tEXIT(ret);\n\t}', 'X509_STORE *X509_STORE_new(void)\n\t{\n\tX509_STORE *ret;\n\tif ((ret=(X509_STORE *)Malloc(sizeof(X509_STORE))) == NULL)\n\t\treturn(NULL);\n\tret->certs=lh_new(x509_object_hash,x509_object_cmp);\n\tret->cache=1;\n\tret->get_cert_methods=sk_new_null();\n\tret->verify=NULL;\n\tret->verify_cb=NULL;\n\tmemset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA));\n\tret->references=1;\n\tret->depth=0;\n\treturn(ret);\n\t}', 'LHASH *lh_new(unsigned long (*h)(), int (*c)())\n\t{\n\tLHASH *ret;\n\tint i;\n\tif ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(int (*)())strcmp:c);\n\tret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tFree((char *)ret);\nerr0:\n\treturn(NULL);\n\t}', 'static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n\t X509 *x, X509 *xca, EVP_PKEY *pkey, char *serialfile, int create,\n\t int days)\n\t{\n\tint ret=0;\n\tBIO *io=NULL;\n\tMS_STATIC char buf2[1024];\n\tchar *buf=NULL,*p;\n\tBIGNUM *serial=NULL;\n\tASN1_INTEGER *bs=NULL,bs2;\n\tX509_STORE_CTX xsc;\n\tEVP_PKEY *upkey;\n\tupkey = X509_get_pubkey(xca);\n\tEVP_PKEY_copy_parameters(upkey,pkey);\n\tEVP_PKEY_free(upkey);\n\tX509_STORE_CTX_init(&xsc,ctx,x,NULL);\n\tbuf=(char *)Malloc(EVP_PKEY_size(pkey)*2+\n\t\t((serialfile == NULL)\n\t\t\t?(strlen(CAfile)+strlen(POSTFIX)+1)\n\t\t\t:(strlen(serialfile)))+1);\n\tif (buf == NULL) { BIO_printf(bio_err,"out of mem\\n"); goto end; }\n\tif (serialfile == NULL)\n\t\t{\n\t\tstrcpy(buf,CAfile);\n\t\tfor (p=buf; *p; p++)\n\t\t\tif (*p == \'.\')\n\t\t\t\t{\n\t\t\t\t*p=\'\\0\';\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\tstrcat(buf,POSTFIX);\n\t\t}\n\telse\n\t\tstrcpy(buf,serialfile);\n\tserial=BN_new();\n\tbs=ASN1_INTEGER_new();\n\tif ((serial == NULL) || (bs == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tio=BIO_new(BIO_s_file());\n\tif (io == NULL)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (BIO_read_filename(io,buf) <= 0)\n\t\t{\n\t\tif (!create)\n\t\t\t{\n\t\t\tperror(buf);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tASN1_INTEGER_set(bs,0);\n\t\t\tBN_zero(serial);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (!a2i_ASN1_INTEGER(io,bs,buf2,1024))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load serial number from %s\\n",buf);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tserial=BN_bin2bn(bs->data,bs->length,serial);\n\t\t\tif (serial == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"error converting bin 2 bn");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (!BN_add_word(serial,1))\n\t\t{ BIO_printf(bio_err,"add_word failure\\n"); goto end; }\n\tbs2.data=(unsigned char *)buf2;\n\tbs2.length=BN_bn2bin(serial,bs2.data);\n\tif (BIO_write_filename(io,buf) <= 0)\n\t\t{\n\t\tBIO_printf(bio_err,"error attempting to write serial number file\\n");\n\t\tperror(buf);\n\t\tgoto end;\n\t\t}\n\ti2a_ASN1_INTEGER(io,&bs2);\n\tBIO_puts(io,"\\n");\n\tBIO_free(io);\n\tio=NULL;\n\tif (!X509_STORE_add_cert(ctx,x)) goto end;\n\tX509_STORE_CTX_set_cert(&xsc,x);\n\tif (!reqfile && !X509_verify_cert(&xsc))\n\t\tgoto end;\n\tif (!X509_check_private_key(xca,pkey))\n\t\t{\n\t\tBIO_printf(bio_err,"CA certificate and CA private key do not match\\n");\n\t\tgoto end;\n\t\t}\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end;\n\tif (!X509_set_serialNumber(x,bs)) goto end;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL)\n\t\tgoto end;\n\tif (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)\n\t\tgoto end;\n\tupkey=X509_get_pubkey(x);\n\tif (!EVP_PKEY_missing_parameters(pkey) &&\n\t\t(EVP_PKEY_cmp_parameters(pkey,upkey) == 0))\n\t\t{\n\t\tEVP_PKEY_save_parameters(upkey,0);\n\t\tX509_set_pubkey(x,upkey);\n\t\t}\n\tEVP_PKEY_free(upkey);\n\tif (!X509_sign(x,pkey,digest)) goto end;\n\tret=1;\nend:\n\tX509_STORE_CTX_cleanup(&xsc);\n\tif (!ret)\n\t\tERR_print_errors(bio_err);\n\tif (buf != NULL) Free(buf);\n\tif (bs != NULL) ASN1_INTEGER_free(bs);\n\tif (io != NULL)\tBIO_free(io);\n\tif (serial != NULL) BN_free(serial);\n\treturn(ret);\n\t}', 'int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)\n\t{\n\tX509_OBJECT *obj,*r;\n\tint ret=1;\n\tif (x == NULL) return(0);\n\tobj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));\n\tif (obj == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tobj->type=X509_LU_X509;\n\tobj->data.x509=x;\n\tCRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n\tX509_OBJECT_up_ref_count(obj);\n\tr=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);\n\tif (r != NULL)\n\t\t{\n\t\tlh_delete(ctx->certs,(char *)obj);\n\t\tX509_OBJECT_free_contents(obj);\n\t\tFree(obj);\n\t\tlh_insert(ctx->certs,(char *)r);\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);\n\t\tret=0;\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\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}', '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}'] |
35,086 | 0 | https://github.com/openssl/openssl/blob/31b446e212e2209d62e66a608e540716716430e4/crypto/x509/x509_vfy.c/#L587 | static int check_chain_extensions(X509_STORE_CTX *ctx)
{
int i, ok = 0, must_be_ca, plen = 0;
X509 *x;
int (*cb) (int xok, X509_STORE_CTX *xctx);
int proxy_path_length = 0;
int purpose;
int allow_proxy_certs;
cb = ctx->verify_cb;
must_be_ca = -1;
if (ctx->parent) {
allow_proxy_certs = 0;
purpose = X509_PURPOSE_CRL_SIGN;
} else {
allow_proxy_certs =
! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))
allow_proxy_certs = 1;
purpose = ctx->param->purpose;
}
for (i = 0; i < ctx->last_untrusted; i++) {
int ret;
x = sk_X509_value(ctx->chain, i);
if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
&& (x->ex_flags & EXFLAG_CRITICAL)) {
ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) {
ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
ret = X509_check_ca(x);
switch (must_be_ca) {
case -1:
if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1) && (ret != 0)) {
ret = 0;
ctx->error = X509_V_ERR_INVALID_CA;
} else
ret = 1;
break;
case 0:
if (ret != 0) {
ret = 0;
ctx->error = X509_V_ERR_INVALID_NON_CA;
} else
ret = 1;
break;
default:
if ((ret == 0)
|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1))) {
ret = 0;
ctx->error = X509_V_ERR_INVALID_CA;
} else
ret = 1;
break;
}
if (ret == 0) {
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
if (ctx->param->purpose > 0) {
ret = X509_check_purpose(x, purpose, must_be_ca > 0);
if ((ret == 0)
|| ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
&& (ret != 1))) {
ctx->error = X509_V_ERR_INVALID_PURPOSE;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
}
if ((i > 1) && !(x->ex_flags & EXFLAG_SI)
&& (x->ex_pathlen != -1)
&& (plen > (x->ex_pathlen + proxy_path_length + 1))) {
ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
if (!(x->ex_flags & EXFLAG_SI))
plen++;
if (x->ex_flags & EXFLAG_PROXY) {
if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) {
ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
ctx->error_depth = i;
ctx->current_cert = x;
ok = cb(0, ctx);
if (!ok)
goto end;
}
proxy_path_length++;
must_be_ca = 0;
} else
must_be_ca = 1;
}
ok = 1;
end:
return ok;
} | ['static int check_chain_extensions(X509_STORE_CTX *ctx)\n{\n int i, ok = 0, must_be_ca, plen = 0;\n X509 *x;\n int (*cb) (int xok, X509_STORE_CTX *xctx);\n int proxy_path_length = 0;\n int purpose;\n int allow_proxy_certs;\n cb = ctx->verify_cb;\n must_be_ca = -1;\n if (ctx->parent) {\n allow_proxy_certs = 0;\n purpose = X509_PURPOSE_CRL_SIGN;\n } else {\n allow_proxy_certs =\n ! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);\n if (getenv("OPENSSL_ALLOW_PROXY_CERTS"))\n allow_proxy_certs = 1;\n purpose = ctx->param->purpose;\n }\n for (i = 0; i < ctx->last_untrusted; i++) {\n int ret;\n x = sk_X509_value(ctx->chain, i);\n if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)\n && (x->ex_flags & EXFLAG_CRITICAL)) {\n ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) {\n ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n ret = X509_check_ca(x);\n switch (must_be_ca) {\n case -1:\n if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1) && (ret != 0)) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_CA;\n } else\n ret = 1;\n break;\n case 0:\n if (ret != 0) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_NON_CA;\n } else\n ret = 1;\n break;\n default:\n if ((ret == 0)\n || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1))) {\n ret = 0;\n ctx->error = X509_V_ERR_INVALID_CA;\n } else\n ret = 1;\n break;\n }\n if (ret == 0) {\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (ctx->param->purpose > 0) {\n ret = X509_check_purpose(x, purpose, must_be_ca > 0);\n if ((ret == 0)\n || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)\n && (ret != 1))) {\n ctx->error = X509_V_ERR_INVALID_PURPOSE;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n }\n if ((i > 1) && !(x->ex_flags & EXFLAG_SI)\n && (x->ex_pathlen != -1)\n && (plen > (x->ex_pathlen + proxy_path_length + 1))) {\n ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n if (!(x->ex_flags & EXFLAG_SI))\n plen++;\n if (x->ex_flags & EXFLAG_PROXY) {\n if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) {\n ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;\n ctx->error_depth = i;\n ctx->current_cert = x;\n ok = cb(0, ctx);\n if (!ok)\n goto end;\n }\n proxy_path_length++;\n must_be_ca = 0;\n } else\n must_be_ca = 1;\n }\n ok = 1;\n end:\n return ok;\n}', 'void *sk_value(const _STACK *st, int i)\n{\n if (!st || (i < 0) || (i >= st->num))\n return NULL;\n return st->data[i];\n}'] |
35,087 | 0 | https://github.com/libav/libav/blob/032f4068646d6d29f4657eeb69425ec349dcaa7c/ffmpeg.c/#L4161 | static int opt_preset(const char *opt, const char *arg)
{
FILE *f=NULL;
char filename[1000], tmp[1000], tmp2[1000], line[1000];
char *codec_name = *opt == 'v' ? video_codec_name :
*opt == 'a' ? audio_codec_name :
subtitle_codec_name;
if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
fprintf(stderr, "File for preset '%s' not found\n", arg);
ffmpeg_exit(1);
}
while(!feof(f)){
int e= fscanf(f, "%999[^\n]\n", line) - 1;
if(line[0] == '#' && !e)
continue;
e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
if(e){
fprintf(stderr, "%s: Invalid syntax: '%s'\n", filename, line);
ffmpeg_exit(1);
}
if(!strcmp(tmp, "acodec")){
opt_audio_codec(tmp2);
}else if(!strcmp(tmp, "vcodec")){
opt_video_codec(tmp2);
}else if(!strcmp(tmp, "scodec")){
opt_subtitle_codec(tmp2);
}else if(opt_default(tmp, tmp2) < 0){
fprintf(stderr, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n", filename, line, tmp, tmp2);
ffmpeg_exit(1);
}
}
fclose(f);
return 0;
} | ['static int opt_preset(const char *opt, const char *arg)\n{\n FILE *f=NULL;\n char filename[1000], tmp[1000], tmp2[1000], line[1000];\n char *codec_name = *opt == \'v\' ? video_codec_name :\n *opt == \'a\' ? audio_codec_name :\n subtitle_codec_name;\n if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == \'f\', codec_name))) {\n fprintf(stderr, "File for preset \'%s\' not found\\n", arg);\n ffmpeg_exit(1);\n }\n while(!feof(f)){\n int e= fscanf(f, "%999[^\\n]\\n", line) - 1;\n if(line[0] == \'#\' && !e)\n continue;\n e|= sscanf(line, "%999[^=]=%999[^\\n]\\n", tmp, tmp2) - 2;\n if(e){\n fprintf(stderr, "%s: Invalid syntax: \'%s\'\\n", filename, line);\n ffmpeg_exit(1);\n }\n if(!strcmp(tmp, "acodec")){\n opt_audio_codec(tmp2);\n }else if(!strcmp(tmp, "vcodec")){\n opt_video_codec(tmp2);\n }else if(!strcmp(tmp, "scodec")){\n opt_subtitle_codec(tmp2);\n }else if(opt_default(tmp, tmp2) < 0){\n fprintf(stderr, "%s: Invalid option or argument: \'%s\', parsed as \'%s\' = \'%s\'\\n", filename, line, tmp, tmp2);\n ffmpeg_exit(1);\n }\n }\n fclose(f);\n return 0;\n}'] |
35,088 | 0 | https://github.com/openssl/openssl/blob/ba4341316ce762f917f973bb4ac604062fb11724/crypto/property/property_parse.c/#L54 | static const char *skip_space(const char *s)
{
while (ossl_isspace(*s))
s++;
return s;
} | ['static int test_register_deregister(void)\n{\n static const struct {\n int nid;\n const char *prop;\n char *impl;\n } impls[] = {\n { 6, "position=1", "a" },\n { 6, "position=2", "b" },\n { 6, "position=3", "c" },\n { 6, "position=4", "d" },\n };\n size_t i;\n int ret = 0;\n OSSL_METHOD_STORE *store;\n if (!TEST_ptr(store = ossl_method_store_new(NULL))\n || !add_property_names("position", NULL))\n goto err;\n for (i = 0; i < OSSL_NELEM(impls); i++)\n if (!TEST_true(ossl_method_store_add(store, impls[i].nid, impls[i].prop,\n impls[i].impl, NULL))) {\n TEST_note("iteration %zd", i + 1);\n goto err;\n }\n for (i = 0; i < OSSL_NELEM(impls); i++) {\n const size_t j = (1 + i * 3) % OSSL_NELEM(impls);\n int nid = impls[j].nid;\n void *impl = impls[j].impl;\n if (!TEST_true(ossl_method_store_remove(store, nid, impl))\n || !TEST_false(ossl_method_store_remove(store, nid, impl))) {\n TEST_note("iteration %zd, position %zd", i + 1, j + 1);\n goto err;\n }\n }\n if (TEST_false(ossl_method_store_remove(store, impls[0].nid, impls[0].impl)))\n ret = 1;\nerr:\n ossl_method_store_free(store);\n return ret;\n}', 'int ossl_method_store_add(OSSL_METHOD_STORE *store,\n int nid, const char *properties,\n void *method, void (*method_destruct)(void *))\n{\n ALGORITHM *alg = NULL;\n IMPLEMENTATION *impl;\n int ret = 0;\n if (nid <= 0 || method == NULL || store == NULL)\n return 0;\n if (properties == NULL)\n properties = "";\n impl = OPENSSL_malloc(sizeof(*impl));\n if (impl == NULL)\n return 0;\n impl->method = method;\n impl->method_destruct = method_destruct;\n ossl_property_write_lock(store);\n ossl_method_cache_flush(store, nid);\n if ((impl->properties = ossl_prop_defn_get(store->ctx, properties)) == NULL) {\n impl->properties = ossl_parse_property(store->ctx, properties);\n if (impl->properties == NULL)\n goto err;\n ossl_prop_defn_set(store->ctx, properties, impl->properties);\n }\n alg = ossl_method_store_retrieve(store, nid);\n if (alg == NULL) {\n if ((alg = OPENSSL_zalloc(sizeof(*alg))) == NULL\n || (alg->impls = sk_IMPLEMENTATION_new_null()) == NULL\n || (alg->cache = lh_QUERY_new(&query_hash, &query_cmp)) == NULL)\n goto err;\n alg->nid = nid;\n if (!ossl_method_store_insert(store, alg))\n goto err;\n }\n if (sk_IMPLEMENTATION_push(alg->impls, impl))\n ret = 1;\n ossl_property_unlock(store);\n if (ret == 0)\n impl_free(impl);\n return ret;\nerr:\n ossl_property_unlock(store);\n alg_cleanup(0, alg);\n impl_free(impl);\n return 0;\n}', 'OSSL_PROPERTY_LIST *ossl_parse_property(OPENSSL_CTX *ctx, const char *defn)\n{\n PROPERTY_DEFINITION *prop = NULL;\n OSSL_PROPERTY_LIST *res = NULL;\n STACK_OF(PROPERTY_DEFINITION) *sk;\n const char *s = defn;\n int done;\n if (s == NULL || (sk = sk_PROPERTY_DEFINITION_new(&pd_compare)) == NULL)\n return NULL;\n s = skip_space(s);\n done = *s == \'\\0\';\n while (!done) {\n const char *start = s;\n prop = OPENSSL_malloc(sizeof(*prop));\n if (prop == NULL)\n goto err;\n memset(&prop->v, 0, sizeof(prop->v));\n prop->optional = 0;\n if (!parse_name(ctx, &s, 1, &prop->name_idx))\n goto err;\n prop->oper = PROPERTY_OPER_EQ;\n if (prop->name_idx == 0) {\n PROPerr(PROP_F_OSSL_PARSE_PROPERTY, PROP_R_PARSE_FAILED);\n ERR_add_error_data(2, "Unknown name HERE-->", start);\n goto err;\n }\n if (match_ch(&s, \'=\')) {\n if (!parse_value(ctx, &s, prop, 1)) {\n PROPerr(PROP_F_OSSL_PARSE_PROPERTY, PROP_R_NO_VALUE);\n ERR_add_error_data(2, "HERE-->", start);\n goto err;\n }\n } else {\n prop->type = PROPERTY_TYPE_STRING;\n prop->v.str_val = ossl_property_true;\n }\n if (!sk_PROPERTY_DEFINITION_push(sk, prop))\n goto err;\n prop = NULL;\n done = !match_ch(&s, \',\');\n }\n if (*s != \'\\0\') {\n PROPerr(PROP_F_OSSL_PARSE_PROPERTY, PROP_R_TRAILING_CHARACTERS);\n ERR_add_error_data(2, "HERE-->", s);\n goto err;\n }\n res = stack_to_property_list(sk);\nerr:\n OPENSSL_free(prop);\n sk_PROPERTY_DEFINITION_pop_free(sk, &pd_free);\n return res;\n}', 'static const char *skip_space(const char *s)\n{\n while (ossl_isspace(*s))\n s++;\n return s;\n}', 'static int parse_name(OPENSSL_CTX *ctx, const char *t[], int create,\n OSSL_PROPERTY_IDX *idx)\n{\n char name[100];\n int err = 0;\n size_t i = 0;\n const char *s = *t;\n int user_name = 0;\n for (;;) {\n if (!ossl_isalpha(*s)) {\n PROPerr(PROP_F_PARSE_NAME, PROP_R_NOT_AN_IDENTIFIER);\n ERR_add_error_data(2, "HERE-->", *t);\n return 0;\n }\n do {\n if (i < sizeof(name) - 1)\n name[i++] = ossl_tolower(*s);\n else\n err = 1;\n } while (*++s == \'_\' || ossl_isalnum(*s));\n if (*s != \'.\')\n break;\n user_name = 1;\n if (i < sizeof(name) - 1)\n name[i++] = *s;\n else\n err = 1;\n s++;\n }\n name[i] = \'\\0\';\n if (err) {\n PROPerr(PROP_F_PARSE_NAME, PROP_R_NAME_TOO_LONG);\n ERR_add_error_data(2, "HERE-->", *t);\n return 0;\n }\n *t = skip_space(s);\n *idx = ossl_property_name(ctx, name, user_name && create);\n return 1;\n}', 'static int match_ch(const char *t[], char m)\n{\n const char *s = *t;\n if (*s == m) {\n *t = skip_space(s + 1);\n return 1;\n }\n return 0;\n}', 'static int parse_value(OPENSSL_CTX *ctx, const char *t[],\n PROPERTY_DEFINITION *res, int create)\n{\n const char *s = *t;\n int r = 0;\n if (*s == \'"\' || *s == \'\\\'\') {\n s++;\n r = parse_string(ctx, &s, s[-1], res, create);\n } else if (*s == \'+\') {\n s++;\n r = parse_number(&s, res);\n } else if (*s == \'-\') {\n s++;\n r = parse_number(&s, res);\n res->v.int_val = -res->v.int_val;\n } else if (*s == \'0\' && s[1] == \'x\') {\n s += 2;\n r = parse_hex(&s, res);\n } else if (*s == \'0\' && ossl_isdigit(s[1])) {\n s++;\n r = parse_oct(&s, res);\n } else if (ossl_isdigit(*s)) {\n return parse_number(t, res);\n } else if (ossl_isalpha(*s))\n return parse_unquoted(ctx, t, res, create);\n if (r)\n *t = s;\n return r;\n}', 'static int parse_string(OPENSSL_CTX *ctx, const char *t[], char delim,\n PROPERTY_DEFINITION *res, const int create)\n{\n char v[1000];\n const char *s = *t;\n size_t i = 0;\n int err = 0;\n while (*s != \'\\0\' && *s != delim) {\n if (i < sizeof(v) - 1)\n v[i++] = *s;\n else\n err = 1;\n s++;\n }\n if (*s == \'\\0\') {\n char buf[2] = { 0, 0 };\n PROPerr(PROP_F_PARSE_STRING,\n PROP_R_NO_MATCHING_STRING_DELIMETER);\n buf[0] = delim;\n ERR_add_error_data(3, "HERE-->", buf, *t);\n return 0;\n }\n v[i] = \'\\0\';\n if (err) {\n PROPerr(PROP_F_PARSE_STRING, PROP_R_STRING_TOO_LONG);\n ERR_add_error_data(2, "HERE-->", *t);\n } else {\n res->v.str_val = ossl_property_value(ctx, v, create);\n }\n *t = skip_space(s + 1);\n res->type = PROPERTY_TYPE_STRING;\n return !err;\n}'] |
35,089 | 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)];
} | ['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_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_RECP_CTX recp;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 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}', '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_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}', '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}'] |
35,090 | 0 | https://github.com/openssl/openssl/blob/72bb2f64fc67dc644f302a07953900becced011f/ssl/ssl_lib.c/#L3178 | EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md)
{
ssl_clear_hash_ctx(hash);
*hash = EVP_MD_CTX_new();
if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {
EVP_MD_CTX_free(*hash);
*hash = NULL;
return NULL;
}
return *hash;
} | ['EVP_MD_CTX *ssl_replace_hash(EVP_MD_CTX **hash, const EVP_MD *md)\n{\n ssl_clear_hash_ctx(hash);\n *hash = EVP_MD_CTX_new();\n if (*hash == NULL || (md && EVP_DigestInit_ex(*hash, md, NULL) <= 0)) {\n EVP_MD_CTX_free(*hash);\n *hash = NULL;\n return NULL;\n }\n return *hash;\n}', 'void ssl_clear_hash_ctx(EVP_MD_CTX **hash)\n{\n if (*hash)\n EVP_MD_CTX_free(*hash);\n *hash = NULL;\n}', 'EVP_MD_CTX *EVP_MD_CTX_new(void)\n{\n return OPENSSL_zalloc(sizeof(EVP_MD_CTX));\n}', 'void *CRYPTO_zalloc(int 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(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}'] |
35,091 | 0 | https://github.com/openssl/openssl/blob/019bfef89964105cdf9256b6a6bc0aa7790bd020/crypto/bn/bn_prime.c/#L394 | static int probable_prime(BIGNUM *rnd, int bits)
{
int i;
BN_ULONG mods[NUMPRIMES];
BN_ULONG delta,maxdelta;
again:
if (!BN_rand(rnd,bits,1,1)) return(0);
for (i=1; i<NUMPRIMES; i++)
mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
maxdelta=BN_MASK2 - primes[NUMPRIMES-1];
delta=0;
loop: for (i=1; i<NUMPRIMES; i++)
{
if (((mods[i]+delta)%primes[i]) <= 1)
{
delta+=2;
if (delta > maxdelta) goto again;
goto loop;
}
}
if (!BN_add_word(rnd,delta)) return(0);
bn_check_top(rnd);
return(1);
} | ['static int probable_prime(BIGNUM *rnd, int bits)\n\t{\n\tint i;\n\tBN_ULONG mods[NUMPRIMES];\n\tBN_ULONG delta,maxdelta;\nagain:\n\tif (!BN_rand(rnd,bits,1,1)) return(0);\n\tfor (i=1; i<NUMPRIMES; i++)\n\t\tmods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);\n\tmaxdelta=BN_MASK2 - primes[NUMPRIMES-1];\n\tdelta=0;\n\tloop: for (i=1; i<NUMPRIMES; i++)\n\t\t{\n\t\tif (((mods[i]+delta)%primes[i]) <= 1)\n\t\t\t{\n\t\t\tdelta+=2;\n\t\t\tif (delta > maxdelta) goto again;\n\t\t\tgoto loop;\n\t\t\t}\n\t\t}\n\tif (!BN_add_word(rnd,delta)) return(0);\n\tbn_check_top(rnd);\n\treturn(1);\n\t}'] |
35,092 | 0 | https://github.com/openssl/openssl/blob/df24f29ae6d14a564c76fed10ac32701128c3f36/crypto/x509/x509_vpm.c/#L550 | int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param)
{
int idx;
X509_VERIFY_PARAM *ptmp;
if (!param_table)
{
param_table = sk_X509_VERIFY_PARAM_new(param_cmp);
if (!param_table)
return 0;
}
else
{
idx = sk_X509_VERIFY_PARAM_find(param_table, param);
if (idx != -1)
{
ptmp = sk_X509_VERIFY_PARAM_value(param_table, idx);
X509_VERIFY_PARAM_free(ptmp);
(void)sk_X509_VERIFY_PARAM_delete(param_table, idx);
}
}
if (!sk_X509_VERIFY_PARAM_push(param_table, param))
return 0;
return 1;
} | ['int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param)\n\t{\n\tint idx;\n\tX509_VERIFY_PARAM *ptmp;\n\tif (!param_table)\n\t\t{\n\t\tparam_table = sk_X509_VERIFY_PARAM_new(param_cmp);\n\t\tif (!param_table)\n\t\t\treturn 0;\n\t\t}\n\telse\n\t\t{\n\t\tidx = sk_X509_VERIFY_PARAM_find(param_table, param);\n\t\tif (idx != -1)\n\t\t\t{\n\t\t\tptmp = sk_X509_VERIFY_PARAM_value(param_table, idx);\n\t\t\tX509_VERIFY_PARAM_free(ptmp);\n\t\t\t(void)sk_X509_VERIFY_PARAM_delete(param_table, idx);\n\t\t\t}\n\t\t}\n\tif (!sk_X509_VERIFY_PARAM_push(param_table, param))\n\t\treturn 0;\n\treturn 1;\n\t}', 'int sk_find(_STACK *st, void *data)\n\t{\n\treturn internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n\t}', 'static int internal_find(_STACK *st, void *data, int ret_val_options)\n\t{\n\tconst void * const *r;\n\tint i;\n\tif(st == NULL) return -1;\n\tif (st->comp == NULL)\n\t\t{\n\t\tfor (i=0; i<st->num; i++)\n\t\t\tif (st->data[i] == data)\n\t\t\t\treturn(i);\n\t\treturn(-1);\n\t\t}\n\tsk_sort(st);\n\tif (data == NULL) return(-1);\n\tr=OBJ_bsearch_ex_(&data,st->data,st->num,sizeof(void *),st->comp,\n\t\t\t ret_val_options);\n\tif (r == NULL) return(-1);\n\treturn (int)((char **)r-st->data);\n\t}', 'void *sk_value(const _STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}'] |
35,093 | 0 | https://github.com/openssl/openssl/blob/69588edbaa424beb71c6a9b1be416588232cb78c/crypto/bn/bn_ctx.c/#L273 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)\n{\n BIGNUM *kinv = NULL;\n BIGNUM *m;\n BIGNUM *xr;\n BN_CTX *ctx = NULL;\n int reason = ERR_R_BN_LIB;\n DSA_SIG *ret = NULL;\n int rv = 0;\n m = BN_new();\n xr = BN_new();\n if (m == NULL || xr == NULL)\n goto err;\n if (!dsa->p || !dsa->q || !dsa->g) {\n reason = DSA_R_MISSING_PARAMETERS;\n goto err;\n }\n ret = DSA_SIG_new();\n if (ret == NULL)\n goto err;\n ret->r = BN_new();\n ret->s = BN_new();\n if (ret->r == NULL || ret->s == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n redo:\n if (!dsa_sign_setup(dsa, ctx, &kinv, &ret->r, dgst, dlen))\n goto err;\n if (dlen > BN_num_bytes(dsa->q))\n dlen = BN_num_bytes(dsa->q);\n if (BN_bin2bn(dgst, dlen, m) == NULL)\n goto err;\n if (!BN_mod_mul(xr, dsa->priv_key, ret->r, dsa->q, ctx))\n goto err;\n if (!BN_add(ret->s, xr, m))\n goto err;\n if (BN_cmp(ret->s, dsa->q) > 0)\n if (!BN_sub(ret->s, ret->s, dsa->q))\n goto err;\n if (!BN_mod_mul(ret->s, ret->s, kinv, dsa->q, ctx))\n goto err;\n if (BN_is_zero(ret->r) || BN_is_zero(ret->s))\n goto redo;\n rv = 1;\n err:\n if (rv == 0) {\n DSAerr(DSA_F_DSA_DO_SIGN, reason);\n DSA_SIG_free(ret);\n ret = NULL;\n }\n BN_CTX_free(ctx);\n BN_clear_free(m);\n BN_clear_free(xr);\n BN_clear_free(kinv);\n return ret;\n}', 'static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k, *kinv = NULL, *r = *rp;\n int ret = 0;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n return 0;\n }\n k = BN_new();\n if (k == NULL)\n goto err;\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n } else\n ctx = ctx_in;\n do {\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n dlen, ctx))\n goto err;\n } else if (!BN_rand_range(k, dsa->q))\n goto err;\n } while (BN_is_zero(k));\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx))\n goto err;\n }\n if (!BN_add(k, k, dsa->q))\n goto err;\n if (BN_num_bits(k) <= BN_num_bits(dsa->q)) {\n if (!BN_add(k, k, dsa->q))\n goto err;\n }\n if ((dsa)->meth->bn_mod_exp != NULL) {\n if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n dsa->method_mont_p))\n goto err;\n } else {\n if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n goto err;\n }\n if (!BN_mod(r, r, dsa->q, ctx))\n goto err;\n if ((kinv = BN_mod_inverse(NULL, k, dsa->q, ctx)) == NULL)\n goto err;\n BN_clear_free(*kinvp);\n *kinvp = kinv;\n kinv = NULL;\n ret = 1;\n err:\n if (!ret)\n DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n BN_clear_free(k);\n return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n BN_CTX *ctx)\n{\n BIGNUM *t;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(m);\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (a == b) {\n if (!BN_sqr(t, a, ctx))\n goto err;\n } else {\n if (!BN_mul(t, a, b, ctx))\n goto err;\n }\n if (!BN_nnmod(r, t, m, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_start", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG_EXIT(ctx);\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n int ret = 0;\n int top, al, bl;\n BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n int i;\n#endif\n#ifdef BN_RECURSION\n BIGNUM *t = NULL;\n int j = 0, k;\n#endif\n bn_check_top(a);\n bn_check_top(b);\n bn_check_top(r);\n al = a->top;\n bl = b->top;\n if ((al == 0) || (bl == 0)) {\n BN_zero(r);\n return (1);\n }\n top = al + bl;\n BN_CTX_start(ctx);\n if ((r == a) || (r == b)) {\n if ((rr = BN_CTX_get(ctx)) == NULL)\n goto err;\n } else\n rr = r;\n rr->neg = a->neg ^ b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n if (i == 0) {\n# if 0\n if (al == 4) {\n if (bn_wexpand(rr, 8) == NULL)\n goto err;\n rr->top = 8;\n bn_mul_comba4(rr->d, a->d, b->d);\n goto end;\n }\n# endif\n if (al == 8) {\n if (bn_wexpand(rr, 16) == NULL)\n goto err;\n rr->top = 16;\n bn_mul_comba8(rr->d, a->d, b->d);\n goto end;\n }\n }\n#endif\n#ifdef BN_RECURSION\n if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n if (i >= -1 && i <= 1) {\n if (i >= 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n }\n if (i == -1) {\n j = BN_num_bits_word((BN_ULONG)bl);\n }\n j = 1 << (j - 1);\n assert(j <= al || j <= bl);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (al > j || bl > j) {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d,\n j, al - j, bl - j, t->d);\n } else {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# if 0\n if (i == 1 && !BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)b;\n if (bn_wexpand(tmp_bn, al) == NULL)\n goto err;\n tmp_bn->d[bl] = 0;\n bl++;\n i--;\n } else if (i == -1 && !BN_get_flags(a, BN_FLG_STATIC_DATA)) {\n BIGNUM *tmp_bn = (BIGNUM *)a;\n if (bn_wexpand(tmp_bn, bl) == NULL)\n goto err;\n tmp_bn->d[al] = 0;\n al++;\n i++;\n }\n if (i == 0) {\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n t = BN_CTX_get(ctx);\n if (al == j) {\n if (bn_wexpand(t, k * 2) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 2) == NULL)\n goto err;\n bn_mul_recursive(rr->d, a->d, b->d, al, t->d);\n } else {\n if (bn_wexpand(t, k * 4) == NULL)\n goto err;\n if (bn_wexpand(rr, k * 4) == NULL)\n goto err;\n bn_mul_part_recursive(rr->d, a->d, b->d, al - j, j, t->d);\n }\n rr->top = top;\n goto end;\n }\n# endif\n }\n#endif\n if (bn_wexpand(rr, top) == NULL)\n goto err;\n rr->top = top;\n bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n bn_correct_top(rr);\n if (r != rr)\n BN_copy(r, rr);\n ret = 1;\n err:\n bn_check_top(r);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG_ENTRY("BN_CTX_end", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}'] |
35,094 | 0 | https://github.com/libav/libav/blob/26f027fba1c5ab482fa2488fbe0fa36c8bb33b69/libavformat/rtsp.c/#L2160 | static int sdp_read_header(AVFormatContext *s)
{
RTSPState *rt = s->priv_data;
RTSPStream *rtsp_st;
int size, i, err;
char *content;
char url[1024];
if (!ff_network_init())
return AVERROR(EIO);
if (s->max_delay < 0)
s->max_delay = DEFAULT_REORDERING_DELAY;
if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)
rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;
content = av_malloc(SDP_MAX_SIZE);
size = avio_read(s->pb, content, SDP_MAX_SIZE - 1);
if (size <= 0) {
av_free(content);
return AVERROR_INVALIDDATA;
}
content[size] ='\0';
err = ff_sdp_parse(s, content);
av_free(content);
if (err) goto fail;
for (i = 0; i < rt->nb_rtsp_streams; i++) {
char namebuf[50];
rtsp_st = rt->rtsp_streams[i];
if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {
getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),
namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
ff_url_join(url, sizeof(url), "rtp", NULL,
namebuf, rtsp_st->sdp_port,
"?localport=%d&ttl=%d&connect=%d&write_to_source=%d",
rtsp_st->sdp_port, rtsp_st->sdp_ttl,
rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0,
rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0);
append_source_addrs(url, sizeof(url), "sources",
rtsp_st->nb_include_source_addrs,
rtsp_st->include_source_addrs);
append_source_addrs(url, sizeof(url), "block",
rtsp_st->nb_exclude_source_addrs,
rtsp_st->exclude_source_addrs);
if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
&s->interrupt_callback, NULL) < 0) {
err = AVERROR_INVALIDDATA;
goto fail;
}
}
if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st)))
goto fail;
}
return 0;
fail:
ff_rtsp_close_streams(s);
ff_network_close();
return err;
} | ['static int sdp_read_header(AVFormatContext *s)\n{\n RTSPState *rt = s->priv_data;\n RTSPStream *rtsp_st;\n int size, i, err;\n char *content;\n char url[1024];\n if (!ff_network_init())\n return AVERROR(EIO);\n if (s->max_delay < 0)\n s->max_delay = DEFAULT_REORDERING_DELAY;\n if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)\n rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;\n content = av_malloc(SDP_MAX_SIZE);\n size = avio_read(s->pb, content, SDP_MAX_SIZE - 1);\n if (size <= 0) {\n av_free(content);\n return AVERROR_INVALIDDATA;\n }\n content[size] =\'\\0\';\n err = ff_sdp_parse(s, content);\n av_free(content);\n if (err) goto fail;\n for (i = 0; i < rt->nb_rtsp_streams; i++) {\n char namebuf[50];\n rtsp_st = rt->rtsp_streams[i];\n if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {\n getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip, sizeof(rtsp_st->sdp_ip),\n namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);\n ff_url_join(url, sizeof(url), "rtp", NULL,\n namebuf, rtsp_st->sdp_port,\n "?localport=%d&ttl=%d&connect=%d&write_to_source=%d",\n rtsp_st->sdp_port, rtsp_st->sdp_ttl,\n rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0,\n rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0);\n append_source_addrs(url, sizeof(url), "sources",\n rtsp_st->nb_include_source_addrs,\n rtsp_st->include_source_addrs);\n append_source_addrs(url, sizeof(url), "block",\n rtsp_st->nb_exclude_source_addrs,\n rtsp_st->exclude_source_addrs);\n if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,\n &s->interrupt_callback, NULL) < 0) {\n err = AVERROR_INVALIDDATA;\n goto fail;\n }\n }\n if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st)))\n goto fail;\n }\n return 0;\nfail:\n ff_rtsp_close_streams(s);\n ff_network_close();\n return err;\n}', 'int ff_network_init(void)\n{\n#if HAVE_WINSOCK2_H\n WSADATA wsaData;\n#endif\n if (!ff_network_inited_globally)\n av_log(NULL, AV_LOG_WARNING, "Using network protocols without global "\n "network initialization. Please use "\n "avformat_network_init(), this will "\n "become mandatory later.\\n");\n#if HAVE_WINSOCK2_H\n if (WSAStartup(MAKEWORD(1,1), &wsaData))\n return 0;\n#endif\n return 1;\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}'] |
35,095 | 0 | https://github.com/libav/libav/blob/3b2fbe67bd63b00331db2a9b213f6d420418a312/libavcodec/opus_silk.c/#L1259 | static void silk_decode_frame(SilkContext *s, OpusRangeCoder *rc,
int frame_num, int channel, int coded_channels, int active, int active1)
{
int voiced;
int qoffset_high;
int order;
float lpc_leadin[16], lpc_body[16], residual[SILK_MAX_LAG + SILK_HISTORY];
int has_lpc_leadin;
float ltpscale;
struct {
float gain;
int pitchlag;
float ltptaps[5];
} sf[4];
SilkFrame * const frame = s->frame + channel;
int i;
if (coded_channels == 2 && channel == 0) {
int n, wi[2], ws[2], w[2];
n = opus_rc_getsymbol(rc, silk_model_stereo_s1);
wi[0] = opus_rc_getsymbol(rc, silk_model_stereo_s2) + 3 * (n / 5);
ws[0] = opus_rc_getsymbol(rc, silk_model_stereo_s3);
wi[1] = opus_rc_getsymbol(rc, silk_model_stereo_s2) + 3 * (n % 5);
ws[1] = opus_rc_getsymbol(rc, silk_model_stereo_s3);
for (i = 0; i < 2; i++)
w[i] = silk_stereo_weights[wi[i]] +
(((silk_stereo_weights[wi[i] + 1] - silk_stereo_weights[wi[i]]) * 6554) >> 16)
* (ws[i]*2 + 1);
s->stereo_weights[0] = (w[0] - w[1]) / 8192.0;
s->stereo_weights[1] = w[1] / 8192.0;
s->midonly = active1 ? 0 : opus_rc_getsymbol(rc, silk_model_mid_only);
}
if (!active) {
qoffset_high = opus_rc_getsymbol(rc, silk_model_frame_type_inactive);
voiced = 0;
} else {
int type = opus_rc_getsymbol(rc, silk_model_frame_type_active);
qoffset_high = type & 1;
voiced = type >> 1;
}
for (i = 0; i < s->subframes; i++) {
int log_gain;
int ipart, fpart, lingain;
if (i == 0 && (frame_num == 0 || !frame->coded)) {
int x = opus_rc_getsymbol(rc, silk_model_gain_highbits[active + voiced]);
log_gain = (x<<3) | opus_rc_getsymbol(rc, silk_model_gain_lowbits);
if (frame->coded)
log_gain = FFMAX(log_gain, frame->log_gain - 16);
} else {
int delta_gain = opus_rc_getsymbol(rc, silk_model_gain_delta);
log_gain = av_clip(FFMAX((delta_gain<<1) - 16,
frame->log_gain + delta_gain - 4), 0, 63);
}
frame->log_gain = log_gain;
log_gain = (log_gain * 0x1D1C71 >> 16) + 2090;
ipart = log_gain >> 7;
fpart = log_gain & 127;
lingain = (1 << ipart) + ((-174 * fpart * (128-fpart) >>16) + fpart) * ((1<<ipart) >> 7);
sf[i].gain = lingain / 65536.0f;
}
silk_decode_lpc(s, frame, rc, lpc_leadin, lpc_body, &order, &has_lpc_leadin, voiced);
if (voiced) {
int lag_absolute = (!frame_num || !frame->prev_voiced);
int primarylag;
int ltpfilter;
const int8_t * offsets;
if (!lag_absolute) {
int delta = opus_rc_getsymbol(rc, silk_model_pitch_delta);
if (delta)
primarylag = frame->primarylag + delta - 9;
else
lag_absolute = 1;
}
if (lag_absolute) {
int highbits, lowbits;
const uint16_t *model[] = {
silk_model_pitch_lowbits_nb, silk_model_pitch_lowbits_mb,
silk_model_pitch_lowbits_wb
};
highbits = opus_rc_getsymbol(rc, silk_model_pitch_highbits);
lowbits = opus_rc_getsymbol(rc, model[s->bandwidth]);
primarylag = silk_pitch_min_lag[s->bandwidth] +
highbits*silk_pitch_scale[s->bandwidth] + lowbits;
}
frame->primarylag = primarylag;
if (s->subframes == 2)
offsets = (s->bandwidth == OPUS_BANDWIDTH_NARROWBAND)
? silk_pitch_offset_nb10ms[opus_rc_getsymbol(rc,
silk_model_pitch_contour_nb10ms)]
: silk_pitch_offset_mbwb10ms[opus_rc_getsymbol(rc,
silk_model_pitch_contour_mbwb10ms)];
else
offsets = (s->bandwidth == OPUS_BANDWIDTH_NARROWBAND)
? silk_pitch_offset_nb20ms[opus_rc_getsymbol(rc,
silk_model_pitch_contour_nb20ms)]
: silk_pitch_offset_mbwb20ms[opus_rc_getsymbol(rc,
silk_model_pitch_contour_mbwb20ms)];
for (i = 0; i < s->subframes; i++)
sf[i].pitchlag = av_clip(primarylag + offsets[i],
silk_pitch_min_lag[s->bandwidth],
silk_pitch_max_lag[s->bandwidth]);
ltpfilter = opus_rc_getsymbol(rc, silk_model_ltp_filter);
for (i = 0; i < s->subframes; i++) {
int index, j;
const uint16_t *filter_sel[] = {
silk_model_ltp_filter0_sel, silk_model_ltp_filter1_sel,
silk_model_ltp_filter2_sel
};
const int8_t (*filter_taps[])[5] = {
silk_ltp_filter0_taps, silk_ltp_filter1_taps, silk_ltp_filter2_taps
};
index = opus_rc_getsymbol(rc, filter_sel[ltpfilter]);
for (j = 0; j < 5; j++)
sf[i].ltptaps[j] = filter_taps[ltpfilter][index][j] / 128.0f;
}
}
if (voiced && frame_num == 0)
ltpscale = silk_ltp_scale_factor[opus_rc_getsymbol(rc,
silk_model_ltp_scale_index)] / 16384.0f;
else ltpscale = 15565.0f/16384.0f;
silk_decode_excitation(s, rc, residual + SILK_MAX_LAG, qoffset_high,
active, voiced);
if (s->output_channels == channel)
return;
for (i = 0; i < s->subframes; i++) {
const float * lpc_coeff = (i < 2 && has_lpc_leadin) ? lpc_leadin : lpc_body;
float *dst = frame->output + SILK_HISTORY + i * s->sflength;
float *resptr = residual + SILK_MAX_LAG + i * s->sflength;
float *lpc = frame->lpc_history + SILK_HISTORY + i * s->sflength;
float sum;
int j, k;
if (voiced) {
int out_end;
float scale;
if (i < 2 || s->nlsf_interp_factor == 4) {
out_end = -i * s->sflength;
scale = ltpscale;
} else {
out_end = -(i - 2) * s->sflength;
scale = 1.0f;
}
for (j = - sf[i].pitchlag - LTP_ORDER/2; j < out_end; j++) {
sum = dst[j];
for (k = 0; k < order; k++)
sum -= lpc_coeff[k] * dst[j - k - 1];
resptr[j] = av_clipf(sum, -1.0f, 1.0f) * scale / sf[i].gain;
}
if (out_end) {
float rescale = sf[i-1].gain / sf[i].gain;
for (j = out_end; j < 0; j++)
resptr[j] *= rescale;
}
for (j = 0; j < s->sflength; j++) {
sum = resptr[j];
for (k = 0; k < LTP_ORDER; k++)
sum += sf[i].ltptaps[k] * resptr[j - sf[i].pitchlag + LTP_ORDER/2 - k];
resptr[j] = sum;
}
}
for (j = 0; j < s->sflength; j++) {
sum = resptr[j] * sf[i].gain;
for (k = 1; k <= order; k++)
sum += lpc_coeff[k - 1] * lpc[j - k];
lpc[j] = sum;
dst[j] = av_clipf(sum, -1.0f, 1.0f);
}
}
frame->prev_voiced = voiced;
memmove(frame->lpc_history, frame->lpc_history + s->flength, SILK_HISTORY * sizeof(float));
memmove(frame->output, frame->output + s->flength, SILK_HISTORY * sizeof(float));
frame->coded = 1;
} | ['static void silk_decode_frame(SilkContext *s, OpusRangeCoder *rc,\n int frame_num, int channel, int coded_channels, int active, int active1)\n{\n int voiced;\n int qoffset_high;\n int order;\n float lpc_leadin[16], lpc_body[16], residual[SILK_MAX_LAG + SILK_HISTORY];\n int has_lpc_leadin;\n float ltpscale;\n struct {\n float gain;\n int pitchlag;\n float ltptaps[5];\n } sf[4];\n SilkFrame * const frame = s->frame + channel;\n int i;\n if (coded_channels == 2 && channel == 0) {\n int n, wi[2], ws[2], w[2];\n n = opus_rc_getsymbol(rc, silk_model_stereo_s1);\n wi[0] = opus_rc_getsymbol(rc, silk_model_stereo_s2) + 3 * (n / 5);\n ws[0] = opus_rc_getsymbol(rc, silk_model_stereo_s3);\n wi[1] = opus_rc_getsymbol(rc, silk_model_stereo_s2) + 3 * (n % 5);\n ws[1] = opus_rc_getsymbol(rc, silk_model_stereo_s3);\n for (i = 0; i < 2; i++)\n w[i] = silk_stereo_weights[wi[i]] +\n (((silk_stereo_weights[wi[i] + 1] - silk_stereo_weights[wi[i]]) * 6554) >> 16)\n * (ws[i]*2 + 1);\n s->stereo_weights[0] = (w[0] - w[1]) / 8192.0;\n s->stereo_weights[1] = w[1] / 8192.0;\n s->midonly = active1 ? 0 : opus_rc_getsymbol(rc, silk_model_mid_only);\n }\n if (!active) {\n qoffset_high = opus_rc_getsymbol(rc, silk_model_frame_type_inactive);\n voiced = 0;\n } else {\n int type = opus_rc_getsymbol(rc, silk_model_frame_type_active);\n qoffset_high = type & 1;\n voiced = type >> 1;\n }\n for (i = 0; i < s->subframes; i++) {\n int log_gain;\n int ipart, fpart, lingain;\n if (i == 0 && (frame_num == 0 || !frame->coded)) {\n int x = opus_rc_getsymbol(rc, silk_model_gain_highbits[active + voiced]);\n log_gain = (x<<3) | opus_rc_getsymbol(rc, silk_model_gain_lowbits);\n if (frame->coded)\n log_gain = FFMAX(log_gain, frame->log_gain - 16);\n } else {\n int delta_gain = opus_rc_getsymbol(rc, silk_model_gain_delta);\n log_gain = av_clip(FFMAX((delta_gain<<1) - 16,\n frame->log_gain + delta_gain - 4), 0, 63);\n }\n frame->log_gain = log_gain;\n log_gain = (log_gain * 0x1D1C71 >> 16) + 2090;\n ipart = log_gain >> 7;\n fpart = log_gain & 127;\n lingain = (1 << ipart) + ((-174 * fpart * (128-fpart) >>16) + fpart) * ((1<<ipart) >> 7);\n sf[i].gain = lingain / 65536.0f;\n }\n silk_decode_lpc(s, frame, rc, lpc_leadin, lpc_body, &order, &has_lpc_leadin, voiced);\n if (voiced) {\n int lag_absolute = (!frame_num || !frame->prev_voiced);\n int primarylag;\n int ltpfilter;\n const int8_t * offsets;\n if (!lag_absolute) {\n int delta = opus_rc_getsymbol(rc, silk_model_pitch_delta);\n if (delta)\n primarylag = frame->primarylag + delta - 9;\n else\n lag_absolute = 1;\n }\n if (lag_absolute) {\n int highbits, lowbits;\n const uint16_t *model[] = {\n silk_model_pitch_lowbits_nb, silk_model_pitch_lowbits_mb,\n silk_model_pitch_lowbits_wb\n };\n highbits = opus_rc_getsymbol(rc, silk_model_pitch_highbits);\n lowbits = opus_rc_getsymbol(rc, model[s->bandwidth]);\n primarylag = silk_pitch_min_lag[s->bandwidth] +\n highbits*silk_pitch_scale[s->bandwidth] + lowbits;\n }\n frame->primarylag = primarylag;\n if (s->subframes == 2)\n offsets = (s->bandwidth == OPUS_BANDWIDTH_NARROWBAND)\n ? silk_pitch_offset_nb10ms[opus_rc_getsymbol(rc,\n silk_model_pitch_contour_nb10ms)]\n : silk_pitch_offset_mbwb10ms[opus_rc_getsymbol(rc,\n silk_model_pitch_contour_mbwb10ms)];\n else\n offsets = (s->bandwidth == OPUS_BANDWIDTH_NARROWBAND)\n ? silk_pitch_offset_nb20ms[opus_rc_getsymbol(rc,\n silk_model_pitch_contour_nb20ms)]\n : silk_pitch_offset_mbwb20ms[opus_rc_getsymbol(rc,\n silk_model_pitch_contour_mbwb20ms)];\n for (i = 0; i < s->subframes; i++)\n sf[i].pitchlag = av_clip(primarylag + offsets[i],\n silk_pitch_min_lag[s->bandwidth],\n silk_pitch_max_lag[s->bandwidth]);\n ltpfilter = opus_rc_getsymbol(rc, silk_model_ltp_filter);\n for (i = 0; i < s->subframes; i++) {\n int index, j;\n const uint16_t *filter_sel[] = {\n silk_model_ltp_filter0_sel, silk_model_ltp_filter1_sel,\n silk_model_ltp_filter2_sel\n };\n const int8_t (*filter_taps[])[5] = {\n silk_ltp_filter0_taps, silk_ltp_filter1_taps, silk_ltp_filter2_taps\n };\n index = opus_rc_getsymbol(rc, filter_sel[ltpfilter]);\n for (j = 0; j < 5; j++)\n sf[i].ltptaps[j] = filter_taps[ltpfilter][index][j] / 128.0f;\n }\n }\n if (voiced && frame_num == 0)\n ltpscale = silk_ltp_scale_factor[opus_rc_getsymbol(rc,\n silk_model_ltp_scale_index)] / 16384.0f;\n else ltpscale = 15565.0f/16384.0f;\n silk_decode_excitation(s, rc, residual + SILK_MAX_LAG, qoffset_high,\n active, voiced);\n if (s->output_channels == channel)\n return;\n for (i = 0; i < s->subframes; i++) {\n const float * lpc_coeff = (i < 2 && has_lpc_leadin) ? lpc_leadin : lpc_body;\n float *dst = frame->output + SILK_HISTORY + i * s->sflength;\n float *resptr = residual + SILK_MAX_LAG + i * s->sflength;\n float *lpc = frame->lpc_history + SILK_HISTORY + i * s->sflength;\n float sum;\n int j, k;\n if (voiced) {\n int out_end;\n float scale;\n if (i < 2 || s->nlsf_interp_factor == 4) {\n out_end = -i * s->sflength;\n scale = ltpscale;\n } else {\n out_end = -(i - 2) * s->sflength;\n scale = 1.0f;\n }\n for (j = - sf[i].pitchlag - LTP_ORDER/2; j < out_end; j++) {\n sum = dst[j];\n for (k = 0; k < order; k++)\n sum -= lpc_coeff[k] * dst[j - k - 1];\n resptr[j] = av_clipf(sum, -1.0f, 1.0f) * scale / sf[i].gain;\n }\n if (out_end) {\n float rescale = sf[i-1].gain / sf[i].gain;\n for (j = out_end; j < 0; j++)\n resptr[j] *= rescale;\n }\n for (j = 0; j < s->sflength; j++) {\n sum = resptr[j];\n for (k = 0; k < LTP_ORDER; k++)\n sum += sf[i].ltptaps[k] * resptr[j - sf[i].pitchlag + LTP_ORDER/2 - k];\n resptr[j] = sum;\n }\n }\n for (j = 0; j < s->sflength; j++) {\n sum = resptr[j] * sf[i].gain;\n for (k = 1; k <= order; k++)\n sum += lpc_coeff[k - 1] * lpc[j - k];\n lpc[j] = sum;\n dst[j] = av_clipf(sum, -1.0f, 1.0f);\n }\n }\n frame->prev_voiced = voiced;\n memmove(frame->lpc_history, frame->lpc_history + s->flength, SILK_HISTORY * sizeof(float));\n memmove(frame->output, frame->output + s->flength, SILK_HISTORY * sizeof(float));\n frame->coded = 1;\n}'] |
35,096 | 0 | https://github.com/libav/libav/blob/e4e30256f87f177decf59b59e923d05ef64147df/libavcodec/indeo4.c/#L247 | static int decode_pic_hdr(IVI4DecContext *ctx, AVCodecContext *avctx)
{
int pic_size_indx, i, p;
IVIPicConfig pic_conf;
if (get_bits(&ctx->gb, 18) != 0x3FFF8) {
av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n");
return AVERROR_INVALIDDATA;
}
ctx->prev_frame_type = ctx->frame_type;
ctx->frame_type = get_bits(&ctx->gb, 3);
if (ctx->frame_type == 7) {
av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d\n", ctx->frame_type);
return AVERROR_INVALIDDATA;
}
#if IVI4_STREAM_ANALYSER
if ( ctx->frame_type == FRAMETYPE_BIDIR1
|| ctx->frame_type == FRAMETYPE_BIDIR)
ctx->has_b_frames = 1;
#endif
ctx->transp_status = get_bits1(&ctx->gb);
#if IVI4_STREAM_ANALYSER
if (ctx->transp_status) {
ctx->has_transp = 1;
}
#endif
if (get_bits1(&ctx->gb)) {
av_log(avctx, AV_LOG_ERROR, "Sync bit is set!\n");
return AVERROR_INVALIDDATA;
}
ctx->data_size = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 24) : 0;
if (ctx->frame_type >= FRAMETYPE_NULL_FIRST) {
av_dlog(avctx, "Null frame encountered!\n");
return 0;
}
if (get_bits1(&ctx->gb)) {
skip_bits_long(&ctx->gb, 32);
av_dlog(avctx, "Password-protected clip!\n");
}
pic_size_indx = get_bits(&ctx->gb, 3);
if (pic_size_indx == IVI4_PIC_SIZE_ESC) {
pic_conf.pic_height = get_bits(&ctx->gb, 16);
pic_conf.pic_width = get_bits(&ctx->gb, 16);
} else {
pic_conf.pic_height = ivi4_common_pic_sizes[pic_size_indx * 2 + 1];
pic_conf.pic_width = ivi4_common_pic_sizes[pic_size_indx * 2 ];
}
if (get_bits1(&ctx->gb)) {
pic_conf.tile_height = scale_tile_size(pic_conf.pic_height, get_bits(&ctx->gb, 4));
pic_conf.tile_width = scale_tile_size(pic_conf.pic_width, get_bits(&ctx->gb, 4));
#if IVI4_STREAM_ANALYSER
ctx->uses_tiling = 1;
#endif
} else {
pic_conf.tile_height = pic_conf.pic_height;
pic_conf.tile_width = pic_conf.pic_width;
}
if (get_bits(&ctx->gb, 2)) {
av_log(avctx, AV_LOG_ERROR, "Only YVU9 picture format is supported!\n");
return AVERROR_INVALIDDATA;
}
pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
pic_conf.luma_bands = decode_plane_subdivision(&ctx->gb);
if (pic_conf.luma_bands)
pic_conf.chroma_bands = decode_plane_subdivision(&ctx->gb);
ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n",
pic_conf.luma_bands, pic_conf.chroma_bands);
return AVERROR_INVALIDDATA;
}
if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) {
if (ff_ivi_init_planes(ctx->planes, &pic_conf)) {
av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n");
return AVERROR(ENOMEM);
}
ctx->pic_conf = pic_conf;
for (p = 0; p <= 2; p++) {
for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {
ctx->planes[p].bands[i].mb_size = !p ? (!ctx->is_scalable ? 16 : 8) : 4;
ctx->planes[p].bands[i].blk_size = !p ? 8 : 4;
}
}
if (ff_ivi_init_tiles(ctx->planes, ctx->pic_conf.tile_width,
ctx->pic_conf.tile_height)) {
av_log(avctx, AV_LOG_ERROR,
"Couldn't reallocate internal structures!\n");
return AVERROR(ENOMEM);
}
}
ctx->frame_num = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 20) : 0;
if (get_bits1(&ctx->gb))
skip_bits(&ctx->gb, 8);
if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_MB_HUFF, &ctx->mb_vlc, avctx) ||
ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, &ctx->blk_vlc, avctx))
return AVERROR_INVALIDDATA;
ctx->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8;
ctx->in_imf = get_bits1(&ctx->gb);
ctx->in_q = get_bits1(&ctx->gb);
ctx->pic_glob_quant = get_bits(&ctx->gb, 5);
ctx->unknown1 = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 0;
ctx->checksum = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 16) : 0;
while (get_bits1(&ctx->gb)) {
av_dlog(avctx, "Pic hdr extension encountered!\n");
skip_bits(&ctx->gb, 8);
}
if (get_bits1(&ctx->gb)) {
av_log(avctx, AV_LOG_ERROR, "Bad blocks bits encountered!\n");
}
align_get_bits(&ctx->gb);
return 0;
} | ['static int decode_pic_hdr(IVI4DecContext *ctx, AVCodecContext *avctx)\n{\n int pic_size_indx, i, p;\n IVIPicConfig pic_conf;\n if (get_bits(&ctx->gb, 18) != 0x3FFF8) {\n av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\\n");\n return AVERROR_INVALIDDATA;\n }\n ctx->prev_frame_type = ctx->frame_type;\n ctx->frame_type = get_bits(&ctx->gb, 3);\n if (ctx->frame_type == 7) {\n av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d\\n", ctx->frame_type);\n return AVERROR_INVALIDDATA;\n }\n#if IVI4_STREAM_ANALYSER\n if ( ctx->frame_type == FRAMETYPE_BIDIR1\n || ctx->frame_type == FRAMETYPE_BIDIR)\n ctx->has_b_frames = 1;\n#endif\n ctx->transp_status = get_bits1(&ctx->gb);\n#if IVI4_STREAM_ANALYSER\n if (ctx->transp_status) {\n ctx->has_transp = 1;\n }\n#endif\n if (get_bits1(&ctx->gb)) {\n av_log(avctx, AV_LOG_ERROR, "Sync bit is set!\\n");\n return AVERROR_INVALIDDATA;\n }\n ctx->data_size = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 24) : 0;\n if (ctx->frame_type >= FRAMETYPE_NULL_FIRST) {\n av_dlog(avctx, "Null frame encountered!\\n");\n return 0;\n }\n if (get_bits1(&ctx->gb)) {\n skip_bits_long(&ctx->gb, 32);\n av_dlog(avctx, "Password-protected clip!\\n");\n }\n pic_size_indx = get_bits(&ctx->gb, 3);\n if (pic_size_indx == IVI4_PIC_SIZE_ESC) {\n pic_conf.pic_height = get_bits(&ctx->gb, 16);\n pic_conf.pic_width = get_bits(&ctx->gb, 16);\n } else {\n pic_conf.pic_height = ivi4_common_pic_sizes[pic_size_indx * 2 + 1];\n pic_conf.pic_width = ivi4_common_pic_sizes[pic_size_indx * 2 ];\n }\n if (get_bits1(&ctx->gb)) {\n pic_conf.tile_height = scale_tile_size(pic_conf.pic_height, get_bits(&ctx->gb, 4));\n pic_conf.tile_width = scale_tile_size(pic_conf.pic_width, get_bits(&ctx->gb, 4));\n#if IVI4_STREAM_ANALYSER\n ctx->uses_tiling = 1;\n#endif\n } else {\n pic_conf.tile_height = pic_conf.pic_height;\n pic_conf.tile_width = pic_conf.pic_width;\n }\n if (get_bits(&ctx->gb, 2)) {\n av_log(avctx, AV_LOG_ERROR, "Only YVU9 picture format is supported!\\n");\n return AVERROR_INVALIDDATA;\n }\n pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;\n pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;\n pic_conf.luma_bands = decode_plane_subdivision(&ctx->gb);\n if (pic_conf.luma_bands)\n pic_conf.chroma_bands = decode_plane_subdivision(&ctx->gb);\n ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;\n if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {\n av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\\n",\n pic_conf.luma_bands, pic_conf.chroma_bands);\n return AVERROR_INVALIDDATA;\n }\n if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) {\n if (ff_ivi_init_planes(ctx->planes, &pic_conf)) {\n av_log(avctx, AV_LOG_ERROR, "Couldn\'t reallocate color planes!\\n");\n return AVERROR(ENOMEM);\n }\n ctx->pic_conf = pic_conf;\n for (p = 0; p <= 2; p++) {\n for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {\n ctx->planes[p].bands[i].mb_size = !p ? (!ctx->is_scalable ? 16 : 8) : 4;\n ctx->planes[p].bands[i].blk_size = !p ? 8 : 4;\n }\n }\n if (ff_ivi_init_tiles(ctx->planes, ctx->pic_conf.tile_width,\n ctx->pic_conf.tile_height)) {\n av_log(avctx, AV_LOG_ERROR,\n "Couldn\'t reallocate internal structures!\\n");\n return AVERROR(ENOMEM);\n }\n }\n ctx->frame_num = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 20) : 0;\n if (get_bits1(&ctx->gb))\n skip_bits(&ctx->gb, 8);\n if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_MB_HUFF, &ctx->mb_vlc, avctx) ||\n ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, &ctx->blk_vlc, avctx))\n return AVERROR_INVALIDDATA;\n ctx->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8;\n ctx->in_imf = get_bits1(&ctx->gb);\n ctx->in_q = get_bits1(&ctx->gb);\n ctx->pic_glob_quant = get_bits(&ctx->gb, 5);\n ctx->unknown1 = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 0;\n ctx->checksum = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 16) : 0;\n while (get_bits1(&ctx->gb)) {\n av_dlog(avctx, "Pic hdr extension encountered!\\n");\n skip_bits(&ctx->gb, 8);\n }\n if (get_bits1(&ctx->gb)) {\n av_log(avctx, AV_LOG_ERROR, "Bad blocks bits encountered!\\n");\n }\n align_get_bits(&ctx->gb);\n return 0;\n}'] |
35,097 | 0 | https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/bn/bn_lib.c/#L250 | int BN_num_bits(const BIGNUM *a)
{
int i = a->top - 1;
bn_check_top(a);
if (BN_is_zero(a)) return 0;
return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
} | ['static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it)\n{\n\tBIGNUM *bn;\n\tint pad;\n\tif(!*pval) return -1;\n\tbn = (BIGNUM *)*pval;\n\tif(BN_num_bits(bn) & 0x7) pad = 0;\n\telse pad = 1;\n\tif(cont) {\n\t\tif(pad) *cont++ = 0;\n\t\tBN_bn2bin(bn, cont);\n\t}\n\treturn pad + BN_num_bytes(bn);\n}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n\t{\n\tint n,i;\n\tBN_ULONG l;\n\tbn_check_top(a);\n\tn=i=BN_num_bytes(a);\n\twhile (i--)\n\t\t{\n\t\tl=a->d[i/BN_BYTES];\n\t\t*(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;\n\t\t}\n\treturn(n);\n\t}'] |
35,098 | 0 | https://github.com/openssl/openssl/blob/47bbaa5b607f592009ed40f5678fde21c10a873c/crypto/bn/bn_ctx.c/#L328 | static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
} | ['int ec_GF2m_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a,\n const EC_POINT *b, BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *x0, *y0, *x1, *y1, *x2, *y2, *s, *t;\n int ret = 0;\n if (EC_POINT_is_at_infinity(group, a)) {\n if (!EC_POINT_copy(r, b))\n return 0;\n return 1;\n }\n if (EC_POINT_is_at_infinity(group, b)) {\n if (!EC_POINT_copy(r, a))\n return 0;\n return 1;\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n return 0;\n }\n BN_CTX_start(ctx);\n x0 = BN_CTX_get(ctx);\n y0 = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n y1 = BN_CTX_get(ctx);\n x2 = BN_CTX_get(ctx);\n y2 = BN_CTX_get(ctx);\n s = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (a->Z_is_one) {\n if (!BN_copy(x0, a->X))\n goto err;\n if (!BN_copy(y0, a->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, a, x0, y0, ctx))\n goto err;\n }\n if (b->Z_is_one) {\n if (!BN_copy(x1, b->X))\n goto err;\n if (!BN_copy(y1, b->Y))\n goto err;\n } else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group, b, x1, y1, ctx))\n goto err;\n }\n if (BN_GF2m_cmp(x0, x1)) {\n if (!BN_GF2m_add(t, x0, x1))\n goto err;\n if (!BN_GF2m_add(s, y0, y1))\n goto err;\n if (!group->meth->field_div(group, s, s, t, ctx))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, t))\n goto err;\n } else {\n if (BN_GF2m_cmp(y0, y1) || BN_is_zero(x1)) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n ret = 1;\n goto err;\n }\n if (!group->meth->field_div(group, s, y1, x1, ctx))\n goto err;\n if (!BN_GF2m_add(s, s, x1))\n goto err;\n if (!group->meth->field_sqr(group, x2, s, ctx))\n goto err;\n if (!BN_GF2m_add(x2, x2, s))\n goto err;\n if (!BN_GF2m_add(x2, x2, group->a))\n goto err;\n }\n if (!BN_GF2m_add(y2, x1, x2))\n goto err;\n if (!group->meth->field_mul(group, y2, y2, s, ctx))\n goto err;\n if (!BN_GF2m_add(y2, y2, x2))\n goto err;\n if (!BN_GF2m_add(y2, y2, y1))\n goto err;\n if (!EC_POINT_set_affine_coordinates_GF2m(group, r, x2, y2, ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG_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}'] |
35,099 | 0 | https://github.com/libav/libav/blob/7684a36113fa12c88ba80b5498f05849a6b58632/libavformat/rtspdec.c/#L134 | static inline int check_sessionid(AVFormatContext *s,
RTSPMessageHeader *request)
{
RTSPState *rt = s->priv_data;
unsigned char *session_id = rt->session_id;
if (!session_id[0]) {
av_log(s, AV_LOG_WARNING, "There is no session-id at the moment\n");
return 0;
}
if (strcmp(session_id, request->session_id)) {
av_log(s, AV_LOG_ERROR, "Unexpected session-id %s\n",
request->session_id);
rtsp_send_reply(s, RTSP_STATUS_SESSION, NULL, request->seq);
return AVERROR_STREAM_NOT_FOUND;
}
return 0;
} | ['static inline int check_sessionid(AVFormatContext *s,\n RTSPMessageHeader *request)\n{\n RTSPState *rt = s->priv_data;\n unsigned char *session_id = rt->session_id;\n if (!session_id[0]) {\n av_log(s, AV_LOG_WARNING, "There is no session-id at the moment\\n");\n return 0;\n }\n if (strcmp(session_id, request->session_id)) {\n av_log(s, AV_LOG_ERROR, "Unexpected session-id %s\\n",\n request->session_id);\n rtsp_send_reply(s, RTSP_STATUS_SESSION, NULL, request->seq);\n return AVERROR_STREAM_NOT_FOUND;\n }\n return 0;\n}', 'static int rtsp_send_reply(AVFormatContext *s, enum RTSPStatusCode code,\n const char *extracontent, uint16_t seq)\n{\n RTSPState *rt = s->priv_data;\n char message[4096];\n int index = 0;\n while (status_messages[index].code) {\n if (status_messages[index].code == code) {\n snprintf(message, sizeof(message), "RTSP/1.0 %d %s\\r\\n",\n code, status_messages[index].message);\n break;\n }\n index++;\n }\n if (!status_messages[index].code)\n return AVERROR(EINVAL);\n av_strlcatf(message, sizeof(message), "CSeq: %d\\r\\n", seq);\n av_strlcatf(message, sizeof(message), "Server: %s\\r\\n", LIBAVFORMAT_IDENT);\n if (extracontent)\n av_strlcat(message, extracontent, sizeof(message));\n av_strlcat(message, "\\r\\n", sizeof(message));\n av_dlog(s, "Sending response:\\n%s", message);\n ffurl_write(rt->rtsp_hd, message, strlen(message));\n return 0;\n}'] |
35,100 | 0 | https://github.com/openssl/openssl/blob/9c46f4b9cd4912b61cb546c48b678488d7f26ed6/crypto/constant_time_locl.h/#L160 | static inline unsigned int constant_time_is_zero(unsigned int a)
{
return constant_time_msb(~a & (a - 1));
} | ['static int RSA_eay_private_decrypt(int flen, const unsigned char *from,\n unsigned char *to, RSA *rsa, int padding)\n{\n BIGNUM *f, *ret;\n int j, num = 0, r = -1;\n unsigned char *p;\n unsigned char *buf = NULL;\n BN_CTX *ctx = NULL;\n int local_blinding = 0;\n BIGNUM *unblind = NULL;\n BN_BLINDING *blinding = NULL;\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 (!f || !ret || !buf) {\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (flen > num) {\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,\n RSA_R_DATA_GREATER_THAN_MOD_LEN);\n goto err;\n }\n if (BN_bin2bn(from, (int)flen, f) == NULL)\n goto err;\n if (BN_ucmp(f, rsa->n) >= 0) {\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,\n RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n goto err;\n }\n if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {\n blinding = rsa_get_blinding(rsa, &local_blinding, ctx);\n if (blinding == NULL) {\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n }\n if (blinding != NULL) {\n if (!local_blinding && ((unblind = BN_CTX_get(ctx)) == NULL)) {\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!rsa_blinding_convert(blinding, f, unblind, ctx))\n goto err;\n }\n if ((rsa->flags & RSA_FLAG_EXT_PKEY) ||\n ((rsa->p != NULL) &&\n (rsa->q != NULL) &&\n (rsa->dmp1 != NULL) && (rsa->dmq1 != NULL) && (rsa->iqmp != NULL))) {\n if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx))\n goto err;\n } else {\n BIGNUM *d = NULL, *local_d = NULL;\n if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {\n local_d = d = BN_new();\n if (!d) {\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n } else\n d = rsa->d;\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {\n if (local_d)\n BN_free(local_d);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n if (local_d)\n BN_free(local_d);\n goto err;\n }\n if (local_d)\n BN_free(local_d);\n }\n if (blinding)\n if (!rsa_blinding_invert(blinding, ret, unblind, ctx))\n goto err;\n p = buf;\n j = BN_bn2bin(ret, p);\n switch (padding) {\n case RSA_PKCS1_PADDING:\n r = RSA_padding_check_PKCS1_type_2(to, num, buf, j, num);\n break;\n# ifndef OPENSSL_NO_SHA\n case RSA_PKCS1_OAEP_PADDING:\n r = RSA_padding_check_PKCS1_OAEP(to, num, buf, j, num, NULL, 0);\n break;\n# endif\n case RSA_SSLV23_PADDING:\n r = RSA_padding_check_SSLv23(to, num, buf, j, num);\n break;\n case RSA_NO_PADDING:\n r = RSA_padding_check_none(to, num, buf, j, num);\n break;\n default:\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, RSA_R_UNKNOWN_PADDING_TYPE);\n goto err;\n }\n if (r < 0)\n RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n if (buf != NULL) {\n OPENSSL_cleanse(buf, num);\n OPENSSL_free(buf);\n }\n return (r);\n}', 'int BN_bn2bin(const BIGNUM *a, unsigned char *to)\n{\n int n, i;\n BN_ULONG l;\n bn_check_top(a);\n n = i = BN_num_bytes(a);\n while (i--) {\n l = a->d[i / BN_BYTES];\n *(to++) = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff;\n }\n return (n);\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 RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,\n const unsigned char *from, int flen, int num,\n const unsigned char *param, int plen)\n{\n return RSA_padding_check_PKCS1_OAEP_mgf1(to, tlen, from, flen, num,\n param, plen, NULL, NULL);\n}', 'int RSA_padding_check_PKCS1_OAEP_mgf1(unsigned char *to, int tlen,\n const unsigned char *from, int flen,\n int num, const unsigned char *param,\n int plen, const EVP_MD *md,\n const EVP_MD *mgf1md)\n{\n int i, dblen, mlen = -1, one_index = 0, msg_index;\n unsigned int good, found_one_byte;\n const unsigned char *maskedseed, *maskeddb;\n unsigned char *db = NULL, *em = NULL, seed[EVP_MAX_MD_SIZE],\n phash[EVP_MAX_MD_SIZE];\n int mdlen;\n if (md == NULL)\n md = EVP_sha1();\n if (mgf1md == NULL)\n mgf1md = md;\n mdlen = EVP_MD_size(md);\n if (tlen <= 0 || flen <= 0)\n return -1;\n if (num < flen || num < 2 * mdlen + 2)\n goto decoding_err;\n dblen = num - mdlen - 1;\n db = OPENSSL_malloc(dblen);\n em = OPENSSL_malloc(num);\n if (db == NULL || em == NULL) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1, ERR_R_MALLOC_FAILURE);\n goto cleanup;\n }\n memset(em, 0, num);\n memcpy(em + num - flen, from, flen);\n good = constant_time_is_zero(em[0]);\n maskedseed = em + 1;\n maskeddb = em + 1 + mdlen;\n if (PKCS1_MGF1(seed, mdlen, maskeddb, dblen, mgf1md))\n goto cleanup;\n for (i = 0; i < mdlen; i++)\n seed[i] ^= maskedseed[i];\n if (PKCS1_MGF1(db, dblen, seed, mdlen, mgf1md))\n goto cleanup;\n for (i = 0; i < dblen; i++)\n db[i] ^= maskeddb[i];\n if (!EVP_Digest((void *)param, plen, phash, NULL, md, NULL))\n goto cleanup;\n good &= constant_time_is_zero(CRYPTO_memcmp(db, phash, mdlen));\n found_one_byte = 0;\n for (i = mdlen; i < dblen; i++) {\n unsigned int equals1 = constant_time_eq(db[i], 1);\n unsigned int equals0 = constant_time_is_zero(db[i]);\n one_index = constant_time_select_int(~found_one_byte & equals1,\n i, one_index);\n found_one_byte |= equals1;\n good &= (found_one_byte | equals0);\n }\n good &= found_one_byte;\n if (!good)\n goto decoding_err;\n msg_index = one_index + 1;\n mlen = dblen - msg_index;\n if (tlen < mlen) {\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1, RSA_R_DATA_TOO_LARGE);\n mlen = -1;\n } else {\n memcpy(to, db + msg_index, mlen);\n goto cleanup;\n }\n decoding_err:\n RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP_MGF1,\n RSA_R_OAEP_DECODING_ERROR);\n cleanup:\n if (db != NULL)\n OPENSSL_free(db);\n if (em != NULL)\n OPENSSL_free(em);\n return mlen;\n}', 'static inline unsigned int constant_time_is_zero(unsigned int a)\n{\n return constant_time_msb(~a & (a - 1));\n}'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.