Shared Secret, is it a public key or a private key?

If it is public it cannot be secret...

A key is "a parameter for an algorithm, which concentrates secrecy". This means that the key is not only secret, but, normally, nothing else is (algorithms are known to everybody).

A public key is a paradoxic terminology which was coined when asymmetric cryptography was invented. The "real" key is what we call the private key. It is the secret parameter which allows for performing an operation which only the key owner should be able to do (e.g. decrypting a piece of data, computing a signature...). The magic of asymmetric cryptography is that the reverse operation (encrypting a piece of data, verifying a signature...) can be done by anybody, using a mathematical object which is linked to the private key, and which can be made public without revealing the private key. You can imagine the public key as the face of a human being: it is distinctive and can convey information, but recognizing the face does not tell you what goes inside the brain. So a "public key" is not really a "key" in the strict sense of the term; and the "private key" could be called simply "key" or "secret key" because that's what it is.

However, Tradition dictates that we say "private key" for a key of the asymmetric kind (a key with enough mathematical structure to have a public face, which can be revealed without endangering the secrecy of the private key), while keys which are just bunches of bits, for symmetric encryption and similar algorithms, are called "secret keys" (or "symmetric keys"). That's traditional, not ultimately rational; terminology is always like that.

Asymmetric cryptography is mightily cool, but it is ill-suited for bulk encryption of gigabytes of data. For that, symmetric cryptography is much better, with "secret keys" (i.e. keys which do not have a public face, they are 100% secret). Diffie-Hellman is an asymmetric key exchange algorithm, in which two parties do the mathematics of DH and end up with a shared secret, i.e. a key: they both know it (thus "shared"), but nobody else (thus "secret"). With it, they can do symmetric cryptography, which was the point.


Read Thomas Pornin's very good answer. I think there's an additional source for confusion which might have tripped you.

A Diffie-Hellman key exchange is said to be a public-key protocol because it involves a pair of values (two such pairs, in fact: one for each party), with one value in the pair remaining secret and the other sent publicly.

  • First the two parties agree on some public parameters (p, g).
  • Then each party chooses a secret value (a, b), and sends a public value (g^a mod p, g^b mod p). In principle, the secret value could be deduced from the public value, but there is no known method to do so with real-world computing power. Such pairs of values where one can easily be computed from the other but not vice versa, when the values are used to help exchange more data, are called public/private key pairs.
  • The magic of Diffie-Hellman is that at the end, even though only public values have been exchanged, the parties manage to independently compute a secret value g^{ab} (one that is only known to the two parties).

Very often, the shared secret value is itself used as a key in some second cryptographic protocol which is based on symmetric cryptography (i.e. with a shared key), for example one based on AES. More precisely, a part of that secret value is used as a key for symmetric cryptography, and that part is called a secret key because of its used as part of the second protocol.