aboutsummaryrefslogtreecommitdiff
path: root/internal/pathiv/pathiv_test.go
blob: 0cecba1afa47aa006190acabfc78b7dff8e90a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package pathiv

import (
	"bytes"
	"encoding/hex"
	"testing"
)

// TestBlockIV makes sure we don't change the block iv derivation algorithm "BlockIV()"
// inadvertedly.
func TestBlockIV(t *testing.T) {
	b0 := make([]byte, 16)
	b0x := BlockIV(b0, 0)
	if !bytes.Equal(b0, b0x) {
		t.Errorf("b0x should be equal to b0")
	}
	b27 := BlockIV(b0, 0x27)
	expected, _ := hex.DecodeString("00000000000000000000000000000027")
	if !bytes.Equal(b27, expected) {
		t.Error()
	}
	bff := bytes.Repeat([]byte{0xff}, 16)
	b28 := BlockIV(bff, 0x28)
	expected, _ = hex.DecodeString("ffffffffffffffff0000000000000027")
	if !bytes.Equal(b28, expected) {
		t.Errorf("\nhave=%s\nwant=%s", hex.EncodeToString(b28), hex.EncodeToString(expected))
	}
}