Adding minio-hash with streaming crypto hashes

This commit is contained in:
Frederick F. Kautz IV
2014-12-21 13:01:27 +13:00
parent aa6cd015fa
commit 2278df9910
11 changed files with 333 additions and 2 deletions
+20 -1
View File
@@ -23,9 +23,12 @@ package sha1
// void sha1_transform(int32_t *hash, const char* input, size_t num_blocks);
import "C"
import (
gosha1 "crypto/sha1"
"errors"
"github.com/minio-io/minio/pkgs/cpu"
"io"
"unsafe"
"github.com/minio-io/minio/pkgs/cpu"
)
const (
@@ -69,3 +72,19 @@ func Sha1(buffer []byte) ([]int32, error) {
return shbuf, nil
}
func Sum(reader io.Reader) ([]byte, error) {
hash := gosha1.New()
var err error
for err == nil {
length := 0
byteBuffer := make([]byte, 1024*1024)
length, err = reader.Read(byteBuffer)
byteBuffer = byteBuffer[0:length]
hash.Write(byteBuffer)
}
if err != io.EOF {
return nil, err
}
return hash.Sum(nil), nil
}