-
- if(!digest_open_sha1(&c->outdigest, -1))
- return false;
-
- size_t len = rsa_size(&c->rsa);
- char key[len];
- char enckey[len];
- char hexkey[2 * len + 1];
-
- /* Create a random key */
-
- randomize(key, len);
-
- /* The message we send must be smaller than the modulus of the RSA key.
- By definition, for a key of k bits, the following formula holds:
-
- 2^(k-1) <= modulus < 2^(k)
-
- Where ^ means "to the power of", not "xor".
- This means that to be sure, we must choose our message < 2^(k-1).
- This can be done by setting the most significant bit to zero.
- */
-
- key[0] &= 0x7F;
-
- cipher_set_key_from_rsa(&c->outcipher, key, len, true);
-
- ifdebug(SCARY_THINGS) {
- bin2hex(key, hexkey, len);
- logger(LOG_DEBUG, "Generated random meta key (unencrypted): %s", hexkey);