2021-05-24 15:28:02 +02:00
|
|
|
package contentenc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2021-08-23 15:05:15 +02:00
|
|
|
"github.com/rfjakob/gocryptfs/v2/internal/cryptocore"
|
2021-05-24 15:28:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestSizeToSize tests CipherSizeToPlainSize and PlainSizeToCipherSize
|
|
|
|
func TestSizeToSize(t *testing.T) {
|
|
|
|
key := make([]byte, cryptocore.KeyLen)
|
2021-09-10 12:14:19 +02:00
|
|
|
cc := cryptocore.New(key, cryptocore.BackendGoGCM, DefaultIVBits, true)
|
|
|
|
ce := New(cc, DefaultBS)
|
2021-05-24 15:28:02 +02:00
|
|
|
|
|
|
|
const rangeMax = 10000
|
|
|
|
|
2021-05-26 18:28:59 +02:00
|
|
|
// y values in this order:
|
|
|
|
// 0 ... CipherSizeToPlainSize
|
|
|
|
// 1 ... PlainSizeToCipherSize
|
|
|
|
// 2 ... PlainOffToCipherOff
|
|
|
|
var yTable [rangeMax][3]uint64
|
2021-05-24 15:28:02 +02:00
|
|
|
|
|
|
|
// Calculate values
|
2021-05-26 18:28:59 +02:00
|
|
|
for x := range yTable {
|
|
|
|
yTable[x][0] = ce.CipherSizeToPlainSize(uint64(x))
|
|
|
|
yTable[x][1] = ce.PlainSizeToCipherSize(uint64(x))
|
|
|
|
yTable[x][2] = ce.PlainOffToCipherOff(uint64(x))
|
2021-05-24 15:28:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Print data table
|
2021-05-26 18:28:59 +02:00
|
|
|
fmt.Print("x\tCipherSizeToPlainSize\tPlainSizeToCipherSize\tPlainOffToCipherOff\n")
|
|
|
|
for x := range yTable {
|
|
|
|
if x > 1 && x < rangeMax-1 {
|
2021-05-24 15:28:02 +02:00
|
|
|
// If the point before has value-1 and the point after has value+1,
|
|
|
|
// it is not interesting. Don't print it out.
|
2021-05-26 18:28:59 +02:00
|
|
|
interesting := false
|
|
|
|
for i := 0; i <= 2; i++ {
|
|
|
|
if yTable[x-1][i]+1 != yTable[x][i] && yTable[x][i]+1 != yTable[x+1][i]+1 {
|
|
|
|
interesting = true
|
|
|
|
}
|
|
|
|
// Monotonicity check
|
|
|
|
if yTable[x][i] < yTable[x-1][i] {
|
|
|
|
t.Errorf("column %d is non-monotonic!", i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !interesting {
|
2021-05-24 15:28:02 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2021-05-26 18:28:59 +02:00
|
|
|
fmt.Printf("%d\t%d\t%d\t%d\n", x, yTable[x][0], yTable[x][1], yTable[x][2])
|
2021-05-24 15:28:02 +02:00
|
|
|
}
|
|
|
|
}
|