---
# System prepended metadata

title: 'linux2021: 9m77fans'

---

# linux2021: 9m77fans

## 測驗 $\alpha - 1$
cd kernel_src/linux-5.4.0/arch/x86/crypto

可以看到chacha-avx2-x86_64.S中有rotl32的應用
這裡使用的是AVX2指令

    # x0 += x1, x3 = rotl32(x3 ^ x0, 16)
    vpaddd      %ymm1,%ymm0,%ymm0
    vpxor       %ymm0,%ymm3,%ymm3
    vpshufb     %ymm5,%ymm3,%ymm3
    
## 測驗 α-2    
我們可以在14行看到rol指令及20行看到ror
gcc編譯時需要開啟O3
```c++=
Dump of assembler code for function main:
   0x00000000000010a0 <+0>:	endbr64 
   0x00000000000010a4 <+4>:	sub    rsp,0x18
   0x00000000000010a8 <+8>:	lea    rdi,[rip+0xf55]        # 0x2004
   0x00000000000010af <+15>:	mov    rax,QWORD PTR fs:0x28
   0x00000000000010b8 <+24>:	mov    QWORD PTR [rsp+0x8],rax
   0x00000000000010bd <+29>:	xor    eax,eax
   0x00000000000010bf <+31>:	lea    rsi,[rsp+0x4]
   0x00000000000010c4 <+36>:	call   0x1090 <__isoc99_scanf@plt>
   0x00000000000010c9 <+41>:	mov    edx,DWORD PTR [rsp+0x4]
   0x00000000000010cd <+45>:	mov    edi,0x1
   0x00000000000010d2 <+50>:	xor    eax,eax
   0x00000000000010d4 <+52>:	lea    rsi,[rip+0xf2c]        # 0x2007
   0x00000000000010db <+59>:	rol    edx,1
   0x00000000000010dd <+61>:	call   0x1080 <__printf_chk@plt>
   0x00000000000010e2 <+66>:	mov    edx,DWORD PTR [rsp+0x4]
   0x00000000000010e6 <+70>:	xor    eax,eax
   0x00000000000010e8 <+72>:	mov    edi,0x1
   0x00000000000010ed <+77>:	lea    rsi,[rip+0xf13]        # 0x2007
   0x00000000000010f4 <+84>:	ror    edx,1
   0x00000000000010f6 <+86>:	call   0x1080 <__printf_chk@plt>
   0x00000000000010fb <+91>:	mov    rax,QWORD PTR [rsp+0x8]
   0x0000000000001100 <+96>:	xor    rax,QWORD PTR fs:0x28
   0x0000000000001109 <+105>:	jne    0x1112 <main+114>
   0x000000000000110b <+107>:	xor    eax,eax
   0x000000000000110d <+109>:	add    rsp,0x18
   0x0000000000001111 <+113>:	ret    
   0x0000000000001112 <+114>:	call   0x1070 <__stack_chk_fail@plt>
End of assembler dump.

```

Ref : https://en.wikipedia.org/wiki/Circular_shift