Skip to content

Commit

Permalink
Removed duplicate method.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Oct 16, 2024
1 parent 862b1ac commit 74395d5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 39 deletions.
40 changes: 2 additions & 38 deletions SharpSnmpLib/Security/AESPrivacyProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/// <summary>
/// Some protocols support a method to extend the encryption or decryption key when supplied key
/// is too short.
/// </summary>
/// <param name="shortKey">Key that needs to be extended</param>
/// <param name="engineId">Authoritative engine id. Value is retrieved as part of SNMP v3 discovery procedure</param>
/// <param name="authProtocol">Authentication protocol class instance cast as <see cref="IAuthenticationProvider"/></param>
/// <returns>Extended key value</returns>
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;
}
}
}
}
2 changes: 1 addition & 1 deletion SharpSnmpLib/Security/TripleDESPrivacyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 74395d5

Please sign in to comment.