engines/e_4758_cca.c:531: error: NULL_DEREFERENCE
  pointer `rtmp` last assigned on line 530 could be null and is dereferenced by call to `RSA_set_ex_data()` at line 531, column 2.
Showing all 95 steps of the trace


engines/e_4758_cca.c:471:1: start of procedure ibm_4758_load_pubkey()
469.   	}
470.   
471. > static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
472.   			UI_METHOD *ui_method, void *callback_data)
473.   	{

engines/e_4758_cca.c:474:2: 
472.   			UI_METHOD *ui_method, void *callback_data)
473.   	{
474. > 	RSA *rtmp = NULL;
475.   	EVP_PKEY *res = NULL;
476.   	unsigned char* keyToken = NULL;

engines/e_4758_cca.c:475:2: 
473.   	{
474.   	RSA *rtmp = NULL;
475. > 	EVP_PKEY *res = NULL;
476.   	unsigned char* keyToken = NULL;
477.   	long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;

engines/e_4758_cca.c:476:2: 
474.   	RSA *rtmp = NULL;
475.   	EVP_PKEY *res = NULL;
476. > 	unsigned char* keyToken = NULL;
477.   	long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
478.   	long returnCode;

engines/e_4758_cca.c:477:2: 
475.   	EVP_PKEY *res = NULL;
476.   	unsigned char* keyToken = NULL;
477. > 	long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
478.   	long returnCode;
479.   	long reasonCode;

engines/e_4758_cca.c:480:2: 
478.   	long returnCode;
479.   	long reasonCode;
480. > 	long exitDataLength = 0;
481.   	long ruleArrayLength = 0;
482.   	unsigned char exitData[8];

engines/e_4758_cca.c:481:2: 
479.   	long reasonCode;
480.   	long exitDataLength = 0;
481. > 	long ruleArrayLength = 0;
482.   	unsigned char exitData[8];
483.   	unsigned char ruleArray[8];

engines/e_4758_cca.c:485:2: 
483.   	unsigned char ruleArray[8];
484.   	unsigned char keyLabel[64];
485. > 	long keyLabelLength = strlen(key_id);
486.   	unsigned char modulus[512];
487.   	long modulusFieldLength = sizeof(modulus);

engines/e_4758_cca.c:487:2: 
485.   	long keyLabelLength = strlen(key_id);
486.   	unsigned char modulus[512];
487. > 	long modulusFieldLength = sizeof(modulus);
488.   	long modulusLength = 0;
489.   	unsigned char exponent[512];

engines/e_4758_cca.c:488:2: 
486.   	unsigned char modulus[512];
487.   	long modulusFieldLength = sizeof(modulus);
488. > 	long modulusLength = 0;
489.   	unsigned char exponent[512];
490.   	long exponentLength = sizeof(exponent);

engines/e_4758_cca.c:490:2: 
488.   	long modulusLength = 0;
489.   	unsigned char exponent[512];
490. > 	long exponentLength = sizeof(exponent);
491.   
492.   	if (keyLabelLength > sizeof(keyLabel))

engines/e_4758_cca.c:492:6: Taking false branch
490.   	long exponentLength = sizeof(exponent);
491.   
492.   	if (keyLabelLength > sizeof(keyLabel))
            ^
493.   		{
494.   		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,

engines/e_4758_cca.c:499:2: 
497.   		}
498.   
499. > 	memset(keyLabel,' ', sizeof(keyLabel));
500.   	memcpy(keyLabel, key_id, keyLabelLength);
501.   

engines/e_4758_cca.c:500:2: 
498.   
499.   	memset(keyLabel,' ', sizeof(keyLabel));
500. > 	memcpy(keyLabel, key_id, keyLabelLength);
501.   
502.   	keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));

engines/e_4758_cca.c:502:2: 
500.   	memcpy(keyLabel, key_id, keyLabelLength);
501.   
502. > 	keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
503.   	if (!keyToken)
504.   		{

crypto/mem.c:289:1: start of procedure CRYPTO_malloc()
  287.   	}
  288.   
  289. > void *CRYPTO_malloc(int num, const char *file, int line)
  290.   	{
  291.   	void *ret = NULL;

crypto/mem.c:291:2: 
  289.   void *CRYPTO_malloc(int num, const char *file, int line)
  290.   	{
  291. > 	void *ret = NULL;
  292.   	extern unsigned char cleanse_ctr;
  293.   

crypto/mem.c:294:2: 
  292.   	extern unsigned char cleanse_ctr;
  293.   
  294. > 	allow_customize = 0;
  295.   	if (malloc_debug_func != NULL)
  296.   		{

crypto/mem.c:295:6: Taking true branch
  293.   
  294.   	allow_customize = 0;
  295.   	if (malloc_debug_func != NULL)
              ^
  296.   		{
  297.   		allow_customize_debug = 0;

crypto/mem.c:297:3: 
  295.   	if (malloc_debug_func != NULL)
  296.   		{
  297. > 		allow_customize_debug = 0;
  298.   		malloc_debug_func(NULL, num, file, line, 0);
  299.   		}

crypto/mem.c:298:3: Skipping __function_pointer__(): unresolved function pointer
  296.   		{
  297.   		allow_customize_debug = 0;
  298.   		malloc_debug_func(NULL, num, file, line, 0);
           ^
  299.   		}
  300.   	ret = malloc_ex_func(num,file,line);

crypto/mem.c:300:2: Skipping __function_pointer__(): unresolved function pointer
  298.   		malloc_debug_func(NULL, num, file, line, 0);
  299.   		}
  300.   	ret = malloc_ex_func(num,file,line);
          ^
  301.   #ifdef LEVITTE_DEBUG_MEM
  302.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:304:6: Taking true branch
  302.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
  303.   #endif
  304.   	if (malloc_debug_func != NULL)
              ^
  305.   		malloc_debug_func(ret, num, file, line, 1);
  306.   

crypto/mem.c:305:3: Skipping __function_pointer__(): unresolved function pointer
  303.   #endif
  304.   	if (malloc_debug_func != NULL)
  305.   		malloc_debug_func(ret, num, file, line, 1);
           ^
  306.   
  307.           /* Create a dependency on the value of 'cleanse_ctr' so our memory

crypto/mem.c:310:12: Taking true branch
  308.            * sanitisation function can't be optimised out. NB: We only do
  309.            * this for >2Kb so the overhead doesn't bother us. */
  310.           if(ret && (num > 2048))
                    ^
  311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
  312.   

crypto/mem.c:310:20: Taking true branch
  308.            * sanitisation function can't be optimised out. NB: We only do
  309.            * this for >2Kb so the overhead doesn't bother us. */
  310.           if(ret && (num > 2048))
                            ^
  311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
  312.   

crypto/mem.c:311:17: 
  309.            * this for >2Kb so the overhead doesn't bother us. */
  310.           if(ret && (num > 2048))
  311. >                 ((unsigned char *)ret)[0] = cleanse_ctr;
  312.   
  313.   	return ret;

crypto/mem.c:313:2: 
  311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
  312.   
  313. > 	return ret;
  314.   	}
  315.   

crypto/mem.c:314:2: return from a call to CRYPTO_malloc
  312.   
  313.   	return ret;
  314.   	}
          ^
  315.   
  316.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

engines/e_4758_cca.c:503:7: Taking false branch
501.   
502.   	keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
503.   	if (!keyToken)
             ^
504.   		{
505.   		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,

engines/e_4758_cca.c:510:2: Skipping __function_pointer__(): unresolved function pointer
508.   		}
509.   
510.   	keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
        ^
511.   		&ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
512.   		keyToken+sizeof(long));

engines/e_4758_cca.c:514:6: Taking false branch
512.   		keyToken+sizeof(long));
513.   
514.   	if (returnCode)
            ^
515.   		{
516.   		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,

engines/e_4758_cca.c:521:7: 
519.   		}
520.   
521. > 	if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
522.   			exponent, &modulusLength, &modulusFieldLength, modulus))
523.   		{

engines/e_4758_cca.c:853:1: start of procedure getModulusAndExponent()
  851.   	}
  852.   
  853. > static int getModulusAndExponent(const unsigned char*token, long *exponentLength,
  854.   		unsigned char *exponent, long *modulusLength, long *modulusFieldLength,
  855.   		unsigned char *modulus)

engines/e_4758_cca.c:859:6: Taking false branch
  857.   	unsigned long len;
  858.   
  859.   	if (*token++ != (char)0x1E) /* internal PKA token? */
              ^
  860.   		return 0;
  861.   

