Skip to content

Commit 7ce51db

Browse files
committed
checkpoint - extra debugs and such removed
1 parent ed25051 commit 7ce51db

File tree

7 files changed

+18
-149
lines changed

7 files changed

+18
-149
lines changed

cipher-ctr-mt.c

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "log.h"
3737
#include <unistd.h>
3838
#include "uthash.h"
39-
#include "misc.h"
4039

4140
/* compatibility with old or broken OpenSSL versions */
4241
#include "openbsd-compat/openssl-compat.h"
@@ -287,11 +286,6 @@ stop_and_join_pregen_threads(struct ssh_aes_ctr_ctx_mt *c)
287286
static void *
288287
thread_loop(void *x)
289288
{
290-
struct statm_t result;
291-
read_mem_stats(&result, 1);
292-
debug_f("********* LOOP START memory usage is now virt: %lu, res: %lu, share: %lu",
293-
result.size*4, result.resident*4, result.share*4);
294-
295289
EVP_CIPHER_CTX *aesni_ctx;
296290
struct ssh_aes_ctr_ctx_mt *c = x;
297291
struct kq *q;
@@ -309,9 +303,6 @@ thread_loop(void *x)
309303

310304
/* create the context for this thread */
311305
aesni_ctx = EVP_CIPHER_CTX_new();
312-
read_mem_stats(&result, 1);
313-
debug_f("********* LOOP new context memory usage is now virt: %lu, res: %lu, share: %lu",
314-
result.size*4, result.resident*4, result.share*4);
315306

316307
/* keep track of the pointer for the evp in this struct
317308
* so we can free it later. So we place it in a hash indexed on the
@@ -322,10 +313,7 @@ thread_loop(void *x)
322313
ptr->tid = pthread_self(); /* index for hash */
323314
ptr->pointer = aesni_ctx;
324315
HASH_ADD_INT(evp_ptrs, tid, ptr);
325-
read_mem_stats(&result, 1);
326-
debug_f("********* LOOP track pointer memory usage is now virt: %lu, res: %lu, share: %lu",
327-
result.size*4, result.resident*4, result.share*4);
328-
316+
329317
/* initialize the cipher ctx with the key provided
330318
* determine which cipher to use based on the key size */
331319
if (c->keylen == 256)
@@ -338,9 +326,6 @@ thread_loop(void *x)
338326
logit("Invalid key length of %d in AES CTR MT. Exiting", c->keylen);
339327
exit(1);
340328
}
341-
read_mem_stats(&result, 1);
342-
debug_f("********* LOOP init ctx memory usage is now virt: %lu, res: %lu, share: %lu",
343-
result.size*4, result.resident*4, result.share*4);
344329

345330
/*
346331
* Handle the special case of startup, one thread must fill
@@ -367,9 +352,6 @@ thread_loop(void *x)
367352
pthread_cond_broadcast(&q->cond);
368353
}
369354
pthread_mutex_unlock(&q->lock);
370-
read_mem_stats(&result, 1);
371-
debug_f("********* LOOP first thread memory usage is now virt: %lu, res: %lu, share: %lu",
372-
result.size*4, result.resident*4, result.share*4);
373355
}
374356

375357
/*
@@ -418,9 +400,6 @@ thread_loop(void *x)
418400

419401
/* see coresponding block above for useful comments */
420402
EVP_EncryptUpdate(aesni_ctx, q->keys[0], &outlen, mynull, KQLEN * AES_BLOCK_SIZE);
421-
read_mem_stats(&result, 1);
422-
// debug_f("Size is %d byte", KQLEN*AES_BLOCK_SIZE);
423-
// debug_f("********* qidx: %d LOOP fill thread memory usage is now virt: %lu, res: %lu, share: %lu", qidx, result.size*4, result.resident*4, result.share*4);
424403

