summaryrefslogtreecommitdiffstats
path: root/utils/zenutils/source/zen_crypt
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2008-08-26 13:21:52 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2008-08-26 13:21:52 +0000
commitbea2ab2398ca116a5cb3c62901769a1031b7d359 (patch)
treea91302573f14bd7f88b6aa12f751a83287a67785 /utils/zenutils/source/zen_crypt
parentaf5f8665e85cb2b151cd394b9209da6f6b03efb1 (diff)
downloadrockbox-bea2ab2398ca116a5cb3c62901769a1031b7d359.tar.gz
rockbox-bea2ab2398ca116a5cb3c62901769a1031b7d359.tar.bz2
rockbox-bea2ab2398ca116a5cb3c62901769a1031b7d359.zip
ZenUtils:
* add FRESC encryption * clean up code a bit git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18345 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils/source/zen_crypt')
-rw-r--r--utils/zenutils/source/zen_crypt/CMakeLists.txt2
-rw-r--r--utils/zenutils/source/zen_crypt/main.cpp60
2 files changed, 44 insertions, 18 deletions
diff --git a/utils/zenutils/source/zen_crypt/CMakeLists.txt b/utils/zenutils/source/zen_crypt/CMakeLists.txt
index 5721bbfa06..c0e9d3ee12 100644
--- a/utils/zenutils/source/zen_crypt/CMakeLists.txt
+++ b/utils/zenutils/source/zen_crypt/CMakeLists.txt
@@ -1,4 +1,6 @@
ADD_EXECUTABLE(zen_crypt main.cpp)
+SET_SOURCE_FILES_PROPERTIES(main.cpp PROPERTIES COMPILE_FLAGS -Wno-multichar)
+
TARGET_LINK_LIBRARIES(zen_crypt shared)
TARGET_LINK_LIBRARIES(zen_crypt beecrypt)
diff --git a/utils/zenutils/source/zen_crypt/main.cpp b/utils/zenutils/source/zen_crypt/main.cpp
index 532de25078..3442baf738 100644
--- a/utils/zenutils/source/zen_crypt/main.cpp
+++ b/utils/zenutils/source/zen_crypt/main.cpp
@@ -46,12 +46,12 @@ enum mode_t
struct player_info_t
{
const char* name;
- const char* null_key; // HMAC-SHA1 key
- const char* fresc_key; // BlowFish key
- const char* tl_key; // BlowFish key
+ const char* null_key; /* HMAC-SHA1 key */
+ const char* fresc_key; /* BlowFish key */
+ const char* tl_key; /* BlowFish key */
bool big_endian;
};
-}; //namespace
+}; /* namespace */
static const char VERSION[] = "0.2";
@@ -210,7 +210,7 @@ bool sign(shared::bytes& data, player_info_t* pi, const std::string& file,
if (index)
{
if (verbose)
- std::cout << "[*] Found NULL signature at: "
+ std::cout << "[*] Found NULL signature at: 0x"
<< std::hex << index << std::endl;
if (verbose)
@@ -317,7 +317,7 @@ bool verify(shared::bytes& data, player_info_t* pi, bool verbose)
return false;
}
if (verbose)
- std::cout << "[*] Found NULL signature at: "
+ std::cout << "[*] Found NULL signature at: 0x"
<< std::hex << index << std::endl;
if (verbose)
@@ -382,8 +382,26 @@ bool encrypt(shared::bytes& data, int mode, player_info_t* pi,
}
else if (mode == mode_fresc)
{
- std::cerr << "FRESC mode is not supported." << std::endl;
- return false;
+ if (verbose)
+ std::cout << "[*] Encrypting input file..." << std::endl;
+
+ dword iv[2] = {shared::swap(data.size()), 0};
+ if (!zen::bf_cbc_encrypt((const byte*)pi->fresc_key,
+ strlen(pi->fresc_key)+1, &data[0],
+ data.size(), (const byte*)iv))
+ {
+ std::cerr << "Failed to encrypt the input file." << std::endl;
+ return false;
+ }
+
+ if (verbose)
+ std::cout << "[*] Writing file data..." << std::endl;
+
+ if (!shared::write_file(file, data, true))
+ {
+ std::cerr << "Failed to save the output file." << std::endl;
+ return false;
+ }
}
else if (mode == mode_tl)
{
@@ -413,7 +431,7 @@ bool encrypt(shared::bytes& data, int mode, player_info_t* pi,
if (!zen::bf_cbc_encrypt((const byte*)pi->tl_key, strlen(pi->tl_key)+1,
&outbuf[0], len, (const byte*)iv))
{
- std::cerr << "Failed to decrypt the input file." << std::endl;
+ std::cerr << "Failed to encrypt the input file." << std::endl;
return false;
}
@@ -540,9 +558,11 @@ bool decrypt(shared::bytes& data, int mode, player_info_t* pi,
int process_arguments(int argc, char*argv[])
{
- //--------------------------------------------------------------------
- // Parse input variables.
- //--------------------------------------------------------------------
+ /*
+ --------------------------------------------------------------------
+ Parse input variables.
+ --------------------------------------------------------------------
+ */
GetPot cl(argc, argv);
if (cl.size() == 1 || cl.search(2, "-h", "--help"))
@@ -636,9 +656,11 @@ int process_arguments(int argc, char*argv[])
pi->big_endian = big_endian;
- //--------------------------------------------------------------------
- // Read the input file.
- //--------------------------------------------------------------------
+ /*
+ --------------------------------------------------------------------
+ Read the input file.
+ --------------------------------------------------------------------
+ */
if (verbose)
std::cout << "[*] Reading input file..." << std::endl;
@@ -651,9 +673,11 @@ int process_arguments(int argc, char*argv[])
}
- //--------------------------------------------------------------------
- // Process the input file.
- //--------------------------------------------------------------------
+ /*
+ --------------------------------------------------------------------
+ Process the input file.
+ --------------------------------------------------------------------
+ */
switch (command)
{