use openssl

This commit is contained in:
nganhkhoa 2023-03-06 10:02:22 +07:00
parent ed4f06ae90
commit e864041b8d
5 changed files with 15 additions and 10 deletions

View File

@ -18,6 +18,7 @@ android {
externalNativeBuild { externalNativeBuild {
cmake { cmake {
cppFlags '-std=c++17' cppFlags '-std=c++17'
arguments "-DANDROID_STL=c++_shared"
} }
} }
} }
@ -45,6 +46,7 @@ android {
} }
buildFeatures { buildFeatures {
viewBinding true viewBinding true
prefab true
} }
} }
@ -57,4 +59,5 @@ dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.android.ndk.thirdparty:openssl:1.1.1q-beta-1'
} }

View File

@ -27,9 +27,7 @@ add_library( # Sets the name of the library.
consts.h consts.h
utils.h utils.h
des.h des.h
des.cpp des.cpp)
sha1.cpp
sha1.h)
set_property(TARGET cccc PROPERTY CXX_STANDARD 17) set_property(TARGET cccc PROPERTY CXX_STANDARD 17)
@ -48,6 +46,8 @@ find_library( # Sets the name of the path variable.
# you want CMake to locate. # you want CMake to locate.
log) log)
find_package(openssl REQUIRED CONFIG)
# Specifies libraries CMake should link to your target library. You # Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this # can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries. # build script, prebuilt third-party libraries, or system libraries.
@ -58,4 +58,5 @@ target_link_libraries( # Specifies the target library.
# Links the target library to the log library # Links the target library to the log library
# included in the NDK. # included in the NDK.
android android
${log-lib}) ${log-lib}
openssl::crypto)

View File

@ -3,8 +3,9 @@
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include <openssl/sha.h>
#include "des.h" #include "des.h"
#include "sha1.h"
/* /*
* The DES function * The DES function
@ -123,10 +124,10 @@ uint64_t des(uint64_t input, uint64_t key, char mode) {
// 00 00 1000 0100 00 00 00 00 00 row mask // 00 00 1000 0100 00 00 00 00 00 row mask
// 00 00 0111 1000 00 00 00 00 00 column mask // 00 00 0111 1000 00 00 00 00 00 column mask
row = (char) ((s_input & (0x0000840000000000 >> 6*j)) >> 42-6*j); row = (char) ((s_input & (0x0000840000000000 >> 6*j)) >> (42-6*j));
row = (row >> 4) | row & 0x01; row = (row >> 4) | row & 0x01;
column = (char) ((s_input & (0x0000780000000000 >> 6*j)) >> 43-6*j); column = (char) ((s_input & (0x0000780000000000 >> 6*j)) >> (43-6*j));
s_output <<= 4; s_output <<= 4;
s_output |= (uint32_t) (S[j][16*row + column] & 0x0f); s_output |= (uint32_t) (S[j][16*row + column] & 0x0f);
@ -262,7 +263,7 @@ bytes KDF(bytes keyseed, int32_t count) {
for (size_t i = 0; i < 4; i++) for (size_t i = 0; i < 4; i++)
msg.push_back(b[3 - i]); msg.push_back(b[3 - i]);
} }
SHA1((char*)hash.data(), (const char*)msg.data(), msg.size()); SHA1(msg.data(), msg.size(), hash.data());
return hash; return hash;
} }

View File

@ -279,7 +279,7 @@ void SHA1Final(
memset(&finalcount, '\0', sizeof(finalcount)); memset(&finalcount, '\0', sizeof(finalcount));
} }
void SHA1( void SHA1_bruh(
char *hash_out, char *hash_out,
const char *str, const char *str,
uint32_t len) uint32_t len)

View File

@ -45,7 +45,7 @@ void SHA1Final(
SHA1_CTX * context SHA1_CTX * context
); );
void SHA1( void SHA1_bruh(
char *hash_out, char *hash_out,
const char *str, const char *str,
uint32_t len); uint32_t len);