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
f10115e5
Commit
f10115e5
authored
Jul 10, 2019
by
Cole Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise minimum bits required for RSA key to 2048
parent
2835a401
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
11 deletions
+13
-11
crypto/key_test.go
crypto/key_test.go
+2
-2
crypto/rsa_common.go
crypto/rsa_common.go
+4
-2
crypto/rsa_go.go
crypto/rsa_go.go
+3
-3
crypto/rsa_openssl.go
crypto/rsa_openssl.go
+1
-1
crypto/rsa_test.go
crypto/rsa_test.go
+3
-3
No files found.
crypto/key_test.go
View file @
f10115e5
...
...
@@ -17,7 +17,7 @@ func TestKeys(t *testing.T) {
}
func
testKeyType
(
typ
int
,
t
*
testing
.
T
)
{
sk
,
pk
,
err
:=
test
.
RandTestKeyPair
(
typ
,
512
)
sk
,
pk
,
err
:=
test
.
RandTestKeyPair
(
typ
,
2048
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -114,7 +114,7 @@ func testKeyEquals(t *testing.T, k Key) {
t
.
Fatal
(
"Key not equal to key with same bytes."
)
}
sk
,
pk
,
err
:=
test
.
RandTestKeyPair
(
RSA
,
512
)
sk
,
pk
,
err
:=
test
.
RandTestKeyPair
(
RSA
,
2048
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
crypto/rsa_common.go
View file @
f10115e5
package
crypto
import
(
"
errors
"
"
fmt
"
)
const
MinRsaKeyBits
=
2048
// ErrRsaKeyTooSmall is returned when trying to generate or parse an RSA key
// that's smaller than 512 bits. Keys need to be larger enough to sign a 256bit
// hash so this is a reasonable absolute minimum.
var
ErrRsaKeyTooSmall
=
errors
.
New
(
"rsa keys must be >=
512
bits to be useful"
)
var
ErrRsaKeyTooSmall
=
fmt
.
Errorf
(
"rsa keys must be >=
%d
bits to be useful"
,
MinRsaKeyBits
)
crypto/rsa_go.go
View file @
f10115e5
...
...
@@ -27,7 +27,7 @@ type RsaPublicKey struct {
// GenerateRSAKeyPair generates a new rsa private and public key
func
GenerateRSAKeyPair
(
bits
int
,
src
io
.
Reader
)
(
PrivKey
,
PubKey
,
error
)
{
if
bits
<
512
{
if
bits
<
MinRsaKeyBits
{
return
nil
,
nil
,
ErrRsaKeyTooSmall
}
priv
,
err
:=
rsa
.
GenerateKey
(
src
,
bits
)
...
...
@@ -102,7 +102,7 @@ func UnmarshalRsaPrivateKey(b []byte) (PrivKey, error) {
if
err
!=
nil
{
return
nil
,
err
}
if
sk
.
N
.
BitLen
()
<
512
{
if
sk
.
N
.
BitLen
()
<
MinRsaKeyBits
{
return
nil
,
ErrRsaKeyTooSmall
}
return
&
RsaPrivateKey
{
sk
:
*
sk
},
nil
...
...
@@ -118,7 +118,7 @@ func UnmarshalRsaPublicKey(b []byte) (PubKey, error) {
if
!
ok
{
return
nil
,
errors
.
New
(
"not actually an rsa public key"
)
}
if
pk
.
N
.
BitLen
()
<
512
{
if
pk
.
N
.
BitLen
()
<
MinRsaKeyBits
{
return
nil
,
ErrRsaKeyTooSmall
}
return
&
RsaPublicKey
{
*
pk
},
nil
...
...
crypto/rsa_openssl.go
View file @
f10115e5
...
...
@@ -21,7 +21,7 @@ type RsaPublicKey struct {
// GenerateRSAKeyPair generates a new rsa private and public key
func
GenerateRSAKeyPair
(
bits
int
,
_
io
.
Reader
)
(
PrivKey
,
PubKey
,
error
)
{
if
bits
<
512
{
if
bits
<
MinRsaKeyBits
{
return
nil
,
nil
,
ErrRsaKeyTooSmall
}
...
...
crypto/rsa_test.go
View file @
f10115e5
...
...
@@ -6,7 +6,7 @@ import (
)
func
TestRSABasicSignAndVerify
(
t
*
testing
.
T
)
{
priv
,
pub
,
err
:=
GenerateRSAKeyPair
(
512
,
rand
.
Reader
)
priv
,
pub
,
err
:=
GenerateRSAKeyPair
(
2048
,
rand
.
Reader
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -47,7 +47,7 @@ func TestRSASmallKey(t *testing.T) {
}
func
TestRSASignZero
(
t
*
testing
.
T
)
{
priv
,
pub
,
err
:=
GenerateRSAKeyPair
(
512
,
rand
.
Reader
)
priv
,
pub
,
err
:=
GenerateRSAKeyPair
(
2048
,
rand
.
Reader
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -68,7 +68,7 @@ func TestRSASignZero(t *testing.T) {
}
func
TestRSAMarshalLoop
(
t
*
testing
.
T
)
{
priv
,
pub
,
err
:=
GenerateRSAKeyPair
(
512
,
rand
.
Reader
)
priv
,
pub
,
err
:=
GenerateRSAKeyPair
(
2048
,
rand
.
Reader
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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