engines/e_4758_cca.c:862:6: Taking false branch
  860.   		return 0;
  861.   
  862.   	if (*token++) /* token version must be zero */
              ^
  863.   		return 0;
  864.   

engines/e_4758_cca.c:865:2: 
  863.   		return 0;
  864.   
  865. > 	len = *token++;
  866.   	len = len << 8;
  867.   	len |= (unsigned char)*token++;

engines/e_4758_cca.c:866:2: 
  864.   
  865.   	len = *token++;
  866. > 	len = len << 8;
  867.   	len |= (unsigned char)*token++;
  868.   

engines/e_4758_cca.c:867:2: 
  865.   	len = *token++;
  866.   	len = len << 8;
  867. > 	len |= (unsigned char)*token++;
  868.   
  869.   	token += 4; /* skip reserved bytes */

engines/e_4758_cca.c:869:2: 
  867.   	len |= (unsigned char)*token++;
  868.   
  869. > 	token += 4; /* skip reserved bytes */
  870.   
  871.   	if (*token++ == (char)0x04)

engines/e_4758_cca.c:871:6: Taking true branch
  869.   	token += 4; /* skip reserved bytes */
  870.   
  871.   	if (*token++ == (char)0x04)
              ^
  872.   		{
  873.   		if (*token++) /* token version must be zero */

engines/e_4758_cca.c:873:7: Taking false branch
  871.   	if (*token++ == (char)0x04)
  872.   		{
  873.   		if (*token++) /* token version must be zero */
               ^
  874.   			return 0;
  875.   

engines/e_4758_cca.c:876:3: 
  874.   			return 0;
  875.   
  876. > 		len = *token++;
  877.   		len = len << 8;
  878.   		len |= (unsigned char)*token++;

engines/e_4758_cca.c:877:3: 
  875.   
  876.   		len = *token++;
  877. > 		len = len << 8;
  878.   		len |= (unsigned char)*token++;
  879.   

engines/e_4758_cca.c:878:3: 
  876.   		len = *token++;
  877.   		len = len << 8;
  878. > 		len |= (unsigned char)*token++;
  879.   
  880.   		token+=2; /* skip reserved section */

engines/e_4758_cca.c:880:3: 
  878.   		len |= (unsigned char)*token++;
  879.   
  880. > 		token+=2; /* skip reserved section */
  881.   
  882.   		len = *token++;

engines/e_4758_cca.c:882:3: 
  880.   		token+=2; /* skip reserved section */
  881.   
  882. > 		len = *token++;
  883.   		len = len << 8;
  884.   		len |= (unsigned char)*token++;

engines/e_4758_cca.c:883:3: 
  881.   
  882.   		len = *token++;
  883. > 		len = len << 8;
  884.   		len |= (unsigned char)*token++;
  885.   

engines/e_4758_cca.c:884:3: 
  882.   		len = *token++;
  883.   		len = len << 8;
  884. > 		len |= (unsigned char)*token++;
  885.   
  886.   		*exponentLength = len;

engines/e_4758_cca.c:886:3: 
  884.   		len |= (unsigned char)*token++;
  885.   
  886. > 		*exponentLength = len;
  887.   
  888.   		len = *token++;

engines/e_4758_cca.c:888:3: 
  886.   		*exponentLength = len;
  887.   
  888. > 		len = *token++;
  889.   		len = len << 8;
  890.   		len |= (unsigned char)*token++;

engines/e_4758_cca.c:889:3: 
  887.   
  888.   		len = *token++;
  889. > 		len = len << 8;
  890.   		len |= (unsigned char)*token++;
  891.   

engines/e_4758_cca.c:890:3: 
  888.   		len = *token++;
  889.   		len = len << 8;
  890. > 		len |= (unsigned char)*token++;
  891.   
  892.   		*modulusLength = len;

engines/e_4758_cca.c:892:3: 
  890.   		len |= (unsigned char)*token++;
  891.   
  892. > 		*modulusLength = len;
  893.   
  894.   		len = *token++;

engines/e_4758_cca.c:894:3: 
  892.   		*modulusLength = len;
  893.   
  894. > 		len = *token++;
  895.   		len = len << 8;
  896.   		len |= (unsigned char)*token++;

engines/e_4758_cca.c:895:3: 
  893.   
  894.   		len = *token++;
  895. > 		len = len << 8;
  896.   		len |= (unsigned char)*token++;
  897.   

engines/e_4758_cca.c:896:3: 
  894.   		len = *token++;
  895.   		len = len << 8;
  896. > 		len |= (unsigned char)*token++;
  897.   
  898.   		*modulusFieldLength = len;

engines/e_4758_cca.c:898:3: 
  896.   		len |= (unsigned char)*token++;
  897.   
  898. > 		*modulusFieldLength = len;
  899.   
  900.   		memcpy(exponent, token, *exponentLength);

engines/e_4758_cca.c:900:3: 
  898.   		*modulusFieldLength = len;
  899.   
  900. > 		memcpy(exponent, token, *exponentLength);
  901.   		token+= *exponentLength;
  902.   

engines/e_4758_cca.c:901:3: 
  899.   
  900.   		memcpy(exponent, token, *exponentLength);
  901. > 		token+= *exponentLength;
  902.   
  903.   		memcpy(modulus, token, *modulusFieldLength);

engines/e_4758_cca.c:903:3: 
  901.   		token+= *exponentLength;
  902.   
  903. > 		memcpy(modulus, token, *modulusFieldLength);
  904.   		return 1;
  905.   		}

engines/e_4758_cca.c:904:3: 
  902.   
  903.   		memcpy(modulus, token, *modulusFieldLength);
  904. > 		return 1;
  905.   		}
  906.   	return 0;

