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
|
|---|---|---|---|---|
901
| 0
|
https://github.com/libav/libav/blob/548a99742c2498575d0dbcd1aa030b9d51d28b18/libswscale/swscale.c/#L3220
|
static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b){
int length= FFMAX(a->length, b->length);
double *coeff= av_malloc(length*sizeof(double));
int i;
SwsVector *vec= av_malloc(sizeof(SwsVector));
vec->coeff= coeff;
vec->length= length;
for (i=0; i<length; i++) coeff[i]= 0.0;
for (i=0; i<a->length; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i];
for (i=0; i<b->length; i++) coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i];
return vec;
}
|
['static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b){\n int length= FFMAX(a->length, b->length);\n double *coeff= av_malloc(length*sizeof(double));\n int i;\n SwsVector *vec= av_malloc(sizeof(SwsVector));\n vec->coeff= coeff;\n vec->length= length;\n for (i=0; i<length; i++) coeff[i]= 0.0;\n for (i=0; i<a->length; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i];\n for (i=0; i<b->length; i++) coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i];\n return vec;\n}', 'void *av_malloc(unsigned int size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
902
| 0
|
https://github.com/openssl/openssl/blob/f10725a6e19f0d72df5789e38601918539e64082/apps/speed.c/#L1595
|
int MAIN(int argc, char **argv)
{
#ifndef OPENSSL_NO_ENGINE
ENGINE *e = NULL;
#endif
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];
unsigned char sha256[SHA256_DIGEST_LENGTH];
unsigned char sha512[SHA512_DIGEST_LENGTH];
#endif
#ifndef OPENSSL_NO_RIPEMD
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_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};
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};
#ifndef OPENSSL_NO_AES
#define MAX_BLOCK_SIZE 128
#else
#define MAX_BLOCK_SIZE 64
#endif
unsigned char DES_iv[8];
unsigned char iv[MAX_BLOCK_SIZE/8];
#ifndef OPENSSL_NO_DES
DES_cblock *buf_as_des_cblock = NULL;
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
#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_RC2 11
#define D_CBC_RC5 12
#define D_CBC_BF 13
#define D_CBC_CAST 14
#define D_CBC_128_AES 15
#define D_CBC_192_AES 16
#define D_CBC_256_AES 17
#define D_EVP 18
#define D_SHA256 19
#define D_SHA512 20
double d=0.0;
long c[ALGOR_NUM][SIZE_NUM];
#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_4096 3
#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,4096};
static unsigned char *rsa_data[RSA_NUM]=
{test512,test1024,test2048,test4096};
static int rsa_data_length[RSA_NUM]={
sizeof(test512),sizeof(test1024),
sizeof(test2048),sizeof(test4096)};
#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 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];
int ecdsa_doit[EC_NUM];
int ecdh_doit[EC_NUM];
int doit[ALGOR_NUM];
int pr_header=0;
const EVP_CIPHER *evp_cipher=NULL;
const EVP_MD *evp_md=NULL;
int decrypt=0;
#ifdef HAVE_FORK
int multi=0;
#endif
#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=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
{
BIO_printf(bio_err,"out of memory\n");
goto end;
}
#ifndef OPENSSL_NO_DES
buf_as_des_cblock = (DES_cblock *)buf;
#endif
if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
{
BIO_printf(bio_err,"out of memory\n");
goto end;
}
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;
}
e = setup_engine(bio_err, *argv, 0);
j--;
}
#endif
#ifdef HAVE_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
#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
if (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;
else
if (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;
else
#endif
#ifndef OPENSSL_NO_RIPEMD
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
#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,"rsa4096") == 0) rsa_doit[R_RSA_4096]=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_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
#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_4096]=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,"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,"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 ");
BIO_printf(bio_err,"sha256 ");
BIO_printf(bio_err,"sha512 ");
#endif
#ifndef OPENSSL_NO_RIPEMD160
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_RIPEMD160)
BIO_printf(bio_err,"\n");
#endif
#ifndef OPENSSL_NO_IDEA
BIO_printf(bio_err,"idea-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_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 ");
#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 rsa4096\n");
#endif
#ifndef OPENSSL_NO_DSA
BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
#endif
#ifndef OPENSSL_NO_ECDSA
BIO_printf(bio_err,"ecdsap160 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 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_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_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_RC2) || \
!defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
!defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES)
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");
#ifdef HAVE_FORK
BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
#endif
goto end;
}
argc--;
argv++;
j++;
}
#ifdef HAVE_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;
}
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");
if (usertime <= 0 && !mr)
{
BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
BIO_printf(bio_err,"program when this computer is idle.\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_IDEA
idea_set_encrypt_key(key16,&idea_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 i;
count*=2;
Time_F(START);
for (i=count; i; i--)
DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
&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_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_SHA256][0]=count;
c[D_SHA512][0]=count;
for (i=1; i<SIZE_NUM; i++)
{
c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
c[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];
c[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];
}
for (i=1; i<SIZE_NUM; i++)
{
long l0,l1;
l0=(long)lengths[i-1];
l1=(long)lengths[i];
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_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;
}
#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_P224; 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_P224; 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)
#define COUNT(d) (count)
signal(SIGALRM,sig_done);
#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++)
EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
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++)
EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
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_RIPEMD
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);
}
}
#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_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])
{
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);
}
}
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();
if (ecdsa[j] == NULL)
{
BIO_printf(bio_err,"ECDSA failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
ecdsa[j]->group = EC_GROUP_new_by_nid(test_curves[j]);
if (ecdsa[j]->group == NULL)
{
BIO_printf(bio_err,"ECDSA failure.Could not obtain group information\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
#if 1
EC_GROUP_precompute_mult(ecdsa[j]->group, 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();
ecdh_b[j] = EC_KEY_new();
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
{
ecdh_a[j]->group = EC_GROUP_new_by_nid(test_curves[j]);
if (ecdh_a[j]->group == NULL)
{
BIO_printf(bio_err,"ECDH failure.\n");
ERR_print_errors(bio_err);
rsa_count=1;
}
else
{
ecdh_b[j]->group = EC_GROUP_dup(ecdh_a[j]->group);
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)(void *in, size_t inlen, void *out, size_t xoutlen);
field_size = EC_GROUP_get_degree(ecdh_a[j]->group);
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,
ecdh_b[j]->pub_key,
ecdh_a[j], kdf);
secret_size_b = ECDH_compute_key(secret_b, outlen,
ecdh_a[j]->pub_key,
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,
ecdh_b[j]->pub_key,
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
#ifdef HAVE_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));
printf("available timing options: ");
#ifdef TIMES
printf("TIMES ");
#endif
#ifdef TIMEB
printf("TIMEB ");
#endif
#ifdef USE_TOD
printf("USE_TOD ");
#endif
#ifdef HZ
#define as_string(s) (#s)
{
double dbl = HZ;
printf("HZ=%g", dbl);
}
# ifdef _SC_CLK_TCK
printf(" [sysconf value]");
# endif
#endif
printf("\n");
printf("timing function used: %s%s%s%s%s%s%s\n",
(ftime_used ? "ftime" : ""),
(ftime_used + times_used > 1 ? "," : ""),
(times_used ? "times" : ""),
(ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
(gettimeofday_used ? "gettimeofday" : ""),
(ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
(getrusage_used ? "getrusage" : ""));
}
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.4fs %8.4fs %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.4fs %8.4fs %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 != NULL) OPENSSL_free(buf);
if (buf2 != NULL) OPENSSL_free(buf2);
#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\t{\n#ifndef OPENSSL_NO_ENGINE\n\tENGINE *e = NULL;\n#endif\n\tunsigned char *buf=NULL,*buf2=NULL;\n\tint mret=1;\n\tlong count=0,save_count=0;\n\tint i,j,k;\n#if !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_DSA)\n\tlong rsa_count;\n#endif\n#ifndef OPENSSL_NO_RSA\n\tunsigned rsa_num;\n#endif\n\tunsigned char md[EVP_MAX_MD_SIZE];\n#ifndef OPENSSL_NO_MD2\n\tunsigned char md2[MD2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tunsigned char mdc2[MDC2_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD4\n\tunsigned char md4[MD4_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_MD5\n\tunsigned char md5[MD5_DIGEST_LENGTH];\n\tunsigned char hmac[MD5_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_SHA\n\tunsigned char sha[SHA_DIGEST_LENGTH];\n\tunsigned char sha256[SHA256_DIGEST_LENGTH];\n\tunsigned char sha512[SHA512_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tunsigned char rmd160[RIPEMD160_DIGEST_LENGTH];\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_KEY rc4_ks;\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_KEY rc5_ks;\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_KEY rc2_ks;\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tIDEA_KEY_SCHEDULE idea_ks;\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_KEY bf_ks;\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_KEY cast_ks;\n#endif\n\tstatic const unsigned char key16[16]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic const unsigned char key24[24]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tstatic const unsigned char key32[32]=\n\t\t{0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,\n\t\t 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,\n\t\t 0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,\n\t\t 0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34,0x56};\n#ifndef OPENSSL_NO_AES\n#define MAX_BLOCK_SIZE 128\n#else\n#define MAX_BLOCK_SIZE 64\n#endif\n\tunsigned char DES_iv[8];\n\tunsigned char iv[MAX_BLOCK_SIZE/8];\n#ifndef OPENSSL_NO_DES\n\tDES_cblock *buf_as_des_cblock = NULL;\n\tstatic DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};\n\tstatic DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};\n\tstatic DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};\n\tDES_key_schedule sch;\n\tDES_key_schedule sch2;\n\tDES_key_schedule sch3;\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_KEY aes_ks1, aes_ks2, aes_ks3;\n#endif\n#define\tD_MD2\t\t0\n#define\tD_MDC2\t\t1\n#define\tD_MD4\t\t2\n#define\tD_MD5\t\t3\n#define\tD_HMAC\t\t4\n#define\tD_SHA1\t\t5\n#define D_RMD160\t6\n#define\tD_RC4\t\t7\n#define\tD_CBC_DES\t8\n#define\tD_EDE3_DES\t9\n#define\tD_CBC_IDEA\t10\n#define\tD_CBC_RC2\t11\n#define\tD_CBC_RC5\t12\n#define\tD_CBC_BF\t13\n#define\tD_CBC_CAST\t14\n#define D_CBC_128_AES\t15\n#define D_CBC_192_AES\t16\n#define D_CBC_256_AES\t17\n#define D_EVP\t\t18\n#define D_SHA256\t19\n#define D_SHA512\t20\n\tdouble d=0.0;\n\tlong c[ALGOR_NUM][SIZE_NUM];\n#define\tR_DSA_512\t0\n#define\tR_DSA_1024\t1\n#define\tR_DSA_2048\t2\n#define\tR_RSA_512\t0\n#define\tR_RSA_1024\t1\n#define\tR_RSA_2048\t2\n#define\tR_RSA_4096\t3\n#define R_EC_P160 0\n#define R_EC_P192 1\n#define R_EC_P224 2\n#define R_EC_P256 3\n#define R_EC_P384 4\n#define R_EC_P521 5\n#define R_EC_K163 6\n#define R_EC_K233 7\n#define R_EC_K283 8\n#define R_EC_K409 9\n#define R_EC_K571 10\n#define R_EC_B163 11\n#define R_EC_B233 12\n#define R_EC_B283 13\n#define R_EC_B409 14\n#define R_EC_B571 15\n#ifndef OPENSSL_NO_RSA\n\tRSA *rsa_key[RSA_NUM];\n\tlong rsa_c[RSA_NUM][2];\n\tstatic unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};\n\tstatic unsigned char *rsa_data[RSA_NUM]=\n\t\t{test512,test1024,test2048,test4096};\n\tstatic int rsa_data_length[RSA_NUM]={\n\t\tsizeof(test512),sizeof(test1024),\n\t\tsizeof(test2048),sizeof(test4096)};\n#endif\n#ifndef OPENSSL_NO_DSA\n\tDSA *dsa_key[DSA_NUM];\n\tlong dsa_c[DSA_NUM][2];\n\tstatic unsigned int dsa_bits[DSA_NUM]={512,1024,2048};\n#endif\n#ifndef OPENSSL_NO_EC\n\tstatic unsigned int test_curves[EC_NUM] =\n\t{\n\tNID_secp160r1,\n\tNID_X9_62_prime192v1,\n\tNID_secp224r1,\n\tNID_X9_62_prime256v1,\n\tNID_secp384r1,\n\tNID_secp521r1,\n\tNID_sect163k1,\n\tNID_sect233k1,\n\tNID_sect283k1,\n\tNID_sect409k1,\n\tNID_sect571k1,\n\tNID_sect163r2,\n\tNID_sect233r1,\n\tNID_sect283r1,\n\tNID_sect409r1,\n\tNID_sect571r1\n\t};\n\tstatic char * test_curves_names[EC_NUM] =\n\t{\n\t"secp160r1",\n\t"nistp192",\n\t"nistp224",\n\t"nistp256",\n\t"nistp384",\n\t"nistp521",\n\t"nistk163",\n\t"nistk233",\n\t"nistk283",\n\t"nistk409",\n\t"nistk571",\n\t"nistb163",\n\t"nistb233",\n\t"nistb283",\n\t"nistb409",\n\t"nistb571"\n\t};\n\tstatic int test_curves_bits[EC_NUM] =\n {\n 160, 192, 224, 256, 384, 521,\n 163, 233, 283, 409, 571,\n 163, 233, 283, 409, 571\n };\n#endif\n#ifndef OPENSSL_NO_ECDSA\n 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\tint rsa_doit[RSA_NUM];\n\tint dsa_doit[DSA_NUM];\n\tint ecdsa_doit[EC_NUM];\n int ecdh_doit[EC_NUM];\n\tint doit[ALGOR_NUM];\n\tint pr_header=0;\n\tconst EVP_CIPHER *evp_cipher=NULL;\n\tconst EVP_MD *evp_md=NULL;\n\tint decrypt=0;\n#ifdef HAVE_FORK\n\tint multi=0;\n#endif\n#ifndef TIMES\n\tusertime=-1;\n#endif\n\tapps_startup();\n\tmemset(results, 0, sizeof(results));\n#ifndef OPENSSL_NO_DSA\n\tmemset(dsa_key,0,sizeof(dsa_key));\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++) ecdsa[i] = NULL;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t\t{\n\t\tecdh_a[i] = NULL;\n\t\tecdh_b[i] = NULL;\n\t\t}\n#endif\n\tif (bio_err == NULL)\n\t\tif ((bio_err=BIO_new(BIO_s_file())) != NULL)\n\t\t\tBIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_key,0,sizeof(rsa_key));\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_key[i]=NULL;\n#endif\n\tif ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_DES\n\tbuf_as_des_cblock = (DES_cblock *)buf;\n#endif\n\tif ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tmemset(c,0,sizeof(c));\n\tmemset(DES_iv,0,sizeof(DES_iv));\n\tmemset(iv,0,sizeof(iv));\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tdoit[i]=0;\n\tfor (i=0; i<RSA_NUM; i++)\n\t\trsa_doit[i]=0;\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tdsa_doit[i]=0;\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++)\n\t\tecdsa_doit[i]=0;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t\tecdh_doit[i]=0;\n#endif\n\tj=0;\n\targc--;\n\targv++;\n\twhile (argc)\n\t\t{\n\t\tif\t((argc > 0) && (strcmp(*argv,"-elapsed") == 0))\n\t\t\t{\n\t\t\tusertime = 0;\n\t\t\tj--;\n\t\t\t}\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-evp") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no EVP given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tevp_cipher=EVP_get_cipherbyname(*argv);\n\t\t\tif(!evp_cipher)\n\t\t\t\t{\n\t\t\t\tevp_md=EVP_get_digestbyname(*argv);\n\t\t\t\t}\n\t\t\tif(!evp_cipher && !evp_md)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"%s is an unknown cipher or digest\\n",*argv);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tdoit[D_EVP]=1;\n\t\t\t}\n\t\telse if (argc > 0 && !strcmp(*argv,"-decrypt"))\n\t\t\t{\n\t\t\tdecrypt=1;\n\t\t\tj--;\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-engine") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no engine given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n e = setup_engine(bio_err, *argv, 0);\n\t\t\tj--;\n\t\t\t}\n#endif\n#ifdef HAVE_FORK\n\t\telse if\t((argc > 0) && (strcmp(*argv,"-multi") == 0))\n\t\t\t{\n\t\t\targc--;\n\t\t\targv++;\n\t\t\tif(argc == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"no multi count given\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tmulti=atoi(argv[0]);\n\t\t\tif(multi <= 0)\n\t\t\t {\n\t\t\t\tBIO_printf(bio_err,"bad multi count\\n");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\tj--;\n\t\t\t}\n#endif\n\t\telse if (argc > 0 && !strcmp(*argv,"-mr"))\n\t\t\t{\n\t\t\tmr=1;\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#ifndef OPENSSL_NO_MD2\n\t\tif\t(strcmp(*argv,"md2") == 0) doit[D_MD2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tif (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tif (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tif (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_SHA\n\t\t\tif (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha") == 0)\tdoit[D_SHA1]=1,\n\t\t\t\t\t\t\tdoit[D_SHA256]=1,\n\t\t\t\t\t\t\tdoit[D_SHA512]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha256") == 0) doit[D_SHA256]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"sha512") == 0) doit[D_SHA512]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\t\t\tif (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;\n\t\telse\n\t\t\tif (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tif (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;\n\t\telse\tif (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes-128-cbc") == 0) doit[D_CBC_128_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-192-cbc") == 0) doit[D_CBC_192_AES]=1;\n\t\telse\tif (strcmp(*argv,"aes-256-cbc") == 0) doit[D_CBC_256_AES]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n#if 0\n\t\t\tif (strcmp(*argv,"rsaref") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_openssl_method(RSA_PKCS1_RSAref());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#ifndef RSA_NULL\n\t\t\tif (strcmp(*argv,"openssl") == 0)\n\t\t\t{\n\t\t\tRSA_set_default_method(RSA_PKCS1_SSLeay());\n\t\t\tj--;\n\t\t\t}\n\t\telse\n#endif\n#endif\n\t\t if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;\n\t\telse if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;\n\t\telse if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;\n\t\telse if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;\n\t\telse if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;\n\t\telse if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;\n\t\telse\n#ifndef OPENSSL_NO_RC2\n\t\t if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;\n\t\telse if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;\n\t\telse if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;\n\t\telse if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;\n\t\telse if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_CAST\n\t\t if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;\n\t\telse if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tif (strcmp(*argv,"des") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_DES]=1;\n\t\t\tdoit[D_EDE3_DES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tif (strcmp(*argv,"aes") == 0)\n\t\t\t{\n\t\t\tdoit[D_CBC_128_AES]=1;\n\t\t\tdoit[D_CBC_192_AES]=1;\n\t\t\tdoit[D_CBC_256_AES]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tif (strcmp(*argv,"rsa") == 0)\n\t\t\t{\n\t\t\trsa_doit[R_RSA_512]=1;\n\t\t\trsa_doit[R_RSA_1024]=1;\n\t\t\trsa_doit[R_RSA_2048]=1;\n\t\t\trsa_doit[R_RSA_4096]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tif (strcmp(*argv,"dsa") == 0)\n\t\t\t{\n\t\t\tdsa_doit[R_DSA_512]=1;\n\t\t\tdsa_doit[R_DSA_1024]=1;\n\t\t\tdsa_doit[R_DSA_2048]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t if (strcmp(*argv,"ecdsap160") == 0) ecdsa_doit[R_EC_P160]=2;\n\t\telse if (strcmp(*argv,"ecdsap224") == 0) ecdsa_doit[R_EC_P224]=2;\n\t\telse if (strcmp(*argv,"ecdsap256") == 0) ecdsa_doit[R_EC_P256]=2;\n\t\telse if (strcmp(*argv,"ecdsap384") == 0) ecdsa_doit[R_EC_P384]=2;\n\t\telse if (strcmp(*argv,"ecdsap521") == 0) ecdsa_doit[R_EC_P521]=2;\n\t\telse if (strcmp(*argv,"ecdsak163") == 0) ecdsa_doit[R_EC_K163]=2;\n\t\telse if (strcmp(*argv,"ecdsak233") == 0) ecdsa_doit[R_EC_K233]=2;\n\t\telse if (strcmp(*argv,"ecdsak283") == 0) ecdsa_doit[R_EC_K283]=2;\n\t\telse if (strcmp(*argv,"ecdsak409") == 0) ecdsa_doit[R_EC_K409]=2;\n\t\telse if (strcmp(*argv,"ecdsak571") == 0) ecdsa_doit[R_EC_K571]=2;\n\t\telse if (strcmp(*argv,"ecdsab163") == 0) ecdsa_doit[R_EC_B163]=2;\n\t\telse if (strcmp(*argv,"ecdsab233") == 0) ecdsa_doit[R_EC_B233]=2;\n\t\telse if (strcmp(*argv,"ecdsab283") == 0) ecdsa_doit[R_EC_B283]=2;\n\t\telse if (strcmp(*argv,"ecdsab409") == 0) ecdsa_doit[R_EC_B409]=2;\n\t\telse if (strcmp(*argv,"ecdsab571") == 0) ecdsa_doit[R_EC_B571]=2;\n\t\telse if (strcmp(*argv,"ecdsa") == 0)\n\t\t\t{\n\t\t\tfor (i=0; i < EC_NUM; i++)\n\t\t\t\tecdsa_doit[i]=1;\n\t\t\t}\n\t\telse\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t if (strcmp(*argv,"ecdhp160") == 0) ecdh_doit[R_EC_P160]=2;\n\t\telse if (strcmp(*argv,"ecdhp224") == 0) ecdh_doit[R_EC_P224]=2;\n\t\telse if (strcmp(*argv,"ecdhp256") == 0) ecdh_doit[R_EC_P256]=2;\n\t\telse if (strcmp(*argv,"ecdhp384") == 0) ecdh_doit[R_EC_P384]=2;\n\t\telse if (strcmp(*argv,"ecdhp521") == 0) ecdh_doit[R_EC_P521]=2;\n\t\telse if (strcmp(*argv,"ecdhk163") == 0) ecdh_doit[R_EC_K163]=2;\n\t\telse if (strcmp(*argv,"ecdhk233") == 0) ecdh_doit[R_EC_K233]=2;\n\t\telse if (strcmp(*argv,"ecdhk283") == 0) ecdh_doit[R_EC_K283]=2;\n\t\telse if (strcmp(*argv,"ecdhk409") == 0) ecdh_doit[R_EC_K409]=2;\n\t\telse if (strcmp(*argv,"ecdhk571") == 0) ecdh_doit[R_EC_K571]=2;\n\t\telse if (strcmp(*argv,"ecdhb163") == 0) ecdh_doit[R_EC_B163]=2;\n\t\telse if (strcmp(*argv,"ecdhb233") == 0) ecdh_doit[R_EC_B233]=2;\n\t\telse if (strcmp(*argv,"ecdhb283") == 0) ecdh_doit[R_EC_B283]=2;\n\t\telse if (strcmp(*argv,"ecdhb409") == 0) ecdh_doit[R_EC_B409]=2;\n\t\telse if (strcmp(*argv,"ecdhb571") == 0) ecdh_doit[R_EC_B571]=2;\n\t\telse if (strcmp(*argv,"ecdh") == 0)\n\t\t\t{\n\t\t\tfor (i=0; i < EC_NUM; i++)\n\t\t\t\tecdh_doit[i]=1;\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Error: bad option or value\\n");\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available values:\\n");\n#ifndef OPENSSL_NO_MD2\n\t\t\tBIO_printf(bio_err,"md2 ");\n#endif\n#ifndef OPENSSL_NO_MDC2\n\t\t\tBIO_printf(bio_err,"mdc2 ");\n#endif\n#ifndef OPENSSL_NO_MD4\n\t\t\tBIO_printf(bio_err,"md4 ");\n#endif\n#ifndef OPENSSL_NO_MD5\n\t\t\tBIO_printf(bio_err,"md5 ");\n#ifndef OPENSSL_NO_HMAC\n\t\t\tBIO_printf(bio_err,"hmac ");\n#endif\n#endif\n#ifndef OPENSSL_NO_SHA1\n\t\t\tBIO_printf(bio_err,"sha1 ");\n\t\t\tBIO_printf(bio_err,"sha256 ");\n\t\t\tBIO_printf(bio_err,"sha512 ");\n#endif\n#ifndef OPENSSL_NO_RIPEMD160\n\t\t\tBIO_printf(bio_err,"rmd160");\n#endif\n#if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \\\n !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \\\n !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC5\n\t\t\tBIO_printf(bio_err,"rc5-cbc ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"bf-cbc");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des-cbc des-ede3 ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes-128-cbc aes-192-cbc aes-256-cbc ");\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\t\tBIO_printf(bio_err,"rc4");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\\n");\n#endif\n#ifndef OPENSSL_NO_DSA\n\t\t\tBIO_printf(bio_err,"dsa512 dsa1024 dsa2048\\n");\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\t\t\tBIO_printf(bio_err,"ecdsap160 ecdsap224 ecdsap256 ecdsap384 ecdsap521\\n");\n\t\t\tBIO_printf(bio_err,"ecdsak163 ecdsak233 ecdsak283 ecdsak409 ecdsak571\\n");\n\t\t\tBIO_printf(bio_err,"ecdsab163 ecdsab233 ecdsab283 ecdsab409 ecdsab571\\n");\n\t\t\tBIO_printf(bio_err,"ecdsa\\n");\n#endif\n#ifndef OPENSSL_NO_ECDH\n\t\t\tBIO_printf(bio_err,"ecdhp160 ecdhp224 ecdhp256 ecdhp384 ecdhp521\\n");\n\t\t\tBIO_printf(bio_err,"ecdhk163 ecdhk233 ecdhk283 ecdhk409 ecdhk571\\n");\n\t\t\tBIO_printf(bio_err,"ecdhb163 ecdhb233 ecdhb283 ecdhb409 ecdhb571\\n");\n\t\t\tBIO_printf(bio_err,"ecdh\\n");\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\t\tBIO_printf(bio_err,"idea ");\n#endif\n#ifndef OPENSSL_NO_RC2\n\t\t\tBIO_printf(bio_err,"rc2 ");\n#endif\n#ifndef OPENSSL_NO_DES\n\t\t\tBIO_printf(bio_err,"des ");\n#endif\n#ifndef OPENSSL_NO_AES\n\t\t\tBIO_printf(bio_err,"aes ");\n#endif\n#ifndef OPENSSL_NO_RSA\n\t\t\tBIO_printf(bio_err,"rsa ");\n#endif\n#ifndef OPENSSL_NO_BF\n\t\t\tBIO_printf(bio_err,"blowfish");\n#endif\n#if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \\\n !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \\\n !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_AES)\n\t\t\tBIO_printf(bio_err,"\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\tBIO_printf(bio_err,"Available options:\\n");\n#if defined(TIMES) || defined(USE_TOD)\n\t\t\tBIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\\n");\n#endif\n#ifndef OPENSSL_NO_ENGINE\n\t\t\tBIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\\n");\n#endif\n\t\t\tBIO_printf(bio_err,"-evp e use EVP e.\\n");\n\t\t\tBIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\\n");\n\t\t\tBIO_printf(bio_err,"-mr produce machine readable output.\\n");\n#ifdef HAVE_FORK\n\t\t\tBIO_printf(bio_err,"-multi n run n benchmarks in parallel.\\n");\n#endif\n\t\t\tgoto end;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\tj++;\n\t\t}\n#ifdef HAVE_FORK\n\tif(multi && do_multi(multi))\n\t\tgoto show_res;\n#endif\n\tif (j == 0)\n\t\t{\n\t\tfor (i=0; i<ALGOR_NUM; i++)\n\t\t\t{\n\t\t\tif (i != D_EVP)\n\t\t\t\tdoit[i]=1;\n\t\t\t}\n\t\tfor (i=0; i<RSA_NUM; i++)\n\t\t\trsa_doit[i]=1;\n\t\tfor (i=0; i<DSA_NUM; i++)\n\t\t\tdsa_doit[i]=1;\n\t\t}\n\tfor (i=0; i<ALGOR_NUM; i++)\n\t\tif (doit[i]) pr_header++;\n\tif (usertime == 0 && !mr)\n\t\tBIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\\n");\n\tif (usertime <= 0 && !mr)\n\t\t{\n\t\tBIO_printf(bio_err,"To get the most accurate results, try to run this\\n");\n\t\tBIO_printf(bio_err,"program when this computer is idle.\\n");\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\t{\n\t\tconst unsigned char *p;\n\t\tp=rsa_data[i];\n\t\trsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);\n\t\tif (rsa_key[i] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"internal error loading RSA key number %d\\n",i);\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,mr ? "+RK:%d:"\n\t\t\t\t : "Loaded RSA key, %d bit modulus and e= 0x",\n\t\t\t\t BN_num_bits(rsa_key[i]->n));\n\t\t\tBN_print(bio_err,rsa_key[i]->e);\n\t\t\tBIO_printf(bio_err,"\\n");\n\t\t\t}\n#endif\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_key[0]=get_dsa512();\n\tdsa_key[1]=get_dsa1024();\n\tdsa_key[2]=get_dsa2048();\n#endif\n#ifndef OPENSSL_NO_DES\n\tDES_set_key_unchecked(&key,&sch);\n\tDES_set_key_unchecked(&key2,&sch2);\n\tDES_set_key_unchecked(&key3,&sch3);\n#endif\n#ifndef OPENSSL_NO_AES\n\tAES_set_encrypt_key(key16,128,&aes_ks1);\n\tAES_set_encrypt_key(key24,192,&aes_ks2);\n\tAES_set_encrypt_key(key32,256,&aes_ks3);\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tidea_set_encrypt_key(key16,&idea_ks);\n#endif\n#ifndef OPENSSL_NO_RC4\n\tRC4_set_key(&rc4_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RC2\n\tRC2_set_key(&rc2_ks,16,key16,128);\n#endif\n#ifndef OPENSSL_NO_RC5\n\tRC5_32_set_key(&rc5_ks,16,key16,12);\n#endif\n#ifndef OPENSSL_NO_BF\n\tBF_set_key(&bf_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_CAST\n\tCAST_set_key(&cast_ks,16,key16);\n#endif\n#ifndef OPENSSL_NO_RSA\n\tmemset(rsa_c,0,sizeof(rsa_c));\n#endif\n#ifndef SIGALRM\n#ifndef OPENSSL_NO_DES\n\tBIO_printf(bio_err,"First we calculate the approximate speed ...\\n");\n\tcount=10;\n\tdo\t{\n\t\tlong i;\n\t\tcount*=2;\n\t\tTime_F(START);\n\t\tfor (i=count; i; i--)\n\t\t\tDES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,\n\t\t\t\t&sch,DES_ENCRYPT);\n\t\td=Time_F(STOP);\n\t\t} while (d <3);\n\tsave_count=count;\n\tc[D_MD2][0]=count/10;\n\tc[D_MDC2][0]=count/10;\n\tc[D_MD4][0]=count;\n\tc[D_MD5][0]=count;\n\tc[D_HMAC][0]=count;\n\tc[D_SHA1][0]=count;\n\tc[D_RMD160][0]=count;\n\tc[D_RC4][0]=count*5;\n\tc[D_CBC_DES][0]=count;\n\tc[D_EDE3_DES][0]=count/3;\n\tc[D_CBC_IDEA][0]=count;\n\tc[D_CBC_RC2][0]=count;\n\tc[D_CBC_RC5][0]=count;\n\tc[D_CBC_BF][0]=count;\n\tc[D_CBC_CAST][0]=count;\n\tc[D_CBC_128_AES][0]=count;\n\tc[D_CBC_192_AES][0]=count;\n\tc[D_CBC_256_AES][0]=count;\n\tc[D_SHA256][0]=count;\n\tc[D_SHA512][0]=count;\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tc[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];\n\t\tc[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];\n\t\tc[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];\n\t\tc[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA256][i]=c[D_SHA256][0]*4*lengths[0]/lengths[i];\n\t\tc[D_SHA512][i]=c[D_SHA512][0]*4*lengths[0]/lengths[i];\n\t\t}\n\tfor (i=1; i<SIZE_NUM; i++)\n\t\t{\n\t\tlong l0,l1;\n\t\tl0=(long)lengths[i-1];\n\t\tl1=(long)lengths[i];\n\t\tc[D_RC4][i]=c[D_RC4][i-1]*l0/l1;\n\t\tc[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;\n\t\tc[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;\n\t\tc[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;\n\t\tc[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;\n\t\tc[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;\n\t\tc[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;\n\t\tc[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;\n\t\tc[D_CBC_128_AES][i]=c[D_CBC_128_AES][i-1]*l0/l1;\n\t\tc[D_CBC_192_AES][i]=c[D_CBC_192_AES][i-1]*l0/l1;\n\t\tc[D_CBC_256_AES][i]=c[D_CBC_256_AES][i-1]*l0/l1;\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\trsa_c[R_RSA_512][0]=count/2000;\n\trsa_c[R_RSA_512][1]=count/400;\n\tfor (i=1; i<RSA_NUM; i++)\n\t\t{\n\t\trsa_c[i][0]=rsa_c[i-1][0]/8;\n\t\trsa_c[i][1]=rsa_c[i-1][1]/4;\n\t\tif ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))\n\t\t\trsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (rsa_c[i][0] == 0)\n\t\t\t\t{\n\t\t\t\trsa_c[i][0]=1;\n\t\t\t\trsa_c[i][1]=20;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tdsa_c[R_DSA_512][0]=count/1000;\n\tdsa_c[R_DSA_512][1]=count/1000/2;\n\tfor (i=1; i<DSA_NUM; i++)\n\t\t{\n\t\tdsa_c[i][0]=dsa_c[i-1][0]/4;\n\t\tdsa_c[i][1]=dsa_c[i-1][1]/4;\n\t\tif ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))\n\t\t\tdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (dsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tdsa_c[i][0]=1;\n\t\t\t\tdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tecdsa_c[R_EC_P160][0]=count/1000;\n\tecdsa_c[R_EC_P160][1]=count/1000/2;\n\tfor (i=R_EC_P224; i<=R_EC_P521; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdsa_c[R_EC_K163][0]=count/1000;\n\tecdsa_c[R_EC_K163][1]=count/1000/2;\n\tfor (i=R_EC_K233; i<=R_EC_K571; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdsa_c[R_EC_B163][0]=count/1000;\n\tecdsa_c[R_EC_B163][1]=count/1000/2;\n\tfor (i=R_EC_B233; i<=R_EC_B571; i++)\n\t\t{\n\t\tecdsa_c[i][0]=ecdsa_c[i-1][0]/2;\n\t\tecdsa_c[i][1]=ecdsa_c[i-1][1]/2;\n\t\tif ((ecdsa_doit[i] <= 1) && (ecdsa_c[i][0] == 0))\n\t\t\tecdsa_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdsa_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdsa_c[i][0]=1;\n\t\t\t\tecdsa_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tecdh_c[R_EC_P160][0]=count/1000;\n\tecdh_c[R_EC_P160][1]=count/1000;\n\tfor (i=R_EC_P224; i<=R_EC_P521; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdh_c[R_EC_K163][0]=count/1000;\n\tecdh_c[R_EC_K163][1]=count/1000;\n\tfor (i=R_EC_K233; i<=R_EC_K571; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tecdh_c[R_EC_B163][0]=count/1000;\n\tecdh_c[R_EC_B163][1]=count/1000;\n\tfor (i=R_EC_B233; i<=R_EC_B571; i++)\n\t\t{\n\t\tecdh_c[i][0]=ecdh_c[i-1][0]/2;\n\t\tecdh_c[i][1]=ecdh_c[i-1][1]/2;\n\t\tif ((ecdh_doit[i] <= 1) && (ecdh_c[i][0] == 0))\n\t\t\tecdh_doit[i]=0;\n\t\telse\n\t\t\t{\n\t\t\tif (ecdh_c[i] == 0)\n\t\t\t\t{\n\t\t\t\tecdh_c[i][0]=1;\n\t\t\t\tecdh_c[i][1]=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#endif\n#define COND(d)\t(count < (d))\n#define COUNT(d) (d)\n#else\n# error "You cannot disable DES on systems without SIGALRM."\n#endif\n#else\n#define COND(c)\t(run)\n#define COUNT(d) (count)\n\tsignal(SIGALRM,sig_done);\n#endif\n#ifndef OPENSSL_NO_MD2\n\tif (doit[D_MD2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD2],c[D_MD2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MDC2\n\tif (doit[D_MDC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MDC2][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MDC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD4\n\tif (doit[D_MD4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD4],c[D_MD4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD4][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_MD5\n\tif (doit[D_MD5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_MD5],c[D_MD5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_MD5][j]); count++)\n\t\t\t\tEVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_MD5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)\n\tif (doit[D_HMAC])\n\t\t{\n\t\tHMAC_CTX hctx;\n\t\tHMAC_CTX_init(&hctx);\n\t\tHMAC_Init_ex(&hctx,(unsigned char *)"This is a key...",\n\t\t\t16,EVP_md5(), NULL);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_HMAC][j]); count++)\n\t\t\t\t{\n\t\t\t\tHMAC_Init_ex(&hctx,NULL,0,NULL,NULL);\n\t\t\t\tHMAC_Update(&hctx,buf,lengths[j]);\n\t\t\t\tHMAC_Final(&hctx,&(hmac[0]),NULL);\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_HMAC,j,count,d);\n\t\t\t}\n\t\tHMAC_CTX_cleanup(&hctx);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA\n\tif (doit[D_SHA1])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA1][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA1,j,count,d);\n\t\t\t}\n\t\t}\n#ifndef OPENSSL_NO_SHA256\n\tif (doit[D_SHA256])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA256],c[D_SHA256][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA256][j]); count++)\n\t\t\t\tSHA256(buf,lengths[j],sha256);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA256,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_SHA512\n\tif (doit[D_SHA512])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_SHA512],c[D_SHA512][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_SHA512][j]); count++)\n\t\t\t\tSHA512(buf,lengths[j],sha512);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_SHA512,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#endif\n#ifndef OPENSSL_NO_RIPEMD\n\tif (doit[D_RMD160])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RMD160][j]); count++)\n\t\t\t\tEVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RMD160,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC4\n\tif (doit[D_RC4])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_RC4],c[D_RC4][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_RC4][j]); count++)\n\t\t\t\tRC4(&rc4_ks,(unsigned int)lengths[j],\n\t\t\t\t\tbuf,buf);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_RC4,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DES\n\tif (doit[D_CBC_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_DES][j]); count++)\n\t\t\t\tDES_ncbc_encrypt(buf,buf,lengths[j],&sch,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_DES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_EDE3_DES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)\n\t\t\t\tDES_ede3_cbc_encrypt(buf,buf,lengths[j],\n\t\t\t\t\t\t &sch,&sch2,&sch3,\n\t\t\t\t\t\t &DES_iv,DES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_EDE3_DES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_AES\n\tif (doit[D_CBC_128_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_128_AES],c[D_CBC_128_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_128_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks1,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_128_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_192_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_192_AES],c[D_CBC_192_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_192_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks2,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_192_AES,j,count,d);\n\t\t\t}\n\t\t}\n\tif (doit[D_CBC_256_AES])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_256_AES],c[D_CBC_256_AES][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_256_AES][j]); count++)\n\t\t\t\tAES_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&aes_ks3,\n\t\t\t\t\tiv,AES_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_256_AES,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_IDEA\n\tif (doit[D_CBC_IDEA])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)\n\t\t\t\tidea_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&idea_ks,\n\t\t\t\t\tiv,IDEA_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_IDEA,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC2\n\tif (doit[D_CBC_RC2])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)\n\t\t\t\tRC2_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc2_ks,\n\t\t\t\t\tiv,RC2_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC2,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_RC5\n\tif (doit[D_CBC_RC5])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)\n\t\t\t\tRC5_32_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&rc5_ks,\n\t\t\t\t\tiv,RC5_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_RC5,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_BF\n\tif (doit[D_CBC_BF])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_BF][j]); count++)\n\t\t\t\tBF_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&bf_ks,\n\t\t\t\t\tiv,BF_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_BF,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_CAST\n\tif (doit[D_CBC_CAST])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tprint_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)\n\t\t\t\tCAST_cbc_encrypt(buf,buf,\n\t\t\t\t\t(unsigned long)lengths[j],&cast_ks,\n\t\t\t\t\tiv,CAST_ENCRYPT);\n\t\t\td=Time_F(STOP);\n\t\t\tprint_result(D_CBC_CAST,j,count,d);\n\t\t\t}\n\t\t}\n#endif\n\tif (doit[D_EVP])\n\t\t{\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (evp_cipher)\n\t\t\t\t{\n\t\t\t\tEVP_CIPHER_CTX ctx;\n\t\t\t\tint outl;\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_cipher->nid);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tEVP_CIPHER_CTX_init(&ctx);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);\n\t\t\t\tEVP_CIPHER_CTX_set_padding(&ctx, 0);\n\t\t\t\tTime_F(START);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\telse\n\t\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\t\tEVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);\n\t\t\t\tif(decrypt)\n\t\t\t\t\tEVP_DecryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\telse\n\t\t\t\t\tEVP_EncryptFinal_ex(&ctx,buf,&outl);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\tEVP_CIPHER_CTX_cleanup(&ctx);\n\t\t\t\t}\n\t\t\tif (evp_md)\n\t\t\t\t{\n\t\t\t\tnames[D_EVP]=OBJ_nid2ln(evp_md->type);\n\t\t\t\tprint_message(names[D_EVP],save_count,\n\t\t\t\t\tlengths[j]);\n\t\t\t\tTime_F(START);\n\t\t\t\tfor (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)\n\t\t\t\t\tEVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);\n\t\t\t\td=Time_F(STOP);\n\t\t\t\t}\n\t\t\tprint_result(D_EVP,j,count,d);\n\t\t\t}\n\t\t}\n\tRAND_pseudo_bytes(buf,36);\n#ifndef OPENSSL_NO_RSA\n\tfor (j=0; j<RSA_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!rsa_doit[j]) continue;\n\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("private","rsa",\n\t\t\t\trsa_c[j][0],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_sign(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\t&rsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit private RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n#if 1\n\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("public","rsa",\n\t\t\t\trsa_c[j][1],rsa_bits[j],\n\t\t\t\tRSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(rsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=RSA_verify(NID_md5_sha1, buf,36, buf2,\n\t\t\t\t\trsa_num, rsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"RSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit public RSA\'s in %.2fs\\n",\n\t\t\t\t count,rsa_bits[j],d);\n\t\t\trsa_results[j][1]=d/(double)count;\n\t\t\t}\n#endif\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<RSA_NUM; j++)\n\t\t\t\trsa_doit[j]=0;\n\t\t\t}\n\t\t}\n#endif\n\tRAND_pseudo_bytes(buf,20);\n#ifndef OPENSSL_NO_DSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<DSA_NUM; j++)\n\t\t{\n\t\tunsigned int kk;\n\t\tint ret;\n\t\tif (!dsa_doit[j]) continue;\n\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t&kk,dsa_key[j]);\n\t\tif (ret == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("sign","dsa",\n\t\t\t\tdsa_c[j][0],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][0]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\t&kk,dsa_key[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA sign failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA signs in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][0]=d/(double)count;\n\t\t\trsa_count=count;\n\t\t\t}\n\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\tkk,dsa_key[j]);\n\t\tif (ret <= 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tdsa_doit[j] = 0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpkey_print_message("verify","dsa",\n\t\t\t\tdsa_c[j][1],dsa_bits[j],\n\t\t\t\tDSA_SECONDS);\n\t\t\tTime_F(START);\n\t\t\tfor (count=0,run=1; COND(dsa_c[j][1]); count++)\n\t\t\t\t{\n\t\t\t\tret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,\n\t\t\t\t\tkk,dsa_key[j]);\n\t\t\t\tif (ret <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t\t"DSA verify failure\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tcount=1;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\td=Time_F(STOP);\n\t\t\tBIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\\n"\n\t\t\t\t : "%ld %d bit DSA verify in %.2fs\\n",\n\t\t\t\t count,dsa_bits[j],d);\n\t\t\tdsa_results[j][1]=d/(double)count;\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<DSA_NUM; j++)\n\t\t\t\tdsa_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<EC_NUM; j++)\n\t\t{\n\t\tint ret;\n\t\tif (!ecdsa_doit[j]) continue;\n\t\tecdsa[j] = EC_KEY_new();\n\t\tif (ecdsa[j] == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"ECDSA failure.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tecdsa[j]->group = EC_GROUP_new_by_nid(test_curves[j]);\n\t\t\tif (ecdsa[j]->group == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDSA failure.Could not obtain group information\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\trsa_count=1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n#if 1\n\t\t\t\tEC_GROUP_precompute_mult(ecdsa[j]->group, NULL);\n#endif\n\t\t\t\tEC_KEY_generate_key(ecdsa[j]);\n\t\t\t\tret = ECDSA_sign(0, buf, 20, ecdsasig,\n\t\t\t\t\t&ecdsasiglen, ecdsa[j]);\n\t\t\t\tif (ret == 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"ECDSA sign failure. No ECDSA sign will be done.\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\trsa_count=1;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tpkey_print_message("sign","ecdsa",\n\t\t\t\t\t\tecdsa_c[j][0],\n\t\t\t\t\t\ttest_curves_bits[j],\n\t\t\t\t\t\tECDSA_SECONDS);\n\t\t\t\t\tTime_F(START);\n\t\t\t\t\tfor (count=0,run=1; COND(ecdsa_c[j][0]);\n\t\t\t\t\t\tcount++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tret=ECDSA_sign(0, buf, 20,\n\t\t\t\t\t\t\tecdsasig, &ecdsasiglen,\n\t\t\t\t\t\t\tecdsa[j]);\n\t\t\t\t\t\tif (ret == 0)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tBIO_printf(bio_err, "ECDSA sign failure\\n");\n\t\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\t\tcount=1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\td=Time_F(STOP);\n\t\t\t\t\t\tBIO_printf(bio_err, mr ? "+R5:%ld:%d:%.2f\\n" :\n\t\t\t\t\t\t"%ld %d bit ECDSA signs in %.2fs \\n",\n\t\t\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\t\t\tecdsa_results[j][0]=d/(double)count;\n\t\t\t\t\t\trsa_count=count;\n\t\t\t\t\t}\n\t\t\t\tret=ECDSA_verify(0, buf, 20, ecdsasig,\n\t\t\t\t\tecdsasiglen, ecdsa[j]);\n\t\t\t\tif (ret != 1)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"ECDSA verify failure. No ECDSA verify will be done.\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tecdsa_doit[j] = 0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tpkey_print_message("verify","ecdsa",\n\t\t\t\t\tecdsa_c[j][1],\n\t\t\t\t\ttest_curves_bits[j],\n\t\t\t\t\tECDSA_SECONDS);\n\t\t\t\t\tTime_F(START);\n\t\t\t\t\tfor (count=0,run=1; COND(ecdsa_c[j][1]); count++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tret=ECDSA_verify(0, buf, 20, ecdsasig, ecdsasiglen, ecdsa[j]);\n\t\t\t\t\t\tif (ret != 1)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tBIO_printf(bio_err, "ECDSA verify failure\\n");\n\t\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\t\tcount=1;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\td=Time_F(STOP);\n\t\t\t\t\t\tBIO_printf(bio_err, mr? "+R6:%ld:%d:%.2f\\n"\n\t\t\t\t\t\t\t: "%ld %d bit ECDSA verify in %.2fs\\n",\n\t\t\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\t\t\tecdsa_results[j][1]=d/(double)count;\n\t\t\t\t\t}\n\t\t\t\tif (rsa_count <= 1)\n\t\t\t\t\t{\n\t\t\t\t\tfor (j++; j<EC_NUM; j++)\n\t\t\t\t\tecdsa_doit[j]=0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tif (RAND_status() != 1)\n\t\t{\n\t\tRAND_seed(rnd_seed, sizeof rnd_seed);\n\t\trnd_fake = 1;\n\t\t}\n\tfor (j=0; j<EC_NUM; j++)\n\t\t{\n\t\tif (!ecdh_doit[j]) continue;\n\t\tecdh_a[j] = EC_KEY_new();\n\t\tecdh_b[j] = EC_KEY_new();\n\t\tif ((ecdh_a[j] == NULL) || (ecdh_b[j] == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"ECDH failure.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\trsa_count=1;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tecdh_a[j]->group = EC_GROUP_new_by_nid(test_curves[j]);\n\t\t\tif (ecdh_a[j]->group == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"ECDH failure.\\n");\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\trsa_count=1;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tecdh_b[j]->group = EC_GROUP_dup(ecdh_a[j]->group);\n\t\t\t\tif (!EC_KEY_generate_key(ecdh_a[j]) ||\n\t\t\t\t\t!EC_KEY_generate_key(ecdh_b[j]))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"ECDH key generation failure.\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\trsa_count=1;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tint field_size, outlen;\n\t\t\t\t\tvoid *(*kdf)(void *in, size_t inlen, void *out, size_t xoutlen);\n\t\t\t\t\tfield_size = EC_GROUP_get_degree(ecdh_a[j]->group);\n\t\t\t\t\tif (field_size <= 24 * 8)\n\t\t\t\t\t\t{\n\t\t\t\t\t\toutlen = KDF1_SHA1_len;\n\t\t\t\t\t\tkdf = KDF1_SHA1;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\toutlen = (field_size+7)/8;\n\t\t\t\t\t\tkdf = NULL;\n\t\t\t\t\t\t}\n\t\t\t\t\tsecret_size_a = ECDH_compute_key(secret_a, outlen,\n\t\t\t\t\t\tecdh_b[j]->pub_key,\n\t\t\t\t\t\tecdh_a[j], kdf);\n\t\t\t\t\tsecret_size_b = ECDH_compute_key(secret_b, outlen,\n\t\t\t\t\t\tecdh_a[j]->pub_key,\n\t\t\t\t\t\tecdh_b[j], kdf);\n\t\t\t\t\tif (secret_size_a != secret_size_b)\n\t\t\t\t\t\tecdh_checks = 0;\n\t\t\t\t\telse\n\t\t\t\t\t\tecdh_checks = 1;\n\t\t\t\t\tfor (secret_idx = 0;\n\t\t\t\t\t (secret_idx < secret_size_a)\n\t\t\t\t\t\t&& (ecdh_checks == 1);\n\t\t\t\t\t secret_idx++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (secret_a[secret_idx] != secret_b[secret_idx])\n\t\t\t\t\t\tecdh_checks = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\tif (ecdh_checks == 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tBIO_printf(bio_err,"ECDH computations don\'t match.\\n");\n\t\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\t\trsa_count=1;\n\t\t\t\t\t\t}\n\t\t\t\t\tpkey_print_message("","ecdh",\n\t\t\t\t\tecdh_c[j][0],\n\t\t\t\t\ttest_curves_bits[j],\n\t\t\t\t\tECDH_SECONDS);\n\t\t\t\t\tTime_F(START);\n\t\t\t\t\tfor (count=0,run=1; COND(ecdh_c[j][0]); count++)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECDH_compute_key(secret_a, outlen,\n\t\t\t\t\t\tecdh_b[j]->pub_key,\n\t\t\t\t\t\tecdh_a[j], kdf);\n\t\t\t\t\t\t}\n\t\t\t\t\td=Time_F(STOP);\n\t\t\t\t\tBIO_printf(bio_err, mr ? "+R7:%ld:%d:%.2f\\n" :"%ld %d-bit ECDH ops in %.2fs\\n",\n\t\t\t\t\tcount, test_curves_bits[j], d);\n\t\t\t\t\tecdh_results[j][0]=d/(double)count;\n\t\t\t\t\trsa_count=count;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tif (rsa_count <= 1)\n\t\t\t{\n\t\t\tfor (j++; j<EC_NUM; j++)\n\t\t\tecdh_doit[j]=0;\n\t\t\t}\n\t\t}\n\tif (rnd_fake) RAND_cleanup();\n#endif\n#ifdef HAVE_FORK\nshow_res:\n#endif\n\tif(!mr)\n\t\t{\n\t\tfprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_VERSION));\n fprintf(stdout,"%s\\n",SSLeay_version(SSLEAY_BUILT_ON));\n\t\tprintf("options:");\n\t\tprintf("%s ",BN_options());\n#ifndef OPENSSL_NO_MD2\n\t\tprintf("%s ",MD2_options());\n#endif\n#ifndef OPENSSL_NO_RC4\n\t\tprintf("%s ",RC4_options());\n#endif\n#ifndef OPENSSL_NO_DES\n\t\tprintf("%s ",DES_options());\n#endif\n#ifndef OPENSSL_NO_AES\n\t\tprintf("%s ",AES_options());\n#endif\n#ifndef OPENSSL_NO_IDEA\n\t\tprintf("%s ",idea_options());\n#endif\n#ifndef OPENSSL_NO_BF\n\t\tprintf("%s ",BF_options());\n#endif\n\t\tfprintf(stdout,"\\n%s\\n",SSLeay_version(SSLEAY_CFLAGS));\n\t\tprintf("available timing options: ");\n#ifdef TIMES\n\t\tprintf("TIMES ");\n#endif\n#ifdef TIMEB\n\t\tprintf("TIMEB ");\n#endif\n#ifdef USE_TOD\n\t\tprintf("USE_TOD ");\n#endif\n#ifdef HZ\n#define as_string(s) (#s)\n\t\t{\n\t\tdouble dbl = HZ;\n\t\tprintf("HZ=%g", dbl);\n\t\t}\n# ifdef _SC_CLK_TCK\n\t\tprintf(" [sysconf value]");\n# endif\n#endif\n\t\tprintf("\\n");\n\t\tprintf("timing function used: %s%s%s%s%s%s%s\\n",\n\t\t (ftime_used ? "ftime" : ""),\n\t\t (ftime_used + times_used > 1 ? "," : ""),\n\t\t (times_used ? "times" : ""),\n\t\t (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),\n\t\t (gettimeofday_used ? "gettimeofday" : ""),\n\t\t (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),\n\t\t (getrusage_used ? "getrusage" : ""));\n\t\t}\n\tif (pr_header)\n\t\t{\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+H");\n\t\telse\n\t\t\t{\n\t\t\tfprintf(stdout,"The \'numbers\' are in 1000s of bytes per second processed.\\n");\n\t\t\tfprintf(stdout,"type ");\n\t\t\t}\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\tfprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);\n\t\tfprintf(stdout,"\\n");\n\t\t}\n\tfor (k=0; k<ALGOR_NUM; k++)\n\t\t{\n\t\tif (!doit[k]) continue;\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F:%d:%s",k,names[k]);\n\t\telse\n\t\t\tfprintf(stdout,"%-13s",names[k]);\n\t\tfor (j=0; j<SIZE_NUM; j++)\n\t\t\t{\n\t\t\tif (results[k][j] > 10000 && !mr)\n\t\t\t\tfprintf(stdout," %11.2fk",results[k][j]/1e3);\n\t\t\telse\n\t\t\t\tfprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);\n\t\t\t}\n\t\tfprintf(stdout,"\\n");\n\t\t}\n#ifndef OPENSSL_NO_RSA\n\tj=1;\n\tfor (k=0; k<RSA_NUM; k++)\n\t\t{\n\t\tif (!rsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F2:%u:%u:%f:%f\\n",\n\t\t\t\tk,rsa_bits[k],rsa_results[k][0],\n\t\t\t\trsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\trsa_bits[k],rsa_results[k][0],rsa_results[k][1],\n\t\t\t\t1.0/rsa_results[k][0],1.0/rsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_DSA\n\tj=1;\n\tfor (k=0; k<DSA_NUM; k++)\n\t\t{\n\t\tif (!dsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%18ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif(mr)\n\t\t\tfprintf(stdout,"+F3:%u:%u:%f:%f\\n",\n\t\t\t\tk,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\tdsa_bits[k],dsa_results[k][0],dsa_results[k][1],\n\t\t\t\t1.0/dsa_results[k][0],1.0/dsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tj=1;\n\tfor (k=0; k<EC_NUM; k++)\n\t\t{\n\t\tif (!ecdsa_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%30ssign verify sign/s verify/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif (mr)\n\t\t\tfprintf(stdout,"+F4:%u:%u:%f:%f\\n",\n\t\t\t\tk, test_curves_bits[k],\n\t\t\t\tecdsa_results[k][0],ecdsa_results[k][1]);\n\t\telse\n\t\t\tfprintf(stdout,\n\t\t\t\t"%4u bit ecdsa (%s) %8.4fs %8.4fs %8.1f %8.1f\\n",\n\t\t\t\ttest_curves_bits[k],\n\t\t\t\ttest_curves_names[k],\n\t\t\t\tecdsa_results[k][0],ecdsa_results[k][1],\n\t\t\t\t1.0/ecdsa_results[k][0],1.0/ecdsa_results[k][1]);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tj=1;\n\tfor (k=0; k<EC_NUM; k++)\n\t\t{\n\t\tif (!ecdh_doit[k]) continue;\n\t\tif (j && !mr)\n\t\t\t{\n\t\t\tprintf("%30sop op/s\\n"," ");\n\t\t\tj=0;\n\t\t\t}\n\t\tif (mr)\n\t\t\tfprintf(stdout,"+F5:%u:%u:%f:%f\\n",\n\t\t\t\tk, test_curves_bits[k],\n\t\t\t\tecdh_results[k][0], 1.0/ecdh_results[k][0]);\n\t\telse\n\t\t\tfprintf(stdout,"%4u bit ecdh (%s) %8.4fs %8.1f\\n",\n\t\t\t\ttest_curves_bits[k],\n\t\t\t\ttest_curves_names[k],\n\t\t\t\tecdh_results[k][0], 1.0/ecdh_results[k][0]);\n\t\t}\n#endif\n\tmret=0;\nend:\n\tERR_print_errors(bio_err);\n\tif (buf != NULL) OPENSSL_free(buf);\n\tif (buf2 != NULL) OPENSSL_free(buf2);\n#ifndef OPENSSL_NO_RSA\n\tfor (i=0; i<RSA_NUM; i++)\n\t\tif (rsa_key[i] != NULL)\n\t\t\tRSA_free(rsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_DSA\n\tfor (i=0; i<DSA_NUM; i++)\n\t\tif (dsa_key[i] != NULL)\n\t\t\tDSA_free(dsa_key[i]);\n#endif\n#ifndef OPENSSL_NO_ECDSA\n\tfor (i=0; i<EC_NUM; i++)\n\t\tif (ecdsa[i] != NULL)\n\t\t\tEC_KEY_free(ecdsa[i]);\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tfor (i=0; i<EC_NUM; i++)\n\t{\n\t\tif (ecdh_a[i] != NULL)\n\t\t\tEC_KEY_free(ecdh_a[i]);\n\t\tif (ecdh_b[i] != NULL)\n\t\t\tEC_KEY_free(ecdh_b[i]);\n\t}\n#endif\n\tapps_shutdown();\n\tOPENSSL_EXIT(mret);\n\t}']
|
903
| 0
|
https://github.com/openssl/openssl/blob/8b0d4242404f9e5da26e7594fa0864b2df4601af/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int DH_check(const DH *dh, int *ret)\n{\n int ok = 0, r;\n BN_CTX *ctx = NULL;\n BN_ULONG l;\n BIGNUM *t1 = NULL, *t2 = NULL;\n *ret = 0;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n if (t1 == NULL)\n goto err;\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (dh->q) {\n if (BN_cmp(dh->g, BN_value_one()) <= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else if (BN_cmp(dh->g, dh->p) >= 0)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n else {\n if (!BN_mod_exp(t1, dh->g, dh->q, dh->p, ctx))\n goto err;\n if (!BN_is_one(t1))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n }\n r = BN_is_prime_ex(dh->q, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_Q_NOT_PRIME;\n if (!BN_div(t1, t2, dh->p, dh->q, ctx))\n goto err;\n if (!BN_is_one(t2))\n *ret |= DH_CHECK_INVALID_Q_VALUE;\n if (dh->j && BN_cmp(dh->j, t1))\n *ret |= DH_CHECK_INVALID_J_VALUE;\n } else if (BN_is_word(dh->g, DH_GENERATOR_2)) {\n l = BN_mod_word(dh->p, 24);\n if (l == (BN_ULONG)-1)\n goto err;\n if (l != 11)\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else if (BN_is_word(dh->g, DH_GENERATOR_5)) {\n l = BN_mod_word(dh->p, 10);\n if (l == (BN_ULONG)-1)\n goto err;\n if ((l != 3) && (l != 7))\n *ret |= DH_NOT_SUITABLE_GENERATOR;\n } else\n *ret |= DH_UNABLE_TO_CHECK_GENERATOR;\n r = BN_is_prime_ex(dh->p, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_PRIME;\n else if (!dh->q) {\n if (!BN_rshift1(t1, dh->p))\n goto err;\n r = BN_is_prime_ex(t1, BN_prime_checks, ctx, NULL);\n if (r < 0)\n goto err;\n if (!r)\n *ret |= DH_CHECK_P_NOT_SAFE_PRIME;\n }\n ok = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return (ok);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return (1);\n }\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (dv == NULL)\n res = BN_CTX_get(ctx);\n else\n res = dv;\n if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return (1);\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n BN_ULONG *ap, *rp, t, c;\n int i, j;\n bn_check_top(r);\n bn_check_top(a);\n if (BN_is_zero(a)) {\n BN_zero(r);\n return (1);\n }\n i = a->top;\n ap = a->d;\n j = i - (ap[i - 1] == 1);\n if (a != r) {\n if (bn_wexpand(r, j) == NULL)\n return (0);\n r->neg = a->neg;\n }\n rp = r->d;\n t = ap[--i];\n c = (t & 1) ? BN_TBIT : 0;\n if (t >>= 1)\n rp[i] = t;\n while (i > 0) {\n t = ap[--i];\n rp[i] = ((t >> 1) & BN_MASK2) | c;\n c = (t & 1) ? BN_TBIT : 0;\n }\n r->top = j;\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return (1);\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
904
| 0
|
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['static int dsa_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)\n{\n const unsigned char *p, *pm;\n int pklen, pmlen;\n int ptype;\n const void *pval;\n const ASN1_STRING *pstr;\n const X509_ALGOR *palg;\n ASN1_INTEGER *privkey = NULL;\n BN_CTX *ctx = NULL;\n DSA *dsa = NULL;\n int ret = 0;\n if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))\n return 0;\n X509_ALGOR_get0(NULL, &ptype, &pval, palg);\n if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL)\n goto decerr;\n if (privkey->type == V_ASN1_NEG_INTEGER || ptype != V_ASN1_SEQUENCE)\n goto decerr;\n pstr = pval;\n pm = pstr->data;\n pmlen = pstr->length;\n if ((dsa = d2i_DSAparams(NULL, &pm, pmlen)) == NULL)\n goto decerr;\n if ((dsa->priv_key = BN_secure_new()) == NULL\n || !ASN1_INTEGER_to_BN(privkey, dsa->priv_key)) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);\n goto dsaerr;\n }\n if ((dsa->pub_key = BN_new()) == NULL) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);\n goto dsaerr;\n }\n if ((ctx = BN_CTX_new()) == NULL) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);\n goto dsaerr;\n }\n BN_set_flags(dsa->priv_key, BN_FLG_CONSTTIME);\n if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {\n DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_BN_ERROR);\n goto dsaerr;\n }\n EVP_PKEY_assign_DSA(pkey, dsa);\n ret = 1;\n goto done;\n decerr:\n DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR);\n dsaerr:\n DSA_free(dsa);\n done:\n BN_CTX_free(ctx);\n ASN1_STRING_clear_free(privkey);\n return ret;\n}', 'BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)\n{\n return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);\n}', 'static BIGNUM *asn1_string_to_bn(const ASN1_INTEGER *ai, BIGNUM *bn,\n int itype)\n{\n BIGNUM *ret;\n if ((ai->type & ~V_ASN1_NEG) != itype) {\n ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_WRONG_INTEGER_TYPE);\n return NULL;\n }\n ret = BN_bin2bn(ai->data, ai->length, bn);\n if (ret == NULL) {\n ASN1err(ASN1_F_ASN1_STRING_TO_BN, ASN1_R_BN_LIB);\n return NULL;\n }\n if (ai->type & V_ASN1_NEG)\n BN_set_negative(ret, 1);\n return ret;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (val[0] == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(val[0], a, m, ctx))\n goto err;\n aa = val[0];\n } else\n aa = a;\n if (BN_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!bn_to_mont_fixed_top(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !bn_mul_mont_fixed_top(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n r->flags |= BN_FLG_FIXED_TOP;\n } else\n#endif\n if (!bn_to_mont_fixed_top(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!bn_mul_mont_fixed_top(r, r, r, mont, ctx))\n goto err;\n }\n if (!bn_mul_mont_fixed_top(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue, wmask, window0;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_abs_is_word(m, 1)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!bn_to_mont_fixed_top(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!bn_to_mont_fixed_top(&am, &am, mont, ctx))\n goto err;\n } else if (!bn_to_mont_fixed_top(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits > 0) {\n if (bits < stride)\n stride = bits;\n bits -= stride;\n wvalue = bn_get_bits(p, bits);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n window0 = (bits - 1) % 5 + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7) {\n while (bits > 0) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n } else {\n while (bits > 0) {\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top,\n bn_get_bits5(p->d, bits -= 5));\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!bn_mul_mont_fixed_top(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n window0 = (bits - 1) % window + 1;\n wmask = (1 << window0) - 1;\n bits -= window0;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n wmask = (1 << window) - 1;\n while (bits > 0) {\n for (i = 0; i < window; i++)\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n bits -= window;\n wvalue = bn_get_bits(p, bits) & wmask;\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!bn_mul_mont_fixed_top(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.flags = BN_FLG_STATIC_DATA;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
905
| 0
|
https://github.com/openssl/openssl/blob/a8140a42f5ee9e4e1423b5b6b319dc4657659f6f/crypto/bn/bn_conv.c/#L171
|
int BN_hex2bn(BIGNUM **bn, const char *a)
{
BIGNUM *ret = NULL;
BN_ULONG l = 0;
int neg = 0, h, m, i, j, k, c;
int num;
if (a == NULL || *a == '\0')
return 0;
if (*a == '-') {
neg = 1;
a++;
}
for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)
continue;
if (i == 0 || i > INT_MAX / 4)
goto err;
num = i + neg;
if (bn == NULL)
return num;
if (*bn == NULL) {
if ((ret = BN_new()) == NULL)
return 0;
} else {
ret = *bn;
BN_zero(ret);
}
if (bn_expand(ret, i * 4) == NULL)
goto err;
j = i;
m = 0;
h = 0;
while (j > 0) {
m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;
l = 0;
for (;;) {
c = a[j - m];
k = OPENSSL_hexchar2int(c);
if (k < 0)
k = 0;
l = (l << 4) | k;
if (--m <= 0) {
ret->d[h++] = l;
break;
}
}
j -= BN_BYTES * 2;
}
ret->top = h;
bn_correct_top(ret);
*bn = ret;
bn_check_top(ret);
if (ret->top != 0)
ret->neg = neg;
return num;
err:
if (*bn == NULL)
BN_free(ret);
return 0;
}
|
['static int test_long_bignum(void)\n{\n int r;\n BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL;\n const char as[] = "1234567890123456789012345678901234567890123456789012"\n "1234567890123456789012345678901234567890123456789012"\n "1234567890123456789012345678901234567890123456789012"\n "1234567890123456789012345678901234567890123456789012"\n "1234567890123456789012345678901234567890123456789012"\n "1234567890123456789012345678901234567890123456789012"\n "FFFFFF";\n const char bs[] = "1234567890123456789012345678901234567890123456789012"\n "1234567890123456789012345678901234567890123456789013"\n "987657";\n const char cs[] = "-"\n "123456789012345678901234567890"\n "123456789012345678901234567890"\n "ABCD";\n const char ds[] = "-"\n "23456789A123456789B123456789C"\n "123456789D123456789E123456789F"\n "ABCD";\n r = TEST_true(BN_hex2bn(&a, as))\n && TEST_true(BN_hex2bn(&b, bs))\n && TEST_true(BN_hex2bn(&c, cs))\n && TEST_true(BN_hex2bn(&d, ds))\n && (TEST(0, TEST_BN_eq(a, b))\n & TEST(0, TEST_BN_eq(b, a))\n & TEST(0, TEST_BN_eq(b, NULL))\n & TEST(0, TEST_BN_eq(NULL, a))\n & TEST(1, TEST_BN_ne(a, NULL))\n & TEST(0, TEST_BN_eq(c, d)));\n BN_free(a);\n BN_free(b);\n BN_free(c);\n BN_free(d);\n return r;\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n BIGNUM *ret = NULL;\n BN_ULONG l = 0;\n int neg = 0, h, m, i, j, k, c;\n int num;\n if (a == NULL || *a == '\\0')\n return 0;\n if (*a == '-') {\n neg = 1;\n a++;\n }\n for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)\n continue;\n if (i == 0 || i > INT_MAX / 4)\n goto err;\n num = i + neg;\n if (bn == NULL)\n return num;\n if (*bn == NULL) {\n if ((ret = BN_new()) == NULL)\n return 0;\n } else {\n ret = *bn;\n BN_zero(ret);\n }\n if (bn_expand(ret, i * 4) == NULL)\n goto err;\n j = i;\n m = 0;\n h = 0;\n while (j > 0) {\n m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;\n l = 0;\n for (;;) {\n c = a[j - m];\n k = OPENSSL_hexchar2int(c);\n if (k < 0)\n k = 0;\n l = (l << 4) | k;\n if (--m <= 0) {\n ret->d[h++] = l;\n break;\n }\n }\n j -= BN_BYTES * 2;\n }\n ret->top = h;\n bn_correct_top(ret);\n *bn = ret;\n bn_check_top(ret);\n if (ret->top != 0)\n ret->neg = neg;\n return num;\n err:\n if (*bn == NULL)\n BN_free(ret);\n return 0;\n}"]
|
906
| 0
|
https://github.com/openssl/openssl/blob/2ce90b9b7481381dff584726d84345a0260ca4d1/crypto/bn/bn_mul.c/#L1028
|
int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
int ret=0;
int top,al,bl;
BIGNUM *rr;
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
int i;
#endif
#ifdef BN_RECURSION
BIGNUM *t=NULL;
int j=0,k;
#endif
#ifdef BN_COUNT
fprintf(stderr,"BN_mul %d * %d\n",a->top,b->top);
#endif
bn_check_top(a);
bn_check_top(b);
bn_check_top(r);
al=a->top;
bl=b->top;
if ((al == 0) || (bl == 0))
{
if (!BN_zero(r)) goto err;
return(1);
}
top=al+bl;
BN_CTX_start(ctx);
if ((r == a) || (r == b))
{
if ((rr = BN_CTX_get(ctx)) == NULL) goto err;
}
else
rr = r;
rr->neg=a->neg^b->neg;
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
i = al-bl;
#endif
#ifdef BN_MUL_COMBA
if (i == 0)
{
# if 0
if (al == 4)
{
if (bn_wexpand(rr,8) == NULL) goto err;
rr->top=8;
bn_mul_comba4(rr->d,a->d,b->d);
goto end;
}
# endif
if (al == 8)
{
if (bn_wexpand(rr,16) == NULL) goto err;
rr->top=16;
bn_mul_comba8(rr->d,a->d,b->d);
goto end;
}
}
#endif
#ifdef BN_RECURSION
if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))
{
if (i >= -1 && i <= 1)
{
int sav_j =0;
if (i >= 0)
{
j = BN_num_bits_word((BN_ULONG)al);
}
if (i == -1)
{
j = BN_num_bits_word((BN_ULONG)bl);
}
sav_j = j;
j = 1<<(j-1);
assert(j <= al || j <= bl);
k = j+j;
t = BN_CTX_get(ctx);
if (al > j || bl > j)
{
bn_wexpand(t,k*4);
bn_wexpand(rr,k*4);
bn_mul_part_recursive(rr->d,a->d,b->d,
j,al-j,bl-j,t->d);
}
else
{
bn_wexpand(t,k*2);
bn_wexpand(rr,k*2);
bn_mul_recursive(rr->d,a->d,b->d,
j,al-j,bl-j,t->d);
}
rr->top=top;
goto end;
}
#if 0
if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BIGNUM *tmp_bn = (BIGNUM *)b;
if (bn_wexpand(tmp_bn,al) == NULL) goto err;
tmp_bn->d[bl]=0;
bl++;
i--;
}
else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))
{
BIGNUM *tmp_bn = (BIGNUM *)a;
if (bn_wexpand(tmp_bn,bl) == NULL) goto err;
tmp_bn->d[al]=0;
al++;
i++;
}
if (i == 0)
{
j=BN_num_bits_word((BN_ULONG)al);
j=1<<(j-1);
k=j+j;
t = BN_CTX_get(ctx);
if (al == j)
{
if (bn_wexpand(t,k*2) == NULL) goto err;
if (bn_wexpand(rr,k*2) == NULL) goto err;
bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
}
else
{
if (bn_wexpand(t,k*4) == NULL) goto err;
if (bn_wexpand(rr,k*4) == NULL) goto err;
bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
}
rr->top=top;
goto end;
}
#endif
}
#endif
if (bn_wexpand(rr,top) == NULL) goto err;
rr->top=top;
bn_mul_normal(rr->d,a->d,al,b->d,bl);
#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
end:
#endif
bn_fix_top(rr);
if (r != rr) BN_copy(r,rr);
ret=1;
err:
BN_CTX_end(ctx);
return(ret);
}
|
['int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tint top,al,bl;\n\tBIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t=NULL;\n\tint j=0,k;\n#endif\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tif (!BN_zero(r)) goto err;\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i >= -1 && i <= 1)\n\t\t\t{\n\t\t\tint sav_j =0;\n\t\t\tif (i >= 0)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)al);\n\t\t\t\t}\n\t\t\tif (i == -1)\n\t\t\t\t{\n\t\t\t\tj = BN_num_bits_word((BN_ULONG)bl);\n\t\t\t\t}\n\t\t\tsav_j = j;\n\t\t\tj = 1<<(j-1);\n\t\t\tassert(j <= al || j <= bl);\n\t\t\tk = j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al > j || bl > j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,\n\t\t\t\t\tj,al-j,bl-j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#if 0\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tif (bn_wexpand(tmp_bn,al) == NULL) goto err;\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tif (bn_wexpand(tmp_bn,bl) == NULL) goto err;\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*2) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*2) == NULL) goto err;\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (bn_wexpand(t,k*4) == NULL) goto err;\n\t\t\t\tif (bn_wexpand(rr,k*4) == NULL) goto err;\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n#endif\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_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}']
|
907
| 0
|
https://gitlab.com/libtiff/libtiff/blob/3adc33842b7533066daea2516741832edc44d5fd/libtiff/tif_read.c/#L945
|
static int
TIFFStartTile(TIFF* tif, uint32 tile)
{
TIFFDirectory *td = &tif->tif_dir;
if ((tif->tif_flags & TIFF_CODERSETUP) == 0) {
if (!(*tif->tif_setupdecode)(tif))
return (0);
tif->tif_flags |= TIFF_CODERSETUP;
}
tif->tif_curtile = tile;
tif->tif_row =
(tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *
td->td_tilelength;
tif->tif_col =
(tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *
td->td_tilewidth;
tif->tif_flags &= ~TIFF_BUF4WRITE;
if (tif->tif_flags&TIFF_NOREADRAW)
{
tif->tif_rawcp = NULL;
tif->tif_rawcc = 0;
}
else
{
tif->tif_rawcp = tif->tif_rawdata;
tif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];
}
return ((*tif->tif_predecode)(tif,
(uint16)(tile/td->td_stripsperimage)));
}
|
['tsize_t t2p_readwrite_pdf_image_tile(T2P* t2p, TIFF* input, TIFF* output, ttile_t tile){\n\tuint16 edge=0;\n\ttsize_t written=0;\n\tunsigned char* buffer=NULL;\n\ttsize_t bufferoffset=0;\n\tunsigned char* samplebuffer=NULL;\n\ttsize_t samplebufferoffset=0;\n\ttsize_t read=0;\n\tuint16 i=0;\n\tttile_t tilecount=0;\n\ttsize_t tilesize=0;\n\tttile_t septilecount=0;\n\ttsize_t septilesize=0;\n#ifdef JPEG_SUPPORT\n\tunsigned char* jpt;\n\tfloat* xfloatp;\n\tuint32 xuint32=0;\n#endif\n\tedge |= t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tedge |= t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile);\n\tif( (t2p->pdf_transcode == T2P_TRANSCODE_RAW) && ((edge == 0)\n#if defined(JPEG_SUPPORT) || defined(OJPEG_SUPPORT)\n\t\t|| (t2p->pdf_compression == T2P_COMPRESS_JPEG)\n#endif\n\t)\n\t){\n#ifdef CCITT_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_G4){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef ZIP_SUPPORT\n\t\tif(t2p->pdf_compression == T2P_COMPRESS_ZIP){\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tTIFFReadRawTile(input, tile, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\tif (t2p->tiff_fillorder==FILLORDER_LSB2MSB){\n\t\t\t\t\tTIFFReverseBits(buffer, t2p->tiff_datasize);\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, t2p->tiff_datasize);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(t2p->tiff_datasize);\n\t\t}\n#endif\n#ifdef OJPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_OJPEG){\n\t\t\tif(! t2p->pdf_ojpegdata){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"No support for OJPEG image %s with "\n "bad tables",\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tbuffer=(unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\t_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);\n\t\t\tif(edge!=0){\n\t\t\t\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[7]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength >> 8) & 0xff;\n\t\t\t\t\tbuffer[8]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength ) & 0xff;\n\t\t\t\t}\n\t\t\t\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile)){\n\t\t\t\t\tbuffer[9]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth >> 8) & 0xff;\n\t\t\t\t\tbuffer[10]=\n\t\t\t\t\t\t(t2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth ) & 0xff;\n\t\t\t\t}\n\t\t\t}\n\t\t\tbufferoffset=t2p->pdf_ojpegdatalength;\n\t\t\tbufferoffset+=TIFFReadRawTile(input,\n\t\t\t\t\ttile,\n\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t-1);\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xff;\n\t\t\t((unsigned char*)buffer)[bufferoffset++]=0xd9;\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n#ifdef JPEG_SUPPORT\n\t\tif(t2p->tiff_compression == COMPRESSION_JPEG){\n\t\t\tunsigned char table_end[2];\n\t\t\tuint32 count = 0;\n\t\t\tbuffer= (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\tt2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_JPEGTABLES, &count, &jpt) != 0) {\n\t\t\t\tif (count > 0) {\n\t\t\t\t\t_TIFFmemcpy(buffer, jpt, count);\n\t\t\t\t\tbufferoffset += count - 2;\n\t\t\t\t\ttable_end[0] = buffer[bufferoffset-2];\n\t\t\t\t\ttable_end[1] = buffer[bufferoffset-1];\n\t\t\t\t}\n\t\t\t\tif (count > 0) {\n\t\t\t\t\txuint32 = bufferoffset;\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset-2]),\n\t\t\t\t\t\t-1);\n\t\t\t\t\t\tbuffer[xuint32-2]=table_end[0];\n\t\t\t\t\t\tbuffer[xuint32-1]=table_end[1];\n\t\t\t\t} else {\n\t\t\t\t\tbufferoffset += TIFFReadRawTile(\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\ttile,\n\t\t\t\t\t\t(tdata_t) &(((unsigned char*)buffer)[bufferoffset]),\n\t\t\t\t\t\t-1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tt2pWriteFile(output, (tdata_t) buffer, bufferoffset);\n\t\t\t_TIFFfree(buffer);\n\t\t\treturn(bufferoffset);\n\t\t}\n#endif\n\t\t(void)0;\n\t}\n\tif(t2p->pdf_sample==T2P_SAMPLE_NOTHING){\n\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\tif(buffer==NULL){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Can\'t allocate %lu bytes of memory for "\n "t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\tTIFFFileName(input));\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tread = TIFFReadEncodedTile(\n\t\t\tinput,\n\t\t\ttile,\n\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\tt2p->tiff_datasize);\n\t\tif(read==-1){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\ttile,\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t} else {\n\t\tif(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){\n\t\t\tseptilesize=TIFFTileSize(input);\n\t\t\tseptilecount=TIFFNumberOfTiles(input);\n\t\t\ttilesize=septilesize*t2p->tiff_samplesperpixel;\n\t\t\ttilecount=septilecount/t2p->tiff_samplesperpixel;\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(samplebuffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tsamplebufferoffset=0;\n\t\t\tfor(i=0;i<t2p->tiff_samplesperpixel;i++){\n\t\t\t\tread =\n\t\t\t\t\tTIFFReadEncodedTile(input,\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\t(tdata_t) &(samplebuffer[samplebufferoffset]),\n\t\t\t\t\t\tseptilesize);\n\t\t\t\tif(read==-1){\n\t\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\t\ttile + i*tilecount,\n\t\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t\t\t_TIFFfree(samplebuffer);\n\t\t\t\t\t\t_TIFFfree(buffer);\n\t\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\t\treturn(0);\n\t\t\t\t}\n\t\t\t\tsamplebufferoffset+=read;\n\t\t\t}\n\t\t\tt2p_sample_planar_separate_to_contig(\n\t\t\t\tt2p,\n\t\t\t\t&(buffer[bufferoffset]),\n\t\t\t\tsamplebuffer,\n\t\t\t\tsamplebufferoffset);\n\t\t\tbufferoffset+=samplebufferoffset;\n\t\t\t_TIFFfree(samplebuffer);\n\t\t}\n\t\tif(buffer==NULL){\n\t\t\tbuffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);\n\t\t\tif(buffer==NULL){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Can\'t allocate %lu bytes of memory "\n "for t2p_readwrite_pdf_image_tile, %s",\n\t\t\t\t\t(unsigned long) t2p->tiff_datasize,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tread = TIFFReadEncodedTile(\n\t\t\t\tinput,\n\t\t\t\ttile,\n\t\t\t\t(tdata_t) &buffer[bufferoffset],\n\t\t\t\tt2p->tiff_datasize);\n\t\t\tif(read==-1){\n\t\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t\t"Error on decoding tile %u of %s",\n\t\t\t\t\ttile,\n\t\t\t\t\tTIFFFileName(input));\n\t\t\t\t_TIFFfree(buffer);\n\t\t\t\tt2p->t2p_error=T2P_ERR_ERROR;\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgba_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_RGBAA_TO_RGB){\n\t\t\tt2p->tiff_datasize=t2p_sample_rgbaa_to_rgb(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){\n\t\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t\t"No support for YCbCr to RGB in tile for %s",\n\t\t\t\tTIFFFileName(input));\n\t\t\t_TIFFfree(buffer);\n\t\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\t\treturn(0);\n\t\t}\n\t\tif(t2p->pdf_sample & T2P_SAMPLE_LAB_SIGNED_TO_UNSIGNED){\n\t\t\tt2p->tiff_datasize=t2p_sample_lab_signed_to_unsigned(\n\t\t\t\t(tdata_t)buffer,\n\t\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth\n\t\t\t\t*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\t}\n\t}\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) != 0){\n\t\tt2p_tile_collapse_left(\n\t\t\tbuffer,\n\t\t\tTIFFTileRowSize(input),\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t}\n\tt2p_disable(output);\n\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, t2p->tiff_photometric);\n\tTIFFSetField(output, TIFFTAG_BITSPERSAMPLE, t2p->tiff_bitspersample);\n\tTIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, t2p->tiff_samplesperpixel);\n\tif(t2p_tile_is_right_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGEWIDTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilewidth);\n\t}\n\tif(t2p_tile_is_bottom_edge(t2p->tiff_tiles[t2p->pdf_page], tile) == 0){\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);\n\t} else {\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_IMAGELENGTH,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t\tTIFFSetField(\n\t\t\toutput,\n\t\t\tTIFFTAG_ROWSPERSTRIP,\n\t\t\tt2p->tiff_tiles[t2p->pdf_page].tiles_edgetilelength);\n\t}\n\tTIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);\n\tTIFFSetField(output, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);\n\tswitch(t2p->pdf_compression){\n\tcase T2P_COMPRESS_NONE:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);\n\t\tbreak;\n#ifdef CCITT_SUPPORT\n\tcase T2P_COMPRESS_G4:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);\n\t\tbreak;\n#endif\n#ifdef JPEG_SUPPORT\n\tcase T2P_COMPRESS_JPEG:\n\t\tif (t2p->tiff_photometric==PHOTOMETRIC_YCBCR) {\n\t\t\tuint16 hor = 0, ver = 0;\n\t\t\tif (TIFFGetField(input, TIFFTAG_YCBCRSUBSAMPLING, &hor, &ver)!=0) {\n\t\t\t\tif (hor != 0 && ver != 0) {\n\t\t\t\t\tTIFFSetField(output, TIFFTAG_YCBCRSUBSAMPLING, hor, ver);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif(TIFFGetField(input, TIFFTAG_REFERENCEBLACKWHITE, &xfloatp)!=0){\n\t\t\t\tTIFFSetField(output, TIFFTAG_REFERENCEBLACKWHITE, xfloatp);\n\t\t\t}\n\t\t}\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);\n\t\tTIFFSetField(output, TIFFTAG_JPEGTABLESMODE, 0);\n\t\tif(t2p->pdf_colorspace & (T2P_CS_RGB | T2P_CS_LAB)){\n\t\t\tTIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_YCBCR);\n\t\t\tif(t2p->tiff_photometric != PHOTOMETRIC_YCBCR){\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);\n\t\t\t} else {\n\t\t\t\tTIFFSetField(output, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RAW);\n\t\t\t}\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_GRAY){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_colorspace & T2P_CS_CMYK){\n\t\t\t(void)0;\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_JPEGQUALITY,\n\t\t\t\tt2p->pdf_defaultcompressionquality);\n\t\t}\n\t\tbreak;\n#endif\n#ifdef ZIP_SUPPORT\n\tcase T2P_COMPRESS_ZIP:\n\t\tTIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);\n\t\tif(t2p->pdf_defaultcompressionquality%100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_PREDICTOR,\n\t\t\t\tt2p->pdf_defaultcompressionquality % 100);\n\t\t}\n\t\tif(t2p->pdf_defaultcompressionquality/100 != 0){\n\t\t\tTIFFSetField(output,\n\t\t\t\tTIFFTAG_ZIPQUALITY,\n\t\t\t\t(t2p->pdf_defaultcompressionquality / 100));\n\t\t}\n\t\tbreak;\n#endif\n\tdefault:\n\t\tbreak;\n\t}\n\tt2p_enable(output);\n\tt2p->outputwritten = 0;\n\tbufferoffset = TIFFWriteEncodedStrip(output, (tstrip_t) 0, buffer,\n\t\t\t\t\t TIFFStripSize(output));\n\tif (buffer != NULL) {\n\t\t_TIFFfree(buffer);\n\t\tbuffer = NULL;\n\t}\n\tif (bufferoffset == -1) {\n\t\tTIFFError(TIFF2PDF_MODULE,\n\t\t\t "Error writing encoded tile to output PDF %s",\n\t\t\t TIFFFileName(output));\n\t\tt2p->t2p_error = T2P_ERR_ERROR;\n\t\treturn(0);\n\t}\n\twritten = t2p->outputwritten;\n\treturn(written);\n}', 'tmsize_t\nTIFFReadEncodedTile(TIFF* tif, uint32 tile, void* buf, tmsize_t size)\n{\n\tstatic const char module[] = "TIFFReadEncodedTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\ttmsize_t tilesize = tif->tif_tilesize;\n\tif (!TIFFCheckRead(tif, 1))\n\t\treturn ((tmsize_t)(-1));\n\tif (tile >= td->td_nstrips) {\n\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t "%lu: Tile out of range, max %lu",\n\t\t (unsigned long) tile, (unsigned long) td->td_nstrips);\n\t\treturn ((tmsize_t)(-1));\n\t}\n\tif (size == (tmsize_t)(-1))\n\t\tsize = tilesize;\n\telse if (size > tilesize)\n\t\tsize = tilesize;\n\tif (TIFFFillTile(tif, tile) && (*tif->tif_decodetile)(tif,\n\t (uint8*) buf, size, (uint16)(tile/td->td_stripsperimage))) {\n\t\t(*tif->tif_postdecode)(tif, (uint8*) buf, size);\n\t\treturn (size);\n\t} else\n\t\treturn ((tmsize_t)(-1));\n}', 'int\nTIFFFillTile(TIFF* tif, uint32 tile)\n{\n\tstatic const char module[] = "TIFFFillTile";\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags&TIFF_NOREADRAW)==0)\n\t{\n\t\tuint64 bytecount = td->td_stripbytecount[tile];\n\t\tif (bytecount <= 0) {\n#if defined(__WIN32__) && defined(_MSC_VER)\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%I64u: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned __int64) bytecount,\n\t\t\t\t (unsigned long) tile);\n#else\n\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t"%llu: Invalid tile byte count, tile %lu",\n\t\t\t\t (unsigned long long) bytecount,\n\t\t\t\t (unsigned long) tile);\n#endif\n\t\t\treturn (0);\n\t\t}\n\t\tif (isMapped(tif) &&\n\t\t (isFillOrder(tif, td->td_fillorder)\n\t\t || (tif->tif_flags & TIFF_NOBITREV))) {\n\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) && tif->tif_rawdata)\n\t\t\t\t_TIFFfree(tif->tif_rawdata);\n\t\t\ttif->tif_flags &= ~TIFF_MYBUFFER;\n\t\t\tif (bytecount > (uint64)tif->tif_size ||\n\t\t\t td->td_stripoffset[tile] > (uint64)tif->tif_size - bytecount) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\treturn (0);\n\t\t\t}\n\t\t\ttif->tif_rawdatasize = (tmsize_t)bytecount;\n\t\t\ttif->tif_rawdata =\n\t\t\t\ttif->tif_base + (tmsize_t)td->td_stripoffset[tile];\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = (tmsize_t) bytecount;\n\t\t} else {\n\t\t\ttmsize_t bytecountm;\n\t\t\tbytecountm=(tmsize_t)bytecount;\n\t\t\tif ((uint64)bytecountm!=bytecount)\n\t\t\t{\n\t\t\t\tTIFFErrorExt(tif->tif_clientdata,module,"Integer overflow");\n\t\t\t\treturn(0);\n\t\t\t}\n\t\t\tif (bytecountm > tif->tif_rawdatasize) {\n\t\t\t\ttif->tif_curtile = NOTILE;\n\t\t\t\tif ((tif->tif_flags & TIFF_MYBUFFER) == 0) {\n\t\t\t\t\tTIFFErrorExt(tif->tif_clientdata, module,\n\t\t\t\t\t "Data buffer too small to hold tile %lu",\n\t\t\t\t\t (unsigned long) tile);\n\t\t\t\t\treturn (0);\n\t\t\t\t}\n\t\t\t\tif (!TIFFReadBufferSetup(tif, 0, bytecountm))\n\t\t\t\t\treturn (0);\n\t\t\t}\n\t\t\tif (TIFFReadRawTile1(tif, tile, tif->tif_rawdata,\n\t\t\t bytecountm, module) != bytecountm)\n\t\t\t\treturn (0);\n tif->tif_rawdataoff = 0;\n tif->tif_rawdataloaded = bytecountm;\n\t\t\tif (!isFillOrder(tif, td->td_fillorder) &&\n\t\t\t (tif->tif_flags & TIFF_NOBITREV) == 0)\n\t\t\t\tTIFFReverseBits(tif->tif_rawdata,\n tif->tif_rawdataloaded);\n\t\t}\n\t}\n\treturn (TIFFStartTile(tif, tile));\n}', 'static int\nTIFFStartTile(TIFF* tif, uint32 tile)\n{\n\tTIFFDirectory *td = &tif->tif_dir;\n\tif ((tif->tif_flags & TIFF_CODERSETUP) == 0) {\n\t\tif (!(*tif->tif_setupdecode)(tif))\n\t\t\treturn (0);\n\t\ttif->tif_flags |= TIFF_CODERSETUP;\n\t}\n\ttif->tif_curtile = tile;\n\ttif->tif_row =\n\t (tile % TIFFhowmany_32(td->td_imagewidth, td->td_tilewidth)) *\n\t\ttd->td_tilelength;\n\ttif->tif_col =\n\t (tile % TIFFhowmany_32(td->td_imagelength, td->td_tilelength)) *\n\t\ttd->td_tilewidth;\n tif->tif_flags &= ~TIFF_BUF4WRITE;\n\tif (tif->tif_flags&TIFF_NOREADRAW)\n\t{\n\t\ttif->tif_rawcp = NULL;\n\t\ttif->tif_rawcc = 0;\n\t}\n\telse\n\t{\n\t\ttif->tif_rawcp = tif->tif_rawdata;\n\t\ttif->tif_rawcc = (tmsize_t)td->td_stripbytecount[tile];\n\t}\n\treturn ((*tif->tif_predecode)(tif,\n\t\t\t(uint16)(tile/td->td_stripsperimage)));\n}']
|
908
| 0
|
https://github.com/libav/libav/blob/41874d0a5df35732367f0c675eac914c23d65aee/libavformat/matroskadec.c/#L802
|
static int ebml_parse_elem(MatroskaDemuxContext *matroska,
EbmlSyntax *syntax, void *data)
{
ByteIOContext *pb = matroska->ctx->pb;
uint32_t id = syntax->id;
uint64_t length;
int res;
data = (char *)data + syntax->data_offset;
if (syntax->list_elem_size) {
EbmlList *list = data;
list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);
data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;
memset(data, 0, syntax->list_elem_size);
list->nb_elem++;
}
if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) {
matroska->current_id = 0;
if ((res = ebml_read_num(matroska, pb, 8, &length)) < 0)
return res;
}
switch (syntax->type) {
case EBML_UINT: res = ebml_read_uint (pb, length, data); break;
case EBML_FLOAT: res = ebml_read_float (pb, length, data); break;
case EBML_STR:
case EBML_UTF8: res = ebml_read_ascii (pb, length, data); break;
case EBML_BIN: res = ebml_read_binary(pb, length, data); break;
case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0)
return res;
if (id == MATROSKA_ID_SEGMENT)
matroska->segment_start = url_ftell(matroska->ctx->pb);
return ebml_parse_nest(matroska, syntax->def.n, data);
case EBML_PASS: return ebml_parse_id(matroska, syntax->def.n, id, data);
case EBML_STOP: return 1;
default: return url_fseek(pb,length,SEEK_CUR)<0 ? AVERROR(EIO) : 0;
}
if (res == AVERROR_INVALIDDATA)
av_log(matroska->ctx, AV_LOG_ERROR, "Invalid element\n");
else if (res == AVERROR(EIO))
av_log(matroska->ctx, AV_LOG_ERROR, "Read error\n");
return res;
}
|
['static int ebml_parse_elem(MatroskaDemuxContext *matroska,\n EbmlSyntax *syntax, void *data)\n{\n ByteIOContext *pb = matroska->ctx->pb;\n uint32_t id = syntax->id;\n uint64_t length;\n int res;\n data = (char *)data + syntax->data_offset;\n if (syntax->list_elem_size) {\n EbmlList *list = data;\n list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size);\n data = (char*)list->elem + list->nb_elem*syntax->list_elem_size;\n memset(data, 0, syntax->list_elem_size);\n list->nb_elem++;\n }\n if (syntax->type != EBML_PASS && syntax->type != EBML_STOP) {\n matroska->current_id = 0;\n if ((res = ebml_read_num(matroska, pb, 8, &length)) < 0)\n return res;\n }\n switch (syntax->type) {\n case EBML_UINT: res = ebml_read_uint (pb, length, data); break;\n case EBML_FLOAT: res = ebml_read_float (pb, length, data); break;\n case EBML_STR:\n case EBML_UTF8: res = ebml_read_ascii (pb, length, data); break;\n case EBML_BIN: res = ebml_read_binary(pb, length, data); break;\n case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0)\n return res;\n if (id == MATROSKA_ID_SEGMENT)\n matroska->segment_start = url_ftell(matroska->ctx->pb);\n return ebml_parse_nest(matroska, syntax->def.n, data);\n case EBML_PASS: return ebml_parse_id(matroska, syntax->def.n, id, data);\n case EBML_STOP: return 1;\n default: return url_fseek(pb,length,SEEK_CUR)<0 ? AVERROR(EIO) : 0;\n }\n if (res == AVERROR_INVALIDDATA)\n av_log(matroska->ctx, AV_LOG_ERROR, "Invalid element\\n");\n else if (res == AVERROR(EIO))\n av_log(matroska->ctx, AV_LOG_ERROR, "Read error\\n");\n return res;\n}']
|
909
| 0
|
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/ocsp/ocsp_ht.c/#L129
|
OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
int maxline)
{
static const char post_hdr[] = "POST %s HTTP/1.0\r\n"
"Content-Type: application/ocsp-request\r\n"
"Content-Length: %d\r\n\r\n";
OCSP_REQ_CTX *rctx;
rctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX));
rctx->state = OHS_FIRSTLINE;
rctx->mem = BIO_new(BIO_s_mem());
rctx->io = io;
if (maxline > 0)
rctx->iobuflen = maxline;
else
rctx->iobuflen = OCSP_MAX_LINE_LEN;
rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);
if (!path)
path = "/";
if (BIO_printf(rctx->mem, post_hdr, path,
i2d_OCSP_REQUEST(req, NULL)) <= 0)
{
rctx->state = OHS_ERROR;
return 0;
}
if (i2d_OCSP_REQUEST_bio(rctx->mem, req) <= 0)
{
rctx->state = OHS_ERROR;
return 0;
}
rctx->state = OHS_ASN1_WRITE;
rctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL);
return rctx;
}
|
['OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,\n\t\t\t\t\t\t\t\tint maxline)\n\t{\n\tstatic const char post_hdr[] = "POST %s HTTP/1.0\\r\\n"\n\t"Content-Type: application/ocsp-request\\r\\n"\n\t"Content-Length: %d\\r\\n\\r\\n";\n\tOCSP_REQ_CTX *rctx;\n\trctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX));\n\trctx->state = OHS_FIRSTLINE;\n\trctx->mem = BIO_new(BIO_s_mem());\n\trctx->io = io;\n\tif (maxline > 0)\n\t\trctx->iobuflen = maxline;\n\telse\n\t\trctx->iobuflen = OCSP_MAX_LINE_LEN;\n\trctx->iobuf = OPENSSL_malloc(rctx->iobuflen);\n\tif (!path)\n\t\tpath = "/";\n if (BIO_printf(rctx->mem, post_hdr, path,\n\t\t\t\ti2d_OCSP_REQUEST(req, NULL)) <= 0)\n\t\t{\n\t\trctx->state = OHS_ERROR;\n\t\treturn 0;\n\t\t}\n if (i2d_OCSP_REQUEST_bio(rctx->mem, req) <= 0)\n\t\t{\n\t\trctx->state = OHS_ERROR;\n\t\treturn 0;\n\t\t}\n\trctx->state = OHS_ASN1_WRITE;\n\trctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL);\n\treturn rctx;\n\t}', 'void *CRYPTO_malloc(size_t 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}']
|
910
| 0
|
https://github.com/openssl/openssl/blob/2d5d70b15559f9813054ddb11b30b816daf62ebe/apps/ts.c/#L612
|
static ASN1_INTEGER *create_nonce(int bits)
{
unsigned char buf[20];
ASN1_INTEGER *nonce = NULL;
int len = (bits - 1) / 8 + 1;
int i;
if (len > (int)sizeof(buf))
goto err;
if (RAND_bytes(buf, len) <= 0)
goto err;
for (i = 0; i < len && !buf[i]; ++i)
continue;
if ((nonce = ASN1_INTEGER_new()) == NULL)
goto err;
OPENSSL_free(nonce->data);
nonce->length = len - i;
nonce->data = app_malloc(nonce->length + 1, "nonce buffer");
memcpy(nonce->data, buf + i, nonce->length);
return nonce;
err:
BIO_printf(bio_err, "could not create nonce\n");
ASN1_INTEGER_free(nonce);
return NULL;
}
|
['static ASN1_INTEGER *create_nonce(int bits)\n{\n unsigned char buf[20];\n ASN1_INTEGER *nonce = NULL;\n int len = (bits - 1) / 8 + 1;\n int i;\n if (len > (int)sizeof(buf))\n goto err;\n if (RAND_bytes(buf, len) <= 0)\n goto err;\n for (i = 0; i < len && !buf[i]; ++i)\n continue;\n if ((nonce = ASN1_INTEGER_new()) == NULL)\n goto err;\n OPENSSL_free(nonce->data);\n nonce->length = len - i;\n nonce->data = app_malloc(nonce->length + 1, "nonce buffer");\n memcpy(nonce->data, buf + i, nonce->length);\n return nonce;\n err:\n BIO_printf(bio_err, "could not create nonce\\n");\n ASN1_INTEGER_free(nonce);\n return NULL;\n}']
|
911
| 0
|
https://github.com/libav/libav/blob/7fa70598e83cca650717d02ac96bcf55e9f97c19/libavformat/matroskadec.c/#L874
|
static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
MatroskaTrack *track)
{
MatroskaTrackEncoding *encodings = track->encodings.elem;
uint8_t* data = *buf;
int isize = *buf_size;
uint8_t* pkt_data = NULL;
int pkt_size = isize;
int result = 0;
int olen;
switch (encodings[0].compression.algo) {
case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
return encodings[0].compression.settings.size;
case MATROSKA_TRACK_ENCODING_COMP_LZO:
do {
olen = pkt_size *= 3;
pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING);
result = av_lzo1x_decode(pkt_data, &olen, data, &isize);
} while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000);
if (result)
goto failed;
pkt_size -= olen;
break;
#if CONFIG_ZLIB
case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
z_stream zstream = {0};
if (inflateInit(&zstream) != Z_OK)
return -1;
zstream.next_in = data;
zstream.avail_in = isize;
do {
pkt_size *= 3;
pkt_data = av_realloc(pkt_data, pkt_size);
zstream.avail_out = pkt_size - zstream.total_out;
zstream.next_out = pkt_data + zstream.total_out;
result = inflate(&zstream, Z_NO_FLUSH);
} while (result==Z_OK && pkt_size<10000000);
pkt_size = zstream.total_out;
inflateEnd(&zstream);
if (result != Z_STREAM_END)
goto failed;
break;
}
#endif
#if CONFIG_BZLIB
case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
bz_stream bzstream = {0};
if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
return -1;
bzstream.next_in = data;
bzstream.avail_in = isize;
do {
pkt_size *= 3;
pkt_data = av_realloc(pkt_data, pkt_size);
bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
bzstream.next_out = pkt_data + bzstream.total_out_lo32;
result = BZ2_bzDecompress(&bzstream);
} while (result==BZ_OK && pkt_size<10000000);
pkt_size = bzstream.total_out_lo32;
BZ2_bzDecompressEnd(&bzstream);
if (result != BZ_STREAM_END)
goto failed;
break;
}
#endif
default:
return -1;
}
*buf = pkt_data;
*buf_size = pkt_size;
return 0;
failed:
av_free(pkt_data);
return -1;
}
|
['static int matroska_decode_buffer(uint8_t** buf, int* buf_size,\n MatroskaTrack *track)\n{\n MatroskaTrackEncoding *encodings = track->encodings.elem;\n uint8_t* data = *buf;\n int isize = *buf_size;\n uint8_t* pkt_data = NULL;\n int pkt_size = isize;\n int result = 0;\n int olen;\n switch (encodings[0].compression.algo) {\n case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:\n return encodings[0].compression.settings.size;\n case MATROSKA_TRACK_ENCODING_COMP_LZO:\n do {\n olen = pkt_size *= 3;\n pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING);\n result = av_lzo1x_decode(pkt_data, &olen, data, &isize);\n } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000);\n if (result)\n goto failed;\n pkt_size -= olen;\n break;\n#if CONFIG_ZLIB\n case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {\n z_stream zstream = {0};\n if (inflateInit(&zstream) != Z_OK)\n return -1;\n zstream.next_in = data;\n zstream.avail_in = isize;\n do {\n pkt_size *= 3;\n pkt_data = av_realloc(pkt_data, pkt_size);\n zstream.avail_out = pkt_size - zstream.total_out;\n zstream.next_out = pkt_data + zstream.total_out;\n result = inflate(&zstream, Z_NO_FLUSH);\n } while (result==Z_OK && pkt_size<10000000);\n pkt_size = zstream.total_out;\n inflateEnd(&zstream);\n if (result != Z_STREAM_END)\n goto failed;\n break;\n }\n#endif\n#if CONFIG_BZLIB\n case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {\n bz_stream bzstream = {0};\n if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)\n return -1;\n bzstream.next_in = data;\n bzstream.avail_in = isize;\n do {\n pkt_size *= 3;\n pkt_data = av_realloc(pkt_data, pkt_size);\n bzstream.avail_out = pkt_size - bzstream.total_out_lo32;\n bzstream.next_out = pkt_data + bzstream.total_out_lo32;\n result = BZ2_bzDecompress(&bzstream);\n } while (result==BZ_OK && pkt_size<10000000);\n pkt_size = bzstream.total_out_lo32;\n BZ2_bzDecompressEnd(&bzstream);\n if (result != BZ_STREAM_END)\n goto failed;\n break;\n }\n#endif\n default:\n return -1;\n }\n *buf = pkt_data;\n *buf_size = pkt_size;\n return 0;\n failed:\n av_free(pkt_data);\n return -1;\n}', 'void *av_realloc(void *ptr, unsigned int size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}']
|
912
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/apps/s_server.c/#L526
|
static int get_ocsp_resp_from_responder(SSL *s, tlsextstatusctx *srctx,
OCSP_RESPONSE **resp)
{
char *host = NULL, *port = NULL, *path = NULL;
int use_ssl;
STACK_OF(OPENSSL_STRING) *aia = NULL;
X509 *x = NULL;
X509_STORE_CTX *inctx = NULL;
X509_OBJECT *obj;
OCSP_REQUEST *req = NULL;
OCSP_CERTID *id = NULL;
STACK_OF(X509_EXTENSION) *exts;
int ret = SSL_TLSEXT_ERR_NOACK;
int i;
x = SSL_get_certificate(s);
aia = X509_get1_ocsp(x);
if (aia != NULL) {
if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),
&host, &port, &path, &use_ssl)) {
BIO_puts(bio_err, "cert_status: can't parse AIA URL\n");
goto err;
}
if (srctx->verbose)
BIO_printf(bio_err, "cert_status: AIA URL: %s\n",
sk_OPENSSL_STRING_value(aia, 0));
} else {
if (srctx->host == NULL) {
BIO_puts(bio_err,
"cert_status: no AIA and no default responder URL\n");
goto done;
}
host = srctx->host;
path = srctx->path;
port = srctx->port;
use_ssl = srctx->use_ssl;
}
inctx = X509_STORE_CTX_new();
if (inctx == NULL)
goto err;
if (!X509_STORE_CTX_init(inctx,
SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),
NULL, NULL))
goto err;
obj = X509_STORE_CTX_get_obj_by_subject(inctx, X509_LU_X509,
X509_get_issuer_name(x));
if (obj == NULL) {
BIO_puts(bio_err, "cert_status: Can't retrieve issuer certificate.\n");
goto done;
}
id = OCSP_cert_to_id(NULL, x, X509_OBJECT_get0_X509(obj));
X509_OBJECT_free(obj);
if (id == NULL)
goto err;
req = OCSP_REQUEST_new();
if (req == NULL)
goto err;
if (!OCSP_request_add0_id(req, id))
goto err;
id = NULL;
SSL_get_tlsext_status_exts(s, &exts);
for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {
X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
if (!OCSP_REQUEST_add_ext(req, ext, -1))
goto err;
}
*resp = process_responder(req, host, path, port, use_ssl, NULL,
srctx->timeout);
if (*resp == NULL) {
BIO_puts(bio_err, "cert_status: error querying responder\n");
goto done;
}
ret = SSL_TLSEXT_ERR_OK;
goto done;
err:
ret = SSL_TLSEXT_ERR_ALERT_FATAL;
done:
if (aia != NULL) {
OPENSSL_free(host);
OPENSSL_free(path);
OPENSSL_free(port);
X509_email_free(aia);
}
OCSP_CERTID_free(id);
OCSP_REQUEST_free(req);
X509_STORE_CTX_free(inctx);
return ret;
}
|
['static int get_ocsp_resp_from_responder(SSL *s, tlsextstatusctx *srctx,\n OCSP_RESPONSE **resp)\n{\n char *host = NULL, *port = NULL, *path = NULL;\n int use_ssl;\n STACK_OF(OPENSSL_STRING) *aia = NULL;\n X509 *x = NULL;\n X509_STORE_CTX *inctx = NULL;\n X509_OBJECT *obj;\n OCSP_REQUEST *req = NULL;\n OCSP_CERTID *id = NULL;\n STACK_OF(X509_EXTENSION) *exts;\n int ret = SSL_TLSEXT_ERR_NOACK;\n int i;\n x = SSL_get_certificate(s);\n aia = X509_get1_ocsp(x);\n if (aia != NULL) {\n if (!OCSP_parse_url(sk_OPENSSL_STRING_value(aia, 0),\n &host, &port, &path, &use_ssl)) {\n BIO_puts(bio_err, "cert_status: can\'t parse AIA URL\\n");\n goto err;\n }\n if (srctx->verbose)\n BIO_printf(bio_err, "cert_status: AIA URL: %s\\n",\n sk_OPENSSL_STRING_value(aia, 0));\n } else {\n if (srctx->host == NULL) {\n BIO_puts(bio_err,\n "cert_status: no AIA and no default responder URL\\n");\n goto done;\n }\n host = srctx->host;\n path = srctx->path;\n port = srctx->port;\n use_ssl = srctx->use_ssl;\n }\n inctx = X509_STORE_CTX_new();\n if (inctx == NULL)\n goto err;\n if (!X509_STORE_CTX_init(inctx,\n SSL_CTX_get_cert_store(SSL_get_SSL_CTX(s)),\n NULL, NULL))\n goto err;\n obj = X509_STORE_CTX_get_obj_by_subject(inctx, X509_LU_X509,\n X509_get_issuer_name(x));\n if (obj == NULL) {\n BIO_puts(bio_err, "cert_status: Can\'t retrieve issuer certificate.\\n");\n goto done;\n }\n id = OCSP_cert_to_id(NULL, x, X509_OBJECT_get0_X509(obj));\n X509_OBJECT_free(obj);\n if (id == NULL)\n goto err;\n req = OCSP_REQUEST_new();\n if (req == NULL)\n goto err;\n if (!OCSP_request_add0_id(req, id))\n goto err;\n id = NULL;\n SSL_get_tlsext_status_exts(s, &exts);\n for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) {\n X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);\n if (!OCSP_REQUEST_add_ext(req, ext, -1))\n goto err;\n }\n *resp = process_responder(req, host, path, port, use_ssl, NULL,\n srctx->timeout);\n if (*resp == NULL) {\n BIO_puts(bio_err, "cert_status: error querying responder\\n");\n goto done;\n }\n ret = SSL_TLSEXT_ERR_OK;\n goto done;\n err:\n ret = SSL_TLSEXT_ERR_ALERT_FATAL;\n done:\n if (aia != NULL) {\n OPENSSL_free(host);\n OPENSSL_free(path);\n OPENSSL_free(port);\n X509_email_free(aia);\n }\n OCSP_CERTID_free(id);\n OCSP_REQUEST_free(req);\n X509_STORE_CTX_free(inctx);\n return ret;\n}', 'X509 *SSL_get_certificate(const SSL *s)\n{\n if (s->cert != NULL)\n return s->cert->key->x509;\n else\n return NULL;\n}']
|
913
| 0
|
https://github.com/libav/libav/blob/e3ec6fe7bb2a622a863e3912181717a659eb1bad/libavcodec/h264_mb.c/#L625
|
static av_always_inline void hl_decode_mb_predict_luma(const H264Context *h,
H264SliceContext *sl,
int mb_type, int is_h264,
int simple,
int transform_bypass,
int pixel_shift,
const int *block_offset,
int linesize,
uint8_t *dest_y, int p)
{
void (*idct_add)(uint8_t *dst, int16_t *block, int stride);
void (*idct_dc_add)(uint8_t *dst, int16_t *block, int stride);
int i;
int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];
block_offset += 16 * p;
if (IS_INTRA4x4(mb_type)) {
if (IS_8x8DCT(mb_type)) {
if (transform_bypass) {
idct_dc_add =
idct_add = h->h264dsp.h264_add_pixels8_clear;
} else {
idct_dc_add = h->h264dsp.h264_idct8_dc_add;
idct_add = h->h264dsp.h264_idct8_add;
}
for (i = 0; i < 16; i += 4) {
uint8_t *const ptr = dest_y + block_offset[i];
const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];
if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) {
h->hpc.pred8x8l_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
} else {
const int nnz = sl->non_zero_count_cache[scan8[i + p * 16]];
h->hpc.pred8x8l[dir](ptr, (sl->topleft_samples_available << i) & 0x8000,
(sl->topright_samples_available << i) & 0x4000, linesize);
if (nnz) {
if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
else
idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
}
}
}
} else {
if (transform_bypass) {
idct_dc_add =
idct_add = h->h264dsp.h264_add_pixels4_clear;
} else {
idct_dc_add = h->h264dsp.h264_idct_dc_add;
idct_add = h->h264dsp.h264_idct_add;
}
for (i = 0; i < 16; i++) {
uint8_t *const ptr = dest_y + block_offset[i];
const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];
if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) {
h->hpc.pred4x4_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
} else {
uint8_t *topright;
int nnz, tr;
uint64_t tr_high;
if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {
const int topright_avail = (sl->topright_samples_available << i) & 0x8000;
assert(sl->mb_y || linesize <= block_offset[i]);
if (!topright_avail) {
if (pixel_shift) {
tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;
topright = (uint8_t *)&tr_high;
} else {
tr = ptr[3 - linesize] * 0x01010101u;
topright = (uint8_t *)&tr;
}
} else
topright = ptr + (4 << pixel_shift) - linesize;
} else
topright = NULL;
h->hpc.pred4x4[dir](ptr, topright, linesize);
nnz = sl->non_zero_count_cache[scan8[i + p * 16]];
if (nnz) {
if (is_h264) {
if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))
idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
else
idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);
} else if (CONFIG_SVQ3_DECODER)
ff_svq3_add_idct_c(ptr, sl->mb + i * 16 + p * 256, linesize, qscale, 0);
}
}
}
}
} else {
h->hpc.pred16x16[sl->intra16x16_pred_mode](dest_y, linesize);
if (is_h264) {
if (sl->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) {
if (!transform_bypass)
h->h264dsp.h264_luma_dc_dequant_idct(sl->mb + (p * 256 << pixel_shift),
sl->mb_luma_dc[p],
h->dequant4_coeff[p][qscale][0]);
else {
static const uint8_t dc_mapping[16] = {
0 * 16, 1 * 16, 4 * 16, 5 * 16,
2 * 16, 3 * 16, 6 * 16, 7 * 16,
8 * 16, 9 * 16, 12 * 16, 13 * 16,
10 * 16, 11 * 16, 14 * 16, 15 * 16
};
for (i = 0; i < 16; i++)
dctcoef_set(sl->mb + (p * 256 << pixel_shift),
pixel_shift, dc_mapping[i],
dctcoef_get(sl->mb_luma_dc[p],
pixel_shift, i));
}
}
} else if (CONFIG_SVQ3_DECODER)
ff_svq3_luma_dc_dequant_idct_c(sl->mb + p * 256,
sl->mb_luma_dc[p], qscale);
}
}
|
['static av_noinline void FUNC(hl_decode_mb)(const H264Context *h, H264SliceContext *sl)\n{\n const int mb_x = sl->mb_x;\n const int mb_y = sl->mb_y;\n const int mb_xy = sl->mb_xy;\n const int mb_type = h->cur_pic.mb_type[mb_xy];\n uint8_t *dest_y, *dest_cb, *dest_cr;\n int linesize, uvlinesize ;\n int i, j;\n const int *block_offset = &h->block_offset[0];\n const int transform_bypass = !SIMPLE && (sl->qscale == 0 && h->sps.transform_bypass);\n const int is_h264 = !CONFIG_SVQ3_DECODER || SIMPLE || h->avctx->codec_id == AV_CODEC_ID_H264;\n void (*idct_add)(uint8_t *dst, int16_t *block, int stride);\n const int block_h = 16 >> h->chroma_y_shift;\n const int chroma422 = CHROMA422(h);\n dest_y = h->cur_pic.f.data[0] + ((mb_x << PIXEL_SHIFT) + mb_y * sl->linesize) * 16;\n dest_cb = h->cur_pic.f.data[1] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;\n dest_cr = h->cur_pic.f.data[2] + (mb_x << PIXEL_SHIFT) * 8 + mb_y * sl->uvlinesize * block_h;\n h->vdsp.prefetch(dest_y + (sl->mb_x & 3) * 4 * sl->linesize + (64 << PIXEL_SHIFT), sl->linesize, 4);\n h->vdsp.prefetch(dest_cb + (sl->mb_x & 7) * sl->uvlinesize + (64 << PIXEL_SHIFT), dest_cr - dest_cb, 2);\n h->list_counts[mb_xy] = sl->list_count;\n if (!SIMPLE && MB_FIELD(sl)) {\n linesize = sl->mb_linesize = sl->linesize * 2;\n uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2;\n block_offset = &h->block_offset[48];\n if (mb_y & 1) {\n dest_y -= sl->linesize * 15;\n dest_cb -= sl->uvlinesize * (block_h - 1);\n dest_cr -= sl->uvlinesize * (block_h - 1);\n }\n if (FRAME_MBAFF(h)) {\n int list;\n for (list = 0; list < sl->list_count; list++) {\n if (!USES_LIST(mb_type, list))\n continue;\n if (IS_16X16(mb_type)) {\n int8_t *ref = &sl->ref_cache[list][scan8[0]];\n fill_rectangle(ref, 4, 4, 8, (16 + *ref) ^ (sl->mb_y & 1), 1);\n } else {\n for (i = 0; i < 16; i += 4) {\n int ref = sl->ref_cache[list][scan8[i]];\n if (ref >= 0)\n fill_rectangle(&sl->ref_cache[list][scan8[i]], 2, 2,\n 8, (16 + ref) ^ (sl->mb_y & 1), 1);\n }\n }\n }\n }\n } else {\n linesize = sl->mb_linesize = sl->linesize;\n uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;\n }\n if (!SIMPLE && IS_INTRA_PCM(mb_type)) {\n if (PIXEL_SHIFT) {\n const int bit_depth = h->sps.bit_depth_luma;\n int j;\n GetBitContext gb;\n init_get_bits(&gb, sl->intra_pcm_ptr,\n ff_h264_mb_sizes[h->sps.chroma_format_idc] * bit_depth);\n for (i = 0; i < 16; i++) {\n uint16_t *tmp_y = (uint16_t *)(dest_y + i * linesize);\n for (j = 0; j < 16; j++)\n tmp_y[j] = get_bits(&gb, bit_depth);\n }\n if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) {\n if (!h->sps.chroma_format_idc) {\n for (i = 0; i < block_h; i++) {\n uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);\n for (j = 0; j < 8; j++)\n tmp_cb[j] = 1 << (bit_depth - 1);\n }\n for (i = 0; i < block_h; i++) {\n uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);\n for (j = 0; j < 8; j++)\n tmp_cr[j] = 1 << (bit_depth - 1);\n }\n } else {\n for (i = 0; i < block_h; i++) {\n uint16_t *tmp_cb = (uint16_t *)(dest_cb + i * uvlinesize);\n for (j = 0; j < 8; j++)\n tmp_cb[j] = get_bits(&gb, bit_depth);\n }\n for (i = 0; i < block_h; i++) {\n uint16_t *tmp_cr = (uint16_t *)(dest_cr + i * uvlinesize);\n for (j = 0; j < 8; j++)\n tmp_cr[j] = get_bits(&gb, bit_depth);\n }\n }\n }\n } else {\n for (i = 0; i < 16; i++)\n memcpy(dest_y + i * linesize, sl->intra_pcm_ptr + i * 16, 16);\n if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) {\n if (!h->sps.chroma_format_idc) {\n for (i = 0; i < block_h; i++) {\n memset(dest_cb + i * uvlinesize, 128, 8);\n memset(dest_cr + i * uvlinesize, 128, 8);\n }\n } else {\n const uint8_t *src_cb = sl->intra_pcm_ptr + 256;\n const uint8_t *src_cr = sl->intra_pcm_ptr + 256 + block_h * 8;\n for (i = 0; i < block_h; i++) {\n memcpy(dest_cb + i * uvlinesize, src_cb + i * 8, 8);\n memcpy(dest_cr + i * uvlinesize, src_cr + i * 8, 8);\n }\n }\n }\n }\n } else {\n if (IS_INTRA(mb_type)) {\n if (sl->deblocking_filter)\n xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n uvlinesize, 1, 0, SIMPLE, PIXEL_SHIFT);\n if (SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) {\n h->hpc.pred8x8[sl->chroma_pred_mode](dest_cb, uvlinesize);\n h->hpc.pred8x8[sl->chroma_pred_mode](dest_cr, uvlinesize);\n }\n hl_decode_mb_predict_luma(h, sl, mb_type, is_h264, SIMPLE,\n transform_bypass, PIXEL_SHIFT,\n block_offset, linesize, dest_y, 0);\n if (sl->deblocking_filter)\n xchg_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n uvlinesize, 0, 0, SIMPLE, PIXEL_SHIFT);\n } else if (is_h264) {\n if (chroma422) {\n FUNC(hl_motion_422)(h, sl, dest_y, dest_cb, dest_cr,\n h->qpel_put, h->h264chroma.put_h264_chroma_pixels_tab,\n h->qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab,\n h->h264dsp.weight_h264_pixels_tab,\n h->h264dsp.biweight_h264_pixels_tab);\n } else {\n FUNC(hl_motion_420)(h, sl, dest_y, dest_cb, dest_cr,\n h->qpel_put, h->h264chroma.put_h264_chroma_pixels_tab,\n h->qpel_avg, h->h264chroma.avg_h264_chroma_pixels_tab,\n h->h264dsp.weight_h264_pixels_tab,\n h->h264dsp.biweight_h264_pixels_tab);\n }\n }\n hl_decode_mb_idct_luma(h, sl, mb_type, is_h264, SIMPLE, transform_bypass,\n PIXEL_SHIFT, block_offset, linesize, dest_y, 0);\n if ((SIMPLE || !CONFIG_GRAY || !(h->flags & CODEC_FLAG_GRAY)) &&\n (sl->cbp & 0x30)) {\n uint8_t *dest[2] = { dest_cb, dest_cr };\n if (transform_bypass) {\n if (IS_INTRA(mb_type) && h->sps.profile_idc == 244 &&\n (sl->chroma_pred_mode == VERT_PRED8x8 ||\n sl->chroma_pred_mode == HOR_PRED8x8)) {\n h->hpc.pred8x8_add[sl->chroma_pred_mode](dest[0],\n block_offset + 16,\n sl->mb + (16 * 16 * 1 << PIXEL_SHIFT),\n uvlinesize);\n h->hpc.pred8x8_add[sl->chroma_pred_mode](dest[1],\n block_offset + 32,\n sl->mb + (16 * 16 * 2 << PIXEL_SHIFT),\n uvlinesize);\n } else {\n idct_add = h->h264dsp.h264_add_pixels4_clear;\n for (j = 1; j < 3; j++) {\n for (i = j * 16; i < j * 16 + 4; i++)\n if (sl->non_zero_count_cache[scan8[i]] ||\n dctcoef_get(sl->mb, PIXEL_SHIFT, i * 16))\n idct_add(dest[j - 1] + block_offset[i],\n sl->mb + (i * 16 << PIXEL_SHIFT),\n uvlinesize);\n if (chroma422) {\n for (i = j * 16 + 4; i < j * 16 + 8; i++)\n if (sl->non_zero_count_cache[scan8[i + 4]] ||\n dctcoef_get(sl->mb, PIXEL_SHIFT, i * 16))\n idct_add(dest[j - 1] + block_offset[i + 4],\n sl->mb + (i * 16 << PIXEL_SHIFT),\n uvlinesize);\n }\n }\n }\n } else {\n if (is_h264) {\n int qp[2];\n if (chroma422) {\n qp[0] = sl->chroma_qp[0] + 3;\n qp[1] = sl->chroma_qp[1] + 3;\n } else {\n qp[0] = sl->chroma_qp[0];\n qp[1] = sl->chroma_qp[1];\n }\n if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 0]])\n h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + (16 * 16 * 1 << PIXEL_SHIFT),\n h->dequant4_coeff[IS_INTRA(mb_type) ? 1 : 4][qp[0]][0]);\n if (sl->non_zero_count_cache[scan8[CHROMA_DC_BLOCK_INDEX + 1]])\n h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + (16 * 16 * 2 << PIXEL_SHIFT),\n h->dequant4_coeff[IS_INTRA(mb_type) ? 2 : 5][qp[1]][0]);\n h->h264dsp.h264_idct_add8(dest, block_offset,\n sl->mb, uvlinesize,\n sl->non_zero_count_cache);\n } else if (CONFIG_SVQ3_DECODER) {\n h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + 16 * 16 * 1,\n h->dequant4_coeff[IS_INTRA(mb_type) ? 1 : 4][sl->chroma_qp[0]][0]);\n h->h264dsp.h264_chroma_dc_dequant_idct(sl->mb + 16 * 16 * 2,\n h->dequant4_coeff[IS_INTRA(mb_type) ? 2 : 5][sl->chroma_qp[1]][0]);\n for (j = 1; j < 3; j++) {\n for (i = j * 16; i < j * 16 + 4; i++)\n if (sl->non_zero_count_cache[scan8[i]] || sl->mb[i * 16]) {\n uint8_t *const ptr = dest[j - 1] + block_offset[i];\n ff_svq3_add_idct_c(ptr, sl->mb + i * 16,\n uvlinesize,\n ff_h264_chroma_qp[0][sl->qscale + 12] - 12, 2);\n }\n }\n }\n }\n }\n }\n}', 'static av_always_inline void hl_decode_mb_predict_luma(const H264Context *h,\n H264SliceContext *sl,\n int mb_type, int is_h264,\n int simple,\n int transform_bypass,\n int pixel_shift,\n const int *block_offset,\n int linesize,\n uint8_t *dest_y, int p)\n{\n void (*idct_add)(uint8_t *dst, int16_t *block, int stride);\n void (*idct_dc_add)(uint8_t *dst, int16_t *block, int stride);\n int i;\n int qscale = p == 0 ? sl->qscale : sl->chroma_qp[p - 1];\n block_offset += 16 * p;\n if (IS_INTRA4x4(mb_type)) {\n if (IS_8x8DCT(mb_type)) {\n if (transform_bypass) {\n idct_dc_add =\n idct_add = h->h264dsp.h264_add_pixels8_clear;\n } else {\n idct_dc_add = h->h264dsp.h264_idct8_dc_add;\n idct_add = h->h264dsp.h264_idct8_add;\n }\n for (i = 0; i < 16; i += 4) {\n uint8_t *const ptr = dest_y + block_offset[i];\n const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];\n if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) {\n h->hpc.pred8x8l_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n } else {\n const int nnz = sl->non_zero_count_cache[scan8[i + p * 16]];\n h->hpc.pred8x8l[dir](ptr, (sl->topleft_samples_available << i) & 0x8000,\n (sl->topright_samples_available << i) & 0x4000, linesize);\n if (nnz) {\n if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))\n idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n else\n idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n }\n }\n }\n } else {\n if (transform_bypass) {\n idct_dc_add =\n idct_add = h->h264dsp.h264_add_pixels4_clear;\n } else {\n idct_dc_add = h->h264dsp.h264_idct_dc_add;\n idct_add = h->h264dsp.h264_idct_add;\n }\n for (i = 0; i < 16; i++) {\n uint8_t *const ptr = dest_y + block_offset[i];\n const int dir = sl->intra4x4_pred_mode_cache[scan8[i]];\n if (transform_bypass && h->sps.profile_idc == 244 && dir <= 1) {\n h->hpc.pred4x4_add[dir](ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n } else {\n uint8_t *topright;\n int nnz, tr;\n uint64_t tr_high;\n if (dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED) {\n const int topright_avail = (sl->topright_samples_available << i) & 0x8000;\n assert(sl->mb_y || linesize <= block_offset[i]);\n if (!topright_avail) {\n if (pixel_shift) {\n tr_high = ((uint16_t *)ptr)[3 - linesize / 2] * 0x0001000100010001ULL;\n topright = (uint8_t *)&tr_high;\n } else {\n tr = ptr[3 - linesize] * 0x01010101u;\n topright = (uint8_t *)&tr;\n }\n } else\n topright = ptr + (4 << pixel_shift) - linesize;\n } else\n topright = NULL;\n h->hpc.pred4x4[dir](ptr, topright, linesize);\n nnz = sl->non_zero_count_cache[scan8[i + p * 16]];\n if (nnz) {\n if (is_h264) {\n if (nnz == 1 && dctcoef_get(sl->mb, pixel_shift, i * 16 + p * 256))\n idct_dc_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n else\n idct_add(ptr, sl->mb + (i * 16 + p * 256 << pixel_shift), linesize);\n } else if (CONFIG_SVQ3_DECODER)\n ff_svq3_add_idct_c(ptr, sl->mb + i * 16 + p * 256, linesize, qscale, 0);\n }\n }\n }\n }\n } else {\n h->hpc.pred16x16[sl->intra16x16_pred_mode](dest_y, linesize);\n if (is_h264) {\n if (sl->non_zero_count_cache[scan8[LUMA_DC_BLOCK_INDEX + p]]) {\n if (!transform_bypass)\n h->h264dsp.h264_luma_dc_dequant_idct(sl->mb + (p * 256 << pixel_shift),\n sl->mb_luma_dc[p],\n h->dequant4_coeff[p][qscale][0]);\n else {\n static const uint8_t dc_mapping[16] = {\n 0 * 16, 1 * 16, 4 * 16, 5 * 16,\n 2 * 16, 3 * 16, 6 * 16, 7 * 16,\n 8 * 16, 9 * 16, 12 * 16, 13 * 16,\n 10 * 16, 11 * 16, 14 * 16, 15 * 16\n };\n for (i = 0; i < 16; i++)\n dctcoef_set(sl->mb + (p * 256 << pixel_shift),\n pixel_shift, dc_mapping[i],\n dctcoef_get(sl->mb_luma_dc[p],\n pixel_shift, i));\n }\n }\n } else if (CONFIG_SVQ3_DECODER)\n ff_svq3_luma_dc_dequant_idct_c(sl->mb + p * 256,\n sl->mb_luma_dc[p], qscale);\n }\n}']
|
914
| 0
|
https://github.com/openssl/openssl/blob/3ba25ee86a3758cc659c954b59718d8397030768/ssl/ssl_cert.c/#L756
|
int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
const char *dir)
{
DIR *d;
struct dirent *dstruct;
int ret = 0;
CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
d = opendir(dir);
if(!d)
{
SYSerr(SYS_F_OPENDIR, get_last_sys_error());
ERR_add_error_data(3, "opendir('", dir, "')");
SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
goto err;
}
while((dstruct=readdir(d)))
{
char buf[1024];
int r;
if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
{
SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
goto err;
}
r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);
if (r <= 0 || r >= sizeof buf)
goto err;
if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
goto err;
}
ret = 1;
err:
CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
return ret;
}
|
['int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,\n\t\t\t\t const char *dir)\n\t{\n\tDIR *d;\n\tstruct dirent *dstruct;\n\tint ret = 0;\n\tCRYPTO_w_lock(CRYPTO_LOCK_READDIR);\n\td = opendir(dir);\n\tif(!d)\n\t\t{\n\t\tSYSerr(SYS_F_OPENDIR, get_last_sys_error());\n\t\tERR_add_error_data(3, "opendir(\'", dir, "\')");\n\t\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);\n\t\tgoto err;\n\t\t}\n\twhile((dstruct=readdir(d)))\n\t\t{\n\t\tchar buf[1024];\n\t\tint r;\n\t\tif(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);\n\t\t\tgoto err;\n\t\t\t}\n\t\tr = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,dstruct->d_name);\n\t\tif (r <= 0 || r >= sizeof buf)\n\t\t\tgoto err;\n\t\tif(!SSL_add_file_cert_subjects_to_stack(stack,buf))\n\t\t\tgoto err;\n\t\t}\n\tret = 1;\nerr:\n\tCRYPTO_w_unlock(CRYPTO_LOCK_READDIR);\n\treturn ret;\n\t}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tchar *rw_text,*operation_text;\n\t\tif (mode & CRYPTO_LOCK)\n\t\t\toperation_text="lock ";\n\t\telse if (mode & CRYPTO_UNLOCK)\n\t\t\toperation_text="unlock";\n\t\telse\n\t\t\toperation_text="ERROR ";\n\t\tif (mode & CRYPTO_READ)\n\t\t\trw_text="r";\n\t\telse if (mode & CRYPTO_WRITE)\n\t\t\trw_text="w";\n\t\telse\n\t\t\trw_text="ERROR";\n\t\tfprintf(stderr,"lock:%08lx:(%s)%s %-18s %s:%d\\n",\n\t\t\tCRYPTO_thread_id(), rw_text, operation_text,\n\t\t\tCRYPTO_get_lock_name(type), file, line);\n\t\t}\n#endif\n\tif (type < 0)\n\t\t{\n\t\tint i = -type - 1;\n\t\tstruct CRYPTO_dynlock_value *pointer\n\t\t\t= CRYPTO_get_dynlock_value(i);\n\t\tif (pointer)\n\t\t\t{\n\t\t\tdynlock_lock_callback(mode, pointer, file, line);\n\t\t\t}\n\t\tCRYPTO_destroy_dynlockid(i);\n\t\t}\n\telse\n\t\tif (locking_callback != NULL)\n\t\t\tlocking_callback(mode,type,file,line);\n\t}']
|
915
| 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 decode_band_hdr(IVI45DecContext *ctx, IVIBandDesc *band,\n AVCodecContext *avctx)\n{\n int i, ret;\n uint8_t band_flags;\n band_flags = bitstream_read(&ctx->bc, 8);\n if (band_flags & 1) {\n band->is_empty = 1;\n return 0;\n }\n band->data_size = (ctx->frame_flags & 0x80) ? bitstream_read(&ctx->bc, 24) : 0;\n band->inherit_mv = band_flags & 2;\n band->inherit_qdelta = band_flags & 8;\n band->qdelta_present = band_flags & 4;\n if (!band->qdelta_present) band->inherit_qdelta = 1;\n band->num_corr = 0;\n if (band_flags & 0x10) {\n band->num_corr = bitstream_read(&ctx->bc, 8);\n if (band->num_corr > 61) {\n av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\\n",\n band->num_corr);\n return AVERROR_INVALIDDATA;\n }\n for (i = 0; i < band->num_corr * 2; i++)\n band->corr[i] = bitstream_read(&ctx->bc, 8);\n }\n band->rvmap_sel = (band_flags & 0x40) ? bitstream_read(&ctx->bc, 3) : 8;\n ret = ff_ivi_dec_huff_desc(&ctx->bc, band_flags & 0x80, IVI_BLK_HUFF,\n &band->blk_vlc, avctx);\n if (ret < 0)\n return ret;\n band->checksum_present = bitstream_read_bit(&ctx->bc);\n if (band->checksum_present)\n band->checksum = bitstream_read(&ctx->bc, 16);\n band->glob_quant = bitstream_read(&ctx->bc, 5);\n if (band_flags & 0x20) {\n bitstream_align(&ctx->bc);\n skip_hdr_extension(&ctx->bc);\n }\n bitstream_align(&ctx->bc);\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
916
| 0
|
https://github.com/openssl/openssl/blob/8580f8015fa2f56da854ece033f9d1894bcc3ede/ssl/d1_both.c/#L1013
|
int
dtls1_buffer_message(SSL *s, int is_ccs)
{
pitem *item;
hm_fragment *frag;
unsigned char seq64be[8];
OPENSSL_assert(s->init_off == 0);
frag = dtls1_hm_fragment_new(s->init_num);
memcpy(frag->fragment, s->init_buf->data, s->init_num);
if ( is_ccs)
{
OPENSSL_assert(s->d1->w_msg_hdr.msg_len +
((s->version==DTLS1_VERSION)?DTLS1_CCS_HEADER_LENGTH:3) == (unsigned int)s->init_num);
}
else
{
OPENSSL_assert(s->d1->w_msg_hdr.msg_len +
DTLS1_HM_HEADER_LENGTH == (unsigned int)s->init_num);
}
frag->msg_header.msg_len = s->d1->w_msg_hdr.msg_len;
frag->msg_header.seq = s->d1->w_msg_hdr.seq;
frag->msg_header.type = s->d1->w_msg_hdr.type;
frag->msg_header.frag_off = 0;
frag->msg_header.frag_len = s->d1->w_msg_hdr.msg_len;
frag->msg_header.is_ccs = is_ccs;
frag->msg_header.saved_retransmit_state.enc_write_ctx = s->enc_write_ctx;
frag->msg_header.saved_retransmit_state.write_hash = s->write_hash;
frag->msg_header.saved_retransmit_state.compress = s->compress;
frag->msg_header.saved_retransmit_state.session = s->session;
frag->msg_header.saved_retransmit_state.epoch = s->d1->w_epoch;
memset(seq64be,0,sizeof(seq64be));
seq64be[6] = (unsigned char)(dtls1_get_queue_priority(frag->msg_header.seq,
frag->msg_header.is_ccs)>>8);
seq64be[7] = (unsigned char)(dtls1_get_queue_priority(frag->msg_header.seq,
frag->msg_header.is_ccs));
item = pitem_new(seq64be, frag);
if ( item == NULL)
{
dtls1_hm_fragment_free(frag);
return 0;
}
#if 0
fprintf( stderr, "buffered messge: \ttype = %xx\n", msg_buf->type);
fprintf( stderr, "\t\t\t\t\tlen = %d\n", msg_buf->len);
fprintf( stderr, "\t\t\t\t\tseq_num = %d\n", msg_buf->seq_num);
#endif
pqueue_insert(s->d1->sent_messages, item);
return 1;
}
|
['int\ndtls1_buffer_message(SSL *s, int is_ccs)\n\t{\n\tpitem *item;\n\thm_fragment *frag;\n\tunsigned char seq64be[8];\n\tOPENSSL_assert(s->init_off == 0);\n\tfrag = dtls1_hm_fragment_new(s->init_num);\n\tmemcpy(frag->fragment, s->init_buf->data, s->init_num);\n\tif ( is_ccs)\n\t\t{\n\t\tOPENSSL_assert(s->d1->w_msg_hdr.msg_len +\n\t\t\t ((s->version==DTLS1_VERSION)?DTLS1_CCS_HEADER_LENGTH:3) == (unsigned int)s->init_num);\n\t\t}\n\telse\n\t\t{\n\t\tOPENSSL_assert(s->d1->w_msg_hdr.msg_len +\n\t\t\tDTLS1_HM_HEADER_LENGTH == (unsigned int)s->init_num);\n\t\t}\n\tfrag->msg_header.msg_len = s->d1->w_msg_hdr.msg_len;\n\tfrag->msg_header.seq = s->d1->w_msg_hdr.seq;\n\tfrag->msg_header.type = s->d1->w_msg_hdr.type;\n\tfrag->msg_header.frag_off = 0;\n\tfrag->msg_header.frag_len = s->d1->w_msg_hdr.msg_len;\n\tfrag->msg_header.is_ccs = is_ccs;\n\tfrag->msg_header.saved_retransmit_state.enc_write_ctx = s->enc_write_ctx;\n\tfrag->msg_header.saved_retransmit_state.write_hash = s->write_hash;\n\tfrag->msg_header.saved_retransmit_state.compress = s->compress;\n\tfrag->msg_header.saved_retransmit_state.session = s->session;\n\tfrag->msg_header.saved_retransmit_state.epoch = s->d1->w_epoch;\n\tmemset(seq64be,0,sizeof(seq64be));\n\tseq64be[6] = (unsigned char)(dtls1_get_queue_priority(frag->msg_header.seq,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t frag->msg_header.is_ccs)>>8);\n\tseq64be[7] = (unsigned char)(dtls1_get_queue_priority(frag->msg_header.seq,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t frag->msg_header.is_ccs));\n\titem = pitem_new(seq64be, frag);\n\tif ( item == NULL)\n\t\t{\n\t\tdtls1_hm_fragment_free(frag);\n\t\treturn 0;\n\t\t}\n#if 0\n\tfprintf( stderr, "buffered messge: \\ttype = %xx\\n", msg_buf->type);\n\tfprintf( stderr, "\\t\\t\\t\\t\\tlen = %d\\n", msg_buf->len);\n\tfprintf( stderr, "\\t\\t\\t\\t\\tseq_num = %d\\n", msg_buf->seq_num);\n#endif\n\tpqueue_insert(s->d1->sent_messages, item);\n\treturn 1;\n\t}', 'static hm_fragment *\ndtls1_hm_fragment_new(unsigned long frag_len)\n\t{\n\thm_fragment *frag = NULL;\n\tunsigned char *buf = NULL;\n\tfrag = (hm_fragment *)OPENSSL_malloc(sizeof(hm_fragment));\n\tif ( frag == NULL)\n\t\treturn NULL;\n\tif (frag_len)\n\t\t{\n\t\tbuf = (unsigned char *)OPENSSL_malloc(frag_len);\n\t\tif ( buf == NULL)\n\t\t\t{\n\t\t\tOPENSSL_free(frag);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\tfrag->fragment = buf;\n\treturn frag;\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}']
|
917
| 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;
}
|
['void\nngx_os_status(ngx_log_t *log)\n{\n ngx_log_error(NGX_LOG_NOTICE, log, 0, NGINX_VER);\n#ifdef NGX_COMPILER\n ngx_log_error(NGX_LOG_NOTICE, log, 0, "built by " NGX_COMPILER);\n#endif\n#if (NGX_HAVE_OS_SPECIFIC_INIT)\n ngx_os_specific_status(log);\n#endif\n ngx_log_error(NGX_LOG_NOTICE, log, 0,\n "getrlimit(RLIMIT_NOFILE): %r:%r",\n rlmt.rlim_cur, rlmt.rlim_max);\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}"]
|
918
| 1
|
https://github.com/libav/libav/blob/63e8d9760f23a4edf81e9ae58c4f6d3baa6ff4dd/libavcodec/dct32.c/#L264
|
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}']
|
919
| 0
|
https://github.com/openssl/openssl/blob/af57d843124672a9053a4da60ad7f9b6d4324a5a/crypto/lhash/lhash.c/#L240
|
void *lh_delete(LHASH *lh, void *data)
{
unsigned long hash;
LHASH_NODE *nn,**rn;
void *ret;
lh->error=0;
rn=getrn(lh,data,&hash);
if (*rn == NULL)
{
lh->num_no_delete++;
return(NULL);
}
else
{
nn= *rn;
*rn=nn->next;
ret=nn->data;
Free(nn);
lh->num_delete++;
}
lh->num_items--;
if ((lh->num_nodes > MIN_NODES) &&
(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
contract(lh);
return(ret);
}
|
['int MAIN(int argc, char **argv)\n\t{\n\tint off=0;\n\tSSL *con=NULL,*con2=NULL;\n\tint s,k,width,state=0;\n\tchar *cbuf=NULL,*sbuf=NULL;\n\tint cbuf_len,cbuf_off;\n\tint sbuf_len,sbuf_off;\n\tfd_set readfds,writefds;\n\tshort port=PORT;\n\tint full_log=1;\n\tchar *host=SSL_HOST_NAME;\n\tchar *cert_file=NULL,*key_file=NULL;\n\tchar *CApath=NULL,*CAfile=NULL,*cipher=NULL;\n\tint reconnect=0,badop=0,verify=SSL_VERIFY_NONE,bugs=0;\n\tint crlf=0;\n\tint write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;\n\tSSL_CTX *ctx=NULL;\n\tint ret=1,in_init=1,i,nbio_test=0;\n\tint prexit = 0;\n\tSSL_METHOD *meth=NULL;\n\tBIO *sbio;\n#ifdef WINDOWS\n\tstruct timeval tv;\n#endif\n#if !defined(NO_SSL2) && !defined(NO_SSL3)\n\tmeth=SSLv23_client_method();\n#elif !defined(NO_SSL3)\n\tmeth=SSLv3_client_method();\n#elif !defined(NO_SSL2)\n\tmeth=SSLv2_client_method();\n#endif\n\tapps_startup();\n\tc_Pause=0;\n\tc_quiet=0;\n\tc_debug=0;\n\tc_showcerts=0;\n\tif (bio_err == NULL)\n\t\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tif (\t((cbuf=Malloc(BUFSIZZ)) == NULL) ||\n\t\t((sbuf=Malloc(BUFSIZZ)) == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tverify_depth=0;\n\tverify_error=X509_V_OK;\n#ifdef FIONBIO\n\tc_nbio=0;\n#endif\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif\t(strcmp(*argv,"-host") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\thost= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-port") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tport=atoi(*(++argv));\n\t\t\tif (port == 0) goto bad;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-connect") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-verify") == 0)\n\t\t\t{\n\t\t\tverify=SSL_VERIFY_PEER;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tverify_depth=atoi(*(++argv));\n\t\t\tBIO_printf(bio_err,"verify depth is %d\\n",verify_depth);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcert_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-prexit") == 0)\n\t\t\tprexit=1;\n\t\telse if\t(strcmp(*argv,"-crlf") == 0)\n\t\t\tcrlf=1;\n\t\telse if\t(strcmp(*argv,"-quiet") == 0)\n\t\t\tc_quiet=1;\n\t\telse if\t(strcmp(*argv,"-pause") == 0)\n\t\t\tc_Pause=1;\n\t\telse if\t(strcmp(*argv,"-debug") == 0)\n\t\t\tc_debug=1;\n\t\telse if\t(strcmp(*argv,"-showcerts") == 0)\n\t\t\tc_showcerts=1;\n\t\telse if\t(strcmp(*argv,"-nbio_test") == 0)\n\t\t\tnbio_test=1;\n\t\telse if\t(strcmp(*argv,"-state") == 0)\n\t\t\tstate=1;\n#ifndef NO_SSL2\n\t\telse if\t(strcmp(*argv,"-ssl2") == 0)\n\t\t\tmeth=SSLv2_client_method();\n#endif\n#ifndef NO_SSL3\n\t\telse if\t(strcmp(*argv,"-ssl3") == 0)\n\t\t\tmeth=SSLv3_client_method();\n#endif\n#ifndef NO_TLS1\n\t\telse if\t(strcmp(*argv,"-tls1") == 0)\n\t\t\tmeth=TLSv1_client_method();\n#endif\n\t\telse if (strcmp(*argv,"-bugs") == 0)\n\t\t\tbugs=1;\n\t\telse if\t(strcmp(*argv,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkey_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-reconnect") == 0)\n\t\t\t{\n\t\t\treconnect=5;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CApath") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCApath= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CAfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-no_tls1") == 0)\n\t\t\toff|=SSL_OP_NO_TLSv1;\n\t\telse if (strcmp(*argv,"-no_ssl3") == 0)\n\t\t\toff|=SSL_OP_NO_SSLv3;\n\t\telse if (strcmp(*argv,"-no_ssl2") == 0)\n\t\t\toff|=SSL_OP_NO_SSLv2;\n\t\telse if\t(strcmp(*argv,"-cipher") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcipher= *(++argv);\n\t\t\t}\n#ifdef FIONBIO\n\t\telse if (strcmp(*argv,"-nbio") == 0)\n\t\t\t{ c_nbio=1; }\n#endif\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadop=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badop)\n\t\t{\nbad:\n\t\tsc_usage();\n\t\tgoto end;\n\t\t}\n\tapp_RAND_load_file(NULL, bio_err, 0);\n\tif (bio_c_out == NULL)\n\t\t{\n\t\tif (c_quiet)\n\t\t\t{\n\t\t\tbio_c_out=BIO_new(BIO_s_null());\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bio_c_out == NULL)\n\t\t\t\tbio_c_out=BIO_new_fp(stdout,BIO_NOCLOSE);\n\t\t\t}\n\t\t}\n\tOpenSSL_add_ssl_algorithms();\n\tSSL_load_error_strings();\n\tctx=SSL_CTX_new(meth);\n\tif (ctx == NULL)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (bugs)\n\t\tSSL_CTX_set_options(ctx,SSL_OP_ALL|off);\n\telse\n\t\tSSL_CTX_set_options(ctx,off);\n\tif (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);\n\tif (cipher != NULL)\n\t\tif(!SSL_CTX_set_cipher_list(ctx,cipher)) {\n\t\tBIO_printf(bio_err,"error setting cipher list\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n#if 0\n\telse\n\t\tSSL_CTX_set_cipher_list(ctx,getenv("SSL_CIPHER"));\n#endif\n\tSSL_CTX_set_verify(ctx,verify,verify_callback);\n\tif (!set_cert_stuff(ctx,cert_file,key_file))\n\t\tgoto end;\n\tif ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||\n\t\t(!SSL_CTX_set_default_verify_paths(ctx)))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tcon=SSL_new(ctx);\nre_start:\n\tif (init_client(&s,host,port) == 0)\n\t\t{\n\t\tBIO_printf(bio_err,"connect:errno=%d\\n",get_last_socket_error());\n\t\tSHUTDOWN(s);\n\t\tgoto end;\n\t\t}\n\tBIO_printf(bio_c_out,"CONNECTED(%08X)\\n",s);\n#ifdef FIONBIO\n\tif (c_nbio)\n\t\t{\n\t\tunsigned long l=1;\n\t\tBIO_printf(bio_c_out,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&l) < 0)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n\tif (c_Pause & 0x01) con->debug=1;\n\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tif (c_debug)\n\t\t{\n\t\tcon->debug=1;\n\t\tBIO_set_callback(sbio,bio_dump_cb);\n\t\tBIO_set_callback_arg(sbio,bio_c_out);\n\t\t}\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_connect_state(con);\n\twidth=SSL_get_fd(con)+1;\n\tread_tty=1;\n\twrite_tty=0;\n\ttty_on=0;\n\tread_ssl=1;\n\twrite_ssl=1;\n\tcbuf_len=0;\n\tcbuf_off=0;\n\tsbuf_len=0;\n\tsbuf_off=0;\n\tfor (;;)\n\t\t{\n\t\tFD_ZERO(&readfds);\n\t\tFD_ZERO(&writefds);\n\t\tif (SSL_in_init(con) && !SSL_total_renegotiations(con))\n\t\t\t{\n\t\t\tin_init=1;\n\t\t\ttty_on=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttty_on=1;\n\t\t\tif (in_init)\n\t\t\t\t{\n\t\t\t\tin_init=0;\n\t\t\t\tprint_stuff(bio_c_out,con,full_log);\n\t\t\t\tif (full_log > 0) full_log--;\n\t\t\t\tif (reconnect)\n\t\t\t\t\t{\n\t\t\t\t\treconnect--;\n\t\t\t\t\tBIO_printf(bio_c_out,"drop connection and then reconnect\\n");\n\t\t\t\t\tSSL_shutdown(con);\n\t\t\t\t\tSSL_set_connect_state(con);\n\t\t\t\t\tSHUTDOWN(SSL_get_fd(con));\n\t\t\t\t\tgoto re_start;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tssl_pending = read_ssl && SSL_pending(con);\n\t\tif (!ssl_pending)\n\t\t\t{\n#ifndef WINDOWS\n\t\t\tif (tty_on)\n\t\t\t\t{\n\t\t\t\tif (read_tty) FD_SET(fileno(stdin),&readfds);\n\t\t\t\tif (write_tty) FD_SET(fileno(stdout),&writefds);\n\t\t\t\t}\n\t\t\tif (read_ssl)\n\t\t\t\tFD_SET(SSL_get_fd(con),&readfds);\n\t\t\tif (write_ssl)\n\t\t\t\tFD_SET(SSL_get_fd(con),&writefds);\n#else\n\t\t\tif(!tty_on || !write_tty) {\n\t\t\t\tif (read_ssl)\n\t\t\t\t\tFD_SET(SSL_get_fd(con),&readfds);\n\t\t\t\tif (write_ssl)\n\t\t\t\t\tFD_SET(SSL_get_fd(con),&writefds);\n\t\t\t}\n#endif\n#ifdef WINDOWS\n\t\t\tif(!write_tty) {\n\t\t\t\tif(read_tty) {\n\t\t\t\t\ttv.tv_sec = 1;\n\t\t\t\t\ttv.tv_usec = 0;\n\t\t\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t\t NULL,&tv);\n\t\t\t\t\tif(!i && (!_kbhit() || !read_tty) ) continue;\n\t\t\t\t} else \ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t NULL,NULL);\n\t\t\t}\n#else\n\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t NULL,NULL);\n#endif\n\t\t\tif ( i < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"bad select %d\\n",\n\t\t\t\tget_last_socket_error());\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n\t\tif (!ssl_pending && FD_ISSET(SSL_get_fd(con),&writefds))\n\t\t\t{\n\t\t\tk=SSL_write(con,&(cbuf[cbuf_off]),\n\t\t\t\t(unsigned int)cbuf_len);\n\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t{\n\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\tcbuf_off+=k;\n\t\t\t\tcbuf_len-=k;\n\t\t\t\tif (k <= 0) goto end;\n\t\t\t\tif (cbuf_len <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=0;\n\t\t\t\t\twrite_ssl=1;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tBIO_printf(bio_c_out,"write W BLOCK\\n");\n\t\t\t\twrite_ssl=1;\n\t\t\t\tread_tty=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tBIO_printf(bio_c_out,"write R BLOCK\\n");\n\t\t\t\twrite_tty=0;\n\t\t\t\tread_ssl=1;\n\t\t\t\twrite_ssl=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\tBIO_printf(bio_c_out,"write X BLOCK\\n");\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\tif (cbuf_len != 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_c_out,"shutdown\\n");\n\t\t\t\t\tgoto shut;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tif ((k != 0) || (cbuf_len != 0))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"write:errno=%d\\n",\n\t\t\t\t\t\tget_last_socket_error());\n\t\t\t\t\tgoto shut;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n#ifdef WINDOWS\n\t\telse if (!ssl_pending && write_tty)\n#else\n\t\telse if (!ssl_pending && FD_ISSET(fileno(stdout),&writefds))\n#endif\n\t\t\t{\n#ifdef CHARSET_EBCDIC\n\t\t\tascii2ebcdic(&(sbuf[sbuf_off]),&(sbuf[sbuf_off]),sbuf_len);\n#endif\n\t\t\ti=write(fileno(stdout),&(sbuf[sbuf_off]),sbuf_len);\n\t\t\tif (i <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_c_out,"DONE\\n");\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\tsbuf_len-=i;;\n\t\t\tsbuf_off+=i;\n\t\t\tif (sbuf_len <= 0)\n\t\t\t\t{\n\t\t\t\tread_ssl=1;\n\t\t\t\twrite_tty=0;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (ssl_pending || FD_ISSET(SSL_get_fd(con),&readfds))\n\t\t\t{\n#ifdef RENEG\n{ static int iiii; if (++iiii == 52) { SSL_renegotiate(con); iiii=0; } }\n#endif\n#if 1\n\t\t\tk=SSL_read(con,sbuf,1024 );\n#else\n\t\t\tk=SSL_read(con,sbuf,16);\n{ char zbuf[10240];\nprintf("read=%d pending=%d peek=%d\\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240));\n}\n#endif\n\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t{\n\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\tif (k <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\tsbuf_off=0;\n\t\t\t\tsbuf_len=k;\n\t\t\t\tread_ssl=0;\n\t\t\t\twrite_tty=1;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tBIO_printf(bio_c_out,"read W BLOCK\\n");\n\t\t\t\twrite_ssl=1;\n\t\t\t\tread_tty=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tBIO_printf(bio_c_out,"read R BLOCK\\n");\n\t\t\t\twrite_tty=0;\n\t\t\t\tread_ssl=1;\n\t\t\t\tif ((read_tty == 0) && (write_ssl == 0))\n\t\t\t\t\twrite_ssl=1;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\tBIO_printf(bio_c_out,"read X BLOCK\\n");\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tBIO_printf(bio_err,"read:errno=%d\\n",get_last_socket_error());\n\t\t\t\tgoto shut;\n\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\tBIO_printf(bio_c_out,"closed\\n");\n\t\t\t\tgoto shut;\n\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n#ifdef WINDOWS\n\t\telse if (_kbhit())\n#else\n\t\telse if (FD_ISSET(fileno(stdin),&readfds))\n#endif\n\t\t\t{\n\t\t\tif (crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=read(fileno(stdin),cbuf,BUFSIZZ/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (cbuf[j] == \'\\n\')\n\t\t\t\t\t\tlf_num++;\n\t\t\t\tfor (j = i-1; j >= 0; j--)\n\t\t\t\t\t{\n\t\t\t\t\tcbuf[j+lf_num] = cbuf[j];\n\t\t\t\t\tif (cbuf[j] == \'\\n\')\n\t\t\t\t\t\t{\n\t\t\t\t\t\tlf_num--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tcbuf[j+lf_num] = \'\\r\';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tassert(lf_num == 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ti=read(fileno(stdin),cbuf,BUFSIZZ);\n\t\t\tif ((!c_quiet) && ((i <= 0) || (cbuf[0] == \'Q\')))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"DONE\\n");\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\tif ((!c_quiet) && (cbuf[0] == \'R\'))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"RENEGOTIATING\\n");\n\t\t\t\tSSL_renegotiate(con);\n\t\t\t\tcbuf_len=0;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tcbuf_len=i;\n\t\t\t\tcbuf_off=0;\n#ifdef CHARSET_EBCDIC\n\t\t\t\tebcdic2ascii(cbuf, cbuf, i);\n#endif\n\t\t\t\t}\n\t\t\twrite_ssl=1;\n\t\t\tread_tty=0;\n\t\t\t}\n\t\t}\nshut:\n\tSSL_shutdown(con);\n\tSHUTDOWN(SSL_get_fd(con));\n\tret=0;\nend:\n\tif(prexit) print_stuff(bio_c_out,con,1);\n\tif (con != NULL) SSL_free(con);\n\tif (con2 != NULL) SSL_free(con2);\n\tif (ctx != NULL) SSL_CTX_free(ctx);\n\tif (cbuf != NULL) { memset(cbuf,0,BUFSIZZ); Free(cbuf); }\n\tif (sbuf != NULL) { memset(sbuf,0,BUFSIZZ); Free(sbuf); }\n\tif (bio_c_out != NULL)\n\t\t{\n\t\tBIO_free(bio_c_out);\n\t\tbio_c_out=NULL;\n\t\t}\n\tEXIT(ret);\n\t}', 'SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)\n\t{\n\tSSL_CTX *ret=NULL;\n\tif (meth == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);\n\t\treturn(NULL);\n\t\t}\n\tif (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n\t\tgoto err;\n\t\t}\n\tret=(SSL_CTX *)Malloc(sizeof(SSL_CTX));\n\tif (ret == NULL)\n\t\tgoto err;\n\tmemset(ret,0,sizeof(SSL_CTX));\n\tret->method=meth;\n\tret->cert_store=NULL;\n\tret->session_cache_mode=SSL_SESS_CACHE_SERVER;\n\tret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n\tret->session_cache_head=NULL;\n\tret->session_cache_tail=NULL;\n\tret->session_timeout=meth->get_timeout();\n\tret->new_session_cb=NULL;\n\tret->remove_session_cb=NULL;\n\tret->get_session_cb=NULL;\n\tmemset((char *)&ret->stats,0,sizeof(ret->stats));\n\tret->references=1;\n\tret->quiet_shutdown=0;\n\tret->info_callback=NULL;\n\tret->app_verify_callback=NULL;\n\tret->app_verify_arg=NULL;\n\tret->read_ahead=0;\n\tret->verify_mode=SSL_VERIFY_NONE;\n\tret->verify_depth=-1;\n\tret->default_verify_callback=NULL;\n\tif ((ret->cert=ssl_cert_new()) == NULL)\n\t\tgoto err;\n\tret->default_passwd_callback=NULL;\n\tret->default_passwd_callback_userdata=NULL;\n\tret->client_cert_cb=NULL;\n\tret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp);\n\tif (ret->sessions == NULL) goto err;\n\tret->cert_store=X509_STORE_new();\n\tif (ret->cert_store == NULL) goto err;\n\tssl_create_cipher_list(ret->method,\n\t\t&ret->cipher_list,&ret->cipher_list_by_id,\n\t\tSSL_DEFAULT_CIPHER_LIST);\n\tif (ret->cipher_list == NULL\n\t || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n\t\tgoto err2;\n\t\t}\n\tif ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)\n\t\tgoto err;\n\tCRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);\n\tret->extra_certs=NULL;\n\tret->comp_methods=SSL_COMP_get_compression_methods();\n\treturn(ret);\nerr:\n\tSSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);\nerr2:\n\tif (ret != NULL) SSL_CTX_free(ret);\n\treturn(NULL);\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(ret);\nerr0:\n\treturn(NULL);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)Malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_mode=ctx->verify_mode;\n\ts->verify_depth=ctx->verify_depth;\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tFree(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tint state;\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->new_session) return(1);\n#endif\n\tstate=s->state;\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n\ts->read_ahead=s->ctx->read_ahead;\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->first_packet=0;\n#if 1\n\tif ((s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tr=(SSL_SESSION *)lh_delete(ctx->sessions,c);\n\t\tif (r != NULL)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(LHASH *lh, 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}']
|
920
| 0
|
https://github.com/libav/libav/blob/41874d0a5df35732367f0c675eac914c23d65aee/ffmpeg.c/#L3569
|
static void new_subtitle_stream(AVFormatContext *oc)
{
AVStream *st;
AVCodecContext *subtitle_enc;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
av_exit(1);
}
avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_SUBTITLE);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters;
subtitle_bitstream_filters= NULL;
subtitle_enc = st->codec;
subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
if(subtitle_codec_tag)
subtitle_enc->codec_tag= subtitle_codec_tag;
if (subtitle_stream_copy) {
st->stream_copy = 1;
} else {
set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,
subtitle_enc->strict_std_compliance);
output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);
}
nb_ocodecs++;
if (subtitle_language) {
av_metadata_set2(&st->metadata, "language", subtitle_language, 0);
av_freep(&subtitle_language);
}
subtitle_disable = 0;
av_freep(&subtitle_codec_name);
subtitle_stream_copy = 0;
}
|
['static void new_subtitle_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *subtitle_enc;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_SUBTITLE);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters;\n subtitle_bitstream_filters= NULL;\n subtitle_enc = st->codec;\n subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n if(subtitle_codec_tag)\n subtitle_enc->codec_tag= subtitle_codec_tag;\n if (subtitle_stream_copy) {\n st->stream_copy = 1;\n } else {\n set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,\n subtitle_enc->strict_std_compliance);\n output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);\n }\n nb_ocodecs++;\n if (subtitle_language) {\n av_metadata_set2(&st->metadata, "language", subtitle_language, 0);\n av_freep(&subtitle_language);\n }\n subtitle_disable = 0;\n av_freep(&subtitle_codec_name);\n subtitle_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS){\n av_log(s, AV_LOG_ERROR, "Too many streams\\n");\n return NULL;\n }\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n 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}']
|
921
| 0
|
https://github.com/openssl/openssl/blob/f38edcab594b4934bd9625ef889934b2dfb5d1f0/crypto/bn/bn_lib.c/#L291
|
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
bn_check_top(b);
if (a == b)
return a;
if (bn_wexpand(a, b->top) == NULL)
return NULL;
if (b->top > 0)
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
a->neg = b->neg;
a->top = b->top;
a->flags |= b->flags & BN_FLG_FIXED_TOP;
bn_check_top(a);
return a;
}
|
['static ECDSA_SIG *sm2_sig_gen(const EC_KEY *key, const BIGNUM *e)\n{\n const BIGNUM *dA = EC_KEY_get0_private_key(key);\n const EC_GROUP *group = EC_KEY_get0_group(key);\n const BIGNUM *order = EC_GROUP_get0_order(group);\n ECDSA_SIG *sig = NULL;\n EC_POINT *kG = NULL;\n BN_CTX *ctx = NULL;\n BIGNUM *k = NULL;\n BIGNUM *rk = NULL;\n BIGNUM *r = NULL;\n BIGNUM *s = NULL;\n BIGNUM *x1 = NULL;\n BIGNUM *tmp = NULL;\n kG = EC_POINT_new(group);\n ctx = BN_CTX_new();\n if (kG == NULL || ctx == NULL) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n BN_CTX_start(ctx);\n k = BN_CTX_get(ctx);\n rk = BN_CTX_get(ctx);\n x1 = BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n r = BN_new();\n s = BN_new();\n if (r == NULL || s == NULL) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n for (;;) {\n if (!BN_priv_rand_range(k, order)) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_INTERNAL_ERROR);\n goto done;\n }\n if (!EC_POINT_mul(group, kG, k, NULL, NULL, ctx)\n || !EC_POINT_get_affine_coordinates(group, kG, x1, NULL,\n ctx)\n || !BN_mod_add(r, e, x1, order, ctx)) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_INTERNAL_ERROR);\n goto done;\n }\n if (BN_is_zero(r))\n continue;\n if (!BN_add(rk, r, k)) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_INTERNAL_ERROR);\n goto done;\n }\n if (BN_cmp(rk, order) == 0)\n continue;\n if (!BN_add(s, dA, BN_value_one())\n || !ec_group_do_inverse_ord(group, s, s, ctx)\n || !BN_mod_mul(tmp, dA, r, order, ctx)\n || !BN_sub(tmp, k, tmp)\n || !BN_mod_mul(s, s, tmp, order, ctx)) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_BN_LIB);\n goto done;\n }\n sig = ECDSA_SIG_new();\n if (sig == NULL) {\n SM2err(SM2_F_SM2_SIG_GEN, ERR_R_MALLOC_FAILURE);\n goto done;\n }\n ECDSA_SIG_set0(sig, r, s);\n break;\n }\n done:\n if (sig == NULL) {\n BN_free(r);\n BN_free(s);\n }\n BN_CTX_free(ctx);\n EC_POINT_free(kG);\n return sig;\n}', 'int BN_priv_rand_range(BIGNUM *r, const BIGNUM *range)\n{\n return bnrand_range(PRIVATE, r, range);\n}', 'static int bnrand_range(BNRAND_FLAG flag, BIGNUM *r, const BIGNUM *range)\n{\n int n;\n int count = 100;\n if (range->neg || BN_is_zero(range)) {\n BNerr(BN_F_BNRAND_RANGE, BN_R_INVALID_RANGE);\n return 0;\n }\n n = BN_num_bits(range);\n if (n == 1)\n BN_zero(r);\n else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {\n do {\n if (!bnrand(flag, r, n + 1, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n return 0;\n if (BN_cmp(r, range) >= 0) {\n if (!BN_sub(r, r, range))\n return 0;\n if (BN_cmp(r, range) >= 0)\n if (!BN_sub(r, r, range))\n return 0;\n }\n if (!--count) {\n BNerr(BN_F_BNRAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n } else {\n do {\n if (!bnrand(flag, r, n, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY))\n return 0;\n if (!--count) {\n BNerr(BN_F_BNRAND_RANGE, BN_R_TOO_MANY_ITERATIONS);\n return 0;\n }\n }\n while (BN_cmp(r, range) >= 0);\n }\n bn_check_top(r);\n return 1;\n}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n int ret = 0;\n size_t i = 0;\n BN_CTX *new_ctx = NULL;\n if ((scalar == NULL) && (num == 0)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n if (!ec_point_is_compat(r, group)) {\n ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n for (i = 0; i < num; i++) {\n if (!ec_point_is_compat(points[i], group)) {\n ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL) {\n ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n if (group->meth->mul != NULL)\n ret = group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n else\n ret = ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n const EC_POINT *generator = NULL;\n EC_POINT *tmp = NULL;\n size_t totalnum;\n size_t blocksize = 0, numblocks = 0;\n size_t pre_points_per_block = 0;\n size_t i, j;\n int k;\n int r_is_inverted = 0;\n int r_is_at_infinity = 1;\n size_t *wsize = NULL;\n signed char **wNAF = NULL;\n size_t *wNAF_len = NULL;\n size_t max_len = 0;\n size_t num_val;\n EC_POINT **val = NULL;\n EC_POINT **v;\n EC_POINT ***val_sub = NULL;\n const EC_PRE_COMP *pre_comp = NULL;\n int num_scalar = 0;\n int ret = 0;\n if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) {\n if ((scalar != NULL) && (num == 0)) {\n return ec_scalar_mul_ladder(group, r, scalar, NULL, ctx);\n }\n if ((scalar == NULL) && (num == 1)) {\n return ec_scalar_mul_ladder(group, r, scalars[0], points[0], ctx);\n }\n }\n if (scalar != NULL) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.ec;\n if (pre_comp && pre_comp->numblocks\n && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n 0)) {\n blocksize = pre_comp->blocksize;\n numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n if (numblocks > pre_comp->numblocks)\n numblocks = pre_comp->numblocks;\n pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n pre_comp = NULL;\n numblocks = 1;\n num_scalar = 1;\n }\n }\n totalnum = num + numblocks;\n wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));\n wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));\n wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));\n val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));\n if (wNAF != NULL)\n wNAF[0] = NULL;\n if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n num_val = 0;\n for (i = 0; i < num + num_scalar; i++) {\n size_t bits;\n bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n wsize[i] = EC_window_bits_for_scalar_size(bits);\n num_val += (size_t)1 << (wsize[i] - 1);\n wNAF[i + 1] = NULL;\n wNAF[i] =\n bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n &wNAF_len[i]);\n if (wNAF[i] == NULL)\n goto err;\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n }\n if (numblocks) {\n if (pre_comp == NULL) {\n if (num_scalar != 1) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n signed char *tmp_wNAF = NULL;\n size_t tmp_len = 0;\n if (num_scalar != 0) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n wsize[num] = pre_comp->w;\n tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n if (!tmp_wNAF)\n goto err;\n if (tmp_len <= max_len) {\n numblocks = 1;\n totalnum = num + 1;\n wNAF[num] = tmp_wNAF;\n wNAF[num + 1] = NULL;\n wNAF_len[num] = tmp_len;\n val_sub[num] = pre_comp->points;\n } else {\n signed char *pp;\n EC_POINT **tmp_points;\n if (tmp_len < numblocks * blocksize) {\n numblocks = (tmp_len + blocksize - 1) / blocksize;\n if (numblocks > pre_comp->numblocks) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n totalnum = num + numblocks;\n }\n pp = tmp_wNAF;\n tmp_points = pre_comp->points;\n for (i = num; i < totalnum; i++) {\n if (i < totalnum - 1) {\n wNAF_len[i] = blocksize;\n if (tmp_len < blocksize) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n tmp_len -= blocksize;\n } else\n wNAF_len[i] = tmp_len;\n wNAF[i + 1] = NULL;\n wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n if (wNAF[i] == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n memcpy(wNAF[i], pp, wNAF_len[i]);\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n if (*tmp_points == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n val_sub[i] = tmp_points;\n tmp_points += pre_points_per_block;\n pp += blocksize;\n }\n OPENSSL_free(tmp_wNAF);\n }\n }\n }\n val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));\n if (val == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n val[num_val] = NULL;\n v = val;\n for (i = 0; i < num + num_scalar; i++) {\n val_sub[i] = v;\n for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n *v = EC_POINT_new(group);\n if (*v == NULL)\n goto err;\n v++;\n }\n }\n if (!(v == val + num_val)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if ((tmp = EC_POINT_new(group)) == NULL)\n goto err;\n for (i = 0; i < num + num_scalar; i++) {\n if (i < num) {\n if (!EC_POINT_copy(val_sub[i][0], points[i]))\n goto err;\n } else {\n if (!EC_POINT_copy(val_sub[i][0], generator))\n goto err;\n }\n if (wsize[i] > 1) {\n if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n goto err;\n for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n if (!EC_POINT_add\n (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n goto err;\n }\n }\n }\n if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n goto err;\n r_is_at_infinity = 1;\n for (k = max_len - 1; k >= 0; k--) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n }\n for (i = 0; i < totalnum; i++) {\n if (wNAF_len[i] > (size_t)k) {\n int digit = wNAF[i][k];\n int is_neg;\n if (digit) {\n is_neg = digit < 0;\n if (is_neg)\n digit = -digit;\n if (is_neg != r_is_inverted) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n r_is_inverted = !r_is_inverted;\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n goto err;\n r_is_at_infinity = 0;\n } else {\n if (!EC_POINT_add\n (group, r, r, val_sub[i][digit >> 1], ctx))\n goto err;\n }\n }\n }\n }\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (r_is_inverted)\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n ret = 1;\n err:\n EC_POINT_free(tmp);\n OPENSSL_free(wsize);\n OPENSSL_free(wNAF_len);\n if (wNAF != NULL) {\n signed char **w;\n for (w = wNAF; *w != NULL; w++)\n OPENSSL_free(*w);\n OPENSSL_free(wNAF);\n }\n if (val != NULL) {\n for (v = val; *v != NULL; v++)\n EC_POINT_clear_free(*v);\n OPENSSL_free(val);\n }\n OPENSSL_free(val_sub);\n return ret;\n}', 'int ec_scalar_mul_ladder(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int i, cardinality_bits, group_top, kbit, pbit, Z_is_one;\n EC_POINT *p = NULL;\n EC_POINT *s = NULL;\n BIGNUM *k = NULL;\n BIGNUM *lambda = NULL;\n BIGNUM *cardinality = NULL;\n int ret = 0;\n if (point != NULL && EC_POINT_is_at_infinity(group, point))\n return EC_POINT_set_to_infinity(group, r);\n if (BN_is_zero(group->order)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_ORDER);\n return 0;\n }\n if (BN_is_zero(group->cofactor)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_UNKNOWN_COFACTOR);\n return 0;\n }\n BN_CTX_start(ctx);\n if (((p = EC_POINT_new(group)) == NULL)\n || ((s = EC_POINT_new(group)) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (point == NULL) {\n if (!EC_POINT_copy(p, group->generator)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);\n goto err;\n }\n } else {\n if (!EC_POINT_copy(p, point)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_EC_LIB);\n goto err;\n }\n }\n EC_POINT_BN_set_flags(p, BN_FLG_CONSTTIME);\n EC_POINT_BN_set_flags(r, BN_FLG_CONSTTIME);\n EC_POINT_BN_set_flags(s, BN_FLG_CONSTTIME);\n cardinality = BN_CTX_get(ctx);\n lambda = BN_CTX_get(ctx);\n k = BN_CTX_get(ctx);\n if (k == NULL) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if (!BN_mul(cardinality, group->order, group->cofactor, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n cardinality_bits = BN_num_bits(cardinality);\n group_top = bn_get_top(cardinality);\n if ((bn_wexpand(k, group_top + 1) == NULL)\n || (bn_wexpand(lambda, group_top + 1) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n if (!BN_copy(k, scalar)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if ((BN_num_bits(k) > cardinality_bits) || (BN_is_negative(k))) {\n if (!BN_nnmod(k, k, cardinality, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n }\n if (!BN_add(lambda, k, cardinality)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n BN_set_flags(lambda, BN_FLG_CONSTTIME);\n if (!BN_add(k, lambda, cardinality)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n kbit = BN_is_bit_set(lambda, cardinality_bits);\n BN_consttime_swap(kbit, k, lambda, group_top + 1);\n group_top = bn_get_top(group->field);\n if ((bn_wexpand(s->X, group_top) == NULL)\n || (bn_wexpand(s->Y, group_top) == NULL)\n || (bn_wexpand(s->Z, group_top) == NULL)\n || (bn_wexpand(r->X, group_top) == NULL)\n || (bn_wexpand(r->Y, group_top) == NULL)\n || (bn_wexpand(r->Z, group_top) == NULL)\n || (bn_wexpand(p->X, group_top) == NULL)\n || (bn_wexpand(p->Y, group_top) == NULL)\n || (bn_wexpand(p->Z, group_top) == NULL)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, ERR_R_BN_LIB);\n goto err;\n }\n if (!ec_point_blind_coordinates(group, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_POINT_COORDINATES_BLIND_FAILURE);\n goto err;\n }\n if (!ec_point_ladder_pre(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_PRE_FAILURE);\n goto err;\n }\n pbit = 1;\n#define EC_POINT_CSWAP(c, a, b, w, t) do { \\\n BN_consttime_swap(c, (a)->X, (b)->X, w); \\\n BN_consttime_swap(c, (a)->Y, (b)->Y, w); \\\n BN_consttime_swap(c, (a)->Z, (b)->Z, w); \\\n t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \\\n (a)->Z_is_one ^= (t); \\\n (b)->Z_is_one ^= (t); \\\n} while(0)\n for (i = cardinality_bits - 1; i >= 0; i--) {\n kbit = BN_is_bit_set(k, i) ^ pbit;\n EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);\n if (!ec_point_ladder_step(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_STEP_FAILURE);\n goto err;\n }\n pbit ^= kbit;\n }\n EC_POINT_CSWAP(pbit, r, s, group_top, Z_is_one);\n#undef EC_POINT_CSWAP\n if (!ec_point_ladder_post(group, r, s, p, ctx)) {\n ECerr(EC_F_EC_SCALAR_MUL_LADDER, EC_R_LADDER_POST_FAILURE);\n goto err;\n }\n ret = 1;\n err:\n EC_POINT_free(p);\n EC_POINT_free(s);\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
922
| 0
|
https://github.com/libav/libav/blob/47399ccdfd93d337c96c76fbf591f0e3637131ef/libavcodec/bitstream.h/#L236
|
static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
bc->bits >>= n;
#else
bc->bits <<= n;
#endif
bc->bits_left -= n;
}
|
['static int read_block_data(MLPDecodeContext *m, BitstreamContext *bc,\n unsigned int substr)\n{\n SubStream *s = &m->substream[substr];\n unsigned int i, ch, expected_stream_pos = 0;\n int ret;\n if (s->data_check_present) {\n expected_stream_pos = bitstream_tell(bc);\n expected_stream_pos += bitstream_read(bc, 16);\n avpriv_request_sample(m->avctx,\n "Substreams with VLC block size check info");\n }\n if (s->blockpos + s->blocksize > m->access_unit_size) {\n av_log(m->avctx, AV_LOG_ERROR, "too many audio samples in frame\\n");\n return AVERROR_INVALIDDATA;\n }\n memset(&m->bypassed_lsbs[s->blockpos][0], 0,\n s->blocksize * sizeof(m->bypassed_lsbs[0]));\n for (i = 0; i < s->blocksize; i++)\n if ((ret = read_huff_channels(m, bc, substr, i)) < 0)\n return ret;\n for (ch = s->min_channel; ch <= s->max_channel; ch++)\n filter_channel(m, substr, ch);\n s->blockpos += s->blocksize;\n if (s->data_check_present) {\n if (bitstream_tell(bc) != expected_stream_pos)\n av_log(m->avctx, AV_LOG_ERROR, "block data length mismatch\\n");\n bitstream_skip(bc, 8);\n }\n return 0;\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n if (n < bc->bits_left)\n skip_remaining(bc, n);\n else {\n n -= bc->bits_left;\n bc->bits = 0;\n bc->bits_left = 0;\n if (n >= 64) {\n unsigned skip = n / 8;\n n -= skip * 8;\n bc->ptr += skip;\n }\n refill_64(bc);\n if (n)\n skip_remaining(bc, n);\n }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n bc->bits >>= n;\n#else\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n}']
|
923
| 0
|
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,\n const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)\n{\n BIGNUM *t;\n int found = 0;\n int i, j, c1 = 0;\n BN_CTX *ctx = NULL;\n prime_t *mods = NULL;\n int checks = BN_prime_checks_for_size(bits);\n if (bits < 2) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n } else if (bits == 2 && safe) {\n BNerr(BN_F_BN_GENERATE_PRIME_EX, BN_R_BITS_TOO_SMALL);\n return 0;\n }\n mods = OPENSSL_zalloc(sizeof(*mods) * NUMPRIMES);\n if (mods == NULL)\n goto err;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n loop:\n if (add == NULL) {\n if (!probable_prime(ret, bits, mods))\n goto err;\n } else {\n if (safe) {\n if (!probable_prime_dh_safe(ret, bits, add, rem, ctx))\n goto err;\n } else {\n if (!bn_probable_prime_dh(ret, bits, add, rem, ctx))\n goto err;\n }\n }\n if (!BN_GENCB_call(cb, 0, c1++))\n goto err;\n if (!safe) {\n i = BN_is_prime_fasttest_ex(ret, checks, ctx, 0, cb);\n if (i == -1)\n goto err;\n if (i == 0)\n goto loop;\n } else {\n if (!BN_rshift1(t, ret))\n goto err;\n for (i = 0; i < checks; i++) {\n j = BN_is_prime_fasttest_ex(ret, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n j = BN_is_prime_fasttest_ex(t, 1, ctx, 0, cb);\n if (j == -1)\n goto err;\n if (j == 0)\n goto loop;\n if (!BN_GENCB_call(cb, 2, c1 - 1))\n goto err;\n }\n }\n found = 1;\n err:\n OPENSSL_free(mods);\n if (ctx != NULL)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n bn_check_top(ret);\n return found;\n}', 'static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,\n const BIGNUM *rem, BN_CTX *ctx)\n{\n int i, ret = 0;\n BIGNUM *t1, *qadd, *q;\n bits--;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n qadd = BN_CTX_get(ctx);\n if (qadd == NULL)\n goto err;\n if (!BN_rshift1(qadd, padd))\n goto err;\n if (!BN_priv_rand(q, bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ODD))\n goto err;\n if (!BN_mod(t1, q, qadd, ctx))\n goto err;\n if (!BN_sub(q, q, t1))\n goto err;\n if (rem == NULL) {\n if (!BN_add_word(q, 1))\n goto err;\n } else {\n if (!BN_rshift1(t1, rem))\n goto err;\n if (!BN_add(q, q, t1))\n goto err;\n }\n if (!BN_lshift1(p, q))\n goto err;\n if (!BN_add_word(p, 1))\n goto err;\n loop:\n for (i = 1; i < NUMPRIMES; i++) {\n BN_ULONG pmod = BN_mod_word(p, (BN_ULONG)primes[i]);\n BN_ULONG qmod = BN_mod_word(q, (BN_ULONG)primes[i]);\n if (pmod == (BN_ULONG)-1 || qmod == (BN_ULONG)-1)\n goto err;\n if (pmod == 0 || qmod == 0) {\n if (!BN_add(p, p, padd))\n goto err;\n if (!BN_add(q, q, qadd))\n goto err;\n goto loop;\n }\n }\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(p);\n return (ret);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return (0);\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return (0);\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return (0);\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n BN_ULONG *ap, *rp, t, c;\n int i, j;\n bn_check_top(r);\n bn_check_top(a);\n if (BN_is_zero(a)) {\n BN_zero(r);\n return 1;\n }\n i = a->top;\n ap = a->d;\n j = i - (ap[i - 1] == 1);\n if (a != r) {\n if (bn_wexpand(r, j) == NULL)\n return (0);\n r->neg = a->neg;\n }\n rp = r->d;\n t = ap[--i];\n c = (t & 1) ? BN_TBIT : 0;\n if (t >>= 1)\n rp[i] = t;\n while (i > 0) {\n t = ap[--i];\n rp[i] = ((t >> 1) & BN_MASK2) | c;\n c = (t & 1) ? BN_TBIT : 0;\n }\n r->top = j;\n if (!r->top)\n r->neg = 0;\n bn_check_top(r);\n return 1;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
924
| 0
|
https://github.com/openssl/openssl/blob/c3be39f2e47ec6c538ef1060d35dbee5c286ea4f/crypto/x509v3/v3_purp.c/#L92
|
int X509_check_purpose(X509 *x, int id, int ca)
{
int idx;
const X509_PURPOSE *pt;
x509v3_cache_extensions(x);
if (id == -1)
return 1;
idx = X509_PURPOSE_get_by_id(id);
if (idx == -1)
return -1;
pt = X509_PURPOSE_get0(idx);
return pt->check_purpose(pt, x, ca);
}
|
['int X509_check_purpose(X509 *x, int id, int ca)\n{\n int idx;\n const X509_PURPOSE *pt;\n x509v3_cache_extensions(x);\n if (id == -1)\n return 1;\n idx = X509_PURPOSE_get_by_id(id);\n if (idx == -1)\n return -1;\n pt = X509_PURPOSE_get0(idx);\n return pt->check_purpose(pt, x, ca);\n}', 'int X509_PURPOSE_get_by_id(int purpose)\n{\n X509_PURPOSE tmp;\n int idx;\n if ((purpose >= X509_PURPOSE_MIN) && (purpose <= X509_PURPOSE_MAX))\n return purpose - X509_PURPOSE_MIN;\n if (xptable == NULL)\n return -1;\n tmp.purpose = purpose;\n idx = sk_X509_PURPOSE_find(xptable, &tmp);\n if (idx < 0)\n return -1;\n return idx + X509_PURPOSE_COUNT;\n}', 'DEFINE_STACK_OF(X509_PURPOSE)', 'int OPENSSL_sk_find(OPENSSL_STACK *st, const void *data)\n{\n return internal_find(st, data, OSSL_BSEARCH_FIRST_VALUE_ON_MATCH);\n}', 'static int internal_find(OPENSSL_STACK *st, const void *data,\n int ret_val_options)\n{\n const void *r;\n int i;\n if (st == NULL || st->num == 0)\n return -1;\n if (st->comp == NULL) {\n for (i = 0; i < st->num; i++)\n if (st->data[i] == data)\n return i;\n return -1;\n }\n if (!st->sorted) {\n if (st->num > 1)\n qsort(st->data, st->num, sizeof(void *), st->comp);\n st->sorted = 1;\n }\n if (data == NULL)\n return -1;\n r = ossl_bsearch(&data, st->data, st->num, sizeof(void *), st->comp,\n ret_val_options);\n return r == NULL ? -1 : (int)((const void **)r - st->data);\n}', 'X509_PURPOSE *X509_PURPOSE_get0(int idx)\n{\n if (idx < 0)\n return NULL;\n if (idx < (int)X509_PURPOSE_COUNT)\n return xstandard + idx;\n return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);\n}']
|
925
| 0
|
https://github.com/openssl/openssl/blob/9ae08a9c04280d72fb7e4e4977ebd73a843d7f69/crypto/engine/hw_4758_cca.c/#L748
|
static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
unsigned char *sigret, unsigned int *siglen, const RSA *rsa)
{
long returnCode;
long reasonCode;
long exitDataLength = 0;
unsigned char exitData[8];
long ruleArrayLength = 1;
unsigned char ruleArray[8] = "PKCS-1.1";
long outputLength=256;
long outputBitLength;
long keyTokenLength;
unsigned char *hashBuffer = NULL;
unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
long length = SSL_SIG_LEN;
long keyLength ;
X509_SIG sig;
ASN1_TYPE parameter;
X509_ALGOR algorithm;
ASN1_OCTET_STRING digest;
keyTokenLength = *(long*)keyToken;
keyToken+=sizeof(long);
if (type == NID_md5 || type == NID_sha1)
{
sig.algor = &algorithm;
algorithm.algorithm = OBJ_nid2obj(type);
if (!algorithm.algorithm)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
return 0;
}
if (!algorithm.algorithm->length)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
return 0;
}
parameter.type = V_ASN1_NULL;
parameter.value.ptr = NULL;
algorithm.parameter = ¶meter;
sig.digest = &digest;
sig.digest->data = (unsigned char*)m;
sig.digest->length = m_len;
length = i2d_X509_SIG(&sig, NULL);
}
keyLength = RSA_size(rsa);
if (length - RSA_PKCS1_PADDING > keyLength)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return 0;
}
switch (type)
{
case NID_md5_sha1 :
if (m_len != SSL_SIG_LEN)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
return 0;
}
hashBuffer = (unsigned char*)m;
length = m_len;
break;
case NID_md5 :
{
unsigned char *ptr;
ptr = hashBuffer = OPENSSL_malloc(
(unsigned int)keyLength+1);
if (!hashBuffer)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
ERR_R_MALLOC_FAILURE);
return 0;
}
i2d_X509_SIG(&sig, &ptr);
}
break;
case NID_sha1 :
{
unsigned char *ptr;
ptr = hashBuffer = OPENSSL_malloc(
(unsigned int)keyLength+1);
if (!hashBuffer)
{
CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
ERR_R_MALLOC_FAILURE);
return 0;
}
i2d_X509_SIG(&sig, &ptr);
}
break;
default:
return 0;
}
digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,
exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
keyToken, &length, hashBuffer, &outputLength, &outputBitLength,
sigret);
if (type == NID_sha1 || type == NID_md5)
{
memset(hashBuffer, keyLength+1, 0);
OPENSSL_free(hashBuffer);
}
*siglen = outputLength;
return ((returnCode || reasonCode) ? 0 : 1);
}
|
['static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,\n\t\tunsigned char *sigret, unsigned int *siglen, const RSA *rsa)\n\t{\n\tlong returnCode;\n\tlong reasonCode;\n\tlong exitDataLength = 0;\n\tunsigned char exitData[8];\n\tlong ruleArrayLength = 1;\n\tunsigned char ruleArray[8] = "PKCS-1.1";\n\tlong outputLength=256;\n\tlong outputBitLength;\n\tlong keyTokenLength;\n\tunsigned char *hashBuffer = NULL;\n\tunsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);\n\tlong length = SSL_SIG_LEN;\n\tlong keyLength ;\n\tX509_SIG sig;\n\tASN1_TYPE parameter;\n\tX509_ALGOR algorithm;\n\tASN1_OCTET_STRING digest;\n\tkeyTokenLength = *(long*)keyToken;\n\tkeyToken+=sizeof(long);\n\tif (type == NID_md5 || type == NID_sha1)\n\t\t{\n\t\tsig.algor = &algorithm;\n\t\talgorithm.algorithm = OBJ_nid2obj(type);\n\t\tif (!algorithm.algorithm)\n\t\t\t{\n\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\t\tCCA4758_R_UNKNOWN_ALGORITHM_TYPE);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif (!algorithm.algorithm->length)\n\t\t\t{\n\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\t\tCCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);\n\t\t\treturn 0;\n\t\t\t}\n\t\tparameter.type = V_ASN1_NULL;\n\t\tparameter.value.ptr = NULL;\n\t\talgorithm.parameter = ¶meter;\n\t\tsig.digest = &digest;\n\t\tsig.digest->data = (unsigned char*)m;\n\t\tsig.digest->length = m_len;\n\t\tlength = i2d_X509_SIG(&sig, NULL);\n\t\t}\n\tkeyLength = RSA_size(rsa);\n\tif (length - RSA_PKCS1_PADDING > keyLength)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\tCCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n\t\treturn 0;\n\t\t}\n\tswitch (type)\n\t\t{\n\t\tcase NID_md5_sha1 :\n\t\t\tif (m_len != SSL_SIG_LEN)\n\t\t\t\t{\n\t\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,\n\t\t\t\tCCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\thashBuffer = (unsigned char*)m;\n\t\t\tlength = m_len;\n\t\t\tbreak;\n\t\tcase NID_md5 :\n\t\t\t{\n\t\t\tunsigned char *ptr;\n\t\t\tptr = hashBuffer = OPENSSL_malloc(\n\t\t\t\t\t(unsigned int)keyLength+1);\n\t\t\tif (!hashBuffer)\n\t\t\t\t{\n\t\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,\n\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\ti2d_X509_SIG(&sig, &ptr);\n\t\t\t}\n\t\t\tbreak;\n\t\tcase NID_sha1 :\n\t\t\t{\n\t\t\tunsigned char *ptr;\n\t\t\tptr = hashBuffer = OPENSSL_malloc(\n\t\t\t\t\t(unsigned int)keyLength+1);\n\t\t\tif (!hashBuffer)\n\t\t\t\t{\n\t\t\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,\n\t\t\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\ti2d_X509_SIG(&sig, &ptr);\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\treturn 0;\n\t\t}\n\tdigitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,\n\t\texitData, &ruleArrayLength, ruleArray, &keyTokenLength,\n\t\tkeyToken, &length, hashBuffer, &outputLength, &outputBitLength,\n\t\tsigret);\n\tif (type == NID_sha1 || type == NID_md5)\n\t\t{\n\t\tmemset(hashBuffer, keyLength+1, 0);\n\t\tOPENSSL_free(hashBuffer);\n\t\t}\n\t*siglen = outputLength;\n\treturn ((returnCode || reasonCode) ? 0 : 1);\n\t}', 'void *RSA_get_ex_data(const RSA *r, int idx)\n\t{\n\treturn(CRYPTO_get_ex_data(&r->ex_data,idx));\n\t}', 'void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx)\n\t{\n\tif (ad->sk == NULL)\n\t\treturn(0);\n\telse if (idx >= sk_num(ad->sk))\n\t\treturn(0);\n\telse\n\t\treturn(sk_value(ad->sk,idx));\n\t}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}']
|
926
| 0
|
https://github.com/openssl/openssl/blob/f345b1f39d9b4e4c9ef07e7522e9b2a870c9ca09/crypto/bn/bn_lib.c/#L233
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = p->top * BN_BITS2;\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n#ifdef RSAZ_ENABLED\n if (!a->neg) {\n if ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_nnmod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top,\n unsigned char *buf, int idx,\n int window)\n{\n int i, j;\n int width = 1 << window;\n volatile BN_ULONG *table = (volatile BN_ULONG *)buf;\n if (bn_wexpand(b, top) == NULL)\n return 0;\n if (window <= 3) {\n for (i = 0; i < top; i++, table += width) {\n BN_ULONG acc = 0;\n for (j = 0; j < width; j++) {\n acc |= table[j] &\n ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));\n }\n b->d[i] = acc;\n }\n } else {\n int xstride = 1 << (window - 2);\n BN_ULONG y0, y1, y2, y3;\n i = idx >> (window - 2);\n idx &= xstride - 1;\n y0 = (BN_ULONG)0 - (constant_time_eq_int(i,0)&1);\n y1 = (BN_ULONG)0 - (constant_time_eq_int(i,1)&1);\n y2 = (BN_ULONG)0 - (constant_time_eq_int(i,2)&1);\n y3 = (BN_ULONG)0 - (constant_time_eq_int(i,3)&1);\n for (i = 0; i < top; i++, table += width) {\n BN_ULONG acc = 0;\n for (j = 0; j < xstride; j++) {\n acc |= ( (table[j + 0 * xstride] & y0) |\n (table[j + 1 * xstride] & y1) |\n (table[j + 2 * xstride] & y2) |\n (table[j + 3 * xstride] & y3) )\n & ((BN_ULONG)0 - (constant_time_eq_int(j,idx)&1));\n }\n b->d[i] = acc;\n }\n }\n b->top = top;\n bn_correct_top(b);\n return 1;\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 bn_pollute(a);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return 0;\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)\n{\n BIGNUM *n;\n BN_ULONG *ap, *np, *rp, n0, v, carry;\n int nl, max, i;\n n = &(mont->N);\n nl = n->top;\n if (nl == 0) {\n ret->top = 0;\n return 1;\n }\n max = (2 * nl);\n if (bn_wexpand(r, max) == NULL)\n return 0;\n r->neg ^= n->neg;\n np = n->d;\n rp = r->d;\n i = max - r->top;\n if (i)\n memset(&rp[r->top], 0, sizeof(*rp) * i);\n r->top = max;\n n0 = mont->n0[0];\n for (carry = 0, i = 0; i < nl; i++, rp++) {\n v = bn_mul_add_words(rp, np, nl, (rp[0] * n0) & BN_MASK2);\n v = (v + carry + rp[nl]) & BN_MASK2;\n carry |= (v != rp[nl]);\n carry &= (v <= rp[nl]);\n rp[nl] = v;\n }\n if (bn_wexpand(ret, nl) == NULL)\n return 0;\n ret->top = nl;\n ret->neg = r->neg;\n rp = ret->d;\n ap = &(r->d[nl]);\n v = bn_sub_words(rp, ap, np, nl) - carry;\n v = 0 - v;\n for (i = 0; i < nl; i++) {\n rp[i] = (v & ap[i]) | (~v & rp[i]);\n ap[i] = 0;\n }\n bn_correct_top(r);\n bn_correct_top(ret);\n bn_check_top(ret);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
927
| 0
|
https://github.com/openssl/openssl/blob/8da94770f0a049497b1a52ee469cca1f4a13b1a7/crypto/bn/bn_lib.c/#L352
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *A, *a = NULL;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b,BN_FLG_SECURE))
a = A = OPENSSL_secure_malloc(words * sizeof(*a));
else
a = A = OPENSSL_malloc(words * sizeof(*a));
if (A == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
#ifdef PURIFY
memset(a, 0, sizeof(*a) * words);
#endif
#if 1
B = b->d;
if (B != NULL) {
for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
BN_ULONG a0, a1, a2, a3;
a0 = B[0];
a1 = B[1];
a2 = B[2];
a3 = B[3];
A[0] = a0;
A[1] = a1;
A[2] = a2;
A[3] = a3;
}
switch (b->top & 3) {
case 3:
A[2] = B[2];
case 2:
A[1] = B[1];
case 1:
A[0] = B[0];
case 0:
;
}
}
#else
memset(A, 0, sizeof(*A) * words);
memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
return (a);
}
|
['int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *y, const BIGNUM *x,\n const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *xinv = NULL;\n int ret = 0;\n bn_check_top(y);\n bn_check_top(x);\n bn_check_top(p);\n BN_CTX_start(ctx);\n xinv = BN_CTX_get(ctx);\n if (xinv == NULL)\n goto err;\n if (!BN_GF2m_mod_inv(xinv, x, p, ctx))\n goto err;\n if (!BN_GF2m_mod_mul(r, y, xinv, p, ctx))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return (1);\n}', 'int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n BIGNUM *b, *c = NULL, *u = NULL, *v = NULL, *tmp;\n int ret = 0;\n bn_check_top(a);\n bn_check_top(p);\n BN_CTX_start(ctx);\n if ((b = BN_CTX_get(ctx)) == NULL)\n goto err;\n if ((c = BN_CTX_get(ctx)) == NULL)\n goto err;\n if ((u = BN_CTX_get(ctx)) == NULL)\n goto err;\n if ((v = BN_CTX_get(ctx)) == NULL)\n goto err;\n if (!BN_GF2m_mod(u, a, p))\n goto err;\n if (BN_is_zero(u))\n goto err;\n if (!BN_copy(v, p))\n goto err;\n# if 0\n if (!BN_one(b))\n goto err;\n while (1) {\n while (!BN_is_odd(u)) {\n if (BN_is_zero(u))\n goto err;\n if (!BN_rshift1(u, u))\n goto err;\n if (BN_is_odd(b)) {\n if (!BN_GF2m_add(b, b, p))\n goto err;\n }\n if (!BN_rshift1(b, b))\n goto err;\n }\n if (BN_abs_is_word(u, 1))\n break;\n if (BN_num_bits(u) < BN_num_bits(v)) {\n tmp = u;\n u = v;\n v = tmp;\n tmp = b;\n b = c;\n c = tmp;\n }\n if (!BN_GF2m_add(u, u, v))\n goto err;\n if (!BN_GF2m_add(b, b, c))\n goto err;\n }\n# else\n {\n int i;\n int ubits = BN_num_bits(u);\n int vbits = BN_num_bits(v);\n int top = p->top;\n BN_ULONG *udp, *bdp, *vdp, *cdp;\n if (!bn_wexpand(u, top))\n goto err;\n udp = u->d;\n for (i = u->top; i < top; i++)\n udp[i] = 0;\n u->top = top;\n if (!bn_wexpand(b, top))\n goto err;\n bdp = b->d;\n bdp[0] = 1;\n for (i = 1; i < top; i++)\n bdp[i] = 0;\n b->top = top;\n if (!bn_wexpand(c, top))\n goto err;\n cdp = c->d;\n for (i = 0; i < top; i++)\n cdp[i] = 0;\n c->top = top;\n vdp = v->d;\n while (1) {\n while (ubits && !(udp[0] & 1)) {\n BN_ULONG u0, u1, b0, b1, mask;\n u0 = udp[0];\n b0 = bdp[0];\n mask = (BN_ULONG)0 - (b0 & 1);\n b0 ^= p->d[0] & mask;\n for (i = 0; i < top - 1; i++) {\n u1 = udp[i + 1];\n udp[i] = ((u0 >> 1) | (u1 << (BN_BITS2 - 1))) & BN_MASK2;\n u0 = u1;\n b1 = bdp[i + 1] ^ (p->d[i + 1] & mask);\n bdp[i] = ((b0 >> 1) | (b1 << (BN_BITS2 - 1))) & BN_MASK2;\n b0 = b1;\n }\n udp[i] = u0 >> 1;\n bdp[i] = b0 >> 1;\n ubits--;\n }\n if (ubits <= BN_BITS2) {\n if (udp[0] == 0)\n goto err;\n if (udp[0] == 1)\n break;\n }\n if (ubits < vbits) {\n i = ubits;\n ubits = vbits;\n vbits = i;\n tmp = u;\n u = v;\n v = tmp;\n tmp = b;\n b = c;\n c = tmp;\n udp = vdp;\n vdp = v->d;\n bdp = cdp;\n cdp = c->d;\n }\n for (i = 0; i < top; i++) {\n udp[i] ^= vdp[i];\n bdp[i] ^= cdp[i];\n }\n if (ubits == vbits) {\n BN_ULONG ul;\n int utop = (ubits - 1) / BN_BITS2;\n while ((ul = udp[utop]) == 0 && utop)\n utop--;\n ubits = utop * BN_BITS2 + BN_num_bits_word(ul);\n }\n }\n bn_correct_top(b);\n }\n# endif\n if (!BN_copy(r, b))\n goto err;\n bn_check_top(r);\n ret = 1;\n err:\n# ifdef BN_DEBUG\n bn_correct_top(c);\n bn_correct_top(u);\n bn_correct_top(v);\n# endif\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n int i;\n BN_ULONG *A;\n const BN_ULONG *B;\n bn_check_top(b);\n if (a == b)\n return (a);\n if (bn_wexpand(a, b->top) == NULL)\n return (NULL);\n#if 1\n A = a->d;\n B = b->d;\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:;\n }\n#else\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n#endif\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return (a);\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *A, *a = NULL;\n const BN_ULONG *B;\n int i;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b,BN_FLG_SECURE))\n a = A = OPENSSL_secure_malloc(words * sizeof(*a));\n else\n a = A = OPENSSL_malloc(words * sizeof(*a));\n if (A == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n#ifdef PURIFY\n memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n B = b->d;\n if (B != NULL) {\n for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n BN_ULONG a0, a1, a2, a3;\n a0 = B[0];\n a1 = B[1];\n a2 = B[2];\n a3 = B[3];\n A[0] = a0;\n A[1] = a1;\n A[2] = a2;\n A[3] = a3;\n }\n switch (b->top & 3) {\n case 3:\n A[2] = B[2];\n case 2:\n A[1] = B[1];\n case 1:\n A[0] = B[0];\n case 0:\n ;\n }\n }\n#else\n memset(A, 0, sizeof(*A) * words);\n memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n return (a);\n}']
|
928
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L404
|
static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
src[0+0*stride]=
src[2+1*stride]=(lt + l0 + 1)>>1;
src[1+0*stride]=
src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
src[0+1*stride]=
src[2+2*stride]=(l0 + l1 + 1)>>1;
src[1+1*stride]=
src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
src[0+2*stride]=
src[2+3*stride]=(l1 + l2+ 1)>>1;
src[1+2*stride]=
src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
src[0+3*stride]=(l2 + l3 + 1)>>1;
src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
}
|
['static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){\n const int lt= src[-1-1*stride];\n LOAD_TOP_EDGE\n LOAD_LEFT_EDGE\n src[0+0*stride]=\n src[2+1*stride]=(lt + l0 + 1)>>1;\n src[1+0*stride]=\n src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;\n src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;\n src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;\n src[0+1*stride]=\n src[2+2*stride]=(l0 + l1 + 1)>>1;\n src[1+1*stride]=\n src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;\n src[0+2*stride]=\n src[2+3*stride]=(l1 + l2+ 1)>>1;\n src[1+2*stride]=\n src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;\n src[0+3*stride]=(l2 + l3 + 1)>>1;\n src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;\n}']
|
929
| 0
|
https://github.com/openssl/openssl/blob/2d13250fd695eba777fe7e2af4beb1b7d356bd8f/crypto/ct/ct_b64.c/#L49
|
static int ct_base64_decode(const char *in, unsigned char **out)
{
size_t inlen = strlen(in);
int outlen;
unsigned char *outbuf = NULL;
if (inlen == 0) {
*out = NULL;
return 0;
}
outlen = (inlen / 4) * 3;
outbuf = OPENSSL_malloc(outlen);
if (outbuf == NULL) {
CTerr(CT_F_CT_BASE64_DECODE, ERR_R_MALLOC_FAILURE);
goto err;
}
outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);
if (outlen < 0) {
CTerr(CT_F_CT_BASE64_DECODE, CT_R_BASE64_DECODE_ERROR);
goto err;
}
while (in[--inlen] == '=') {
--outlen;
}
*out = outbuf;
return outlen;
err:
OPENSSL_free(outbuf);
return -1;
}
|
['static int test_encode_tls_sct()\n{\n const char log_id[] = "3xwuwRUAlFJHqWFoMl3cXHlZ6PfG04j8AC4LvT9012Q=";\n const uint64_t timestamp = 1;\n const char extensions[] = "";\n const char signature[] = "BAMARzBAMiBIL2dRrzXbplQ2vh/WZA89v5pBQpSVkkUwKI+j5"\n "eI+BgIhAOTtwNs6xXKx4vXoq2poBlOYfc9BAn3+/6EFUZ2J7b8I";\n SCT *sct = NULL;\n SETUP_CT_TEST_FIXTURE();\n fixture.sct_list = sk_SCT_new_null();\n sct = SCT_new_from_base64(SCT_VERSION_V1, log_id,\n CT_LOG_ENTRY_TYPE_X509, timestamp,\n extensions, signature);\n if (sct == NULL) {\n tear_down(fixture);\n fprintf(stderr, "Failed to create SCT from base64-encoded test data\\n");\n return 0;\n }\n sk_SCT_push(fixture.sct_list, sct);\n fixture.sct_dir = ct_dir;\n fixture.sct_text_file = "tls1.sct";\n EXECUTE_CT_TEST();\n}', 'SCT *SCT_new_from_base64(unsigned char version, const char *logid_base64,\n ct_log_entry_type_t entry_type, uint64_t timestamp,\n const char *extensions_base64,\n const char *signature_base64)\n{\n SCT *sct = SCT_new();\n unsigned char *dec = NULL;\n const unsigned char* p = NULL;\n int declen;\n if (sct == NULL) {\n CTerr(CT_F_SCT_NEW_FROM_BASE64, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n if (!SCT_set_version(sct, version)) {\n CTerr(CT_F_SCT_NEW_FROM_BASE64, CT_R_SCT_UNSUPPORTED_VERSION);\n goto err;\n }\n declen = ct_base64_decode(logid_base64, &dec);\n if (declen < 0) {\n CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);\n goto err;\n }\n if (!SCT_set0_log_id(sct, dec, declen))\n goto err;\n dec = NULL;\n declen = ct_base64_decode(extensions_base64, &dec);\n if (declen < 0) {\n CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);\n goto err;\n }\n SCT_set0_extensions(sct, dec, declen);\n dec = NULL;\n declen = ct_base64_decode(signature_base64, &dec);\n if (declen < 0) {\n CTerr(CT_F_SCT_NEW_FROM_BASE64, X509_R_BASE64_DECODE_ERROR);\n goto err;\n }\n p = dec;\n if (o2i_SCT_signature(sct, &p, declen) <= 0)\n goto err;\n OPENSSL_free(dec);\n dec = NULL;\n SCT_set_timestamp(sct, timestamp);\n if (!SCT_set_log_entry_type(sct, entry_type))\n goto err;\n return sct;\n err:\n OPENSSL_free(dec);\n SCT_free(sct);\n return NULL;\n}', "static int ct_base64_decode(const char *in, unsigned char **out)\n{\n size_t inlen = strlen(in);\n int outlen;\n unsigned char *outbuf = NULL;\n if (inlen == 0) {\n *out = NULL;\n return 0;\n }\n outlen = (inlen / 4) * 3;\n outbuf = OPENSSL_malloc(outlen);\n if (outbuf == NULL) {\n CTerr(CT_F_CT_BASE64_DECODE, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n outlen = EVP_DecodeBlock(outbuf, (unsigned char *)in, inlen);\n if (outlen < 0) {\n CTerr(CT_F_CT_BASE64_DECODE, CT_R_BASE64_DECODE_ERROR);\n goto err;\n }\n while (in[--inlen] == '=') {\n --outlen;\n }\n *out = outbuf;\n return outlen;\nerr:\n OPENSSL_free(outbuf);\n return -1;\n}"]
|
930
| 0
|
https://github.com/openssl/openssl/blob/3b5873567d24bf0d8bc2a175848e716e295d6c94/crypto/bn/bn_ctx.c/#L273
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int rsa_ossl_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)\n{\n BIGNUM *r1, *m1, *vrfy, *r2, *m[RSA_MAX_PRIME_NUM];\n int ret = 0, i, ex_primes = 0;\n RSA_PRIME_INFO *pinfo;\n BN_CTX_start(ctx);\n r1 = BN_CTX_get(ctx);\n r2 = BN_CTX_get(ctx);\n m1 = BN_CTX_get(ctx);\n vrfy = BN_CTX_get(ctx);\n if (vrfy == NULL)\n goto err;\n if (rsa->version == RSA_ASN1_VERSION_MULTI\n && (ex_primes = sk_RSA_PRIME_INFO_num(rsa->prime_infos)) <= 0)\n goto err;\n {\n BIGNUM *p = BN_new(), *q = BN_new();\n if (p == NULL || q == NULL) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);\n BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME);\n if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) {\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_p, rsa->lock, p, ctx)\n || !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,\n rsa->lock, q, ctx)) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n if (ex_primes > 0) {\n BIGNUM *r = BN_new();\n if (r == NULL) {\n BN_free(p);\n BN_free(q);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(r, pinfo->r, BN_FLG_CONSTTIME);\n if (!BN_MONT_CTX_set_locked(&pinfo->m, rsa->lock, r, ctx)) {\n BN_free(p);\n BN_free(q);\n BN_free(r);\n goto err;\n }\n }\n BN_free(r);\n }\n }\n BN_free(p);\n BN_free(q);\n }\n if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)\n if (!BN_MONT_CTX_set_locked\n (&rsa->_method_mod_n, rsa->lock, rsa->n, ctx))\n goto err;\n {\n BIGNUM *c = BN_new();\n if (c == NULL)\n goto err;\n BN_with_flags(c, I, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, c, rsa->q, ctx)) {\n BN_free(c);\n goto err;\n }\n {\n BIGNUM *dmq1 = BN_new();\n if (dmq1 == NULL) {\n BN_free(c);\n goto err;\n }\n BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(m1, r1, dmq1, rsa->q, ctx,\n rsa->_method_mod_q)) {\n BN_free(c);\n BN_free(dmq1);\n goto err;\n }\n BN_free(dmq1);\n }\n if (!BN_mod(r1, c, rsa->p, ctx)) {\n BN_free(c);\n goto err;\n }\n BN_free(c);\n }\n {\n BIGNUM *dmp1 = BN_new();\n if (dmp1 == NULL)\n goto err;\n BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, r1, dmp1, rsa->p, ctx,\n rsa->_method_mod_p)) {\n BN_free(dmp1);\n goto err;\n }\n BN_free(dmp1);\n }\n if (ex_primes > 0) {\n BIGNUM *di = BN_new(), *cc = BN_new();\n if (cc == NULL || di == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n for (i = 0; i < ex_primes; i++) {\n if ((m[i] = BN_CTX_get(ctx)) == NULL) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n BN_with_flags(cc, I, BN_FLG_CONSTTIME);\n BN_with_flags(di, pinfo->d, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, cc, pinfo->r, ctx)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n if (!rsa->meth->bn_mod_exp(m[i], r1, di, pinfo->r, ctx, pinfo->m)) {\n BN_free(cc);\n BN_free(di);\n goto err;\n }\n }\n BN_free(cc);\n BN_free(di);\n }\n if (!BN_sub(r0, r0, m1))\n goto err;\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->iqmp, ctx))\n goto err;\n {\n BIGNUM *pr1 = BN_new();\n if (pr1 == NULL)\n goto err;\n BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);\n if (!BN_mod(r0, pr1, rsa->p, ctx)) {\n BN_free(pr1);\n goto err;\n }\n BN_free(pr1);\n }\n if (BN_is_negative(r0))\n if (!BN_add(r0, r0, rsa->p))\n goto err;\n if (!BN_mul(r1, r0, rsa->q, ctx))\n goto err;\n if (!BN_add(r0, r1, m1))\n goto err;\n if (ex_primes > 0) {\n BIGNUM *pr2 = BN_new();\n if (pr2 == NULL)\n goto err;\n for (i = 0; i < ex_primes; i++) {\n pinfo = sk_RSA_PRIME_INFO_value(rsa->prime_infos, i);\n if (!BN_sub(r1, m[i], r0)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r2, r1, pinfo->t, ctx)) {\n BN_free(pr2);\n goto err;\n }\n BN_with_flags(pr2, r2, BN_FLG_CONSTTIME);\n if (!BN_mod(r1, pr2, pinfo->r, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (BN_is_negative(r1))\n if (!BN_add(r1, r1, pinfo->r)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_mul(r1, r1, pinfo->pp, ctx)) {\n BN_free(pr2);\n goto err;\n }\n if (!BN_add(r0, r0, r1)) {\n BN_free(pr2);\n goto err;\n }\n }\n BN_free(pr2);\n }\n if (rsa->e && rsa->n) {\n if (!rsa->meth->bn_mod_exp(vrfy, r0, rsa->e, rsa->n, ctx,\n rsa->_method_mod_n))\n goto err;\n if (!BN_sub(vrfy, vrfy, I))\n goto err;\n if (!BN_mod(vrfy, vrfy, rsa->n, ctx))\n goto err;\n if (BN_is_negative(vrfy))\n if (!BN_add(vrfy, vrfy, rsa->n))\n goto err;\n if (!BN_is_zero(vrfy)) {\n BIGNUM *d = BN_new();\n if (d == NULL)\n goto err;\n BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);\n if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,\n rsa->_method_mod_n)) {\n BN_free(d);\n goto err;\n }\n BN_free(d);\n }\n }\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}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, CRYPTO_RWLOCK *lock,\n const BIGNUM *mod, BN_CTX *ctx)\n{\n BN_MONT_CTX *ret;\n CRYPTO_THREAD_read_lock(lock);\n ret = *pmont;\n CRYPTO_THREAD_unlock(lock);\n if (ret)\n return ret;\n ret = BN_MONT_CTX_new();\n if (ret == NULL)\n return NULL;\n if (!BN_MONT_CTX_set(ret, mod, ctx)) {\n BN_MONT_CTX_free(ret);\n return NULL;\n }\n CRYPTO_THREAD_write_lock(lock);\n if (*pmont) {\n BN_MONT_CTX_free(ret);\n ret = *pmont;\n } else\n *pmont = ret;\n CRYPTO_THREAD_unlock(lock);\n return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n int ret = 0;\n BIGNUM *Ri, *R;\n if (BN_is_zero(mod))\n return 0;\n BN_CTX_start(ctx);\n if ((Ri = BN_CTX_get(ctx)) == NULL)\n goto err;\n R = &(mont->RR);\n if (!BN_copy(&(mont->N), mod))\n goto err;\n mont->N.neg = 0;\n#ifdef MONT_WORD\n {\n BIGNUM tmod;\n BN_ULONG buf[2];\n bn_init(&tmod);\n tmod.d = buf;\n tmod.dmax = 2;\n tmod.neg = 0;\n if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n BN_zero(R);\n if (!(BN_set_bit(R, 2 * BN_BITS2)))\n goto err;\n tmod.top = 0;\n if ((buf[0] = mod->d[0]))\n tmod.top = 1;\n if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n tmod.top = 2;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n goto err;\n Ri->neg = 0;\n Ri->d[0] = BN_MASK2;\n Ri->d[1] = BN_MASK2;\n Ri->top = 2;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n BN_zero(R);\n if (!(BN_set_bit(R, BN_BITS2)))\n goto err;\n buf[0] = mod->d[0];\n buf[1] = 0;\n tmod.top = buf[0] != 0 ? 1 : 0;\n if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, BN_BITS2))\n goto err;\n if (!BN_is_zero(Ri)) {\n if (!BN_sub_word(Ri, 1))\n goto err;\n } else {\n if (!BN_set_word(Ri, BN_MASK2))\n goto err;\n }\n if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n goto err;\n mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n mont->n0[1] = 0;\n# endif\n }\n#else\n {\n mont->ri = BN_num_bits(&mont->N);\n BN_zero(R);\n if (!BN_set_bit(R, mont->ri))\n goto err;\n if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n goto err;\n if (!BN_lshift(Ri, Ri, mont->ri))\n goto err;\n if (!BN_sub_word(Ri, 1))\n goto err;\n if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n goto err;\n }\n#endif\n BN_zero(&(mont->RR));\n if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n goto err;\n if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n goto err;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return ret;\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return ret;\n}', '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}']
|
931
| 0
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,\n BIGNUM **kinvp, BIGNUM **rp,\n const unsigned char *dgst, int dlen)\n{\n BN_CTX *ctx = NULL;\n BIGNUM *k = NULL, *r = NULL, *X = NULL;\n const BIGNUM *order;\n EC_POINT *tmp_point = NULL;\n const EC_GROUP *group;\n int ret = 0;\n int order_bits;\n if (eckey == NULL || (group = EC_KEY_get0_group(eckey)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!EC_KEY_can_sign(eckey)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, EC_R_CURVE_DOES_NOT_SUPPORT_SIGNING);\n return 0;\n }\n if (ctx_in == NULL) {\n if ((ctx = BN_CTX_new()) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n } else\n ctx = ctx_in;\n k = BN_new();\n r = BN_new();\n X = BN_new();\n if (k == NULL || r == NULL || X == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n if ((tmp_point = EC_POINT_new(group)) == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n order = EC_GROUP_get0_order(group);\n if (order == NULL) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n order_bits = BN_num_bits(order);\n if (!BN_set_bit(k, order_bits)\n || !BN_set_bit(r, order_bits)\n || !BN_set_bit(X, order_bits))\n goto err;\n do {\n do\n if (dgst != NULL) {\n if (!BN_generate_dsa_nonce\n (k, order, EC_KEY_get0_private_key(eckey), dgst, dlen,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n } else {\n if (!BN_priv_rand_range(k, order)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP,\n EC_R_RANDOM_NUMBER_GENERATION_FAILED);\n goto err;\n }\n }\n while (BN_is_zero(k));\n if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) ==\n NID_X9_62_prime_field) {\n if (!EC_POINT_get_affine_coordinates_GFp\n (group, tmp_point, X, NULL, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#ifndef OPENSSL_NO_EC2M\n else {\n if (!EC_POINT_get_affine_coordinates_GF2m(group,\n tmp_point, X, NULL,\n ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);\n goto err;\n }\n }\n#endif\n if (!BN_nnmod(r, X, order, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n }\n while (BN_is_zero(r));\n if (!ec_group_do_inverse_ord(group, k, k, ctx)) {\n ECerr(EC_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);\n goto err;\n }\n BN_clear_free(*rp);\n BN_clear_free(*kinvp);\n *rp = r;\n *kinvp = k;\n ret = 1;\n err:\n if (!ret) {\n BN_clear_free(k);\n BN_clear_free(r);\n }\n if (ctx != ctx_in)\n BN_CTX_free(ctx);\n EC_POINT_free(tmp_point);\n BN_clear_free(X);\n return ret;\n}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n int i, j, k;\n if (n < 0)\n return 0;\n i = n / BN_BITS2;\n j = n % BN_BITS2;\n if (a->top <= i) {\n if (bn_wexpand(a, i + 1) == NULL)\n return 0;\n for (k = a->top; k < i + 1; k++)\n a->d[k] = 0;\n a->top = i + 1;\n a->flags &= ~BN_FLG_FIXED_TOP;\n }\n a->d[i] |= (((BN_ULONG)1) << j);\n bn_check_top(a);\n return 1;\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n return a->top == 0;\n}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n const EC_POINT *points[1];\n const BIGNUM *scalars[1];\n points[0] = point;\n scalars[0] = p_scalar;\n return EC_POINTs_mul(group, r, g_scalar,\n (point != NULL\n && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[],\n const BIGNUM *scalars[], BN_CTX *ctx)\n{\n if (group->meth->mul == 0)\n return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n return group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n const EC_POINT *generator = NULL;\n EC_POINT *tmp = NULL;\n size_t totalnum;\n size_t blocksize = 0, numblocks = 0;\n size_t pre_points_per_block = 0;\n size_t i, j;\n int k;\n int r_is_inverted = 0;\n int r_is_at_infinity = 1;\n size_t *wsize = NULL;\n signed char **wNAF = NULL;\n size_t *wNAF_len = NULL;\n size_t max_len = 0;\n size_t num_val;\n EC_POINT **val = NULL;\n EC_POINT **v;\n EC_POINT ***val_sub = NULL;\n const EC_PRE_COMP *pre_comp = NULL;\n int num_scalar = 0;\n int ret = 0;\n if (!ec_point_is_compat(r, group)) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n if ((scalar == NULL) && (num == 0)) {\n return EC_POINT_set_to_infinity(group, r);\n }\n if (!BN_is_zero(group->order) && !BN_is_zero(group->cofactor)) {\n if ((scalar != NULL) && (num == 0)) {\n return ec_mul_consttime(group, r, scalar, NULL, ctx);\n }\n if ((scalar == NULL) && (num == 1)) {\n return ec_mul_consttime(group, r, scalars[0], points[0], ctx);\n }\n }\n for (i = 0; i < num; i++) {\n if (!ec_point_is_compat(points[i], group)) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n return 0;\n }\n }\n if (ctx == NULL) {\n ctx = new_ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n }\n if (scalar != NULL) {\n generator = EC_GROUP_get0_generator(group);\n if (generator == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n goto err;\n }\n pre_comp = group->pre_comp.ec;\n if (pre_comp && pre_comp->numblocks\n && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n 0)) {\n blocksize = pre_comp->blocksize;\n numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n if (numblocks > pre_comp->numblocks)\n numblocks = pre_comp->numblocks;\n pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n pre_comp = NULL;\n numblocks = 1;\n num_scalar = 1;\n }\n }\n totalnum = num + numblocks;\n wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));\n wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));\n wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));\n val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));\n if (wNAF != NULL)\n wNAF[0] = NULL;\n if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n num_val = 0;\n for (i = 0; i < num + num_scalar; i++) {\n size_t bits;\n bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n wsize[i] = EC_window_bits_for_scalar_size(bits);\n num_val += (size_t)1 << (wsize[i] - 1);\n wNAF[i + 1] = NULL;\n wNAF[i] =\n bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n &wNAF_len[i]);\n if (wNAF[i] == NULL)\n goto err;\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n }\n if (numblocks) {\n if (pre_comp == NULL) {\n if (num_scalar != 1) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n } else {\n signed char *tmp_wNAF = NULL;\n size_t tmp_len = 0;\n if (num_scalar != 0) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n wsize[num] = pre_comp->w;\n tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n if (!tmp_wNAF)\n goto err;\n if (tmp_len <= max_len) {\n numblocks = 1;\n totalnum = num + 1;\n wNAF[num] = tmp_wNAF;\n wNAF[num + 1] = NULL;\n wNAF_len[num] = tmp_len;\n val_sub[num] = pre_comp->points;\n } else {\n signed char *pp;\n EC_POINT **tmp_points;\n if (tmp_len < numblocks * blocksize) {\n numblocks = (tmp_len + blocksize - 1) / blocksize;\n if (numblocks > pre_comp->numblocks) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n totalnum = num + numblocks;\n }\n pp = tmp_wNAF;\n tmp_points = pre_comp->points;\n for (i = num; i < totalnum; i++) {\n if (i < totalnum - 1) {\n wNAF_len[i] = blocksize;\n if (tmp_len < blocksize) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n tmp_len -= blocksize;\n } else\n wNAF_len[i] = tmp_len;\n wNAF[i + 1] = NULL;\n wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n if (wNAF[i] == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n memcpy(wNAF[i], pp, wNAF_len[i]);\n if (wNAF_len[i] > max_len)\n max_len = wNAF_len[i];\n if (*tmp_points == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n OPENSSL_free(tmp_wNAF);\n goto err;\n }\n val_sub[i] = tmp_points;\n tmp_points += pre_points_per_block;\n pp += blocksize;\n }\n OPENSSL_free(tmp_wNAF);\n }\n }\n }\n val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));\n if (val == NULL) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n val[num_val] = NULL;\n v = val;\n for (i = 0; i < num + num_scalar; i++) {\n val_sub[i] = v;\n for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n *v = EC_POINT_new(group);\n if (*v == NULL)\n goto err;\n v++;\n }\n }\n if (!(v == val + num_val)) {\n ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n goto err;\n }\n if ((tmp = EC_POINT_new(group)) == NULL)\n goto err;\n for (i = 0; i < num + num_scalar; i++) {\n if (i < num) {\n if (!EC_POINT_copy(val_sub[i][0], points[i]))\n goto err;\n } else {\n if (!EC_POINT_copy(val_sub[i][0], generator))\n goto err;\n }\n if (wsize[i] > 1) {\n if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n goto err;\n for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n if (!EC_POINT_add\n (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n goto err;\n }\n }\n }\n if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n goto err;\n r_is_at_infinity = 1;\n for (k = max_len - 1; k >= 0; k--) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n }\n for (i = 0; i < totalnum; i++) {\n if (wNAF_len[i] > (size_t)k) {\n int digit = wNAF[i][k];\n int is_neg;\n if (digit) {\n is_neg = digit < 0;\n if (is_neg)\n digit = -digit;\n if (is_neg != r_is_inverted) {\n if (!r_is_at_infinity) {\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n r_is_inverted = !r_is_inverted;\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n goto err;\n r_is_at_infinity = 0;\n } else {\n if (!EC_POINT_add\n (group, r, r, val_sub[i][digit >> 1], ctx))\n goto err;\n }\n }\n }\n }\n }\n if (r_is_at_infinity) {\n if (!EC_POINT_set_to_infinity(group, r))\n goto err;\n } else {\n if (r_is_inverted)\n if (!EC_POINT_invert(group, r, ctx))\n goto err;\n }\n ret = 1;\n err:\n BN_CTX_free(new_ctx);\n EC_POINT_free(tmp);\n OPENSSL_free(wsize);\n OPENSSL_free(wNAF_len);\n if (wNAF != NULL) {\n signed char **w;\n for (w = wNAF; *w != NULL; w++)\n OPENSSL_free(*w);\n OPENSSL_free(wNAF);\n }\n if (val != NULL) {\n for (v = val; *v != NULL; v++)\n EC_POINT_clear_free(*v);\n OPENSSL_free(val);\n }\n OPENSSL_free(val_sub);\n return ret;\n}', 'static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r,\n const BIGNUM *scalar, const EC_POINT *point,\n BN_CTX *ctx)\n{\n int i, cardinality_bits, group_top, kbit, pbit, Z_is_one;\n EC_POINT *s = NULL;\n BIGNUM *k = NULL;\n BIGNUM *lambda = NULL;\n BIGNUM *cardinality = NULL;\n BN_CTX *new_ctx = NULL;\n int ret = 0;\n if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)\n return 0;\n BN_CTX_start(ctx);\n s = EC_POINT_new(group);\n if (s == NULL)\n goto err;\n if (point == NULL) {\n if (!EC_POINT_copy(s, group->generator))\n goto err;\n } else {\n if (!EC_POINT_copy(s, point))\n goto err;\n }\n EC_POINT_BN_set_flags(s, BN_FLG_CONSTTIME);\n cardinality = BN_CTX_get(ctx);\n lambda = BN_CTX_get(ctx);\n k = BN_CTX_get(ctx);\n if (k == NULL || !BN_mul(cardinality, group->order, group->cofactor, ctx))\n goto err;\n cardinality_bits = BN_num_bits(cardinality);\n group_top = bn_get_top(cardinality);\n if ((bn_wexpand(k, group_top + 1) == NULL)\n || (bn_wexpand(lambda, group_top + 1) == NULL))\n goto err;\n if (!BN_copy(k, scalar))\n goto err;\n BN_set_flags(k, BN_FLG_CONSTTIME);\n if ((BN_num_bits(k) > cardinality_bits) || (BN_is_negative(k))) {\n if (!BN_nnmod(k, k, cardinality, ctx))\n goto err;\n }\n if (!BN_add(lambda, k, cardinality))\n goto err;\n BN_set_flags(lambda, BN_FLG_CONSTTIME);\n if (!BN_add(k, lambda, cardinality))\n goto err;\n kbit = BN_is_bit_set(lambda, cardinality_bits);\n BN_consttime_swap(kbit, k, lambda, group_top + 1);\n group_top = bn_get_top(group->field);\n if ((bn_wexpand(s->X, group_top) == NULL)\n || (bn_wexpand(s->Y, group_top) == NULL)\n || (bn_wexpand(s->Z, group_top) == NULL)\n || (bn_wexpand(r->X, group_top) == NULL)\n || (bn_wexpand(r->Y, group_top) == NULL)\n || (bn_wexpand(r->Z, group_top) == NULL))\n goto err;\n if (!ec_point_blind_coordinates(group, s, ctx))\n goto err;\n if (!EC_POINT_copy(r, s))\n goto err;\n EC_POINT_BN_set_flags(r, BN_FLG_CONSTTIME);\n if (!EC_POINT_dbl(group, s, s, ctx))\n goto err;\n pbit = 0;\n#define EC_POINT_CSWAP(c, a, b, w, t) do { \\\n BN_consttime_swap(c, (a)->X, (b)->X, w); \\\n BN_consttime_swap(c, (a)->Y, (b)->Y, w); \\\n BN_consttime_swap(c, (a)->Z, (b)->Z, w); \\\n t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \\\n (a)->Z_is_one ^= (t); \\\n (b)->Z_is_one ^= (t); \\\n} while(0)\n for (i = cardinality_bits - 1; i >= 0; i--) {\n kbit = BN_is_bit_set(k, i) ^ pbit;\n EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);\n if (!EC_POINT_add(group, s, r, s, ctx))\n goto err;\n if (!EC_POINT_dbl(group, r, r, ctx))\n goto err;\n pbit ^= kbit;\n }\n EC_POINT_CSWAP(pbit, r, s, group_top, Z_is_one);\n#undef EC_POINT_CSWAP\n ret = 1;\n err:\n EC_POINT_free(s);\n BN_CTX_end(ctx);\n BN_CTX_free(new_ctx);\n return ret;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
932
| 0
|
https://github.com/openssl/openssl/blob/92eb4c551d7433ba1e74e77001dab2e256f8a870/crypto/x509/x509_vfy.c/#L246
|
int X509_verify_cert(X509_STORE_CTX *ctx)
{
X509 *x,*xtmp,*chain_ss=NULL;
int bad_chain = 0;
X509_VERIFY_PARAM *param = ctx->param;
int depth,i,ok=0;
int num;
int (*cb)(int xok,X509_STORE_CTX *xctx);
STACK_OF(X509) *sktmp=NULL;
if (ctx->cert == NULL)
{
X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
return -1;
}
cb=ctx->verify_cb;
if (ctx->chain == NULL)
{
if ( ((ctx->chain=sk_X509_new_null()) == NULL) ||
(!sk_X509_push(ctx->chain,ctx->cert)))
{
X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
goto end;
}
CRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);
ctx->last_untrusted=1;
}
if (ctx->untrusted != NULL
&& (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)
{
X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
goto end;
}
num=sk_X509_num(ctx->chain);
x=sk_X509_value(ctx->chain,num-1);
depth=param->depth;
for (;;)
{
if (depth < num) break;
if (cert_self_signed(x))
break;
if (ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST)
{
ok = ctx->get_issuer(&xtmp, ctx, x);
if (ok < 0)
return ok;
if (ok > 0)
{
X509_free(xtmp);
break;
}
}
if (ctx->untrusted != NULL)
{
xtmp=find_issuer(ctx, sktmp,x);
if (xtmp != NULL)
{
if (!sk_X509_push(ctx->chain,xtmp))
{
X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
goto end;
}
CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
(void)sk_X509_delete_ptr(sktmp,xtmp);
ctx->last_untrusted++;
x=xtmp;
num++;
continue;
}
}
break;
}
i=sk_X509_num(ctx->chain);
x=sk_X509_value(ctx->chain,i-1);
if (cert_self_signed(x))
{
if (sk_X509_num(ctx->chain) == 1)
{
ok = ctx->get_issuer(&xtmp, ctx, x);
if ((ok <= 0) || X509_cmp(x, xtmp))
{
ctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
ctx->current_cert=x;
ctx->error_depth=i-1;
if (ok == 1) X509_free(xtmp);
bad_chain = 1;
ok=cb(0,ctx);
if (!ok) goto end;
}
else
{
X509_free(x);
x = xtmp;
(void)sk_X509_set(ctx->chain, i - 1, x);
ctx->last_untrusted=0;
}
}
else
{
chain_ss=sk_X509_pop(ctx->chain);
ctx->last_untrusted--;
num--;
x=sk_X509_value(ctx->chain,num-1);
}
}
for (;;)
{
if (depth < num) break;
if (cert_self_signed(x))
break;
ok = ctx->get_issuer(&xtmp, ctx, x);
if (ok < 0) return ok;
if (ok == 0) break;
x = xtmp;
if (!sk_X509_push(ctx->chain,x))
{
X509_free(xtmp);
X509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);
return 0;
}
num++;
}
i = check_trust(ctx);
if (i == X509_TRUST_REJECTED)
goto end;
if (i != X509_TRUST_TRUSTED)
{
if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss))
{
if (ctx->last_untrusted >= num)
ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
else
ctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
ctx->current_cert=x;
}
else
{
sk_X509_push(ctx->chain,chain_ss);
num++;
ctx->last_untrusted=num;
ctx->current_cert=chain_ss;
ctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
chain_ss=NULL;
}
ctx->error_depth=num-1;
bad_chain = 1;
ok=cb(0,ctx);
if (!ok) goto end;
}
ok = check_chain_extensions(ctx);
if (!ok) goto end;
ok = check_name_constraints(ctx);
if (!ok) goto end;
X509_get_pubkey_parameters(NULL,ctx->chain);
ok = ctx->check_revocation(ctx);
if(!ok) goto end;
if (ctx->verify != NULL)
ok=ctx->verify(ctx);
else
ok=internal_verify(ctx);
if(!ok) goto end;
#ifndef OPENSSL_NO_RFC3779
ok = v3_asid_validate_path(ctx);
if (!ok) goto end;
ok = v3_addr_validate_path(ctx);
if (!ok) goto end;
#endif
if (!bad_chain && (ctx->param->flags & X509_V_FLAG_POLICY_CHECK))
ok = ctx->check_policy(ctx);
if(!ok) goto end;
if (0)
{
end:
X509_get_pubkey_parameters(NULL,ctx->chain);
}
if (sktmp != NULL) sk_X509_free(sktmp);
if (chain_ss != NULL) X509_free(chain_ss);
return ok;
}
|
['int X509_verify_cert(X509_STORE_CTX *ctx)\n\t{\n\tX509 *x,*xtmp,*chain_ss=NULL;\n\tint bad_chain = 0;\n\tX509_VERIFY_PARAM *param = ctx->param;\n\tint depth,i,ok=0;\n\tint num;\n\tint (*cb)(int xok,X509_STORE_CTX *xctx);\n\tSTACK_OF(X509) *sktmp=NULL;\n\tif (ctx->cert == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);\n\t\treturn -1;\n\t\t}\n\tcb=ctx->verify_cb;\n\tif (ctx->chain == NULL)\n\t\t{\n\t\tif (\t((ctx->chain=sk_X509_new_null()) == NULL) ||\n\t\t\t(!sk_X509_push(ctx->chain,ctx->cert)))\n\t\t\t{\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\tgoto end;\n\t\t\t}\n\t\tCRYPTO_add(&ctx->cert->references,1,CRYPTO_LOCK_X509);\n\t\tctx->last_untrusted=1;\n\t\t}\n\tif (ctx->untrusted != NULL\n\t && (sktmp=sk_X509_dup(ctx->untrusted)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\tgoto end;\n\t\t}\n\tnum=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,num-1);\n\tdepth=param->depth;\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\tif (cert_self_signed(x))\n\t\t\tbreak;\n\t\tif (ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST)\n\t\t\t{\n\t\t\tok = ctx->get_issuer(&xtmp, ctx, x);\n\t\t\tif (ok < 0)\n\t\t\t\treturn ok;\n\t\t\tif (ok > 0)\n\t\t\t\t{\n\t\t\t\tX509_free(xtmp);\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\tif (ctx->untrusted != NULL)\n\t\t\t{\n\t\t\txtmp=find_issuer(ctx, sktmp,x);\n\t\t\tif (xtmp != NULL)\n\t\t\t\t{\n\t\t\t\tif (!sk_X509_push(ctx->chain,xtmp))\n\t\t\t\t\t{\n\t\t\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tCRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);\n\t\t\t\t(void)sk_X509_delete_ptr(sktmp,xtmp);\n\t\t\t\tctx->last_untrusted++;\n\t\t\t\tx=xtmp;\n\t\t\t\tnum++;\n\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\tbreak;\n\t\t}\n\ti=sk_X509_num(ctx->chain);\n\tx=sk_X509_value(ctx->chain,i-1);\n\tif (cert_self_signed(x))\n\t\t{\n\t\tif (sk_X509_num(ctx->chain) == 1)\n\t\t\t{\n\t\t\tok = ctx->get_issuer(&xtmp, ctx, x);\n\t\t\tif ((ok <= 0) || X509_cmp(x, xtmp))\n\t\t\t\t{\n\t\t\t\tctx->error=X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;\n\t\t\t\tctx->current_cert=x;\n\t\t\t\tctx->error_depth=i-1;\n\t\t\t\tif (ok == 1) X509_free(xtmp);\n\t\t\t\tbad_chain = 1;\n\t\t\t\tok=cb(0,ctx);\n\t\t\t\tif (!ok) goto end;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tX509_free(x);\n\t\t\t\tx = xtmp;\n\t\t\t\t(void)sk_X509_set(ctx->chain, i - 1, x);\n\t\t\t\tctx->last_untrusted=0;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tchain_ss=sk_X509_pop(ctx->chain);\n\t\t\tctx->last_untrusted--;\n\t\t\tnum--;\n\t\t\tx=sk_X509_value(ctx->chain,num-1);\n\t\t\t}\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tif (depth < num) break;\n\t\tif (cert_self_signed(x))\n\t\t\tbreak;\n\t\tok = ctx->get_issuer(&xtmp, ctx, x);\n\t\tif (ok < 0) return ok;\n\t\tif (ok == 0) break;\n\t\tx = xtmp;\n\t\tif (!sk_X509_push(ctx->chain,x))\n\t\t\t{\n\t\t\tX509_free(xtmp);\n\t\t\tX509err(X509_F_X509_VERIFY_CERT,ERR_R_MALLOC_FAILURE);\n\t\t\treturn 0;\n\t\t\t}\n\t\tnum++;\n\t\t}\n\ti = check_trust(ctx);\n\tif (i == X509_TRUST_REJECTED)\n\t\tgoto end;\n\tif (i != X509_TRUST_TRUSTED)\n\t\t{\n\t\tif ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss))\n\t\t\t{\n\t\t\tif (ctx->last_untrusted >= num)\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;\n\t\t\telse\n\t\t\t\tctx->error=X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;\n\t\t\tctx->current_cert=x;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsk_X509_push(ctx->chain,chain_ss);\n\t\t\tnum++;\n\t\t\tctx->last_untrusted=num;\n\t\t\tctx->current_cert=chain_ss;\n\t\t\tctx->error=X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;\n\t\t\tchain_ss=NULL;\n\t\t\t}\n\t\tctx->error_depth=num-1;\n\t\tbad_chain = 1;\n\t\tok=cb(0,ctx);\n\t\tif (!ok) goto end;\n\t\t}\n\tok = check_chain_extensions(ctx);\n\tif (!ok) goto end;\n\tok = check_name_constraints(ctx);\n\tif (!ok) goto end;\n\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\tok = ctx->check_revocation(ctx);\n\tif(!ok) goto end;\n\tif (ctx->verify != NULL)\n\t\tok=ctx->verify(ctx);\n\telse\n\t\tok=internal_verify(ctx);\n\tif(!ok) goto end;\n#ifndef OPENSSL_NO_RFC3779\n\tok = v3_asid_validate_path(ctx);\n\tif (!ok) goto end;\n\tok = v3_addr_validate_path(ctx);\n\tif (!ok) goto end;\n#endif\n\tif (!bad_chain && (ctx->param->flags & X509_V_FLAG_POLICY_CHECK))\n\t\tok = ctx->check_policy(ctx);\n\tif(!ok) goto end;\n\tif (0)\n\t\t{\nend:\n\t\tX509_get_pubkey_parameters(NULL,ctx->chain);\n\t\t}\n\tif (sktmp != NULL) sk_X509_free(sktmp);\n\tif (chain_ss != NULL) X509_free(chain_ss);\n\treturn ok;\n\t}', 'int sk_num(const _STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}', '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}', 'static int cert_self_signed(X509 *x)\n\t{\n\tX509_check_purpose(x, -1, 0);\n\tif (x->ex_flags & EXFLAG_SS)\n\t\treturn 1;\n\telse\n\t\treturn 0;\n\t}', 'int sk_push(_STACK *st, void *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}', 'int CRYPTO_add_lock(int *pointer, int amount, int type, const char *file,\n\t int line)\n\t{\n\tint ret = 0;\n\tif (add_lock_callback != NULL)\n\t\t{\n#ifdef LOCK_DEBUG\n\t\tint before= *pointer;\n#endif\n\t\tret=add_lock_callback(pointer,amount,type,file,line);\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tCRYPTO_THREADID id;\n\t\tCRYPTO_THREADID_current(&id);\n\t\tfprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n\t\t\tCRYPTO_THREADID_hash(&id), before,amount,ret,\n\t\t\tCRYPTO_get_lock_name(type),\n\t\t\tfile,line);\n\t\t}\n#endif\n\t\t}\n\telse\n\t\t{\n\t\tCRYPTO_lock(CRYPTO_LOCK|CRYPTO_WRITE,type,file,line);\n\t\tret= *pointer+amount;\n#ifdef LOCK_DEBUG\n\t\t{\n\t\tCRYPTO_THREADID id;\n\t\tCRYPTO_THREADID_current(&id);\n\t\tfprintf(stderr,"ladd:%08lx:%2d+%2d->%2d %-18s %s:%d\\n",\n\t\t\tCRYPTO_THREADID_hash(&id),\n\t\t\t*pointer,amount,ret,\n\t\t\tCRYPTO_get_lock_name(type),\n\t\t\tfile,line);\n\t\t}\n#endif\n\t\t*pointer=ret;\n\t\tCRYPTO_lock(CRYPTO_UNLOCK|CRYPTO_WRITE,type,file,line);\n\t\t}\n\treturn(ret);\n\t}', 'void CRYPTO_lock(int mode, int type, const char *file, int line)\n\t{\n#ifdef LOCK_DEBUG\n\t\t{\n\t\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}', 'void *sk_delete_ptr(_STACK *st, void *p)\n\t{\n\tint i;\n\tfor (i=0; i<st->num; i++)\n\t\tif (st->data[i] == p)\n\t\t\treturn(sk_delete(st,i));\n\treturn(NULL);\n\t}']
|
933
| 0
|
https://github.com/libav/libav/blob/7ed63ca2e7817e837facd29b01d25a1a69087916/libavcodec/h264_direct.c/#L364
|
static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
MpegEncContext * const s = &h->s;
int b8_stride = h->b8_stride;
int b4_stride = h->b_stride;
int mb_xy = h->mb_xy;
int mb_type_col[2];
const int16_t (*l1mv0)[2], (*l1mv1)[2];
const int8_t *l1ref0, *l1ref1;
const int is_b8x8 = IS_8X8(*mb_type);
unsigned int sub_mb_type= MB_TYPE_L0L1;
int i8, i4;
int ref[2];
int mv[2];
int list;
assert(h->ref_list[1][0].reference&3);
#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
for(list=0; list<2; list++){
int left_ref = h->ref_cache[list][scan8[0] - 1];
int top_ref = h->ref_cache[list][scan8[0] - 8];
int refc = h->ref_cache[list][scan8[0] - 8 + 4];
const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4];
if(refc == PART_NOT_AVAILABLE){
refc = h->ref_cache[list][scan8[0] - 8 - 1];
C = h-> mv_cache[list][scan8[0] - 8 - 1];
}
ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc);
if(ref[list] >= 0){
const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];
const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];
int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]);
if(match_count > 1){
mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]),
mid_pred(A[1], B[1], C[1]) );
}else {
assert(match_count==1);
if(left_ref==ref[list]){
mv[list]= AV_RN32A(A);
}else if(top_ref==ref[list]){
mv[list]= AV_RN32A(B);
}else{
mv[list]= AV_RN32A(C);
}
}
}else{
int mask= ~(MB_TYPE_L0 << (2*list));
mv[list] = 0;
ref[list] = -1;
if(!is_b8x8)
*mb_type &= mask;
sub_mb_type &= mask;
}
}
if(ref[0] < 0 && ref[1] < 0){
ref[0] = ref[1] = 0;
if(!is_b8x8)
*mb_type |= MB_TYPE_L0L1;
sub_mb_type |= MB_TYPE_L0L1;
}
if(!(is_b8x8|mv[0]|mv[1])){
fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);
*mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;
return;
}
if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){
if(!IS_INTERLACED(*mb_type)){
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
b8_stride = 0;
}else{
mb_xy += h->col_fieldoff;
}
goto single_col;
}else{
if(IS_INTERLACED(*mb_type)){
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
b8_stride *= 3;
b4_stride *= 6;
sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;
if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
&& (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
&& !is_b8x8){
*mb_type |= MB_TYPE_16x8 |MB_TYPE_DIRECT2;
}else{
*mb_type |= MB_TYPE_8x8;
}
}else{
single_col:
mb_type_col[0] =
mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;
if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
*mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;
}else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){
*mb_type |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));
}else{
if(!h->sps.direct_8x8_inference_flag){
sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16);
}
*mb_type |= MB_TYPE_8x8;
}
}
}
l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
if(!b8_stride){
if(s->mb_y&1){
l1ref0 += h->b8_stride;
l1ref1 += h->b8_stride;
l1mv0 += 2*b4_stride;
l1mv1 += 2*b4_stride;
}
}
if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
int n=0;
for(i8=0; i8<4; i8++){
int x8 = i8&1;
int y8 = i8>>1;
int xy8 = x8+y8*b8_stride;
int xy4 = 3*x8+y8*b4_stride;
int a,b;
if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
continue;
h->sub_mb_type[i8] = sub_mb_type;
fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref
&& ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
|| (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
a=b=0;
if(ref[0] > 0)
a= mv[0];
if(ref[1] > 0)
b= mv[1];
n++;
}else{
a= mv[0];
b= mv[1];
}
fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
}
if(!is_b8x8 && !(n&3))
*mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;
}else if(IS_16X16(*mb_type)){
int a,b;
fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref
&& ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
|| (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
&& h->x264_build>33U))){
a=b=0;
if(ref[0] > 0)
a= mv[0];
if(ref[1] > 0)
b= mv[1];
}else{
a= mv[0];
b= mv[1];
}
fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
}else{
int n=0;
for(i8=0; i8<4; i8++){
const int x8 = i8&1;
const int y8 = i8>>1;
if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
continue;
h->sub_mb_type[i8] = sub_mb_type;
fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4);
fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4);
fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[x8 + y8*b8_stride] == 0
|| (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
&& h->x264_build>33U))){
const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
if(IS_SUB_8X8(sub_mb_type)){
const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
if(ref[0] == 0)
fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
if(ref[1] == 0)
fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
n+=4;
}
}else{
int m=0;
for(i4=0; i4<4; i4++){
const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
if(ref[0] == 0)
AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]);
if(ref[1] == 0)
AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]);
m++;
}
}
if(!(m&3))
h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8;
n+=m;
}
}
}
if(!is_b8x8 && !(n&15))
*mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;
}
}
|
['static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){\n MpegEncContext * const s = &h->s;\n int b8_stride = h->b8_stride;\n int b4_stride = h->b_stride;\n int mb_xy = h->mb_xy;\n int mb_type_col[2];\n const int16_t (*l1mv0)[2], (*l1mv1)[2];\n const int8_t *l1ref0, *l1ref1;\n const int is_b8x8 = IS_8X8(*mb_type);\n unsigned int sub_mb_type= MB_TYPE_L0L1;\n int i8, i4;\n int ref[2];\n int mv[2];\n int list;\n assert(h->ref_list[1][0].reference&3);\n#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)\n for(list=0; list<2; list++){\n int left_ref = h->ref_cache[list][scan8[0] - 1];\n int top_ref = h->ref_cache[list][scan8[0] - 8];\n int refc = h->ref_cache[list][scan8[0] - 8 + 4];\n const int16_t *C= h->mv_cache[list][ scan8[0] - 8 + 4];\n if(refc == PART_NOT_AVAILABLE){\n refc = h->ref_cache[list][scan8[0] - 8 - 1];\n C = h-> mv_cache[list][scan8[0] - 8 - 1];\n }\n ref[list] = FFMIN3((unsigned)left_ref, (unsigned)top_ref, (unsigned)refc);\n if(ref[list] >= 0){\n const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ];\n const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ];\n int match_count= (left_ref==ref[list]) + (top_ref==ref[list]) + (refc==ref[list]);\n if(match_count > 1){\n mv[list]= pack16to32(mid_pred(A[0], B[0], C[0]),\n mid_pred(A[1], B[1], C[1]) );\n }else {\n assert(match_count==1);\n if(left_ref==ref[list]){\n mv[list]= AV_RN32A(A);\n }else if(top_ref==ref[list]){\n mv[list]= AV_RN32A(B);\n }else{\n mv[list]= AV_RN32A(C);\n }\n }\n }else{\n int mask= ~(MB_TYPE_L0 << (2*list));\n mv[list] = 0;\n ref[list] = -1;\n if(!is_b8x8)\n *mb_type &= mask;\n sub_mb_type &= mask;\n }\n }\n if(ref[0] < 0 && ref[1] < 0){\n ref[0] = ref[1] = 0;\n if(!is_b8x8)\n *mb_type |= MB_TYPE_L0L1;\n sub_mb_type |= MB_TYPE_L0L1;\n }\n if(!(is_b8x8|mv[0]|mv[1])){\n fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);\n fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);\n fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);\n fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, 0, 4);\n *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;\n return;\n }\n if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){\n if(!IS_INTERLACED(*mb_type)){\n mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;\n b8_stride = 0;\n }else{\n mb_xy += h->col_fieldoff;\n }\n goto single_col;\n }else{\n if(IS_INTERLACED(*mb_type)){\n mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;\n mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];\n mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];\n b8_stride *= 3;\n b4_stride *= 6;\n sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;\n if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)\n && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)\n && !is_b8x8){\n *mb_type |= MB_TYPE_16x8 |MB_TYPE_DIRECT2;\n }else{\n *mb_type |= MB_TYPE_8x8;\n }\n }else{\nsingle_col:\n mb_type_col[0] =\n mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];\n sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;\n if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){\n *mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2;\n }else if(!is_b8x8 && (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16))){\n *mb_type |= MB_TYPE_DIRECT2 | (mb_type_col[0] & (MB_TYPE_16x8|MB_TYPE_8x16));\n }else{\n if(!h->sps.direct_8x8_inference_flag){\n sub_mb_type += (MB_TYPE_8x8-MB_TYPE_16x16);\n }\n *mb_type |= MB_TYPE_8x8;\n }\n }\n }\n l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];\n l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];\n l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];\n l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];\n if(!b8_stride){\n if(s->mb_y&1){\n l1ref0 += h->b8_stride;\n l1ref1 += h->b8_stride;\n l1mv0 += 2*b4_stride;\n l1mv1 += 2*b4_stride;\n }\n }\n if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){\n int n=0;\n for(i8=0; i8<4; i8++){\n int x8 = i8&1;\n int y8 = i8>>1;\n int xy8 = x8+y8*b8_stride;\n int xy4 = 3*x8+y8*b4_stride;\n int a,b;\n if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))\n continue;\n h->sub_mb_type[i8] = sub_mb_type;\n fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);\n fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);\n if(!IS_INTRA(mb_type_col[y8]) && !h->ref_list[1][0].long_ref\n && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)\n || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){\n a=b=0;\n if(ref[0] > 0)\n a= mv[0];\n if(ref[1] > 0)\n b= mv[1];\n n++;\n }else{\n a= mv[0];\n b= mv[1];\n }\n fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);\n fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);\n }\n if(!is_b8x8 && !(n&3))\n *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;\n }else if(IS_16X16(*mb_type)){\n int a,b;\n fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);\n fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);\n if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref\n && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)\n || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1\n && h->x264_build>33U))){\n a=b=0;\n if(ref[0] > 0)\n a= mv[0];\n if(ref[1] > 0)\n b= mv[1];\n }else{\n a= mv[0];\n b= mv[1];\n }\n fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);\n fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);\n }else{\n int n=0;\n for(i8=0; i8<4; i8++){\n const int x8 = i8&1;\n const int y8 = i8>>1;\n if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))\n continue;\n h->sub_mb_type[i8] = sub_mb_type;\n fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, mv[0], 4);\n fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, mv[1], 4);\n fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);\n fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);\n if(!IS_INTRA(mb_type_col[0]) && !h->ref_list[1][0].long_ref && ( l1ref0[x8 + y8*b8_stride] == 0\n || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0\n && h->x264_build>33U))){\n const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;\n if(IS_SUB_8X8(sub_mb_type)){\n const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];\n if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){\n if(ref[0] == 0)\n fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);\n if(ref[1] == 0)\n fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);\n n+=4;\n }\n }else{\n int m=0;\n for(i4=0; i4<4; i4++){\n const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];\n if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){\n if(ref[0] == 0)\n AV_ZERO32(h->mv_cache[0][scan8[i8*4+i4]]);\n if(ref[1] == 0)\n AV_ZERO32(h->mv_cache[1][scan8[i8*4+i4]]);\n m++;\n }\n }\n if(!(m&3))\n h->sub_mb_type[i8]+= MB_TYPE_16x16 - MB_TYPE_8x8;\n n+=m;\n }\n }\n }\n if(!is_b8x8 && !(n&15))\n *mb_type= (*mb_type & ~(MB_TYPE_8x8|MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_P1L0|MB_TYPE_P1L1))|MB_TYPE_16x16|MB_TYPE_DIRECT2;\n }\n}']
|
934
| 0
|
https://github.com/openssl/openssl/blob/8e826a339f8cda20a4311fa88a1de782972cf40d/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)\n{\n int ok = 0;\n BIGNUM *tmp = NULL;\n BN_CTX *ctx = NULL;\n *ret = 0;\n ctx = BN_CTX_new();\n if (ctx == NULL)\n goto err;\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL || !BN_set_word(tmp, 1))\n goto err;\n if (BN_cmp(pub_key, tmp) <= 0)\n *ret |= DH_CHECK_PUBKEY_TOO_SMALL;\n if (BN_copy(tmp, dh->p) == NULL || !BN_sub_word(tmp, 1))\n goto err;\n if (BN_cmp(pub_key, tmp) >= 0)\n *ret |= DH_CHECK_PUBKEY_TOO_LARGE;\n if (dh->q != NULL) {\n if (!BN_mod_exp(tmp, pub_key, dh->q, dh->p, ctx))\n goto err;\n if (!BN_is_one(tmp))\n *ret |= DH_CHECK_PUBKEY_INVALID;\n }\n ok = 1;\n err:\n if (ctx != NULL) {\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n }\n return (ok);\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 if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n BN_set_flags(a, BN_FLG_CONSTTIME);\n a->top = b->top;\n a->neg = b->neg;\n bn_check_top(a);\n return a;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return (ret);\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
935
| 0
|
https://github.com/libav/libav/blob/52b0943f10a790145f990f8056ab603edc0f7edb/libavformat/utils.c/#L2568
|
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);
}
if (st->attached_pic.data)
av_free_packet(&st->attached_pic);
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 opt_input_file(OptionsContext *o, const char *opt, const char *filename)\n{\n AVFormatContext *ic;\n AVInputFormat *file_iformat = NULL;\n int err, i, ret;\n int64_t timestamp;\n uint8_t buf[128];\n AVDictionary **opts;\n int orig_nb_streams;\n if (o->format) {\n if (!(file_iformat = av_find_input_format(o->format))) {\n av_log(NULL, AV_LOG_FATAL, "Unknown input format: \'%s\'\\n", o->format);\n exit_program(1);\n }\n }\n if (!strcmp(filename, "-"))\n filename = "pipe:";\n using_stdin |= !strncmp(filename, "pipe:", 5) ||\n !strcmp(filename, "/dev/stdin");\n ic = avformat_alloc_context();\n if (!ic) {\n print_error(filename, AVERROR(ENOMEM));\n exit_program(1);\n }\n if (o->nb_audio_sample_rate) {\n snprintf(buf, sizeof(buf), "%d", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i);\n av_dict_set(&format_opts, "sample_rate", buf, 0);\n }\n if (o->nb_audio_channels) {\n snprintf(buf, sizeof(buf), "%d", o->audio_channels[o->nb_audio_channels - 1].u.i);\n av_dict_set(&format_opts, "channels", buf, 0);\n }\n if (o->nb_frame_rates) {\n av_dict_set(&format_opts, "framerate", o->frame_rates[o->nb_frame_rates - 1].u.str, 0);\n }\n if (o->nb_frame_sizes) {\n av_dict_set(&format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);\n }\n if (o->nb_frame_pix_fmts)\n av_dict_set(&format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);\n ic->flags |= AVFMT_FLAG_NONBLOCK;\n ic->interrupt_callback = int_cb;\n err = avformat_open_input(&ic, filename, file_iformat, &format_opts);\n if (err < 0) {\n print_error(filename, err);\n exit_program(1);\n }\n assert_avoptions(format_opts);\n for (i = 0; i < ic->nb_streams; i++)\n choose_decoder(o, ic, ic->streams[i]);\n opts = setup_find_stream_info_opts(ic, codec_opts);\n orig_nb_streams = ic->nb_streams;\n ret = avformat_find_stream_info(ic, opts);\n if (ret < 0) {\n av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\\n", filename);\n avformat_close_input(&ic);\n exit_program(1);\n }\n timestamp = o->start_time;\n if (ic->start_time != AV_NOPTS_VALUE)\n timestamp += ic->start_time;\n if (o->start_time != 0) {\n ret = av_seek_frame(ic, -1, timestamp, AVSEEK_FLAG_BACKWARD);\n if (ret < 0) {\n av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\\n",\n filename, (double)timestamp / AV_TIME_BASE);\n }\n }\n add_input_streams(o, ic);\n av_dump_format(ic, nb_input_files, filename, 0);\n input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);\n input_files[nb_input_files - 1].ctx = ic;\n input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams;\n input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp);\n input_files[nb_input_files - 1].nb_streams = ic->nb_streams;\n input_files[nb_input_files - 1].rate_emu = o->rate_emu;\n for (i = 0; i < o->nb_dump_attachment; i++) {\n int j;\n for (j = 0; j < ic->nb_streams; j++) {\n AVStream *st = ic->streams[j];\n if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)\n dump_attachment(st, o->dump_attachment[i].u.str);\n }\n }\n for (i = 0; i < orig_nb_streams; i++)\n av_dict_free(&opts[i]);\n av_freep(&opts);\n reset_options(o);\n return 0;\n}', 'int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)\n{\n int i, count, ret, read_size, j;\n AVStream *st;\n AVPacket pkt1, *pkt;\n int64_t old_offset = avio_tell(ic->pb);\n int orig_nb_streams = ic->nb_streams;\n for(i=0;i<ic->nb_streams;i++) {\n AVCodec *codec;\n AVDictionary *thread_opt = NULL;\n st = ic->streams[i];\n if (!st->parser && !(ic->flags & AVFMT_FLAG_NOPARSE)) {\n st->parser = av_parser_init(st->codec->codec_id);\n if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){\n st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;\n }\n }\n codec = st->codec->codec ? st->codec->codec :\n avcodec_find_decoder(st->codec->codec_id);\n av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0);\n if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE\n && codec && !st->codec->codec)\n avcodec_open2(st->codec, codec, options ? &options[i]\n : &thread_opt);\n if(!has_codec_parameters(st->codec)){\n if (codec && !st->codec->codec)\n avcodec_open2(st->codec, codec, options ? &options[i]\n : &thread_opt);\n }\n if (!options)\n av_dict_free(&thread_opt);\n }\n for (i=0; i<ic->nb_streams; i++) {\n ic->streams[i]->info->last_dts = AV_NOPTS_VALUE;\n }\n count = 0;\n read_size = 0;\n for(;;) {\n if (ff_check_interrupt(&ic->interrupt_callback)){\n ret= AVERROR_EXIT;\n av_log(ic, AV_LOG_DEBUG, "interrupted\\n");\n break;\n }\n for(i=0;i<ic->nb_streams;i++) {\n int fps_analyze_framecount = 20;\n st = ic->streams[i];\n if (!has_codec_parameters(st->codec))\n break;\n if (av_q2d(st->time_base) > 0.0005)\n fps_analyze_framecount *= 2;\n if (ic->fps_probe_size >= 0)\n fps_analyze_framecount = ic->fps_probe_size;\n if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num)\n && st->info->duration_count < fps_analyze_framecount\n && st->codec->codec_type == AVMEDIA_TYPE_VIDEO)\n break;\n if(st->parser && st->parser->parser->split && !st->codec->extradata)\n break;\n if(st->first_dts == AV_NOPTS_VALUE)\n break;\n }\n if (i == ic->nb_streams) {\n if (!(ic->ctx_flags & AVFMTCTX_NOHEADER)) {\n ret = count;\n av_log(ic, AV_LOG_DEBUG, "All info found\\n");\n break;\n }\n }\n if (read_size >= ic->probesize) {\n ret = count;\n av_log(ic, AV_LOG_DEBUG, "Probe buffer size limit %d reached\\n", ic->probesize);\n break;\n }\n ret = read_frame_internal(ic, &pkt1);\n if (ret == AVERROR(EAGAIN))\n continue;\n if (ret < 0) {\n AVPacket empty_pkt = { 0 };\n int err;\n av_init_packet(&empty_pkt);\n ret = -1;\n for(i=0;i<ic->nb_streams;i++) {\n st = ic->streams[i];\n do {\n err = try_decode_frame(st, &empty_pkt,\n (options && i < orig_nb_streams) ?\n &options[i] : NULL);\n } while (err > 0 && !has_codec_parameters(st->codec));\n if (err < 0) {\n av_log(ic, AV_LOG_WARNING,\n "decoding for stream %d failed\\n", st->index);\n } else if (!has_codec_parameters(st->codec)){\n char buf[256];\n avcodec_string(buf, sizeof(buf), st->codec, 0);\n av_log(ic, AV_LOG_WARNING,\n "Could not find codec parameters (%s)\\n", buf);\n } else {\n ret = 0;\n }\n }\n break;\n }\n pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end);\n if ((ret = av_dup_packet(pkt)) < 0)\n goto find_stream_info_err;\n read_size += pkt->size;\n st = ic->streams[pkt->stream_index];\n if (st->codec_info_nb_frames>1) {\n if (st->time_base.den > 0 && av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) {\n av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\\n");\n break;\n }\n st->info->codec_info_duration += pkt->duration;\n }\n {\n int64_t last = st->info->last_dts;\n if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && pkt->dts > last){\n int64_t duration= pkt->dts - last;\n double dur= duration * av_q2d(st->time_base);\n if (st->info->duration_count < 2)\n memset(st->info->duration_error, 0, sizeof(st->info->duration_error));\n for (i=1; i<FF_ARRAY_ELEMS(st->info->duration_error); i++) {\n int framerate= get_std_framerate(i);\n int ticks= lrintf(dur*framerate/(1001*12));\n double error = dur - (double)ticks*1001*12 / framerate;\n st->info->duration_error[i] += error*error;\n }\n st->info->duration_count++;\n if (st->info->duration_count > 3)\n st->info->duration_gcd = av_gcd(st->info->duration_gcd, duration);\n }\n if (last == AV_NOPTS_VALUE || st->info->duration_count <= 1)\n st->info->last_dts = pkt->dts;\n }\n if(st->parser && st->parser->parser->split && !st->codec->extradata){\n int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);\n if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) {\n st->codec->extradata_size= i;\n st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);\n if (!st->codec->extradata)\n return AVERROR(ENOMEM);\n memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size);\n memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE);\n }\n }\n try_decode_frame(st, pkt, (options && i < orig_nb_streams ) ? &options[i] : NULL);\n st->codec_info_nb_frames++;\n count++;\n }\n for(i=0;i<ic->nb_streams;i++) {\n st = ic->streams[i];\n avcodec_close(st->codec);\n }\n for(i=0;i<ic->nb_streams;i++) {\n st = ic->streams[i];\n if (st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && st->info->codec_info_duration)\n av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,\n (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den,\n st->info->codec_info_duration*(int64_t)st->time_base.num, 60000);\n if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > 1 && !st->r_frame_rate.num)\n av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX);\n if (st->info->duration_count && !st->r_frame_rate.num\n && tb_unreliable(st->codec) ){\n int num = 0;\n double best_error= 2*av_q2d(st->time_base);\n best_error = best_error*best_error*st->info->duration_count*1000*12*30;\n for (j=1; j<FF_ARRAY_ELEMS(st->info->duration_error); j++) {\n double error = st->info->duration_error[j] * get_std_framerate(j);\n if(error < best_error){\n best_error= error;\n num = get_std_framerate(j);\n }\n }\n if (num && (!st->r_frame_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(st->r_frame_rate)))\n av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX);\n }\n }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {\n if(!st->codec->bits_per_coded_sample)\n st->codec->bits_per_coded_sample= av_get_bits_per_sample(st->codec->codec_id);\n switch (st->codec->audio_service_type) {\n case AV_AUDIO_SERVICE_TYPE_EFFECTS:\n st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; break;\n case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:\n st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; break;\n case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:\n st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; break;\n case AV_AUDIO_SERVICE_TYPE_COMMENTARY:\n st->disposition = AV_DISPOSITION_COMMENT; break;\n case AV_AUDIO_SERVICE_TYPE_KARAOKE:\n st->disposition = AV_DISPOSITION_KARAOKE; break;\n }\n }\n }\n estimate_timings(ic, old_offset);\n compute_chapters_end(ic);\n#if 0\n for(i=0;i<ic->nb_streams;i++) {\n st = ic->streams[i];\n if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {\n if(b-frames){\n ppktl = &ic->packet_buffer;\n while(ppkt1){\n if(ppkt1->stream_index != i)\n continue;\n if(ppkt1->pkt->dts < 0)\n break;\n if(ppkt1->pkt->pts != AV_NOPTS_VALUE)\n break;\n ppkt1->pkt->dts -= delta;\n ppkt1= ppkt1->next;\n }\n if(ppkt1)\n continue;\n st->cur_dts -= delta;\n }\n }\n }\n#endif\n find_stream_info_err:\n for (i=0; i < ic->nb_streams; i++) {\n if (ic->streams[i]->codec)\n ic->streams[i]->codec->thread_count = 0;\n av_freep(&ic->streams[i]->info);\n }\n return ret;\n}', 'static void estimate_timings(AVFormatContext *ic, int64_t old_offset)\n{\n int64_t file_size;\n if (ic->iformat->flags & AVFMT_NOFILE) {\n file_size = 0;\n } else {\n file_size = avio_size(ic->pb);\n file_size = FFMAX(0, file_size);\n }\n if ((!strcmp(ic->iformat->name, "mpeg") ||\n !strcmp(ic->iformat->name, "mpegts")) &&\n file_size && ic->pb->seekable) {\n estimate_timings_from_pts(ic, old_offset);\n } else if (has_duration(ic)) {\n fill_all_stream_timings(ic);\n } else {\n av_log(ic, AV_LOG_WARNING, "Estimating duration from bitrate, this may be inaccurate\\n");\n estimate_timings_from_bit_rate(ic);\n }\n update_stream_timings(ic);\n {\n int i;\n AVStream av_unused *st;\n for(i = 0;i < ic->nb_streams; i++) {\n st = ic->streams[i];\n av_dlog(ic, "%d: start_time: %0.3f duration: %0.3f\\n", i,\n (double) st->start_time / AV_TIME_BASE,\n (double) st->duration / AV_TIME_BASE);\n }\n av_dlog(ic, "stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\\n",\n (double) ic->start_time / AV_TIME_BASE,\n (double) ic->duration / AV_TIME_BASE,\n ic->bit_rate / 1000);\n }\n}', 'static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)\n{\n AVPacket pkt1, *pkt = &pkt1;\n AVStream *st;\n int read_size, i, ret;\n int64_t end_time;\n int64_t filesize, offset, duration;\n int retry=0;\n ic->cur_st = NULL;\n flush_packet_queue(ic);\n for (i=0; i<ic->nb_streams; i++) {\n st = ic->streams[i];\n if (st->start_time == AV_NOPTS_VALUE && st->first_dts == AV_NOPTS_VALUE)\n av_log(st->codec, AV_LOG_WARNING, "start time is not set in estimate_timings_from_pts\\n");\n if (st->parser) {\n av_parser_close(st->parser);\n st->parser= NULL;\n av_free_packet(&st->cur_pkt);\n }\n }\n filesize = ic->pb ? avio_size(ic->pb) : 0;\n end_time = AV_NOPTS_VALUE;\n do{\n offset = filesize - (DURATION_MAX_READ_SIZE<<retry);\n if (offset < 0)\n offset = 0;\n avio_seek(ic->pb, offset, SEEK_SET);\n read_size = 0;\n for(;;) {\n if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0)))\n break;\n do {\n ret = av_read_packet(ic, pkt);\n } while(ret == AVERROR(EAGAIN));\n if (ret != 0)\n break;\n read_size += pkt->size;\n st = ic->streams[pkt->stream_index];\n if (pkt->pts != AV_NOPTS_VALUE &&\n (st->start_time != AV_NOPTS_VALUE ||\n st->first_dts != AV_NOPTS_VALUE)) {\n duration = end_time = pkt->pts;\n if (st->start_time != AV_NOPTS_VALUE)\n duration -= st->start_time;\n else\n duration -= st->first_dts;\n if (duration < 0)\n duration += 1LL<<st->pts_wrap_bits;\n if (duration > 0) {\n if (st->duration == AV_NOPTS_VALUE || st->duration < duration)\n st->duration = duration;\n }\n }\n av_free_packet(pkt);\n }\n }while( end_time==AV_NOPTS_VALUE\n && filesize > (DURATION_MAX_READ_SIZE<<retry)\n && ++retry <= DURATION_MAX_RETRY);\n fill_all_stream_timings(ic);\n avio_seek(ic->pb, old_offset, SEEK_SET);\n for (i=0; i<ic->nb_streams; i++) {\n st= ic->streams[i];\n st->cur_dts= st->first_dts;\n st->last_IP_pts = AV_NOPTS_VALUE;\n st->reference_dts = AV_NOPTS_VALUE;\n }\n}', 'static void flush_packet_queue(AVFormatContext *s)\n{\n free_packet_buffer(&s->packet_buffer, &s->packet_buffer_end);\n free_packet_buffer(&s->raw_packet_buffer, &s->raw_packet_buffer_end);\n s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;\n}', 'static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end)\n{\n while (*pkt_buf) {\n AVPacketList *pktl = *pkt_buf;\n *pkt_buf = pktl->next;\n av_free_packet(&pktl->pkt);\n av_freep(&pktl);\n }\n *pkt_buf_end = NULL;\n}', 'void av_log(void* avcl, int level, const char *fmt, ...)\n{\n AVClass* avc = avcl ? *(AVClass **) avcl : NULL;\n va_list vl;\n va_start(vl, fmt);\n if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&\n avc->log_level_offset_offset && level >= AV_LOG_FATAL)\n level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);\n av_vlog(avcl, level, fmt, vl);\n va_end(vl);\n}', 'void avformat_close_input(AVFormatContext **ps)\n{\n AVFormatContext *s = *ps;\n AVIOContext *pb = (s->iformat->flags & AVFMT_NOFILE) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ?\n NULL : s->pb;\n flush_packet_queue(s);\n if (s->iformat->read_close)\n s->iformat->read_close(s);\n avformat_free_context(s);\n *ps = NULL;\n if (pb)\n avio_close(pb);\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 if (st->attached_pic.data)\n av_free_packet(&st->attached_pic);\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}']
|
936
| 0
|
https://github.com/openssl/openssl/blob/bf55ece1c17d31f082e3a7df44e605218b1f03f1/crypto/rijndael/rijndael-alg-fst.c/#L39
|
int rijndaelKeySched(const word8 k[RIJNDAEL_MAXKC][4],
word8 W[RIJNDAEL_MAXROUNDS+1][4][4],int ROUNDS)
{
int j, r, t, rconpointer = 0;
word8 tk[RIJNDAEL_MAXKC][4];
int KC = ROUNDS - 6;
for (j = KC-1; j >= 0; j--)
*((word32*)tk[j]) = *((word32*)k[j]);
r = 0;
t = 0;
for (j = 0; (j < KC) && (r < ROUNDS + 1); )
{
for (; (j < KC) && (t < 4); j++, t++)
*((word32*)W[r][t]) = *((word32*)tk[j]);
if (t == 4)
{
r++;
t = 0;
}
}
while (r < ROUNDS + 1)
{
tk[0][0] ^= S[tk[KC-1][1]];
tk[0][1] ^= S[tk[KC-1][2]];
tk[0][2] ^= S[tk[KC-1][3]];
tk[0][3] ^= S[tk[KC-1][0]];
tk[0][0] ^= rcon[rconpointer++];
if (KC != 8)
{
for (j = 1; j < KC; j++)
{
*((word32*)tk[j]) ^= *((word32*)tk[j-1]);
}
}
else
{
for (j = 1; j < KC/2; j++)
{
*((word32*)tk[j]) ^= *((word32*)tk[j-1]);
}
tk[KC/2][0] ^= S[tk[KC/2 - 1][0]];
tk[KC/2][1] ^= S[tk[KC/2 - 1][1]];
tk[KC/2][2] ^= S[tk[KC/2 - 1][2]];
tk[KC/2][3] ^= S[tk[KC/2 - 1][3]];
for (j = KC/2 + 1; j < KC; j++)
{
*((word32*)tk[j]) ^= *((word32*)tk[j-1]);
}
}
for (j = 0; (j < KC) && (r < ROUNDS + 1); )
{
for (; (j < KC) && (t < 4); j++, t++)
{
*((word32*)W[r][t]) = *((word32*)tk[j]);
}
if (t == 4)
{
r++;
t = 0;
}
}
}
return 0;
}
|
['int rijndaelKeySched(const word8 k[RIJNDAEL_MAXKC][4],\n\t\t word8 W[RIJNDAEL_MAXROUNDS+1][4][4],int ROUNDS)\n {\n int j, r, t, rconpointer = 0;\n word8 tk[RIJNDAEL_MAXKC][4];\n int KC = ROUNDS - 6;\n for (j = KC-1; j >= 0; j--)\n\t*((word32*)tk[j]) = *((word32*)k[j]);\n r = 0;\n t = 0;\n for (j = 0; (j < KC) && (r < ROUNDS + 1); )\n\t{\n\tfor (; (j < KC) && (t < 4); j++, t++)\n\t *((word32*)W[r][t]) = *((word32*)tk[j]);\n\tif (t == 4)\n\t {\n\t r++;\n\t t = 0;\n\t }\n\t}\n while (r < ROUNDS + 1)\n\t{\n\ttk[0][0] ^= S[tk[KC-1][1]];\n\ttk[0][1] ^= S[tk[KC-1][2]];\n\ttk[0][2] ^= S[tk[KC-1][3]];\n\ttk[0][3] ^= S[tk[KC-1][0]];\n\ttk[0][0] ^= rcon[rconpointer++];\n\tif (KC != 8)\n\t {\n\t for (j = 1; j < KC; j++)\n\t\t{\n\t\t*((word32*)tk[j]) ^= *((word32*)tk[j-1]);\n\t\t}\n\t }\n\telse\n\t {\n\t for (j = 1; j < KC/2; j++)\n\t\t{\n\t\t*((word32*)tk[j]) ^= *((word32*)tk[j-1]);\n\t\t}\n\t tk[KC/2][0] ^= S[tk[KC/2 - 1][0]];\n\t tk[KC/2][1] ^= S[tk[KC/2 - 1][1]];\n\t tk[KC/2][2] ^= S[tk[KC/2 - 1][2]];\n\t tk[KC/2][3] ^= S[tk[KC/2 - 1][3]];\n\t for (j = KC/2 + 1; j < KC; j++)\n\t\t{\n\t\t*((word32*)tk[j]) ^= *((word32*)tk[j-1]);\n\t\t}\n\t }\n\tfor (j = 0; (j < KC) && (r < ROUNDS + 1); )\n\t {\n\t for (; (j < KC) && (t < 4); j++, t++)\n\t\t{\n\t\t*((word32*)W[r][t]) = *((word32*)tk[j]);\n\t\t}\n\t if (t == 4)\n\t\t{\n\t\tr++;\n\t\tt = 0;\n\t\t}\n\t }\n\t}\n return 0;\n }']
|
937
| 0
|
https://github.com/openssl/openssl/blob/3d81ec5b92e1141762eb72caf2aeb9b2cd019a78/crypto/constant_time_locl.h/#L167
|
static inline unsigned int constant_time_is_zero(unsigned int a)
{
return constant_time_msb(~a & (a - 1));
}
|
['static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,\n\t\t const unsigned char *iv,int in,\n\t\t const unsigned char *plaintext,int pn,\n\t\t const unsigned char *ciphertext,int cn,\n\t\t const unsigned char *aad,int an,\n\t\t const unsigned char *tag,int tn,\n\t\t int encdec)\n {\n EVP_CIPHER_CTX *ctx = NULL;\n unsigned char out[4096];\n int outl,outl2,mode;\n printf("Testing cipher %s%s\\n",EVP_CIPHER_name(c),\n\t (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)")));\n hexdump(stdout,"Key",key,kn);\n if(in)\n\thexdump(stdout,"IV",iv,in);\n hexdump(stdout,"Plaintext",plaintext,pn);\n hexdump(stdout,"Ciphertext",ciphertext,cn);\n if (an)\n \thexdump(stdout,"AAD",aad,an);\n if (tn)\n \thexdump(stdout,"Tag",tag,tn);\n mode = EVP_CIPHER_mode(c);\n if(kn != EVP_CIPHER_key_length(c))\n\t{\n\tfprintf(stderr,"Key length doesn\'t match, got %d expected %lu\\n",kn,\n\t\t(unsigned long)EVP_CIPHER_key_length(c));\n\ttest1_exit(5);\n\t}\n ctx = EVP_CIPHER_CTX_new();\n EVP_CIPHER_CTX_set_flags(ctx,EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);\n if (encdec != 0)\n {\n\tif (mode == EVP_CIPH_GCM_MODE)\n\t {\n\t if(!EVP_EncryptInit_ex(ctx,c,NULL,NULL,NULL))\n\t {\n\t\tfprintf(stderr,"EncryptInit failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(10);\n\t\t}\n\t if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL))\n\t {\n\t\tfprintf(stderr,"IV length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(11);\n\t\t}\n\t if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv))\n\t {\n\t\tfprintf(stderr,"Key/IV set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(12);\n\t\t}\n\t if (an && !EVP_EncryptUpdate(ctx,NULL,&outl,aad,an))\n\t {\n\t\tfprintf(stderr,"AAD set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(13);\n\t\t}\n\t }\n\telse if (mode == EVP_CIPH_CCM_MODE)\n\t {\n\t if(!EVP_EncryptInit_ex(ctx,c,NULL,NULL,NULL))\n\t {\n\t\tfprintf(stderr,"EncryptInit failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(10);\n\t\t}\n\t if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN, in, NULL))\n\t {\n\t\tfprintf(stderr,"IV length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(11);\n\t\t}\n\t if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tn, NULL))\n\t {\n\t\tfprintf(stderr,"Tag length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(11);\n\t\t}\n\t if(!EVP_EncryptInit_ex(ctx,NULL,NULL,key,iv))\n\t {\n\t\tfprintf(stderr,"Key/IV set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(12);\n\t\t}\n\t if (!EVP_EncryptUpdate(ctx,NULL,&outl,NULL,pn))\n\t {\n\t\tfprintf(stderr,"Plaintext length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(12);\n\t\t}\n\t if (an && !EVP_EncryptUpdate(ctx,NULL,&outl,aad,an))\n\t {\n\t\tfprintf(stderr,"AAD set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(13);\n\t\t}\n\t }\n\telse if (mode == EVP_CIPH_WRAP_MODE)\n\t {\n\t if(!EVP_EncryptInit_ex(ctx,c,NULL,key,in ? iv : NULL))\n\t {\n\t\tfprintf(stderr,"EncryptInit failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(10);\n\t\t}\n\t }\n\telse if(!EVP_EncryptInit_ex(ctx,c,NULL,key,iv))\n\t {\n\t fprintf(stderr,"EncryptInit failed\\n");\n\t ERR_print_errors_fp(stderr);\n\t test1_exit(10);\n\t }\n\tEVP_CIPHER_CTX_set_padding(ctx,0);\n\ttest_ctx_replace(&ctx);\n\tif(!EVP_EncryptUpdate(ctx,out,&outl,plaintext,pn))\n\t {\n\t fprintf(stderr,"Encrypt failed\\n");\n\t ERR_print_errors_fp(stderr);\n\t test1_exit(6);\n\t }\n\tif(!EVP_EncryptFinal_ex(ctx,out+outl,&outl2))\n\t {\n\t fprintf(stderr,"EncryptFinal failed\\n");\n\t ERR_print_errors_fp(stderr);\n\t test1_exit(7);\n\t }\n\tif(outl+outl2 != cn)\n\t {\n\t fprintf(stderr,"Ciphertext length mismatch got %d expected %d\\n",\n\t\t outl+outl2,cn);\n\t test1_exit(8);\n\t }\n\tif(memcmp(out,ciphertext,cn))\n\t {\n\t fprintf(stderr,"Ciphertext mismatch\\n");\n\t hexdump(stderr,"Got",out,cn);\n\t hexdump(stderr,"Expected",ciphertext,cn);\n\t test1_exit(9);\n\t }\n\tif (mode == EVP_CIPH_GCM_MODE || mode == EVP_CIPH_CCM_MODE)\n\t {\n\t unsigned char rtag[16];\n\t if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, tn, rtag))\n\t {\n\t\tfprintf(stderr,"Get tag failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(14);\n\t\t}\n\t if (memcmp(rtag, tag, tn))\n\t\t{\n\t\tfprintf(stderr,"Tag mismatch\\n");\n\t\thexdump(stderr,"Got",rtag,tn);\n\t\thexdump(stderr,"Expected",tag,tn);\n\t\ttest1_exit(9);\n\t \t}\n\t }\n\t}\n if (encdec <= 0)\n {\n\tif (mode == EVP_CIPH_GCM_MODE)\n\t {\n\t if(!EVP_DecryptInit_ex(ctx,c,NULL,NULL,NULL))\n\t {\n\t\tfprintf(stderr,"EncryptInit failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(10);\n\t\t}\n\t if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, in, NULL))\n\t {\n\t\tfprintf(stderr,"IV length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(11);\n\t\t}\n\t if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv))\n\t {\n\t\tfprintf(stderr,"Key/IV set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(12);\n\t\t}\n\t if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, tn, (void *)tag))\n\t {\n\t\tfprintf(stderr,"Set tag failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(14);\n\t\t}\n\t if (an && !EVP_DecryptUpdate(ctx,NULL,&outl,aad,an))\n\t {\n\t\tfprintf(stderr,"AAD set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(13);\n\t\t}\n\t }\n\telse if (mode == EVP_CIPH_CCM_MODE)\n\t {\n\t if(!EVP_DecryptInit_ex(ctx,c,NULL,NULL,NULL))\n\t {\n\t\tfprintf(stderr,"DecryptInit failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(10);\n\t\t}\n\t if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_IVLEN, in, NULL))\n\t {\n\t\tfprintf(stderr,"IV length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(11);\n\t\t}\n\t if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_SET_TAG, tn, (void *)tag))\n\t {\n\t\tfprintf(stderr,"Tag length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(11);\n\t\t}\n\t if(!EVP_DecryptInit_ex(ctx,NULL,NULL,key,iv))\n\t {\n\t\tfprintf(stderr,"Key/Nonce set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(12);\n\t\t}\n\t if (!EVP_DecryptUpdate(ctx,NULL,&outl,NULL,pn))\n\t {\n\t\tfprintf(stderr,"Plaintext length set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(12);\n\t\t}\n\t if (an && !EVP_EncryptUpdate(ctx,NULL,&outl,aad,an))\n\t {\n\t\tfprintf(stderr,"AAD set failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(13);\n\t\t}\n\t }\n\telse if (mode == EVP_CIPH_WRAP_MODE)\n\t {\n\t if(!EVP_DecryptInit_ex(ctx,c,NULL,key,in ? iv : NULL))\n\t {\n\t\tfprintf(stderr,"EncryptInit failed\\n");\n\t\tERR_print_errors_fp(stderr);\n\t\ttest1_exit(10);\n\t\t}\n\t }\n\telse if(!EVP_DecryptInit_ex(ctx,c,NULL,key,iv))\n\t {\n\t fprintf(stderr,"DecryptInit failed\\n");\n\t ERR_print_errors_fp(stderr);\n\t test1_exit(11);\n\t }\n\tEVP_CIPHER_CTX_set_padding(ctx,0);\n\ttest_ctx_replace(&ctx);\n\tif(!EVP_DecryptUpdate(ctx,out,&outl,ciphertext,cn))\n\t {\n\t fprintf(stderr,"Decrypt failed\\n");\n\t ERR_print_errors_fp(stderr);\n\t test1_exit(6);\n\t }\n\tif(mode != EVP_CIPH_CCM_MODE && !EVP_DecryptFinal_ex(ctx,out+outl,&outl2))\n\t {\n\t fprintf(stderr,"DecryptFinal failed\\n");\n\t ERR_print_errors_fp(stderr);\n\t test1_exit(7);\n\t }\n\tif(outl+outl2 != pn)\n\t {\n\t fprintf(stderr,"Plaintext length mismatch got %d expected %d\\n",\n\t\t outl+outl2,pn);\n\t test1_exit(8);\n\t }\n\tif(memcmp(out,plaintext,pn))\n\t {\n\t fprintf(stderr,"Plaintext mismatch\\n");\n\t hexdump(stderr,"Got",out,pn);\n\t hexdump(stderr,"Expected",plaintext,pn);\n\t test1_exit(9);\n\t }\n\t}\n EVP_CIPHER_CTX_free(ctx);\n printf("\\n");\n }', 'int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)\n\t{\n\tunsigned int i, b;\n unsigned char pad, padding_good;\n\t*outl=0;\n\tif (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER)\n\t\t{\n\t\tint ret = ctx->cipher->do_cipher(ctx, out, NULL, 0);\n\t\tif (ret < 0)\n\t\t\treturn 0;\n\t\telse\n\t\t\t*outl = ret;\n\t\treturn 1;\n\t\t}\n\tb=(unsigned int)(ctx->cipher->block_size);\n\tif (ctx->flags & EVP_CIPH_NO_PADDING)\n\t\t{\n\t\tif(ctx->buf_len)\n\t\t\t{\n\t\t\tEVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);\n\t\t\treturn 0;\n\t\t\t}\n\t\t*outl = 0;\n\t\treturn 1;\n\t\t}\n\tif (b > 1)\n\t\t{\n\t\tif (ctx->buf_len || !ctx->final_used)\n\t\t\t{\n\t\t\tEVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH);\n\t\t\treturn(0);\n\t\t\t}\n\t\tOPENSSL_assert(b <= sizeof ctx->final);\n\t\tpad=ctx->final[b-1];\n\t\tpadding_good = (unsigned char)(~constant_time_is_zero_8(pad));\n\t\tpadding_good &= constant_time_ge_8(b, pad);\n for (i = 1; i < b; ++i)\n\t\t\t{\n\t\t\tunsigned char is_pad_index = constant_time_lt_8(i, pad);\n\t\t\tunsigned char pad_byte_good = constant_time_eq_8(ctx->final[b-i-1], pad);\n\t\t\tpadding_good &= constant_time_select_8(is_pad_index, pad_byte_good, 0xff);\n\t\t\t}\n\t\tfor (i = 0; i < b - 1; ++i)\n\t\t\tout[i] = ctx->final[i] & padding_good;\n\t\t*outl = padding_good & ((unsigned char)(b - pad));\n\t\treturn padding_good & 1;\n\t\t}\n\telse\n\t\t{\n\t\t*outl = 0;\n\t\treturn 1;\n\t\t}\n\t}', 'static inline unsigned char constant_time_is_zero_8(unsigned int a)\n\t{\n\treturn (unsigned char)(constant_time_is_zero(a));\n\t}', 'static inline unsigned int constant_time_is_zero(unsigned int a)\n\t{\n\treturn constant_time_msb(~a & (a - 1));\n\t}']
|
938
| 0
|
https://github.com/libav/libav/blob/dc2cabd003d264644926b3b4326ed3792405f953/libavformat/mms.c/#L111
|
int ff_mms_asf_header_parser(MMSContext *mms)
{
uint8_t *p = mms->asf_header;
uint8_t *end;
int flags, stream_id;
mms->stream_num = 0;
if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||
memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {
av_log(NULL, AV_LOG_ERROR,
"Corrupt stream (invalid ASF header, size=%d)\n",
mms->asf_header_size);
return AVERROR_INVALIDDATA;
}
end = mms->asf_header + mms->asf_header_size;
p += sizeof(ff_asf_guid) + 14;
while(end - p >= sizeof(ff_asf_guid) + 8) {
uint64_t chunksize;
if (!memcmp(p, ff_asf_data_header, sizeof(ff_asf_guid))) {
chunksize = 50;
} else {
chunksize = AV_RL64(p + sizeof(ff_asf_guid));
}
if (!chunksize || chunksize > end - p) {
av_log(NULL, AV_LOG_ERROR,
"Corrupt stream (header chunksize %"PRId64" is invalid)\n",
chunksize);
return AVERROR_INVALIDDATA;
}
if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {
if (end - p > sizeof(ff_asf_guid) * 2 + 68) {
mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);
if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {
av_log(NULL, AV_LOG_ERROR,
"Corrupt stream (too large pkt_len %d)\n",
mms->asf_packet_len);
return AVERROR_INVALIDDATA;
}
}
} else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {
flags = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);
stream_id = flags & 0x7F;
if (mms->stream_num < MMS_MAX_STREAMS &&
46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {
mms->streams = av_fast_realloc(mms->streams,
&mms->nb_streams_allocated,
(mms->stream_num + 1) * sizeof(MMSStream));
mms->streams[mms->stream_num].id = stream_id;
mms->stream_num++;
} else {
av_log(NULL, AV_LOG_ERROR,
"Corrupt stream (too many A/V streams)\n");
return AVERROR_INVALIDDATA;
}
} else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {
chunksize = 46;
}
p += chunksize;
}
return 0;
}
|
['int ff_mms_asf_header_parser(MMSContext *mms)\n{\n uint8_t *p = mms->asf_header;\n uint8_t *end;\n int flags, stream_id;\n mms->stream_num = 0;\n if (mms->asf_header_size < sizeof(ff_asf_guid) * 2 + 22 ||\n memcmp(p, ff_asf_header, sizeof(ff_asf_guid))) {\n av_log(NULL, AV_LOG_ERROR,\n "Corrupt stream (invalid ASF header, size=%d)\\n",\n mms->asf_header_size);\n return AVERROR_INVALIDDATA;\n }\n end = mms->asf_header + mms->asf_header_size;\n p += sizeof(ff_asf_guid) + 14;\n while(end - p >= sizeof(ff_asf_guid) + 8) {\n uint64_t chunksize;\n if (!memcmp(p, ff_asf_data_header, sizeof(ff_asf_guid))) {\n chunksize = 50;\n } else {\n chunksize = AV_RL64(p + sizeof(ff_asf_guid));\n }\n if (!chunksize || chunksize > end - p) {\n av_log(NULL, AV_LOG_ERROR,\n "Corrupt stream (header chunksize %"PRId64" is invalid)\\n",\n chunksize);\n return AVERROR_INVALIDDATA;\n }\n if (!memcmp(p, ff_asf_file_header, sizeof(ff_asf_guid))) {\n if (end - p > sizeof(ff_asf_guid) * 2 + 68) {\n mms->asf_packet_len = AV_RL32(p + sizeof(ff_asf_guid) * 2 + 64);\n if (mms->asf_packet_len <= 0 || mms->asf_packet_len > sizeof(mms->in_buffer)) {\n av_log(NULL, AV_LOG_ERROR,\n "Corrupt stream (too large pkt_len %d)\\n",\n mms->asf_packet_len);\n return AVERROR_INVALIDDATA;\n }\n }\n } else if (!memcmp(p, ff_asf_stream_header, sizeof(ff_asf_guid))) {\n flags = AV_RL16(p + sizeof(ff_asf_guid)*3 + 24);\n stream_id = flags & 0x7F;\n if (mms->stream_num < MMS_MAX_STREAMS &&\n 46 + mms->stream_num * 6 < sizeof(mms->out_buffer)) {\n mms->streams = av_fast_realloc(mms->streams,\n &mms->nb_streams_allocated,\n (mms->stream_num + 1) * sizeof(MMSStream));\n mms->streams[mms->stream_num].id = stream_id;\n mms->stream_num++;\n } else {\n av_log(NULL, AV_LOG_ERROR,\n "Corrupt stream (too many A/V streams)\\n");\n return AVERROR_INVALIDDATA;\n }\n } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) {\n chunksize = 46;\n }\n p += chunksize;\n }\n return 0;\n}', 'void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)\n{\n if(min_size < *size)\n return ptr;\n *size= FFMAX(17*min_size/16 + 32, min_size);\n ptr= av_realloc(ptr, *size);\n if(!ptr)\n *size= 0;\n return ptr;\n}', 'void *av_realloc(void *ptr, unsigned int size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}']
|
939
| 0
|
https://github.com/libav/libav/blob/9993a067f6c8c7e7838052ac3146aa6b80dd7e81/libavcodec/mpegvideo_enc.c/#L1432
|
static void frame_end(MpegEncContext *s)
{
int i;
if (s->unrestricted_mv &&
s->current_picture.reference &&
!s->intra_only) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
int hshift = desc->log2_chroma_w;
int vshift = desc->log2_chroma_h;
s->mpvencdsp.draw_edges(s->current_picture.f->data[0], s->linesize,
s->h_edge_pos, s->v_edge_pos,
EDGE_WIDTH, EDGE_WIDTH,
EDGE_TOP | EDGE_BOTTOM);
s->mpvencdsp.draw_edges(s->current_picture.f->data[1], s->uvlinesize,
s->h_edge_pos >> hshift,
s->v_edge_pos >> vshift,
EDGE_WIDTH >> hshift,
EDGE_WIDTH >> vshift,
EDGE_TOP | EDGE_BOTTOM);
s->mpvencdsp.draw_edges(s->current_picture.f->data[2], s->uvlinesize,
s->h_edge_pos >> hshift,
s->v_edge_pos >> vshift,
EDGE_WIDTH >> hshift,
EDGE_WIDTH >> vshift,
EDGE_TOP | EDGE_BOTTOM);
}
emms_c();
s->last_pict_type = s->pict_type;
s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality;
if (s->pict_type!= AV_PICTURE_TYPE_B)
s->last_non_b_pict_type = s->pict_type;
if (s->encoding) {
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
if (!s->picture[i].reference)
ff_mpeg_unref_picture(s, &s->picture[i]);
}
}
s->avctx->coded_frame = s->current_picture_ptr->f;
}
|
['static void frame_end(MpegEncContext *s)\n{\n int i;\n if (s->unrestricted_mv &&\n s->current_picture.reference &&\n !s->intra_only) {\n const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);\n int hshift = desc->log2_chroma_w;\n int vshift = desc->log2_chroma_h;\n s->mpvencdsp.draw_edges(s->current_picture.f->data[0], s->linesize,\n s->h_edge_pos, s->v_edge_pos,\n EDGE_WIDTH, EDGE_WIDTH,\n EDGE_TOP | EDGE_BOTTOM);\n s->mpvencdsp.draw_edges(s->current_picture.f->data[1], s->uvlinesize,\n s->h_edge_pos >> hshift,\n s->v_edge_pos >> vshift,\n EDGE_WIDTH >> hshift,\n EDGE_WIDTH >> vshift,\n EDGE_TOP | EDGE_BOTTOM);\n s->mpvencdsp.draw_edges(s->current_picture.f->data[2], s->uvlinesize,\n s->h_edge_pos >> hshift,\n s->v_edge_pos >> vshift,\n EDGE_WIDTH >> hshift,\n EDGE_WIDTH >> vshift,\n EDGE_TOP | EDGE_BOTTOM);\n }\n emms_c();\n s->last_pict_type = s->pict_type;\n s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f->quality;\n if (s->pict_type!= AV_PICTURE_TYPE_B)\n s->last_non_b_pict_type = s->pict_type;\n if (s->encoding) {\n for (i = 0; i < MAX_PICTURE_COUNT; i++) {\n if (!s->picture[i].reference)\n ff_mpeg_unref_picture(s, &s->picture[i]);\n }\n }\n s->avctx->coded_frame = s->current_picture_ptr->f;\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n return NULL;\n return &av_pix_fmt_descriptors[pix_fmt];\n}']
|
940
| 0
|
https://github.com/openssl/openssl/blob/3ec9e4ec46eb4356bc106db5e0e33148c693c8f0/crypto/lhash/lhash.c/#L139
|
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;
}
|
['OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,\n const char *host, const char *path,\n const char *port, int use_ssl,\n STACK_OF(CONF_VALUE) *headers,\n int req_timeout)\n{\n BIO *cbio = NULL;\n SSL_CTX *ctx = NULL;\n OCSP_RESPONSE *resp = NULL;\n cbio = BIO_new_connect(host);\n if (cbio == NULL) {\n BIO_printf(bio_err, "Error creating connect BIO\\n");\n goto end;\n }\n if (port != NULL)\n BIO_set_conn_port(cbio, port);\n if (use_ssl == 1) {\n BIO *sbio;\n ctx = SSL_CTX_new(TLS_client_method());\n if (ctx == NULL) {\n BIO_printf(bio_err, "Error creating SSL context.\\n");\n goto end;\n }\n SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);\n sbio = BIO_new_ssl(ctx, 1);\n cbio = BIO_push(sbio, cbio);\n }\n resp = query_responder(cbio, host, path, headers, req, req_timeout);\n if (resp == NULL)\n BIO_printf(bio_err, "Error querying OCSP responder\\n");\n end:\n BIO_free_all(cbio);\n SSL_CTX_free(ctx);\n return resp;\n}', 'BIO *BIO_new_ssl(SSL_CTX *ctx, int client)\n{\n BIO *ret;\n SSL *ssl;\n if ((ret = BIO_new(BIO_f_ssl())) == NULL)\n return NULL;\n if ((ssl = SSL_new(ctx)) == NULL) {\n BIO_free(ret);\n return NULL;\n }\n if (client)\n SSL_set_connect_state(ssl);\n else\n SSL_set_accept_state(ssl);\n BIO_set_ssl(ret, ssl, BIO_CLOSE);\n return ret;\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 if (RAND_get_rand_method() == RAND_OpenSSL()) {\n s->drbg =\n RAND_DRBG_new(0, 0, RAND_DRBG_get0_public());\n if (s->drbg == NULL\n || RAND_DRBG_instantiate(s->drbg,\n (const unsigned char *) SSL_version_str,\n sizeof(SSL_version_str) - 1) == 0)\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->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 if (!s->method->ssl_new(s))\n goto err;\n s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n if (!SSL_clear(s))\n goto err;\n if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n goto err;\n#ifndef OPENSSL_NO_PSK\n s->psk_client_callback = ctx->psk_client_callback;\n s->psk_server_callback = ctx->psk_server_callback;\n#endif\n s->psk_find_session_cb = ctx->psk_find_session_cb;\n s->psk_use_session_cb = ctx->psk_use_session_cb;\n s->job = NULL;\n#ifndef OPENSSL_NO_CT\n if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n ctx->ct_validation_callback_arg))\n goto err;\n#endif\n return s;\n err:\n SSL_free(s);\n SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n return NULL;\n}', 'int SSL_clear(SSL *s)\n{\n if (s->method == NULL) {\n SSLerr(SSL_F_SSL_CLEAR, SSL_R_NO_METHOD_SPECIFIED);\n return 0;\n }\n if (ssl_clear_bad_session(s)) {\n SSL_SESSION_free(s->session);\n s->session = NULL;\n }\n SSL_SESSION_free(s->psksession);\n s->psksession = NULL;\n OPENSSL_free(s->psksession_id);\n s->psksession_id = NULL;\n s->psksession_id_len = 0;\n s->hello_retry_request = 0;\n s->error = 0;\n s->hit = 0;\n s->shutdown = 0;\n if (s->renegotiate) {\n SSLerr(SSL_F_SSL_CLEAR, ERR_R_INTERNAL_ERROR);\n return 0;\n }\n ossl_statem_clear(s);\n s->version = s->method->version;\n s->client_version = s->version;\n s->rwstate = SSL_NOTHING;\n BUF_MEM_free(s->init_buf);\n s->init_buf = NULL;\n clear_ciphers(s);\n s->first_packet = 0;\n s->key_update = SSL_KEY_UPDATE_NONE;\n EVP_MD_CTX_free(s->pha_dgst);\n s->pha_dgst = NULL;\n s->dane.mdpth = -1;\n s->dane.pdpth = -1;\n X509_free(s->dane.mcert);\n s->dane.mcert = NULL;\n s->dane.mtlsa = NULL;\n X509_VERIFY_PARAM_move_peername(s->param, NULL);\n if (s->method != s->ctx->method) {\n s->method->ssl_free(s);\n s->method = s->ctx->method;\n if (!s->method->ssl_new(s))\n return 0;\n } else {\n if (!s->method->ssl_clear(s))\n return 0;\n }\n RECORD_LAYER_clear(&s->rlayer);\n return 1;\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n if ((s->session != NULL) &&\n !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n !(SSL_in_init(s) || SSL_in_before(s))) {\n SSL_CTX_remove_session(s->session_ctx, s->session);\n return 1;\n } else\n return 0;\n}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n SSL_SESSION *r;\n int ret = 0;\n if ((c != NULL) && (c->session_id_length != 0)) {\n if (lck)\n CRYPTO_THREAD_write_lock(ctx->lock);\n if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) != 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 (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}']
|
941
| 0
|
https://github.com/openssl/openssl/blob/5d1c09de1f2736e1d4b1877206d08455ec75f558/crypto/bn/bn_lib.c/#L232
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n int retn = 0;\n#ifdef MONT_WORD\n BIGNUM *t;\n BN_CTX_start(ctx);\n if ((t = BN_CTX_get(ctx)) && BN_copy(t, a)) {\n retn = bn_from_montgomery_word(ret, t, mont);\n bn_correct_top(ret);\n bn_check_top(ret);\n }\n BN_CTX_end(ctx);\n#else\n BIGNUM *t1, *t2;\n BN_CTX_start(ctx);\n t1 = BN_CTX_get(ctx);\n t2 = BN_CTX_get(ctx);\n if (t2 == NULL)\n goto err;\n if (!BN_copy(t1, a))\n goto err;\n BN_mask_bits(t1, mont->ri);\n if (!BN_mul(t2, t1, &mont->Ni, ctx))\n goto err;\n BN_mask_bits(t2, mont->ri);\n if (!BN_mul(t1, t2, &mont->N, ctx))\n goto err;\n if (!BN_add(t2, a, t1))\n goto err;\n if (!BN_rshift(ret, t2, mont->ri))\n goto err;\n if (BN_ucmp(ret, &(mont->N)) >= 0) {\n if (!BN_usub(ret, ret, &(mont->N)))\n goto err;\n }\n retn = 1;\n bn_check_top(ret);\n err:\n BN_CTX_end(ctx);\n#endif\n return retn;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG_ENTRY("BN_CTX_get", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ctx->used++;\n CTXDBG_RET(ctx, ret);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
942
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h263.c/#L1448
|
void h263_encode_mb(MpegEncContext * s,
DCTELEM block[6][64],
int motion_x, int motion_y)
{
int cbpc, cbpy, i, cbp, pred_x, pred_y;
int16_t pred_dc;
int16_t rec_intradc[6];
int16_t *dc_ptr[6];
const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1);
const int dquant_code[5]= {1,0,9,2,3};
if (!s->mb_intra) {
cbp= get_p_cbp(s, block, motion_x, motion_y);
if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) {
put_bits(&s->pb, 1, 1);
if(interleaved_stats){
s->misc_bits++;
s->last_bits++;
}
s->skip_count++;
return;
}
put_bits(&s->pb, 1, 0);
cbpc = cbp & 3;
cbpy = cbp >> 2;
if(s->alt_inter_vlc==0 || cbpc!=3)
cbpy ^= 0xF;
if(s->dquant) cbpc+= 8;
if(s->mv_type==MV_TYPE_16X16){
put_bits(&s->pb,
inter_MCBPC_bits[cbpc],
inter_MCBPC_code[cbpc]);
put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
if(s->dquant)
put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
if(interleaved_stats){
s->misc_bits+= get_bits_diff(s);
}
h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
else {
h263p_encode_umotion(s, motion_x - pred_x);
h263p_encode_umotion(s, motion_y - pred_y);
if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
put_bits(&s->pb,1,1);
}
}else{
put_bits(&s->pb,
inter_MCBPC_bits[cbpc+16],
inter_MCBPC_code[cbpc+16]);
put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
if(s->dquant)
put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
if(interleaved_stats){
s->misc_bits+= get_bits_diff(s);
}
for(i=0; i<4; i++){
h263_pred_motion(s, i, 0, &pred_x, &pred_y);
motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
else {
h263p_encode_umotion(s, motion_x - pred_x);
h263p_encode_umotion(s, motion_y - pred_y);
if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
put_bits(&s->pb,1,1);
}
}
}
if(interleaved_stats){
s->mv_bits+= get_bits_diff(s);
}
} else {
assert(s->mb_intra);
cbp = 0;
if (s->h263_aic) {
for(i=0; i<6; i++) {
int16_t level = block[i][0];
int scale;
if(i<4) scale= s->y_dc_scale;
else scale= s->c_dc_scale;
pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
level -= pred_dc;
if (level >= 0)
level = (level + (scale>>1))/scale;
else
level = (level - (scale>>1))/scale;
if (level == 0 && s->block_last_index[i] == 0)
s->block_last_index[i] = -1;
if(!s->modified_quant){
if (level < -127)
level = -127;
else if (level > 127)
level = 127;
}
block[i][0] = level;
rec_intradc[i] = scale*level + pred_dc;
rec_intradc[i] |= 1;
if (rec_intradc[i] < 0)
rec_intradc[i] = 0;
else if (rec_intradc[i] > 2047)
rec_intradc[i] = 2047;
*dc_ptr[i] = rec_intradc[i];
if (s->block_last_index[i] >= 0)
cbp |= 1 << (5 - i);
}
}else{
for(i=0; i<6; i++) {
if (s->block_last_index[i] >= 1)
cbp |= 1 << (5 - i);
}
}
cbpc = cbp & 3;
if (s->pict_type == FF_I_TYPE) {
if(s->dquant) cbpc+=4;
put_bits(&s->pb,
intra_MCBPC_bits[cbpc],
intra_MCBPC_code[cbpc]);
} else {
if(s->dquant) cbpc+=8;
put_bits(&s->pb, 1, 0);
put_bits(&s->pb,
inter_MCBPC_bits[cbpc + 4],
inter_MCBPC_code[cbpc + 4]);
}
if (s->h263_aic) {
put_bits(&s->pb, 1, 0);
}
cbpy = cbp >> 2;
put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);
if(s->dquant)
put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
if(interleaved_stats){
s->misc_bits+= get_bits_diff(s);
}
}
for(i=0; i<6; i++) {
h263_encode_block(s, block[i], i);
if (s->h263_aic && s->mb_intra) {
block[i][0] = rec_intradc[i];
}
}
if(interleaved_stats){
if (!s->mb_intra) {
s->p_tex_bits+= get_bits_diff(s);
s->f_count++;
}else{
s->i_tex_bits+= get_bits_diff(s);
s->i_count++;
}
}
}
|
['void h263_encode_mb(MpegEncContext * s,\n DCTELEM block[6][64],\n int motion_x, int motion_y)\n{\n int cbpc, cbpy, i, cbp, pred_x, pred_y;\n int16_t pred_dc;\n int16_t rec_intradc[6];\n int16_t *dc_ptr[6];\n const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1);\n const int dquant_code[5]= {1,0,9,2,3};\n if (!s->mb_intra) {\n cbp= get_p_cbp(s, block, motion_x, motion_y);\n if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) {\n put_bits(&s->pb, 1, 1);\n if(interleaved_stats){\n s->misc_bits++;\n s->last_bits++;\n }\n s->skip_count++;\n return;\n }\n put_bits(&s->pb, 1, 0);\n cbpc = cbp & 3;\n cbpy = cbp >> 2;\n if(s->alt_inter_vlc==0 || cbpc!=3)\n cbpy ^= 0xF;\n if(s->dquant) cbpc+= 8;\n if(s->mv_type==MV_TYPE_16X16){\n put_bits(&s->pb,\n inter_MCBPC_bits[cbpc],\n inter_MCBPC_code[cbpc]);\n put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);\n if(s->dquant)\n put_bits(&s->pb, 2, dquant_code[s->dquant+2]);\n if(interleaved_stats){\n s->misc_bits+= get_bits_diff(s);\n }\n h263_pred_motion(s, 0, 0, &pred_x, &pred_y);\n if (!s->umvplus) {\n ff_h263_encode_motion_vector(s, motion_x - pred_x,\n motion_y - pred_y, 1);\n }\n else {\n h263p_encode_umotion(s, motion_x - pred_x);\n h263p_encode_umotion(s, motion_y - pred_y);\n if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))\n put_bits(&s->pb,1,1);\n }\n }else{\n put_bits(&s->pb,\n inter_MCBPC_bits[cbpc+16],\n inter_MCBPC_code[cbpc+16]);\n put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);\n if(s->dquant)\n put_bits(&s->pb, 2, dquant_code[s->dquant+2]);\n if(interleaved_stats){\n s->misc_bits+= get_bits_diff(s);\n }\n for(i=0; i<4; i++){\n h263_pred_motion(s, i, 0, &pred_x, &pred_y);\n motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];\n motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];\n if (!s->umvplus) {\n ff_h263_encode_motion_vector(s, motion_x - pred_x,\n motion_y - pred_y, 1);\n }\n else {\n h263p_encode_umotion(s, motion_x - pred_x);\n h263p_encode_umotion(s, motion_y - pred_y);\n if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))\n put_bits(&s->pb,1,1);\n }\n }\n }\n if(interleaved_stats){\n s->mv_bits+= get_bits_diff(s);\n }\n } else {\n assert(s->mb_intra);\n cbp = 0;\n if (s->h263_aic) {\n for(i=0; i<6; i++) {\n int16_t level = block[i][0];\n int scale;\n if(i<4) scale= s->y_dc_scale;\n else scale= s->c_dc_scale;\n pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);\n level -= pred_dc;\n if (level >= 0)\n level = (level + (scale>>1))/scale;\n else\n level = (level - (scale>>1))/scale;\n if (level == 0 && s->block_last_index[i] == 0)\n s->block_last_index[i] = -1;\n if(!s->modified_quant){\n if (level < -127)\n level = -127;\n else if (level > 127)\n level = 127;\n }\n block[i][0] = level;\n rec_intradc[i] = scale*level + pred_dc;\n rec_intradc[i] |= 1;\n if (rec_intradc[i] < 0)\n rec_intradc[i] = 0;\n else if (rec_intradc[i] > 2047)\n rec_intradc[i] = 2047;\n *dc_ptr[i] = rec_intradc[i];\n if (s->block_last_index[i] >= 0)\n cbp |= 1 << (5 - i);\n }\n }else{\n for(i=0; i<6; i++) {\n if (s->block_last_index[i] >= 1)\n cbp |= 1 << (5 - i);\n }\n }\n cbpc = cbp & 3;\n if (s->pict_type == FF_I_TYPE) {\n if(s->dquant) cbpc+=4;\n put_bits(&s->pb,\n intra_MCBPC_bits[cbpc],\n intra_MCBPC_code[cbpc]);\n } else {\n if(s->dquant) cbpc+=8;\n put_bits(&s->pb, 1, 0);\n put_bits(&s->pb,\n inter_MCBPC_bits[cbpc + 4],\n inter_MCBPC_code[cbpc + 4]);\n }\n if (s->h263_aic) {\n put_bits(&s->pb, 1, 0);\n }\n cbpy = cbp >> 2;\n put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]);\n if(s->dquant)\n put_bits(&s->pb, 2, dquant_code[s->dquant+2]);\n if(interleaved_stats){\n s->misc_bits+= get_bits_diff(s);\n }\n }\n for(i=0; i<6; i++) {\n h263_encode_block(s, block[i], i);\n if (s->h263_aic && s->mb_intra) {\n block[i][0] = rec_intradc[i];\n }\n }\n if(interleaved_stats){\n if (!s->mb_intra) {\n s->p_tex_bits+= get_bits_diff(s);\n s->f_count++;\n }else{\n s->i_tex_bits+= get_bits_diff(s);\n s->i_count++;\n }\n }\n}']
|
943
| 0
|
https://github.com/openssl/openssl/blob/37b8f1e21c56996644afa38816f575b05eb483ae/crypto/ui/ui_util.c/#L111
|
static int ui_read(UI *ui, UI_STRING *uis)
{
switch (UI_get_string_type(uis)) {
case UIT_PROMPT:
{
char result[PEM_BUFSIZE];
const struct pem_password_cb_data *data =
UI_method_get_ex_data(UI_get_method(ui), ui_method_data_index);
int maxsize = UI_get_result_maxsize(uis);
int len = data->cb(result,
maxsize > PEM_BUFSIZE ? PEM_BUFSIZE : maxsize,
data->rwflag, UI_get0_user_data(ui));
if (len <= 0)
return len;
if (UI_set_result(ui, uis, result) >= 0)
return 1;
return 0;
}
case UIT_VERIFY:
case UIT_NONE:
case UIT_BOOLEAN:
case UIT_INFO:
case UIT_ERROR:
break;
}
return 1;
}
|
['static int ui_read(UI *ui, UI_STRING *uis)\n{\n switch (UI_get_string_type(uis)) {\n case UIT_PROMPT:\n {\n char result[PEM_BUFSIZE];\n const struct pem_password_cb_data *data =\n UI_method_get_ex_data(UI_get_method(ui), ui_method_data_index);\n int maxsize = UI_get_result_maxsize(uis);\n int len = data->cb(result,\n maxsize > PEM_BUFSIZE ? PEM_BUFSIZE : maxsize,\n data->rwflag, UI_get0_user_data(ui));\n if (len <= 0)\n return len;\n if (UI_set_result(ui, uis, result) >= 0)\n return 1;\n return 0;\n }\n case UIT_VERIFY:\n case UIT_NONE:\n case UIT_BOOLEAN:\n case UIT_INFO:\n case UIT_ERROR:\n break;\n }\n return 1;\n}', 'enum UI_string_types UI_get_string_type(UI_STRING *uis)\n{\n return uis->type;\n}', 'const UI_METHOD *UI_get_method(UI *ui)\n{\n return ui->meth;\n}', 'const void *UI_method_get_ex_data(const UI_METHOD *method, int idx)\n{\n return CRYPTO_get_ex_data(&method->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}', 'int UI_get_result_maxsize(UI_STRING *uis)\n{\n switch (uis->type) {\n case UIT_PROMPT:\n case UIT_VERIFY:\n return uis->_.string_data.result_maxsize;\n case UIT_NONE:\n case UIT_INFO:\n case UIT_ERROR:\n case UIT_BOOLEAN:\n break;\n }\n return -1;\n}']
|
944
| 0
|
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L907
|
PUT_HEVC_QPEL_HV(3, 1)
|
['QPEL(32)', 'PUT_HEVC_QPEL_HV(3, 1)']
|
945
| 0
|
https://github.com/openssl/openssl/blob/54d00677f305375eee65a0c9edb5f0980c5f020f/crypto/bn/bn_lib.c/#L291
|
BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
bn_check_top(b);
if (a == b)
return a;
if (bn_wexpand(a, b->top) == NULL)
return NULL;
if (b->top > 0)
memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
a->neg = b->neg;
a->top = b->top;
a->flags |= b->flags & BN_FLG_FIXED_TOP;
bn_check_top(a);
return a;
}
|
['int ec_GF2m_simple_make_affine(const EC_GROUP *group, EC_POINT *point,\n BN_CTX *ctx)\n{\n BN_CTX *new_ctx = NULL;\n BIGNUM *x, *y;\n int ret = 0;\n if (point->Z_is_one || EC_POINT_is_at_infinity(group, point))\n return 1;\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 (!EC_POINT_get_affine_coordinates(group, point, x, y, ctx))\n goto err;\n if (!BN_copy(point->X, x))\n goto err;\n if (!BN_copy(point->Y, y))\n goto err;\n if (!BN_one(point->Z))\n goto err;\n point->Z_is_one = 1;\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}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n bn_check_top(b);\n if (a == b)\n return a;\n if (bn_wexpand(a, b->top) == NULL)\n return NULL;\n if (b->top > 0)\n memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n a->neg = b->neg;\n a->top = b->top;\n a->flags |= b->flags & BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return a;\n}']
|
946
| 0
|
https://github.com/libav/libav/blob/58ef4ecff834f47f5a4c2a6bd4385b1999a30930/libavcodec/h264.h/#L935
|
static void fill_decode_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
const uint8_t * left_block= h->left_block;
int i;
uint8_t *nnz;
uint8_t *nnz_cache;
topleft_xy = h->topleft_mb_xy;
top_xy = h->top_mb_xy;
topright_xy = h->topright_mb_xy;
left_xy[LTOP] = h->left_mb_xy[LTOP];
left_xy[LBOT] = h->left_mb_xy[LBOT];
topleft_type = h->topleft_type;
top_type = h->top_type;
topright_type = h->topright_type;
left_type[LTOP]= h->left_type[LTOP];
left_type[LBOT]= h->left_type[LBOT];
if(!IS_SKIP(mb_type)){
if(IS_INTRA(mb_type)){
int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
h->topleft_samples_available=
h->top_samples_available=
h->left_samples_available= 0xFFFF;
h->topright_samples_available= 0xEEEA;
if(!(top_type & type_mask)){
h->topleft_samples_available= 0xB3FF;
h->top_samples_available= 0x33FF;
h->topright_samples_available= 0x26EA;
}
if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){
if(IS_INTERLACED(mb_type)){
if(!(left_type[LTOP] & type_mask)){
h->topleft_samples_available&= 0xDFFF;
h->left_samples_available&= 0x5FFF;
}
if(!(left_type[LBOT] & type_mask)){
h->topleft_samples_available&= 0xFF5F;
h->left_samples_available&= 0xFF5F;
}
}else{
int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];
assert(left_xy[LTOP] == left_xy[LBOT]);
if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
}else{
if(!(left_type[LTOP] & type_mask)){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
if(!(topleft_type & type_mask))
h->topleft_samples_available&= 0x7FFF;
if(!(topright_type & type_mask))
h->topright_samples_available&= 0xFBFF;
if(IS_INTRA4x4(mb_type)){
if(IS_INTRA4x4(top_type)){
AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
}else{
h->intra4x4_pred_mode_cache[4+8*0]=
h->intra4x4_pred_mode_cache[5+8*0]=
h->intra4x4_pred_mode_cache[6+8*0]=
h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);
}
for(i=0; i<2; i++){
if(IS_INTRA4x4(left_type[LEFT(i)])){
int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
}else{
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);
}
}
}
}
nnz_cache = h->non_zero_count_cache;
if(top_type){
nnz = h->non_zero_count[top_xy];
AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);
if(CHROMA444){
AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);
AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);
}else{
AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);
AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);
}
}else{
uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
AV_WN32A(&nnz_cache[4+8* 0], top_empty);
AV_WN32A(&nnz_cache[4+8* 5], top_empty);
AV_WN32A(&nnz_cache[4+8*10], top_empty);
}
for (i=0; i<2; i++) {
if(left_type[LEFT(i)]){
nnz = h->non_zero_count[left_xy[LEFT(i)]];
nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];
nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];
if(CHROMA444){
nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];
nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];
nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];
nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];
}else{
nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];
nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];
}
}else{
nnz_cache[3+8* 1 + 2*8*i]=
nnz_cache[3+8* 2 + 2*8*i]=
nnz_cache[3+8* 6 + 2*8*i]=
nnz_cache[3+8* 7 + 2*8*i]=
nnz_cache[3+8*11 + 2*8*i]=
nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
}
}
if( CABAC ) {
if(top_type) {
h->top_cbp = h->cbp_table[top_xy];
} else {
h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
if (left_type[LTOP]) {
h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)
| ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)
| (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);
} else {
h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
}
}
if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
int list;
int b_stride = h->b_stride;
for(list=0; list<h->list_count; list++){
int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
int8_t *ref = s->current_picture.f.ref_index[list];
int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
int16_t (*mv)[2] = s->current_picture.f.motion_val[list];
if(!USES_LIST(mb_type, list)){
continue;
}
assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);
ref_cache[0 - 1*8]=
ref_cache[1 - 1*8]= ref[4*top_xy + 2];
ref_cache[2 - 1*8]=
ref_cache[3 - 1*8]= ref[4*top_xy + 3];
}else{
AV_ZERO128(mv_cache[0 - 1*8]);
AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);
}
if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
for(i=0; i<2; i++){
int cache_idx = -1 + i*2*8;
if(USES_LIST(left_type[LEFT(i)], list)){
const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;
const int b8_xy= 4*left_xy[LEFT(i)] + 1;
AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);
AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);
ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];
ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];
}else{
AV_ZERO32(mv_cache[cache_idx ]);
AV_ZERO32(mv_cache[cache_idx+8]);
ref_cache[cache_idx ]=
ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
}else{
if(USES_LIST(left_type[LTOP], list)){
const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
const int b8_xy= 4*left_xy[LTOP] + 1;
AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);
ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];
}else{
AV_ZERO32(mv_cache[-1]);
ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if(USES_LIST(topright_type, list)){
const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;
AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);
ref_cache[4 - 1*8]= ref[4*topright_xy + 2];
}else{
AV_ZERO32(mv_cache[4 - 1*8]);
ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
if(ref_cache[4 - 1*8] < 0){
if(USES_LIST(topleft_type, list)){
const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);
const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);
ref_cache[-1 - 1*8]= ref[b8_xy];
}else{
AV_ZERO32(mv_cache[-1 - 1*8]);
ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
continue;
if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){
uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
uint8_t (*mvd)[2] = h->mvd_table[list];
ref_cache[2+8*0] =
ref_cache[2+8*2] = PART_NOT_AVAILABLE;
AV_ZERO32(mv_cache[2+8*0]);
AV_ZERO32(mv_cache[2+8*2]);
if( CABAC ) {
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2br_xy[top_xy];
AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);
}else{
AV_ZERO64(mvd_cache[0 - 1*8]);
}
if(USES_LIST(left_type[LTOP], list)){
const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;
AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);
AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);
}else{
AV_ZERO16(mvd_cache[-1 + 0*8]);
AV_ZERO16(mvd_cache[-1 + 1*8]);
}
if(USES_LIST(left_type[LBOT], list)){
const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;
AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);
AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);
}else{
AV_ZERO16(mvd_cache[-1 + 2*8]);
AV_ZERO16(mvd_cache[-1 + 3*8]);
}
AV_ZERO16(mvd_cache[2+8*0]);
AV_ZERO16(mvd_cache[2+8*2]);
if(h->slice_type_nos == AV_PICTURE_TYPE_B){
uint8_t *direct_cache = &h->direct_cache[scan8[0]];
uint8_t *direct_table = h->direct_table;
fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);
if(IS_DIRECT(top_type)){
AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
}else if(IS_8X8(top_type)){
int b8_xy = 4*top_xy;
direct_cache[0 - 1*8]= direct_table[b8_xy + 2];
direct_cache[2 - 1*8]= direct_table[b8_xy + 3];
}else{
AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));
}
if(IS_DIRECT(left_type[LTOP]))
direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[LTOP]))
direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];
else
direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;
if(IS_DIRECT(left_type[LBOT]))
direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[LBOT]))
direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];
else
direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;
}
}
}
if(FRAME_MBAFF){
#define MAP_MVS\
MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\
MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\
MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\
MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])
if(MB_FIELD){
#define MAP_F2F(idx, mb_type)\
if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] <<= 1;\
h->mv_cache[list][idx][1] /= 2;\
h->mvd_cache[list][idx][1] >>=1;\
}
MAP_MVS
#undef MAP_F2F
}else{
#define MAP_F2F(idx, mb_type)\
if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] >>= 1;\
h->mv_cache[list][idx][1] <<= 1;\
h->mvd_cache[list][idx][1] <<= 1;\
}
MAP_MVS
#undef MAP_F2F
}
}
}
}
h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
}
|
['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 int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\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 != AV_PICTURE_TYPE_I ) {\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.f.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 == AV_PICTURE_TYPE_B ) {\n int ctx = 0;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_B);\n if( !IS_DIRECT( h->left_type[LTOP]-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 == AV_PICTURE_TYPE_P ) {\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 == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\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 static const uint16_t mb_sizes[4] = {256,384,512,768};\n const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;\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, mb_size); ptr+=mb_size;\n ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n h->cbp_table[mb_xy] = 0xf7ef;\n h->chroma_pred_mode_table[mb_xy] = 0;\n s->current_picture.f.qscale_table[mb_xy] = 0;\n memset(h->non_zero_count[mb_xy], 16, 48);\n s->current_picture.f.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 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(decode_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 } else {\n h->chroma_pred_mode= DC_128_PRED8x8;\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 == AV_PICTURE_TYPE_B ) {\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, 2);\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 uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, index)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, 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 fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\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, 2);\n fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n } else {\n int list, i;\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 }\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int mx,my,mpx,mpy;\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 0)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }\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 int mx,my,mpx,mpy;\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 8*i)\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, pack8to16(mpx,mpy), 2);\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, 2);\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 int mx,my,mpx,mpy;\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 4*i)\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, pack8to16(mpx,mpy), 2);\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, 2);\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(decode_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 if (CHROMA444 && IS_8x8DCT(mb_type)){\n int i;\n uint8_t *nnz_cache = h->non_zero_count_cache;\n for (i = 0; i < 2; i++){\n if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n }\n }\n if (h->top_type && !IS_8x8DCT(h->top_type)){\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n }\n s->current_picture.f.mb_type[mb_xy] = mb_type;\n if( cbp || IS_INTRA16x16( mb_type ) ) {\n const uint8_t *scan, *scan8x8;\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 }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\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 const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n ctx= 3;\n val++;\n if(val > 2*max_qp){\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) > max_qp){\n if(s->qscale<0) s->qscale+= max_qp+1;\n else s->qscale-= max_qp+1;\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 decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n if(CHROMA444){\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n } else {\n if( cbp&0x30 ){\n int c;\n for( c = 0; c < 2; c++ ) {\n decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 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 + 16 * c + i;\n decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n h->last_qscale_diff = 0;\n }\n s->current_picture.f.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[LEFT_MBS];\n static const uint8_t left_block_options[4][32]={\n {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},\n {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},\n {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},\n {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1);\n topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1);\n top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy ] >> 7) & 1) - 1);\n }\n if (left_mb_field_flag != curr_mb_field_flag) {\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = s->current_picture.f.mb_type[topleft_xy];\n h->top_type = s->current_picture.f.mb_type[top_xy];\n h->topright_type = s->current_picture.f.mb_type[topright_xy];\n h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]];\n h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]];\n if(FMO){\n if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }else{\n if(h->slice_table[topleft_xy ] != h->slice_num){\n h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t * left_block= h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP]= h->left_type[LTOP];\n left_type[LBOT]= h->left_type[LBOT];\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[LBOT] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n }else{\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[LEFT(i)])){\n int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];\n }else{\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if(top_type){\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);\n if(CHROMA444){\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);\n }else{\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);\n }\n }else{\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n for (i=0; i<2; i++) {\n if(left_type[LEFT(i)]){\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];\n nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];\n if(CHROMA444){\n nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];\n nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];\n nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];\n nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];\n }else{\n nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];\n nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];\n }\n }else{\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else {\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)\n | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)\n | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n int b_stride = h->b_stride;\n for(list=0; list<h->list_count; list++){\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = s->current_picture.f.ref_index[list];\n int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t (*mv)[2] = s->current_picture.f.motion_val[list];\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;\n AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);\n ref_cache[0 - 1*8]=\n ref_cache[1 - 1*8]= ref[4*top_xy + 2];\n ref_cache[2 - 1*8]=\n ref_cache[3 - 1*8]= ref[4*top_xy + 3];\n }else{\n AV_ZERO128(mv_cache[0 - 1*8]);\n AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){\n for(i=0; i<2; i++){\n int cache_idx = -1 + i*2*8;\n if(USES_LIST(left_type[LEFT(i)], list)){\n const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy= 4*left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);\n AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);\n ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];\n ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];\n }else{\n AV_ZERO32(mv_cache[cache_idx ]);\n AV_ZERO32(mv_cache[cache_idx+8]);\n ref_cache[cache_idx ]=\n ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n }else{\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy= 4*left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);\n ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];\n }else{\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;\n AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);\n ref_cache[4 - 1*8]= ref[4*topright_xy + 2];\n }else{\n AV_ZERO32(mv_cache[4 - 1*8]);\n ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(ref_cache[4 - 1*8] < 0){\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);\n const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);\n ref_cache[-1 - 1*8]= ref[b8_xy];\n }else{\n AV_ZERO32(mv_cache[-1 - 1*8]);\n ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){\n uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t (*mvd)[2] = h->mvd_table[list];\n ref_cache[2+8*0] =\n ref_cache[2+8*2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2+8*0]);\n AV_ZERO32(mv_cache[2+8*2]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);\n }else{\n AV_ZERO64(mvd_cache[0 - 1*8]);\n }\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 0*8]);\n AV_ZERO16(mvd_cache[-1 + 1*8]);\n }\n if(USES_LIST(left_type[LBOT], list)){\n const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 2*8]);\n AV_ZERO16(mvd_cache[-1 + 3*8]);\n }\n AV_ZERO16(mvd_cache[2+8*0]);\n AV_ZERO16(mvd_cache[2+8*2]);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = 4*top_xy;\n direct_cache[0 - 1*8]= direct_table[b8_xy + 2];\n direct_cache[2 - 1*8]= direct_table[b8_xy + 3];\n }else{\n AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];\n else\n direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];\n else\n direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] >>=1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
|
947
| 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_do_verify(const unsigned char *dgst, int dgst_len,\n DSA_SIG *sig, DSA *dsa)\n{\n BN_CTX *ctx;\n BIGNUM *u1, *u2, *t1;\n BN_MONT_CTX *mont = NULL;\n const BIGNUM *r, *s;\n int ret = -1, i;\n if (!dsa->p || !dsa->q || !dsa->g) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS);\n return -1;\n }\n i = BN_num_bits(dsa->q);\n if (i != 160 && i != 224 && i != 256) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE);\n return -1;\n }\n if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {\n DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE);\n return -1;\n }\n u1 = BN_new();\n u2 = BN_new();\n t1 = BN_new();\n ctx = BN_CTX_new();\n if (u1 == NULL || u2 == NULL || t1 == NULL || ctx == NULL)\n goto err;\n DSA_SIG_get0(sig, &r, &s);\n if (BN_is_zero(r) || BN_is_negative(r) ||\n BN_ucmp(r, dsa->q) >= 0) {\n ret = 0;\n goto err;\n }\n if (BN_is_zero(s) || BN_is_negative(s) ||\n BN_ucmp(s, dsa->q) >= 0) {\n ret = 0;\n goto err;\n }\n if ((BN_mod_inverse(u2, s, dsa->q, ctx)) == NULL)\n goto err;\n if (dgst_len > (i >> 3))\n dgst_len = (i >> 3);\n if (BN_bin2bn(dgst, dgst_len, u1) == NULL)\n goto err;\n if (!BN_mod_mul(u1, u1, u2, dsa->q, ctx))\n goto err;\n if (!BN_mod_mul(u2, r, u2, dsa->q, ctx))\n goto err;\n if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n dsa->lock, dsa->p, ctx);\n if (!mont)\n goto err;\n }\n if (dsa->meth->dsa_mod_exp != NULL) {\n if (!dsa->meth->dsa_mod_exp(dsa, t1, dsa->g, u1, dsa->pub_key, u2,\n dsa->p, ctx, mont))\n goto err;\n } else {\n if (!BN_mod_exp2_mont(t1, dsa->g, u1, dsa->pub_key, u2, dsa->p, ctx,\n mont))\n goto err;\n }\n if (!BN_mod(u1, t1, dsa->q, ctx))\n goto err;\n ret = (BN_ucmp(u1, r) == 0);\n err:\n if (ret < 0)\n DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB);\n BN_CTX_free(ctx);\n BN_free(u1);\n BN_free(u2);\n BN_free(t1);\n return (ret);\n}', 'BIGNUM *BN_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)\n{\n BIGNUM *rv;\n int noinv;\n rv = int_bn_mod_inverse(in, a, n, ctx, &noinv);\n if (noinv)\n BNerr(BN_F_BN_MOD_INVERSE, BN_R_NO_INVERSE);\n return rv;\n}', 'BIGNUM *int_bn_mod_inverse(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,\n int *pnoinv)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n if (pnoinv)\n *pnoinv = 0;\n if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0)) {\n return BN_mod_inverse_no_branch(in, a, n, ctx);\n }\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n if (!BN_nnmod(B, B, A, ctx))\n goto err;\n }\n sign = -1;\n if (BN_is_odd(n) && (BN_num_bits(n) <= 2048)) {\n int shift;\n while (!BN_is_zero(B)) {\n shift = 0;\n while (!BN_is_bit_set(B, shift)) {\n shift++;\n if (BN_is_odd(X)) {\n if (!BN_uadd(X, X, n))\n goto err;\n }\n if (!BN_rshift1(X, X))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(B, B, shift))\n goto err;\n }\n shift = 0;\n while (!BN_is_bit_set(A, shift)) {\n shift++;\n if (BN_is_odd(Y)) {\n if (!BN_uadd(Y, Y, n))\n goto err;\n }\n if (!BN_rshift1(Y, Y))\n goto err;\n }\n if (shift > 0) {\n if (!BN_rshift(A, A, shift))\n goto err;\n }\n if (BN_ucmp(B, A) >= 0) {\n if (!BN_uadd(X, X, Y))\n goto err;\n if (!BN_usub(B, B, A))\n goto err;\n } else {\n if (!BN_uadd(Y, Y, X))\n goto err;\n if (!BN_usub(A, A, B))\n goto err;\n }\n }\n } else {\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n if (BN_num_bits(A) == BN_num_bits(B)) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else if (BN_num_bits(A) == BN_num_bits(B) + 1) {\n if (!BN_lshift1(T, B))\n goto err;\n if (BN_ucmp(A, T) < 0) {\n if (!BN_one(D))\n goto err;\n if (!BN_sub(M, A, B))\n goto err;\n } else {\n if (!BN_sub(M, A, T))\n goto err;\n if (!BN_add(D, T, B))\n goto err;\n if (BN_ucmp(A, D) < 0) {\n if (!BN_set_word(D, 2))\n goto err;\n } else {\n if (!BN_set_word(D, 3))\n goto err;\n if (!BN_sub(M, M, B))\n goto err;\n }\n }\n } else {\n if (!BN_div(D, M, A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (BN_is_one(D)) {\n if (!BN_add(tmp, X, Y))\n goto err;\n } else {\n if (BN_is_word(D, 2)) {\n if (!BN_lshift1(tmp, X))\n goto err;\n } else if (BN_is_word(D, 4)) {\n if (!BN_lshift(tmp, X, 2))\n goto err;\n } else if (D->top == 1) {\n if (!BN_copy(tmp, X))\n goto err;\n if (!BN_mul_word(tmp, D->d[0]))\n goto err;\n } else {\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n }\n if (!BN_add(tmp, tmp, Y))\n goto err;\n }\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n if (pnoinv)\n *pnoinv = 1;\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', 'static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,\n const BIGNUM *a, const BIGNUM *n,\n BN_CTX *ctx)\n{\n BIGNUM *A, *B, *X, *Y, *M, *D, *T, *R = NULL;\n BIGNUM *ret = NULL;\n int sign;\n bn_check_top(a);\n bn_check_top(n);\n BN_CTX_start(ctx);\n A = BN_CTX_get(ctx);\n B = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n D = BN_CTX_get(ctx);\n M = BN_CTX_get(ctx);\n Y = BN_CTX_get(ctx);\n T = BN_CTX_get(ctx);\n if (T == NULL)\n goto err;\n if (in == NULL)\n R = BN_new();\n else\n R = in;\n if (R == NULL)\n goto err;\n BN_one(X);\n BN_zero(Y);\n if (BN_copy(B, a) == NULL)\n goto err;\n if (BN_copy(A, n) == NULL)\n goto err;\n A->neg = 0;\n if (B->neg || (BN_ucmp(B, A) >= 0)) {\n {\n BIGNUM local_B;\n bn_init(&local_B);\n BN_with_flags(&local_B, B, BN_FLG_CONSTTIME);\n if (!BN_nnmod(B, &local_B, A, ctx))\n goto err;\n }\n }\n sign = -1;\n while (!BN_is_zero(B)) {\n BIGNUM *tmp;\n {\n BIGNUM local_A;\n bn_init(&local_A);\n BN_with_flags(&local_A, A, BN_FLG_CONSTTIME);\n if (!BN_div(D, M, &local_A, B, ctx))\n goto err;\n }\n tmp = A;\n A = B;\n B = M;\n if (!BN_mul(tmp, D, X, ctx))\n goto err;\n if (!BN_add(tmp, tmp, Y))\n goto err;\n M = Y;\n Y = X;\n X = tmp;\n sign = -sign;\n }\n if (sign < 0) {\n if (!BN_sub(Y, n, Y))\n goto err;\n }\n if (BN_is_one(A)) {\n if (!Y->neg && BN_ucmp(Y, n) < 0) {\n if (!BN_copy(R, Y))\n goto err;\n } else {\n if (!BN_nnmod(R, Y, n, ctx))\n goto err;\n }\n } else {\n BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH, BN_R_NO_INVERSE);\n goto err;\n }\n ret = R;\n err:\n if ((ret == NULL) && (in == NULL))\n BN_free(R);\n BN_CTX_end(ctx);\n bn_check_top(ret);\n return (ret);\n}', '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}']
|
948
| 0
|
https://github.com/openssl/openssl/blob/80aa9cc985251463a3ad65b0a4d64bf93c70b175/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx)\n {\n genrand(ctx);\n generate_step_part(&send->p1, ctx->xa, ctx->p.g, ctx);\n generate_step_part(&send->p2, ctx->xb, ctx->p.g, ctx);\n return 1;\n }', 'static void generate_step_part(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *g, JPAKE_CTX *ctx)\n {\n BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx);\n generate_zkp(p, x, g, ctx);\n }', 'static void generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *zkpg, JPAKE_CTX *ctx)\n {\n BIGNUM *r = BN_new();\n BIGNUM *h = BN_new();\n BIGNUM *t = BN_new();\n BN_rand_range(r, ctx->p.q);\n BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx);\n zkp_hash(h, zkpg, p, ctx->p.name);\n BN_mod_mul(t, x, h, ctx->p.q, ctx->ctx);\n BN_mod_sub(p->zkpx.b, r, t, ctx->p.q, ctx->ctx);\n BN_free(t);\n BN_free(h);\n BN_free(r);\n }', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_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}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tif (!BN_sub(r, a, b)) return 0;\n\treturn BN_nnmod(r, r, m, ctx);\n\t}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(r);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\taa = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif(!aa || !val[0]) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (m->neg)\n\t\t{\n\t\tif (!BN_copy(aa, m)) goto err;\n\t\taa->neg = 0;\n\t\tif (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\t\t}\n\tif (!BN_nnmod(val[0],a,m,ctx)) goto err;\n\tif (BN_is_zero(val[0]))\n\t\t{\n\t\tBN_zero(r);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,val[0],val[0],&recp,ctx))\n\t\t\tgoto 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_reciprocal(val[i],val[i-1],\n\t\t\t\t\t\taa,&recp,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_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tBN_RECP_CTX_free(&recp);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif (num->top > 0 && num->d[num->top - 1] == 0)\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_NOT_INITIALIZED);\n\t\treturn 0;\n\t\t}\n\tbn_check_top(num);\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\t{\n\t\t\tBN_ULONG ql, qh;\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n\t\t\t}\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
949
| 0
|
https://github.com/openssl/openssl/blob/21e8bbf2904e5ac8709d46424e18f8ba6e813b06/apps/ts.c/#L1051
|
static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest,
char *queryfile,
char *ca_path, char *ca_file,
char *untrusted)
{
TS_VERIFY_CTX *ctx = NULL;
BIO *input = NULL;
TS_REQ *request = NULL;
int ret = 0;
if (data != NULL || digest != NULL)
{
if (!(ctx = TS_VERIFY_CTX_new())) goto err;
ctx->flags = TS_VFY_VERSION | TS_VFY_SIGNER;
if (data != NULL)
{
ctx->flags |= TS_VFY_DATA;
if (!(ctx->data = BIO_new_file(data, "rb"))) goto err;
}
else if (digest != NULL)
{
long imprint_len;
ctx->flags |= TS_VFY_IMPRINT;
if (!(ctx->imprint = string_to_hex(digest,
&imprint_len)))
{
BIO_printf(bio_err, "invalid digest string\n");
goto err;
}
ctx->imprint_len = imprint_len;
}
}
else if (queryfile != NULL)
{
if (!(input = BIO_new_file(queryfile, "rb"))) goto err;
if (!(request = d2i_TS_REQ_bio(input, NULL))) goto err;
if (!(ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL))) goto err;
}
ctx->flags |= TS_VFY_SIGNATURE;
if (!(ctx->store = create_cert_store(ca_path, ca_file))) goto err;
if (untrusted && !(ctx->certs = TS_CONF_load_certs(untrusted)))
goto err;
ret = 1;
err:
if (!ret)
{
TS_VERIFY_CTX_free(ctx);
ctx = NULL;
}
BIO_free_all(input);
TS_REQ_free(request);
return ctx;
}
|
['static TS_VERIFY_CTX *create_verify_ctx(char *data, char *digest,\n\t\t\t\t\tchar *queryfile,\n\t\t\t\t\tchar *ca_path, char *ca_file,\n\t\t\t\t\tchar *untrusted)\n\t{\n\tTS_VERIFY_CTX *ctx = NULL;\n\tBIO *input = NULL;\n\tTS_REQ *request = NULL;\n\tint ret = 0;\n\tif (data != NULL || digest != NULL)\n\t\t{\n\t\tif (!(ctx = TS_VERIFY_CTX_new())) goto err;\n\t\tctx->flags = TS_VFY_VERSION | TS_VFY_SIGNER;\n\t\tif (data != NULL)\n\t\t\t{\n\t\t\tctx->flags |= TS_VFY_DATA;\n\t\t\tif (!(ctx->data = BIO_new_file(data, "rb"))) goto err;\n\t\t\t}\n\t\telse if (digest != NULL)\n\t\t\t{\n\t\t\tlong imprint_len;\n\t\t\tctx->flags |= TS_VFY_IMPRINT;\n\t\t\tif (!(ctx->imprint = string_to_hex(digest,\n\t\t\t\t\t\t\t &imprint_len)))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err, "invalid digest string\\n");\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\tctx->imprint_len = imprint_len;\n\t\t\t}\n\t\t}\n\telse if (queryfile != NULL)\n\t\t{\n\t\tif (!(input = BIO_new_file(queryfile, "rb"))) goto err;\n\t\tif (!(request = d2i_TS_REQ_bio(input, NULL))) goto err;\n\t\tif (!(ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL))) goto err;\n\t\t}\n\tctx->flags |= TS_VFY_SIGNATURE;\n\tif (!(ctx->store = create_cert_store(ca_path, ca_file))) goto err;\n\tif (untrusted && !(ctx->certs = TS_CONF_load_certs(untrusted)))\n\t\tgoto err;\n\tret = 1;\n err:\n\tif (!ret)\n\t\t{\n\t\tTS_VERIFY_CTX_free(ctx);\n\t\tctx = NULL;\n\t\t}\n\tBIO_free_all(input);\n\tTS_REQ_free(request);\n\treturn ctx;\n\t}']
|
950
| 0
|
https://github.com/openssl/openssl/blob/9dd4ac8cf17f2afd636e85ae0111d1df4104a475/crypto/rand/md_rand.c/#L523
|
static int rand_bytes(unsigned char *buf, int num, int pseudo)
{
static volatile int stirred_pool = 0;
int i, j, k;
size_t num_ceil, st_idx, st_num;
int ok;
long md_c[2];
unsigned char local_md[MD_DIGEST_LENGTH];
EVP_MD_CTX *m;
#ifndef GETPID_IS_MEANINGLESS
pid_t curr_pid = getpid();
#endif
time_t curr_time = time(NULL);
int do_stir_pool = 0;
#ifdef OPENSSL_SYS_WIN32
FILETIME tv;
# ifdef _WIN32_WCE
SYSTEMTIME t;
GetSystemTime(&t);
SystemTimeToFileTime(&t, &tv);
# else
GetSystemTimeAsFileTime(&tv);
# endif
#elif defined(OPENSSL_SYS_VXWORKS)
struct timespec tv;
clock_gettime(CLOCK_REALTIME, &ts);
#elif defined(OPENSSL_SYS_DSPBIOS)
unsigned long long tv, OPENSSL_rdtsc();
tv = OPENSSL_rdtsc();
#else
struct timeval tv;
gettimeofday(&tv, NULL);
#endif
#ifdef PREDICT
if (rand_predictable) {
unsigned char val = 1;
for (i = 0; i < num; i++)
buf[i] = val++;
return (1);
}
#endif
if (num <= 0)
return 1;
m = EVP_MD_CTX_new();
if (m == NULL)
goto err_mem;
num_ceil =
(1 + (num - 1) / (MD_DIGEST_LENGTH / 2)) * (MD_DIGEST_LENGTH / 2);
if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))
goto err_mem;
CRYPTO_THREAD_write_lock(rand_lock);
ASYNC_block_pause();
CRYPTO_THREAD_write_lock(rand_tmp_lock);
locking_threadid = CRYPTO_THREAD_get_current_id();
CRYPTO_THREAD_unlock(rand_tmp_lock);
crypto_lock_rand = 1;
if (!initialized) {
RAND_poll();
initialized = 1;
}
if (!stirred_pool)
do_stir_pool = 1;
ok = (entropy >= ENTROPY_NEEDED);
if (!ok) {
entropy -= num;
if (entropy < 0)
entropy = 0;
}
if (do_stir_pool) {
int n = STATE_SIZE;
while (n > 0) {
#if MD_DIGEST_LENGTH > 20
# error "Please adjust DUMMY_SEED."
#endif
#define DUMMY_SEED "...................."
rand_add(DUMMY_SEED, MD_DIGEST_LENGTH, 0.0);
n -= MD_DIGEST_LENGTH;
}
if (ok)
stirred_pool = 1;
}
st_idx = state_index;
st_num = state_num;
md_c[0] = md_count[0];
md_c[1] = md_count[1];
memcpy(local_md, md, sizeof md);
state_index += num_ceil;
if (state_index > state_num)
state_index %= state_num;
md_count[0] += 1;
crypto_lock_rand = 0;
ASYNC_unblock_pause();
CRYPTO_THREAD_unlock(rand_lock);
while (num > 0) {
j = (num >= MD_DIGEST_LENGTH / 2) ? MD_DIGEST_LENGTH / 2 : num;
num -= j;
if (!MD_Init(m))
goto err;
#ifndef GETPID_IS_MEANINGLESS
if (curr_pid) {
if (!MD_Update(m, (unsigned char *)&curr_pid, sizeof curr_pid))
goto err;
curr_pid = 0;
}
#endif
if (curr_time) {
if (!MD_Update(m, (unsigned char *)&curr_time, sizeof curr_time))
goto err;
if (!MD_Update(m, (unsigned char *)&tv, sizeof tv))
goto err;
curr_time = 0;
if (!rand_hw_seed(m))
goto err;
}
if (!MD_Update(m, local_md, MD_DIGEST_LENGTH))
goto err;
if (!MD_Update(m, (unsigned char *)&(md_c[0]), sizeof(md_c)))
goto err;
k = (st_idx + MD_DIGEST_LENGTH / 2) - st_num;
if (k > 0) {
if (!MD_Update(m, &(state[st_idx]), MD_DIGEST_LENGTH / 2 - k))
goto err;
if (!MD_Update(m, &(state[0]), k))
goto err;
} else if (!MD_Update(m, &(state[st_idx]), MD_DIGEST_LENGTH / 2))
goto err;
if (!MD_Final(m, local_md))
goto err;
for (i = 0; i < MD_DIGEST_LENGTH / 2; i++) {
state[st_idx++] ^= local_md[i];
if (st_idx >= st_num)
st_idx = 0;
if (i < j)
*(buf++) = local_md[i + MD_DIGEST_LENGTH / 2];
}
}
if (!MD_Init(m)
|| !MD_Update(m, (unsigned char *)&(md_c[0]), sizeof(md_c))
|| !MD_Update(m, local_md, MD_DIGEST_LENGTH))
goto err;
CRYPTO_THREAD_write_lock(rand_lock);
ASYNC_block_pause();
if (!MD_Update(m, md, MD_DIGEST_LENGTH) || !MD_Final(m, md)) {
CRYPTO_THREAD_unlock(rand_lock);
goto err;
}
ASYNC_unblock_pause();
CRYPTO_THREAD_unlock(rand_lock);
EVP_MD_CTX_free(m);
if (ok)
return (1);
else if (pseudo)
return 0;
else {
RANDerr(RAND_F_RAND_BYTES, RAND_R_PRNG_NOT_SEEDED);
ERR_add_error_data(1, "You need to read the OpenSSL FAQ, "
"https://www.openssl.org/docs/faq.html");
return (0);
}
err:
RANDerr(RAND_F_RAND_BYTES, ERR_R_EVP_LIB);
EVP_MD_CTX_free(m);
return 0;
err_mem:
RANDerr(RAND_F_RAND_BYTES, ERR_R_MALLOC_FAILURE);
EVP_MD_CTX_free(m);
return 0;
}
|
['static int rand_bytes(unsigned char *buf, int num, int pseudo)\n{\n static volatile int stirred_pool = 0;\n int i, j, k;\n size_t num_ceil, st_idx, st_num;\n int ok;\n long md_c[2];\n unsigned char local_md[MD_DIGEST_LENGTH];\n EVP_MD_CTX *m;\n#ifndef GETPID_IS_MEANINGLESS\n pid_t curr_pid = getpid();\n#endif\n time_t curr_time = time(NULL);\n int do_stir_pool = 0;\n#ifdef OPENSSL_SYS_WIN32\n FILETIME tv;\n# ifdef _WIN32_WCE\n SYSTEMTIME t;\n GetSystemTime(&t);\n SystemTimeToFileTime(&t, &tv);\n# else\n GetSystemTimeAsFileTime(&tv);\n# endif\n#elif defined(OPENSSL_SYS_VXWORKS)\n struct timespec tv;\n clock_gettime(CLOCK_REALTIME, &ts);\n#elif defined(OPENSSL_SYS_DSPBIOS)\n unsigned long long tv, OPENSSL_rdtsc();\n tv = OPENSSL_rdtsc();\n#else\n struct timeval tv;\n gettimeofday(&tv, NULL);\n#endif\n#ifdef PREDICT\n if (rand_predictable) {\n unsigned char val = 1;\n for (i = 0; i < num; i++)\n buf[i] = val++;\n return (1);\n }\n#endif\n if (num <= 0)\n return 1;\n m = EVP_MD_CTX_new();\n if (m == NULL)\n goto err_mem;\n num_ceil =\n (1 + (num - 1) / (MD_DIGEST_LENGTH / 2)) * (MD_DIGEST_LENGTH / 2);\n if (!RUN_ONCE(&rand_lock_init, do_rand_lock_init))\n goto err_mem;\n CRYPTO_THREAD_write_lock(rand_lock);\n ASYNC_block_pause();\n CRYPTO_THREAD_write_lock(rand_tmp_lock);\n locking_threadid = CRYPTO_THREAD_get_current_id();\n CRYPTO_THREAD_unlock(rand_tmp_lock);\n crypto_lock_rand = 1;\n if (!initialized) {\n RAND_poll();\n initialized = 1;\n }\n if (!stirred_pool)\n do_stir_pool = 1;\n ok = (entropy >= ENTROPY_NEEDED);\n if (!ok) {\n entropy -= num;\n if (entropy < 0)\n entropy = 0;\n }\n if (do_stir_pool) {\n int n = STATE_SIZE;\n while (n > 0) {\n#if MD_DIGEST_LENGTH > 20\n# error "Please adjust DUMMY_SEED."\n#endif\n#define DUMMY_SEED "...................."\n rand_add(DUMMY_SEED, MD_DIGEST_LENGTH, 0.0);\n n -= MD_DIGEST_LENGTH;\n }\n if (ok)\n stirred_pool = 1;\n }\n st_idx = state_index;\n st_num = state_num;\n md_c[0] = md_count[0];\n md_c[1] = md_count[1];\n memcpy(local_md, md, sizeof md);\n state_index += num_ceil;\n if (state_index > state_num)\n state_index %= state_num;\n md_count[0] += 1;\n crypto_lock_rand = 0;\n ASYNC_unblock_pause();\n CRYPTO_THREAD_unlock(rand_lock);\n while (num > 0) {\n j = (num >= MD_DIGEST_LENGTH / 2) ? MD_DIGEST_LENGTH / 2 : num;\n num -= j;\n if (!MD_Init(m))\n goto err;\n#ifndef GETPID_IS_MEANINGLESS\n if (curr_pid) {\n if (!MD_Update(m, (unsigned char *)&curr_pid, sizeof curr_pid))\n goto err;\n curr_pid = 0;\n }\n#endif\n if (curr_time) {\n if (!MD_Update(m, (unsigned char *)&curr_time, sizeof curr_time))\n goto err;\n if (!MD_Update(m, (unsigned char *)&tv, sizeof tv))\n goto err;\n curr_time = 0;\n if (!rand_hw_seed(m))\n goto err;\n }\n if (!MD_Update(m, local_md, MD_DIGEST_LENGTH))\n goto err;\n if (!MD_Update(m, (unsigned char *)&(md_c[0]), sizeof(md_c)))\n goto err;\n k = (st_idx + MD_DIGEST_LENGTH / 2) - st_num;\n if (k > 0) {\n if (!MD_Update(m, &(state[st_idx]), MD_DIGEST_LENGTH / 2 - k))\n goto err;\n if (!MD_Update(m, &(state[0]), k))\n goto err;\n } else if (!MD_Update(m, &(state[st_idx]), MD_DIGEST_LENGTH / 2))\n goto err;\n if (!MD_Final(m, local_md))\n goto err;\n for (i = 0; i < MD_DIGEST_LENGTH / 2; i++) {\n state[st_idx++] ^= local_md[i];\n if (st_idx >= st_num)\n st_idx = 0;\n if (i < j)\n *(buf++) = local_md[i + MD_DIGEST_LENGTH / 2];\n }\n }\n if (!MD_Init(m)\n || !MD_Update(m, (unsigned char *)&(md_c[0]), sizeof(md_c))\n || !MD_Update(m, local_md, MD_DIGEST_LENGTH))\n goto err;\n CRYPTO_THREAD_write_lock(rand_lock);\n ASYNC_block_pause();\n if (!MD_Update(m, md, MD_DIGEST_LENGTH) || !MD_Final(m, md)) {\n CRYPTO_THREAD_unlock(rand_lock);\n goto err;\n }\n ASYNC_unblock_pause();\n CRYPTO_THREAD_unlock(rand_lock);\n EVP_MD_CTX_free(m);\n if (ok)\n return (1);\n else if (pseudo)\n return 0;\n else {\n RANDerr(RAND_F_RAND_BYTES, RAND_R_PRNG_NOT_SEEDED);\n ERR_add_error_data(1, "You need to read the OpenSSL FAQ, "\n "https://www.openssl.org/docs/faq.html");\n return (0);\n }\n err:\n RANDerr(RAND_F_RAND_BYTES, ERR_R_EVP_LIB);\n EVP_MD_CTX_free(m);\n return 0;\n err_mem:\n RANDerr(RAND_F_RAND_BYTES, ERR_R_MALLOC_FAILURE);\n EVP_MD_CTX_free(m);\n return 0;\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 if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}', 'void EVP_MD_CTX_free(EVP_MD_CTX *ctx)\n{\n EVP_MD_CTX_reset(ctx);\n OPENSSL_free(ctx);\n}', 'void CRYPTO_free(void *str, const char *file, int line)\n{\n if (free_impl != NULL && free_impl != &CRYPTO_free) {\n free_impl(str, file, line);\n return;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_free(str, 0, file, line);\n free(str);\n CRYPTO_mem_debug_free(str, 1, file, line);\n } else {\n free(str);\n }\n#else\n free(str);\n#endif\n}']
|
951
| 0
|
https://github.com/nginx/nginx/blob/4fe0a09942f8aed90f84c77969847980e9aadd98/src/core/ngx_string.c/#L1034
|
off_t
ngx_atoof(u_char *line, size_t n)
{
off_t value, cutoff, cutlim;
if (n == 0) {
return NGX_ERROR;
}
cutoff = NGX_MAX_OFF_T_VALUE / 10;
cutlim = NGX_MAX_OFF_T_VALUE % 10;
for (value = 0; n--; line++) {
if (*line < '0' || *line > '9') {
return NGX_ERROR;
}
if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {
return NGX_ERROR;
}
value = value * 10 + (*line - '0');
}
return value;
}
|
['char *\nngx_conf_set_off_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n char *p = conf;\n off_t *op;\n ngx_str_t *value;\n ngx_conf_post_t *post;\n op = (off_t *) (p + cmd->offset);\n if (*op != NGX_CONF_UNSET) {\n return "is duplicate";\n }\n value = cf->args->elts;\n *op = ngx_parse_offset(&value[1]);\n if (*op == (off_t) NGX_ERROR) {\n return "invalid value";\n }\n if (cmd->post) {\n post = cmd->post;\n return post->post_handler(cf, post, op);\n }\n return NGX_CONF_OK;\n}', "off_t\nngx_parse_offset(ngx_str_t *line)\n{\n u_char unit;\n off_t offset, scale, max;\n size_t len;\n len = line->len;\n unit = line->data[len - 1];\n switch (unit) {\n case 'K':\n case 'k':\n len--;\n max = NGX_MAX_OFF_T_VALUE / 1024;\n scale = 1024;\n break;\n case 'M':\n case 'm':\n len--;\n max = NGX_MAX_OFF_T_VALUE / (1024 * 1024);\n scale = 1024 * 1024;\n break;\n case 'G':\n case 'g':\n len--;\n max = NGX_MAX_OFF_T_VALUE / (1024 * 1024 * 1024);\n scale = 1024 * 1024 * 1024;\n break;\n default:\n max = NGX_MAX_OFF_T_VALUE;\n scale = 1;\n }\n offset = ngx_atoof(line->data, len);\n if (offset == NGX_ERROR || offset > max) {\n return NGX_ERROR;\n }\n offset *= scale;\n return offset;\n}", "off_t\nngx_atoof(u_char *line, size_t n)\n{\n off_t value, cutoff, cutlim;\n if (n == 0) {\n return NGX_ERROR;\n }\n cutoff = NGX_MAX_OFF_T_VALUE / 10;\n cutlim = NGX_MAX_OFF_T_VALUE % 10;\n for (value = 0; n--; line++) {\n if (*line < '0' || *line > '9') {\n return NGX_ERROR;\n }\n if (value >= cutoff && (value > cutoff || *line - '0' > cutlim)) {\n return NGX_ERROR;\n }\n value = value * 10 + (*line - '0');\n }\n return value;\n}"]
|
952
| 0
|
https://github.com/openssl/openssl/blob/fbf66436078deb9cc8ff91c8ccc245da271e9d35/crypto/evp/evp_pbe.c/#L187
|
int EVP_PBE_find(int type, int pbe_nid,
int *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen)
{
EVP_PBE_CTL *pbetmp, pbelu;
int i;
if (pbe_nid == NID_undef)
return 0;
pbelu.pbe_type = type;
pbelu.pbe_nid = pbe_nid;
i = sk_find(pbe_algs, (char *)&pbelu);
if (i == -1)
return 0;
pbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);
if (pcnid)
*pcnid = pbetmp->cipher_nid;
if (pmnid)
*pmnid = pbetmp->md_nid;
if (pkeygen)
*pkeygen = pbetmp->keygen;
return 1;
}
|
['int EVP_PBE_find(int type, int pbe_nid,\n\t\t\tint *pcnid, int *pmnid, EVP_PBE_KEYGEN **pkeygen)\n\t{\n\tEVP_PBE_CTL *pbetmp, pbelu;\n\tint i;\n\tif (pbe_nid == NID_undef)\n\t\treturn 0;\n\tpbelu.pbe_type = type;\n\tpbelu.pbe_nid = pbe_nid;\n\ti = sk_find(pbe_algs, (char *)&pbelu);\n\tif (i == -1)\n\t\treturn 0;\n\tpbetmp = (EVP_PBE_CTL *)sk_value (pbe_algs, i);\n\tif (pcnid)\n\t\t*pcnid = pbetmp->cipher_nid;\n\tif (pmnid)\n\t\t*pmnid = pbetmp->md_nid;\n\tif (pkeygen)\n\t\t*pkeygen = pbetmp->keygen;\n\treturn 1;\n\t}', 'int sk_find(STACK *st, char *data)\n\t{\n\treturn internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH);\n\t}', 'static int internal_find(STACK *st, char *data, int ret_val_options)\n\t{\n\tchar **r;\n\tint i;\n\tint (*comp_func)(const void *,const void *);\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\tcomp_func=(int (*)(const void *,const void *))(st->comp);\n\tr=(char **)OBJ_bsearch_ex((char *)&data,(char *)st->data,\n\t\tst->num,sizeof(char *),comp_func,ret_val_options);\n\tif (r == NULL) return(-1);\n\treturn((int)(r-st->data));\n\t}', 'char *sk_value(const STACK *st, int i)\n{\n\tif(!st || (i < 0) || (i >= st->num)) return NULL;\n\treturn st->data[i];\n}']
|
953
| 0
|
https://github.com/libav/libav/blob/85395ba73f9cc1b3cece3e85ae12f491ad7c1dd2/libavcodec/rv40.c/#L514
|
static void rv40_loop_filter(RV34DecContext *r, int row)
{
MpegEncContext *s = &r->s;
int mb_pos, mb_x;
int i, j, k;
uint8_t *Y, *C;
int alpha, beta, betaY, betaC;
int q;
int mbtype[4];
int mb_strong[4];
int clip[4];
int cbp[4];
int uvcbp[4][2];
unsigned mvmasks[4];
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];
if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))
r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;
if(IS_INTRA(mbtype))
r->cbp_chroma[mb_pos] = 0xFF;
}
mb_pos = row * s->mb_stride;
for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){
int y_h_deblock, y_v_deblock;
int c_v_deblock[2], c_h_deblock[2];
int clip_left;
int avail[4];
unsigned y_to_deblock;
int c_to_deblock[2];
q = s->current_picture_ptr->f.qscale_table[mb_pos];
alpha = rv40_alpha_tab[q];
beta = rv40_beta_tab [q];
betaY = betaC = beta * 3;
if(s->width * s->height <= 176*144)
betaY += beta;
avail[0] = 1;
avail[1] = row;
avail[2] = mb_x;
avail[3] = row < s->mb_height - 1;
for(i = 0; i < 4; i++){
if(avail[i]){
int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;
mvmasks[i] = r->deblock_coefs[pos];
mbtype [i] = s->current_picture_ptr->f.mb_type[pos];
cbp [i] = r->cbp_luma[pos];
uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;
uvcbp[i][1] = r->cbp_chroma[pos] >> 4;
}else{
mvmasks[i] = 0;
mbtype [i] = mbtype[0];
cbp [i] = 0;
uvcbp[i][0] = uvcbp[i][1] = 0;
}
mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);
clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];
}
y_to_deblock = mvmasks[POS_CUR]
| (mvmasks[POS_BOTTOM] << 16);
y_h_deblock = y_to_deblock
| ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)
| ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);
y_v_deblock = y_to_deblock
| ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)
| ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);
if(!mb_x)
y_v_deblock &= ~MASK_Y_LEFT_COL;
if(!row)
y_h_deblock &= ~MASK_Y_TOP_ROW;
if(row == s->mb_height - 1 || (mb_strong[POS_CUR] | mb_strong[POS_BOTTOM]))
y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);
for(i = 0; i < 2; i++){
c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];
c_v_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)
| ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);
c_h_deblock[i] = c_to_deblock[i]
| ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)
| (uvcbp[POS_CUR][i] << 2);
if(!mb_x)
c_v_deblock[i] &= ~MASK_C_LEFT_COL;
if(!row)
c_h_deblock[i] &= ~MASK_C_TOP_ROW;
if(row == s->mb_height - 1 || (mb_strong[POS_CUR] | mb_strong[POS_BOTTOM]))
c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);
}
for(j = 0; j < 16; j += 4){
Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;
for(i = 0; i < 4; i++, Y += 4){
int ij = i + j;
int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
int dither = j ? ij : i*4;
if(y_h_deblock & (MASK_BOTTOM << ij)){
rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,
s->linesize, dither,
y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,
clip_cur, alpha, beta, betaY,
0, 0, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] | mb_strong[POS_LEFT]))){
if(!i)
clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
else
clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 0, 1);
}
if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] | mb_strong[POS_TOP])){
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,
alpha, beta, betaY, 0, 1, 0);
}
if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] | mb_strong[POS_LEFT])){
clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;
rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,
clip_cur,
clip_left,
alpha, beta, betaY, 0, 1, 1);
}
}
}
for(k = 0; k < 2; k++){
for(j = 0; j < 2; j++){
C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;
for(i = 0; i < 2; i++, C += 4){
int ij = i + j*2;
int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;
if(c_h_deblock[k] & (MASK_CUR << (ij+2))){
int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,
clip_bot,
clip_cur,
alpha, beta, betaC, 1, 0, 0);
}
if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] | mb_strong[POS_LEFT]))){
if(!i)
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
else
clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 0, 1);
}
if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] | mb_strong[POS_TOP])){
int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,
clip_cur,
clip_top,
alpha, beta, betaC, 1, 1, 0);
}
if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] | mb_strong[POS_LEFT])){
clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;
rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,
clip_cur,
clip_left,
alpha, beta, betaC, 1, 1, 1);
}
}
}
}
}
}
|
['static void rv40_loop_filter(RV34DecContext *r, int row)\n{\n MpegEncContext *s = &r->s;\n int mb_pos, mb_x;\n int i, j, k;\n uint8_t *Y, *C;\n int alpha, beta, betaY, betaC;\n int q;\n int mbtype[4];\n int mb_strong[4];\n int clip[4];\n int cbp[4];\n int uvcbp[4][2];\n unsigned mvmasks[4];\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int mbtype = s->current_picture_ptr->f.mb_type[mb_pos];\n if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype))\n r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF;\n if(IS_INTRA(mbtype))\n r->cbp_chroma[mb_pos] = 0xFF;\n }\n mb_pos = row * s->mb_stride;\n for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){\n int y_h_deblock, y_v_deblock;\n int c_v_deblock[2], c_h_deblock[2];\n int clip_left;\n int avail[4];\n unsigned y_to_deblock;\n int c_to_deblock[2];\n q = s->current_picture_ptr->f.qscale_table[mb_pos];\n alpha = rv40_alpha_tab[q];\n beta = rv40_beta_tab [q];\n betaY = betaC = beta * 3;\n if(s->width * s->height <= 176*144)\n betaY += beta;\n avail[0] = 1;\n avail[1] = row;\n avail[2] = mb_x;\n avail[3] = row < s->mb_height - 1;\n for(i = 0; i < 4; i++){\n if(avail[i]){\n int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride;\n mvmasks[i] = r->deblock_coefs[pos];\n mbtype [i] = s->current_picture_ptr->f.mb_type[pos];\n cbp [i] = r->cbp_luma[pos];\n uvcbp[i][0] = r->cbp_chroma[pos] & 0xF;\n uvcbp[i][1] = r->cbp_chroma[pos] >> 4;\n }else{\n mvmasks[i] = 0;\n mbtype [i] = mbtype[0];\n cbp [i] = 0;\n uvcbp[i][0] = uvcbp[i][1] = 0;\n }\n mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]);\n clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q];\n }\n y_to_deblock = mvmasks[POS_CUR]\n | (mvmasks[POS_BOTTOM] << 16);\n y_h_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW)\n | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12);\n y_v_deblock = y_to_deblock\n | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL)\n | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3);\n if(!mb_x)\n y_v_deblock &= ~MASK_Y_LEFT_COL;\n if(!row)\n y_h_deblock &= ~MASK_Y_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] | mb_strong[POS_BOTTOM]))\n y_h_deblock &= ~(MASK_Y_TOP_ROW << 16);\n for(i = 0; i < 2; i++){\n c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i];\n c_v_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL)\n | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1);\n c_h_deblock[i] = c_to_deblock[i]\n | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2)\n | (uvcbp[POS_CUR][i] << 2);\n if(!mb_x)\n c_v_deblock[i] &= ~MASK_C_LEFT_COL;\n if(!row)\n c_h_deblock[i] &= ~MASK_C_TOP_ROW;\n if(row == s->mb_height - 1 || (mb_strong[POS_CUR] | mb_strong[POS_BOTTOM]))\n c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4);\n }\n for(j = 0; j < 16; j += 4){\n Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize;\n for(i = 0; i < 4; i++, Y += 4){\n int ij = i + j;\n int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n int dither = j ? ij : i*4;\n if(y_h_deblock & (MASK_BOTTOM << ij)){\n rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize,\n s->linesize, dither,\n y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0,\n clip_cur, alpha, beta, betaY,\n 0, 0, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] | mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n else\n clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 0, 1);\n }\n if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] | mb_strong[POS_TOP])){\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0,\n alpha, beta, betaY, 0, 1, 0);\n }\n if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] | mb_strong[POS_LEFT])){\n clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither,\n clip_cur,\n clip_left,\n alpha, beta, betaY, 0, 1, 1);\n }\n }\n }\n for(k = 0; k < 2; k++){\n for(j = 0; j < 2; j++){\n C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize;\n for(i = 0; i < 2; i++, C += 4){\n int ij = i + j*2;\n int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0;\n if(c_h_deblock[k] & (MASK_CUR << (ij+2))){\n int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8,\n clip_bot,\n clip_cur,\n alpha, beta, betaC, 1, 0, 0);\n }\n if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] | mb_strong[POS_LEFT]))){\n if(!i)\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n else\n clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 0, 1);\n }\n if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] | mb_strong[POS_TOP])){\n int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8,\n clip_cur,\n clip_top,\n alpha, beta, betaC, 1, 1, 0);\n }\n if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] | mb_strong[POS_LEFT])){\n clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0;\n rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8,\n clip_cur,\n clip_left,\n alpha, beta, betaC, 1, 1, 1);\n }\n }\n }\n }\n }\n}']
|
954
| 0
|
https://github.com/libav/libav/blob/37e34df5a5cb3c493123ea18dc3141f9eef13458/ffmpeg.c/#L3186
|
static void new_audio_stream(AVFormatContext *oc)
{
AVStream *st;
AVCodecContext *audio_enc;
enum CodecID codec_id;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
av_exit(1);
}
avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;
audio_bitstream_filters= NULL;
if(thread_count>1)
avcodec_thread_init(st->codec, thread_count);
audio_enc = st->codec;
audio_enc->codec_type = CODEC_TYPE_AUDIO;
if(audio_codec_tag)
audio_enc->codec_tag= audio_codec_tag;
if (oc->oformat->flags & AVFMT_GLOBALHEADER) {
audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
if (audio_stream_copy) {
st->stream_copy = 1;
audio_enc->channels = audio_channels;
} else {
AVCodec *codec;
set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
if (audio_codec_name) {
codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);
codec = avcodec_find_encoder_by_name(audio_codec_name);
output_codecs[nb_ocodecs] = codec;
} else {
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
codec = avcodec_find_encoder(codec_id);
}
audio_enc->codec_id = codec_id;
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
}
audio_enc->thread_count = thread_count;
audio_enc->channels = audio_channels;
audio_enc->sample_fmt = audio_sample_fmt;
audio_enc->channel_layout = channel_layout;
if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)
audio_enc->channel_layout = 0;
if(codec && codec->sample_fmts){
const enum SampleFormat *p= codec->sample_fmts;
for(; *p!=-1; p++){
if(*p == audio_enc->sample_fmt)
break;
}
if(*p == -1)
audio_enc->sample_fmt = codec->sample_fmts[0];
}
}
nb_ocodecs++;
audio_enc->sample_rate = audio_sample_rate;
audio_enc->time_base= (AVRational){1, audio_sample_rate};
if (audio_language) {
av_metadata_set(&st->metadata, "language", audio_language);
av_free(audio_language);
audio_language = NULL;
}
audio_disable = 0;
av_freep(&audio_codec_name);
audio_stream_copy = 0;
}
|
['static void new_audio_stream(AVFormatContext *oc)\n{\n AVStream *st;\n AVCodecContext *audio_enc;\n enum CodecID codec_id;\n st = av_new_stream(oc, oc->nb_streams);\n if (!st) {\n fprintf(stderr, "Could not alloc stream\\n");\n av_exit(1);\n }\n avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);\n bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;\n audio_bitstream_filters= NULL;\n if(thread_count>1)\n avcodec_thread_init(st->codec, thread_count);\n audio_enc = st->codec;\n audio_enc->codec_type = CODEC_TYPE_AUDIO;\n if(audio_codec_tag)\n audio_enc->codec_tag= audio_codec_tag;\n if (oc->oformat->flags & AVFMT_GLOBALHEADER) {\n audio_enc->flags |= CODEC_FLAG_GLOBAL_HEADER;\n avcodec_opts[CODEC_TYPE_AUDIO]->flags|= CODEC_FLAG_GLOBAL_HEADER;\n }\n if (audio_stream_copy) {\n st->stream_copy = 1;\n audio_enc->channels = audio_channels;\n } else {\n AVCodec *codec;\n set_context_opts(audio_enc, avcodec_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);\n if (audio_codec_name) {\n codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);\n codec = avcodec_find_encoder_by_name(audio_codec_name);\n output_codecs[nb_ocodecs] = codec;\n } else {\n codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);\n codec = avcodec_find_encoder(codec_id);\n }\n audio_enc->codec_id = codec_id;\n if (audio_qscale > QSCALE_NONE) {\n audio_enc->flags |= CODEC_FLAG_QSCALE;\n audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;\n }\n audio_enc->thread_count = thread_count;\n audio_enc->channels = audio_channels;\n audio_enc->sample_fmt = audio_sample_fmt;\n audio_enc->channel_layout = channel_layout;\n if (avcodec_channel_layout_num_channels(channel_layout) != audio_channels)\n audio_enc->channel_layout = 0;\n if(codec && codec->sample_fmts){\n const enum SampleFormat *p= codec->sample_fmts;\n for(; *p!=-1; p++){\n if(*p == audio_enc->sample_fmt)\n break;\n }\n if(*p == -1)\n audio_enc->sample_fmt = codec->sample_fmts[0];\n }\n }\n nb_ocodecs++;\n audio_enc->sample_rate = audio_sample_rate;\n audio_enc->time_base= (AVRational){1, audio_sample_rate};\n if (audio_language) {\n av_metadata_set(&st->metadata, "language", audio_language);\n av_free(audio_language);\n audio_language = NULL;\n }\n audio_disable = 0;\n av_freep(&audio_codec_name);\n audio_stream_copy = 0;\n}', 'AVStream *av_new_stream(AVFormatContext *s, int id)\n{\n AVStream *st;\n int i;\n if (s->nb_streams >= MAX_STREAMS)\n return NULL;\n st = av_mallocz(sizeof(AVStream));\n if (!st)\n return NULL;\n st->codec= avcodec_alloc_context();\n if (s->iformat) {\n st->codec->bit_rate = 0;\n }\n st->index = s->nb_streams;\n st->id = id;\n st->start_time = AV_NOPTS_VALUE;\n st->duration = AV_NOPTS_VALUE;\n st->cur_dts = 0;\n st->first_dts = AV_NOPTS_VALUE;\n 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}']
|
955
| 0
|
https://github.com/openssl/openssl/blob/f9df0a7775f483c175cda5832360cccd1db6943a/crypto/bn/bn_lib.c/#L271
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
bn_check_top(b);
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return (NULL);
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return (NULL);
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['static int test_mod_exp_zero(void)\n{\n BIGNUM *a = NULL, *p = NULL, *m = NULL;\n BIGNUM *r = NULL;\n BN_ULONG one_word = 1;\n BN_CTX *ctx = BN_CTX_new();\n int ret = 1, failed = 0;\n if (!TEST_ptr(m = BN_new())\n || !TEST_ptr(a = BN_new())\n || !TEST_ptr(p = BN_new())\n || !TEST_ptr(r = BN_new()))\n goto err;\n BN_one(m);\n BN_one(a);\n BN_zero(p);\n if (!TEST_true(BN_rand(a, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)))\n goto err;\n if (!TEST_true(BN_mod_exp(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_recp(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_recp", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_simple(r, a, p, m, ctx)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_simple", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont(r, a, p, m, ctx, NULL)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)))\n goto err;\n if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a)))\n failed = 1;\n if (!TEST_true(BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL)))\n goto err;\n if (!TEST_BN_eq_zero(r)) {\n TEST_error("BN_mod_exp_mont_word failed: "\n "1 ** 0 mod 1 = r (should be 0)");\n BN_print_var(r);\n goto err;\n }\n ret = !failed;\n err:\n BN_free(r);\n BN_free(a);\n BN_free(p);\n BN_free(m);\n BN_CTX_free(ctx);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return (0);\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n bn_check_top(b);\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n bn_check_top(b);\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n bn_check_top(b);\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return (NULL);\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return (NULL);\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}']
|
956
| 0
|
https://github.com/openssl/openssl/blob/7432d073af97539e5a2c8b0f1ff254d6b53c9682/ssl/ssl_lib.c/#L1372
|
STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
STACK_OF(SSL_CIPHER) **skp)
{
SSL_CIPHER *c;
STACK_OF(SSL_CIPHER) *sk;
int i,n;
n=ssl_put_cipher_by_char(s,NULL,NULL);
if ((num%n) != 0)
{
SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
return(NULL);
}
if ((skp == NULL) || (*skp == NULL))
sk=sk_SSL_CIPHER_new_null();
else
{
sk= *skp;
sk_SSL_CIPHER_zero(sk);
}
for (i=0; i<num; i+=n)
{
c=ssl_get_cipher_by_char(s,p);
p+=n;
if (c != NULL)
{
if (!sk_SSL_CIPHER_push(sk,c))
{
SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
goto err;
}
}
}
if (skp != NULL)
*skp=sk;
return(sk);
err:
if ((skp == NULL) || (*skp == NULL))
sk_SSL_CIPHER_free(sk);
return(NULL);
}
|
['STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,\n\t\t\t\t\t STACK_OF(SSL_CIPHER) **skp)\n\t{\n\tSSL_CIPHER *c;\n\tSTACK_OF(SSL_CIPHER) *sk;\n\tint i,n;\n\tn=ssl_put_cipher_by_char(s,NULL,NULL);\n\tif ((num%n) != 0)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);\n\t\treturn(NULL);\n\t\t}\n\tif ((skp == NULL) || (*skp == NULL))\n\t\tsk=sk_SSL_CIPHER_new_null();\n\telse\n\t\t{\n\t\tsk= *skp;\n\t\tsk_SSL_CIPHER_zero(sk);\n\t\t}\n\tfor (i=0; i<num; i+=n)\n\t\t{\n\t\tc=ssl_get_cipher_by_char(s,p);\n\t\tp+=n;\n\t\tif (c != NULL)\n\t\t\t{\n\t\t\tif (!sk_SSL_CIPHER_push(sk,c))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (skp != NULL)\n\t\t*skp=sk;\n\treturn(sk);\nerr:\n\tif ((skp == NULL) || (*skp == NULL))\n\t\tsk_SSL_CIPHER_free(sk);\n\treturn(NULL);\n\t}', 'STACK *sk_new_null(void)\n\t{\n\treturn sk_new((int (*)(const char * const *, const char * const *))0);\n\t}', 'STACK *sk_new(int (*c)(const char * const *, const char * const *))\n\t{\n\tSTACK *ret;\n\tint i;\n\tif ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)\n\t\tgoto err;\n\tif ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)\n\t\tgoto err;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->data[i]=NULL;\n\tret->comp=c;\n\tret->num_alloc=MIN_NODES;\n\tret->num=0;\n\tret->sorted=0;\n\treturn(ret);\nerr:\n\tif(ret)\n\t\tOPENSSL_free(ret);\n\treturn(NULL);\n\t}', 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\tif (num <= 0) return NULL;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n#ifndef OPENSSL_CPUID_OBJ\n if(ret && (num > 2048))\n\t{\textern unsigned char cleanse_ctr;\n ((unsigned char *)ret)[0] = cleanse_ctr;\n\t}\n#endif\n\treturn ret;\n\t}', 'int sk_push(STACK *st, char *data)\n\t{\n\treturn(sk_insert(st,data,st->num));\n\t}']
|
957
| 0
|
https://github.com/openssl/openssl/blob/8e826a339f8cda20a4311fa88a1de782972cf40d/crypto/bn/bn_sqr.c/#L120
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['int dsa_builtin_paramgen2(DSA *ret, size_t L, size_t N,\n const EVP_MD *evpmd, const unsigned char *seed_in,\n size_t seed_len, int idx, unsigned char *seed_out,\n int *counter_ret, unsigned long *h_ret,\n BN_GENCB *cb)\n{\n int ok = -1;\n unsigned char *seed = NULL, *seed_tmp = NULL;\n unsigned char md[EVP_MAX_MD_SIZE];\n int mdsize;\n BIGNUM *r0, *W, *X, *c, *test;\n BIGNUM *g = NULL, *q = NULL, *p = NULL;\n BN_MONT_CTX *mont = NULL;\n int i, k, n = 0, m = 0, qsize = N >> 3;\n int counter = 0;\n int r = 0;\n BN_CTX *ctx = NULL;\n EVP_MD_CTX *mctx = EVP_MD_CTX_new();\n unsigned int h = 2;\n if (mctx == NULL)\n goto err;\n if (evpmd == NULL) {\n if (N == 160)\n evpmd = EVP_sha1();\n else if (N == 224)\n evpmd = EVP_sha224();\n else\n evpmd = EVP_sha256();\n }\n mdsize = EVP_MD_size(evpmd);\n if (!ret->p || !ret->q || idx >= 0) {\n if (seed_len == 0)\n seed_len = mdsize;\n seed = OPENSSL_malloc(seed_len);\n if (seed_out)\n seed_tmp = seed_out;\n else\n seed_tmp = OPENSSL_malloc(seed_len);\n if (seed == NULL || seed_tmp == NULL)\n goto err;\n if (seed_in)\n memcpy(seed, seed_in, seed_len);\n }\n if ((ctx = BN_CTX_new()) == NULL)\n goto err;\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n BN_CTX_start(ctx);\n r0 = BN_CTX_get(ctx);\n g = BN_CTX_get(ctx);\n W = BN_CTX_get(ctx);\n X = BN_CTX_get(ctx);\n c = BN_CTX_get(ctx);\n test = BN_CTX_get(ctx);\n if (test == NULL)\n goto err;\n if (ret->p && ret->q) {\n p = ret->p;\n q = ret->q;\n if (idx >= 0)\n memcpy(seed_tmp, seed, seed_len);\n goto g_only;\n } else {\n p = BN_CTX_get(ctx);\n q = BN_CTX_get(ctx);\n if (q == NULL)\n goto err;\n }\n if (!BN_lshift(test, BN_value_one(), L - 1))\n goto err;\n for (;;) {\n for (;;) {\n unsigned char *pmd;\n if (!BN_GENCB_call(cb, 0, m++))\n goto err;\n if (!seed_in) {\n if (RAND_bytes(seed, seed_len) <= 0)\n goto err;\n }\n if (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n goto err;\n if (mdsize > qsize)\n pmd = md + mdsize - qsize;\n else\n pmd = md;\n if (mdsize < qsize)\n memset(md + mdsize, 0, qsize - mdsize);\n pmd[0] |= 0x80;\n pmd[qsize - 1] |= 0x01;\n if (!BN_bin2bn(pmd, qsize, q))\n goto err;\n r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,\n seed_in ? 1 : 0, cb);\n if (r > 0)\n break;\n if (r != 0)\n goto err;\n if (seed_in) {\n ok = 0;\n DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_Q_NOT_PRIME);\n goto err;\n }\n }\n if (seed_out)\n memcpy(seed_out, seed, seed_len);\n if (!BN_GENCB_call(cb, 2, 0))\n goto err;\n if (!BN_GENCB_call(cb, 3, 0))\n goto err;\n counter = 0;\n n = (L - 1) / (mdsize << 3);\n for (;;) {\n if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))\n goto err;\n BN_zero(W);\n for (k = 0; k <= n; k++) {\n for (i = seed_len - 1; i >= 0; i--) {\n seed[i]++;\n if (seed[i] != 0)\n break;\n }\n if (!EVP_Digest(seed, seed_len, md, NULL, evpmd, NULL))\n goto err;\n if (!BN_bin2bn(md, mdsize, r0))\n goto err;\n if (!BN_lshift(r0, r0, (mdsize << 3) * k))\n goto err;\n if (!BN_add(W, W, r0))\n goto err;\n }\n if (!BN_mask_bits(W, L - 1))\n goto err;\n if (!BN_copy(X, W))\n goto err;\n if (!BN_add(X, X, test))\n goto err;\n if (!BN_lshift1(r0, q))\n goto err;\n if (!BN_mod(c, X, r0, ctx))\n goto err;\n if (!BN_sub(r0, c, BN_value_one()))\n goto err;\n if (!BN_sub(p, X, r0))\n goto err;\n if (BN_cmp(p, test) >= 0) {\n r = BN_is_prime_fasttest_ex(p, DSS_prime_checks, ctx, 1, cb);\n if (r > 0)\n goto end;\n if (r != 0)\n goto err;\n }\n counter++;\n if (counter >= (int)(4 * L))\n break;\n }\n if (seed_in) {\n ok = 0;\n DSAerr(DSA_F_DSA_BUILTIN_PARAMGEN2, DSA_R_INVALID_PARAMETERS);\n goto err;\n }\n }\n end:\n if (!BN_GENCB_call(cb, 2, 1))\n goto err;\n g_only:\n if (!BN_sub(test, p, BN_value_one()))\n goto err;\n if (!BN_div(r0, NULL, test, q, ctx))\n goto err;\n if (idx < 0) {\n if (!BN_set_word(test, h))\n goto err;\n } else\n h = 1;\n if (!BN_MONT_CTX_set(mont, p, ctx))\n goto err;\n for (;;) {\n static const unsigned char ggen[4] = { 0x67, 0x67, 0x65, 0x6e };\n if (idx >= 0) {\n md[0] = idx & 0xff;\n md[1] = (h >> 8) & 0xff;\n md[2] = h & 0xff;\n if (!EVP_DigestInit_ex(mctx, evpmd, NULL))\n goto err;\n if (!EVP_DigestUpdate(mctx, seed_tmp, seed_len))\n goto err;\n if (!EVP_DigestUpdate(mctx, ggen, sizeof(ggen)))\n goto err;\n if (!EVP_DigestUpdate(mctx, md, 3))\n goto err;\n if (!EVP_DigestFinal_ex(mctx, md, NULL))\n goto err;\n if (!BN_bin2bn(md, mdsize, test))\n goto err;\n }\n if (!BN_mod_exp_mont(g, test, r0, p, ctx, mont))\n goto err;\n if (!BN_is_one(g))\n break;\n if (idx < 0 && !BN_add(test, test, BN_value_one()))\n goto err;\n h++;\n if (idx >= 0 && h > 0xffff)\n goto err;\n }\n if (!BN_GENCB_call(cb, 3, 1))\n goto err;\n ok = 1;\n err:\n if (ok == 1) {\n if (p != ret->p) {\n BN_free(ret->p);\n ret->p = BN_dup(p);\n }\n if (q != ret->q) {\n BN_free(ret->q);\n ret->q = BN_dup(q);\n }\n BN_free(ret->g);\n ret->g = BN_dup(g);\n if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {\n ok = -1;\n goto err;\n }\n if (counter_ret != NULL)\n *counter_ret = counter;\n if (h_ret != NULL)\n *h_ret = h;\n }\n OPENSSL_free(seed);\n if (seed_out != seed_tmp)\n OPENSSL_free(seed_tmp);\n if (ctx)\n BN_CTX_end(ctx);\n BN_CTX_free(ctx);\n BN_MONT_CTX_free(mont);\n EVP_MD_CTX_free(mctx);\n return ok;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return (0);\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'int BN_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_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (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_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n 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 ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
958
| 0
|
https://github.com/openssl/openssl/blob/edbcba6c6bd4587e96fb4e4d07a6c24920897579/ssl/s3_clnt.c/#L1648
|
static int ssl3_check_cert_and_algorithm(SSL *s)
{
int i,idx;
long algs;
EVP_PKEY *pkey=NULL;
SESS_CERT *sc;
#ifndef NO_RSA
RSA *rsa;
#endif
#ifndef NO_DH
DH *dh;
#endif
sc=s->session->sess_cert;
if (sc == NULL)
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);
goto err;
}
algs=s->s3->tmp.new_cipher->algorithms;
if (algs & (SSL_aDH|SSL_aNULL))
return(1);
#ifndef NO_RSA
rsa=s->session->sess_cert->peer_rsa_tmp;
#endif
#ifndef NO_DH
dh=s->session->sess_cert->peer_dh_tmp;
#endif
idx=sc->peer_cert_type;
pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);
i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);
EVP_PKEY_free(pkey);
if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
goto f_err;
}
#ifndef NO_DSA
else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
goto f_err;
}
#endif
#ifndef NO_RSA
if ((algs & SSL_kRSA) &&
!(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
goto f_err;
}
#endif
#ifndef NO_DH
if ((algs & SSL_kEDH) &&
!(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
goto f_err;
}
else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
goto f_err;
}
#ifndef NO_DSA
else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
goto f_err;
}
#endif
#endif
if (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))
{
#ifndef NO_RSA
if (algs & SSL_kRSA)
{
if (rsa == NULL
|| RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
goto f_err;
}
}
else
#endif
#ifndef NO_DH
if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
{
if (dh == NULL
|| DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
goto f_err;
}
}
else
#endif
{
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
goto f_err;
}
}
return(1);
f_err:
ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
err:
return(0);
}
|
['static int ssl3_check_cert_and_algorithm(SSL *s)\n\t{\n\tint i,idx;\n\tlong algs;\n\tEVP_PKEY *pkey=NULL;\n\tSESS_CERT *sc;\n#ifndef NO_RSA\n\tRSA *rsa;\n#endif\n#ifndef NO_DH\n\tDH *dh;\n#endif\n\tsc=s->session->sess_cert;\n\tif (sc == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);\n\t\tgoto err;\n\t\t}\n\talgs=s->s3->tmp.new_cipher->algorithms;\n\tif (algs & (SSL_aDH|SSL_aNULL))\n\t\treturn(1);\n#ifndef NO_RSA\n\trsa=s->session->sess_cert->peer_rsa_tmp;\n#endif\n#ifndef NO_DH\n\tdh=s->session->sess_cert->peer_dh_tmp;\n#endif\n\tidx=sc->peer_cert_type;\n\tpkey=X509_get_pubkey(sc->peer_pkeys[idx].x509);\n\ti=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey);\n\tEVP_PKEY_free(pkey);\n\tif ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);\n\t\tgoto f_err;\n\t\t}\n#ifndef NO_DSA\n\telse if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);\n\t\tgoto f_err;\n\t\t}\n#endif\n#ifndef NO_RSA\n\tif ((algs & SSL_kRSA) &&\n\t\t!(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);\n\t\tgoto f_err;\n\t\t}\n#endif\n#ifndef NO_DH\n\tif ((algs & SSL_kEDH) &&\n\t\t!(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);\n\t\tgoto f_err;\n\t\t}\n\telse if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);\n\t\tgoto f_err;\n\t\t}\n#ifndef NO_DSA\n\telse if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);\n\t\tgoto f_err;\n\t\t}\n#endif\n#endif\n\tif (SSL_C_IS_EXPORT(s->s3->tmp.new_cipher) && !has_bits(i,EVP_PKT_EXP))\n\t\t{\n#ifndef NO_RSA\n\t\tif (algs & SSL_kRSA)\n\t\t\t{\n\t\t\tif (rsa == NULL\n\t\t\t || RSA_size(rsa) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n#ifndef NO_DH\n\t\t\tif (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))\n\t\t\t {\n\t\t\t if (dh == NULL\n\t\t\t\t|| DH_size(dh) > SSL_C_EXPORT_PKEYLENGTH(s->s3->tmp.new_cipher))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);\n\t\t\t\tgoto f_err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n#endif\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);\n\t\t\tgoto f_err;\n\t\t\t}\n\t\t}\n\treturn(1);\nf_err:\n\tssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);\nerr:\n\treturn(0);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}']
|
959
| 0
|
https://github.com/libav/libav/blob/74b1f96859eb967222fcb3eb4c72d949b5165a89/libavcodec/bink.c/#L1242
|
static av_cold void binkb_calc_quant()
{
float s[64];
int i, j;
for (j = 0; j < 8; j++) {
for (i = 0; i < 8; i++) {
if (j && j != 4)
if (i && i != 4)
s[j*8 + i] = cos(j * M_PI/16.0f) * cos(i * M_PI/16.0f) * 2.0f;
else
s[j*8 + i] = cos(j * M_PI/16.0f) * sqrt(2.0f);
else
if (i && i != 4)
s[j*8 + i] = cos(i * M_PI/16.0f) * sqrt(2.0f);
else
s[j*8 + i] = 1.0f;
}
}
for (j = 0; j < 16; j++) {
for (i = 0; i < 64; i++) {
binkb_intra_quant[j][i] = (1L << 12) * binkb_intra_seed[i] * s[i] *
binkb_num[j]/(float)binkb_den[j];
binkb_inter_quant[j][i] = (1L << 12) * binkb_inter_seed[i] * s[i] *
binkb_num[j]/(float)binkb_den[j];
}
}
}
|
['static av_cold void binkb_calc_quant()\n{\n float s[64];\n int i, j;\n for (j = 0; j < 8; j++) {\n for (i = 0; i < 8; i++) {\n if (j && j != 4)\n if (i && i != 4)\n s[j*8 + i] = cos(j * M_PI/16.0f) * cos(i * M_PI/16.0f) * 2.0f;\n else\n s[j*8 + i] = cos(j * M_PI/16.0f) * sqrt(2.0f);\n else\n if (i && i != 4)\n s[j*8 + i] = cos(i * M_PI/16.0f) * sqrt(2.0f);\n else\n s[j*8 + i] = 1.0f;\n }\n }\n for (j = 0; j < 16; j++) {\n for (i = 0; i < 64; i++) {\n binkb_intra_quant[j][i] = (1L << 12) * binkb_intra_seed[i] * s[i] *\n binkb_num[j]/(float)binkb_den[j];\n binkb_inter_quant[j][i] = (1L << 12) * binkb_inter_seed[i] * s[i] *\n binkb_num[j]/(float)binkb_den[j];\n }\n }\n}']
|
960
| 0
|
https://github.com/libav/libav/blob/688417399c69aadd4c287bdb0dec82ef8799011c/libavcodec/hevcdsp_template.c/#L904
|
PUT_HEVC_QPEL_HV(2, 1)
|
['QPEL(4)', 'PUT_HEVC_QPEL_HV(2, 1)']
|
961
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_ctx.c/#L273
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,\n const BIGNUM *b, const BIGNUM *N)\n{\n BIGNUM *tmp = NULL, *S = NULL;\n BN_CTX *bn_ctx;\n if (u == NULL || A == NULL || v == NULL || b == NULL || N == NULL)\n return NULL;\n if ((bn_ctx = BN_CTX_new()) == NULL || (tmp = BN_new()) == NULL)\n goto err;\n if (!BN_mod_exp(tmp, v, u, N, bn_ctx))\n goto err;\n if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))\n goto err;\n S = BN_new();\n if (S != NULL && !BN_mod_exp(S, tmp, b, N, bn_ctx)) {\n BN_free(S);\n S = NULL;\n }\n err:\n BN_CTX_free(bn_ctx);\n BN_clear_free(tmp);\n return S;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n BN_CTX *ctx)\n{\n int ret;\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n if (a->top == 1 && !a->neg\n && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n BN_MONT_CTX *mont = NULL;\n int b, bits, ret = 0;\n int r_is_one;\n BN_ULONG w, next_w;\n BIGNUM *r, *t;\n BIGNUM *swap_tmp;\n#define BN_MOD_MUL_WORD(r, w, m) \\\n (BN_mul_word(r, (w)) && \\\n ( \\\n (BN_mod(t, r, m, ctx) && (swap_tmp = r, r = t, t = swap_tmp, 1))))\n#define BN_TO_MONTGOMERY_WORD(r, w, mont) \\\n (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n return 0;\n }\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_WORD, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n if (m->top == 1)\n a %= m->d[0];\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n if (a == 0) {\n BN_zero(rr);\n ret = 1;\n return ret;\n }\n BN_CTX_start(ctx);\n r = BN_CTX_get(ctx);\n t = BN_CTX_get(ctx);\n if (t == NULL)\n goto err;\n if (in_mont != NULL)\n mont = in_mont;\n else {\n if ((mont = BN_MONT_CTX_new()) == NULL)\n goto err;\n if (!BN_MONT_CTX_set(mont, m, ctx))\n goto err;\n }\n r_is_one = 1;\n w = a;\n for (b = bits - 2; b >= 0; b--) {\n next_w = w * w;\n if ((next_w / w) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = 1;\n }\n w = next_w;\n if (!r_is_one) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (BN_is_bit_set(p, b)) {\n next_w = w * a;\n if ((next_w / a) != w) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n next_w = a;\n }\n w = next_w;\n }\n }\n if (w != 1) {\n if (r_is_one) {\n if (!BN_TO_MONTGOMERY_WORD(r, w, mont))\n goto err;\n r_is_one = 0;\n } else {\n if (!BN_MOD_MUL_WORD(r, w, m))\n goto err;\n }\n }\n if (r_is_one) {\n if (!BN_one(rr))\n goto err;\n } else {\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n }\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', '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_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_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}']
|
962
| 0
|
https://github.com/openssl/openssl/blob/eaeb1870d4ef887a89f0bcec6b5ee1ec7fafa00f/crypto/bn/bn_lib.c/#L470
|
BIGNUM *bn_expand2(BIGNUM *b, int words)
{
BN_ULONG *A,*a;
const BN_ULONG *B;
int i;
bn_check_top(b);
if (words > b->max)
{
bn_check_top(b);
if (BN_get_flags(b,BN_FLG_STATIC_DATA))
{
BNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return(NULL);
}
a=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));
if (A == NULL)
{
BNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);
return(NULL);
}
#if 1
B=b->d;
if (B != NULL)
{
#if 0
for (i=b->top&(~7); i>0; i-=8)
{
A[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];
A[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];
A+=8;
B+=8;
}
switch (b->top&7)
{
case 7:
A[6]=B[6];
case 6:
A[5]=B[5];
case 5:
A[4]=B[4];
case 4:
A[3]=B[3];
case 3:
A[2]=B[2];
case 2:
A[1]=B[1];
case 1:
A[0]=B[0];
case 0:
;
}
#else
for (i=b->top>>2; i>0; i--,A+=4,B+=4)
{
BN_ULONG a0,a1,a2,a3;
a0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];
A[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;
}
switch (b->top&3)
{
case 3: A[2]=B[2];
case 2: A[1]=B[1];
case 1: A[0]=B[0];
case 0: ;
}
#endif
Free(b->d);
}
b->d=a;
b->max=words;
A= &(b->d[b->top]);
for (i=(b->max - b->top)>>3; i>0; i--,A+=8)
{
A[0]=0; A[1]=0; A[2]=0; A[3]=0;
A[4]=0; A[5]=0; A[6]=0; A[7]=0;
}
for (i=(b->max - b->top)&7; i>0; i--,A++)
A[0]=0;
#else
memset(A,0,sizeof(BN_ULONG)*(words+1));
memcpy(A,b->d,sizeof(b->d[0])*b->top);
b->d=a;
b->max=words;
#endif
}
return(b);
}
|
['int test_rshift1(BIO *bp)\n\t{\n\tBIGNUM *a,*b,*c;\n\tint i;\n\ta=BN_new();\n\tb=BN_new();\n\tc=BN_new();\n\tBN_rand(a,200,0,0);\n\ta->neg=rand_neg();\n\tfor (i=0; i<70; i++)\n\t\t{\n\t\tBN_rshift1(b,a);\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," / 2");\n\t\t\t\tBIO_puts(bp," - ");\n\t\t\t\t}\n\t\t\tBN_print(bp,b);\n\t\t\tBIO_puts(bp,"\\n");\n\t\t\t}\n\t\tBN_sub(c,a,b);\n\t\tBN_sub(c,c,b);\n\t\tif(!BN_is_zero(c) && !BN_is_one(c))\n\t\t {\n\t\t BIO_puts(bp,"Right shift one test failed!\\n");\n\t\t return 0;\n\t\t }\n\t\tBN_copy(a,b);\n\t\t}\n\tBN_free(a);\n\tBN_free(b);\n\tBN_free(c);\n\treturn(1);\n\t}', 'int BN_sub(BIGNUM *r, BIGNUM *a, BIGNUM *b)\n\t{\n\tint max;\n\tint add=0,neg=0;\n\tBIGNUM *tmp;\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->neg)\n\t\t{\n\t\tif (b->neg)\n\t\t\t{ tmp=a; a=b; b=tmp; }\n\t\telse\n\t\t\t{ add=1; neg=1; }\n\t\t}\n\telse\n\t\t{\n\t\tif (b->neg) { add=1; neg=0; }\n\t\t}\n\tif (add)\n\t\t{\n\t\tif (!BN_uadd(r,a,b)) return(0);\n\t\tr->neg=neg;\n\t\treturn(1);\n\t\t}\n\tmax=(a->top > b->top)?a->top:b->top;\n\tif (bn_wexpand(r,max) == NULL) return(0);\n\tif (BN_ucmp(a,b) < 0)\n\t\t{\n\t\tif (!BN_usub(r,b,a)) return(0);\n\t\tr->neg=1;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_usub(r,a,b)) return(0);\n\t\tr->neg=0;\n\t\t}\n\treturn(1);\n\t}', 'BIGNUM *BN_copy(BIGNUM *a, BIGNUM *b)\n\t{\n\tint i;\n\tBN_ULONG *A;\n\tconst BN_ULONG *B;\n\tbn_check_top(b);\n\tif (a == b) return(a);\n\tif (bn_wexpand(a,b->top) == NULL) return(NULL);\n#if 1\n\tA=a->d;\n\tB=b->d;\n\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t{\n\t\tBN_ULONG a0,a1,a2,a3;\n\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t}\n\tswitch (b->top&3)\n\t\t{\n\t\tcase 3: A[2]=B[2];\n\t\tcase 2: A[1]=B[1];\n\t\tcase 1: A[0]=B[0];\n\t\tcase 0: ;\n\t\t}\n#else\n\tmemcpy(a->d,b->d,sizeof(b->d[0])*b->top);\n#endif\n\ta->top=b->top;\n\tif ((a->top == 0) && (a->d != NULL))\n\t\ta->d[0]=0;\n\ta->neg=b->neg;\n\treturn(a);\n\t}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n\t{\n\tBN_ULONG *A,*a;\n\tconst BN_ULONG *B;\n\tint i;\n\tbn_check_top(b);\n\tif (words > b->max)\n\t\t{\n\t\tbn_check_top(b);\n\t\tif (BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n\t\t\treturn(NULL);\n\t\t\t}\n\t\ta=A=(BN_ULONG *)Malloc(sizeof(BN_ULONG)*(words+1));\n\t\tif (A == NULL)\n\t\t\t{\n\t\t\tBNerr(BN_F_BN_EXPAND2,ERR_R_MALLOC_FAILURE);\n\t\t\treturn(NULL);\n\t\t\t}\n#if 1\n\t\tB=b->d;\n\t\tif (B != NULL)\n\t\t\t{\n#if 0\n\t\t\tfor (i=b->top&(~7); i>0; i-=8)\n\t\t\t\t{\n\t\t\t\tA[0]=B[0]; A[1]=B[1]; A[2]=B[2]; A[3]=B[3];\n\t\t\t\tA[4]=B[4]; A[5]=B[5]; A[6]=B[6]; A[7]=B[7];\n\t\t\t\tA+=8;\n\t\t\t\tB+=8;\n\t\t\t\t}\n\t\t\tswitch (b->top&7)\n\t\t\t\t{\n\t\t\tcase 7:\n\t\t\t\tA[6]=B[6];\n\t\t\tcase 6:\n\t\t\t\tA[5]=B[5];\n\t\t\tcase 5:\n\t\t\t\tA[4]=B[4];\n\t\t\tcase 4:\n\t\t\t\tA[3]=B[3];\n\t\t\tcase 3:\n\t\t\t\tA[2]=B[2];\n\t\t\tcase 2:\n\t\t\t\tA[1]=B[1];\n\t\t\tcase 1:\n\t\t\t\tA[0]=B[0];\n\t\t\tcase 0:\n\t\t\t\t;\n\t\t\t\t}\n#else\n\t\t\tfor (i=b->top>>2; i>0; i--,A+=4,B+=4)\n\t\t\t\t{\n\t\t\t\tBN_ULONG a0,a1,a2,a3;\n\t\t\t\ta0=B[0]; a1=B[1]; a2=B[2]; a3=B[3];\n\t\t\t\tA[0]=a0; A[1]=a1; A[2]=a2; A[3]=a3;\n\t\t\t\t}\n\t\t\tswitch (b->top&3)\n\t\t\t\t{\n\t\t\t\tcase 3:\tA[2]=B[2];\n\t\t\t\tcase 2:\tA[1]=B[1];\n\t\t\t\tcase 1:\tA[0]=B[0];\n\t\t\t\tcase 0:\t;\n\t\t\t\t}\n#endif\n\t\t\tFree(b->d);\n\t\t\t}\n\t\tb->d=a;\n\t\tb->max=words;\n\t\tA= &(b->d[b->top]);\n\t\tfor (i=(b->max - b->top)>>3; i>0; i--,A+=8)\n\t\t\t{\n\t\t\tA[0]=0; A[1]=0; A[2]=0; A[3]=0;\n\t\t\tA[4]=0; A[5]=0; A[6]=0; A[7]=0;\n\t\t\t}\n\t\tfor (i=(b->max - b->top)&7; i>0; i--,A++)\n\t\t\tA[0]=0;\n#else\n\t\t\tmemset(A,0,sizeof(BN_ULONG)*(words+1));\n\t\t\tmemcpy(A,b->d,sizeof(b->d[0])*b->top);\n\t\t\tb->d=a;\n\t\t\tb->max=words;\n#endif\n\t\t}\n\treturn(b);\n\t}']
|
963
| 0
|
https://github.com/libav/libav/blob/2f99117f6ff24ce5be2abb9e014cb8b86c2aa0e0/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 twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,\n const uint8_t *buf, int buf_size)\n{\n TwinVQFrameData *bits = &tctx->bits[0];\n const TwinVQModeTab *mtab = tctx->mtab;\n int channels = tctx->avctx->channels;\n int sub;\n BitstreamContext bc;\n int i, j, k;\n bitstream_init(&bc, buf, buf_size * 8);\n bitstream_skip(&bc, bitstream_read(&bc, 8));\n bits->window_type = bitstream_read(&bc, TWINVQ_WINDOW_TYPE_BITS);\n if (bits->window_type > 8) {\n av_log(avctx, AV_LOG_ERROR, "Invalid window type, broken sample?\\n");\n return AVERROR_INVALIDDATA;\n }\n bits->ftype = ff_twinvq_wtype_to_ftype_table[tctx->bits[0].window_type];\n sub = mtab->fmode[bits->ftype].sub;\n read_cb_data(tctx, &bc, bits->main_coeffs, bits->ftype);\n for (i = 0; i < channels; i++)\n for (j = 0; j < sub; j++)\n for (k = 0; k < mtab->fmode[bits->ftype].bark_n_coef; k++)\n bits->bark1[i][j][k] =\n bitstream_read(&bc, mtab->fmode[bits->ftype].bark_n_bit);\n for (i = 0; i < channels; i++)\n for (j = 0; j < sub; j++)\n bits->bark_use_hist[i][j] = bitstream_read_bit(&bc);\n if (bits->ftype == TWINVQ_FT_LONG) {\n for (i = 0; i < channels; i++)\n bits->gain_bits[i] = bitstream_read(&bc, TWINVQ_GAIN_BITS);\n } else {\n for (i = 0; i < channels; i++) {\n bits->gain_bits[i] = bitstream_read(&bc, TWINVQ_GAIN_BITS);\n for (j = 0; j < sub; j++)\n bits->sub_gain_bits[i * sub + j] = bitstream_read(&bc, TWINVQ_SUB_GAIN_BITS);\n }\n }\n for (i = 0; i < channels; i++) {\n bits->lpc_hist_idx[i] = bitstream_read(&bc, mtab->lsp_bit0);\n bits->lpc_idx1[i] = bitstream_read(&bc, mtab->lsp_bit1);\n for (j = 0; j < mtab->lsp_split; j++)\n bits->lpc_idx2[i][j] = bitstream_read(&bc, mtab->lsp_bit2);\n }\n if (bits->ftype == TWINVQ_FT_LONG) {\n read_cb_data(tctx, &bc, bits->ppc_coeffs, 3);\n for (i = 0; i < channels; i++) {\n bits->p_coef[i] = bitstream_read(&bc, mtab->ppc_period_bit);\n bits->g_coef[i] = bitstream_read(&bc, mtab->pgain_bit);\n }\n }\n return 0;\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline uint64_t get_val(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n uint64_t ret = bc->bits & ((UINT64_C(1) << n) - 1);\n bc->bits >>= n;\n#else\n uint64_t ret = bc->bits >> (64 - n);\n bc->bits <<= n;\n#endif\n bc->bits_left -= n;\n return ret;\n}']
|
964
| 0
|
https://github.com/libav/libav/blob/78bc4d69ebe6189395e5c7e4719ddef50bc943ba/libavcodec/h264.c/#L1128
|
static void copy_parameter_set(void **to, void **from, int count, int size)
{
int i;
for (i = 0; i < count; i++) {
if (to[i] && !from[i])
av_freep(&to[i]);
else if (from[i] && !to[i])
to[i] = av_malloc(size);
if (from[i])
memcpy(to[i], from[i], size);
}
}
|
['static void copy_parameter_set(void **to, void **from, int count, int size)\n{\n int i;\n for (i = 0; i < count; i++) {\n if (to[i] && !from[i])\n av_freep(&to[i]);\n else if (from[i] && !to[i])\n to[i] = av_malloc(size);\n if (from[i])\n memcpy(to[i], from[i], size);\n }\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}']
|
965
| 0
|
https://github.com/openssl/openssl/blob/55525742f4c2bf416013fc3a75ec642775d97f80/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint i;\n\tint ret = -2;\n\tint err = 0;\n\tBIGNUM *A, *B, *tmp;\n\tstatic const int tab[8] = {0, 1, 0, -1, 0, -1, 0, 1};\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tBN_CTX_start(ctx);\n\tA = BN_CTX_get(ctx);\n\tB = BN_CTX_get(ctx);\n\tif (B == NULL) goto end;\n\terr = !BN_copy(A, a);\n\tif (err) goto end;\n\terr = !BN_copy(B, b);\n\tif (err) goto end;\n\tif (BN_is_zero(B))\n\t\t{\n\t\tret = BN_abs_is_word(A, 1);\n\t\tgoto end;\n \t\t}\n\tif (!BN_is_odd(A) && !BN_is_odd(B))\n\t\t{\n\t\tret = 0;\n\t\tgoto end;\n\t\t}\n\ti = 0;\n\twhile (!BN_is_bit_set(B, i))\n\t\ti++;\n\terr = !BN_rshift(B, B, i);\n\tif (err) goto end;\n\tif (i & 1)\n\t\t{\n\t\tret = tab[BN_lsw(A) & 7];\n\t\t}\n\telse\n\t\t{\n\t\tret = 1;\n\t\t}\n\tif (B->neg)\n\t\t{\n\t\tB->neg = 0;\n\t\tif (A->neg)\n\t\t\tret = -ret;\n\t\t}\n\twhile (1)\n\t\t{\n\t\tif (BN_is_zero(A))\n\t\t\t{\n\t\t\tret = BN_is_one(B) ? ret : 0;\n\t\t\tgoto end;\n\t\t\t}\n\t\ti = 0;\n\t\twhile (!BN_is_bit_set(A, i))\n\t\t\ti++;\n\t\terr = !BN_rshift(A, A, i);\n\t\tif (err) goto end;\n\t\tif (i & 1)\n\t\t\t{\n\t\t\tret = ret * tab[BN_lsw(B) & 7];\n\t\t\t}\n\t\tif ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)\n\t\t\tret = -ret;\n\t\terr = !BN_nnmod(B, B, A, ctx);\n\t\tif (err) goto end;\n\t\ttmp = A; A = B; B = tmp;\n\t\ttmp->neg = 0;\n\t\t}\nend:\n\tBN_CTX_end(ctx);\n\tif (err)\n\t\treturn -2;\n\telse\n\t\treturn ret;\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))\n\t\t{\n\t\treturn BN_div_no_branch(dv, rm, num, divisor, ctx);\n\t\t}\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n\tconst BIGNUM *divisor, BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tif (snum->top <= sdiv->top+1)\n\t\t{\n\t\tif (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;\n\t\tfor (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;\n\t\tsnum->top = sdiv->top + 2;\n\t\t}\n\telse\n\t\t{\n\t\tif (bn_wexpand(snum, snum->top + 1) == NULL) goto err;\n\t\tsnum->d[snum->top] = 0;\n\t\tsnum->top ++;\n\t\t}\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop-1;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tbn_correct_top(res);\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
966
| 0
|
https://github.com/openssl/openssl/blob/5c98b2caf5ce545fbf77611431c7084979da8177/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,\n\tconst BIGNUM *x_, int y_bit, BN_CTX *ctx)\n\t{\n\tBN_CTX *new_ctx = NULL;\n\tBIGNUM *tmp1, *tmp2, *x, *y;\n\tint ret = 0;\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\ty_bit = (y_bit != 0);\n\tBN_CTX_start(ctx);\n\ttmp1 = BN_CTX_get(ctx);\n\ttmp2 = BN_CTX_get(ctx);\n\tx = BN_CTX_get(ctx);\n\ty = BN_CTX_get(ctx);\n\tif (y == NULL) goto err;\n\tif (!BN_nnmod(x, x_, &group->field,ctx)) goto err;\n\tif (group->meth->field_decode == 0)\n\t\t{\n\t\tif (!group->meth->field_sqr(group, tmp2, x_, ctx)) goto err;\n\t\tif (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mod_sqr(tmp2, x_, &group->field, ctx)) goto err;\n\t\tif (!BN_mod_mul(tmp1, tmp2, x_, &group->field, ctx)) goto err;\n\t\t}\n\tif (group->a_is_minus3)\n\t\t{\n\t\tif (!BN_mod_lshift1_quick(tmp2, x, &group->field)) goto err;\n\t\tif (!BN_mod_add_quick(tmp2, tmp2, x, &group->field)) goto err;\n\t\tif (!BN_mod_sub_quick(tmp1, tmp1, tmp2, &group->field)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (group->meth->field_decode)\n\t\t\t{\n\t\t\tif (!group->meth->field_decode(group, tmp2, &group->a, ctx)) goto err;\n\t\t\tif (!BN_mod_mul(tmp2, tmp2, x, &group->field, ctx)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!group->meth->field_mul(group, tmp2, &group->a, x, ctx)) goto err;\n\t\t\t}\n\t\tif (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;\n\t\t}\n\tif (group->meth->field_decode)\n\t\t{\n\t\tif (!group->meth->field_decode(group, tmp2, &group->b, ctx)) goto err;\n\t\tif (!BN_mod_add_quick(tmp1, tmp1, tmp2, &group->field)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mod_add_quick(tmp1, tmp1, &group->b, &group->field)) goto err;\n\t\t}\n\tif (!BN_mod_sqrt(y, tmp1, &group->field, ctx))\n\t\t{\n\t\tunsigned long err = ERR_peek_error();\n\t\tif (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE)\n\t\t\t{\n\t\t\t(void)ERR_get_error();\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);\n\t\t\t}\n\t\telse\n\t\t\tECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB);\n\t\tgoto err;\n\t\t}\n\tif (y_bit != BN_is_odd(y))\n\t\t{\n\t\tif (BN_is_zero(y))\n\t\t\t{\n\t\t\tint kron;\n\t\t\tkron = BN_kronecker(x, &group->field, ctx);\n\t\t\tif (kron == -2) goto err;\n\t\t\tif (kron == 1)\n\t\t\t\tECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSION_BIT);\n\t\t\telse\n\t\t\t\tECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!BN_usub(y, &group->field, y)) goto err;\n\t\t}\n\tif (y_bit != BN_is_odd(y))\n\t\t{\n\t\tECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_INTERNAL_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) goto err;\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}', '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_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tif (dv)\n\t\tbn_check_top(dv);\n\tif (rm)\n\t\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tif (rm)\n\t\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', 'void BN_CTX_end(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_end", ctx);\n\tif(ctx->err_stack)\n\t\tctx->err_stack--;\n\telse\n\t\t{\n\t\tunsigned int fp = BN_STACK_pop(&ctx->stack);\n\t\tif(fp < ctx->used)\n\t\t\tBN_POOL_release(&ctx->pool, ctx->used - fp);\n\t\tctx->used = fp;\n\t\tctx->too_many = 0;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n\t{\n\treturn st->indexes[--(st->depth)];\n\t}']
|
967
| 0
|
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L268
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,\n BIGNUM *Xp1, BIGNUM *Xp2,\n const BIGNUM *Xp,\n const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb)\n{\n int ret = 0;\n BN_CTX_start(ctx);\n if (Xp1 == NULL)\n Xp1 = BN_CTX_get(ctx);\n if (Xp2 == NULL)\n Xp2 = BN_CTX_get(ctx);\n if (Xp1 == NULL || Xp2 == NULL)\n goto error;\n if (!BN_priv_rand(Xp1, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto error;\n if (!BN_priv_rand(Xp2, 101, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY))\n goto error;\n if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb))\n goto error;\n ret = 1;\n error:\n BN_CTX_end(ctx);\n return ret;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
968
| 0
|
https://github.com/openssl/openssl/blob/305b68f1a2b6d4d0aa07a6ab47ac372f067a40bb/crypto/bn/bn_lib.c/#L231
|
static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
BN_ULONG *a = NULL;
if (words > (INT_MAX / (4 * BN_BITS2))) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
return NULL;
}
if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
return NULL;
}
if (BN_get_flags(b, BN_FLG_SECURE))
a = OPENSSL_secure_zalloc(words * sizeof(*a));
else
a = OPENSSL_zalloc(words * sizeof(*a));
if (a == NULL) {
BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
return NULL;
}
assert(b->top <= words);
if (b->top > 0)
memcpy(a, b->d, sizeof(*a) * b->top);
return a;
}
|
['int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,\n BN_RECP_CTX *recp, BN_CTX *ctx)\n{\n int i, j, ret = 0;\n BIGNUM *a, *b, *d, *r;\n BN_CTX_start(ctx);\n d = (dv != NULL) ? dv : BN_CTX_get(ctx);\n r = (rem != NULL) ? rem : BN_CTX_get(ctx);\n a = BN_CTX_get(ctx);\n b = BN_CTX_get(ctx);\n if (b == NULL)\n goto err;\n if (BN_ucmp(m, &(recp->N)) < 0) {\n BN_zero(d);\n if (!BN_copy(r, m)) {\n BN_CTX_end(ctx);\n return 0;\n }\n BN_CTX_end(ctx);\n return 1;\n }\n i = BN_num_bits(m);\n j = recp->num_bits << 1;\n if (j > i)\n i = j;\n if (i != recp->shift)\n recp->shift = BN_reciprocal(&(recp->Nr), &(recp->N), i, ctx);\n if (recp->shift == -1)\n goto err;\n if (!BN_rshift(a, m, recp->num_bits))\n goto err;\n if (!BN_mul(b, a, &(recp->Nr), ctx))\n goto err;\n if (!BN_rshift(d, b, i - recp->num_bits))\n goto err;\n d->neg = 0;\n if (!BN_mul(b, &(recp->N), d, ctx))\n goto err;\n if (!BN_usub(r, m, b))\n goto err;\n r->neg = 0;\n j = 0;\n while (BN_ucmp(r, &(recp->N)) >= 0) {\n if (j++ > 2) {\n BNerr(BN_F_BN_DIV_RECP, BN_R_BAD_RECIPROCAL);\n goto err;\n }\n if (!BN_usub(r, r, &(recp->N)))\n goto err;\n if (!BN_add_word(d, 1))\n goto err;\n }\n r->neg = BN_is_zero(r) ? 0 : m->neg;\n d->neg = m->neg ^ recp->N.neg;\n ret = 1;\n err:\n BN_CTX_end(ctx);\n bn_check_top(dv);\n bn_check_top(rem);\n return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n bn_check_top(a);\n if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n return 0;\n a->neg = 0;\n a->d[0] = w;\n a->top = (w ? 1 : 0);\n a->flags &= ~BN_FLG_FIXED_TOP;\n bn_check_top(a);\n return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n if (bits > (INT_MAX - BN_BITS2 + 1))\n return NULL;\n if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n return a;\n return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n if (words > b->dmax) {\n BN_ULONG *a = bn_expand_internal(b, words);\n if (!a)\n return NULL;\n if (b->d) {\n OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n bn_free_d(b);\n }\n b->d = a;\n b->dmax = words;\n }\n return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n BN_ULONG *a = NULL;\n if (words > (INT_MAX / (4 * BN_BITS2))) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n return NULL;\n }\n if (BN_get_flags(b, BN_FLG_SECURE))\n a = OPENSSL_secure_zalloc(words * sizeof(*a));\n else\n a = OPENSSL_zalloc(words * sizeof(*a));\n if (a == NULL) {\n BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n return NULL;\n }\n assert(b->top <= words);\n if (b->top > 0)\n memcpy(a, b->d, sizeof(*a) * b->top);\n return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n INCREMENT(malloc_count);\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num == 0)\n return NULL;\n FAILTEST();\n if (allow_customize) {\n allow_customize = 0;\n }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n (void)(file); (void)(line);\n ret = malloc(num);\n#endif\n return ret;\n}']
|
969
| 0
|
https://github.com/openssl/openssl/blob/67dc995eaf538ea309c6292a1a5073465201f55b/ssl/packet.c/#L48
|
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
if (!ossl_assert(pkt->subs != NULL && len != 0))
return 0;
if (pkt->maxsize - pkt->written < len)
return 0;
if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {
size_t newlen;
size_t reflen;
reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
if (reflen > SIZE_MAX / 2) {
newlen = SIZE_MAX;
} else {
newlen = reflen * 2;
if (newlen < DEFAULT_BUF_SIZE)
newlen = DEFAULT_BUF_SIZE;
}
if (BUF_MEM_grow(pkt->buf, newlen) == 0)
return 0;
}
if (allocbytes != NULL)
*allocbytes = WPACKET_get_curr(pkt);
return 1;
}
|
['int tls_construct_client_hello(SSL *s, WPACKET *pkt)\n{\n unsigned char *p;\n size_t sess_id_len;\n int i, 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\n || !ssl_version_supported(s, sess->ssl_version)\n || !SSL_SESSION_is_resumable(sess)) {\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),\n DOWNGRADE_NONE) <= 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 || s->session->ssl_version == TLS1_3_VERSION)\n sess_id_len = 0;\n else\n sess_id_len = s->session->session_id_length;\n if (sess_id_len > sizeof(s->session->session_id)\n || !WPACKET_start_sub_packet_u8(pkt)\n || (sess_id_len != 0 && !WPACKET_memcpy(pkt, s->session->session_id,\n sess_id_len))\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)\n && s->ctx->comp_methods\n && (SSL_IS_DTLS(s) || s->s3->tmp.max_ver < TLS1_3_VERSION)) {\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 (!tls_construct_extensions(s, pkt, SSL_EXT_CLIENT_HELLO, NULL, 0, &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 if (!ossl_assert(pkt->subs != NULL))\n return 0;\n sub = OPENSSL_zalloc(sizeof(*sub));\n if (sub == NULL)\n return 0;\n sub->parent = pkt->subs;\n pkt->subs = sub;\n sub->pwritten = pkt->written + lenbytes;\n sub->lenbytes = lenbytes;\n if (lenbytes == 0) {\n sub->packet_len = 0;\n return 1;\n }\n if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n return 0;\n sub->packet_len = lenchars - GETBUF(pkt);\n return 1;\n}', 'int WPACKET_allocate_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!WPACKET_reserve_bytes(pkt, len, allocbytes))\n return 0;\n pkt->written += len;\n pkt->curr += len;\n return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n if (!ossl_assert(pkt->subs != NULL && len != 0))\n return 0;\n if (pkt->maxsize - pkt->written < len)\n return 0;\n if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n size_t newlen;\n size_t reflen;\n reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n if (reflen > SIZE_MAX / 2) {\n newlen = SIZE_MAX;\n } else {\n newlen = reflen * 2;\n if (newlen < DEFAULT_BUF_SIZE)\n newlen = DEFAULT_BUF_SIZE;\n }\n if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n return 0;\n }\n if (allocbytes != NULL)\n *allocbytes = WPACKET_get_curr(pkt);\n return 1;\n}']
|
970
| 0
|
https://github.com/openssl/openssl/blob/5ea564f154ebe8bda2a0e091a312e2058edf437f/crypto/bn/bn_lib.c/#L331
|
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;
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;
}
|
['int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *group,\n EC_POINT *point,\n const BIGNUM *x,\n const BIGNUM *y, BN_CTX *ctx)\n{\n int ret = 0;\n if (x == NULL || y == NULL) {\n ECerr(EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES,\n ERR_R_PASSED_NULL_PARAMETER);\n return 0;\n }\n if (!BN_copy(point->X, x))\n goto err;\n BN_set_negative(point->X, 0);\n if (!BN_copy(point->Y, y))\n goto err;\n BN_set_negative(point->Y, 0);\n if (!BN_copy(point->Z, BN_value_one()))\n goto err;\n BN_set_negative(point->Z, 0);\n point->Z_is_one = 1;\n ret = 1;\n err:\n return ret;\n}', 'const BIGNUM *BN_value_one(void)\n{\n static const BN_ULONG data_one = 1L;\n static const BIGNUM const_one =\n { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n return (&const_one);\n}', '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 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}']
|
971
| 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);
}
|
['static int RSA_eay_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)\n\t{\n\tBIGNUM r1,m1;\n\tint ret=0;\n\tBN_CTX *ctx;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_init(&m1);\n\tBN_init(&r1);\n\tif (rsa->flags & RSA_FLAG_CACHE_PRIVATE)\n\t\t{\n\t\tif (rsa->_method_mod_p == NULL)\n\t\t\t{\n\t\t\tif ((rsa->_method_mod_p=BN_MONT_CTX_new()) != NULL)\n\t\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_p,rsa->p,\n\t\t\t\t\t\t ctx))\n\t\t\t\t\tgoto err;\n\t\t\t}\n\t\tif (rsa->_method_mod_q == NULL)\n\t\t\t{\n\t\t\tif ((rsa->_method_mod_q=BN_MONT_CTX_new()) != NULL)\n\t\t\t\tif (!BN_MONT_CTX_set(rsa->_method_mod_q,rsa->q,\n\t\t\t\t\t\t ctx))\n\t\t\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tif (!BN_mod(&r1,I,rsa->q,ctx)) goto err;\n\tif (!rsa->meth->bn_mod_exp(&m1,&r1,rsa->dmq1,rsa->q,ctx,\n\t\trsa->_method_mod_q)) goto err;\n\tif (!BN_mod(&r1,I,rsa->p,ctx)) goto err;\n\tif (!rsa->meth->bn_mod_exp(r0,&r1,rsa->dmp1,rsa->p,ctx,\n\t\trsa->_method_mod_p)) goto err;\n\tif (!BN_sub(r0,r0,&m1)) goto err;\n\tif (r0->neg)\n\t\tif (!BN_add(r0,r0,rsa->p)) goto err;\n\tif (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;\n\tif (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;\n\tif (r0->neg)\n\t\tif (!BN_add(r0,r0,rsa->p)) goto err;\n\tif (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;\n\tif (!BN_add(r0,&r1,&m1)) goto err;\n\tret=1;\nerr:\n\tBN_clear_free(&m1);\n\tBN_clear_free(&r1);\n\tBN_CTX_free(ctx);\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}', '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}']
|
972
| 0
|
https://github.com/openssl/openssl/blob/280eb33b5930efef9a3dfdeab5c3df46a9425243/crypto/x509/x509_req.c/#L200
|
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 d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
ext->value.sequence->length,
d2i_X509_EXTENSION, X509_EXTENSION_free,
V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
}
|
['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 d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,\n\t\t\text->value.sequence->length,\n\t\t\td2i_X509_EXTENSION, X509_EXTENSION_free,\n\t\t\tV_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);\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}', 'int sk_num(const STACK *st)\n{\n\tif(st == NULL) return -1;\n\treturn st->num;\n}']
|
973
| 0
|
https://github.com/openssl/openssl/blob/daea0ff8a960237e0f9a71301721824c25ad3b25/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];
}
|
['static int generate_key(DH *dh)\n\t{\n\tint ok=0;\n\tunsigned int i;\n\tBN_CTX ctx;\n\tBN_MONT_CTX *mont;\n\tBIGNUM *pub_key=NULL,*priv_key=NULL;\n\tBN_CTX_init(&ctx);\n\tif (dh->priv_key == NULL)\n\t\t{\n\t\ti=dh->length;\n\t\tif (i == 0)\n\t\t\t{\n\t\t\ti=BN_num_bits(dh->p)-1;\n\t\t\t}\n\t\tpriv_key=BN_new();\n\t\tif (priv_key == NULL) goto err;\n\t\tif (!BN_rand(priv_key,i,0,0)) goto err;\n\t\t}\n\telse\n\t\tpriv_key=dh->priv_key;\n\tif (dh->pub_key == NULL)\n\t\t{\n\t\tpub_key=BN_new();\n\t\tif (pub_key == NULL) goto err;\n\t\t}\n\telse\n\t\tpub_key=dh->pub_key;\n\tif ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P))\n\t\t{\n\t\tif ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL)\n\t\t\tif (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p,\n\t\t\t\tdh->p,&ctx)) goto err;\n\t\t}\n\tmont=(BN_MONT_CTX *)dh->method_mont_p;\n\tif (!ENGINE_get_DH(dh->engine)->bn_mod_exp(dh, pub_key, dh->g,\n\t\t\t\tpriv_key,dh->p,&ctx,mont))\n\t\tgoto err;\n\tdh->pub_key=pub_key;\n\tdh->priv_key=priv_key;\n\tok=1;\nerr:\n\tif (ok != 1)\n\t\tDHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);\n\tif ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);\n\tif ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);\n\tBN_CTX_free(&ctx);\n\treturn(ok);\n\t}', '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_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\tmont->N.neg = 0;\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=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 = (Ri.top > 0) ? Ri.d[0] : 0;\n\t\tBN_free(&Ri);\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tif (!BN_zero(R)) goto err;\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\tBN_free(&Ri);\n\t\t}\n#endif\n\tif (!BN_zero(&(mont->RR))) goto err;\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\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_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}', '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}']
|
974
| 0
|
https://github.com/openssl/openssl/blob/18e1e302452e6dea4500b6f981cee7e151294dea/crypto/bn/bn_ctx.c/#L268
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['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("ENTER BN_CTX_start()", ctx);\n if (ctx->err_stack || ctx->too_many)\n ctx->err_stack++;\n else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n ctx->err_stack++;\n }\n CTXDBG("LEAVE BN_CTX_start()", ctx);\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n BIGNUM *ret;\n CTXDBG("ENTER BN_CTX_get()", ctx);\n if (ctx->err_stack || ctx->too_many)\n return NULL;\n if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n ctx->too_many = 1;\n BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n return NULL;\n }\n BN_zero(ret);\n ret->flags &= (~BN_FLG_CONSTTIME);\n ctx->used++;\n CTXDBG("LEAVE BN_CTX_get()", ctx);\n return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int ret = bn_sqr_fixed_top(r, a, ctx);\n bn_correct_top(r);\n bn_check_top(r);\n return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n rr->top = max;\n rr->flags |= BN_FLG_FIXED_TOP;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n if (!(BN_mod(r, m, d, ctx)))\n return 0;\n if (!r->neg)\n return 1;\n return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int ret;\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (divisor->d[divisor->top - 1] == 0) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n ret = bn_div_fixed_top(dv, rm, num, divisor, ctx);\n if (ret) {\n if (dv != NULL)\n bn_correct_top(dv);\n if (rm != NULL)\n bn_correct_top(rm);\n }\n return ret;\n}', 'int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,\n const BIGNUM *divisor, BN_CTX *ctx)\n{\n int norm_shift, i, j, loop;\n BIGNUM *tmp, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnum, *wnumtop;\n BN_ULONG d0, d1;\n int num_n, div_n;\n assert(divisor->top > 0 && divisor->d[divisor->top - 1] != 0);\n bn_check_top(num);\n bn_check_top(divisor);\n bn_check_top(dv);\n bn_check_top(rm);\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n if (!BN_copy(sdiv, divisor))\n goto err;\n norm_shift = bn_left_align(sdiv);\n sdiv->neg = 0;\n if (!(bn_lshift_fixed_top(snum, num, norm_shift)))\n goto err;\n div_n = sdiv->top;\n num_n = snum->top;\n if (num_n <= div_n) {\n if (bn_wexpand(snum, div_n + 1) == NULL)\n goto err;\n memset(&(snum->d[num_n]), 0, (div_n - num_n + 1) * sizeof(BN_ULONG));\n snum->top = num_n = div_n + 1;\n }\n loop = num_n - div_n;\n wnum = &(snum->d[loop]);\n wnumtop = &(snum->d[num_n - 1]);\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n if (!bn_wexpand(res, loop))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop;\n res->flags |= BN_FLG_FIXED_TOP;\n resp = &(res->d[loop]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n for (i = 0; i < loop; i++, wnumtop--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W)\n q = bn_div_3_words(wnumtop, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnumtop[0];\n n1 = wnumtop[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n BN_ULONG n2 = (wnumtop == wnum) ? 0 : wnumtop[-2];\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | n2))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= n2)))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum--;\n l0 = bn_sub_words(wnum, wnum, tmp->d, div_n + 1);\n q -= l0;\n for (l0 = 0 - l0, j = 0; j < div_n; j++)\n tmp->d[j] = sdiv->d[j] & l0;\n l0 = bn_add_words(wnum, wnum, tmp->d, div_n);\n (*wnumtop) += l0;\n assert((*wnumtop) == 0);\n *--resp = q;\n }\n snum->neg = num->neg;\n snum->top = div_n;\n snum->flags |= BN_FLG_FIXED_TOP;\n if (rm != NULL)\n bn_rshift_fixed_top(rm, snum, norm_shift);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n CTXDBG("ENTER BN_CTX_end()", ctx);\n if (ctx->err_stack)\n ctx->err_stack--;\n else {\n unsigned int fp = BN_STACK_pop(&ctx->stack);\n if (fp < ctx->used)\n BN_POOL_release(&ctx->pool, ctx->used - fp);\n ctx->used = fp;\n ctx->too_many = 0;\n }\n CTXDBG("LEAVE BN_CTX_end()", ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n return st->indexes[--(st->depth)];\n}']
|
975
| 0
|
https://github.com/openssl/openssl/blob/8e826a339f8cda20a4311fa88a1de782972cf40d/crypto/bn/bn_sqr.c/#L120
|
void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
int i, j, max;
const BN_ULONG *ap;
BN_ULONG *rp;
max = n * 2;
ap = a;
rp = r;
rp[0] = rp[max - 1] = 0;
rp++;
j = n;
if (--j > 0) {
ap++;
rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
rp += 2;
}
for (i = n - 2; i > 0; i--) {
j--;
ap++;
rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
rp += 2;
}
bn_add_words(r, r, r, max);
bn_sqr_words(tmp, a, n);
bn_add_words(r, r, tmp, max);
}
|
['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_priv_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_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_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (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_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return (ret);\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return (0);\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n 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 ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_to_montgomery(BIGNUM *r, const BIGNUM *a, BN_MONT_CTX *mont,\n BN_CTX *ctx)\n{\n return BN_mod_mul_montgomery(r, a, &(mont->RR), mont, ctx);\n}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n BN_MONT_CTX *mont, BN_CTX *ctx)\n{\n BIGNUM *tmp;\n int ret = 0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n int num = mont->N.top;\n if (num > 1 && a->top == num && b->top == num) {\n if (bn_wexpand(r, num) == NULL)\n return (0);\n if (bn_mul_mont(r->d, a->d, b->d, mont->N.d, mont->n0, num)) {\n r->neg = a->neg ^ b->neg;\n r->top = num;\n bn_correct_top(r);\n return 1;\n }\n }\n#endif\n BN_CTX_start(ctx);\n tmp = BN_CTX_get(ctx);\n if (tmp == NULL)\n goto err;\n bn_check_top(tmp);\n if (a == b) {\n if (!BN_sqr(tmp, a, ctx))\n goto err;\n } else {\n if (!BN_mul(tmp, a, b, ctx))\n goto err;\n }\n#ifdef MONT_WORD\n if (!BN_from_montgomery_word(r, tmp, mont))\n goto err;\n#else\n if (!BN_from_montgomery(r, tmp, mont, ctx))\n goto err;\n#endif\n bn_check_top(r);\n ret = 1;\n err:\n BN_CTX_end(ctx);\n return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n int max, al;\n int ret = 0;\n BIGNUM *tmp, *rr;\n bn_check_top(a);\n al = a->top;\n if (al <= 0) {\n r->top = 0;\n r->neg = 0;\n return 1;\n }\n BN_CTX_start(ctx);\n rr = (a != r) ? r : BN_CTX_get(ctx);\n tmp = BN_CTX_get(ctx);\n if (rr == NULL || tmp == NULL)\n goto err;\n max = 2 * al;\n if (bn_wexpand(rr, max) == NULL)\n goto err;\n if (al == 4) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[8];\n bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n bn_sqr_comba4(rr->d, a->d);\n#endif\n } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n BN_ULONG t[16];\n bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n bn_sqr_comba8(rr->d, a->d);\n#endif\n } else {\n#if defined(BN_RECURSION)\n if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n bn_sqr_normal(rr->d, a->d, al, t);\n } else {\n int j, k;\n j = BN_num_bits_word((BN_ULONG)al);\n j = 1 << (j - 1);\n k = j + j;\n if (al == j) {\n if (bn_wexpand(tmp, k * 2) == NULL)\n goto err;\n bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n } else {\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n }\n }\n#else\n if (bn_wexpand(tmp, max) == NULL)\n goto err;\n bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n }\n rr->neg = 0;\n if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n rr->top = max - 1;\n else\n rr->top = max;\n if (r != rr && BN_copy(r, rr) == NULL)\n goto err;\n ret = 1;\n err:\n bn_check_top(rr);\n bn_check_top(tmp);\n BN_CTX_end(ctx);\n return (ret);\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n int i, j, max;\n const BN_ULONG *ap;\n BN_ULONG *rp;\n max = n * 2;\n ap = a;\n rp = r;\n rp[0] = rp[max - 1] = 0;\n rp++;\n j = n;\n if (--j > 0) {\n ap++;\n rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n for (i = n - 2; i > 0; i--) {\n j--;\n ap++;\n rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n rp += 2;\n }\n bn_add_words(r, r, r, max);\n bn_sqr_words(tmp, a, n);\n bn_add_words(r, r, tmp, max);\n}']
|
976
| 0
|
https://github.com/libav/libav/blob/3ec394ea823c2a6e65a6abbdb2041ce1c66964f8/libavcodec/h264pred.c/#L403
|
static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){
const int lt= src[-1-1*stride];
LOAD_TOP_EDGE
LOAD_LEFT_EDGE
src[0+0*stride]=
src[2+1*stride]=(lt + l0 + 1)>>1;
src[1+0*stride]=
src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;
src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;
src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;
src[0+1*stride]=
src[2+2*stride]=(l0 + l1 + 1)>>1;
src[1+1*stride]=
src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;
src[0+2*stride]=
src[2+3*stride]=(l1 + l2+ 1)>>1;
src[1+2*stride]=
src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;
src[0+3*stride]=(l2 + l3 + 1)>>1;
src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;
}
|
['static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){\n const int lt= src[-1-1*stride];\n LOAD_TOP_EDGE\n LOAD_LEFT_EDGE\n src[0+0*stride]=\n src[2+1*stride]=(lt + l0 + 1)>>1;\n src[1+0*stride]=\n src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2;\n src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2;\n src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2;\n src[0+1*stride]=\n src[2+2*stride]=(l0 + l1 + 1)>>1;\n src[1+1*stride]=\n src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2;\n src[0+2*stride]=\n src[2+3*stride]=(l1 + l2+ 1)>>1;\n src[1+2*stride]=\n src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2;\n src[0+3*stride]=(l2 + l3 + 1)>>1;\n src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2;\n}']
|
977
| 0
|
https://github.com/libav/libav/blob/c8b4a3999bc7f3732a537cdec6475918a65d6e78/libavfilter/avfilter.c/#L91
|
void avfilter_unref_buffer(AVFilterBufferRef *ref)
{
if (!ref)
return;
if (!(--ref->buf->refcount))
ref->buf->free(ref->buf);
if (ref->extended_data != ref->data)
av_freep(&ref->extended_data);
av_free(ref->video);
av_free(ref->audio);
av_free(ref);
}
|
['static void end_frame(AVFilterLink *inlink)\n{\n TransContext *trans = inlink->dst->priv;\n AVFilterBufferRef *inpic = inlink->cur_buf;\n AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;\n AVFilterLink *outlink = inlink->dst->outputs[0];\n int plane;\n for (plane = 0; outpic->data[plane]; plane++) {\n int hsub = plane == 1 || plane == 2 ? trans->hsub : 0;\n int vsub = plane == 1 || plane == 2 ? trans->vsub : 0;\n int pixstep = trans->pixsteps[plane];\n int inh = inpic->video->h>>vsub;\n int outw = outpic->video->w>>hsub;\n int outh = outpic->video->h>>vsub;\n uint8_t *out, *in;\n int outlinesize, inlinesize;\n int x, y;\n out = outpic->data[plane]; outlinesize = outpic->linesize[plane];\n in = inpic ->data[plane]; inlinesize = inpic ->linesize[plane];\n if (trans->dir&1) {\n in += inpic->linesize[plane] * (inh-1);\n inlinesize *= -1;\n }\n if (trans->dir&2) {\n out += outpic->linesize[plane] * (outh-1);\n outlinesize *= -1;\n }\n for (y = 0; y < outh; y++) {\n switch (pixstep) {\n case 1:\n for (x = 0; x < outw; x++)\n out[x] = in[x*inlinesize + y];\n break;\n case 2:\n for (x = 0; x < outw; x++)\n *((uint16_t *)(out + 2*x)) = *((uint16_t *)(in + x*inlinesize + y*2));\n break;\n case 3:\n for (x = 0; x < outw; x++) {\n int32_t v = AV_RB24(in + x*inlinesize + y*3);\n AV_WB24(out + 3*x, v);\n }\n break;\n case 4:\n for (x = 0; x < outw; x++)\n *((uint32_t *)(out + 4*x)) = *((uint32_t *)(in + x*inlinesize + y*4));\n break;\n }\n out += outlinesize;\n }\n }\n avfilter_unref_buffer(inpic);\n avfilter_draw_slice(outlink, 0, outpic->video->h, 1);\n avfilter_end_frame(outlink);\n avfilter_unref_buffer(outpic);\n}', 'void avfilter_unref_buffer(AVFilterBufferRef *ref)\n{\n if (!ref)\n return;\n if (!(--ref->buf->refcount))\n ref->buf->free(ref->buf);\n if (ref->extended_data != ref->data)\n av_freep(&ref->extended_data);\n av_free(ref->video);\n av_free(ref->audio);\n av_free(ref);\n}']
|
978
| 0
|
https://github.com/libav/libav/blob/c9ef6b09326a24010bf86d6b0d19cfa42df4d546/libavcodec/proresdec.c/#L328
|
static inline int decode_vlc_codeword(GetBitContext *gb, unsigned codebook)
{
unsigned int rice_order, exp_order, switch_bits;
unsigned int buf, code;
int log, prefix_len, len;
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
switch_bits = (codebook & 3) + 1;
rice_order = codebook >> 5;
exp_order = (codebook >> 2) & 7;
log = 31 - av_log2(buf);
if (log < switch_bits) {
if (!rice_order) {
code = log;
LAST_SKIP_BITS(re, gb, log + 1);
} else {
prefix_len = log + 1;
code = (log << rice_order) + NEG_USR32(buf << prefix_len, rice_order);
LAST_SKIP_BITS(re, gb, prefix_len + rice_order);
}
} else {
len = (log << 1) - switch_bits + exp_order + 1;
code = NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);
LAST_SKIP_BITS(re, gb, len);
}
CLOSE_READER(re, gb);
return code;
}
|
['static int decode_slice_plane(ProresContext *ctx, ProresThreadData *td,\n const uint8_t *buf,\n int data_size, uint16_t *out_ptr,\n int linesize, int mbs_per_slice,\n int blocks_per_mb, int plane_size_factor,\n const int16_t *qmat, int is_chroma)\n{\n GetBitContext gb;\n int16_t *block_ptr;\n int mb_num, blocks_per_slice, ret;\n blocks_per_slice = mbs_per_slice * blocks_per_mb;\n memset(td->blocks, 0, 8 * 4 * 64 * sizeof(*td->blocks));\n init_get_bits(&gb, buf, data_size << 3);\n decode_dc_coeffs(&gb, td->blocks, blocks_per_slice);\n ret = decode_ac_coeffs(&gb, td->blocks, blocks_per_slice,\n plane_size_factor, ctx->scantable.permutated);\n if (ret < 0)\n return ret;\n block_ptr = td->blocks;\n if (!is_chroma) {\n for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {\n ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);\n block_ptr += 64;\n if (blocks_per_mb > 2) {\n ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);\n block_ptr += 64;\n }\n ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);\n block_ptr += 64;\n if (blocks_per_mb > 2) {\n ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);\n block_ptr += 64;\n }\n }\n } else {\n for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) {\n ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat);\n block_ptr += 64;\n ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat);\n block_ptr += 64;\n if (blocks_per_mb > 2) {\n ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat);\n block_ptr += 64;\n ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat);\n block_ptr += 64;\n }\n }\n }\n return 0;\n}', 'static inline void decode_dc_coeffs(GetBitContext *gb, int16_t *out,\n int nblocks)\n{\n int16_t prev_dc;\n int i, sign;\n int16_t delta;\n unsigned int code;\n code = decode_vlc_codeword(gb, FIRST_DC_CB);\n out[0] = prev_dc = TOSIGNED(code);\n out += 64;\n delta = 3;\n for (i = 1; i < nblocks; i++, out += 64) {\n code = decode_vlc_codeword(gb, ff_prores_dc_codebook[FFMIN(FFABS(delta), 3)]);\n sign = -(((delta >> 15) & 1) ^ (code & 1));\n delta = (((code + 1) >> 1) ^ sign) - sign;\n prev_dc += delta;\n out[0] = prev_dc;\n }\n}', 'static inline int decode_vlc_codeword(GetBitContext *gb, unsigned codebook)\n{\n unsigned int rice_order, exp_order, switch_bits;\n unsigned int buf, code;\n int log, prefix_len, len;\n OPEN_READER(re, gb);\n UPDATE_CACHE(re, gb);\n buf = GET_CACHE(re, gb);\n switch_bits = (codebook & 3) + 1;\n rice_order = codebook >> 5;\n exp_order = (codebook >> 2) & 7;\n log = 31 - av_log2(buf);\n if (log < switch_bits) {\n if (!rice_order) {\n code = log;\n LAST_SKIP_BITS(re, gb, log + 1);\n } else {\n prefix_len = log + 1;\n code = (log << rice_order) + NEG_USR32(buf << prefix_len, rice_order);\n LAST_SKIP_BITS(re, gb, prefix_len + rice_order);\n }\n } else {\n len = (log << 1) - switch_bits + exp_order + 1;\n code = NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order);\n LAST_SKIP_BITS(re, gb, len);\n }\n CLOSE_READER(re, gb);\n return code;\n}']
|
979
| 0
|
https://github.com/openssl/openssl/blob/97d37b85d4e1a218fdc61dbe0dff3e7c8ff36121/crypto/rand/rand_lib.c/#L821
|
int RAND_pseudo_bytes(unsigned char *buf, int num)
{
const RAND_METHOD *meth = RAND_get_rand_method();
if (meth->pseudorand != NULL)
return meth->pseudorand(buf, num);
return -1;
}
|
['int RAND_pseudo_bytes(unsigned char *buf, int num)\n{\n const RAND_METHOD *meth = RAND_get_rand_method();\n if (meth->pseudorand != NULL)\n return meth->pseudorand(buf, num);\n return -1;\n}', 'const RAND_METHOD *RAND_get_rand_method(void)\n{\n const RAND_METHOD *tmp_meth = NULL;\n if (!RUN_ONCE(&rand_init, do_rand_init))\n return NULL;\n CRYPTO_THREAD_write_lock(rand_meth_lock);\n if (default_RAND_meth == NULL) {\n#ifndef OPENSSL_NO_ENGINE\n ENGINE *e;\n if ((e = ENGINE_get_default_RAND()) != NULL\n && (tmp_meth = ENGINE_get_RAND(e)) != NULL) {\n funct_ref = e;\n default_RAND_meth = tmp_meth;\n } else {\n ENGINE_finish(e);\n default_RAND_meth = &rand_meth;\n }\n#else\n default_RAND_meth = &rand_meth;\n#endif\n }\n tmp_meth = default_RAND_meth;\n CRYPTO_THREAD_unlock(rand_meth_lock);\n return tmp_meth;\n}', 'int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))\n{\n if (pthread_once(once, init) != 0)\n return 0;\n return 1;\n}']
|
980
| 0
|
https://github.com/libav/libav/blob/72ccfb3cb7a85d35cfe2c99ab53e981974e599cd/libavformat/movenc.c/#L3000
|
static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
{
MOVMuxContext *mov = s->priv_data;
MOVTrack *track = &mov->tracks[tracknum];
AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };
int i, len;
track->mode = mov->mode;
track->tag = MKTAG('t','e','x','t');
track->timescale = MOV_TIMESCALE;
track->enc = avcodec_alloc_context3(NULL);
track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
for (i = 0; i < s->nb_chapters; i++) {
AVChapter *c = s->chapters[i];
AVDictionaryEntry *t;
int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});
pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});
pkt.duration = end - pkt.dts;
if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {
len = strlen(t->value);
pkt.size = len+2;
pkt.data = av_malloc(pkt.size);
AV_WB16(pkt.data, len);
memcpy(pkt.data+2, t->value, len);
ff_mov_write_packet(s, &pkt);
av_freep(&pkt.data);
}
}
}
|
['static void mov_create_chapter_track(AVFormatContext *s, int tracknum)\n{\n MOVMuxContext *mov = s->priv_data;\n MOVTrack *track = &mov->tracks[tracknum];\n AVPacket pkt = { .stream_index = tracknum, .flags = AV_PKT_FLAG_KEY };\n int i, len;\n track->mode = mov->mode;\n track->tag = MKTAG(\'t\',\'e\',\'x\',\'t\');\n track->timescale = MOV_TIMESCALE;\n track->enc = avcodec_alloc_context3(NULL);\n track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;\n for (i = 0; i < s->nb_chapters; i++) {\n AVChapter *c = s->chapters[i];\n AVDictionaryEntry *t;\n int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE});\n pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE});\n pkt.duration = end - pkt.dts;\n if ((t = av_dict_get(c->metadata, "title", NULL, 0))) {\n len = strlen(t->value);\n pkt.size = len+2;\n pkt.data = av_malloc(pkt.size);\n AV_WB16(pkt.data, len);\n memcpy(pkt.data+2, t->value, len);\n ff_mov_write_packet(s, &pkt);\n av_freep(&pkt.data);\n }\n }\n}', 'AVCodecContext *avcodec_alloc_context3(AVCodec *codec){\n AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n if(avctx==NULL) return NULL;\n if(avcodec_get_context_defaults3(avctx, codec) < 0){\n av_free(avctx);\n return NULL;\n }\n return avctx;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-32) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+32);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&31) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,32,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(32,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}', 'int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)\n{\n return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF);\n}', 'int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq,\n enum AVRounding rnd)\n{\n int64_t b= bq.num * (int64_t)cq.den;\n int64_t c= cq.num * (int64_t)bq.den;\n return av_rescale_rnd(a, b, c, rnd);\n}', 'static av_always_inline av_const uint16_t av_bswap16(uint16_t x)\n{\n x= (x>>8) | (x<<8);\n return x;\n}']
|
981
| 0
|
https://github.com/openssl/openssl/blob/aa8b03b415d20c0863f44c211486f881c6689383/crypto/bn/bn_ctx.c/#L353
|
static unsigned int BN_STACK_pop(BN_STACK *st)
{
return st->indexes[--(st->depth)];
}
|
['static int RSA_eay_public_encrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tBIGNUM *f,*ret;\n\tint i,j,k,num=0,r= -1;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tBN_CTX_start(ctx);\n\tf = BN_CTX_get(ctx);\n\tret = BN_CTX_get(ctx);\n\tnum=BN_num_bytes(rsa->n);\n\tbuf = OPENSSL_malloc(num);\n\tif (!f || !ret || !buf)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\ti=RSA_padding_add_PKCS1_type_2(buf,num,from,flen);\n\t\tbreak;\n#ifndef OPENSSL_NO_SHA\n\tcase RSA_PKCS1_OAEP_PADDING:\n\t i=RSA_padding_add_PKCS1_OAEP(buf,num,from,flen,NULL,0);\n\t\tbreak;\n#endif\n\tcase RSA_SSLV23_PADDING:\n\t\ti=RSA_padding_add_SSLv23(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\ti=RSA_padding_add_none(buf,num,from,flen);\n\t\tbreak;\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (i <= 0) goto err;\n\tif (BN_bin2bn(buf,num,f) == NULL) goto err;\n\tif (BN_ucmp(f, rsa->n) >= 0)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);\n\t\tgoto err;\n\t\t}\n\tMONT_HELPER(rsa, ctx, n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);\n\tif (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx,\n\t\trsa->_method_mod_n)) goto err;\n\tj=BN_num_bytes(ret);\n\ti=BN_bn2bin(ret,&(to[num-j]));\n\tfor (k=0; k<(num-i); k++)\n\t\tto[k]=0;\n\tr=num;\nerr:\n\tif (ctx != NULL)\n\t\t{\n\t\tBN_CTX_end(ctx);\n\t\tBN_CTX_free(ctx);\n\t\t}\n\tif (buf != NULL)\n\t\t{\n\t\tOPENSSL_cleanse(buf,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,\n\t\t\t\t\tconst BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tif (*pmont)\n\t\treturn *pmont;\n\tCRYPTO_w_lock(lock);\n\tif (!*pmont)\n\t\t{\n\t\t*pmont = BN_MONT_CTX_new();\n\t\tif (*pmont && !BN_MONT_CTX_set(*pmont, mod, ctx))\n\t\t\t{\n\t\t\tBN_MONT_CTX_free(*pmont);\n\t\t\t*pmont = NULL;\n\t\t\t}\n\t\t}\n\tCRYPTO_w_unlock(lock);\n\treturn *pmont;\n\t}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n\t{\n\tint ret = 0;\n\tBIGNUM *Ri,*R;\n\tBN_CTX_start(ctx);\n\tif((Ri = BN_CTX_get(ctx)) == NULL) goto err;\n\tR= &(mont->RR);\n\tif (!BN_copy(&(mont->N),mod)) goto err;\n\tmont->N.neg = 0;\n#ifdef MONT_WORD\n\t\t{\n\t\tBIGNUM tmod;\n\t\tBN_ULONG buf[2];\n\t\ttmod.d=buf;\n\t\ttmod.dmax=2;\n\t\ttmod.neg=0;\n\t\tmont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;\n#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,2*BN_BITS2))) goto err;\n\t\t\t\t\t\t\t\ttmod.top=0;\n\t\tif ((buf[0] = mod->d[0]))\t\t\ttmod.top=1;\n\t\tif ((buf[1] = mod->top>1 ? mod->d[1] : 0))\ttmod.top=2;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)\n\t\t\t\tgoto err;\n\t\t\tRi->neg=0;\n\t\t\tRi->d[0]=BN_MASK2;\n\t\t\tRi->d[1]=BN_MASK2;\n\t\t\tRi->top=2;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n#else\n\t\tBN_zero(R);\n\t\tif (!(BN_set_bit(R,BN_BITS2))) goto err;\n\t\tbuf[0]=mod->d[0];\n\t\tbuf[1]=0;\n\t\ttmod.top = buf[0] != 0 ? 1 : 0;\n\t\tif ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,BN_BITS2)) goto err;\n\t\tif (!BN_is_zero(Ri))\n\t\t\t{\n\t\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_set_word(Ri,BN_MASK2)) goto err;\n\t\t\t}\n\t\tif (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;\n\t\tmont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n\t\tmont->n0[1] = 0;\n#endif\n\t\t}\n#else\n\t\t{\n\t\tmont->ri=BN_num_bits(&mont->N);\n\t\tBN_zero(R);\n\t\tif (!BN_set_bit(R,mont->ri)) goto err;\n\t\tif ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL)\n\t\t\tgoto err;\n\t\tif (!BN_lshift(Ri,Ri,mont->ri)) goto err;\n\t\tif (!BN_sub_word(Ri,1)) goto err;\n\t\tif (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err;\n\t\t}\n#endif\n\tBN_zero(&(mont->RR));\n\tif (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;\n\tif (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;\n\tret = 1;\nerr:\n\tBN_CTX_end(ctx);\n\treturn ret;\n\t}', '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\tif (BN_is_odd(n) && (BN_num_bits(n) <= (BN_BITS <= 32 ? 450 : 2048)))\n\t\t{\n\t\tint shift;\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(B, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(X))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(X, X, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(X, X)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(B, B, shift)) goto err;\n\t\t\t\t}\n\t\t\tshift = 0;\n\t\t\twhile (!BN_is_bit_set(A, shift))\n\t\t\t\t{\n\t\t\t\tshift++;\n\t\t\t\tif (BN_is_odd(Y))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_uadd(Y, Y, n)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_rshift1(Y, Y)) goto err;\n\t\t\t\t}\n\t\t\tif (shift > 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_rshift(A, A, shift)) goto err;\n\t\t\t\t}\n\t\t\tif (BN_ucmp(B, A) >= 0)\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(X, X, Y)) goto err;\n\t\t\t\tif (!BN_usub(B, B, A)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_uadd(Y, Y, X)) goto err;\n\t\t\t\tif (!BN_usub(A, A, B)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\twhile (!BN_is_zero(B))\n\t\t\t{\n\t\t\tBIGNUM *tmp;\n\t\t\tif (BN_num_bits(A) == BN_num_bits(B))\n\t\t\t\t{\n\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t}\n\t\t\telse if (BN_num_bits(A) == BN_num_bits(B) + 1)\n\t\t\t\t{\n\t\t\t\tif (!BN_lshift1(T,B)) goto err;\n\t\t\t\tif (BN_ucmp(A,T) < 0)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_one(D)) goto err;\n\t\t\t\t\tif (!BN_sub(M,A,B)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_sub(M,A,T)) goto err;\n\t\t\t\t\tif (!BN_add(D,T,B)) goto err;\n\t\t\t\t\tif (BN_ucmp(A,D) < 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,2)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!BN_set_word(D,3)) goto err;\n\t\t\t\t\t\tif (!BN_sub(M,M,B)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (!BN_div(D,M,A,B,ctx)) goto err;\n\t\t\t\t}\n\t\t\ttmp=A;\n\t\t\tA=B;\n\t\t\tB=M;\n\t\t\tif (BN_is_one(D))\n\t\t\t\t{\n\t\t\t\tif (!BN_add(tmp,X,Y)) goto err;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tif (BN_is_word(D,2))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift1(tmp,X)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (BN_is_word(D,4))\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_lshift(tmp,X,2)) goto err;\n\t\t\t\t\t}\n\t\t\t\telse if (D->top == 1)\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_copy(tmp,X)) goto err;\n\t\t\t\t\tif (!BN_mul_word(tmp,D->d[0])) goto err;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tif (!BN_mul(tmp,D,X,ctx)) goto err;\n\t\t\t\t\t}\n\t\t\t\tif (!BN_add(tmp,tmp,Y)) goto err;\n\t\t\t\t}\n\t\t\tM=Y;\n\t\t\tY=X;\n\t\t\tX=tmp;\n\t\t\tsign = -sign;\n\t\t\t}\n\t\t}\n\tif (sign < 0)\n\t\t{\n\t\tif (!BN_sub(Y,n,Y)) goto err;\n\t\t}\n\tif (BN_is_one(A))\n\t\t{\n\t\tif (!Y->neg && BN_ucmp(Y,n) < 0)\n\t\t\t{\n\t\t\tif (!BN_copy(R,Y)) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!BN_nnmod(R,Y,n,ctx)) goto err;\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_INVERSE,BN_R_NO_INVERSE);\n\t\tgoto err;\n\t\t}\n\tret=R;\nerr:\n\tif ((ret == NULL) && (in == NULL)) BN_free(R);\n\tBN_CTX_end(ctx);\n\tbn_check_top(ret);\n\treturn(ret);\n\t}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!(BN_mod(r,m,d,ctx)))\n\t\treturn 0;\n\tif (!r->neg)\n\t\treturn 1;\n\treturn (d->neg ? BN_sub : BN_add)(r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n\t BN_CTX *ctx)\n\t{\n\tint norm_shift,i,loop;\n\tBIGNUM *tmp,wnum,*snum,*sdiv,*res;\n\tBN_ULONG *resp,*wnump;\n\tBN_ULONG d0,d1;\n\tint num_n,div_n;\n\tbn_check_top(dv);\n\tbn_check_top(rm);\n\tbn_check_top(num);\n\tbn_check_top(divisor);\n\tif (BN_is_zero(divisor))\n\t\t{\n\t\tBNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO);\n\t\treturn(0);\n\t\t}\n\tif (BN_ucmp(num,divisor) < 0)\n\t\t{\n\t\tif (rm != NULL)\n\t\t\t{ if (BN_copy(rm,num) == NULL) return(0); }\n\t\tif (dv != NULL) BN_zero(dv);\n\t\treturn(1);\n\t\t}\n\tBN_CTX_start(ctx);\n\ttmp=BN_CTX_get(ctx);\n\tsnum=BN_CTX_get(ctx);\n\tsdiv=BN_CTX_get(ctx);\n\tif (dv == NULL)\n\t\tres=BN_CTX_get(ctx);\n\telse\tres=dv;\n\tif (sdiv == NULL || res == NULL) goto err;\n\tnorm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);\n\tif (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;\n\tsdiv->neg=0;\n\tnorm_shift+=BN_BITS2;\n\tif (!(BN_lshift(snum,num,norm_shift))) goto err;\n\tsnum->neg=0;\n\tdiv_n=sdiv->top;\n\tnum_n=snum->top;\n\tloop=num_n-div_n;\n\twnum.neg = 0;\n\twnum.d = &(snum->d[loop]);\n\twnum.top = div_n;\n\twnum.dmax = snum->dmax - loop;\n\td0=sdiv->d[div_n-1];\n\td1=(div_n == 1)?0:sdiv->d[div_n-2];\n\twnump= &(snum->d[num_n-1]);\n\tres->neg= (num->neg^divisor->neg);\n\tif (!bn_wexpand(res,(loop+1))) goto err;\n\tres->top=loop;\n\tresp= &(res->d[loop-1]);\n\tif (!bn_wexpand(tmp,(div_n+1))) goto err;\n\tif (BN_ucmp(&wnum,sdiv) >= 0)\n\t\t{\n\t\tbn_clear_top2max(&wnum);\n\t\tbn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n\t\t*resp=1;\n\t\t}\n\telse\n\t\tres->top--;\n\tif (res->top == 0)\n\t\tres->neg = 0;\n\telse\n\t\tresp--;\n\tfor (i=0; i<loop-1; i++, wnump--, resp--)\n\t\t{\n\t\tBN_ULONG q,l0;\n#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n\t\tBN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);\n\t\tq=bn_div_3_words(wnump,d1,d0);\n#else\n\t\tBN_ULONG n0,n1,rem=0;\n\t\tn0=wnump[0];\n\t\tn1=wnump[-1];\n\t\tif (n0 == d0)\n\t\t\tq=BN_MASK2;\n\t\telse\n\t\t\t{\n#ifdef BN_LLONG\n\t\t\tBN_ULLONG t2;\n#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n\t\t\tq=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);\n#else\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n\t\t\tt2=(BN_ULLONG)d1*q;\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tt2 -= d1;\n\t\t\t\t}\n#else\n\t\t\tBN_ULONG t2l,t2h,ql,qh;\n\t\t\tq=bn_div_words(n0,n1,d0);\n#ifdef BN_DEBUG_LEVITTE\n\t\t\tfprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\\\nX) -> 0x%08X\\n",\n\t\t\t\tn0, n1, d0, q);\n#endif\n#ifndef REMAINDER_IS_ALREADY_CALCULATED\n\t\t\trem=(n1-q*d0)&BN_MASK2;\n#endif\n#if defined(BN_UMULT_LOHI)\n\t\t\tBN_UMULT_LOHI(t2l,t2h,d1,q);\n#elif defined(BN_UMULT_HIGH)\n\t\t\tt2l = d1 * q;\n\t\t\tt2h = BN_UMULT_HIGH(d1,q);\n#else\n\t\t\tt2l=LBITS(d1); t2h=HBITS(d1);\n\t\t\tql =LBITS(q); qh =HBITS(q);\n\t\t\tmul64(t2l,t2h,ql,qh);\n#endif\n\t\t\tfor (;;)\n\t\t\t\t{\n\t\t\t\tif ((t2h < rem) ||\n\t\t\t\t\t((t2h == rem) && (t2l <= wnump[-2])))\n\t\t\t\t\tbreak;\n\t\t\t\tq--;\n\t\t\t\trem += d0;\n\t\t\t\tif (rem < d0) break;\n\t\t\t\tif (t2l < d1) t2h--; t2l -= d1;\n\t\t\t\t}\n#endif\n\t\t\t}\n#endif\n\t\tl0=bn_mul_words(tmp->d,sdiv->d,div_n,q);\n\t\ttmp->d[div_n]=l0;\n\t\twnum.d--;\n\t\tif (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))\n\t\t\t{\n\t\t\tq--;\n\t\t\tif (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n\t\t\t\t(*wnump)++;\n\t\t\t}\n\t\t*resp = q;\n\t\t}\n\tbn_correct_top(snum);\n\tif (rm != NULL)\n\t\t{\n\t\tint neg = num->neg;\n\t\tBN_rshift(rm,snum,norm_shift);\n\t\tif (!BN_is_zero(rm))\n\t\t\trm->neg = neg;\n\t\tbn_check_top(rm);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(1);\nerr:\n\tbn_check_top(rm);\n\tBN_CTX_end(ctx);\n\treturn(0);\n\t}', '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}']
|
982
| 0
|
https://gitlab.com/libtiff/libtiff/blob/33c391eff475db1e182fad01e6c9f1c1fd0d396f/libtiff/tif_fax3.c/#L707
|
static void
Fax3PutEOL(TIFF* tif)
{
Fax3CodecState* sp = EncoderState(tif);
unsigned int bit = sp->bit;
int data = sp->data;
unsigned int code, length, tparm;
if (sp->b.groupoptions & GROUP3OPT_FILLBITS) {
int align = 8 - 4;
if (align != sp->bit) {
if (align > sp->bit)
align = sp->bit + (8 - align);
else
align = sp->bit - align;
tparm=align;
_PutBits(tif, 0, tparm);
}
}
code = EOL, length = 12;
if (is2DEncoding(sp))
code = (code<<1) | (sp->tag == G3_1D), length++;
_PutBits(tif, code, length);
sp->data = data;
sp->bit = bit;
}
|
['static void\nFax3PutEOL(TIFF* tif)\n{\n\tFax3CodecState* sp = EncoderState(tif);\n\tunsigned int bit = sp->bit;\n\tint data = sp->data;\n\tunsigned int code, length, tparm;\n\tif (sp->b.groupoptions & GROUP3OPT_FILLBITS) {\n\t\tint align = 8 - 4;\n\t\tif (align != sp->bit) {\n\t\t\tif (align > sp->bit)\n\t\t\t\talign = sp->bit + (8 - align);\n\t\t\telse\n\t\t\t\talign = sp->bit - align;\n\t\t\ttparm=align;\n\t\t\t_PutBits(tif, 0, tparm);\n\t\t}\n\t}\n\tcode = EOL, length = 12;\n\tif (is2DEncoding(sp))\n\t\tcode = (code<<1) | (sp->tag == G3_1D), length++;\n\t_PutBits(tif, code, length);\n\tsp->data = data;\n\tsp->bit = bit;\n}']
|
983
| 0
|
https://github.com/libav/libav/blob/490a022d86ef1c506a79744c5a95368af356fc69/libavcodec/v210enc.c/#L45
|
static av_cold int encode_init(AVCodecContext *avctx)
{
if (avctx->width & 1) {
av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
return -1;
}
if (avctx->pix_fmt != PIX_FMT_YUV422P16) {
av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P16\n");
return -1;
}
if (avctx->bits_per_raw_sample != 10)
av_log(avctx, AV_LOG_WARNING, "bits per raw sample: %d != 10-bit\n",
avctx->bits_per_raw_sample);
avctx->coded_frame = avcodec_alloc_frame();
avctx->coded_frame->key_frame = 1;
avctx->coded_frame->pict_type = FF_I_TYPE;
return 0;
}
|
['static av_cold int encode_init(AVCodecContext *avctx)\n{\n if (avctx->width & 1) {\n av_log(avctx, AV_LOG_ERROR, "v210 needs even width\\n");\n return -1;\n }\n if (avctx->pix_fmt != PIX_FMT_YUV422P16) {\n av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P16\\n");\n return -1;\n }\n if (avctx->bits_per_raw_sample != 10)\n av_log(avctx, AV_LOG_WARNING, "bits per raw sample: %d != 10-bit\\n",\n avctx->bits_per_raw_sample);\n avctx->coded_frame = avcodec_alloc_frame();\n avctx->coded_frame->key_frame = 1;\n avctx->coded_frame->pict_type = FF_I_TYPE;\n return 0;\n}', 'AVFrame *avcodec_alloc_frame(void){\n AVFrame *pic= av_malloc(sizeof(AVFrame));\n if(pic==NULL) return NULL;\n avcodec_get_frame_defaults(pic);\n return pic;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n#if CONFIG_MEMALIGN_HACK\n long diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n ptr = malloc(size+16);\n if(!ptr)\n return ptr;\n diff= ((-(long)ptr - 1)&15) + 1;\n ptr = (char*)ptr + diff;\n ((char*)ptr)[-1]= diff;\n#elif HAVE_POSIX_MEMALIGN\n if (posix_memalign(&ptr,16,size))\n ptr = NULL;\n#elif HAVE_MEMALIGN\n ptr = memalign(16,size);\n#else\n ptr = malloc(size);\n#endif\n return ptr;\n}']
|
984
| 0
|
https://github.com/openssl/openssl/blob/9b02dc97e4963969da69675a871dbe80e6d31cda/crypto/bn/bn_shift.c/#L112
|
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
int i, nw, lb, rb;
BN_ULONG *t, *f;
BN_ULONG l;
bn_check_top(r);
bn_check_top(a);
if (n < 0) {
BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
return 0;
}
nw = n / BN_BITS2;
if (bn_wexpand(r, a->top + nw + 1) == NULL)
return 0;
r->neg = a->neg;
lb = n % BN_BITS2;
rb = BN_BITS2 - lb;
f = a->d;
t = r->d;
t[a->top + nw] = 0;
if (lb == 0)
for (i = a->top - 1; i >= 0; i--)
t[nw + i] = f[i];
else
for (i = a->top - 1; i >= 0; i--) {
l = f[i];
t[nw + i + 1] |= (l >> rb) & BN_MASK2;
t[nw + i] = (l << lb) & BN_MASK2;
}
memset(t, 0, sizeof(*t) * nw);
r->top = a->top + nw + 1;
bn_correct_top(r);
bn_check_top(r);
return 1;
}
|
['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_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_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_get_flags(a, BN_FLG_CONSTTIME) == 0)\n && (BN_get_flags(m, BN_FLG_CONSTTIME) == 0)) {\n BN_ULONG A = a->d[0];\n ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n } else\n# endif\n ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n } else\n#endif\n#ifdef RECP_MUL_MOD\n {\n ret = BN_mod_exp_recp(r, a, p, m, ctx);\n }\n#else\n {\n ret = BN_mod_exp_simple(r, a, p, m, ctx);\n }\n#endif\n bn_check_top(r);\n return ret;\n}', 'int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n{\n int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n int start = 1;\n BIGNUM *d, *r;\n const BIGNUM *aa;\n BIGNUM *val[TABLE_SIZE];\n BN_MONT_CTX *mont = NULL;\n if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(a, BN_FLG_CONSTTIME) != 0\n || BN_get_flags(m, BN_FLG_CONSTTIME) != 0) {\n return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);\n }\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n d = BN_CTX_get(ctx);\n r = BN_CTX_get(ctx);\n val[0] = BN_CTX_get(ctx);\n if (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_is_zero(aa)) {\n BN_zero(rr);\n ret = 1;\n goto err;\n }\n if (!BN_to_montgomery(val[0], aa, mont, ctx))\n goto err;\n window = BN_window_bits_for_exponent_size(bits);\n if (window > 1) {\n if (!BN_mod_mul_montgomery(d, val[0], val[0], mont, ctx))\n goto err;\n j = 1 << (window - 1);\n for (i = 1; i < j; i++) {\n if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n !BN_mod_mul_montgomery(val[i], val[i - 1], d, mont, ctx))\n goto err;\n }\n }\n start = 1;\n wvalue = 0;\n wstart = bits - 1;\n wend = 0;\n#if 1\n j = m->top;\n if (m->d[j - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n if (bn_wexpand(r, j) == NULL)\n goto err;\n r->d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < j; i++)\n r->d[i] = (~m->d[i]) & BN_MASK2;\n r->top = j;\n bn_correct_top(r);\n } else\n#endif\n if (!BN_to_montgomery(r, BN_value_one(), mont, ctx))\n goto err;\n for (;;) {\n if (BN_is_bit_set(p, wstart) == 0) {\n if (!start) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (wstart == 0)\n break;\n wstart--;\n continue;\n }\n j = wstart;\n wvalue = 1;\n wend = 0;\n for (i = 1; i < window; i++) {\n if (wstart - i < 0)\n break;\n if (BN_is_bit_set(p, wstart - i)) {\n wvalue <<= (i - wend);\n wvalue |= 1;\n wend = i;\n }\n }\n j = wend + 1;\n if (!start)\n for (i = 0; i < j; i++) {\n if (!BN_mod_mul_montgomery(r, r, r, mont, ctx))\n goto err;\n }\n if (!BN_mod_mul_montgomery(r, r, val[wvalue >> 1], mont, ctx))\n goto err;\n wstart -= wend + 1;\n wvalue = 0;\n start = 0;\n if (wstart < 0)\n break;\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n j = mont->N.top;\n val[0]->d[0] = 1;\n for (i = 1; i < j; i++)\n val[0]->d[i] = 0;\n val[0]->top = j;\n if (!BN_mod_mul_montgomery(rr, r, val[0], mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, r, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n BN_CTX_end(ctx);\n bn_check_top(rr);\n return ret;\n}', 'int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,\n const BIGNUM *m, BN_CTX *ctx,\n BN_MONT_CTX *in_mont)\n{\n int i, bits, ret = 0, window, wvalue;\n int top;\n BN_MONT_CTX *mont = NULL;\n int numPowers;\n unsigned char *powerbufFree = NULL;\n int powerbufLen = 0;\n unsigned char *powerbuf = NULL;\n BIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n unsigned int t4 = 0;\n#endif\n bn_check_top(a);\n bn_check_top(p);\n bn_check_top(m);\n if (!BN_is_odd(m)) {\n BNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME, BN_R_CALLED_WITH_EVEN_MODULUS);\n return 0;\n }\n top = m->top;\n bits = BN_num_bits(p);\n if (bits == 0) {\n if (BN_is_one(m)) {\n ret = 1;\n BN_zero(rr);\n } else {\n ret = BN_one(rr);\n }\n return ret;\n }\n BN_CTX_start(ctx);\n 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 ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n && rsaz_avx2_eligible()) {\n if (NULL == bn_wexpand(rr, 16))\n goto err;\n RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d,\n mont->n0[0]);\n rr->top = 16;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n } else if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512)) {\n if (NULL == bn_wexpand(rr, 8))\n goto err;\n RSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n rr->top = 8;\n rr->neg = 0;\n bn_correct_top(rr);\n ret = 1;\n goto err;\n }\n#endif\n window = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n if (window >= 5 && (top & 15) == 0 && top <= 64 &&\n (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) ==\n (CFR_MONTMUL | CFR_MONTSQR) && (t4 = OPENSSL_sparcv9cap_P[0]))\n window = 5;\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window >= 5) {\n window = 5;\n powerbufLen += top * sizeof(mont->N.d[0]);\n }\n#endif\n (void)0;\n numPowers = 1 << window;\n powerbufLen += sizeof(m->d[0]) * (top * numPowers +\n ((2 * top) >\n numPowers ? (2 * top) : numPowers));\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree =\n alloca(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n else\n#endif\n if ((powerbufFree =\n OPENSSL_malloc(powerbufLen + MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH))\n == NULL)\n goto err;\n powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n memset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n if (powerbufLen < 3072)\n powerbufFree = NULL;\n#endif\n tmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0]) * top * numPowers);\n am.d = tmp.d + top;\n tmp.top = am.top = 0;\n tmp.dmax = am.dmax = top;\n tmp.neg = am.neg = 0;\n tmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n if (m->d[top - 1] & (((BN_ULONG)1) << (BN_BITS2 - 1))) {\n tmp.d[0] = (0 - m->d[0]) & BN_MASK2;\n for (i = 1; i < top; i++)\n tmp.d[i] = (~m->d[i]) & BN_MASK2;\n tmp.top = top;\n } else\n#endif\n if (!BN_to_montgomery(&tmp, BN_value_one(), mont, ctx))\n goto err;\n if (a->neg || BN_ucmp(a, m) >= 0) {\n if (!BN_mod(&am, a, m, ctx))\n goto err;\n if (!BN_to_montgomery(&am, &am, mont, ctx))\n goto err;\n } else if (!BN_to_montgomery(&am, a, mont, ctx))\n goto err;\n#if defined(SPARC_T4_MONT)\n if (t4) {\n typedef int (*bn_pwr5_mont_f) (BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_8(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_16(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_24(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n int bn_pwr5_mont_t4_32(BN_ULONG *tp, const BN_ULONG *np,\n const BN_ULONG *n0, const void *table,\n int power, int bits);\n static const bn_pwr5_mont_f pwr5_funcs[4] = {\n bn_pwr5_mont_t4_8, bn_pwr5_mont_t4_16,\n bn_pwr5_mont_t4_24, bn_pwr5_mont_t4_32\n };\n bn_pwr5_mont_f pwr5_worker = pwr5_funcs[top / 16 - 1];\n typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, const void *bp,\n const BN_ULONG *np, const BN_ULONG *n0);\n int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0);\n static const bn_mul_mont_f mul_funcs[4] = {\n bn_mul_mont_t4_8, bn_mul_mont_t4_16,\n bn_mul_mont_t4_24, bn_mul_mont_t4_32\n };\n bn_mul_mont_f mul_worker = mul_funcs[top / 16 - 1];\n void bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *bp, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n void bn_mul_mont_gather5_t4(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_flip_n_scatter5_t4(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5_t4(BN_ULONG *out, size_t num,\n void *table, size_t power);\n void bn_flip_t4(BN_ULONG *dst, BN_ULONG *src, size_t num);\n BN_ULONG *np = mont->N.d, *n0 = mont->n0;\n int stride = 5 * (6 - (top / 16 - 1));\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 0);\n bn_flip_n_scatter5_t4(am.d, top, powerbuf, 1);\n if (!(*mul_worker) (tmp.d, am.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, am.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, am.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, 2);\n for (i = 3; i < 32; i++) {\n if (!(*mul_worker) (tmp.d, tmp.d, am.d, np, n0) &&\n !(*mul_worker) (tmp.d, tmp.d, am.d, np, n0))\n bn_mul_mont_vis3(tmp.d, tmp.d, am.d, np, n0, top);\n bn_flip_n_scatter5_t4(tmp.d, top, powerbuf, i);\n }\n np = alloca(top * sizeof(BN_ULONG));\n top /= 2;\n bn_flip_t4(np, mont->N.d, top);\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5_t4(tmp.d, top, powerbuf, wvalue);\n while (bits >= 0) {\n if (bits < stride)\n stride = bits + 1;\n bits -= stride;\n wvalue = bn_get_bits(p, bits + 1);\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n if ((*pwr5_worker) (tmp.d, np, n0, powerbuf, wvalue, stride))\n continue;\n bits += stride - 5;\n wvalue >>= stride - 5;\n wvalue &= 31;\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_t4(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5_t4(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n }\n bn_flip_t4(tmp.d, tmp.d, top);\n top *= 2;\n tmp.top = top;\n bn_correct_top(&tmp);\n OPENSSL_cleanse(np, top * sizeof(BN_ULONG));\n } else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window == 5 && top > 1) {\n void bn_mul_mont_gather5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n void bn_scatter5(const BN_ULONG *inp, size_t num,\n void *table, size_t power);\n void bn_gather5(BN_ULONG *out, size_t num, void *table, size_t power);\n void bn_power5(BN_ULONG *rp, const BN_ULONG *ap,\n const void *table, const BN_ULONG *np,\n const BN_ULONG *n0, int num, int power);\n int bn_get_bits5(const BN_ULONG *ap, int off);\n int bn_from_montgomery(BN_ULONG *rp, const BN_ULONG *ap,\n const BN_ULONG *not_used, const BN_ULONG *np,\n const BN_ULONG *n0, int num);\n BN_ULONG *n0 = mont->n0, *np;\n for (i = am.top; i < top; i++)\n am.d[i] = 0;\n for (i = tmp.top; i < top; i++)\n tmp.d[i] = 0;\n for (np = am.d + top, i = 0; i < top; i++)\n np[i] = mont->N.d[i];\n bn_scatter5(tmp.d, top, powerbuf, 0);\n bn_scatter5(am.d, am.top, powerbuf, 1);\n bn_mul_mont(tmp.d, am.d, am.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2);\n# if 0\n for (i = 3; i < 32; i++) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# else\n for (i = 4; i < 32; i *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n for (i = 3; i < 8; i += 2) {\n int j;\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n for (j = 2 * i; j < 32; j *= 2) {\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, j);\n }\n }\n for (; i < 16; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_scatter5(tmp.d, top, powerbuf, 2 * i);\n }\n for (; i < 32; i += 2) {\n bn_mul_mont_gather5(tmp.d, am.d, powerbuf, np, n0, top, i - 1);\n bn_scatter5(tmp.d, top, powerbuf, i);\n }\n# endif\n bits--;\n for (wvalue = 0, i = bits % 5; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_gather5(tmp.d, top, powerbuf, wvalue);\n if (top & 7)\n while (bits >= 0) {\n for (wvalue = 0, i = 0; i < 5; i++, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont(tmp.d, tmp.d, tmp.d, np, n0, top);\n bn_mul_mont_gather5(tmp.d, tmp.d, powerbuf, np, n0, top,\n wvalue);\n } else {\n while (bits >= 0) {\n wvalue = bn_get_bits5(p->d, bits - 4);\n bits -= 5;\n bn_power5(tmp.d, tmp.d, powerbuf, np, n0, top, wvalue);\n }\n }\n ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);\n tmp.top = top;\n bn_correct_top(&tmp);\n if (ret) {\n if (!BN_copy(rr, &tmp))\n ret = 0;\n goto err;\n }\n } else\n#endif\n {\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, window))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, window))\n goto err;\n if (window > 1) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &am, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2,\n window))\n goto err;\n for (i = 3; i < numPowers; i++) {\n if (!BN_mod_mul_montgomery(&tmp, &am, &tmp, mont, ctx))\n goto err;\n if (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i,\n window))\n goto err;\n }\n }\n bits--;\n for (wvalue = 0, i = bits % window; i >= 0; i--, bits--)\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp, top, powerbuf, wvalue,\n window))\n goto err;\n while (bits >= 0) {\n wvalue = 0;\n for (i = 0; i < window; i++, bits--) {\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &tmp, mont, ctx))\n goto err;\n wvalue = (wvalue << 1) + BN_is_bit_set(p, bits);\n }\n if (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue,\n window))\n goto err;\n if (!BN_mod_mul_montgomery(&tmp, &tmp, &am, mont, ctx))\n goto err;\n }\n }\n#if defined(SPARC_T4_MONT)\n if (OPENSSL_sparcv9cap_P[0] & (SPARCV9_VIS3 | SPARCV9_PREFER_FPU)) {\n am.d[0] = 1;\n for (i = 1; i < top; i++)\n am.d[i] = 0;\n if (!BN_mod_mul_montgomery(rr, &tmp, &am, mont, ctx))\n goto err;\n } else\n#endif\n if (!BN_from_montgomery(rr, &tmp, mont, ctx))\n goto err;\n ret = 1;\n err:\n if (in_mont == NULL)\n BN_MONT_CTX_free(mont);\n if (powerbuf != NULL) {\n OPENSSL_cleanse(powerbuf, powerbufLen);\n OPENSSL_free(powerbufFree);\n }\n BN_CTX_end(ctx);\n return ret;\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n BN_CTX *ctx)\n{\n int norm_shift, i, loop;\n BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n BN_ULONG *resp, *wnump;\n BN_ULONG d0, d1;\n int num_n, div_n;\n int no_branch = 0;\n if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n return 0;\n }\n bn_check_top(num);\n bn_check_top(divisor);\n if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n no_branch = 1;\n }\n bn_check_top(dv);\n bn_check_top(rm);\n if (BN_is_zero(divisor)) {\n BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n return 0;\n }\n if (!no_branch && BN_ucmp(num, divisor) < 0) {\n if (rm != NULL) {\n if (BN_copy(rm, num) == NULL)\n return 0;\n }\n if (dv != NULL)\n BN_zero(dv);\n return 1;\n }\n BN_CTX_start(ctx);\n res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n tmp = BN_CTX_get(ctx);\n snum = BN_CTX_get(ctx);\n sdiv = BN_CTX_get(ctx);\n if (sdiv == NULL)\n goto err;\n norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n if (!(BN_lshift(sdiv, divisor, norm_shift)))\n goto err;\n sdiv->neg = 0;\n norm_shift += BN_BITS2;\n if (!(BN_lshift(snum, num, norm_shift)))\n goto err;\n snum->neg = 0;\n if (no_branch) {\n if (snum->top <= sdiv->top + 1) {\n if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n goto err;\n for (i = snum->top; i < sdiv->top + 2; i++)\n snum->d[i] = 0;\n snum->top = sdiv->top + 2;\n } else {\n if (bn_wexpand(snum, snum->top + 1) == NULL)\n goto err;\n snum->d[snum->top] = 0;\n snum->top++;\n }\n }\n div_n = sdiv->top;\n num_n = snum->top;\n loop = num_n - div_n;\n wnum.neg = 0;\n wnum.d = &(snum->d[loop]);\n wnum.top = div_n;\n wnum.dmax = snum->dmax - loop;\n d0 = sdiv->d[div_n - 1];\n d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n wnump = &(snum->d[num_n - 1]);\n if (!bn_wexpand(res, (loop + 1)))\n goto err;\n res->neg = (num->neg ^ divisor->neg);\n res->top = loop - no_branch;\n resp = &(res->d[loop - 1]);\n if (!bn_wexpand(tmp, (div_n + 1)))\n goto err;\n if (!no_branch) {\n if (BN_ucmp(&wnum, sdiv) >= 0) {\n bn_clear_top2max(&wnum);\n bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n *resp = 1;\n } else\n res->top--;\n }\n resp++;\n if (res->top == 0)\n res->neg = 0;\n else\n resp--;\n for (i = 0; i < loop - 1; i++, wnump--) {\n BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n q = bn_div_3_words(wnump, d1, d0);\n# else\n BN_ULONG n0, n1, rem = 0;\n n0 = wnump[0];\n n1 = wnump[-1];\n if (n0 == d0)\n q = BN_MASK2;\n else {\n# ifdef BN_LLONG\n BN_ULLONG t2;\n# if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n# else\n q = bn_div_words(n0, n1, d0);\n# endif\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n t2 = (BN_ULLONG) d1 *q;\n for (;;) {\n if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n t2 -= d1;\n }\n# else\n BN_ULONG t2l, t2h;\n q = bn_div_words(n0, n1, d0);\n# ifndef REMAINDER_IS_ALREADY_CALCULATED\n rem = (n1 - q * d0) & BN_MASK2;\n# endif\n# if defined(BN_UMULT_LOHI)\n BN_UMULT_LOHI(t2l, t2h, d1, q);\n# elif defined(BN_UMULT_HIGH)\n t2l = d1 * q;\n t2h = BN_UMULT_HIGH(d1, q);\n# else\n {\n BN_ULONG ql, qh;\n t2l = LBITS(d1);\n t2h = HBITS(d1);\n ql = LBITS(q);\n qh = HBITS(q);\n mul64(t2l, t2h, ql, qh);\n }\n# endif\n for (;;) {\n if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n break;\n q--;\n rem += d0;\n if (rem < d0)\n break;\n if (t2l < d1)\n t2h--;\n t2l -= d1;\n }\n# endif\n }\n# endif\n l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n tmp->d[div_n] = l0;\n wnum.d--;\n if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n q--;\n if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n (*wnump)++;\n }\n resp--;\n *resp = q;\n }\n bn_correct_top(snum);\n if (rm != NULL) {\n int neg = num->neg;\n BN_rshift(rm, snum, norm_shift);\n if (!BN_is_zero(rm))\n rm->neg = neg;\n bn_check_top(rm);\n }\n if (no_branch)\n bn_correct_top(res);\n BN_CTX_end(ctx);\n return 1;\n err:\n bn_check_top(rm);\n BN_CTX_end(ctx);\n return 0;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n int i, nw, lb, rb;\n BN_ULONG *t, *f;\n BN_ULONG l;\n bn_check_top(r);\n bn_check_top(a);\n if (n < 0) {\n BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n return 0;\n }\n nw = n / BN_BITS2;\n if (bn_wexpand(r, a->top + nw + 1) == NULL)\n return 0;\n r->neg = a->neg;\n lb = n % BN_BITS2;\n rb = BN_BITS2 - lb;\n f = a->d;\n t = r->d;\n t[a->top + nw] = 0;\n if (lb == 0)\n for (i = a->top - 1; i >= 0; i--)\n t[nw + i] = f[i];\n else\n for (i = a->top - 1; i >= 0; i--) {\n l = f[i];\n t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n t[nw + i] = (l << lb) & BN_MASK2;\n }\n memset(t, 0, sizeof(*t) * nw);\n r->top = a->top + nw + 1;\n bn_correct_top(r);\n bn_check_top(r);\n return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']
|
985
| 0
|
https://github.com/libav/libav/blob/831018b0bbe26a603802a9022472f714a59293be/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 inline int decode_block(CLVContext *ctx, int16_t *blk, int has_ac,\n int ac_quant)\n{\n BitstreamContext *bc = &ctx->bc;\n int idx = 1, last = 0, val, skip;\n memset(blk, 0, sizeof(*blk) * 64);\n blk[0] = bitstream_read_vlc(bc, ctx->dc_vlc.table, 9, 3);\n if (blk[0] < 0)\n return AVERROR_INVALIDDATA;\n blk[0] -= 63;\n if (!has_ac)\n return 0;\n while (idx < 64 && !last) {\n val = bitstream_read_vlc(bc, ctx->ac_vlc.table, 9, 2);\n if (val < 0)\n return AVERROR_INVALIDDATA;\n if (val != 0x1BFF) {\n last = val >> 12;\n skip = (val >> 4) & 0xFF;\n val &= 0xF;\n if (bitstream_read_bit(bc))\n val = -val;\n } else {\n last = bitstream_read_bit(bc);\n skip = bitstream_read(bc, 6);\n val = bitstream_read_signed(bc, 8);\n }\n if (val) {\n int aval = FFABS(val), sign = val < 0;\n val = ac_quant * (2 * aval + 1);\n if (!(ac_quant & 1))\n val--;\n if (sign)\n val = -val;\n }\n idx += skip;\n if (idx >= 64)\n return AVERROR_INVALIDDATA;\n blk[ff_zigzag_direct[idx++]] = val;\n }\n return (idx <= 64 && last) ? 0 : -1;\n}', 'static inline int32_t bitstream_read_signed(BitstreamContext *bc, unsigned n)\n{\n return sign_extend(bitstream_read(bc, n), n);\n}', 'static inline uint32_t bitstream_read(BitstreamContext *bc, unsigned n)\n{\n if (!n)\n return 0;\n if (n > bc->bits_left) {\n refill_32(bc);\n if (bc->bits_left < 32)\n bc->bits_left = n;\n }\n return get_val(bc, n);\n}', 'static inline 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}']
|
986
| 0
|
https://github.com/libav/libav/blob/43bacd5b7d3d265a77cd29d8abb131057796aecc/libavformat/mpegts.c/#L699
|
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
{
GetBitContext gb;
int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
int dts_flag = -1, cts_flag = -1;
int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;
init_get_bits(&gb, buf, buf_size*8);
if (sl->use_au_start)
au_start_flag = get_bits1(&gb);
if (sl->use_au_end)
au_end_flag = get_bits1(&gb);
if (!sl->use_au_start && !sl->use_au_end)
au_start_flag = au_end_flag = 1;
if (sl->ocr_len > 0)
ocr_flag = get_bits1(&gb);
if (sl->use_idle)
idle_flag = get_bits1(&gb);
if (sl->use_padding)
padding_flag = get_bits1(&gb);
if (padding_flag)
padding_bits = get_bits(&gb, 3);
if (!idle_flag && (!padding_flag || padding_bits != 0)) {
if (sl->packet_seq_num_len)
skip_bits_long(&gb, sl->packet_seq_num_len);
if (sl->degr_prior_len)
if (get_bits1(&gb))
skip_bits(&gb, sl->degr_prior_len);
if (ocr_flag)
skip_bits_long(&gb, sl->ocr_len);
if (au_start_flag) {
if (sl->use_rand_acc_pt)
get_bits1(&gb);
if (sl->au_seq_num_len > 0)
skip_bits_long(&gb, sl->au_seq_num_len);
if (sl->use_timestamps) {
dts_flag = get_bits1(&gb);
cts_flag = get_bits1(&gb);
}
}
if (sl->inst_bitrate_len)
inst_bitrate_flag = get_bits1(&gb);
if (dts_flag == 1)
dts = get_bits64(&gb, sl->timestamp_len);
if (cts_flag == 1)
cts = get_bits64(&gb, sl->timestamp_len);
if (sl->au_len > 0)
skip_bits_long(&gb, sl->au_len);
if (inst_bitrate_flag)
skip_bits_long(&gb, sl->inst_bitrate_len);
}
if (dts != AV_NOPTS_VALUE)
pes->dts = dts;
if (cts != AV_NOPTS_VALUE)
pes->pts = cts;
if (sl->timestamp_len && sl->timestamp_res)
avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);
return (get_bits_count(&gb) + 7) >> 3;
}
|
['static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)\n{\n GetBitContext gb;\n int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;\n int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;\n int dts_flag = -1, cts_flag = -1;\n int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;\n init_get_bits(&gb, buf, buf_size*8);\n if (sl->use_au_start)\n au_start_flag = get_bits1(&gb);\n if (sl->use_au_end)\n au_end_flag = get_bits1(&gb);\n if (!sl->use_au_start && !sl->use_au_end)\n au_start_flag = au_end_flag = 1;\n if (sl->ocr_len > 0)\n ocr_flag = get_bits1(&gb);\n if (sl->use_idle)\n idle_flag = get_bits1(&gb);\n if (sl->use_padding)\n padding_flag = get_bits1(&gb);\n if (padding_flag)\n padding_bits = get_bits(&gb, 3);\n if (!idle_flag && (!padding_flag || padding_bits != 0)) {\n if (sl->packet_seq_num_len)\n skip_bits_long(&gb, sl->packet_seq_num_len);\n if (sl->degr_prior_len)\n if (get_bits1(&gb))\n skip_bits(&gb, sl->degr_prior_len);\n if (ocr_flag)\n skip_bits_long(&gb, sl->ocr_len);\n if (au_start_flag) {\n if (sl->use_rand_acc_pt)\n get_bits1(&gb);\n if (sl->au_seq_num_len > 0)\n skip_bits_long(&gb, sl->au_seq_num_len);\n if (sl->use_timestamps) {\n dts_flag = get_bits1(&gb);\n cts_flag = get_bits1(&gb);\n }\n }\n if (sl->inst_bitrate_len)\n inst_bitrate_flag = get_bits1(&gb);\n if (dts_flag == 1)\n dts = get_bits64(&gb, sl->timestamp_len);\n if (cts_flag == 1)\n cts = get_bits64(&gb, sl->timestamp_len);\n if (sl->au_len > 0)\n skip_bits_long(&gb, sl->au_len);\n if (inst_bitrate_flag)\n skip_bits_long(&gb, sl->inst_bitrate_len);\n }\n if (dts != AV_NOPTS_VALUE)\n pes->dts = dts;\n if (cts != AV_NOPTS_VALUE)\n pes->pts = cts;\n if (sl->timestamp_len && sl->timestamp_res)\n avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res);\n return (get_bits_count(&gb) + 7) >> 3;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n int bit_size)\n{\n int buffer_size;\n int ret = 0;\n if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n buffer_size = bit_size = 0;\n buffer = NULL;\n ret = AVERROR_INVALIDDATA;\n }\n buffer_size = (bit_size + 7) >> 3;\n s->buffer = buffer;\n s->size_in_bits = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n s->size_in_bits_plus8 = bit_size + 8;\n#endif\n s->buffer_end = buffer + buffer_size;\n s->index = 0;\n return ret;\n}', 'static inline unsigned int get_bits1(GetBitContext *s)\n{\n unsigned int index = s->index;\n uint8_t result = s->buffer[index >> 3];\n#ifdef BITSTREAM_READER_LE\n result >>= index & 7;\n result &= 1;\n#else\n result <<= index & 7;\n result >>= 8 - 1;\n#endif\n#if !UNCHECKED_BITSTREAM_READER\n if (s->index < s->size_in_bits_plus8)\n#endif\n index++;\n s->index = index;\n return result;\n}']
|
987
| 0
|
https://github.com/libav/libav/blob/e557584aa7df6ac9f52af7ee7e5c963437da2e2f/libavcodec/mpegvideo_enc.c/#L1051
|
static int estimate_best_b_count(MpegEncContext *s)
{
AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);
AVCodecContext *c = avcodec_alloc_context3(NULL);
AVFrame input[FF_MAX_B_FRAMES + 2];
const int scale = s->avctx->brd_scale;
int i, j, out_size, p_lambda, b_lambda, lambda2;
int64_t best_rd = INT64_MAX;
int best_b_count = -1;
assert(scale >= 0 && scale <= 3);
p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];
b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B];
if (!b_lambda)
b_lambda = p_lambda;
lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>
FF_LAMBDA_SHIFT;
c->width = s->width >> scale;
c->height = s->height >> scale;
c->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR |
CODEC_FLAG_INPUT_PRESERVED ;
c->flags |= s->avctx->flags & CODEC_FLAG_QPEL;
c->mb_decision = s->avctx->mb_decision;
c->me_cmp = s->avctx->me_cmp;
c->mb_cmp = s->avctx->mb_cmp;
c->me_sub_cmp = s->avctx->me_sub_cmp;
c->pix_fmt = AV_PIX_FMT_YUV420P;
c->time_base = s->avctx->time_base;
c->max_b_frames = s->max_b_frames;
if (avcodec_open2(c, codec, NULL) < 0)
return -1;
for (i = 0; i < s->max_b_frames + 2; i++) {
int ysize = c->width * c->height;
int csize = (c->width / 2) * (c->height / 2);
Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :
s->next_picture_ptr;
avcodec_get_frame_defaults(&input[i]);
input[i].data[0] = av_malloc(ysize + 2 * csize);
input[i].data[1] = input[i].data[0] + ysize;
input[i].data[2] = input[i].data[1] + csize;
input[i].linesize[0] = c->width;
input[i].linesize[1] =
input[i].linesize[2] = c->width / 2;
if (pre_input_ptr && (!i || s->input_picture[i - 1])) {
pre_input = *pre_input_ptr;
if (!pre_input.shared && i) {
pre_input.f.data[0] += INPLACE_OFFSET;
pre_input.f.data[1] += INPLACE_OFFSET;
pre_input.f.data[2] += INPLACE_OFFSET;
}
s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0],
pre_input.f.data[0], pre_input.f.linesize[0],
c->width, c->height);
s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1],
pre_input.f.data[1], pre_input.f.linesize[1],
c->width >> 1, c->height >> 1);
s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2],
pre_input.f.data[2], pre_input.f.linesize[2],
c->width >> 1, c->height >> 1);
}
}
for (j = 0; j < s->max_b_frames + 1; j++) {
int64_t rd = 0;
if (!s->input_picture[j])
break;
c->error[0] = c->error[1] = c->error[2] = 0;
input[0].pict_type = AV_PICTURE_TYPE_I;
input[0].quality = 1 * FF_QP2LAMBDA;
out_size = encode_frame(c, &input[0]);
for (i = 0; i < s->max_b_frames + 1; i++) {
int is_p = i % (j + 1) == j || i == s->max_b_frames;
input[i + 1].pict_type = is_p ?
AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B;
input[i + 1].quality = is_p ? p_lambda : b_lambda;
out_size = encode_frame(c, &input[i + 1]);
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
}
while (out_size) {
out_size = encode_frame(c, NULL);
rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);
}
rd += c->error[0] + c->error[1] + c->error[2];
if (rd < best_rd) {
best_rd = rd;
best_b_count = j;
}
}
avcodec_close(c);
av_freep(&c);
for (i = 0; i < s->max_b_frames + 2; i++) {
av_freep(&input[i].data[0]);
}
return best_b_count;
}
|
['static int estimate_best_b_count(MpegEncContext *s)\n{\n AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id);\n AVCodecContext *c = avcodec_alloc_context3(NULL);\n AVFrame input[FF_MAX_B_FRAMES + 2];\n const int scale = s->avctx->brd_scale;\n int i, j, out_size, p_lambda, b_lambda, lambda2;\n int64_t best_rd = INT64_MAX;\n int best_b_count = -1;\n assert(scale >= 0 && scale <= 3);\n p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];\n b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B];\n if (!b_lambda)\n b_lambda = p_lambda;\n lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>\n FF_LAMBDA_SHIFT;\n c->width = s->width >> scale;\n c->height = s->height >> scale;\n c->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR |\n CODEC_FLAG_INPUT_PRESERVED ;\n c->flags |= s->avctx->flags & CODEC_FLAG_QPEL;\n c->mb_decision = s->avctx->mb_decision;\n c->me_cmp = s->avctx->me_cmp;\n c->mb_cmp = s->avctx->mb_cmp;\n c->me_sub_cmp = s->avctx->me_sub_cmp;\n c->pix_fmt = AV_PIX_FMT_YUV420P;\n c->time_base = s->avctx->time_base;\n c->max_b_frames = s->max_b_frames;\n if (avcodec_open2(c, codec, NULL) < 0)\n return -1;\n for (i = 0; i < s->max_b_frames + 2; i++) {\n int ysize = c->width * c->height;\n int csize = (c->width / 2) * (c->height / 2);\n Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] :\n s->next_picture_ptr;\n avcodec_get_frame_defaults(&input[i]);\n input[i].data[0] = av_malloc(ysize + 2 * csize);\n input[i].data[1] = input[i].data[0] + ysize;\n input[i].data[2] = input[i].data[1] + csize;\n input[i].linesize[0] = c->width;\n input[i].linesize[1] =\n input[i].linesize[2] = c->width / 2;\n if (pre_input_ptr && (!i || s->input_picture[i - 1])) {\n pre_input = *pre_input_ptr;\n if (!pre_input.shared && i) {\n pre_input.f.data[0] += INPLACE_OFFSET;\n pre_input.f.data[1] += INPLACE_OFFSET;\n pre_input.f.data[2] += INPLACE_OFFSET;\n }\n s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0],\n pre_input.f.data[0], pre_input.f.linesize[0],\n c->width, c->height);\n s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1],\n pre_input.f.data[1], pre_input.f.linesize[1],\n c->width >> 1, c->height >> 1);\n s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2],\n pre_input.f.data[2], pre_input.f.linesize[2],\n c->width >> 1, c->height >> 1);\n }\n }\n for (j = 0; j < s->max_b_frames + 1; j++) {\n int64_t rd = 0;\n if (!s->input_picture[j])\n break;\n c->error[0] = c->error[1] = c->error[2] = 0;\n input[0].pict_type = AV_PICTURE_TYPE_I;\n input[0].quality = 1 * FF_QP2LAMBDA;\n out_size = encode_frame(c, &input[0]);\n for (i = 0; i < s->max_b_frames + 1; i++) {\n int is_p = i % (j + 1) == j || i == s->max_b_frames;\n input[i + 1].pict_type = is_p ?\n AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B;\n input[i + 1].quality = is_p ? p_lambda : b_lambda;\n out_size = encode_frame(c, &input[i + 1]);\n rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);\n }\n while (out_size) {\n out_size = encode_frame(c, NULL);\n rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3);\n }\n rd += c->error[0] + c->error[1] + c->error[2];\n if (rd < best_rd) {\n best_rd = rd;\n best_b_count = j;\n }\n }\n avcodec_close(c);\n av_freep(&c);\n for (i = 0; i < s->max_b_frames + 2; i++) {\n av_freep(&input[i].data[0]);\n }\n return best_b_count;\n}', 'AVCodec *avcodec_find_encoder(enum AVCodecID id)\n{\n return find_encdec(id, 1);\n}', 'AVCodecContext *avcodec_alloc_context3(const AVCodec *codec)\n{\n AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));\n if(avctx==NULL) return NULL;\n if(avcodec_get_context_defaults3(avctx, codec) < 0){\n av_free(avctx);\n return NULL;\n }\n return avctx;\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}']
|
988
| 0
|
https://github.com/openssl/openssl/blob/d40a1b865fddc3d67f8c06ff1f1466fad331c8f7/crypto/mem_dbg.c/#L683
|
static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)
{
char buf[1024];
char *bufp = buf;
APP_INFO *amip;
size_t ami_cnt;
struct tm *lcl = NULL;
CRYPTO_THREADID ti;
#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
if(m->addr == (char *)l->bio)
return;
if (options & V_CRYPTO_MDEBUG_TIME)
{
lcl = localtime(&m->time);
BIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",
lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
bufp += strlen(bufp);
}
BIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ",
m->order,m->file,m->line);
bufp += strlen(bufp);
if (options & V_CRYPTO_MDEBUG_THREAD)
{
BIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ",
CRYPTO_THREADID_hash(&m->threadid));
bufp += strlen(bufp);
}
BIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\n",
m->num,(unsigned long)m->addr);
bufp += strlen(bufp);
BIO_puts(l->bio,buf);
l->chunks++;
l->bytes+=m->num;
amip=m->app_info;
ami_cnt=0;
if (!amip)
return;
CRYPTO_THREADID_cpy(&ti, &amip->threadid);
do
{
size_t buf_len;
int info_len;
ami_cnt++;
memset(buf,'>',ami_cnt);
BIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,
" thread=%lu, file=%s, line=%d, info=\"",
CRYPTO_THREADID_hash(&amip->threadid), amip->file,
amip->line);
buf_len=strlen(buf);
info_len=strlen(amip->info);
if (128 - buf_len - 3 < info_len)
{
memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
buf_len = 128 - 3;
}
else
{
BUF_strlcpy(buf + buf_len, amip->info,
sizeof buf - buf_len);
buf_len = strlen(buf);
}
BIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\"\n");
BIO_puts(l->bio,buf);
amip = amip->next;
}
while(amip && !CRYPTO_THREADID_cmp(&amip->threadid, &ti));
#ifdef LEVITTE_DEBUG_MEM
if (amip)
{
fprintf(stderr, "Thread switch detected in backtrace!!!!\n");
abort();
}
#endif
}
|
['static void print_leak_doall_arg(const MEM *m, MEM_LEAK *l)\n\t{\n\tchar buf[1024];\n\tchar *bufp = buf;\n\tAPP_INFO *amip;\n\tsize_t ami_cnt;\n\tstruct tm *lcl = NULL;\n\tCRYPTO_THREADID ti;\n#define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))\n\tif(m->addr == (char *)l->bio)\n\t return;\n\tif (options & V_CRYPTO_MDEBUG_TIME)\n\t\t{\n\t\tlcl = localtime(&m->time);\n\t\tBIO_snprintf(bufp, BUF_REMAIN, "[%02d:%02d:%02d] ",\n\t\t\tlcl->tm_hour,lcl->tm_min,lcl->tm_sec);\n\t\tbufp += strlen(bufp);\n\t\t}\n\tBIO_snprintf(bufp, BUF_REMAIN, "%5lu file=%s, line=%d, ",\n\t\tm->order,m->file,m->line);\n\tbufp += strlen(bufp);\n\tif (options & V_CRYPTO_MDEBUG_THREAD)\n\t\t{\n\t\tBIO_snprintf(bufp, BUF_REMAIN, "thread=%lu, ",\n\t\t\tCRYPTO_THREADID_hash(&m->threadid));\n\t\tbufp += strlen(bufp);\n\t\t}\n\tBIO_snprintf(bufp, BUF_REMAIN, "number=%d, address=%08lX\\n",\n\t\tm->num,(unsigned long)m->addr);\n\tbufp += strlen(bufp);\n\tBIO_puts(l->bio,buf);\n\tl->chunks++;\n\tl->bytes+=m->num;\n\tamip=m->app_info;\n\tami_cnt=0;\n\tif (!amip)\n\t\treturn;\n\tCRYPTO_THREADID_cpy(&ti, &amip->threadid);\n\tdo\n\t\t{\n\t\tsize_t buf_len;\n\t\tint info_len;\n\t\tami_cnt++;\n\t\tmemset(buf,\'>\',ami_cnt);\n\t\tBIO_snprintf(buf + ami_cnt, sizeof buf - ami_cnt,\n\t\t\t" thread=%lu, file=%s, line=%d, info=\\"",\n\t\t\tCRYPTO_THREADID_hash(&amip->threadid), amip->file,\n\t\t\tamip->line);\n\t\tbuf_len=strlen(buf);\n\t\tinfo_len=strlen(amip->info);\n\t\tif (128 - buf_len - 3 < info_len)\n\t\t\t{\n\t\t\tmemcpy(buf + buf_len, amip->info, 128 - buf_len - 3);\n\t\t\tbuf_len = 128 - 3;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBUF_strlcpy(buf + buf_len, amip->info,\n\t\t\t\t sizeof buf - buf_len);\n\t\t\tbuf_len = strlen(buf);\n\t\t\t}\n\t\tBIO_snprintf(buf + buf_len, sizeof buf - buf_len, "\\"\\n");\n\t\tBIO_puts(l->bio,buf);\n\t\tamip = amip->next;\n\t\t}\n\twhile(amip && !CRYPTO_THREADID_cmp(&amip->threadid, &ti));\n#ifdef LEVITTE_DEBUG_MEM\n\tif (amip)\n\t\t{\n\t\tfprintf(stderr, "Thread switch detected in backtrace!!!!\\n");\n\t\tabort();\n\t\t}\n#endif\n\t}']
|
989
| 0
|
https://github.com/openssl/openssl/blob/c051cbc83ff13e1dee9951b10255f0b9679ba502/crypto/bn/bn_ctx.c/#L355
|
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\t\t const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)\n\t{\n\tint i,bits,ret=0,window,wvalue;\n\tint top;\n\tBN_MONT_CTX *mont=NULL;\n\tint numPowers;\n\tunsigned char *powerbufFree=NULL;\n\tint powerbufLen = 0;\n\tunsigned char *powerbuf=NULL;\n\tBIGNUM tmp, am;\n#if defined(SPARC_T4_MONT)\n\tunsigned int t4=0;\n#endif\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n\ttop = m->top;\n\tif (!(m->d[0] & 1))\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_MONT_CONSTTIME,BN_R_CALLED_WITH_EVEN_MODULUS);\n\t\treturn(0);\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(rr);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\tif (in_mont != NULL)\n\t\tmont=in_mont;\n\telse\n\t\t{\n\t\tif ((mont=BN_MONT_CTX_new()) == NULL) goto err;\n\t\tif (!BN_MONT_CTX_set(mont,m,ctx)) goto err;\n\t\t}\n#ifdef RSAZ_ENABLED\n\tif ((16 == a->top) && (16 == p->top) && (BN_num_bits(m) == 1024)\n\t && rsaz_avx2_eligible())\n\t \t{\n\t\tif (NULL == bn_wexpand(rr, 16)) goto err;\n\t\tRSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d, mont->n0[0]);\n\t\trr->top = 16;\n\t\trr->neg = 0;\n\t\tbn_correct_top(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\telse if ((8 == a->top) && (8 == p->top) && (BN_num_bits(m) == 512))\n\t\t{\n\t\tif (NULL == bn_wexpand(rr,8)) goto err;\n\t\tRSAZ_512_mod_exp(rr->d, a->d, p->d, m->d, mont->n0[0], mont->RR.d);\n\t\trr->top = 8;\n\t\trr->neg = 0;\n\t\tbn_correct_top(rr);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n#endif\n\twindow = BN_window_bits_for_ctime_exponent_size(bits);\n#if defined(SPARC_T4_MONT)\n\tif (window>=5 && (top&15)==0 && top<=64 &&\n\t (OPENSSL_sparcv9cap_P[1]&(CFR_MONTMUL|CFR_MONTSQR))==\n\t \t\t\t (CFR_MONTMUL|CFR_MONTSQR) &&\n\t (t4=OPENSSL_sparcv9cap_P[0]))\n\t\twindow=5;\n\telse\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n\tif (window==6 && bits<=1024) window=5;\n#endif\n\t(void)0;\n\tnumPowers = 1 << window;\n\tpowerbufLen = sizeof(m->d[0])*(top*numPowers +\n\t\t\t\t((2*top)>numPowers?(2*top):numPowers));\n#ifdef alloca\n\tif (powerbufLen < 3072)\n\t\tpowerbufFree = alloca(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);\n\telse\n#endif\n\tif ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)\n\t\tgoto err;\n\tpowerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);\n\tmemset(powerbuf, 0, powerbufLen);\n#ifdef alloca\n\tif (powerbufLen < 3072)\n\t\tpowerbufFree = NULL;\n#endif\n\ttmp.d = (BN_ULONG *)(powerbuf + sizeof(m->d[0])*top*numPowers);\n\tam.d = tmp.d + top;\n\ttmp.top = am.top = 0;\n\ttmp.dmax = am.dmax = top;\n\ttmp.neg = am.neg = 0;\n\ttmp.flags = am.flags = BN_FLG_STATIC_DATA;\n#if 1\n\tif (m->d[top-1] & (((BN_ULONG)1)<<(BN_BITS2-1)))\n\t\t{\n\t\ttmp.d[0] = (0-m->d[0])&BN_MASK2;\n\t\tfor (i=1;i<top;i++) tmp.d[i] = (~m->d[i])&BN_MASK2;\n\t\ttmp.top = top;\n\t\t}\n\telse\n#endif\n \tif (!BN_to_montgomery(&tmp,BN_value_one(),mont,ctx))\tgoto err;\n\tif (a->neg || BN_ucmp(a,m) >= 0)\n\t\t{\n\t\tif (!BN_mod(&am,a,m,ctx))\t\t\tgoto err;\n\t\tif (!BN_to_montgomery(&am,&am,mont,ctx))\tgoto err;\n\t\t}\n\telse\tif (!BN_to_montgomery(&am,a,mont,ctx))\t\tgoto err;\n#if defined(SPARC_T4_MONT)\n if (t4)\n\t{\n\ttypedef int (*bn_pwr5_mont_f)(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_8(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_16(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_24(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tint bn_pwr5_mont_t4_32(BN_ULONG *tp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,const void *table,int power,int bits);\n\tstatic const bn_pwr5_mont_f pwr5_funcs[4] = {\n\t\t\tbn_pwr5_mont_t4_8,\tbn_pwr5_mont_t4_16,\n\t\t\tbn_pwr5_mont_t4_24,\tbn_pwr5_mont_t4_32 };\n\tbn_pwr5_mont_f pwr5_worker = pwr5_funcs[top/16-1];\n\ttypedef int (*bn_mul_mont_f)(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_8(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_16(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_24(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tint bn_mul_mont_t4_32(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,const BN_ULONG *n0);\n\tstatic const bn_mul_mont_f mul_funcs[4] = {\n\t\t\tbn_mul_mont_t4_8,\tbn_mul_mont_t4_16,\n\t\t\tbn_mul_mont_t4_24,\tbn_mul_mont_t4_32 };\n\tbn_mul_mont_f mul_worker = mul_funcs[top/16-1];\n\tvoid bn_mul_mont_vis3(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num);\n\tvoid bn_mul_mont_t4(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *bp,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num);\n\tvoid bn_mul_mont_gather5_t4(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *table,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num,int power);\n\tvoid bn_flip_n_scatter5_t4(const BN_ULONG *inp,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_gather5_t4(BN_ULONG *out,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_flip_t4(BN_ULONG *dst,BN_ULONG *src,size_t num);\n\tBN_ULONG *np=mont->N.d, *n0=mont->n0;\n\tint stride = 5*(6-(top/16-1));\n\tfor (i=am.top; i<top; i++)\tam.d[i]=0;\n\tfor (i=tmp.top; i<top; i++)\ttmp.d[i]=0;\n\tbn_flip_n_scatter5_t4(tmp.d,top,powerbuf,0);\n\tbn_flip_n_scatter5_t4(am.d,top,powerbuf,1);\n\tif (!(*mul_worker)(tmp.d,am.d,am.d,np,n0) &&\n\t !(*mul_worker)(tmp.d,am.d,am.d,np,n0))\n\t\tbn_mul_mont_vis3(tmp.d,am.d,am.d,np,n0,top);\n\tbn_flip_n_scatter5_t4(tmp.d,top,powerbuf,2);\n\tfor (i=3; i<32; i++)\n\t\t{\n\t\tif (!(*mul_worker)(tmp.d,tmp.d,am.d,np,n0) &&\n\t\t !(*mul_worker)(tmp.d,tmp.d,am.d,np,n0))\n\t\t\tbn_mul_mont_vis3(tmp.d,tmp.d,am.d,np,n0,top);\n\t\tbn_flip_n_scatter5_t4(tmp.d,top,powerbuf,i);\n\t\t}\n\tnp = alloca(top*sizeof(BN_ULONG));\n\ttop /= 2;\n\tbn_flip_t4(np,mont->N.d,top);\n\tbits--;\n\tfor (wvalue=0, i=bits%5; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tbn_gather5_t4(tmp.d,top,powerbuf,wvalue);\n\twhile (bits >= 0)\n\t\t{\n\t\tif (bits < stride) stride = bits+1;\n\t\tbits -= stride;\n\t\twvalue = bn_get_bits(p,bits+1);\n\t\tif ((*pwr5_worker)(tmp.d,np,n0,powerbuf,wvalue,stride)) continue;\n\t\tif ((*pwr5_worker)(tmp.d,np,n0,powerbuf,wvalue,stride)) continue;\n\t\tbits += stride-5;\n\t\twvalue >>= stride-5;\n\t\twvalue &= 31;\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_t4(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_gather5_t4(tmp.d,tmp.d,powerbuf,np,n0,top,wvalue);\n\t\t}\n\tbn_flip_t4(tmp.d,tmp.d,top);\n\ttop *= 2;\n\ttmp.top=top;\n\tbn_correct_top(&tmp);\n\tOPENSSL_cleanse(np,top*sizeof(BN_ULONG));\n\t}\n else\n#endif\n#if defined(OPENSSL_BN_ASM_MONT5)\n if (window==5)\n\t{\n\tvoid bn_mul_mont_gather5(BN_ULONG *rp,const BN_ULONG *ap,\n\t\t\tconst void *table,const BN_ULONG *np,\n\t\t\tconst BN_ULONG *n0,int num,int power);\n\tvoid bn_scatter5(const BN_ULONG *inp,size_t num,\n\t\t\tvoid *table,size_t power);\n\tvoid bn_gather5(BN_ULONG *out,size_t num,\n\t\t\tvoid *table,size_t power);\n\tBN_ULONG *np=mont->N.d, *n0=mont->n0;\n\tfor (i=am.top; i<top; i++)\tam.d[i]=0;\n\tfor (i=tmp.top; i<top; i++)\ttmp.d[i]=0;\n\tbn_scatter5(tmp.d,top,powerbuf,0);\n\tbn_scatter5(am.d,am.top,powerbuf,1);\n\tbn_mul_mont(tmp.d,am.d,am.d,np,n0,top);\n\tbn_scatter5(tmp.d,top,powerbuf,2);\n#if 0\n\tfor (i=3; i<32; i++)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n#else\n\tfor (i=4; i<32; i*=2)\n\t\t{\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n\tfor (i=3; i<8; i+=2)\n\t\t{\n\t\tint j;\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\tfor (j=2*i; j<32; j*=2)\n\t\t\t{\n\t\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\t\tbn_scatter5(tmp.d,top,powerbuf,j);\n\t\t\t}\n\t\t}\n\tfor (; i<16; i+=2)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_scatter5(tmp.d,top,powerbuf,2*i);\n\t\t}\n\tfor (; i<32; i+=2)\n\t\t{\n\t\tbn_mul_mont_gather5(tmp.d,am.d,powerbuf,np,n0,top,i-1);\n\t\tbn_scatter5(tmp.d,top,powerbuf,i);\n\t\t}\n#endif\n\tbits--;\n\tfor (wvalue=0, i=bits%5; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tbn_gather5(tmp.d,top,powerbuf,wvalue);\n\twhile (bits >= 0)\n\t\t{\n\t\tfor (wvalue=0, i=0; i<5; i++,bits--)\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont(tmp.d,tmp.d,tmp.d,np,n0,top);\n\t\tbn_mul_mont_gather5(tmp.d,tmp.d,powerbuf,np,n0,top,wvalue);\n\t\t}\n\ttmp.top=top;\n\tbn_correct_top(&tmp);\n\t}\n else\n#endif\n\t{\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 0, numPowers)) goto err;\n\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&am, top, powerbuf, 1, numPowers)) goto err;\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_montgomery(&tmp,&am,&am,mont,ctx))\tgoto err;\n\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, 2, numPowers)) goto err;\n\t\tfor (i=3; i<numPowers; i++)\n\t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(&tmp,&am,&tmp,mont,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (!MOD_EXP_CTIME_COPY_TO_PREBUF(&tmp, top, powerbuf, i, numPowers)) goto err;\n\t\t\t}\n\t\t}\n\tbits--;\n\tfor (wvalue=0, i=bits%window; i>=0; i--,bits--)\n\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&tmp,top,powerbuf,wvalue,numPowers)) goto err;\n \twhile (bits >= 0)\n \t\t{\n \t\twvalue=0;\n \t\tfor (i=0; i<window; i++,bits--)\n \t\t\t{\n\t\t\tif (!BN_mod_mul_montgomery(&tmp,&tmp,&tmp,mont,ctx))\tgoto err;\n\t\t\twvalue = (wvalue<<1)+BN_is_bit_set(p,bits);\n \t\t\t}\n\t\tif (!MOD_EXP_CTIME_COPY_FROM_PREBUF(&am, top, powerbuf, wvalue, numPowers)) goto err;\n \t\tif (!BN_mod_mul_montgomery(&tmp,&tmp,&am,mont,ctx)) goto err;\n \t\t}\n\t}\n#if defined(SPARC_T4_MONT)\n\tif (OPENSSL_sparcv9cap_P[0]&(SPARCV9_VIS3|SPARCV9_PREFER_FPU))\n\t\t{\n\t\tam.d[0] = 1;\n\t\tfor (i=1;i<top;i++) am.d[i] = 0;\n\t\tif (!BN_mod_mul_montgomery(rr,&tmp,&am,mont,ctx)) goto err;\n\t\t}\n\telse\n#endif\n\tif (!BN_from_montgomery(rr,&tmp,mont,ctx)) goto err;\n\tret=1;\nerr:\n\tif ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);\n\tif (powerbuf!=NULL)\n\t\t{\n\t\tOPENSSL_cleanse(powerbuf,powerbufLen);\n\t\tif (powerbufFree) OPENSSL_free(powerbufFree);\n\t\t}\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}', 'void BN_CTX_start(BN_CTX *ctx)\n\t{\n\tCTXDBG_ENTRY("BN_CTX_start", ctx);\n\tif(ctx->err_stack || ctx->too_many)\n\t\tctx->err_stack++;\n\telse if(!BN_STACK_push(&ctx->stack, ctx->used))\n\t\t{\n\t\tBNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n\t\tctx->err_stack++;\n\t\t}\n\tCTXDBG_EXIT(ctx);\n\t}', 'int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n\t\t\t BN_MONT_CTX *mont, BN_CTX *ctx)\n\t{\n\tBIGNUM *tmp;\n\tint ret=0;\n#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)\n\tint num = mont->N.top;\n\tif (num>1 && a->top==num && b->top==num)\n\t\t{\n\t\tif (bn_wexpand(r,num) == NULL) return(0);\n\t\tif (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))\n\t\t\t{\n\t\t\tr->neg = a->neg^b->neg;\n\t\t\tr->top = num;\n\t\t\tbn_correct_top(r);\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n#endif\n\tBN_CTX_start(ctx);\n\ttmp = BN_CTX_get(ctx);\n\tif (tmp == NULL) goto err;\n\tbn_check_top(tmp);\n\tif (a == b)\n\t\t{\n\t\tif (!BN_sqr(tmp,a,ctx)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (!BN_mul(tmp,a,b,ctx)) goto err;\n\t\t}\n#ifdef MONT_WORD\n\tif (!BN_from_montgomery_word(r,tmp,mont)) goto err;\n#else\n\tif (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;\n#endif\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}']
|
990
| 0
|
https://github.com/openssl/openssl/blob/183733f882056ea3e6fe95e665b85fcc6a45dcb4/crypto/async/async.c/#L274
|
int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
void *args, size_t size)
{
async_ctx *ctx = async_get_ctx();
if (ctx == NULL)
ctx = async_ctx_new();
if (ctx == NULL) {
return ASYNC_ERR;
}
if (*job) {
ctx->currjob = *job;
}
for (;;) {
if (ctx->currjob != NULL) {
if (ctx->currjob->status == ASYNC_JOB_STOPPING) {
*ret = ctx->currjob->ret;
async_release_job(ctx->currjob);
ctx->currjob = NULL;
*job = NULL;
return ASYNC_FINISH;
}
if (ctx->currjob->status == ASYNC_JOB_PAUSING) {
*job = ctx->currjob;
ctx->currjob->status = ASYNC_JOB_PAUSED;
ctx->currjob = NULL;
return ASYNC_PAUSE;
}
if (ctx->currjob->status == ASYNC_JOB_PAUSED) {
ctx->currjob = *job;
if (!async_fibre_swapcontext(&ctx->dispatcher,
&ctx->currjob->fibrectx, 1)) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB,
ASYNC_R_FAILED_TO_SWAP_CONTEXT);
goto err;
}
continue;
}
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_INTERNAL_ERROR);
async_release_job(ctx->currjob);
ctx->currjob = NULL;
*job = NULL;
return ASYNC_ERR;
}
if ((ctx->currjob = async_get_pool_job()) == NULL) {
return ASYNC_NO_JOBS;
}
if (args != NULL) {
ctx->currjob->funcargs = OPENSSL_malloc(size);
if (ctx->currjob->funcargs == NULL) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE);
async_release_job(ctx->currjob);
ctx->currjob = NULL;
return ASYNC_ERR;
}
memcpy(ctx->currjob->funcargs, args, size);
} else {
ctx->currjob->funcargs = NULL;
}
ctx->currjob->func = func;
if (!async_fibre_swapcontext(&ctx->dispatcher,
&ctx->currjob->fibrectx, 1)) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
goto err;
}
}
err:
async_release_job(ctx->currjob);
ctx->currjob = NULL;
*job = NULL;
return ASYNC_ERR;
}
|
['int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),\n void *args, size_t size)\n{\n async_ctx *ctx = async_get_ctx();\n if (ctx == NULL)\n ctx = async_ctx_new();\n if (ctx == NULL) {\n return ASYNC_ERR;\n }\n if (*job) {\n ctx->currjob = *job;\n }\n for (;;) {\n if (ctx->currjob != NULL) {\n if (ctx->currjob->status == ASYNC_JOB_STOPPING) {\n *ret = ctx->currjob->ret;\n async_release_job(ctx->currjob);\n ctx->currjob = NULL;\n *job = NULL;\n return ASYNC_FINISH;\n }\n if (ctx->currjob->status == ASYNC_JOB_PAUSING) {\n *job = ctx->currjob;\n ctx->currjob->status = ASYNC_JOB_PAUSED;\n ctx->currjob = NULL;\n return ASYNC_PAUSE;\n }\n if (ctx->currjob->status == ASYNC_JOB_PAUSED) {\n ctx->currjob = *job;\n if (!async_fibre_swapcontext(&ctx->dispatcher,\n &ctx->currjob->fibrectx, 1)) {\n ASYNCerr(ASYNC_F_ASYNC_START_JOB,\n ASYNC_R_FAILED_TO_SWAP_CONTEXT);\n goto err;\n }\n continue;\n }\n ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_INTERNAL_ERROR);\n async_release_job(ctx->currjob);\n ctx->currjob = NULL;\n *job = NULL;\n return ASYNC_ERR;\n }\n if ((ctx->currjob = async_get_pool_job()) == NULL) {\n return ASYNC_NO_JOBS;\n }\n if (args != NULL) {\n ctx->currjob->funcargs = OPENSSL_malloc(size);\n if (ctx->currjob->funcargs == NULL) {\n ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE);\n async_release_job(ctx->currjob);\n ctx->currjob = NULL;\n return ASYNC_ERR;\n }\n memcpy(ctx->currjob->funcargs, args, size);\n } else {\n ctx->currjob->funcargs = NULL;\n }\n ctx->currjob->func = func;\n if (!async_fibre_swapcontext(&ctx->dispatcher,\n &ctx->currjob->fibrectx, 1)) {\n ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);\n goto err;\n }\n }\nerr:\n async_release_job(ctx->currjob);\n ctx->currjob = NULL;\n *job = NULL;\n return ASYNC_ERR;\n}', 'static async_ctx *async_get_ctx(void)\n{\n OPENSSL_INIT_crypto_library_start(OPENSSL_INIT_ASYNC, NULL);\n return async_arch_get_ctx();\n}', 'static async_ctx *async_ctx_new(void)\n{\n async_ctx *nctx = NULL;\n nctx = OPENSSL_malloc(sizeof (async_ctx));\n if (nctx == NULL) {\n ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);\n goto err;\n }\n async_fibre_init_dispatcher(&nctx->dispatcher);\n nctx->currjob = NULL;\n nctx->blocked = 0;\n if (!async_set_ctx(nctx))\n goto err;\n return nctx;\nerr:\n OPENSSL_free(nctx);\n return NULL;\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}']
|
991
| 1
|
https://github.com/openssl/openssl/blob/3aecef76973dbea037ec4e1ceba7ec1bd3fb683a/crypto/objects/obj_dat.c/#L479
|
int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
{
int i,idx=0,n=0,len,nid;
unsigned long l;
unsigned char *p;
const char *s;
char tbuf[32];
if (buf_len <= 0) return(0);
if ((a == NULL) || (a->data == NULL)) {
buf[0]='\0';
return(0);
}
if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {
len=a->length;
p=a->data;
idx=0;
l=0;
while (idx < a->length) {
l|=(p[idx]&0x7f);
if (!(p[idx] & 0x80)) break;
l<<=7L;
idx++;
}
idx++;
i=(int)(l/40);
if (i > 2) i=2;
l-=(long)(i*40);
sprintf(tbuf,"%d.%lu",i,l);
i=strlen(tbuf);
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
for (; idx<len; idx++) {
l|=p[idx]&0x7f;
if (!(p[idx] & 0x80)) {
sprintf(tbuf,".%lu",l);
i=strlen(tbuf);
if (buf_len > 0)
strncpy(buf,tbuf,buf_len);
buf_len-=i;
buf+=i;
n+=i;
l=0;
}
l<<=7L;
}
} else {
s=OBJ_nid2ln(nid);
if (s == NULL)
s=OBJ_nid2sn(nid);
strncpy(buf,s,buf_len);
n=strlen(s);
}
buf[buf_len-1]='\0';
return(n);
}
|
['int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)\n\t{\n\tchar buf[80];\n\tint i;\n\tif ((a == NULL) || (a->data == NULL))\n\t\treturn(BIO_write(bp,"NULL",4));\n\ti=i2t_ASN1_OBJECT(buf,80,a);\n\tif (i > 80) i=80;\n\tBIO_write(bp,buf,i);\n\treturn(i);\n\t}', 'int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)\n{\n\treturn OBJ_obj2txt(buf, buf_len, a, 0);\n}', 'int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)\n{\n\tint i,idx=0,n=0,len,nid;\n\tunsigned long l;\n\tunsigned char *p;\n\tconst char *s;\n\tchar tbuf[32];\n\tif (buf_len <= 0) return(0);\n\tif ((a == NULL) || (a->data == NULL)) {\n\t\tbuf[0]=\'\\0\';\n\t\treturn(0);\n\t}\n\tif (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {\n\t\tlen=a->length;\n\t\tp=a->data;\n\t\tidx=0;\n\t\tl=0;\n\t\twhile (idx < a->length) {\n\t\t\tl|=(p[idx]&0x7f);\n\t\t\tif (!(p[idx] & 0x80)) break;\n\t\t\tl<<=7L;\n\t\t\tidx++;\n\t\t}\n\t\tidx++;\n\t\ti=(int)(l/40);\n\t\tif (i > 2) i=2;\n\t\tl-=(long)(i*40);\n\t\tsprintf(tbuf,"%d.%lu",i,l);\n\t\ti=strlen(tbuf);\n\t\tstrncpy(buf,tbuf,buf_len);\n\t\tbuf_len-=i;\n\t\tbuf+=i;\n\t\tn+=i;\n\t\tl=0;\n\t\tfor (; idx<len; idx++) {\n\t\t\tl|=p[idx]&0x7f;\n\t\t\tif (!(p[idx] & 0x80)) {\n\t\t\t\tsprintf(tbuf,".%lu",l);\n\t\t\t\ti=strlen(tbuf);\n\t\t\t\tif (buf_len > 0)\n\t\t\t\t\tstrncpy(buf,tbuf,buf_len);\n\t\t\t\tbuf_len-=i;\n\t\t\t\tbuf+=i;\n\t\t\t\tn+=i;\n\t\t\t\tl=0;\n\t\t\t}\n\t\t\tl<<=7L;\n\t\t}\n\t} else {\n\t\ts=OBJ_nid2ln(nid);\n\t\tif (s == NULL)\n\t\t\ts=OBJ_nid2sn(nid);\n\t\tstrncpy(buf,s,buf_len);\n\t\tn=strlen(s);\n\t}\n\tbuf[buf_len-1]=\'\\0\';\n\treturn(n);\n}']
|
992
| 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 void generate_step_part(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *g, JPAKE_CTX *ctx)\n {\n BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx);\n generate_zkp(p, x, g, ctx);\n }', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n\t BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(a);\n\tbn_check_top(p);\n\tbn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n\tif (BN_is_odd(m))\n\t\t{\n# ifdef MONT_EXP_WORD\n\t\tif (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0))\n\t\t\t{\n\t\t\tBN_ULONG A = a->d[0];\n\t\t\tret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);\n\t\t\t}\n\t\telse\n# endif\n\t\t\tret=BN_mod_exp_mont(r,a,p,m,ctx,NULL);\n\t\t}\n\telse\n#endif\n#ifdef RECP_MUL_MOD\n\t\t{ ret=BN_mod_exp_recp(r,a,p,m,ctx); }\n#else\n\t\t{ ret=BN_mod_exp_simple(r,a,p,m,ctx); }\n#endif\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_mod_exp_mont_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}', 'static void generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x,\n\t\t\t const BIGNUM *zkpg, JPAKE_CTX *ctx)\n {\n BIGNUM *r = BN_new();\n BIGNUM *h = BN_new();\n BIGNUM *t = BN_new();\n BN_rand_range(r, ctx->p.q);\n BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx);\n zkp_hash(h, zkpg, p, ctx->p.name);\n BN_mod_mul(t, x, h, ctx->p.q, ctx->ctx);\n BN_mod_sub(p->zkpx.b, r, t, ctx->p.q, ctx->ctx);\n BN_free(t);\n BN_free(h);\n BN_free(r);\n }', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n\t\t const BIGNUM *m, BN_CTX *ctx)\n\t{\n\tint i,j,bits,ret=0,wstart,wend,window,wvalue;\n\tint start=1;\n\tBIGNUM *aa;\n\tBIGNUM *val[TABLE_SIZE];\n\tBN_RECP_CTX recp;\n\tif (BN_get_flags(p, BN_FLG_CONSTTIME) != 0)\n\t\t{\n\t\tBNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn -1;\n\t\t}\n\tbits=BN_num_bits(p);\n\tif (bits == 0)\n\t\t{\n\t\tret = BN_one(r);\n\t\treturn ret;\n\t\t}\n\tBN_CTX_start(ctx);\n\taa = BN_CTX_get(ctx);\n\tval[0] = BN_CTX_get(ctx);\n\tif(!aa || !val[0]) goto err;\n\tBN_RECP_CTX_init(&recp);\n\tif (m->neg)\n\t\t{\n\t\tif (!BN_copy(aa, m)) goto err;\n\t\taa->neg = 0;\n\t\tif (BN_RECP_CTX_set(&recp,aa,ctx) <= 0) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;\n\t\t}\n\tif (!BN_nnmod(val[0],a,m,ctx)) goto err;\n\tif (BN_is_zero(val[0]))\n\t\t{\n\t\tBN_zero(r);\n\t\tret = 1;\n\t\tgoto err;\n\t\t}\n\twindow = BN_window_bits_for_exponent_size(bits);\n\tif (window > 1)\n\t\t{\n\t\tif (!BN_mod_mul_reciprocal(aa,val[0],val[0],&recp,ctx))\n\t\t\tgoto 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_reciprocal(val[i],val[i-1],\n\t\t\t\t\t\taa,&recp,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_one(r)) goto err;\n\tfor (;;)\n\t\t{\n\t\tif (BN_is_bit_set(p,wstart) == 0)\n\t\t\t{\n\t\t\tif (!start)\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\tgoto err;\n\t\t\tif (wstart == 0) break;\n\t\t\twstart--;\n\t\t\tcontinue;\n\t\t\t}\n\t\tj=wstart;\n\t\twvalue=1;\n\t\twend=0;\n\t\tfor (i=1; i<window; i++)\n\t\t\t{\n\t\t\tif (wstart-i < 0) break;\n\t\t\tif (BN_is_bit_set(p,wstart-i))\n\t\t\t\t{\n\t\t\t\twvalue<<=(i-wend);\n\t\t\t\twvalue|=1;\n\t\t\t\twend=i;\n\t\t\t\t}\n\t\t\t}\n\t\tj=wend+1;\n\t\tif (!start)\n\t\t\tfor (i=0; i<j; i++)\n\t\t\t\t{\n\t\t\t\tif (!BN_mod_mul_reciprocal(r,r,r,&recp,ctx))\n\t\t\t\t\tgoto err;\n\t\t\t\t}\n\t\tif (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],&recp,ctx))\n\t\t\tgoto err;\n\t\twstart-=wend+1;\n\t\twvalue=0;\n\t\tstart=0;\n\t\tif (wstart < 0) break;\n\t\t}\n\tret=1;\nerr:\n\tBN_CTX_end(ctx);\n\tBN_RECP_CTX_free(&recp);\n\tbn_check_top(r);\n\treturn(ret);\n\t}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n\t{\n\tif (!BN_copy(&(recp->N),d)) return 0;\n\tBN_zero(&(recp->Nr));\n\trecp->num_bits=BN_num_bits(d);\n\trecp->shift=0;\n\treturn(1);\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}']
|
993
| 0
|
https://github.com/libav/libav/blob/6cecd63005b29a1dc3a5104e6ac85fd112705122/libavcodec/put_bits.h/#L176
|
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
#ifndef ALT_BITSTREAM_WRITER
{
unsigned int bit_buf;
int bit_left;
assert(n == 32 || value < (1U << n));
bit_buf = s->bit_buf;
bit_left = s->bit_left;
#ifdef BITSTREAM_WRITER_LE
bit_buf |= value << (32 - bit_left);
if (n >= bit_left) {
#if !HAVE_FAST_UNALIGNED
if (3 & (intptr_t) s->buf_ptr) {
AV_WL32(s->buf_ptr, bit_buf);
} else
#endif
*(uint32_t *)s->buf_ptr = le2me_32(bit_buf);
s->buf_ptr+=4;
bit_buf = (bit_left==32)?0:value >> bit_left;
bit_left+=32;
}
bit_left-=n;
#else
if (n < bit_left) {
bit_buf = (bit_buf<<n) | value;
bit_left-=n;
} else {
bit_buf<<=bit_left;
bit_buf |= value >> (n - bit_left);
#if !HAVE_FAST_UNALIGNED
if (3 & (intptr_t) s->buf_ptr) {
AV_WB32(s->buf_ptr, bit_buf);
} else
#endif
*(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
s->buf_ptr+=4;
bit_left+=32 - n;
bit_buf = value;
}
#endif
s->bit_buf = bit_buf;
s->bit_left = bit_left;
}
|
['static int mov_write_ac3_tag(ByteIOContext *pb, MOVTrack *track)\n{\n GetBitContext gbc;\n PutBitContext pbc;\n uint8_t buf[3];\n int fscod, bsid, bsmod, acmod, lfeon, frmsizecod;\n if (track->vosLen < 7)\n return -1;\n put_be32(pb, 11);\n put_tag(pb, "dac3");\n init_get_bits(&gbc, track->vosData+4, track->vosLen-4);\n fscod = get_bits(&gbc, 2);\n frmsizecod = get_bits(&gbc, 6);\n bsid = get_bits(&gbc, 5);\n bsmod = get_bits(&gbc, 3);\n acmod = get_bits(&gbc, 3);\n if (acmod == 2) {\n skip_bits(&gbc, 2);\n } else {\n if ((acmod & 1) && acmod != 1)\n skip_bits(&gbc, 2);\n if (acmod & 4)\n skip_bits(&gbc, 2);\n }\n lfeon = get_bits1(&gbc);\n init_put_bits(&pbc, buf, sizeof(buf));\n put_bits(&pbc, 2, fscod);\n put_bits(&pbc, 5, bsid);\n put_bits(&pbc, 3, bsmod);\n put_bits(&pbc, 3, acmod);\n put_bits(&pbc, 1, lfeon);\n put_bits(&pbc, 5, frmsizecod>>1);\n put_bits(&pbc, 5, 0);\n flush_put_bits(&pbc);\n put_buffer(pb, buf, sizeof(buf));\n return 11;\n}', 'static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)\n{\n if(buffer_size < 0) {\n buffer_size = 0;\n buffer = NULL;\n }\n s->size_in_bits= 8*buffer_size;\n s->buf = buffer;\n s->buf_end = s->buf + buffer_size;\n#ifdef ALT_BITSTREAM_WRITER\n s->index=0;\n ((uint32_t*)(s->buf))[0]=0;\n#else\n s->buf_ptr = s->buf;\n s->bit_left=32;\n s->bit_buf=0;\n#endif\n}', 'static inline void put_bits(PutBitContext *s, int n, unsigned int value)\n#ifndef ALT_BITSTREAM_WRITER\n{\n unsigned int bit_buf;\n int bit_left;\n assert(n == 32 || value < (1U << n));\n bit_buf = s->bit_buf;\n bit_left = s->bit_left;\n#ifdef BITSTREAM_WRITER_LE\n bit_buf |= value << (32 - bit_left);\n if (n >= bit_left) {\n#if !HAVE_FAST_UNALIGNED\n if (3 & (intptr_t) s->buf_ptr) {\n AV_WL32(s->buf_ptr, bit_buf);\n } else\n#endif\n *(uint32_t *)s->buf_ptr = le2me_32(bit_buf);\n s->buf_ptr+=4;\n bit_buf = (bit_left==32)?0:value >> bit_left;\n bit_left+=32;\n }\n bit_left-=n;\n#else\n if (n < bit_left) {\n bit_buf = (bit_buf<<n) | value;\n bit_left-=n;\n } else {\n bit_buf<<=bit_left;\n bit_buf |= value >> (n - bit_left);\n#if !HAVE_FAST_UNALIGNED\n if (3 & (intptr_t) s->buf_ptr) {\n AV_WB32(s->buf_ptr, bit_buf);\n } else\n#endif\n *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);\n s->buf_ptr+=4;\n bit_left+=32 - n;\n bit_buf = value;\n }\n#endif\n s->bit_buf = bit_buf;\n s->bit_left = bit_left;\n}']
|
994
| 0
|
https://github.com/openssl/openssl/blob/b984cd2b016bd37eabf41ef34a573208c5661685/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];
}
|
['static int RSA_eay_private_encrypt(int flen, const unsigned char *from,\n\t unsigned char *to, RSA *rsa, int padding)\n\t{\n\tconst RSA_METHOD *meth;\n\tBIGNUM f,ret;\n\tint i,j,k,num=0,r= -1;\n\tunsigned char *buf=NULL;\n\tBN_CTX *ctx=NULL;\n\tmeth = ENGINE_get_RSA(rsa->engine);\n\tBN_init(&f);\n\tBN_init(&ret);\n\tif ((ctx=BN_CTX_new()) == NULL) goto err;\n\tnum=BN_num_bytes(rsa->n);\n\tif ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tswitch (padding)\n\t\t{\n\tcase RSA_PKCS1_PADDING:\n\t\ti=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_NO_PADDING:\n\t\ti=RSA_padding_add_none(buf,num,from,flen);\n\t\tbreak;\n\tcase RSA_SSLV23_PADDING:\n\tdefault:\n\t\tRSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_UNKNOWN_PADDING_TYPE);\n\t\tgoto err;\n\t\t}\n\tif (i <= 0) goto err;\n\tif (BN_bin2bn(buf,num,&f) == NULL) goto err;\n\tif ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL))\n\t\tRSA_blinding_on(rsa,ctx);\n\tif (rsa->flags & RSA_FLAG_BLINDING)\n\t\tif (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err;\n\tif ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||\n\t\t((rsa->p != NULL) &&\n\t\t(rsa->q != NULL) &&\n\t\t(rsa->dmp1 != NULL) &&\n\t\t(rsa->dmq1 != NULL) &&\n\t\t(rsa->iqmp != NULL)) )\n\t\t{ if (!meth->rsa_mod_exp(&ret,&f,rsa)) goto err; }\n\telse\n\t\t{\n\t\tif (!meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err;\n\t\t}\n\tif (rsa->flags & RSA_FLAG_BLINDING)\n\t\tif (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err;\n\tj=BN_num_bytes(&ret);\n\ti=BN_bn2bin(&ret,&(to[num-j]));\n\tfor (k=0; k<(num-i); k++)\n\t\tto[k]=0;\n\tr=num;\nerr:\n\tif (ctx != NULL) BN_CTX_free(ctx);\n\tBN_clear_free(&ret);\n\tBN_clear_free(&f);\n\tif (buf != NULL)\n\t\t{\n\t\tmemset(buf,0,num);\n\t\tOPENSSL_free(buf);\n\t\t}\n\treturn(r);\n\t}', '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_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tint ret;\n\tbn_check_top(n);\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);\n\t\treturn(0);\n\t\t}\n\tif ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)\n\t\t{\n\t\tif (!BN_BLINDING_update(b,ctx))\n\t\t\treturn(0);\n\t\t}\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\tret=1;\nerr:\n\tBN_CTX_end(ctx);\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}', '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}', 'int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)\n\t{\n\tint ret=0;\n\tif ((b->A == NULL) || (b->Ai == NULL))\n\t\t{\n\t\tBNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);\n\t\tgoto err;\n\t\t}\n\tif (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;\n\tif (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;\n\tret=1;\nerr:\n\treturn(ret);\n\t}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n\t{\n\tint top,al,bl;\n\tBIGNUM *rr;\n\tint ret = 0;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\tint i;\n#endif\n#ifdef BN_RECURSION\n\tBIGNUM *t;\n\tint j,k;\n#endif\n\tBIGNUM *free_a = NULL, *free_b = NULL;\n#ifdef BN_COUNT\n\tfprintf(stderr,"BN_mul %d * %d\\n",a->top,b->top);\n#endif\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tbn_check_top(r);\n\tal=a->top;\n\tbl=b->top;\n\tif ((al == 0) || (bl == 0))\n\t\t{\n\t\tBN_zero(r);\n\t\treturn(1);\n\t\t}\n\ttop=al+bl;\n\tBN_CTX_start(ctx);\n\tif ((r == a) || (r == b))\n\t\t{\n\t\tif ((rr = BN_CTX_get(ctx)) == NULL) goto err;\n\t\t}\n\telse\n\t\trr = r;\n\trr->neg=a->neg^b->neg;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n\ti = al-bl;\n#endif\n#ifdef BN_MUL_COMBA\n\tif (i == 0)\n\t\t{\n# if 0\n\t\tif (al == 4)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,8) == NULL) goto err;\n\t\t\trr->top=8;\n\t\t\tbn_mul_comba4(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n# endif\n\t\tif (al == 8)\n\t\t\t{\n\t\t\tif (bn_wexpand(rr,16) == NULL) goto err;\n\t\t\trr->top=16;\n\t\t\tbn_mul_comba8(rr->d,a->d,b->d);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifdef BN_RECURSION\n\tif ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))\n\t\t{\n\t\tif (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)b;\n\t\t\tbn_wexpand(tmp_bn,al);\n\t\t\ttmp_bn->d[bl]=0;\n\t\t\tbl++;\n\t\t\ti--;\n\t\t\t}\n\t\telse if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA))\n\t\t\t{\n\t\t\tBIGNUM *tmp_bn = (BIGNUM *)a;\n\t\t\tbn_wexpand(tmp_bn,bl);\n\t\t\ttmp_bn->d[al]=0;\n\t\t\tal++;\n\t\t\ti++;\n\t\t\t}\n\t\tif (i == 0)\n\t\t\t{\n\t\t\tj=BN_num_bits_word((BN_ULONG)al);\n\t\t\tj=1<<(j-1);\n\t\t\tk=j+j;\n\t\t\tt = BN_CTX_get(ctx);\n\t\t\tif (al == j)\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*2);\n\t\t\t\tbn_wexpand(rr,k*2);\n\t\t\t\tbn_mul_recursive(rr->d,a->d,b->d,al,t->d);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tbn_wexpand(t,k*4);\n\t\t\t\tbn_wexpand(rr,k*4);\n\t\t\t\tbn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);\n\t\t\t\t}\n\t\t\trr->top=top;\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n\tif (bn_wexpand(rr,top) == NULL) goto err;\n\trr->top=top;\n\tbn_mul_normal(rr->d,a->d,al,b->d,bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\nend:\n#endif\n\tbn_fix_top(rr);\n\tif (r != rr) BN_copy(r,rr);\n\tret=1;\nerr:\n\tif (free_a) BN_free(free_a);\n\tif (free_b) BN_free(free_b);\n\tBN_CTX_end(ctx);\n\treturn(ret);\n\t}']
|
995
| 0
|
https://github.com/libav/libav/blob/ab3554e1a7c04a5ea30f9c905de92348478ef7c8/libavformat/oggparsespeex.c/#L82
|
static int speex_header(AVFormatContext *s, int idx) {
struct ogg *ogg = s->priv_data;
struct ogg_stream *os = ogg->streams + idx;
struct speex_params *spxp = os->private;
AVStream *st = s->streams[idx];
uint8_t *p = os->buf + os->pstart;
if (!spxp) {
spxp = av_mallocz(sizeof(*spxp));
if (!spxp)
return AVERROR(ENOMEM);
os->private = spxp;
}
if (spxp->seq > 1)
return 0;
if (spxp->seq == 0) {
int frames_per_packet;
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
st->codecpar->codec_id = AV_CODEC_ID_SPEEX;
st->codecpar->sample_rate = AV_RL32(p + 36);
st->codecpar->channels = AV_RL32(p + 48);
if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {
av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\n");
return AVERROR_INVALIDDATA;
}
st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :
AV_CH_LAYOUT_STEREO;
spxp->packet_size = AV_RL32(p + 56);
frames_per_packet = AV_RL32(p + 64);
if (frames_per_packet)
spxp->packet_size *= frames_per_packet;
st->codecpar->extradata_size = os->psize;
st->codecpar->extradata = av_malloc(st->codecpar->extradata_size
+ AV_INPUT_BUFFER_PADDING_SIZE);
memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size);
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
} else
ff_vorbis_stream_comment(s, st, p, os->psize);
spxp->seq++;
return 1;
}
|
['static int speex_header(AVFormatContext *s, int idx) {\n struct ogg *ogg = s->priv_data;\n struct ogg_stream *os = ogg->streams + idx;\n struct speex_params *spxp = os->private;\n AVStream *st = s->streams[idx];\n uint8_t *p = os->buf + os->pstart;\n if (!spxp) {\n spxp = av_mallocz(sizeof(*spxp));\n if (!spxp)\n return AVERROR(ENOMEM);\n os->private = spxp;\n }\n if (spxp->seq > 1)\n return 0;\n if (spxp->seq == 0) {\n int frames_per_packet;\n st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;\n st->codecpar->codec_id = AV_CODEC_ID_SPEEX;\n st->codecpar->sample_rate = AV_RL32(p + 36);\n st->codecpar->channels = AV_RL32(p + 48);\n if (st->codecpar->channels < 1 || st->codecpar->channels > 2) {\n av_log(s, AV_LOG_ERROR, "invalid channel count. Speex must be mono or stereo.\\n");\n return AVERROR_INVALIDDATA;\n }\n st->codecpar->channel_layout = st->codecpar->channels == 1 ? AV_CH_LAYOUT_MONO :\n AV_CH_LAYOUT_STEREO;\n spxp->packet_size = AV_RL32(p + 56);\n frames_per_packet = AV_RL32(p + 64);\n if (frames_per_packet)\n spxp->packet_size *= frames_per_packet;\n st->codecpar->extradata_size = os->psize;\n st->codecpar->extradata = av_malloc(st->codecpar->extradata_size\n + AV_INPUT_BUFFER_PADDING_SIZE);\n memcpy(st->codecpar->extradata, p, st->codecpar->extradata_size);\n avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);\n } else\n ff_vorbis_stream_comment(s, st, p, os->psize);\n spxp->seq++;\n return 1;\n}', 'void *av_malloc(size_t size)\n{\n void *ptr = NULL;\n if (size > (INT_MAX - 32) || !size)\n return NULL;\n#if 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}']
|
996
| 0
|
https://github.com/openssl/openssl/blob/f006217bb628d05a2d5b866ff252bd94e3477e1f/crypto/dh/dh_lib.c/#L104
|
DH *DH_new(void)
{
return DH_new_method(NULL);
}
|
['DH *DH_new(void)\n{\n return DH_new_method(NULL);\n}']
|
997
| 0
|
https://github.com/libav/libav/blob/556f8a066cb33241bf29e85d7e24c9acf7ea9043/libavcodec/h264.h/#L979
|
static void fill_decode_caches(H264Context *h, int mb_type){
MpegEncContext * const s = &h->s;
int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
const uint8_t * left_block= h->left_block;
int i;
uint8_t *nnz;
uint8_t *nnz_cache;
topleft_xy = h->topleft_mb_xy;
top_xy = h->top_mb_xy;
topright_xy = h->topright_mb_xy;
left_xy[LTOP] = h->left_mb_xy[LTOP];
left_xy[LBOT] = h->left_mb_xy[LBOT];
topleft_type = h->topleft_type;
top_type = h->top_type;
topright_type = h->topright_type;
left_type[LTOP]= h->left_type[LTOP];
left_type[LBOT]= h->left_type[LBOT];
if(!IS_SKIP(mb_type)){
if(IS_INTRA(mb_type)){
int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;
h->topleft_samples_available=
h->top_samples_available=
h->left_samples_available= 0xFFFF;
h->topright_samples_available= 0xEEEA;
if(!(top_type & type_mask)){
h->topleft_samples_available= 0xB3FF;
h->top_samples_available= 0x33FF;
h->topright_samples_available= 0x26EA;
}
if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){
if(IS_INTERLACED(mb_type)){
if(!(left_type[LTOP] & type_mask)){
h->topleft_samples_available&= 0xDFFF;
h->left_samples_available&= 0x5FFF;
}
if(!(left_type[LBOT] & type_mask)){
h->topleft_samples_available&= 0xFF5F;
h->left_samples_available&= 0xFF5F;
}
}else{
int left_typei = s->current_picture.mb_type[left_xy[LTOP] + s->mb_stride];
assert(left_xy[LTOP] == left_xy[LBOT]);
if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
}else{
if(!(left_type[LTOP] & type_mask)){
h->topleft_samples_available&= 0xDF5F;
h->left_samples_available&= 0x5F5F;
}
}
if(!(topleft_type & type_mask))
h->topleft_samples_available&= 0x7FFF;
if(!(topright_type & type_mask))
h->topright_samples_available&= 0xFBFF;
if(IS_INTRA4x4(mb_type)){
if(IS_INTRA4x4(top_type)){
AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
}else{
h->intra4x4_pred_mode_cache[4+8*0]=
h->intra4x4_pred_mode_cache[5+8*0]=
h->intra4x4_pred_mode_cache[6+8*0]=
h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);
}
for(i=0; i<2; i++){
if(IS_INTRA4x4(left_type[LEFT(i)])){
int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];
}else{
h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);
}
}
}
}
nnz_cache = h->non_zero_count_cache;
if(top_type){
nnz = h->non_zero_count[top_xy];
AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);
if(CHROMA444){
AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);
AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);
}else{
AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);
AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);
}
}else{
uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;
AV_WN32A(&nnz_cache[4+8* 0], top_empty);
AV_WN32A(&nnz_cache[4+8* 5], top_empty);
AV_WN32A(&nnz_cache[4+8*10], top_empty);
}
for (i=0; i<2; i++) {
if(left_type[LEFT(i)]){
nnz = h->non_zero_count[left_xy[LEFT(i)]];
nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];
nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];
if(CHROMA444){
nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];
nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];
nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];
nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];
}else{
nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];
nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];
}
}else{
nnz_cache[3+8* 1 + 2*8*i]=
nnz_cache[3+8* 2 + 2*8*i]=
nnz_cache[3+8* 6 + 2*8*i]=
nnz_cache[3+8* 7 + 2*8*i]=
nnz_cache[3+8*11 + 2*8*i]=
nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;
}
}
if( CABAC ) {
if(top_type) {
h->top_cbp = h->cbp_table[top_xy];
} else {
h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
if (left_type[LTOP]) {
h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)
| ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)
| (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);
} else {
h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
}
}
}
if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
int list;
int b_stride = h->b_stride;
for(list=0; list<h->list_count; list++){
int8_t *ref_cache = &h->ref_cache[list][scan8[0]];
int8_t *ref = s->current_picture.ref_index[list];
int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];
int16_t (*mv)[2] = s->current_picture.motion_val[list];
if(!USES_LIST(mb_type, list)){
continue;
}
assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;
AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);
ref_cache[0 - 1*8]=
ref_cache[1 - 1*8]= ref[4*top_xy + 2];
ref_cache[2 - 1*8]=
ref_cache[3 - 1*8]= ref[4*top_xy + 3];
}else{
AV_ZERO128(mv_cache[0 - 1*8]);
AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);
}
if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){
for(i=0; i<2; i++){
int cache_idx = -1 + i*2*8;
if(USES_LIST(left_type[LEFT(i)], list)){
const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;
const int b8_xy= 4*left_xy[LEFT(i)] + 1;
AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);
AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);
ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];
ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];
}else{
AV_ZERO32(mv_cache[cache_idx ]);
AV_ZERO32(mv_cache[cache_idx+8]);
ref_cache[cache_idx ]=
ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
}else{
if(USES_LIST(left_type[LTOP], list)){
const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;
const int b8_xy= 4*left_xy[LTOP] + 1;
AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);
ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];
}else{
AV_ZERO32(mv_cache[-1]);
ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if(USES_LIST(topright_type, list)){
const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;
AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);
ref_cache[4 - 1*8]= ref[4*topright_xy + 2];
}else{
AV_ZERO32(mv_cache[4 - 1*8]);
ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
if(ref_cache[4 - 1*8] < 0){
if(USES_LIST(topleft_type, list)){
const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);
const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);
AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);
ref_cache[-1 - 1*8]= ref[b8_xy];
}else{
AV_ZERO32(mv_cache[-1 - 1*8]);
ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;
}
}
if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)
continue;
if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){
uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];
uint8_t (*mvd)[2] = h->mvd_table[list];
ref_cache[2+8*0] =
ref_cache[2+8*2] = PART_NOT_AVAILABLE;
AV_ZERO32(mv_cache[2+8*0]);
AV_ZERO32(mv_cache[2+8*2]);
if( CABAC ) {
if(USES_LIST(top_type, list)){
const int b_xy= h->mb2br_xy[top_xy];
AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);
}else{
AV_ZERO64(mvd_cache[0 - 1*8]);
}
if(USES_LIST(left_type[LTOP], list)){
const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;
AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);
AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);
}else{
AV_ZERO16(mvd_cache[-1 + 0*8]);
AV_ZERO16(mvd_cache[-1 + 1*8]);
}
if(USES_LIST(left_type[LBOT], list)){
const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;
AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);
AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);
}else{
AV_ZERO16(mvd_cache[-1 + 2*8]);
AV_ZERO16(mvd_cache[-1 + 3*8]);
}
AV_ZERO16(mvd_cache[2+8*0]);
AV_ZERO16(mvd_cache[2+8*2]);
if(h->slice_type_nos == AV_PICTURE_TYPE_B){
uint8_t *direct_cache = &h->direct_cache[scan8[0]];
uint8_t *direct_table = h->direct_table;
fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);
if(IS_DIRECT(top_type)){
AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));
}else if(IS_8X8(top_type)){
int b8_xy = 4*top_xy;
direct_cache[0 - 1*8]= direct_table[b8_xy + 2];
direct_cache[2 - 1*8]= direct_table[b8_xy + 3];
}else{
AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));
}
if(IS_DIRECT(left_type[LTOP]))
direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[LTOP]))
direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];
else
direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;
if(IS_DIRECT(left_type[LBOT]))
direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;
else if(IS_8X8(left_type[LBOT]))
direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];
else
direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;
}
}
}
if(FRAME_MBAFF){
#define MAP_MVS\
MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\
MAP_F2F(scan8[0] + 0 - 1*8, top_type)\
MAP_F2F(scan8[0] + 1 - 1*8, top_type)\
MAP_F2F(scan8[0] + 2 - 1*8, top_type)\
MAP_F2F(scan8[0] + 3 - 1*8, top_type)\
MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\
MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\
MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\
MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\
MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])
if(MB_FIELD){
#define MAP_F2F(idx, mb_type)\
if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] <<= 1;\
h->mv_cache[list][idx][1] /= 2;\
h->mvd_cache[list][idx][1] >>=1;\
}
MAP_MVS
#undef MAP_F2F
}else{
#define MAP_F2F(idx, mb_type)\
if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\
h->ref_cache[list][idx] >>= 1;\
h->mv_cache[list][idx][1] <<= 1;\
h->mvd_cache[list][idx][1] <<= 1;\
}
MAP_MVS
#undef MAP_F2F
}
}
}
}
h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
}
|
['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 int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2;\n const int pixel_shift = h->pixel_shift;\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 != AV_PICTURE_TYPE_I ) {\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 == AV_PICTURE_TYPE_B ) {\n int ctx = 0;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_B);\n if( !IS_DIRECT( h->left_type[LTOP]-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 == AV_PICTURE_TYPE_P ) {\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 == AV_PICTURE_TYPE_SI && mb_type)\n mb_type--;\n assert(h->slice_type_nos == AV_PICTURE_TYPE_I);\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 static const uint16_t mb_sizes[4] = {256,384,512,768};\n const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3;\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, mb_size); ptr+=mb_size;\n ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);\n h->cbp_table[mb_xy] = 0xf7ef;\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, 48);\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 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(decode_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 } else {\n h->chroma_pred_mode= DC_128_PRED8x8;\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 == AV_PICTURE_TYPE_B ) {\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, 2);\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 uint8_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];\n pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, index)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, 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 fill_rectangle(h->mv_cache [list][ scan8[4*i] ], 2, 2, 8, 0, 4);\n fill_rectangle(h->mvd_cache[list][ scan8[4*i] ], 2, 2, 8, 0, 2);\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, 2);\n fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 2);\n dct8x8_allowed &= h->sps.direct_8x8_inference_flag;\n } else {\n int list, i;\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 }\n }\n for(list=0; list<h->list_count; list++){\n if(IS_DIR(mb_type, 0, list)){\n int mx,my,mpx,mpy;\n pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 0)\n tprintf(s->avctx, "final mv:%d %d\\n", mx, my);\n fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack8to16(mpx,mpy), 2);\n fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);\n }\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 int mx,my,mpx,mpy;\n pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 8*i)\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, pack8to16(mpx,mpy), 2);\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, 2);\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 int mx,my,mpx,mpy;\n pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);\n DECODE_CABAC_MB_MVD( h, list, 4*i)\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, pack8to16(mpx,mpy), 2);\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, 2);\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(decode_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 if (CHROMA444 && IS_8x8DCT(mb_type)){\n int i;\n uint8_t *nnz_cache = h->non_zero_count_cache;\n for (i = 0; i < 2; i++){\n if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0;\n }\n }\n if (h->top_type && !IS_8x8DCT(h->top_type)){\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n }\n s->current_picture.mb_type[mb_xy]= mb_type;\n if( cbp || IS_INTRA16x16( mb_type ) ) {\n const uint8_t *scan, *scan8x8;\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 }else{\n scan8x8= s->qscale ? h->zigzag_scan8x8 : h->zigzag_scan8x8_q0;\n scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0;\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 const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);\n while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {\n ctx= 3;\n val++;\n if(val > 2*max_qp){\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) > max_qp){\n if(s->qscale<0) s->qscale+= max_qp+1;\n else s->qscale-= max_qp+1;\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 decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0);\n if(CHROMA444){\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1);\n decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2);\n } else {\n if( cbp&0x30 ){\n int c;\n for( c = 0; c < 2; c++ ) {\n decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 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 + 16 * c + i;\n decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\n }\n }\n } else {\n fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1);\n fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1);\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[LEFT_MBS];\n static const uint8_t left_block_options[4][32]={\n {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4},\n {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4},\n {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4},\n {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}\n };\n h->topleft_partition= -1;\n top_xy = mb_xy - (s->mb_stride << MB_FIELD);\n topleft_xy = top_xy - 1;\n topright_xy= top_xy + 1;\n left_xy[LBOT] = left_xy[LTOP] = mb_xy-1;\n h->left_block = left_block_options[0];\n if(FRAME_MBAFF){\n const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);\n const int curr_mb_field_flag = IS_INTERLACED(mb_type);\n if(s->mb_y&1){\n if (left_mb_field_flag != curr_mb_field_flag) {\n left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1;\n if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n topleft_xy += s->mb_stride;\n h->topleft_partition = 0;\n h->left_block = left_block_options[1];\n }\n }\n }else{\n if(curr_mb_field_flag){\n topleft_xy += s->mb_stride & (((s->current_picture.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 if (curr_mb_field_flag) {\n left_xy[LBOT] += s->mb_stride;\n h->left_block = left_block_options[3];\n } else {\n h->left_block = left_block_options[2];\n }\n }\n }\n }\n h->topleft_mb_xy = topleft_xy;\n h->top_mb_xy = top_xy;\n h->topright_mb_xy= topright_xy;\n h->left_mb_xy[LTOP] = left_xy[LTOP];\n h->left_mb_xy[LBOT] = left_xy[LBOT];\n h->topleft_type = s->current_picture.mb_type[topleft_xy] ;\n h->top_type = s->current_picture.mb_type[top_xy] ;\n h->topright_type= s->current_picture.mb_type[topright_xy];\n h->left_type[LTOP] = s->current_picture.mb_type[left_xy[LTOP]] ;\n h->left_type[LBOT] = s->current_picture.mb_type[left_xy[LBOT]] ;\n if(FMO){\n if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }else{\n if(h->slice_table[topleft_xy ] != h->slice_num){\n h->topleft_type = 0;\n if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0;\n if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0;\n }\n }\n if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0;\n}', 'static void fill_decode_caches(H264Context *h, int mb_type){\n MpegEncContext * const s = &h->s;\n int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];\n int topleft_type, top_type, topright_type, left_type[LEFT_MBS];\n const uint8_t * left_block= h->left_block;\n int i;\n uint8_t *nnz;\n uint8_t *nnz_cache;\n topleft_xy = h->topleft_mb_xy;\n top_xy = h->top_mb_xy;\n topright_xy = h->topright_mb_xy;\n left_xy[LTOP] = h->left_mb_xy[LTOP];\n left_xy[LBOT] = h->left_mb_xy[LBOT];\n topleft_type = h->topleft_type;\n top_type = h->top_type;\n topright_type = h->topright_type;\n left_type[LTOP]= h->left_type[LTOP];\n left_type[LBOT]= h->left_type[LBOT];\n if(!IS_SKIP(mb_type)){\n if(IS_INTRA(mb_type)){\n int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1;\n h->topleft_samples_available=\n h->top_samples_available=\n h->left_samples_available= 0xFFFF;\n h->topright_samples_available= 0xEEEA;\n if(!(top_type & type_mask)){\n h->topleft_samples_available= 0xB3FF;\n h->top_samples_available= 0x33FF;\n h->topright_samples_available= 0x26EA;\n }\n if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){\n if(IS_INTERLACED(mb_type)){\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDFFF;\n h->left_samples_available&= 0x5FFF;\n }\n if(!(left_type[LBOT] & type_mask)){\n h->topleft_samples_available&= 0xFF5F;\n h->left_samples_available&= 0xFF5F;\n }\n }else{\n int left_typei = s->current_picture.mb_type[left_xy[LTOP] + s->mb_stride];\n assert(left_xy[LTOP] == left_xy[LBOT]);\n if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n }else{\n if(!(left_type[LTOP] & type_mask)){\n h->topleft_samples_available&= 0xDF5F;\n h->left_samples_available&= 0x5F5F;\n }\n }\n if(!(topleft_type & type_mask))\n h->topleft_samples_available&= 0x7FFF;\n if(!(topright_type & type_mask))\n h->topright_samples_available&= 0xFBFF;\n if(IS_INTRA4x4(mb_type)){\n if(IS_INTRA4x4(top_type)){\n AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]);\n }else{\n h->intra4x4_pred_mode_cache[4+8*0]=\n h->intra4x4_pred_mode_cache[5+8*0]=\n h->intra4x4_pred_mode_cache[6+8*0]=\n h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask);\n }\n for(i=0; i<2; i++){\n if(IS_INTRA4x4(left_type[LEFT(i)])){\n int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]];\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]];\n }else{\n h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=\n h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask);\n }\n }\n }\n }\n nnz_cache = h->non_zero_count_cache;\n if(top_type){\n nnz = h->non_zero_count[top_xy];\n AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]);\n if(CHROMA444){\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]);\n }else{\n AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]);\n AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]);\n }\n }else{\n uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040;\n AV_WN32A(&nnz_cache[4+8* 0], top_empty);\n AV_WN32A(&nnz_cache[4+8* 5], top_empty);\n AV_WN32A(&nnz_cache[4+8*10], top_empty);\n }\n for (i=0; i<2; i++) {\n if(left_type[LEFT(i)]){\n nnz = h->non_zero_count[left_xy[LEFT(i)]];\n nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]];\n nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]];\n if(CHROMA444){\n nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4];\n nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4];\n nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4];\n nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4];\n }else{\n nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]];\n nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]];\n }\n }else{\n nnz_cache[3+8* 1 + 2*8*i]=\n nnz_cache[3+8* 2 + 2*8*i]=\n nnz_cache[3+8* 6 + 2*8*i]=\n nnz_cache[3+8* 7 + 2*8*i]=\n nnz_cache[3+8*11 + 2*8*i]=\n nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64;\n }\n }\n if( CABAC ) {\n if(top_type) {\n h->top_cbp = h->cbp_table[top_xy];\n } else {\n h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n if (left_type[LTOP]) {\n h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0)\n | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2)\n | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2);\n } else {\n h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;\n }\n }\n }\n if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){\n int list;\n int b_stride = h->b_stride;\n for(list=0; list<h->list_count; list++){\n int8_t *ref_cache = &h->ref_cache[list][scan8[0]];\n int8_t *ref = s->current_picture.ref_index[list];\n int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]];\n int16_t (*mv)[2] = s->current_picture.motion_val[list];\n if(!USES_LIST(mb_type, list)){\n continue;\n }\n assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred));\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride;\n AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]);\n ref_cache[0 - 1*8]=\n ref_cache[1 - 1*8]= ref[4*top_xy + 2];\n ref_cache[2 - 1*8]=\n ref_cache[3 - 1*8]= ref[4*top_xy + 3];\n }else{\n AV_ZERO128(mv_cache[0 - 1*8]);\n AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101);\n }\n if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){\n for(i=0; i<2; i++){\n int cache_idx = -1 + i*2*8;\n if(USES_LIST(left_type[LEFT(i)], list)){\n const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3;\n const int b8_xy= 4*left_xy[LEFT(i)] + 1;\n AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]);\n AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]);\n ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)];\n ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)];\n }else{\n AV_ZERO32(mv_cache[cache_idx ]);\n AV_ZERO32(mv_cache[cache_idx+8]);\n ref_cache[cache_idx ]=\n ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n }else{\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3;\n const int b8_xy= 4*left_xy[LTOP] + 1;\n AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]);\n ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)];\n }else{\n AV_ZERO32(mv_cache[-1]);\n ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if(USES_LIST(topright_type, list)){\n const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride;\n AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]);\n ref_cache[4 - 1*8]= ref[4*topright_xy + 2];\n }else{\n AV_ZERO32(mv_cache[4 - 1*8]);\n ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n if(ref_cache[4 - 1*8] < 0){\n if(USES_LIST(topleft_type, list)){\n const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride);\n const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2);\n AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]);\n ref_cache[-1 - 1*8]= ref[b8_xy];\n }else{\n AV_ZERO32(mv_cache[-1 - 1*8]);\n ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE;\n }\n }\n if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF)\n continue;\n if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){\n uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]];\n uint8_t (*mvd)[2] = h->mvd_table[list];\n ref_cache[2+8*0] =\n ref_cache[2+8*2] = PART_NOT_AVAILABLE;\n AV_ZERO32(mv_cache[2+8*0]);\n AV_ZERO32(mv_cache[2+8*2]);\n if( CABAC ) {\n if(USES_LIST(top_type, list)){\n const int b_xy= h->mb2br_xy[top_xy];\n AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]);\n }else{\n AV_ZERO64(mvd_cache[0 - 1*8]);\n }\n if(USES_LIST(left_type[LTOP], list)){\n const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6;\n AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]);\n AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 0*8]);\n AV_ZERO16(mvd_cache[-1 + 1*8]);\n }\n if(USES_LIST(left_type[LBOT], list)){\n const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6;\n AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]);\n AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]);\n }else{\n AV_ZERO16(mvd_cache[-1 + 2*8]);\n AV_ZERO16(mvd_cache[-1 + 3*8]);\n }\n AV_ZERO16(mvd_cache[2+8*0]);\n AV_ZERO16(mvd_cache[2+8*2]);\n if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n uint8_t *direct_cache = &h->direct_cache[scan8[0]];\n uint8_t *direct_table = h->direct_table;\n fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1);\n if(IS_DIRECT(top_type)){\n AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1));\n }else if(IS_8X8(top_type)){\n int b8_xy = 4*top_xy;\n direct_cache[0 - 1*8]= direct_table[b8_xy + 2];\n direct_cache[2 - 1*8]= direct_table[b8_xy + 3];\n }else{\n AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1));\n }\n if(IS_DIRECT(left_type[LTOP]))\n direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LTOP]))\n direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)];\n else\n direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1;\n if(IS_DIRECT(left_type[LBOT]))\n direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1;\n else if(IS_8X8(left_type[LBOT]))\n direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)];\n else\n direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1;\n }\n }\n }\n if(FRAME_MBAFF){\n#define MAP_MVS\\\n MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\\\n MAP_F2F(scan8[0] + 0 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 1 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 2 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 3 - 1*8, top_type)\\\n MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\\\n MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\\\n MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\\\n MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT])\n if(MB_FIELD){\n#define MAP_F2F(idx, mb_type)\\\n if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] <<= 1;\\\n h->mv_cache[list][idx][1] /= 2;\\\n h->mvd_cache[list][idx][1] >>=1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }else{\n#define MAP_F2F(idx, mb_type)\\\n if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\\\n h->ref_cache[list][idx] >>= 1;\\\n h->mv_cache[list][idx][1] <<= 1;\\\n h->mvd_cache[list][idx][1] <<= 1;\\\n }\n MAP_MVS\n#undef MAP_F2F\n }\n }\n }\n }\n h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);\n}']
|
998
| 0
|
https://github.com/openssl/openssl/blob/a68d8c7b77a3d46d591b89cfd0ecd2a2242e4613/crypto/async/async.c/#L352
|
int ASYNC_init_thread(size_t max_size, size_t init_size)
{
async_pool *pool;
size_t curr_size = 0;
if (init_size > max_size) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_INVALID_POOL_SIZE);
return 0;
}
if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL)) {
return 0;
}
if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC)) {
return 0;
}
pool = OPENSSL_zalloc(sizeof *pool);
if (pool == NULL) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);
return 0;
}
pool->jobs = sk_ASYNC_JOB_new_null();
if (pool->jobs == NULL) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);
OPENSSL_free(pool);
return 0;
}
pool->max_size = max_size;
while (init_size--) {
ASYNC_JOB *job;
job = async_job_new();
if (job == NULL || !async_fibre_makecontext(&job->fibrectx)) {
async_job_free(job);
break;
}
job->funcargs = NULL;
sk_ASYNC_JOB_push(pool->jobs, job);
curr_size++;
}
pool->curr_size = curr_size;
if (!CRYPTO_THREAD_set_local(&poolkey, pool)) {
ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_FAILED_TO_SET_POOL);
goto err;
}
return 1;
err:
async_free_pool_internal(pool);
return 0;
}
|
['int ASYNC_init_thread(size_t max_size, size_t init_size)\n{\n async_pool *pool;\n size_t curr_size = 0;\n if (init_size > max_size) {\n ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_INVALID_POOL_SIZE);\n return 0;\n }\n if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL)) {\n return 0;\n }\n if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC)) {\n return 0;\n }\n pool = OPENSSL_zalloc(sizeof *pool);\n if (pool == NULL) {\n ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);\n return 0;\n }\n pool->jobs = sk_ASYNC_JOB_new_null();\n if (pool->jobs == NULL) {\n ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE);\n OPENSSL_free(pool);\n return 0;\n }\n pool->max_size = max_size;\n while (init_size--) {\n ASYNC_JOB *job;\n job = async_job_new();\n if (job == NULL || !async_fibre_makecontext(&job->fibrectx)) {\n async_job_free(job);\n break;\n }\n job->funcargs = NULL;\n sk_ASYNC_JOB_push(pool->jobs, job);\n curr_size++;\n }\n pool->curr_size = curr_size;\n if (!CRYPTO_THREAD_set_local(&poolkey, pool)) {\n ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_FAILED_TO_SET_POOL);\n goto err;\n }\n return 1;\nerr:\n async_free_pool_internal(pool);\n return 0;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n void *ret = CRYPTO_malloc(num, file, line);\n FAILTEST();\n if (ret != NULL)\n memset(ret, 0, num);\n return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n void *ret = NULL;\n if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n return malloc_impl(num, file, line);\n if (num <= 0)\n return NULL;\n FAILTEST();\n allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n if (call_malloc_debug) {\n CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n ret = malloc(num);\n CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n } else {\n ret = malloc(num);\n }\n#else\n osslargused(file); osslargused(line);\n ret = malloc(num);\n#endif\n return ret;\n}', 'DEFINE_STACK_OF(ASYNC_JOB)', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);\n}', 'int async_fibre_makecontext(async_fibre *fibre)\n{\n fibre->env_init = 0;\n if (getcontext(&fibre->fibre) == 0) {\n fibre->fibre.uc_stack.ss_sp = OPENSSL_malloc(STACKSIZE);\n if (fibre->fibre.uc_stack.ss_sp != NULL) {\n fibre->fibre.uc_stack.ss_size = STACKSIZE;\n fibre->fibre.uc_link = NULL;\n makecontext(&fibre->fibre, async_start_func, 0);\n return 1;\n }\n } else {\n fibre->fibre.uc_stack.ss_sp = NULL;\n }\n return 0;\n}', 'int OPENSSL_sk_push(OPENSSL_STACK *st, const void *data)\n{\n return (OPENSSL_sk_insert(st, data, st->num));\n}']
|
999
| 0
|
https://github.com/libav/libav/blob/8a2c99b48688008dd0a01c4826161ad4f7c25436/ffmpeg.c/#L3696
|
static int opt_streamid(const char *opt, const char *arg)
{
int idx;
char *p;
char idx_str[16];
strncpy(idx_str, arg, sizeof(idx_str));
idx_str[sizeof(idx_str)-1] = '\0';
p = strchr(idx_str, ':');
if (!p) {
fprintf(stderr,
"Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
arg, opt);
ffmpeg_exit(1);
}
*p++ = '\0';
idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);
streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
return 0;
}
|
['static int opt_streamid(const char *opt, const char *arg)\n{\n int idx;\n char *p;\n char idx_str[16];\n strncpy(idx_str, arg, sizeof(idx_str));\n idx_str[sizeof(idx_str)-1] = \'\\0\';\n p = strchr(idx_str, \':\');\n if (!p) {\n fprintf(stderr,\n "Invalid value \'%s\' for option \'%s\', required syntax is \'index:value\'\\n",\n arg, opt);\n ffmpeg_exit(1);\n }\n *p++ = \'\\0\';\n idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);\n streamid_map = grow_array(streamid_map, sizeof(*streamid_map), &nb_streamid_map, idx+1);\n streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);\n return 0;\n}', 'static void *grow_array(void *array, int elem_size, int *size, int new_size)\n{\n if (new_size >= INT_MAX / elem_size) {\n fprintf(stderr, "Array too big.\\n");\n ffmpeg_exit(1);\n }\n if (*size < new_size) {\n uint8_t *tmp = av_realloc(array, new_size*elem_size);\n if (!tmp) {\n fprintf(stderr, "Could not alloc buffer.\\n");\n ffmpeg_exit(1);\n }\n memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);\n *size = new_size;\n return tmp;\n }\n return array;\n}', 'void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size)\n{\n#if CONFIG_MEMALIGN_HACK\n int diff;\n#endif\n if(size > (INT_MAX-16) )\n return NULL;\n#if CONFIG_MEMALIGN_HACK\n if(!ptr) return av_malloc(size);\n diff= ((char*)ptr)[-1];\n return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n return realloc(ptr, size);\n#endif\n}']
|
1,000
| 0
|
https://github.com/libav/libav/blob/776f2bb91a5e31a385ee0a200df907e9acb0de87/avconv.c/#L1294
|
static void do_video_stats(AVFormatContext *os, OutputStream *ost,
int frame_size)
{
AVCodecContext *enc;
int frame_number;
double ti1, bitrate, avg_bitrate;
if (!vstats_file) {
vstats_file = fopen(vstats_filename, "w");
if (!vstats_file) {
perror("fopen");
exit_program(1);
}
}
enc = ost->st->codec;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
frame_number = ost->frame_number;
fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);
if (enc->flags&CODEC_FLAG_PSNR)
fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));
fprintf(vstats_file,"f_size= %6d ", frame_size);
ti1 = ost->sync_opts * av_q2d(enc->time_base);
if (ti1 < 0.01)
ti1 = 0.01;
bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
(double)video_size / 1024, ti1, bitrate, avg_bitrate);
fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type));
}
}
|
['static void do_video_stats(AVFormatContext *os, OutputStream *ost,\n int frame_size)\n{\n AVCodecContext *enc;\n int frame_number;\n double ti1, bitrate, avg_bitrate;\n if (!vstats_file) {\n vstats_file = fopen(vstats_filename, "w");\n if (!vstats_file) {\n perror("fopen");\n exit_program(1);\n }\n }\n enc = ost->st->codec;\n if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {\n frame_number = ost->frame_number;\n fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA);\n if (enc->flags&CODEC_FLAG_PSNR)\n fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0)));\n fprintf(vstats_file,"f_size= %6d ", frame_size);\n ti1 = ost->sync_opts * av_q2d(enc->time_base);\n if (ti1 < 0.01)\n ti1 = 0.01;\n bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;\n avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;\n fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",\n (double)video_size / 1024, ti1, bitrate, avg_bitrate);\n fprintf(vstats_file, "type= %c\\n", av_get_picture_type_char(enc->coded_frame->pict_type));\n }\n}']
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.