I build OpenSSL-1.0.2n with -g 386 shared --prefix=/usr option (to work with basic assembly version) to generate shared library libcrypto.so.1.0.0.
Inside crypto/aes folder, aes-x86_64.s is generated.
To perform AES encryption and decryption I used following commands in linux terminal.
/usr/bin/openssl enc -aes-128-cbc -in secrets.txt -out cipher.bin
/usr/bin/openssl enc -d -aes-128-cbc -in cipher.bin -out decrypt_cip2.txt
Using GDB, I am able to debug the execution of above command as follow
gdb openssl
gdb> set args enc -d -aes-128-cbc -in cipher.bin -out decrypt_cip2.txt
gdb> b AES_cbc_encrypt
gdb> run
Breakpoint 1, AES_cbc_encrypt () at aes-x86_64.s:1300
1300 cmpq $0,%rdx
From the above output of gdb debugging, it is verified that AES_cbc_encrypt function of aes-x86_64.s file is called.
I need to verify, if I use a C program where system call is used to execute bash script to perform AES decryption, will the AES_cbc_encrypt function of aes-x86_64.s file still called ?
//test.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
char cmd[500];
sprintf(cmd, "/usr/bin/openssl enc -d -aes-128-cbc -in cipher.bin -out decrypt_cip2.txt ");
system(cmd);
return 0;
}
gcc test.c -o test
./test
Will I be wrong, if I say when I execute this C program, it indirectly call openssl library (libcrypto.so) and perform decryption. So it must call AES_cbc_encrypt function of aes-x86_64.o file.
However, when I use GDB to debug this program it is not showing any call to AES_cbc_encrypt function of aes-x86_64.o file. It simply make some calls to /sysdeps/posix/system.c, /sysdeps/unix/sysv/linux/x86_64/sigaction.c etc.
gdb test
gdb> b AES_cbc_encrypt
Function "AES_cbc_encrypt" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (AES_cbc_encrypt) pending.
So, Here is my questions
how to debug the above C code using gdb so that it will stop at breakpoint AES_cbc_encrypt of installed OpenSSL?
Should I use other than system call in C program to run those bash command which will ensure indirectly calling AES_cbc_encrypt function of aes-x86_64.s file?
Any help or link to solve this will be greatly appreciable.
I am using Ubuntu 16.04 , gcc-7.0 with debugging symbol on in OpenSSL version-1.0.2n.