How to solve undefined reference to `AES_ctr128_encrypt'











up vote
0
down vote

favorite












Hello I was studying aes 128 encryption with this link https://www.gurutechnologies.net/blog/aes-ctr-encryption-in-c/.
But to run the example main.c
Compiled as follows



gcc main.c -lm -lcrypto -lssl -o mai.c


Then I get the following error:



main.c: In function ‘fencrypt’:
main.c:83:3: warning: implicit declaration of function ‘AES_ctr128_encrypt’; did you mean ‘AES_cfb128_encrypt’? [-Wimplicit-function-declaration]
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
^~~~~~~~~~~~~~~~~~
AES_cfb128_encrypt
/tmp/cc1Gq6eV.o: In function `fencrypt':
main.c:(.text+0x253): undefined reference to `AES_ctr128_encrypt'
/tmp/cc1Gq6eV.o: In function `fdecrypt':
main.c:(.text+0x449): undefined reference to `AES_ctr128_encrypt'
collect2: error: ld returned 1 exit status


To fix this I go into the directory where openssl is located, and in the aes.h header file
I tried to find the AES_ctr128_encrypt function, but it did not
So I updated the openssl and confirmed that there is a AES_ctr128_encrypt function in aes.h and tried to recompile it, but nothing changed. I will leave a question because I could not find a solution anymore.



This is the code for AES_ctr128_encrypt



void fencrypt(char* read, char* write, const unsigned char* enc_key)
{
if(!RAND_bytes(iv, AES_BLOCK_SIZE))
{
fprintf(stderr, "Could not create random bytes.");
exit(1);
}

readFile = fopen(read,"rb"); // The b is required in windows.
writeFile = fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr, "Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fwrite(iv, 1, 8, writeFile); // IV bytes 1 - 8
fwrite("", 1, 8, writeFile); // Fill the last 4 with null bytes 9 - 16

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set encryption key.");
exit(1);
}

init_ctr(&state, iv); //Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}

fclose(writeFile);
fclose(readFile);
}

void fdecrypt(char* read, char* write, const unsigned char* enc_key)
{

readFile=fopen(read,"rb"); // The b is required in windows.
writeFile=fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr,"Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fread(iv, 1, AES_BLOCK_SIZE, readFile);

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set decryption key.");
exit(1);
}

init_ctr(&state, iv);//Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
//printf("%in", state.num);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}
fclose(writeFile);
fclose(readFile);
}


Thank you in advance.










share|improve this question






















  • Did you get exact same compiler warnings including the implicit declaration of function?
    – Antti Haapala
    Nov 14 at 8:05










  • Yes i did.......
    – 이용현
    Nov 14 at 8:40










  • Don't you think that the #includes that you use would be relevant to the question?
    – Antti Haapala
    Nov 14 at 8:46















up vote
0
down vote

favorite












Hello I was studying aes 128 encryption with this link https://www.gurutechnologies.net/blog/aes-ctr-encryption-in-c/.
But to run the example main.c
Compiled as follows



gcc main.c -lm -lcrypto -lssl -o mai.c


Then I get the following error:



main.c: In function ‘fencrypt’:
main.c:83:3: warning: implicit declaration of function ‘AES_ctr128_encrypt’; did you mean ‘AES_cfb128_encrypt’? [-Wimplicit-function-declaration]
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
^~~~~~~~~~~~~~~~~~
AES_cfb128_encrypt
/tmp/cc1Gq6eV.o: In function `fencrypt':
main.c:(.text+0x253): undefined reference to `AES_ctr128_encrypt'
/tmp/cc1Gq6eV.o: In function `fdecrypt':
main.c:(.text+0x449): undefined reference to `AES_ctr128_encrypt'
collect2: error: ld returned 1 exit status


To fix this I go into the directory where openssl is located, and in the aes.h header file
I tried to find the AES_ctr128_encrypt function, but it did not
So I updated the openssl and confirmed that there is a AES_ctr128_encrypt function in aes.h and tried to recompile it, but nothing changed. I will leave a question because I could not find a solution anymore.



This is the code for AES_ctr128_encrypt



void fencrypt(char* read, char* write, const unsigned char* enc_key)
{
if(!RAND_bytes(iv, AES_BLOCK_SIZE))
{
fprintf(stderr, "Could not create random bytes.");
exit(1);
}

readFile = fopen(read,"rb"); // The b is required in windows.
writeFile = fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr, "Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fwrite(iv, 1, 8, writeFile); // IV bytes 1 - 8
fwrite("", 1, 8, writeFile); // Fill the last 4 with null bytes 9 - 16

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set encryption key.");
exit(1);
}

init_ctr(&state, iv); //Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}

fclose(writeFile);
fclose(readFile);
}

void fdecrypt(char* read, char* write, const unsigned char* enc_key)
{

readFile=fopen(read,"rb"); // The b is required in windows.
writeFile=fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr,"Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fread(iv, 1, AES_BLOCK_SIZE, readFile);

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set decryption key.");
exit(1);
}

init_ctr(&state, iv);//Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
//printf("%in", state.num);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}
fclose(writeFile);
fclose(readFile);
}


Thank you in advance.










share|improve this question






















  • Did you get exact same compiler warnings including the implicit declaration of function?
    – Antti Haapala
    Nov 14 at 8:05










  • Yes i did.......
    – 이용현
    Nov 14 at 8:40










  • Don't you think that the #includes that you use would be relevant to the question?
    – Antti Haapala
    Nov 14 at 8:46













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Hello I was studying aes 128 encryption with this link https://www.gurutechnologies.net/blog/aes-ctr-encryption-in-c/.
But to run the example main.c
Compiled as follows



gcc main.c -lm -lcrypto -lssl -o mai.c


Then I get the following error:



main.c: In function ‘fencrypt’:
main.c:83:3: warning: implicit declaration of function ‘AES_ctr128_encrypt’; did you mean ‘AES_cfb128_encrypt’? [-Wimplicit-function-declaration]
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
^~~~~~~~~~~~~~~~~~
AES_cfb128_encrypt
/tmp/cc1Gq6eV.o: In function `fencrypt':
main.c:(.text+0x253): undefined reference to `AES_ctr128_encrypt'
/tmp/cc1Gq6eV.o: In function `fdecrypt':
main.c:(.text+0x449): undefined reference to `AES_ctr128_encrypt'
collect2: error: ld returned 1 exit status


To fix this I go into the directory where openssl is located, and in the aes.h header file
I tried to find the AES_ctr128_encrypt function, but it did not
So I updated the openssl and confirmed that there is a AES_ctr128_encrypt function in aes.h and tried to recompile it, but nothing changed. I will leave a question because I could not find a solution anymore.



This is the code for AES_ctr128_encrypt



void fencrypt(char* read, char* write, const unsigned char* enc_key)
{
if(!RAND_bytes(iv, AES_BLOCK_SIZE))
{
fprintf(stderr, "Could not create random bytes.");
exit(1);
}

readFile = fopen(read,"rb"); // The b is required in windows.
writeFile = fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr, "Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fwrite(iv, 1, 8, writeFile); // IV bytes 1 - 8
fwrite("", 1, 8, writeFile); // Fill the last 4 with null bytes 9 - 16

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set encryption key.");
exit(1);
}

init_ctr(&state, iv); //Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}

fclose(writeFile);
fclose(readFile);
}

void fdecrypt(char* read, char* write, const unsigned char* enc_key)
{

readFile=fopen(read,"rb"); // The b is required in windows.
writeFile=fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr,"Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fread(iv, 1, AES_BLOCK_SIZE, readFile);

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set decryption key.");
exit(1);
}

init_ctr(&state, iv);//Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
//printf("%in", state.num);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}
fclose(writeFile);
fclose(readFile);
}


Thank you in advance.










share|improve this question













Hello I was studying aes 128 encryption with this link https://www.gurutechnologies.net/blog/aes-ctr-encryption-in-c/.
But to run the example main.c
Compiled as follows



gcc main.c -lm -lcrypto -lssl -o mai.c


Then I get the following error:



main.c: In function ‘fencrypt’:
main.c:83:3: warning: implicit declaration of function ‘AES_ctr128_encrypt’; did you mean ‘AES_cfb128_encrypt’? [-Wimplicit-function-declaration]
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);
^~~~~~~~~~~~~~~~~~
AES_cfb128_encrypt
/tmp/cc1Gq6eV.o: In function `fencrypt':
main.c:(.text+0x253): undefined reference to `AES_ctr128_encrypt'
/tmp/cc1Gq6eV.o: In function `fdecrypt':
main.c:(.text+0x449): undefined reference to `AES_ctr128_encrypt'
collect2: error: ld returned 1 exit status


To fix this I go into the directory where openssl is located, and in the aes.h header file
I tried to find the AES_ctr128_encrypt function, but it did not
So I updated the openssl and confirmed that there is a AES_ctr128_encrypt function in aes.h and tried to recompile it, but nothing changed. I will leave a question because I could not find a solution anymore.



This is the code for AES_ctr128_encrypt



void fencrypt(char* read, char* write, const unsigned char* enc_key)
{
if(!RAND_bytes(iv, AES_BLOCK_SIZE))
{
fprintf(stderr, "Could not create random bytes.");
exit(1);
}

readFile = fopen(read,"rb"); // The b is required in windows.
writeFile = fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr, "Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fwrite(iv, 1, 8, writeFile); // IV bytes 1 - 8
fwrite("", 1, 8, writeFile); // Fill the last 4 with null bytes 9 - 16

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set encryption key.");
exit(1);
}

init_ctr(&state, iv); //Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}

fclose(writeFile);
fclose(readFile);
}

void fdecrypt(char* read, char* write, const unsigned char* enc_key)
{

readFile=fopen(read,"rb"); // The b is required in windows.
writeFile=fopen(write,"wb");

if(readFile==NULL)
{
fprintf(stderr,"Read file is null.");
exit(1);
}

if(writeFile==NULL)
{
fprintf(stderr, "Write file is null.");
exit(1);
}

fread(iv, 1, AES_BLOCK_SIZE, readFile);

//Initializing the encryption KEY
if (AES_set_encrypt_key(enc_key, 128, &key) < 0)
{
fprintf(stderr, "Could not set decryption key.");
exit(1);
}

init_ctr(&state, iv);//Counter call
//Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext
while(1)
{
bytes_read = fread(indata, 1, AES_BLOCK_SIZE, readFile);
//printf("%in", state.num);
AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num);

bytes_written = fwrite(outdata, 1, bytes_read, writeFile);
if (bytes_read < AES_BLOCK_SIZE)
{
break;
}
}
fclose(writeFile);
fclose(readFile);
}


Thank you in advance.







c encryption aes






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 at 6:24









이용현

43




43












  • Did you get exact same compiler warnings including the implicit declaration of function?
    – Antti Haapala
    Nov 14 at 8:05










  • Yes i did.......
    – 이용현
    Nov 14 at 8:40










  • Don't you think that the #includes that you use would be relevant to the question?
    – Antti Haapala
    Nov 14 at 8:46


















  • Did you get exact same compiler warnings including the implicit declaration of function?
    – Antti Haapala
    Nov 14 at 8:05










  • Yes i did.......
    – 이용현
    Nov 14 at 8:40










  • Don't you think that the #includes that you use would be relevant to the question?
    – Antti Haapala
    Nov 14 at 8:46
















Did you get exact same compiler warnings including the implicit declaration of function?
– Antti Haapala
Nov 14 at 8:05




Did you get exact same compiler warnings including the implicit declaration of function?
– Antti Haapala
Nov 14 at 8:05












Yes i did.......
– 이용현
Nov 14 at 8:40




Yes i did.......
– 이용현
Nov 14 at 8:40












Don't you think that the #includes that you use would be relevant to the question?
– Antti Haapala
Nov 14 at 8:46




Don't you think that the #includes that you use would be relevant to the question?
– Antti Haapala
Nov 14 at 8:46












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Assuming you are using openssl 1.1.0, see What is exact alternate API instead of AES_ctr128_encrypt from openssl 1.1.0?



You can use CRYPTO_ctr128_encrypt instead of AES_ctr128_encrypt.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294246%2fhow-to-solve-undefined-reference-to-aes-ctr128-encrypt%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Assuming you are using openssl 1.1.0, see What is exact alternate API instead of AES_ctr128_encrypt from openssl 1.1.0?



    You can use CRYPTO_ctr128_encrypt instead of AES_ctr128_encrypt.






    share|improve this answer

























      up vote
      0
      down vote













      Assuming you are using openssl 1.1.0, see What is exact alternate API instead of AES_ctr128_encrypt from openssl 1.1.0?



      You can use CRYPTO_ctr128_encrypt instead of AES_ctr128_encrypt.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Assuming you are using openssl 1.1.0, see What is exact alternate API instead of AES_ctr128_encrypt from openssl 1.1.0?



        You can use CRYPTO_ctr128_encrypt instead of AES_ctr128_encrypt.






        share|improve this answer












        Assuming you are using openssl 1.1.0, see What is exact alternate API instead of AES_ctr128_encrypt from openssl 1.1.0?



        You can use CRYPTO_ctr128_encrypt instead of AES_ctr128_encrypt.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 at 8:46









        sergiopm

        1264




        1264






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53294246%2fhow-to-solve-undefined-reference-to-aes-ctr128-encrypt%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?