Skip to content
/ dchash Public

A configurable variation of Dropbox's Content Hash algorithm in idiomatic Go.

License

Notifications You must be signed in to change notification settings

azazeal/dchash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Coverage Report Go Reference

dchash

Package dchash implements a configurable variation of Dropbox's Content Hash algorithm in idiomatic Go.

Usage

package checksum

import (
	"crypto/sha512"
	"io"

	"github.com/azazeal/dchash"
)

// Dropbox hashes the data in src as per Dropbox's Content Hash algorithm, using
// SHA256 and over blocks of 4 MiB in size.
func Dropbox(src io.Reader) (sum []byte, err error) {
	h := dchash.New(nil, -1)

	if _, err = io.Copy(h, src); err == nil {
		sum = h.Sum(nil)
	}

	return
}

// SHA512m1 hashes the data in src as per Dropbox's Content Hash algorithm but
// with SHA512 (instead of SHA256) and over blocks of 1 (instead  of 4) MiB in
// size.
func SHA512m1(src io.Reader) (sum []byte, err error) {
	h := dchash.New(sha512.New, 1<<20)

	if _, err = io.Copy(h, src); err == nil {
		sum = h.Sum(nil)
	}

	return
}

About

A configurable variation of Dropbox's Content Hash algorithm in idiomatic Go.

Topics

Resources

License

Stars

Watchers

Forks

Languages