^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2006 by Joachim Fritschi, <jfritschi@freenet.de> *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) .file "twofish-i586-asm.S"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /* return address at 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define in_blk 12 /* input byte array address parameter*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define out_blk 8 /* output byte array address parameter*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ctx 4 /* Twofish context structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define a_offset 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define b_offset 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define c_offset 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define d_offset 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* Structure of the crypto context struct*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define s0 0 /* S0 Array 256 Words each */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define s1 1024 /* S1 Array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define s2 2048 /* S2 Array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define s3 3072 /* S3 Array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define w 4096 /* 8 whitening keys (word) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define k 4128 /* key 1-32 ( word ) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* define a few register aliases to allow macro substitution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define R0D %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define R0B %al
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define R0H %ah
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define R1D %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define R1B %bl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define R1H %bh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define R2D %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define R2B %cl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define R2H %ch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define R3D %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define R3B %dl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define R3H %dh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* performs input whitening */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define input_whitening(src,context,offset)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) xor w+offset(context), src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* performs input whitening */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define output_whitening(src,context,offset)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) xor w+16+offset(context), src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * a input register containing a (rotated 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * b input register containing b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * c input register containing c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * d input register containing d (already rol $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * operations on a and b are interleaved to increase performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define encrypt_round(a,b,c,d,round)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) push d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) mov s1(%ebp,%edi,4),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) mov s2(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ror $16, b ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) xor s2(%ebp,%edi,4),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ror $16, a ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) xor s3(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) xor s3(%ebp,%edi,4),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) xor (%ebp,%edi,4), %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ror $15, b ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) xor (%ebp,%edi,4), d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) xor s1(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) pop %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) add d ## D, %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) add %esi, d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) add k+round(%ebp), %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) xor %esi, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) rol $15, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) add k+4+round(%ebp),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) xor %edi, d ## D;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * a input register containing a (rotated 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * b input register containing b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * c input register containing c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * d input register containing d (already rol $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * operations on a and b are interleaved to increase performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * last round has different rotations for the output preparation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define encrypt_last_round(a,b,c,d,round)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) push d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) mov s1(%ebp,%edi,4),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) mov s2(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ror $16, b ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) xor s2(%ebp,%edi,4),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ror $16, a ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) xor s3(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) xor s3(%ebp,%edi,4),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) xor (%ebp,%edi,4), %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ror $16, b ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) xor (%ebp,%edi,4), d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) xor s1(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) pop %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) add d ## D, %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) add %esi, d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) add k+round(%ebp), %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) xor %esi, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ror $1, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) add k+4+round(%ebp),d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) xor %edi, d ## D;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * a input register containing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * b input register containing b (rotated 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * c input register containing c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * d input register containing d (already rol $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * operations on a and b are interleaved to increase performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define decrypt_round(a,b,c,d,round)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) push c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) mov (%ebp,%edi,4), c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) mov s3(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ror $16, a ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) xor s1(%ebp,%edi,4),c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ror $16, b ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) xor (%ebp,%edi,4), %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) xor s2(%ebp,%edi,4),c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) xor s1(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ror $15, a ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) xor s3(%ebp,%edi,4),c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) xor s2(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) pop %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) add %esi, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) add c ## D, %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) add k+round(%ebp), c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) xor %edi, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) add k+4+round(%ebp),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) xor %esi, d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) rol $15, d ## D;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * a input register containing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * b input register containing b (rotated 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * c input register containing c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * d input register containing d (already rol $1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * operations on a and b are interleaved to increase performance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * last round has different rotations for the output preparation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define decrypt_last_round(a,b,c,d,round)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) push c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) mov (%ebp,%edi,4), c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) mov s3(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ror $16, a ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) xor s1(%ebp,%edi,4),c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ror $16, b ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) xor (%ebp,%edi,4), %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) movzx a ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) xor s2(%ebp,%edi,4),c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) movzx b ## B, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) xor s1(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) movzx a ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ror $16, a ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) xor s3(%ebp,%edi,4),c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) movzx b ## H, %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) xor s2(%ebp,%edi,4),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) pop %edi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) add %esi, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) add c ## D, %esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) add k+round(%ebp), c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) xor %edi, c ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) add k+4+round(%ebp),%esi;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) xor %esi, d ## D;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ror $1, d ## D;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) SYM_FUNC_START(twofish_enc_blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) push %ebp /* save registers according to calling convention*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) push %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) push %esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) push %edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) mov ctx + 16(%esp), %ebp /* abuse the base pointer: set new base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * pointer to the ctx address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) mov in_blk+16(%esp),%edi /* input address in edi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) mov (%edi), %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) mov b_offset(%edi), %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) mov c_offset(%edi), %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) mov d_offset(%edi), %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) input_whitening(%eax,%ebp,a_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) ror $16, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) input_whitening(%ebx,%ebp,b_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) input_whitening(%ecx,%ebp,c_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) input_whitening(%edx,%ebp,d_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) rol $1, %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) encrypt_round(R0,R1,R2,R3,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) encrypt_round(R2,R3,R0,R1,8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) encrypt_round(R0,R1,R2,R3,2*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) encrypt_round(R2,R3,R0,R1,3*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) encrypt_round(R0,R1,R2,R3,4*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) encrypt_round(R2,R3,R0,R1,5*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) encrypt_round(R0,R1,R2,R3,6*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) encrypt_round(R2,R3,R0,R1,7*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) encrypt_round(R0,R1,R2,R3,8*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) encrypt_round(R2,R3,R0,R1,9*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) encrypt_round(R0,R1,R2,R3,10*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) encrypt_round(R2,R3,R0,R1,11*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) encrypt_round(R0,R1,R2,R3,12*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) encrypt_round(R2,R3,R0,R1,13*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) encrypt_round(R0,R1,R2,R3,14*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) encrypt_last_round(R2,R3,R0,R1,15*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) output_whitening(%eax,%ebp,c_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) output_whitening(%ebx,%ebp,d_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) output_whitening(%ecx,%ebp,a_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) output_whitening(%edx,%ebp,b_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) mov out_blk+16(%esp),%edi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) mov %eax, c_offset(%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) mov %ebx, d_offset(%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) mov %ecx, (%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) mov %edx, b_offset(%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) pop %edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pop %esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) pop %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pop %ebp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) mov $1, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) SYM_FUNC_END(twofish_enc_blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) SYM_FUNC_START(twofish_dec_blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) push %ebp /* save registers according to calling convention*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) push %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) push %esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) push %edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) mov ctx + 16(%esp), %ebp /* abuse the base pointer: set new base
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * pointer to the ctx address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) mov in_blk+16(%esp),%edi /* input address in edi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) mov (%edi), %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) mov b_offset(%edi), %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) mov c_offset(%edi), %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) mov d_offset(%edi), %edx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) output_whitening(%eax,%ebp,a_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) output_whitening(%ebx,%ebp,b_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ror $16, %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) output_whitening(%ecx,%ebp,c_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) output_whitening(%edx,%ebp,d_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) rol $1, %ecx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) decrypt_round(R0,R1,R2,R3,15*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) decrypt_round(R2,R3,R0,R1,14*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) decrypt_round(R0,R1,R2,R3,13*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) decrypt_round(R2,R3,R0,R1,12*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) decrypt_round(R0,R1,R2,R3,11*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) decrypt_round(R2,R3,R0,R1,10*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) decrypt_round(R0,R1,R2,R3,9*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) decrypt_round(R2,R3,R0,R1,8*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) decrypt_round(R0,R1,R2,R3,7*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) decrypt_round(R2,R3,R0,R1,6*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) decrypt_round(R0,R1,R2,R3,5*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) decrypt_round(R2,R3,R0,R1,4*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) decrypt_round(R0,R1,R2,R3,3*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) decrypt_round(R2,R3,R0,R1,2*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) decrypt_round(R0,R1,R2,R3,1*8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) decrypt_last_round(R2,R3,R0,R1,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) input_whitening(%eax,%ebp,c_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) input_whitening(%ebx,%ebp,d_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) input_whitening(%ecx,%ebp,a_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) input_whitening(%edx,%ebp,b_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) mov out_blk+16(%esp),%edi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) mov %eax, c_offset(%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) mov %ebx, d_offset(%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) mov %ecx, (%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) mov %edx, b_offset(%edi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) pop %edi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pop %esi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) pop %ebx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pop %ebp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) mov $1, %eax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) SYM_FUNC_END(twofish_dec_blk)