-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add lightweight crypto implementation including tests (No round reduction) * Add round reduction to lightweight crypto implementation including tests for encrypt decrypt for round reduced functions Added method of view returning its copy in vector * Coding standard: change absolute paths, use #pragma once * Added exceptions for missing lightweight tests
- Loading branch information
Showing
65 changed files
with
9,967 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// Created by mhajas on 7/6/18. | ||
// | ||
|
||
#include "chaskey.h" | ||
#include <streams/block/ciphers/lightweight/common/cipher.h> | ||
|
||
namespace block { | ||
|
||
uint32_t chaskey::rol(uint32_t x, const uint8_t n) { | ||
return (x << n) | (x >> (32 - n)); | ||
} | ||
|
||
uint32_t chaskey::ror(uint32_t x, const uint8_t n) { | ||
return (x >> n) | (x << (32 - n)); | ||
} | ||
|
||
void chaskey::Encrypt(uint8_t *block) { | ||
uint32_t *v = (uint32_t *) block; | ||
uint32_t *k = (uint32_t *) _key; | ||
uint8_t i; | ||
|
||
/* Whitening */ | ||
v[0] ^= READ_ROUND_KEY_DOUBLE_WORD(k[0]); | ||
v[1] ^= READ_ROUND_KEY_DOUBLE_WORD(k[1]); | ||
v[2] ^= READ_ROUND_KEY_DOUBLE_WORD(k[2]); | ||
v[3] ^= READ_ROUND_KEY_DOUBLE_WORD(k[3]); | ||
|
||
/* Chaskey permutation*/ | ||
for (i = 0; i < _rounds; ++i) { | ||
v[0] += v[1]; | ||
v[1] = rol(v[1], 5); | ||
v[1] ^= v[0]; | ||
v[0] = rol(v[0], 16); | ||
v[2] += v[3]; | ||
v[3] = rol(v[3], 8); | ||
v[3] ^= v[2]; | ||
v[0] += v[3]; | ||
v[3] = rol(v[3], 13); | ||
v[3] ^= v[0]; | ||
v[2] += v[1]; | ||
v[1] = rol(v[1], 7); | ||
v[1] ^= v[2]; | ||
v[2] = rol(v[2], 16); | ||
} | ||
|
||
/* Whitening */ | ||
v[0] ^= READ_ROUND_KEY_DOUBLE_WORD(k[0]); | ||
v[1] ^= READ_ROUND_KEY_DOUBLE_WORD(k[1]); | ||
v[2] ^= READ_ROUND_KEY_DOUBLE_WORD(k[2]); | ||
v[3] ^= READ_ROUND_KEY_DOUBLE_WORD(k[3]); | ||
} | ||
|
||
void chaskey::Decrypt(uint8_t *block) { | ||
uint32_t *v = (uint32_t *) block; | ||
uint32_t *k = (uint32_t *) _key; | ||
uint8_t i; | ||
|
||
/* Whitening */ | ||
v[0] ^= READ_ROUND_KEY_DOUBLE_WORD(k[0]); | ||
v[1] ^= READ_ROUND_KEY_DOUBLE_WORD(k[1]); | ||
v[2] ^= READ_ROUND_KEY_DOUBLE_WORD(k[2]); | ||
v[3] ^= READ_ROUND_KEY_DOUBLE_WORD(k[3]); | ||
|
||
/* Chaskey permutation */ | ||
for (i = 0; i < _rounds; ++i) { | ||
v[2] = ror(v[2], 16); | ||
v[1] ^= v[2]; | ||
v[1] = ror(v[1], 7); | ||
v[2] -= v[1]; | ||
v[3] ^= v[0]; | ||
v[3] = ror(v[3], 13); | ||
v[0] -= v[3]; | ||
v[3] ^= v[2]; | ||
v[3] = ror(v[3], 8); | ||
v[2] -= v[3]; | ||
v[0] = ror(v[0], 16); | ||
v[1] ^= v[0]; | ||
v[1] = ror(v[1], 5); | ||
v[0] -= v[1]; | ||
} | ||
|
||
/* Whitening */ | ||
v[0] ^= READ_ROUND_KEY_DOUBLE_WORD(k[0]); | ||
v[1] ^= READ_ROUND_KEY_DOUBLE_WORD(k[1]); | ||
v[2] ^= READ_ROUND_KEY_DOUBLE_WORD(k[2]); | ||
v[3] ^= READ_ROUND_KEY_DOUBLE_WORD(k[3]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Created by mhajas on 7/6/18. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <streams/block/ciphers/lightweight/lightweight.h> | ||
#include "../../../block_cipher.h" | ||
|
||
|
||
#define CHASKEY_BLOCK_SIZE 16 | ||
#define CHASKEY_KEY_SIZE 16 | ||
#define CHASKEY_ROUND_KEYS_SIZE 16 | ||
#define CHASKEY_NUMBER_OF_ROUNDS 16 | ||
|
||
namespace block { | ||
|
||
class chaskey : public lightweight<CHASKEY_KEY_SIZE, CHASKEY_BLOCK_SIZE> { | ||
|
||
static inline uint32_t rol(uint32_t x, const uint8_t n); | ||
|
||
static inline uint32_t ror(uint32_t x, const uint8_t n); | ||
public: | ||
chaskey(size_t rounds) : lightweight(rounds) {}; | ||
|
||
void Encrypt(uint8_t *block) override; | ||
|
||
void Decrypt(uint8_t *block) override; | ||
}; | ||
|
||
} //namespace block | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* | ||
* University of Luxembourg | ||
* Laboratory of Algorithmics, Cryptology and Security (LACS) | ||
* | ||
* FELICS - Fair Evaluation of Lightweight Cryptographic Systems | ||
* | ||
* Copyright (C) 2015 University of Luxembourg | ||
* | ||
* Written in 2015 by Daniel Dinu <dumitru-daniel.dinu@uni.lu> and | ||
* Yann Le Corre <yann.lecorre@uni.lu> | ||
* | ||
* This file is part of FELICS. | ||
* | ||
* FELICS is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* FELICS is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
/* | ||
* | ||
* Optimization levels | ||
* ... OPTIMIZATION_LEVEL_0 - O0 | ||
* ... OPTIMIZATION_LEVEL_1 - O1 | ||
* ... OPTIMIZATION_LEVEL_2 - O2 | ||
* ... OPTIMIZATION_LEVEL_3 - O3 = defualt | ||
* | ||
*/ | ||
#define OPTIMIZATION_LEVEL_0 __attribute__((optimize("O0"))) | ||
#define OPTIMIZATION_LEVEL_1 __attribute__((optimize("O1"))) | ||
#define OPTIMIZATION_LEVEL_2 __attribute__((optimize("O2"))) | ||
#define OPTIMIZATION_LEVEL_3 __attribute__((optimize("O3"))) | ||
|
||
|
||
/* | ||
* | ||
* SCENARIO values: | ||
* ... SCENARIO_0 0 - cipher operation: encrypt & decrypt one data block | ||
* ... SCENARIO_1 1 - scenario 1: encrypt & decrypt data in CBC mode | ||
* ... SCENARIO_2 2 - scenario 2: encrypt & decrypt data in CTR mode | ||
* | ||
*/ | ||
#define SCENARIO_0 0 | ||
#define SCENARIO_1 1 | ||
#define SCENARIO_2 2 | ||
|
||
#ifndef SCENARIO | ||
#define SCENARIO SCENARIO_0 | ||
#endif | ||
|
||
|
||
/* | ||
* | ||
* MEASURE_CYCLE_COUNT values: | ||
* ... MEASURE_CYCLE_COUNT_DISABLED 0 - measure cycle count is disabled | ||
* ... MEASURE_CYCLE_COUNT_ENABLED 1 - measure cycle count is enabled | ||
* | ||
*/ | ||
#define MEASURE_CYCLE_COUNT_DISABLED 0 | ||
#define MEASURE_CYCLE_COUNT_ENABLED 1 | ||
|
||
#ifndef MEASURE_CYCLE_COUNT | ||
#define MEASURE_CYCLE_COUNT MEASURE_CYCLE_COUNT_DISABLED | ||
#endif | ||
|
||
|
||
/* | ||
* | ||
* Align memory boundaries in bytes | ||
* | ||
*/ | ||
#define ALIGN_PC_BOUNDRY 64 | ||
#define ALIGN_AVR_BOUNDRY 2 | ||
#define ALIGN_MSP_BOUNDRY 2 | ||
#define ALIGN_ARM_BOUNDRY 8 | ||
|
||
#define ALIGNED __attribute__ ((aligned(ALIGN_PC_BOUNDRY))) | ||
|
||
/* | ||
* | ||
* RAM data types | ||
* | ||
*/ | ||
#define RAM_DATA_BYTE uint8_t ALIGNED | ||
#define RAM_DATA_WORD uint16_t ALIGNED | ||
#define RAM_DATA_DOUBLE_WORD uint32_t ALIGNED | ||
|
||
#define READ_RAM_DATA_BYTE(x) x | ||
#define READ_RAM_DATA_WORD(x) x | ||
#define READ_RAM_DATA_DOUBLE_WORD(x) x | ||
|
||
|
||
/* | ||
* | ||
* Flash/ROM data types | ||
* | ||
*/ | ||
|
||
#define ROM_DATA_BYTE const uint8_t ALIGNED | ||
#define ROM_DATA_WORD const uint16_t ALIGNED | ||
#define ROM_DATA_DOUBLE_WORD const uint32_t ALIGNED | ||
|
||
#define READ_ROM_DATA_BYTE(x) x | ||
#define READ_ROM_DATA_WORD(x) x | ||
#define READ_ROM_DATA_DOUBLE_WORD(x) x | ||
|
||
#define READ_ROUND_KEY_BYTE(x) READ_RAM_DATA_BYTE(x) | ||
#define READ_ROUND_KEY_WORD(x) READ_RAM_DATA_WORD(x) | ||
#define READ_ROUND_KEY_DOUBLE_WORD(x) READ_RAM_DATA_DOUBLE_WORD(x) | ||
|
Oops, something went wrong.