mirror of
https://github.com/nmap/nmap.git
synced 2026-01-19 12:49:02 +00:00
Update libssh2 to 1.11.1
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2004-2007, Sara Golemon <sarag@libssh2.org>
|
||||
/* Copyright (C) Sara Golemon <sarag@libssh2.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
@@ -33,6 +33,8 @@
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
@@ -122,23 +124,27 @@ mac_method_hmac_sha2_512_hash(LIBSSH2_SESSION * session,
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
libssh2_hmac_ctx_init(ctx);
|
||||
libssh2_hmac_sha512_init(&ctx, *abstract, 64);
|
||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||
libssh2_hmac_update(ctx, packet, packet_len);
|
||||
if(addtl && addtl_len) {
|
||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||
}
|
||||
libssh2_hmac_final(ctx, buf);
|
||||
libssh2_hmac_cleanup(&ctx);
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_sha512_init(&ctx, *abstract, 64) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return 0;
|
||||
return !res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_512 = {
|
||||
"hmac-sha2-512",
|
||||
64,
|
||||
@@ -177,21 +183,23 @@ mac_method_hmac_sha2_256_hash(LIBSSH2_SESSION * session,
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
libssh2_hmac_ctx_init(ctx);
|
||||
libssh2_hmac_sha256_init(&ctx, *abstract, 32);
|
||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||
libssh2_hmac_update(ctx, packet, packet_len);
|
||||
if(addtl && addtl_len) {
|
||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||
}
|
||||
libssh2_hmac_final(ctx, buf);
|
||||
libssh2_hmac_cleanup(&ctx);
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_sha256_init(&ctx, *abstract, 32) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return 0;
|
||||
return !res;
|
||||
}
|
||||
|
||||
|
||||
@@ -234,21 +242,23 @@ mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session,
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
libssh2_hmac_ctx_init(ctx);
|
||||
libssh2_hmac_sha1_init(&ctx, *abstract, 20);
|
||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||
libssh2_hmac_update(ctx, packet, packet_len);
|
||||
if(addtl && addtl_len) {
|
||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||
}
|
||||
libssh2_hmac_final(ctx, buf);
|
||||
libssh2_hmac_cleanup(&ctx);
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_sha1_init(&ctx, *abstract, 20) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return 0;
|
||||
return !res;
|
||||
}
|
||||
|
||||
|
||||
@@ -286,10 +296,11 @@ mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session,
|
||||
{
|
||||
unsigned char temp[SHA_DIGEST_LENGTH];
|
||||
|
||||
mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len,
|
||||
addtl, addtl_len, abstract);
|
||||
memcpy(buf, (char *) temp, 96 / 8);
|
||||
if(mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len,
|
||||
addtl, addtl_len, abstract))
|
||||
return 1;
|
||||
|
||||
memcpy(buf, (char *) temp, 96 / 8);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -319,21 +330,23 @@ mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf,
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
libssh2_hmac_ctx_init(ctx);
|
||||
libssh2_hmac_md5_init(&ctx, *abstract, 16);
|
||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||
libssh2_hmac_update(ctx, packet, packet_len);
|
||||
if(addtl && addtl_len) {
|
||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||
}
|
||||
libssh2_hmac_final(ctx, buf);
|
||||
libssh2_hmac_cleanup(&ctx);
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_md5_init(&ctx, *abstract, 16) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return 0;
|
||||
return !res;
|
||||
}
|
||||
|
||||
|
||||
@@ -360,8 +373,11 @@ mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
unsigned char temp[MD5_DIGEST_LENGTH];
|
||||
mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len,
|
||||
addtl, addtl_len, abstract);
|
||||
|
||||
if(mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len,
|
||||
addtl, addtl_len, abstract))
|
||||
return 1;
|
||||
|
||||
memcpy(buf, (char *) temp, 96 / 8);
|
||||
return 0;
|
||||
}
|
||||
@@ -394,21 +410,23 @@ mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session,
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
libssh2_hmac_ctx_init(ctx);
|
||||
libssh2_hmac_ripemd160_init(&ctx, *abstract, 20);
|
||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||
libssh2_hmac_update(ctx, packet, packet_len);
|
||||
if(addtl && addtl_len) {
|
||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||
}
|
||||
libssh2_hmac_final(ctx, buf);
|
||||
libssh2_hmac_cleanup(&ctx);
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_ripemd160_init(&ctx, *abstract, 20) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return 0;
|
||||
return !res;
|
||||
}
|
||||
|
||||
|
||||
@@ -467,6 +485,44 @@ _libssh2_mac_methods(void)
|
||||
}
|
||||
|
||||
#if LIBSSH2_AES_GCM
|
||||
static int
|
||||
mac_method_none_init(LIBSSH2_SESSION * session, unsigned char *key,
|
||||
int *free_key, void **abstract)
|
||||
{
|
||||
(void)session;
|
||||
(void)key;
|
||||
(void)free_key;
|
||||
(void)abstract;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mac_method_hmac_none_hash(LIBSSH2_SESSION * session,
|
||||
unsigned char *buf, uint32_t seqno,
|
||||
const unsigned char *packet,
|
||||
size_t packet_len,
|
||||
const unsigned char *addtl,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
(void)session;
|
||||
(void)buf;
|
||||
(void)seqno;
|
||||
(void)packet;
|
||||
(void)packet_len;
|
||||
(void)addtl;
|
||||
(void)addtl_len;
|
||||
(void)abstract;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
mac_method_none_dtor(LIBSSH2_SESSION * session, void **abstract)
|
||||
{
|
||||
(void)session;
|
||||
(void)abstract;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Stub for aes256-gcm@openssh.com crypto type, which has an integrated
|
||||
HMAC method. This must not be added to mac_methods[] since it cannot be
|
||||
negotiated separately. */
|
||||
@@ -474,9 +530,9 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_aesgcm = {
|
||||
"INTEGRATED-AES-GCM", /* made up name for display only */
|
||||
16,
|
||||
16,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
mac_method_none_init,
|
||||
mac_method_hmac_none_hash,
|
||||
mac_method_none_dtor,
|
||||
0
|
||||
};
|
||||
#endif /* LIBSSH2_AES_GCM */
|
||||
|
||||
Reference in New Issue
Block a user