engines/e_4758_cca.c:907:2: return from a call to getModulusAndExponent
  905.   		}
  906.   	return 0;
  907.   	}
          ^
  908.   
  909.   #endif /* OPENSSL_NO_RSA */

engines/e_4758_cca.c:521:7: Taking false branch
519.   		}
520.   
521.   	if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
             ^
522.   			exponent, &modulusLength, &modulusFieldLength, modulus))
523.   		{

engines/e_4758_cca.c:529:2: 
527.   		}
528.   
529. > 	(*(long*)keyToken) = keyTokenLength;
530.   	rtmp = RSA_new_method(e);
531.   	RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);

engines/e_4758_cca.c:530:2: 
528.   
529.   	(*(long*)keyToken) = keyTokenLength;
530. > 	rtmp = RSA_new_method(e);
531.   	RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
532.   	rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);

crypto/rsa/rsa_lib.c:121:1: start of procedure RSA_new_method()
  119.   	}
  120.   
  121. > RSA *RSA_new_method(ENGINE *engine)
  122.   	{
  123.   	RSA *ret;

crypto/rsa/rsa_lib.c:125:2: 
  123.   	RSA *ret;
  124.   
  125. > 	ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
  126.   	if (ret == NULL)
  127.   		{

crypto/mem.c:289:1: start of procedure CRYPTO_malloc()
    287.   	}
    288.   
    289. > void *CRYPTO_malloc(int num, const char *file, int line)
    290.   	{
    291.   	void *ret = NULL;

crypto/mem.c:291:2: 
    289.   void *CRYPTO_malloc(int num, const char *file, int line)
    290.   	{
    291. > 	void *ret = NULL;
    292.   	extern unsigned char cleanse_ctr;
    293.   

crypto/mem.c:294:2: 
    292.   	extern unsigned char cleanse_ctr;
    293.   
    294. > 	allow_customize = 0;
    295.   	if (malloc_debug_func != NULL)
    296.   		{

crypto/mem.c:295:6: Taking true branch
    293.   
    294.   	allow_customize = 0;
    295.   	if (malloc_debug_func != NULL)
                ^
    296.   		{
    297.   		allow_customize_debug = 0;

crypto/mem.c:297:3: 
    295.   	if (malloc_debug_func != NULL)
    296.   		{
    297. > 		allow_customize_debug = 0;
    298.   		malloc_debug_func(NULL, num, file, line, 0);
    299.   		}

crypto/mem.c:298:3: Skipping __function_pointer__(): unresolved function pointer
    296.   		{
    297.   		allow_customize_debug = 0;
    298.   		malloc_debug_func(NULL, num, file, line, 0);
             ^
    299.   		}
    300.   	ret = malloc_ex_func(num,file,line);

crypto/mem.c:300:2: Skipping __function_pointer__(): unresolved function pointer
    298.   		malloc_debug_func(NULL, num, file, line, 0);
    299.   		}
    300.   	ret = malloc_ex_func(num,file,line);
            ^
    301.   #ifdef LEVITTE_DEBUG_MEM
    302.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);

crypto/mem.c:304:6: Taking true branch
    302.   	fprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\n", ret, num);
    303.   #endif
    304.   	if (malloc_debug_func != NULL)
                ^
    305.   		malloc_debug_func(ret, num, file, line, 1);
    306.   

crypto/mem.c:305:3: Skipping __function_pointer__(): unresolved function pointer
    303.   #endif
    304.   	if (malloc_debug_func != NULL)
    305.   		malloc_debug_func(ret, num, file, line, 1);
             ^
    306.   
    307.           /* Create a dependency on the value of 'cleanse_ctr' so our memory

crypto/mem.c:310:12: Taking false branch
    308.            * sanitisation function can't be optimised out. NB: We only do
    309.            * this for >2Kb so the overhead doesn't bother us. */
    310.           if(ret && (num > 2048))
                      ^
    311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
    312.   

crypto/mem.c:313:2: 
    311.                   ((unsigned char *)ret)[0] = cleanse_ctr;
    312.   
    313. > 	return ret;
    314.   	}
    315.   

crypto/mem.c:314:2: return from a call to CRYPTO_malloc
    312.   
    313.   	return ret;
    314.   	}
            ^
    315.   
    316.   void *CRYPTO_realloc(void *str, int num, const char *file, int line)

crypto/rsa/rsa_lib.c:126:6: Taking true branch
  124.   
  125.   	ret=(RSA *)OPENSSL_malloc(sizeof(RSA));
  126.   	if (ret == NULL)
              ^
  127.   		{
  128.   		RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);

crypto/rsa/rsa_lib.c:128:3: 
  126.   	if (ret == NULL)
  127.   		{
  128. > 		RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
  129.   		return NULL;
  130.   		}

crypto/err/err.c:617:1: start of procedure ERR_put_error()
    615.   /********************************************************/
    616.   
    617. > void ERR_put_error(int lib, int func, int reason, const char *file,
    618.   	     int line)
    619.   	{

crypto/err/err.c:641:2: Skipping ERR_get_state(): empty list of specs
    639.   	}
    640.   #endif
    641.   	es=ERR_get_state();
            ^
    642.   
    643.   	es->top=(es->top+1)%ERR_NUM_ERRORS;

crypto/err/err.c:643:2: 
    641.   	es=ERR_get_state();
    642.   
    643. > 	es->top=(es->top+1)%ERR_NUM_ERRORS;
    644.   	if (es->top == es->bottom)
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;

crypto/err/err.c:644:6: Taking false branch
    642.   
    643.   	es->top=(es->top+1)%ERR_NUM_ERRORS;
    644.   	if (es->top == es->bottom)
                ^
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    646.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);

