Thank you for the distinction.
What does leaking mean legally speaking?
Does the leaker have to know they are leaking classified material, to break the law?
There are multiple laws in this regard. This list is not exhaustive ...
18 USC 1905 - General prohibition against release
18 USC 793 - Espionage Act
18 USC 794 - Illegal communications
18 USC 797 - Transferring photos or sketches of military installations
18 USC 798 - Publication of classified information
50 USC 421 - Outing the Covert Agent Act
Does the leaker have to know they are leaking classified material, to break the law?
It depends on the statute. "Yes," for "outing the covert agent" and for 18 USC 798. Note the "knowingly" and "willingly" language.
But for 18 USC 793 and 18 USC 794 (and others), the information need not be classified in order to find the elements of the crime.