1
0
mirror of https://github.com/fumiama/gofastTEA.git synced 2026-06-28 22:30:24 +08:00

fix: decode panic on malformed index

This commit is contained in:
源文雨
2025-01-06 19:57:45 +09:00
parent 0a22b9b092
commit 32a4953771
10 changed files with 49 additions and 1330 deletions

View File

@@ -1,11 +1,5 @@
# gofastTEA
TEA 编码算法的 PLAN9 汇编优化实现
## 编译逻辑
- 大于等于 1.17 版本且是 amd64使用非`asm`非内联算法
- 大于等于 1.17 版本且不是 amd64使用非`asm`内联算法
- 小于 1.17 版本且是 amd64使用`asm`内联算法
- 小于 1.17 版本且不是 amd64使用非`asm`内联算法
TEA 编码算法的优化实现
## 1.17 版本及以上
代码与[MiraiGo](https://github.com/Mrs4s/MiraiGo/blob/574c4e57b1467225f03936342e477ee0d587a2dc/binary/tea.go)相比,替换了随机算法为`runtime.fastrand`,且简化了`Decrypt`,提升速度如下。
@@ -32,29 +26,7 @@ TEAde/32K-8 164MB/s ± 1% 165MB/s ± 0% +0.37% (p=0.001 n=9+9)
```
## 1.16 版本及以下
使用 PLAN9 汇编编写`Encrypt`,内联编写`Decrypt`,替换了加密算法为`runtime.fastrand`,与[MiraiGo](https://github.com/Mrs4s/MiraiGo/blob/574c4e57b1467225f03936342e477ee0d587a2dc/binary/tea.go)代码同`go1.16`版本下编译相比,提升速度如下new16.txt
```css
name old time/op new time/op delta
TEAen/16-8 252ns ± 0% 227ns ± 0% -10.00% (p=0.000 n=9+10)
TEAen/256-8 1.77µs ± 1% 1.66µs ± 0% -6.28% (p=0.000 n=9+10)
TEAen/4K-8 25.9µs ± 0% 24.9µs ± 1% -3.65% (p=0.000 n=10+10)
TEAen/32K-8 208µs ± 1% 200µs ± 0% -3.70% (p=0.000 n=10+9)
TEAde/16-8 216ns ± 1% 210ns ± 1% -3.04% (p=0.000 n=10+10)
TEAde/256-8 1.71µs ± 1% 1.66µs ± 1% -2.93% (p=0.000 n=10+10)
TEAde/4K-8 25.4µs ± 1% 24.8µs ± 0% -2.36% (p=0.000 n=10+9)
TEAde/32K-8 206µs ± 0% 200µs ± 0% -2.53% (p=0.000 n=9+9)
name old speed new speed delta
TEAen/16-8 63.5MB/s ± 0% 70.6MB/s ± 0% +11.12% (p=0.000 n=9+10)
TEAen/256-8 145MB/s ± 1% 154MB/s ± 0% +6.69% (p=0.000 n=9+10)
TEAen/4K-8 158MB/s ± 0% 164MB/s ± 1% +3.79% (p=0.000 n=10+10)
TEAen/32K-8 158MB/s ± 1% 164MB/s ± 0% +3.84% (p=0.000 n=10+9)
TEAde/16-8 148MB/s ± 1% 152MB/s ± 1% +3.12% (p=0.000 n=10+10)
TEAde/256-8 160MB/s ± 1% 164MB/s ± 1% +3.01% (p=0.000 n=10+10)
TEAde/4K-8 162MB/s ± 1% 166MB/s ± 0% +2.41% (p=0.000 n=10+9)
TEAde/32K-8 159MB/s ± 0% 164MB/s ± 0% +2.60% (p=0.000 n=9+9)
```
另外[MiraiGo](https://github.com/Mrs4s/MiraiGo/blob/574c4e57b1467225f03936342e477ee0d587a2dc/binary/tea.go)本身在`go1.16`版本与在`go1.17`版本下编译相比提升速度如下new17.txt
[MiraiGo](https://github.com/Mrs4s/MiraiGo/blob/574c4e57b1467225f03936342e477ee0d587a2dc/binary/tea.go)本身`go1.16`版本与在`go1.17`版本下编译相比,提升速度如下。
```css
name old time/op new time/op delta
TEAen/16-8 252ns ± 0% 241ns ± 1% -4.09% (p=0.000 n=9+10)
@@ -76,4 +48,3 @@ TEAde/256-8 160MB/s ± 1% 165MB/s ± 1% +3.55% (p=0.000 n=10+10)
TEAde/4K-8 162MB/s ± 1% 168MB/s ± 0% +3.52% (p=0.000 n=10+10)
TEAde/32K-8 159MB/s ± 0% 165MB/s ± 0% +3.45% (p=0.000 n=9+9)
```
可见在编码时,在`go1.16`版本下的某些时候(编码大小在`0-16kb`之间),`gofastTEA``go1.17`版本的`MiraiGo`实现更快,且整体来看,`gofastTEA``go1.16`版本下的执行效率已经可以与`MiraiGo`实现的`go1.17`版本基本持平。