assist.h 2.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
;
; **********************************************
; * PHOTON-Beetle                              *
; * Authenticated Encryption and Hash Family   *
; *                                            *
; * Assembly implementation for 8-bit AVR CPU  *
; * Version 1.0 2020 by PHOTON-Beetle Team     *
; **********************************************
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Bitslice
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.MACRO Reorder_8_bits i0, i1, i2, i3, i4
    ror \i0
    ror \i1
    ror \i0
    ror \i2
    ror \i0
    ror \i3
    ror \i0
    ror \i4 
    ror \i0
    ror \i1
    ror \i0
    ror \i2
    ror \i0
    ror \i3
    ror \i0
    ror \i4 
.ENDM

.MACRO InvReorder_8_bits i0, i1, i2, i3, i4
    ror \i1
    ror \i0
    ror \i2
    ror \i0
    ror \i3
    ror \i0
    ror \i4 
    ror \i0
    ror \i1
    ror \i0
    ror \i2
    ror \i0
    ror \i3
    ror \i0
    ror \i4 
    ror \i0
.ENDM

; require XH:XL be the address of the input
Load_Reorder_32_bits:
    ldi cnt1, 4
reorder_8_bits_loop:
    ld rmp, X+
    Reorder_8_bits rmp, x0, x1, x2, x3
    dec cnt1
    brne reorder_8_bits_loop
ret

; require YH:YL be the address of the output
invReorder_Store_32_bits:
    ldi cnt1, 4
invreorder_8_bits_loop:
    InvReorder_8_bits rmp, x0, x1, x2, x3
    st Y+, rmp
    dec cnt1
    brne invreorder_8_bits_loop
ret

; require XH:XL be the address of the input
; require YH:YL be the address of the output
Load_Reorder_Store_128_bits:
    ldi cnt0, 4
reorder_32_bits_loop:
    rcall Load_Reorder_32_bits
    st Y+, x0
    st Y+, x1
    st Y+, x2
    st Y+, x3
    dec cnt0
    brne reorder_32_bits_loop
ret

; require XH:XL be the address of the input
; require YH:YL be the address of the output
Load_invReorder_Store_128_bits:
    ldi cnt0, 4
invreorder_32_bits_loop:
    ld x0, X+
    ld x1, X+
    ld x2, X+
    ld x3, X+
    rcall invReorder_Store_32_bits
    dec cnt0
    brne invreorder_32_bits_loop
ret

.macro PUSH_ALL
push    r2
push    r3
push    r4
push    r5
push    r6
push    r7
push    r8
push    r9
push    r10
push    r11
push    r12
push    r13
push    r14
push    r15
push    r16
push    r17
push    r28
push    r29
.endm

.macro POP_ALL
pop    r29
pop    r28
pop    r17
pop    r16
pop    r15
pop    r14
pop    r13
pop    r12
pop    r11
pop    r10
pop    r9
pop    r8
pop    r7
pop    r6
pop    r5
pop    r4
pop    r3
pop    r2
clr    r1
.endm