set2

package
v0.0.0-...-dc0442f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPadding = errors.New("invalid PKCS7 padding")

Functions

func DecryptCbcMode

func DecryptCbcMode(data, key, iv []byte) ([]byte, error)

DecryptCbcMode decrypts a cipher encrypted with AES-128 in CBC mode.

The cipher-block chaining (CBC) mode is more secure than EBC because each input to the cipher core is randomized, hiding patterns in the plaintext. Nice write-up: https://crypto.stackexchange.com/questions/1129/can-cbc-ciphertext-be-decrypted-if-the-key-is-known-but-the-iv-not

func DecryptEcbByteByByte

func DecryptEcbByteByByte(oracle *Oracle) ([]byte, error)

DecryptEcbByteByByte decrypts the input oracle's unknown buffer.

func EncryptEbcOrCbc

func EncryptEbcOrCbc(data []byte) ([]byte, error)

EncryptEbcOrCbc pads the beginning and end of the data with random buffers of random length, and then encrypts the result using either ECB or CBC mode (also randomly picked).

func GenerateRandBuffer

func GenerateRandBuffer(size int) ([]byte, error)

GenerateRandBuffer generates a random buffer.

func Pkcs7Padding

func Pkcs7Padding(data []byte, blockSize int) []byte

Pkcs7Padding pads the input buffer to blockSize. The value used for padding is the number of padding bytes.

func StripPkcs7Padding

func StripPkcs7Padding(data []byte) ([]byte, error)

StripPkcs7Padding removes the padding bytes from the input buffer. Returns an error if the padding is not valid PKCS#7.

TODO: how should inputs without padding be handled? Assuming that padding is not added to inputs with length equal to block size.

Types

type Mode

type Mode int
const (
	Ecb Mode = iota
	Cbc
)

func EncryptAndDetectEbcOrCbc

func EncryptAndDetectEbcOrCbc(data []byte) (Mode, error)

EncryptAndDetectEbcOrCbc encrypts a buffer with either ECB or CBC mode (randomly picked) and then detects which encryption mode was used.

type Oracle

type Oracle struct {
	// contains filtered or unexported fields
}

func NewOracle

func NewOracle(unknown, key []byte) *Oracle

func (*Oracle) Encrypt

func (o *Oracle) Encrypt(data []byte) ([]byte, error)

Encrypt appends an unknown buffer to the data and then encrypts it using ECB mode.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL