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 .balign 16
      4  1.1  christos .globl rv64i_zkne_encrypt
      5  1.1  christos .type   rv64i_zkne_encrypt,@function
      6  1.1  christos rv64i_zkne_encrypt:
      7  1.1  christos     addi    sp,sp,-16
      8  1.1  christos     sd      x8,8(sp)
      9  1.1  christos     sd      x9,0(sp)
     10  1.1  christos 
     11  1.1  christos     # Load input to block cipher
     12  1.1  christos     ld      x6,0(x10)
     13  1.1  christos     ld      x7,8(x10)
     14  1.1  christos 
     15  1.1  christos     # Load key
     16  1.1  christos     ld      x13,0(x12)
     17  1.1  christos     ld      x14,8(x12)
     18  1.1  christos 
     19  1.1  christos     # Load number of rounds
     20  1.1  christos     lwu     x30,240(x12)
     21  1.1  christos 
     22  1.1  christos     # initial transformation
     23  1.1  christos     xor     x6,x6,x13
     24  1.1  christos     xor     x7,x7,x14
     25  1.1  christos 
     26  1.1  christos     # The main loop only executes the first N-1 rounds.
     27  1.1  christos     add     x30,x30,-1
     28  1.1  christos 
     29  1.1  christos     # Do Nr - 1 rounds (final round is special)
     30  1.1  christos 1:
     31  1.1  christos     .word 913507379
     32  1.1  christos     .word 912491699
     33  1.1  christos 
     34  1.1  christos     # Update key ptr to point to next key in schedule
     35  1.1  christos     add     x12,x12,16
     36  1.1  christos 
     37  1.1  christos     # Grab next key in schedule
     38  1.1  christos     ld      x13,0(x12)
     39  1.1  christos     ld      x14,8(x12)
     40  1.1  christos     xor     x6,x8,x13
     41  1.1  christos     xor     x7,x9,x14
     42  1.1  christos 
     43  1.1  christos     add     x30,x30,-1
     44  1.1  christos     bgtz    x30,1b
     45  1.1  christos 
     46  1.1  christos     # final round
     47  1.1  christos     .word 846398515
     48  1.1  christos     .word 845382835
     49  1.1  christos 
     50  1.1  christos     # since not added 16 before
     51  1.1  christos     ld      x13,16(x12)
     52  1.1  christos     ld      x14,24(x12)
     53  1.1  christos     xor     x6,x8,x13
     54  1.1  christos     xor     x7,x9,x14
     55  1.1  christos 
     56  1.1  christos     sd      x6,0(x11)
     57  1.1  christos     sd      x7,8(x11)
     58  1.1  christos 
     59  1.1  christos     # Pop registers and return
     60  1.1  christos     ld      x8,8(sp)
     61  1.1  christos     ld      x9,0(sp)
     62  1.1  christos     addi    sp,sp,16
     63  1.1  christos     ret
     64  1.1  christos .text
     65  1.1  christos .balign 16
     66  1.1  christos .globl rv64i_zknd_decrypt
     67  1.1  christos .type   rv64i_zknd_decrypt,@function
     68  1.1  christos rv64i_zknd_decrypt:
     69  1.1  christos     addi    sp,sp,-16
     70  1.1  christos     sd      x8,8(sp)
     71  1.1  christos     sd      x9,0(sp)
     72  1.1  christos 
     73  1.1  christos     # Load input to block cipher
     74  1.1  christos     ld      x6,0(x10)
     75  1.1  christos     ld      x7,8(x10)
     76  1.1  christos 
     77  1.1  christos     # Load number of rounds
     78  1.1  christos     lwu     x30,240(x12)
     79  1.1  christos 
     80  1.1  christos     # Load the last key
     81  1.1  christos     slli    x13,x30,4
     82  1.1  christos     add     x12,x12,x13
     83  1.1  christos     ld      x13,0(x12)
     84  1.1  christos     ld      x14,8(x12)
     85  1.1  christos 
     86  1.1  christos     xor     x6,x6,x13
     87  1.1  christos     xor     x7,x7,x14
     88  1.1  christos 
     89  1.1  christos     # The main loop only executes the first N-1 rounds.
     90  1.1  christos     add     x30,x30,-1
     91  1.1  christos 
     92  1.1  christos     # Do Nr - 1 rounds (final round is special)
     93  1.1  christos 1:
     94  1.1  christos     .word 1047725107
     95  1.1  christos     .word 1046709427
     96  1.1  christos 
     97  1.1  christos     # Update key ptr to point to next key in schedule
     98  1.1  christos     add     x12,x12,-16
     99  1.1  christos 
    100  1.1  christos     # Grab next key in schedule
    101  1.1  christos     ld      x13,0(x12)
    102  1.1  christos     ld      x14,8(x12)
    103  1.1  christos     xor     x6,x8,x13
    104  1.1  christos     xor     x7,x9,x14
    105  1.1  christos 
    106  1.1  christos     add     x30,x30,-1
    107  1.1  christos     bgtz    x30,1b
    108  1.1  christos 
    109  1.1  christos     # final round
    110  1.1  christos     .word 980616243
    111  1.1  christos     .word 979600563
    112  1.1  christos 
    113  1.1  christos     add     x12,x12,-16
    114  1.1  christos     ld      x13,0(x12)
    115  1.1  christos     ld      x14,8(x12)
    116  1.1  christos     xor     x6,x8,x13
    117  1.1  christos     xor     x7,x9,x14
    118  1.1  christos 
    119  1.1  christos     sd      x6,0(x11)
    120  1.1  christos     sd      x7,8(x11)
    121  1.1  christos     # Pop registers and return
    122  1.1  christos     ld      x8,8(sp)
    123  1.1  christos     ld      x9,0(sp)
    124  1.1  christos     addi    sp,sp,16
    125  1.1  christos     ret
    126  1.1  christos .text
    127  1.1  christos .balign 16
    128  1.1  christos .globl rv64i_zkne_set_encrypt_key
    129  1.1  christos .type   rv64i_zkne_set_encrypt_key,@function
    130  1.1  christos rv64i_zkne_set_encrypt_key:
    131  1.1  christos     addi    sp,sp,-16
    132  1.1  christos     sd      x8,0(sp)
    133  1.1  christos     bnez    x10,1f        # if (!userKey || !key) return -1;
    134  1.1  christos     bnez    x12,1f
    135  1.1  christos     li      a0,-1
    136  1.1  christos     ret
    137  1.1  christos 1:
    138  1.1  christos     # Determine number of rounds from key size in bits
    139  1.1  christos     li      x6,128
    140  1.1  christos     bne     x11,x6,1f
    141  1.1  christos     li      x7,10          # key->rounds = 10 if bits == 128
    142  1.1  christos     sw      x7,240(x12)  # store key->rounds
    143  1.1  christos     ld      x6,0(x10)
    144  1.1  christos     ld      x7,8(x10)
    145  1.1  christos     sd      x6,0(x12)
    146  1.1  christos     sd      x7,8(x12)
    147  1.1  christos     .word 822318099
    148  1.1  christos     .word 2120483635
    149  1.1  christos     .word 2121466803
    150  1.1  christos     add         x12,x12,16
    151  1.1  christos     sd          x6,0(x12)
    152  1.1  christos     sd          x7,8(x12)
    153  1.1  christos     .word 823366675
    154  1.1  christos     .word 2120483635
    155  1.1  christos     .word 2121466803
    156  1.1  christos     add         x12,x12,16
    157  1.1  christos     sd          x6,0(x12)
    158  1.1  christos     sd          x7,8(x12)
    159  1.1  christos     .word 824415251
    160  1.1  christos     .word 2120483635
    161  1.1  christos     .word 2121466803
    162  1.1  christos     add         x12,x12,16
    163  1.1  christos     sd          x6,0(x12)
    164  1.1  christos     sd          x7,8(x12)
    165  1.1  christos     .word 825463827
    166  1.1  christos     .word 2120483635
    167  1.1  christos     .word 2121466803
    168  1.1  christos     add         x12,x12,16
    169  1.1  christos     sd          x6,0(x12)
    170  1.1  christos     sd          x7,8(x12)
    171  1.1  christos     .word 826512403
    172  1.1  christos     .word 2120483635
    173  1.1  christos     .word 2121466803
    174  1.1  christos     add         x12,x12,16
    175  1.1  christos     sd          x6,0(x12)
    176  1.1  christos     sd          x7,8(x12)
    177  1.1  christos     .word 827560979
    178  1.1  christos     .word 2120483635
    179  1.1  christos     .word 2121466803
    180  1.1  christos     add         x12,x12,16
    181  1.1  christos     sd          x6,0(x12)
    182  1.1  christos     sd          x7,8(x12)
    183  1.1  christos     .word 828609555
    184  1.1  christos     .word 2120483635
    185  1.1  christos     .word 2121466803
    186  1.1  christos     add         x12,x12,16
    187  1.1  christos     sd          x6,0(x12)
    188  1.1  christos     sd          x7,8(x12)
    189  1.1  christos     .word 829658131
    190  1.1  christos     .word 2120483635
    191  1.1  christos     .word 2121466803
    192  1.1  christos     add         x12,x12,16
    193  1.1  christos     sd          x6,0(x12)
    194  1.1  christos     sd          x7,8(x12)
    195  1.1  christos     .word 830706707
    196  1.1  christos     .word 2120483635
    197  1.1  christos     .word 2121466803
    198  1.1  christos     add         x12,x12,16
    199  1.1  christos     sd          x6,0(x12)
    200  1.1  christos     sd          x7,8(x12)
    201  1.1  christos     .word 831755283
    202  1.1  christos     .word 2120483635
    203  1.1  christos     .word 2121466803
    204  1.1  christos     add         x12,x12,16
    205  1.1  christos     sd          x6,0(x12)
    206  1.1  christos     sd          x7,8(x12)
    207  1.1  christos 
    208  1.1  christos     j       4f
    209  1.1  christos 1:
    210  1.1  christos     li      x6,192
    211  1.1  christos     bne     x11,x6,2f
    212  1.1  christos     li      x7,12          # key->rounds = 12 if bits == 192
    213  1.1  christos     sw      x7,240(x12)  # store key->rounds
    214  1.1  christos     ld      x6,0(x10)
    215  1.1  christos     ld      x7,8(x10)
    216  1.1  christos     ld      x8,16(x10)
    217  1.1  christos     sd      x6,0(x12)
    218  1.1  christos     sd      x7,8(x12)
    219  1.1  christos     sd      x8,16(x12)
    220  1.1  christos     .word 822351507
    221  1.1  christos     .word 2120647475
    222  1.1  christos     .word 2121466803
    223  1.1  christos     .word 2122548275
    224  1.1  christos     add         x12,x12,24
    225  1.1  christos     sd          x6,0(x12)
    226  1.1  christos     sd          x7,8(x12)
    227  1.1  christos     sd          x8,16(x12)
    228  1.1  christos     .word 823400083
    229  1.1  christos     .word 2120647475
    230  1.1  christos     .word 2121466803
    231  1.1  christos     .word 2122548275
    232  1.1  christos     add         x12,x12,24
    233  1.1  christos     sd          x6,0(x12)
    234  1.1  christos     sd          x7,8(x12)
    235  1.1  christos     sd          x8,16(x12)
    236  1.1  christos     .word 824448659
    237  1.1  christos     .word 2120647475
    238  1.1  christos     .word 2121466803
    239  1.1  christos     .word 2122548275
    240  1.1  christos     add         x12,x12,24
    241  1.1  christos     sd          x6,0(x12)
    242  1.1  christos     sd          x7,8(x12)
    243  1.1  christos     sd          x8,16(x12)
    244  1.1  christos     .word 825497235
    245  1.1  christos     .word 2120647475
    246  1.1  christos     .word 2121466803
    247  1.1  christos     .word 2122548275
    248  1.1  christos     add         x12,x12,24
    249  1.1  christos     sd          x6,0(x12)
    250  1.1  christos     sd          x7,8(x12)
    251  1.1  christos     sd          x8,16(x12)
    252  1.1  christos     .word 826545811
    253  1.1  christos     .word 2120647475
    254  1.1  christos     .word 2121466803
    255  1.1  christos     .word 2122548275
    256  1.1  christos     add         x12,x12,24
    257  1.1  christos     sd          x6,0(x12)
    258  1.1  christos     sd          x7,8(x12)
    259  1.1  christos     sd          x8,16(x12)
    260  1.1  christos     .word 827594387
    261  1.1  christos     .word 2120647475
    262  1.1  christos     .word 2121466803
    263  1.1  christos     .word 2122548275
    264  1.1  christos     add         x12,x12,24
    265  1.1  christos     sd          x6,0(x12)
    266  1.1  christos     sd          x7,8(x12)
    267  1.1  christos     sd          x8,16(x12)
    268  1.1  christos     .word 828642963
    269  1.1  christos     .word 2120647475
    270  1.1  christos     .word 2121466803
    271  1.1  christos     .word 2122548275
    272  1.1  christos     add         x12,x12,24
    273  1.1  christos     sd          x6,0(x12)
    274  1.1  christos     sd          x7,8(x12)
    275  1.1  christos     sd          x8,16(x12)
    276  1.1  christos     .word 829691539
    277  1.1  christos     .word 2120647475
    278  1.1  christos     .word 2121466803
    279  1.1  christos     add         x12,x12,24
    280  1.1  christos     sd          x6,0(x12)
    281  1.1  christos     sd          x7,8(x12)
    282  1.1  christos 
    283  1.1  christos     j       4f
    284  1.1  christos 2:
    285  1.1  christos     li      x7,14          # key->rounds = 14 if bits == 256
    286  1.1  christos     li      x6,256
    287  1.1  christos     beq     x11,x6,3f
    288  1.1  christos     li      a0,-2           # If bits != 128, 192, or 256, return -2
    289  1.1  christos     j       5f
    290  1.1  christos 3:
    291  1.1  christos     sw      x7,240(x12)  # store key->rounds
    292  1.1  christos     ld      x6,0(x10)
    293  1.1  christos     ld      x7,8(x10)
    294  1.1  christos     ld      x8,16(x10)
    295  1.1  christos     ld      x13,24(x10)
    296  1.1  christos     sd      x6,0(x12)
    297  1.1  christos     sd      x7,8(x12)
    298  1.1  christos     sd      x8,16(x12)
    299  1.1  christos     sd      x13,24(x12)
    300  1.1  christos     .word 822515475
    301  1.1  christos     .word 2120680243
    302  1.1  christos     .word 2121466803
    303  1.1  christos     add         x12,x12,32
    304  1.1  christos     sd          x6,0(x12)
    305  1.1  christos     sd          x7,8(x12)
    306  1.1  christos     .word 832804627
    307  1.1  christos     .word 2122777651
    308  1.1  christos     .word 2127824563
    309  1.1  christos     sd          x8,16(x12)
    310  1.1  christos     sd          x13,24(x12)
    311  1.1  christos     .word 823564051
    312  1.1  christos     .word 2120680243
    313  1.1  christos     .word 2121466803
    314  1.1  christos     add         x12,x12,32
    315  1.1  christos     sd          x6,0(x12)
    316  1.1  christos     sd          x7,8(x12)
    317  1.1  christos     .word 832804627
    318  1.1  christos     .word 2122777651
    319  1.1  christos     .word 2127824563
    320  1.1  christos     sd          x8,16(x12)
    321  1.1  christos     sd          x13,24(x12)
    322  1.1  christos     .word 824612627
    323  1.1  christos     .word 2120680243
    324  1.1  christos     .word 2121466803
    325  1.1  christos     add         x12,x12,32
    326  1.1  christos     sd          x6,0(x12)
    327  1.1  christos     sd          x7,8(x12)
    328  1.1  christos     .word 832804627
    329  1.1  christos     .word 2122777651
    330  1.1  christos     .word 2127824563
    331  1.1  christos     sd          x8,16(x12)
    332  1.1  christos     sd          x13,24(x12)
    333  1.1  christos     .word 825661203
    334  1.1  christos     .word 2120680243
    335  1.1  christos     .word 2121466803
    336  1.1  christos     add         x12,x12,32
    337  1.1  christos     sd          x6,0(x12)
    338  1.1  christos     sd          x7,8(x12)
    339  1.1  christos     .word 832804627
    340  1.1  christos     .word 2122777651
    341  1.1  christos     .word 2127824563
    342  1.1  christos     sd          x8,16(x12)
    343  1.1  christos     sd          x13,24(x12)
    344  1.1  christos     .word 826709779
    345  1.1  christos     .word 2120680243
    346  1.1  christos     .word 2121466803
    347  1.1  christos     add         x12,x12,32
    348  1.1  christos     sd          x6,0(x12)
    349  1.1  christos     sd          x7,8(x12)
    350  1.1  christos     .word 832804627
    351  1.1  christos     .word 2122777651
    352  1.1  christos     .word 2127824563
    353  1.1  christos     sd          x8,16(x12)
    354  1.1  christos     sd          x13,24(x12)
    355  1.1  christos     .word 827758355
    356  1.1  christos     .word 2120680243
    357  1.1  christos     .word 2121466803
    358  1.1  christos     add         x12,x12,32
    359  1.1  christos     sd          x6,0(x12)
    360  1.1  christos     sd          x7,8(x12)
    361  1.1  christos     .word 832804627
    362  1.1  christos     .word 2122777651
    363  1.1  christos     .word 2127824563
    364  1.1  christos     sd          x8,16(x12)
    365  1.1  christos     sd          x13,24(x12)
    366  1.1  christos     .word 828806931
    367  1.1  christos     .word 2120680243
    368  1.1  christos     .word 2121466803
    369  1.1  christos     add         x12,x12,32
    370  1.1  christos     sd          x6,0(x12)
    371  1.1  christos     sd          x7,8(x12)
    372  1.1  christos 
    373  1.1  christos 4:  # return 0
    374  1.1  christos     li      a0,0
    375  1.1  christos 5:  # return a0
    376  1.1  christos     ld      x8,0(sp)
    377  1.1  christos     addi    sp,sp,16
    378  1.1  christos     ret
    379  1.1  christos .text
    380  1.1  christos .balign 16
    381  1.1  christos .globl rv64i_zknd_set_decrypt_key
    382  1.1  christos .type   rv64i_zknd_set_decrypt_key,@function
    383  1.1  christos rv64i_zknd_set_decrypt_key:
    384  1.1  christos     addi    sp,sp,-16
    385  1.1  christos     sd      x8,0(sp)
    386  1.1  christos     bnez    x10,1f        # if (!userKey || !key) return -1;
    387  1.1  christos     bnez    x12,1f
    388  1.1  christos     li      a0,-1
    389  1.1  christos     ret
    390  1.1  christos 1:
    391  1.1  christos     # Determine number of rounds from key size in bits
    392  1.1  christos     li      x6,128
    393  1.1  christos     bne     x11,x6,1f
    394  1.1  christos     li      x7,10          # key->rounds = 10 if bits == 128
    395  1.1  christos     sw      x7,240(x12)  # store key->rounds
    396  1.1  christos     ld      x6,0(x10)
    397  1.1  christos     ld      x7,8(x10)
    398  1.1  christos     sd      x6,0(x12)
    399  1.1  christos     sd      x7,8(x12)
    400  1.1  christos     .word 822318099
    401  1.1  christos     .word 2120483635
    402  1.1  christos     .word 2121466803
    403  1.1  christos     add         x12,x12,16
    404  1.1  christos     .word 805508115
    405  1.1  christos     sd          x8,0(x12)
    406  1.1  christos     .word 805540883
    407  1.1  christos     sd          x8,8(x12)
    408  1.1  christos     .word 823366675
    409  1.1  christos     .word 2120483635
    410  1.1  christos     .word 2121466803
    411  1.1  christos     add         x12,x12,16
    412  1.1  christos     .word 805508115
    413  1.1  christos     sd          x8,0(x12)
    414  1.1  christos     .word 805540883
    415  1.1  christos     sd          x8,8(x12)
    416  1.1  christos     .word 824415251
    417  1.1  christos     .word 2120483635
    418  1.1  christos     .word 2121466803
    419  1.1  christos     add         x12,x12,16
    420  1.1  christos     .word 805508115
    421  1.1  christos     sd          x8,0(x12)
    422  1.1  christos     .word 805540883
    423  1.1  christos     sd          x8,8(x12)
    424  1.1  christos     .word 825463827
    425  1.1  christos     .word 2120483635
    426  1.1  christos     .word 2121466803
    427  1.1  christos     add         x12,x12,16
    428  1.1  christos     .word 805508115
    429  1.1  christos     sd          x8,0(x12)
    430  1.1  christos     .word 805540883
    431  1.1  christos     sd          x8,8(x12)
    432  1.1  christos     .word 826512403
    433  1.1  christos     .word 2120483635
    434  1.1  christos     .word 2121466803
    435  1.1  christos     add         x12,x12,16
    436  1.1  christos     .word 805508115
    437  1.1  christos     sd          x8,0(x12)
    438  1.1  christos     .word 805540883
    439  1.1  christos     sd          x8,8(x12)
    440  1.1  christos     .word 827560979
    441  1.1  christos     .word 2120483635
    442  1.1  christos     .word 2121466803
    443  1.1  christos     add         x12,x12,16
    444  1.1  christos     .word 805508115
    445  1.1  christos     sd          x8,0(x12)
    446  1.1  christos     .word 805540883
    447  1.1  christos     sd          x8,8(x12)
    448  1.1  christos     .word 828609555
    449  1.1  christos     .word 2120483635
    450  1.1  christos     .word 2121466803
    451  1.1  christos     add         x12,x12,16
    452  1.1  christos     .word 805508115
    453  1.1  christos     sd          x8,0(x12)
    454  1.1  christos     .word 805540883
    455  1.1  christos     sd          x8,8(x12)
    456  1.1  christos     .word 829658131
    457  1.1  christos     .word 2120483635
    458  1.1  christos     .word 2121466803
    459  1.1  christos     add         x12,x12,16
    460  1.1  christos     .word 805508115
    461  1.1  christos     sd          x8,0(x12)
    462  1.1  christos     .word 805540883
    463  1.1  christos     sd          x8,8(x12)
    464  1.1  christos     .word 830706707
    465  1.1  christos     .word 2120483635
    466  1.1  christos     .word 2121466803
    467  1.1  christos     add         x12,x12,16
    468  1.1  christos     .word 805508115
    469  1.1  christos     sd          x8,0(x12)
    470  1.1  christos     .word 805540883
    471  1.1  christos     sd          x8,8(x12)
    472  1.1  christos     .word 831755283
    473  1.1  christos     .word 2120483635
    474  1.1  christos     .word 2121466803
    475  1.1  christos     add         x12,x12,16
    476  1.1  christos     sd          x6,0(x12)
    477  1.1  christos     sd          x7,8(x12)
    478  1.1  christos 
    479  1.1  christos     j       4f
    480  1.1  christos 1:
    481  1.1  christos     li      x6,192
    482  1.1  christos     bne     x11,x6,2f
    483  1.1  christos     li      x7,12          # key->rounds = 12 if bits == 192
    484  1.1  christos     sw      x7,240(x12)  # store key->rounds
    485  1.1  christos     ld      x6,0(x10)
    486  1.1  christos     ld      x7,8(x10)
    487  1.1  christos     ld      x8,16(x10)
    488  1.1  christos     sd      x6,0(x12)
    489  1.1  christos     sd      x7,8(x12)
    490  1.1  christos     .word 805574291
    491  1.1  christos     sd      x13,16(x12)
    492  1.1  christos     .word 822351507
    493  1.1  christos     .word 2120647475
    494  1.1  christos     .word 2121466803
    495  1.1  christos     add         x12,x12,24
    496  1.1  christos     .word 805508755
    497  1.1  christos     sd          x13,0(x12)
    498  1.1  christos     .word 805541523
    499  1.1  christos     sd          x13,8(x12)
    500  1.1  christos     # the reason is in ke192enc
    501  1.1  christos     .word 2122548275
    502  1.1  christos     .word 805574291
    503  1.1  christos     sd          x13,16(x12)
    504  1.1  christos     .word 823400083
    505  1.1  christos     .word 2120647475
    506  1.1  christos     .word 2121466803
    507  1.1  christos     add         x12,x12,24
    508  1.1  christos     .word 805508755
    509  1.1  christos     sd          x13,0(x12)
    510  1.1  christos     .word 805541523
    511  1.1  christos     sd          x13,8(x12)
    512  1.1  christos     # the reason is in ke192enc
    513  1.1  christos     .word 2122548275
    514  1.1  christos     .word 805574291
    515  1.1  christos     sd          x13,16(x12)
    516  1.1  christos     .word 824448659
    517  1.1  christos     .word 2120647475
    518  1.1  christos     .word 2121466803
    519  1.1  christos     add         x12,x12,24
    520  1.1  christos     .word 805508755
    521  1.1  christos     sd          x13,0(x12)
    522  1.1  christos     .word 805541523
    523  1.1  christos     sd          x13,8(x12)
    524  1.1  christos     # the reason is in ke192enc
    525  1.1  christos     .word 2122548275
    526  1.1  christos     .word 805574291
    527  1.1  christos     sd          x13,16(x12)
    528  1.1  christos     .word 825497235
    529  1.1  christos     .word 2120647475
    530  1.1  christos     .word 2121466803
    531  1.1  christos     add         x12,x12,24
    532  1.1  christos     .word 805508755
    533  1.1  christos     sd          x13,0(x12)
    534  1.1  christos     .word 805541523
    535  1.1  christos     sd          x13,8(x12)
    536  1.1  christos     # the reason is in ke192enc
    537  1.1  christos     .word 2122548275
    538  1.1  christos     .word 805574291
    539  1.1  christos     sd          x13,16(x12)
    540  1.1  christos     .word 826545811
    541  1.1  christos     .word 2120647475
    542  1.1  christos     .word 2121466803
    543  1.1  christos     add         x12,x12,24
    544  1.1  christos     .word 805508755
    545  1.1  christos     sd          x13,0(x12)
    546  1.1  christos     .word 805541523
    547  1.1  christos     sd          x13,8(x12)
    548  1.1  christos     # the reason is in ke192enc
    549  1.1  christos     .word 2122548275
    550  1.1  christos     .word 805574291
    551  1.1  christos     sd          x13,16(x12)
    552  1.1  christos     .word 827594387
    553  1.1  christos     .word 2120647475
    554  1.1  christos     .word 2121466803
    555  1.1  christos     add         x12,x12,24
    556  1.1  christos     .word 805508755
    557  1.1  christos     sd          x13,0(x12)
    558  1.1  christos     .word 805541523
    559  1.1  christos     sd          x13,8(x12)
    560  1.1  christos     # the reason is in ke192enc
    561  1.1  christos     .word 2122548275
    562  1.1  christos     .word 805574291
    563  1.1  christos     sd          x13,16(x12)
    564  1.1  christos     .word 828642963
    565  1.1  christos     .word 2120647475
    566  1.1  christos     .word 2121466803
    567  1.1  christos     add         x12,x12,24
    568  1.1  christos     .word 805508755
    569  1.1  christos     sd          x13,0(x12)
    570  1.1  christos     .word 805541523
    571  1.1  christos     sd          x13,8(x12)
    572  1.1  christos     # the reason is in ke192enc
    573  1.1  christos     .word 2122548275
    574  1.1  christos     .word 805574291
    575  1.1  christos     sd          x13,16(x12)
    576  1.1  christos     .word 829691539
    577  1.1  christos     .word 2120647475
    578  1.1  christos     .word 2121466803
    579  1.1  christos     add         x12,x12,24
    580  1.1  christos     sd          x6,0(x12)
    581  1.1  christos     sd          x7,8(x12)
    582  1.1  christos 
    583  1.1  christos     j       4f
    584  1.1  christos 2:
    585  1.1  christos     li      x7,14          # key->rounds = 14 if bits == 256
    586  1.1  christos     li      x6,256
    587  1.1  christos     beq     x11,x6,3f
    588  1.1  christos     li      a0,-2           # If bits != 128, 192, or 256, return -2
    589  1.1  christos     j       5f
    590  1.1  christos 3:
    591  1.1  christos     sw      x7,240(x12)  # store key->rounds
    592  1.1  christos     ld      x6,0(x10)
    593  1.1  christos     ld      x7,8(x10)
    594  1.1  christos     ld      x8,16(x10)
    595  1.1  christos     ld      x13,24(x10)
    596  1.1  christos     sd      x6,0(x12)
    597  1.1  christos     sd      x7,8(x12)
    598  1.1  christos     .word 805574419
    599  1.1  christos     sd      x14,16(x12)
    600  1.1  christos     .word 805738259
    601  1.1  christos     sd      x14,24(x12)
    602  1.1  christos     .word 822515475
    603  1.1  christos     .word 2120680243
    604  1.1  christos     .word 2121466803
    605  1.1  christos     add         x12,x12,32
    606  1.1  christos     .word 832804627
    607  1.1  christos     .word 2122777651
    608  1.1  christos     .word 2127824563
    609  1.1  christos     .word 805508883
    610  1.1  christos     sd          x14,0(x12)
    611  1.1  christos     .word 805541651
    612  1.1  christos     sd          x14,8(x12)
    613  1.1  christos     .word 805574419
    614  1.1  christos     sd          x14,16(x12)
    615  1.1  christos     .word 805738259
    616  1.1  christos     sd          x14,24(x12)
    617  1.1  christos     .word 823564051
    618  1.1  christos     .word 2120680243
    619  1.1  christos     .word 2121466803
    620  1.1  christos     add         x12,x12,32
    621  1.1  christos     .word 832804627
    622  1.1  christos     .word 2122777651
    623  1.1  christos     .word 2127824563
    624  1.1  christos     .word 805508883
    625  1.1  christos     sd          x14,0(x12)
    626  1.1  christos     .word 805541651
    627  1.1  christos     sd          x14,8(x12)
    628  1.1  christos     .word 805574419
    629  1.1  christos     sd          x14,16(x12)
    630  1.1  christos     .word 805738259
    631  1.1  christos     sd          x14,24(x12)
    632  1.1  christos     .word 824612627
    633  1.1  christos     .word 2120680243
    634  1.1  christos     .word 2121466803
    635  1.1  christos     add         x12,x12,32
    636  1.1  christos     .word 832804627
    637  1.1  christos     .word 2122777651
    638  1.1  christos     .word 2127824563
    639  1.1  christos     .word 805508883
    640  1.1  christos     sd          x14,0(x12)
    641  1.1  christos     .word 805541651
    642  1.1  christos     sd          x14,8(x12)
    643  1.1  christos     .word 805574419
    644  1.1  christos     sd          x14,16(x12)
    645  1.1  christos     .word 805738259
    646  1.1  christos     sd          x14,24(x12)
    647  1.1  christos     .word 825661203
    648  1.1  christos     .word 2120680243
    649  1.1  christos     .word 2121466803
    650  1.1  christos     add         x12,x12,32
    651  1.1  christos     .word 832804627
    652  1.1  christos     .word 2122777651
    653  1.1  christos     .word 2127824563
    654  1.1  christos     .word 805508883
    655  1.1  christos     sd          x14,0(x12)
    656  1.1  christos     .word 805541651
    657  1.1  christos     sd          x14,8(x12)
    658  1.1  christos     .word 805574419
    659  1.1  christos     sd          x14,16(x12)
    660  1.1  christos     .word 805738259
    661  1.1  christos     sd          x14,24(x12)
    662  1.1  christos     .word 826709779
    663  1.1  christos     .word 2120680243
    664  1.1  christos     .word 2121466803
    665  1.1  christos     add         x12,x12,32
    666  1.1  christos     .word 832804627
    667  1.1  christos     .word 2122777651
    668  1.1  christos     .word 2127824563
    669  1.1  christos     .word 805508883
    670  1.1  christos     sd          x14,0(x12)
    671  1.1  christos     .word 805541651
    672  1.1  christos     sd          x14,8(x12)
    673  1.1  christos     .word 805574419
    674  1.1  christos     sd          x14,16(x12)
    675  1.1  christos     .word 805738259
    676  1.1  christos     sd          x14,24(x12)
    677  1.1  christos     .word 827758355
    678  1.1  christos     .word 2120680243
    679  1.1  christos     .word 2121466803
    680  1.1  christos     add         x12,x12,32
    681  1.1  christos     .word 832804627
    682  1.1  christos     .word 2122777651
    683  1.1  christos     .word 2127824563
    684  1.1  christos     .word 805508883
    685  1.1  christos     sd          x14,0(x12)
    686  1.1  christos     .word 805541651
    687  1.1  christos     sd          x14,8(x12)
    688  1.1  christos     .word 805574419
    689  1.1  christos     sd          x14,16(x12)
    690  1.1  christos     .word 805738259
    691  1.1  christos     sd          x14,24(x12)
    692  1.1  christos     .word 828806931
    693  1.1  christos     .word 2120680243
    694  1.1  christos     .word 2121466803
    695  1.1  christos     add         x12,x12,32
    696  1.1  christos     sd          x6,0(x12)
    697  1.1  christos     sd          x7,8(x12)
    698  1.1  christos     # last two one dropped
    699  1.1  christos 
    700  1.1  christos 4:  # return 0
    701  1.1  christos     li      a0,0
    702  1.1  christos 5:  # return a0
    703  1.1  christos     ld      x8,0(sp)
    704  1.1  christos     addi    sp,sp,16
    705  1.1  christos     ret
    706