All Projects → multiformats → Multihash

multiformats / Multihash

Licence: mit
Self describing hashes - for future proofing

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Multihash

Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (-29.27%)
Mutual labels:  protocol
Cdsa
A library of generic intrusive data structures and algorithms in ANSI C
Stars: ✭ 549 (-16.31%)
Mutual labels:  hash-functions
Ngtcp2
ngtcp2 project is an effort to implement IETF QUIC protocol
Stars: ✭ 589 (-10.21%)
Mutual labels:  protocol
Quiche
🥧 Savoury implementation of the QUIC transport protocol and HTTP/3
Stars: ✭ 5,481 (+735.52%)
Mutual labels:  protocol
Mihome Binary Protocol
Stars: ✭ 536 (-18.29%)
Mutual labels:  protocol
Drtlaplus
Dr. TLA+ series - learn an algorithm and protocol, study a specification
Stars: ✭ 561 (-14.48%)
Mutual labels:  protocol
Fluence
Peer-to-peer computing protocol and licensing system
Stars: ✭ 453 (-30.95%)
Mutual labels:  protocol
Dhcpwn
All your IPs are belong to us.
Stars: ✭ 642 (-2.13%)
Mutual labels:  protocol
Lnd
Lightning Network Daemon ⚡️
Stars: ✭ 5,623 (+757.16%)
Mutual labels:  protocol
Blinksocks
A framework for building composable proxy protocol stack.
Stars: ✭ 587 (-10.52%)
Mutual labels:  protocol
Aztec
Public repository for the AZTEC protocol
Stars: ✭ 483 (-26.37%)
Mutual labels:  protocol
Laminar
A simple semi-reliable UDP protocol for multiplayer games
Stars: ✭ 530 (-19.21%)
Mutual labels:  protocol
Zero Allocation Hashing
Zero-allocation hashing for Java
Stars: ✭ 561 (-14.48%)
Mutual labels:  hash-functions
Upash
🔒Unified API for password hashing algorithms
Stars: ✭ 484 (-26.22%)
Mutual labels:  hash-functions
Neo4j Python Driver
Neo4j Bolt driver for Python
Stars: ✭ 607 (-7.47%)
Mutual labels:  protocol
Onebot
OneBot 标准:一个聊天机器人应用接口标准
Stars: ✭ 455 (-30.64%)
Mutual labels:  protocol
Xxhash
Extremely fast non-cryptographic hash algorithm
Stars: ✭ 5,783 (+781.55%)
Mutual labels:  hash-functions
Ipban
IPBan Monitors failed logins and bad behavior and bans ip addresses on Windows and Linux. Highly configurable, lean and powerful. Learn more at -->
Stars: ✭ 652 (-0.61%)
Mutual labels:  protocol
Quickfixj
QuickFIX/J is a full featured messaging engine for the FIX protocol. - This is the official project repository.
Stars: ✭ 638 (-2.74%)
Mutual labels:  protocol
Quic Go
A QUIC implementation in pure go
Stars: ✭ 6,085 (+827.59%)
Mutual labels:  protocol

multihash

Self identifying hashes

Multihash is a protocol for differentiating outputs from various well-established cryptographic hash functions, addressing size + encoding considerations.

It is useful to write applications that future-proof their use of hashes, and allow multiple hash functions to coexist. See jbenet/random-ideas#1 for a longer discussion.

Table of Contents

Example

Outputs of <encoding>.encode(multihash(<digest>, <function>)):

# sha1 - 0x11 - sha1("multihash")
111488c2f11fb2ce392acb5b2986e640211c4690073e # sha1 in hex
CEKIRQXRD6ZM4OJKZNNSTBXGIAQRYRUQA47A==== # sha1 in base32
5dsgvJGnvAfiR3K6HCBc4hcokSfmjj # sha1 in base58
ERSIwvEfss45KstbKYbmQCEcRpAHPg== # sha1 in base64

# sha2-256 0x12 - sha2-256("multihash")
12209cbc07c3f991725836a3aa2a581ca2029198aa420b9d99bc0e131d9f3e2cbe47 # sha2-256 in hex
CIQJZPAHYP4ZC4SYG2R2UKSYDSRAFEMYVJBAXHMZXQHBGHM7HYWL4RY= # sha256 in base32
QmYtUc4iTCbbfVSDNKvtQqrfyezPPnFvE33wFmutw9PBBk # sha256 in base58
EiCcvAfD+ZFyWDajqipYHKICkZiqQgudmbwOEx2fPiy+Rw== # sha256 in base64

Note: You should consider using multibase to base-encode these hashes instead of base-encoding them directly.

Format

<varint hash function code><varint digest size in bytes><hash function output>

Binary example (only 4 bytes for simplicity):

fn code  dig size hash digest
-------- -------- ------------------------------------
00010001 00000100 101101100 11111000 01011100 10110101
sha1     4 bytes  4 byte sha1 digest

Why have digest size as a separate number?

Because otherwise you end up with a function code really meaning "function-and-digest-size-code". Makes using custom digest sizes annoying, and is less flexible.

Why isn't the size first?

Because aesthetically I prefer the code first. You already have to write your stream parsing code to understand that a single byte already means "a length in bytes more to skip". Reversing these doesn't buy you much.

Why varints?

So that we have no limitation on functions or lengths.

What kind of varints?

A Most Significant Bit unsigned varint (also called base-128 varints), as defined by the multiformats/unsigned-varint.

Don't we have to agree on a table of functions?

Yes, but we already have to agree on functions, so this is not hard. The table even leaves some room for custom function codes.

Implementations:

Table for Multihash

We use a single multicodec table across all of our multiformat projects. The shared namespace reduces the chances of accidentally interpreting a code in the wrong context.

The current table lives here

Other Tables

Cannot find a good standard on this. Found some different IANA ones:

They disagree. :(

Disclaimers

Warning: obviously multihash values bias the first two bytes. Do not expect them to be uniformly distributed. The entropy size is len(multihash) - 2. Skip the first two bytes when using them with bloom filters, etc. Why not _ap_pend instead of _pre_pend? Because when reading a stream of hashes, you can know the length of the whole value, and allocate the right amount of memory, skip it, or discard it.

Obsolete and deprecated hash functions are included in this list. MD4, MD5 and SHA-1 should no longer be used for cryptographic purposes, but since many such hashes already exist they are included in this specification and may be implemented in multihash libraries.

Visual Examples

These are visual aids that help tell the story of why Multihash matters.

Consider these 4 different hashes of same input

Same length: 256 bits

Different hash functions

Idea: self-describe the values to distinguish

Multihash: fn code + length prefix

Multihash: a pretty good multiformat

Multihash: has a bunch of implementations already

Maintainers

Captain: @jbenet.

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

This repository is only for documents. All of these are licensed under the CC-BY-SA 3.0 license © 2016 Protocol Labs Inc. Any code is under a MIT © 2016 Protocol Labs Inc.

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].