diff options
| author | rsiddharth <s@ricketyspace.net> | 2021-02-24 19:58:23 -0500 | 
|---|---|---|
| committer | rsiddharth <s@ricketyspace.net> | 2021-02-24 19:58:23 -0500 | 
| commit | 6c4749a903744a16deb2fa6c426c4193afe76b4c (patch) | |
| tree | ea2ff9e001a04e2b667ee767ce58e10e5f458b4e /challenge | |
| parent | 97eaaa35e1630033ee68653e7f9c7c7aa84163bd (diff) | |
lib: remove OracleAESRandomEncrypt
Move function into C11 where it is used.
Diffstat (limited to 'challenge')
| -rw-r--r-- | challenge/c11.go | 34 | 
1 files changed, 33 insertions, 1 deletions
| diff --git a/challenge/c11.go b/challenge/c11.go index 703b959..211d48c 100644 --- a/challenge/c11.go +++ b/challenge/c11.go @@ -10,11 +10,43 @@ import (  )  func C11() { +	// Given an input `in`, this function AES encrypts `in` using a +	// randomly generate 16-byte key using ECB or CBC mode and returns the +	// cipher. +	encrypt := func(in []byte) []byte { +		// Generate random key. +		key, err := lib.RandomBytes(16) +		if err != nil { +			panic(err) +		} +		// Generate random initialization vector; needed for AES CBC. +		iv, err := lib.RandomBytes(16) +		if err != nil { +			panic(err) +		} + +		// Add 5-10 bytes at the beginning and end of `in` +		in = append(lib.RandomBytesWithLengthBetween(5, 10), in...) +		in = append(in, lib.RandomBytesWithLengthBetween(5, 10)...) + +		// Randomly encrypt `in` with AES in ECB or CBC mode. +		m := lib.RandomInt(0, 1) +		var out []byte +		if m == 0 { +			// Encrypt with AES in ECB mode. +			out = lib.AESEncryptECB(in, key) +		} else { +			// Encrypt with AES in CBC mode. +			out = lib.AESEncryptCBC(in, key, iv) +		} +		return out +	} +  	p := lib.StrToBytes("YellowSubmarine YellowSubmarine YellowSubmarine")  	fmt.Printf("Input: %v (%d)\n", p, len(p))  	for i := 0; i < 10; i++ { -		o := lib.OracleAESRandomEncrypt(p) +		o := encrypt(p)  		if lib.CipherUsesECB(o) != nil {  			fmt.Printf("%d -> Enciphered with ECB: %v (%d)\n", i, o, len(o))  		} else { | 
