--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+//
+// Microsoft Visual C++ generated resource script.
+//
+#define APSTUDIO_READONLY_SYMBOLS
+#include "WinResrc.h" //"afxres.h"
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Neutral resources
+//
+#ifdef _WIN32
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x3L
+#else
+ FILEFLAGS 0x2L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "000004b0"
+ BEGIN
+ VALUE "ProductName", "MCrypt"
+ VALUE "FileDescription", "MCrypt Utility"
+ VALUE "ProductVersion", "1.0.0"
+ VALUE "FileVersion", "1.0.0"
+ VALUE "InternalName", "mcrypt"
+ VALUE "OriginalFilename", "mcrypt.exe"
+ VALUE "LegalCopyright", "Created by LoRd_MuldeR <MuldeR2@GMX.de>"
+ VALUE "CompanyName", "Muldersoft"
+ VALUE "LegalTrademarks", "Muldersoft"
+ VALUE "Comments", "This work has been released under the CC0 1.0 Universal license!"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x0, 1200
+ END
+END
<ClInclude Include="src\platform.h" />
<ClInclude Include="src\utils.h" />
</ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="MCrypt.rc" />
+ </ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{86d28793-713e-4cec-9686-335514ac5ef0}</ProjectGuid>
<RootNamespace>MCrypt</RootNamespace>
- <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>mcrypt</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>mcrypt</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>mcrypt</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>mcrypt</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <GenerateDebugInformation>true</GenerateDebugInformation>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <GenerateDebugInformation>true</GenerateDebugInformation>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="MCrypt.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
</Project>
\ No newline at end of file
#include <string.h>
#include <time.h>
#include <inttypes.h>
+#include <ctype.h>
static void print_string(const char *const text, const size_t length)
{
return 0;
}
+static int weak_passphrase(const CHR *str)
+{
+ int flags[4U] = { 0, 0, 0, 0 };
+ while (*str)
+ {
+ const CHR c = *str++;
+ if (iswupper(c)) flags[0U] = 1;
+ else if (iswlower(c)) flags[1U] = 1;
+ else if (iswdigit(c)) flags[2U] = 1;
+ else if (iswgraph(c)) flags[3U] = 1;
+ }
+ const int strong = flags[0U] && flags[1U] && flags[2U] && flags[3U];
+ return !strong;
+}
+
static int encrypt(const CHR* const passphrase, const CHR* const input, const CHR* const output)
{
mcrypt_t ctx = NULL;
FILE *fin = NULL, *fout = NULL;
int result = -1;
- if (!passphrase[0U])
+ if (STRLEN(passphrase) < 8U)
{
- FPUTS(T("Error: The given passphrase is empty!\n\n"), stderr);
- goto clean_up;
+ FPUTS(L"Warning: Using a short passphrase. Eight characters or more are recommended!\n\n", stderr);
+ }
+ else if (weak_passphrase(passphrase))
+ {
+ FPUTS(L"Warning: Using a weak passphrase. A mix of upper-case characters, lower-case characters, digits and 'special' characters is recommended!\n\n", stderr);
}
char *const passphrase_utf8 = utf16_to_bytes(passphrase, CP_UTF8);
FILE *fin = NULL, *fout = NULL;
int result = -1;
- if (!passphrase[0U])
- {
- FPUTS(T("Error: The given passphrase is empty!\n\n"), stderr);
- goto clean_up;
- }
-
char *const passphrase_utf8 = utf16_to_bytes(passphrase, CP_UTF8);
if (!passphrase_utf8)
{
int MAIN(int argc, CHR* argv[])
{
- FPRINTF(stderr, T("MCrypt Utility [%") T(PRIstr) T("]\n"), __DATE__" "__TIME__);
+ FPRINTF(stderr, T("MCrypt Utility [%") T(PRIstr) T("]\n"), __DATE__", "__TIME__);
FPRINTF(stderr, T("Powered by libMCrypt v%") T(PRIstr) T(" [%") T(PRIstr) T("]\n\n"), LIBMCRYPT_VERSION, LIBMCRYPT_BUILDNO);
- if (argc < 4)
+ if ((argc < 5) || (!STRICMP(argv[1U], T("--help"))) || (!STRICMP(argv[1U], T("--version"))))
{
+ FPUTS(T("This software has been released under the CC0 1.0 Universal license:\n"), stderr);
+ FPUTS(T("https://creativecommons.org/publicdomain/zero/1.0/legalcode\n\n"), stderr);
+ if (argc < 2)
+ {
+ FPUTS(T("Nothing to do!\n\n"), stderr);
+ }
FPUTS(T("Usage:\n"), stderr);
- FPRINTF(stderr, T(" %s [--decrypt] <passphrase> <input> <output>\n\n"), argv[0U]);
+ FPRINTF(stderr, T(" %") T(PRIwcs) T(" --encrypt <passphrase> <input.txt> <output.enc>\n"), argv[0U]);
+ FPRINTF(stderr, T(" %") T(PRIwcs) T(" --decrypt <passphrase> <input.enc> <output.txt>\n\n"), argv[0U]);
+ return 1;
+ }
+
+ if (!argv[1U][0U])
+ {
+ FPUTS(T("Error: The passphrase must not be empty!\n\n"), stderr);
return 1;
}
- int result = -1;
const clock_t clk_start = clock();
+ int result = -1;
- if ((argc > 4) && ((!STRICMP(argv[1U], T("-d"))) || (!STRICMP(argv[1U], T("--decrypt")))))
+ if (!STRICMP(argv[1U], T("--encrypt")))
+ {
+ result = encrypt(argv[2U], argv[3U], argv[4U]);
+ }
+ else if (!STRICMP(argv[1U], T("--decrypt")))
{
result = decrypt(argv[2U], argv[3U], argv[4U]);
- erase(argv[2U], STRLEN(argv[2U]) * sizeof(CHR));
}
else
{
- result = encrypt(argv[1U], argv[2U], argv[3U]);
- erase(argv[1U], STRLEN(argv[1U]) * sizeof(CHR));
+ FPRINTF(stderr, T("Error: Command \"%") T(PRIwcs) T("\" is unknown!\n\n"), argv[1U]);
+ erase(argv[2U], STRLEN(argv[2U]) * sizeof(CHR));
+ return 1;
}
FPUTS(T("--------\n\n"), stderr);
fflush(stderr);
+ erase(argv[2U], STRLEN(argv[2U]) * sizeof(CHR));
const clock_t clk_end = clock();
FPRINTF(stderr, T("Operation completed after %.1f seconds.\n\n"), (clk_end - clk_start) / ((double)CLOCKS_PER_SEC));
#define STAT64_T struct _stati64
#ifdef __MINGW32__
#define PRIstr "hs"
+#define PRIwcs "ls"
#else
#define PRIstr "S"
+#define PRIwcs "s"
#endif
#else
#define MAIN main
#define FSTAT64(X,Y) fstat64((X),(Y))
#define STAT64_T struct stat64
#define PRIstr "s"
+#define PRIwcs "ls"
#endif
#define T(X) _T(X)
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a4a3879c-bd2c-4304-af66-7349cef7e4c0}</ProjectGuid>
<RootNamespace>libMCrypt</RootNamespace>
- <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>libmcrypt-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>libmcrypt-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>libmcrypt-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)obj\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
+ <TargetName>libmcrypt-1</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
#include <string.h>
const char* const LIBMCRYPT_VERSION = "1.0.0";
-const char* const LIBMCRYPT_BUILDNO = __DATE__" "__TIME__;
+const char* const LIBMCRYPT_BUILDNO = __DATE__", "__TIME__;
typedef struct
{
#ifdef __unix__
#include <unistd.h>
#include <fcntl.h>
+#if (defined(__GLIBC__) && defined(__GLIBC_MINOR__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25)) || (defined(__FreeBSD__) && (__FreeBSD__ >= 12))
+#define HAVE_GENRANDOM_SYSCALL 1
+#include <sys/random.h>
+#else
+#undef HAVE_GENRANDOM_SYSCALL
+#endif
#endif
int mcrypt_random_bytes(uint8_t* const buffer, const size_t length)
return 0;
#else
#ifdef __unix__
- static const char* const PATH[] = { "/dev/urandom", "/dev/random" };
+#ifdef HAVE_GENRANDOM_SYSCALL
+ if (getrandom(buffer, length, 0U) >= length)
+ {
+ return 0;
+ }
+ return -1;
+#else
+ static const char* const PATH[] = { "/dev/urandom", "/dev/arandom", "/dev/random" };
int result = -1;
- for (size_t i = 0; (i < 2U) && (result < 0); ++i)
+ for (size_t i = 0; (i < 3U) && (result < 0); ++i)
{
const int fd = open(PATH[i], O_RDONLY);
if (fd >= 0)
}
}
return result;
+#endif
#else
#error Unsupported target platform!
#endif