I'm interested in cryptography, but unfortunately haven't found the time to dive into the topic much. I have done some quantum encryption stuff back in the day, but that isn't helping me with my current challenge. I hope this community can help me to get going with the following.

I am currently implementing security measures on the nginx ingress and -servers my team uses, for this I'm following the latest CIS NGINX benchmark. So far so good. On the topic of Diffie-Hellman parameters, I was able to create a 4096 bit DH key using openssl and configure it to be used. So far still good.

My team's management is checking a certain website to see if our websites are secure (internet.nl, which is created by the Dutch Cyber Security Center, a government organisation). This website detects that we have a 4096 bit DH key in place, but they disregard it, as they do not trust self-generated keys. They are referring to the finite-field groups available here: IETF: Negotiated Finite Field Diffie-Hellman Ephemeral Parameters for Transport Layer Security (TLS).

I want to follow their recommendations, but do not really know how to approach this.

My question is: How can I get a diffie-helman key in PEM format from the finite-field group, defined in the following way?

A.3.  ffdhe4096

   The 4096-bit group has registry value 258 and is calculated from the
   following formula:

   The modulus is:

   p = 2^4096 - 2^4032 + {[2^3966 * e] + 5736041} * 2^64 - 1

   The hexadecimal representation of p is:

    D8B9C583 CE2D3695 A9E13641 146433FB CC939DCE 249B3EF9
    7D2FE363 630C75D8 F681B202 AEC4617A D3DF1ED5 D5FD6561
    2433F51F 5F066ED0 85636555 3DED1AF3 B557135E 7F57C935
    984F0C70 E0E68B77 E2A689DA F3EFE872 1DF158A1 36ADE735
    30ACCA4F 483A797A BC0AB182 B324FB61 D108A94B B2C8E3FB
    B96ADAB7 60D7F468 1D4F42A3 DE394DF4 AE56EDE7 6372BB19
    0B07A7C8 EE0A6D70 9E02FCE1 CDF7E2EC C03404CD 28342F61
    9172FE9C E98583FF 8E4F1232 EEF28183 C3FE3B1B 4C6FAD73
    3BB5FCBC 2EC22005 C58EF183 7D1683B2 C6F34A26 C1B2EFFA
    886B4238 611FCFDC DE355B3B 6519035B BC34F4DE F99C0238
    61B46FC9 D6E6C907 7AD91D26 91F7F7EE 598CB0FA C186D91C
    AEFE1309 85139270 B4130C93 BC437944 F4FD4452 E2D74DD3
    64F2E21E 71F54BFF 5CAE82AB 9C9DF69E E86D2BC5 22363A0D
    ABC52197 9B0DEADA 1DBF9A42 D5C4484E 0ABCD06B FA53DDEF
    3C1B20EE 3FD59D7C 25E41D2B 669E1EF1 6E6F52C3 164DF4FB
    7930E9E4 E58857B6 AC7D5F42 D69F6D18 7763CF1D 55034004
    87F55BA5 7E31CC7A 7135C886 EFB4318A ED6A1E01 2D9E6832
    A907600A 918130C4 6DC778F9 71AD0038 092999A3 33CB8B7A
    1A1DB93D 7140003C 2A4ECEA9 F98D0ACC 0A8291CD CEC97DCF
    8EC9B55A 7F88A46B 4DB5A851 F44182E1 C68A007E 5E655F6A

   The generator is: g = 2

   The group size is: q = (p-1)/2

Gillmor                      Standards Track                   [Page 22]

