Skip to content

Commit

Permalink
Merge pull request #407 from ckormanyos/coverity_scan
Browse files Browse the repository at this point in the history
Fix #408 vie coverity scan defect reduction
  • Loading branch information
ckormanyos authored Jan 27, 2024
2 parents 694a005 + d625895 commit 91f955b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
19 changes: 11 additions & 8 deletions examples/example012_rsa_crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ namespace local_rsa
return b;
}

local_integer_type tmp_x;
local_integer_type tmp_y;
local_integer_type tmp_x { };
local_integer_type tmp_y { };

local_integer_type gcd_ext = extended_euclidean(b % a, a, &tmp_x, &tmp_y);

*x = tmp_y - ((b / a) * tmp_x);
*y = tmp_x;
*x = std::move(tmp_y - ((b / a) * tmp_x));
*y = std::move(tmp_x);

return gcd_ext;
}
Expand Down Expand Up @@ -250,17 +250,20 @@ namespace local_rsa

auto calculate_private_key() -> void
{
my_uintwide_t a = phi_of_m;
my_uintwide_t b = my_r;
my_uintwide_t a { phi_of_m };
my_uintwide_t b { my_r };

my_uintwide_t x { };
my_uintwide_t s { };

euclidean::extended_euclidean(a, b, &x, &s);

s = is_neg(s) ? make_positive(s, phi_of_m) : s;
if(is_neg(s))
{
s = std::move(make_positive(s, phi_of_m));
}

private_key = private_key_type { s, my_p, my_q };
private_key = std::move( private_key_type { std::move(s), my_p, my_q } );
}

private:
Expand Down
13 changes: 8 additions & 5 deletions examples/example013_ecdsa_sign_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,15 @@ namespace example013_ecdsa

while((r == 0) || (s == 0)) // NOLINT(altera-id-dependent-backward-branch)
{
const uint_type
uk
{
(p_uint_seed == nullptr) ? std::move(get_pseudo_random_uint<uint_type>()) : *p_uint_seed
};

// TBD: Be sure to limit to random.randrange(1, curve.n).
const auto k =
double_sint_type
(
(p_uint_seed == nullptr) ? static_cast<double_sint_type>(get_pseudo_random_uint<uint_type>()) : static_cast<double_sint_type>(*p_uint_seed)
);

const double_sint_type k { std::move(static_cast<double_sint_type>(uk)) };

const auto pt = scalar_mult(k, { curve_gx(), curve_gy() } );

Expand Down
10 changes: 6 additions & 4 deletions examples/example014_pi_spigot_wide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ namespace example014_pi_spigot
- i
);

const auto di =
((j == static_cast<std::uint32_t>(UINT8_C(0)))
? static_cast<unsigned_large_type>(d_init())
: static_cast<unsigned_large_type>(my_pi_in[my_index]));
unsigned_large_type di { my_pi_in[my_index] };

if(j == static_cast<std::uint32_t>(UINT8_C(0)))
{
di = std::move(static_cast<unsigned_large_type>(d_init()));
}

val_d += (di * local_pow10);

Expand Down
2 changes: 1 addition & 1 deletion math/wide_integer/uintwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -6583,7 +6583,7 @@
}
else // NOLINT(llvm-else-after-return,readability-else-after-return)
{
ArithmeticType val_unsigned(val);
ArithmeticType val_unsigned = std::move(val);

val_unsigned.negate();

Expand Down

0 comments on commit 91f955b

Please sign in to comment.