use more official blake2b checksum

This commit is contained in:
nemunaire 2018-02-03 02:03:08 +01:00
parent 1dcebc4eca
commit 62aea5413e
4 changed files with 11 additions and 9 deletions

View File

@ -2,6 +2,7 @@ package sync
import ( import (
"bufio" "bufio"
"crypto"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
@ -11,7 +12,7 @@ import (
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
"github.com/dchest/blake2b" _ "golang.org/x/crypto/blake2b"
) )
func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) { func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
@ -52,7 +53,7 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
// Handle big files as downloadable content // Handle big files as downloadable content
if res, err := i.importFile(path.Join(exercice.Path, "hints", hfile), func(filePath string, origin string) (interface{}, error) { if res, err := i.importFile(path.Join(exercice.Path, "hints", hfile), func(filePath string, origin string) (interface{}, error) {
// Calculate hash // Calculate hash
hash512 := blake2b.New512() hash512 := crypto.BLAKE2b_512.New()
if fd, err := os.Open(filePath); err != nil { if fd, err := os.Open(filePath); err != nil {
return nil, err return nil, err
} else { } else {

View File

@ -13,7 +13,7 @@ import (
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
"github.com/dchest/blake2b" "golang.org/x/crypto/blake2b"
) )
type Importer interface { type Importer interface {

View File

@ -2,7 +2,8 @@ package fic
import ( import (
"bufio" "bufio"
"crypto/sha1" "crypto"
_ "crypto/sha1"
"encoding/hex" "encoding/hex"
"errors" "errors"
"io" "io"
@ -10,7 +11,7 @@ import (
"path" "path"
"strings" "strings"
"github.com/dchest/blake2b" _ "golang.org/x/crypto/blake2b"
) )
var FilesDir string = "./FILES/" var FilesDir string = "./FILES/"
@ -110,8 +111,8 @@ func checkFileHash(filePath string, digest []byte) ([]byte, int64, error) {
defer fd.Close() defer fd.Close()
reader := bufio.NewReader(fd) reader := bufio.NewReader(fd)
hash160 := sha1.New() hash160 := crypto.SHA1.New()
hash512 := blake2b.New512() hash512 := crypto.BLAKE2b_512.New()
w := io.MultiWriter(hash160, hash512) w := io.MultiWriter(hash160, hash512)
if _, err := io.Copy(w, reader); err != nil { if _, err := io.Copy(w, reader); err != nil {

View File

@ -3,7 +3,7 @@ package fic
import ( import (
"time" "time"
"github.com/dchest/blake2b" "golang.org/x/crypto/blake2b"
) )
type Key struct { type Key struct {
@ -37,7 +37,7 @@ func (e Exercice) GetKeys() ([]Key, error) {
} }
} }
func getHashedKey(raw_value string) [blake2b.KeySize]byte { func getHashedKey(raw_value string) [blake2b.Size]byte {
hash := blake2b.Sum512([]byte(raw_value)) hash := blake2b.Sum512([]byte(raw_value))
return hash return hash
} }