3

I want to use bouncycastle in order to perform Diffie-Hellman key exchange between two software components (Alice and Bob). Alice and Bob have their own key pair, issued from the same CA. However, Alice will be Java and Bob will be C#.

I've searched for - and found - examples of how to perform the exchange in each language. But I have 2 issues with the examples that I find:

  1. The examples over-simplify by implementing the exchange between Alice and Bob in the same block of example code. I'm having trouble understanding what Alice and Bob would look like when they actually have to exchange their intermediate values (g^a mod p and g^b mod p) over an SSL stream.
  2. The examples are always for software components written in the same language. I've read elsewhere that the Diffie-Hellman key exchange libraries often use some internal constants in order to generate their intermediate values. Based on my knowledge of how DH works, I don't see where any sort of constants would be necessary, but I'm no expert.

Based on those two issues, I have two questions:

  1. Does anyone know of a code example that shows the code for both sides separately, and
  2. If I use the bouncycastle APIs for both the java and .net components, does anyone know of any reason why the components would not be able to agree upon the same secret symetric key?
John Ruiz
  • 2,371
  • 3
  • 20
  • 29
  • The necessary constants are the ones fixed, namely: The group in which we work, and one generator of this group. For usual modular DH, this means the modulus `p` and the generator `g`. – Paŭlo Ebermann Nov 08 '11 at 22:45
  • Also, do you want to implement SSL (or TLS), or do you want to create your own protocol (instead or on top of SSL/TLS)? – Paŭlo Ebermann Nov 08 '11 at 22:46
  • @Paulo - Since both Alice and Bob have their own key pair, I was hoping to establish SSL on TCP and use that stream to perform DH key exchange between them. Did I answer your question, or are you asking something else? – John Ruiz Nov 09 '11 at 00:11
  • So, why do you need another DH exchange, if you already have SSL, which protects your data connection? DH is mainly useful if the connection can be listened on (for example, in the SSL handshake). – Paŭlo Ebermann Nov 09 '11 at 00:16
  • I see what you're getting at now. The key that gets generated from performing DH isn't meant to provide confidentiality for communication between Alice and Bob. As you say, SSL already provides confidentiality. I'm using SSL for mutual authentication. Once Alice and Bob are certain that they're talking to each other, I want them to generate a temporary, shared, symmetric key for other purposes. – John Ruiz Nov 09 '11 at 01:49
  • 1
    You could then have simply one of them generate the key and send to the other. (Not that I want to talk you out of using Diffie-Hellman, it just seems a bit superfluous overhead. And I don't know sample code.) If you show the BouncyCastle code you are using, maybe we can find your mistake. – Paŭlo Ebermann Nov 09 '11 at 02:01
  • Have you been able to figure this out? I am trying to get the same thing going on between an server and client. – usselite Feb 04 '16 at 10:00

0 Answers0