\hypertarget{g__bde__crypt_8c_source}{}\doxysection{g\+\_\+bde\+\_\+crypt.\+c}
\label{g__bde__crypt_8c_source}\index{geom/bde/g\_bde\_crypt.c@{geom/bde/g\_bde\_crypt.c}}
\mbox{\hyperlink{g__bde__crypt_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2002 Poul-\/Henning Kamp}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00005}00005 \textcolor{comment}{ * Copyright (c) 2002 Networks Associates Technology, Inc.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00006}00006 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00007}00007 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00008}00008 \textcolor{comment}{ * This software was developed for the FreeBSD Project by Poul-\/Henning Kamp}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00009}00009 \textcolor{comment}{ * and NAI Labs, the Security Research Division of Network Associates, Inc.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00010}00010 \textcolor{comment}{ * under DARPA/SPAWAR contract N66001-\/01-\/C-\/8035 ("{}CBOSS"{}), as part of the}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00011}00011 \textcolor{comment}{ * DARPA CHATS research program.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00012}00012 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00013}00013 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00014}00014 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00015}00015 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00016}00016 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00017}00017 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00018}00018 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00019}00019 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00020}00020 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00021}00021 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00022}00022 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00023}00023 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00024}00024 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00025}00025 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00026}00026 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00027}00027 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00028}00028 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00029}00029 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00030}00030 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00031}00031 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00032}00032 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00033}00033 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00034}00034 \textcolor{comment}{ * \$FreeBSD\$}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00035}00035 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00036}00036 \textcolor{comment}{/* This source file contains the functions responsible for the crypto, keying}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00037}00037 \textcolor{comment}{ * and mapping operations on the I/O requests.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00038}00038 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00039}00039 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00040}00040 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <sys/bio.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <sys/lock.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <sys/mutex.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <sys/queue.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00046}00046 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00047}00047 \textcolor{preprocessor}{\#include <sys/libkern.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00048}00048 \textcolor{preprocessor}{\#include <sys/endian.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00049}00049 \textcolor{preprocessor}{\#include <sys/md5.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00050}00050 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00051}00051 \textcolor{preprocessor}{\#include <crypto/rijndael/rijndael-\/api-\/fst.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00052}00052 \textcolor{preprocessor}{\#include <crypto/sha2/sha512.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00053}00053 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00054}00054 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{geom_8h}{geom/geom.h}}>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00055}00055 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{g__bde_8h}{geom/bde/g\_bde.h}}>}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00056}00056 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00057}00057 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00058}00058 \textcolor{comment}{ * XXX: Debugging DO NOT ENABLE}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00059}00059 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00060}00060 \textcolor{preprocessor}{\#undef MD5\_KEY}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00061}00061 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00062}00062 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00063}00063 \textcolor{comment}{ * Derive kkey from mkey + sector offset.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00064}00064 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00065}00065 \textcolor{comment}{ * Security objective: Derive a potentially very large number of distinct skeys}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00066}00066 \textcolor{comment}{ * from the comparatively small key material in our mkey, in such a way that}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00067}00067 \textcolor{comment}{ * if one, more or even many of the kkeys are compromised, this does not}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00068}00068 \textcolor{comment}{ * significantly help an attack on other kkeys and in particular does not}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00069}00069 \textcolor{comment}{ * weaken or compromise the mkey.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00070}00070 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00071}00071 \textcolor{comment}{ * First we MD5 hash the sectornumber with the salt from the lock sector.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00072}00072 \textcolor{comment}{ * The salt prevents the precalculation and statistical analysis of the MD5}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00073}00073 \textcolor{comment}{ * output which would be possible if we only gave it the sectornumber.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00074}00074 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00075}00075 \textcolor{comment}{ * The MD5 hash is used to pick out 16 bytes from the masterkey, which}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00076}00076 \textcolor{comment}{ * are then hashed with MD5 together with the sector number.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00077}00077 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00078}00078 \textcolor{comment}{ * The resulting MD5 hash is the kkey.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00079}00079 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00080}00080 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00081}00081 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00082}\mbox{\hyperlink{g__bde__crypt_8c_a7a31fdc0198933c4dd749ea4731f039a}{00082}} \mbox{\hyperlink{g__bde__crypt_8c_a7a31fdc0198933c4dd749ea4731f039a}{g\_bde\_kkey}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc, keyInstance *ki, \textcolor{keywordtype}{int} dir, off\_t sector)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00083}00083 \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00084}00084         u\_int t;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00085}00085         MD5\_CTX ct;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00086}00086         u\_char \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[16];}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00087}00087         u\_char buf2[8];}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00088}00088 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00089}00089         \textcolor{comment}{/* We have to be architecture neutral */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00090}00090         le64enc(buf2, sector);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00091}00091 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00092}00092         MD5Init(\&ct);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00093}00093         MD5Update(\&ct, sc-\/>\mbox{\hyperlink{structg__bde__softc_aed5c45f058e35c02ee14c6707fcc0b37}{key}}.\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}}, 8);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00094}00094         MD5Update(\&ct, buf2, \textcolor{keyword}{sizeof} buf2);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00095}00095         MD5Update(\&ct, sc-\/>\mbox{\hyperlink{structg__bde__softc_aed5c45f058e35c02ee14c6707fcc0b37}{key}}.\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}} + 8, 8);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00096}00096         MD5Final(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \&ct);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00097}00097 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00098}00098         MD5Init(\&ct);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00099}00099         \textcolor{keywordflow}{for} (t = 0; t < 16; t++) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00100}00100                 MD5Update(\&ct, \&sc-\/>\mbox{\hyperlink{structg__bde__softc_aed5c45f058e35c02ee14c6707fcc0b37}{key}}.\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}}[\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[t]], 1);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00101}00101                 \textcolor{keywordflow}{if} (t == 8)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00102}00102                         MD5Update(\&ct, buf2, \textcolor{keyword}{sizeof} buf2);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00103}00103         \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00104}00104         bzero(buf2, \textcolor{keyword}{sizeof} buf2);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00105}00105         MD5Final(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \&ct);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00106}00106         bzero(\&ct, \textcolor{keyword}{sizeof} ct);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00107}00107         \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(ki, dir, \mbox{\hyperlink{g__bde_8h_ac023a67b536d4bd7b16f5a6e17b6614c}{G\_BDE\_KKEYBITS}}, \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00108}00108         bzero(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \textcolor{keyword}{sizeof} \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00109}00109 \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00110}00110 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00111}00111 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00112}00112 \textcolor{comment}{ * Encryption work for read operation.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00113}00113 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00114}00114 \textcolor{comment}{ * Security objective: Find the kkey, find the skey, decrypt the sector data.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00115}00115 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00116}00116 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00117}00117 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00118}\mbox{\hyperlink{g__bde_8h_a0e360ba2bc6c7e1f8cd28e1766276311}{00118}} \mbox{\hyperlink{g__bde__crypt_8c_a0e360ba2bc6c7e1f8cd28e1766276311}{g\_bde\_crypt\_read}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__work}{g\_bde\_work}} *wp)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00119}00119 \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00120}00120         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00121}00121         u\_char *d;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00122}00122         u\_int n;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00123}00123         off\_t o;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00124}00124         u\_char skey[\mbox{\hyperlink{g__bde_8h_aeb4e94faeca023758a78cd9cd45cc656}{G\_BDE\_SKEYLEN}}];}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00125}00125         keyInstance ki;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00126}00126         cipherInstance ci;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00127}00127 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00128}00128         \mbox{\hyperlink{g__bde_8h_ab5d14c928ffff64fb86d9524d0f5dada}{AES\_init}}(\&ci);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00129}00129         sc = wp-\/>\mbox{\hyperlink{structg__bde__work_a95d7fe0bbd8677b35b2872432580b2f5}{softc}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00130}00130         o = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00131}00131         \textcolor{keywordflow}{for} (n = 0; o < wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}}; n++, o += sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}}) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00132}00132                 d = (u\_char *)wp-\/>\mbox{\hyperlink{structg__bde__work_a24857e16bf46ac3c536872760b0e6986}{ksp}}-\/>\mbox{\hyperlink{structg__bde__sector_ab14f76aa177a3dbb8e2dff0dc721cf2a}{data}} + wp-\/>\mbox{\hyperlink{structg__bde__work_a4e98481241d51940b80fc557434a1e53}{ko}} + n * \mbox{\hyperlink{g__bde_8h_aeb4e94faeca023758a78cd9cd45cc656}{G\_BDE\_SKEYLEN}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00133}00133                 \mbox{\hyperlink{g__bde__crypt_8c_a7a31fdc0198933c4dd749ea4731f039a}{g\_bde\_kkey}}(sc, \&ki, DIR\_DECRYPT, wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}} + o);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00134}00134                 \mbox{\hyperlink{g__bde_8h_a51f1110fa4c35557b1a2cd0b7d184c9f}{AES\_decrypt}}(\&ci, \&ki, d, skey, \textcolor{keyword}{sizeof} skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00135}00135                 d = (u\_char *)wp-\/>\mbox{\hyperlink{structg__bde__work_a6feacf929bb3b01d0a28013504de8d8a}{data}} + o;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00136}00136                 \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(\&ki, DIR\_DECRYPT, \mbox{\hyperlink{g__bde_8h_aa2e8cd900a66aea1ef03f639a2adaefd}{G\_BDE\_SKEYBITS}}, skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00137}00137                 \mbox{\hyperlink{g__bde_8h_a51f1110fa4c35557b1a2cd0b7d184c9f}{AES\_decrypt}}(\&ci, \&ki, d, d, sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00138}00138         \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00139}00139         bzero(skey, \textcolor{keyword}{sizeof} skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00140}00140         bzero(\&ci, \textcolor{keyword}{sizeof} ci);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00141}00141         bzero(\&ki, \textcolor{keyword}{sizeof} ki);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00142}00142 \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00143}00143 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00144}00144 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00145}00145 \textcolor{comment}{ * Encryption work for write operation.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00146}00146 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00147}00147 \textcolor{comment}{ * Security objective: Create random skey, encrypt sector data,}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00148}00148 \textcolor{comment}{ * encrypt skey with the kkey.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00149}00149 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00150}00150 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00151}00151 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00152}\mbox{\hyperlink{g__bde_8h_a3704204fda32232892e3c0f046c04e8c}{00152}} \mbox{\hyperlink{g__bde__crypt_8c_a3704204fda32232892e3c0f046c04e8c}{g\_bde\_crypt\_write}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__work}{g\_bde\_work}} *wp)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00153}00153 \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00154}00154         u\_char *s, *d;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00155}00155         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00156}00156         u\_int n;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00157}00157         off\_t o;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00158}00158         u\_char skey[\mbox{\hyperlink{g__bde_8h_aeb4e94faeca023758a78cd9cd45cc656}{G\_BDE\_SKEYLEN}}];}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00159}00159         keyInstance ki;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00160}00160         cipherInstance ci;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00161}00161 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00162}00162         sc = wp-\/>\mbox{\hyperlink{structg__bde__work_a95d7fe0bbd8677b35b2872432580b2f5}{softc}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00163}00163         \mbox{\hyperlink{g__bde_8h_ab5d14c928ffff64fb86d9524d0f5dada}{AES\_init}}(\&ci);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00164}00164         o = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00165}00165         \textcolor{keywordflow}{for} (n = 0; o < wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}}; n++, o += sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}}) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00166}00166                 s = (u\_char *)wp-\/>\mbox{\hyperlink{structg__bde__work_a6feacf929bb3b01d0a28013504de8d8a}{data}} + o;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00167}00167                 d = (u\_char *)wp-\/>\mbox{\hyperlink{structg__bde__work_ab479e99436eaef7b084e0de5b8efbacd}{sp}}-\/>\mbox{\hyperlink{structg__bde__sector_ab14f76aa177a3dbb8e2dff0dc721cf2a}{data}} + o;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00168}00168                 arc4rand(skey, \textcolor{keyword}{sizeof} skey, 0);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00169}00169                 \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(\&ki, DIR\_ENCRYPT, \mbox{\hyperlink{g__bde_8h_aa2e8cd900a66aea1ef03f639a2adaefd}{G\_BDE\_SKEYBITS}}, skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00170}00170                 \mbox{\hyperlink{g__bde_8h_ad6e8bd58e9bdf77aa27d86282309d0f4}{AES\_encrypt}}(\&ci, \&ki, s, d, sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00171}00171 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00172}00172                 d = (u\_char *)wp-\/>\mbox{\hyperlink{structg__bde__work_a24857e16bf46ac3c536872760b0e6986}{ksp}}-\/>\mbox{\hyperlink{structg__bde__sector_ab14f76aa177a3dbb8e2dff0dc721cf2a}{data}} + wp-\/>\mbox{\hyperlink{structg__bde__work_a4e98481241d51940b80fc557434a1e53}{ko}} + n * \mbox{\hyperlink{g__bde_8h_aeb4e94faeca023758a78cd9cd45cc656}{G\_BDE\_SKEYLEN}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00173}00173                 \mbox{\hyperlink{g__bde__crypt_8c_a7a31fdc0198933c4dd749ea4731f039a}{g\_bde\_kkey}}(sc, \&ki, DIR\_ENCRYPT, wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}} + o);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00174}00174                 \mbox{\hyperlink{g__bde_8h_ad6e8bd58e9bdf77aa27d86282309d0f4}{AES\_encrypt}}(\&ci, \&ki, skey, d, \textcolor{keyword}{sizeof} skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00175}00175                 bzero(skey, \textcolor{keyword}{sizeof} skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00176}00176         \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00177}00177         bzero(skey, \textcolor{keyword}{sizeof} skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00178}00178         bzero(\&ci, \textcolor{keyword}{sizeof} ci);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00179}00179         bzero(\&ki, \textcolor{keyword}{sizeof} ki);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00180}00180 \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00181}00181 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00182}00182 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00183}00183 \textcolor{comment}{ * Encryption work for delete operation.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00184}00184 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00185}00185 \textcolor{comment}{ * Security objective: Write random data to the sectors.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00186}00186 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00187}00187 \textcolor{comment}{ * XXX: At a hit in performance we would trash the encrypted skey as well.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00188}00188 \textcolor{comment}{ * XXX: This would add frustration to the cleaning lady attack by making}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00189}00189 \textcolor{comment}{ * XXX: deletes look like writes.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00190}00190 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00191}00191 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00192}00192 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00193}\mbox{\hyperlink{g__bde_8h_aa424947a388f787015d468937a543765}{00193}} \mbox{\hyperlink{g__bde__crypt_8c_aa424947a388f787015d468937a543765}{g\_bde\_crypt\_delete}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__work}{g\_bde\_work}} *wp)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00194}00194 \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00195}00195         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00196}00196         u\_char *d;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00197}00197         off\_t o;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00198}00198         u\_char skey[\mbox{\hyperlink{g__bde_8h_aeb4e94faeca023758a78cd9cd45cc656}{G\_BDE\_SKEYLEN}}];}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00199}00199         keyInstance ki;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00200}00200         cipherInstance ci;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00201}00201 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00202}00202         sc = wp-\/>\mbox{\hyperlink{structg__bde__work_a95d7fe0bbd8677b35b2872432580b2f5}{softc}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00203}00203         d = wp-\/>\mbox{\hyperlink{structg__bde__work_ab479e99436eaef7b084e0de5b8efbacd}{sp}}-\/>\mbox{\hyperlink{structg__bde__sector_ab14f76aa177a3dbb8e2dff0dc721cf2a}{data}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00204}00204         \mbox{\hyperlink{g__bde_8h_ab5d14c928ffff64fb86d9524d0f5dada}{AES\_init}}(\&ci);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00205}00205         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00206}00206 \textcolor{comment}{         * Do not unroll this loop!}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00207}00207 \textcolor{comment}{         * Our zone may be significantly wider than the amount of random}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00208}00208 \textcolor{comment}{         * bytes arc4rand likes to give in one reseeding, whereas our}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00209}00209 \textcolor{comment}{         * sectorsize is far more likely to be in the same range.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00210}00210 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00211}00211         \textcolor{keywordflow}{for} (o = 0; o < wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}}; o += sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}}) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00212}00212                 arc4rand(d, sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}}, 0);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00213}00213                 arc4rand(skey, \textcolor{keyword}{sizeof} skey, 0);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00214}00214                 \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(\&ki, DIR\_ENCRYPT, \mbox{\hyperlink{g__bde_8h_aa2e8cd900a66aea1ef03f639a2adaefd}{G\_BDE\_SKEYBITS}}, skey);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00215}00215                 \mbox{\hyperlink{g__bde_8h_ad6e8bd58e9bdf77aa27d86282309d0f4}{AES\_encrypt}}(\&ci, \&ki, d, d, sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00216}00216                 d += sc-\/>\mbox{\hyperlink{structg__bde__softc_a3550952b25e3c8697e43254841743beb}{sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00217}00217         \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00218}00218         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00219}00219 \textcolor{comment}{         * Having written a long random sequence to disk here, we want to}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00220}00220 \textcolor{comment}{         * force a reseed, to avoid weakening the next time we use random}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00221}00221 \textcolor{comment}{         * data for something important.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00222}00222 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00223}00223         arc4rand(\&o, \textcolor{keyword}{sizeof} o, 1);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00224}00224 \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00225}00225 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00226}00226 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00227}00227 \textcolor{comment}{ * Calculate the total payload size of the encrypted device.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00228}00228 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00229}00229 \textcolor{comment}{ * Security objectives: none.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00230}00230 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00231}00231 \textcolor{comment}{ * This function needs to agree with g\_bde\_map\_sector() about things.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00232}00232 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00233}00233 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00234}00234 uint64\_t}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00235}\mbox{\hyperlink{g__bde_8h_a1a81354f303cb614add4800492d5298a}{00235}} \mbox{\hyperlink{g__bde__crypt_8c_a70b43defa589bce1b2aa95103c5f50ab}{g\_bde\_max\_sector}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__key}{g\_bde\_key}} *kp)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00236}00236 \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00237}00237         uint64\_t maxsect;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00238}00238 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00239}00239         maxsect = kp-\/>\mbox{\hyperlink{structg__bde__key_a71c1315e6871a2546e82ab7e38d93b23}{media\_width}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00240}00240         maxsect /= kp-\/>\mbox{\hyperlink{structg__bde__key_ae57a9921228a0b26282b8a131623d630}{zone\_width}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00241}00241         maxsect *= kp-\/>\mbox{\hyperlink{structg__bde__key_a19fcaf93ac99c557c6bb6f6ed0ee2c42}{zone\_cont}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00242}00242         \textcolor{keywordflow}{return} (maxsect);}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00243}00243 \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00244}00244 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00245}00245 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00246}00246 \textcolor{comment}{ * Convert an unencrypted side offset to offsets on the encrypted side.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00247}00247 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00248}00248 \textcolor{comment}{ * Security objective:  Make it harder to identify what sectors contain what}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00249}00249 \textcolor{comment}{ * on a "{}cold"{} disk image.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00250}00250 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00251}00251 \textcolor{comment}{ * We do this by adding the "{}keyoffset"{} from the lock to the physical sector}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00252}00252 \textcolor{comment}{ * number modulus the available number of sectors.  Since all physical sectors}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00253}00253 \textcolor{comment}{ * presumably look the same cold, this will do.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00254}00254 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00255}00255 \textcolor{comment}{ * As part of the mapping we have to skip the lock sectors which we know}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00256}00256 \textcolor{comment}{ * the physical address off.  We also truncate the work packet, respecting}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00257}00257 \textcolor{comment}{ * zone boundaries and lock sectors, so that we end up with a sequence of}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00258}00258 \textcolor{comment}{ * sectors which are physically contiguous.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00259}00259 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00260}00260 \textcolor{comment}{ * Shuffling things further is an option, but the incremental frustration is}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00261}00261 \textcolor{comment}{ * not currently deemed worth the run-\/time performance hit resulting from the}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00262}00262 \textcolor{comment}{ * increased number of disk arm movements it would incur.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00263}00263 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00264}00264 \textcolor{comment}{ * This function offers nothing but a trivial diversion for an attacker able}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00265}00265 \textcolor{comment}{ * to do "{}the cleaning lady attack"{} in its current static mapping form.}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00266}00266 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00267}00267 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00268}00268 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00269}\mbox{\hyperlink{g__bde_8h_ac2890ae097fa50be721493bdd8d5b3d7}{00269}} \mbox{\hyperlink{g__bde__crypt_8c_ac2890ae097fa50be721493bdd8d5b3d7}{g\_bde\_map\_sector}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__work}{g\_bde\_work}} *wp)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00270}00270 \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00271}00271 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00272}00272         u\_int   zone, zoff, u, len;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00273}00273         uint64\_t ko;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00274}00274         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00275}00275         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__bde__key}{g\_bde\_key}} *kp;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00276}00276 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00277}00277         sc = wp-\/>\mbox{\hyperlink{structg__bde__work_a95d7fe0bbd8677b35b2872432580b2f5}{softc}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00278}00278         kp = \&sc-\/>\mbox{\hyperlink{structg__bde__softc_aed5c45f058e35c02ee14c6707fcc0b37}{key}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00279}00279 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00280}00280         \textcolor{comment}{/* find which zone and the offset in it */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00281}00281         zone = wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}} / kp-\/>\mbox{\hyperlink{structg__bde__key_a19fcaf93ac99c557c6bb6f6ed0ee2c42}{zone\_cont}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00282}00282         zoff = wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}} \% kp-\/>\mbox{\hyperlink{structg__bde__key_a19fcaf93ac99c557c6bb6f6ed0ee2c42}{zone\_cont}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00283}00283 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00284}00284         \textcolor{comment}{/* Calculate the offset of the key in the key sector */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00285}00285         wp-\/>\mbox{\hyperlink{structg__bde__work_a4e98481241d51940b80fc557434a1e53}{ko}} = (zoff / kp-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}) * \mbox{\hyperlink{g__bde_8h_aeb4e94faeca023758a78cd9cd45cc656}{G\_BDE\_SKEYLEN}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00286}00286 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00287}00287         \textcolor{comment}{/* restrict length to that zone */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00288}00288         len = kp-\/>\mbox{\hyperlink{structg__bde__key_a19fcaf93ac99c557c6bb6f6ed0ee2c42}{zone\_cont}} -\/ zoff;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00289}00289 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00290}00290         \textcolor{comment}{/* ... and in general */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00291}00291         \textcolor{keywordflow}{if} (len > DFLTPHYS)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00292}00292                 len = DFLTPHYS;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00293}00293 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00294}00294         \textcolor{keywordflow}{if} (len < wp-\/>\mbox{\hyperlink{g__raid__tr__if_8m_ae809d5359ac030c60a30a8f0b2294b82}{length}})}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00295}00295                 wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}} = len;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00296}00296 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00297}00297         \textcolor{comment}{/* Find physical sector address */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00298}00298         wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} = zone * kp-\/>\mbox{\hyperlink{structg__bde__key_ae57a9921228a0b26282b8a131623d630}{zone\_width}} + zoff;}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00299}00299         wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} += kp-\/>\mbox{\hyperlink{structg__bde__key_a584abb7851a7de46edfcee8b05f6f13f}{keyoffset}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00300}00300         wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} \%= kp-\/>\mbox{\hyperlink{structg__bde__key_a71c1315e6871a2546e82ab7e38d93b23}{media\_width}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00301}00301         \textcolor{keywordflow}{if} (wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} + wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}} > kp-\/>\mbox{\hyperlink{structg__bde__key_a71c1315e6871a2546e82ab7e38d93b23}{media\_width}})}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00302}00302                 wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}} = kp-\/>\mbox{\hyperlink{structg__bde__key_a71c1315e6871a2546e82ab7e38d93b23}{media\_width}} -\/ wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00303}00303         wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} += kp-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00304}00304 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00305}00305         \textcolor{comment}{/* The key sector is the last in this zone. */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00306}00306         wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} = zone * kp-\/>\mbox{\hyperlink{structg__bde__key_ae57a9921228a0b26282b8a131623d630}{zone\_width}} + kp-\/>\mbox{\hyperlink{structg__bde__key_a19fcaf93ac99c557c6bb6f6ed0ee2c42}{zone\_cont}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00307}00307         wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} += kp-\/>\mbox{\hyperlink{structg__bde__key_a584abb7851a7de46edfcee8b05f6f13f}{keyoffset}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00308}00308         wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} \%= kp-\/>\mbox{\hyperlink{structg__bde__key_a71c1315e6871a2546e82ab7e38d93b23}{media\_width}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00309}00309         wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} += kp-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}}; }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00310}00310 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00311}00311         \textcolor{comment}{/* Compensate for lock sectors */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00312}00312         \textcolor{keywordflow}{for} (u = 0; u < \mbox{\hyperlink{g__bde_8h_a0f44849dd4673db8de19f94a741d27a7}{G\_BDE\_MAXKEYS}}; u++) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00313}00313                 \textcolor{comment}{/* Find the start of this lock sector */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00314}00314                 ko = rounddown2(kp-\/>\mbox{\hyperlink{structg__bde__key_ad26d0aae2eb539ddd316bdaac5a6fabe}{lsector}}[u], (uint64\_t)kp-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00315}00315 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00316}00316                 \textcolor{keywordflow}{if} (wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} >= ko)}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00317}00317                         wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} += kp-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00318}00318 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00319}00319                 \textcolor{keywordflow}{if} (wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} >= ko) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00320}00320                         \textcolor{comment}{/* lock sector before work packet */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00321}00321                         wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} += kp-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00322}00322                 \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} ((wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} + wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}}) > ko) \{}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00323}00323                         \textcolor{comment}{/* lock sector in work packet, truncate */}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00324}00324                         wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}} = ko -\/ wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}};}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00325}00325                 \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00326}00326         \}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00327}00327 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00328}00328 \textcolor{preprocessor}{\#if 0}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00329}00329         printf(\textcolor{stringliteral}{"{}off \%jd len \%jd so \%jd ko \%jd kso \%u\(\backslash\)n"{}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00330}00330             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00331}00331             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00332}00332             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00333}00333             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00334}00334             wp-\/>\mbox{\hyperlink{structg__bde__work_a4e98481241d51940b80fc557434a1e53}{ko}});}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00335}00335 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00336}00336         KASSERT(wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} + wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}} <= kp-\/>\mbox{\hyperlink{structg__bde__key_a24a6da7f1a62a46ce669f45927f00307}{sectorN}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00337}00337             (\textcolor{stringliteral}{"{}wp-\/>so (\%jd) + wp-\/>length (\%jd) > EOM (\%jd), offset = \%jd"{}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00338}00338             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00339}00339             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a9f7d343383548b89da65779a624142d1}{length}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00340}00340             (intmax\_t)kp-\/>\mbox{\hyperlink{structg__bde__key_a24a6da7f1a62a46ce669f45927f00307}{sectorN}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00341}00341             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}}));}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00342}00342 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00343}00343         KASSERT(wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} + kp-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}} <= kp-\/>\mbox{\hyperlink{structg__bde__key_a24a6da7f1a62a46ce669f45927f00307}{sectorN}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00344}00344             (\textcolor{stringliteral}{"{}wp-\/>kso (\%jd) + kp-\/>sectorsize > EOM (\%jd), offset = \%jd"{}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00345}00345             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00346}00346             (intmax\_t)kp-\/>\mbox{\hyperlink{structg__bde__key_a24a6da7f1a62a46ce669f45927f00307}{sectorN}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00347}00347             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}}));}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00348}00348 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00349}00349         KASSERT(wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}} >= kp-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00350}00350             (\textcolor{stringliteral}{"{}wp-\/>so (\%jd) < BOM (\%jd), offset = \%jd"{}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00351}00351             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a1f99159bf221d1f9d359d5c35a4b02e6}{so}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00352}00352             (intmax\_t)kp-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00353}00353             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}}));}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00354}00354 }
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00355}00355         KASSERT(wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}} >= kp-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00356}00356             (\textcolor{stringliteral}{"{}wp-\/>kso (\%jd) <BOM (\%jd), offset = \%jd"{}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00357}00357             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_aacdf8f69d74bf6a308fd80ca7f77eac9}{kso}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00358}00358             (intmax\_t)kp-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}},}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00359}00359             (intmax\_t)wp-\/>\mbox{\hyperlink{structg__bde__work_a3e62b5e2255f2d340b3f661458d05ad8}{offset}}));}
\DoxyCodeLine{\Hypertarget{g__bde__crypt_8c_source_l00360}00360 \}}

\end{DoxyCode}
