Skip to content

Commit

Permalink
Some CodeQL directed code cleanup (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
emlowe authored Jun 20, 2023
1 parent ec18617 commit 2b6e809
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
5 changes: 0 additions & 5 deletions src/hdkeys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ class HDKeys {
throw std::invalid_argument("Seed size must be at least 32 bytes");
}

// std::cout << "seed: "<< Util::HexStr(seed.begin(),seed.size()) <<
// std::endl;

blst_scalar* skBn = Util::SecAlloc<blst_scalar>(1);
blst_keygen_v3(skBn, seed.begin(), seed.size(), info, infoLen);
uint8_t* skBytes = Util::SecAlloc<uint8_t>(32);
blst_bendian_from_scalar(skBytes, skBn);

// std::cout << "skBytes: "<< Util::HexStr(skBytes,32) << std::endl;

PrivateKey k = PrivateKey::FromBytes(Bytes(skBytes, 32));

Util::SecFree(skBn);
Expand Down
2 changes: 0 additions & 2 deletions src/test-bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "bls.hpp"
#include "test-utils.hpp"

using std::cout;
using std::endl;
using std::string;
using std::vector;

Expand Down
2 changes: 0 additions & 2 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

#include "bls.hpp"
#include "test-utils.hpp"
using std::cout;
using std::endl;
using std::string;
using std::vector;

Expand Down
42 changes: 20 additions & 22 deletions src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,28 @@ static void md_hmac(uint8_t *mac, const uint8_t *in, int in_len, const uint8_t *
#define RLC_MD_LEN 32
uint8_t opad[block_size + RLC_MD_LEN];
uint8_t *ipad = (uint8_t *)malloc(block_size + in_len);
uint8_t _key[block_size];
uint8_t _key[block_size];

/* if (ipad == NULL) {
RLC_THROW(ERR_NO_MEMORY);
return;
if (ipad == NULL)
throw std::runtime_error("out of memory");

if (key_len > block_size) {
Hash256(_key, key, key_len);
key = _key;
key_len = RLC_MD_LEN;
}
*/
if (key_len > block_size) {
Hash256(_key, key, key_len);
key = _key;
key_len = RLC_MD_LEN;
}
if (key_len <= block_size) {
memcpy(_key, key, key_len);
memset(_key + key_len, 0, block_size - key_len);
key = _key;
}
for (int i = 0; i < block_size; i++) {
opad[i] = 0x5C ^ key[i];
ipad[i] = 0x36 ^ key[i];
}
memcpy(ipad + block_size, in, in_len);
Hash256(opad + block_size, ipad, block_size + in_len);
Hash256(mac, opad, block_size + RLC_MD_LEN);

memcpy(_key, key, key_len);
memset(_key + key_len, 0, block_size - key_len);
key = _key;

for (int i = 0; i < block_size; i++) {
opad[i] = 0x5C ^ key[i];
ipad[i] = 0x36 ^ key[i];
}
memcpy(ipad + block_size, in, in_len);
Hash256(opad + block_size, ipad, block_size + in_len);
Hash256(mac, opad, block_size + RLC_MD_LEN);

free(ipad);
}
Expand Down

0 comments on commit 2b6e809

Please sign in to comment.