Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

ecryptfs-setup-private will by default use an AES 128 bit key.

Can I make it use a 256 bit key (32 bytes key length)?

Of course, I could do the whole process manually as described here: https://wiki.archlinux.org/index.php/System_Encryption_with_eCryptfs#Setup_.28in_detail.29

But I want to have the convenience of using ecryptfs's easy to use tools but just with a stronger encryption key.

I tried modifying /usr/bin/ecryptfs-setup-private (changing KEYBYTES="16" to KEYBYTES="32" inside), but the process of creating the Private/.Private directories will fail.

share|improve this question
1  
Note that there is no practical security benefit to using AES-256 over AES-128. Using a 256-bit key will make your system a bit slower, but it will not make it more secure. See e.g. Amount of simple operations that is safely out of reach for all humanity? –  Gilles May 12 '12 at 17:32
    
@Gilles That article makes a boatload of assumptions. Things can go wrong basically with each of his assumptions. My personal paranoia level requires all the security I can get. –  user12681 May 13 '12 at 16:34
    
Thomas Pornin is a professional cryptographer, he knows when your paranoia is misplaced. You're putting faith in having a bigger number without understanding what this number means. –  Gilles May 13 '12 at 17:37
    
@Gilles I'm actually a trained computer scientist myself, so I'm not totally clueless about this. The idea is that there are a lot of assumptions in his text and my personal paranoia level is high. So, in short, I just want the biggest number possible. The idea is that I'm not satisfied even with 256, but as I said, the idea is just all the security I can get. –  user12681 May 14 '12 at 18:34
    
@Gilles And he doesn't even mention potential flaws that might be found in AES in the future. Which could make (pie in the sky estimate) 256 bit just as safe as 64 bit is now thought of as. And my personal paranoia can find many other such quibbles if I get down to it. –  user12681 May 14 '12 at 18:52

2 Answers 2

up vote 5 down vote accepted

The short answer is 'no'. When I wrote ecryptfs-setup-private, I chose a set of defaults for eCryptfs that I considered sensible, secure and supportable for millions of Ubuntu users who wouldn't care much about tunables over the long haul. This limited the number of configuration combinations we had to test and support.

As you've noted, eCryptfs is very configurable if you read the docs and mount manually, while the Ubuntu Encrypted Private/Home feature has a consistent set of options everywhere.

Moreover, Bruce Schneier has recommended against using AES256, in favor of AES128:

And for new applications I suggest that people don't use AES-256. AES-128 provides more than enough security margin for the forseeable future.

share|improve this answer
1  
Thanks, for your answer, didn't expect to actually encounter the person who wrote the script! But the ecryptfs-setup-private is accepting many parameters. Why not add this one as well (for the paranoid users)? –  user12681 May 13 '12 at 16:37

Well, the long answer may be "yes, but be aware of losing compatibility to 16 byte encoded directories".

Applying the following patch against the recent ecryptfs-utils-104 sources should do the job - however, it simply changes the hardcoded value to 32 without the possibility to choose. But if it's useful to someone:

diff -ruN ecryptfs-utils-104/README ecryptfs-utils-104-32byte/README
--- ecryptfs-utils-104/README   2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/README    2015-01-23 05:43:43.206773596 +0100
@@ -278,13 +278,13 @@
 You should get something like this:

 ---
-/secret /secret ecryptfs rw,ecryptfs_sig=deadbeefdeadbeef,ecryptfs_key_bytes=16,ecryptfs_cipher=aes 0 0
+/secret /secret ecryptfs rw,ecryptfs_sig=deadbeefdeadbeef,ecryptfs_key_bytes=32,ecryptfs_cipher=aes 0 0
 ---

 Add ``user'' and ``noauto'' to the mount options:

 ---
-/secret /secret ecryptfs user,noauto,rw,ecryptfs_sig=deadbeefdeadbeef,ecryptfs_key_bytes=16,ecryptfs_cipher=aes 0 0
+/secret /secret ecryptfs user,noauto,rw,ecryptfs_sig=deadbeefdeadbeef,ecryptfs_key_bytes=32,ecryptfs_cipher=aes 0 0
 ---

 Append your edited line to your /etc/fstab file. Now it's time to test
