5

I am using Whisper private network to post the message and get the message. It is working fine.

I analysed the process and found that there is no private key is generated.

I have seen that the public key (x,y,curve) is generated based on the To address. Message is encrypted using this and sent.

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.

Can any one help me or correct me in the above.

2
  • What do you mean by you having "analysed the process"? Decrypting a message without the private key should not be possible. Are you sure the message is actually encrypted? Dec 25, 2016 at 17:43
  • I have gone through all the steps and put various print statements. Messages are getting encrypted and decrypted. Key generation part is not clear. Keys are generated only using From and To address.
    – userven
    Dec 26, 2016 at 13:12

1 Answer 1

3

"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.]

1
  • How recipient's public key is published on a P2P server? Is it publicly readable? @Richard Horrocks
    – alper
    Nov 4, 2018 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.