Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ttxssh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6229 by yutakapon, Fri Jan 1 11:06:37 2016 UTC revision 6250 by doda, Tue Jan 5 12:05:47 2016 UTC
# Line 39  SOFTWARE, EVEN IF ADVISED OF THE POSSIBI Line 39  SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
39  #include "ttcommon.h"  #include "ttcommon.h"
40  #include "ttlib.h"  #include "ttlib.h"
41  #include "keyfiles.h"  #include "keyfiles.h"
42    #include "arc4random.h"
43    
44  #include <stdlib.h>  #include <stdlib.h>
45  #include <stdio.h>  #include <stdio.h>
# Line 4066  error: Line 4067  error:
4067    
4068    
4069  //  //
 // RC4  
 //  
   
 /* Size of key to use */  
 #define SEED_SIZE 20  
   
 /* Number of bytes to reseed after */  
 #define REKEY_BYTES (1 << 24)  
   
 static int rc4_ready = 0;  
 static RC4_KEY rc4;  
   
 static void seed_rng(void)  
 {  
         if (RAND_status() != 1)  
                 return;  
 }  
   
 static void arc4random_stir(void)  
 {  
         unsigned char rand_buf[SEED_SIZE];  
         int i;  
   
         memset(&rc4, 0, sizeof(rc4));  
         if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0) {  
                 //fatal("Couldn't obtain random bytes (error %ld)",  
                 //    ERR_get_error());  
         }  
         RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);  
   
         /*  
          * Discard early keystream, as per recommendations in:  
          * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps  
          */  
         for(i = 0; i <= 256; i += sizeof(rand_buf))  
                 RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);  
   
         SecureZeroMemory(rand_buf, sizeof(rand_buf));  
   
         rc4_ready = REKEY_BYTES;  
 }  
   
 static unsigned int arc4random(void)  
 {  
         unsigned int r = 0;  
         static int first_time = 1;  
   
         if (rc4_ready <= 0) {  
                 if (first_time) {  
                         seed_rng();  
                 }  
                 first_time = 0;  
                 arc4random_stir();  
         }  
   
         RC4(&rc4, sizeof(r), (unsigned char *)&r, (unsigned char *)&r);  
   
         rc4_ready -= sizeof(r);  
   
         return(r);  
 }  
   
 void arc4random_buf(void *_buf, size_t n)  
 {  
         size_t i;  
         unsigned int r = 0;  
         char *buf = (char *)_buf;  
   
         for (i = 0; i < n; i++) {  
                 if (i % 4 == 0)  
                         r = arc4random();  
                 buf[i] = r & 0xff;  
                 r >>= 8;  
         }  
         i = r = 0;  
 }  
   
 //  
4070  // SSH1 3DES  // SSH1 3DES
4071  //  //
4072  /*  /*

Legend:
Removed from v.6229  
changed lines
  Added in v.6250

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26