From: bg Date: Sat, 8 Dec 2012 10:45:34 +0000 (+0100) Subject: AES code reformatting X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=13dbf0a84670c266c122cb5dcd084b394ce30804;p=avr-crypto-lib.git AES code reformatting --- diff --git a/aes/aes_enc-asm.S b/aes/aes_enc-asm.S index 5b46a2a..77c3336 100644 --- a/aes/aes_enc-asm.S +++ b/aes/aes_enc-asm.S @@ -96,8 +96,10 @@ aes_encrypt_core: mov CTR, r20 clt - .irp param,ST00, ST01, ST02, ST03, ST10, ST11, ST12, ST13, ST20, ST21, ST22, ST23, ST30, ST31, ST32, ST33 - ld \param, Z+ + .irp row, 0, 1, 2, 3 + .irp col, 0, 1, 2, 3 + ld ST\row\col, Z+ + .endr .endr ldi xREDUCER, 0x1b /* load reducer */ @@ -105,31 +107,23 @@ aes_encrypt_core: /* key whitening */ 1: - .irp param,ST00, ST01, ST02, ST03, ST10, ST11, ST12, ST13, ST20, ST21, ST22, ST23, ST30, ST31, ST32, ST33 - ld r0, X+ - eor \param, r0 + + .irp row, 0, 1, 2, 3 + .irp col, 0, 1, 2, 3 + ld r0, X+ + eor ST\row\col, r0 + .endr .endr brtc 2f -exit: +exit: pop r31 pop r30 - st Z+, ST00 - st Z+, ST01 - st Z+, ST02 - st Z+, ST03 - st Z+, ST10 - st Z+, ST11 - st Z+, ST12 - st Z+, ST13 - st Z+, ST20 - st Z+, ST21 - st Z+, ST22 - st Z+, ST23 - st Z+, ST30 - st Z+, ST31 - st Z+, ST32 - st Z+, ST33 + .irp row, 0, 1, 2, 3 + .irp col, 0, 1, 2, 3 + st Z+, ST\row\col + .endr + .endr pop r29 pop r28 pop_range 2, 17 @@ -187,145 +181,43 @@ exit: brtc 2f rjmp 1b 2: - /* mixrow 1 */ - mov r0, ST02 - eor r0, ST03 - mov T2, r0 - - mov T0, ST00 - eor ST00, ST01 - eor r0, ST00 - lsl ST00 - brcc 3f - eor ST00, xREDUCER -3: eor ST00, r0 - eor ST00, T0 - - mov T1, ST01 - eor T1, ST02 - lsl T1 - brcc 3f - eor T1, xREDUCER -3: eor T1, r0 - eor ST01, T1 - - lsl T2 - brcc 3f - eor T2, xREDUCER -3: eor T2, r0 - eor ST02, T2 - - eor T0, ST03 - lsl T0 - brcc 3f - eor T0, xREDUCER -3: eor T0, r0 - eor ST03, T0 - - /* mixrow 2 */ - mov r0, ST12 - eor r0, ST13 - mov T2, r0 - - mov T0, ST10 - eor ST10, ST11 - eor r0, ST10 - lsl ST10 - brcc 3f - eor ST10, xREDUCER -3: eor ST10, r0 - eor ST10, T0 - - mov T1, ST11 - eor T1, ST12 - lsl T1 - brcc 3f - eor T1, xREDUCER -3: eor T1, r0 - eor ST11, T1 - - lsl T2 - brcc 3f - eor T2, xREDUCER -3: eor T2, r0 - eor ST12, T2 - - eor T0, ST13 - lsl T0 - brcc 3f - eor T0, xREDUCER -3: eor T0, r0 - eor ST13, T0 - - /* mixrow 3 */ - mov r0, ST22 - eor r0, ST23 - mov T2, r0 - - mov T0, ST20 - eor ST20, ST21 - eor r0, ST20 - lsl ST20 - brcc 3f - eor ST20, xREDUCER -3: eor ST20, r0 - eor ST20, T0 - - mov T1, ST21 - eor T1, ST22 - lsl T1 - brcc 3f - eor T1, xREDUCER -3: eor T1, r0 - eor ST21, T1 - - lsl T2 - brcc 3f - eor T2, xREDUCER -3: eor T2, r0 - eor ST22, T2 - - eor T0, ST23 - lsl T0 - brcc 3f - eor T0, xREDUCER -3: eor T0, r0 - eor ST23, T0 - - /* mixrow 4 */ - mov r0, ST32 - eor r0, ST33 + /* mixrows */ + .irp row, 0, 1, 2, 3 + mov r0, ST\row\()2 + eor r0, ST\row\()3 mov T2, r0 - - mov T0, ST30 - eor ST30, ST31 - eor r0, ST30 - lsl ST30 + + mov T0, ST\row\()0 + eor ST\row\()0, ST\row\()1 + eor r0, ST\row\()0 + lsl ST\row\()0 brcc 3f - eor ST30, xREDUCER -3: eor ST30, r0 - eor ST30, T0 - - mov T1, ST31 - eor T1, ST32 + eor ST\row\()0, xREDUCER +3: eor ST\row\()0, r0 + eor ST\row\()0, T0 + + mov T1, ST\row\()1 + eor T1, ST\row\()2 lsl T1 brcc 3f eor T1, xREDUCER 3: eor T1, r0 - eor ST31, T1 - + eor ST\row\()1, T1 + lsl T2 brcc 3f eor T2, xREDUCER 3: eor T2, r0 - eor ST32, T2 - - eor T0, ST33 + eor ST\row\()2, T2 + + eor T0, ST\row\()3 lsl T0 brcc 3f eor T0, xREDUCER 3: eor T0, r0 - eor ST33, T0 + eor ST\row\()3, T0 + +.endr /* mix colums (rows) done */ /* add key*/