crypto/err/err.c:646:2: 
    644.   	if (es->top == es->bottom)
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    646. > 	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    647.   	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;

crypto/err/err.c:647:2: 
    645.   		es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
    646.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    647. > 	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);

crypto/err/err.c:648:2: 
    646.   	es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
    647.   	es->err_file[es->top]=file;
    648. > 	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
    650.   	}

crypto/err/err.c:649:2: Taking true branch
    647.   	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
            ^
    650.   	}
    651.   

crypto/err/err.c:649:2: Taking false branch
    647.   	es->err_file[es->top]=file;
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
            ^
    650.   	}
    651.   

crypto/err/err.c:650:2: return from a call to ERR_put_error
    648.   	es->err_line[es->top]=line;
    649.   	err_clear_data(es,es->top);
    650.   	}
            ^
    651.   
    652.   void ERR_clear_error(void)

crypto/rsa/rsa_lib.c:129:3: 
  127.   		{
  128.   		RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
  129. > 		return NULL;
  130.   		}
  131.   

crypto/rsa/rsa_lib.c:185:2: return from a call to RSA_new_method
  183.   		}
  184.   	return(ret);
  185.   	}
          ^
  186.   
  187.   void RSA_free(RSA *r)

engines/e_4758_cca.c:531:2: 
529.   	(*(long*)keyToken) = keyTokenLength;
530.   	rtmp = RSA_new_method(e);
531. > 	RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
532.   	rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
533.   	rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);

