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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, macos-latest]
os: [ubuntu-22.04, ubuntu-latest, macos-latest]

steps:
- name: checkout
Expand All @@ -36,7 +36,7 @@ jobs:
run: ctest --output-on-failure

cppcheck:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
Expand Down
19 changes: 11 additions & 8 deletions src/lib/mcleece/cbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "serialize/format.h"
#include "util/byte_view.h"

#include "sodium/crypto_box.h"
#include "sodium/crypto_generichash.h"
#include <string>
#include <vector>

Expand All @@ -31,10 +31,15 @@ namespace cbox {
return 0;
}

inline void mix_buf(unsigned char* out, const unsigned char* in, unsigned n)
inline void mix_buf(unsigned char* out, const unsigned char* in, unsigned n, const unsigned char* key, unsigned keylen)
{
for (unsigned i = 0; i < n; ++i)
out[i] ^= in[i];
// out = hmac(out + in)
// hmac key is our nonce
crypto_generichash_state hashState;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a small change, too 馃珷

crypto_generichash_init(&hashState, key, keylen, n);
crypto_generichash_update(&hashState, out, n);
crypto_generichash_update(&hashState, in, n);
crypto_generichash_final(&hashState, out, n);
}

inline bool mcleece_seal_mix(mcleece::byte_view& out, unsigned char* key, const unsigned char* nonce, const mcleece::public_key_simple& pubk)
Expand All @@ -45,8 +50,7 @@ namespace cbox {
out.write(session.encrypted_key().data(), session.encrypted_key().size());

// then mix key and session
// currently: xor
mix_buf(key, session.key().data(), session.key().size());
mix_buf(key, session.key().data(), session.key().size(), nonce, crypto_box_NONCEBYTES);

return true;
}
Expand All @@ -62,8 +66,7 @@ namespace cbox {
in.advance(mcleece::session_key::size());

// then mix key and session
// currently: xor
mix_buf(key, session.key().data(), session.key().size());
mix_buf(key, session.key().data(), session.key().size(), nonce, crypto_box_NONCEBYTES);

return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/lib/util/MakeTempDirectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

#include <cstdio>
#include <experimental/filesystem>
#include <filesystem>
#include <string>

class MakeTempDirectory
Expand All @@ -12,24 +12,24 @@ class MakeTempDirectory
: _cleanup(cleanup)
{
_path = std::tmpnam(nullptr);
std::experimental::filesystem::create_directory(_path);
std::filesystem::create_directory(_path);
}

~MakeTempDirectory()
{
if (_cleanup)
{
std::error_code ec;
std::experimental::filesystem::remove_all(_path, ec);
std::filesystem::remove_all(_path, ec);
}
}

std::experimental::filesystem::path path() const
std::filesystem::path path() const
{
return _path;
}

protected:
bool _cleanup;
std::experimental::filesystem::path _path;
std::filesystem::path _path;
};
12 changes: 6 additions & 6 deletions test/TestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#include "mcleece/actions.h"
#include "serialize/format.h"
#include "util/File.h"
#include <experimental/filesystem>
#include <filesystem>
#include <string>

namespace TestHelpers
{
inline void generate_keypair(std::experimental::filesystem::path target_prefix, int mode=mcleece::SIMPLE)
inline void generate_keypair(std::filesystem::path target_prefix, int mode=mcleece::SIMPLE)
{
std::string basename = std::experimental::filesystem::path(target_prefix).filename();
std::string path = std::experimental::filesystem::temp_directory_path() / basename;
std::string basename = std::filesystem::path(target_prefix).filename();
std::string path = std::filesystem::temp_directory_path() / basename;
std::string pk = fmt::format("{}.pk", path);
std::string sk = fmt::format("{}.sk", path);
if (!File(pk).good() or !File(sk).good())
mcleece::actions::keypair_to_file(path, "password", mode);

std::experimental::filesystem::copy(pk, target_prefix.replace_extension(".pk"));
std::experimental::filesystem::copy(sk, target_prefix.replace_extension(".sk"));
std::filesystem::copy(pk, target_prefix.replace_extension(".pk"));
std::filesystem::copy(sk, target_prefix.replace_extension(".sk"));
}
}

Loading