\hypertarget{g__bde__lock_8c_source}{}\doxysection{g\+\_\+bde\+\_\+lock.\+c}
\label{g__bde__lock_8c_source}\index{geom/bde/g\_bde\_lock.c@{geom/bde/g\_bde\_lock.c}}
\mbox{\hyperlink{g__bde__lock_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2002 Poul-\/Henning Kamp}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00005}00005 \textcolor{comment}{ * Copyright (c) 2002 Networks Associates Technology, Inc.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00006}00006 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00007}00007 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00008}00008 \textcolor{comment}{ * This software was developed for the FreeBSD Project by Poul-\/Henning Kamp}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00009}00009 \textcolor{comment}{ * and NAI Labs, the Security Research Division of Network Associates, Inc.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00010}00010 \textcolor{comment}{ * under DARPA/SPAWAR contract N66001-\/01-\/C-\/8035 ("{}CBOSS"{}), as part of the}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00011}00011 \textcolor{comment}{ * DARPA CHATS research program.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00012}00012 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00013}00013 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00014}00014 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00015}00015 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00016}00016 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00017}00017 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00018}00018 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00019}00019 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00020}00020 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00021}00021 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00022}00022 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00023}00023 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00024}00024 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00025}00025 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00026}00026 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00027}00027 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00028}00028 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00029}00029 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00030}00030 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00031}00031 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00032}00032 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00033}00033 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00034}00034 \textcolor{comment}{ * \$FreeBSD\$}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00035}00035 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00036}00036 \textcolor{comment}{/* This souce file contains routines which operates on the lock sectors, both}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00037}00037 \textcolor{comment}{ * for the kernel and the userland program gbde(1).}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00038}00038 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00039}00039 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00040}00040 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <sys/queue.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <sys/lock.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <sys/mutex.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00045}00045 \textcolor{preprocessor}{\#include <sys/endian.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00046}00046 \textcolor{preprocessor}{\#include <sys/md5.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00047}00047 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00048}00048 \textcolor{preprocessor}{\#ifdef \_KERNEL}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00049}00049 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00050}00050 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00051}00051 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00052}00052 \textcolor{preprocessor}{\#include <err.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00053}00053 \textcolor{preprocessor}{\#define CTASSERT(foo)}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00054}00054 \textcolor{preprocessor}{\#define KASSERT(foo, bar) do \{ if(!(foo)) \{ warn bar ; exit (1); \} \} while (0)}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00055}00055 \textcolor{preprocessor}{\#include <errno.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00056}00056 \textcolor{preprocessor}{\#include <string.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00057}00057 \textcolor{preprocessor}{\#include <stdlib.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00058}00058 \textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00059}00059 \textcolor{preprocessor}{\#define g\_free(foo)     free(foo)}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00060}00060 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00061}00061 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00062}00062 \textcolor{preprocessor}{\#include <crypto/rijndael/rijndael-\/api-\/fst.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00063}00063 \textcolor{preprocessor}{\#include <crypto/sha2/sha512.h>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00064}00064 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00065}00065 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{geom_8h}{geom/geom.h}}>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00066}00066 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{g__bde_8h}{geom/bde/g\_bde.h}}>}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00067}00067 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00068}00068 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00069}00069 \textcolor{comment}{ * Hash the raw pass-\/phrase.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00070}00070 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00071}00071 \textcolor{comment}{ * Security objectives: produce from the pass-\/phrase a fixed length}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00072}00072 \textcolor{comment}{ * bytesequence with PRN like properties in a reproducible way retaining}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00073}00073 \textcolor{comment}{ * as much entropy from the pass-\/phrase as possible.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00074}00074 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00075}00075 \textcolor{comment}{ * SHA2-\/512 makes this easy.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00076}00076 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00077}00077 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00078}00078 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00079}\mbox{\hyperlink{g__bde_8h_af46081ae7dda9d7486438fe24b6a9316}{00079}} \mbox{\hyperlink{g__bde__lock_8c_af46081ae7dda9d7486438fe24b6a9316}{g\_bde\_hash\_pass}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *input, u\_int len)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00080}00080 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00081}00081         SHA512\_CTX cx;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00082}00082 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00083}00083         SHA512\_Init(\&cx);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00084}00084         SHA512\_Update(\&cx, input, len);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00085}00085         SHA512\_Final(sc-\/>\mbox{\hyperlink{structg__bde__softc_a3004ff7ec5e1294d1cca2bbd35ea3e29}{sha2}}, \&cx);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00086}00086 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00087}00087 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00088}00088 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00089}00089 \textcolor{comment}{ * Encode/Decode the lock structure in byte-\/sequence format.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00090}00090 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00091}00091 \textcolor{comment}{ * Security objectives: Store in pass-\/phrase dependent variant format.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00092}00092 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00093}00093 \textcolor{comment}{ * C-\/structure packing and byte-\/endianess depends on architecture, compiler}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00094}00094 \textcolor{comment}{ * and compiler options.  Writing raw structures to disk is therefore a bad}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00095}00095 \textcolor{comment}{ * idea in these enlightend days.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00096}00096 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00097}00097 \textcolor{comment}{ * We spend a fraction of the key-\/material on shuffling the fields around}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00098}00098 \textcolor{comment}{ * so they will be stored in an unpredictable sequence.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00099}00099 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00100}00100 \textcolor{comment}{ * For each byte of the key-\/material we derive two field indexes, and swap}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00101}00101 \textcolor{comment}{ * the position of those two fields.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00102}00102 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00103}00103 \textcolor{comment}{ * I have not worked out the statistical properties of this shuffle, but}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00104}00104 \textcolor{comment}{ * given that the key-\/material has PRN properties, the primary objective}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00105}00105 \textcolor{comment}{ * of making it hard to figure out which bits are where in the lock sector}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00106}00106 \textcolor{comment}{ * is sufficiently fulfilled.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00107}00107 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00108}00108 \textcolor{comment}{ * We include (and shuffle) an extra hash field in the stored version for}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00109}00109 \textcolor{comment}{ * identification and versioning purposes.  This field contains the MD5 hash}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00110}00110 \textcolor{comment}{ * of a version identifier (currently "{}0000"{}) followed by the stored lock}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00111}00111 \textcolor{comment}{ * sector byte-\/sequence substituting zero bytes for the hash field.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00112}00112 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00113}00113 \textcolor{comment}{ * The stored keysequence is protected by AES/256/CBC elsewhere in the code}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00114}00114 \textcolor{comment}{ * so the fact that the generated byte sequence has a much higher than}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00115}00115 \textcolor{comment}{ * average density of zero bits (from the numeric fields) is not currently}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00116}00116 \textcolor{comment}{ * a concern.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00117}00117 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00118}00118 \textcolor{comment}{ * Should this later become a concern, a simple software update and }}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00119}00119 \textcolor{comment}{ * pass-\/phrase change can remedy the situation.  One possible solution }}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00120}00120 \textcolor{comment}{ * could be to XOR the numeric fields with a key-\/material derived PRN.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00121}00121 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00122}00122 \textcolor{comment}{ * The chosen shuffle algorithm only works as long as we have no more than 16 }}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00123}00123 \textcolor{comment}{ * fields in the stored part of the lock structure (hence the CTASSERT below).}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00124}00124 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00125}00125 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00126}\mbox{\hyperlink{g__bde__lock_8c_a877839f657d74e5f15aefc3e5324bc54}{00126}} \mbox{\hyperlink{g__bde__lock_8c_a877839f657d74e5f15aefc3e5324bc54}{CTASSERT}}(\mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}} <= 16);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00127}00127 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00128}00128 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00129}\mbox{\hyperlink{g__bde__lock_8c_a0a04f943aec21bc49009147950e87c19}{00129}} \mbox{\hyperlink{g__bde__lock_8c_a0a04f943aec21bc49009147950e87c19}{g\_bde\_shuffle\_lock}}(u\_char *sha2, \textcolor{keywordtype}{int} *\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}})}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00130}00130 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00131}00131         \textcolor{keywordtype}{int} j, k, l;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00132}00132         u\_int u;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00133}00133 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00134}00134         \textcolor{comment}{/* Assign the fields sequential positions */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00135}00135         \textcolor{keywordflow}{for}(u = 0; u < \mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}}; u++)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00136}00136                 \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[u] = u;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00137}00137 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00138}00138         \textcolor{comment}{/* Then mix it all up */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00139}00139         \textcolor{keywordflow}{for}(u = 48; u < SHA512\_DIGEST\_LENGTH; u++) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00140}00140                 j = sha2[u] \% \mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00141}00141                 k = (sha2[u] / \mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}}) \% \mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00142}00142                 l = \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[j];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00143}00143                 \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[j] = \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[k];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00144}00144                 \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[k] = l;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00145}00145         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00146}00146 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00147}00147 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00148}00148 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00149}\mbox{\hyperlink{g__bde_8h_ad69ecfe3a582f50544c89fba125cd66e}{00149}} \mbox{\hyperlink{g__bde__lock_8c_ad69ecfe3a582f50544c89fba125cd66e}{g\_bde\_encode\_lock}}(u\_char *sha2, \textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__key}{g\_bde\_key}} *gl, u\_char *ptr)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00150}00150 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00151}00151         \textcolor{keywordtype}{int} shuffle[\mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}}];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00152}00152         u\_char *hash, *p;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00153}00153         \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00154}00154         MD5\_CTX c;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00155}00155 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00156}00156         p = ptr;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00157}00157         hash = NULL;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00158}00158         \mbox{\hyperlink{g__bde__lock_8c_a0a04f943aec21bc49009147950e87c19}{g\_bde\_shuffle\_lock}}(sha2, shuffle);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00159}00159         \textcolor{keywordflow}{for} (i = 0; i < \mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}}; i++) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00160}00160                 \textcolor{keywordflow}{switch}(shuffle[i]) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00161}00161                 \textcolor{keywordflow}{case} 0:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00162}00162                         le64enc(p, gl-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00163}00163                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00164}00164                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00165}00165                 \textcolor{keywordflow}{case} 1:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00166}00166                         le64enc(p, gl-\/>\mbox{\hyperlink{structg__bde__key_a24a6da7f1a62a46ce669f45927f00307}{sectorN}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00167}00167                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00168}00168                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00169}00169                 \textcolor{keywordflow}{case} 2:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00170}00170                         le64enc(p, gl-\/>\mbox{\hyperlink{structg__bde__key_a584abb7851a7de46edfcee8b05f6f13f}{keyoffset}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00171}00171                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00172}00172                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00173}00173                 \textcolor{keywordflow}{case} 3:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00174}00174                         le32enc(p, gl-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00175}00175                         p += 4;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00176}00176                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00177}00177                 \textcolor{keywordflow}{case} 4:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00178}00178                         le32enc(p, gl-\/>\mbox{\hyperlink{structg__bde__key_a1012e5b3d52eba182fd2f716d2e7d84f}{flags}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00179}00179                         p += 4;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00180}00180                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00181}00181                 \textcolor{keywordflow}{case} 5:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00182}00182                 \textcolor{keywordflow}{case} 6:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00183}00183                 \textcolor{keywordflow}{case} 7:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00184}00184                 \textcolor{keywordflow}{case} 8:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00185}00185                         le64enc(p, gl-\/>\mbox{\hyperlink{structg__bde__key_ad26d0aae2eb539ddd316bdaac5a6fabe}{lsector}}[shuffle[i] -\/ 5]);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00186}00186                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00187}00187                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00188}00188                 \textcolor{keywordflow}{case} 9:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00189}00189                         bcopy(gl-\/>\mbox{\hyperlink{structg__bde__key_ab34992a035e2b0c5f3331bee50b92da8}{spare}}, p, \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_ab34992a035e2b0c5f3331bee50b92da8}{spare}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00190}00190                         p += \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_ab34992a035e2b0c5f3331bee50b92da8}{spare}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00191}00191                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00192}00192                 \textcolor{keywordflow}{case} 10:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00193}00193                         bcopy(gl-\/>\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}}, p, \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00194}00194                         p += \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00195}00195                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00196}00196                 \textcolor{keywordflow}{case} 11:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00197}00197                         bcopy(gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}}, p, \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00198}00198                         p += \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00199}00199                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00200}00200                 \textcolor{keywordflow}{case} 12:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00201}00201                         bzero(p, 16);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00202}00202                         hash = p;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00203}00203                         p += 16;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00204}00204                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00205}00205                 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00206}00206         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00207}00207         \textcolor{keywordflow}{if}(ptr + \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}} != p)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00208}00208                 \textcolor{keywordflow}{return}(-\/1);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00209}00209         \textcolor{keywordflow}{if} (hash == NULL)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00210}00210                 \textcolor{keywordflow}{return}(-\/1);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00211}00211         MD5Init(\&c);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00212}00212         MD5Update(\&c, \textcolor{stringliteral}{"{}0000"{}}, 4);       \textcolor{comment}{/* Versioning */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00213}00213         MD5Update(\&c, ptr, \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00214}00214         MD5Final(hash, \&c);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00215}00215         \textcolor{keywordflow}{return}(0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00216}00216 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00217}00217 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00218}00218 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00219}\mbox{\hyperlink{g__bde_8h_af339e70d3ac7ec78e2151533ffe938c3}{00219}} \mbox{\hyperlink{g__bde__lock_8c_af339e70d3ac7ec78e2151533ffe938c3}{g\_bde\_decode\_lock}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc, \textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__key}{g\_bde\_key}} *gl, u\_char *ptr)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00220}00220 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00221}00221         \textcolor{keywordtype}{int} shuffle[\mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}}];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00222}00222         u\_char *p;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00223}00223         u\_char hash[16], hash2[16];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00224}00224         MD5\_CTX c;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00225}00225         \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00226}00226 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00227}00227         p = ptr;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00228}00228         \mbox{\hyperlink{g__bde__lock_8c_a0a04f943aec21bc49009147950e87c19}{g\_bde\_shuffle\_lock}}(sc-\/>\mbox{\hyperlink{structg__bde__softc_a3004ff7ec5e1294d1cca2bbd35ea3e29}{sha2}}, shuffle);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00229}00229         \textcolor{keywordflow}{for} (i = 0; i < \mbox{\hyperlink{g__bde_8h_a21fe3d6953b8844e9257ed9e1e1f2b6b}{NLOCK\_FIELDS}}; i++) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00230}00230                 \textcolor{keywordflow}{switch}(shuffle[i]) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00231}00231                 \textcolor{keywordflow}{case} 0:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00232}00232                         gl-\/>\mbox{\hyperlink{structg__bde__key_ac3bc453b01531611394dcabb3c25ead6}{sector0}} = le64dec(p);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00233}00233                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00234}00234                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00235}00235                 \textcolor{keywordflow}{case} 1:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00236}00236                         gl-\/>\mbox{\hyperlink{structg__bde__key_a24a6da7f1a62a46ce669f45927f00307}{sectorN}} = le64dec(p);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00237}00237                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00238}00238                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00239}00239                 \textcolor{keywordflow}{case} 2:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00240}00240                         gl-\/>\mbox{\hyperlink{structg__bde__key_a584abb7851a7de46edfcee8b05f6f13f}{keyoffset}} = le64dec(p);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00241}00241                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00242}00242                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00243}00243                 \textcolor{keywordflow}{case} 3:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00244}00244                         gl-\/>\mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}} = le32dec(p);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00245}00245                         p += 4;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00246}00246                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00247}00247                 \textcolor{keywordflow}{case} 4:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00248}00248                         gl-\/>\mbox{\hyperlink{structg__bde__key_a1012e5b3d52eba182fd2f716d2e7d84f}{flags}} = le32dec(p);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00249}00249                         p += 4;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00250}00250                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00251}00251                 \textcolor{keywordflow}{case} 5:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00252}00252                 \textcolor{keywordflow}{case} 6:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00253}00253                 \textcolor{keywordflow}{case} 7:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00254}00254                 \textcolor{keywordflow}{case} 8:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00255}00255                         gl-\/>\mbox{\hyperlink{structg__bde__key_ad26d0aae2eb539ddd316bdaac5a6fabe}{lsector}}[shuffle[i] -\/ 5] = le64dec(p);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00256}00256                         p += 8;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00257}00257                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00258}00258                 \textcolor{keywordflow}{case} 9:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00259}00259                         bcopy(p, gl-\/>\mbox{\hyperlink{structg__bde__key_ab34992a035e2b0c5f3331bee50b92da8}{spare}}, \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_ab34992a035e2b0c5f3331bee50b92da8}{spare}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00260}00260                         p += \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_ab34992a035e2b0c5f3331bee50b92da8}{spare}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00261}00261                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00262}00262                 \textcolor{keywordflow}{case} 10:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00263}00263                         bcopy(p, gl-\/>\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}}, \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00264}00264                         p += \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_abb805853def101310aac4f48b0dd22a9}{salt}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00265}00265                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00266}00266                 \textcolor{keywordflow}{case} 11:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00267}00267                         bcopy(p, gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}}, \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00268}00268                         p += \textcolor{keyword}{sizeof} gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00269}00269                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00270}00270                 \textcolor{keywordflow}{case} 12:}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00271}00271                         bcopy(p, hash2, \textcolor{keyword}{sizeof} hash2);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00272}00272                         bzero(p, \textcolor{keyword}{sizeof} hash2);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00273}00273                         p += \textcolor{keyword}{sizeof} hash2;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00274}00274                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00275}00275                 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00276}00276         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00277}00277         \textcolor{keywordflow}{if}(ptr + \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}} != p)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00278}00278                 \textcolor{keywordflow}{return}(-\/1);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00279}00279         MD5Init(\&c);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00280}00280         MD5Update(\&c, \textcolor{stringliteral}{"{}0000"{}}, 4);       \textcolor{comment}{/* Versioning */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00281}00281         MD5Update(\&c, ptr, \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00282}00282         MD5Final(hash, \&c);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00283}00283         \textcolor{keywordflow}{if} (bcmp(hash, hash2, \textcolor{keyword}{sizeof} hash2))}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00284}00284                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00285}00285         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00286}00286 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00287}00287 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00288}00288 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00289}00289 \textcolor{comment}{ * Encode/Decode the locksector address ("{}metadata"{}) with key-\/material.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00290}00290 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00291}00291 \textcolor{comment}{ * Security objectives: Encode/Decode the metadata encrypted by key-\/material.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00292}00292 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00293}00293 \textcolor{comment}{ * A simple AES/128/CBC will do.  We take care to always store the metadata}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00294}00294 \textcolor{comment}{ * in the same endianness to make it MI.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00295}00295 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00296}00296 \textcolor{comment}{ * In the typical case the metadata is stored in encrypted format in sector}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00297}00297 \textcolor{comment}{ * zero on the media, but at the users discretion or if the piece of the}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00298}00298 \textcolor{comment}{ * device used (sector0...sectorN) does not contain sector zero, it can}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00299}00299 \textcolor{comment}{ * be stored in a filesystem or on a PostIt.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00300}00300 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00301}00301 \textcolor{comment}{ * The inability to easily locate the lock sectors makes an attack on a}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00302}00302 \textcolor{comment}{ * cold disk much less attractive, without unduly inconveniencing the}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00303}00303 \textcolor{comment}{ * legitimate user who can feasibly do a brute-\/force scan if the metadata}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00304}00304 \textcolor{comment}{ * was lost.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00305}00305 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00306}00306 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00307}00307 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00308}\mbox{\hyperlink{g__bde_8h_a5534d1f15d8ca8c1d65e97ecf4165c1b}{00308}} \mbox{\hyperlink{g__bde__lock_8c_a5534d1f15d8ca8c1d65e97ecf4165c1b}{g\_bde\_keyloc\_encrypt}}(u\_char *sha2, uint64\_t v0, uint64\_t v1, \textcolor{keywordtype}{void} *output)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00309}00309 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00310}00310         u\_char \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[16];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00311}00311         keyInstance ki;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00312}00312         cipherInstance ci;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00313}00313 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00314}00314         le64enc(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, v0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00315}00315         le64enc(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} + 8, v1);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00316}00316         \mbox{\hyperlink{g__bde_8h_ab5d14c928ffff64fb86d9524d0f5dada}{AES\_init}}(\&ci);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00317}00317         \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(\&ki, DIR\_ENCRYPT, \mbox{\hyperlink{g__bde_8h_ac023a67b536d4bd7b16f5a6e17b6614c}{G\_BDE\_KKEYBITS}}, sha2 + 0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00318}00318         \mbox{\hyperlink{g__bde_8h_ad6e8bd58e9bdf77aa27d86282309d0f4}{AES\_encrypt}}(\&ci, \&ki, \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, output, \textcolor{keyword}{sizeof} \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00319}00319         explicit\_bzero(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \textcolor{keyword}{sizeof} \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00320}00320         explicit\_bzero(\&ci, \textcolor{keyword}{sizeof} ci);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00321}00321         explicit\_bzero(\&ki, \textcolor{keyword}{sizeof} ki);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00322}00322         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00323}00323 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00324}00324 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00325}00325 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00326}\mbox{\hyperlink{g__bde_8h_a310e51f6b1a625aa5573d3888662a8ea}{00326}} \mbox{\hyperlink{g__bde__lock_8c_a310e51f6b1a625aa5573d3888662a8ea}{g\_bde\_keyloc\_decrypt}}(u\_char *sha2, \textcolor{keywordtype}{void} *input, uint64\_t *output)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00327}00327 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00328}00328         keyInstance ki;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00329}00329         cipherInstance ci;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00330}00330         u\_char \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}[16];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00331}00331 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00332}00332         \mbox{\hyperlink{g__bde_8h_ab5d14c928ffff64fb86d9524d0f5dada}{AES\_init}}(\&ci);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00333}00333         \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(\&ki, DIR\_DECRYPT, \mbox{\hyperlink{g__bde_8h_ac023a67b536d4bd7b16f5a6e17b6614c}{G\_BDE\_KKEYBITS}}, sha2 + 0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00334}00334         \mbox{\hyperlink{g__bde_8h_a51f1110fa4c35557b1a2cd0b7d184c9f}{AES\_decrypt}}(\&ci, \&ki, input, \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \textcolor{keyword}{sizeof} \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00335}00335         *output = le64dec(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00336}00336         explicit\_bzero(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \textcolor{keyword}{sizeof} \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00337}00337         explicit\_bzero(\&ci, \textcolor{keyword}{sizeof} ci);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00338}00338         explicit\_bzero(\&ki, \textcolor{keyword}{sizeof} ki);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00339}00339         \textcolor{keywordflow}{return}(0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00340}00340 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00341}00341 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00342}00342 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00343}00343 \textcolor{comment}{ * Find and Encode/Decode lock sectors.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00344}00344 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00345}00345 \textcolor{comment}{ * Security objective: given the pass-\/phrase, find, decrypt, decode and}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00346}00346 \textcolor{comment}{ * validate the lock sector contents.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00347}00347 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00348}00348 \textcolor{comment}{ * For ondisk metadata we cannot know beforehand which of the lock sectors}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00349}00349 \textcolor{comment}{ * a given pass-\/phrase opens so we must try each of the metadata copies in}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00350}00350 \textcolor{comment}{ * sector zero in turn.  If metadata was passed as an argument, we don't}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00351}00351 \textcolor{comment}{ * have this problem.}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00352}00352 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00353}00353 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00354}00354 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00355}00355 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00356}\mbox{\hyperlink{g__bde__lock_8c_a60c1935ea0796c6197939b75e11ab1e4}{00356}} \mbox{\hyperlink{g__bde__lock_8c_a60c1935ea0796c6197939b75e11ab1e4}{g\_bde\_decrypt\_lockx}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc, u\_char *meta, off\_t mediasize, u\_int sectorsize, u\_int *nkey)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00357}00357 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00358}00358         u\_char *\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, *q;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00359}00359         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__bde__key}{g\_bde\_key}} *gl;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00360}00360         uint64\_t off, q1;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00361}00361         \textcolor{keywordtype}{int} error, m, i;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00362}00362         keyInstance ki;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00363}00363         cipherInstance ci;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00364}00364 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00365}00365         gl = \&sc-\/>\mbox{\hyperlink{structg__bde__softc_aed5c45f058e35c02ee14c6707fcc0b37}{key}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00366}00366 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00367}00367         \textcolor{comment}{/* Try to decrypt the metadata */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00368}00368         error = \mbox{\hyperlink{g__bde__lock_8c_a310e51f6b1a625aa5573d3888662a8ea}{g\_bde\_keyloc\_decrypt}}(sc-\/>\mbox{\hyperlink{structg__bde__softc_a3004ff7ec5e1294d1cca2bbd35ea3e29}{sha2}}, meta, \&off);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00369}00369         \textcolor{keywordflow}{if} (error)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00370}00370                 \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00371}00371 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00372}00372         \textcolor{comment}{/* If it points into thin blue air, forget it */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00373}00373         \textcolor{keywordflow}{if} (off + \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}} > (uint64\_t)mediasize) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00374}00374                 off = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00375}00375                 \textcolor{keywordflow}{return} (EINVAL);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00376}00376         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00377}00377 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00378}00378         \textcolor{comment}{/* The lock data may span two physical sectors. */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00379}00379 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00380}00380         m = 1;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00381}00381         \textcolor{keywordflow}{if} (off \% \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}} > \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}} -\/ \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}})}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00382}00382                 m++;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00383}00383 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00384}00384         \textcolor{comment}{/* Read the suspected sector(s) */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00385}00385         \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} = \mbox{\hyperlink{geom_8h_a550c2071f79908eea3d1ccbf821c4e4f}{g\_read\_data}}(sc-\/>\mbox{\hyperlink{structg__bde__softc_a3bc97d06913991a91d0e7009c6991ce5}{consumer}},}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00386}00386                 off -\/ (off \% \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}),}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00387}00387                 m * \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}, \&error);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00388}00388         \textcolor{keywordflow}{if} (\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} == NULL) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00389}00389                 off = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00390}00390                 \textcolor{keywordflow}{return}(error);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00391}00391         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00392}00392 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00393}00393         \textcolor{comment}{/* Find the byte-\/offset of the stored byte sequence */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00394}00394         q = \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} + off \% \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00395}00395 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00396}00396         \textcolor{comment}{/* If it is all zero, somebody nuked our lock sector */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00397}00397         q1 = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00398}00398         \textcolor{keywordflow}{for} (i = 0; i < \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}}; i++)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00399}00399                 q1 += q[i];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00400}00400         \textcolor{keywordflow}{if} (q1 == 0) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00401}00401                 off = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00402}00402                 \mbox{\hyperlink{geom_8h_ad9924deb20de7b40cb6cf06e5ae28855}{g\_free}}(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00403}00403                 \textcolor{keywordflow}{return} (ESRCH);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00404}00404         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00405}00405 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00406}00406         \textcolor{comment}{/* Decrypt the byte-\/sequence in place */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00407}00407         \mbox{\hyperlink{g__bde_8h_ab5d14c928ffff64fb86d9524d0f5dada}{AES\_init}}(\&ci);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00408}00408         \mbox{\hyperlink{g__bde_8h_a7620f4db15c690c1dbf4dfc40a656727}{AES\_makekey}}(\&ki, DIR\_DECRYPT, 256, sc-\/>\mbox{\hyperlink{structg__bde__softc_a3004ff7ec5e1294d1cca2bbd35ea3e29}{sha2}} + 16);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00409}00409         \mbox{\hyperlink{g__bde_8h_a51f1110fa4c35557b1a2cd0b7d184c9f}{AES\_decrypt}}(\&ci, \&ki, q, q, \mbox{\hyperlink{g__bde_8h_a5f776be28c749118116249f13953d13c}{G\_BDE\_LOCKSIZE}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00410}00410 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00411}00411         \textcolor{comment}{/* Decode the byte-\/sequence */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00412}00412         i = \mbox{\hyperlink{g__bde__lock_8c_af339e70d3ac7ec78e2151533ffe938c3}{g\_bde\_decode\_lock}}(sc, gl, q);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00413}00413         q = NULL;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00414}00414         \textcolor{keywordflow}{if} (i < 0) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00415}00415                 off = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00416}00416                 \textcolor{keywordflow}{return} (EDOOFUS);       \textcolor{comment}{/* Programming error */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00417}00417         \} \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (i > 0) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00418}00418                 off = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00419}00419                 \textcolor{keywordflow}{return} (ENOTDIR);       \textcolor{comment}{/* Hash didn't match */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00420}00420         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00421}00421 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00422}00422         bzero(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}} * m);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00423}00423         \mbox{\hyperlink{geom_8h_ad9924deb20de7b40cb6cf06e5ae28855}{g\_free}}(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00424}00424 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00425}00425         \textcolor{comment}{/* If the masterkey is all zeros, user destroyed it */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00426}00426         q1 = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00427}00427         \textcolor{keywordflow}{for} (i = 0; i < (int)\textcolor{keyword}{sizeof}(gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}}); i++)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00428}00428                 q1 += gl-\/>\mbox{\hyperlink{structg__bde__key_a77621e014c439240f155633e58960277}{mkey}}[i];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00429}00429         if (q1 == 0)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00430}00430                 \textcolor{keywordflow}{return} (ENOENT);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00431}00431 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00432}00432         \textcolor{comment}{/* If we have an unsorted lock-\/sequence, refuse */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00433}00433         \textcolor{keywordflow}{for} (i = 0; i < \mbox{\hyperlink{g__bde_8h_a0f44849dd4673db8de19f94a741d27a7}{G\_BDE\_MAXKEYS}} -\/ 1; i++)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00434}00434                 \textcolor{keywordflow}{if} (gl-\/>\mbox{\hyperlink{structg__bde__key_ad26d0aae2eb539ddd316bdaac5a6fabe}{lsector}}[i] >= gl-\/>\mbox{\hyperlink{structg__bde__key_ad26d0aae2eb539ddd316bdaac5a6fabe}{lsector}}[i + 1])}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00435}00435                         \textcolor{keywordflow}{return} (EINVAL);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00436}00436 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00437}00437         \textcolor{comment}{/* Finally, find out which key was used by matching the byte offset */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00438}00438         \textcolor{keywordflow}{for} (i = 0; i < \mbox{\hyperlink{g__bde_8h_a0f44849dd4673db8de19f94a741d27a7}{G\_BDE\_MAXKEYS}}; i++)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00439}00439                 \textcolor{keywordflow}{if} (nkey != NULL \&\& off == gl-\/>\mbox{\hyperlink{structg__bde__key_ad26d0aae2eb539ddd316bdaac5a6fabe}{lsector}}[i])}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00440}00440                         *nkey = i;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00441}00441         off = 0;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00442}00442         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00443}00443 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00444}00444 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00445}00445 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00446}\mbox{\hyperlink{g__bde_8h_a39fd847b1c2a22e14446402feaf1442b}{00446}} \mbox{\hyperlink{g__bde__lock_8c_a39fd847b1c2a22e14446402feaf1442b}{g\_bde\_decrypt\_lock}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__bde__softc}{g\_bde\_softc}} *sc, u\_char *keymat, u\_char *meta, off\_t mediasize, u\_int \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}, u\_int *nkey)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00447}00447 \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00448}00448         u\_char *\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}}, buf1[16];}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00449}00449         \textcolor{keywordtype}{int} error, e, i;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00450}00450 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00451}00451         \textcolor{comment}{/* set up the key-\/material */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00452}00452         bcopy(keymat, sc-\/>\mbox{\hyperlink{structg__bde__softc_a3004ff7ec5e1294d1cca2bbd35ea3e29}{sha2}}, SHA512\_DIGEST\_LENGTH);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00453}00453 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00454}00454         \textcolor{comment}{/* If passed-\/in metadata is non-\/zero, use it */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00455}00455         bzero(buf1, \textcolor{keyword}{sizeof} buf1);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00456}00456         \textcolor{keywordflow}{if} (meta != NULL \&\& bcmp(buf1, meta, \textcolor{keyword}{sizeof} buf1))}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00457}00457                 \textcolor{keywordflow}{return} (\mbox{\hyperlink{g__bde__lock_8c_a60c1935ea0796c6197939b75e11ab1e4}{g\_bde\_decrypt\_lockx}}(sc, meta, mediasize,}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00458}00458                     \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}, nkey));}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00459}00459 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00460}00460         \textcolor{comment}{/* Read sector zero */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00461}00461         \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} = \mbox{\hyperlink{geom_8h_a550c2071f79908eea3d1ccbf821c4e4f}{g\_read\_data}}(sc-\/>\mbox{\hyperlink{structg__bde__softc_a3bc97d06913991a91d0e7009c6991ce5}{consumer}}, 0, \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}, \&error);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00462}00462         \textcolor{keywordflow}{if} (\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} == NULL)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00463}00463                 \textcolor{keywordflow}{return}(error);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00464}00464 }
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00465}00465         \textcolor{comment}{/* Try each index in turn, save indicative errors for final result */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00466}00466         error = EINVAL;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00467}00467         \textcolor{keywordflow}{for} (i = 0; i < \mbox{\hyperlink{g__bde_8h_a0f44849dd4673db8de19f94a741d27a7}{G\_BDE\_MAXKEYS}}; i++) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00468}00468                 e = \mbox{\hyperlink{g__bde__lock_8c_a60c1935ea0796c6197939b75e11ab1e4}{g\_bde\_decrypt\_lockx}}(sc, \mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}} + i * 16, mediasize,}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00469}00469                     \mbox{\hyperlink{structg__bde__key_a66aa1db7d90034f5b5ac35ba7a011ab7}{sectorsize}}, nkey);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00470}00470                 \textcolor{comment}{/* Success or destroyed master key terminates */}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00471}00471                 \textcolor{keywordflow}{if} (e == 0 || e == ENOENT) \{}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00472}00472                         error = e;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00473}00473                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00474}00474                 \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00475}00475                 \textcolor{keywordflow}{if} (e != 0 \&\& error == EINVAL)}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00476}00476                         error = e;}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00477}00477         \}}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00478}00478         \mbox{\hyperlink{geom_8h_ad9924deb20de7b40cb6cf06e5ae28855}{g\_free}}(\mbox{\hyperlink{g__part__if_8m_ac14417684334d01b4e1e807a19d92816}{buf}});}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00479}00479         \textcolor{keywordflow}{return} (error);}
\DoxyCodeLine{\Hypertarget{g__bde__lock_8c_source_l00480}00480 \}}

\end{DoxyCode}
