All Projects → amosnier → sha-2

amosnier / sha-2

Licence: other
SHA-2 algorithm implementations

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to sha-2

signet
Easily compare SHA/BLAKE2 sums.
Stars: ✭ 13 (-89.34%)
Mutual labels:  hash, sha256
CudaSHA256
Simple tool to calculate sha256 on GPU using Cuda
Stars: ✭ 38 (-68.85%)
Mutual labels:  hash, sha256
SHA256
A C++ SHA256 implementation.
Stars: ✭ 79 (-35.25%)
Mutual labels:  hash, sha256
bookshelf-secure-password
A Bookshelf.js plugin for handling secure passwords
Stars: ✭ 24 (-80.33%)
Mutual labels:  hash, secure
simple-sha256
Generate SHA-256 hashes (in Node and the Browser)
Stars: ✭ 42 (-65.57%)
Mutual labels:  hash, sha256
BruteForce
A simple brute forcer written in GO for SHA1, SHA256, SHA512, MD5 and bcrypt
Stars: ✭ 49 (-59.84%)
Mutual labels:  hash, sha256
noble-hashes
Audited & minimal JS implementation of SHA2, SHA3, RIPEMD, BLAKE2/3, HMAC, HKDF, PBKDF2 & Scrypt
Stars: ✭ 213 (+74.59%)
Mutual labels:  hash, sha256
Gtkhash
A cross-platform desktop utility for computing message digests or checksums
Stars: ✭ 167 (+36.89%)
Mutual labels:  hash, sha256
go-checksum
Simple tool to calc Golang module checksum of go.mod and module dir.
Stars: ✭ 45 (-63.11%)
Mutual labels:  hash, sha256
rust-hmac-sha256
A small, self-contained SHA256 and HMAC-SHA256 implementation.
Stars: ✭ 24 (-80.33%)
Mutual labels:  hash, sha256
Bughunt
A weekly challenge where we share some code and you find a bug in it.
Stars: ✭ 68 (-44.26%)
Mutual labels:  review, hash
jscrypto
Crypto library for Node/ES6/Typescript/Browser.
Stars: ✭ 20 (-83.61%)
Mutual labels:  hash, sha256
Hash Library
Portable C++ hashing library
Stars: ✭ 109 (-10.66%)
Mutual labels:  portable, sha256
fhash
fHash - an open source files hash calculator for Windows and macOS
Stars: ✭ 222 (+81.97%)
Mutual labels:  hash, sha256
Nsec
A modern and easy-to-use cryptographic library for .NET Core based on libsodium
Stars: ✭ 217 (+77.87%)
Mutual labels:  hash, sha256
WebCrypto.swift
A small collection of cryptographic functions based on the JavaScript WebCrypto API.
Stars: ✭ 16 (-86.89%)
Mutual labels:  hash, sha256
Digestpp
C++11 header-only message digest library
Stars: ✭ 116 (-4.92%)
Mutual labels:  hash, sha256
Merkle
Node.js module implementing Merkle tree algorithm
Stars: ✭ 123 (+0.82%)
Mutual labels:  hash, sha256
hash-checker
Fast and simple application that allows you to generate and compare hashes from files and text
Stars: ✭ 72 (-40.98%)
Mutual labels:  hash, sha256
hash-wasm
Lightning fast hash functions using hand-tuned WebAssembly binaries
Stars: ✭ 382 (+213.11%)
Mutual labels:  hash, sha256

sha-2 Build Status

Contents

SHA-2 algorithm implementations.

At the moment, only SHA-256 is implemented.

Design criteria

  • C99

  • Easy to test, include in any project, compile and link.

  • Portable. Makes no assumptions on the target system's endianess or word size.

  • The SHA-256 implementation is a straightforward implementation of the algorithm specified on Wikipedia.

Streaming API

In response to an enhancement request, a new streaming API has been created.

The following code is a silly but complete example:

