summaryrefslogtreecommitdiffhomepage
path: root/cli-algo.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2013-03-29 23:29:48 +0800
committerMatt Johnston <matt@ucc.asn.au>2013-03-29 23:29:48 +0800
commit99d9cf500b30c77107bf8477dd55831626f9beaf (patch)
tree6ad847a1d5fc2a8317e1597f8e5be7350c480c37 /cli-algo.c
parent4f62da0f0d5da78b6c7a0cf507307aeacc8ac842 (diff)
Add kexguess2 behaviour
--HG-- branch : kexguess
Diffstat (limited to 'cli-algo.c')
-rw-r--r--cli-algo.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/cli-algo.c b/cli-algo.c
index 09da41a..ec8c541 100644
--- a/cli-algo.c
+++ b/cli-algo.c
@@ -34,7 +34,7 @@
* that is also on the server's list.
*/
algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[],
- int *goodguess) {
+ enum kexguess2_used *kexguess2, int *goodguess) {
unsigned char * algolist = NULL;
unsigned char * remotealgos[MAX_PROPOSED_ALGO];
@@ -42,7 +42,9 @@ algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[],
unsigned int count, i, j;
algo_type * ret = NULL;
- *goodguess = 0;
+ if (goodguess) {
+ *goodguess = 0;
+ }
/* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
algolist = buf_getstring(buf, &len);
@@ -72,6 +74,19 @@ algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[],
}
}
+ if (kexguess2 && *kexguess2 == KEXGUESS2_LOOK) {
+ for (i = 0; i < count; i++)
+ {
+ if (strcmp(remotealgos[i], KEXGUESS2_ALGO_NAME) == 0) {
+ *kexguess2 = KEXGUESS2_YES;
+ break;
+ }
+ }
+ if (*kexguess2 == KEXGUESS2_LOOK) {
+ *kexguess2 = KEXGUESS2_NO;
+ }
+ }
+
/* iterate and find the first match */
for (j = 0; localalgos[j].name != NULL; j++) {
@@ -81,9 +96,16 @@ algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[],
if (len == strlen(remotealgos[i])
&& strncmp(localalgos[j].name,
remotealgos[i], len) == 0) {
- if (i == 0 && j == 0) {
- /* was a good guess */
- *goodguess = 1;
+ if (goodguess && kexguess2) {
+ if (*kexguess2 == KEXGUESS2_YES) {
+ if (j == 0) {
+ *goodguess = 1;
+ }
+ } else {
+ if (i == 0 && j == 0) {
+ *goodguess = 1;
+ }
+ }
}
ret = &localalgos[j];
goto out;