diff -ruN ecryptfs-utils-104/doc/manpage/mount.ecryptfs_private.1 ecryptfs-utils-104-32byte/doc/manpage/mount.ecryptfs_private.1
--- ecryptfs-utils-104/doc/manpage/mount.ecryptfs_private.1 2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/doc/manpage/mount.ecryptfs_private.1  2015-01-23 05:43:43.206773596 +0100
@@ -29,7 +29,7 @@
   - mount SOURCE onto DESTINATION
   - as an ecryptfs filesystem
   - using the AES cipher
-  - with a key length of 16 bytes
+  - with a key length of 32 bytes
   - using the passphrase whose signature is in ~/.ecryptfs/Private.sig

 The only setuid operation in this program is the call to \fBmount\fP(8) or \fBumount\fP(8).
diff -ruN ecryptfs-utils-104/src/include/ecryptfs.h ecryptfs-utils-104-32byte/src/include/ecryptfs.h
--- ecryptfs-utils-104/src/include/ecryptfs.h   2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/src/include/ecryptfs.h    2015-01-23 05:43:43.207773542 +0100
@@ -144,7 +144,7 @@
 #define ECRYPTFS_ECHO_OFF 0

 #define ECRYPTFS_AES_BLOCK_SIZE 16
-#define ECRYPTFS_AES_KEY_BYTES 16
+#define ECRYPTFS_AES_KEY_BYTES 32

 #define ECRYPTFS_DEFAULT_WRAPPED_PASSPHRASE_FILENAME "wrapped-passphrase"

diff -ruN ecryptfs-utils-104/src/utils/ecryptfs-recover-private ecryptfs-utils-104-32byte/src/utils/ecryptfs-recover-private
--- ecryptfs-utils-104/src/utils/ecryptfs-recover-private   2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/src/utils/ecryptfs-recover-private    2015-01-23 05:43:43.207773542 +0100
@@ -101,12 +101,12 @@
        1)
            mount_sig=$(echo "$sigs" | head -n1)
            fnek_sig=
-           mount_opts="$opts,ecryptfs_sig=$mount_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=16"
+           mount_opts="$opts,ecryptfs_sig=$mount_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=32"
        ;;
        2)
            mount_sig=$(echo "$sigs" | head -n1)
            fnek_sig=$(echo "$sigs" | tail -n1)
-           mount_opts="$opts,ecryptfs_sig=$mount_sig,ecryptfs_fnek_sig=$fnek_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=16"
+           mount_opts="$opts,ecryptfs_sig=$mount_sig,ecryptfs_fnek_sig=$fnek_sig,ecryptfs_cipher=aes,ecryptfs_key_bytes=32"
        ;;
        *)
            continue
diff -ruN ecryptfs-utils-104/src/utils/ecryptfs-setup-private ecryptfs-utils-104-32byte/src/utils/ecryptfs-setup-private
--- ecryptfs-utils-104/src/utils/ecryptfs-setup-private 2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/src/utils/ecryptfs-setup-private  2015-01-23 05:43:43.208773488 +0100
@@ -13,7 +13,8 @@
 TEXTDOMAIN="ecryptfs-utils"
 MESSAGE="$(gettext 'Enter your login passphrase')"
 CIPHER="aes"
-KEYBYTES="16"
+KEYBYTES="32"
+SIGBYTES="16"
 FNEK=

 # Zero out user-defined GREP_OPTIONS, such as --line-number
@@ -97,7 +98,8 @@
    bytes=$1
    # Pull $1 of random data from /dev/urandom,
    # and convert to a string of hex digits
