<!doctype linuxdoctr system>

<!-- Loopback Encrypted Filesystem HOWTO by Ryan T. Rhea -->

<article>

<!-- Title information -->

<title>Loopback Encrypted Filesystem HOWTO
<author>Copyright by Ryan T. Rhea,
<tt/rhear@cs.winthrop.edu/
<date>v1.1, 29 November 1999
<trans>Linux JF Project <tt/JF@linux.or.jp/
<tdate>v1.1, 30 November 1999

<abstract>
<!--O
This document explains how to setup and then use a filesystem
that, when mounted by a user, dynamically and transparently
encrypts its contents.  The filesystem is stored in a regular
file, which can be hidden or named non-conspicuously such that it
would most likely be overlooked.  This allows for a high level of
secure storage of data.
-->
この文書は，ユーザがマウントしたときに，その内容を動的かつ透過的に
暗号化するファイルシステムの設定方法と使用方法を説明します．
このファイルシステムは通常ファイルの中に置かれるので，隠しファイルにし
たり目立たない名前を付けたりして，ほとんど見つからないようにすることが
できます．
この方法により，データを非常に安全に保持することが可能です．
</abstract>

<!-- Table of contents -->
<toc>

<!-- Begin the document -->

<!--O
<sect>Before you begin
-->
<sect>始める前に

<p>
<!--O
This process requires the kernel source code, knowledge of
compiling this
code, and a lot of patience.  I highly recommend having a boot
disk ready. 
Also, be sure to have a backup before you permanently store your
important
data on the encrypted filesystem - it can be corrupted like any
other
filesystem.
-->
この処理を行うにはカーネルのソースコード，カーネルのコンパイルに関する
知識，それからかなりの根気が必要です．起動ディスクを用意しておくこ
とを筆者はお勧めします．また，重要なデータを暗号化したファイルシステム
に移す前には，必ずバックアップを取っておきましょう．
他のファイルシステムと同様に壊れるかもしれないからです．

<!--O
As a minimum, you will have to patch to at least version 2.2.9 of
the linux
kernel before continuing.  There are further instructions on
applying patches
in the <ref id="Details"> section later in this document.
-->
まず最初に，Linux カーネルにパッチを当ててバージョンを少なくとも 2.2.9 
以上にしておかなければなりません．パッチを当てる詳しい手順は，
この文書の<!-- REF --><ref id="Details" name="詳細な手順">の節で後述します．

<!--O
Kernel source can be found at:
-->
カーネルのソースコードは以下の場所にあります:

<tscreen>
<url url="ftp://ftp.kerneli.org/">
</tscreen>

<!--O
There is a HOWTO on the process of recompiling kernels at:
-->
カーネルの再コンパイル手順に関する HOWTO 文書は以下の場所から入手できます:

<tscreen>
<url url="http://metalab.unc.edu/LDP/HOWTO/">
</tscreen>

<!--O
This document may be reproduced and distributed in whole or in
part, without fee, subject to the following conditions:
-->
本文書の全体または一部は，以下の条件の下において，無料で複製・配布して
もかまいません．

<itemize>
<!--O
<item>The copyright notice and this permission notice must be
preserved complete on all complete or partial copies.
-->
<item>本文書の全体あるいは一部をコピーした場合は，著作権表示とこの許諾
表示を残さなければなりません．

<!--O
<item>Any translation or derived work must be approved by the
author
in writing before distribution.
-->
<item>翻訳または派生物については，配布を行う前に著者の承認が必要です．

<!--O
<item>If you distribute this work in part, instructions for
obtaining
he complete version of this manual must be included, and a means
for obtaining a complete version provided.
-->
<item>本文書の一部分を配布する場合には，本文書の完全な版を入手する手順
を含めなければなりません．また，完全な版を得る手段を提供しなければなり
ません．

<!--O
<item>All source code in this document is placed under the GNU
General Public License, available via anonymous FTP from:
-->
<item>本文書に書かれた全てのソースコードは GNU General Public License
に従います．このライセンスは以下の場所から anonymous FTP を使って入手
できます:
</itemize>

