# \[Outline\] Hash Function

**URL:** <https://discuss.hashpire.io/t/outline-hash-function/297>\
**Category:** กระดานเนื้อหา 📄\
**Tags:** in-review\
**Created:** [July 25, 2022, 3:12am UTC](https://discuss.hashpire.io/t/outline-hash-function/297 "2022-07-25T03:12:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [July 25, 2022, 3:12am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/1 "2022-07-25T03:12:04Z")

</div>

1. Hash Function

- ทำเป็น Glossary \> อธิบายความหมายโดยย่อ 1-2 บรรทัด \> [[Glossary] Cryptographic Hash Function - #24 by Namtan](https://discuss.hashpire.io/t/glossary-cryptographic-hash-function/322/24)

* * *

- ทำเป็น บทความ ประกอบด้วย
  - Hash Function คืออะไร
  - คุณสมบัติของ Hash Function \> มี 4 ข้อ \> [คุณสมบัติของ Cryptographic Hash Function](https://discuss.hashpire.io/t/cryptographic-hash-function/323)
  - ตัวอย่าง Hash function \> [ตัวอย่าง Cryptographic Hash function - #2 by supanut](https://discuss.hashpire.io/t/cryptographic-hash-function/324/2)

- บทความ อื่น ๆ ที่เกี่ยวข้อง
  - [Glossary] Compression Algorithm \> [[Glossary] Compression Algorithm](https://discuss.hashpire.io/t/glossary-compression-algorithm/325)

  - [Glossary] Hash vs Compression \> [Hash Vs Compression](https://discuss.hashpire.io/t/hash-vs-compression/326)

  - What is Encryption มี 2 รูปแบบ คือ
    - Glossary
    - บทความ ประกอบด้วย
      - Encryption คืออะไร
      - การทำงานของ Encryption
      - ประเภทของ Encryption (อันนี้แยก Content ออกไป)

  - [Glossary] Hash vs Encryption \> [Hash Vs Encryption](https://discuss.hashpire.io/t/hash-vs-encryption/328)

* * *

[STEP2] Draft Content : ==\> CF ว่าประเด็นที่เราจะเล่าทั้งหมดครบถ้วนตามที่ต้องการไหม

1. กำหนดหัวข้อหลักว่าจะเขียนเรื่องอะไร
2. กำหนดรูปแบบที่จะเขียน เช่น แบบ Glossary หรือ แบบบทความยาว
3. อธิบายถึงประเด็นที่จะเขียนเป็น outline ว่ามีอะไรบ้าง
4. สรุปประเด็นเรื่อง Graphic ว่ามีรูปแบบอะไรบ้าง
5. เพิ่ม Ref

**คำถามที่อยากให้ Reviewer ช่วยตอบ**

1. ต้องการรู้ประเด็นไหนเพิ่มเติมไหม เพราะอะไร
2. คิดว่าเรียงลำดับการนำเสนอได้ดีรึยัง ถ้าไม่ดี มีไอเดียอย่างไร
3. มีประเด็นไหนควรตัดทิ้งไหม เพราะอะไร

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:23am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/2 "2022-08-24T06:23:18Z")

</div>

[Glossary] Hash Function

คือ ฟังก์ชันการทำงานแบบทางเดียว (One-way function) ซึ่งสามารถแปลงข้อมูล (Input) ที่มีความยาวเท่าไรก็ได้ (Arbitrary length) ออกมาเป็นข้อมูล (Output) ที่ความยาวคงที่ (Fixed-length) โดยผลลัพธ์ที่ได้จะถูกเรียกว่า " Hash value "

\*\* ฟังก์ชัน คือ ความสัมพันธ์ซึ่งในสองคู่อันดับใด ๆ ของความสัมพันธ์นั้น ถ้ามีสมาชิกตัวหน้าเท่ากันแล้ว  
สมาชิกตัวหลังต้องเหมือนกันด้วย

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:25am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/3 "2022-08-24T06:25:21Z")

</div>

คุณสมบัติของ Cryptographic Hash Function มีดังนี้

1. Arbitrary-length message to fixed-length digest คือ ขนาดของข้อมูล (Input) ก่อนที่จะนำไปเข้า Hash Function จะมีความยาวเท่าใดก็ได้ แต่ค่าแฮช (Output) ที่ได้ออกมาจะมีขนาดความยาวเท่ากันหมด  

2. Pre-image resistant คือ เป็นการทำงานแบบทางเดียว การย้อนกลับทำได้ยาก จนแทบจะเรียกได้ว่าไม่สามารถย้อนกลับได้ แม้ว่าเราจะมีค่า Output ก็ไม่สามารถหาค่า Input ออกมาได้  

3. Second pre-image resistant คือ แม้ว่าเราจะมีค่า Input ค่าแฮชอยู่ เราก็ไม่สามารถหาค่า Input อื่น ๆ ที่มีค่าแฮชเดียวกันได้  

4. Collision resistant คือ การที่ค่าแฮชจะไม่ชนกัน หมายความว่า เป็นเรื่องที่ยากมากในการที่ Input ที่แตกต่างกัน 2 อัน เเม้จะแตกต่างกัเล็กน้อยก็ตาม จะทำให้ได้ค่าแฮชค่าเดียวกัน

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:34am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/4 "2022-08-24T06:34:05Z")

</div>

ตัวอย่าง มาตรฐาน Hash Function ที่เป็นที่นิยม เช่น

- MD5 ที่ออกแบบโดย Ron Rivest สามารถสร้างค่าแฮช (Hash Value) 128 bit เป็น Hash Algorithm ที่นิยมมากที่สุด แต่ภายหลังมีปัญหาเรื่องการโจมตีแบบ brute-force กับ Cryptanalytic กำหนดเป็นมาตรฐานอินเทอร์เน็ต RFC132
- SHA ได้รับการออกแบบโดย NIST & NSA ในปี 1993 ก่อนจะพบจุดอ่อนหลายประการและได้แก้ไขในปี 1995 เป็น SHA-1 เป็นมาตรฐานในสหรัฐอเมริกาสำหรับใช้กับ DSA Signature Scheme สามารถสร้างค่าแฮช (Hash Value) 160 bit
- SHA-2 สร้างขึ้นเพื่ออุดช่องโหว่ของ SHA-1 มีโครงสร้างและรายละเอียดคล้ายกับ SHA-1 และมีการเพิ่ม วิธีการแฮชขึ้นมาอีก 3 ตัว คือ SHA-256, SHA-384, SHA-512 เป็นมาตรฐานที่ใช้กันอย่างแพร่หลายในปัจจุบัน เช่น Bitcoin ที่ใช้ SHA-256

มาตรฐาน Hash Function ที่มีการใช้งานกันอยู่ในปัจจุบัน อย่าง Message Digest Algorithm (MD5) หรือ Secure Hash Algorithm เช่น SHA-1, SHA-2 จะมีความแตกต่างกันไปขึ้นอยู่กับวิธีการที่ใช้และขนาดความยาวของ Output (Fixed Length Output) ที่ได้จากกระบวนการ Hash

นอกจากตัวอย่างที่ยกมานี้ยังมี มาตรฐานอื่น ๆ อีกมากมายเช่น RIPEMD160 (RIPE Message Digest), SM3 (Shang Mi) 256-bit output, Whirlpool 512-bit output และ SHA-3 เป็นต้น

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:35am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/5 "2022-08-24T06:35:08Z")

</div>

[Glossary] Compression Algorithm

คือ การบีบอัดข้อมูลให้มีขนาดเล็กลง และสามารถทำให้ข้อมูลกับไปมีขนาดเท่าเดิมได้ อย่างเช่น Winzip หรือ WinRAR ที่เราสามารถบีบอัดไฟล์ให้มีขนาดเล็กลงและสามารถแตกไฟล์ (Extract files) ให้กลับมาเป็นเหมือนเดิมได้ ตามต้องการไม่จำกัด

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:36am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/6 "2022-08-24T06:36:16Z")

</div>

[Glossary] Hash vs Compression

Hash Function กับ Compression Algorithm มีความคล้ายคลึงกันในเรื่องของการทำให้ข้อมูลมีขนาดเล็กลง แต่ Compression เป็นการบีบอัดข้อมูลที่ยังสามารถทำให้ข้อมูลกับไปเป็นเหมือนเดิมได้ ตามต้องการไม่จำกัด ในขณะที่ Hash Function เมื่อข้อมูลถูกทำให้มีขนาดเล็กลงแล้วจะไม่สามารถทำให้กลับไปเป็นรูปแบบเดิมได้อีก

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:43am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/7 "2022-08-24T06:43:50Z")

</div>

[Glossary] Encryption

> Encryption is the method by which information is converted into secret code that hides the information’s true meaning. The science of encrypting and decrypting information is called _cryptography_ .

> **[What is Encryption and How Does it Work? | Definition from TechTarget](https://www.techtarget.com/cybersecurity/definition/encryption)**
>
> Learn how encryption works and how to use it to protect data from being accessed by unauthorized users. Explore benefits, types, implementation and more.

---

<div class="post-metadata">

**Author:** ![Namtan](https://discuss.hashpire.io/user_avatar/discuss.hashpire.io/namtan/32/23_2.png) [@Namtan](https://discuss.hashpire.io/u/Namtan)\
**Post date:** [August 24, 2022, 6:45am UTC](https://discuss.hashpire.io/t/outline-hash-function/297/8 "2022-08-24T06:45:08Z")

</div>

[Glossary] Hash Vs Encryption

Hash Function แตกต่างกับการเข้ารหัส (Encryption) ตรงที่ Encryption เป็นการทำงานแบบ 2 ทาง คือจะต้องใช้คีย์ทั้งการเข้าและถอดรหัส (Decryption) แต่ Hash Function เป็นการทำงานแบบทางเดียว คือเมื่อทำการ Hash แล้ว จะไม่มี ‘de-hashing’