-   od -x -N $bytes --width=$bytes /dev/urandom | head -n 1 | sed "s/^0000000//" | sed "s/\s*//g"
+   # od -x -N $bytes --width=$bytes /dev/urandom | head -n 1 | sed "s/^0000000//" | sed "s/\s*//g"
+   dd if=/dev/urandom bs=$[$bytes*3/2] count=1 status=none | base64
 }

 filename_encryption_available() {
@@ -393,7 +395,7 @@
    error "$(gettext 'Could not add passphrase to the current keyring')"
 fi
 sig=`echo "$response" | grep "Inserted auth tok" | sed "s/^.*\[//" | sed "s/\].*$//"`
-if ! echo "$sig" | egrep -qs "^[0-9a-fA-F]{$KEYBYTES,$KEYBYTES}$"; then
+if ! echo "$sig" | egrep -qs "^[0-9a-fA-F]{$SIGBYTES,$SIGBYTES}$"; then
    error "$(gettext 'Could not obtain the key signature')"
 fi
 temp=`mktemp`
diff -ruN ecryptfs-utils-104/src/utils/mount.ecryptfs_private.c ecryptfs-utils-104-32byte/src/utils/mount.ecryptfs_private.c
--- ecryptfs-utils-104/src/utils/mount.ecryptfs_private.c   2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/src/utils/mount.ecryptfs_private.c    2015-01-23 05:43:43.208773488 +0100
@@ -47,7 +47,8 @@
  * by the system administrator (or user?) at run time.  For now, these are set
  * to reasonable values to reduce the burden of input validation.
  */
-#define KEY_BYTES 16
+#define SIG_BYTES 16
+#define KEY_BYTES 32
 #define KEY_CIPHER "aes"
 #define FSTYPE "ecryptfs"
 #define TMP "/dev/shm"
@@ -159,13 +160,13 @@
    sig[0] = NULL;
    sig[1] = NULL;
    for (i=0; i<2; i++) {
-       if ((sig[i] = (char *)malloc(KEY_BYTES*sizeof(char)+2)) == NULL) {
+       if ((sig[i] = (char *)malloc(SIG_BYTES*sizeof(char)+2)) == NULL) {
            perror("malloc");
            goto err;
        }
-       memset(sig[i], '\0', KEY_BYTES+2);
-       /* Read KEY_BYTES characters from line */
-       if (fgets(sig[i], KEY_BYTES+2, fh) == NULL) {
+       memset(sig[i], '\0', SIG_BYTES+2);
+       /* Read SIG_BYTES characters from line */
+       if (fgets(sig[i], SIG_BYTES+2, fh) == NULL) {
            if (i == 0) {
                fputs("Missing file encryption signature", stderr);
                goto err;
@@ -187,7 +188,7 @@
                sig[i][j] = '\0';
            }
        }
-       if (strlen(sig[i]) > 0 && strlen(sig[i]) != KEY_BYTES) {
+       if (strlen(sig[i]) > 0 && strlen(sig[i]) != SIG_BYTES) {
            fputs("Invalid hex signature length\n", stderr);
            goto err;
        }
@@ -489,7 +490,7 @@
  *  - mounts ~/.Private onto ~/Private
  *    - as an ecryptfs filesystem
  *    - using the AES cipher
- *    - with a key length of 16 bytes
+ *    - with a key length of 32 bytes
  *    - and using the signature defined in ~/.ecryptfs/Private.sig
  *    - ONLY IF the user
  *      - has the signature's key in his keyring
diff -ruN ecryptfs-utils-104/tests/lib/etl_funcs.sh ecryptfs-utils-104-32byte/tests/lib/etl_funcs.sh
--- ecryptfs-utils-104/tests/lib/etl_funcs.sh   2014-01-23 19:09:48.000000000 +0100
+++ ecryptfs-utils-104-32byte/tests/lib/etl_funcs.sh    2015-01-23 05:43:43.209773433 +0100
@@ -32,7 +32,7 @@
 default_ext2_opts="user_xattr,acl"
 default_ext3_opts="user_xattr,acl,commit=600,barrier=1,data=ordered"
 default_btrfs_opts="nodatacow"
-default_mount_opts="rw,relatime,ecryptfs_cipher=aes,ecryptfs_key_bytes=16,ecryptfs_sig=\${ETL_FEKEK_SIG}"
+default_mount_opts="rw,relatime,ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_sig=\${ETL_FEKEK_SIG}"
 default_fne_mount_opts="${default_mount_opts},ecryptfs_fnek_sig=\${ETL_FNEK_SIG}"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.