Super Spatial Optimized Code

There are key standalone algorithms, particularly those related to cryptography, such as AES, RSA, SHA1, etc., which you can find on the Internet on the Internet.

Some of them are written as nice and portable clean C.

Some of them are recorded quickly - often with macros and explicit expansions.

As far as I can tell, no one is trying to be particularly super-small, so I put up with writing my own - explicitly decrypted AES128 and SHA1 for ARM THUMB2. (I checked by compiling everything that I can find for my target machine with GCC with -Os and -mthumb, etc.)

What patterns and tricks can I use for this?

Are there compilers / tools capable of folding code?

+3
source share
2 answers

It depends on what kind of space you are trying to optimize: code or data. There are essentially three variations of AES128 that are commonly used, each of which differs in the amount of pre-computed search table space.

  • The fastest version uses 4k, which are arranged in four 32-bit x 256 lookup tables (commonly called T-tables). If you can afford such a volume of data space, then the only instructions in this version are EORs to combine the results of the table, they will be collapsed into a very small piece of code.
  • SBox 8- 256 x 256. , .
  • () , AES, . , , .
+2

( ): , , , aes128 , ?

aes128, , , , - , . (- ) , .

ARM gcc :

-Os   Optimize for size.  

     -Os enables all -O2 optimizations that do not typically 
      increase code size. It also performs further optimizations
      designed to reduce code size.
+4

Source: https://habr.com/ru/post/1748313/


All Articles