aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-11-08 10:37:23 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2020-11-08 10:37:23 +0200
commit0551ad0ea4227a96c886fe073514f79eba6c4d35 (patch)
treeae85b934e66d9d8ebb772db8027d85ba6c07a7e5
parentInitial commit (diff)
downloadblowfish-0551ad0ea4227a96c886fe073514f79eba6c4d35.tar.xz
Replace P and S C-arrays with std::array
-rw-r--r--blowfish.hpp8
-rw-r--r--blowfish_init.hpp26
2 files changed, 14 insertions, 20 deletions
diff --git a/blowfish.hpp b/blowfish.hpp
index e0468cd..9a6e0fe 100644
--- a/blowfish.hpp
+++ b/blowfish.hpp
@@ -23,9 +23,7 @@ public:
constexpr Blowfish(const uint8_t key[], size_t keylen) {
for (size_t i = 0; i < BOXES; ++i) {
- for (size_t j = 0; j < ENTRIES; ++j) {
- S[i][j] = S_INIT[i][j];
- }
+ std::copy(S_INIT[i].begin(), S_INIT[i].end(), S[i].begin());
}
//
@@ -98,6 +96,6 @@ private:
return y;
}
- uint32_t P[SUBKEYS];
- uint32_t S[BOXES][ENTRIES];
+ std::array<uint32_t, SUBKEYS> P;
+ std::array<std::array<uint32_t, ENTRIES>, BOXES> S;
};
diff --git a/blowfish_init.hpp b/blowfish_init.hpp
index 3dee01a..9d2366d 100644
--- a/blowfish_init.hpp
+++ b/blowfish_init.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include <array>
#include <cstddef>
#include <cstdint>
@@ -7,14 +8,14 @@ constexpr size_t SUBKEYS = ROUNDS + 2;
constexpr size_t BOXES = 4;
constexpr size_t ENTRIES = 256;
-constexpr uint32_t P_INIT[SUBKEYS]{
+constexpr std::array<uint32_t, SUBKEYS> P_INIT{
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,
0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b,
};
-constexpr uint32_t S_INIT[BOXES][ENTRIES]{
- {
+constexpr std::array<std::array<uint32_t, ENTRIES>, BOXES> S_INIT{
+ std::array<uint32_t, ENTRIES>{
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96,
0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658,
@@ -57,9 +58,8 @@ constexpr uint32_t S_INIT[BOXES][ENTRIES]{
0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f,
0xf296ec6b, 0x2a0dd915, 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
- 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
- },
- {
+ 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a},
+ std::array<uint32_t, ENTRIES>{
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d,
0x9cee60b8, 0x8fedb266, 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, 0x3f54989a, 0x5b429d65,
@@ -102,9 +102,8 @@ constexpr uint32_t S_INIT[BOXES][ENTRIES]{
0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd,
0x675fda79, 0xe3674340, 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
- 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
- },
- {
+ 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7},
+ std::array<uint32_t, ENTRIES>{
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7,
0xbcf46b2e, 0xd4a20068, 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, 0x4d95fc1d, 0x96b591af,
@@ -147,9 +146,8 @@ constexpr uint32_t S_INIT[BOXES][ENTRIES]{
0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8,
0xa28514d9, 0x6c51133c, 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
- 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
- },
- {
+ 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0},
+ std::array<uint32_t, ENTRIES>{
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742,
0xd3822740, 0x99bc9bbe, 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, 0x5748ab2f, 0xbc946e79,
@@ -192,6 +190,4 @@ constexpr uint32_t S_INIT[BOXES][ENTRIES]{
0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c,
0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
- 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6,
- },
-};
+ 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6}};