RFC 7919                Negotiated FFDHE for TLS             August 2016

   The hexadecimal representation of q is:

    7FFFFFFF FFFFFFFF D6FC2A2C 515DA54D 57EE2B10 139E9E78
    EC5CE2C1 E7169B4A D4F09B20 8A3219FD E649CEE7 124D9F7C
    BE97F1B1 B1863AEC 7B40D901 576230BD 69EF8F6A EAFEB2B0
    9219FA8F AF833768 42B1B2AA 9EF68D79 DAAB89AF 3FABE49A
    CC278638 707345BB F15344ED 79F7F439 0EF8AC50 9B56F39A
    98566527 A41D3CBD 5E0558C1 59927DB0 E88454A5 D96471FD
    DCB56D5B B06BFA34 0EA7A151 EF1CA6FA 572B76F3 B1B95D8C
    8583D3E4 770536B8 4F017E70 E6FBF176 601A0266 941A17B0
    C8B97F4E 74C2C1FF C7278919 777940C1 E1FF1D8D A637D6B9
    9DDAFE5E 17611002 E2C778C1 BE8B41D9 6379A513 60D977FD
    4435A11C 308FE7EE 6F1AAD9D B28C81AD DE1A7A6F 7CCE011C
    30DA37E4 EB736483 BD6C8E93 48FBFBF7 2CC6587D 60C36C8E
    577F0984 C289C938 5A098649 DE21BCA2 7A7EA229 716BA6E9
    B279710F 38FAA5FF AE574155 CE4EFB4F 743695E2 911B1D06
    D5E290CB CD86F56D 0EDFCD21 6AE22427 055E6835 FD29EEF7
    9E0D9077 1FEACEBE 12F20E95 B34F0F78 B737A961 8B26FA7D
    BC9874F2 72C42BDB 563EAFA1 6B4FB68C 3BB1E78E AA81A002
    43FAADD2 BF18E63D 389AE443 77DA18C5 76B50F00 96CF3419
    5483B005 48C09862 36E3BC7C B8D6801C 0494CCD1 99E5C5BD
    0D0EDC9E B8A0001E 15276754 FCC68566 054148E6 E764BEE7
    C764DAAD 3FC45235 A6DAD428 FA20C170 E345003F 2F32AFB5

   The estimated symmetric-equivalent strength of this group is 150

   Peers using ffdhe4096 that want to optimize their key exchange with a
   short exponent (Section 5.2) should choose a secret key of at least
   325 bits.

Any advice or answers you might have are very welcome. Thanks up front!

Best, Ludo

  • $\begingroup$ This isn't really a cryptography question, and you want parameters (for DHE) NOT A KEY but: if you have nginx you have OpenSSL which as of 1.1.1 not only implements the rfc7919 groups (as a TLS 1.2 and/or 1.3 implementation should) but exposes them. See openssl.org/docs/man1.1.1/man3/DH_new_by_nid.html and openssl.org/docs/man1.1.1/man3/PEM_write_DHparams.html (or the DHxparams version if you want X9.42 format, but for nginx you don't). $\endgroup$ – dave_thompson_085 May 27 at 23:43
  • $\begingroup$ Thanks for pointing me to openssl. I'm only used to running openssl in cli, and I it looks like that doesn't support the PEM functions, correct? Do you have any advice how I can used those functions? I'm ok with bash, but not much into C and other languages, unfortunately. $\endgroup$ – L de Pudo Jun 10 at 12:58
  • $\begingroup$ I looked more thoroughly and there is commandline support, not (yet?) documented; use openssl genpkey -genparam -pkeyopt dh_param:ffdhe4096 $\endgroup$ – dave_thompson_085 Jun 12 at 9:17
  • $\begingroup$ Thanks a million! with a slight tweak (prepend -pkopts [...] with -algorithm DH), it worked: openssl genpkey -genparam -algorithm DH -pkeyopt dh_param:ffdhe4096 -out file.pem -outform PEM documentation on openssl genpkey that lead me to the slight tweak can be found here: openssl.org/docs/man1.1.0/man1/genpkey.html @dave_thompson_085 Would you care to answer this question so that I can accept, or shall I fill in the 'answer' section? $\endgroup$ – L de Pudo Jun 15 at 6:24
  • $\begingroup$ You're right about -algorithm DH, I don't know how I lost that. -outform PEM isn't actually needed as it's the default, but de gustibus. According to my understanding and past observation, use of specific programs rather than cryptographic algorithms or principles is voted off-topic for crypto.SX which is why I didn't answer originally, but there doesn't seem to have been any move to close, so I will go ahead and post. $\endgroup$ – dave_thompson_085 Jun 17 at 6:24

As already resolved but to close out the status: openssl commandline does support this API (added in 1.1.1), though it isn't (yet?) documented (in manmaster on the website, which supposedly closely tracks 'head'):

openssl genpkey -genparam -algorithm DH -pkeyopt dh_param:ffdhe4096 -out file.pem [-outform PEM] 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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