On the structure of groups whose exterior or tensor square is a p-group