<tscreen>
<url url="ftp://prep.ai.mit.edu/pub/gnu/COPYING/">
</tscreen>

<!--O
<sect>Introduction
-->
<sect>はじめに

<p>
<!--O
The process uses the device '/dev/loop*' (where * can be 0-7 on
most installations) to mount a loopback filesystem.  The same
process can be used without encryption to store a linux
filesystem on a non-linux partition.  There is a HOWTO on this at
the LDP site mentioned previously.
-->
今回の作業では，`/dev/loop*' デバイス(普通にインストールしていれば *
は 0 から 7 まででしょう)を使ってループバックファイルシステムをマウン
トします．この作業は暗号化を用いずに行うこともでき，Linux ファイルシス
テムを Linux 以外のパーティションに置くことができます．これについて述べ
た HOWTO 文書が以前は LDP にありました．

<!--O
Different types of encryption can be used, including XOR, DES,
twofish, blowfish, cast128, serpent, MARS, RC6, DFC, and IDEA.
The program 'losetup' (loopback setup) is what associates your
encrypted file with a filesystem and it's cipher type.  According
to Alexander
Kjeldaas, who maintains kerneli.org and the international crypto
patches, DES
and losetup are currently incompatible.  This is due to
differences in the way
the two handle parity bits.  There are no plans to support DES as
it is much
more insecure than the other ciphers.  
-->
何種類かの暗号を使えます．例えば XOR, DES, twofish,
blowfish, cast128, serpent, MARS, RC6, DFC, IDEA などです．
暗号化されたファイルと，その中に含まれるファイルシステムや暗号の種類を
関連付けるのは `losetup' (loopback setup)プログラムの役割です．
kerneli.org と国際版の crypto パッチを管理している Alexander Kjeldaas 
によると，現在は DES と losetup は組み合わせられません．これは両者にお
けるパリティビットの扱いが異なるためです．DES は他の暗号と比べて安全性
がずっと劣るので，DES をサポートする計画はありません．

<!--O
Twofish, blowfish, cast128, and serpent are all licensed free for
any use. 
The others may or may not have licensing restrictions.  Several
of them are
candidates for the AES standard.  The finalists will provide
royalty free use
of their ciphers worldwide.
-->
Twofish, blowfish, cast128, serpent は，目的を問わずに自由に使えるライ
センスです．他はライセンスに制限が不明です．
これらのいくつかは，AES 標準の候補です．
最終的に勝ち残った暗号は，使用料なしで世界中で使えるようになるでしょう．

<!--O
This document uses the serpent algorithm because it is strong yet
remarkably fast, and it's freely distributable under the GPL. 
According to
it's documentation, serpent uses a 128-bit block cipher designed
by Ross
Anderson, Eli Biham and Lars Knudsen.  It provides users with the
highest
practical level of assurance that no shortcut attacks will be
found.  The
documentation on serpent as well as the source code can be found
at:
-->
本文書では serpent アルゴリズムを利用します．なぜなら，この暗号は
強度が高い上に極めて高速で，かつ GPL の下で自由に配布できるからです．
serpent 付属の文書によると，serpent は
Ross Anderson, Eli Biham, Lars Knudsen が設計した 128 ビットブロック
の暗号を使っています．この暗号は，抜け道を使った攻撃がないことを実用最
高級のレベルで保証しています．
serpent に関する文書とソースコードは以下の場所から入手できます:

<tscreen>
<url url="http://www.cl.cam.ac.uk/~rja14/serpent.html">
</tscreen>

