Replace blake2b by sha512 (as it is not yet available on alpine

This commit is contained in:
nemunaire 2018-02-21 01:51:06 +01:00 committed by Pierre-Olivier Mercier
parent 78e94d4766
commit 6df70342af
4 changed files with 7 additions and 12 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"crypto/hmac"
"crypto/sha512"
"encoding/hex"
"encoding/json"
"errors"
@ -13,7 +14,6 @@ import (
"time"
"github.com/julienschmidt/httprouter"
"golang.org/x/crypto/blake2b"
)
const IPgwDMZ = "172.23.200.1"
@ -129,7 +129,7 @@ func challengeDisk(s *Student, t *givenToken, chid int) error {
return err
}
expectedToken := blake2b.Sum512([]byte(pkey[n1:n2]))
expectedToken := sha512.Sum512([]byte(pkey[n1:n2]))
if ! hmac.Equal(expectedToken[:], sum) {
return errors.New("This is not the expected token.")

View file

@ -1,19 +1,14 @@
package main
import (
"crypto/sha512"
"fmt"
"golang.org/x/crypto/blake2b"
)
func GenerateToken(pkey []byte, id int, a... []byte) ([]byte, error) {
h, err := blake2b.New(blake2b.Size, nil)
if err != nil {
return nil, err
}
h := sha512.New()
h.Write(pkey)
h.Write([]byte(fmt.Sprintf(":%d", id)))
h.Write([]byte(fmt.Sprintf("%x:%d", pkey, id)))
for _, v := range a {
h.Write([]byte(":"))