Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1 | From 1f76151c92e1b52e9c24ebf06adc77fbd6c062bc Mon Sep 17 00:00:00 2001 |
| 2 | From: Will Cosgrove <will@panic.com> |
| 3 | Date: Tue, 26 Jan 2021 11:41:21 -0800 |
| 4 | Subject: [PATCH] kex.c: move EC macro outside of if check #549 (#550) |
| 5 | |
| 6 | File: kex.c |
| 7 | |
| 8 | Notes: |
| 9 | Moved the macro LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY outside of the LIBSSH2_ECDSA since it's also now used by the ED25519 code. |
| 10 | |
| 11 | Sha 256, 384 and 512 need to be defined for all backends now even if they aren't used directly. I believe this is already the case, but just a heads up. |
| 12 | |
| 13 | Credit: |
| 14 | Stefan-Ghinea |
| 15 | |
| 16 | Upstream-Status: Backport |
| 17 | |
| 18 | Reference to upstream patch: |
| 19 | https://github.com/libssh2/libssh2/commit/1f76151c92e1b52e9c24ebf06adc77fbd6c062bc |
| 20 | |
| 21 | Signed-off-by: Stefan Ghinea <stefan.ghinea@windriver.com> |
| 22 | --- |
| 23 | src/kex.c | 66 +++++++++++++++++++++++++++---------------------------- |
| 24 | 1 file changed, 33 insertions(+), 33 deletions(-) |
| 25 | |
| 26 | diff --git a/src/kex.c b/src/kex.c |
| 27 | index cb16639..19ab6ec 100644 |
| 28 | --- a/src/kex.c |
| 29 | +++ b/src/kex.c |
| 30 | @@ -1885,39 +1885,6 @@ kex_method_diffie_hellman_group_exchange_sha256_key_exchange |
| 31 | } |
| 32 | |
| 33 | |
| 34 | -#if LIBSSH2_ECDSA |
| 35 | - |
| 36 | -/* kex_session_ecdh_curve_type |
| 37 | - * returns the EC curve type by name used in key exchange |
| 38 | - */ |
| 39 | - |
| 40 | -static int |
| 41 | -kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) |
| 42 | -{ |
| 43 | - int ret = 0; |
| 44 | - libssh2_curve_type type; |
| 45 | - |
| 46 | - if(name == NULL) |
| 47 | - return -1; |
| 48 | - |
| 49 | - if(strcmp(name, "ecdh-sha2-nistp256") == 0) |
| 50 | - type = LIBSSH2_EC_CURVE_NISTP256; |
| 51 | - else if(strcmp(name, "ecdh-sha2-nistp384") == 0) |
| 52 | - type = LIBSSH2_EC_CURVE_NISTP384; |
| 53 | - else if(strcmp(name, "ecdh-sha2-nistp521") == 0) |
| 54 | - type = LIBSSH2_EC_CURVE_NISTP521; |
| 55 | - else { |
| 56 | - ret = -1; |
| 57 | - } |
| 58 | - |
| 59 | - if(ret == 0 && out_type) { |
| 60 | - *out_type = type; |
| 61 | - } |
| 62 | - |
| 63 | - return ret; |
| 64 | -} |
| 65 | - |
| 66 | - |
| 67 | /* LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY |
| 68 | * |
| 69 | * Macro that create and verifies EC SHA hash with a given digest bytes |
| 70 | @@ -2027,6 +1994,39 @@ kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) |
| 71 | } \ |
| 72 | |
| 73 | |
| 74 | +#if LIBSSH2_ECDSA |
| 75 | + |
| 76 | +/* kex_session_ecdh_curve_type |
| 77 | + * returns the EC curve type by name used in key exchange |
| 78 | + */ |
| 79 | + |
| 80 | +static int |
| 81 | +kex_session_ecdh_curve_type(const char *name, libssh2_curve_type *out_type) |
| 82 | +{ |
| 83 | + int ret = 0; |
| 84 | + libssh2_curve_type type; |
| 85 | + |
| 86 | + if(name == NULL) |
| 87 | + return -1; |
| 88 | + |
| 89 | + if(strcmp(name, "ecdh-sha2-nistp256") == 0) |
| 90 | + type = LIBSSH2_EC_CURVE_NISTP256; |
| 91 | + else if(strcmp(name, "ecdh-sha2-nistp384") == 0) |
| 92 | + type = LIBSSH2_EC_CURVE_NISTP384; |
| 93 | + else if(strcmp(name, "ecdh-sha2-nistp521") == 0) |
| 94 | + type = LIBSSH2_EC_CURVE_NISTP521; |
| 95 | + else { |
| 96 | + ret = -1; |
| 97 | + } |
| 98 | + |
| 99 | + if(ret == 0 && out_type) { |
| 100 | + *out_type = type; |
| 101 | + } |
| 102 | + |
| 103 | + return ret; |
| 104 | +} |
| 105 | + |
| 106 | + |
| 107 | /* ecdh_sha2_nistp |
| 108 | * Elliptic Curve Diffie Hellman Key Exchange |
| 109 | */ |
| 110 | -- |
| 111 | 2.17.1 |
| 112 | |