|
63 | 63 | #endif |
64 | 64 | #include <signal.h> |
65 | 65 | #include <time.h> |
| 66 | +#ifdef HAVE_UTIL_H |
| 67 | +# include <util.h> |
| 68 | +#endif |
66 | 69 |
|
67 | 70 | /* |
68 | 71 | * Explicitly include OpenSSL before zlib as some versions of OpenSSL have |
@@ -888,6 +891,7 @@ ssh_set_newkeys(struct ssh *ssh, int mode) |
888 | 891 | const char *wmsg; |
889 | 892 | int r, crypt_type; |
890 | 893 | const char *dir = mode == MODE_OUT ? "out" : "in"; |
| 894 | + char blocks_s[FMT_SCALED_STRSIZE], bytes_s[FMT_SCALED_STRSIZE]; |
891 | 895 |
|
892 | 896 | debug2_f("mode %d", mode); |
893 | 897 |
|
@@ -956,29 +960,20 @@ ssh_set_newkeys(struct ssh *ssh, int mode) |
956 | 960 | } |
957 | 961 | comp->enabled = 1; |
958 | 962 | } |
959 | | - /* |
960 | | - * The 2^(blocksize*2) limit is too expensive for 3DES, |
961 | | - * so enforce a 1GB limit for small blocksizes. |
962 | | - * See RFC4344 section 3.2. |
963 | | - */ |
964 | 963 |
|
965 | | - /* we really don't need to rekey if we are using the none cipher |
966 | | - * but there isn't a good way to disable it entirely that I can find |
967 | | - * and using a blocksize larger that 16 doesn't work (dunno why) |
968 | | - * so this seems to be a good limit for now - CJR 10/16/2020*/ |
969 | | - if (ssh->none == 1) { |
970 | | - *max_blocks = (u_int64_t)1 << (31*2); |
971 | | - } else { |
972 | | - if (enc->block_size >= 16) |
973 | | - *max_blocks = (u_int64_t)1 << (enc->block_size*2); |
974 | | - else |
975 | | - *max_blocks = ((u_int64_t)1 << 30) / enc->block_size; |
976 | | - } |
977 | | - if (state->rekey_limit) |
978 | | - *max_blocks = MINIMUM(*max_blocks, |
979 | | - state->rekey_limit / enc->block_size); |
980 | | - debug("rekey %s after %llu blocks", dir, |
981 | | - (unsigned long long)*max_blocks); |
| 964 | + /* get the maximum number of blocks the cipher can |
| 965 | + * handle safely */ |
| 966 | + *max_blocks = cipher_rekey_blocks(enc->cipher); |
| 967 | + |
| 968 | + /* these lines support the debug */ |
| 969 | + strlcpy(blocks_s, "?", sizeof(blocks_s)); |
| 970 | + strlcpy(bytes_s, "?", sizeof(bytes_s)); |
| 971 | + if (*max_blocks * enc->block_size < LLONG_MAX) { |
| 972 | + fmt_scaled((long long)*max_blocks, blocks_s); |
| 973 | + fmt_scaled((long long)*max_blocks * enc->block_size, bytes_s); |
| 974 | + } |
| 975 | + debug("rekey %s after %s blocks / %sB data", dir, blocks_s, bytes_s); |
| 976 | + |
982 | 977 | return 0; |
983 | 978 | } |
984 | 979 |
|
@@ -2241,6 +2236,14 @@ ssh_packet_set_server(struct ssh *ssh) |
2241 | 2236 | ssh->kex->server = 1; /* XXX unify? */ |
2242 | 2237 | } |
2243 | 2238 |
|
| 2239 | +/* Set the state of the connection to post auth |
| 2240 | + * While we are here also decrease the size of |
| 2241 | + * packet_max_size to something more reasonable. |
| 2242 | + * In this case thats 33k. Which is the size of |
| 2243 | + * the largest packet we expect to see and some space |
| 2244 | + * for overhead. This reduces memory usage in high |
| 2245 | + * BDP environments without impacting performance |
| 2246 | + * -cjr 4/11/23 */ |
2244 | 2247 | void |
2245 | 2248 | ssh_packet_set_authenticated(struct ssh *ssh) |
2246 | 2249 | { |
|
0 commit comments