From 74395d50c3460ae68c5f97512412d59c1e3f4fbe Mon Sep 17 00:00:00 2001 From: Lex Li Date: Wed, 16 Oct 2024 02:34:51 -0400 Subject: [PATCH] Removed duplicate method. --- .../Security/AESPrivacyProviderBase.cs | 40 +------------------ .../Security/TripleDESPrivacyProvider.cs | 2 +- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/SharpSnmpLib/Security/AESPrivacyProviderBase.cs b/SharpSnmpLib/Security/AESPrivacyProviderBase.cs index a764947d..baee6d02 100644 --- a/SharpSnmpLib/Security/AESPrivacyProviderBase.cs +++ b/SharpSnmpLib/Security/AESPrivacyProviderBase.cs @@ -426,7 +426,7 @@ public byte[] PasswordToKey(byte[] secret, byte[] engineId) var pkey = AuthenticationProvider.PasswordToKey(secret, engineId); if (pkey.Length < MinimumKeyLength) { - pkey = ExtendShortKey(pkey, engineId, AuthenticationProvider); + pkey = TripleDESPrivacyProvider.ExtendShortKey(pkey, engineId, AuthenticationProvider); } return pkey; @@ -463,42 +463,6 @@ private byte[] GetIV(int engineBoots, int engineTime, byte[] privacyParameters) // Copy salt value to the iv array Buffer.BlockCopy(privacyParameters, 0, iv, 8, PrivacyParametersLength); return iv; - } - - /// - /// Some protocols support a method to extend the encryption or decryption key when supplied key - /// is too short. - /// - /// Key that needs to be extended - /// Authoritative engine id. Value is retrieved as part of SNMP v3 discovery procedure - /// Authentication protocol class instance cast as - /// Extended key value - internal byte[] ExtendShortKey(byte[] shortKey, byte[] engineId, IAuthenticationProvider authProtocol) - { - byte[] extKey = new byte[MinimumKeyLength]; - byte[] lastKeyBuf = new byte[shortKey.Length]; - Array.Copy(shortKey, lastKeyBuf, shortKey.Length); - int keyLen = shortKey.Length > MinimumKeyLength ? MinimumKeyLength : shortKey.Length; - Array.Copy(shortKey, extKey, keyLen); - while (keyLen < MinimumKeyLength) - { - byte[] tmpBuf = authProtocol.PasswordToKey(lastKeyBuf, engineId); - if (tmpBuf.Length <= (MinimumKeyLength - keyLen)) - { - Array.Copy(tmpBuf, 0, extKey, keyLen, tmpBuf.Length); - keyLen += tmpBuf.Length; - } - else - { - Array.Copy(tmpBuf, 0, extKey, keyLen, MinimumKeyLength - keyLen); - keyLen += MinimumKeyLength - keyLen; - } - - lastKeyBuf = new byte[tmpBuf.Length]; - Array.Copy(tmpBuf, lastKeyBuf, tmpBuf.Length); - } - - return extKey; - } + } } } diff --git a/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs b/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs index c9fc273d..f61547a6 100644 --- a/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs +++ b/SharpSnmpLib/Security/TripleDESPrivacyProvider.cs @@ -416,7 +416,7 @@ public byte[] PasswordToKey(byte[] secret, byte[] engineId) return encryptionKey; } - private byte[] ExtendShortKey(byte[] shortKey, byte[] engineID, IAuthenticationProvider authProtocol) + internal static byte[] ExtendShortKey(byte[] shortKey, byte[] engineID, IAuthenticationProvider authProtocol) { int length = shortKey.Length; byte[] extendedKey = new byte[MinimumKeyLength];