feat: 新增XTS/CCM流式与KDF能力,补充安全测试并更新README/CHANGELOG

This commit is contained in:
2026-03-18 13:43:18 +08:00
parent e89350b56a
commit 4fa79744e8
44 changed files with 4636 additions and 77 deletions
+4 -3
View File
@@ -6,6 +6,7 @@ import (
"errors"
"io"
"os"
"strings"
)
var (
@@ -192,12 +193,12 @@ func Base85Encode(bstr []byte) string {
}
func Base85Decode(str string) ([]byte, error) {
out := make([]byte, len(str))
n, _, err := ascii85.Decode(out, []byte(str), true)
dec := ascii85.NewDecoder(strings.NewReader(str))
out, err := io.ReadAll(dec)
if err != nil {
return nil, err
}
return out[:n], nil
return out, nil
}
func Base85EncodeFile(src, dst string, progress func(float64)) error {
+33
View File
@@ -96,3 +96,36 @@ func TestBase64AndBase85FileRoundTrip(t *testing.T) {
t.Fatalf("base85 file roundtrip mismatch")
}
}
func TestBase85RoundTripEdgeLengths(t *testing.T) {
for n := 0; n <= 128; n++ {
plain := make([]byte, n)
for i := range plain {
plain[i] = byte((i*37 + n) % 256)
}
e := Base85Encode(plain)
d, err := Base85Decode(e)
if err != nil {
t.Fatalf("Base85Decode failed at len=%d: %v", n, err)
}
if !bytes.Equal(d, plain) {
t.Fatalf("base85 mismatch at len=%d", n)
}
}
}
func TestBase91RoundTripEdgeLengths(t *testing.T) {
for n := 0; n <= 256; n++ {
plain := make([]byte, n)
for i := range plain {
plain[i] = byte((i*53 + n) % 256)
}
e := Base91Encode(plain)
d := Base91Decode(e)
if !bytes.Equal(d, plain) {
t.Fatalf("base91 mismatch at len=%d", n)
}
}
}