Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add two filecoin hashes, without Sum() implementations #128

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 44 additions & 38 deletions multihash.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ const (
// Deprecated: use MURMUR3_128
MURMUR3 = MURMUR3_128

X11 = 0x1100
SHA2_256_TRUNC254_PADDED = 0x1012
X11 = 0x1100
POSEIDON_BLS12_381_A1_FC1 = 0xb401
)

func init() {
Expand All @@ -93,47 +95,51 @@ func init() {

// Names maps the name of a hash to the code
var Names = map[string]uint64{
"identity": IDENTITY,
"sha1": SHA1,
"sha2-256": SHA2_256,
"sha2-512": SHA2_512,
"sha3": SHA3_512,
"sha3-224": SHA3_224,
"sha3-256": SHA3_256,
"sha3-384": SHA3_384,
"sha3-512": SHA3_512,
"dbl-sha2-256": DBL_SHA2_256,
"murmur3-128": MURMUR3_128,
"keccak-224": KECCAK_224,
"keccak-256": KECCAK_256,
"keccak-384": KECCAK_384,
"keccak-512": KECCAK_512,
"shake-128": SHAKE_128,
"shake-256": SHAKE_256,
"x11": X11,
"md5": MD5,
"identity": IDENTITY,
"sha1": SHA1,
"sha2-256": SHA2_256,
"sha2-512": SHA2_512,
"sha3": SHA3_512,
"sha3-224": SHA3_224,
"sha3-256": SHA3_256,
"sha3-384": SHA3_384,
"sha3-512": SHA3_512,
"dbl-sha2-256": DBL_SHA2_256,
"murmur3-128": MURMUR3_128,
"keccak-224": KECCAK_224,
"keccak-256": KECCAK_256,
"keccak-384": KECCAK_384,
"keccak-512": KECCAK_512,
"shake-128": SHAKE_128,
"shake-256": SHAKE_256,
"sha2-256-trunc254-padded": SHA2_256_TRUNC254_PADDED,
"x11": X11,
"md5": MD5,
"poseidon-bls12_381-a2-fc1": POSEIDON_BLS12_381_A1_FC1,
}

// Codes maps a hash code to it's name
var Codes = map[uint64]string{
IDENTITY: "identity",
SHA1: "sha1",
SHA2_256: "sha2-256",
SHA2_512: "sha2-512",
SHA3_224: "sha3-224",
SHA3_256: "sha3-256",
SHA3_384: "sha3-384",
SHA3_512: "sha3-512",
DBL_SHA2_256: "dbl-sha2-256",
MURMUR3_128: "murmur3-128",
KECCAK_224: "keccak-224",
KECCAK_256: "keccak-256",
KECCAK_384: "keccak-384",
KECCAK_512: "keccak-512",
SHAKE_128: "shake-128",
SHAKE_256: "shake-256",
X11: "x11",
MD5: "md5",
IDENTITY: "identity",
SHA1: "sha1",
SHA2_256: "sha2-256",
SHA2_512: "sha2-512",
SHA3_224: "sha3-224",
SHA3_256: "sha3-256",
SHA3_384: "sha3-384",
SHA3_512: "sha3-512",
DBL_SHA2_256: "dbl-sha2-256",
MURMUR3_128: "murmur3-128",
KECCAK_224: "keccak-224",
KECCAK_256: "keccak-256",
KECCAK_384: "keccak-384",
KECCAK_512: "keccak-512",
SHAKE_128: "shake-128",
SHAKE_256: "shake-256",
SHA2_256_TRUNC254_PADDED: "sha2-256-trunc254-padded",
X11: "x11",
POSEIDON_BLS12_381_A1_FC1: "poseidon-bls12_381-a2-fc1",
MD5: "md5",
}

// DefaultLengths maps a hash code to it's default length
Expand Down
4 changes: 4 additions & 0 deletions multihash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var tCodes = map[uint64]string{
0x19: "shake-256",
0x1100: "x11",
0xd5: "md5",
0x1012: "sha2-256-trunc254-padded",
0xb401: "poseidon-bls12_381-a2-fc1",
}

type TestCase struct {
Expand All @@ -54,6 +56,8 @@ var testCases = []TestCase{
{"1af97f7818a28edfdfce5ec66dbdc7e871813816d7d585fe1f12475ded5b6502b7723b74e2ee36f2651a10a8eaca72aa9148c3c761aaceac8f6d6cc64381ed39", 0x19, "shake-256"},
{"4bca2b137edc580fe50a88983ef860ebaca36c857b1f492839d6d7392452a63c82cbebc68e3b70a2a1480b4bb5d437a7cba6ecf9d89f9ff3ccd14cd6146ea7e7", 0x14, "sha3-512"},
{"d41d8cd98f00b204e9800998ecf8427e", 0xd5, "md5"},
{"14fcb37dc45fa9a3c492557121bd4d461c0db40e5dcfcaa98498bd238486c307", 0x1012, "sha2-256-trunc254-padded"},
{"14fcb37dc45fa9a3c492557121bd4d461c0db40e5dcfcaa98498bd238486c307", 0xb401, "poseidon-bls12_381-a2-fc1"},
}

func (tc TestCase) Multihash() (Multihash, error) {
Expand Down
2 changes: 1 addition & 1 deletion spec/multicodec
Submodule multicodec updated 2 files
+21 −44 README.md
+15 −0 table.csv
2 changes: 1 addition & 1 deletion spec/multihash
Submodule multihash updated 1 files
+1 −1 README.md