1.\" $NetBSD: cgd.4,v 1.21 2016/12/12 10:13:00 wiz Exp $ 2.\" 3.\" Copyright (c) 2002, 2003 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Roland C. Dowdeswell. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd December 11, 2016 31.Dt CGD 4 32.Os 33.Sh NAME 34.Nm cgd 35.Nd cryptographic disk driver 36.Sh SYNOPSIS 37.Cd pseudo-device cgd 38.Sh DESCRIPTION 39The 40.Nm 41driver provides the capability of encrypting blocks on their way 42to and from a disk or partition. 43.Pp 44In order to compile support for the 45.Nm 46into your kernel, you must add the driver to your kernel configuration 47file. 48To do this, add a line similar to: 49.Bd -unfilled -offset indent 50pseudo-device cgd # cryptographic disk driver 51.Ed 52.Pp 53The 54.Nm 55devices are allocated as needed. 56.Ss Encryption Algorithms 57Currently the following cryptographic algorithms are supported: 58.Bl -tag -width indentxxxxxxx 59.It Ic aes-cbc 60.Tn AES 61in 62.Tn CBC 63mode. 64.Tn AES 65uses a 128 bit blocksize and can accept keys of length 128, 192, or 256. 66The default key length is 128. 67.It Ic aes-xts 68.Tn AES 69in 70.Tn XTS 71mode. 72.Tn AES-XTS 73uses a 128 bit blocksize and can accept keys of length 256 or 512. 74Note that an 75.Tn AES-XTS 76key consists of two 77.Tn AES 78keys of equal size. 79The second key is used solely to encrypt the block number of the physical 80disk block. 81The default key length is 256. 82.It Ic 3des-cbc 83Triple 84.Tn DES 85in 86.Tn CBC 87mode. 88Triple 89.Tn DES 90uses a 64 bit blocksize and is performed in 91.Tn EDE3 92mode with a 168 bit key. 93The key passed to the kernel is 192 bits but the parity bits are ignored. 94.It Ic blowfish-cbc 95Blowfish in 96.Tn CBC 97mode. 98Blowfish uses a 64 bit blocksize and can accept keys between 40 and 99448 bits in multiples of 8. 100It is strongly encouraged that keys be at least 128 bits long. 101There are no performance advantages of using shorter keys. 102The default key length is 128 bits. 103.El 104.Ss IV Methods 105Currently, the following 106.Tn IV 107Methods are supported: 108.Bl -tag -width encblkno1 109.It Ic encblkno1 110This method encrypts the block number of the physical disk block once with 111the cipher and key provided and uses the result as the 112.Tn IV 113for 114.Tn CBC 115mode. 116This method should ensure that each block has a different 117.Tn IV 118and that the 119.Tn IV 120is reasonably unpredictable. 121This is the default method used by 122.Xr cgdconfig 8 123when configuring a new 124.Nm . 125.It Ic encblkno8 126This is the original 127.Tn IV 128method used by 129.Nm 130and provided for backward compatibility. 131It repeatedly encrypts the block number of the physical disk block 132eight times and uses the result as the 133.Tn IV 134for 135.Tn CBC 136mode. 137This method should ensure that each block has a different 138.Tn IV 139and that the 140.Tn IV 141is reasonably unpredictable. 142The eightfold encryption was not intended and causes a notable 143performance loss with little (if any) increase in security over a 144single encryption. 145.El 146.Ss IOCTLS 147A 148.Nm 149responds to all of the standard disk 150.Xr ioctl 2 151calls defined in 152.Xr sd 4 , 153and also defines the following: 154.Bl -tag -width CGDIOCSET -offset indent 155.It Dv CGDIOCSET 156Configure the 157.Nm . 158This 159.Xr ioctl 2 160sets up the encryption parameters and points the 161.Nm 162at the underlying disk. 163.It Dv CGDIOCCLR 164Unconfigure the 165.Nm . 166.It Dv CGDIOCGET 167Get info about the 168.Nm . 169.El 170.Pp 171These 172.Xr ioctl 2 Ns 's 173and their associated data structures are defined in 174.In dev/cgdvar.h 175header. 176.Sh WARNINGS 177It goes without saying that if you forget the passphrase that you used 178to configure a 179.Nm , 180then you have irrevocably lost all of the data on the disk. 181Please ensure that you are using an appropriate backup strategy. 182.Pp 183A 184.Nm 185device doesn't authenticate data and thus it can't guarantee integrity 186of the encrypted data. 187In particular, if the plaintext is known to an adversary, it is 188possible to change every second block on a disk encrypted in the 189.Tn CBC 190mode to plaintext blocks of their choice. 191The 192.Tn 193XTS mode isn't vulnerable to this particular attack but a lack of 194integrity should be taken into account when evaluating security risks. 195.Sh FILES 196.Bl -tag -width indentxxxxxxxxxxx 197.It /dev/{,r}cgd* 198.Nm 199device special files. 200.El 201.Sh SEE ALSO 202.Xr config 1 , 203.Xr ioctl 2 , 204.Xr sd 4 , 205.Xr cgdconfig 8 , 206.Xr MAKEDEV 8 207.Rs 208.%A Roland C. Dowdeswell 209.%A John Ioannidis 210.%T The CryptoGraphic Disk Driver 211.%I USENIX Association 212.%B Proceedings of the FREENIX Track: 2003 USENIX Annual Technical Conference 213.%P 179-186 214.%D June 9-14, 2003 215.%U http://www.usenix.org/event/usenix03/tech/freenix03/full_papers/dowdeswell/dowdeswell.pdf 216.Re 217.Sh HISTORY 218The 219.Nm 220driver was written by Roland C. Dowdeswell for 221.Nx . 222The 223.Nm 224driver originally appeared in 225.Nx 2.0 . 226