[BACK]Return to mpaux.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/Attic/mpaux.c between version 1.1 and 1.2

version 1.1, 1999/09/26 20:53:36 version 1.2, 1999/09/28 04:45:36
Line 17 
Line 17 
 #include "includes.h"  #include "includes.h"
 RCSID("$Id$");  RCSID("$Id$");
   
 #include <gmp.h>  #include <ssl/bn.h>
 #include "getput.h"  #include "getput.h"
 #include "xmalloc.h"  #include "xmalloc.h"
 #include "ssh_md5.h"  #include "ssh_md5.h"
   
 /* Converts a multiple-precision integer into bytes to be stored in the buffer.  void
    The buffer will contain the value of the integer, msb first. */  compute_session_id(unsigned char session_id[16],
                      unsigned char cookie[8],
 void mp_linearize_msb_first(unsigned char *buf, unsigned int len,                     unsigned int host_key_bits,
                             MP_INT *value)                     BIGNUM *host_key_n,
                      unsigned int session_key_bits,
                      BIGNUM *session_key_n)
 {  {
   unsigned int i;  
   MP_INT aux;  
   mpz_init_set(&aux, value);  
   for (i = len; i >= 4; i -= 4)  
     {  
       unsigned int limb = mpz_get_ui(&aux);  
       PUT_32BIT(buf + i - 4, limb);  
       mpz_div_2exp(&aux, &aux, 32);  
     }  
   for (; i > 0; i--)  
     {  
       buf[i - 1] = mpz_get_ui(&aux);  
       mpz_div_2exp(&aux, &aux, 8);  
     }  
   mpz_clear(&aux);  
 }  
   
 /* Extract a multiple-precision integer from buffer.  The value is stored  
    in the buffer msb first. */  
   
 void mp_unlinearize_msb_first(MP_INT *value, const unsigned char *buf,  
                               unsigned int len)  
 {  
   unsigned int i;  
   mpz_set_ui(value, 0);  
   for (i = 0; i + 4 <= len; i += 4)  
     {  
       unsigned int limb = GET_32BIT(buf + i);  
       mpz_mul_2exp(value, value, 32);  
       mpz_add_ui(value, value, limb);  
     }  
   for (; i < len; i++)  
     {  
       mpz_mul_2exp(value, value, 8);  
       mpz_add_ui(value, value, buf[i]);  
     }  
 }  
   
 /* Computes a 16-byte session id in the global variable session_id.  
    The session id is computed by concatenating the linearized, msb  
    first representations of host_key_n, session_key_n, and the cookie. */  
   
 void compute_session_id(unsigned char session_id[16],  
                         unsigned char cookie[8],  
                         unsigned int host_key_bits,  
                         MP_INT *host_key_n,  
                         unsigned int session_key_bits,  
                         MP_INT *session_key_n)  
 {  
   unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8;    unsigned int bytes = (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8 + 8;
   unsigned char *buf = xmalloc(bytes);    unsigned char *buf = xmalloc(bytes);
   struct MD5Context md;    struct MD5Context md;
   
   mp_linearize_msb_first(buf, (host_key_bits + 7 ) / 8, host_key_n);    BN_bn2bin(host_key_n, buf);
   mp_linearize_msb_first(buf + (host_key_bits + 7 ) / 8,    BN_bn2bin(session_key_n, buf + (host_key_bits + 7 ) / 8);
                          (session_key_bits + 7) / 8, session_key_n);  
   memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8,    memcpy(buf + (host_key_bits + 7) / 8 + (session_key_bits + 7) / 8,
          cookie, 8);           cookie, 8);
   MD5Init(&md);    MD5Init(&md);

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2