From 5bb869dd229c111ff6c0b3aecc70e4c162e60f9f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 28 Aug 2021 10:25:09 +0100 Subject: [PATCH] Add references for the Diffie-Hellman fixed primes. I ran across their defining RFCs recently and noticed that each one provides an explicit mathematical expression for the prime (since each one is derived from the expansion of pi, with framing FFs and a correction term to make it actually prime). Those expressions can be re-evaluated trivially by spigot, so it seems reasonable to add those spigot commands in comments. This also means the comments contain citations for these primes in actual standards, including both the hex digits and the mathematical expressions. --- crypto/diffie-hellman.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto/diffie-hellman.c b/crypto/diffie-hellman.c index 634ef297..0461a430 100644 --- a/crypto/diffie-hellman.c +++ b/crypto/diffie-hellman.c @@ -19,12 +19,18 @@ struct dh_extra { static void dh_group1_construct(dh_ctx *ctx) { + /* Command to recompute, from the expression in RFC 2412 section E.2: +spigot -B16 '2^1024 - 2^960 - 1 + 2^64 * ( floor(2^894 pi) + 129093 )' + */ ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF); ctx->g = mp_from_integer(2); } static void dh_group14_construct(dh_ctx *ctx) { + /* Command to recompute, from the expression in RFC 3526 section 3: +spigot -B16 '2^2048 - 2^1984 - 1 + 2^64 * ( floor(2^1918 pi) + 124476 )' + */ ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF); ctx->g = mp_from_integer(2); }