struct Sha_256 sha_256;
uint8_t hash[32];
sha_256_init(&sha_256, hash);
sha_256_write(&sha_256, "ab", strlen("ab"));
sha_256_write(&sha_256, "c", strlen("c"));
sha_256_close(&sha_256);

That is the equivalent of the (of course still supported) legacy way:

uint8_t hash[32];
calc_sha_256(hash, "abc", strlen("abc"));

See header file for more information.

Since the streaming API is a generalization of the non-streaming one, the latter has been ported to the former, without measurable performance impact. However, a legacy branch has been created in order to make the legacy implementation easily available. If you can measure a significant difference between the two, please post an issue.

Notes

The Makefile is as minimal as possible. No effort was put into making it general. Its purpose is mainly to ease testing for the developer's host machine. The actual implementation is however extremely easy to include in any project, may it use GNU make or any other build tool.

Code review

This code has been reviewed at Stack Exchange CODE REVIEW, and the implementation has been improved accordingly.

Testing

Testing is continuously performed on Travis CI (see above).

Apart from that, the implementation has been successfully tested on an x86-64 machine under Linux as well as on a 16-bit DSP. On the x86-64 machine, all the available NIST test vectors where successfully tested (SHA-256 examples and SHA-2 Additional examples, plus a few others).

In particular:

Input Message: "abc"
Message Digest is BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD
Input Message: "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
Message Digest is 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1
SHA-256 Test Data
#1) 1 byte 0xbd
68325720 aabd7c82 f30f554b 313d0570 c95accbb 7dc4b5aa e11204c0 8ffe732b
#2) 4 bytes 0xc98c8e55
7abc22c0 ae5af26c e93dbb94 433a0e0b 2e119d01 4f8e7f65 bd56c61c cccd9504
#3) 55 bytes of zeros
02779466 cdec1638 11d07881 5c633f21 90141308 1449002f 24aa3e80 f0b88ef7
#4) 56 bytes of zeros
d4817aa5 497628e7 c77e6b60 6107042b bba31308 88c5f47a 375e6179 be789fbb
#5) 57 bytes of zeros
65a16cb7 861335d5 ace3c607 18b5052e 44660726 da4cd13b b745381b 235a1785
#6) 64 bytes of zeros
f5a5fd42 d16a2030 2798ef6e d309979b 43003d23 20d9f0e8 ea9831a9 2759fb4b
#7) 1000 bytes of zeros
541b3e9d aa09b20b f85fa273 e5cbd3e8 0185aa4e c298e765 db87742b 70138a53
#8) 1000 bytes of 0x41 ‘A’
c2e68682 3489ced2 017f6059 b8b23931 8b6364f6 dcd835d0 a519105a 1eadd6e4
#9) 1005 bytes of 0x55 ‘U’
f4d62dde c0f3dd90 ea1380fa 16a5ff8d c4c54b21 740650f2 4afc4120 903552b0
#10) 1000000 bytes of zeros
d29751f2 649b32ff 572b5e0a 9f541ea6 60a50f94 ff0beedf b0b692b9 24cc8025
#11) 0x20000000 (536870912) bytes of 0x5a ‘Z’
15a1868c 12cc5395 1e182344 277447cd 0979536b adcc512a d24c67e9 b2d4f3dd
#12) 0x41000000 (1090519040) bytes of zeros
461c19a9 3bd4344f 9215f5ec 64357090 342bc66b 15a14831 7d276e31 cbc20b53
#13) 0x6000003e (1610612798) bytes of 0x42 ‘B’
c23ce8a7 895f4b21 ec0daf37 920ac0a2 62a22004 5a03eb2d fed48ef9 b05aabea

License

This repository is made available under a permissive license. See LICENSE FILE.

Reference implementation

I had missed that when I made this implementation but RFC 6234, chapter 8 actually includes a reference implementation in C that is (at least in ambition) broader in scope than this one. I have however neither compiled nor tested it.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].