# Difference between key generation and key agreement

Please excuse my ignorance as I am new to information security.

Could someone please explain in simple terms what the difference is between key generation and key agreement. In which situation would I use which.

Key agreement is a sub-case of key generation.

Key generation is about moving from a World where there is no key, to a World where there is a key. A "key", here, is some value with the correct structure for some cryptographic algorithm (e.g., an AES key is a sequence of 128, 192 or 256 bits; a RSA key is a set of a few big integers which fulfil some specific relations). Since keys have value by being unguessable by third parties, key generation necessarily involves using source data which is unknown to other people; in general, this "source data" will be random values obtained from a suitable source.

Key agreement is when the key generation must be such that, at the end of the process, two specific entities will know the key, and only them. A prime example is the Diffie-Hellman protocol where both parties use randomness to produce some data elements, exchange some of these elements with each other, and do some computations, which end up with both of them obtaining the same result at the end, while keeping external observers completely nonplussed.

A common method for key agreement is asymmetric encryption: Alice generates a key K for some algorithm (say, a sequence of 128 random bits), then encrypts it with Bob's public key, and sends the result to Bob. Bob decrypts it (with his private key), and thus obtains a copy of K. At the end of the day, Alice and Bob both know the same secret key K, so that's key agreement. If we look at the details, we see that the key agreement begins with a key generation, which is done entirely by Alice. That "local-generation-then-asymmetric-encryption" method is how most SSL connections are done on the Internet; note that Diffie-Hellman cannot be described that way, so one should not assume that all key agreement works that way.

Here is what I could find about each term:

Key agreement:

In cryptography, a key-agreement protocol is a protocol whereby two or more parties can agree on a key in such a way that both influence the outcome. If properly done, this precludes undesired third-parties from forcing a key choice on the agreeing parties. Protocols that are useful in practice also do not reveal to any eavesdropping party what key has been agreed upon.

http://en.wikipedia.org/wiki/Key-agreement_protocol

Key generation:

Key generation is the process of generating keys for cryptography. A key is used to encrypt > and decrypt whatever data is being encrypted/decrypted.

http://en.wikipedia.org/wiki/Key_generation

Hope this helps you. Regards

Key generation (as said in one of the previous answers) is the process of moving from a world with no key to a world with a key: i.e., a key is generated. A key can be generated by any number of methods. For example, the key could be generated individually by one person running an algorithm, or could be generated in a collaborative manner. The definition of key generation does not require certain parties to know about the key: key generation can be done in isolation and the key not shared.

Key establishment is a process or protocol whereby a shared secret (which here, is a key) becomes available to two or more parties, for subsequent cryptographic use.

Key establishment may be broadly subdivided into key transport and key agreement.

A key transport protocol or mechanism is a key establishment technique where one party creates or otherwise obtains a secret value (by generating a key themselves, for example), and securely transfers it to the other(s).

A key agreement protocol or mechanism is a key establishment technique in which a shared secret is derived by two (or more) parties as a function of information contributed by, or associated with, each of these, (ideally) such that no party can predetermine the resulting value. In this process, the key generation is done in a collaborative manner, resulting in both parties having the key.

An example of a key transport protocol is where one player will generate a symmetric key and encrypt the key under the public key of the recipient using asymmetric cryptography. This is a key transport protocol (sometimes called a key encapsulation mechanism, or KEM), and not a key agreement, as the key is dependent on inputs from only one party: the sender. The key is generated by one party and then transported to the other party.

An example of a key agreement protocol is Diffie Hellman key exchange. In DH, both parties influence the resulting key, rather than just one party. The key is agreed on by all the parties contributing.

Reference for definitions: Chapter 12 of the Handbook of Applied Cryptography, by A. Menezes, P. van Oorschot, and S. Vanstone, CRC Press, 1996.