done interface part, need write encrypt code

This commit is contained in:
redlineo committed 2025-01-27 09:59:57 +00:00
1 parent 350e2833f2
commit d1cb628eec
4 files changed
+107 -79

No files matched your search

+44 -44
View File
@@ -1097,7 +1097,7 @@ void print_rnd_key(WORD key[])
/*********************** TEST FUNCTION DEFINITIONS ***********************/
#ifdef TEST_FUNCTIONS_ENABLED
void print_hex(BYTE str[], int len)
void red_print_hex(BYTE str[], int len)
{
int idx;
@@ -1126,21 +1126,21 @@ int aes_ecb_test(void)
//printf("* ECB mode:\n");
aes_key_setup(key[0], key_schedule, 256);
//printf( "Key : ");
//print_hex(key[0], 32);
//red_print_hex(key[0], 32);
for(idx = 0; idx < 2; idx++) {
aes_encrypt(plaintext[idx], enc_buf, key_schedule, 256);
//printf("\nPlaintext : ");
//print_hex(plaintext[idx], 16);
//red_print_hex(plaintext[idx], 16);
//printf("\n-encrypted to: ");
//print_hex(enc_buf, 16);
//red_print_hex(enc_buf, 16);
pass = pass && !memcmp(enc_buf, ciphertext[idx], 16);
aes_decrypt(ciphertext[idx], enc_buf, key_schedule, 256);
//printf("\nCiphertext : ");
//print_hex(ciphertext[idx], 16);
//red_print_hex(ciphertext[idx], 16);
//printf("\n-decrypted to: ");
//print_hex(enc_buf, 16);
//red_print_hex(enc_buf, 16);
pass = pass && !memcmp(enc_buf, plaintext[idx], 16);
//printf("\n\n");
@@ -1171,26 +1171,26 @@ int aes_cbc_test(void)
aes_key_setup(key[0], key_schedule, 256);
//printf( "Key : ");
//print_hex(key[0], 32);
//red_print_hex(key[0], 32);
//printf("\nIV : ");
//print_hex(iv[0], 16);
//red_print_hex(iv[0], 16);
aes_encrypt_cbc(plaintext[0], 32, enc_buf, key_schedule, 256, iv[0]);
//printf("\nPlaintext : ");
//print_hex(plaintext[0], 32);
//red_print_hex(plaintext[0], 32);
//printf("\n-encrypted to: ");
//print_hex(enc_buf, 32);
//red_print_hex(enc_buf, 32);
//printf("\nCiphertext : ");
//print_hex(ciphertext[0], 32);
//red_print_hex(ciphertext[0], 32);
pass = pass && !memcmp(enc_buf, ciphertext[0], 32);
aes_decrypt_cbc(ciphertext[0], 32, enc_buf, key_schedule, 256, iv[0]);
//printf("\nCiphertext : ");
//print_hex(ciphertext[0], 32);
//red_print_hex(ciphertext[0], 32);
//printf("\n-decrypted to: ");
//print_hex(enc_buf, 32);
//red_print_hex(enc_buf, 32);
//printf("\nPlaintext : ");
//print_hex(plaintext[0], 32);
//red_print_hex(plaintext[0], 32);
pass = pass && !memcmp(enc_buf, plaintext[0], 32);
//printf("\n\n");
@@ -1219,22 +1219,22 @@ int aes_ctr_test(void)
aes_key_setup(key[0], key_schedule, 256);
//printf( "Key : ");
//print_hex(key[0], 32);
//red_print_hex(key[0], 32);
//printf("\nIV : ");
//print_hex(iv[0], 16);
//red_print_hex(iv[0], 16);
aes_encrypt_ctr(plaintext[0], 32, enc_buf, key_schedule, 256, iv[0]);
//printf("\nPlaintext : ");
//print_hex(plaintext[0], 32);
//red_print_hex(plaintext[0], 32);
//printf("\n-encrypted to: ");
//print_hex(enc_buf, 32);
//red_print_hex(enc_buf, 32);
pass = pass && !memcmp(enc_buf, ciphertext[0], 32);
aes_decrypt_ctr(ciphertext[0], 32, enc_buf, key_schedule, 256, iv[0]);
//printf("\nCiphertext : ");
//print_hex(ciphertext[0], 32);
//red_print_hex(ciphertext[0], 32);
//printf("\n-decrypted to: ");
//print_hex(enc_buf, 32);
//red_print_hex(enc_buf, 32);
pass = pass && !memcmp(enc_buf, plaintext[0], 32);
//printf("\n\n");
@@ -1273,70 +1273,70 @@ int aes_ccm_test(void)
//printf("* CCM mode:\n");
//printf("Key : ");
//print_hex(key[0], 16);
//red_print_hex(key[0], 16);
//print_hex(plaintext[0], 4);
//print_hex(assoc[0], 8);
//print_hex(ciphertext[0], 8);
//print_hex(iv[0], 7);
//print_hex(key[0], 16);
//red_print_hex(plaintext[0], 4);
//red_print_hex(assoc[0], 8);
//red_print_hex(ciphertext[0], 8);
//red_print_hex(iv[0], 7);
//red_print_hex(key[0], 16);
aes_encrypt_ccm(plaintext[0], 4, assoc[0], 8, iv[0], 7, enc_buf, &enc_buf_len, 4, key[0], 128);
//printf("\nNONCE : ");
//print_hex(iv[0], 7);
//red_print_hex(iv[0], 7);
//printf("\nAssoc. Data : ");
//print_hex(assoc[0], 8);
//red_print_hex(assoc[0], 8);
//printf("\nPayload : ");
//print_hex(plaintext[0], 4);
//red_print_hex(plaintext[0], 4);
//printf("\n-encrypted to: ");
//print_hex(enc_buf, enc_buf_len);
//red_print_hex(enc_buf, enc_buf_len);
pass = pass && !memcmp(enc_buf, ciphertext[0], enc_buf_len);
aes_decrypt_ccm(ciphertext[0], 8, assoc[0], 8, iv[0], 7, enc_buf, &enc_buf_len, 4, &mac_auth, key[0], 128);
//printf("\n-Ciphertext : ");
//print_hex(ciphertext[0], 8);
//red_print_hex(ciphertext[0], 8);
//printf("\n-decrypted to: ");
//print_hex(enc_buf, enc_buf_len);
//red_print_hex(enc_buf, enc_buf_len);
//printf("\nAuthenticated: %d ", mac_auth);
pass = pass && !memcmp(enc_buf, plaintext[0], enc_buf_len) && mac_auth;
aes_encrypt_ccm(plaintext[1], 16, assoc[1], 16, iv[1], 8, enc_buf, &enc_buf_len, 6, key[0], 128);
//printf("\n\nNONCE : ");
//print_hex(iv[1], 8);
//red_print_hex(iv[1], 8);
//printf("\nAssoc. Data : ");
//print_hex(assoc[1], 16);
//red_print_hex(assoc[1], 16);
//printf("\nPayload : ");
//print_hex(plaintext[1], 16);
//red_print_hex(plaintext[1], 16);
//printf("\n-encrypted to: ");
//print_hex(enc_buf, enc_buf_len);
//red_print_hex(enc_buf, enc_buf_len);
pass = pass && !memcmp(enc_buf, ciphertext[1], enc_buf_len);
aes_decrypt_ccm(ciphertext[1], 22, assoc[1], 16, iv[1], 8, enc_buf, &enc_buf_len, 6, &mac_auth, key[0], 128);
//printf("\n-Ciphertext : ");
//print_hex(ciphertext[1], 22);
//red_print_hex(ciphertext[1], 22);
//printf("\n-decrypted to: ");
//print_hex(enc_buf, enc_buf_len);
//red_print_hex(enc_buf, enc_buf_len);
//printf("\nAuthenticated: %d ", mac_auth);
pass = pass && !memcmp(enc_buf, plaintext[1], enc_buf_len) && mac_auth;
aes_encrypt_ccm(plaintext[2], 24, assoc[2], 20, iv[2], 12, enc_buf, &enc_buf_len, 8, key[0], 128);
//printf("\n\nNONCE : ");
//print_hex(iv[2], 12);
//red_print_hex(iv[2], 12);
//printf("\nAssoc. Data : ");
//print_hex(assoc[2], 20);
//red_print_hex(assoc[2], 20);
//printf("\nPayload : ");
//print_hex(plaintext[2], 24);
//red_print_hex(plaintext[2], 24);
//printf("\n-encrypted to: ");
//print_hex(enc_buf, enc_buf_len);
//red_print_hex(enc_buf, enc_buf_len);
pass = pass && !memcmp(enc_buf, ciphertext[2], enc_buf_len);
aes_decrypt_ccm(ciphertext[2], 32, assoc[2], 20, iv[2], 12, enc_buf, &enc_buf_len, 8, &mac_auth, key[0], 128);
//printf("\n-Ciphertext : ");
//print_hex(ciphertext[2], 32);
//red_print_hex(ciphertext[2], 32);
//printf("\n-decrypted to: ");
//print_hex(enc_buf, enc_buf_len);
//red_print_hex(enc_buf, enc_buf_len);
//printf("\nAuthenticated: %d ", mac_auth);
pass = pass && !memcmp(enc_buf, plaintext[2], enc_buf_len) && mac_auth;