<!--O
Also, this document assumes that the ciphers are compiled
directly into the
kernel.  You may install them as modules, but the technique is
not discussed
in this document.  You will have to edit the file
'/etc/conf.module'; the
process is discussed in detail in the kernel compilation HOWTO
referenced previously.
-->
また本文書では，暗号化の機構は直接カーネルに組み込まれるものとします．
これはモジュールとしてもインストールできますが，その方法は本文書では
説明しません．`/etc/conf.module' ファイルを編集する必要があるでしょう．
この手順は，先に述べたカーネルのコンパイルに関する HOWTO 文書で詳しく
説明されています．

<!--O
<sect>Summary
-->
<sect>手順のまとめ

<p>
<!--O
There are many steps involved in the process.  I will provide
<ref id="Details"> for these steps in the next section. I thought
it would
be nice to provide a summary first to provide reference (if you
are experienced with unix/linux you probably don't need the
details anyway).  Here they are summarized as follows:
-->
作業はいくつかの手順からなります．それぞれの手順については，次の節
<!-- REF --><ref id="Details" name="詳細な手順">で説明します．
リファレンスとしてまとめを最初に用意しておくといいだろうと考えました
(もし読者の皆さんの UNIX/Linux の経験が豊富ならば，いずれにせよ細かい
説明は不要でしょう)．では，まとめを以下に示します:

<enum>
<!--O
<item>Download the newest international crypto patch (I used
'patch-int-2.2.10.4' at the time this document was written) from: 
-->
<item>国際版暗号パッチの最新版を以下の場所からダウンロードします(本文
書の執筆時点では `patch-int-2.2.10.4' を用いました):

<p><tscreen>
<url url="http://ftp.kerneli.org/pub/kerneli/">
</tscreen>

<!--O
<p><item>Patch the kernel
-->
<p><item>カーネルにパッチを当てます

<!--O
<p><item>Run 'config' (or 'menuconfig' or 'xconfig') to configure
your
'MakeFile' for the new kernel.  The options to enable encryption
are
scattered.  First of all, before you will see any other options
you must
enable 'Prompt for development and/or incomplete code/drivers'
under 'Code
Maturity level options'.  Under 'Crypto options' enable 'crypto
ciphers' and
'serpent'.  Once again, this document assumes you are using
serpent, but try
whatever you want.  Remember that DES is known to be incompatible
as of
2.2.10.4 - it may never be supported at all.  There are several
important options to select under 'Block Devices'.  These include
'Loopback
device support', 'Use relative block numbers as basis for
transfer functions
(RECOMMENDED)', and 'General encryption support'.  DO NOT select
'cast 128' or
'twofish' encryption here.  Also note that you don't need any of
the crypto
options under the various network categories.  I will not go  any
further into
configuration of the kernel, it is out of the scope of this
document and can
be found at the LDP site.
-->
<p><item>`make config'(または `menuconfig' や `xconfig')を実行して，新しい
カーネル用の `Makefile' を設定します．暗号化を有効にするためのオプ
ションは，あちこちに散らばっています．まずはともかく，どのオプションよ
りも前に `Code Maturity level options'
の下の `Prompt for development and/or incomplete code/drivers' を有効
にしてください．
次に，`Crypto options' の下の `crypto ciphers' と `serpent'
を有効にします．繰り返しますが，本文書では serpent を使うものと
します．でも，読者の皆さんは好きなものを試してください．ただし 
2.2.10.4 の時点では DES とは組み合わせられないことを忘れないでください．
今後もまずサポートされることはないでしょう．`Block Devices' の下には，選択
すべき重要なオプションがいくつかあります．
`Loopback device support', `Use relative block numbers as basis for
transfer functions(RECOMMENDED)', `General encryption support'
です．ここでは `cast 128' や `twofish' は選択<em/しないで/ください．ネット
ワーク関連の各種項目の下にある暗号関係のオプションは，どれも選択する必
要はありません．カーネルの設定については，これ以上細かい部分には立ち入
りません．これは本文書の守備範囲ではないので，LDP のサイトにある他の文
書をご覧になってください．

<!--O
<p><item>Compile the new kernel.
-->
<p><item>新しいカーネルをコンパイルします．

