diff --git a/src-tauri/build.rs b/src-tauri/build.rs index a4b29c7..4d4f01a 100644 --- a/src-tauri/build.rs +++ b/src-tauri/build.rs @@ -3,12 +3,17 @@ fn main() { .include("mhycrypto") .cpp(true) - .file("mhycrypto/aes.cpp") .file("mhycrypto/memecrypto.cpp") .file("mhycrypto/metadata.cpp") .file("mhycrypto/metadatastringdec.cpp") .compile("mhycrypto"); + cc::Build::new() + .include("mhycrypto") + .file("mhycrypto/aes.c") + + .compile("mhycrypto-aes"); + tauri_build::build() } diff --git a/src-tauri/mhycrypto/aes.cpp b/src-tauri/mhycrypto/aes.c similarity index 99% rename from src-tauri/mhycrypto/aes.cpp rename to src-tauri/mhycrypto/aes.c index 9f7847b..5f8023b 100644 --- a/src-tauri/mhycrypto/aes.cpp +++ b/src-tauri/mhycrypto/aes.c @@ -318,28 +318,6 @@ void oqs_aes128_enc_c(const uint8_t *plaintext, const void *_schedule, uint8_t * xor_round_key(ciphertext, schedule, 10); } -// It's not enc nor dec, it's something in between -void oqs_mhy128_enc_c(const uint8_t *plaintext, const void *_schedule, uint8_t *ciphertext) { - const uint8_t *schedule = (const uint8_t *) _schedule; - int i; // To count the rounds - - // First Round - memcpy(ciphertext, plaintext, 16); - xor_round_key(ciphertext, schedule, 0); - - // Middle rounds - for (i = 0; i < 9; i++) { - sub_bytes_inv(ciphertext, 16); - shift_rows_inv(ciphertext); - mix_cols_inv(ciphertext); - xor_round_key(ciphertext, schedule, i + 1); - } - - // Final Round - sub_bytes_inv(ciphertext, 16); - shift_rows_inv(ciphertext); - xor_round_key(ciphertext, schedule, 10); -} void oqs_aes128_dec_c(const uint8_t *ciphertext, const void *_schedule, uint8_t *plaintext) { const uint8_t *schedule = (const uint8_t *) _schedule; @@ -363,6 +341,29 @@ void oqs_aes128_dec_c(const uint8_t *ciphertext, const void *_schedule, uint8_t xor_round_key(plaintext, schedule, 0); } +// It's not enc nor dec, it's something in between +void oqs_mhy128_enc_c(const uint8_t *plaintext, const void *_schedule, uint8_t *ciphertext) { + const uint8_t *schedule = (const uint8_t *) _schedule; + int i; // To count the rounds + + // First Round + memcpy(ciphertext, plaintext, 16); + xor_round_key(ciphertext, schedule, 0); + + // Middle rounds + for (i = 0; i < 9; i++) { + sub_bytes_inv(ciphertext, 16); + shift_rows_inv(ciphertext); + mix_cols_inv(ciphertext); + xor_round_key(ciphertext, schedule, i + 1); + } + + // Final Round + sub_bytes_inv(ciphertext, 16); + shift_rows_inv(ciphertext); + xor_round_key(ciphertext, schedule, 10); +} + void oqs_mhy128_dec_c(const uint8_t *ciphertext, const void *_schedule, uint8_t *plaintext) { const uint8_t *schedule = (const uint8_t *) _schedule; int i; // To count the rounds diff --git a/src-tauri/mhycrypto/aes.h b/src-tauri/mhycrypto/aes.h index f905742..a33b167 100644 --- a/src-tauri/mhycrypto/aes.h +++ b/src-tauri/mhycrypto/aes.h @@ -63,4 +63,4 @@ void OQS_AES128_ECB_enc_sch(const uint8_t *plaintext, const size_t plaintext_len */ void OQS_AES128_ECB_dec_sch(const uint8_t *ciphertext, const size_t ciphertext_len, const void *schedule, uint8_t *plaintext); -#endif +#endif \ No newline at end of file diff --git a/src-tauri/mhycrypto/memecrypto.cpp b/src-tauri/mhycrypto/memecrypto.cpp index 71ccfd4..7be79d8 100644 --- a/src-tauri/mhycrypto/memecrypto.cpp +++ b/src-tauri/mhycrypto/memecrypto.cpp @@ -3,7 +3,8 @@ #include #include -#include "aes.h" +extern "C" void oqs_mhy128_enc_c(const uint8_t *plaintext, const void *_schedule, uint8_t *ciphertext); +extern "C" void oqs_mhy128_dec_c(const uint8_t *ciphertext, const void *_schedule, uint8_t *plaintext); static uint8_t dexor16(const uint8_t *c) { uint8_t ret = 0; @@ -17,9 +18,6 @@ void memecrypto_prepare_key(const uint8_t *in, uint8_t *out) { out[i] = dexor16(&in[0x10 * i]); } -extern "C" void oqs_mhy128_enc_c(const uint8_t *plaintext, const void *_schedule, uint8_t *ciphertext); -extern "C" void oqs_mhy128_dec_c(const uint8_t *ciphertext, const void *_schedule, uint8_t *plaintext); - void memecrypto_decrypt(const uint8_t *key, uint8_t *data) { uint8_t plaintext[16]; oqs_mhy128_enc_c(data, key, plaintext);