CODE OPTIMIZATION
The summary of the changes performed are:
- The data copy is performed using for loop and to optimize this memcopy and memset function was used.
- To load and store 32bit integers from/to 8bit integers built-in swap functions were used. The swap operation can be seen in the functions ISHAResult() and F().
- Loop unrolling is performed which reduces the time. This can be observed in F() function.
- Assembly code usage will help optimize the code. The assembly code was written for the function ISHAProcessMessageBlock().
- Unnecessary code which would not run was removed.
- Length High was removed and only length low was used for buffer calculation and corrupted check is removed. This can be observed in ISHAResult and ISHAinput respectively.
- The ISHAReset and ISHAInput functions required to be calculated once for inner padding and outer padding.Hence static structures were used for optimization.
Results:
Before Optimisation code size - 21056 bytes
Before Optimisation run time - 8744ms
After Optimisation code Size - 19468 bytes
After Opitimised run time - 1393ms
Debug Mode:
In debug code under optimisation code size is 20776 and run time is 1396 milliseconds
Release Mode:
In release mode under optimisation code size is 19468 and run time is 1393 milliseconds
Extra Credit:
- Optimized the code size with assembly which reduced the time to 1393 ms