[Cryptography] How to lock registers with GCC?

Tom Mitchell mitch at niftyegg.com
Fri May 9 04:22:59 EDT 2014


On Thu, May 8, 2014 at 4:56 PM,  <tpb-crypto at laposte.net> wrote:
> People,
>
>
> I've been tinkering a while with GCC while trying to follow programming best practices for security, as some of you guys advocate.
>
> While making an encryption routine I stumbled upon the possibility of using a register to keep the key, while erasing it from memory.
...

GCC flag... not that I know..

Not without rewriting the compiler and the ABI used by the compiler.

The issue is system and subroutine calling conventions.
Since registers are scarce the compiler will want
to use all of them that it can.  See: register allocation
   http://en.wikipedia.org/wiki/Register_allocation
and see "register spill compiler"
  http://on-demand.gputechconf.com/gtc-express/2011/presentations/register_spilling.pdf

A subroutine that you write might do what your want
up to the point the system clock interrupts and a time
slice happens.

It is interesting to note that an Application Binary Interface (ABI)
often has the convention that the caller saves registers that it
values (safer) other times the called code must save and restore
registers that it might need (faster ish).  Stack conventions are also
important.

The first place to start is the GCC flag that causes the compiler
to generate and save the assembly language text files.  Inspect
these files and the symbols generated by the code/compiler/assembler/linker

You can replace C code with assembly directives but portable code
and assembler are in conflict.


-- 
  T o m    M i t c h e l l


More information about the cryptography mailing list