Linking problems in compiling a simple RSA encryption C code -


i have included code using learn rsa encryption , decryption, when try compile using command gcc rsa.c -lcrypto -lssl throws linking errors.

#include <openssl/pem.h> #include <openssl/ssl.h> #include <openssl/rsa.h> #include <openssl/evp.h> #include <openssl/bio.h> #include <openssl/err.h> #include <stdio.h>  int padding = rsa_pkcs1_padding;  rsa * creatersa(unsigned char * key,int public) {     rsa *rsa= null;     bio *keybio ;     keybio = bio_new_mem_buf(key, -1);     if (keybio==null)     {         printf( "failed create key bio");         return 0;     }     if(public)     {         rsa = pem_read_bio_rsa_pubkey(keybio, &rsa,null, null);     }     else     {         rsa = pem_read_bio_rsaprivatekey(keybio, &rsa,null, null);     }     if(rsa == null)     {         printf( "failed create rsa");     }      return rsa; }  int public_encrypt(unsigned char * data,int data_len,unsigned char * key, unsigned char *encrypted) {     rsa * rsa = creatersa(key,1);     int result = rsa_public_encrypt(data_len,data,encrypted,rsa,padding);     return result; } int private_decrypt(unsigned char * enc_data,int data_len,unsigned char * key, unsigned char *decrypted) {     rsa * rsa = creatersa(key,0);     int  result = rsa_private_decrypt(data_len,enc_data,decrypted,rsa,padding);     return result; }   int private_encrypt(unsigned char * data,int data_len,unsigned char * key, unsigned char *encrypted) {     rsa * rsa = creatersa(key,0);     int result = rsa_private_encrypt(data_len,data,encrypted,rsa,padding);     return result; } int public_decrypt(unsigned char * enc_data,int data_len,unsigned char * key, unsigned char *decrypted) {     rsa * rsa = creatersa(key,1);     int  result = rsa_public_decrypt(data_len,enc_data,decrypted,rsa,padding);     return result; }   int main(void){      char plaintext[2048/8] = "hello ravi"; //key length : 2048       char publickey[]="-----begin public key-----\n"\     "miibijanbgkqhkig9w0baqefaaocaq8amiibcgkcaqeay8dbv8prpj/0kkhlgejy\n"\     "ozo2t60eg8l0561g13r29lvmr5hyvgzlgjpmn65+a4xhxinjyipukzrkunapelz+\n"\     "vw1hocoaztwk0z3r26ua8kqyokx9qt/dbcdvsf9wf8grk0ptx9m6r13nvbxvvqap\n"\     "fc9jb9ntzphogm4jieyvlv8flhg9yzovmyd6wwf3aoxk891vqxtr/kqyoq1yp+68\n"\     "i6t4nnq7nwc+unvjqhxnqmqmzu6lwcx8zyg3yh88oaqkuxixkfq+nkvyq1cxamov\n"\     "ppy72+evthkzpmeyhkbn7ciumk5qgltejafwzpe4f4efzj/rc8y8jj2is5kvpjuy\n"\     "wqidaqab\n"\     "-----end public key-----\n";       char privatekey[]="-----begin rsa private key-----\n"\     "miieowibaakcaqeay8dbv8prpj/0kkhlgejyozo2t60eg8l0561g13r29lvmr5hy\n"\     "vgzlgjpmn65+a4xhxinjyipukzrkunapelz+vw1hocoaztwk0z3r26ua8kqyokx9\n"\     "qt/dbcdvsf9wf8grk0ptx9m6r13nvbxvvqapfc9jb9ntzphogm4jieyvlv8flhg9\n"\     "yzovmyd6wwf3aoxk891vqxtr/kqyoq1yp+68i6t4nnq7nwc+unvjqhxnqmqmzu6l\n"\     "wcx8zyg3yh88oaqkuxixkfq+nkvyq1cxamovppy72+evthkzpmeyhkbn7ciumk5q\n"\     "gltejafwzpe4f4efzj/rc8y8jj2is5kvpjuywqidaqabaoibadhg1u1mv1haalx8\n"\     "omz1gn2f4aaw2aos2cm5udcnw1symj+9srikaxjrse/c4o9sw1oxrg1/z6kajv0e\n"\     "n/t008fdlvkhxaiywf93jmovvipmmt8jft6an/y3nmpivgt2inmmejzyniofjkzg\n"\     "x+/vkyvsviszm2fw8nfnkvaqk55yu+grwbzgoes9k+lbyvowcrjkhhz66m4bedkd\n"\     "gvaix6ne5iwmjnxktsqljmcjbtdnxg/xo1/g4kg2p/mo1hlckfe1n5fgbixj3qjl\n"\     "vgvjjzkh1as2ktgapobqzap03738vnyg23isyvft/tearvgtxrmfp7939evjfkpf\n"\     "1wtxudkcgyea7t0dr37zt+dejy+5vm7zsmn97venwqjfwmiulkhga0yu3llasxxu\n"\     "m0outndijenivsx6t3y+agk2f3epbb0az5wz1p1ixs4vktgeqwssbdqcm8lzfdvz\n"\     "upboqnjordikd62xnp5ekieibafop8v2wfpsfe7nnh2u4cpaxnsf9hscgyea2l8d\n"\     "jrde5m9kkn+j4l+adgfebl1igpf3dnupov67bpgiaagi4h25ujzxidkkoa706s0d\n"\     "4xb74zolx11magpmidhlg+sgeqfnoc5le4zwxnyesjh1svgrgt9nbc2vtl6bxcvv\n"\     "wbktec5d6c/qxcai6yw6oyynndp0uznkure1xvmcgybvyycejwqmuavyferfgv+5\n"\     "nwqr5gm+yjmfm2bequpd/hhsloeimm2o8kikvwseryznohktdz7fwgzyxr8fgmog\n"\     "pxq1vk9dxcvzl4trpvau5rmknud9hg9dqg6xibgidr+f79sb8qjywmcfgc1sywoa\n"\     "skjlykz2yt4xnqi3bfid9qkbggqlgryxmxp1qovibrawui55nzhg1xbkwzqpxvz1\n"\     "i3umlv1jljjlhk3eukqtpmc05hoapkwshea0/gobmg404xyayjtdccidtg6hlf96\n"\     "zbja3xapzuxqm62f6dv4fqqzfx0wwhwp5n301n33r0qr6fummkjzmvj1ta8tmzef\n"\     "yinraogbajqioys8rk6exza8ywyljqtlu/yqslbn/4ta36k8dycolnlnxsuox+a5\n"\     "w6z2vefrvqdq4hm4vbzjdi3qfylnktitqlcvgwz+ex44ogxtdtdo7c+gemkwz4xx\n"\     "ujsuvl5+cvjkljzej6qc2wzll94xswl71e41h4ycivnscqxvc4jw\n"\     "-----end rsa private key-----\n";       unsigned char  encrypted[4098]={};     unsigned char decrypted[4098]={};      int encrypted_length= public_encrypt(plaintext,strlen(plaintext),publickey,encrypted);      printf("encrypted length =%d\n",encrypted_length);      int decrypted_length = private_decrypt(encrypted,encrypted_length,privatekey, decrypted);      printf("decrypted text =%s\n",decrypted);     printf("decrypted length =%d\n",decrypted_length);      encrypted_length= private_encrypt(plaintext,strlen(plaintext),privatekey,encrypted);      printf("encrypted length =%d\n",encrypted_length);      printf("decrypted text =%s\n",decrypted);     printf("decrypted length =%d\n",decrypted_length);  } 

linking errors follows:

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21 /usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2 /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: in function `_start': (.text+0x20): undefined reference `main' collect2: error: ld returned 1 exit status 

i have ensured use flags , include relevant header files, still dont know why there linking error.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -