No. The public key in the key pair always corresponds to the size of the private key, in fact, it is obtained from the private key.
However, with some public key cryptographic implementations, such as OpenPGP , keys are created with subsections assigned to different tasks. These subsections can be of different sizes for each other and the master key used to create them. In these cases, the public key data will indicate the key sizes for the master key and subkey (s) that will correspond to the corresponding private key data.
While many other public key implementations do not use subkeys (for example, TLS ), so you will see only one key size. Again, the key size will be indicated in both public and private keys.
The only key size change you'll see is when asymmetric encryption is used in combination with symmetric encryption. Symmetric encryption (session key) will be less, but it uses completely different algorithms (for example, AES, TWOFISH, etc.) and is not part of the public key (except for OpenPGP, where symmetric encryption settings can be saved because it is not to be used live connection for establishing symmetrically encrypted data exchange and exchange of session data).
EDIT: more information on the relationship between public and private key data (also known as David's false evidence)
Pointing to RSA is all very good and good, but it depends on the key exchange protocol, and for this we go to Diffie-Hellman Key Exchange and the original patent , which has expired. Both of them have examples and explanations of key exchange methods and the relationship between public and private keys.
Algorithms that implement this relationship, including RSA and El-Gamal , all simultaneously create both public and private keys. In particular, by creating a private key, which then generates a public key. The public key inherits all the functions of the private key that created it. A method only for receiving incorrectly matched data between two components will somehow generate a public key regardless of the private key. The problem there, of course, is that they will no longer be a key pair.
The key generation description for RSA and El-Gamal explains the common data between the public and private keys and, in particular, that all components of the public key are part of the private key, but the private key contains additional data necessary to decrypt the data and / or sign the data. In El-Gamal, the publicly available components are G, q, g, and h, and the private components are G, q, g, h, and x.
Now, due to the lack of mention of the bit size of key pairs in the algorithms, yes, this is true, but each practical implementation of them includes the selected key size as one of the constants when generating the private key. Here is the appropriate code (after selecting all options, including choosing a key size and determining a passphrase) for generating keys in GnuPG:
static int do_create( int algo, unsigned int nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek, STRING2KEY *s2k, PKT_secret_key **sk, u32 timestamp, u32 expiredate, int is_subkey ) { int rc=0; if( !opt.batch ) tty_printf(_( "We need to generate a lot of random bytes. It is a good idea to perform\n" "some other action (type on the keyboard, move the mouse, utilize the\n" "disks) during the prime generation; this gives the random number\n" "generator a better chance to gain enough entropy.\n") ); if( algo == PUBKEY_ALGO_ELGAMAL_E ) rc = gen_elg(algo, nbits, pub_root, sec_root, dek, s2k, sk, timestamp, expiredate, is_subkey); else if( algo == PUBKEY_ALGO_DSA ) rc = gen_dsa(nbits, pub_root, sec_root, dek, s2k, sk, timestamp, expiredate, is_subkey); else if( algo == PUBKEY_ALGO_RSA ) rc = gen_rsa(algo, nbits, pub_root, sec_root, dek, s2k, sk, timestamp, expiredate, is_subkey); else BUG(); return rc; }
The slight differences between the three algorithms relate to the values ββfor the elements mentioned in the published algorithms, but in each case, "nbits" is a constant.
You will find the same consistency associated with the key size in the code for generating keys in OpenSSL, OpenSSH and any other system that uses public key cryptography. In each implementation, in order to have a consistent pair of public and private keys, the public key must be obtained from the private key. Since the private key is generated with the key size as a constant, this key size must be inherited by the public key. If the public key does not contain all the correct general information with the private key, then by definition it will not correspond to this key and, therefore, the encryption / decryption processes and the signature / verification processes will not work.