crypto/ecies: use AES-192 for curve P384 (#24139)

Using curve P384 for encryption causes the error "ecies: shared key params
are too big". Also, readme.md says curve P384 should use AES192 not AES256.

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
This commit is contained in:
xq840622 2022-01-12 18:09:10 +08:00 committed by GitHub
parent 2c58e6b62d
commit 045e90c897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -279,7 +279,7 @@ var testCases = []testCase{
{ {
Curve: elliptic.P384(), Curve: elliptic.P384(),
Name: "P384", Name: "P384",
Expected: ECIES_AES256_SHA384, Expected: ECIES_AES192_SHA384,
}, },
{ {
Curve: elliptic.P521(), Curve: elliptic.P521(),

View File

@ -80,6 +80,14 @@ var (
KeyLen: 16, KeyLen: 16,
} }
ECIES_AES192_SHA384 = &ECIESParams{
Hash: sha512.New384,
hashAlgo: crypto.SHA384,
Cipher: aes.NewCipher,
BlockSize: aes.BlockSize,
KeyLen: 24,
}
ECIES_AES256_SHA256 = &ECIESParams{ ECIES_AES256_SHA256 = &ECIESParams{
Hash: sha256.New, Hash: sha256.New,
hashAlgo: crypto.SHA256, hashAlgo: crypto.SHA256,
@ -108,7 +116,7 @@ var (
var paramsFromCurve = map[elliptic.Curve]*ECIESParams{ var paramsFromCurve = map[elliptic.Curve]*ECIESParams{
ethcrypto.S256(): ECIES_AES128_SHA256, ethcrypto.S256(): ECIES_AES128_SHA256,
elliptic.P256(): ECIES_AES128_SHA256, elliptic.P256(): ECIES_AES128_SHA256,
elliptic.P384(): ECIES_AES256_SHA384, elliptic.P384(): ECIES_AES192_SHA384,
elliptic.P521(): ECIES_AES256_SHA512, elliptic.P521(): ECIES_AES256_SHA512,
} }