425404
/* Re-lock, mark full and signal consumer */
426405
pthread_mutex_lock(&q->lock);
@@ -539,14 +518,9 @@ ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
539518
int enc)
540519
{
541520
struct ssh_aes_ctr_ctx_mt *c;
542-
struct statm_t result;
543521
int i;
544-
read_mem_stats(&result, 1);
545-
debug_f("********* START INIT memory usage is now virt: %lu, res: %lu, share: %lu",
546-
result.size*4, result.resident*4, result.share*4);
547-
522+
548523
char *aes_threads = getenv("SSH_CIPHER_THREADS");
549-
debug_f("!!!!!!!!!!!!!!!!! threads = %s", aes_threads);
550524
if (aes_threads != NULL && strlen(aes_threads) != 0)
551525
cipher_threads = atoi(aes_threads);
552526
else
@@ -567,10 +541,6 @@ ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
567541

568542
/* set up the initial state of c (our cipher stream struct) */
569543
if ((c = EVP_CIPHER_CTX_get_app_data(ctx)) == NULL) {
570-
read_mem_stats(&result, 1);
571-
debug_f("********* start get app data memory usage is now virt: %lu, res: %lu, share: %lu",
572-
result.size*4, result.resident*4, result.share*4);
573-
574544
c = xmalloc(sizeof(*c));
575545
pthread_rwlock_init(&c->tid_lock, NULL);
576546
#ifdef __APPLE__
@@ -588,18 +558,12 @@ ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
588558

589559
/* attach our struct to the context */
590560
EVP_CIPHER_CTX_set_app_data(ctx, c);
591-
read_mem_stats(&result, 1);
592-
debug_f("********* get app data memory usage is now virt: %lu, res: %lu, share: %lu",
593-
result.size*4, result.resident*4, result.share*4);
594561
}
595562

596563
/* we are initializing but the current structure already
597564
has an IV and key so we want to kill the existing key data
598565
and start over. This is important when we need to rekey the data stream */
599566
if (c->state == (HAVE_KEY | HAVE_IV)) {
600-
read_mem_stats(&result, 1);
601-
debug_f("********* start c->state memory usage is now virt: %lu, res: %lu, share: %lu",
602-
result.size*4, result.resident*4, result.share*4);
603567
/* tell the pregen threads to exit */
604568
stop_and_join_pregen_threads(c);
605569

@@ -610,46 +574,25 @@ ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
610574

611575
/* Start over getting key & iv */
612576
c->state = HAVE_NONE;
613-
read_mem_stats(&result, 1);
614-
debug_f("********* c->state memory usage is now virt: %lu, res: %lu, share: %lu",
615-
result.size*4, result.resident*4, result.share*4);
616577
}
617578

618579
/* set the initial key for this key stream queue */
619580
if (key != NULL) {
620-
read_mem_stats(&result, 1);
621-
debug_f("********* start key != NULL memory usage is now virt: %lu, res: %lu, share: %lu",
622-
result.size*4, result.resident*4, result.share*4);
623581
AES_set_encrypt_key(key, EVP_CIPHER_CTX_key_length(ctx) * 8,
624582
&c->aes_key);
625583
c->orig_key = key;
626584
c->keylen = EVP_CIPHER_CTX_key_length(ctx) * 8;
627585
c->state |= HAVE_KEY;
628-
read_mem_stats(&result, 1);
629-
debug_f("********* key != NULL memory usage is now virt: %lu, res: %lu, share: %lu",
630-
result.size*4, result.resident*4, result.share*4);
631586
}
632587

633588
/* set the IV */
634589
if (iv != NULL) {
635590
/* init the counter this is just a 16byte uchar */
636-
read_mem_stats(&result, 1);
637-
debug_f("********* start iv != NULL memory usage is now virt: %lu, res: %lu, share: %lu",
638-
result.size*4, result.resident*4, result.share*4);
639591
memcpy(c->aes_counter, iv, AES_BLOCK_SIZE);
640592
c->state |= HAVE_IV;
641-
read_mem_stats(&result, 1);
642-
debug_f("********* iv != NULL memory usage is now virt: %lu, res: %lu, share: %lu",
643-
result.size*4, result.resident*4, result.share*4);
644-
645593
}
646594

647595
if (c->state == (HAVE_KEY | HAVE_IV)) {
648-
debug_f("start thread init");
649-
read_mem_stats(&result, 1);
650-
debug_f("********* start thread init memory usage is now virt: %lu, res: %lu, share: %lu",
651-
result.size*4, result.resident*4, result.share*4);
652-
653596
/* Clear queues */
654597
/* set the first key in the key queue to the current counter */
655598
memcpy(c->q[0].ctr, c->aes_counter, AES_BLOCK_SIZE);
@@ -666,19 +609,14 @@ ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
666609
c->ridx = 0;
667610
c->struct_id = global_struct_id++;
668611

669-
612+
670613
/* Start threads */
671614
#define STACK_SIZE (1024 * 1024)
672615
pthread_attr_t attr;
673616
pthread_attr_init(&attr);
674617
pthread_attr_setstacksize(&attr, STACK_SIZE);
675618
for (i = 0; i < cipher_threads; i++) {
676619
pthread_rwlock_wrlock(&c->tid_lock);
677-
read_mem_stats(&result, 1);
678-
debug_f("********* %d: pre thread create memory usage is now virt: %lu, res: %lu, share: %lu",
679-
i, result.size*4, result.resident*4, result.share*4);
680-
debug("size of c is %zu", sizeof(*c));
681-
debug("size of ctx is %zu", sizeof(ctx));
682620
if (pthread_create(&c->tid[i], &attr, thread_loop, c) != 0)
683621
fatal ("AES-CTR MT Could not create thread in %s", __FUNCTION__);
684622
/*should die here */
@@ -687,26 +625,14 @@ ssh_aes_ctr_init(EVP_CIPHER_CTX *ctx, const u_char *key, const u_char *iv,
687625
debug ("AES-CTR MT spawned a thread with id %lu in %s (%lu, %d)",
688626
c->tid[i], __FUNCTION__, c->struct_id, c->id[i]);
689627
}
690-
//sleep (5);
691-
read_mem_stats(&result, 1);
692-
debug_f("********* %d: post thread create memory usage is now virt: %lu, res: %lu, share: %lu",
693-
i, result.size*4, result.resident*4, result.share*4);
694628
pthread_rwlock_unlock(&c->tid_lock);
695629
}
696630
pthread_mutex_lock(&c->q[0].lock);
697631
// wait for all of the threads to be initialized
698632
while (c->q[0].qstate == KQINIT)
699633
pthread_cond_wait(&c->q[0].cond, &c->q[0].lock);
700634
pthread_mutex_unlock(&c->q[0].lock);
701-
read_mem_stats(&result, 1);
702-
debug_f("********* end thread init memory usage is now virt: %lu, res: %lu, share: %lu",
703-
result.size*4, result.resident*4, result.share*4);
704-
705-
debug_f("end thread init");
706635
}
707-
read_mem_stats(&result, 1);
708-
debug_f("********* END INIT memory usage is now virt: %lu, res: %lu, share: %lu",
709-
result.size*4, result.resident*4, result.share*4);
710636
return 1;
711637
}
712638

