Esempio n. 1
0
func fastAES_initialize(key []byte) cipher.Block {
	if !(len(key) == 16 || len(key) == 32) {
		panic("AES must use 128 or 256 bits in a key")
	}
	aes_schedule := make([]byte, 4096)
	C.aes_setup((*C.uchar)(unsafe.Pointer(&(key[0]))), C.int(len(key)), 0,
		(*C.symmetric_key)(unsafe.Pointer(&aes_schedule[0])))
	toret := cipher.Block(fastAES{aes_schedule})
	return toret
}
Esempio n. 2
0
// Test the cbcDecAble interface is detected correctly by the cipher package.
func TestCBCDecAble(t *testing.T) {
	b := cipher.Block(&testBlock{})
	if _, ok := b.(cbcDecAble); !ok {
		t.Fatalf("testBlock does not implement the cbcDecAble interface")
	}
	bm := cipher.NewCBCDecrypter(b, []byte{})
	if _, ok := bm.(testInterface); !ok {
		t.Fatalf("cipher.NewCBCDecrypter did not use cbcDecAble interface")
	}
}
Esempio n. 3
0
// Test the ctrAble interface is detected correctly by the cipher package.
func TestCTRAble(t *testing.T) {
	b := cipher.Block(&testBlock{})
	if _, ok := b.(ctrAble); !ok {
		t.Fatalf("testBlock does not implement the ctrAble interface")
	}
	s := cipher.NewCTR(b, []byte{})
	if _, ok := s.(testInterface); !ok {
		t.Fatalf("cipher.NewCTR did not use ctrAble interface")
	}
}
Esempio n. 4
0
// Test the gcmAble interface is detected correctly by the cipher package.
func TestGCMAble(t *testing.T) {
	b := cipher.Block(&testBlock{})
	if _, ok := b.(gcmAble); !ok {
		t.Fatalf("testBlock does not implement the gcmAble interface")
	}
	aead, err := cipher.NewGCM(b)
	if err != nil {
		t.Fatalf("%v", err)
	}
	if _, ok := aead.(testInterface); !ok {
		t.Fatalf("cipher.NewGCM did not use gcmAble interface")
	}
}