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)
287286static void *
288287thread_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
0 commit comments