Skip to content

Commit

Permalink
Revert "Switch phone number hashing to use scrypt (ethereum#342)" (et…
Browse files Browse the repository at this point in the history
…hereum#344)

This reverts commit b58f3c4.
  • Loading branch information
marekolszewski authored and mergify[bot] committed Jul 13, 2019
1 parent 3e4e2c2 commit 49724b8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 83 deletions.
35 changes: 2 additions & 33 deletions abe/abe.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,25 @@ import (
"encoding/json"
"errors"
"fmt"
"golang.org/x/crypto/scrypt"
"net/http"
"regexp"
"time"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
)

var ScryptParams = struct {
salt []byte
N int
r int
p int
dkLen int
}{
[]byte("nNWKc3l0a1fAj0r35BLGB8kn"),
512,
16,
1,
32,
}

func hashPhoneNumber(phoneNumber []byte) ([]byte, error) {
return scrypt.Key(
phoneNumber,
ScryptParams.salt,
ScryptParams.N,
ScryptParams.r,
ScryptParams.p,
ScryptParams.dkLen,
)
}

func decryptPhoneNumber(request types.AttestationRequest, account accounts.Account, wallet accounts.Wallet) (string, error) {
phoneNumber, err := wallet.Decrypt(account, request.EncryptedPhone, nil, nil)
if err != nil {
return "", err
}
// TODO(asa): Better validation of phone numbers
r, _ := regexp.Compile(`^\+[0-9]{8,15}$`)

hashedPhone, err := hashPhoneNumber(phoneNumber)
if err != nil {
return "Hashing phone number failed", err
}

if !bytes.Equal(hashedPhone, request.PhoneHash.Bytes()) {
if !bytes.Equal(crypto.Keccak256(phoneNumber), request.PhoneHash.Bytes()) {
return string(phoneNumber), errors.New("Phone hash doesn't match decrypted phone number")
} else if !r.MatchString(string(phoneNumber)) {
return string(phoneNumber), fmt.Errorf("Decrypted phone number invalid: %s", string(phoneNumber))
Expand Down
50 changes: 0 additions & 50 deletions abe/abe_test.go

This file was deleted.

0 comments on commit 49724b8

Please sign in to comment.