Home | History | Annotate | Line # | Download | only in riscv64
      1  1.1  christos #include <machine/asm.h>
      2  1.1  christos .text
      3  1.1  christos .p2align 3
      4  1.1  christos .globl rv64i_zvkb_zvkned_ctr32_encrypt_blocks
      5  1.1  christos .type rv64i_zvkb_zvkned_ctr32_encrypt_blocks,@function
      6  1.1  christos rv64i_zvkb_zvkned_ctr32_encrypt_blocks:
      7  1.1  christos     beqz a2, 1f
      8  1.1  christos 
      9  1.1  christos     # Load number of rounds
     10  1.1  christos     lwu t0, 240(a3)
     11  1.1  christos     li t1, 14
     12  1.1  christos     li t2, 12
     13  1.1  christos     li t3, 10
     14  1.1  christos 
     15  1.1  christos     slli t5, a2, 2
     16  1.1  christos 
     17  1.1  christos     beq t0, t1, ctr32_encrypt_blocks_256
     18  1.1  christos     beq t0, t2, ctr32_encrypt_blocks_192
     19  1.1  christos     beq t0, t3, ctr32_encrypt_blocks_128
     20  1.1  christos 
     21  1.1  christos 1:
     22  1.1  christos     ret
     23  1.1  christos 
     24  1.1  christos .size rv64i_zvkb_zvkned_ctr32_encrypt_blocks,.-rv64i_zvkb_zvkned_ctr32_encrypt_blocks
     25  1.1  christos .p2align 3
     26  1.1  christos ctr32_encrypt_blocks_128:
     27  1.1  christos     # Load all 11 round keys to v1-v11 registers.
     28  1.1  christos     .word 3439489111
     29  1.1  christos     .word 34005127
     30  1.1  christos     addi a3, a3, 16
     31  1.1  christos     .word 34005255
     32  1.1  christos     addi a3, a3, 16
     33  1.1  christos     .word 34005383
     34  1.1  christos     addi a3, a3, 16
     35  1.1  christos     .word 34005511
     36  1.1  christos     addi a3, a3, 16
     37  1.1  christos     .word 34005639
     38  1.1  christos     addi a3, a3, 16
     39  1.1  christos     .word 34005767
     40  1.1  christos     addi a3, a3, 16
     41  1.1  christos     .word 34005895
     42  1.1  christos     addi a3, a3, 16
     43  1.1  christos     .word 34006023
     44  1.1  christos     addi a3, a3, 16
     45  1.1  christos     .word 34006151
     46  1.1  christos     addi a3, a3, 16
     47  1.1  christos     .word 34006279
     48  1.1  christos     addi a3, a3, 16
     49  1.1  christos     .word 34006407
     50  1.1  christos 
     51  1.1  christos         # Setup mask into v0
     52  1.1  christos     # The mask pattern for 4*N-th elements
     53  1.1  christos     # mask v0: [000100010001....]
     54  1.1  christos     # Note:
     55  1.1  christos     #   We could setup the mask just for the maximum element length instead of
     56  1.1  christos     #   the VLMAX.
     57  1.1  christos     li t0, 0b10001000
     58  1.1  christos     .word 201356247
     59  1.1  christos     .word 1577238615
     60  1.1  christos     # Load IV.
     61  1.1  christos     # v31:[IV0, IV1, IV2, big-endian count]
     62  1.1  christos     .word 3439489111
     63  1.1  christos     .word 34041735
     64  1.1  christos     # Convert the big-endian counter into little-endian.
     65  1.1  christos     .word 3305271383
     66  1.1  christos     .word 1240772567
     67  1.1  christos     # Splat the IV to v16
     68  1.1  christos     .word 221212759
     69  1.1  christos     .word 1577072727
     70  1.1  christos     .word 2817763447
     71  1.1  christos     # Prepare the ctr pattern into v20
     72  1.1  christos     # v20: [x, x, x, 0, x, x, x, 1, x, x, x, 2, ...]
     73  1.1  christos     .word 1342712407
     74  1.1  christos     # v16:[IV0, IV1, IV2, count+0, IV0, IV1, IV2, count+1, ...]
     75  1.1  christos     .word 86998743
     76  1.1  christos     .word 17434711
     77  1.1  christos 
     78  1.1  christos 
     79  1.1  christos     ##### AES body
     80  1.1  christos     j 2f
     81  1.1  christos 1:
     82  1.1  christos     .word 86998743
     83  1.1  christos     # Increase ctr in v16.
     84  1.1  christos     .word 17811543
     85  1.1  christos 2:
     86  1.1  christos     # Load plaintext into v20
     87  1.1  christos     .word 33909255
     88  1.1  christos     slli t0, t4, 2
     89  1.1  christos     srli t6, t4, 2
     90  1.1  christos     sub t5, t5, t4
     91  1.1  christos     add a0, a0, t0
     92  1.1  christos     # Prepare the AES ctr input into v24.
     93  1.1  christos     # The ctr data uses big-endian form.
     94  1.1  christos     .word 1577585751
     95  1.1  christos     .word 1233431639
     96  1.1  christos 
     97  1.1  christos     .word 2786307191
     98  1.1  christos     .word 2787191927
     99  1.1  christos     .word 2788240503
    100  1.1  christos     .word 2789289079
    101  1.1  christos     .word 2790337655
    102  1.1  christos     .word 2791386231
    103  1.1  christos     .word 2792434807
    104  1.1  christos     .word 2793483383
    105  1.1  christos     .word 2794531959
    106  1.1  christos     .word 2795580535
    107  1.1  christos     .word 2796661879
    108  1.1  christos 
    109  1.1  christos     # ciphertext
    110  1.1  christos     .word 797576279
    111  1.1  christos 
    112  1.1  christos     # Store the ciphertext.
    113  1.1  christos     .word 33942567
    114  1.1  christos     add a1, a1, t0
    115  1.1  christos 
    116  1.1  christos     bnez t5, 1b
    117  1.1  christos 
    118  1.1  christos     ret
    119  1.1  christos .size ctr32_encrypt_blocks_128,.-ctr32_encrypt_blocks_128
    120  1.1  christos .p2align 3
    121  1.1  christos ctr32_encrypt_blocks_192:
    122  1.1  christos     # Load all 13 round keys to v1-v13 registers.
    123  1.1  christos     .word 3439489111
    124  1.1  christos     .word 34005127
    125  1.1  christos     addi a3, a3, 16
    126  1.1  christos     .word 34005255
    127  1.1  christos     addi a3, a3, 16
    128  1.1  christos     .word 34005383
    129  1.1  christos     addi a3, a3, 16
    130  1.1  christos     .word 34005511
    131  1.1  christos     addi a3, a3, 16
    132  1.1  christos     .word 34005639
    133  1.1  christos     addi a3, a3, 16
    134  1.1  christos     .word 34005767
    135  1.1  christos     addi a3, a3, 16
    136  1.1  christos     .word 34005895
    137  1.1  christos     addi a3, a3, 16
    138  1.1  christos     .word 34006023
    139  1.1  christos     addi a3, a3, 16
    140  1.1  christos     .word 34006151
    141  1.1  christos     addi a3, a3, 16
    142  1.1  christos     .word 34006279
    143  1.1  christos     addi a3, a3, 16
    144  1.1  christos     .word 34006407
    145  1.1  christos     addi a3, a3, 16
    146  1.1  christos     .word 34006535
    147  1.1  christos     addi a3, a3, 16
    148  1.1  christos     .word 34006663
    149  1.1  christos 
    150  1.1  christos         # Setup mask into v0
    151  1.1  christos     # The mask pattern for 4*N-th elements
    152  1.1  christos     # mask v0: [000100010001....]
    153  1.1  christos     # Note:
    154  1.1  christos     #   We could setup the mask just for the maximum element length instead of
    155  1.1  christos     #   the VLMAX.
    156  1.1  christos     li t0, 0b10001000
    157  1.1  christos     .word 201356247
    158  1.1  christos     .word 1577238615
    159  1.1  christos     # Load IV.
    160  1.1  christos     # v31:[IV0, IV1, IV2, big-endian count]
    161  1.1  christos     .word 3439489111
    162  1.1  christos     .word 34041735
    163  1.1  christos     # Convert the big-endian counter into little-endian.
    164  1.1  christos     .word 3305271383
    165  1.1  christos     .word 1240772567
    166  1.1  christos     # Splat the IV to v16
    167  1.1  christos     .word 221212759
    168  1.1  christos     .word 1577072727
    169  1.1  christos     .word 2817763447
    170  1.1  christos     # Prepare the ctr pattern into v20
    171  1.1  christos     # v20: [x, x, x, 0, x, x, x, 1, x, x, x, 2, ...]
    172  1.1  christos     .word 1342712407
    173  1.1  christos     # v16:[IV0, IV1, IV2, count+0, IV0, IV1, IV2, count+1, ...]
    174  1.1  christos     .word 86998743
    175  1.1  christos     .word 17434711
    176  1.1  christos 
    177  1.1  christos 
    178  1.1  christos     ##### AES body
    179  1.1  christos     j 2f
    180  1.1  christos 1:
    181  1.1  christos     .word 86998743
    182  1.1  christos     # Increase ctr in v16.
    183  1.1  christos     .word 17811543
    184  1.1  christos 2:
    185  1.1  christos     # Load plaintext into v20
    186  1.1  christos     .word 33909255
    187  1.1  christos     slli t0, t4, 2
    188  1.1  christos     srli t6, t4, 2
    189  1.1  christos     sub t5, t5, t4
    190  1.1  christos     add a0, a0, t0
    191  1.1  christos     # Prepare the AES ctr input into v24.
    192  1.1  christos     # The ctr data uses big-endian form.
    193  1.1  christos     .word 1577585751
    194  1.1  christos     .word 1233431639
    195  1.1  christos 
    196  1.1  christos     .word 2786307191
    197  1.1  christos     .word 2787191927
    198  1.1  christos     .word 2788240503
    199  1.1  christos     .word 2789289079
    200  1.1  christos     .word 2790337655
    201  1.1  christos     .word 2791386231
    202  1.1  christos     .word 2792434807
    203  1.1  christos     .word 2793483383
    204  1.1  christos     .word 2794531959
    205  1.1  christos     .word 2795580535
    206  1.1  christos     .word 2796629111
    207  1.1  christos     .word 2797677687
    208  1.1  christos     .word 2798759031
    209  1.1  christos 
    210  1.1  christos     # ciphertext
    211  1.1  christos     .word 797576279
    212  1.1  christos 
    213  1.1  christos     # Store the ciphertext.
    214  1.1  christos     .word 33942567
    215  1.1  christos     add a1, a1, t0
    216  1.1  christos 
    217  1.1  christos     bnez t5, 1b
    218  1.1  christos 
    219  1.1  christos     ret
    220  1.1  christos .size ctr32_encrypt_blocks_192,.-ctr32_encrypt_blocks_192
    221  1.1  christos .p2align 3
    222  1.1  christos ctr32_encrypt_blocks_256:
    223  1.1  christos     # Load all 15 round keys to v1-v15 registers.
    224  1.1  christos     .word 3439489111
    225  1.1  christos     .word 34005127
    226  1.1  christos     addi a3, a3, 16
    227  1.1  christos     .word 34005255
    228  1.1  christos     addi a3, a3, 16
    229  1.1  christos     .word 34005383
    230  1.1  christos     addi a3, a3, 16
    231  1.1  christos     .word 34005511
    232  1.1  christos     addi a3, a3, 16
    233  1.1  christos     .word 34005639
    234  1.1  christos     addi a3, a3, 16
    235  1.1  christos     .word 34005767
    236  1.1  christos     addi a3, a3, 16
    237  1.1  christos     .word 34005895
    238  1.1  christos     addi a3, a3, 16
    239  1.1  christos     .word 34006023
    240  1.1  christos     addi a3, a3, 16
    241  1.1  christos     .word 34006151
    242  1.1  christos     addi a3, a3, 16
    243  1.1  christos     .word 34006279
    244  1.1  christos     addi a3, a3, 16
    245  1.1  christos     .word 34006407
    246  1.1  christos     addi a3, a3, 16
    247  1.1  christos     .word 34006535
    248  1.1  christos     addi a3, a3, 16
    249  1.1  christos     .word 34006663
    250  1.1  christos     addi a3, a3, 16
    251  1.1  christos     .word 34006791
    252  1.1  christos     addi a3, a3, 16
    253  1.1  christos     .word 34006919
    254  1.1  christos 
    255  1.1  christos         # Setup mask into v0
    256  1.1  christos     # The mask pattern for 4*N-th elements
    257  1.1  christos     # mask v0: [000100010001....]
    258  1.1  christos     # Note:
    259  1.1  christos     #   We could setup the mask just for the maximum element length instead of
    260  1.1  christos     #   the VLMAX.
    261  1.1  christos     li t0, 0b10001000
    262  1.1  christos     .word 201356247
    263  1.1  christos     .word 1577238615
    264  1.1  christos     # Load IV.
    265  1.1  christos     # v31:[IV0, IV1, IV2, big-endian count]
    266  1.1  christos     .word 3439489111
    267  1.1  christos     .word 34041735
    268  1.1  christos     # Convert the big-endian counter into little-endian.
    269  1.1  christos     .word 3305271383
    270  1.1  christos     .word 1240772567
    271  1.1  christos     # Splat the IV to v16
    272  1.1  christos     .word 221212759
    273  1.1  christos     .word 1577072727
    274  1.1  christos     .word 2817763447
    275  1.1  christos     # Prepare the ctr pattern into v20
    276  1.1  christos     # v20: [x, x, x, 0, x, x, x, 1, x, x, x, 2, ...]
    277  1.1  christos     .word 1342712407
    278  1.1  christos     # v16:[IV0, IV1, IV2, count+0, IV0, IV1, IV2, count+1, ...]
    279  1.1  christos     .word 86998743
    280  1.1  christos     .word 17434711
    281  1.1  christos 
    282  1.1  christos 
    283  1.1  christos     ##### AES body
    284  1.1  christos     j 2f
    285  1.1  christos 1:
    286  1.1  christos     .word 86998743
    287  1.1  christos     # Increase ctr in v16.
    288  1.1  christos     .word 17811543
    289  1.1  christos 2:
    290  1.1  christos     # Load plaintext into v20
    291  1.1  christos     .word 33909255
    292  1.1  christos     slli t0, t4, 2
    293  1.1  christos     srli t6, t4, 2
    294  1.1  christos     sub t5, t5, t4
    295  1.1  christos     add a0, a0, t0
    296  1.1  christos     # Prepare the AES ctr input into v24.
    297  1.1  christos     # The ctr data uses big-endian form.
    298  1.1  christos     .word 1577585751
    299  1.1  christos     .word 1233431639
    300  1.1  christos 
    301  1.1  christos     .word 2786307191
    302  1.1  christos     .word 2787191927
    303  1.1  christos     .word 2788240503
    304  1.1  christos     .word 2789289079
    305  1.1  christos     .word 2790337655
    306  1.1  christos     .word 2791386231
    307  1.1  christos     .word 2792434807
    308  1.1  christos     .word 2793483383
    309  1.1  christos     .word 2794531959
    310  1.1  christos     .word 2795580535
    311  1.1  christos     .word 2796629111
    312  1.1  christos     .word 2797677687
    313  1.1  christos     .word 2798726263
    314  1.1  christos     .word 2799774839
    315  1.1  christos     .word 2800856183
    316  1.1  christos 
    317  1.1  christos     # ciphertext
    318  1.1  christos     .word 797576279
    319  1.1  christos 
    320  1.1  christos     # Store the ciphertext.
    321  1.1  christos     .word 33942567
    322  1.1  christos     add a1, a1, t0
    323  1.1  christos 
    324  1.1  christos     bnez t5, 1b
    325  1.1  christos 
    326  1.1  christos     ret
    327  1.1  christos .size ctr32_encrypt_blocks_256,.-ctr32_encrypt_blocks_256
    328