summaryrefslogtreecommitdiffstats
path: root/utils/nwztools/upgtools/mg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/nwztools/upgtools/mg.cpp')
-rw-r--r--utils/nwztools/upgtools/mg.cpp105
1 files changed, 79 insertions, 26 deletions
diff --git a/utils/nwztools/upgtools/mg.cpp b/utils/nwztools/upgtools/mg.cpp
index 66566770f9..4bab5d9c61 100644
--- a/utils/nwztools/upgtools/mg.cpp
+++ b/utils/nwztools/upgtools/mg.cpp
@@ -26,43 +26,96 @@
#include <stdio.h>
using namespace CryptoPP;
-namespace
+
+void mg_decrypt_fw(void *in, int size, void *out, uint8_t *key)
{
- inline void dec_des_ecb(void *in, int size, void *out, uint8_t *key)
- {
- ECB_Mode< DES >::Decryption dec;
- if(size % 8)
- abort(); /* size must be a multiple of 8 */
- dec.SetKey(key, 8);
- dec.ProcessData((byte*)out, (byte*)in, size);
- }
-
- inline void enc_des_ecb(void *in, int size, void *out, uint8_t *key)
- {
- ECB_Mode< DES >::Encryption enc;
- if(size % 8)
- abort(); /* size must be a multiple of 8 */
- enc.SetKey(key, 8);
- enc.ProcessData((byte*)out, (byte*)in, size);
- }
+ ECB_Mode< DES >::Decryption dec;
+ if(size % 8)
+ abort(); /* size must be a multiple of 8 */
+ dec.SetKey(key, 8);
+ dec.ProcessData((byte*)out, (byte*)in, size);
}
-void mg_decrypt_fw(void *in, int size, void *out, uint8_t *key)
+static ECB_Mode< DES >::Decryption g_des_ecb_dec;
+
+void des_ecb_dec_set_key(const uint8_t key[8])
{
- dec_des_ecb(in, size, out, key);
+ g_des_ecb_dec.SetKey(key, 8);
}
-void mg_encrypt_fw(void *in, int size, void *out, uint8_t *key)
+void des_ecb_dec(void *in, int size, void *out)
{
- enc_des_ecb(in, size, out, key);
+ if(size % 8)
+ abort(); /* size must be a multiple of 8 */
+ g_des_ecb_dec.ProcessData((byte*)out, (byte*)in, size);
}
-void mg_decrypt_pass(void *in, int size, void *out, uint8_t *key)
+static ECB_Mode< DES >::Encryption g_des_ecb_enc;
+
+void des_ecb_enc_set_key(const uint8_t key[8])
+{
+ g_des_ecb_enc.SetKey(key, 8);
+}
+
+void des_ecb_enc(void *in, int size, void *out)
+{
+ if(size % 8)
+ abort(); /* size must be a multiple of 8 */
+ g_des_ecb_enc.ProcessData((byte*)out, (byte*)in, size);
+}
+
+static ECB_Mode< AES >::Decryption g_aes_ecb_dec;
+
+void aes_ecb_dec_set_key(const uint8_t key[16])
+{
+ g_aes_ecb_dec.SetKey(key, 16);
+}
+
+void aes_ecb_dec(void *in, int size, void *out)
+{
+ if(size % 16)
+ abort(); /* size must be a multiple of 16 */
+ g_aes_ecb_dec.ProcessData((byte*)out, (byte*)in, size);
+}
+
+static ECB_Mode< AES >::Encryption g_aes_ecb_enc;
+
+void aes_ecb_enc_set_key(const uint8_t key[16])
+{
+ g_aes_ecb_enc.SetKey(key, 16);
+}
+
+void aes_ecb_enc(void *in, int size, void *out)
+{
+ if(size % 16)
+ abort(); /* size must be a multiple of 16 */
+ g_aes_ecb_enc.ProcessData((byte*)out, (byte*)in, size);
+}
+
+static CBC_Mode< AES >::Decryption g_aes_cbc_dec;
+
+void aes_cbc_dec_set_key_iv(const uint8_t key[16], const uint8_t iv[16])
+{
+ g_aes_cbc_dec.SetKeyWithIV(key, 16, iv);
+}
+
+void aes_cbc_dec(void *in, int size, void *out)
+{
+ if(size % 16)
+ abort(); /* size must be a multiple of 16 */
+ g_aes_cbc_dec.ProcessData((byte*)out, (byte*)in, size);
+}
+
+static CBC_Mode< AES >::Encryption g_aes_cbc_enc;
+
+void aes_cbc_enc_set_key_iv(const uint8_t key[16], const uint8_t iv[16])
{
- dec_des_ecb(in, size, out, key);
+ g_aes_cbc_enc.SetKeyWithIV(key, 16, iv);
}
-void mg_encrypt_pass(void *in, int size, void *out, uint8_t *key)
+void aes_cbc_enc(void *in, int size, void *out)
{
- enc_des_ecb(in, size, out, key);
+ if(size % 16)
+ abort(); /* size must be a multiple of 16 */
+ g_aes_cbc_enc.ProcessData((byte*)out, (byte*)in, size);
}