Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #31 from libp2p/bug/remove-blowfish-support
Browse files Browse the repository at this point in the history
Remove support for blowfish
  • Loading branch information
bigs authored Aug 6, 2019
2 parents 33faefe + 47983a3 commit 9698a72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
12 changes: 7 additions & 5 deletions crypto/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ type StretchedKeys struct {
}

// KeyStretcher returns a set of keys for each party by stretching the shared key.
// (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey)
// (myIV, theirIV, myCipherKey, theirCipherKey, myMACKey, theirMACKey).
// This function accepts the following cipher types:
// - AES-128
// - AES-256
// The function will panic upon receiving an unknown cipherType
func KeyStretcher(cipherType string, hashType string, secret []byte) (StretchedKeys, StretchedKeys) {
var cipherKeySize int
var ivSize int
Expand All @@ -193,10 +197,8 @@ func KeyStretcher(cipherType string, hashType string, secret []byte) (StretchedK
case "AES-256":
ivSize = 16
cipherKeySize = 32
case "Blowfish":
ivSize = 8
// Note: cypherKeySize arbitrarily selected, needs more thought
cipherKeySize = 32
default:
panic("Unrecognized cipher, programmer error?")
}

hmacKeySize := 20
Expand Down
20 changes: 20 additions & 0 deletions crypto/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,23 @@ func TestUnknownCurveErrors(t *testing.T) {
t.Fatal("expected invalid key type to error")
}
}

func TestPanicOnUnknownCipherType(t *testing.T) {
passed := false
defer func() {
if !passed {
t.Fatal("expected known cipher and hash to succeed")
}
err := recover()
errStr, ok := err.(string)
if !ok {
t.Fatal("expected string in panic")
}
if errStr != "Unrecognized cipher, programmer error?" {
t.Fatal("expected \"Unrecognized cipher, programmer error?\"")
}
}()
KeyStretcher("AES-256", "SHA1", []byte("foo"))
passed = true
KeyStretcher("Fooba", "SHA1", []byte("foo"))
}

0 comments on commit 9698a72

Please sign in to comment.