Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-core
Commits
9698a72f
Unverified
Commit
9698a72f
authored
Aug 06, 2019
by
bigs
Committed by
GitHub
Aug 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #31 from libp2p/bug/remove-blowfish-support
Remove support for blowfish
parents
33faefeb
47983a3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
5 deletions
+27
-5
crypto/key.go
crypto/key.go
+7
-5
crypto/key_test.go
crypto/key_test.go
+20
-0
No files found.
crypto/key.go
View file @
9698a72f
...
...
@@ -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
...
...
@@ -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
...
...
crypto/key_test.go
View file @
9698a72f
...
...
@@ -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"
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment