react-native-fs-turbo 0.3.7 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +119 -27
  2. package/RNFSTurbo.podspec +2 -2
  3. package/android/CMakeLists.txt +62 -9
  4. package/android/build.gradle +80 -3
  5. package/android/gradle.properties +5 -5
  6. package/android/src/main/codegen/RNFSTurboSpec.java +17 -0
  7. package/android/src/main/cpp/JNIOnLoad.cpp +18 -0
  8. package/android/src/main/cpp/RNFSTurboLogger.cpp +4 -0
  9. package/android/src/main/cpp/RNFSTurboModule.cpp +44 -0
  10. package/android/src/main/cpp/RNFSTurboModule.h +40 -0
  11. package/android/src/main/cpp/RNFSTurboPlatformHelper.cpp +5 -1
  12. package/android/src/main/java/com/cmpayc/rnfsturbo/JNIOnLoad.java +27 -0
  13. package/android/src/main/java/com/cmpayc/rnfsturbo/{RNFSTurboPlatformContextModule.java → RNFSTurboModule.java} +62 -11
  14. package/android/src/main/java/com/cmpayc/rnfsturbo/RNFSTurboPackage.java +11 -9
  15. package/cpp/RNFSTurboHostObject.cpp +138 -15
  16. package/cpp/RNFSTurboHostObject.h +12 -4
  17. package/cpp/RNFSTurboInstall.cpp +27 -0
  18. package/cpp/RNFSTurboInstall.h +20 -0
  19. package/cpp/RNFSTurboLogger.h +4 -0
  20. package/cpp/RNFSTurboPlatformHelper.h +4 -0
  21. package/cpp/algorithms/Krypt/AES.cpp +502 -0
  22. package/cpp/algorithms/Krypt/AES.hpp +150 -0
  23. package/cpp/algorithms/Krypt/aes-config.hpp +71 -0
  24. package/cpp/algorithms/Krypt/blockcipher.hpp +69 -0
  25. package/cpp/algorithms/Krypt/bytearray.cpp +158 -0
  26. package/cpp/algorithms/Krypt/bytearray.hpp +80 -0
  27. package/cpp/algorithms/Krypt/functions.cpp +137 -0
  28. package/cpp/algorithms/Krypt/functions.hpp +54 -0
  29. package/cpp/algorithms/Krypt/mode.cpp +203 -0
  30. package/cpp/algorithms/Krypt/mode.hpp +131 -0
  31. package/cpp/algorithms/Krypt/padding.cpp +219 -0
  32. package/cpp/algorithms/Krypt/padding.hpp +148 -0
  33. package/cpp/algorithms/Krypt/types.hpp +208 -0
  34. package/cpp/encryption/encryption-utils.cpp +162 -0
  35. package/cpp/encryption/encryption-utils.h +43 -0
  36. package/cpp/filesystem/{helpers.cpp → filesystem-utils.cpp} +5 -1
  37. package/cpp/filesystem/{helpers.h → filesystem-utils.h} +4 -0
  38. package/ios/RNFSTurboLogger.mm +4 -0
  39. package/ios/{RNFSTurboPlatformContextModule.h → RNFSTurboModule.h} +3 -3
  40. package/ios/{RNFSTurboPlatformContextModule.mm → RNFSTurboModule.mm} +22 -5
  41. package/ios/RNFSTurboPlatformHelper.mm +4 -0
  42. package/lib/commonjs/NativeRNFSTurboModule.js +14 -16
  43. package/lib/commonjs/NativeRNFSTurboModule.js.map +1 -1
  44. package/lib/commonjs/createRNFSTurbo.js +3 -2
  45. package/lib/commonjs/createRNFSTurbo.js.map +1 -1
  46. package/lib/commonjs/globals.d.js +6 -0
  47. package/lib/commonjs/globals.d.js.map +1 -0
  48. package/lib/module/NativeRNFSTurboModule.js +14 -16
  49. package/lib/module/NativeRNFSTurboModule.js.map +1 -1
  50. package/lib/module/createRNFSTurbo.js +3 -2
  51. package/lib/module/createRNFSTurbo.js.map +1 -1
  52. package/lib/module/globals.d.js +4 -0
  53. package/lib/module/globals.d.js.map +1 -0
  54. package/lib/typescript/NativeRNFSTurboModule.d.ts +12 -3
  55. package/lib/typescript/NativeRNFSTurboModule.d.ts.map +1 -1
  56. package/lib/typescript/Types.d.ts +11 -0
  57. package/lib/typescript/Types.d.ts.map +1 -1
  58. package/lib/typescript/createRNFSTurbo.d.ts.map +1 -1
  59. package/package.json +7 -3
  60. package/react-native.config.js +1 -5
  61. package/src/NativeRNFSTurboModule.ts +25 -21
  62. package/src/Types.ts +11 -0
  63. package/src/createRNFSTurbo.ts +4 -2
  64. package/src/globals.d.ts +9 -0
  65. package/cpp/NativeRNFSTurboModule.cpp +0 -24
  66. package/cpp/NativeRNFSTurboModule.h +0 -31
  67. package/ios/RNFSTurboOnLoad.mm +0 -25
  68. package/lib/commonjs/NativeRNFSTurboPlatformContextModule.js +0 -22
  69. package/lib/commonjs/NativeRNFSTurboPlatformContextModule.js.map +0 -1
  70. package/lib/module/NativeRNFSTurboPlatformContextModule.js +0 -18
  71. package/lib/module/NativeRNFSTurboPlatformContextModule.js.map +0 -1
  72. package/lib/typescript/NativeRNFSTurboPlatformContextModule.d.ts +0 -16
  73. package/lib/typescript/NativeRNFSTurboPlatformContextModule.d.ts.map +0 -1
  74. package/src/NativeRNFSTurboPlatformContextModule.ts +0 -34
@@ -0,0 +1,71 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2023 Jubal Mordecai Velasco
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #pragma once
26
+
27
+ #ifdef RNFSTURBO_USE_ENCRYPTION
28
+
29
+ #ifndef AES_CONFIG_HPP
30
+ #define AES_CONFIG_HPP
31
+
32
+ // WIP
33
+
34
+ #if defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(__amd64__)
35
+ #include <immintrin.h>
36
+ #include <xmmintrin.h>
37
+ #define AES_IMPLEMENT_INTEL_AESNI
38
+ #elif defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM)
39
+ #if defined(__GNUC__)
40
+ #include <stdint.h>
41
+ #endif
42
+
43
+ #if defined(__ARM_NEON) || defined(_MSC_VER)
44
+ #include <arm_neon.h>
45
+ #endif
46
+
47
+ /* GCC and LLVM Clang, but not Apple Clang */
48
+ #if defined(__GNUC__) && !defined(__apple_build_version__)
49
+ #if defined(__ARM_ACLE) || defined(__ARM_FEATURE_CRYPTO)
50
+ #include <arm_acle.h>
51
+ #endif
52
+ #endif
53
+ #define AES_IMPLEMENT_ARM_NEON
54
+ #else
55
+ #define AES_IMPLEMENT_PORTABLE_CPLUSPLUS
56
+ #endif
57
+
58
+ #if defined(USE_AES_ARM_NEON)
59
+ #undef AES_IMPLEMENT_INTEL_AESNI
60
+ #undef AES_IMPLEMENT_PORTABLE_CPLUSPLUS
61
+ #elif defined(USE_AES_INTEL_AESNI)
62
+ #undef AES_IMPLEMENT_ARM_NEON
63
+ #undef AES_IMPLEMENT_PORTABLE_CPLUSPLUS
64
+ #else
65
+ #undef AES_IMPLEMENT_ARM_NEON
66
+ #undef AES_IMPLEMENT_INTEL_AESNI
67
+ #endif
68
+
69
+ #endif
70
+
71
+ #endif
@@ -0,0 +1,69 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2019 SergeyBel
5
+ * Copyright (c) 2023 Jubal Mordecai Velasco
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #pragma once
27
+
28
+ #ifdef RNFSTURBO_USE_ENCRYPTION
29
+
30
+ #ifndef KRYPT_BLOCKCIPHER_HPP
31
+ #define KRYPT_BLOCKCIPHER_HPP
32
+
33
+ #include <cstring>
34
+ #include <exception>
35
+ #include <iostream>
36
+ #include "types.hpp"
37
+
38
+ namespace Krypt {
39
+ namespace BlockCipher {
40
+ class BASE_BLOCKCIPHER {
41
+ public:
42
+
43
+ size_t BLOCK_SIZE;
44
+
45
+ BASE_BLOCKCIPHER(size_t blockSize) : BLOCK_SIZE(blockSize) {
46
+ }
47
+
48
+ /// encrypts a fixed 16 byte block from `src` into `dest`.
49
+ /// @param src a pointer to an array of unsigned char*/Bytes* in heap this is
50
+ /// the array you want to encrypt.
51
+ /// @param dest another pointer to an array of unsigned char*/Bytes* in heap
52
+ /// this is the array where the encrypted block will be stored.
53
+ virtual void EncryptBlock(Bytes *, Bytes *) = 0;
54
+
55
+ /// decrypts a fixed 16 byte block from `src` into `dest`.
56
+ /// @param src a pointer to an array of unsigned char*/Bytes* in heap this is
57
+ /// the array you want to decrypt.
58
+ /// @param dest another pointer to an array of unsigned char*/Bytes* in heap
59
+ /// this is the array where the decrypted block will be stored.
60
+ virtual void DecryptBlock(Bytes *, Bytes *) = 0;
61
+
62
+ virtual ~BASE_BLOCKCIPHER() = default;
63
+ };
64
+ } // namespace BlockCipher
65
+ } // namespace Krypt
66
+
67
+ #endif
68
+
69
+ #endif
@@ -0,0 +1,158 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2019 SergeyBel
5
+ * Copyright (c) 2023 Jubal Mordecai Velasco
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifdef RNFSTURBO_USE_ENCRYPTION
27
+
28
+ #ifndef KRYPT_BYTEARRAY_CPP
29
+ #define KRYPT_BYTEARRAY_CPP
30
+
31
+ #include "bytearray.hpp"
32
+
33
+ namespace Krypt {
34
+ // returns the pointer array, leaving the .array() equal to NULL, and .length() equal to zero
35
+ Bytes *ByteArray::detach() {
36
+ Bytes *ptr = array;
37
+ array = NULL;
38
+ length = 0;
39
+ return ptr;
40
+ }
41
+
42
+ const Bytes &ByteArray::operator[](size_t i) const {
43
+ #ifndef INDEX_CHECK_DISABLE
44
+ if (length == 0) {
45
+ throw std::underflow_error(
46
+ "Krypt::ByteArray[] :"
47
+ " accessing an empty byte array"
48
+ );
49
+ }
50
+
51
+ if (i >= length) {
52
+ throw std::overflow_error(
53
+ "Krypt::ByteArray[] :"
54
+ " index given for operator[] is greater-than ByteArray.length()-1"
55
+ );
56
+ }
57
+ #endif
58
+ return array[i];
59
+ }
60
+
61
+ Bytes &ByteArray::operator[](size_t i) {
62
+ #ifndef INDEX_CHECK_DISABLE
63
+ if (length == 0) {
64
+ throw std::underflow_error(
65
+ "Krypt::ByteArray[] :"
66
+ " accessing an empty byte array"
67
+ );
68
+ }
69
+
70
+ if (i >= length) {
71
+ throw std::overflow_error(
72
+ "Krypt::ByteArray[] :"
73
+ " index given for operator[] is greater-than ByteArray.length()-1"
74
+ );
75
+ }
76
+ #endif
77
+ return array[i];
78
+ }
79
+
80
+ ByteArray::ByteArray() {
81
+ array = NULL;
82
+ length = 0;
83
+ }
84
+
85
+ ByteArray::ByteArray(Bytes *heap_obj, size_t length) {
86
+ array = heap_obj;
87
+ this->length = length;
88
+ }
89
+
90
+ // copy constructor
91
+ ByteArray::ByteArray(const ByteArray &other) : array(new Bytes[other.length]), length(other.length) {
92
+ memcpy(array, other.array, other.length);
93
+ }
94
+
95
+ // move constructor
96
+ ByteArray::ByteArray(ByteArray &&other) noexcept : array(other.array), length(other.length) {
97
+ other.array = NULL;
98
+ other.length = 0;
99
+ }
100
+
101
+ // copy assignment
102
+ ByteArray &ByteArray::operator=(const ByteArray &other) {
103
+ if (this != &other) {
104
+ if (array != NULL) {
105
+ memset((Bytes *) array, 0x00, length);
106
+ delete[] array;
107
+ }
108
+
109
+ array = new Bytes[other.length];
110
+ length = other.length;
111
+ memcpy(array, other.array, other.length);
112
+ }
113
+ return *this;
114
+ }
115
+
116
+ // move assingment
117
+ ByteArray &ByteArray::operator=(ByteArray &&other) noexcept {
118
+ if (this != &other) {
119
+ if (array != NULL) {
120
+ memset((Bytes *) array, 0x00, length);
121
+ delete[] array;
122
+ }
123
+
124
+ array = other.array;
125
+ length = other.length;
126
+
127
+ other.array = NULL;
128
+ other.length = 0;
129
+ }
130
+ return *this;
131
+ }
132
+
133
+ ByteArray::~ByteArray() {
134
+ if (array != NULL) {
135
+ memset((Bytes *) array, 0x00, length);
136
+ delete[] array;
137
+ }
138
+ length = 0;
139
+ }
140
+
141
+ std::ostream &operator<<(std::ostream &outputStream, const ByteArray &instance) {
142
+ for (size_t i = 0; i < instance.length; ++i) {
143
+ outputStream << instance.array[i];
144
+ }
145
+ return outputStream;
146
+ }
147
+
148
+ std::istream &operator>>(std::istream &inputStream, ByteArray &instance) {
149
+ for (size_t i = 0; i < instance.length; ++i) {
150
+ inputStream >> instance.array[i];
151
+ }
152
+ return inputStream;
153
+ }
154
+ } // namespace Krypt
155
+
156
+ #endif
157
+
158
+ #endif
@@ -0,0 +1,80 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2019 SergeyBel
5
+ * Copyright (c) 2023 Jubal Mordecai Velasco
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #pragma once
27
+
28
+ #ifdef RNFSTURBO_USE_ENCRYPTION
29
+
30
+ #ifndef KRYPT_BYTEARRAY_HPP
31
+ #define KRYPT_BYTEARRAY_HPP
32
+
33
+ #include <iostream>
34
+ #include <utility>
35
+ #include "types.hpp"
36
+
37
+ namespace Krypt {
38
+ class ByteArray {
39
+ public:
40
+
41
+ /// this is the Bytes* or unsigned char* that contains the elements of the array
42
+ Bytes *array;
43
+
44
+ /// the total element of the in the array
45
+ size_t length;
46
+
47
+ /// detach the heap allocated pointer inside of the ByteArray class instance.
48
+ /// @return raw pointer of unsigned char* or Bytes*.
49
+ Bytes *detach();
50
+
51
+ Bytes &operator[](size_t i);
52
+ const Bytes &operator[](size_t i) const;
53
+
54
+ ByteArray();
55
+
56
+ ByteArray(Bytes *heap_obj, size_t length);
57
+
58
+ // copy constructor
59
+ ByteArray(const ByteArray &other);
60
+
61
+ // move constructor
62
+ ByteArray(ByteArray &&other) noexcept;
63
+
64
+ // copy assignment
65
+ ByteArray &operator=(const ByteArray &other);
66
+
67
+ // move assingment
68
+ ByteArray &operator=(ByteArray &&other) noexcept;
69
+
70
+ ~ByteArray();
71
+ };
72
+
73
+ std::ostream &operator<<(std::ostream &outputStream, const ByteArray &instance);
74
+
75
+ std::istream &operator>>(std::istream &inputStream, ByteArray &instance);
76
+ } // namespace Krypt
77
+
78
+ #endif
79
+
80
+ #endif
@@ -0,0 +1,137 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2019 SergeyBel
5
+ * Copyright (c) 2023 Jubal Mordecai Velasco
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifdef RNFSTURBO_USE_ENCRYPTION
27
+
28
+ #ifndef KRYPT_FUNCTIONS_CPP
29
+ #define KRYPT_FUNCTIONS_CPP
30
+
31
+ #include "functions.hpp"
32
+ #include "types.hpp"
33
+
34
+ // #define USE_AESNI
35
+
36
+ #if defined(USE_AESNI)
37
+ #include <immintrin.h>
38
+ #else
39
+
40
+ #endif
41
+
42
+ // here the DWORDS is formed from 4 continous elements from a starting index of an unsinged char* array or Bytes*.
43
+ // a DWORD or double-word occupies 32-bits in a memory.
44
+ // the term DWORD is usually used to represent bits inside the eax,edx,...r15d parts of an x86_64 cpu register which can
45
+ // contain 32 bits inside.
46
+
47
+ namespace Krypt {
48
+ Bytes xtime(Bytes b) // multiply on x
49
+ {
50
+ return (b << 1) ^ (((b >> 7) & 1) * 0x1b);
51
+ }
52
+
53
+ void SubDWordBytes(Bytes *a) {
54
+ a[0] = sbox[a[0]];
55
+ a[1] = sbox[a[1]];
56
+ a[2] = sbox[a[2]];
57
+ a[3] = sbox[a[3]];
58
+ }
59
+
60
+ void RotDWord(Bytes *a) {
61
+ Bytes c = a[0];
62
+ a[0] = a[1];
63
+ a[1] = a[2];
64
+ a[2] = a[3];
65
+ a[3] = c;
66
+ }
67
+
68
+ void XorDWords(Bytes *a, Bytes *b, Bytes *dest) {
69
+ dest[0] = a[0] ^ b[0];
70
+ dest[1] = a[1] ^ b[1];
71
+ dest[2] = a[2] ^ b[2];
72
+ dest[3] = a[3] ^ b[3];
73
+ }
74
+
75
+ void XorBlocks(unsigned char *a, unsigned char *b, unsigned char *dest, unsigned int len) {
76
+ for (unsigned int i = 0; i < len; i++) {
77
+ dest[i] = a[i] ^ b[i];
78
+ }
79
+ }
80
+
81
+ void XorAesBlock(unsigned char *a, unsigned char *b, unsigned char *result) {
82
+ #if defined(USE_AESNI)
83
+ __m128i vxor = _mm_xor_si128(
84
+ _mm_load_si128((__m128i *) a),
85
+ _mm_load_si128((__m128i *) b)
86
+ );
87
+
88
+ _mm_storeu_si128((__m128i *) (result), vxor);
89
+ #else
90
+ uint64_t
91
+ *A = reinterpret_cast<uint64_t *>(a),
92
+ *B = reinterpret_cast<uint64_t *>(b),
93
+ *C = reinterpret_cast<uint64_t *>(result);
94
+
95
+ C[0] = A[0] ^ B[0];
96
+ C[1] = A[1] ^ B[1];
97
+ #endif
98
+ }
99
+
100
+ void Rcon(Bytes *a, int n) {
101
+ int i;
102
+ Bytes c = 1;
103
+ for (i = 0; i < n - 1; i++) {
104
+ c = xtime(c);
105
+ }
106
+
107
+ a[0] = c;
108
+ a[1] = a[2] = a[3] = 0;
109
+ }
110
+
111
+ void printHexArray(unsigned char a[], size_t n) {
112
+ for (size_t i = 0; i < n; i++) {
113
+ printf("%02x ", a[i]);
114
+ }
115
+ std::cout << "\n";
116
+ }
117
+
118
+ void printHexVector(const std::vector<unsigned char> &a) {
119
+ for (size_t i = 0; i < a.size(); i++) {
120
+ printf("%02x ", a[i]);
121
+ }
122
+ }
123
+
124
+ std::vector<unsigned char> ArrayToVector(std::unique_ptr<unsigned char[]> a, unsigned char len) {
125
+ return std::vector<unsigned char>(a.get(), a.get() + len);
126
+ }
127
+
128
+ std::unique_ptr<unsigned char[]> VectorToArray(const std::vector<unsigned char>& a) {
129
+ auto cpy = std::make_unique<unsigned char[]>(a.size());
130
+ memcpy(cpy.get(), a.data(), a.size());
131
+ return cpy;
132
+ }
133
+ } // namespace Krypt
134
+
135
+ #endif
136
+
137
+ #endif
@@ -0,0 +1,54 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2019 SergeyBel
5
+ * Copyright (c) 2023 Jubal Mordecai Velasco
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #pragma once
27
+
28
+ #ifdef RNFSTURBO_USE_ENCRYPTION
29
+
30
+ #ifndef KRYPT_FUNCTIONS_HPP
31
+ #define KRYPT_FUNCTIONS_HPP
32
+
33
+ #include <iostream>
34
+ #include "types.hpp"
35
+
36
+ namespace Krypt {
37
+ Bytes xtime(Bytes b); // multiply on x
38
+ void SubDWordBytes(Bytes *a);
39
+ void RotDWord(Bytes *a);
40
+ void XorDWords(Bytes *a, Bytes *b, Bytes *dest);
41
+ void XorBlocks(unsigned char *a, unsigned char *b, unsigned char *c, unsigned int len);
42
+ void XorAesBlock(unsigned char *a, unsigned char *b, unsigned char *result);
43
+
44
+ void Rcon(Bytes *a, int n);
45
+ void printHexArray(unsigned char a[], size_t n);
46
+ void printHexVector(const std::vector<unsigned char> &a);
47
+
48
+ std::vector<unsigned char> ArrayToVector(std::unique_ptr<unsigned char[]> a, unsigned char len);
49
+ std::unique_ptr<unsigned char[]> VectorToArray(const std::vector<unsigned char>& a);
50
+ } // namespace Krypt
51
+
52
+ #endif
53
+
54
+ #endif