fix keystream generation