SHA-224 Implementation Examples

Reference implementations of the SHA-224 cryptographic hash function in multiple programming languages

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.

Browser Compatible Node.js No Dependencies

Python

Pure Python implementation with detailed comments explaining each step.

Python 3.x No Dependencies Standalone

Java

Object-oriented Java implementation with message digest interface pattern.

Java 8+ OOP Design Test Suite

C#

C# implementation with .NET cryptography extension pattern.

.NET Standard Extension Methods LINQ Support

Go

Go implementation following standard hash.Hash interface pattern.

Go 1.13+ Standard Interface Benchmarks

Ruby

Ruby implementation with both class and module approaches.

Ruby 2.5+ Pure Ruby No Gems Required

Rust

Memory-safe, high-performance Rust implementation.

Rust 1.39+ Zero Copy No Unsafe

PHP

PHP implementation as both a class and standalone functions.

PHP 7.2+ Type Hinting Namespace Support

Swift

Swift implementation with protocol-oriented design and memory safety.

Swift 5+ Protocol-Oriented iOS/macOS Compatible

C

Low-level C implementation focusing on performance and portability.

ANSI C Portable Optimized

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.

Contribute Your Implementation

Have you implemented SHA-224 in another language or have improvements for our examples? Consider contributing to our open-source repository and help the community.

Learn About Contributing