<!--O
<p><item>Edit '/etc/lilo.conf' to add the new kernel image.  Run
'lilo -v' to
add the kernel to the boot loader.
-->
<p><item>`/etc/lilo.conf' を編集して，新しいカーネルイメージを追加しま
す．それから `lilo -v' を実行して，ブートローダにこのカーネルを追加し
ます．

<!--O
<p><item>Download the source for the newest 'util-linux' (I used
'util-linux-2.9v') package from:
-->
<p><item>最新の `util-linux' パッケージ(筆者は `util-linux-2.9v' を使っ
ています)を以下の場所から入手します:

<p><tscreen>
<url url="ftp://ftp.kernel.org/pub/linux/utils/util-linux/">
</tscreen>

<!--O
<p><item>Extract the 'util-linux' source.
-->
<p><item>`util-linux' のソースを展開します．

<!--O
<p><item>Apply the corresponding patch found in your
'/usr/src/linux/Documentation/crypto/' directory.
-->
<p><item>ローカルの `/usr/src/linux/Documentation/crypto/' ディレクトリ
にある，使いたい暗号に対応するパッチを当てます．

<!--O
<p><item>CAREFULLY read the 'INSTALL' file!  This package
contains the 
sources for many system dependent files (important tools such as
'login', 'passwd', and 'init').  If you don't carefully edit the
MCONFIG
file before compiling these sources have a boot disk and/or
shotgun ready
because your system will be quite confused.  Basically you want
to set almost
all of the 'HAVE_*' fields equal to yes so that the important
authentication
tools are not compiled and written over.  The tools you do want
rebuilt
are 'mount' and 'losetup' to accommodate the new encryption
schemes.  I
suggest that you refer to the <ref id="Details"> section below
for this step.
-->
<p><item>`INSTALL' ファイルを<em/注意深く/読んでください! このパッケー
ジには，システム依存のファイル(`login', `passwd', `init' といった重要
なツール群)のソースコードがたくさん入っています．
MCONFIG ファイルをいい加減に編集してこれらのソースをコンパイルしてしま
うと，システムがめちゃくちゃになるかもしれません - 起動ディスクか
ショットガンを用意しておきましょう．
基本的には，ほとんど全ての `HAVE_*' の項目を `yes' にしておき，重要な
認証ツールのコンパイルと上書きが行われないようにしておきましょう．
再構築の必要があるツールは，新しい暗号化手法に対応させる `mount' と `losetup' 
です．このステップについては，後述の
<!-- REF --><ref id="Details" name="詳細な手順">の節を参照することをお
勧めします．


<!--O
<p><item>Compile and install the 'util-linux' source
-->
<p><item>`util-linux' のソースのコンパイルとインストールを行います．

<!--O
<p><item>Reboot the machine with the new kernel.
-->
<p><item>新しいカーネルでマシンを再起動します．

<!--O
<p><item>Edit '/etc/fstab', adding an entry for your mount point
as follows:
-->
<p><item>`/etc/fstab' を編集し，以下のようなマウントポイントの項目を追
加します:

<p><tscreen><code>
/dev/loop0  /mnt/crypt  ext2  user,noauto,rw,loop 0 0
</code></tscreen>

