func isPadValid(ct, iv []byte) bool { block, _ := aes.NewCipher(key) res := make([]byte, len(ct)) copy(res, ct) util.CBCDecrypt(block, iv, res, res) _, err := util.CheckPadding(res) // fmt.Println(res, err == nil) return err == nil }
func aesDecrypt(s *big.Int, ct, iv []byte) (t []byte) { sum := sha1.Sum([]byte(s.String())) blockA, _ := aes.NewCipher(sum[0:16]) tPadded := make([]byte, len(ct)) util.CBCDecrypt(blockA, iv, tPadded, ct) t, err := util.CheckPadding(tPadded) if err != nil { log.Fatal(err, tPadded) } return }
func main() { ct, iv0 := getMsg() fmt.Println("len:", len(ct), "blocks:", len(ct)/16) pt := attackPadding(ct[:16], iv0) for i := len(ct) - 16; i < len(ct); i += 16 { p := attackPadding(ct[i:i+16], ct[i-16:i]) pt = append(pt, p...) } pt, err := util.CheckPadding(pt) fmt.Println("Plaintext:", string(pt), "\nPadding is valid:", err == nil) }
func main() { fmt.Println(util.CheckPadding([]byte("ICE ICE BABY\x04\x04\x04\x04"))) fmt.Println(util.CheckPadding([]byte("ICE ICE BABY\x05\x05\x05\x05"))) fmt.Println(util.CheckPadding([]byte("ICE ICE BABY\x01\x02\x03\x04"))) }