There are no available options for this view.

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

revision 1.6 by botg, Tue Oct 14 22:01:21 2003 UTC revision 1.7 by botg, Thu Aug 5 10:15:16 2004 UTC
# Line 22  Line 22 
22      (cp)[2] = (unsigned char)((value) >> 8); \      (cp)[2] = (unsigned char)((value) >> 8); \
23      (cp)[3] = (unsigned char)(value); }      (cp)[3] = (unsigned char)(value); }
24    
25  int makekey(unsigned char *data, struct RSAKey *result,  int makekey(unsigned char *data, int len, struct RSAKey *result,
26              unsigned char **keystr, int order)              unsigned char **keystr, int order)
27  {  {
28      unsigned char *p = data;      unsigned char *p = data;
29      int i;      int i, n;
30    
31        if (len < 4)
32            return -1;
33    
34      if (result) {      if (result) {
35          result->bits = 0;          result->bits = 0;
# Line 35  Line 38 
38      } else      } else
39          p += 4;          p += 4;
40    
41        len -= 4;
42    
43      /*      /*
44       * order=0 means exponent then modulus (the keys sent by the       * order=0 means exponent then modulus (the keys sent by the
45       * server). order=1 means modulus then exponent (the keys       * server). order=1 means modulus then exponent (the keys
46       * stored in a keyfile).       * stored in a keyfile).
47       */       */
48    
49      if (order == 0)      if (order == 0) {
50          p += ssh1_read_bignum(p, result ? &result->exponent : NULL);          n = ssh1_read_bignum(p, len, result ? &result->exponent : NULL);
51            if (n < 0) return -1;
52            p += n;
53            len -= n;
54        }
55    
56        n = ssh1_read_bignum(p, len, result ? &result->modulus : NULL);
57        if (n < 0) return -1;
58      if (result)      if (result)
59          result->bytes = (((p[0] << 8) + p[1]) + 7) / 8;          result->bytes = n - 2;
60      if (keystr)      if (keystr)
61          *keystr = p + 2;          *keystr = p + 2;
62      p += ssh1_read_bignum(p, result ? &result->modulus : NULL);      p += n;
63      if (order == 1)      len -= n;
         p += ssh1_read_bignum(p, result ? &result->exponent : NULL);  
64    
65        if (order == 1) {
66            n = ssh1_read_bignum(p, len, result ? &result->exponent : NULL);
67            if (n < 0) return -1;
68            p += n;
69            len -= n;
70        }
71      return p - data;      return p - data;
72  }  }
73    
74  int makeprivate(unsigned char *data, struct RSAKey *result)  int makeprivate(unsigned char *data, int len, struct RSAKey *result)
75  {  {
76      return ssh1_read_bignum(data, &result->private_exponent);      return ssh1_read_bignum(data, len, &result->private_exponent);
77  }  }
78    
79  void rsaencrypt(unsigned char *data, int length, struct RSAKey *key)  int rsaencrypt(unsigned char *data, int length, struct RSAKey *key)
80  {  {
81      Bignum b1, b2;      Bignum b1, b2;
82      int i;      int i;
83      unsigned char *p;      unsigned char *p;
84    
85        if (key->bytes < length + 4)
86            return 0;                      /* RSA key too short! */
87    
88      memmove(data + key->bytes - length, data, length);      memmove(data + key->bytes - length, data, length);
89      data[0] = 0;      data[0] = 0;
90      data[1] = 2;      data[1] = 2;
# Line 87  Line 107 
107    
108      freebn(b1);      freebn(b1);
109      freebn(b2);      freebn(b2);
110    
111        return 1;
112  }  }
113    
114  static void sha512_mpint(SHA512_State * s, Bignum b)  static void sha512_mpint(SHA512_State * s, Bignum b)
# Line 378  Line 400 
400  }  }
401    
402  /* Given a public blob, determine its length. */  /* Given a public blob, determine its length. */
403  int rsa_public_blob_len(void *data)  int rsa_public_blob_len(void *data, int maxlen)
404  {  {
405      unsigned char *p = (unsigned char *)data;      unsigned char *p = (unsigned char *)data;
406        int n;
407    
408        if (maxlen < 4)
409            return -1;
410      p += 4;                            /* length word */      p += 4;                            /* length word */
411      p += ssh1_read_bignum(p, NULL);    /* exponent */      maxlen -= 4;
412      p += ssh1_read_bignum(p, NULL);    /* modulus */  
413        n = ssh1_read_bignum(p, maxlen, NULL);    /* exponent */
414        if (n < 0)
415            return -1;
416        p += n;
417    
418        n = ssh1_read_bignum(p, maxlen, NULL);    /* modulus */
419        if (n < 0)
420            return -1;
421        p += n;
422    
423      return p - (unsigned char *)data;      return p - (unsigned char *)data;
424  }  }
# Line 629  Line 663 
663      return bloblen;      return bloblen;
664  }  }
665    
666    static int rsa2_pubkey_bits(void *blob, int len)
667    {
668        struct RSAKey *rsa;
669        int ret;
670    
671        rsa = rsa2_newkey((char *) blob, len);
672        ret = bignum_bitcount(rsa->modulus);
673        rsa2_freekey(rsa);
674    
675        return ret;
676    }
677    
678  static char *rsa2_fingerprint(void *key)  static char *rsa2_fingerprint(void *key)
679  {  {
680      struct RSAKey *rsa = (struct RSAKey *) key;      struct RSAKey *rsa = (struct RSAKey *) key;
# Line 715  Line 761 
761    
762      ret = 1;      ret = 1;
763    
764      bytes = bignum_bitcount(rsa->modulus) / 8;      bytes = (bignum_bitcount(rsa->modulus)+7) / 8;
765      /* Top (partial) byte should be zero. */      /* Top (partial) byte should be zero. */
766      if (bignum_byte(out, bytes - 1) != 0)      if (bignum_byte(out, bytes - 1) != 0)
767          ret = 0;          ret = 0;
# Line 738  Line 784 
784          if (bignum_byte(out, i) != hash[j])          if (bignum_byte(out, i) != hash[j])
785              ret = 0;              ret = 0;
786      }      }
787        freebn(out);
788    
789      return ret;      return ret;
790  }  }
# Line 793  Line 840 
840      rsa2_createkey,      rsa2_createkey,
841      rsa2_openssh_createkey,      rsa2_openssh_createkey,
842      rsa2_openssh_fmtkey,      rsa2_openssh_fmtkey,
843        rsa2_pubkey_bits,
844      rsa2_fingerprint,      rsa2_fingerprint,
845      rsa2_verifysig,      rsa2_verifysig,
846      rsa2_sign,      rsa2_sign,

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7