summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c53
1 files changed, 8 insertions, 45 deletions
diff --git a/kex.c b/kex.c
index 308ffb1b6..78e108e90 100644
--- a/kex.c
+++ b/kex.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: kex.c,v 1.22 2001/03/05 17:17:20 markus Exp $"); 26RCSID("$OpenBSD: kex.c,v 1.23 2001/03/10 17:51:04 markus Exp $");
27 27
28#include <openssl/crypto.h> 28#include <openssl/crypto.h>
29#include <openssl/bio.h> 29#include <openssl/bio.h>
@@ -42,6 +42,7 @@ RCSID("$OpenBSD: kex.c,v 1.22 2001/03/05 17:17:20 markus Exp $");
42#include "key.h" 42#include "key.h"
43#include "log.h" 43#include "log.h"
44#include "mac.h" 44#include "mac.h"
45#include "match.h"
45 46
46#define KEX_COOKIE_LEN 16 47#define KEX_COOKIE_LEN 16
47 48
@@ -372,49 +373,10 @@ derive_key(int id, int need, u_char *hash, BIGNUM *shared_secret)
372 return digest; 373 return digest;
373} 374}
374 375
375#define NKEYS 6
376
377#define MAX_PROP 20
378#define SEP ","
379
380char *
381get_match(char *client, char *server)
382{
383 char *sproposals[MAX_PROP];
384 char *c, *s, *p, *ret, *cp, *sp;
385 int i, j, nproposals;
386
387 c = cp = xstrdup(client);
388 s = sp = xstrdup(server);
389
390 for ((p = strsep(&sp, SEP)), i=0; p && *p != '\0';
391 (p = strsep(&sp, SEP)), i++) {
392 if (i < MAX_PROP)
393 sproposals[i] = p;
394 else
395 break;
396 }
397 nproposals = i;
398
399 for ((p = strsep(&cp, SEP)), i=0; p && *p != '\0';
400 (p = strsep(&cp, SEP)), i++) {
401 for (j = 0; j < nproposals; j++) {
402 if (strcmp(p, sproposals[j]) == 0) {
403 ret = xstrdup(p);
404 xfree(c);
405 xfree(s);
406 return ret;
407 }
408 }
409 }
410 xfree(c);
411 xfree(s);
412 return NULL;
413}
414void 376void
415choose_enc(Enc *enc, char *client, char *server) 377choose_enc(Enc *enc, char *client, char *server)
416{ 378{
417 char *name = get_match(client, server); 379 char *name = match_list(client, server, NULL);
418 if (name == NULL) 380 if (name == NULL)
419 fatal("no matching cipher found: client %s server %s", client, server); 381 fatal("no matching cipher found: client %s server %s", client, server);
420 enc->cipher = cipher_by_name(name); 382 enc->cipher = cipher_by_name(name);
@@ -428,7 +390,7 @@ choose_enc(Enc *enc, char *client, char *server)
428void 390void
429choose_mac(Mac *mac, char *client, char *server) 391choose_mac(Mac *mac, char *client, char *server)
430{ 392{
431 char *name = get_match(client, server); 393 char *name = match_list(client, server, NULL);
432 if (name == NULL) 394 if (name == NULL)
433 fatal("no matching mac found: client %s server %s", client, server); 395 fatal("no matching mac found: client %s server %s", client, server);
434 if (mac_init(mac, name) < 0) 396 if (mac_init(mac, name) < 0)
@@ -443,7 +405,7 @@ choose_mac(Mac *mac, char *client, char *server)
443void 405void
444choose_comp(Comp *comp, char *client, char *server) 406choose_comp(Comp *comp, char *client, char *server)
445{ 407{
446 char *name = get_match(client, server); 408 char *name = match_list(client, server, NULL);
447 if (name == NULL) 409 if (name == NULL)
448 fatal("no matching comp found: client %s server %s", client, server); 410 fatal("no matching comp found: client %s server %s", client, server);
449 if (strcmp(name, "zlib") == 0) { 411 if (strcmp(name, "zlib") == 0) {
@@ -458,7 +420,7 @@ choose_comp(Comp *comp, char *client, char *server)
458void 420void
459choose_kex(Kex *k, char *client, char *server) 421choose_kex(Kex *k, char *client, char *server)
460{ 422{
461 k->name = get_match(client, server); 423 k->name = match_list(client, server, NULL);
462 if (k->name == NULL) 424 if (k->name == NULL)
463 fatal("no kex alg"); 425 fatal("no kex alg");
464 if (strcmp(k->name, KEX_DH1) == 0) { 426 if (strcmp(k->name, KEX_DH1) == 0) {
@@ -471,7 +433,7 @@ choose_kex(Kex *k, char *client, char *server)
471void 433void
472choose_hostkeyalg(Kex *k, char *client, char *server) 434choose_hostkeyalg(Kex *k, char *client, char *server)
473{ 435{
474 char *hostkeyalg = get_match(client, server); 436 char *hostkeyalg = match_list(client, server, NULL);
475 if (hostkeyalg == NULL) 437 if (hostkeyalg == NULL)
476 fatal("no hostkey alg"); 438 fatal("no hostkey alg");
477 k->hostkey_type = key_type_from_name(hostkeyalg); 439 k->hostkey_type = key_type_from_name(hostkeyalg);
@@ -524,6 +486,7 @@ kex_choose_conf(char *cprop[PROPOSAL_MAX], char *sprop[PROPOSAL_MAX], int server
524 return k; 486 return k;
525} 487}
526 488
489#define NKEYS 6
527int 490int
528kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret) 491kex_derive_keys(Kex *k, u_char *hash, BIGNUM *shared_secret)
529{ 492{