This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.
JavaScript algorithmsartificial-intelligencebugbountycryptographycyber-threat-intelligencecybersecurity-projectsethical-hackinghacking-toolsmalwarenessusnetwork-monitoringnetwork-securitynmapportscannerpythonpythonprojectsthreat-intelligencevirus-scanning
Create SHA-256 (Secure Hash Algorithm 256-bit).md
Abdul Wahab Junaid118bcf48419d
diff --git a/Cryptography/Cryptography Course/Course/SHA-256 (Secure Hash Algorithm 256-bit).md b/Cryptography/Cryptography Course/Course/SHA-256 (Secure Hash Algorithm 256-bit).mdnew file mode 100644index 0000000..b042af2--- /dev/null+++ b/Cryptography/Cryptography Course/Course/SHA-256 (Secure Hash Algorithm 256-bit).md@@ -0,0 +1,102 @@+### **SHA-256 (Secure Hash Algorithm 256-bit)**++**SHA-256** is part of the **SHA-2** family of cryptographic hash functions, developed by the National Security Agency (NSA) and published by the National Institute of Standards and Technology (NIST) in 2001. It is widely used for ensuring data integrity, digital signatures, and certificates in modern cryptographic systems. SHA-256 is one of the most secure and commonly used hash functions for a variety of applications, including SSL/TLS certificates, blockchain technology, and digital forensics.++### **SHA-256 Characteristics**++- **Output Size**: SHA-256 produces a **256-bit hash** (32 bytes), represented as a 64-character hexadecimal string.+- **Deterministic**: The same input will always produce the same output hash.+- **Pre-image Resistance**: It is computationally infeasible to find an input that hashes to a given output.+- **Collision Resistance**: It is highly unlikely that two different inputs will produce the same hash.+- **Avalanche Effect**: A small change in the input (even a single bit) will result in a drastically different hash value.+- **Fast Computation**: Despite being more computationally intensive than older hash functions like SHA-1, SHA-256 is still designed to be efficient.++### **SHA-256 Algorithm Structure**++SHA-256 processes data in **512-bit blocks** (64-byte blocks), and the process consists of multiple rounds of mathematical operations. Here is a step-by-step breakdown of how SHA-256 works:++1. **Padding**:+ - The input message is padded to ensure its length is a multiple of 512 bits. Padding starts with a single '1' bit followed by enough '0' bits, and then appends a 64-bit integer representing the original message length.++2. **Message Schedule**:+ - The padded message is broken into 512-bit blocks. Each 512-bit block is divided into 16 32-bit words. These words are expanded to create a schedule of 64 words, which are used in the subsequent processing.++3. **Initial Hash Values**:+ - SHA-256 uses eight initial 32-bit hash values, derived from the fractional parts of the square roots of the first eight prime numbers:+ - **H0 = 0x6a09e667**+ - **H1 = 0xbb67ae85**+ - **H2 = 0x3c6ef372**+ - **H3 = 0xa54ff53a**+ - **H4 = 0x510e527f**+ - **H5 = 0x9b05688c**+ - **H6 = 0x1f83d9ab**+ - **H7 = 0x5be0cd19**++4. **Main Loop**:+ - The algorithm uses 64 rounds of processing for each block. Each round uses bitwise operations like AND, OR, XOR, NOT, and modular addition. The 64-word schedule is used to update the hash values (H0, H1, H2, H3, H4, H5, H6, H7).++5. **Final Hash**:+ - After all message blocks are processed, the final hash is computed by concatenating the eight 32-bit hash values, producing the 256-bit final output.++### **SHA-256 Example**++To compute the SHA-256 hash of a string, such as `"hello world"`, in Python, you can use the `hashlib` library:++```python+import hashlib++# Input message+message = "hello world"++# Compute SHA-256 hash+sha256_hash = hashlib.sha256(message.encode()).hexdigest()++print(f"SHA-256 Hash of '{message}': {sha256_hash}")+```++**Output:**+```+SHA-256 Hash of 'hello world': a591a6d40bf420404a011733cfb7b190d62c65bf0bcda473d3e2e787dce4c5e4+```++### **SHA-256 Usage and Applications**++1. **Data Integrity**:+ - SHA-256 is used to ensure the integrity of data. It is common to verify file integrity by comparing the SHA-256 hash of a file before and after transmission or storage. If the hashes match, the file has not been altered.++2. **Digital Signatures**:+ - SHA-256 is widely used in digital signatures, especially in the **RSA**, **ECDSA**, and **DSA** algorithms. In these cases, the hash of a message is signed with a private key, and the signature is verified using the corresponding public key.++3. **SSL/TLS Certificates**:+ - In **SSL/TLS** protocols, SHA-256 is used for signing certificates. When a certificate is signed, the certificate authority (CA) creates a SHA-256 hash of the certificate content and signs it with its private key.++4. **Blockchain**:+ - SHA-256 is integral to the Bitcoin blockchain and many other cryptocurrencies. In Bitcoin, each block contains a SHA-256 hash of the previous block, and the mining process involves solving a computational puzzle using SHA-256.++5. **Password Hashing**:+ - SHA-256 is sometimes used in password hashing (although newer methods like **bcrypt** or **Argon2** are more secure). A user's password can be hashed using SHA-256, and the hash is stored in the database for comparison during authentication.++6. **Digital Forensics**:+ - SHA-256 is widely used in forensics for file verification and generating hash values for evidence integrity. This ensures that the evidence has not been tampered with during an investigation.++### **Security of SHA-256**++SHA-256 is currently considered to be **secure** for cryptographic applications:++- **Collision Resistance**: No practical collisions (two different inputs producing the same hash) have been found for SHA-256, making it suitable for use in digital signatures, certificates, and other security applications.+- **Pre-image Resistance**: SHA-256 is resistant to pre-image attacks, making it computationally infeasible to reverse-engineer the input from its hash.+- **Brute-force Resistance**: The 256-bit output provides a large enough space (2^256 possible hashes) that brute-force attacks are not practical.++However, **quantum computers** in the future could potentially undermine the security of SHA-256. Quantum algorithms like **Grover's algorithm** could reduce the effective security of SHA-256 to 128 bits, which might not be sufficient for sensitive applications. For this reason, **quantum-resistant hash functions** are being explored, but this is an issue for the future.++### **Alternatives to SHA-256**++While SHA-256 is secure and widely used, there are other hash functions that may be used in different contexts:++1. **SHA-512**: Part of the SHA-2 family, SHA-512 produces a 512-bit hash and is used when a larger hash size is needed for enhanced security. However, it is more computationally intensive.+2. **SHA-3**: SHA-3 is a newer hash function family, which uses a different construction (the Keccak algorithm) and is considered resistant to attacks that could affect SHA-2.+3. **BLAKE2**: A high-speed cryptographic hash function that is designed to be faster than SHA-2 while offering equivalent or superior security.++### **Conclusion**++SHA-256 is a secure, efficient, and widely used cryptographic hash function. It is a vital component in modern digital security, offering robust protection for data integrity, digital signatures, and certificate verification. Despite its widespread use and security, as technology advances, there may be future developments that further improve hashing algorithms or offer solutions to potential vulnerabilities, particularly with the advent of quantum computing.