CRC32: Prevent decompression of data used in CRC32 calculation on host. This leads to false negatives with TrueCrypt/VeraCrypt keyfiles

pull/2593/head^2
Jens Steube 3 years ago
parent e79a2aa90c
commit f54643479d

@ -29,6 +29,7 @@
- UTF8-to-UTF16: Replaced naive UTF8 to UTF16 conversion with true conversion for RAR3, AES Crypt, MultiBit HD (scrypt) and Umbraco HMAC-SHA1
- AES Crypt Plugin: Reduced max password length from 256 to 128 which improved performance by 22%
- RAR3-p (Compressed): Fix workaround in unrar library in AES constant table generation to enable multi-threading support
- CRC32: Prevent decompression of data used in CRC32 calculation on host. This leads to false negatives with TrueCrypt/VeraCrypt keyfiles
##
## Technical

@ -15,22 +15,23 @@
int _wopen (const char *path, int oflag, ...);
#endif
bool hc_fopen (HCFILE *fp, const char *path, char *mode);
int hc_fscanf (HCFILE *fp, const char *format, void *ptr);
int hc_fprintf (HCFILE *fp, const char *format, ...);
int hc_vfprintf (HCFILE *fp, const char *format, va_list ap);
int hc_fseek (HCFILE *fp, off_t offset, int whence);
void hc_rewind (HCFILE *fp);
off_t hc_ftell (HCFILE *fp);
int hc_fgetc (HCFILE *fp);
int hc_fileno (HCFILE *fp);
int hc_feof (HCFILE *fp);
void hc_fflush (HCFILE *fp);
void hc_fclose (HCFILE *fp);
int hc_fputc (int c, HCFILE *fp);
char *hc_fgets (char *buf, int len, HCFILE *fp);
size_t hc_fwrite (const void *ptr, size_t size, size_t nmemb, HCFILE *fp);
size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp);
bool hc_fopen (HCFILE *fp, const char *path, char *mode);
bool hc_fopen_nozip (HCFILE *fp, const char *path, char *mode);
int hc_fscanf (HCFILE *fp, const char *format, void *ptr);
int hc_fprintf (HCFILE *fp, const char *format, ...);
int hc_vfprintf (HCFILE *fp, const char *format, va_list ap);
int hc_fseek (HCFILE *fp, off_t offset, int whence);
void hc_rewind (HCFILE *fp);
off_t hc_ftell (HCFILE *fp);
int hc_fgetc (HCFILE *fp);
int hc_fileno (HCFILE *fp);
int hc_feof (HCFILE *fp);
void hc_fflush (HCFILE *fp);
void hc_fclose (HCFILE *fp);
int hc_fputc (int c, HCFILE *fp);
char *hc_fgets (char *buf, int len, HCFILE *fp);
size_t hc_fwrite (const void *ptr, size_t size, size_t nmemb, HCFILE *fp);
size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp);
size_t fgetl (HCFILE *fp, char *line_buf, const size_t line_sz);
u64 count_lines (HCFILE *fp);

@ -94,7 +94,7 @@ int cpu_crc32 (const char *filename, u8 keytab[64])
HCFILE fp;
hc_fopen (&fp, filename, "rb");
hc_fopen_nozip (&fp, filename, "rb");
#define MAX_KEY_SIZE (1024 * 1024)

@ -113,6 +113,68 @@ bool hc_fopen (HCFILE *fp, const char *path, char *mode)
return true;
}
bool hc_fopen_nozip (HCFILE *fp, const char *path, char *mode)
{
if (path == NULL || mode == NULL) return false;
int oflag = -1;
int fmode = S_IRUSR|S_IWUSR;
if (strncmp (mode, "a", 1) == 0 || strncmp (mode, "ab", 2) == 0)
{
oflag = O_WRONLY | O_CREAT | O_APPEND;
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
if (strncmp (mode, "ab", 2) == 0) oflag |= O_BINARY;
#endif
}
else if (strncmp (mode, "r", 1) == 0 || strncmp (mode, "rb", 2) == 0)
{
oflag = O_RDONLY;
fmode = -1;
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
if (strncmp (mode, "rb", 2) == 0) oflag |= O_BINARY;
#endif
}
else if (strncmp (mode, "w", 1) == 0 || strncmp (mode, "wb", 2) == 0)
{
oflag = O_WRONLY | O_CREAT | O_TRUNC;
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
if (strncmp (mode, "wb", 2) == 0) oflag |= O_BINARY;
#endif
}
else
{
// ADD more strncmp to handle more "mode"
return false;
}
fp->pfp = NULL;
fp->is_gzip = false;
fp->is_zip = false;
if (fmode == -1)
{
fp->fd = open (path, oflag);
}
else
{
fp->fd = open (path, oflag, fmode);
}
if (fp->fd == -1 && fp->is_zip == false) return false;
if ((fp->pfp = fdopen (fp->fd, mode)) == NULL) return false;
fp->path = path;
fp->mode = mode;
return true;
}
size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
{
size_t n = -1;

Loading…
Cancel
Save