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.
c encryption aes
add a comment |
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.
c encryption aes
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#include
s that you use would be relevant to the question?
– Antti Haapala
Nov 14 at 8:46
add a comment |
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.
c encryption aes
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
c encryption aes
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#include
s that you use would be relevant to the question?
– Antti Haapala
Nov 14 at 8:46
add a comment |
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#include
s 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
#include
s that you use would be relevant to the question?– Antti Haapala
Nov 14 at 8:46
Don't you think that the
#include
s that you use would be relevant to the question?– Antti Haapala
Nov 14 at 8:46
add a comment |
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
.
add a comment |
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
.
add a comment |
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
.
add a comment |
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
.
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
.
answered Nov 14 at 8:46
sergiopm
1264
1264
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
#include
s that you use would be relevant to the question?– Antti Haapala
Nov 14 at 8:46