Skip to content

Commit

Permalink
Update for PR feedback
Browse files Browse the repository at this point in the history
Fix the error strings in sig_public_key.cpp to reflect
that the errors are in the public key, not the private key.

Replace the typedefs for bignumbers in the crypto extenions
with the existing definitions from the crypto library. Not
sure the shared header file should be universally visible
but it is for now.

Signed-off-by: Mic Bowman <[email protected]>
  • Loading branch information
cmickeyb committed Jan 8, 2024
1 parent b45c7b8 commit 7dd35f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 7 additions & 7 deletions common/crypto/sig_public_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,33 @@ pcrypto::sig::PublicKey::PublicKey(

pdo::crypto::BN_CTX_ptr b_ctx(BN_CTX_new(), BN_CTX_free);
Error::ThrowIf<Error::MemoryError>(
b_ctx == nullptr, "Crypto Error (sig::PrivateKey): Cound not create BN context");
b_ctx == nullptr, "Crypto Error (sig::PublicKey): Cound not create BN context");

EC_GROUP_ptr group(EC_GROUP_new_by_curve_name(sigDetails_.sslNID), EC_GROUP_clear_free);
Error::ThrowIf<Error::MemoryError>(
group == nullptr, "Crypto Error (sig::PrivateKey): Cound not create group");
group == nullptr, "Crypto Error (sig::PublicKey): Cound not create group");

EC_GROUP_set_point_conversion_form(group.get(), POINT_CONVERSION_COMPRESSED);

EC_KEY_ptr public_key(EC_KEY_new(), EC_KEY_free);
Error::ThrowIf<Error::MemoryError>(
public_key == nullptr, "Crypto Error (sig::PrivateKey): Cound not create public_key");
public_key == nullptr, "Crypto Error (sig::PublicKey): Cound not create public_key");

res = EC_KEY_set_group(public_key.get(), group.get());
Error::ThrowIf<Error::CryptoError>(
res <= 0, "Crypto Error (sig::DeserializeXYFromHex): Could not set EC_GROUP");

EC_POINT_ptr point(EC_POINT_new(group.get()), EC_POINT_free);
Error::ThrowIf<Error::MemoryError>(
point == nullptr, "Crypto Error (sig::PrivateKey): Cound not create point");
point == nullptr, "Crypto Error (sig::PublicKey): Cound not create point");

res = EC_POINT_oct2point(group.get(), point.get(), numeric_key.data(), numeric_key.size(), b_ctx.get());
Error::ThrowIf<Error::CryptoError>(
res <= 0, "Crypto Error (sig::PrivateKey): Cound not convert octet to point");
res <= 0, "Crypto Error (sig::PublicKey): Cound not convert octet to point");

res = EC_KEY_set_public_key(public_key.get(), point.get());
Error::ThrowIf<Error::CryptoError>(
res <= 0, "Crypto Error (sig::PrivateKey): Cound not set public key");
res <= 0, "Crypto Error (sig::PublicKey): Cound not set public key");

key_ = public_key.get();
public_key.release();
Expand Down Expand Up @@ -319,7 +319,7 @@ void pcrypto::sig::PublicKey::GetNumericKey(ByteArray& numeric_key) const

pdo::crypto::BN_CTX_ptr b_ctx(BN_CTX_new(), BN_CTX_free);
Error::ThrowIf<Error::MemoryError>(
b_ctx == nullptr, "Crypto Error (sig::PrivateKey): Cound not create BN context");
b_ctx == nullptr, "Crypto Error (sig::PublicKey): Cound not create BN context");

const EC_GROUP *group = EC_KEY_get0_group(key_);
const EC_POINT *point = EC_KEY_get0_public_key(key_);
Expand Down
5 changes: 1 addition & 4 deletions common/interpreter/wawaka_wasm/WasmCryptoExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "packages/parson/parson.h"

#include "crypto.h"
#include "crypto_shared.h"
#include "crypto/verify_ias_report/ias-certificates.h"
#include "error.h"
#include "jsonvalue.h"
Expand All @@ -41,10 +42,6 @@
namespace pe = pdo::error;
namespace pcrypto = pdo::crypto;

typedef std::unique_ptr<BIGNUM, void (*)(BIGNUM*)> BIGNUM_ptr;
typedef std::unique_ptr<EC_GROUP, void (*)(EC_GROUP*)> EC_GROUP_ptr;


/* ----------------------------------------------------------------- *
* NAME: _b64_encode_wrapper
* ----------------------------------------------------------------- */
Expand Down

0 comments on commit 7dd35f5

Please sign in to comment.