Beispiel #1
0
func testConstruction() (*chow.Construction, []byte) {
	key := test_vectors.AESVectors[50].Key
	seed := test_vectors.AESVectors[51].Key
	constr, _, _ := chow.GenerateEncryptionKeys(key, seed, chow.SameMasks(chow.IdentityMask))

	return &constr, key
}
Beispiel #2
0
func TestRecoverKey(t *testing.T) {
	key := make([]byte, 16)
	rand.Read(key)

	constr, _, _ := chow.GenerateEncryptionKeys(
		key, key, common.IndependentMasks{common.RandomMask, common.RandomMask},
	)

	cand := RecoverKey(&constr)

	if !bytes.Equal(cand, key) {
		t.Fatalf("Recovered wrong key!\nreal=%x\ncand=%x", key, cand)
	}
}
Beispiel #3
0
func main() {
	flag.Parse()

	// Generate AES key and seed for the white-box generator.
	key, seed := make([]byte, 16), make([]byte, 16)
	rand.Read(key)
	rand.Read(seed)

	fmt.Printf("Key: %x\n", key)

	// Create a white-box version of the above key.
	constr, _, _ := chow.GenerateEncryptionKeys(key, seed, common.SameMasks(common.IdentityMask))
	keyData := constr.Serialize()

	ioutil.WriteFile(*out, keyData, os.ModePerm)
}
Beispiel #4
0
func ExtractKey(cand ast.Expr) ([]byte, bool) {
	// Verify expression contains a byte slice.
	compositeLit, ok := cand.(*ast.CompositeLit)
	if !ok {
		return nil, false
	}

	arrayType, ok := compositeLit.Type.(*ast.ArrayType)
	if !ok {
		return nil, false
	}

	elt, ok := arrayType.Elt.(*ast.Ident)
	if !ok || elt.Name != "byte" || elt.Obj != nil {
		return nil, false
	}

	// Extract raw key.
	key := []byte{}

	for _, e := range compositeLit.Elts {
		basicLit, ok := e.(*ast.BasicLit)
		if !ok || basicLit.Kind != token.INT {
			return nil, false
		}

		num, err := strconv.ParseUint(basicLit.Value, 0, 8)
		if err != nil {
			return nil, false
		}

		key = append(key, byte(num))
	}

	if len(key) != 16 {
		return nil, false
	}

	// Mask key.
	seed := make([]byte, 16)
	rand.Read(seed)

	constr, _, _ := chow.GenerateEncryptionKeys(key, seed, chow.SameMasks(chow.IdentityMask))

	return constr.Serialize(), true
}