Setting up hardware and software

What is a key in encryption? Public and private encryption key

Cryptographic keys are used as secret information.

Cryptographic key is a sequence of characters generated according to certain rules. This sequence is used for cryptographic text transformations. Each cryptographic algorithm has its own requirements in accordance with which keys are created. Each key is created for a specific algorithm.

To ensure non-reproducibility electronic signature and the impossibility of reading encrypted texts by strangers, cryptographic keys are used in cryptography.

A modern cryptographic key is a sequence of numbers of a certain length, created according to certain rules based on a sequence of random numbers. For each key, a sequence of random numbers is created anew; no sequence is used more than once. To generate sequences of random numbers, special software objects or devices called random number sensors are used.

Each algorithm has its own key requirements, so any cryptographic key is created for a specific algorithm and used only with that algorithm.

If the generation of an electronic signature and its verification, or the encryption and decryption of text are performed using the same key, this approach is called symmetric cryptography(respectively symmetric algorithms and symmetric keys). Symmetric cryptography operations are fast and relatively simple. But they require at least two people to know the key, which significantly increases the risk of them being compromised (i.e., being accessed by unauthorized persons).

Therefore, it is now mainly used asymmetric cryptography. In asymmetric cryptography, the generation of an electronic signature or encryption is performed on one key, and the signature verification or decryption is performed on another, paired key.



Asymmetric cryptography uses so-called key pairs. Each such pair consists of two interconnected keys. One of these keys is a private key. It is known only to the owner of the key and under no circumstances should it be accessible to anyone else. Another key is a public key, it can be accessed

anyone who wants it.

Authentication Methods

Authentication is the issuance of certain access rights to the subscriber based on the identifier he has. IEEE 802.11 provides two authentication methods:

1. Open authentication Open Authentication):

The workstation makes an authentication request that contains only the client's MAC address. The access point responds with either a denial or confirmation of authentication. The decision is made based on MAC filtering, i.e. In essence, this is protection based on access restrictions, which is not secure.

2. Shared key authentication Shared Key Authentication):

You need to configure a static WEP encryption key. Wired Equivalent Privacy). The client makes a request to the access point for authentication, for which it receives a confirmation that contains 128 bytes of random information. The station encrypts the received data with the WEP algorithm (bitwise modulo 2 addition of the message data with the key sequence) and sends the ciphertext along with the association request. The access point decrypts the text and compares it with the original data. If there is a match, an association confirmation is sent and the client is considered connected to the network.
The shared key authentication scheme is vulnerable to Man in the middle attacks. The WEP encryption algorithm is a simple XOR of the key sequence with useful information Therefore, by listening to the traffic between the station and the access point, you can recover part of the key.
IEEE began developing a new standard, IEEE 802.11i, but due to approval difficulties, the WECA organization (eng. Wi-Fi Alliance) together with IEEE announced the WPA standard (eng. Wi-Fi Protected Access). WPA uses TKIP. Temporal Key Integrity Protocol, a key integrity protocol), which uses an advanced key management method and frame-by-frame rekeying.

WPA also uses two authentication methods:

1. Authentication using a preset WPA-PSK key. Pre-Shared Key) (Enterprise Authentication);

2. Authentication using a RADIUS server Remote Access Dial-in User Service)

Types of encryption

Encryption- conversion method open information to closed and back. Used for storage important information in unreliable sources or transmitted through unsecured communication channels. Encryption is divided into the process of encrypting and decrypting.

Depending on the data conversion algorithm, encryption methods are divided into guaranteed or temporary cryptographic strength.

Depending on the structure of the keys used, encryption methods are divided into

§ symmetric encryption: unauthorized persons may know the encryption algorithm, but a small portion of secret information is unknown - the key, which is the same for the sender and recipient of the message;

§ asymmetric encryption: outsiders may know the encryption algorithm, and perhaps the public key, but not private key, known only to the recipient.

The following cryptographic primitives exist:

§ Keyless

1. Hash functions

2. One-sided permutations

3. Pseudo-random number generators

§ Symmetrical circuits

1. Ciphers (block, stream)

2. Hash functions

4. Pseudo-random number generators

5. Identification primitives

§ Asymmetrical circuits

3. Identification primitives

Encrypting data on disk
The Zserver system is a means of protecting confidential information stored and processed on corporate servers by encrypting data on disk. Zserver works on the principle of “transparent” partition encryption hard drives. The system automatically, online, encrypts information when writing to disk and decrypts it when reading from it. This ensures that the data is stored on the disk in encrypted form and cannot be used without the encryption key, even if the server or media is removed. The Zserver system provides encryption of files and folders on the disk, as well as the entire official information- file placement tables, etc. Thus, the Zserver system not only reliably protects confidential data, but also hides the very fact of its presence from outsiders. Information on protected drives is stored in encrypted form and becomes accessible only when the network administrator grants the user the appropriate permissions. Access rights to protected disks are set using the operating system. Encryption of files and folders on the disk is carried out by the software driver. Disk encryption keys are entered when the server boots from a PIN-protected smart card. Without knowing the PIN code, you cannot use the smart card. Three attempts to enter the PIN code incorrectly will block the card. A smart card is only needed when connecting secure media, and is not required during operation. If you reboot the server without a smart card, the protected disks will not be accessible. The Zserver system provides the ability to remotely enter encryption keys and administer the system from any workstation local network, or via the Internet. Currently, Zserver systems have been developed that run the following: operating systems: Windows 2000/XP/2003/2008 (32- and 64-bit); Linux with kernel 2.6.x.

The data in this case is considered as messages, and to protect its meaning it is used classical encryption technique.

Cryptography involves three components: data, key, and cryptographic transformation. When encrypting, the initial data is the message, and the resulting data is the encryption. When decrypting, they change places. It is believed that the cryptographic transformation is known to everyone, but without knowing the key with which the user hid the meaning of the message from prying eyes, it is necessary to spend an unimaginably large amount of effort to restore the text of the message. (It should be repeated once again that there is no encryption that is absolutely unbreakable. The quality of the cipher is determined only by the money that needs to be paid for opening it, from $10 to $1,000,000.) This requirement is satisfied by a number of modern cryptographic systems, for example, those created according to the “Data Encryption Standard of the National US Bureau of Standards" DES and GOST 28147-89. Since a number of data are critical to some of their distortions that cannot be detected from the context, only encryption methods that are sensitive to the distortion of any character are usually used. They guarantee not only high security, but also effective detection of any distortions or errors.

Algorithm parameters

There are many (at least two dozen) symmetric cipher algorithms, the essential parameters of which are:

§ durability

§ key length

§ number of rounds

§ length of the processed block

§ complexity of hardware/software implementation

§ complexity of conversion

[Common Algorithms

§ AES Advanced Encryption Standard) - American encryption standard

§ GOST 28147-89 - domestic standard data encryption

§DES Data Encryption Standard) - data encryption standard in the USA up to AES

§ 3DES (Triple-DES, triple DES)

§ RC6 (Rivest Cipher)

§ IDEA International Data Encryption Algorithm)

§ SEED - Korean data encryption standard

The main purpose of using SSL certificates is to encrypt data transmitted to the server from the client and to the client from the server. To ensure the security of such a connection modern browsers use the TLS algorithm based on X.509 certificates. This algorithm uses asymmetric encryption to create a session key for symmetric encryption. The latter is used directly for data transfer after establishing a secure connection.

What is a key in cryptography?

A key in cryptography is secret information, which is used in cryptography to encrypt and decode messages, to affix a digital signature and verify it, to calculate message authenticity codes, etc. How reliable a key is is determined by the so-called key length, which is measured in bits. The standard key length for SSL certificates is 128 or 256 bits. The root certificate key length must not be less than 4096 bits. All certification authorities with which we cooperate provide SSL certificates with a key that fully complies with modern standards:

Public and private key in asymmetric encryption

Asymmetric encryption uses pair of keys: open (Public key) And closed, also called secret (Private key). The public and private keys in this case allow the cryptographic algorithm to encrypt and decrypt the message. In this case, messages encrypted with a public key can only be decrypted using the private key. The public key is published in the owner’s certificate and is available to the connecting client, and the private key is stored by the owner of the certificate. The public and private keys are interconnected by mathematical dependencies, so it is impossible to select a public or private key in a short time (the validity period of the certificate). That is why maximum term The validity of SSL certificates with a higher level of protection is always lower. So, you can order for a maximum of 2 years. At the same time, when ordering a new SSL certificate or renewing an old one, it is important to generate a new CSR request, since your private key is tied to it and when issuing a new SSL certificate, it is better to update it. The client interacts with the server as follows:
  1. browser based public key encrypts the request and sends it to the server;
  2. the server, using the private key, decrypts the received message;
  3. the server encrypts its digital identifier with a private key and transmits it to the client;
  4. the client checks the server identifier and transmits its own;
  5. after mutual authentication, the client encrypts the future session key with a public key and transmits it to the server;
  6. all subsequent messages that are transmitted between the client and server are signed with the session key and encrypted using a public and private key.
This ensures several security points:
  • the possibility of information leakage is eliminated - if intercepted, it cannot be decrypted;
  • the server confirms its address and identifier, the possibility of redirection to another site is cut off (phishing);
  • the client is assigned an individual session, which allows him to be distinguished from other clients more reliably;
  • Once a secure session is established, all messages are encrypted using the client ID and cannot be undetected or modified.

In general, public-private key encryption can be considered as a case for which two keys are used: one can only be closed, the other can only be opened. If the case was closed with the first key, only the second can open it; if it was closed with the second, the first one will be required to open it. This can be clearly seen in the diagram above. public key, noted that this requirement denies the whole essence of cryptography, namely the ability to maintain universal secrecy in communications.

The second task is the need to create mechanisms that would make it impossible to replace any of the participants, i.e. needed digital signature . When communications are used for a wide range of purposes, such as commercial and private purposes, electronic messages and documents must have the equivalent of a signature contained in paper documents. A method needs to be created to ensure that all participants are convinced that the email was sent by a specific participant. This is a stronger requirement than authentication.

Diffie and Hellman achieved significant results by proposing a way to solve both problems that is radically different from all previous approaches to encryption.

Let's look at the general features first encryption algorithms with a public key and requirements for these algorithms. Let us determine the requirements that must be met by an algorithm that uses one key for encryption and another key for decryption, and it is computationally impossible to determine the decryption key knowing only the encryption algorithm and the encryption key.

Additionally, some algorithms, such as RSA, have the following characteristic: each of the two keys can be used for both encryption and decryption.

We will first consider algorithms that have both characteristics, and then move on to public key algorithms that do not have the second property.

When describing symmetric encryption and public key encryption we will use the following terminology. Key used in symmetric encryption, we will call secret key. The two keys used in public key encryption will be called public key And private key. The private key is kept secret, but we will call it the private key rather than the secret key to avoid confusion with the key used in symmetric encryption. The private key will be denoted by KR, the public key by KU.

We will assume that all participants have access to each other's public keys, and that private keys are created locally by each participant and therefore should not be distributed.

At any time, a participant can change his private key and publish the pairing public key, replacing the old public key.

Diffie and Hellman describe the requirements that must be met encryption algorithm with a public key.

  1. It is computationally easy to create a pair (public key KU, private key KR).
  2. It is computationally easy, given a public key and an unencrypted message M, to create a corresponding encrypted message:
  3. It is computationally easy to decrypt a message using the private key:

    M = D KR [C] = D KR ]

  4. It is computationally impossible, knowing the public key KU, to determine the private key KR.
  5. It is computationally impossible, knowing the public key KU and the encrypted message C, to restore the original message M.

    A sixth requirement can be added, although it does not hold for all public key algorithms:

  6. The encryption and decryption functions can be used in any order:

    M = E KU]

These are quite strong requirements that introduce the concept. One way function is a function in which each argument has a single inverse value, while the function itself is easy to calculate, but the inverse function is difficult to calculate.

Typically "easy" means that the problem can be solved in a polynomial time of the length of the input. Thus, if the input length has n bits, then the function computation time is proportional to n a , where a is a fixed constant. Thus, the algorithm is said to belong to the class of polynomial algorithms P. The term "hard" means a more complex concept. In general, we will assume that the problem cannot be solved if the effort to solve it is greater than the polynomial time of the input value. For example, if the input length is n bits, and the function computation time is proportional to 2n, then it is considered a computationally impossible problem. Unfortunately, it is difficult to determine whether a particular algorithm exhibits such complexity. Moreover, traditional views of computational complexity focus on the worst-case or average-case complexity of an algorithm. This is unacceptable for cryptography, which requires the inability to invert a function for all or almost all input values.

Let's go back to the definition single-sided function with hatch, which, like one-way function, is easy to compute in one direction and difficult to compute in the opposite direction unless some additional information is available. With this additional information, the inversion can be computed in polynomial time. Thus, one way function with hatch belongs to the family one-way functions f k such that

We see that the development of a particular public key algorithm depends on the discovery of the corresponding single-sided function with hatch.

Cryptanalysis of public key algorithms

As in the case symmetric encryption, encryption algorithm with a public key is vulnerable to a frontal attack. The countermeasure is standard: use large keys.

A public key cryptosystem uses certain non-invertible mathematical functions. The complexity of computing such functions is not linear with the number of bits of the key, but increases faster than the key. Thus, the key size must be large enough to make a brute force attack impractical, but small enough to allow practical encryption. In practice, the key size is made such that a brute force attack is impractical, but the resulting encryption speed is slow enough for the algorithm to be used for general purposes. Therefore, public key encryption is currently mainly limited to key management and signing applications that require encryption of a small block of data.

Another form of attack is to find a way to calculate the private key by knowing the public key. It is impossible to prove mathematically that this form attacks are excluded for a specific public key algorithm. So any algorithm, including the widely used RSA algorithm, is suspect.

Finally, there is a form of attack specific to the way public key systems are used. This is a probable message attack. For example, suppose that the message being sent consists solely of a 56-bit session key for a symmetric encryption algorithm. An adversary can encrypt all possible keys using the public key, and can decrypt any message matching the ciphertext transmitted. Thus, regardless of the key size of the public key scheme, the attack amounts to a brute force attack on the 56-bit symmetric key. The defense against such an attack is to add a certain number of random bits to simple messages.

Basic Uses of Public Key Algorithms

The main uses of public key algorithms are encryption/decryption, signature creation and verification, and key exchange.

Encryption with a public key consists of the following steps:


Rice. 7.1.

  1. User B creates a pair of keys KU b and KR b used to encrypt and decrypt transmitted messages.
  2. User B makes his encryption key available in some reliable way, i.e. public key KU b . The paired private key KR b is kept secret.
  3. If A wants to send a message to B, he encrypts the message using B's public key KU b.
  4. When B receives the message, he decrypts it using his private key KR b. No one else will be able to decrypt the message, since only B knows this private key.

If the user ( end system) securely stores your private key, no one will be able to spy on transmitted messages.

Creating and verifying a signature consists of the following steps:


Rice. 7.2.
  1. User A creates a pair of keys KR A and KU A, which are used to create and verify the signature of transmitted messages.
  2. User A makes his verification key available in some reliable way, i.e.

The protection of secrets can be based on the principle of access to secrets only to initiated persons, implying that the uninitiated do not have physical access To her. In another case, the protection of secrets can be based on the principle of possible access by unauthorized persons, but with an understanding of the meaning of the secret only by authorized persons. Historically, the second method has become more widespread than the first, which is more expensive and sometimes simply impossible. With the advent of writing, it became widespread, and became almost universal: secret cards, encrypted writing. Available to everyone, but understandable only to initiates. Today it is the main method of hiding secrets for storing and transmitting information.

Encrypted message hides the meaning of the original (open) message. Thus, the process of encryption is the process of hiding the meaning of the original message in the original alphabet. The encrypted message becomes unreadable. And only dedicated people who know some secret can decrypt the encrypted message. In the future, we will combine the processes of encryption and decryption with one word “encryption” or discuss these processes separately. The science called cryptography deals with the construction of encryption systems.

As a result of the use of encryption, cipher text appears, which hides the information secret. For example, the secret message “Tomorrow Scott’s company will sell shares at reduced prices” has some encrypted text in the form “?т6ifmфвшб4-!nmdавжшт”. The cipher text of the secret is available to everyone, moreover, the cipher text contains the full content of the secret, it contains the whole meaning of the secret, but the secret is accessible only to initiates. Here it is necessary to make one small note and clarification. Yes, the secret is easily and quickly accessible only to insiders. Uninitiated persons can penetrate the secret over a longer period of time, with some effort. The success of uninitiated persons is guaranteed precisely because the cipher text contains all the information hiding the secret. To read cipher text Some additional information is needed that allows you to easily and quickly comprehend the meaning of the message hidden from outsiders. We will be interested in encryption systems that have one characteristic feature for insiders: a one-to-one direct and inverse transformation of the original (plain) text into a single ciphertext. We will show later that for the uninitiated, in some cases this may not be entirely true.

Keys in cryptography

What allows you to quickly open your closed door, you, the person who is allowed to do so? The key, you say. Well, with a good lock, the burglar will tinker for a while, but he will also open your door without a key. To prevent a burglar from quickly opening the door of your apartment, the lock must be good enough. The time of illegal opening of your apartment depends on this. As a last resort, a thief can use brute force to try to break down the door itself. In cryptography the situation is similar: the door is a cipher text that opens the way to the secret. The key is that additional information that allows insiders to quickly read the ciphertext. This Additional information we will also call it a cryptographic key or simply a key. The key to the apartment must not be lost, it must not be given to strangers whom you do not trust. For the same reasons, the cryptographic key cannot be given to anyone. It must be kept secret because it is very easy to make a copy of, easier than an ordinary door key. Regular key from the apartment is small in size so that it is convenient to store it. For the same reasons, the cryptographic key should also be small in size, although today when using computers this is not such a strict requirement. What plays the role of a lock in cryptography? It is a device or rule (algorithm) for how to create ciphertext. Wait a minute! If it is very easy to copy a real key, then you can create it yourself. Yes, you can, but which one to create? Quantity possible keys very large.

Modern cryptographic systems have a much larger set of possible keys than the set of possible keys for an ordinary lock on your door. This number can be comparable to the number of atoms in our Universe (1077≈2264). Trying all possible keys is equivalent to breaking doors, i.e. the use of brute force. You can make a secret, unique lock that a typical thief’s master key will not work with. In ancient times, when monarchs, appanage princes or counts created secret shelters, underground passages, the builders were usually killed, blinded, in general, they did everything to keep these structures secret. What will you do with the master of your castle? He knows the design of the lock, and perhaps even made a key for it! The Dutch military cryptographer Dutchman A. Kerkhoffs solved this problem back in the 19th century by formulating in his book “Military Cryptography,” published in 1883, six basic requirements for an encryption system: the encryption system must be unbreakable, if not in theoretical terms, then in practical; compromise of the system should not cause inconvenience to its users; the secret key must be easy to remember without writing it down; the cryptogram must be in such a form that it can be transmitted by telegraph; encryption equipment must be portable and such that it can be operated by one person; the system should not require memorizing a long list of rules and should be easy to use.

Despite the primitivism of individual requirements from the perspective of today's capabilities (don't forget about 1883), this list contains an important (second) fundamental point of requirements for a system of maintaining secrecy: the design of your door lock (the rule for obtaining cipher text) can be known to everyone. Only the key to it should be secret. If at the same time your system turns out to be reliable against hacking, you can rest easy. Where can I get this secret key, a key that no one would know? There can only be one answer: you need to do it yourself. So, for your complete peace of mind, you should purchase an algorithm for creating a secret from a reliable company with a guarantee and make the secret key yourself.

In your PC the key represents some file that consists of zeros and ones. Each zero or one represents one of two values ​​for a unit of information called a bit. The total number of zeros and ones in the key file determines its length. For example, a key with a length of 256 bits means that the key file contains a number of zeros and ones, the total number of which is 256. How many keys can there be? You can build a special computer to quickly enumerate keys. This car will probably cost enough big money. Gordon E. Moor noted that over the course of a year, processor sizes, costs, and instruction execution times are reduced by approximately 40%. This pattern is called Moore's law after this researcher. We can illustrate the effect of Moore's law using the example of breaking the DES cryptographic algorithm with a key length of 46 bits. At the current time, it is accepted that a key length of 246 bits is quite acceptable for protection against a complete search of the key field. Thus, the key is a secret parameter of the cryptographic data transformation algorithm, ensuring the selection of only one option from all possible options of this algorithm.

Now you see what an important role the key plays in the strength of the encryption system. Therefore, the key transmission channel must be absolutely reliable, and the key itself must be well protected from unauthorized persons. Let's assume that these two conditions are met. And yet, based only on intercepted ciphertexts, a hacker can ultimately determine your The secret key. This is because most ciphertexts practical systems encryption have a pattern, difficult to define, but a pattern nonetheless. In what follows, the process of hacker decryption of messages without prior knowledge of the key will be called the decryption process.

Few people know exactly how asymmetric encryption works. For example, there are people who do not consider the https protocol to be any adequate protection for transmitted data. And as a rule, when trying to convince them otherwise, they respond with something along the lines of “if we transmit encrypted data, then we must say how to decrypt it, and this information can be intercepted and, therefore, the data can be decrypted.” And to the arguments that this is not so and that asymmetric encryption is the basis, the answer is “So what?”

Okay, I understand that not everyone needs to know all the intricacies of implementing asymmetric encryption. But general principle work, I believe, should be known to everyone who is in any way connected with computers.

I would like to summarize the essence of this post in this annotation: Remember, asymmetric encryption is secure, of course, if all conditions are met. And to prove this I will try to describe the algorithm in clear language so that everyone can understand that it is safe. Meet Alice, Bob and Eve and the transmission of their secret message under the cut.

By the way, why Alice and Bob? There is a short article about this on Wikipedia: Alice, Bob and Eve. To make it clearer, Alice and Bob want to exchange messages, and Eve is trying to intercept and read these messages.

A little history

Cryptography of past centuries had one huge problem - the problem of key transfer. At that time, there were only so-called “symmetric” ciphers - ciphers in which data is encrypted and decrypted with the same key.

For example, Alice encrypted some message and wants to send it to Bob. Naturally, for Bob to read it, he needs the key with which the message was encrypted. And then the problem arises of how to transfer the key so that no one can intercept it. Inquisitive minds will make an offer - let them pass it on in person, and then communicate as much as they want. Yes, I don’t argue, it’s a way out. Now imagine for a second that your Internet mail, before you log in to it, will require you to travel to the physical location of the mail server. Comfortable? Perhaps not very much.

Of course, the key can be transmitted over another communication channel. But cryptography considers all unsecured communication channels as insecure. That is, transferring the key to Bob over the phone, for example, is considered unsafe, just as nothing prevents Eve from listening to the phone as well.

Until the 70s, this problem became so common that it was considered an axiom that in order to transmit a message, you need to transmit the key with which the message is encrypted (and some people still think this way). But in 1976, Diffie and Hellman proposed their “exponential key exchange method.” Since these years, the development of asymmetric cryptosystems began.

A little bit of real life

Before studying any algorithm, you need to imagine how it works. And the easiest way is to compare it with how something works in reality.

Let's imagine that Alice and Bob live in a country in which everything postal system is absolutely immoral and postal employees read all unsecured correspondence. Alice, a not stupid girl, before sending a message to Bob, took an iron box and, putting the letter inside and closing it with her lock, sent this box to Bob.

Naturally, the post office cannot read this letter, but Bob himself cannot read it, since he does not have the key with which the lock is closed. Alice, of course, can take another iron box, put the key from the previous one in it, and send it to Bob, but Bob will not be able to open it either...

The only way is to make a duplicate of the key and give it to Bob in person...

And so it begins to seem that key exchange is an inevitable part of encryption - or is it not?

Let's imagine a different picture. I'll write it down step by step:

  1. Alice puts her letter in an iron box and, locking it, sends it to Bob.
  2. Bob, upon receiving the box, (attention!) takes his lock and, having additionally locked the box with it, sends it back.
  3. Alice already receives the box with two locks (let me remind you, Alice’s first lock, for which she has the key, and Bob’s second, for which only Bob has the key).
  4. Alice removes her lock and sends the box back to Bob
  5. Bob receives a box with one of his locks for which he has a key
  6. Bob unlocks his remaining lock with his key and reads the message

The significance of this short story is enormous. It shows that two people can transmit a secret message without exchanging keys. Think about it! This story actually destroys all the axioms on which the cryptography of that time was built. Yes, we get some complication of the process (the box had to be sent three times), but the result...

Let's get back to cryptography

It would seem that a solution has been found. The sender and receiver encrypt their message, and then the interlocutors take turns deciphering theirs.


But the point is that there are no ciphers that would allow one to remove a cipher from another cipher. That is, the stage where Alice removes her cipher is impossible:


Unfortunately, all available algorithms still require the removal of ciphers in the queue in which they were applied. I’m afraid to call this an axiom (since history already knows cases when such axioms were smashed to smithereens), but this is still the case.

Let's get back to math

The box idea I described above inspired Diffie and Hellman to look for a way to convey a message. Eventually they ended up using one-way functions.

What is a one-way function? For example, there is a doubling function, i.e. double(4)=8, it is two-sided, because from result 8 it is easy to obtain the initial value 4. A one-way function is a function after applying which it is almost impossible to obtain the initial value. For example, mixing yellow and blue paint is an example of a one-way function. Mix them up easily, but to get the original components back - impossible. One such function in mathematics is modulo calculation.

As a basis for the algorithm, Hellman proposed the function Y x (mod P). Reverse conversion for such a function it is very difficult, and we can say that, in essence, it consists of a complete enumeration of the original values.

For example, you were told that 5 x (mod 7) = 2, try to find x, A? Found it? Now imagine that numbers on the order of 10,300 are taken as Y and P.

By the way, to increase durability, the number P must be a prime number, and Y- be a primitive root modulo P. But since we are still trying to understand the theory, I don’t see the point in bothering with this.

Diffie-Hellman algorithm

And then one day it dawned on Hellman and he was able to develop a working key exchange algorithm. This algorithm requires steps on both sides to work, so I'll put it in a table:

Alice Bean
Stage 1 Both participants agree on meanings Y And P for a general one-way function. This information is not secret. Let's say the values ​​were selected 7 And 11 . The general function would look like this: 7 x (mod 11)
Stage 2 Alice chooses random number, For example 3 A Bob chooses a random number, for example 6 , keeps it secret, let's denote it as a number B
Stage 3 Alice substitutes the number A 7 3 (mod 11)= 343 (mod 11) = 2 a Bob plugs in the number B V general function and calculates the result 7 6 (mod 11)= 117649 (mod 11) = 4 , denotes the result of this calculation as a number b
Stage 4 Alice passes the number a Bob Bob passes the number b Alice
Stage 5 Alice gets b from Bob, and calculates the value b A (mod 11)= 4 3 (mod 11) = 64 (mod 11) = 9 Bob gets a from Alice, and calculates the value a B (mod 11)= 2 6 (mod 11) = 64 (mod 11) = 9
Stage 6 Both participants ended up with a number 9 . This will be the key.

Magic? I don’t argue, it’s not clear at first glance. But after reading and thinking about this table, it becomes clear how it works. However, if it is not clear, then scroll to the end of the chapter, where I posted an explanatory video.

Moreover, please note that to obtain the key in the final formula, any person needs to have three values:

  • Values a And P, and Bob's secret number B
  • or meanings b And P, and Alice's secret number A

But secret numbers are not transmitted over the channel! Eve won't be able to recover the key without someone's secret number. Why - I wrote above, this function is one-sided. Try solving the equation 4 x (mod 11) = 2 y (mod 11) having found x And y.

To make it clearer how the Hellman scheme works, imagine a cipher that somehow uses color as a key:

Let's first assume that everyone, including Alice, Bob and Eve, has a three-liter jar into which one liter of yellow paint is poured. If Alice and Bob want to agree on a secret key, they each add one liter of their own secret paint to their jars.

Alice can add purple paint, and Bob can add crimson. After that, each of them sends his jar with the mixed contents to the other.

Finally, Alice takes Bob's mixture and adds one liter of her secret paint to it, and Bob takes Alice's mixture and adds one liter of his secret paint to it. The paint in both cans will now be the same color, since each can contains one liter of yellow, purple and crimson paint.

It is this color, obtained by adding twice to the paint jars, that will be used as a key. Alice has no idea what kind of paint Bob added, and Bob also has no idea what kind of paint Alice poured, but they both achieved the same result.

Meanwhile, Eve is furious. Even if she were able to intercept the jars containing the intermediate product, she would not be able to determine the final color, which would be the agreed upon key. Eve can see the color of the paint obtained by mixing the yellow paint and Alice's secret paint in the jar sent to Bob, and she can see the color of the paint obtained by mixing the yellow paint and Bob's secret paint in the jar sent to Alice, but to find the key, she, in fact, it is necessary to know the colors of Alice and Bob's original secret paints. However, by looking at the jars of mixed paints, Eve will not be able to identify Alice and Bob's secret colors. Even if she takes a sample of one of the mixed paints, she will not be able to separate it into the original paints to find the secret one, since mixing paint is a one-way function.

Still not clear? Then watch the video:

Well, I hope you understand that there is quite real way secure key exchange. But please note that it is not yet possible to call this algorithm an asymmetric cipher, since in essence it is just a key exchange algorithm.

Asymmetric encryption

an asymmetric algorithm assumes the presence of two keys - public and private. That is, the message is encrypted with a public key and decrypted with a private key and nothing else. Actually, it was this concept that Diffie formulated.

In general, the essence of this algorithm is that the receiving side, before receiving the message, generates a pair of keys based on the modular arithmetic algorithm (the principle is the same as in the Diffie-Hellman algorithm), the actual private and public key. Before sending, the sender receives a public key and encrypts the message with this key, after which this message can only be decrypted with a private key, which is kept secret by the receiving party.


If we return to the analogy with locks, then public key encryption can be thought of as follows:

Anyone can lock a lock by simply clicking it until it closes, but only someone who has the key can unlock it. Locking a lock (encryption) is easy, almost everyone can do it, but only the owner of the key can open it (decryption). Understanding how to latch a lock so it closes won't tell you how to unlock it.

A deeper analogy can be drawn.

Imagine that Alice is designing a lock and key. She vigilantly guards the key, but at the same time makes thousands of duplicate locks and sends them to post offices around the world. If Bob wants to send a message, he puts it in a box, goes to the local post office, asks for an "Alice lock" and locks the box with it. Now he will no longer be able to open the box, but when Alice receives the box, she will be able to open it with her only key.

Putting a lock and clicking it to close is equivalent to a shared key for encryption, since everyone has access to the locks and everyone can use the lock to lock the message in the box. The key to the lock is equivalent to the secret decryption key because only Alice has it, only she can open the lock, and only she can access the message in the box.

There are several algorithms that implement asymmetric encryption. The most famous of them is RSA. I don’t see the point in describing it, since I still won’t be able to understand how it works right away, and I still won’t be able to write it better than what’s written on Wikipedia.

Conclusion

Well, I hope that, having understood how asymmetric encryption works from the inside, you will begin to trust it more and, accordingly, use SSL more often =)

Materials were used from the book Singh Simon - Book of Codes. By the way, the best book for those who want to understand at least a little about cryptography. I advise everyone to read it.

  1. tv

    Selecting such a key will take you a lot of time. Little more than the universe exists. Even on very powerful computers.

  2. Igor

    What is this nonsense with public keys for? Symmetrical ones are more reliable.
    Good afternoon
    Good site, the material is clearly presented, many thanks to the author. I came here by accident in September, when I was looking for information on practical encryption.
    I am writing because I want to ask: Anyone want to know how to find numbers for symmetric encryption? I can teach you how to quickly check the number P for primality (without searching for the number g) - but this is unlikely to be interesting. The most interesting:
    Find the number P of any length and the number g to it. I don’t use any 2 to the power of n plus one (or minus one). Naturally, it's free. There is even a website where I posted my work.

  • Uasya Petrovich

    I understand that a lot of time has passed, but I will still answer for new readers like me.

    This won't work because... after actions 2 and 3 we see the difference by which the number of each of the blocks has changed, therefore Bob’s secret number becomes obvious to us and we can only intercept the message after the 4th action (i.e. without Alice’s cipher) and use what is already known to us Bob's number.

  • Eugene

    Thank you so much for the article!
    After reading, almost everything fell into place on its own shelves and acquired a structure that was easy to expand upon.
    Having such a structure, it is easy to generate the right questions (MiTM attack shelf, special thanks to Mikhail :)).

    From a pedagogical point of view, you did everything perfectly. I think you are right that you did not add MiTM attacks to this article, otherwise there would have been information overload.

    The video is adorable, especially considering its age.

    PS: the use of metaphors to explain “complex” systems is frankly difficult to overestimate. Thanks again!

  • dbzix

    From this article I did not catch the moment of transition from the Diffie-Hellman algorithm, where two subscribers exchange public data and intermediate results of calculations to obtain a secret key (in the example there were as many as 6 stages) to the stage where a certain public key is used for encryption, which is then decrypted using a private one (I count here only 2 stages of data transfer - sending a public key and sending a message encrypted with this key).
    Those. I understand that somewhere between these two explanations there is probably a lot of mathematics hidden, and in the end the explanation boils down to “this is how it works, just trust me.” But it would probably be easier to understand this sudden transition if the analogy with paints were extended to explain the essence of encryption with a public key followed by decryption with a private one. In the meantime, the result is some kind of “B works because A,” while there is no clear connection between A and B. At least for me.
    Dear author, would you be so kind as to explain to me this mystical jump from A to B? :) Thank you!

  • Eugene

    Good afternoon,

    Given: there is a formula Y^x (mod P).
    the example in the article is based on the formula 7^x (mod 11)

    I took 4^x (mod 7) for my example
    and I couldn’t come up with a common key.
    Question: why does the algorithm in the example work for 7^x (mod 11) and not for 4^x (mod 7)?

  • Jessi-jane
  • Andrey

    Thank you, great article!
    Only now I almost figured out the algorithm, how to calculate through the module.
    Could you tell me how to calculate the number B if the number A is less than the modulus?
    Well, for example:
    3(mod 13) = ?

    I know that if, for example, you need to calculate 625(mod 13), you need 625/13, and then multiply the largest possible integer divisor (48) by the modulus (which here will be equal to 624), and finally 625-624 = 1
    The numbers 625 and 1 are comparable modulo 13, since 624 is divisible by 13.
    This is what I understand. But what if the module is greater than the number a?

  • Yellow Horror

    1. Man-in-the-middle attack is a serious problem. As far as I can tell, within the framework of cryptography alone, this problem cannot be solved in principle: if we accept that Eve is capable of intercepting and imperceptibly replacing ALL data coming to Alice or emanating from her via ANY communication channels, no encryption will help. At least one certificate must be obtained by Alice from a completely reliable source. But if an attacker can only listen to the communication channel and not change the data in it, asymmetric encryption is quite reliable.
    2. As for the ability to remove one “cipher layer” from under another, the banal XOR function, widely used in cryptography from ancient times to this day, has this property. I don't think it can be patented :(

    1. Dmitry Amirov Author

      Yes you are right, mitm attack Today there is no way to solve it if you are absolutely paranoid. If they are not, then fiddling with certificates and signatures will provide “necessary and sufficient” protection.

      As for the XOR function, it can hardly be called a cipher, because it is not one in its essence.

      1. Yellow Horror

        Come on? Google the Vernam Cipher. This is a messaging system with absolute crypto-resistant. And it is based precisely on XOR. Leaving aside some organizational difficulties (creating truly random keys with uniform distribution, maintaining the secrecy of the encryption pad in an unfriendly environment, and securely destroying used keys), humanity has not yet come up with anything simpler and more reliable.

      2. Yellow Horror

        Although, upon reasonable reflection, I realized that the double reversible encryption method does not work if the attacker knows the encryption algorithm. Let's look at Mikhail's ideas as an example:

        1. We break the encrypted information into blocks. Each block is represented by a number. The block size (number of bits) determines the number of possible block values ​​and (accordingly?) the strength of the encryption.
        2. To encrypt the message, Alice selects a secret number (which she does not send to anyone), which she adds to each of the numbers in the blocks and sends the message encrypted in this way to Bob.

        So far so good: Eve can't read Alice's message because... does not know the key number. If the blocks are large enough, it is difficult to recover Alice’s message, but if the block is longer than the message and the key does not have vulnerabilities, it is impossible. But Eve can and does copy Alice's ciphergram.

        3. Bob receives the encrypted message, chooses his secret number (which he also does not send to anyone), adds this number to each of the numbers in the blocks of the message encrypted by Alice, and sends this double-encrypted message to Alice.

        And here the problems begin: Eve still cannot read Alice’s message, but, having a copy of the ciphergram received by Bob and the double encryption sent by him, she can easily restore key Boba.

        4. Alice subtracts her secret number from each number in the blocks of this double-encrypted message and sends the resulting message to Bob.

        Alice has removed her “layer” of cipher and now sends Bob her letter, encrypted only with Bob’s key. Which Eva already has! Eve decrypts the letter and reads it, and, just in case, can recover Alice’s key using the decrypted text of the letter and the first ciphergram she intercepted.

  • Dmitriy

    Hello. Good article, but I also did not understand some of the points described above.
    It is the transition from the algorithm for obtaining a secret key by both interlocutors (Alice and Bob) (without putting them into public access) to asymmetric encryption.
    You write that the message is encrypted on Alice's side with the public key received from Bob. But if we encrypt with a public key, then Eve can easily get it and decrypt it herself, right?
    It still remains unclear to me how you can encrypt with a public key and decrypt only secret on Bob's side. That is, they encrypted it with the word “Home”, and deciphered it with the word “World”. For me this is some kind of nonsense.
    Based on these obvious gaps (either yours or mine), I concluded that the circuit here must be more complicated than in the picture. Most likely, the arrow from Bob’s public key to Alice means something else, namely the entire sequence of actions to obtain “Y” and “P”, obtain intermediate results, etc. In other words, I think that when the original message is encrypted with a supposedly public key, it is actually encrypted not with a public key, but with a secret one, which is calculated on each side separately.

    I also had a question about decrypting a double-encrypted message. If we take, say, the Caesar cipher, where each letter is encrypted with another letter, standing, say, 3 positions further. If Alice encrypts the letter A in the message with the letter B, and then Bob encrypts this letter B with the letter G, then it will be easy to obtain the letter A from G, and in any order. True, this will most likely work only in cases where both know the encryption type of the interlocutor and with fairly simple encryption types (monoalphabetic/polyalphabetic). I'm also new to cryptography, so this is my opinion ;)

    1. Dmitriy

      I forgot to ask.
      What is the difference between symmetrical and asymmetrical methods?

      1. Dmitriy

        I read it, more or less somehow grouped everything in my mind.
        I will answer the questions I wrote, perhaps thereby helping other readers.
        1. About

        You write that the message is encrypted on Alice's side with the public key received from Bob. But if we encrypt with a public key, then Eve can easily get it and decrypt it herself, right?
        It also remains unclear to me how it is possible to encrypt with a public key and decrypt only with a secret one on Bob’s side. That is, they encrypted it with the word “Home”, and deciphered it with the word “World”. For me this is some kind of nonsense.

        This article mentions the RSA algorithm. Symmetric encryption algorithm. It actually uses the following algorithm:
        1) Based on a certain one-way encryption function (a function that is easy to calculate in one direction, but very difficult in the other. A) we create a pair on the recipient (public key; private key). This pair is unique, that is, each public key corresponds to a unique private key for this one-way function.

        3) The sender encrypts the message
        4) Transfers to the recipient

        As you can see, the sender does not know the private key and he is not able to decrypt his own encrypted message. That's why it's called asymmetric, because one has all the keys, and the other only has the part needed for encryption.

        What is the difference between symmetrical and asymmetrical methods?
        If I used the Diffie and Hellman algorithm to transmit the secret key, and then was able to securely transmit the encrypted message, would this method be symmetric?

        The Daffy-Hellman algorithm, which serves for key exchange and further symmetric encryption. That is, its essence is that first both receive full key for encryption and decryption, and then they begin the most common symmetric encryption.

        Asymmetric method - one node has all the information for encryption/decryption, and the other, as a rule, only for encryption

        Symmetric - both nodes know all the information for encryption/decryption.

        I hope I helped someone;3

        1. Dmitriy

          This article mentions the RSA algorithm. Asymmetric encryption algorithm I sealed it.

        2. Dmitry Amirov Author

          Hmm... just now noticed your comments. My apologies.

          Everything seems to be correct. There is one thing about your last paragraph, specifically the terms:

          • Daffy-Hellman algorithm- is an algorithm that allows you to obtain one shared secret key and nothing more
          • Asymmetric/symmetric encryption- in general, everything is correct with you
          • RSA- an algorithm that is a combination of these things. On your fingers: using asymmetric encryption using the Deffie-Helman protocol, a secret key is established with the help of which messages between interlocutors are encrypted using the symmetric encryption method.
        3. Dmitriy

          I still didn't understand the statement:
          2) The public key is transferred to the sender.
          3) The sender encrypts the message
          4) Transfers to the recipient
          5) The recipient decrypts using the private key. This message cannot be decrypted using the public key.

          It turns out that you had in mind from the very beginning. We encrypt with the word Home, and decrypt with the word World. Does this mean that there is another algorithm connecting the World and the Home with each other?

  • Robert

    Thanks a lot!!!

  • Novel

    Thank you. I finally decided to figure out how it works and learned from this article. Only, I believe, if the accomplices know each other and it is possible to exchange public keys securely, then it is worth doing. To eliminate the detrimental impact of the possible appearance of a person in the middle when exchanging keys, who will pretend to be A as B and B as A, replacing the keys with their own and ultimately viewing all the information.

    And in the video, I think it’s in vain that they use this 3^(24*54), because It’s not at all obvious where it came from, or they would explain that it’s conditional.

  • RinswinD

    Thank you for the article. Everything is explained very clearly.

  • grigory

    Well, this illiteracy of spelling irritates everyone - “one-sided”, “applied”, “long”, as if in the 5th grade. And so, not bad for understanding the basics.

  • grigory

    Sometimes the question is simple. Ransomware viruses use a private key. There is an original file, there is an encrypted file. Task: find an algorithm, so to speak, that looks for an algorithm for converting the first file into the second...

  • Allexys

    Thank you for the clear and fun article! Finally I got the hang of the basics :).

  • Yaroslav

    Unfortunately, all available algorithms still require the removal of ciphers in the queue in which they were applied.

    This is not entirely true. I'll give you an example:
    — suppose that each letter corresponds to digital code A = 1, B = 2, C = 3, etc.;
    — suppose that Alice sends Bob a letter consisting of a single letter A (to simplify the example);

    Alice: puts her cipher A + 2 = B

    Bob: puts his cipher B + 3 = E
    Bob: sends a letter to Alice
    Alice: removes her cipher E - 2 = G
    Alice: sends a letter to Bob
    Bob: removes his cipher G - 3 = A

    Here the number 2 is Alice's secret key, 3 is Bob's secret key. Moreover, it may not be one-character. In principle, its length is unlimited.

  • Dmitriy

    I've been avoiding for a long time theoretical basis asymmetric encryption. I knew superficially - there is a public key with which the data is encrypted, and there is a private key with which the data is decrypted. But the thought of implementing such encryption has always bothered me.
    Your article helped a lot, thank you very much for that!
    Only towards the end of it did I see this nonsense again - “encrypted with a public key.” After all, strictly speaking, the message is encrypted not with a public key, but with a key obtained based on the sender’s private key and the recipient’s public key (which, in turn, was generated based on the recipient’s private key). Indeed, in the table about Alice and Bob - they and only they were able to obtain the same key “9” - it is used to encrypt and decrypt the message. But this key can only be obtained based on a pair of keys - secret (Alice/Bob) and public (Bob/Alice).
    Figuratively - yes, the message is always encrypted with the sender’s secret key (it is, roughly speaking, constant) and the recipient’s public key (it depends on the specific recipient), therefore, in the description, encryption with the “secret” key is omitted - and this omission breaks the whole order of reasoning.

  • Clarkson

    I read the article and didn’t understand it very well, although it was better than on the wiki. But there’s just one thing I don’t understand. If anyone can answer correctly, please help.

    if I send everyone the question “how much is 2+2?”, I tell them how to encrypt the answer to me (I tell everyone the public key), and everyone will send me an answer to the question, how do I find out from whom exactly I am waiting for an answer, that is, with whom Did I really want to make a connection?

    1. Dmitry Amirov Author

      Here you are asking the question a little wrong.

      If you need to establish a connection with someone, then you need to go from the opposite direction. You connect to your interlocutor, and already he will tell you provides your public key, not you.

      UPD: wrote an article about, I think this will be the correct answer to your question.

      1. Clarkson

        I'll have to fight my stupidity. the topic is discussed in the comments and in your article, it seems that everything was explained.

        yet. Why do I need to publish his key? tell me if I don't understand correctly.
        I am the initiator (I need answers, in the example I am the receiving party), which means I generate a pair. it’s him who responds (the sender in your example) who needs my public

        Before sending, the sender receives a public key and encrypts the message with this key, after which this message can only be decrypted with a private key, which is kept secret by the receiving party.

  • Beshot

    I re-read this article and others on the topic several times, but the algorithm for using digital signatures in email is unclear. documents If it’s like this here: https://ru.wikipedia.org/wiki/Electronic_signature, then discrepancies arise. So do we still encrypt using a private key or a public one?

    1. Dmitry Amirov Author

      If we sign something, we form the signature based on our private key. And the recipient must have our public key, with the help of it he will be able to decrypt this signature.

      If the signature is “decrypted”, then the public key corresponds to the private key, and since a priori, only the sender has the private key, which means it was the sender who signed the document.

      1. Beshot

        Dmitry, your article helped me a lot, you have good style. But there is an incomprehensible point: you claim that the asymmetric algorithm assumes the presence of two keys - public and private. That is, the message is encrypted with a public key and decrypted with a private key and nothing else.

        It may be a matter of the original task, for example the recipient needs to authenticate the messenger.
        Then I can’t imagine how this scheme can help?

        1. Dmitry Amirov Author

          That is, the message is encrypted with a public key and decrypted with a private key and nothing else.

          Not entirely true. The message is encrypted with one key and decrypted with another. Those. It’s entirely possible to encrypt it privately and decrypt it publicly.

          Let's look at an example. You want to send me a message, I want to make sure that it was you who sent it to me. Step by step:
          1) You encrypt the message with the private key
          2) Send it to me
          3) I contact you and receive your public key from you
          4) I decrypt the received message with your public key
          5) If the message is decrypted, it means you were the one who sent it

          No one else can send this message pretending to be you, because only you have the private key.

          1. Beshot

            Ok, but what if you need to hide a message from prying eyes?

  • Anya

    Good afternoon I liked the article, but I still had questions (there were even a couple of similar ones in the comments, but without answers).
    If in the second part of the article we move on to the analogy with Alice and Bob, in particular to the numbers A, B, a, b, P and the number 9 obtained in the example, which of them will be the private key and which will be the public key? Thanks in advance for your answer!

    1. Anya

      It’s not clear whether my comment was posted or not :(

    2. Dmitry Amirov Author

      It would be more correct to say that in the process of exchanging data, Alice and Bob receive a common key 9 , which can later be used to encrypt their messages. In fact, in the article I described not asymmetric encryption itself, but the key exchange protocol, which gave impetus to the development of asymmetric encryption.
      The algorithm for generating a private/public key pair is actually a little more complicated, although it is similar to the algorithm outlined above, but still probably deserves a separate article. I won’t write this out right away in the comments, because I might confuse a lot of things.

  • Gregory
  • Did you like the article? Share with your friends!
    Was this article helpful?
    Yes
    No
    Thanks for your feedback!
    Something went wrong and your vote was not counted.
    Thank you. Your message has been sent
    Found an error in the text?
    Select it, click Ctrl + Enter and we will fix everything!