Hi! I was to send SHA1 hash of my public to some peer. For that i have written a function:
EVP_PKEY * ReadPublicKey(const char *certfile) { FILE *fp = fopen (certfile, "r"); X509 *x509; EVP_PKEY *pkey; if (!fp) return NULL; x509 = PEM_read_X509(fp, NULL, 0, NULL); if (x509 == NULL) { ERR_print_errors_fp (stderr); return NULL; } fclose (fp); pkey=X509_extract_key(x509); X509_free(x509); if (pkey == NULL) ERR_print_errors_fp (stderr); return pkey; } Then, I am extracting the public key in a buffer: pubKey = ReadPublicKey(PUBFILE); if(!pubKey) { fprintf(stderr,"Error: can't load public key"); exit(1); } issuer_pubkey_len = i2d_PUBKEY(pubKey, NULL); issuer_pubkey = malloc(issuer_pubkey_len); i2d_PUBKEY(pubKey, &issuer_pubkey); memory_dump("issuer_pubkey", issuer_pubkey, issuer_pubkey_len); The problem, is issuer_pubkey buffer is different each time, I run the my application using same code. To debug the problem, i created a separate test code, just reading the issuer cert in .pem format and reading the pubkey in buffer, the buffer is same each time i run test code as expected. How come pubkey in a buffer can be different each time in my application ? Is this some -lcrypto linking problem ? I have also debugged for memory corruption. It is not present. Please provide some pointers. Thanks for the help in advance. Best Regards, Raj