Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "attribute.h"
#include "utils.h"
#include "error.h"
#include <openssl/md5.h>
#include <openssl/evp.h>
#include <algorithm>
#include <iostream>

Expand Down Expand Up @@ -140,8 +140,10 @@ Encrypted::Encrypted(uint8_t type, const uint8_t* data, size_t size, const std::
for (size_t i = 0; i < size / 16; ++i)
{
std::array<uint8_t, 16> md;
unsigned mdSize = md.size();

EVP_Digest(mdBuffer.data(), mdBuffer.size(), md.data(), &mdSize, EVP_md5(), nullptr);

MD5(mdBuffer.data(), mdBuffer.size(), md.data());
for (size_t j = 0; j < 16; ++j)
plaintext[i * 16 + j] = data[i * 16 + j] ^ md[j];

Expand Down Expand Up @@ -181,7 +183,9 @@ std::vector<uint8_t> Encrypted::toVector(const std::string& secret, const std::a
for (size_t i = 0; i < plaintext.length() / 16; ++i)
{
std::array<uint8_t, 16> md;
MD5(mdBuffer.data(), mdBuffer.size(), md.data());
unsigned mdSize = md.size();

EVP_Digest(mdBuffer.data(), mdBuffer.size(), md.data(), &mdSize, EVP_md5(), nullptr);

for (size_t j = 0; j < md.size(); ++j)
*it++ = plaintext[i * 16 + j] ^ md[j];
Expand Down
6 changes: 4 additions & 2 deletions src/packet.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "packet.h"
#include "error.h"
#include "attribute_types.h"
#include <openssl/md5.h>
#include <openssl/evp.h>
#include <stdexcept>

using Packet = RadProto::Packet;
Expand Down Expand Up @@ -132,7 +132,9 @@ const std::vector<uint8_t> Packet::makeSendBuffer(const std::string& secret) con
sendBuffer[i + sendBuffer.size() - secret.length()] = secret[i];

std::array<uint8_t, 16> md;
MD5(sendBuffer.data(), sendBuffer.size(), md.data());
unsigned mdSize = md.size();

EVP_Digest(sendBuffer.data(), sendBuffer.size(), md.data(), &mdSize, EVP_md5(), nullptr);

sendBuffer.resize(sendBuffer.size() - secret.length());

Expand Down
2 changes: 1 addition & 1 deletion tests/socket_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(TestAsyncSend)

boost::asio::io_context io_context;

boost::asio::ip::udp::endpoint destination(boost::asio::ip::address_v4::from_string("127.0.0.1"), 3000);
boost::asio::ip::udp::endpoint destination(boost::asio::ip::make_address_v4("127.0.0.1"), 3000);

RadProto::Socket s(io_context, "secret", 3000);

Expand Down
Loading