From fed191fa0f5fca17834e9ef3ef48c8efc0fc00f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=93=E6=B4=AA=E6=98=8C?= Date: Tue, 21 Jan 2025 16:32:28 +0800 Subject: [PATCH] add hamc-sm3 --- 0003-feat-Add-HMAC-SM3.patch | 79 ++++++++++++++++++++++++++++++++++++ libssh2.spec | 11 ++++- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 0003-feat-Add-HMAC-SM3.patch diff --git a/0003-feat-Add-HMAC-SM3.patch b/0003-feat-Add-HMAC-SM3.patch new file mode 100644 index 0000000..b92ded2 --- /dev/null +++ b/0003-feat-Add-HMAC-SM3.patch @@ -0,0 +1,79 @@ +From c0390fac943ab8f29303a504586ae911d4eaee1b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=E5=BA=93=E6=B4=AA=E6=98=8C?= +Date: Tue, 21 Jan 2025 16:06:57 +0800 +Subject: [PATCH] add sm3 + +--- + src/mac.c | 39 +++++++++++++++++++++++++++++++++++++++ + src/openssl.h | 4 ++++ + 2 files changed, 43 insertions(+) + +diff --git a/src/mac.c b/src/mac.c +index 01c5faa..204bd27 100644 +--- a/src/mac.c ++++ b/src/mac.c +@@ -434,7 +434,46 @@ static const LIBSSH2_MAC_METHOD mac_method_hmac_ripemd160_openssh_com = { + }; + #endif /* LIBSSH2_HMAC_RIPEMD */ + ++static int ++mac_method_hmac_sm3_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) ++{ ++ libssh2_hmac_ctx ctx; ++ unsigned char seqno_buf[4]; ++ (void)session; ++ ++ _libssh2_htonu32(seqno_buf, seqno); ++ ++ libssh2_hmac_ctx_init(ctx); ++ libssh2_hmac_sm3_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); ++ ++ return 0; ++} ++ ++static const LIBSSH2_MAC_METHOD mac_method_hmac_sm3 = { ++ "hmac-sm3", ++ 32, ++ 32, ++ mac_method_common_init, ++ mac_method_hmac_sm3_hash, ++ mac_method_common_dtor, ++ 0 ++}; ++ + static const LIBSSH2_MAC_METHOD *mac_methods[] = { ++ &mac_method_hmac_sm3, + #if LIBSSH2_HMAC_SHA256 + &mac_method_hmac_sha2_256, + &mac_method_hmac_sha2_256_etm, +diff --git a/src/openssl.h b/src/openssl.h +index b7652c0..6e9721e 100644 +--- a/src/openssl.h ++++ b/src/openssl.h +@@ -328,6 +328,10 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx); + #define libssh2_hmac_sha512_init(ctx, key, keylen) \ + HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL) + ++/*GM HMAC-SM3*/ ++#define libssh2_hmac_sm3_init(ctx, key, keylen) \ ++ HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sm3(), NULL) ++ + #ifdef LIBSSH2_WOLFSSL + /* FIXME: upstream bug as of v5.6.0: datalen is int instead of size_t */ + #define libssh2_hmac_update(ctx, data, datalen) \ +-- +2.43.0 + diff --git a/libssh2.spec b/libssh2.spec index fd933df..b0be661 100644 --- a/libssh2.spec +++ b/libssh2.spec @@ -1,6 +1,6 @@ Name: libssh2 Version: 1.11.0 -Release: 4 +Release: 5 Summary: A library implementing the SSH2 protocol License: BSD URL: https://www.libssh2.org/ @@ -18,7 +18,8 @@ Patch8: backport-buildconf-drop.patch Patch9: backport-Prevent-possible-double-free-of-hostkey.patch Patch10: backport-Fix-unstable-connections-over-nonblocking-sockets.patch Patch11: backport-session-support-server-banners-up-to-8192-bytes-was-256.patch - +Patch12: 0003-feat-Add-HMAC-SM3.patch + BuildRequires: coreutils findutils /usr/bin/man zlib-devel BuildRequires: gcc make sed openssl-devel > 1:1.0.2 openssh-server BuildRequires: glibc-langpack-en groff @@ -97,6 +98,12 @@ echo "exit 0" > tests/mansyntax.sh %{_mandir}/man3/libssh2_*.3* %changelog +* Tue Jan 21 2025 hcku - 1.11.0-5 +- Type:feature +- ID:NA +- SUG:NA +- DESC:Add MAC Algorithm HMAC-SM3 + * Tue Oct 29 2024 bitianyuan - 1.11.0-4 - Type:bugfix - ID:NA -- Gitee