cipher.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
276276
const EVP_CIPHER *type;
277277
int klen;
278278
#endif
279-
#include "misc.h"
280-
struct statm_t result;
281279

282280
*ccp = NULL;
283281
if ((cc = calloc(sizeof(*cc), 1)) == NULL)
@@ -323,12 +321,6 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
323321
* start the threaded cipher. If OSSL supports providers (OSSL 3.0+) then
324322
* we load our hpnssh provider. If it doesn't (OSSL < 1.1) then we use the
325323
* _meth_new process found in cipher-ctr-mt.c */
326-
if (post_auth) {
327-
read_mem_stats(&result, post_auth);
328-
329-
debug_f("********* pre provider load memory usage is now virt: %lu, res: %lu, share: %lu",
330-
result.size*4, result.resident*4, result.share*4);
331-
}
332324
if (strstr(cc->cipher->name, "ctr") && post_auth) {
333325
#if OPENSSL_VERSION_NUMBER >= 0x30000000UL
334326
/* this version of openssl uses providers */
@@ -342,11 +334,6 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
342334
}
343335
aes_mt_provider = OSSL_PROVIDER_load(aes_lib, "hpnssh");
344336

345-
read_mem_stats(&result, post_auth);
346-
347-
debug_f("********* post provider load memory usage is now virt: %lu, res: %lu, share: %lu",
348-
result.size*4, result.resident*4, result.share*4);
349-
350337
if (aes_mt_provider != NULL) {
351338
/* use the previous key length to determine which cipher to load */
352339
if (cipher->key_len == 32)
@@ -366,11 +353,6 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
366353
ERR_print_errors_fp(stderr);
367354
fatal("Failed to load HPN-SSH AES-CTR-MT provider.");
368355
}
369-
370-
read_mem_stats(&result, post_auth);
371-
372-
debug_f("********* post EVP_CIPHER_fetch memory usage is now virt: %lu, res: %lu, share: %lu",
373-
result.size*4, result.resident*4, result.share*4);
374356
#else
375357
type = (*evp_aes_ctr_mt)(); /* see cipher-ctr-mt.c */
376358
/* we need to free this later if using aes_ctr_mt
@@ -386,47 +368,23 @@ cipher_init(struct sshcipher_ctx **ccp, const struct sshcipher *cipher,
386368
ret = SSH_ERR_LIBCRYPTO_ERROR;
387369
goto out;
388370
}
389-
if (post_auth) {
390-
read_mem_stats(&result, post_auth);
391-
392-
debug_f("********* post 1st EVP_CIPHER_init memory usage is now virt: %lu, res: %lu, share: %lu",
393-
result.size*4, result.resident*4, result.share*4);
394-
}
395371
if (cipher_authlen(cipher) &&
396372
!EVP_CIPHER_CTX_ctrl(cc->evp, EVP_CTRL_GCM_SET_IV_FIXED,
397373
-1, (u_char *)iv)) {
398374
ret = SSH_ERR_LIBCRYPTO_ERROR;
399375
goto out;
400376
}
401-
if (post_auth) {
402-
read_mem_stats(&result, post_auth);
403-
404-
debug_f("********* post 1st authlen memory usage is now virt: %lu, res: %lu, share: %lu",
405-
result.size*4, result.resident*4, result.share*4);
406-
}
407377
klen = EVP_CIPHER_CTX_key_length(cc->evp);
408378
if (klen > 0 && keylen != (u_int)klen) {
409379
if (EVP_CIPHER_CTX_set_key_length(cc->evp, keylen) == 0) {
410380
ret = SSH_ERR_LIBCRYPTO_ERROR;
411381
goto out;
412382
}
413383
}
414-
if (post_auth) {
415-
read_mem_stats(&result, post_auth);
416-
417-
debug_f("********* post key_len memory usage is now virt: %lu, res: %lu, share: %lu",
418-
result.size*4, result.resident*4, result.share*4);
419-
}
420384
if (EVP_CipherInit(cc->evp, NULL, (u_char *)key, NULL, -1) == 0) {
421385
ret = SSH_ERR_LIBCRYPTO_ERROR;
422386
goto out;
423387
}
424-
if (post_auth) {
425-
read_mem_stats(&result, post_auth);
426-
427-
debug_f("********* post 2nd EVP_CIPHER_init memory usage is now virt: %lu, res: %lu, share: %lu",
428-
result.size*4, result.resident*4, result.share*4);
429-
}
430388
ret = 0;
431389
#endif /* WITH_OPENSSL */
432390
out:

