Exemple #1
0
func SetupDecrypt(r io.Reader, key []byte, iv []byte) (io.Reader, os.Error) {
	c, e := aes.NewCipher(key)
	if e != nil {
		return nil, e
	}
	return block.NewCBCDecrypter(c, iv, r), nil
}
Exemple #2
0
func create_readers(ciphers *[]block.Cipher) *[]io.Reader {
	reader := &NullReaderWriter{}

	// ECB, CBC, CTR, OFB ...?
	readers := make([]io.Reader, len(*ciphers)*4)

	for i, cipher := range *ciphers {

		readers[i] = block.NewECBDecrypter(cipher, io.LimitReader(reader, 1024*1024*16))
		readers[i+len(*ciphers)] = block.NewCBCDecrypter(cipher, gen_iv(cipher), io.LimitReader(reader, 1024*1024*16))
		readers[i+2*len(*ciphers)] = block.NewCTRReader(cipher, gen_iv(cipher), io.LimitReader(reader, 1024*1024*16))
		readers[i+3*len(*ciphers)] = block.NewOFBReader(cipher, gen_iv(cipher), io.LimitReader(reader, 1024*1024*16))

	}
	return &readers
}
Exemple #3
0
func genericDES(c block.Cipher, t *testing.T, tt cbcTest) {
	test := tt.name

	var crypt bytes.Buffer
	w := block.NewCBCEncrypter(c, tt.iv, &crypt)
	var r io.Reader = bytes.NewBuffer(tt.in)
	n, err := io.Copy(w, r)
	if n != int64(len(tt.in)) || err != nil {
		t.Errorf("%s: CBCEncrypter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.in))
	} else if d := crypt.Bytes(); !same(tt.out, d) {
		t.Errorf("%s: CBCEncrypter\nhave %x\nwant %x", test, d, tt.out)
	}

	var plain bytes.Buffer
	r = block.NewCBCDecrypter(c, tt.iv, bytes.NewBuffer(tt.out))
	w = &plain
	n, err = io.Copy(w, r)
	if n != int64(len(tt.out)) || err != nil {
		t.Errorf("%s: CBCDecrypter io.Copy = %d, %v want %d, nil", test, n, err, len(tt.out))
	} else if d := plain.Bytes(); !same(tt.in, d) {
		t.Errorf("%s: CBCDecrypter\nhave %x\nwant %x", test, d, tt.in)
	}
}