Ejemplo n.º 1
0
func encryptOracle(src []byte) []byte {
	key := util.RandAes128()
	block, _ := aes.NewCipher(key)
	out := make([]byte, len(src))
	copy(out, src)

	// random prepend and append
	prefixSize := util.RandByte()%10 + 5
	postfixSize := util.RandByte()%10 + 5
	postfix := util.RandBytes(int(postfixSize))
	out = append(util.RandBytes(int(prefixSize)), out...)
	out = append(out, postfix...)
	// padding
	out = util.PadTo(out, 16)
	// fmt.Println("before enc", out)

	// random encryption mode
	mode := util.RandByte()
	if mode%2 == 0 {
		// ecb
		fmt.Println("ecb")
		util.ECBEncrypt(block, out, out)
	} else {
		// cbc
		fmt.Println("cbc")
		iv := util.RandAes128()
		util.CBCEncrypt(block, iv, out, out)
	}
	return out
}
Ejemplo n.º 2
0
func aesCrypt(s *big.Int, t []byte) (ct, iv []byte) {
	sum := sha1.Sum([]byte(s.String()))
	blockA, _ := aes.NewCipher(sum[0:16])
	tPadded := util.PadTo(t, 16)
	ct = make([]byte, len(tPadded))
	iv = util.RandBytes(16)
	util.CBCEncrypt(blockA, iv, ct, tPadded)
	return
}
Ejemplo n.º 3
0
func crypt(userdata []byte) []byte {
	res := bytes.Replace(userdata, []byte("="), []byte("%3D"), -1)
	res = bytes.Replace(res, []byte(";"), []byte("%3B"), -1)
	res = append(prefix, res...)
	res = append(res, postfix...)
	block, _ := aes.NewCipher(key)
	res = util.PadTo(res, 16)
	util.CBCEncrypt(block, iv, res, res)
	return res
}
Ejemplo n.º 4
0
func getMsg() (ct, iv []byte) {
	ct, err := base64.StdEncoding.DecodeString(msgs[util.RandByte()%10])
	if err != nil {
		log.Fatal("Cannot decode", err)
	}
	iv = util.RandAes128()
	block, _ := aes.NewCipher(key)
	ct = util.PadTo(ct, block.BlockSize())
	util.CBCEncrypt(block, iv, ct, ct)
	return ct, iv
}
Ejemplo n.º 5
0
func crypt(userdata []byte) []byte {
	res := bytes.Replace(userdata, []byte("="), []byte("%3D"), -1)
	res = bytes.Replace(res, []byte(";"), []byte("%3B"), -1)
	res = append(prefix, res...)
	res = append(res, postfix...)
	block, _ := aes.NewCipher(key)
	res = util.PadTo(res, 16)
	fmt.Println("crypt peek:", string(res))
	util.CTREncrypt(block, nonce, res, res)
	return res
}
Ejemplo n.º 6
0
func encryptProfile(email string) []byte {
	block, _ := aes.NewCipher(key)
	profile := profileFor(string(email))
	out := make([]byte, len(profile))
	copy(out, profile)

	out = util.PadTo(out, 16)
	fmt.Println("before enc:", out)
	util.ECBEncrypt(block, out, out)

	return out
}
Ejemplo n.º 7
0
func encryptOracle(src []byte) []byte {
	block, _ := aes.NewCipher(key)
	out := make([]byte, len(src))
	copy(out, src)

	appendix, _ := base64.StdEncoding.DecodeString("Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK")

	out = append(out, appendix...)
	out = util.PadTo(out, 16)
	// fmt.Println("before enc", out)
	util.ECBEncrypt(block, out, out)

	return out
}
Ejemplo n.º 8
0
func encryptOracle(src []byte) []byte {
	block, _ := aes.NewCipher(key)
	out := make([]byte, len(src))
	copy(out, src)

	target := []byte("secret bytes. nobody is gonna read them.")
	out = append(prefix, out...)
	out = append(out, target...)
	out = util.PadTo(out, 16)
	// fmt.Println("before enc", out)
	util.ECBEncrypt(block, out, out)

	return out
}