packet.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
/* SSH_IOBUFSZ + 1k of head room */
107107
/* OpenSSH usings 256KB packet size max but that consumes a
108-
* lot of memory wiht the buffers we are using. This keeps it
108+
* lot of memory wiht the buffers we are using. This keeps it
109109
* in check. Doesn't seem to have an impact on performance or
110110
* functionality cjr 04/06/2023 */
111111
#define PACKET_MAX_SIZE (SSH_IOBUFSZ + 1024)
@@ -1846,7 +1846,6 @@ ssh_packet_process_read(struct ssh *ssh, int fd)
18461846
return r;
18471847

18481848
if (state->packet_discard) {
1849-
debug_f("discard");
18501849
if ((r = sshbuf_consume_end(state->input, rlen)) != 0)
18511850
return r;
18521851
state->keep_alive_timeouts = 0; /* ?? */

session.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -706,15 +706,6 @@ do_exec(struct ssh *ssh, Session *s, const char *command)
706706
ssh_remote_port(ssh),
707707
s->self);
708708

709-
int post_auth = packet_authentication_state(ssh);
710-
if (post_auth) {
711-
struct statm_t result;
712-
read_mem_stats(&result, post_auth);
713-
debug_f("********** Post session start memory usage is now virt: %lu, res: %lu, share: %lu",
714-
result.size*4, result.resident*4, result.share*4);
715-
}
716-
717-
718709
#ifdef SSH_AUDIT_EVENTS
719710
if (command != NULL)
720711
PRIVSEP(audit_run_command(command));

sshbuf-misc.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,16 @@ sshbuf_read(int fd, struct sshbuf *buf, size_t maxlen, size_t *rlen)
283283
*rlen = 0;
284284
if ((r = sshbuf_reserve(buf, maxlen, &d)) != 0)
285285
return r;
286-
//debug_f("trying to reserve %zu, r is %d", maxlen, r);
287-
288286
rr = read(fd, d, maxlen);
289287
oerrno = errno;
290-
288+
291289
/* Adjust the buffer to include only what was actually read */
292290
if ((adjust = maxlen - (rr > 0 ? rr : 0)) != 0) {
293-
//debug_f("adjust: %zu, rr: %zu, maxlen: %zu", adjust, rr, maxlen);
294291
if ((r = sshbuf_consume_end(buf, adjust)) != 0) {
295292
/* avoid returning uninitialised data to caller */
296293
memset(d + rr, '\0', adjust);
297294
return SSH_ERR_INTERNAL_ERROR; /* shouldn't happen */
298295
}
299-
} else {
300-
//debug_f("FOOL!!! adjust: %zu, rr: %zu, maxlen: %zu", adjust, rr, maxlen);
301296
}
302297
if (rr < 0) {
303298
errno = oerrno;
@@ -309,8 +304,6 @@ sshbuf_read(int fd, struct sshbuf *buf, size_t maxlen, size_t *rlen)
309304
/* success */
310305
if (rlen != NULL) {
311306
*rlen = (size_t)rr;
312-
//debug_f("rlen at end is %zu", *rlen);
313-
} //else
314-
//debug_f("RLEN IS NULL!");
307+
}
315308
return 0;
316309
}

0 commit comments

Comments
 (0)