<!--O
<p><item>Create the directory that will hold your filesystem, as
in
'/mnt/crypt' above.
-->
<p><item>ファイルシステムをマウントするためのディレクトリを作ります．
上記の例では `/mnt/crypt' です．

<!--O
<p><item>As the user, create your encrypted file as follows:
-->
<p><item>一般ユーザ権限で，暗号化するファイルを以下のようにして作ります:

<p><tscreen><verb>
dd if=/dev/urandom of=/etc/cryptfile bs=1M count=10
</verb></tscreen>

<!--O
<p><item>Run losetup as follows:
-->
<p><item>以下のように losetup を実行します:

<p><tscreen><verb>
losetup -e serpent /dev/loop0 /etc/cryptfile
</verb></tscreen>

<!--O
You only have one chance to enter the password, be careful.  If
you want to
double-check your password, you can use the command:
-->
パスワードを入力する機会は一度しかないので注意してください．パスワード
の二重チェックをしたければ，以下のコマンドを使いましょう:

<p><tscreen><verb>
losetup -d /dev/loop0
</verb></tscreen>

<!--O
This will deactivate your loop device.  Next you will run losetup
again to
test your password, as follows:
-->
このコマンドは loop デバイスをアクティブでない状態にします．次にもう一
度 losetup を実行し，以下のようにしてパスワードを確認します．

<p><tscreen><verb>
losetup -e serpent /dev/loop0 /etc/cryptfile
</verb></tscreen>

<!--O
<p><item>Make your ext2 filesystem as follows:
-->
<p><item>ext2 ファイルシステムを以下のようにして作成します:

<p><tscreen><verb>
mkfs -t ext2 /dev/loop0
</verb></tscreen>

<!--O
<p><item>Now you can mount the encrypted filesystem with:
-->
<p><item>ここで，暗号化したファイルシステムを以下のコマンドでマウント
します:

<p><tscreen><verb>
mount -t ext2 /dev/loop0 /mnt/crypt
</verb></tscreen>

<!--O
<p><item>When your done, you want to unmount and protect your
filesystem as
follows: 
-->
<p><item>ファイルシステムの使用を終了したら，以下のコマンドでファイル
システムをアンマウントして保護します:

<p><tscreen><verb>
umount /dev/loop0
losetup -d /dev/loop0
</verb></tscreen>

</enum>


<!--O
<sect>Details<label id="Details">
-->
<sect>詳細な手順<label id="Details">

<!--O
<p><bf/Kernel Patches:/
-->
<p><bf/カーネルへのパッチ当て:/

<!--O
You can upgrade from '2.2.x' releases by patching.  Each patch
that is released for '2.2.x' contains bugfixes.  New features
will be added to the Linux '2.3.x' development kernel.  To
install by patching, get all the newer patch files and do the
following:
-->
パッチを当てて，`2.2.x' リリースからアップグレードします．
`2.2.x' 向けにリリースされているそれぞれのパッチはバグ修正です．
新機能は開発版カーネルである `2.3.x' に追加されます．
パッチを当ててインストールするには，現在のバージョンより新しい
パッチファイルを全て入手し，以下のコマンドを実行します:

<tscreen><verb>
cd /usr/src
gzip -cd patchXX.gz | patch -p0
</verb></tscreen>

<!--O
Repeat xx for all versions bigger than the version of your
current source tree, IN ORDER.
-->
現在のソースツリーよりバージョン番号が大きいものを全て，XX に当てはめ
ていきます．これは<em/番号順/に行います．

<!--O
The default directory for the kernel source is '/usr/src/linux'.
If your source is installed somewhere else, I would suggest using
a symbolic link from '/usr/src/linux'.
-->
カーネルソースのデフォルトのディレクトリは `/usr/src/linux' です．
ソースが別の場所にインストールされている場合は，`/usr/src/linux'
からシンボリックリンクを張ることをお勧めします．

<!--O
<p><bf/Editing 'MCONFIG' for the 'util-linux' package
compilation:/
-->
<p><bf/`util-linux' パッケージのコンパイルのために `MCONFIG' を編集します:/

<!--O
The following are excerpts from the 'MCONFIG' file I used to
compile the 'util-linux' package.  Note that this is fairly
specific for my setup, which is loosely based on RedHat 5.2.  The
point is to make sure you don't overwrite any important system
tools such as 'login', 'getty', or 'passwd'.  Anyway, here are
the
important lines as follows:
-->
以下に示すのは，筆者が `util-linux' パッケージのコンパイルに使った `MCONFIG'
ファイルです．これは筆者の設定(RedHat 5.2 をある程度ベースにしています)
にかなり特化しているので注意してください．
確実に守るべき点は，`login', `getty', `passwd' といった重要なシステム
ファイルを上書きしないことです．とりあえず，重要な行を以下に示します:

