apps/pkcs12.c:380: error: BUFFER_OVERRUN_L3
  Offset added: [4, +oo] (⇐ [4, +oo] + [0, 8]) Size: [0, +oo] by call to `PKCS12_pack_p7encdata`.
Showing all 24 steps of the trace


apps/pkcs12.c:380:13: Call
378.   	if (!twopass) strcpy(macpass, pass);
379.   	/* Turn certbags into encrypted authsafe */
380.   	authsafe = PKCS12_pack_p7encdata (cert_pbe, cpass, -1, NULL, 0,
                   ^
381.   								 iter, bags);
382.   	sk_pop_free(bags, PKCS12_SAFEBAG_free);

crypto/pkcs12/p12_add.c:150:1: Parameter `saltlen`
  148.   /* Turn a stack of SAFEBAGS into a PKCS#7 encrypted data ContentInfo */
  149.   
  150. > PKCS7 *PKCS12_pack_p7encdata (int pbe_nid, const char *pass, int passlen,
  151.   	     unsigned char *salt, int saltlen, int iter, STACK *bags)
  152.   {

crypto/pkcs12/p12_add.c:166:14: Call
  164.   	ASN1_INTEGER_set (p7->d.encrypted->version, 0);
  165.   	p7->d.encrypted->enc_data->content_type = OBJ_nid2obj(NID_pkcs7_data);
  166.   	if (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) {
                      ^
  167.   		PKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);
  168.   		return NULL;

crypto/asn1/p5_pbe.c:112:1: Parameter `saltlen`
    110.   /* Return an algorithm identifier for a PKCS#5 PBE algorithm */
    111.   
    112. > X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
    113.   	     int saltlen)
    114.   {

crypto/asn1/p5_pbe.c:132:2: Assignment
    130.   		return NULL;
    131.   	}
    132.   	pbe->salt->length = saltlen;
            ^
    133.   	if (salt) memcpy (pbe->salt->data, salt, saltlen);
    134.   	else RAND_bytes (pbe->salt->data, saltlen);

crypto/asn1/p5_pbe.c:135:15: Call
    133.   	if (salt) memcpy (pbe->salt->data, salt, saltlen);
    134.   	else RAND_bytes (pbe->salt->data, saltlen);
    135.   	if (!(plen = i2d_PBEPARAM (pbe, NULL))) {
                         ^
    136.   		ASN1err(ASN1_F_ASN1_PBE_SET,ASN1_R_ENCODE_ERROR);
    137.   		return NULL;

crypto/asn1/p5_pbe.c:68:1: Parameter `a->iter->length`
      66.   #define PKCS5_SALT_LEN	8
      67.   
      68. > int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)
      69.   {
      70.   	M_ASN1_I2D_vars(a);

crypto/asn1/p5_pbe.c:144:2: Call
    142.   	}
    143.   	ptmp = pdata;
    144.   	i2d_PBEPARAM (pbe, &ptmp);
            ^
    145.   	PBEPARAM_free (pbe);
    146.   

crypto/asn1/p5_pbe.c:68:1: Parameter `a->salt->length`
      66.   #define PKCS5_SALT_LEN	8
      67.   
      68. > int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)
      69.   {
      70.   	M_ASN1_I2D_vars(a);

crypto/asn1/p5_pbe.c:76:2: Call
      74.   	M_ASN1_I2D_seq_total ();
      75.   
      76.   	M_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING);
             ^
      77.   	M_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);
      78.   	M_ASN1_I2D_finish();

crypto/asn1/a_octet.c:63:1: Parameter `**pp`
        61.   #include <openssl/asn1.h>
        62.   
        63. > int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
        64.   	{
        65.   	return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,

crypto/asn1/a_octet.c:65:9: Call
        63.   int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)
        64.   	{
        65.   	return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
                      ^
        66.   		V_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL));
        67.   	}

crypto/asn1/a_bytes.c:141:1: <Offset trace>
139.   	}
140.   
141. > int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
142.   	{
143.   	int ret,r,constructed;

crypto/asn1/a_bytes.c:141:1: Parameter `a->length`
          139.   	}
          140.   
          141. > int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
          142.   	{
          143.   	int ret,r,constructed;

crypto/asn1/a_bytes.c:141:1: <Length trace>
139.   	}
140.   
141. > int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
142.   	{
143.   	int ret,r,constructed;

crypto/asn1/a_bytes.c:141:1: Parameter `**pp`
          139.   	}
          140.   
          141. > int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
          142.   	{
          143.   	int ret,r,constructed;

crypto/asn1/a_bytes.c:154:2: Assignment
          152.   	r=ASN1_object_size(0,ret,tag);
          153.   	if (pp == NULL) return(r);
          154.   	p= *pp;
                  ^
          155.   
          156.   	if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))

