Documentation
¶
Overview ¶
Package cryptopals contains solutions to the Cryptopals challenges.
Index ¶
- func Englishness(b []byte) float64
- func FindBlockSize(oracle func([]byte) []byte) int
- func FindSingleByteXORCiphertext(cts [][]byte) int
- func Hamming(a, b []byte) int
- func HexToBase64(s string) (string, error)
- func IsECBCiphertext(b []byte, blockSize int) bool
- func IsECBOracle(oracle func([]byte) []byte) bool
- func NewAdminProfile(m *ProfileManager) []byte
- func NewCBCDecrypter(b cipher.Block, iv []byte) cipher.BlockMode
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func NewECBOrCBCPrefixSuffixOracle() func([]byte) []byte
- func NewECBPrefixSuffixOracle(secret []byte) func([]byte) []byte
- func NewECBSuffixOracle(secret []byte) func([]byte) []byte
- func NewRepeatingKeyXORCipher(key []byte) cipher.Stream
- func NewSingleByteXORCipher(key byte) cipher.Stream
- func PadPKCS7(b []byte, n int) []byte
- func RecoverECBSuffixOracleSecret(oracle func([]byte) []byte) []byte
- func RecoverRepeatingKeyXORKey(ct []byte) []byte
- func RecoverRepeatingKeyXORKeySize(ct []byte, lo, hi int) int
- func RecoverSingleByteXORKey(ct []byte) byte
- func UnpadPKCS7(b []byte) []byte
- func XOR(a, b []byte) []byte
- type ProfileManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Englishness ¶
Englishness scores b on how much it resembles English.
Scores are length-normalized and between 0 and 1 inclusive. Higher is better.
If len(b) == 0, Englishness returns 0.
func FindBlockSize ¶
FindBlockSize returns the block size used by an encryption oracle.
func FindSingleByteXORCiphertext ¶
FindSingleByteXORCiphertext returns the index of the ciphertext most likely to be single-byte XOR encrypted.
FindSingleByteXORCiphertext returns -1 if no ciphertext was found.
func Hamming ¶
Hamming returns the Hamming distance between a and b.
It panics if a and b have different lengths.
func HexToBase64 ¶
HexToBase64 converts a hex-encoded string to a Base64-encoded string.
func IsECBCiphertext ¶
IsECBCiphertext returns true if b is likely to be ECB encrypted.
func IsECBOracle ¶
IsECBOracle returns true if an encryption oracle uses ECB mode.
func NewAdminProfile ¶
func NewAdminProfile(m *ProfileManager) []byte
NewAdminProfile performs a cut-and-paste ECB attack to create an admin profile from multiple user profiles.
TODO: Is this possible to do without using an invalid TLD (.admin)?
func NewCBCDecrypter ¶
NewCBCDecrypter returns a cipher.BlockMode which decrypts in cipher block chaining mode.
func NewECBDecrypter ¶
NewECBDecrypter returns a cipher.BlockMode which decrypts in electronic codebook mode.
func NewECBEncrypter ¶
NewECBEncrypter returns a cipher.BlockMode which encrypts in electronic codebook mode.
func NewECBOrCBCPrefixSuffixOracle ¶
NewECBOrCBCPrefixSuffixOracle returns a new oracle that encrypts inputs as described in challenge 11.
The oracle returns encrypt(pad(prefix || input || suffix)) under either AES-128-ECB or AES-128-CBC.
func NewECBPrefixSuffixOracle ¶
NewECBPrefixSuffixOracle returns an encryption oracle that behaves as described in challenge 14.
It returns AES-128-ECB(key, prefix || input || secret). The key and prefix are random and fixed.
func NewECBSuffixOracle ¶
NewECBSuffixOracle returns an oracle that encrypts inputs as described in challenge 12.
The oracle returns encrypt(pad(input || secret)).
func NewRepeatingKeyXORCipher ¶
NewRepeatingKeyXORCipher returns a new repeating-key XOR cipher.
func NewSingleByteXORCipher ¶
NewSingleByteXORCipher returns a new single-byte XOR cipher.
func PadPKCS7 ¶
PadPKCS7 returns a new slice that concatenates b with PKCS #7 padding to guarantee block size n.
func RecoverECBSuffixOracleSecret ¶
RecoverECBSuffixOracleSecret takes an encryption oracle that behaves as described in challenge 12 and recovers the secret used.
func RecoverRepeatingKeyXORKey ¶
RecoverRepeatingKeyXORKey returns the most likely key for a repeating-key XOR ciphertext.
It assumes the plaintext is English. It also assumes that the key size is between 2 and 40 bytes.
func RecoverRepeatingKeyXORKeySize ¶
RecoverRepeatingKeyXORKeySize returns the most likely key size for a repeating-key XOR ciphertext, within lo to hi inclusive.
It assumes that the plaintext is English.
TODO: Avoid panicking when a or b is large compared to len(ct).
func RecoverSingleByteXORKey ¶
RecoverSingleByteXORKey returns the most likely key for a single-byte XOR ciphertext.
It assumes the plaintext is English.
func UnpadPKCS7 ¶
UnpadPKCS7 returns a subslice of b with PKCS #7 padding removed.
Types ¶
type ProfileManager ¶
type ProfileManager struct {
// contains filtered or unexported fields
}
ProfileManager manages profiles as described in challenge 13.
func NewProfileManager ¶
func NewProfileManager() *ProfileManager
NewProfileManager returns a new profile manager.
func (ProfileManager) IsAdmin ¶
func (p ProfileManager) IsAdmin(profile []byte) bool
IsAdmin returns true if the profile has admin permissions.
func (ProfileManager) NewUserProfile ¶
func (p ProfileManager) NewUserProfile(email string) []byte
NewUserProfile returns a new profile with user permissions.