<tscreen><code>
CPU=$(shell uname -m | sed s/I.86/intel/)

LOCALEDIR=/usr/share/locale

HAVE_PAM=no

HAVE_SHADOW=yes

HAVE_PASSWD=yes

REQUIRE_PASSWORD=yes

ONLY_LISTED_SHELLS=yes

HAVE_SYSVINIT=yes

HAVE_SYSVINIT_UTILS=yes

HAVE_GETTY=yes

USE_TTY_GROUP=yes

HAVE_RESET=yes

HAVE_SLN=yes

CC=gcc
</code></tscreen>

<!--O
<p><bf/Suggestions:/
-->
<p><bf/お勧め:/

<!--O
Note that you could use any of the eight loopback devices, from
'dev/loop0'
to '/dev/loop7'.  Use an inconspicuous directory for the mount
point.  I would
suggest creating a folder with 700 permissions inside your home
folder.  The
same goes for the file that holds the data.  I use a filename
like 'sysfile'
or 'config.data' inside the '/etc' folder.  This will usually get
overlooked.
-->
8 つのループバックデバイス(`dev/loop0' から `/dev/loop7' まで)のどれを
使ってもよいことに注意してください．また，マウントポイントは目立た
ないディレクトリにしましょう．筆者は，ホームディレクトリ以下に
パーミッション 700 のディレクトリを作ることをお勧めします．同じことが
データを入れるファイルにも言えます．
筆者は `/etc' フォルダ内に `sysfile' や `config.data' といったファイル
名で置いています．これは普通，見逃されます．

<!--O
I created very simple Perl scripts to mount and unmount the
filesystem with one command.  Write these, make them executable
(chmod u+x), and store them somewhere in your path.
-->
筆者は，1 コマンドでファイルシステムのマウントとアンマウントを行うため
の，とても簡単な Perl スクリプトを書きました．以下の内容のファイルを作
り，これを実行可能にし(chmod u+x)，パスが通った場所に置いてください．

<tscreen><code>
#!/usr/bin/perl -w
#
#minimal utility to setup loopback encryption filesystem
#Copyright 1999 by Ryan T. Rhea
`losetup -e serpent /dev/loop0 /etc/cryptfile`;
`mount /mnt/crypt`;
</code></tscreen>

<!--O
Name the above script 'loop', and then you can be on your way
with one command ('loop') and a password.
-->
上記のスクリプトを `loop' と名付けます．
これを使うと，コマンド一つ(`loop')とパスワード入力でマウントを行えます．

<tscreen><code>
#!/usr/bin/perl -w
#
#minimal utility to deactivate loopback encryption filesystem
#Copyright 1999 by Ryan T. Rhea
`umount /mount/crypt`;
`losetup -d /dev/loop0`;
</code></tscreen>

<!--O
Name the second one 'unloop', and then typing 'unloop' will
quickly deactivate your filesystem.
-->
2 つ目のスクリプトを `unloop' と名付けます．`unloop' を実行すると，す
ぐにファイルシステムを非アクティブにできます．

<sect>日本語訳について
<p>
日本語訳は Linux Japanese FAQ Project が行いました。
翻訳に関するご意見は JF プロジェクト
&lt;JF@linux.or.jp&gt;
宛に連絡してください。

改訂履歴を以下に示します。

<descrip>
<tag>v1.0j, 27 November 1999</tag>
翻訳:
藤原輝嘉 &lt;fujiwara@linux.or.jp&gt;

校正:
<itemize>
<item>高城正平 &lt;takavoid@palette.plala.or.jp&gt;
<item>中野武雄 &lt;nakano@apm.seikei.ac.jp&gt;
<item>武井伸光 &lt;takei@cc.kochi-u.ac.jp&gt;
</itemize>

<tag>v1.1j, 29 November 1999</tag>
翻訳:
藤原輝嘉 &lt;fujiwara@linux.or.jp&gt;
</descrip>

</article>