crypto/asn1/a_bytes.c:160:2: Call
          158.   	else
          159.   		constructed=0;
          160.   	ASN1_put_object(&p,constructed,ret,tag,xclass);
                  ^
          161.   	memcpy(p,a->data,a->length);
          162.   	p+=a->length;

crypto/asn1/asn1_lib.c:180:1: Parameter `**pp`
            178.   /* class 0 is constructed
            179.    * constructed == 2 for indefinitle length constructed */
            180. > void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
            181.   	     int xclass)
            182.   	{

crypto/asn1/asn1_lib.c:183:2: Assignment
            181.   	     int xclass)
            182.   	{
            183.   	unsigned char *p= *pp;
                    ^
            184.   	int i;
            185.   

crypto/asn1/asn1_lib.c:189:5: Assignment
            187.   	i|=(xclass&V_ASN1_PRIVATE);
            188.   	if (tag < 31)
            189.   		*(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);
                       ^
            190.   	else
            191.   		{

crypto/asn1/asn1_lib.c:201:5: Assignment
            199.   		}
            200.   	if ((constructed == 2) && (length == 0))
            201.   		*(p++)=0x80; /* der_put_length would output 0 instead */
                       ^
            202.   	else
            203.   		asn1_put_length(&p,length);

crypto/asn1/asn1_lib.c:204:2: Assignment
            202.   	else
            203.   		asn1_put_length(&p,length);
            204.   	*pp=p;
                    ^
            205.   	}
            206.   

crypto/asn1/a_bytes.c:161:2: Array access: Offset added: [4, +oo] (⇐ [4, +oo] + [0, 8]) Size: [0, +oo] by call to `PKCS12_pack_p7encdata` 
          159.   		constructed=0;
          160.   	ASN1_put_object(&p,constructed,ret,tag,xclass);
          161.   	memcpy(p,a->data,a->length);
                  ^
          162.   	p+=a->length;
          163.   	*pp= p;

int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
	{
	int ret,r,constructed;
	unsigned char *p;
	if (a == NULL)  return(0);
	if (tag == V_ASN1_BIT_STRING)
		return(i2d_ASN1_BIT_STRING(a,pp));
	ret=a->length;
	r=ASN1_object_size(0,ret,tag);
	if (pp == NULL) return(r);
	p= *pp;
	if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
		constructed=1;
	else
		constructed=0;
	ASN1_put_object(&p,constructed,ret,tag,xclass);
	memcpy(p,a->data,a->length);
	p+=a->length;
	*pp= p;
	return(r);
	}
['int MAIN(int argc, char **argv)\n{\n    char *infile=NULL, *outfile=NULL, *keyname = NULL;\n    char *certfile=NULL;\n    BIO *in=NULL, *out = NULL, *inkey = NULL, *certsin = NULL;\n    char **args;\n    char *name = NULL;\n    PKCS12 *p12 = NULL;\n    char pass[50], macpass[50];\n    int export_cert = 0;\n    int options = 0;\n    int chain = 0;\n    int badarg = 0;\n    int iter = _ITER_;\n    int maciter = 1;\n    int twopass = 0;\n    int keytype = 0;\n    int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;\n    int ret = 1;\n    int macver = 1;\n    int noprompt = 0;\n    STACK *canames = NULL;\n    char *cpass = NULL, *mpass = NULL;\n    apps_startup();\n    enc = EVP_des_ede3_cbc();\n    if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);\n    args = argv + 1;\n    while (*args) {\n\tif (*args[0] == \'-\') {\n\t\tif (!strcmp (*args, "-nokeys")) options |= NOKEYS;\n\t\telse if (!strcmp (*args, "-keyex")) keytype = KEY_EX;\n\t\telse if (!strcmp (*args, "-keysig")) keytype = KEY_SIG;\n\t\telse if (!strcmp (*args, "-nocerts")) options |= NOCERTS;\n\t\telse if (!strcmp (*args, "-clcerts")) options |= CLCERTS;\n\t\telse if (!strcmp (*args, "-cacerts")) options |= CACERTS;\n\t\telse if (!strcmp (*args, "-noout")) options |= (NOKEYS|NOCERTS);\n\t\telse if (!strcmp (*args, "-info")) options |= INFO;\n\t\telse if (!strcmp (*args, "-chain")) chain = 1;\n\t\telse if (!strcmp (*args, "-twopass")) twopass = 1;\n\t\telse if (!strcmp (*args, "-nomacver")) macver = 0;\n\t\telse if (!strcmp (*args, "-descert"))\n    \t\t\tcert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;\n\t\telse if (!strcmp (*args, "-export")) export_cert = 1;\n\t\telse if (!strcmp (*args, "-des")) enc=EVP_des_cbc();\n#ifndef NO_IDEA\n\t\telse if (!strcmp (*args, "-idea")) enc=EVP_idea_cbc();\n#endif\n\t\telse if (!strcmp (*args, "-des3")) enc = EVP_des_ede3_cbc();\n\t\telse if (!strcmp (*args, "-noiter")) iter = 1;\n\t\telse if (!strcmp (*args, "-maciter")) maciter = _ITER_;\n\t\telse if (!strcmp (*args, "-nodes")) enc=NULL;\n\t\telse if (!strcmp (*args, "-inkey")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tkeyname = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-certfile")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tcertfile = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-name")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tname = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-caname")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tif (!canames) canames = sk_new(NULL);\n\t\t\tsk_push(canames, *args);\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-in")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tinfile = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-out")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\toutfile = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-envpass")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tif(!(cpass = getenv(*args))) {\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t "Can\'t read environment variable %s\\n", *args);\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\tnoprompt = 1;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-password")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tcpass = *args;\n\t\t    \tnoprompt = 1;\n\t\t    } else badarg = 1;\n\t\t} else badarg = 1;\n\t} else badarg = 1;\n\targs++;\n    }\n    if (badarg) {\n\tBIO_printf (bio_err, "Usage: pkcs12 [options]\\n");\n\tBIO_printf (bio_err, "where options are\\n");\n\tBIO_printf (bio_err, "-export       output PKCS12 file\\n");\n\tBIO_printf (bio_err, "-chain        add certificate chain\\n");\n\tBIO_printf (bio_err, "-inkey file   private key if not infile\\n");\n\tBIO_printf (bio_err, "-certfile f   add all certs in f\\n");\n\tBIO_printf (bio_err, "-name \\"name\\"  use name as friendly name\\n");\n\tBIO_printf (bio_err, "-caname \\"nm\\"  use nm as CA friendly name (can be used more than once).\\n");\n\tBIO_printf (bio_err, "-in  infile   input filename\\n");\n\tBIO_printf (bio_err, "-out outfile  output filename\\n");\n\tBIO_printf (bio_err, "-noout        don\'t output anything, just verify.\\n");\n\tBIO_printf (bio_err, "-nomacver     don\'t verify MAC.\\n");\n\tBIO_printf (bio_err, "-nocerts      don\'t output certificates.\\n");\n\tBIO_printf (bio_err, "-clcerts      only output client certificates.\\n");\n\tBIO_printf (bio_err, "-cacerts      only output CA certificates.\\n");\n\tBIO_printf (bio_err, "-nokeys       don\'t output private keys.\\n");\n\tBIO_printf (bio_err, "-info         give info about PKCS#12 structure.\\n");\n\tBIO_printf (bio_err, "-des          encrypt private keys with DES\\n");\n\tBIO_printf (bio_err, "-des3         encrypt private keys with triple DES (default)\\n");\n#ifndef NO_IDEA\n\tBIO_printf (bio_err, "-idea         encrypt private keys with idea\\n");\n#endif\n\tBIO_printf (bio_err, "-nodes        don\'t encrypt private keys\\n");\n\tBIO_printf (bio_err, "-noiter       don\'t use encryption iteration\\n");\n\tBIO_printf (bio_err, "-maciter      use MAC iteration\\n");\n\tBIO_printf (bio_err, "-twopass      separate MAC, encryption passwords\\n");\n\tBIO_printf (bio_err, "-descert      encrypt PKCS#12 certificates with triple DES (default RC2-40)\\n");\n\tBIO_printf (bio_err, "-keyex        set MS key exchange type\\n");\n\tBIO_printf (bio_err, "-keysig       set MS key signature type\\n");\n\tBIO_printf (bio_err, "-password p   set import/export password (NOT RECOMMENDED)\\n");\n\tBIO_printf (bio_err, "-envpass p    set import/export password from environment\\n");\n    \tgoto end;\n    }\n    if(cpass) mpass = cpass;\n    else {\n\tcpass = pass;\n\tmpass = macpass;\n    }\n    ERR_load_crypto_strings();\n    in = BIO_new (BIO_s_file());\n    out = BIO_new (BIO_s_file());\n    if (!infile) BIO_set_fp (in, stdin, BIO_NOCLOSE);\n    else {\n        if (BIO_read_filename (in, infile) <= 0) {\n\t    perror (infile);\n\t    goto end;\n\t}\n    }\n   if (certfile) {\n    \tcertsin = BIO_new (BIO_s_file());\n        if (BIO_read_filename (certsin, certfile) <= 0) {\n\t    perror (certfile);\n\t    goto end;\n\t}\n    }\n    if (keyname) {\n    \tinkey = BIO_new (BIO_s_file());\n        if (BIO_read_filename (inkey, keyname) <= 0) {\n\t    perror (keyname);\n\t    goto end;\n\t}\n     }\n    if (!outfile) BIO_set_fp (out, stdout, BIO_NOCLOSE);\n    else {\n        if (BIO_write_filename (out, outfile) <= 0) {\n\t    perror (outfile);\n\t    goto end;\n\t}\n    }\n    if (twopass) {\n\tif(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert)) {\n    \t    BIO_printf (bio_err, "Can\'t read Password\\n");\n    \t    goto end;\n       \t}\n    }\nif (export_cert) {\n\tEVP_PKEY *key;\n\tSTACK *bags, *safes;\n\tPKCS12_SAFEBAG *bag;\n\tPKCS8_PRIV_KEY_INFO *p8;\n\tPKCS7 *authsafe;\n\tX509 *cert, *ucert = NULL;\n\tSTACK *certs;\n\tchar *catmp;\n\tint i, pmatch = 0;\n\tunsigned char keyid[EVP_MAX_MD_SIZE];\n\tunsigned int keyidlen;\n\tkey = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL);\n\tif (!inkey) BIO_reset(in);\n\tif (!key) {\n\t\tBIO_printf (bio_err, "Error loading private key\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tcerts = sk_new(NULL);\n\tif(!cert_load(in, certs)) {\n\t\tBIO_printf(bio_err, "Error loading certificates from input\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tbags = sk_new (NULL);\n\tif (certsin) {\n\t\tif(!cert_load(certsin, certs)) {\n\t\t\tBIO_printf(bio_err, "Error loading certificates from certfile\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t    \tBIO_free(certsin);\n \t}\n\tfor(i = 0; i < sk_num(certs); i++) {\n\t\t\tcert = (X509 *)sk_value(certs, i);\n\t\t\tif(X509_check_private_key(cert, key)) {\n\t\t\t\tucert = cert;\n\t\t\t\tbreak;\n\t\t\t}\n\t}\n\tif(!ucert) {\n\t\tBIO_printf(bio_err, "No certificate matches private key\\n");\n\t\tgoto end;\n\t}\n\tif (chain) {\n        \tint vret;\n\t\tSTACK *chain2;\n\t\tvret = get_cert_chain (ucert, &chain2);\n\t\tif (vret) {\n\t\t\tBIO_printf (bio_err, "Error %s getting chain.\\n",\n\t\t\t\t\tX509_verify_cert_error_string(vret));\n\t\t\tgoto end;\n\t\t}\n\t\tfor (i = 1; i < sk_num (chain2) ; i++)\n\t\t\t\t sk_push(certs, sk_value (chain2, i));\n\t\tsk_free(chain2);\n    \t}\n\tfor(i = 0; i < sk_num(certs); i++) {\n\t\tcert = (X509 *)sk_value(certs, i);\n\t\tbag = M_PKCS12_x5092certbag(cert);\n\t\tif(cert == ucert) {\n\t\t\tif(name) PKCS12_add_friendlyname(bag, name, -1);\n\t\t\tX509_digest(cert, EVP_sha1(), keyid, &keyidlen);\n\t\t\tPKCS12_add_localkeyid(bag, keyid, keyidlen);\n\t\t\tpmatch = 1;\n\t\t} else if((catmp = sk_shift(canames)))\n\t\t\t\tPKCS12_add_friendlyname(bag, catmp, -1);\n\t\tsk_push(bags, (char *)bag);\n\t}\n\tif (canames) sk_free(canames);\n\tif(!noprompt &&\n\t\tEVP_read_pw_string(pass, 50, "Enter Export Password:", 1)) {\n\t    BIO_printf (bio_err, "Can\'t read Password\\n");\n\t    goto end;\n        }\n\tif (!twopass) strcpy(macpass, pass);\n\tauthsafe = PKCS12_pack_p7encdata (cert_pbe, cpass, -1, NULL, 0,\n\t\t\t\t\t\t\t\t iter, bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tif (!authsafe) {\n\t\tERR_print_errors (bio_err);\n\t\tgoto end;\n\t}\n\tsafes = sk_new (NULL);\n\tsk_push (safes, (char *)authsafe);\n\tp8 = EVP_PKEY2PKCS8 (key);\n\tEVP_PKEY_free(key);\n\tif(keytype) PKCS8_add_keyusage(p8, keytype);\n\tbag = PKCS12_MAKE_SHKEYBAG (NID_pbe_WithSHA1And3_Key_TripleDES_CBC,\n\t\t\tcpass, -1, NULL, 0, iter, p8);\n\tPKCS8_PRIV_KEY_INFO_free(p8);\n        if (name) PKCS12_add_friendlyname (bag, name, -1);\n\tPKCS12_add_localkeyid (bag, keyid, keyidlen);\n\tbags = sk_new(NULL);\n\tsk_push (bags, (char *)bag);\n\tauthsafe = PKCS12_pack_p7data (bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tsk_push (safes, (char *)authsafe);\n\tp12 = PKCS12_init (NID_pkcs7_data);\n\tM_PKCS12_pack_authsafes (p12, safes);\n\tsk_pop_free(safes, PKCS7_free);\n\tPKCS12_set_mac (p12, mpass, -1, NULL, 0, maciter, NULL);\n\ti2d_PKCS12_bio (out, p12);\n\tPKCS12_free(p12);\n\tret = 0;\n\tgoto end;\n}\n    if (!(p12 = d2i_PKCS12_bio (in, NULL))) {\n\tERR_print_errors(bio_err);\n\tgoto end;\n    }\n    if(!noprompt && EVP_read_pw_string(pass, 50, "Enter Import Password:", 0)) {\n\tBIO_printf (bio_err, "Can\'t read Password\\n");\n\tgoto end;\n    }\n    if (!twopass) strcpy(macpass, pass);\n    if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);\n    if(macver) {\n\tif (!PKCS12_verify_mac (p12, mpass, -1)) {\n\t    BIO_printf (bio_err, "Mac verify errror: invalid password?\\n");\n\t    ERR_print_errors (bio_err);\n\t    goto end;\n\t} else BIO_printf (bio_err, "MAC verified OK\\n");\n    }\n    if (!dump_certs_keys_p12 (out, p12, cpass, -1, options)) {\n\tBIO_printf(bio_err, "Error outputting keys and certificates\\n");\n\tERR_print_errors (bio_err);\n\tgoto end;\n    }\n    PKCS12_free(p12);\n    ret = 0;\n    end:\n    EXIT(ret);\n}', 'PKCS7 *PKCS12_pack_p7encdata (int pbe_nid, const char *pass, int passlen,\n\t     unsigned char *salt, int saltlen, int iter, STACK *bags)\n{\n\tPKCS7 *p7;\n\tX509_ALGOR *pbe;\n\tif (!(p7 = PKCS7_new())) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tp7->type = OBJ_nid2obj(NID_pkcs7_encrypted);\n\tif (!(p7->d.encrypted = PKCS7_ENCRYPT_new ())) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tASN1_INTEGER_set (p7->d.encrypted->version, 0);\n\tp7->d.encrypted->enc_data->content_type = OBJ_nid2obj(NID_pkcs7_data);\n\tif (!(pbe = PKCS5_pbe_set (pbe_nid, iter, salt, saltlen))) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tX509_ALGOR_free(p7->d.encrypted->enc_data->algorithm);\n\tp7->d.encrypted->enc_data->algorithm = pbe;\n\tASN1_OCTET_STRING_free(p7->d.encrypted->enc_data->enc_data);\n\tif (!(p7->d.encrypted->enc_data->enc_data =\n\tPKCS12_i2d_encrypt (pbe, i2d_PKCS12_SAFEBAG, pass, passlen,\n\t\t\t\t (char *)bags, 1))) {\n\t\tPKCS12err(PKCS12_F_PKCS12_PACK_P7ENCDATA, PKCS12_R_ENCRYPT_ERROR);\n\t\treturn NULL;\n\t}\n\treturn p7;\n}', 'X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,\n\t     int saltlen)\n{\n\tunsigned char *pdata, *ptmp;\n\tint plen;\n\tPBEPARAM *pbe;\n\tASN1_OBJECT *al;\n\tX509_ALGOR *algor;\n\tASN1_TYPE *astype;\n\tif (!(pbe = PBEPARAM_new ())) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tASN1_INTEGER_set (pbe->iter, iter);\n\tif (!saltlen) saltlen = PKCS5_SALT_LEN;\n\tif (!(pbe->salt->data = Malloc (saltlen))) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tpbe->salt->length = saltlen;\n\tif (salt) memcpy (pbe->salt->data, salt, saltlen);\n\telse RAND_bytes (pbe->salt->data, saltlen);\n\tif (!(plen = i2d_PBEPARAM (pbe, NULL))) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ASN1_R_ENCODE_ERROR);\n\t\treturn NULL;\n\t}\n\tif (!(pdata = Malloc (plen))) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tptmp = pdata;\n\ti2d_PBEPARAM (pbe, &ptmp);\n\tPBEPARAM_free (pbe);\n\tif (!(astype = ASN1_TYPE_new())) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tastype->type = V_ASN1_SEQUENCE;\n\tif (!(astype->value.sequence=ASN1_STRING_new())) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tASN1_STRING_set (astype->value.sequence, pdata, plen);\n\tFree (pdata);\n\tal = OBJ_nid2obj(alg);\n\tif (!(algor = X509_ALGOR_new())) {\n\t\tASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t}\n\tASN1_OBJECT_free(algor->algorithm);\n\talgor->algorithm = al;\n\talgor->parameter = astype;\n\treturn (algor);\n}', 'int i2d_PBEPARAM(PBEPARAM *a, unsigned char **pp)\n{\n\tM_ASN1_I2D_vars(a);\n\tM_ASN1_I2D_len (a->salt, i2d_ASN1_OCTET_STRING);\n\tM_ASN1_I2D_len (a->iter, i2d_ASN1_INTEGER);\n\tM_ASN1_I2D_seq_total ();\n\tM_ASN1_I2D_put (a->salt, i2d_ASN1_OCTET_STRING);\n\tM_ASN1_I2D_put (a->iter, i2d_ASN1_INTEGER);\n\tM_ASN1_I2D_finish();\n}', 'int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a, unsigned char **pp)\n\t{\n\treturn(i2d_ASN1_bytes((ASN1_STRING *)a,pp,\n\t\tV_ASN1_OCTET_STRING,V_ASN1_UNIVERSAL));\n\t}', 'int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)\n\t{\n\tint ret,r,constructed;\n\tunsigned char *p;\n\tif (a == NULL)  return(0);\n\tif (tag == V_ASN1_BIT_STRING)\n\t\treturn(i2d_ASN1_BIT_STRING(a,pp));\n\tret=a->length;\n\tr=ASN1_object_size(0,ret,tag);\n\tif (pp == NULL) return(r);\n\tp= *pp;\n\tif ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))\n\t\tconstructed=1;\n\telse\n\t\tconstructed=0;\n\tASN1_put_object(&p,constructed,ret,tag,xclass);\n\tmemcpy(p,a->data,a->length);\n\tp+=a->length;\n\t*pp= p;\n\treturn(r);\n\t}', 'void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,\n\t     int xclass)\n\t{\n\tunsigned char *p= *pp;\n\tint i;\n\ti=(constructed)?V_ASN1_CONSTRUCTED:0;\n\ti|=(xclass&V_ASN1_PRIVATE);\n\tif (tag < 31)\n\t\t*(p++)=i|(tag&V_ASN1_PRIMATIVE_TAG);\n\telse\n\t\t{\n\t\t*(p++)=i|V_ASN1_PRIMATIVE_TAG;\n\t\twhile (tag > 0x7f)\n\t\t\t{\n\t\t\t*(p++)=(tag&0x7f)|0x80;\n\t\t\ttag>>=7;\n\t\t\t}\n\t\t*(p++)=(tag&0x7f);\n\t\t}\n\tif ((constructed == 2) && (length == 0))\n\t\t*(p++)=0x80;\n\telse\n\t\tasn1_put_length(&p,length);\n\t*pp=p;\n\t}']