"I am not clear how the private key is generated at the receiver side
to decrypt the message. I found that no additional inputs are given to
decrypt other than the sealed envelope."
There are two cases:
- If you're sending a message to a specific recipient;
- If you're sending a multicast message.
Specific recipient
If the message is for a specific recipient - i.e. it's not a multicast message - then it will have been encrypted with the recipient's public key, which was published on a P2P server when the recipient originally joined the network.
From the Envelopes and Messages section of How to Whisper:
Whenever a message needs to be encrypted for a specific recipient
supply the Opts
struct with an additional To
parameter which accepts
the recipients public key (ecdsa.PublicKey
).
The pseudocode in Putting it all together shows that the keypair is generated via SECP-256k1:
pub, _ := secp256k1.GenerateKeyPair()
And the public key published:
srv := p2p.Server{
MaxPeers: 10,
Identity: p2p.NewSimpleClientIdentity("my-whisper-app", "1.0", "", string(pub)),
ListenAddr: ":8000",
Protocols: []p2p.Protocol{whisper.Protocol()},
}
Decryption is then just a case of the recipient using their private key.
Multicast message
In this case there's no single recipient, so you can't use a published public key. In which case:
If the message has no recipient, then [the payload is encrypted] by AES-256 with a randomly
generated key. This key is then XORed with each of the full topics to
form a salted topic.
The "topics", to put it very simply, are like binary tags or keywords that allow interested parties to look for and receive a given message. More specifically:
Each topic is determined as the first (left) 4 bytes of the SHA3-256
hash of some arbitrary data given by the original author of the
message
Then to decrypt we reverse the process, with the key assumption being that the recipient(s) must know at least one of the topics (because it's the "keyword" they're using to identify the message):
...we assume that at least one topic is known (since
otherwise, the envelope could not be properly "identified"). In this
case, we match the known full topic to one of the abridged topics in
the envelope, determine the index and de-salt the according salted-key
at the beginning of the data segment in order to retrieve the final
key.
[These snippets are sourced from the Messages section of the Whisper Protocol Spec.]