2018-01-14 17:17:34 +11:00
|
|
|
/*
|
2018-08-04 15:18:16 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-01-14 17:17:34 +11:00
|
|
|
*
|
2018-12-02 13:45:26 +11:00
|
|
|
* Copyright 2015-2018 Danny Robson <danny@nerdcruft.net>
|
2018-01-14 17:17:34 +11:00
|
|
|
*/
|
|
|
|
|
2018-12-02 13:45:26 +11:00
|
|
|
#pragma once
|
2018-01-14 17:17:34 +11:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
|
2018-12-02 13:45:26 +11:00
|
|
|
#include <cruft/util/std.hpp>
|
|
|
|
#include <cruft/util/view.hpp>
|
|
|
|
|
|
|
|
|
2018-01-14 17:17:34 +11:00
|
|
|
namespace cruft::crypto::block {
|
2018-12-02 13:45:26 +11:00
|
|
|
/// An implementation of the "eXtended TEA" block cipher.
|
|
|
|
///
|
|
|
|
/// ref: http://en.wikipedia.org/wiki/XTEA
|
2018-01-14 17:17:34 +11:00
|
|
|
class XTEA {
|
|
|
|
public:
|
2018-12-02 13:45:26 +11:00
|
|
|
using key_t = std::array<u32,4>;
|
|
|
|
using word_t = u32;
|
2018-01-14 17:17:34 +11:00
|
|
|
|
|
|
|
explicit XTEA (key_t);
|
|
|
|
|
2018-12-02 13:45:26 +11:00
|
|
|
void encrypt (cruft::view<word_t*> data);
|
|
|
|
void decrypt (cruft::view<word_t*> data);
|
2018-01-14 17:17:34 +11:00
|
|
|
|
|
|
|
private:
|
|
|
|
key_t m_key;
|
|
|
|
};
|
|
|
|
}
|