Page 255 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 255
Unit 12: Refactoring
12.5 Complexity Metrics Analysis Notes
Using the heuristics mentioned earlier, we selected and ordered transformations to use with
AES. Rather than examining the effects of each transformation separately, we grouped the
transformations into the following 14 blocks:
1. Loop rerolling for major loops in the encryption and decryption functions
2. Reversal of word packing to use four-byte arrays
3. Reversal of table lookups
4. Packing four words into a state/block
5. Reversal of inline subroutines for major the encryption and decryption functions
6. Reversal of inline functions for key expansion subprograms
7. Moving statements into conditionals to reveal three distinct execution paths followed by
procedure splitting
8. Adjustment of loop forms
9. Reversal of additional inline functions
10. Loop rerolling for sequential state updates
11. Procedure splitting
12. Adjustment of intermediate variables
13. Adjustment of loop forms; and
14. Additional procedure splitting.
Blocks 7-11 were for the subprogram that set up the key schedule for encryption, and blocks
12-14 were for the subprogram that modified the key schedule for decryption. As well as the
main transformations, each block of transformations involved smaller transformations that
modified redundant or intermediate computations and storage.
As part of determining whether further refactoring was required, we periodically attempted the
proofs and determined the source-code metrics. Some of the results of the effect of applying the
transformations on the values of the metrics are (shown in Figure 12.4). The histograms show
the values of different metrics after the application of the 14 blocks of transformations where
block 0 the original code is:
As the transformations were applied, the primary element metric, code size, dropped. The
non-comment, non-annotation lines dropped from over 1365 to 412 mainly because loops were
rerolled and precompiled tables was removed. The other transformations had little additional
effect on length. We hypothesize that fewer source code lines will usually result in shorter
annotations and verification conditions.
The average McCabe cyclamate complexities also declined as transformations were applied,
dropping from 2.4 to 1.48. Statement complexity, essential complexity, etc. also declined. There
is no evidence that these complexity metrics are related to the difficulty of verification, but their
reduction suggests that the refectories program might be easier to analyses.
Since we would not undertake full annotation until refactoring was complete, we had no way
to assess the feasibility of the proofs. To gain some insight, we set the post conditions for all
subprograms to true for each version of the refectories code, generated verification conditions
LOVELY PROFESSIONAL UNIVERSITY 249