diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-05-26 22:10:38 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-05-26 22:10:38 +0000 |
commit | 9e1655a33b3b31864aec89432d15be91f7140819 (patch) | |
tree | 09102c8eb253340719e9f620464f286a1086bab1 | |
parent | 608e10bc50b0c2690f259fd4969461cc07c164eb (diff) | |
download | gnutls-9e1655a33b3b31864aec89432d15be91f7140819.tar.gz |
some cleanups in Diffie Hellman key exchange
-rw-r--r-- | lib/gnutls_dh.c | 105 |
1 files changed, 97 insertions, 8 deletions
diff --git a/lib/gnutls_dh.c b/lib/gnutls_dh.c index 3a821c1ef8..3137de71c3 100644 --- a/lib/gnutls_dh.c +++ b/lib/gnutls_dh.c @@ -28,6 +28,7 @@ #define DH_G_1024 2 #define DH_G_4096 5 #define DH_G_2048 5 +#define DH_G_3072 13 static const uint8 diffie_hellman_group1_prime[130] = { 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, @@ -121,6 +122,64 @@ const uint8 diffie_hellman_prime_4096[512] = { 0x7f }; +/* prime - 3072 bits */ +const uint8 diffie_hellman_prime_3072[384] = { + 0xd5, 0x6e, 0xc8, 0x1f, 0xe9, 0x80, 0x9e, + 0x56, 0x35, 0x6d, 0x6d, 0xdb, 0xfa, 0x47, + 0x75, 0xcd, 0xfa, 0x32, 0x52, 0x1a, 0xc8, + 0xad, 0xee, 0xb0, 0xdb, 0xb7, 0x07, 0x58, + 0xa6, 0x42, 0xfe, 0x59, 0xfb, 0xce, 0xe8, + 0x12, 0x63, 0x09, 0x9f, 0x5d, 0x15, 0x25, + 0x49, 0xf2, 0x61, 0x83, 0xd8, 0x5c, 0x81, + 0xdd, 0x4c, 0x26, 0xe6, 0x24, 0xce, 0x6a, + 0xa5, 0x07, 0x80, 0x1c, 0x3d, 0x94, 0xd1, + 0x5d, 0x73, 0xbd, 0x26, 0x48, 0x22, 0x25, + 0xdd, 0x2f, 0x64, 0xe5, 0xed, 0xb3, 0xa9, + 0x94, 0xb3, 0x96, 0x88, 0x5d, 0x06, 0x41, + 0x80, 0xf8, 0xe1, 0x3c, 0x8f, 0xa9, 0x5b, + 0x44, 0x7e, 0x32, 0xbd, 0x62, 0x37, 0xe1, + 0xde, 0x18, 0xe8, 0x12, 0x7d, 0x28, 0x7d, + 0x5c, 0xcf, 0xa9, 0x16, 0x0f, 0xdc, 0xc1, + 0x92, 0xe0, 0x43, 0xac, 0xd0, 0x25, 0x37, + 0x8e, 0x5d, 0x4d, 0x26, 0x46, 0xbc, 0xc5, + 0x22, 0x05, 0x29, 0x41, 0x53, 0x2f, 0x7a, + 0x95, 0xa8, 0x36, 0xed, 0x85, 0xac, 0xf3, + 0xde, 0x0c, 0xbe, 0xa9, 0xfa, 0xc4, 0xa6, + 0x0b, 0x23, 0xfc, 0x7c, 0x77, 0xdc, 0x7c, + 0x94, 0x9b, 0x7c, 0xe0, 0x3b, 0xa1, 0x66, + 0x78, 0x85, 0x99, 0x5a, 0xba, 0x26, 0xa3, + 0xac, 0x97, 0xd4, 0x3a, 0x33, 0xee, 0xa3, + 0x96, 0xe0, 0x16, 0xdf, 0x61, 0xe7, 0x1f, + 0x35, 0xa5, 0x47, 0x54, 0x51, 0xce, 0x93, + 0x40, 0x6f, 0x40, 0x86, 0x3b, 0x17, 0x12, + 0xd3, 0x4d, 0x2e, 0xb3, 0x04, 0xf8, 0x8b, + 0x30, 0xb1, 0x27, 0xd7, 0xeb, 0xde, 0xd7, + 0xa9, 0x06, 0xfe, 0x6b, 0x59, 0x8c, 0x5d, + 0x9f, 0x93, 0x1f, 0x12, 0x65, 0xe6, 0xa6, + 0xeb, 0x5d, 0x4b, 0x9a, 0x16, 0x85, 0xce, + 0x18, 0x16, 0x5a, 0x5c, 0x3c, 0xeb, 0xc0, + 0xe1, 0x58, 0x64, 0x06, 0x38, 0x1c, 0x66, + 0x90, 0x4a, 0x30, 0xbe, 0x82, 0xe9, 0x9b, + 0x40, 0x2e, 0x6a, 0x91, 0x4f, 0x48, 0xc2, + 0x82, 0x40, 0xe9, 0xcd, 0x87, 0x77, 0x24, + 0xa7, 0xdc, 0x26, 0x05, 0x18, 0x9c, 0x8b, + 0x0e, 0x84, 0x29, 0x57, 0x76, 0x66, 0x7d, + 0x1e, 0x39, 0xc2, 0xf6, 0x2f, 0xbb, 0xeb, + 0x6e, 0x58, 0x3b, 0x11, 0x70, 0x75, 0xdb, + 0xe9, 0xf8, 0xcb, 0xd4, 0x4c, 0x84, 0xb3, + 0xcb, 0x66, 0x81, 0x4e, 0x93, 0xd9, 0x2f, + 0xc5, 0x60, 0x53, 0x69, 0x6e, 0xf3, 0x8e, + 0xa5, 0x6a, 0xa0, 0x96, 0xae, 0x31, 0xb6, + 0x12, 0x91, 0x0e, 0xc4, 0xc9, 0xd0, 0x50, + 0xf7, 0xbc, 0xe7, 0x78, 0xc9, 0x97, 0x02, + 0x26, 0x6a, 0xe3, 0x9a, 0x16, 0x63, 0xa2, + 0x5e, 0x1d, 0x4e, 0x71, 0x52, 0xb4, 0x73, + 0x31, 0x27, 0x6c, 0x46, 0xe4, 0x67, 0x02, + 0xde, 0x34, 0x7e, 0x24, 0x3b, 0xb9, 0xfe, + 0x08, 0x7e, 0xe9, 0x0a, 0xdc, 0xe7, 0xc2, + 0xa6, 0xa6, 0xb3, 0x7d, 0xe0, 0xa2, 0xe7, + 0x6d, 0x2e, 0x33, 0xed, 0x47, 0xf7 +}; /* prime - 2048 bits */ const uint8 diffie_hellman_prime_2048[256] = { @@ -180,14 +239,25 @@ const uint8 diffie_hellman_prime_2048[256] = { gnutls_mpi_release(g); */ -#define X_SIZE 512 + +/* This function should return a resonable size for X + * (DH secret key). The input is the number of bits of + * the modulus. + * FIXME: This function is not correct + */ +static int get_x_size( int bits) { + if (bits <= 2048) return 512; + if (bits <= 4096) return 768; + return 1024; +} MPI gnutls_calc_dh_secret(MPI * ret_x, MPI g, MPI prime) { MPI e, x; - - x = gcry_mpi_new(X_SIZE); /* FIXME: allocate in secure memory */ - gcry_mpi_randomize(x, X_SIZE, GCRY_STRONG_RANDOM); + int x_size = get_x_size( gcry_mpi_get_nbits(prime)); + + x = gcry_mpi_new(x_size); /* FIXME: allocate in secure memory */ + gcry_mpi_randomize(x, x_size, GCRY_STRONG_RANDOM); /* fixme: set high bit of x and select a larger one */ e = gcry_mpi_alloc_like(prime); @@ -200,16 +270,19 @@ MPI gnutls_calc_dh_secret(MPI * ret_x, MPI g, MPI prime) return e; } -/* returns g and p */ +/* returns g and p, depends on the requested bits. + * We only support limited key sizes. + */ MPI gnutls_get_dh_params(MPI * ret_p, int bits) { MPI g, prime; size_t n; if (bits >= 4096) bits = 4096; - else if (bits>=2048) bits=2048; - else if (bits>=1024) bits=1024; - else bits=1024; + else if (bits<=1024) bits=1024; + else if (bits<=2048) bits=2048; + else if (bits<=3072) bits=3072; + else if (bits<=4096) bits=4096; switch (bits) { case 1024: @@ -244,6 +317,22 @@ MPI gnutls_get_dh_params(MPI * ret_p, int bits) else gcry_mpi_release(prime); return g; + case 3072: + n = sizeof diffie_hellman_prime_3072; + + if (gcry_mpi_scan(&prime, GCRYMPI_FMT_USG, + diffie_hellman_prime_3072, &n)) { + gnutls_assert(); + abort(); + } + + g = gcry_mpi_set_ui(NULL, DH_G_3072); + + if (ret_p) + *ret_p = prime; + else + gcry_mpi_release(prime); + return g; case 4096: n = sizeof diffie_hellman_prime_4096; |