Below you'll find reference implementations of the SHA-224 hash function in various programming languages. These implementations are provided for educational purposes and to help you understand how SHA-224 works across different platforms.
Each implementation follows the specification defined in NIST FIPS 180-4 and passes all test vectors. While these examples prioritize clarity over performance, they can be used as a starting point for your own optimized implementations.
Important Notes
- These implementations are intended for educational purposes
- For production use, consider using your language's standard cryptographic libraries
- All examples are MIT licensed and can be freely used in your projects
- Test vectors are included in each implementation
JavaScript
ES6 implementation with both class-based and functional approaches.
Python
Pure Python implementation with detailed comments explaining each step.
Java
Object-oriented Java implementation with message digest interface pattern.
C#
C# implementation with .NET cryptography extension pattern.
Go
Go implementation following standard hash.Hash interface pattern.
Ruby
Ruby implementation with both class and module approaches.
Rust
Memory-safe, high-performance Rust implementation.
PHP
PHP implementation as both a class and standalone functions.
Swift
Swift implementation with protocol-oriented design and memory safety.
C
Low-level C implementation focusing on performance and portability.
Implementation Notes
When implementing SHA-224 in your own projects, consider the following best practices:
- Use Standard Libraries: Most modern languages provide cryptographic libraries with optimized SHA-224 implementations. Use these when available for production code.
- Test Vectors: Always verify your implementation against the official NIST test vectors to ensure correctness.
- Security Context: Remember that SHA-224 alone is not suitable for password hashing. For password storage, use specialized algorithms like Argon2, bcrypt, or PBKDF2.
- Performance Considerations: If performance is critical, consider using hardware acceleration when available, or optimized libraries with assembly implementations.
- Constant-Time Operations: For security-sensitive applications, ensure that operations are constant-time to prevent timing attacks.
All examples on this page are provided under the MIT License, allowing you to freely use and modify them for your own projects, both commercial and non-commercial.