Skip to content

Commit

Permalink
Basic Aria test added #26
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaskov committed Jun 24, 2020
1 parent 913cc72 commit 4879a35
Showing 1 changed file with 12 additions and 44 deletions.
56 changes: 12 additions & 44 deletions test/aria.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
// Copyright (c) 2020 Nikita Kaskov <nbering@nil.foundation>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE aria_cipher_test
#define BOOST_TEST_MODULE noekeon_cipher_test

#include <iostream>
#include <unordered_map>
Expand All @@ -20,53 +21,20 @@

#include <nil/crypto3/block/aria.hpp>

using namespace nil::crypto3::block;
using namespace nil::crypto3;

namespace boost {
namespace test_tools {
namespace tt_detail {
template<template<typename, typename> class P, typename K, typename V>
struct print_log_value<P<K, V>> {
void operator()(std::ostream&, P<K, V> const&) {
}
};
} // namespace tt_detail
} // namespace test_tools
} // namespace boost
BOOST_AUTO_TEST_SUITE(aria_test_suite)

static const std::unordered_map<std::string, std::vector<std::uint8_t>> valid_data = {
{"Zg==", {0x66}},
{"Zm8=", {0x66, 0x6F}},
{"Zm9v", {0x66, 0x6F, 0x6F}},
{"aGVsbG8gd29ybGQ=", {0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64}},
{"aGVsbG8gd29ybGQh", {0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21}},
{"SGVsbG8sIHdvcmxkLg==", {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x2E}},
{"VGhlIDEyIGNoYXJz", {0x54, 0x68, 0x65, 0x20, 0x31, 0x32, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73}},
{"VGhlIDEzIGNoYXJzLg==", {0x54, 0x68, 0x65, 0x20, 0x31, 0x33, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73, 0x2E}},
{"VGhlIDE0IGNoYXJzLi4=", {0x54, 0x68, 0x65, 0x20, 0x31, 0x34, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73, 0x2E, 0x2E}},
{"VGhlIDE1IGNoYXJzLi4u",
{0x54, 0x68, 0x65, 0x20, 0x31, 0x35, 0x20, 0x63, 0x68, 0x61, 0x72, 0x73, 0x2E, 0x2E, 0x2E}},
{"QW4gVVRGLTggdXVtbDogw7w=",
{0x41, 0x6E, 0x20, 0x55, 0x54, 0x46, 0x2D, 0x38, 0x20, 0x75, 0x75, 0x6D, 0x6C, 0x3A, 0x20, 0xC3, 0xBC}},
{"V2VpcmQgR2VybWFuIDIgYnl0ZSB0aGluZzogw58u",
{0x57, 0x65, 0x69, 0x72, 0x64, 0x20, 0x47, 0x65, 0x72, 0x6D, 0x61, 0x6E, 0x20, 0x32, 0x20,
0x62, 0x79, 0x74, 0x65, 0x20, 0x74, 0x68, 0x69, 0x6E, 0x67, 0x3A, 0x20, 0xC3, 0x9F, 0x2E}},
{"mw==", {0x9B}},
{"HGA=", {0x1C, 0x60}},
{"gTS9", {0x81, 0x34, 0xBD}},
{"Xmz/3g==", {0x5E, 0x6C, 0xFF, 0xDE}},
{"ss3w3H8=", {0xb2, 0xcd, 0xf0, 0xdc, 0x7f}},
{"/FYt2tQO", {0xfc, 0x56, 0x2d, 0xda, 0xd4, 0x0e}},
{"KbIyLohB6A==", {0x29, 0xb2, 0x32, 0x2e, 0x88, 0x41, 0xe8}},
{"Dw/O2Ul6r5I=", {0x0f, 0x0f, 0xce, 0xd9, 0x49, 0x7a, 0xaf, 0x92}},
{"Jw+xiYKADaZA", {0x27, 0x0f, 0xb1, 0x89, 0x82, 0x80, 0x0d, 0xa6, 0x40}}};
BOOST_AUTO_TEST_CASE(aria_1) {

static const std::vector<std::string> invalid_data = {"ZOOL!isnotvalidbase64", "Neitheris:this?"};
std::vector<char> input = {'\x00', '\x11', '\x22', '\x33', '\x44', '\x55', '\x66', '\x77',
'\x88', '\x99', '\xaa', '\xbb', '\xcc', '\xdd', '\xee', '\xff'};
std::vector<char> key = {'\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
'\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f'};

BOOST_AUTO_TEST_SUITE(aria_test_suite)
std::string out = encrypt<block::aria<128>>(input, key);

BOOST_DATA_TEST_CASE(aria_single_range_encrypt,
boost::unit_test::data::random(0, 16) ^ boost::unit_test::data::xrange(7), random_sample, index) {
BOOST_CHECK_EQUAL(out, "d718fbd6ab644c739da95f3be6451778");
}

BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 4879a35

Please sign in to comment.