static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
			UI_METHOD *ui_method, void *callback_data)
	{
	RSA *rtmp = NULL;
	EVP_PKEY *res = NULL;
	unsigned char* keyToken = NULL;
	long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
	long returnCode;
	long reasonCode;
	long exitDataLength = 0;
	long ruleArrayLength = 0;
	unsigned char exitData[8];
	unsigned char ruleArray[8];
	unsigned char keyLabel[64];
	long keyLabelLength = strlen(key_id);
	unsigned char modulus[512];
	long modulusFieldLength = sizeof(modulus);
	long modulusLength = 0;
	unsigned char exponent[512];
	long exponentLength = sizeof(exponent);
	if (keyLabelLength > sizeof(keyLabel))
		{
		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
			CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
		return NULL;
		}
	memset(keyLabel,' ', sizeof(keyLabel));
	memcpy(keyLabel, key_id, keyLabelLength);
	keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
	if (!keyToken)
		{
		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,
				ERR_R_MALLOC_FAILURE);
		goto err;
		}
	keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
		&ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
		keyToken+sizeof(long));
	if (returnCode)
		{
		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
				ERR_R_MALLOC_FAILURE);
		goto err;
		}
	if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
			exponent, &modulusLength, &modulusFieldLength, modulus))
		{
		CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
			CCA4758_R_FAILED_LOADING_PUBLIC_KEY);
		goto err;
		}
	(*(long*)keyToken) = keyTokenLength;
	rtmp = RSA_new_method(e);
	RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
	rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
	rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
	rtmp->flags |= RSA_FLAG_EXT_PKEY;
	res = EVP_PKEY_new();
	EVP_PKEY_assign_RSA(res, rtmp);
	return res;
err:
	if (keyToken)
		OPENSSL_free(keyToken);
	if (res)
		EVP_PKEY_free(res);
	if (rtmp)
		RSA_free(rtmp);
	return NULL;
	}
