mirror of https://github.com/aria2/aria2
commit
1be304e90e
|
@ -6,12 +6,12 @@ jobs:
|
||||||
build:
|
build:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-22.04, macos-11]
|
os: [ubuntu-22.04, macos-14]
|
||||||
compiler: [gcc, clang]
|
compiler: [gcc, clang]
|
||||||
crypto: [openssl, gnutls]
|
crypto: [openssl, gnutls]
|
||||||
bittorrent: [with-bt, without-bt]
|
bittorrent: [with-bt, without-bt]
|
||||||
exclude:
|
exclude:
|
||||||
- os: macos-11
|
- os: macos-14
|
||||||
crypto: gnutls
|
crypto: gnutls
|
||||||
- crypto: openssl
|
- crypto: openssl
|
||||||
bittorrent: without-bt
|
bittorrent: without-bt
|
||||||
|
|
|
@ -55,7 +55,7 @@ void DHKeyExchange::init(const unsigned char* prime, size_t primeBits,
|
||||||
if (pr.empty()) {
|
if (pr.empty()) {
|
||||||
throw DL_ABORT_EX("No valid prime supplied");
|
throw DL_ABORT_EX("No valid prime supplied");
|
||||||
}
|
}
|
||||||
prime_ = n(pr.c_str(), pr.length());
|
prime_ = n(reinterpret_cast<const unsigned char*>(pr.c_str()), pr.length());
|
||||||
|
|
||||||
std::string gen = reinterpret_cast<const char*>(generator);
|
std::string gen = reinterpret_cast<const char*>(generator);
|
||||||
if (gen.length() % 2) {
|
if (gen.length() % 2) {
|
||||||
|
@ -65,12 +65,13 @@ void DHKeyExchange::init(const unsigned char* prime, size_t primeBits,
|
||||||
if (gen.empty()) {
|
if (gen.empty()) {
|
||||||
throw DL_ABORT_EX("No valid generator supplied");
|
throw DL_ABORT_EX("No valid generator supplied");
|
||||||
}
|
}
|
||||||
generator_ = n(gen.c_str(), gen.length());
|
generator_ =
|
||||||
|
n(reinterpret_cast<const unsigned char*>(gen.c_str()), gen.length());
|
||||||
|
|
||||||
size_t pbytes = (privateKeyBits + 7) / 8;
|
size_t pbytes = (privateKeyBits + 7) / 8;
|
||||||
unsigned char buf[pbytes];
|
unsigned char buf[pbytes];
|
||||||
util::generateRandomData(buf, pbytes);
|
util::generateRandomData(buf, pbytes);
|
||||||
privateKey_ = n(reinterpret_cast<char*>(buf), pbytes);
|
privateKey_ = n(buf, pbytes);
|
||||||
|
|
||||||
keyLength_ = (primeBits + 7) / 8;
|
keyLength_ = (primeBits + 7) / 8;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +89,7 @@ size_t DHKeyExchange::getPublicKey(unsigned char* out, size_t outLength) const
|
||||||
static_cast<unsigned long>(keyLength_),
|
static_cast<unsigned long>(keyLength_),
|
||||||
static_cast<unsigned long>(outLength)));
|
static_cast<unsigned long>(outLength)));
|
||||||
}
|
}
|
||||||
publicKey_.binary(reinterpret_cast<char*>(out), outLength);
|
publicKey_.binary(out, outLength);
|
||||||
return keyLength_;
|
return keyLength_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,10 +115,9 @@ size_t DHKeyExchange::computeSecret(unsigned char* out, size_t outLength,
|
||||||
static_cast<unsigned long>(peerPublicKeyLength)));
|
static_cast<unsigned long>(peerPublicKeyLength)));
|
||||||
}
|
}
|
||||||
|
|
||||||
n peerKey(reinterpret_cast<const char*>(peerPublicKeyData),
|
n peerKey(peerPublicKeyData, peerPublicKeyLength);
|
||||||
peerPublicKeyLength);
|
|
||||||
n secret = peerKey.mul_mod(privateKey_, prime_);
|
n secret = peerKey.mul_mod(privateKey_, prime_);
|
||||||
secret.binary(reinterpret_cast<char*>(out), outLength);
|
secret.binary(out, outLength);
|
||||||
|
|
||||||
return outLength;
|
return outLength;
|
||||||
}
|
}
|
||||||
|
|
40
src/bignum.h
40
src/bignum.h
|
@ -30,20 +30,20 @@ public:
|
||||||
typedef std::make_unsigned<char_t>::type uchar_t;
|
typedef std::make_unsigned<char_t>::type uchar_t;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<char_t[]> buf_;
|
std::unique_ptr<uchar_t[]> buf_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline ulong() : buf_(aria2::make_unique<char_t[]>(dim)) {}
|
inline ulong() : buf_(aria2::make_unique<uchar_t[]>(dim)) {}
|
||||||
inline ulong(size_t t) : buf_(aria2::make_unique<char_t[]>(dim))
|
inline ulong(size_t t) : buf_(aria2::make_unique<uchar_t[]>(dim))
|
||||||
{
|
{
|
||||||
memcpy(buf_.get(), (char_t*)&t, sizeof(t));
|
memcpy(buf_.get(), (uchar_t*)&t, sizeof(t));
|
||||||
}
|
}
|
||||||
inline ulong(const ulong<dim>& rhs) : buf_(aria2::make_unique<char_t[]>(dim))
|
inline ulong(const ulong<dim>& rhs) : buf_(aria2::make_unique<uchar_t[]>(dim))
|
||||||
{
|
{
|
||||||
memcpy(buf_.get(), rhs.buf_.get(), dim);
|
memcpy(buf_.get(), rhs.buf_.get(), dim);
|
||||||
}
|
}
|
||||||
explicit inline ulong(const char_t* data, size_t size)
|
explicit inline ulong(const uchar_t* data, size_t size)
|
||||||
: buf_(aria2::make_unique<char_t[]>(dim))
|
: buf_(aria2::make_unique<uchar_t[]>(dim))
|
||||||
{
|
{
|
||||||
if (size > dim) {
|
if (size > dim) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
|
@ -73,8 +73,8 @@ public:
|
||||||
const auto b2 = rhs.buf_.get();
|
const auto b2 = rhs.buf_.get();
|
||||||
for (ssize_t i = dim - 1; i >= 0; --i) {
|
for (ssize_t i = dim - 1; i >= 0; --i) {
|
||||||
for (ssize_t j = 1; j >= 0; --j) {
|
for (ssize_t j = 1; j >= 0; --j) {
|
||||||
char_t t = ((uchar_t)(b1[i] << 4 * (1 - j))) >> 4;
|
uchar_t t = ((uchar_t)(b1[i] << 4 * (1 - j))) >> 4;
|
||||||
char_t r = ((uchar_t)(b2[i] << 4 * (1 - j))) >> 4;
|
uchar_t r = ((uchar_t)(b2[i] << 4 * (1 - j))) >> 4;
|
||||||
if (t != r) {
|
if (t != r) {
|
||||||
return t > r;
|
return t > r;
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@ public:
|
||||||
bool base = false;
|
bool base = false;
|
||||||
for (size_t i = 0; i < dim; ++i) {
|
for (size_t i = 0; i < dim; ++i) {
|
||||||
for (ssize_t j = 0; j < 2; ++j) {
|
for (ssize_t j = 0; j < 2; ++j) {
|
||||||
char_t t = ((uchar_t)(b1[i] << 4 * (1 - j))) >> 4;
|
uchar_t t = ((uchar_t)(b1[i] << 4 * (1 - j))) >> 4;
|
||||||
char_t r = ((uchar_t)(b2[i] << 4 * (1 - j))) >> 4;
|
uchar_t r = ((uchar_t)(b2[i] << 4 * (1 - j))) >> 4;
|
||||||
if (base) {
|
if (base) {
|
||||||
t++;
|
t++;
|
||||||
}
|
}
|
||||||
|
@ -144,8 +144,8 @@ public:
|
||||||
bool base = false;
|
bool base = false;
|
||||||
for (size_t i = 0; i < dim; ++i) {
|
for (size_t i = 0; i < dim; ++i) {
|
||||||
for (ssize_t j = 0; j < 2; ++j) {
|
for (ssize_t j = 0; j < 2; ++j) {
|
||||||
char_t t = ((uchar_t)(b1[i] << 4 * (1 - j))) >> 4;
|
uchar_t t = ((uchar_t)(b1[i] << 4 * (1 - j))) >> 4;
|
||||||
char_t r = ((uchar_t)(b2[i] << 4 * (1 - j))) >> 4;
|
uchar_t r = ((uchar_t)(b2[i] << 4 * (1 - j))) >> 4;
|
||||||
if (base) {
|
if (base) {
|
||||||
t--;
|
t--;
|
||||||
}
|
}
|
||||||
|
@ -238,14 +238,14 @@ public:
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<char_t[]> binary() const
|
std::unique_ptr<uchar_t[]> binary() const
|
||||||
{
|
{
|
||||||
ulong<dim> c = *this;
|
ulong<dim> c = *this;
|
||||||
std::unique_ptr<char_t[]> rv;
|
std::unique_ptr<uchar_t[]> rv;
|
||||||
rv.swap(c.buf_);
|
rv.swap(c.buf_);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
void binary(char_t* buf, size_t len) const
|
void binary(uchar_t* buf, size_t len) const
|
||||||
{
|
{
|
||||||
memcpy(buf, buf_.get(), std::min(dim, len));
|
memcpy(buf, buf_.get(), std::min(dim, len));
|
||||||
}
|
}
|
||||||
|
@ -258,8 +258,8 @@ private:
|
||||||
size_t rv = dim * 2;
|
size_t rv = dim * 2;
|
||||||
const auto b = buf_.get();
|
const auto b = buf_.get();
|
||||||
for (ssize_t i = dim - 1; i >= 0; --i) {
|
for (ssize_t i = dim - 1; i >= 0; --i) {
|
||||||
char_t f = b[i] >> 4;
|
uchar_t f = b[i] >> 4;
|
||||||
char_t s = (b[i] << 4) >> 4;
|
uchar_t s = (b[i] << 4) >> 4;
|
||||||
if (!f && !s) {
|
if (!f && !s) {
|
||||||
rv -= 2;
|
rv -= 2;
|
||||||
continue;
|
continue;
|
||||||
|
@ -282,8 +282,8 @@ private:
|
||||||
const size_t d2 = digits / 2;
|
const size_t d2 = digits / 2;
|
||||||
for (size_t i = d2; i < dim; ++i) {
|
for (size_t i = d2; i < dim; ++i) {
|
||||||
for (size_t j = 0; j < 2; ++j) {
|
for (size_t j = 0; j < 2; ++j) {
|
||||||
char_t c = ((uchar_t)(bt[(dim - 1) - i] << 4 * (1 - j))) >> 4;
|
uchar_t c = ((uchar_t)(bt[(dim - 1) - i] << 4 * (1 - j))) >> 4;
|
||||||
char_t r = c << (npar * (1 - j) * 4 + (1 - npar) * j * 4);
|
uchar_t r = c << (npar * (1 - j) * 4 + (1 - npar) * j * 4);
|
||||||
ssize_t idx = i - d2 - npar * j;
|
ssize_t idx = i - d2 - npar * j;
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
b[(dim - 1) - idx] += r;
|
b[(dim - 1) - idx] += r;
|
||||||
|
|
Loading…
Reference in New Issue