Skip to content

Commit

Permalink
Merge branch 'master' of ssh://home/home/ashley/src/encrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
albinoloverats committed Jun 23, 2015
2 parents 9b94167 + 7f18a0c commit 6889e73
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 192 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: clean distclean

APP = encrypt
ALT = decrypt
ALT = decrypt

SOURCE = src/main.c src/init.c src/crypt.c src/encrypt.c src/decrypt.c src/crypt_io.c
GUI = src/gui-gtk.c
Expand Down
16 changes: 8 additions & 8 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@

#ifndef __bswap_64
#define __bswap_64(x) /*!< Define ourselves a 8-byte swap macro */ \
((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
( (((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
#endif

#if __BYTE_ORDER == __LITTLE_ENDIAN || BYTE_ORDER == LITTLE_ENDIAN || _WIN32
Expand Down
60 changes: 30 additions & 30 deletions src/common/non-gnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ char *strchrnul(const char *s, int c_in)
/* Handle the first few characters by reading one character at a time.
Do this until CHAR_PTR is aligned on a longword boundary. */
for (char_ptr = (const unsigned char *) s;
((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0;
++char_ptr)
if (*char_ptr == c || *char_ptr == '\0')
((unsigned long int) char_ptr & (sizeof (longword) - 1)) != 0;
++char_ptr)
if (*char_ptr == c || *char_ptr == '\0')
return (void *) char_ptr;

/* All these elucidatory comments refer to 4-byte longwords,
Expand All @@ -78,27 +78,27 @@ char *strchrnul(const char *s, int c_in)
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
switch (sizeof (longword))
{
case 4: magic_bits = 0x7efefeffL; break;
case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
default:
abort ();
}
{
case 4: magic_bits = 0x7efefeffL; break;
case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
default:
abort ();
}

/* Set up a longword, each of whose bytes is C. */
charmask = c | (c << 8);
charmask |= charmask << 16;
if (sizeof (longword) > 4)
/* Do the shift in two steps to avoid a warning if long has 32 bits. */
charmask |= (charmask << 16) << 16;
/* Do the shift in two steps to avoid a warning if long has 32 bits. */
charmask |= (charmask << 16) << 16;
if (sizeof (longword) > 8)
abort ();
abort ();

/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing
if *any of the four* bytes in the longword in question are zero. */
for (;;)
{
{
/* We tentatively exit the loop if adding MAGIC_BITS to
LONGWORD fails to change any of the hole bits of LONGWORD.
Expand Down Expand Up @@ -138,44 +138,44 @@ char *strchrnul(const char *s, int c_in)
/* Add MAGIC_BITS to LONGWORD. */
if ((((longword + magic_bits)

/* Set those bits that were unchanged by the addition. */
^ ~longword)
/* Set those bits that were unchanged by the addition. */
^ ~longword)

/* Look at only the hole bits. If any of the hole bits
are unchanged, most likely one of the bytes was a
zero. */
& ~magic_bits) != 0 ||
& ~magic_bits) != 0 ||

/* That caught zeroes. Now test for C. */
((((longword ^ charmask) + magic_bits) ^ ~(longword ^ charmask))
& ~magic_bits) != 0)
{
& ~magic_bits) != 0)
{
/* Which of the bytes was C or zero?
If none of them were, it was a misfire; continue the search. */

const unsigned char *cp = (const unsigned char *) (longword_ptr - 1);

if (*cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (*++cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (*++cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (*++cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (sizeof (longword) > 4)
{
{
if (*++cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (*++cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (*++cp == c || *cp == '\0')
return (char *) cp;
return (char *) cp;
if (*++cp == c || *cp == '\0')
return (char *) cp;
}
}
}
return (char *) cp;
}
}
}

/* This should never happen. */
return NULL;
Expand Down
6 changes: 1 addition & 5 deletions src/common/win32_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ extern char *strndup(const char *s, size_t l)
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
extern int scandir(const char *path,
struct dirent ***res,
int (*sel)(const struct dirent *),
int (*cmp)(const struct dirent **,
const struct dirent **))
extern int scandir(const char *path, struct dirent ***res, int (*sel)(const struct dirent *), int (*cmp)(const struct dirent **, const struct dirent **))
{
DIR *d = opendir(path);
struct dirent *de, **names = 0, **tmp;
Expand Down
10 changes: 2 additions & 8 deletions src/common/win32_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,12 @@
#define __LITTLE_ENDIAN 1234 /*!< Not defined in MinGW, so set here */
#define __BYTE_ORDER __LITTLE_ENDIAN /*!< Windows is almost always going to be LE */

#define __bswap_16(x) /*!< Define ourselves a 2-byte swap macro */ \
((((x) & 0xff00) >> 8)\
| (((x) & 0x00ff) << 8))
#define __bswap_16(x) /*!< Define ourselves a 2-byte swap macro */ ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8))

#define ntohs(x) __bswap_16(x) /*!< Make sure that network-to-host-short exists */
#define htons(x) __bswap_16(x) /*!< Make sure that host-to-network-short exists */

#define __bswap_32(x) /*!< Define ourselves a 4-byte swap macro */ \
((((x) & 0xff000000ul) >> 24) \
| (((x) & 0x00ff0000ul) >> 8) \
| (((x) & 0x0000ff00ul) << 8) \
| (((x) & 0x000000fful) << 24))
#define __bswap_32(x) /*!< Define ourselves a 4-byte swap macro */ ((((x) & 0xff000000ul) >> 24) | (((x) & 0x00ff0000ul) >> 8) | (((x) & 0x0000ff00ul) << 8) | (((x) & 0x000000fful) << 24))

#define ntohl(x) __bswap_32(x) /*!< Make sure that network-to-host-long exists */
#define htonl(x) __bswap_32(x) /*!< Make sure that host-to-network-long exists */
Expand Down
22 changes: 11 additions & 11 deletions src/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ file_type_e;
*/
typedef enum
{
VERSION_UNKNOWN = 0, /*!< Unknown version, or not encrypted */
VERSION_2011_08, /*!< Version 2011.08 */
VERSION_2011_10, /*!< Version 2011.10 */
VERSION_2012_11, /*!< Version 2012.11 */
VERSION_2013_02, /*!< Version 2013.02 */
VERSION_2013_11, /*!< Version 2013.11 */
VERSION_2014_06, /*!< Version 2014.06 */
VERSION_2015_01, /*!< Version 2015.01 */
VERSION_UNKNOWN = 0, /*!< Unknown version, or not encrypted */
VERSION_2011_08, /*!< Version 2011.08 */
VERSION_2011_10, /*!< Version 2011.10 */
VERSION_2012_11, /*!< Version 2012.11 */
VERSION_2013_02, /*!< Version 2013.02 */
VERSION_2013_11, /*!< Version 2013.11 */
VERSION_2014_06, /*!< Version 2014.06 */
VERSION_2015_01, /*!< Version 2015.01 */

VERSION_CURRENT = VERSION_2015_01 /*!< Next release / current development version */
}
Expand All @@ -138,9 +138,9 @@ typedef enum
TAG_COMPRESSED, /*!< Data is compressed */
TAG_DIRECTORY, /*!< Data is a directory hierarchy */
TAG_FILENAME /*!< Single file name */
/*
* TODO add tags for stat data (mode, atime, ctime, mtime)
*/
/*
* TODO add tags for stat data (mode, atime, ctime, mtime)
*/
} __attribute__((packed))
stream_tags_e;

Expand Down
16 changes: 1 addition & 15 deletions src/crypt_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,7 @@ extern bool io_is_stdout(IO_HANDLE ptr)
return io_ptr->fd == STDOUT_FILENO;
}

extern void io_encryption_init(IO_HANDLE ptr,
enum gcry_cipher_algos c,
enum gcry_md_algos h,
enum gcry_cipher_modes m,
const uint8_t *k,
size_t l,
io_extra_t x)
extern void io_encryption_init(IO_HANDLE ptr, enum gcry_cipher_algos c, enum gcry_md_algos h, enum gcry_cipher_modes m, const uint8_t *k, size_t l, io_extra_t x)
{
io_private_t *io_ptr = ptr;
if (!io_ptr || io_ptr->fd < 0)
Expand Down Expand Up @@ -346,13 +340,10 @@ extern ssize_t io_write(IO_HANDLE f, const void *d, size_t l)
if (!io_ptr->lzma_init)
io_do_compress(io_ptr);
return lzma_write(io_ptr, d, l);

case IO_ENCRYPT:
return enc_write(io_ptr, d, l);

case IO_DEFAULT:
return write(io_ptr->fd, d, l);

}
errno = EINVAL;
return -1;
Expand All @@ -372,15 +363,12 @@ extern ssize_t io_read(IO_HANDLE f, void *d, size_t l)
io_do_decompress(io_ptr);
r = lzma_read(io_ptr, d, l);
break;

case IO_ENCRYPT:
r = enc_read(io_ptr, d, l);
break;

case IO_DEFAULT:
r = read(io_ptr->fd, d, l);
break;

default:
errno = EINVAL;
r = -1;
Expand All @@ -401,10 +389,8 @@ extern int io_sync(IO_HANDLE ptr)
{
case IO_LZMA:
return lzma_sync(io_ptr);

case IO_ENCRYPT:
return enc_sync(io_ptr);

case IO_DEFAULT:
return fsync(io_ptr->fd);
}
Expand Down
8 changes: 1 addition & 7 deletions src/crypt_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,7 @@ extern off_t io_seek(IO_HANDLE f, off_t o, int w) __attribute__((nonnull(1)));
* Initialise encryption/decryption of data read/written. This is then
* active for the rest of the life of the IO_HANDLE.
*/
extern void io_encryption_init(IO_HANDLE f,
enum gcry_cipher_algos c,
enum gcry_md_algos h,
enum gcry_cipher_modes m,
const uint8_t *k,
size_t l,
io_extra_t x) __attribute__((nonnull(1, 5)));
extern void io_encryption_init(IO_HANDLE f, enum gcry_cipher_algos c, enum gcry_md_algos h, enum gcry_cipher_modes m, const uint8_t *k, size_t l, io_extra_t x) __attribute__((nonnull(1, 5)));

/*
* \brief Compression initialisation
Expand Down
10 changes: 1 addition & 9 deletions src/decrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,7 @@ static void decrypt_directory(crypto_t *, const char *);
static void decrypt_stream(crypto_t *);
static void decrypt_file(crypto_t *);

extern crypto_t *decrypt_init(const char * const restrict i,
const char * const restrict o,
const char * const restrict c,
const char * const restrict h,
const char * const restrict m,
const void * const restrict k,
size_t l,
bool n)
extern crypto_t *decrypt_init(const char * const restrict i, const char * const restrict o, const char * const restrict c, const char * const restrict h, const char * const restrict m, const void * const restrict k, size_t l, bool n)
{
init_crypto();

Expand Down Expand Up @@ -215,7 +208,6 @@ static void *process(void *ptr)
*/
break;
}

/*
* the 2011.* versions (incorrectly) used key length instead of block
* length
Expand Down
9 changes: 1 addition & 8 deletions src/decrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@
* the encrypted file; the only reason to set them is if there is no
* header information.
*/
extern crypto_t *decrypt_init(const char * const restrict i,
const char * const restrict o,
const char * const restrict c,
const char * const restrict h,
const char * const restrict m,
const void * const restrict k,
size_t l,
bool n) __attribute__((nonnull(6)));
extern crypto_t *decrypt_init(const char * const restrict i, const char * const restrict o, const char * const restrict c, const char * const restrict h, const char * const restrict m, const void * const restrict k, size_t l, bool n) __attribute__((nonnull(6)));

#endif /* ! _ENCRYPT_DECRYPT_H_ */
16 changes: 1 addition & 15 deletions src/encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,7 @@ typedef struct
}
link_count_t;

extern crypto_t *encrypt_init(const char * const restrict i,
const char * const restrict o,
const char * const restrict c,
const char * const restrict h,
const char * const restrict m,
const void * const restrict k,
size_t l,
bool n,
bool x,
bool f,
version_e v)
extern crypto_t *encrypt_init(const char * const restrict i, const char * const restrict o, const char * const restrict c, const char * const restrict h, const char * const restrict m, const void * const restrict k, size_t l, bool n, bool x, bool f, version_e v)
{
init_crypto();

Expand Down Expand Up @@ -222,7 +212,6 @@ extern crypto_t *encrypt_init(const char * const restrict i,
z->version = VERSION_2011_08;
z->mode = mode_id_from_name("CBC");
break;

case VERSION_2013_02:
z->follow_links = true;
/* allow fall-through to force CBC mode */
Expand All @@ -241,7 +230,6 @@ extern crypto_t *encrypt_init(const char * const restrict i,
* allows extra padding at beginning of file
*/
break;

default:
die(_("We’ve reached an unreachable location in the code @ %s:%d:%s"), __FILE__, __LINE__, __func__);
}
Expand Down Expand Up @@ -270,13 +258,11 @@ static void *process(void *ptr)
case VERSION_2012_11:
pre_random = false;
break;

case VERSION_2013_02:
case VERSION_2013_11:
case VERSION_2014_06:
iv_type = IV_SIMPLE;
break;

case VERSION_2015_01:
default:
/* no changes */
Expand Down
12 changes: 1 addition & 11 deletions src/encrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@
* ready to be executed. Any other status is a failure. If the input and
* output file names are NULL, stdin/stdout will be used instead.
*/
extern crypto_t *encrypt_init(const char * const restrict i,
const char * const restrict o,
const char * const restrict c,
const char * const restrict h,
const char * const restrict m,
const void * const restrict k,
size_t l,
bool n,
bool x,
bool f,
version_e v) __attribute__((nonnull(3, 4, 5, 6)));
extern crypto_t *encrypt_init(const char * const restrict i, const char * const restrict o, const char * const restrict c, const char * const restrict h, const char * const restrict m, const void * const restrict k, size_t l, bool n, bool x, bool f, version_e v) __attribute__((nonnull(3, 4, 5, 6)));

#endif /* ! _ENCRYPT_ENCRYPT_H */
Loading

0 comments on commit 6889e73

Please sign in to comment.