["static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,\n\t\t\tUI_METHOD *ui_method, void *callback_data)\n\t{\n\tRSA *rtmp = NULL;\n\tEVP_PKEY *res = NULL;\n\tunsigned char* keyToken = NULL;\n\tlong keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;\n\tlong returnCode;\n\tlong reasonCode;\n\tlong exitDataLength = 0;\n\tlong ruleArrayLength = 0;\n\tunsigned char exitData[8];\n\tunsigned char ruleArray[8];\n\tunsigned char keyLabel[64];\n\tlong keyLabelLength = strlen(key_id);\n\tunsigned char modulus[512];\n\tlong modulusFieldLength = sizeof(modulus);\n\tlong modulusLength = 0;\n\tunsigned char exponent[512];\n\tlong exponentLength = sizeof(exponent);\n\tif (keyLabelLength > sizeof(keyLabel))\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\tCCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);\n\t\treturn NULL;\n\t\t}\n\tmemset(keyLabel,' ', sizeof(keyLabel));\n\tmemcpy(keyLabel, key_id, keyLabelLength);\n\tkeyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));\n\tif (!keyToken)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,\n\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tkeyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,\n\t\t&ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,\n\t\tkeyToken+sizeof(long));\n\tif (returnCode)\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\t\tERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tif (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,\n\t\t\texponent, &modulusLength, &modulusFieldLength, modulus))\n\t\t{\n\t\tCCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,\n\t\t\tCCA4758_R_FAILED_LOADING_PUBLIC_KEY);\n\t\tgoto err;\n\t\t}\n\t(*(long*)keyToken) = keyTokenLength;\n\trtmp = RSA_new_method(e);\n\tRSA_set_ex_data(rtmp, hndidx, (char *)keyToken);\n\trtmp->e = BN_bin2bn(exponent, exponentLength, NULL);\n\trtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);\n\trtmp->flags |= RSA_FLAG_EXT_PKEY;\n\tres = EVP_PKEY_new();\n\tEVP_PKEY_assign_RSA(res, rtmp);\n\treturn res;\nerr:\n\tif (keyToken)\n\t\tOPENSSL_free(keyToken);\n\tif (res)\n\t\tEVP_PKEY_free(res);\n\tif (rtmp)\n\t\tRSA_free(rtmp);\n\treturn NULL;\n\t}", 'void *CRYPTO_malloc(int num, const char *file, int line)\n\t{\n\tvoid *ret = NULL;\n\textern unsigned char cleanse_ctr;\n\tallow_customize = 0;\n\tif (malloc_debug_func != NULL)\n\t\t{\n\t\tallow_customize_debug = 0;\n\t\tmalloc_debug_func(NULL, num, file, line, 0);\n\t\t}\n\tret = malloc_ex_func(num,file,line);\n#ifdef LEVITTE_DEBUG_MEM\n\tfprintf(stderr, "LEVITTE_DEBUG_MEM:         > 0x%p (%d)\\n", ret, num);\n#endif\n\tif (malloc_debug_func != NULL)\n\t\tmalloc_debug_func(ret, num, file, line, 1);\n        if(ret && (num > 2048))\n                ((unsigned char *)ret)[0] = cleanse_ctr;\n\treturn ret;\n\t}', 'static int getModulusAndExponent(const unsigned char*token, long *exponentLength,\n\t\tunsigned char *exponent, long *modulusLength, long *modulusFieldLength,\n\t\tunsigned char *modulus)\n\t{\n\tunsigned long len;\n\tif (*token++ != (char)0x1E)\n\t\treturn 0;\n\tif (*token++)\n\t\treturn 0;\n\tlen = *token++;\n\tlen = len << 8;\n\tlen |= (unsigned char)*token++;\n\ttoken += 4;\n\tif (*token++ == (char)0x04)\n\t\t{\n\t\tif (*token++)\n\t\t\treturn 0;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\ttoken+=2;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\t*exponentLength = len;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\t*modulusLength = len;\n\t\tlen = *token++;\n\t\tlen = len << 8;\n\t\tlen |= (unsigned char)*token++;\n\t\t*modulusFieldLength = len;\n\t\tmemcpy(exponent, token, *exponentLength);\n\t\ttoken+= *exponentLength;\n\t\tmemcpy(modulus, token, *modulusFieldLength);\n\t\treturn 1;\n\t\t}\n\treturn 0;\n\t}', 'RSA *RSA_new_method(ENGINE *engine)\n\t{\n\tRSA *ret;\n\tret=(RSA *)OPENSSL_malloc(sizeof(RSA));\n\tif (ret == NULL)\n\t\t{\n\t\tRSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn NULL;\n\t\t}\n\tret->meth = RSA_get_default_method();\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_RSA();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_RSA(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tRSAerr(RSA_F_RSA_NEW_METHOD,\n\t\t\t\tERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\tret->pad=0;\n\tret->version=0;\n\tret->n=NULL;\n\tret->e=NULL;\n\tret->d=NULL;\n\tret->p=NULL;\n\tret->q=NULL;\n\tret->dmp1=NULL;\n\tret->dmq1=NULL;\n\tret->iqmp=NULL;\n\tret->references=1;\n\tret->_method_mod_n=NULL;\n\tret->_method_mod_p=NULL;\n\tret->_method_mod_q=NULL;\n\tret->blinding=NULL;\n\tret->bignum_data=NULL;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'void ERR_put_error(int lib, int func, int reason, const char *file,\n\t     int line)\n\t{\n\tERR_STATE *es;\n#ifdef _OSD_POSIX\n\tif (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {\n\t\tchar *end;\n\t\tfile += sizeof("*POSIX(")-1;\n\t\tend = &file[strlen(file)-1];\n\t\tif (*end == \')\')\n\t\t\t*end = \'\\0\';\n\t\tif ((end = strrchr(file, \'/\')) != NULL)\n\t\t\tfile = &end[1];\n\t}\n#endif\n\tes=ERR_get_state();\n\tes->top=(es->top+1)%ERR_NUM_ERRORS;\n\tif (es->top == es->bottom)\n\t\tes->bottom=(es->bottom+1)%ERR_NUM_ERRORS;\n\tes->err_buffer[es->top]=ERR_PACK(lib,func,reason);\n\tes->err_file[es->top]=file;\n\tes->err_line[es->top]=line;\n\terr_clear_data(es,es->top);\n\t}']