It's highly necessary to write your own code (optimized assembly) to improve the performance of your program. Using Gcc-03
Actually, this is something you do
not want to do with any cryptography library or any other encryption library, because sometimes, -O3 introduces side-channel attacks that are difficult to find because they are not in the code.
A classic example is removing no-op codes that don't appear to do anything, but stall execution so that someone can't hook up an oscilloscope to your computer to make a graph of the heat coming out of your processor (indicates when an operation is doing a slow operation instead of a fast one e.g. multiply instead of add).
Since the encryption algorithms go through a lot of loops, the same procedure can be used to discover the computational operations done in each loop.
It is better to not build with any optimization at all, and pass these flags to the build process:
CFLAGS="-fPIE -fstack-protector-all -D_FORTIFY_SOURCE=2"
LDFLAGS="-Wl,-z,now -Wl,-z,relro"
Turns on
ASLR (Address Space Layout Randomization), and protects you from buffer overflows and stacks belonging to random functions from being overwritten by bad code.
If you do want faster performance for these kind of programs then you must buy a faster processor, there's no way around it.