Deleted Added
full compact
key.c (99063) key.c (106130)
1/*
2 * read_bignum():
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 *
5 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be

--- 18 unchanged lines hidden (view full) ---

27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34#include "includes.h"
1/*
2 * read_bignum():
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 *
5 * As far as I am concerned, the code I have written for this software
6 * can be used freely for any purpose. Any derived versions of this
7 * software must be clearly marked as such, and if the derived work is
8 * incompatible with the protocol description in the RFC file, it must be

--- 18 unchanged lines hidden (view full) ---

27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34#include "includes.h"
35RCSID("$OpenBSD: key.c,v 1.45 2002/06/23 03:26:19 deraadt Exp $");
36RCSID("$FreeBSD: head/crypto/openssh/key.c 99063 2002-06-29 11:48:59Z des $");
35RCSID("$OpenBSD: key.c,v 1.49 2002/09/09 14:54:14 markus Exp $");
36RCSID("$FreeBSD: head/crypto/openssh/key.c 106130 2002-10-29 10:16:02Z des $");
37
38#include <openssl/evp.h>
39
40#include "xmalloc.h"
41#include "key.h"
42#include "rsa.h"
43#include "ssh-dss.h"
44#include "ssh-rsa.h"

--- 122 unchanged lines hidden (view full) ---

167 break;
168 default:
169 fatal("key_equal: bad key type %d", a->type);
170 break;
171 }
172 return 0;
173}
174
37
38#include <openssl/evp.h>
39
40#include "xmalloc.h"
41#include "key.h"
42#include "rsa.h"
43#include "ssh-dss.h"
44#include "ssh-rsa.h"

--- 122 unchanged lines hidden (view full) ---

167 break;
168 default:
169 fatal("key_equal: bad key type %d", a->type);
170 break;
171 }
172 return 0;
173}
174
175static u_char*
175static u_char *
176key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length)
177{
178 const EVP_MD *md = NULL;
179 EVP_MD_CTX ctx;
180 u_char *blob = NULL;
181 u_char *retval = NULL;
182 u_int len = 0;
183 int nlen, elen;

--- 39 unchanged lines hidden (view full) ---

223 memset(blob, 0, len);
224 xfree(blob);
225 } else {
226 fatal("key_fingerprint_raw: blob is null");
227 }
228 return retval;
229}
230
176key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length)
177{
178 const EVP_MD *md = NULL;
179 EVP_MD_CTX ctx;
180 u_char *blob = NULL;
181 u_char *retval = NULL;
182 u_int len = 0;
183 int nlen, elen;

--- 39 unchanged lines hidden (view full) ---

223 memset(blob, 0, len);
224 xfree(blob);
225 } else {
226 fatal("key_fingerprint_raw: blob is null");
227 }
228 return retval;
229}
230
231static char*
232key_fingerprint_hex(u_char* dgst_raw, u_int dgst_raw_len)
231static char *
232key_fingerprint_hex(u_char *dgst_raw, u_int dgst_raw_len)
233{
234 char *retval;
235 int i;
236
237 retval = xmalloc(dgst_raw_len * 3 + 1);
238 retval[0] = '\0';
239 for (i = 0; i < dgst_raw_len; i++) {
240 char hex[4];
241 snprintf(hex, sizeof(hex), "%02x:", dgst_raw[i]);
242 strlcat(retval, hex, dgst_raw_len * 3);
243 }
244 retval[(dgst_raw_len * 3) - 1] = '\0';
245 return retval;
246}
247
233{
234 char *retval;
235 int i;
236
237 retval = xmalloc(dgst_raw_len * 3 + 1);
238 retval[0] = '\0';
239 for (i = 0; i < dgst_raw_len; i++) {
240 char hex[4];
241 snprintf(hex, sizeof(hex), "%02x:", dgst_raw[i]);
242 strlcat(retval, hex, dgst_raw_len * 3);
243 }
244 retval[(dgst_raw_len * 3) - 1] = '\0';
245 return retval;
246}
247
248static char*
249key_fingerprint_bubblebabble(u_char* dgst_raw, u_int dgst_raw_len)
248static char *
249key_fingerprint_bubblebabble(u_char *dgst_raw, u_int dgst_raw_len)
250{
251 char vowels[] = { 'a', 'e', 'i', 'o', 'u', 'y' };
252 char consonants[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm',
253 'n', 'p', 'r', 's', 't', 'v', 'z', 'x' };
254 u_int i, j = 0, rounds, seed = 1;
255 char *retval;
256
257 rounds = (dgst_raw_len / 2) + 1;

--- 29 unchanged lines hidden (view full) ---

287 retval[j++] = vowels[idx2];
288 }
289 }
290 retval[j++] = 'x';
291 retval[j++] = '\0';
292 return retval;
293}
294
250{
251 char vowels[] = { 'a', 'e', 'i', 'o', 'u', 'y' };
252 char consonants[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm',
253 'n', 'p', 'r', 's', 't', 'v', 'z', 'x' };
254 u_int i, j = 0, rounds, seed = 1;
255 char *retval;
256
257 rounds = (dgst_raw_len / 2) + 1;

--- 29 unchanged lines hidden (view full) ---

287 retval[j++] = vowels[idx2];
288 }
289 }
290 retval[j++] = 'x';
291 retval[j++] = '\0';
292 return retval;
293}
294
295char*
295char *
296key_fingerprint(Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep)
297{
298 char *retval = NULL;
299 u_char *dgst_raw;
300 u_int dgst_raw_len;
301
302 dgst_raw = key_fingerprint_raw(k, dgst_type, &dgst_raw_len);
303 if (!dgst_raw)

--- 186 unchanged lines hidden (view full) ---

490 return success;
491}
492
493int
494key_write(Key *key, FILE *f)
495{
496 int n, success = 0;
497 u_int len, bits = 0;
296key_fingerprint(Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep)
297{
298 char *retval = NULL;
299 u_char *dgst_raw;
300 u_int dgst_raw_len;
301
302 dgst_raw = key_fingerprint_raw(k, dgst_type, &dgst_raw_len);
303 if (!dgst_raw)

--- 186 unchanged lines hidden (view full) ---

490 return success;
491}
492
493int
494key_write(Key *key, FILE *f)
495{
496 int n, success = 0;
497 u_int len, bits = 0;
498 u_char *blob, *uu;
498 u_char *blob;
499 char *uu;
499
500 if (key->type == KEY_RSA1 && key->rsa != NULL) {
501 /* size of modulus 'n' */
502 bits = BN_num_bits(key->rsa->n);
503 fprintf(f, "%u", bits);
504 if (write_bignum(f, key->rsa->e) &&
505 write_bignum(f, key->rsa->n)) {
506 success = 1;

--- 218 unchanged lines hidden (view full) ---

725 return key;
726}
727
728int
729key_to_blob(Key *key, u_char **blobp, u_int *lenp)
730{
731 Buffer b;
732 int len;
500
501 if (key->type == KEY_RSA1 && key->rsa != NULL) {
502 /* size of modulus 'n' */
503 bits = BN_num_bits(key->rsa->n);
504 fprintf(f, "%u", bits);
505 if (write_bignum(f, key->rsa->e) &&
506 write_bignum(f, key->rsa->n)) {
507 success = 1;

--- 218 unchanged lines hidden (view full) ---

726 return key;
727}
728
729int
730key_to_blob(Key *key, u_char **blobp, u_int *lenp)
731{
732 Buffer b;
733 int len;
733 u_char *buf;
734
735 if (key == NULL) {
736 error("key_to_blob: key == NULL");
737 return 0;
738 }
739 buffer_init(&b);
740 switch (key->type) {
741 case KEY_DSA:

--- 9 unchanged lines hidden (view full) ---

751 buffer_put_bignum2(&b, key->rsa->n);
752 break;
753 default:
754 error("key_to_blob: unsupported key type %d", key->type);
755 buffer_free(&b);
756 return 0;
757 }
758 len = buffer_len(&b);
734
735 if (key == NULL) {
736 error("key_to_blob: key == NULL");
737 return 0;
738 }
739 buffer_init(&b);
740 switch (key->type) {
741 case KEY_DSA:

--- 9 unchanged lines hidden (view full) ---

751 buffer_put_bignum2(&b, key->rsa->n);
752 break;
753 default:
754 error("key_to_blob: unsupported key type %d", key->type);
755 buffer_free(&b);
756 return 0;
757 }
758 len = buffer_len(&b);
759 buf = xmalloc(len);
760 memcpy(buf, buffer_ptr(&b), len);
761 memset(buffer_ptr(&b), 0, len);
762 buffer_free(&b);
763 if (lenp != NULL)
764 *lenp = len;
759 if (lenp != NULL)
760 *lenp = len;
765 if (blobp != NULL)
766 *blobp = buf;
761 if (blobp != NULL) {
762 *blobp = xmalloc(len);
763 memcpy(*blobp, buffer_ptr(&b), len);
764 }
765 memset(buffer_ptr(&b), 0, len);
766 buffer_free(&b);
767 return len;
768}
769
770int
771key_sign(
772 Key *key,
773 u_char **sigp, u_int *lenp,
774 u_char *data, u_int datalen)

--- 83 unchanged lines hidden ---
767 return len;
768}
769
770int
771key_sign(
772 Key *key,
773 u_char **sigp, u_int *lenp,
774 u_char *data, u_int datalen)

--- 83 unchanged lines hidden ---