Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Fix EC deriveKey
Browse files Browse the repository at this point in the history
- wrong aes key length
  • Loading branch information
microshine committed Dec 18, 2016
1 parent bb576fc commit 30b2784
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/crypto/ec.ts
Expand Up @@ -226,7 +226,7 @@ export class EcCrypto extends BaseCrypto {
}

// derive key
(baseKey.native as native.Key).EcdhDeriveKey((_algorithm.public as any).native, _derivedKeyType.length, (err, raw) => {
(baseKey.native as native.Key).EcdhDeriveKey((_algorithm.public as any).native, _derivedKeyType.length / 8, (err, raw) => {
if (err) reject(err);
else {
AesClass.importKey("raw", raw, _derivedKeyType, extractable, keyUsages)
Expand Down
4 changes: 3 additions & 1 deletion src/ec/ec_dh.cpp
Expand Up @@ -3,6 +3,8 @@
Handle<std::string> ECDH_derive_key(Handle<ScopedEVP_PKEY> pkey, Handle<ScopedEVP_PKEY> pubkey, size_t &secret_len) {
LOG_FUNC();

size_t aes_key_length = secret_len;

ScopedEVP_PKEY_CTX ctx;
Handle<std::string>hSecret(new std::string());

Expand Down Expand Up @@ -34,7 +36,7 @@ Handle<std::string> ECDH_derive_key(Handle<ScopedEVP_PKEY> pkey, Handle<ScopedEV
if (1 != (EVP_PKEY_derive(ctx.Get(), secret, &secret_len))) {
THROW_OPENSSL("EVP_PKEY_derive_init");
}
hSecret->resize(secret_len);
hSecret->resize(aes_key_length);

return hSecret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/node/async_ec.cpp
Expand Up @@ -27,7 +27,7 @@ void AsyncEcGenerateKey::HandleOKCallback() {

void AsyncEcdhDeriveKey::Execute() {
try {
dkey = ECDH_derive_key(pkey,pubkey, secret_len);
dkey = ECDH_derive_key(pkey, pubkey, secret_len);
}
catch (std::exception& e) {
this->SetErrorMessage(e.what());
Expand Down

0 comments on commit 30b2784

Please sign in to comment.