diff options
author | Damien Miller <djm@mindrot.org> | 2002-02-19 15:21:23 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2002-02-19 15:21:23 +1100 |
commit | 963f6b25e28ff55290ae45f540b7f7148a3622a9 (patch) | |
tree | 48d1a96683326594903955672277fe008bf622e4 /authfile.c | |
parent | 19a59451050446bb8656d1b72a8787e97cd1c99b (diff) |
- markus@cvs.openbsd.org 2002/02/14 23:41:01
[authfile.c cipher.c cipher.h kex.c kex.h packet.c]
hide some more implementation details of cipher.[ch] and prepares for move
to EVP, ok deraadt@
Diffstat (limited to 'authfile.c')
-rw-r--r-- | authfile.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/authfile.c b/authfile.c index 69e0da03b..e35714e93 100644 --- a/authfile.c +++ b/authfile.c | |||
@@ -36,7 +36,7 @@ | |||
36 | */ | 36 | */ |
37 | 37 | ||
38 | #include "includes.h" | 38 | #include "includes.h" |
39 | RCSID("$OpenBSD: authfile.c,v 1.45 2001/12/29 21:56:01 stevesk Exp $"); | 39 | RCSID("$OpenBSD: authfile.c,v 1.46 2002/02/14 23:41:01 markus Exp $"); |
40 | 40 | ||
41 | #include <openssl/err.h> | 41 | #include <openssl/err.h> |
42 | #include <openssl/evp.h> | 42 | #include <openssl/evp.h> |
@@ -69,7 +69,7 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase, | |||
69 | { | 69 | { |
70 | Buffer buffer, encrypted; | 70 | Buffer buffer, encrypted; |
71 | u_char buf[100], *cp; | 71 | u_char buf[100], *cp; |
72 | int fd, i; | 72 | int fd, i, cipher_num; |
73 | CipherContext ciphercontext; | 73 | CipherContext ciphercontext; |
74 | Cipher *cipher; | 74 | Cipher *cipher; |
75 | u_int32_t rand; | 75 | u_int32_t rand; |
@@ -78,11 +78,9 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase, | |||
78 | * If the passphrase is empty, use SSH_CIPHER_NONE to ease converting | 78 | * If the passphrase is empty, use SSH_CIPHER_NONE to ease converting |
79 | * to another cipher; otherwise use SSH_AUTHFILE_CIPHER. | 79 | * to another cipher; otherwise use SSH_AUTHFILE_CIPHER. |
80 | */ | 80 | */ |
81 | if (strcmp(passphrase, "") == 0) | 81 | cipher_num = (strcmp(passphrase, "") == 0) ? |
82 | cipher = cipher_by_number(SSH_CIPHER_NONE); | 82 | SSH_CIPHER_NONE : SSH_AUTHFILE_CIPHER; |
83 | else | 83 | if ((cipher = cipher_by_number(cipher_num)) == NULL) |
84 | cipher = cipher_by_number(SSH_AUTHFILE_CIPHER); | ||
85 | if (cipher == NULL) | ||
86 | fatal("save_private_key_rsa: bad cipher"); | 84 | fatal("save_private_key_rsa: bad cipher"); |
87 | 85 | ||
88 | /* This buffer is used to built the secret part of the private key. */ | 86 | /* This buffer is used to built the secret part of the private key. */ |
@@ -119,7 +117,7 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase, | |||
119 | buffer_put_char(&encrypted, 0); | 117 | buffer_put_char(&encrypted, 0); |
120 | 118 | ||
121 | /* Store cipher type. */ | 119 | /* Store cipher type. */ |
122 | buffer_put_char(&encrypted, cipher->number); | 120 | buffer_put_char(&encrypted, cipher_num); |
123 | buffer_put_int(&encrypted, 0); /* For future extension */ | 121 | buffer_put_int(&encrypted, 0); /* For future extension */ |
124 | 122 | ||
125 | /* Store public key. This will be in plain text. */ | 123 | /* Store public key. This will be in plain text. */ |
@@ -131,9 +129,11 @@ key_save_private_rsa1(Key *key, const char *filename, const char *passphrase, | |||
131 | /* Allocate space for the private part of the key in the buffer. */ | 129 | /* Allocate space for the private part of the key in the buffer. */ |
132 | cp = buffer_append_space(&encrypted, buffer_len(&buffer)); | 130 | cp = buffer_append_space(&encrypted, buffer_len(&buffer)); |
133 | 131 | ||
134 | cipher_set_key_string(&ciphercontext, cipher, passphrase); | 132 | cipher_set_key_string(&ciphercontext, cipher, passphrase, |
135 | cipher_encrypt(&ciphercontext, cp, | 133 | CIPHER_ENCRYPT); |
134 | cipher_crypt(&ciphercontext, cp, | ||
136 | buffer_ptr(&buffer), buffer_len(&buffer)); | 135 | buffer_ptr(&buffer), buffer_len(&buffer)); |
136 | cipher_cleanup(&ciphercontext); | ||
137 | memset(&ciphercontext, 0, sizeof(ciphercontext)); | 137 | memset(&ciphercontext, 0, sizeof(ciphercontext)); |
138 | 138 | ||
139 | /* Destroy temporary data. */ | 139 | /* Destroy temporary data. */ |
@@ -380,9 +380,11 @@ key_load_private_rsa1(int fd, const char *filename, const char *passphrase, | |||
380 | cp = buffer_append_space(&decrypted, buffer_len(&buffer)); | 380 | cp = buffer_append_space(&decrypted, buffer_len(&buffer)); |
381 | 381 | ||
382 | /* Rest of the buffer is encrypted. Decrypt it using the passphrase. */ | 382 | /* Rest of the buffer is encrypted. Decrypt it using the passphrase. */ |
383 | cipher_set_key_string(&ciphercontext, cipher, passphrase); | 383 | cipher_set_key_string(&ciphercontext, cipher, passphrase, |
384 | cipher_decrypt(&ciphercontext, cp, | 384 | CIPHER_DECRYPT); |
385 | cipher_crypt(&ciphercontext, cp, | ||
385 | buffer_ptr(&buffer), buffer_len(&buffer)); | 386 | buffer_ptr(&buffer), buffer_len(&buffer)); |
387 | cipher_cleanup(&ciphercontext); | ||
386 | memset(&ciphercontext, 0, sizeof(ciphercontext)); | 388 | memset(&ciphercontext, 0, sizeof(ciphercontext)); |
387 | buffer_free(&buffer); | 389 | buffer_free(&buffer); |
388 | 390 | ||