Re: [心得][.NET] GetHashCode()

作者: AmosYang (泛用人型編碼器)   2016-11-27 03:11:03
重構了這篇文章,拆開成幾個小題目來談、排版、整理後續討論,應該在可讀性上
有進步。
值得一提的是新加入的這篇文
* C# `System.Valuetype.GetHashCode()` 潛在效能、安全問題
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-valuetype.html
ValueType 的 `GetHashCode() 預設實作是把所有欄位(field) 大鍋炒成
雜湊(hash)值;有看過些說法主張這可能造成潛在的效能問題外,然而,更嚴
重的 是如其原碼註解 所指出的,這多少會在某種程度上把敏感資訊透露出去
,也就是有 **潛在的安全問題** 。
https://github.com/dotnet/coreclr/blob/release/1.1.0/src/vm/comutilnative.cpp#L2770-L2774
// The default implementation of GetHashCode() for all value types.
// Note that this implementation reveals the value of the fields.
// So if the value type contains any sensitive information it should
// implement its own GetHashCode().
FCIMPL1(INT32, ValueTypeHelper::GetHashCode, Object* objUNSAFE)
是故,原碼註解主張
若此 value type 含有敏感資訊,那它應該為 GetHashCode() 提供自己
的實作版本。
然而,很遺憾的, System.Valuetype.GetHashCode() 的官方文件
目前(2016-11-25)並沒有特別提醒這件事。
更進一步的原始碼追蹤可參考這篇
* C# `GetHashCode()` 原始碼
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-source-code.html
:)
========================================================================
* 列表: http://www.30abysses.com/TWY/2016/11/21/index.html
* C# `GetHashCode()`
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode.html
* C# `GetHashCode()` 簡單來說就是……
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-explained.html
* C# `GetHashCode()` 起源、守則、法則
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-origin-guidelines-rules.html
* C# `GetHashCode()` 討論
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-discussion.html
* C# `GetHashCode()` 原始碼
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-source-code.html
* C# `System.Valuetype.GetHashCode()` 潛在效能、安全問題
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode-valuetype.html
* C# `GetHashCode()` 系列文之緣起
http://www.30abysses.com/TWY/2016/11/21/c_sharp-gethashcode.meta.html
作者: james732 (好人超)   2016-11-27 14:22:00
不過有可能從標準實作算出的hash去倒推特定的資料嗎?

Links booklink

Contact Us: admin [ a t ] ucptt.com