--- /dev/null
+APPLE PUBLIC SOURCE LICENSE
+Version 1.1 - April 19,1999
+
+Please read this License carefully before downloading this software.
+By downloading and using this software, you are agreeing to be bound
+by the terms of this License. If you do not or cannot agree to the
+terms of this License, please do not download or use the software.
+
+1. General; Definitions. This License applies to any program or other
+work which Apple Computer, Inc. ("Apple") publicly announces as
+subject to this Apple Public Source License and which contains a
+notice placed by Apple identifying such program or work as "Original
+Code" and stating that it is subject to the terms of this Apple Public
+Source License version 1.1 (or subsequent version thereof), as it may
+be revised from time to time by Apple ("License"). As used in this
+License:
+
+1.1 "Affected Original Code" means only those specific portions of
+Original Code that allegedly infringe upon any party's intellectual
+property rights or are otherwise the subject of a claim of
+infringement.
+
+1.2 "Applicable Patent Rights" mean: (a) in the case where Apple is
+the grantor of rights, (i) claims of patents that are now or hereafter
+acquired, owned by or assigned to Apple and (ii) that cover subject
+matter contained in the Original Code, but only to the extent
+necessary to use, reproduce and/or distribute the Original Code
+without infringement; and (b) in the case where You are the grantor of
+rights, (i) claims of patents that are now or hereafter acquired,
+owned by or assigned to You and (ii) that cover subject matter in Your
+Modifications, taken alone or in combination with Original Code.
+
+1.3 "Covered Code" means the Original Code, Modifications, the
+combination of Original Code and any Modifications, and/or any
+respective portions thereof.
+
+1.4 "Deploy" means to use, sublicense or distribute Covered Code other
+than for Your internal research and development (R&D), and includes
+without limitation, any and all internal use or distribution of
+Covered Code within Your business or organization except for R&D use,
+as well as direct or indirect sublicensing or distribution of Covered
+Code by You to any third party in any form or manner.
+
+1.5 "Larger Work" means a work which combines Covered Code or portions
+thereof with code not governed by the terms of this License.
+
+1.6 "Modifications" mean any addition to, deletion from, and/or change
+to, the substance and/or structure of Covered Code. When code is
+released as a series of files, a Modification is: (a) any addition to
+or deletion from the contents of a file containing Covered Code;
+and/or (b) any new file or other representation of computer program
+statements that contains any part of Covered Code.
+
+1.7 "Original Code" means (a) the Source Code of a program or other
+work as originally made available by Apple under this License,
+including the Source Code of any updates or upgrades to such programs
+or works made available by Apple under this License, and that has been
+expressly identified by Apple as such in the header file(s) of such
+work; and (b) the object code compiled from such Source Code and
+originally made available by Apple under this License.
+
+1.8 "Source Code" means the human readable form of a program or other
+work that is suitable for making modifications to it, including all
+modules it contains, plus any associated interface definition files,
+scripts used to control compilation and installation of an executable
+(object code).
+
+1.9 "You" or "Your" means an individual or a legal entity exercising
+rights under this License. For legal entities, "You" or "Your"
+includes any entity which controls, is controlled by, or is under
+common control with, You, where "control" means (a) the power, direct
+or indirect, to cause the direction or management of such entity,
+whether by contract or otherwise, or (b) ownership of fifty percent
+(50%) or more of the outstanding shares or beneficial ownership of
+such entity.
+
+2. Permitted Uses; Conditions & Restrictions. Subject to the terms
+and conditions of this License, Apple hereby grants You, effective on
+the date You accept this License and download the Original Code, a
+world-wide, royalty-free, non- exclusive license, to the extent of
+Apple's Applicable Patent Rights and copyrights covering the Original
+Code, to do the following:
+
+2.1 You may use, copy, modify and distribute Original Code, with or
+without Modifications, solely for Your internal research and
+development, provided that You must in each instance:
+
+(a) retain and reproduce in all copies of Original Code the copyright
+and other proprietary notices and disclaimers of Apple as they appear
+in the Original Code, and keep intact all notices in the Original Code
+that refer to this License;
+
+(b) include a copy of this License with every copy of Source Code of
+Covered Code and documentation You distribute, and You may not offer
+or impose any terms on such Source Code that alter or restrict this
+License or the recipients' rights hereunder, except as permitted under
+Section 6; and
+
+(c) completely and accurately document all Modifications that you have
+made and the date of each such Modification, designate the version of
+the Original Code you used, prominently include a file carrying such
+information with the Modifications, and duplicate the notice in
+Exhibit A in each file of the Source Code of all such Modifications.
+
+2.2 You may Deploy Covered Code, provided that You must in each
+ instance:
+
+(a) satisfy all the conditions of Section 2.1 with respect to the
+Source Code of the Covered Code;
+
+(b) make all Your Deployed Modifications publicly available in Source
+Code form via electronic distribution (e.g. download from a web site)
+under the terms of this License and subject to the license grants set
+forth in Section 3 below, and any additional terms You may choose to
+offer under Section 6. You must continue to make the Source Code of
+Your Deployed Modifications available for as long as you Deploy the
+Covered Code or twelve (12) months from the date of initial
+Deployment, whichever is longer;
+
+(c) if You Deploy Covered Code containing Modifications made by You,
+inform others of how to obtain those Modifications by filling out and
+submitting the information found at
+http://www.apple.com/publicsource/modifications.html, if available;
+and
+
+(d) if You Deploy Covered Code in object code, executable form only,
+include a prominent notice, in the code itself as well as in related
+documentation, stating that Source Code of the Covered Code is
+available under the terms of this License with information on how and
+where to obtain such Source Code.
+
+3. Your Grants. In consideration of, and as a condition to, the
+licenses granted to You under this License:
+
+(a) You hereby grant to Apple and all third parties a non-exclusive,
+royalty-free license, under Your Applicable Patent Rights and other
+intellectual property rights owned or controlled by You, to use,
+reproduce, modify, distribute and Deploy Your Modifications of the
+same scope and extent as Apple's licenses under Sections 2.1 and 2.2;
+and
+
+(b) You hereby grant to Apple and its subsidiaries a non-exclusive,
+worldwide, royalty-free, perpetual and irrevocable license, under Your
+Applicable Patent Rights and other intellectual property rights owned
+or controlled by You, to use, reproduce, execute, compile, display,
+perform, modify or have modified (for Apple and/or its subsidiaries),
+sublicense and distribute Your Modifications, in any form, through
+multiple tiers of distribution.
+
+4. Larger Works. You may create a Larger Work by combining Covered
+Code with other code not governed by the terms of this License and
+distribute the Larger Work as a single product. In each such
+instance, You must make sure the requirements of this License are
+fulfilled for the Covered Code or any portion thereof.
+
+5. Limitations on Patent License. Except as expressly stated in
+Section 2, no other patent rights, express or implied, are granted by
+Apple herein. Modifications and/or Larger Works may require
+additional patent licenses from Apple which Apple may grant in its
+sole discretion.
+
+6. Additional Terms. You may choose to offer, and to charge a fee
+for, warranty, support, indemnity or liability obligations and/or
+other rights consistent with the scope of the license granted herein
+("Additional Terms") to one or more recipients of Covered
+Code. However, You may do so only on Your own behalf and as Your sole
+responsibility, and not on behalf of Apple. You must obtain the
+recipient's agreement that any such Additional Terms are offered by
+You alone, and You hereby agree to indemnify, defend and hold Apple
+harmless for any liability incurred by or claims asserted against
+Apple by reason of any such Additional Terms.
+
+7. Versions of the License. Apple may publish revised and/or new
+versions of this License from time to time. Each version will be
+given a distinguishing version number. Once Original Code has been
+published under a particular version of this License, You may continue
+to use it under the terms of that version. You may also choose to use
+such Original Code under the terms of any subsequent version of this
+License published by Apple. No one other than Apple has the right to
+modify the terms applicable to Covered Code created under this
+License.
+
+8. NO WARRANTY OR SUPPORT. The Original Code may contain in whole or
+in part pre-release, untested, or not fully tested works. The
+Original Code may contain errors that could cause failures or loss of
+data, and may be incomplete or contain inaccuracies. You expressly
+acknowledge and agree that use of the Original Code, or any portion
+thereof, is at Your sole and entire risk. THE ORIGINAL CODE IS
+PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND
+AND APPLE AND APPLE'S LICENSOR(S) (FOR THE PURPOSES OF SECTIONS 8 AND
+9, APPLE AND APPLE'S LICENSOR(S) ARE COLLECTIVELY REFERRED TO AS
+"APPLE") EXPRESSLY DISCLAIM ALL WARRANTIES AND/OR CONDITIONS, EXPRESS
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+AND/OR CONDITIONS OF MERCHANTABILITY OR SATISFACTORY QUALITY AND
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
+RIGHTS. APPLE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE
+ORIGINAL CODE WILL MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF
+THE ORIGINAL CODE WILL BE UNINTERRUPTED OR ERROR- FREE, OR THAT
+DEFECTS IN THE ORIGINAL CODE WILL BE CORRECTED. NO ORAL OR WRITTEN
+INFORMATION OR ADVICE GIVEN BY APPLE OR AN APPLE AUTHORIZED
+REPRESENTATIVE SHALL CREATE A WARRANTY OR IN ANY WAY INCREASE THE
+SCOPE OF THIS WARRANTY. You acknowledge that the Original Code is not
+intended for use in the operation of nuclear facilities, aircraft
+navigation, communication systems, or air traffic control machines in
+which case the failure of the Original Code could lead to death,
+personal injury, or severe physical or environmental damage.
+
+9. Liability.
+
+9.1 Infringement. If any portion of, or functionality implemented by,
+the Original Code becomes the subject of a claim of infringement,
+Apple may, at its option: (a) attempt to procure the rights necessary
+for Apple and You to continue using the Affected Original Code; (b)
+modify the Affected Original Code so that it is no longer infringing;
+or (c) suspend Your rights to use, reproduce, modify, sublicense and
+distribute the Affected Original Code until a final determination of
+the claim is made by a court or governmental administrative agency of
+competent jurisdiction and Apple lifts the suspension as set forth
+below. Such suspension of rights will be effective immediately upon
+Apple's posting of a notice to such effect on the Apple web site that
+is used for implementation of this License. Upon such final
+determination being made, if Apple is legally able, without the
+payment of a fee or royalty, to resume use, reproduction,
+modification, sublicensing and distribution of the Affected Original
+Code, Apple will lift the suspension of rights to the Affected
+Original Code by posting a notice to such effect on the Apple web site
+that is used for implementation of this License. If Apple suspends
+Your rights to Affected Original Code, nothing in this License shall
+be construed to restrict You, at Your option and subject to applicable
+law, from replacing the Affected Original Code with non-infringing
+code or independently negotiating for necessary rights from such third
+party.
+
+9.2 LIMITATION OF LIABILITY. UNDER NO CIRCUMSTANCES SHALL APPLE BE
+LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF OR RELATING TO THIS LICENSE OR YOUR USE OR INABILITY TO
+USE THE ORIGINAL CODE, OR ANY PORTION THEREOF, WHETHER UNDER A THEORY
+OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY
+OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF
+ANY REMEDY. In no event shall Apple's total liability to You for all
+damages under this License exceed the amount of fifty dollars
+($50.00).
+
+10. Trademarks. This License does not grant any rights to use the
+trademarks or trade names "Apple", "Apple Computer", "Mac OS X", "Mac
+OS X Server" or any other trademarks or trade names belonging to Apple
+(collectively "Apple Marks") and no Apple Marks may be used to endorse
+or promote products derived from the Original Code other than as
+permitted by and in strict compliance at all times with Apple's third
+party trademark usage guidelines which are posted at
+http://www.apple.com/legal/guidelinesfor3rdparties.html.
+
+11. Ownership. Apple retains all rights, title and interest in and to
+the Original Code and any Modifications made by or on behalf of Apple
+("Apple Modifications"), and such Apple Modifications will not be
+automatically subject to this License. Apple may, at its sole
+discretion, choose to license such Apple Modifications under this
+License, or on different terms from those contained in this License or
+may choose not to license them at all. Apple's development, use,
+reproduction, modification, sublicensing and distribution of Covered
+Code will not be subject to this License.
+
+12. Termination.
+
+12.1 Termination. This License and the rights granted hereunder will
+ terminate:
+
+(a) automatically without notice from Apple if You fail to comply with
+any term(s) of this License and fail to cure such breach within 30
+days of becoming aware of such breach; (b) immediately in the event of
+the circumstances described in Section 13.5(b); or (c) automatically
+without notice from Apple if You, at any time during the term of this
+License, commence an action for patent infringement against Apple.
+
+12.2 Effect of Termination. Upon termination, You agree to
+immediately stop any further use, reproduction, modification,
+sublicensing and distribution of the Covered Code and to destroy all
+copies of the Covered Code that are in your possession or control.
+All sublicenses to the Covered Code which have been properly granted
+prior to termination shall survive any termination of this License.
+Provisions which, by their nature, should remain in effect beyond the
+termination of this License shall survive, including but not limited
+to Sections 3, 5, 8, 9, 10, 11, 12.2 and 13. Neither party will be
+liable to the other for compensation, indemnity or damages of any sort
+solely as a result of terminating this License in accordance with its
+terms, and termination of this License will be without prejudice to
+any other right or remedy of either party.
+
+13. Miscellaneous.
+
+13.1 Government End Users. The Covered Code is a "commercial item" as
+defined in FAR 2.101. Government software and technical data rights
+in the Covered Code include only those rights customarily provided to
+the public as defined in this License. This customary commercial
+license in technical data and software is provided in accordance with
+FAR 12.211 (Technical Data) and 12.212 (Computer Software) and, for
+Department of Defense purchases, DFAR 252.227-7015 (Technical Data --
+Commercial Items) and 227.7202-3 (Rights in Commercial Computer
+Software or Computer Software Documentation). Accordingly, all U.S.
+Government End Users acquire Covered Code with only those rights set
+forth herein.
+
+13.2 Relationship of Parties. This License will not be construed as
+creating an agency, partnership, joint venture or any other form of
+legal association between You and Apple, and You will not represent to
+the contrary, whether expressly, by implication, appearance or
+otherwise.
+
+13.3 Independent Development. Nothing in this License will impair
+Apple's right to acquire, license, develop, have others develop for
+it, market and/or distribute technology or products that perform the
+same or similar functions as, or otherwise compete with,
+Modifications, Larger Works, technology or products that You may
+develop, produce, market or distribute.
+
+13.4 Waiver; Construction. Failure by Apple to enforce any provision
+of this License will not be deemed a waiver of future enforcement of
+that or any other provision. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+will not apply to this License.
+
+13.5 Severability. (a) If for any reason a court of competent
+jurisdiction finds any provision of this License, or portion thereof,
+to be unenforceable, that provision of the License will be enforced to
+the maximum extent permissible so as to effect the economic benefits
+and intent of the parties, and the remainder of this License will
+continue in full force and effect. (b) Notwithstanding the foregoing,
+if applicable law prohibits or restricts You from fully and/or
+specifically complying with Sections 2 and/or 3 or prevents the
+enforceability of either of those Sections, this License will
+immediately terminate and You must immediately discontinue any use of
+the Covered Code and destroy all copies of it that are in your
+possession or control.
+
+13.6 Dispute Resolution. Any litigation or other dispute resolution
+between You and Apple relating to this License shall take place in the
+Northern District of California, and You and Apple hereby consent to
+the personal jurisdiction of, and venue in, the state and federal
+courts within that District with respect to this License. The
+application of the United Nations Convention on Contracts for the
+International Sale of Goods is expressly excluded.
+
+13.7 Entire Agreement; Governing Law. This License constitutes the
+entire agreement between the parties with respect to the subject
+matter hereof. This License shall be governed by the laws of the
+United States and the State of California, except that body of
+California law concerning conflicts of law.
+
+Where You are located in the province of Quebec, Canada, the following
+clause applies: The parties hereby confirm that they have requested
+that this License and all related documents be drafted in English. Les
+parties ont exige que le present contrat et tous les documents
+connexes soient rediges en anglais.
+
+EXHIBIT A.
+
+"Portions Copyright (c) 1999-2000 Apple Computer, Inc. All Rights
+Reserved. This file contains Original Code and/or Modifications of
+Original Code as defined in and that are subject to the Apple Public
+Source License Version 1.1 (the "License"). You may not use this file
+except in compliance with the License. Please obtain a copy of the
+License at http://www.apple.com/publicsource and read it before using
+this file.
+
+The Original Code and all software distributed under the License are
+distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
+License for the specific language governing rights and limitations
+under the License."
# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags
# passed to ld/libtool (defaults to nothing)
+WARNING_CFLAGS = -Wall
# Library and Framework projects only:
# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked
-INCLUDED_ARCHS = ppc
-OTHER_RECURSIVE_VARIABLES += INCLUDED_ARCHS
-
###############################################################################
# Makefile.preamble
# Copyright 1997, Apple Computer, Inc.
HEADER_PATHS = -I$(SRCROOT)/bootx.tproj/include.subproj
-NEXTSTEP_PB_CFLAGS = -static
+NEXTSTEP_PB_CFLAGS = -static -msoft-float
NEXTSTEP_PB_LDFLAGS = -nostdlib -e _StartTVector -seg1addr 05600000
# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags
# passed to ld/libtool (defaults to nothing)
-WARNING_CFLAGS = -Wmost -Wno-format
-OPTIMIZE_BUILD_CFLAGS = -O0
+WARNING_CFLAGS = -Wall -Wno-format
+OPTIMIZE_BUILD_CFLAGS = -Os
# Library and Framework projects only:
# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked
# you do not have to (and shouldn't) add OTHER_*FLAGS to
# OTHER_RECURSIVE_VARIABLES.
-OTHER_RECURSIVE_VARIABLES = WARNING_CFLAGS OPTIMIZE_BUILD_CFLAGS
+INCLUDED_ARCHS=ppc
+OTHER_RECURSIVE_VARIABLES = WARNING_CFLAGS OPTIMIZE_BUILD_CFLAGS INCLUDED_ARCHS
LIBRARY_STYLE = STATIC
# Additional headers to export beyond those in the PB.project:
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
CICell ihandle;
long ret;
+ // intercept software RAID's virtual devices
+ if(isRAIDPath(devSpec))
+ return (CICell)RAIDOpen(devSpec);
+
ciArgs.service = "open";
ciArgs.nArgs = 1;
ciArgs.nReturns = 1;
{
CIArgs ciArgs;
+ if(isRAIDDevice((void*)ihandle)) {
+ RAIDClose((RAIDDevicePtr)ihandle);
+ return;
+ }
+
ciArgs.service = "close";
ciArgs.nArgs = 1;
ciArgs.nReturns = 0;
long actual;
long ret;
+ if(isRAIDDevice((void*)ihandle))
+ return RAIDRead((RAIDDevicePtr)ihandle, addr, length, -1);
+
ciArgs.service = "read";
ciArgs.nArgs = 3;
ciArgs.nReturns = 1;
CIArgs ciArgs;
long actual;
long ret;
+
+ if(isRAIDDevice((void*)ihandle)) {
+ printf("who's trying to write to RAID?!\n");
+ return -1;
+ }
ciArgs.service = "write";
ciArgs.nArgs = 3;
CIArgs ciArgs;
long ret;
+ if(isRAIDDevice((void*)ihandle))
+ return RAIDSeek((RAIDDevicePtr)ihandle, position);
+
ciArgs.service = "seek";
ciArgs.nArgs = 3;
ciArgs.nReturns = 1;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
return ch;
}
+
+int puts(const char *str)
+{
+ while (*str != '\0')
+ putchar(*str++);
+
+ putchar('\n');
+
+ return 0;
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
ufs_byteorder.h
CFILES = cache.c ext2fs.c ext2fs_bswap.c fs.c hfs.c HFSCompare.c\
- net.c ufs.c ufs_byteorder.c
+ net.c ufs.c ufs_byteorder.c md5c.c
OTHERSRCS = Makefile.preamble Makefile Makefile.postamble
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
long CacheRead(CICell ih, char *buffer, long long offset,
long length, long cache)
{
- long cnt, oldestEntry, oldestTime, loadCache = 0;
+ long cnt, oldestEntry = 0, oldestTime, loadCache = 0;
CacheEntry *entry;
// See if the data can be cached.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
return 0;
}
+// XX no support in AppleFileSystemDriver yet
+long Ext2GetUUID(CICell ih, char *uuidStr)
+{
+ uint8_t *uuid = gFS->e2fs.e2fs_uuid;
+
+ if (Ext2InitPartition(ih) == -1) return -1;
+
+ return CreateUUIDString(uuid, sizeof(gFS->e2fs.e2fs_uuid), uuidStr);
+}
+
// Private functions
static long HowMany(long bufferSize, long unitSize)
// Get Double Indirect Block Number.
if (blockNum < (refsPerBlock * refsPerBlock)) {
- indBlockNum = fileInode->e2di_blocks[NDADDR + 1];
+ indBlockNum = bswap32(fileInode->e2di_blocks[NDADDR + 1]);
} else {
- blockNum -= refsPerBlock * refsPerBlock;
+ blockNum -= refsPerBlock * refsPerBlock;
- // Get Triple Indirect Block Number.
- indBlockNum = fileInode->e2di_blocks[NDADDR + 2];
+ // Get Triple Indirect Block Number.
+ indBlockNum = bswap32(fileInode->e2di_blocks[NDADDR + 2]);
- indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1);
- indBlockOff = blockNum / (refsPerBlock * refsPerBlock);
- blockNum %= (refsPerBlock * refsPerBlock);
- indBlockNum = bswap32(((u_int32_t *)indBlock)[indBlockOff]);
+ indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1);
+ indBlockOff = blockNum / (refsPerBlock * refsPerBlock);
+ blockNum %= (refsPerBlock * refsPerBlock);
+ indBlockNum = bswap32(((u_int32_t *)indBlock)[indBlockOff]);
}
indBlock = ReadBlock(indBlockNum, 0, gBlockSize, 0, 1);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* fs.c - Generic access to the file system modules.
*
- * Copyright (c) 1999-2000 Apple Computer, Inc.
+ * Copyright (c) 1999-2004 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
#include <sl.h>
+#include <sys/md5.h>
typedef long (* FSLoadFile)(CICell ih, char *filePath);
+typedef long (* FSReadFile)(CICell ih, char *filePath,
+ void *base, unsigned long offset,
+ unsigned long length);
typedef long (* FSGetDirEntry)(CICell ih, char *dirPath,
long *dirIndex, char **name,
long *flags, long *time);
+typedef long (* FSGetUUID)(CICell ih, char *uuidStr);
#define kPartNet (0)
#define kPartHFS (1)
long partType;
CICell partIH;
FSLoadFile loadFile;
+ FSReadFile readFile;
FSGetDirEntry getDirEntry;
+ FSGetUUID getUUID;
char partName[1024];
};
typedef struct PartInfo PartInfo, *PartInfoPtr;
return length;
}
+long LoadThinFatFile(char *fileSpec, void **binary)
+{
+ char devSpec[256];
+ char *filePath;
+ FSLoadFile loadFile;
+ FSReadFile readFile;
+ long ret, length, length2, partIndex;
+
+ ret = ConvertFileSpec(fileSpec, devSpec, &filePath);
+ if ((ret == -1) || (filePath == NULL)) return -1;
+
+ // Get the partition index for devSpec.
+ partIndex = LookupPartition(devSpec);
+ if (partIndex == -1) return -1;
+
+ *binary = (void *)kLoadAddr;
+
+ readFile = gParts[partIndex].readFile;
+
+ if (readFile != NULL) {
+ // Read the first 4096 bytes (fat header)
+ length = readFile(gParts[partIndex].partIH, filePath, *binary, 0, 0x1000);
+ if (length > 0) {
+ if (ThinFatBinary(binary, &length) == 0) {
+ // We found a fat binary; read only the thin part
+ length = readFile(gParts[partIndex].partIH, filePath,
+ (void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length);
+ *binary = (void *)kLoadAddr;
+ } else {
+ // Not a fat binary; read the rest of the file
+ length2 = readFile(gParts[partIndex].partIH, filePath, (void *)(kLoadAddr + length), length, 0);
+ if (length2 == -1) return -1;
+ length += length2;
+ }
+ }
+ } else {
+ loadFile = gParts[partIndex].loadFile;
+ length = loadFile(gParts[partIndex].partIH, filePath);
+ if (length > 0) {
+ ThinFatBinary(binary, &length);
+ }
+ }
+
+ return length;
+}
+
+long GetFSUUID(char *spec, char *uuidStr)
+{
+ long rval = -1, partIndex;
+ FSGetUUID getUUID;
+ char devSpec[256];
+
+ do {
+ if(ConvertFileSpec(spec, devSpec, NULL)) break;
+
+ // Get the partition index
+ partIndex = LookupPartition(devSpec);
+ if (partIndex == -1) break;
+
+ getUUID = gParts[partIndex].getUUID;
+ if(getUUID)
+ rval = getUUID(gParts[partIndex].partIH, uuidStr);
+ } while(0);
+
+ return rval;
+}
+
+
+// from our uuid/namespace.h (UFS and HFS uuids can live in the same space?)
+static char kFSUUIDNamespaceSHA1[] = {0xB3,0xE2,0x0F,0x39,0xF2,0x92,0x11,0xD6,0x97,0xA4,0x00,0x30,0x65,0x43,0xEC,0xAC};
+
+// filesystem-specific getUUID functions call this shared string generator
+long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr)
+{
+ unsigned fmtbase, fmtidx, i;
+ uint8_t uuidfmt[] = { 4, 2, 2, 2, 6 };
+ char *p = uuidStr;
+ MD5_CTX md5c;
+ uint8_t mdresult[16];
+
+ bzero(mdresult, sizeof(mdresult));
+
+ // just like AppleFileSystemDriver
+ MD5Init(&md5c);
+ MD5Update(&md5c, kFSUUIDNamespaceSHA1, sizeof(kFSUUIDNamespaceSHA1));
+ MD5Update(&md5c, uubytes, nbytes);
+ MD5Final(mdresult, &md5c);
+
+ // this UUID has been made version 3 style (i.e. via namespace)
+ // see "-uuid-urn-" IETF draft (which otherwise copies byte for byte)
+ mdresult[6] = 0x30 | ( mdresult[6] & 0x0F );
+ mdresult[8] = 0x80 | ( mdresult[8] & 0x3F );
+
+
+ // generate the text: e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292
+ i = 0; fmtbase = 0;
+ for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) {
+ for(i=0; i < uuidfmt[fmtidx]; i++) {
+ uint8_t byte = mdresult[fmtbase+i];
+ char nib;
+
+ nib = byte >> 4;
+ *p = nib + '0'; // 0x4 -> '4'
+ if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
+ p++;
+
+ nib = byte & 0xf;
+ *p = nib + '0'; // 0x4 -> '4'
+ if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
+ p++;
+
+ }
+ fmtbase += i;
+ if(fmtidx < sizeof(uuidfmt)-1)
+ *(p++) = '-';
+ else
+ *p = '\0';
+ }
+
+ return 0;
+}
+
long GetFileInfo(char *dirSpec, char *name, long *flags, long *time)
{
long ret, index = 0;
switch (partType) {
case kPartNet:
gParts[partIndex].loadFile = NetLoadFile;
+ gParts[partIndex].readFile = NULL;
gParts[partIndex].getDirEntry = NetGetDirEntry;
+ gParts[partIndex].getUUID = NULL;
break;
case kPartHFS:
gParts[partIndex].loadFile = HFSLoadFile;
+ gParts[partIndex].readFile = HFSReadFile;
gParts[partIndex].getDirEntry = HFSGetDirEntry;
+ gParts[partIndex].getUUID = HFSGetUUID;
break;
case kPartUFS:
gParts[partIndex].loadFile = UFSLoadFile;
+ gParts[partIndex].readFile = UFSReadFile;
gParts[partIndex].getDirEntry = UFSGetDirEntry;
+ gParts[partIndex].getUUID = UFSGetUUID;
break;
case kPartExt2:
gParts[partIndex].loadFile = Ext2LoadFile;
+ gParts[partIndex].readFile = NULL;
gParts[partIndex].getDirEntry = Ext2GetDirEntry;
+ gParts[partIndex].getUUID = NULL;
+ // Ext2GetUUID exists, but there's no kernel support
break;
}
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* hfs.c - File System Module for HFS and HFS+.
*
- * Copyright (c) 1999-2002 Apple Computer, Inc.
+ * Copyright (c) 1999-2004 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
static char gHFSPlusHeader[kBlockSize];
static HFSPlusVolumeHeader *gHFSPlus =(HFSPlusVolumeHeader*)gHFSPlusHeader;
static char gLinkTemp[64];
+static long long gVolID;
-static long ReadFile(void *file, long *length);
+static long ReadFile(void *file, long *length, void *base, long offset);
static long GetCatalogEntryInfo(void *entry, long *flags, long *time);
static long ResolvePathToCatalogEntry(char *filePath, long *flags,
void *entry, long dirID, long *dirIndex);
gBlockSize = gHFSMDB->drAlBlkSiz;
CacheInit(ih, gBlockSize);
gCurrentIH = ih;
+
+ // grab the 64 bit volume ID
+ bcopy(&gHFSMDB->drFndrInfo[6], &gVolID, 8);
// Get the Catalog BTree node size.
extent = (HFSExtentDescriptor *)&gHFSMDB->drCTExtRec;
Seek(ih, gAllocationOffset + kMDBBaseOffset);
Read(ih, (long)gHFSPlusHeader, kBlockSize);
+//printf("checking signatures...\n");
// Not a HFS[+] volume.
if ((gHFSPlus->signature != kHFSPlusSigWord) &&
(gHFSPlus->signature != kHFSXSigWord)) return -1;
-
+//printf("continuing with HFS\n");
+
gIsHFSPlus = 1;
gBlockSize = gHFSPlus->blockSize;
CacheInit(ih, gBlockSize);
gCurrentIH = ih;
+ // grab the 64 bit volume ID
+ bcopy(&gHFSPlus->finderInfo[24], &gVolID, 8);
+
// Get the Catalog BTree node size.
extent = &gHFSPlus->catalogFile.extents;
extentSize = gHFSPlus->catalogFile.logicalSize;
}
long HFSLoadFile(CICell ih, char *filePath)
+{
+ return HFSReadFile(ih, filePath, (void *)kLoadAddr, 0, 0);
+}
+
+extern long HFSReadFile(CICell ih, char *filePath, void *base,
+ unsigned long offset, unsigned long length)
{
char entry[512];
- long dirID, result, length, flags;
+ long dirID, result, flags;
if (HFSInitPartition(ih) == -1) return -1;
- printf("Loading HFS%s file: [%s] from %x.\n",
+ printf("%s HFS%s file: [%s] from %x.\n",
+ (((offset == 0) && (length == 0)) ? "Loading" : "Reading"),
(gIsHFSPlus ? "+" : ""), filePath, ih);
dirID = kHFSRootFolderID;
if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1;
// Check file owner and permissions.
- if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) return -1;
+ if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) {
+ printf("%s: permissions incorrect\n", filePath);
+ return -1;
+ }
- result = ReadFile(entry, &length);
+ result = ReadFile(entry, &length, base, offset);
if (result == -1) return -1;
return length;
return 0;
}
+long HFSGetUUID(CICell ih, char *uuidStr)
+{
+ if (HFSInitPartition(ih) == -1) return -1;
+ if (gVolID == 0LL) return -1;
+
+ return CreateUUIDString((uint8_t*)(&gVolID), sizeof(gVolID), uuidStr);
+}
+
// Private Functions
-static long ReadFile(void *file, long *length)
+static long ReadFile(void *file, long *length, void *base, long offset)
{
void *extents;
- long fileID;
+ long fileID, fileLength;
HFSCatalogFile *hfsFile = file;
HFSPlusCatalogFile *hfsPlusFile = file;
if (gIsHFSPlus) {
fileID = hfsPlusFile->fileID;
- *length = hfsPlusFile->dataFork.logicalSize;
+ fileLength = hfsPlusFile->dataFork.logicalSize;
extents = &hfsPlusFile->dataFork.extents;
} else {
fileID = hfsFile->fileID;
- *length = hfsFile->dataLogicalSize;
+ fileLength = hfsFile->dataLogicalSize;
extents = &hfsFile->dataExtents;
}
+ if (offset > fileLength) {
+ printf("Offset is too large.\n");
+ return -1;
+ }
+
+ if ((*length == 0) || ((offset + *length) > fileLength)) {
+ *length = fileLength - offset;
+ }
+
if (*length > kLoadSize) {
printf("File is too large.\n");
return -1;
}
- *length = ReadExtent((char *)extents, *length, fileID,
- 0, *length, (char *)kLoadAddr, 0);
+ *length = ReadExtent((char *)extents, fileLength, fileID,
+ offset, *length, base, 0);
return 0;
}
static long GetCatalogEntryInfo(void *entry, long *flags, long *time)
{
- long tmpTime;
+ long tmpTime = 0;
// Get information about the file.
switch (*(short *)entry) {
case kHFSPlusFolderRecord :
*flags = kFileTypeDirectory |
(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode & kPermMask);
- if (((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID != 0)
+ if (((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID != 0) {
+ static int nwarnings = 0;
+ if(nwarnings++ < 25) // so we don't warn for all in an Extensions walk
+ printf("non-root file owner detected: %d\n",
+ ((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID);
*flags |= kOwnerNotRoot;
+ }
tmpTime = ((HFSPlusCatalogFolder *)entry)->contentModDate;
break;
case kHFSPlusFileRecord :
*flags = kFileTypeFlat |
(((HFSPlusCatalogFile *)entry)->bsdInfo.fileMode & kPermMask);
- if (((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID != 0)
+ if (((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID != 0) {
+ printf("non-root file owner detected: %d\n",
+ ((HFSPlusCatalogFile *)entry)->bsdInfo.ownerID);
*flags |= kOwnerNotRoot;
+ }
tmpTime = ((HFSPlusCatalogFile *)entry)->contentModDate;
break;
void *entry, long dirID, long *dirIndex)
{
char *restPath;
- long result, cnt, subFolderID, tmpDirIndex;
+ long result, cnt, subFolderID = 0, tmpDirIndex;
HFSPlusCatalogFile *hfsPlusFile;
// Copy the file name to gTempStr
short extentFile;
char *nodeBuf;
BTNodeDescriptor *node;
- long nodeSize, result, entrySize;
- long curNode, index, lowerBound, upperBound;
+ long nodeSize, result = 0, entrySize = 0;
+ long curNode, index = 0, lowerBound, upperBound;
char *testKey, *recordData;
// Figure out which tree is being looked at.
--- /dev/null
+/*
+ * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ *
+ * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+ * rights reserved.
+ *
+ * License to copy and use this software is granted provided that it
+ * is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+ * Algorithm" in all material mentioning or referencing this software
+ * or this function.
+ *
+ * License is also granted to make and use derivative works provided
+ * that such works are identified as "derived from the RSA Data
+ * Security, Inc. MD5 Message-Digest Algorithm" in all material
+ * mentioning or referencing the derived work.
+ *
+ * RSA Data Security, Inc. makes no representations concerning either
+ * the merchantability of this software or the suitability of this
+ * software for any particular purpose. It is provided "as is"
+ * without express or implied warranty of any kind.
+ *
+ * These notices must be retained in any copies of any part of this
+ * documentation and/or software.
+ *
+ * $Id: md5c.c,v 1.2 2005/02/03 05:16:40 lindak Exp $
+ *
+ * This code is the same as the code published by RSA Inc. It has been
+ * edited for clarity and style only.
+ */
+
+#include <sys/types.h>
+
+#ifdef KERNEL
+#include <sys/systm.h>
+#else
+#include <string.h>
+#endif
+
+#include <sys/md5.h>
+
+
+#ifdef KERNEL
+#define memset(x,y,z) bzero(x,z);
+#define memcpy(x,y,z) bcopy(y, x, z)
+#endif
+
+#if defined(__i386__) || defined(__alpha__)
+#define Encode memcpy
+#define Decode memcpy
+#else /* __i386__ */
+
+/*
+ * Encodes input (u_int32_t) into output (unsigned char). Assumes len is
+ * a multiple of 4.
+ */
+
+/* XXX not prototyped, and not compatible with memcpy(). */
+static void
+Encode (output, input, len)
+ unsigned char *output;
+ u_int32_t *input;
+ unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/*
+ * Decodes input (unsigned char) into output (u_int32_t). Assumes len is
+ * a multiple of 4.
+ */
+
+static void
+Decode (output, input, len)
+ u_int32_t *output;
+ const unsigned char *input;
+ unsigned int len;
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((u_int32_t)input[j]) | (((u_int32_t)input[j+1]) << 8) |
+ (((u_int32_t)input[j+2]) << 16) | (((u_int32_t)input[j+3]) << 24);
+}
+#endif /* i386 */
+
+static unsigned char PADDING[64] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions. */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits. */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/*
+ * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+ * Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+ (a) += F ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define GG(a, b, c, d, x, s, ac) { \
+ (a) += G ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define HH(a, b, c, d, x, s, ac) { \
+ (a) += H ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+#define II(a, b, c, d, x, s, ac) { \
+ (a) += I ((b), (c), (d)) + (x) + (u_int32_t)(ac); \
+ (a) = ROTATE_LEFT ((a), (s)); \
+ (a) += (b); \
+ }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context. */
+
+void
+MD5Init (context)
+ MD5_CTX *context;
+{
+
+ context->count[0] = context->count[1] = 0;
+
+ /* Load magic initialization constants. */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
+}
+
+/*
+ * MD5 block update operation. Continues an MD5 message-digest
+ * operation, processing another message block, and updating the
+ * context.
+ */
+
+void
+MD5Update (context, input, inputLen)
+ MD5_CTX *context;
+ const unsigned char *input;
+ unsigned int inputLen;
+{
+ unsigned int i, index, partLen;
+
+ /* Compute number of bytes mod 64 */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+ /* Update number of bits */
+ if ((context->count[0] += ((u_int32_t)inputLen << 3))
+ < ((u_int32_t)inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((u_int32_t)inputLen >> 29);
+
+ partLen = 64 - index;
+
+ /* Transform as many times as possible. */
+ if (inputLen >= partLen) {
+ memcpy((void *)&context->buffer[index], (const void *)input,
+ partLen);
+ MD5Transform (context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform (context->state, &input[i]);
+
+ index = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ memcpy ((void *)&context->buffer[index], (const void *)&input[i],
+ inputLen-i);
+}
+
+/*
+ * MD5 padding. Adds padding followed by original length.
+ */
+
+void
+MD5Pad (context)
+ MD5_CTX *context;
+{
+ unsigned char bits[8];
+ unsigned int index, padLen;
+
+ /* Save number of bits */
+ Encode (bits, context->count, 8);
+
+ /* Pad out to 56 mod 64. */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ MD5Update (context, PADDING, padLen);
+
+ /* Append length (before padding) */
+ MD5Update (context, bits, 8);
+}
+
+/*
+ * MD5 finalization. Ends an MD5 message-digest operation, writing the
+ * the message digest and zeroizing the context.
+ */
+
+void
+MD5Final (digest, context)
+ unsigned char digest[16];
+ MD5_CTX *context;
+{
+ /* Do padding. */
+ MD5Pad (context);
+
+ /* Store state in digest */
+ Encode (digest, context->state, 16);
+
+ /* Zeroize sensitive information. */
+ memset ((void *)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block. */
+
+void
+MD5Transform (state, block)
+ u_int32_t state[4];
+ const unsigned char block[64];
+{
+ u_int32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+
+ Decode (x, block, 64);
+
+ /* Round 1 */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+ FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+ FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+ FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+ FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+ FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+ FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+ FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+ FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+ FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+ FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+ FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+ GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+ GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+ GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+ GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+ GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+ GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+ GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+ GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+ GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+ GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+ GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+ HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+ HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+ HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+ HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+ HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+ HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+ HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+ HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
+ HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+ HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+ II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+ II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+ II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+ II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+ II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+ II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+ II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+ II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+ II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+ II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information. */
+ memset ((void *)x, 0, sizeof (x));
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* ufs.c - File System Module for UFS.
*
- * Copyright (c) 1998-2002 Apple Computer, Inc.
+ * Copyright (c) 1998-2004 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
InodePtr fileInode, InodePtr dirInode);
static char *ReadFileBlock(InodePtr fileInode, long fragNum, long blockOffset,
long length, char *buffer, long cache);
-static long ReadFile(InodePtr fileInode, long *length);
+static long ReadFile(InodePtr fileInode, long *length,
+ void *base, long offset);
static CICell gCurrentIH;
static long long gPartitionBase;
static char gFSBuf[SBSIZE];
static struct fs *gFS;
+static struct ufslabel gUFSLabel; // for UUID
static long gBlockSize;
static long gBlockSizeOld;
static long gFragSize;
long UFSInitPartition(CICell ih)
{
+ int ret;
+
if (ih == gCurrentIH) return 0;
printf("UFSInitPartition: %x\n", ih);
gCurrentIH = 0;
-
- // Assume there is no Disk Label
+
+ // Assume UFS starts at the beginning of the device
gPartitionBase = 0;
+ // read the disk label to get the UUID
+ // (rumor has it that UFS headers can be either-endian on disk; hopefully
+ // that isn't true for this UUID field).
+ Seek(ih, gPartitionBase + UFS_LABEL_OFFSET);
+ ret = Read(ih, (long)&gUFSLabel, UFS_LABEL_SIZE);
+ if(ret != UFS_LABEL_SIZE)
+ bzero(&gUFSLabel, UFS_LABEL_SIZE);
+
// Look for the Super Block
Seek(ih, gPartitionBase + SBOFF);
Read(ih, (long)gFSBuf, SBSIZE);
gFS = (struct fs *)gFSBuf;
+//printf("looking for UFS magic ... \n");
if (gFS->fs_magic != FS_MAGIC) {
return -1;
}
+//printf("continuing w/UFS\n");
// Calculate the block size and set up the block cache.
gBlockSize = gFS->fs_bsize;
}
+long UFSGetUUID(CICell ih, char *uuidStr)
+{
+ long long uuid = gUFSLabel.ul_uuid;
+
+ if (UFSInitPartition(ih) == -1) return -1;
+ if (uuid == 0LL) return -1;
+
+ return CreateUUIDString((uint8_t*)(&uuid), sizeof(uuid), uuidStr);
+}
+
long UFSLoadFile(CICell ih, char *filePath)
{
- long ret, length, flags;
+ return UFSReadFile(ih, filePath, (void *)kLoadAddr, 0, 0);
+}
+
+long UFSReadFile(CICell ih, char *filePath, void *base,
+ unsigned long offset, unsigned long length)
+{
+ long ret, flags;
if (UFSInitPartition(ih) == -1) return -1;
- printf("Loading UFS file: [%s] from %x.\n", filePath, ih);
+ printf("%s UFS file: [%s] from %x.\n",
+ (((offset == 0) && (length == 0)) ? "Loading" : "Reading"),
+ filePath, ih);
// Skip one or two leading '\'.
if (*filePath == '\\') filePath++;
ret = ResolvePathToInode(filePath, &flags, &gFileInode, &gRootInode);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat)) return -1;
- if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) return -1;
+ if (flags & (kOwnerNotRoot | kPermGroupWrite | kPermOtherWrite)) {
+ printf("%s: permissions incorrect\n", filePath);
+ return -1;
+ }
- ret = ReadFile(&gFileInode, &length);
+ ret = ReadFile(&gFileInode, &length, base, offset);
if (ret == -1) return -1;
return length;
*flags |= inode->di_mode & kPermMask;
- if (inode->di_uid != 0) *flags |= kOwnerNotRoot;
+ if (inode->di_uid != 0) {
+ static int nwarnings = 0;
+ if(nwarnings++ < 25) // so we don't warn for all in an Extensions walk
+ printf("non-root file owner detected: %d\n", inode->di_uid);
+ *flags |= kOwnerNotRoot;
+ }
}
return 0;
}
-static long ReadFile(InodePtr fileInode, long *length)
+static long ReadFile(InodePtr fileInode, long *length, void *base, long offset)
{
- long bytesLeft, curSize, curFrag = 0;
- char *buffer, *curAddr = (char *)kLoadAddr;
+ long bytesLeft, curSize, curFrag;
+ char *buffer, *curAddr = (char *)base;
+
+ bytesLeft = fileInode->di_size;
- bytesLeft = *length = fileInode->di_size;
+ if (offset > bytesLeft) {
+ printf("Offset is too large.\n");
+ return -1;
+ }
+
+ if ((*length == 0) || ((offset + *length) > bytesLeft)) {
+ *length = bytesLeft - offset;
+ }
if (*length > kLoadSize) {
printf("File is too large.\n");
return -1;
}
+ bytesLeft = *length;
+ curFrag = (offset / gBlockSize) * gFragsPerBlock;
+ offset %= gBlockSize;
+
while (bytesLeft) {
- if (bytesLeft > gBlockSize) curSize = gBlockSize;
- else curSize = bytesLeft;
+ curSize = gBlockSize;
+ if (curSize > bytesLeft) curSize = bytesLeft;
+ if (offset != 0) curSize -= offset;
- buffer = ReadFileBlock(fileInode, curFrag, 0, curSize, curAddr, 0);
+ buffer = ReadFileBlock(fileInode, curFrag, offset, curSize, curAddr, 0);
if (buffer == 0) break;
+ if (offset != 0) offset = 0;
+
curFrag += gFragsPerBlock;
curAddr += curSize;
bytesLeft -= curSize;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* fs.h - Externs for the File System Modules
*
- * Copyright (c) 1999-2000 Apple Computer, Inc.
+ * Copyright (c) 1999-2004 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
// Externs for fs.c
extern long LoadFile(char *fileSpec);
+extern long LoadThinFatFile(char *fileSpec, void **binary);
extern long GetFileInfo(char *dirSpec, char *name, long *flags, long *time);
extern long GetDirEntry(char *dirSpec, long *dirIndex, char **name,
long *flags, long *time);
extern long DumpDir(char *dirSpec);
+extern long GetFSUUID(char *devSpec, char *uuidStr);
+extern long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr);
// Externs for cache.c
extern unsigned long gCacheHits;
// Externs for hfs.c
extern long HFSInitPartition(CICell ih);
extern long HFSLoadFile(CICell ih, char *filePath);
+extern long HFSReadFile(CICell ih, char *filePath,
+ void *base, unsigned long offset,
+ unsigned long length);
extern long HFSGetDirEntry(CICell ih, char *dirPath,
long *dirIndex, char **name,
long *flags, long *time);
+extern long HFSGetUUID(CICell ih, char *uuidStr);
// Externs for ufs.c
extern long UFSInitPartition(CICell ih);
extern long UFSLoadFile(CICell ih, char *filePath);
+extern long UFSReadFile(CICell ih, char *filePath,
+ void *base, unsigned long offset,
+ unsigned long length);
extern long UFSGetDirEntry(CICell ih, char *dirPath,
long *dirIndex, char **name,
long *flags, long *time);
+extern long UFSGetUUID(CICell ih, char *uuidStr);
// Externs for ext2.c
extern long Ext2InitPartition(CICell ih);
extern long Ext2GetDirEntry(CICell ih, char *dirPath,
long *dirIndex, char **name,
long *flags, long *time);
+extern long Ext2GetUUID(CICell ih, char *uuidStr);
#endif /* ! _BOOTX_FS_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
// ci_io.c
extern int putchar(int ch);
+extern int puts(const char *str);
// prf.c
-extern void prf(const char *fmt, unsigned int *adx, void (*putfn_p)(),
+extern void prf(const char *fmt, unsigned int *adx, int (*putfn_p)(int ch),
void *putfn_arg);
// printf.c
extern int strncmp(const char *s1, const char *s2, size_t len);
extern char *strcpy(char *s1, const char *s2);
extern char *strncpy(char *s1, const char *s2, size_t n);
-extern int ptol(char *str);
-extern int atoi(const char *str);
extern char *strncat(char *s1, const char *s2, size_t n);
extern char *strcat(char *s1, const char *s2);
extern int strncasecmp(const char *s1, const char *s2, size_t len);
extern int isdigit(char c);
extern char tolower(char c);
extern long strtol(const char *nptr, char **endptr, register int base);
+extern u_quad_t strtouq(const char *nptr, char **endptr, register int base);
// zalloc.c
extern void malloc_init(char *start, int size);
// mem.c
extern void *memcpy(void *dst, const void *src, size_t len);
extern void *memset(void *dst, int ch, size_t len);
+extern int memcmp(const void *b1, const void *b2, size_t len);
extern void bcopy(const void *src, void *dst, size_t len);
extern void bzero(void *dst, int len);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _BOOTX_SL_H_
#define _BOOTX_SL_H_
+// i.e. should we put up our failure screen; else back to OF
#define kFailToBoot (1)
/*
#define kMallocAddr (0x05400000)
#define kMallocSize (0x00200000)
+#define kMallocAddr_H (0x05400000)
+#define kMallocSize_H (0x00200000)
+#define kImageAddr_H (0x06000000)
+
// Default Output Level
#define kOutputLevelOff (0)
#define kOutputLevelFull (16)
#define kOptKey (0x201)
#define kShiftKey (0x202)
#define kControlKey (0x203)
+#define kDeleteKey (0x204)
// Mac OS X Booter Signature 'MOSX'
#define kMacOSXSignature (0x4D4F5358)
#include <sys/stat.h>
#include <sys/types.h>
+#include <stdint.h>
#include <ci.h>
#include <sl_words.h>
#include <fs.h>
#include <boot_args.h>
+// types for plist.c
+typedef enum {
+ kTagTypeNone = 0,
+ kTagTypeDict,
+ kTagTypeKey,
+ kTagTypeString,
+ kTagTypeInteger,
+ kTagTypeData,
+ kTagTypeDate,
+ kTagTypeFalse,
+ kTagTypeTrue,
+ kTagTypeArray
+} TagType;
+
+struct Tag {
+ TagType type;
+ char *string;
+ struct Tag *tag;
+ struct Tag *tagNext;
+};
+typedef struct Tag Tag, *TagPtr;
+
// Externs for main.c
extern char *gVectorSaveAddr;
extern long gKernelEntryPoint;
extern char gHaveKernelCache;
extern char gBootDevice[256];
extern char gBootFile[256];
+extern TagPtr gBootDict;
extern char gTempStr[4096];
extern CICell gStdOutIH;
extern CICell gKeyboardIH;
+// useful to activate debug logs near when a problem happens
+//extern int gDebugCount;
+
extern long ThinFatBinary(void **binary, unsigned long *length);
extern long GetDeviceType(char *devSpec);
extern long ConvertFileSpec(char *fileSpec, char *devSpec, char **filePath);
extern void *AllocateBootXMemory(long size);
extern long AllocateKernelMemory(long size);
extern long AllocateMemoryRange(char *rangeName, long start, long length);
-extern unsigned long Alder32(unsigned char *buffer, long length);
+extern unsigned long Adler32(unsigned char *buffer, long length);
// Externs for macho.c
extern long ThinFatBinaryMachO(void **binary, unsigned long *length);
extern CICell SearchForNodeMatching(CICell ph, long top, char *value);
// Externs for display.c
-extern long InitDisplays(void);
+extern long InitDisplays(int fill);
extern long DrawSplashScreen(long stage);
extern long DrawFailedBootPicture(void);
-extern void GetMainScreenPH(Boot_Video_Ptr video);
+extern void GetMainScreenPH(Boot_Video_Ptr video, int setProperties);
+void SplashPreview(void *src, u_int8_t * saveunder, u_int32_t savelen);
+void SplashProgress(u_int8_t * saveunder, int32_t firstBlob, int32_t select);
+
+// Externs for bmdecompress.c
+extern int DecompressData(void *srcbase, void *dstbase,
+ int dw, int dh, int bytesPerPixel, int rowbytes);
// Externs for drivers.c
extern long LoadDrivers(char *dirPath);
// Externs for lzss.c
extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen);
+
+// Externs for plist.c
+#define PLIST_DEBUG 0 // whether report parsing errors, etc
+
+extern TagPtr GetProperty(TagPtr dict, char *key);
+extern long ParseXML(char *buffer, TagPtr *dict);
+extern void FreeTag(TagPtr tag);
+#if PLIST_DEBUG
+extern void DumpTag(TagPtr tag, long depth);
+#endif
+
+
+// Externs/types for raid.c
+typedef struct RAIDMember *RAIDDevicePtr;
+
+extern int isRAIDPath(char *devSpec);
+extern int isRAIDDevice(void *ih);
+extern long LookForRAID(TagPtr bootDict);
+extern RAIDDevicePtr RAIDOpen(char *devSpec);
+extern void RAIDClose(RAIDDevicePtr raid);
+extern long RAIDRead(RAIDDevicePtr raid, long a, long n, long long offset);
+extern long RAIDSeek(RAIDDevicePtr raid, long long position);
+
+
#endif /* ! _BOOTX_SL_H_ */
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
return dst;
}
+
+int
+memcmp(const void *b1, const void *b2, size_t len)
+{
+ register long n = len;
+ unsigned char *m1 = (unsigned char *)b1;
+ unsigned char *m2 = (unsigned char *)b2;
+
+ while (n-- && (*m1 == *m2)) {
+ m1++;
+ m2++;
+ }
+
+ return ((n < 0) ? 0 : (*m1 - *m2));
+}
+
+
void bcopy(const void *src, void *dst, size_t len)
{
memcpy(dst, src, len);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
va_start(ap, fmt);
pi.str = str;
pi.last_str = 0;
- prf(fmt, (unsigned int *)ap, sputc, &pi);
+ prf(fmt, (unsigned int *)ap, (int (*)(int ch))sputc, &pi);
*pi.str = '\0';
va_end(ap);
return 0;
struct putc_info pi;
pi.str = str;
pi.last_str = str + len - 1;
- prf(fmt, (unsigned int *)ap, sputc, &pi);
+ prf(fmt, (unsigned int *)ap, (int (*)(int ch))sputc, &pi);
*pi.str = '\0';
return (pi.str - str);
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
return ret;
}
-int
-ptol(char *str)
-{
- register int c = *str;
-
- if (c <= '7' && c >= '0')
- c -= '0';
- else if (c <= 'h' && c >= 'a')
- c -= 'a';
- else c = 0;
- return c;
-}
-
-int
-atoi(const char *str)
-{
- register int sum = 0;
- while (*str == ' ' || *str == '\t')
- str++;
- while (*str >= '0' && *str <= '9') {
- sum *= 10;
- sum += *str++ - '0';
- }
- return sum;
-}
-
-
char *strncat(char *s1, const char *s2, size_t n)
{
register char *ret = s1;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
return (acc);
}
+/*
+ * Convert a string to an unsigned quad integer.
+ *
+ * Ignores `locale' stuff. Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+u_quad_t
+strtouq(nptr, endptr, base)
+ const char *nptr;
+ char **endptr;
+ register int base;
+{
+ register const char *s = nptr;
+ register u_quad_t acc;
+ register int c;
+ register u_quad_t qbase, cutoff;
+ register int neg, any, cutlim;
+
+ /*
+ * See strtoq for comments as to the logic used.
+ */
+ s = nptr;
+ do {
+ c = *s++;
+ } while (isspace(c));
+ if (c == '-') {
+ neg = 1;
+ c = *s++;
+ } else {
+ neg = 0;
+ if (c == '+')
+ c = *s++;
+ }
+ if ((base == 0 || base == 16) &&
+ c == '0' && (*s == 'x' || *s == 'X')) {
+ c = s[1];
+ s += 2;
+ base = 16;
+ }
+ if (base == 0)
+ base = c == '0' ? 8 : 10;
+ qbase = (unsigned)base;
+ cutoff = (u_quad_t)UQUAD_MAX / qbase;
+ cutlim = (u_quad_t)UQUAD_MAX % qbase;
+ for (acc = 0, any = 0;; c = *s++) {
+ if (isdigit(c))
+ c -= '0';
+ else if (isalpha(c))
+ c -= isupper(c) ? 'A' - 10 : 'a' - 10;
+ else
+ break;
+ if (c >= base)
+ break;
+ if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
+ any = -1;
+ else {
+ any = 1;
+ acc *= qbase;
+ acc += c;
+ }
+ }
+ if (any < 0) {
+ acc = UQUAD_MAX;
+// errno = ERANGE;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != 0)
+ *endptr = (char *)(any ? s - 1 : nptr);
+ return (acc);
+}
+
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
void
free(void *pointer)
{
- int i, tsize, found = 0;
+ int i, tsize = 0, found = 0;
char *start = pointer;
if (!zalloc_base) {
PROJECTVERSION = 2.8
PROJECT_TYPE = Component
-HFILES = appleboot.h clut.h elf.h failedboot.h netboot.h
+HFILES = appleboot.h clut.h elf.h failedboot.h netboot.h aesopt.h aestab.h aes.h
-CFILES = main.c macho.c device_tree.c display.c drivers.c elf.c lzss.c
+CFILES = main.c macho.c device_tree.c display.c drivers.c elf.c lzss.c aescrypt.c aeskey.c aestab.c bmdecompress.c plist.c raid.c
OTHERSRCS = Makefile.preamble Makefile Makefile.postamble
# DEBUG_BUILD_LDFLAGS, OPTIMIZE_BUILD_LDFLAGS, PROFILE_BUILD_LDFLAGS: flags
# passed to ld/libtool (defaults to nothing)
+WARNING_CFLAGS = -Wall
+
# Library and Framework projects only:
# INSTALL_NAME_DIRECTIVE: This directive ensures that executables linked
--- /dev/null
+/*
+ ---------------------------------------------------------------------------
+ Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
+
+ LICENSE TERMS
+
+ The free distribution and use of this software in both source and binary
+ form is allowed (with or without changes) provided that:
+
+ 1. distributions of this source code include the above copyright
+ notice, this list of conditions and the following disclaimer;
+
+ 2. distributions in binary form include the above copyright
+ notice, this list of conditions and the following disclaimer
+ in the documentation and/or other associated materials;
+
+ 3. the copyright holder's name is not used to endorse products
+ built using this software without specific written permission.
+
+ ALTERNATIVELY, provided that this notice is retained in full, this product
+ may be distributed under the terms of the GNU General Public License (GPL),
+ in which case the provisions of the GPL apply INSTEAD OF those given above.
+
+ DISCLAIMER
+
+ This software is provided 'as is' with no explicit or implied warranties
+ in respect of its properties, including, but not limited to, correctness
+ and/or fitness for purpose.
+ ---------------------------------------------------------------------------
+ Issue 28/01/2004
+
+ This file contains the definitions required to use AES in C. See aesopt.h
+ for optimisation details.
+*/
+
+#if !defined( _AES_H )
+#define _AES_H
+
+/* This include is used to find 8 & 32 bit unsigned integer types */
+#include <machine/limits.h>
+
+#if defined(__cplusplus)
+extern "C"
+{
+#endif
+
+#define AES_128 /* define if AES with 128 bit keys is needed */
+#define AES_192 /* define if AES with 192 bit keys is needed */
+#define AES_256 /* define if AES with 256 bit keys is needed */
+#define AES_VAR /* define if a variable key size is needed */
+
+/* The following must also be set in assembler files if being used */
+
+//#define AES_ENCRYPT /* if support for encryption is needed */
+#define AES_DECRYPT /* if support for decryption is needed */
+//#define AES_ERR_CHK /* for parameter checks & error return codes */
+
+#if UCHAR_MAX == 0xff /* an unsigned 8 bit type */
+ typedef unsigned char aes_08t;
+#else
+# error Please define aes_08t as an 8-bit unsigned integer type in aes.h
+#endif
+
+#if UINT_MAX == 4294967295 /* an unsigned 32 bit type */
+ typedef unsigned int aes_32t;
+#elif ULONG_MAX == 4294967295ul
+ typedef unsigned long aes_32t;
+#else
+# error Please define aes_32t as a 32-bit unsigned integer type in aes.h
+#endif
+
+#define AES_BLOCK_SIZE 16 /* the AES block size in bytes */
+#define N_COLS 4 /* the number of columns in the state */
+
+/* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */
+/* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */
+/* or 44, 52 or 60 32-bit words. For simplicity this code allocates */
+/* the maximum 60 word array for the key schedule for all key sizes */
+
+#if defined( AES_VAR ) || defined( AES_256 )
+#define KS_LENGTH 60
+#elif defined( AES_192 )
+#define KS_LENGTH 52
+#else
+#define KS_LENGTH 44
+#endif
+
+#if defined( AES_ERR_CHK )
+#define aes_ret int
+#define aes_good 0
+#define aes_error -1
+#else
+#define aes_ret void
+#endif
+
+#if !defined( AES_DLL ) /* implement normal/DLL functions */
+#define aes_rval aes_ret
+#else
+#define aes_rval aes_ret __declspec(dllexport) _stdcall
+#endif
+
+typedef struct
+{ aes_32t ks[KS_LENGTH];
+ aes_32t rn;
+} aes_encrypt_ctx;
+
+typedef struct
+{ aes_32t ks[KS_LENGTH];
+ aes_32t rn;
+} aes_decrypt_ctx;
+
+typedef struct
+{
+ aes_decrypt_ctx decrypt;
+ aes_encrypt_ctx encrypt;
+} aes_ctx;
+
+
+/* This routine must be called before first use if non-static */
+/* tables are being used */
+
+void gen_tabs(void);
+
+/* The key length (klen) is input in bytes when it is in the range */
+/* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */
+
+#if defined( AES_ENCRYPT )
+
+#if defined(AES_128) || defined(AES_VAR)
+aes_rval aes_encrypt_key128(const unsigned char *in_key, aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined(AES_192) || defined(AES_VAR)
+aes_rval aes_encrypt_key192(const unsigned char *in_key, aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined(AES_256) || defined(AES_VAR)
+aes_rval aes_encrypt_key256(const unsigned char *in_key, aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined(AES_VAR)
+aes_rval aes_encrypt_key(const unsigned char *in_key, int key_len, aes_encrypt_ctx cx[1]);
+#endif
+
+aes_rval aes_encrypt_cbc(const unsigned char *in_blk, const unsigned char *in_iv, unsigned int num_blk,
+ unsigned char *out_blk, const aes_encrypt_ctx cx[1]);
+#endif
+
+#if defined( AES_DECRYPT )
+
+#if defined(AES_128) || defined(AES_VAR)
+aes_rval aes_decrypt_key128(const unsigned char *in_key, aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined(AES_192) || defined(AES_VAR)
+aes_rval aes_decrypt_key192(const unsigned char *in_key, aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined(AES_256) || defined(AES_VAR)
+aes_rval aes_decrypt_key256(const unsigned char *in_key, aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined(AES_VAR)
+aes_rval aes_decrypt_key(const unsigned char *in_key, int key_len, aes_decrypt_ctx cx[1]);
+#endif
+
+aes_rval aes_decrypt_cbc(const unsigned char *in_blk, const unsigned char *in_iv, unsigned int num_blk,
+ unsigned char *out_blk, const aes_decrypt_ctx cx[1]);
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue 28/01/2004\r
+\r
+ This file contains the code for implementing encryption and decryption\r
+ for AES (Rijndael) for block and key sizes of 16, 24 and 32 bytes. It\r
+ can optionally be replaced by code written in assembler using NASM. For\r
+ further details see the file aesopt.h\r
+*/\r
+\r
+#include "aesopt.h"\r
+#include "aestab.h"\r
+\r
+#if defined(__cplusplus)\r
+extern "C"\r
+{\r
+#endif\r
+\r
+#define ki(y,x,k,c) (s(y,c) = s(x, c) ^ (k)[c])\r
+#define xo(y,x,c) (s(y,c) ^= s(x, c))\r
+#define si(y,x,c) (s(y,c) = word_in(x, c))\r
+#define so(y,x,c) word_out(y, c, s(x,c))\r
+\r
+#if defined(ARRAYS)\r
+#define locals(y,x) x[4],y[4]\r
+#else\r
+#define locals(y,x) x##0,x##1,x##2,x##3,y##0,y##1,y##2,y##3\r
+#endif\r
+\r
+#define dtables(tab) const aes_32t *tab##0, *tab##1, *tab##2, *tab##3\r
+#define itables(tab) tab##0 = tab[0]; tab##1 = tab[1]; tab##2 = tab[2]; tab##3 = tab[3]\r
+\r
+#define l_copy(y, x) s(y,0) = s(x,0); s(y,1) = s(x,1); \\r
+ s(y,2) = s(x,2); s(y,3) = s(x,3);\r
+\r
+#define key_in(y,x,k) ki(y,x,k,0); ki(y,x,k,1); ki(y,x,k,2); ki(y,x,k,3)\r
+#define cbc(y,x) xo(y,x,0); xo(y,x,1); xo(y,x,2); xo(y,x,3)\r
+#define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3)\r
+#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)\r
+#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3)\r
+\r
+#if defined(ENCRYPTION) && !defined(AES_ASM)\r
+\r
+/* Visual C++ .Net v7.1 provides the fastest encryption code when using\r
+ Pentium optimiation with small code but this is poor for decryption\r
+ so we need to control this with the following VC++ pragmas\r
+*/\r
+\r
+#if defined(_MSC_VER)\r
+#pragma optimize( "s", on )\r
+#endif\r
+\r
+/* Given the column (c) of the output state variable, the following\r
+ macros give the input state variables which are needed in its\r
+ computation for each row (r) of the state. All the alternative\r
+ macros give the same end values but expand into different ways\r
+ of calculating these values. In particular the complex macro\r
+ used for dynamically variable block sizes is designed to expand\r
+ to a compile time constant whenever possible but will expand to\r
+ conditional clauses on some branches (I am grateful to Frank\r
+ Yellin for this construction)\r
+*/\r
+\r
+#define fwd_var(x,r,c)\\r
+ ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\\r
+ : r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\\r
+ : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\\r
+ : ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2)))\r
+\r
+#if defined(FT4_SET)\r
+#undef dec_fmvars\r
+# if defined(ENC_ROUND_CACHE_TABLES)\r
+#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_fn,fwd_var,rf1,c))\r
+# else\r
+#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_fn,fwd_var,rf1,c))\r
+# endif\r
+#elif defined(FT1_SET)\r
+#undef dec_fmvars\r
+#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_fn,fwd_var,rf1,c))\r
+#else\r
+#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ fwd_mcol(no_table(x,t_sbox,fwd_var,rf1,c)))\r
+#endif\r
+\r
+#if defined(FL4_SET)\r
+# if defined(LAST_ENC_ROUND_CACHE_TABLES)\r
+#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_fl,fwd_var,rf1,c))\r
+# else\r
+#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_fl,fwd_var,rf1,c))\r
+# endif\r
+#elif defined(FL1_SET)\r
+#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_fl,fwd_var,rf1,c))\r
+#else\r
+#define fwd_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_sbox,fwd_var,rf1,c))\r
+#endif\r
+\r
+aes_rval aes_encrypt_cbc(const unsigned char *in, const unsigned char *in_iv, unsigned int num_blk,\r
+ unsigned char *out, const aes_encrypt_ctx cx[1])\r
+{ aes_32t locals(b0, b1);\r
+ const aes_32t *kp = cx->ks;\r
+#if defined(ENC_ROUND_CACHE_TABLES)\r
+ dtables(t_fn);\r
+#endif\r
+#if defined(LAST_ENC_ROUND_CACHE_TABLES)\r
+ dtables(t_fl);\r
+#endif\r
+\r
+#if defined( dec_fmvars )\r
+ dec_fmvars; /* declare variables for fwd_mcol() if needed */\r
+#endif\r
+\r
+#if defined( AES_ERR_CHK )\r
+ if( cx->rn != 10 && cx->rn != 12 && cx->rn != 14 )\r
+ return aes_error;\r
+#endif\r
+\r
+ // Load IV into b0.\r
+ state_in(b0, in_iv);\r
+\r
+ for (;num_blk; in += AES_BLOCK_SIZE, out += AES_BLOCK_SIZE, --num_blk)\r
+ {\r
+#if 0\r
+ // Read the plaintext into b1\r
+ state_in(b1, in);\r
+ // Do the CBC with b0 which is either the iv or the ciphertext of the previous block.\r
+ cbc(b1, b0);\r
+\r
+ // Xor b1 with the key schedule to get things started.\r
+ key_in(b0, b1, kp);\r
+#else\r
+ // Since xor is associative we mess with the ordering here to get the loads started early\r
+ key_in(b1, b0, kp); // Xor b0(IV) with the key schedule and assign to b1\r
+ state_in(b0, in); // Load block into b0\r
+ cbc(b0, b1); // Xor b0 with b1 and store in b0\r
+#endif\r
+\r
+#if defined(ENC_ROUND_CACHE_TABLES)\r
+ itables(t_fn);\r
+#endif\r
+\r
+#if (ENC_UNROLL == FULL)\r
+\r
+ switch(cx->rn)\r
+ {\r
+ case 14:\r
+ round(fwd_rnd, b1, b0, kp + 1 * N_COLS);\r
+ round(fwd_rnd, b0, b1, kp + 2 * N_COLS);\r
+ kp += 2 * N_COLS;\r
+ case 12:\r
+ round(fwd_rnd, b1, b0, kp + 1 * N_COLS);\r
+ round(fwd_rnd, b0, b1, kp + 2 * N_COLS);\r
+ kp += 2 * N_COLS;\r
+ case 10:\r
+ default:\r
+ round(fwd_rnd, b1, b0, kp + 1 * N_COLS);\r
+ round(fwd_rnd, b0, b1, kp + 2 * N_COLS);\r
+ round(fwd_rnd, b1, b0, kp + 3 * N_COLS);\r
+ round(fwd_rnd, b0, b1, kp + 4 * N_COLS);\r
+ round(fwd_rnd, b1, b0, kp + 5 * N_COLS);\r
+ round(fwd_rnd, b0, b1, kp + 6 * N_COLS);\r
+ round(fwd_rnd, b1, b0, kp + 7 * N_COLS);\r
+ round(fwd_rnd, b0, b1, kp + 8 * N_COLS);\r
+ round(fwd_rnd, b1, b0, kp + 9 * N_COLS);\r
+#if defined(LAST_ENC_ROUND_CACHE_TABLES)\r
+ itables(t_fl);\r
+#endif\r
+ round(fwd_lrnd, b0, b1, kp +10 * N_COLS);\r
+ }\r
+\r
+#else\r
+\r
+ { aes_32t rnd;\r
+#if (ENC_UNROLL == PARTIAL)\r
+ for(rnd = 0; rnd < (cx->rn >> 1) - 1; ++rnd)\r
+ {\r
+ kp += N_COLS;\r
+ round(fwd_rnd, b1, b0, kp);\r
+ kp += N_COLS;\r
+ round(fwd_rnd, b0, b1, kp);\r
+ }\r
+ kp += N_COLS;\r
+ round(fwd_rnd, b1, b0, kp);\r
+#else\r
+ for(rnd = 0; rnd < cx->rn - 1; ++rnd)\r
+ {\r
+ kp += N_COLS;\r
+ round(fwd_rnd, b1, b0, kp);\r
+ l_copy(b0, b1);\r
+ }\r
+#endif\r
+#if defined(LAST_ENC_ROUND_CACHE_TABLES)\r
+ itables(t_fl);\r
+#endif\r
+ kp += N_COLS;\r
+ round(fwd_lrnd, b0, b1, kp);\r
+ }\r
+#endif\r
+ \r
+ state_out(out, b0);\r
+ }\r
+\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(DECRYPTION) && !defined(AES_ASM)\r
+\r
+/* Visual C++ .Net v7.1 provides the fastest encryption code when using\r
+ Pentium optimiation with small code but this is poor for decryption\r
+ so we need to control this with the following VC++ pragmas\r
+*/\r
+\r
+#if defined(_MSC_VER)\r
+#pragma optimize( "t", on )\r
+#endif\r
+\r
+/* Given the column (c) of the output state variable, the following\r
+ macros give the input state variables which are needed in its\r
+ computation for each row (r) of the state. All the alternative\r
+ macros give the same end values but expand into different ways\r
+ of calculating these values. In particular the complex macro\r
+ used for dynamically variable block sizes is designed to expand\r
+ to a compile time constant whenever possible but will expand to\r
+ conditional clauses on some branches (I am grateful to Frank\r
+ Yellin for this construction)\r
+*/\r
+\r
+#define inv_var(x,r,c)\\r
+ ( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\\r
+ : r == 1 ? ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2))\\r
+ : r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\\r
+ : ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0)))\r
+\r
+#if defined(IT4_SET)\r
+#undef dec_imvars\r
+# if defined(DEC_ROUND_CACHE_TABLES)\r
+#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_in,inv_var,rf1,c))\r
+# else\r
+#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_in,inv_var,rf1,c))\r
+# endif\r
+#elif defined(IT1_SET)\r
+#undef dec_imvars\r
+#define inv_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,upr,t_in,inv_var,rf1,c))\r
+#else\r
+#define inv_rnd(y,x,k,c) (s(y,c) = inv_mcol((k)[c] ^ no_table(x,t_ibox,inv_var,rf1,c)))\r
+#endif\r
+\r
+#if defined(IL4_SET)\r
+# if defined(LAST_DEC_ROUND_CACHE_TABLES)\r
+#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_cached_tables(x,t_il,inv_var,rf1,c))\r
+# else\r
+#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_il,inv_var,rf1,c))\r
+# endif\r
+#elif defined(IL1_SET)\r
+#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ one_table(x,ups,t_il,inv_var,rf1,c))\r
+#else\r
+#define inv_lrnd(y,x,k,c) (s(y,c) = (k)[c] ^ no_table(x,t_ibox,inv_var,rf1,c))\r
+#endif\r
+\r
+aes_rval aes_decrypt_cbc(const unsigned char *in, const unsigned char *in_iv, unsigned int num_blk,\r
+ unsigned char *out, const aes_decrypt_ctx cx[1])\r
+{ aes_32t locals(b0, b1);\r
+ const aes_32t *kp = cx->ks + cx->rn * N_COLS;\r
+#if defined(DEC_ROUND_CACHE_TABLES)\r
+ dtables(t_in);\r
+#endif\r
+#if defined(LAST_DEC_ROUND_CACHE_TABLES)\r
+ dtables(t_il);\r
+#endif\r
+\r
+#if defined( dec_imvars )\r
+ dec_imvars; /* declare variables for inv_mcol() if needed */\r
+#endif\r
+ \r
+#if defined( AES_ERR_CHK )\r
+ if( cx->rn != 10 && cx->rn != 12 && cx->rn != 14 )\r
+ return aes_error;\r
+#endif\r
+\r
+#if defined(DEC_ROUND_CACHE_TABLES)\r
+ itables(t_in);\r
+#endif \r
+ \r
+ in += AES_BLOCK_SIZE * (num_blk - 1);\r
+ out += AES_BLOCK_SIZE * (num_blk - 1);\r
+ // Load the last block's ciphertext into b1\r
+ state_in(b1, in);\r
+\r
+ for (;num_blk; out -= AES_BLOCK_SIZE, --num_blk)\r
+ {\r
+ // Do the xor part of state_in, where b1 is the previous block's ciphertext.\r
+ key_in(b0, b1, kp);\r
+\r
+#if (DEC_UNROLL == FULL)\r
+ \r
+ switch(cx->rn)\r
+ {\r
+ case 14:\r
+ round(inv_rnd, b1, b0, kp - 1 * N_COLS);\r
+ round(inv_rnd, b0, b1, kp - 2 * N_COLS);\r
+ kp -= 2 * N_COLS;\r
+ case 12:\r
+ round(inv_rnd, b1, b0, kp - 1 * N_COLS);\r
+ round(inv_rnd, b0, b1, kp - 2 * N_COLS);\r
+ kp -= 2 * N_COLS;\r
+ case 10:\r
+ default:\r
+ round(inv_rnd, b1, b0, kp - 1 * N_COLS);\r
+ round(inv_rnd, b0, b1, kp - 2 * N_COLS);\r
+ round(inv_rnd, b1, b0, kp - 3 * N_COLS);\r
+ round(inv_rnd, b0, b1, kp - 4 * N_COLS);\r
+ round(inv_rnd, b1, b0, kp - 5 * N_COLS);\r
+ round(inv_rnd, b0, b1, kp - 6 * N_COLS);\r
+ round(inv_rnd, b1, b0, kp - 7 * N_COLS);\r
+ round(inv_rnd, b0, b1, kp - 8 * N_COLS);\r
+ round(inv_rnd, b1, b0, kp - 9 * N_COLS);\r
+#if defined(LAST_DEC_ROUND_CACHE_TABLES)\r
+ itables(t_il);\r
+#endif \r
+ round(inv_lrnd, b0, b1, kp - 10 * N_COLS);\r
+ }\r
+\r
+#else\r
+ \r
+ { aes_32t rnd;\r
+#if (DEC_UNROLL == PARTIAL)\r
+ for(rnd = 0; rnd < (cx->rn >> 1) - 1; ++rnd)\r
+ {\r
+ kp -= N_COLS;\r
+ round(inv_rnd, b1, b0, kp);\r
+ kp -= N_COLS;\r
+ round(inv_rnd, b0, b1, kp);\r
+ }\r
+ kp -= N_COLS;\r
+ round(inv_rnd, b1, b0, kp);\r
+#else\r
+ for(rnd = 0; rnd < cx->rn - 1; ++rnd)\r
+ {\r
+ kp -= N_COLS;\r
+ round(inv_rnd, b1, b0, kp);\r
+ l_copy(b0, b1);\r
+ }\r
+#endif\r
+#if defined(LAST_DEC_ROUND_CACHE_TABLES)\r
+ itables(t_il);\r
+#endif \r
+ kp -= N_COLS;\r
+ round(inv_lrnd, b0, b1, kp);\r
+ }\r
+#endif\r
+\r
+ if (num_blk == 1)\r
+ {\r
+ // We are doing the first block so we need the IV rather than the previous\r
+ // block for CBC (there is no previous block)\r
+ state_in(b1, in_iv);\r
+ }\r
+ else\r
+ {\r
+ in -= AES_BLOCK_SIZE;\r
+ state_in(b1, in);\r
+ }\r
+\r
+ // Do the CBC with b1 which is either the IV or the ciphertext of the previous block.\r
+ cbc(b0, b1);\r
+\r
+ state_out(out, b0);\r
+ }\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif\r
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue Date: 26/08/2003\r
+\r
+ This file contains the code for implementing the key schedule for AES\r
+ (Rijndael) for block and key sizes of 16, 24, and 32 bytes. See aesopt.h\r
+ for further details including optimisation.\r
+*/\r
+\r
+#include "aesopt.h"\r
+#include "aestab.h"\r
+\r
+#if defined(__cplusplus)\r
+extern "C"\r
+{\r
+#endif\r
+\r
+/* Initialise the key schedule from the user supplied key. The key\r
+ length can be specified in bytes, with legal values of 16, 24\r
+ and 32, or in bits, with legal values of 128, 192 and 256. These\r
+ values correspond with Nk values of 4, 6 and 8 respectively.\r
+\r
+ The following macros implement a single cycle in the key\r
+ schedule generation process. The number of cycles needed\r
+ for each cx->n_col and nk value is:\r
+\r
+ nk = 4 5 6 7 8\r
+ ------------------------------\r
+ cx->n_col = 4 10 9 8 7 7\r
+ cx->n_col = 5 14 11 10 9 9\r
+ cx->n_col = 6 19 15 12 11 11\r
+ cx->n_col = 7 21 19 16 13 14\r
+ cx->n_col = 8 29 23 19 17 14\r
+*/\r
+\r
+#define ke4(k,i) \\r
+{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \\r
+ k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \\r
+}\r
+#define kel4(k,i) \\r
+{ k[4*(i)+4] = ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+5] = ss[1] ^= ss[0]; \\r
+ k[4*(i)+6] = ss[2] ^= ss[1]; k[4*(i)+7] = ss[3] ^= ss[2]; \\r
+}\r
+\r
+#define ke6(k,i) \\r
+{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \\r
+ k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \\r
+ k[6*(i)+10] = ss[4] ^= ss[3]; k[6*(i)+11] = ss[5] ^= ss[4]; \\r
+}\r
+#define kel6(k,i) \\r
+{ k[6*(i)+ 6] = ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 7] = ss[1] ^= ss[0]; \\r
+ k[6*(i)+ 8] = ss[2] ^= ss[1]; k[6*(i)+ 9] = ss[3] ^= ss[2]; \\r
+}\r
+\r
+#define ke8(k,i) \\r
+{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \\r
+ k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \\r
+ k[8*(i)+12] = ss[4] ^= ls_box(ss[3],0); k[8*(i)+13] = ss[5] ^= ss[4]; \\r
+ k[8*(i)+14] = ss[6] ^= ss[5]; k[8*(i)+15] = ss[7] ^= ss[6]; \\r
+}\r
+#define kel8(k,i) \\r
+{ k[8*(i)+ 8] = ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 9] = ss[1] ^= ss[0]; \\r
+ k[8*(i)+10] = ss[2] ^= ss[1]; k[8*(i)+11] = ss[3] ^= ss[2]; \\r
+}\r
+\r
+#if defined(ENCRYPTION_KEY_SCHEDULE)\r
+\r
+#if defined(AES_128) || defined(AES_VAR)\r
+\r
+aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1])\r
+{ aes_32t ss[4];\r
+\r
+ cx->ks[0] = ss[0] = word_in(key, 0);\r
+ cx->ks[1] = ss[1] = word_in(key, 1);\r
+ cx->ks[2] = ss[2] = word_in(key, 2);\r
+ cx->ks[3] = ss[3] = word_in(key, 3);\r
+\r
+#if ENC_UNROLL == NONE\r
+ { aes_32t i;\r
+\r
+ for(i = 0; i < ((11 * N_COLS - 5) / 4); ++i)\r
+ ke4(cx->ks, i);\r
+ }\r
+#else\r
+ ke4(cx->ks, 0); ke4(cx->ks, 1);\r
+ ke4(cx->ks, 2); ke4(cx->ks, 3);\r
+ ke4(cx->ks, 4); ke4(cx->ks, 5);\r
+ ke4(cx->ks, 6); ke4(cx->ks, 7);\r
+ ke4(cx->ks, 8);\r
+#endif\r
+ kel4(cx->ks, 9);\r
+ cx->rn = 10;\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(AES_192) || defined(AES_VAR)\r
+\r
+aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1])\r
+{ aes_32t ss[6];\r
+\r
+ cx->ks[0] = ss[0] = word_in(key, 0);\r
+ cx->ks[1] = ss[1] = word_in(key, 1);\r
+ cx->ks[2] = ss[2] = word_in(key, 2);\r
+ cx->ks[3] = ss[3] = word_in(key, 3);\r
+ cx->ks[4] = ss[4] = word_in(key, 4);\r
+ cx->ks[5] = ss[5] = word_in(key, 5);\r
+\r
+#if ENC_UNROLL == NONE\r
+ { aes_32t i;\r
+\r
+ for(i = 0; i < (13 * N_COLS - 7) / 6; ++i)\r
+ ke6(cx->ks, i);\r
+ }\r
+#else\r
+ ke6(cx->ks, 0); ke6(cx->ks, 1);\r
+ ke6(cx->ks, 2); ke6(cx->ks, 3);\r
+ ke6(cx->ks, 4); ke6(cx->ks, 5);\r
+ ke6(cx->ks, 6);\r
+#endif\r
+ kel6(cx->ks, 7);\r
+ cx->rn = 12;\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(AES_256) || defined(AES_VAR)\r
+\r
+aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1])\r
+{ aes_32t ss[8];\r
+\r
+ cx->ks[0] = ss[0] = word_in(key, 0);\r
+ cx->ks[1] = ss[1] = word_in(key, 1);\r
+ cx->ks[2] = ss[2] = word_in(key, 2);\r
+ cx->ks[3] = ss[3] = word_in(key, 3);\r
+ cx->ks[4] = ss[4] = word_in(key, 4);\r
+ cx->ks[5] = ss[5] = word_in(key, 5);\r
+ cx->ks[6] = ss[6] = word_in(key, 6);\r
+ cx->ks[7] = ss[7] = word_in(key, 7);\r
+\r
+#if ENC_UNROLL == NONE\r
+ { aes_32t i;\r
+\r
+ for(i = 0; i < (15 * N_COLS - 9) / 8; ++i)\r
+ ke8(cx->ks, i);\r
+ }\r
+#else\r
+ ke8(cx->ks, 0); ke8(cx->ks, 1);\r
+ ke8(cx->ks, 2); ke8(cx->ks, 3);\r
+ ke8(cx->ks, 4); ke8(cx->ks, 5);\r
+#endif\r
+ kel8(cx->ks, 6);\r
+ cx->rn = 14;\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(AES_VAR)\r
+\r
+aes_rval aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1])\r
+{\r
+ switch(key_len)\r
+ {\r
+#if defined( AES_ERR_CHK )\r
+ case 16: case 128: return aes_encrypt_key128(key, cx);\r
+ case 24: case 192: return aes_encrypt_key192(key, cx);\r
+ case 32: case 256: return aes_encrypt_key256(key, cx);\r
+ default: return aes_error;\r
+#else\r
+ case 16: case 128: aes_encrypt_key128(key, cx); return;\r
+ case 24: case 192: aes_encrypt_key192(key, cx); return;\r
+ case 32: case 256: aes_encrypt_key256(key, cx); return;\r
+#endif\r
+ }\r
+}\r
+\r
+#endif\r
+\r
+#endif\r
+\r
+#if defined(DECRYPTION_KEY_SCHEDULE)\r
+\r
+#if DEC_ROUND == NO_TABLES\r
+#define ff(x) (x)\r
+#else\r
+#define ff(x) inv_mcol(x)\r
+#if defined( dec_imvars )\r
+#define d_vars dec_imvars\r
+#endif\r
+#endif\r
+\r
+#if 1\r
+#define kdf4(k,i) \\r
+{ ss[0] = ss[0] ^ ss[2] ^ ss[1] ^ ss[3]; ss[1] = ss[1] ^ ss[3]; ss[2] = ss[2] ^ ss[3]; ss[3] = ss[3]; \\r
+ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \\r
+ ss[4] ^= k[4*(i)]; k[4*(i)+4] = ff(ss[4]); ss[4] ^= k[4*(i)+1]; k[4*(i)+5] = ff(ss[4]); \\r
+ ss[4] ^= k[4*(i)+2]; k[4*(i)+6] = ff(ss[4]); ss[4] ^= k[4*(i)+3]; k[4*(i)+7] = ff(ss[4]); \\r
+}\r
+#define kd4(k,i) \\r
+{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; ss[4] = ff(ss[4]); \\r
+ k[4*(i)+4] = ss[4] ^= k[4*(i)]; k[4*(i)+5] = ss[4] ^= k[4*(i)+1]; \\r
+ k[4*(i)+6] = ss[4] ^= k[4*(i)+2]; k[4*(i)+7] = ss[4] ^= k[4*(i)+3]; \\r
+}\r
+#define kdl4(k,i) \\r
+{ ss[4] = ls_box(ss[(i+3) % 4], 3) ^ t_use(r,c)[i]; ss[i % 4] ^= ss[4]; \\r
+ k[4*(i)+4] = (ss[0] ^= ss[1]) ^ ss[2] ^ ss[3]; k[4*(i)+5] = ss[1] ^ ss[3]; \\r
+ k[4*(i)+6] = ss[0]; k[4*(i)+7] = ss[1]; \\r
+}\r
+#else\r
+#define kdf4(k,i) \\r
+{ ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ff(ss[0]); ss[1] ^= ss[0]; k[4*(i)+ 5] = ff(ss[1]); \\r
+ ss[2] ^= ss[1]; k[4*(i)+ 6] = ff(ss[2]); ss[3] ^= ss[2]; k[4*(i)+ 7] = ff(ss[3]); \\r
+}\r
+#define kd4(k,i) \\r
+{ ss[4] = ls_box(ss[3],3) ^ t_use(r,c)[i]; \\r
+ ss[0] ^= ss[4]; ss[4] = ff(ss[4]); k[4*(i)+ 4] = ss[4] ^= k[4*(i)]; \\r
+ ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[4] ^= k[4*(i)+ 1]; \\r
+ ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[4] ^= k[4*(i)+ 2]; \\r
+ ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[4] ^= k[4*(i)+ 3]; \\r
+}\r
+#define kdl4(k,i) \\r
+{ ss[0] ^= ls_box(ss[3],3) ^ t_use(r,c)[i]; k[4*(i)+ 4] = ss[0]; ss[1] ^= ss[0]; k[4*(i)+ 5] = ss[1]; \\r
+ ss[2] ^= ss[1]; k[4*(i)+ 6] = ss[2]; ss[3] ^= ss[2]; k[4*(i)+ 7] = ss[3]; \\r
+}\r
+#endif\r
+\r
+#define kdf6(k,i) \\r
+{ ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ff(ss[0]); ss[1] ^= ss[0]; k[6*(i)+ 7] = ff(ss[1]); \\r
+ ss[2] ^= ss[1]; k[6*(i)+ 8] = ff(ss[2]); ss[3] ^= ss[2]; k[6*(i)+ 9] = ff(ss[3]); \\r
+ ss[4] ^= ss[3]; k[6*(i)+10] = ff(ss[4]); ss[5] ^= ss[4]; k[6*(i)+11] = ff(ss[5]); \\r
+}\r
+#define kd6(k,i) \\r
+{ ss[6] = ls_box(ss[5],3) ^ t_use(r,c)[i]; \\r
+ ss[0] ^= ss[6]; ss[6] = ff(ss[6]); k[6*(i)+ 6] = ss[6] ^= k[6*(i)]; \\r
+ ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[6] ^= k[6*(i)+ 1]; \\r
+ ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[6] ^= k[6*(i)+ 2]; \\r
+ ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[6] ^= k[6*(i)+ 3]; \\r
+ ss[4] ^= ss[3]; k[6*(i)+10] = ss[6] ^= k[6*(i)+ 4]; \\r
+ ss[5] ^= ss[4]; k[6*(i)+11] = ss[6] ^= k[6*(i)+ 5]; \\r
+}\r
+#define kdl6(k,i) \\r
+{ ss[0] ^= ls_box(ss[5],3) ^ t_use(r,c)[i]; k[6*(i)+ 6] = ss[0]; ss[1] ^= ss[0]; k[6*(i)+ 7] = ss[1]; \\r
+ ss[2] ^= ss[1]; k[6*(i)+ 8] = ss[2]; ss[3] ^= ss[2]; k[6*(i)+ 9] = ss[3]; \\r
+}\r
+\r
+#define kdf8(k,i) \\r
+{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ff(ss[0]); ss[1] ^= ss[0]; k[8*(i)+ 9] = ff(ss[1]); \\r
+ ss[2] ^= ss[1]; k[8*(i)+10] = ff(ss[2]); ss[3] ^= ss[2]; k[8*(i)+11] = ff(ss[3]); \\r
+ ss[4] ^= ls_box(ss[3],0); k[8*(i)+12] = ff(ss[4]); ss[5] ^= ss[4]; k[8*(i)+13] = ff(ss[5]); \\r
+ ss[6] ^= ss[5]; k[8*(i)+14] = ff(ss[6]); ss[7] ^= ss[6]; k[8*(i)+15] = ff(ss[7]); \\r
+}\r
+#define kd8(k,i) \\r
+{ aes_32t g = ls_box(ss[7],3) ^ t_use(r,c)[i]; \\r
+ ss[0] ^= g; g = ff(g); k[8*(i)+ 8] = g ^= k[8*(i)]; \\r
+ ss[1] ^= ss[0]; k[8*(i)+ 9] = g ^= k[8*(i)+ 1]; \\r
+ ss[2] ^= ss[1]; k[8*(i)+10] = g ^= k[8*(i)+ 2]; \\r
+ ss[3] ^= ss[2]; k[8*(i)+11] = g ^= k[8*(i)+ 3]; \\r
+ g = ls_box(ss[3],0); \\r
+ ss[4] ^= g; g = ff(g); k[8*(i)+12] = g ^= k[8*(i)+ 4]; \\r
+ ss[5] ^= ss[4]; k[8*(i)+13] = g ^= k[8*(i)+ 5]; \\r
+ ss[6] ^= ss[5]; k[8*(i)+14] = g ^= k[8*(i)+ 6]; \\r
+ ss[7] ^= ss[6]; k[8*(i)+15] = g ^= k[8*(i)+ 7]; \\r
+}\r
+#define kdl8(k,i) \\r
+{ ss[0] ^= ls_box(ss[7],3) ^ t_use(r,c)[i]; k[8*(i)+ 8] = ss[0]; ss[1] ^= ss[0]; k[8*(i)+ 9] = ss[1]; \\r
+ ss[2] ^= ss[1]; k[8*(i)+10] = ss[2]; ss[3] ^= ss[2]; k[8*(i)+11] = ss[3]; \\r
+}\r
+\r
+#if defined(AES_128) || defined(AES_VAR)\r
+\r
+aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1])\r
+{ aes_32t ss[5];\r
+#if defined( d_vars )\r
+ d_vars;\r
+#endif\r
+ cx->ks[0] = ss[0] = word_in(key, 0);\r
+ cx->ks[1] = ss[1] = word_in(key, 1);\r
+ cx->ks[2] = ss[2] = word_in(key, 2);\r
+ cx->ks[3] = ss[3] = word_in(key, 3);\r
+\r
+#if DEC_UNROLL == NONE\r
+ { aes_32t i;\r
+\r
+ for(i = 0; i < (11 * N_COLS - 5) / 4; ++i)\r
+ ke4(cx->ks, i);\r
+ kel4(cx->ks, 9);\r
+#if !(DEC_ROUND == NO_TABLES)\r
+ for(i = N_COLS; i < 10 * N_COLS; ++i)\r
+ cx->ks[i] = inv_mcol(cx->ks[i]);\r
+#endif\r
+ }\r
+#else\r
+ kdf4(cx->ks, 0); kd4(cx->ks, 1);\r
+ kd4(cx->ks, 2); kd4(cx->ks, 3);\r
+ kd4(cx->ks, 4); kd4(cx->ks, 5);\r
+ kd4(cx->ks, 6); kd4(cx->ks, 7);\r
+ kd4(cx->ks, 8); kdl4(cx->ks, 9);\r
+#endif\r
+ cx->rn = 10;\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(AES_192) || defined(AES_VAR)\r
+\r
+aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1])\r
+{ aes_32t ss[7];\r
+#if defined( d_vars )\r
+ d_vars;\r
+#endif\r
+ cx->ks[0] = ss[0] = word_in(key, 0);\r
+ cx->ks[1] = ss[1] = word_in(key, 1);\r
+ cx->ks[2] = ss[2] = word_in(key, 2);\r
+ cx->ks[3] = ss[3] = word_in(key, 3);\r
+\r
+#if DEC_UNROLL == NONE\r
+ cx->ks[4] = ss[4] = word_in(key, 4);\r
+ cx->ks[5] = ss[5] = word_in(key, 5);\r
+ { aes_32t i;\r
+\r
+ for(i = 0; i < (13 * N_COLS - 7) / 6; ++i)\r
+ ke6(cx->ks, i);\r
+ kel6(cx->ks, 7);\r
+#if !(DEC_ROUND == NO_TABLES)\r
+ for(i = N_COLS; i < 12 * N_COLS; ++i)\r
+ cx->ks[i] = inv_mcol(cx->ks[i]);\r
+#endif\r
+ }\r
+#else\r
+ cx->ks[4] = ff(ss[4] = word_in(key, 4));\r
+ cx->ks[5] = ff(ss[5] = word_in(key, 5));\r
+ kdf6(cx->ks, 0); kd6(cx->ks, 1);\r
+ kd6(cx->ks, 2); kd6(cx->ks, 3);\r
+ kd6(cx->ks, 4); kd6(cx->ks, 5);\r
+ kd6(cx->ks, 6); kdl6(cx->ks, 7);\r
+#endif\r
+ cx->rn = 12;\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(AES_256) || defined(AES_VAR)\r
+\r
+aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1])\r
+{ aes_32t ss[8];\r
+#if defined( d_vars )\r
+ d_vars;\r
+#endif\r
+ cx->ks[0] = ss[0] = word_in(key, 0);\r
+ cx->ks[1] = ss[1] = word_in(key, 1);\r
+ cx->ks[2] = ss[2] = word_in(key, 2);\r
+ cx->ks[3] = ss[3] = word_in(key, 3);\r
+\r
+#if DEC_UNROLL == NONE\r
+ cx->ks[4] = ss[4] = word_in(key, 4);\r
+ cx->ks[5] = ss[5] = word_in(key, 5);\r
+ cx->ks[6] = ss[6] = word_in(key, 6);\r
+ cx->ks[7] = ss[7] = word_in(key, 7);\r
+ { aes_32t i;\r
+\r
+ for(i = 0; i < (15 * N_COLS - 9) / 8; ++i)\r
+ ke8(cx->ks, i);\r
+ kel8(cx->ks, i);\r
+#if !(DEC_ROUND == NO_TABLES)\r
+ for(i = N_COLS; i < 14 * N_COLS; ++i)\r
+ cx->ks[i] = inv_mcol(cx->ks[i]);\r
+\r
+#endif\r
+ }\r
+#else\r
+ cx->ks[4] = ff(ss[4] = word_in(key, 4));\r
+ cx->ks[5] = ff(ss[5] = word_in(key, 5));\r
+ cx->ks[6] = ff(ss[6] = word_in(key, 6));\r
+ cx->ks[7] = ff(ss[7] = word_in(key, 7));\r
+ kdf8(cx->ks, 0); kd8(cx->ks, 1);\r
+ kd8(cx->ks, 2); kd8(cx->ks, 3);\r
+ kd8(cx->ks, 4); kd8(cx->ks, 5);\r
+ kdl8(cx->ks, 6);\r
+#endif\r
+ cx->rn = 14;\r
+#if defined( AES_ERR_CHK )\r
+ return aes_good;\r
+#endif\r
+}\r
+\r
+#endif\r
+\r
+#if defined(AES_VAR)\r
+\r
+aes_rval aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1])\r
+{\r
+ switch(key_len)\r
+ {\r
+#if defined( AES_ERR_CHK )\r
+ case 16: case 128: return aes_decrypt_key128(key, cx);\r
+ case 24: case 192: return aes_decrypt_key192(key, cx);\r
+ case 32: case 256: return aes_decrypt_key256(key, cx);\r
+ default: return aes_error;\r
+#else\r
+ case 16: case 128: aes_decrypt_key128(key, cx); return;\r
+ case 24: case 192: aes_decrypt_key192(key, cx); return;\r
+ case 32: case 256: aes_decrypt_key256(key, cx); return;\r
+#endif\r
+ }\r
+}\r
+\r
+#endif\r
+\r
+#endif\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif\r
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue 28/01/2004\r
+\r
+ My thanks go to Dag Arne Osvik for devising the schemes used here for key\r
+ length derivation from the form of the key schedule\r
+\r
+ This file contains the compilation options for AES (Rijndael) and code\r
+ that is common across encryption, key scheduling and table generation.\r
+\r
+ OPERATION\r
+\r
+ These source code files implement the AES algorithm Rijndael designed by\r
+ Joan Daemen and Vincent Rijmen. This version is designed for the standard\r
+ block size of 16 bytes and for key sizes of 128, 192 and 256 bits (16, 24\r
+ and 32 bytes).\r
+\r
+ This version is designed for flexibility and speed using operations on\r
+ 32-bit words rather than operations on bytes. It can be compiled with\r
+ either big or little endian internal byte order but is faster when the\r
+ native byte order for the processor is used.\r
+\r
+ THE CIPHER INTERFACE\r
+\r
+ The cipher interface is implemented as an array of bytes in which lower\r
+ AES bit sequence indexes map to higher numeric significance within bytes.\r
+\r
+ aes_08t (an unsigned 8-bit type)\r
+ aes_32t (an unsigned 32-bit type)\r
+ struct aes_encrypt_ctx (structure for the cipher encryption context)\r
+ struct aes_decrypt_ctx (structure for the cipher decryption context)\r
+ aes_rval the function return type\r
+\r
+ C subroutine calls:\r
+\r
+ aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);\r
+ aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);\r
+ aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);\r
+ aes_rval aes_encrypt(const unsigned char *in, unsigned char *out,\r
+ const aes_encrypt_ctx cx[1]);\r
+\r
+ aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);\r
+ aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);\r
+ aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);\r
+ aes_rval aes_decrypt(const unsigned char *in, unsigned char *out,\r
+ const aes_decrypt_ctx cx[1]);\r
+\r
+ IMPORTANT NOTE: If you are using this C interface with dynamic tables make sure that\r
+ you call genTabs() before AES is used so that the tables are initialised.\r
+\r
+ C++ aes class subroutines:\r
+\r
+ Class AESencrypt for encryption\r
+\r
+ Construtors:\r
+ AESencrypt(void)\r
+ AESencrypt(const unsigned char *key) - 128 bit key\r
+ Members:\r
+ aes_rval key128(const unsigned char *key)\r
+ aes_rval key192(const unsigned char *key)\r
+ aes_rval key256(const unsigned char *key)\r
+ aes_rval encrypt(const unsigned char *in, unsigned char *out) const\r
+\r
+ Class AESdecrypt for encryption\r
+ Construtors:\r
+ AESdecrypt(void)\r
+ AESdecrypt(const unsigned char *key) - 128 bit key\r
+ Members:\r
+ aes_rval key128(const unsigned char *key)\r
+ aes_rval key192(const unsigned char *key)\r
+ aes_rval key256(const unsigned char *key)\r
+ aes_rval decrypt(const unsigned char *in, unsigned char *out) const\r
+\r
+ COMPILATION\r
+\r
+ The files used to provide AES (Rijndael) are\r
+\r
+ a. aes.h for the definitions needed for use in C.\r
+ b. aescpp.h for the definitions needed for use in C++.\r
+ c. aesopt.h for setting compilation options (also includes common code).\r
+ d. aescrypt.c for encryption and decrytpion, or\r
+ e. aeskey.c for key scheduling.\r
+ f. aestab.c for table loading or generation.\r
+ g. aescrypt.asm for encryption and decryption using assembler code.\r
+ h. aescrypt.mmx.asm for encryption and decryption using MMX assembler.\r
+\r
+ To compile AES (Rijndael) for use in C code use aes.h and set the\r
+ defines here for the facilities you need (key lengths, encryption\r
+ and/or decryption). Do not define AES_DLL or AES_CPP. Set the options\r
+ for optimisations and table sizes here.\r
+\r
+ To compile AES (Rijndael) for use in in C++ code use aescpp.h but do\r
+ not define AES_DLL\r
+\r
+ To compile AES (Rijndael) in C as a Dynamic Link Library DLL) use\r
+ aes.h and include the AES_DLL define.\r
+\r
+ CONFIGURATION OPTIONS (here and in aes.h)\r
+\r
+ a. set AES_DLL in aes.h if AES (Rijndael) is to be compiled as a DLL\r
+ b. You may need to set PLATFORM_BYTE_ORDER to define the byte order.\r
+ c. If you want the code to run in a specific internal byte order, then\r
+ ALGORITHM_BYTE_ORDER must be set accordingly.\r
+ d. set other configuration options decribed below.\r
+*/\r
+\r
+#if !defined( _AESOPT_H )\r
+#define _AESOPT_H\r
+\r
+#include "aes.h"\r
+\r
+/* CONFIGURATION - USE OF DEFINES\r
+\r
+ Later in this section there are a number of defines that control the\r
+ operation of the code. In each section, the purpose of each define is\r
+ explained so that the relevant form can be included or excluded by\r
+ setting either 1's or 0's respectively on the branches of the related\r
+ #if clauses.\r
+\r
+ PLATFORM SPECIFIC INCLUDES AND BYTE ORDER IN 32-BIT WORDS\r
+\r
+ To obtain the highest speed on processors with 32-bit words, this code\r
+ needs to determine the byte order of the target machine. The following\r
+ block of code is an attempt to capture the most obvious ways in which\r
+ various environemnts define byte order. It may well fail, in which case\r
+ the definitions will need to be set by editing at the points marked\r
+ **** EDIT HERE IF NECESSARY **** below. My thanks go to Peter Gutmann\r
+ for his assistance with this endian detection nightmare.\r
+*/\r
+\r
+#define BRG_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */\r
+#define BRG_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */\r
+\r
+#if defined(__GNUC__) || defined(__GNU_LIBRARY__)\r
+# if defined(__FreeBSD__) || defined(__OpenBSD__)\r
+# include <sys/endian.h>\r
+# elif defined( BSD ) && BSD >= 199103\r
+# include <machine/endian.h>\r
+# elif defined(__APPLE__)\r
+# if defined(__BIG_ENDIAN__) && !defined( BIG_ENDIAN )\r
+# define BIG_ENDIAN\r
+# elif defined(__LITTLE_ENDIAN__) && !defined( LITTLE_ENDIAN )\r
+# define LITTLE_ENDIAN\r
+# endif\r
+# else\r
+# include <endian.h>\r
+# if defined(__BEOS__)\r
+# include <byteswap.h>\r
+# endif\r
+# endif\r
+#endif\r
+\r
+#if !defined(PLATFORM_BYTE_ORDER)\r
+# if defined(LITTLE_ENDIAN) || defined(BIG_ENDIAN)\r
+# if defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+# elif !defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+# elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+# elif defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+# endif\r
+# elif defined(_LITTLE_ENDIAN) || defined(_BIG_ENDIAN)\r
+# if defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+# elif !defined(_LITTLE_ENDIAN) && defined(_BIG_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _LITTLE_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+# elif defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN)\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+# endif\r
+# elif defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__)\r
+# if defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+# elif !defined(__LITTLE_ENDIAN__) && defined(__BIG_ENDIAN__)\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __LITTLE_ENDIAN__)\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+# elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__)\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+# endif\r
+# endif\r
+#endif\r
+\r
+/* if the platform is still unknown, try to find its byte order */\r
+/* from commonly used machine defines */\r
+\r
+#if !defined(PLATFORM_BYTE_ORDER)\r
+\r
+#if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \\r
+ defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \\r
+ defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \\r
+ defined( vax ) || defined( vms ) || defined( VMS ) || \\r
+ defined( __VMS )\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+\r
+#elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \\r
+ defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \\r
+ defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \\r
+ defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \\r
+ defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \\r
+ defined( __TANDEM ) || defined( THINK_C ) || defined( __VMCMS__ )\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+\r
+#elif 0 /* **** EDIT HERE IF NECESSARY **** */\r
+# define PLATFORM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+#elif 0 /* **** EDIT HERE IF NECESSARY **** */\r
+# define PLATFORM_BYTE_ORDER BRG_BIG_ENDIAN\r
+#else\r
+# error Please edit aesopt.h (line 234 or 236) to set the platform byte order\r
+#endif\r
+\r
+#endif\r
+\r
+/* SOME LOCAL DEFINITIONS */\r
+\r
+#define NO_TABLES 0\r
+#define ONE_TABLE 1\r
+#define FOUR_TABLES 4\r
+#define NONE 0\r
+#define PARTIAL 1\r
+#define FULL 2\r
+\r
+#if defined(bswap32)\r
+#define aes_sw32 bswap32\r
+#elif defined(bswap_32)\r
+#define aes_sw32 bswap_32\r
+#else\r
+#define brot(x,n) (((aes_32t)(x) << n) | ((aes_32t)(x) >> (32 - n)))\r
+#define aes_sw32(x) ((brot((x),8) & 0x00ff00ff) | (brot((x),24) & 0xff00ff00))\r
+#endif\r
+\r
+/* 1. FUNCTIONS REQUIRED\r
+\r
+ This implementation provides subroutines for encryption, decryption\r
+ and for setting the three key lengths (separately) for encryption\r
+ and decryption. When the assembler code is not being used the following\r
+ definition blocks allow the selection of the routines that are to be\r
+ included in the compilation.\r
+*/\r
+#if defined( AES_ENCRYPT )\r
+#define ENCRYPTION\r
+#define ENCRYPTION_KEY_SCHEDULE\r
+#endif\r
+\r
+#if defined( AES_DECRYPT )\r
+#define DECRYPTION\r
+#define DECRYPTION_KEY_SCHEDULE\r
+#endif\r
+\r
+/* 2. ASSEMBLER SUPPORT\r
+\r
+ This define (which can be on the command line) enables the use of the\r
+ assembler code routines for encryption and decryption with the C code\r
+ only providing key scheduling\r
+*/\r
+#if 0 && !defined(AES_ASM)\r
+#define AES_ASM\r
+#endif\r
+\r
+/* 3. BYTE ORDER WITHIN 32 BIT WORDS\r
+\r
+ The fundamental data processing units in Rijndael are 8-bit bytes. The\r
+ input, output and key input are all enumerated arrays of bytes in which\r
+ bytes are numbered starting at zero and increasing to one less than the\r
+ number of bytes in the array in question. This enumeration is only used\r
+ for naming bytes and does not imply any adjacency or order relationship\r
+ from one byte to another. When these inputs and outputs are considered\r
+ as bit sequences, bits 8*n to 8*n+7 of the bit sequence are mapped to\r
+ byte[n] with bit 8n+i in the sequence mapped to bit 7-i within the byte.\r
+ In this implementation bits are numbered from 0 to 7 starting at the\r
+ numerically least significant end of each byte (bit n represents 2^n).\r
+\r
+ However, Rijndael can be implemented more efficiently using 32-bit\r
+ words by packing bytes into words so that bytes 4*n to 4*n+3 are placed\r
+ into word[n]. While in principle these bytes can be assembled into words\r
+ in any positions, this implementation only supports the two formats in\r
+ which bytes in adjacent positions within words also have adjacent byte\r
+ numbers. This order is called big-endian if the lowest numbered bytes\r
+ in words have the highest numeric significance and little-endian if the\r
+ opposite applies.\r
+\r
+ This code can work in either order irrespective of the order used by the\r
+ machine on which it runs. Normally the internal byte order will be set\r
+ to the order of the processor on which the code is to be run but this\r
+ define can be used to reverse this in special situations\r
+\r
+ NOTE: Assembler code versions rely on PLATFORM_BYTE_ORDER being set\r
+*/\r
+#if 1 || defined(AES_ASM)\r
+#define ALGORITHM_BYTE_ORDER PLATFORM_BYTE_ORDER\r
+#elif 0\r
+#define ALGORITHM_BYTE_ORDER BRG_LITTLE_ENDIAN\r
+#elif 0\r
+#define ALGORITHM_BYTE_ORDER BRG_BIG_ENDIAN\r
+#else\r
+#error The algorithm byte order is not defined\r
+#endif\r
+\r
+/* 4. FAST INPUT/OUTPUT OPERATIONS.\r
+\r
+ On some machines it is possible to improve speed by transferring the\r
+ bytes in the input and output arrays to and from the internal 32-bit\r
+ variables by addressing these arrays as if they are arrays of 32-bit\r
+ words. On some machines this will always be possible but there may\r
+ be a large performance penalty if the byte arrays are not aligned on\r
+ the normal word boundaries. On other machines this technique will\r
+ lead to memory access errors when such 32-bit word accesses are not\r
+ properly aligned. The option SAFE_IO avoids such problems but will\r
+ often be slower on those machines that support misaligned access\r
+ (especially so if care is taken to align the input and output byte\r
+ arrays on 32-bit word boundaries). If SAFE_IO is not defined it is\r
+ assumed that access to byte arrays as if they are arrays of 32-bit\r
+ words will not cause problems when such accesses are misaligned.\r
+*/\r
+#if 0 && !defined(_MSC_VER)\r
+#define SAFE_IO\r
+#endif\r
+\r
+/* 5. LOOP UNROLLING\r
+\r
+ The code for encryption and decrytpion cycles through a number of rounds\r
+ that can be implemented either in a loop or by expanding the code into a\r
+ long sequence of instructions, the latter producing a larger program but\r
+ one that will often be much faster. The latter is called loop unrolling.\r
+ There are also potential speed advantages in expanding two iterations in\r
+ a loop with half the number of iterations, which is called partial loop\r
+ unrolling. The following options allow partial or full loop unrolling\r
+ to be set independently for encryption and decryption\r
+*/\r
+#if 1\r
+#define ENC_UNROLL FULL\r
+#elif 0\r
+#define ENC_UNROLL PARTIAL\r
+#else\r
+#define ENC_UNROLL NONE\r
+#endif\r
+\r
+#if 1\r
+#define DEC_UNROLL FULL\r
+#elif 0\r
+#define DEC_UNROLL PARTIAL\r
+#else\r
+#define DEC_UNROLL NONE\r
+#endif\r
+\r
+/* 6. FAST FINITE FIELD OPERATIONS\r
+\r
+ If this section is included, tables are used to provide faster finite\r
+ field arithmetic (this has no effect if FIXED_TABLES is defined).\r
+*/\r
+#if 1\r
+#define FF_TABLES\r
+#endif\r
+\r
+/* 7. INTERNAL STATE VARIABLE FORMAT\r
+\r
+ The internal state of Rijndael is stored in a number of local 32-bit\r
+ word varaibles which can be defined either as an array or as individual\r
+ names variables. Include this section if you want to store these local\r
+ varaibles in arrays. Otherwise individual local variables will be used.\r
+*/\r
+#if 0\r
+#define ARRAYS\r
+#endif\r
+\r
+/* In this implementation the columns of the state array are each held in\r
+ 32-bit words. The state array can be held in various ways: in an array\r
+ of words, in a number of individual word variables or in a number of\r
+ processor registers. The following define maps a variable name x and\r
+ a column number c to the way the state array variable is to be held.\r
+ The first define below maps the state into an array x[c] whereas the\r
+ second form maps the state into a number of individual variables x0,\r
+ x1, etc. Another form could map individual state colums to machine\r
+ register names.\r
+*/\r
+\r
+#if defined(ARRAYS)\r
+#define s(x,c) x[c]\r
+#else\r
+#define s(x,c) x##c\r
+#endif\r
+\r
+/* 8. FIXED OR DYNAMIC TABLES\r
+\r
+ When this section is included the tables used by the code are compiled\r
+ statically into the binary file. Otherwise the subroutine gen_tabs()\r
+ must be called to compute them before the code is first used.\r
+*/\r
+#if 1\r
+#define FIXED_TABLES\r
+#endif\r
+\r
+/* 9. TABLE ALIGNMENT\r
+\r
+ On some sytsems speed will be improved by aligning the AES large lookup\r
+ tables on particular boundaries. This define should be set to a power of\r
+ two giving the desired alignment. It can be left undefined if alignment\r
+ is not needed. This option is specific to the Microsft VC++ compiler -\r
+ it seems to sometimes cause trouble for the VC++ version 6 compiler.\r
+*/\r
+\r
+#if 0 && defined(_MSC_VER) && (_MSC_VER >= 1300)\r
+#define TABLE_ALIGN 64\r
+#endif\r
+\r
+/* 10. INTERNAL TABLE CONFIGURATION\r
+\r
+ This cipher proceeds by repeating in a number of cycles known as 'rounds'\r
+ which are implemented by a round function which can optionally be speeded\r
+ up using tables. The basic tables are each 256 32-bit words, with either\r
+ one or four tables being required for each round function depending on\r
+ how much speed is required. The encryption and decryption round functions\r
+ are different and the last encryption and decrytpion round functions are\r
+ different again making four different round functions in all.\r
+\r
+ This means that:\r
+ 1. Normal encryption and decryption rounds can each use either 0, 1\r
+ or 4 tables and table spaces of 0, 1024 or 4096 bytes each.\r
+ 2. The last encryption and decryption rounds can also use either 0, 1\r
+ or 4 tables and table spaces of 0, 1024 or 4096 bytes each.\r
+\r
+ Include or exclude the appropriate definitions below to set the number\r
+ of tables used by this implementation.\r
+*/\r
+\r
+#if 1 /* set tables for the normal encryption round */\r
+#define ENC_ROUND FOUR_TABLES\r
+#elif 0\r
+#define ENC_ROUND ONE_TABLE\r
+#else\r
+#define ENC_ROUND NO_TABLES\r
+#endif\r
+\r
+#if 1 /* set tables for the last encryption round */\r
+#define LAST_ENC_ROUND FOUR_TABLES\r
+#elif 0\r
+#define LAST_ENC_ROUND ONE_TABLE\r
+#else\r
+#define LAST_ENC_ROUND NO_TABLES\r
+#endif\r
+\r
+#if 1 /* set tables for the normal decryption round */\r
+#define DEC_ROUND FOUR_TABLES\r
+#elif 0\r
+#define DEC_ROUND ONE_TABLE\r
+#else\r
+#define DEC_ROUND NO_TABLES\r
+#endif\r
+\r
+#if 1 /* set tables for the last decryption round */\r
+#define LAST_DEC_ROUND FOUR_TABLES\r
+#elif 0\r
+#define LAST_DEC_ROUND ONE_TABLE\r
+#else\r
+#define LAST_DEC_ROUND NO_TABLES\r
+#endif\r
+\r
+/* The decryption key schedule can be speeded up with tables in the same\r
+ way that the round functions can. Include or exclude the following\r
+ defines to set this requirement.\r
+*/\r
+#if 1\r
+#define KEY_SCHED FOUR_TABLES\r
+#elif 0\r
+#define KEY_SCHED ONE_TABLE\r
+#else\r
+#define KEY_SCHED NO_TABLES\r
+#endif\r
+\r
+/* 11. TABLE POINTER CACHING\r
+\r
+ Normally tables are referenced directly, Enable this option if you wish to\r
+ cache pointers to the tables in the encrypt/decrypt code. Note that this\r
+ only works if you are using FOUR_TABLES for the ROUND you enable this for.\r
+*/\r
+#if 1\r
+#define ENC_ROUND_CACHE_TABLES\r
+#endif\r
+#if 1\r
+#define LAST_ENC_ROUND_CACHE_TABLES\r
+#endif\r
+#if 1\r
+#define DEC_ROUND_CACHE_TABLES\r
+#endif\r
+#if 1\r
+#define LAST_DEC_ROUND_CACHE_TABLES\r
+#endif\r
+\r
+\r
+/* END OF CONFIGURATION OPTIONS */\r
+\r
+#define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2))\r
+\r
+/* Disable or report errors on some combinations of options */\r
+\r
+#if ENC_ROUND == NO_TABLES && LAST_ENC_ROUND != NO_TABLES\r
+#undef LAST_ENC_ROUND\r
+#define LAST_ENC_ROUND NO_TABLES\r
+#elif ENC_ROUND == ONE_TABLE && LAST_ENC_ROUND == FOUR_TABLES\r
+#undef LAST_ENC_ROUND\r
+#define LAST_ENC_ROUND ONE_TABLE\r
+#endif\r
+\r
+#if ENC_ROUND == NO_TABLES && ENC_UNROLL != NONE\r
+#undef ENC_UNROLL\r
+#define ENC_UNROLL NONE\r
+#endif\r
+\r
+#if DEC_ROUND == NO_TABLES && LAST_DEC_ROUND != NO_TABLES\r
+#undef LAST_DEC_ROUND\r
+#define LAST_DEC_ROUND NO_TABLES\r
+#elif DEC_ROUND == ONE_TABLE && LAST_DEC_ROUND == FOUR_TABLES\r
+#undef LAST_DEC_ROUND\r
+#define LAST_DEC_ROUND ONE_TABLE\r
+#endif\r
+\r
+#if DEC_ROUND == NO_TABLES && DEC_UNROLL != NONE\r
+#undef DEC_UNROLL\r
+#define DEC_UNROLL NONE\r
+#endif\r
+\r
+/* upr(x,n): rotates bytes within words by n positions, moving bytes to\r
+ higher index positions with wrap around into low positions\r
+ ups(x,n): moves bytes by n positions to higher index positions in\r
+ words but without wrap around\r
+ bval(x,n): extracts a byte from a word\r
+\r
+ NOTE: The definitions given here are intended only for use with\r
+ unsigned variables and with shift counts that are compile\r
+ time constants\r
+*/\r
+\r
+#if (ALGORITHM_BYTE_ORDER == BRG_LITTLE_ENDIAN)\r
+#define upr(x,n) (((aes_32t)(x) << (8 * (n))) | ((aes_32t)(x) >> (32 - 8 * (n))))\r
+#define ups(x,n) ((aes_32t) (x) << (8 * (n)))\r
+#define bval(x,n) ((aes_08t)((x) >> (8 * (n))))\r
+#define bytes2word(b0, b1, b2, b3) \\r
+ (((aes_32t)(b3) << 24) | ((aes_32t)(b2) << 16) | ((aes_32t)(b1) << 8) | (b0))\r
+#endif\r
+\r
+#if (ALGORITHM_BYTE_ORDER == BRG_BIG_ENDIAN)\r
+#define upr(x,n) (((aes_32t)(x) >> (8 * (n))) | ((aes_32t)(x) << (32 - 8 * (n))))\r
+#define ups(x,n) ((aes_32t) (x) >> (8 * (n))))\r
+#define bval(x,n) ((aes_08t)((x) >> (24 - 8 * (n))))\r
+#define bytes2word(b0, b1, b2, b3) \\r
+ (((aes_32t)(b0) << 24) | ((aes_32t)(b1) << 16) | ((aes_32t)(b2) << 8) | (b3))\r
+#endif\r
+\r
+#if defined(SAFE_IO)\r
+\r
+#define word_in(x,c) bytes2word(((aes_08t*)(x)+4*c)[0], ((aes_08t*)(x)+4*c)[1], \\r
+ ((aes_08t*)(x)+4*c)[2], ((aes_08t*)(x)+4*c)[3])\r
+#define word_out(x,c,v) { ((aes_08t*)(x)+4*c)[0] = bval(v,0); ((aes_08t*)(x)+4*c)[1] = bval(v,1); \\r
+ ((aes_08t*)(x)+4*c)[2] = bval(v,2); ((aes_08t*)(x)+4*c)[3] = bval(v,3); }\r
+\r
+#elif (ALGORITHM_BYTE_ORDER == PLATFORM_BYTE_ORDER)\r
+\r
+#define word_in(x,c) (*((aes_32t*)(x)+(c)))\r
+#define word_out(x,c,v) (*((aes_32t*)(x)+(c)) = (v))\r
+\r
+#else\r
+\r
+#define word_in(x,c) aes_sw32(*((aes_32t*)(x)+(c)))\r
+#define word_out(x,c,v) (*((aes_32t*)(x)+(c)) = aes_sw32(v))\r
+\r
+#endif\r
+\r
+/* the finite field modular polynomial and elements */\r
+\r
+#define WPOLY 0x011b\r
+#define BPOLY 0x1b\r
+\r
+/* multiply four bytes in GF(2^8) by 'x' {02} in parallel */\r
+\r
+#define m1 0x80808080\r
+#define m2 0x7f7f7f7f\r
+#define gf_mulx(x) ((((x) & m2) << 1) ^ ((((x) & m1) >> 7) * BPOLY))\r
+\r
+/* The following defines provide alternative definitions of gf_mulx that might\r
+ give improved performance if a fast 32-bit multiply is not available. Note\r
+ that a temporary variable u needs to be defined where gf_mulx is used.\r
+\r
+#define gf_mulx(x) (u = (x) & m1, u |= (u >> 1), ((x) & m2) << 1) ^ ((u >> 3) | (u >> 6))\r
+#define m4 (0x01010101 * BPOLY)\r
+#define gf_mulx(x) (u = (x) & m1, ((x) & m2) << 1) ^ ((u - (u >> 7)) & m4)\r
+*/\r
+\r
+/* Work out which tables are needed for the different options */\r
+\r
+#if defined( AES_ASM )\r
+#if defined( ENC_ROUND )\r
+#undef ENC_ROUND\r
+#endif\r
+#define ENC_ROUND FOUR_TABLES\r
+#if defined( LAST_ENC_ROUND )\r
+#undef LAST_ENC_ROUND\r
+#endif\r
+#define LAST_ENC_ROUND FOUR_TABLES\r
+#if defined( DEC_ROUND )\r
+#undef DEC_ROUND\r
+#endif\r
+#define DEC_ROUND FOUR_TABLES\r
+#if defined( LAST_DEC_ROUND )\r
+#undef LAST_DEC_ROUND\r
+#endif\r
+#define LAST_DEC_ROUND FOUR_TABLES\r
+#if defined( KEY_SCHED )\r
+#undef KEY_SCHED\r
+#define KEY_SCHED FOUR_TABLES\r
+#endif\r
+#endif\r
+\r
+#if defined(ENCRYPTION) || defined(AES_ASM)\r
+#if ENC_ROUND == ONE_TABLE\r
+#define FT1_SET\r
+#elif ENC_ROUND == FOUR_TABLES\r
+#define FT4_SET\r
+#else\r
+#define SBX_SET\r
+#endif\r
+#if LAST_ENC_ROUND == ONE_TABLE\r
+#define FL1_SET\r
+#elif LAST_ENC_ROUND == FOUR_TABLES\r
+#define FL4_SET\r
+#elif !defined(SBX_SET)\r
+#define SBX_SET\r
+#endif\r
+#endif\r
+\r
+#if defined(DECRYPTION) || defined(AES_ASM)\r
+#if DEC_ROUND == ONE_TABLE\r
+#define IT1_SET\r
+#elif DEC_ROUND == FOUR_TABLES\r
+#define IT4_SET\r
+#else\r
+#define ISB_SET\r
+#endif\r
+#if LAST_DEC_ROUND == ONE_TABLE\r
+#define IL1_SET\r
+#elif LAST_DEC_ROUND == FOUR_TABLES\r
+#define IL4_SET\r
+#elif !defined(ISB_SET)\r
+#define ISB_SET\r
+#endif\r
+#endif\r
+\r
+#if defined(ENCRYPTION_KEY_SCHEDULE) || defined(DECRYPTION_KEY_SCHEDULE)\r
+#if KEY_SCHED == ONE_TABLE\r
+#define LS1_SET\r
+#define IM1_SET\r
+#elif KEY_SCHED == FOUR_TABLES\r
+#define LS4_SET\r
+#define IM4_SET\r
+#elif !defined(SBX_SET)\r
+#define SBX_SET\r
+#endif\r
+#endif\r
+\r
+/* generic definitions of Rijndael macros that use tables */\r
+\r
+#define no_table(x,box,vf,rf,c) bytes2word( \\r
+ box[bval(vf(x,0,c),rf(0,c))], \\r
+ box[bval(vf(x,1,c),rf(1,c))], \\r
+ box[bval(vf(x,2,c),rf(2,c))], \\r
+ box[bval(vf(x,3,c),rf(3,c))])\r
+\r
+#define one_table(x,op,tab,vf,rf,c) \\r
+ ( tab[bval(vf(x,0,c),rf(0,c))] \\r
+ ^ op(tab[bval(vf(x,1,c),rf(1,c))],1) \\r
+ ^ op(tab[bval(vf(x,2,c),rf(2,c))],2) \\r
+ ^ op(tab[bval(vf(x,3,c),rf(3,c))],3))\r
+\r
+#define four_tables(x,tab,vf,rf,c) \\r
+ ( tab[0][bval(vf(x,0,c),rf(0,c))] \\r
+ ^ tab[1][bval(vf(x,1,c),rf(1,c))] \\r
+ ^ tab[2][bval(vf(x,2,c),rf(2,c))] \\r
+ ^ tab[3][bval(vf(x,3,c),rf(3,c))])\r
+\r
+#define four_cached_tables(x,tab,vf,rf,c) \\r
+( tab##0[bval(vf(x,0,c),rf(0,c))] \\r
+ ^ tab##1[bval(vf(x,1,c),rf(1,c))] \\r
+ ^ tab##2[bval(vf(x,2,c),rf(2,c))] \\r
+ ^ tab##3[bval(vf(x,3,c),rf(3,c))])\r
+\r
+#define vf1(x,r,c) (x)\r
+#define rf1(r,c) (r)\r
+#define rf2(r,c) ((8+r-c)&3)\r
+\r
+/* perform forward and inverse column mix operation on four bytes in long word x in */\r
+/* parallel. NOTE: x must be a simple variable, NOT an expression in these macros. */\r
+\r
+#if defined(FM4_SET) /* not currently used */\r
+#define fwd_mcol(x) four_tables(x,t_use(f,m),vf1,rf1,0)\r
+#elif defined(FM1_SET) /* not currently used */\r
+#define fwd_mcol(x) one_table(x,upr,t_use(f,m),vf1,rf1,0)\r
+#else\r
+#define dec_fmvars aes_32t g2\r
+#define fwd_mcol(x) (g2 = gf_mulx(x), g2 ^ upr((x) ^ g2, 3) ^ upr((x), 2) ^ upr((x), 1))\r
+#endif\r
+\r
+#if defined(IM4_SET)\r
+#define inv_mcol(x) four_tables(x,t_use(i,m),vf1,rf1,0)\r
+#elif defined(IM1_SET)\r
+#define inv_mcol(x) one_table(x,upr,t_use(i,m),vf1,rf1,0)\r
+#else\r
+#define dec_imvars aes_32t g2, g4, g9\r
+#define inv_mcol(x) (g2 = gf_mulx(x), g4 = gf_mulx(g2), g9 = (x) ^ gf_mulx(g4), g4 ^= g9, \\r
+ (x) ^ g2 ^ g4 ^ upr(g2 ^ g9, 3) ^ upr(g4, 2) ^ upr(g9, 1))\r
+#endif\r
+\r
+#if defined(FL4_SET)\r
+#define ls_box(x,c) four_tables(x,t_use(f,l),vf1,rf2,c)\r
+#elif defined(LS4_SET)\r
+#define ls_box(x,c) four_tables(x,t_use(l,s),vf1,rf2,c)\r
+#elif defined(FL1_SET)\r
+#define ls_box(x,c) one_table(x,upr,t_use(f,l),vf1,rf2,c)\r
+#elif defined(LS1_SET)\r
+#define ls_box(x,c) one_table(x,upr,t_use(l,s),vf1,rf2,c)\r
+#else\r
+#define ls_box(x,c) no_table(x,t_use(s,box),vf1,rf2,c)\r
+#endif\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue 28/01/2004\r
+\r
+*/\r
+\r
+#if defined(__cplusplus)\r
+extern "C"\r
+{\r
+#endif\r
+\r
+#define DO_TABLES\r
+\r
+#include "aesopt.h"\r
+\r
+#if defined(FIXED_TABLES)\r
+\r
+#define sb_data(w) {\\r
+ w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\\r
+ w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\\r
+ w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\\r
+ w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\\r
+ w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\\r
+ w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\\r
+ w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\\r
+ w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\\r
+ w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\\r
+ w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\\r
+ w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\\r
+ w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\\r
+ w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\\r
+ w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\\r
+ w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\\r
+ w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\\r
+ w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\\r
+ w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\\r
+ w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\\r
+ w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\\r
+ w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\\r
+ w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\\r
+ w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\\r
+ w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\\r
+ w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\\r
+ w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\\r
+ w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\\r
+ w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\\r
+ w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\\r
+ w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\\r
+ w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\\r
+ w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }\r
+\r
+#define isb_data(w) {\\r
+ w(0x52), w(0x09), w(0x6a), w(0xd5), w(0x30), w(0x36), w(0xa5), w(0x38),\\r
+ w(0xbf), w(0x40), w(0xa3), w(0x9e), w(0x81), w(0xf3), w(0xd7), w(0xfb),\\r
+ w(0x7c), w(0xe3), w(0x39), w(0x82), w(0x9b), w(0x2f), w(0xff), w(0x87),\\r
+ w(0x34), w(0x8e), w(0x43), w(0x44), w(0xc4), w(0xde), w(0xe9), w(0xcb),\\r
+ w(0x54), w(0x7b), w(0x94), w(0x32), w(0xa6), w(0xc2), w(0x23), w(0x3d),\\r
+ w(0xee), w(0x4c), w(0x95), w(0x0b), w(0x42), w(0xfa), w(0xc3), w(0x4e),\\r
+ w(0x08), w(0x2e), w(0xa1), w(0x66), w(0x28), w(0xd9), w(0x24), w(0xb2),\\r
+ w(0x76), w(0x5b), w(0xa2), w(0x49), w(0x6d), w(0x8b), w(0xd1), w(0x25),\\r
+ w(0x72), w(0xf8), w(0xf6), w(0x64), w(0x86), w(0x68), w(0x98), w(0x16),\\r
+ w(0xd4), w(0xa4), w(0x5c), w(0xcc), w(0x5d), w(0x65), w(0xb6), w(0x92),\\r
+ w(0x6c), w(0x70), w(0x48), w(0x50), w(0xfd), w(0xed), w(0xb9), w(0xda),\\r
+ w(0x5e), w(0x15), w(0x46), w(0x57), w(0xa7), w(0x8d), w(0x9d), w(0x84),\\r
+ w(0x90), w(0xd8), w(0xab), w(0x00), w(0x8c), w(0xbc), w(0xd3), w(0x0a),\\r
+ w(0xf7), w(0xe4), w(0x58), w(0x05), w(0xb8), w(0xb3), w(0x45), w(0x06),\\r
+ w(0xd0), w(0x2c), w(0x1e), w(0x8f), w(0xca), w(0x3f), w(0x0f), w(0x02),\\r
+ w(0xc1), w(0xaf), w(0xbd), w(0x03), w(0x01), w(0x13), w(0x8a), w(0x6b),\\r
+ w(0x3a), w(0x91), w(0x11), w(0x41), w(0x4f), w(0x67), w(0xdc), w(0xea),\\r
+ w(0x97), w(0xf2), w(0xcf), w(0xce), w(0xf0), w(0xb4), w(0xe6), w(0x73),\\r
+ w(0x96), w(0xac), w(0x74), w(0x22), w(0xe7), w(0xad), w(0x35), w(0x85),\\r
+ w(0xe2), w(0xf9), w(0x37), w(0xe8), w(0x1c), w(0x75), w(0xdf), w(0x6e),\\r
+ w(0x47), w(0xf1), w(0x1a), w(0x71), w(0x1d), w(0x29), w(0xc5), w(0x89),\\r
+ w(0x6f), w(0xb7), w(0x62), w(0x0e), w(0xaa), w(0x18), w(0xbe), w(0x1b),\\r
+ w(0xfc), w(0x56), w(0x3e), w(0x4b), w(0xc6), w(0xd2), w(0x79), w(0x20),\\r
+ w(0x9a), w(0xdb), w(0xc0), w(0xfe), w(0x78), w(0xcd), w(0x5a), w(0xf4),\\r
+ w(0x1f), w(0xdd), w(0xa8), w(0x33), w(0x88), w(0x07), w(0xc7), w(0x31),\\r
+ w(0xb1), w(0x12), w(0x10), w(0x59), w(0x27), w(0x80), w(0xec), w(0x5f),\\r
+ w(0x60), w(0x51), w(0x7f), w(0xa9), w(0x19), w(0xb5), w(0x4a), w(0x0d),\\r
+ w(0x2d), w(0xe5), w(0x7a), w(0x9f), w(0x93), w(0xc9), w(0x9c), w(0xef),\\r
+ w(0xa0), w(0xe0), w(0x3b), w(0x4d), w(0xae), w(0x2a), w(0xf5), w(0xb0),\\r
+ w(0xc8), w(0xeb), w(0xbb), w(0x3c), w(0x83), w(0x53), w(0x99), w(0x61),\\r
+ w(0x17), w(0x2b), w(0x04), w(0x7e), w(0xba), w(0x77), w(0xd6), w(0x26),\\r
+ w(0xe1), w(0x69), w(0x14), w(0x63), w(0x55), w(0x21), w(0x0c), w(0x7d) }\r
+\r
+#define mm_data(w) {\\r
+ w(0x00), w(0x01), w(0x02), w(0x03), w(0x04), w(0x05), w(0x06), w(0x07),\\r
+ w(0x08), w(0x09), w(0x0a), w(0x0b), w(0x0c), w(0x0d), w(0x0e), w(0x0f),\\r
+ w(0x10), w(0x11), w(0x12), w(0x13), w(0x14), w(0x15), w(0x16), w(0x17),\\r
+ w(0x18), w(0x19), w(0x1a), w(0x1b), w(0x1c), w(0x1d), w(0x1e), w(0x1f),\\r
+ w(0x20), w(0x21), w(0x22), w(0x23), w(0x24), w(0x25), w(0x26), w(0x27),\\r
+ w(0x28), w(0x29), w(0x2a), w(0x2b), w(0x2c), w(0x2d), w(0x2e), w(0x2f),\\r
+ w(0x30), w(0x31), w(0x32), w(0x33), w(0x34), w(0x35), w(0x36), w(0x37),\\r
+ w(0x38), w(0x39), w(0x3a), w(0x3b), w(0x3c), w(0x3d), w(0x3e), w(0x3f),\\r
+ w(0x40), w(0x41), w(0x42), w(0x43), w(0x44), w(0x45), w(0x46), w(0x47),\\r
+ w(0x48), w(0x49), w(0x4a), w(0x4b), w(0x4c), w(0x4d), w(0x4e), w(0x4f),\\r
+ w(0x50), w(0x51), w(0x52), w(0x53), w(0x54), w(0x55), w(0x56), w(0x57),\\r
+ w(0x58), w(0x59), w(0x5a), w(0x5b), w(0x5c), w(0x5d), w(0x5e), w(0x5f),\\r
+ w(0x60), w(0x61), w(0x62), w(0x63), w(0x64), w(0x65), w(0x66), w(0x67),\\r
+ w(0x68), w(0x69), w(0x6a), w(0x6b), w(0x6c), w(0x6d), w(0x6e), w(0x6f),\\r
+ w(0x70), w(0x71), w(0x72), w(0x73), w(0x74), w(0x75), w(0x76), w(0x77),\\r
+ w(0x78), w(0x79), w(0x7a), w(0x7b), w(0x7c), w(0x7d), w(0x7e), w(0x7f),\\r
+ w(0x80), w(0x81), w(0x82), w(0x83), w(0x84), w(0x85), w(0x86), w(0x87),\\r
+ w(0x88), w(0x89), w(0x8a), w(0x8b), w(0x8c), w(0x8d), w(0x8e), w(0x8f),\\r
+ w(0x90), w(0x91), w(0x92), w(0x93), w(0x94), w(0x95), w(0x96), w(0x97),\\r
+ w(0x98), w(0x99), w(0x9a), w(0x9b), w(0x9c), w(0x9d), w(0x9e), w(0x9f),\\r
+ w(0xa0), w(0xa1), w(0xa2), w(0xa3), w(0xa4), w(0xa5), w(0xa6), w(0xa7),\\r
+ w(0xa8), w(0xa9), w(0xaa), w(0xab), w(0xac), w(0xad), w(0xae), w(0xaf),\\r
+ w(0xb0), w(0xb1), w(0xb2), w(0xb3), w(0xb4), w(0xb5), w(0xb6), w(0xb7),\\r
+ w(0xb8), w(0xb9), w(0xba), w(0xbb), w(0xbc), w(0xbd), w(0xbe), w(0xbf),\\r
+ w(0xc0), w(0xc1), w(0xc2), w(0xc3), w(0xc4), w(0xc5), w(0xc6), w(0xc7),\\r
+ w(0xc8), w(0xc9), w(0xca), w(0xcb), w(0xcc), w(0xcd), w(0xce), w(0xcf),\\r
+ w(0xd0), w(0xd1), w(0xd2), w(0xd3), w(0xd4), w(0xd5), w(0xd6), w(0xd7),\\r
+ w(0xd8), w(0xd9), w(0xda), w(0xdb), w(0xdc), w(0xdd), w(0xde), w(0xdf),\\r
+ w(0xe0), w(0xe1), w(0xe2), w(0xe3), w(0xe4), w(0xe5), w(0xe6), w(0xe7),\\r
+ w(0xe8), w(0xe9), w(0xea), w(0xeb), w(0xec), w(0xed), w(0xee), w(0xef),\\r
+ w(0xf0), w(0xf1), w(0xf2), w(0xf3), w(0xf4), w(0xf5), w(0xf6), w(0xf7),\\r
+ w(0xf8), w(0xf9), w(0xfa), w(0xfb), w(0xfc), w(0xfd), w(0xfe), w(0xff) }\r
+\r
+#define rc_data(w) {\\r
+ w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\\r
+ w(0x1b), w(0x36) }\r
+\r
+#define h0(x) (x)\r
+\r
+#define w0(p) bytes2word(p, 0, 0, 0)\r
+#define w1(p) bytes2word(0, p, 0, 0)\r
+#define w2(p) bytes2word(0, 0, p, 0)\r
+#define w3(p) bytes2word(0, 0, 0, p)\r
+\r
+#define u0(p) bytes2word(f2(p), p, p, f3(p))\r
+#define u1(p) bytes2word(f3(p), f2(p), p, p)\r
+#define u2(p) bytes2word(p, f3(p), f2(p), p)\r
+#define u3(p) bytes2word(p, p, f3(p), f2(p))\r
+\r
+#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p))\r
+#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p))\r
+#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p))\r
+#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p))\r
+\r
+#endif\r
+\r
+#if defined(FIXED_TABLES) || !defined(FF_TABLES)\r
+\r
+#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY))\r
+#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))\r
+#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) \\r
+ ^ (((x>>5) & 4) * WPOLY))\r
+#define f3(x) (f2(x) ^ x)\r
+#define f9(x) (f8(x) ^ x)\r
+#define fb(x) (f8(x) ^ f2(x) ^ x)\r
+#define fd(x) (f8(x) ^ f4(x) ^ x)\r
+#define fe(x) (f8(x) ^ f4(x) ^ f2(x))\r
+\r
+#else\r
+\r
+#define f2(x) ((x) ? pow[log[x] + 0x19] : 0)\r
+#define f3(x) ((x) ? pow[log[x] + 0x01] : 0)\r
+#define f9(x) ((x) ? pow[log[x] + 0xc7] : 0)\r
+#define fb(x) ((x) ? pow[log[x] + 0x68] : 0)\r
+#define fd(x) ((x) ? pow[log[x] + 0xee] : 0)\r
+#define fe(x) ((x) ? pow[log[x] + 0xdf] : 0)\r
+#define fi(x) ((x) ? pow[ 255 - log[x]] : 0)\r
+\r
+#endif\r
+\r
+#include "aestab.h"\r
+\r
+#if defined(FIXED_TABLES)\r
+\r
+/* implemented in case of wrong call for fixed tables */\r
+\r
+void gen_tabs(void)\r
+{\r
+}\r
+\r
+#else /* dynamic table generation */\r
+\r
+#if !defined(FF_TABLES)\r
+\r
+/* Generate the tables for the dynamic table option\r
+\r
+ It will generally be sensible to use tables to compute finite\r
+ field multiplies and inverses but where memory is scarse this\r
+ code might sometimes be better. But it only has effect during\r
+ initialisation so its pretty unimportant in overall terms.\r
+*/\r
+\r
+/* return 2 ^ (n - 1) where n is the bit number of the highest bit\r
+ set in x with x in the range 1 < x < 0x00000200. This form is\r
+ used so that locals within fi can be bytes rather than words\r
+*/\r
+\r
+static aes_08t hibit(const aes_32t x)\r
+{ aes_08t r = (aes_08t)((x >> 1) | (x >> 2));\r
+\r
+ r |= (r >> 2);\r
+ r |= (r >> 4);\r
+ return (r + 1) >> 1;\r
+}\r
+\r
+/* return the inverse of the finite field element x */\r
+\r
+static aes_08t fi(const aes_08t x)\r
+{ aes_08t p1 = x, p2 = BPOLY, n1 = hibit(x), n2 = 0x80, v1 = 1, v2 = 0;\r
+\r
+ if(x < 2) return x;\r
+\r
+ for(;;)\r
+ {\r
+ if(!n1) return v1;\r
+\r
+ while(n2 >= n1)\r
+ {\r
+ n2 /= n1; p2 ^= p1 * n2; v2 ^= v1 * n2; n2 = hibit(p2);\r
+ }\r
+\r
+ if(!n2) return v2;\r
+\r
+ while(n1 >= n2)\r
+ {\r
+ n1 /= n2; p1 ^= p2 * n1; v1 ^= v2 * n1; n1 = hibit(p1);\r
+ }\r
+ }\r
+}\r
+\r
+#endif\r
+\r
+/* The forward and inverse affine transformations used in the S-box */\r
+\r
+#define fwd_affine(x) \\r
+ (w = (aes_32t)x, w ^= (w<<1)^(w<<2)^(w<<3)^(w<<4), 0x63^(aes_08t)(w^(w>>8)))\r
+\r
+#define inv_affine(x) \\r
+ (w = (aes_32t)x, w = (w<<1)^(w<<3)^(w<<6), 0x05^(aes_08t)(w^(w>>8)))\r
+\r
+static int init = 0;\r
+\r
+void gen_tabs(void)\r
+{ aes_32t i, w;\r
+\r
+#if defined(FF_TABLES)\r
+\r
+ aes_08t pow[512], log[256];\r
+\r
+ if(init) return;\r
+ /* log and power tables for GF(2^8) finite field with\r
+ WPOLY as modular polynomial - the simplest primitive\r
+ root is 0x03, used here to generate the tables\r
+ */\r
+\r
+ i = 0; w = 1;\r
+ do\r
+ {\r
+ pow[i] = (aes_08t)w;\r
+ pow[i + 255] = (aes_08t)w;\r
+ log[w] = (aes_08t)i++;\r
+ w ^= (w << 1) ^ (w & 0x80 ? WPOLY : 0);\r
+ }\r
+ while (w != 1);\r
+\r
+#else\r
+ if(init) return;\r
+#endif\r
+\r
+ for(i = 0, w = 1; i < RC_LENGTH; ++i)\r
+ {\r
+ t_set(r,c)[i] = bytes2word(w, 0, 0, 0);\r
+ w = f2(w);\r
+ }\r
+\r
+ for(i = 0; i < 256; ++i)\r
+ { aes_08t b;\r
+\r
+ b = fwd_affine(fi((aes_08t)i));\r
+ w = bytes2word(f2(b), b, b, f3(b));\r
+\r
+#if defined( SBX_SET )\r
+ t_set(s,box)[i] = b;\r
+#endif\r
+\r
+#if defined( FT1_SET ) /* tables for a normal encryption round */\r
+ t_set(f,n)[i] = w;\r
+#endif\r
+#if defined( FT4_SET )\r
+ t_set(f,n)[0][i] = w;\r
+ t_set(f,n)[1][i] = upr(w,1);\r
+ t_set(f,n)[2][i] = upr(w,2);\r
+ t_set(f,n)[3][i] = upr(w,3);\r
+#endif\r
+ w = bytes2word(b, 0, 0, 0);\r
+\r
+#if defined( FL1_SET ) /* tables for last encryption round (may also */\r
+ t_set(f,l)[i] = w; /* be used in the key schedule) */\r
+#endif\r
+#if defined( FL4_SET )\r
+ t_set(f,l)[0][i] = w;\r
+ t_set(f,l)[1][i] = upr(w,1);\r
+ t_set(f,l)[2][i] = upr(w,2);\r
+ t_set(f,l)[3][i] = upr(w,3);\r
+#endif\r
+\r
+#if defined( LS1_SET ) /* table for key schedule if t_set(f,l) above is */\r
+ t_set(l,s)[i] = w; /* not of the required form */\r
+#endif\r
+#if defined( LS4_SET )\r
+ t_set(l,s)[0][i] = w;\r
+ t_set(l,s)[1][i] = upr(w,1);\r
+ t_set(l,s)[2][i] = upr(w,2);\r
+ t_set(l,s)[3][i] = upr(w,3);\r
+#endif\r
+\r
+ b = fi(inv_affine((aes_08t)i));\r
+ w = bytes2word(fe(b), f9(b), fd(b), fb(b));\r
+\r
+#if defined( IM1_SET ) /* tables for the inverse mix column operation */\r
+ t_set(i,m)[b] = w;\r
+#endif\r
+#if defined( IM4_SET )\r
+ t_set(i,m)[0][b] = w;\r
+ t_set(i,m)[1][b] = upr(w,1);\r
+ t_set(i,m)[2][b] = upr(w,2);\r
+ t_set(i,m)[3][b] = upr(w,3);\r
+#endif\r
+\r
+#if defined( ISB_SET )\r
+ t_set(i,box)[i] = b;\r
+#endif\r
+#if defined( IT1_SET ) /* tables for a normal decryption round */\r
+ t_set(i,n)[i] = w;\r
+#endif\r
+#if defined( IT4_SET )\r
+ t_set(i,n)[0][i] = w;\r
+ t_set(i,n)[1][i] = upr(w,1);\r
+ t_set(i,n)[2][i] = upr(w,2);\r
+ t_set(i,n)[3][i] = upr(w,3);\r
+#endif\r
+ w = bytes2word(b, 0, 0, 0);\r
+#if defined( IL1_SET ) /* tables for last decryption round */\r
+ t_set(i,l)[i] = w;\r
+#endif\r
+#if defined( IL4_SET )\r
+ t_set(i,l)[0][i] = w;\r
+ t_set(i,l)[1][i] = upr(w,1);\r
+ t_set(i,l)[2][i] = upr(w,2);\r
+ t_set(i,l)[3][i] = upr(w,3);\r
+#endif\r
+ }\r
+ init = 1;\r
+}\r
+\r
+#endif\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif\r
+\r
--- /dev/null
+/*\r
+ ---------------------------------------------------------------------------\r
+ Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.\r
+\r
+ LICENSE TERMS\r
+\r
+ The free distribution and use of this software in both source and binary\r
+ form is allowed (with or without changes) provided that:\r
+\r
+ 1. distributions of this source code include the above copyright\r
+ notice, this list of conditions and the following disclaimer;\r
+\r
+ 2. distributions in binary form include the above copyright\r
+ notice, this list of conditions and the following disclaimer\r
+ in the documentation and/or other associated materials;\r
+\r
+ 3. the copyright holder's name is not used to endorse products\r
+ built using this software without specific written permission.\r
+\r
+ ALTERNATIVELY, provided that this notice is retained in full, this product\r
+ may be distributed under the terms of the GNU General Public License (GPL),\r
+ in which case the provisions of the GPL apply INSTEAD OF those given above.\r
+\r
+ DISCLAIMER\r
+\r
+ This software is provided 'as is' with no explicit or implied warranties\r
+ in respect of its properties, including, but not limited to, correctness\r
+ and/or fitness for purpose.\r
+ ---------------------------------------------------------------------------\r
+ Issue 28/01/2004\r
+\r
+ This file contains the code for declaring the tables needed to implement\r
+ AES. The file aesopt.h is assumed to be included before this header file.\r
+ If there are no global variables, the definitions here can be used to put\r
+ the AES tables in a structure so that a pointer can then be added to the\r
+ AES context to pass them to the AES routines that need them. If this\r
+ facility is used, the calling program has to ensure that this pointer is\r
+ managed appropriately. In particular, the value of the t_dec(in,it) item\r
+ in the table structure must be set to zero in order to ensure that the\r
+ tables are initialised. In practice the three code sequences in aeskey.c\r
+ that control the calls to gen_tabs() and the gen_tabs() routine itself will\r
+ have to be changed for a specific implementation. If global variables are\r
+ available it will generally be preferable to use them with the precomputed\r
+ FIXED_TABLES option that uses static global tables.\r
+\r
+ The following defines can be used to control the way the tables\r
+ are defined, initialised and used in embedded environments that\r
+ require special features for these purposes\r
+\r
+ the 't_dec' construction is used to declare fixed table arrays\r
+ the 't_set' construction is used to set fixed table values\r
+ the 't_use' construction is used to access fixed table values\r
+\r
+ 256 byte tables:\r
+\r
+ t_xxx(s,box) => forward S box\r
+ t_xxx(i,box) => inverse S box\r
+\r
+ 256 32-bit word OR 4 x 256 32-bit word tables:\r
+\r
+ t_xxx(f,n) => forward normal round\r
+ t_xxx(f,l) => forward last round\r
+ t_xxx(i,n) => inverse normal round\r
+ t_xxx(i,l) => inverse last round\r
+ t_xxx(l,s) => key schedule table\r
+ t_xxx(i,m) => key schedule table\r
+\r
+ Other variables and tables:\r
+\r
+ t_xxx(r,c) => the rcon table\r
+*/\r
+\r
+#if !defined( _AESTAB_H )\r
+#define _AESTAB_H\r
+\r
+#define t_dec(m,n) t_##m##n\r
+#define t_set(m,n) t_##m##n\r
+#define t_use(m,n) t_##m##n\r
+\r
+#if defined(FIXED_TABLES)\r
+#define Const const\r
+#else\r
+#define Const\r
+#endif\r
+\r
+#if defined(DO_TABLES)\r
+#define Extern\r
+#else\r
+#define Extern extern\r
+#endif\r
+\r
+#if defined(_MSC_VER) && defined(TABLE_ALIGN)\r
+#define Align __declspec(align(TABLE_ALIGN))\r
+#else\r
+#define Align\r
+#endif\r
+\r
+#if defined(__cplusplus)\r
+extern "C"\r
+{\r
+#endif\r
+\r
+#if defined(DO_TABLES) && defined(FIXED_TABLES)\r
+#define d_1(t,n,b,e) Align Const t n[256] = b(e)\r
+#define d_4(t,n,b,e,f,g,h) Align Const t n[4][256] = { b(e), b(f), b(g), b(h) }\r
+Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0);\r
+#else\r
+#define d_1(t,n,b,e) Extern Align Const t n[256]\r
+#define d_4(t,n,b,e,f,g,h) Extern Align Const t n[4][256]\r
+Extern Align Const aes_32t t_dec(r,c)[RC_LENGTH];\r
+#endif\r
+\r
+#if defined( SBX_SET )\r
+ d_1(aes_08t, t_dec(s,box), sb_data, h0);\r
+#endif\r
+#if defined( ISB_SET )\r
+ d_1(aes_08t, t_dec(i,box), isb_data, h0);\r
+#endif\r
+\r
+#if defined( FT1_SET )\r
+ d_1(aes_32t, t_dec(f,n), sb_data, u0);\r
+#endif\r
+#if defined( FT4_SET )\r
+ d_4(aes_32t, t_dec(f,n), sb_data, u0, u1, u2, u3);\r
+#endif\r
+\r
+#if defined( FL1_SET )\r
+ d_1(aes_32t, t_dec(f,l), sb_data, w0);\r
+#endif\r
+#if defined( FL4_SET )\r
+ d_4(aes_32t, t_dec(f,l), sb_data, w0, w1, w2, w3);\r
+#endif\r
+\r
+#if defined( IT1_SET )\r
+ d_1(aes_32t, t_dec(i,n), isb_data, v0);\r
+#endif\r
+#if defined( IT4_SET )\r
+ d_4(aes_32t, t_dec(i,n), isb_data, v0, v1, v2, v3);\r
+#endif\r
+\r
+#if defined( IL1_SET )\r
+ d_1(aes_32t, t_dec(i,l), isb_data, w0);\r
+#endif\r
+#if defined( IL4_SET )\r
+ d_4(aes_32t, t_dec(i,l), isb_data, w0, w1, w2, w3);\r
+#endif\r
+\r
+#if defined( LS1_SET )\r
+#if defined( FL1_SET )\r
+#undef LS1_SET\r
+#else\r
+ d_1(aes_32t, t_dec(l,s), sb_data, w0);\r
+#endif\r
+#endif\r
+\r
+#if defined( LS4_SET )\r
+#if defined( FL4_SET )\r
+#undef LS4_SET\r
+#else\r
+ d_4(aes_32t, t_dec(l,s), sb_data, w0, w1, w2, w3);\r
+#endif\r
+#endif\r
+\r
+#if defined( IM1_SET )\r
+ d_1(aes_32t, t_dec(i,m), mm_data, v0);\r
+#endif\r
+#if defined( IM4_SET )\r
+ d_4(aes_32t, t_dec(i,m), mm_data, v0, v1, v2, v3);\r
+#endif\r
+\r
+#if defined(__cplusplus)\r
+}\r
+#endif\r
+\r
+#endif\r
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
--- /dev/null
+/*
+ * Copyright (c) 1995-2002 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+#include <sl.h>
+#include <stdint.h>
+
+typedef uint8_t UInt8;
+typedef uint16_t UInt16;
+typedef uint32_t UInt32;
+typedef int8_t SInt8;
+typedef int16_t SInt16;
+typedef int32_t SInt32;
+
+enum { false = 0, true = 1 };
+
+static void
+PreviewDecompress16(uint32_t * compressBuffer,
+ uint32_t width, uint32_t height, uint32_t row,
+ uint16_t * output)
+{
+ int i, j;
+ uint32_t * input;
+
+ uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t));
+ uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t));
+ uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t));
+ uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t));
+ uint32_t sr0, sr1, sr2, sr3;
+
+ bzero(sc0, (width+2) * sizeof(uint16_t));
+ bzero(sc1, (width+2) * sizeof(uint16_t));
+ bzero(sc2, (width+2) * sizeof(uint16_t));
+ bzero(sc3, (width+2) * sizeof(uint16_t));
+
+ uint32_t tmp1, tmp2, out;
+ for (j = 0; j < (height + 2); j++)
+ {
+ input = compressBuffer;
+ if (j < height)
+ input += j;
+ else
+ input += height - 1;
+ input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer));
+
+ uint32_t data, repeat, fetch, count = 0;
+ sr0 = sr1 = sr2 = sr3 = 0;
+
+ for (i = 0; i < (width + 2); i++)
+ {
+ if (i < width)
+ {
+ if (!count)
+ {
+ count = *input++;
+ repeat = (count & 0xff000000);
+ count ^= repeat;
+ fetch = true;
+ }
+ else
+ fetch = (0 == repeat);
+
+ count--;
+
+ if (fetch)
+ {
+ data = *((uint16_t *)input)++;
+
+ // grayscale
+ // srgb 13933, 46871, 4732
+ // ntsc 19595, 38470, 7471
+ data = 13933 * (0x1f & (data >> 10))
+ + 46871 * (0x1f & (data >> 5))
+ + 4732 * (0x1f & data);
+ data >>= 13;
+
+ // 70% white, 30 % black
+ data *= 19661;
+ data += (103 << 16);
+ data >>= 16;
+ }
+ }
+
+ // gauss blur
+ tmp2 = sr0 + data;
+ sr0 = data;
+ tmp1 = sr1 + tmp2;
+ sr1 = tmp2;
+ tmp2 = sr2 + tmp1;
+ sr2 = tmp1;
+ tmp1 = sr3 + tmp2;
+ sr3 = tmp2;
+
+ tmp2 = sc0[i] + tmp1;
+ sc0[i] = tmp1;
+ tmp1 = sc1[i] + tmp2;
+ sc1[i] = tmp2;
+ tmp2 = sc2[i] + tmp1;
+ sc2[i] = tmp1;
+ out = (128 + sc3[i] + tmp2) >> 11;
+ sc3[i] = tmp2;
+
+ out &= 0x1f;
+ if ((i > 1) && (j > 1))
+ output[i-2] = out | (out << 5) | (out << 10);
+ }
+
+ if (j > 1)
+ output += row;
+ }
+ free(sc3);
+ free(sc2);
+ free(sc1);
+ free(sc0);
+}
+
+static void
+PreviewDecompress32(uint32_t * compressBuffer,
+ uint32_t width, uint32_t height, uint32_t row,
+ uint32_t * output)
+{
+ int i, j;
+ uint32_t * input;
+
+ uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t));
+ uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t));
+ uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t));
+ uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t));
+ uint32_t sr0, sr1, sr2, sr3;
+
+ bzero(sc0, (width+2) * sizeof(uint16_t));
+ bzero(sc1, (width+2) * sizeof(uint16_t));
+ bzero(sc2, (width+2) * sizeof(uint16_t));
+ bzero(sc3, (width+2) * sizeof(uint16_t));
+
+ uint32_t tmp1, tmp2, out;
+ for (j = 0; j < (height + 2); j++)
+ {
+ input = compressBuffer;
+ if (j < height)
+ input += j;
+ else
+ input += height - 1;
+ input = (uint32_t *)(input[3] + ((uint8_t *)compressBuffer));
+
+ uint32_t data, repeat, fetch, count = 0;
+ sr0 = sr1 = sr2 = sr3 = 0;
+
+ for (i = 0; i < (width + 2); i++)
+ {
+ if (i < width)
+ {
+ if (!count)
+ {
+ count = *input++;
+ repeat = (count & 0xff000000);
+ count ^= repeat;
+ fetch = true;
+ }
+ else
+ fetch = (0 == repeat);
+
+ count--;
+
+ if (fetch)
+ {
+ data = *input++;
+
+ // grayscale
+ // srgb 13933, 46871, 4732
+ // ntsc 19595, 38470, 7471
+ data = 13933 * (0xff & (data >> 24))
+ + 46871 * (0xff & (data >> 16))
+ + 4732 * (0xff & data);
+ data >>= 16;
+
+ // 70% white, 30 % black
+ data *= 19661;
+ data += (103 << 16);
+ data >>= 16;
+ }
+ }
+
+ // gauss blur
+ tmp2 = sr0 + data;
+ sr0 = data;
+ tmp1 = sr1 + tmp2;
+ sr1 = tmp2;
+ tmp2 = sr2 + tmp1;
+ sr2 = tmp1;
+ tmp1 = sr3 + tmp2;
+ sr3 = tmp2;
+
+ tmp2 = sc0[i] + tmp1;
+ sc0[i] = tmp1;
+ tmp1 = sc1[i] + tmp2;
+ sc1[i] = tmp2;
+ tmp2 = sc2[i] + tmp1;
+ sc2[i] = tmp1;
+ out = (128 + sc3[i] + tmp2) >> 8;
+ sc3[i] = tmp2;
+
+ out &= 0xff;
+ if ((i > 1) && (j > 1))
+ output[i-2] = out | (out << 8) | (out << 16);
+ }
+
+ if (j > 1)
+ output += row;
+ }
+
+ free(sc3);
+ free(sc2);
+ free(sc1);
+ free(sc0);
+}
+
+int
+DecompressData(void *srcbase, void *dstbase,
+ int dw, int dh, int bytesPerPixel, int rowbytes)
+{
+ uint32_t * src = (uint32_t *) srcbase;
+
+ if ((bytesPerPixel != (int) src[0]) || (dw != (int) src[1]) || (dh != (int) src[2]))
+ return (false);
+
+ switch(bytesPerPixel)
+ {
+ case 4:
+ PreviewDecompress32((uint32_t *)srcbase, dw, dh, rowbytes >> 2, (uint32_t *) dstbase);
+ return (true);
+ case 2:
+ PreviewDecompress16((uint32_t *)srcbase, dw, dh, rowbytes >> 1, (uint16_t *) dstbase);
+ return (true);
+ default:
+ return (false);
+ }
+}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
typedef struct DisplayInfo DisplayInfo, *DisplayInfoPtr;
-static long FindDisplays(void);
-static long OpenDisplays(void);
-static long OpenDisplay(long displayNum);
-static long InitDisplay(long displayNum);
+static long FindDisplays();
+static long OpenDisplays(int fill);
+static long OpenDisplay(long displayNum, int fill);
+static long InitDisplay(long displayNum, int fill);
static long LookUpCLUTIndex(long index, long depth);
static long gNumDisplays;
// Public Functions
-long InitDisplays(void)
+long InitDisplays(int fill)
{
FindDisplays();
- OpenDisplays();
+ OpenDisplays(fill);
return 0;
}
+void CloseDisplays(void)
+{
+ int cnt;
+ for (cnt = 0; cnt < gNumDisplays; cnt++) {
+ if (gDisplays[cnt].screenIH)
+ Close(gDisplays[cnt].screenIH);
+ }
+}
long DrawSplashScreen(long stage)
{
}
-void GetMainScreenPH(Boot_Video_Ptr video)
+void GetMainScreenPH(Boot_Video_Ptr video, int setProperties)
{
DisplayInfoPtr display;
long address, size;
video->v_height = display->height;
video->v_depth = display->depth;
}
-
- // Allocate memory and a range for the CLUT.
+
+ if (!setProperties) return;
+
size = 256 * 3;
+ // Allocate memory and a range for the CLUT.
address = AllocateKernelMemory(size);
AllocateMemoryRange("BootCLUT", address, size);
bcopy((char *)gClut, (char *)address, size);
// Find the main screen using the screen alias or chaos/control.
gMainDisplayNum = -1;
screenPH = FindDevice("screen");
+ gDisplays[gNumDisplays++].screenPH = screenPH;
if (screenPH == -1) screenPH = controlPH;
for (cnt = 0; cnt < gNumDisplays; cnt++)
if (gDisplays[cnt].screenPH == screenPH) gMainDisplayNum = cnt;
}
-static long OpenDisplays(void)
+static long OpenDisplays(int fill)
{
long cnt;
// Open the main screen or
// look for a main screen if we don't have one.
- if ((gMainDisplayNum == -1) || !OpenDisplay(gMainDisplayNum)) {
+ if ((gMainDisplayNum == -1) || !OpenDisplay(gMainDisplayNum, fill)) {
gMainDisplayNum = -1;
for (cnt = 0; cnt < gNumDisplays; cnt++) {
- if (OpenDisplay(cnt)) {
+ if (OpenDisplay(cnt, fill)) {
gMainDisplayNum = cnt;
break;
}
// Open the rest of the displays
if (gOFVersion >= kOFVersion3x) {
for (cnt = 0; cnt < gNumDisplays; cnt++) {
- OpenDisplay(cnt);
+ OpenDisplay(cnt, 1);
}
}
}
-static long OpenDisplay(long displayNum)
+static long OpenDisplay(long displayNum, int fill)
{
char screenPath[258], displayType[32];
CICell screenPH, screenIH;
gDisplays[displayNum].screenIH = screenIH;
// Initialize the display.
- if (screenIH != 0) InitDisplay(displayNum);
+ if (screenIH != 0) InitDisplay(displayNum, fill);
return screenIH != 0;
}
-static long InitDisplay(long displayNum)
+static long InitDisplay(long displayNum, int fill)
{
DisplayInfoPtr display = &gDisplays[displayNum];
CICell screenPH = display->screenPH;
CallMethod(3, 0, screenIH, "set-colors", (long)gClut, 0, 256);
}
- // Set the screen to 75% grey.
- CallMethod(5, 0, screenIH, "fill-rectangle",
+ if (fill)
+ // Set the screen to 75% grey.
+ CallMethod(5, 0, screenIH, "fill-rectangle",
LookUpCLUTIndex(0x01, display->depth),
0, 0, display->width, display->height);
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#define DRIVER_DEBUG 0
-enum {
- kTagTypeNone = 0,
- kTagTypeDict,
- kTagTypeKey,
- kTagTypeString,
- kTagTypeInteger,
- kTagTypeData,
- kTagTypeDate,
- kTagTypeFalse,
- kTagTypeTrue,
- kTagTypeArray
-};
-
-#define kXMLTagPList "plist "
-#define kXMLTagDict "dict"
-#define kXMLTagKey "key"
-#define kXMLTagString "string"
-#define kXMLTagInteger "integer"
-#define kXMLTagData "data"
-#define kXMLTagDate "date"
-#define kXMLTagFalse "false/"
-#define kXMLTagTrue "true/"
-#define kXMLTagArray "array"
-
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")
#define kPropIOKitPersonalities ("IOKitPersonalities")
#define kPropIONameMatch ("IONameMatch")
-struct Tag {
- long type;
- char *string;
- struct Tag *tag;
- struct Tag *tagNext;
-};
-typedef struct Tag Tag, *TagPtr;
-
struct Module {
struct Module *nextModule;
long willLoad;
unsigned long signature1;
unsigned long signature2;
unsigned long length;
- unsigned long alder32;
+ unsigned long adler32;
unsigned long version;
unsigned long numDrivers;
unsigned long reserved1;
static long LoadMatchedModules(void);
static long MatchPersonalities(void);
static long MatchLibraries(void);
-static TagPtr GetProperty(TagPtr dict, char *key);
static ModulePtr FindModule(char *name);
-static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);
-static long ParseNextTag(char *buffer, TagPtr *tag);
-static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty);
-static long ParseTagKey(char *buffer, TagPtr *tag);
-static long ParseTagString(char *buffer, TagPtr *tag);
-static long ParseTagInteger(char *buffer, TagPtr *tag);
-static long ParseTagData(char *buffer, TagPtr *tag);
-static long ParseTagDate(char *buffer, TagPtr *tag);
-static long ParseTagBoolean(char *buffer, TagPtr *tag, long type);
-static long GetNextTag(char *buffer, char **tag, long *start);
-static long FixDataMatchingTag(char *buffer, char *tag);
-static TagPtr NewTag(void);
-static void FreeTag(TagPtr tag);
-static char *NewSymbol(char *string);
-static void FreeSymbol(char *string);
-#if DRIVER_DEBUG
-static void DumpTag(TagPtr tag, long depth);
-#endif
+static long XML2Module(char *buffer, ModulePtr *module, TagPtr *personalities);
static ModulePtr gModuleHead, gModuleTail;
static TagPtr gPersonalityHead, gPersonalityTail;
ret = GetFileInfo(dirSpec, "Extensions.mkext", &flags, &time);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)) {
ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
- if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) ||
- (((gBootMode & kBootModeSafe) == 0) && (time > time2))) {
+ // use mkext if if it looks right or if the folder was bad
+ if ((ret != 0) ||
+ ((flags & kFileTypeMask) != kFileTypeDirectory) ||
+ (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1)))) {
sprintf(gDriverSpec, "%sExtensions.mkext", dirSpec);
- printf("LoadDrivers: Loading from [%s]\n", gDriverSpec);
+ printf("FileLoadDrivers: Loading from [%s]\n", gDriverSpec);
if (LoadDriverMKext(gDriverSpec) == 0) return 0;
- }
+ } else if(time != (time2 + 1)) {
+ printf("mkext timestamp isn't quite right (delta: %d); ignoring...\n",
+ time2 - time);
+ }
}
strcat(dirSpec, "Extensions");
}
- printf("LoadDrivers: Loading from [%s]\n", dirSpec);
+ printf("FileLoadDrivers: Loading from [%s]\n", dirSpec);
index = 0;
while (1) {
ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
if (ret == -1) break;
-
+
// Make sure this is a directory.
if ((flags & kFileTypeMask ) != kFileTypeDirectory) continue;
}
ret = LoadDriverPList(dirSpec, gFileName, bundleType);
- if (ret != 0) {
- printf("LoadDrivers: failed\n");
- }
if (!plugin) {
ret = FileLoadDrivers(gDriverSpec, 1);
{
unsigned long driversAddr, driversLength, length;
char segName[32];
- DriversPackage *package = (DriversPackage *)kLoadAddr;
+ DriversPackage *package;
// Load the MKext.
- length = LoadFile(fileSpec);
+ length = LoadThinFatFile(fileSpec, (void **)&package);
if (length == -1) return -1;
- ThinFatBinary((void **)&package, &length);
-
// Verify the MKext.
if ((package->signature1 != kDriverPackageSignature1) ||
(package->signature2 != kDriverPackageSignature2)) return -1;
if (package->length > kLoadSize) return -1;
- if (package->alder32 != Alder32((char *)&package->version,
+ if (package->adler32 != Adler32((char *)&package->version,
package->length - 0x10)) return -1;
// Make space for the MKext.
(bundleType == kCFBundleType2) ? "Contents\\" : "");
length = LoadFile(gFileSpec);
+ *((char*)kLoadAddr + length) = '\0'; // terminate for parser safety
if (length == -1) {
free(tmpDriverPath);
return -1;
}
strncpy(buffer, (char *)kLoadAddr, length);
- ret = ParseXML(buffer, &module, &personalities);
+ ret = XML2Module(buffer, &module, &personalities);
free(buffer);
if (ret != 0) {
+ // could trap ret == -2 and report missing OSBundleRequired
free(tmpDriverPath);
return -1;
}
else gModuleTail->nextModule = module;
gModuleTail = module;
- // Add the persionalities to the personality list.
+ // Add the extracted personalities to the list.
if (personalities) personalities = personalities->tag;
while (personalities != 0) {
if (gPersonalityHead == 0) gPersonalityHead = personalities->tag;
if (prop != 0) {
fileName = prop->string;
sprintf(gFileSpec, "%s%s", module->driverPath, fileName);
- length = LoadFile(gFileSpec);
+ length = LoadThinFatFile(gFileSpec, &driverModuleAddr);
} else length = 0;
if (length != -1) {
- if (length != 0) {
- driverModuleAddr = (void *)kLoadAddr;
- ThinFatBinary(&driverModuleAddr, &length);
- }
-
// Make make in the image area.
driverLength = sizeof(DriverInfo) + module->plistLength + length;
driverAddr = AllocateKernelMemory(driverLength);
}
-static TagPtr GetProperty(TagPtr dict, char *key)
-{
- TagPtr tagList, tag;
-
- if (dict->type != kTagTypeDict) return 0;
-
- tag = 0;
- tagList = dict->tag;
- while (tagList) {
- tag = tagList;
- tagList = tag->tagNext;
-
- if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue;
-
- if (!strcmp(tag->string, key)) return tag->tag;
- }
-
- return 0;
-}
-
-
static ModulePtr FindModule(char *name)
{
ModulePtr module;
return module;
}
-
-static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities)
+/* turn buffer of XML into a ModulePtr for driver analysis */
+static long XML2Module(char *buffer, ModulePtr *module, TagPtr *personalities)
{
- long length, pos;
- TagPtr moduleDict, required;
+ TagPtr moduleDict = NULL, required;
ModulePtr tmpModule;
-
- pos = 0;
- while (1) {
- length = ParseNextTag(buffer + pos, &moduleDict);
- if (length == -1) break;
- pos += length;
-
- if (moduleDict == 0) continue;
-
- if (moduleDict->type == kTagTypeDict) break;
-
- FreeTag(moduleDict);
- }
-
- if (length == -1) return -1;
-
+
+ if(ParseXML(buffer, &moduleDict) < 0)
+ return -1;
+
required = GetProperty(moduleDict, kPropOSBundleRequired);
if ((required == 0) || (required->type != kTagTypeString) ||
!strcmp(required->string, "Safe Boot")) {
FreeTag(moduleDict);
- return -1;
+ return -2;
}
tmpModule = AllocateBootXMemory(sizeof(Module));
return 0;
}
-
-
-static long ParseNextTag(char *buffer, TagPtr *tag)
-{
- long length, pos;
- char *tagName;
-
- length = GetNextTag(buffer, &tagName, 0);
- if (length == -1) return -1;
-
- pos = length;
- if (!strncmp(tagName, kXMLTagPList, 6)) {
- length = 0;
- } else if (!strcmp(tagName, kXMLTagDict)) {
- length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
- } else if (!strcmp(tagName, kXMLTagDict "/")) {
- length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
- } else if (!strcmp(tagName, kXMLTagKey)) {
- length = ParseTagKey(buffer + pos, tag);
- } else if (!strcmp(tagName, kXMLTagString)) {
- length = ParseTagString(buffer + pos, tag);
- } else if (!strcmp(tagName, kXMLTagInteger)) {
- length = ParseTagInteger(buffer + pos, tag);
- } else if (!strcmp(tagName, kXMLTagData)) {
- length = ParseTagData(buffer + pos, tag);
- } else if (!strcmp(tagName, kXMLTagDate)) {
- length = ParseTagDate(buffer + pos, tag);
- } else if (!strcmp(tagName, kXMLTagFalse)) {
- length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
- } else if (!strcmp(tagName, kXMLTagTrue)) {
- length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
- } else if (!strcmp(tagName, kXMLTagArray)) {
- length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
- } else if (!strcmp(tagName, kXMLTagArray "/")) {
- length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
- } else {
- *tag = 0;
- length = 0;
- }
-
- if (length == -1) return -1;
-
- return pos + length;
-}
-
-
-static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty)
-{
- long length, pos;
- TagPtr tagList, tmpTag;
-
- tagList = 0;
- pos = 0;
-
- if (!empty) {
- while (1) {
- length = ParseNextTag(buffer + pos, &tmpTag);
- if (length == -1) break;
- pos += length;
-
- if (tmpTag == 0) break;
- tmpTag->tagNext = tagList;
- tagList = tmpTag;
- }
-
- if (length == -1) {
- FreeTag(tagList);
- return -1;
- }
- }
-
- tmpTag = NewTag();
- if (tmpTag == 0) {
- FreeTag(tagList);
- return -1;
- }
-
- tmpTag->type = type;
- tmpTag->string = 0;
- tmpTag->tag = tagList;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return pos;
-}
-
-
-static long ParseTagKey(char *buffer, TagPtr *tag)
-{
- long length, length2;
- char *string;
- TagPtr tmpTag, subTag;
-
- length = FixDataMatchingTag(buffer, kXMLTagKey);
- if (length == -1) return -1;
-
- length2 = ParseNextTag(buffer + length, &subTag);
- if (length2 == -1) return -1;
-
- tmpTag = NewTag();
- if (tmpTag == 0) {
- FreeTag(subTag);
- return -1;
- }
-
- string = NewSymbol(buffer);
- if (string == 0) {
- FreeTag(subTag);
- FreeTag(tmpTag);
- return -1;
- }
-
- tmpTag->type = kTagTypeKey;
- tmpTag->string = string;
- tmpTag->tag = subTag;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return length + length2;
-}
-
-
-static long ParseTagString(char *buffer, TagPtr *tag)
-{
- long length;
- char *string;
- TagPtr tmpTag;
-
- length = FixDataMatchingTag(buffer, kXMLTagString);
- if (length == -1) return -1;
-
- tmpTag = NewTag();
- if (tmpTag == 0) return -1;
-
- string = NewSymbol(buffer);
- if (string == 0) {
- FreeTag(tmpTag);
- return -1;
- }
-
- tmpTag->type = kTagTypeString;
- tmpTag->string = string;
- tmpTag->tag = 0;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return length;
-}
-
-
-static long ParseTagInteger(char *buffer, TagPtr *tag)
-{
- long length, integer;
- TagPtr tmpTag;
-
- length = FixDataMatchingTag(buffer, kXMLTagInteger);
- if (length == -1) return -1;
-
- tmpTag = NewTag();
- if (tmpTag == 0) return -1;
-
- integer = 0;
-
- tmpTag->type = kTagTypeInteger;
- tmpTag->string = (char *)integer;
- tmpTag->tag = 0;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return length;
-}
-
-
-static long ParseTagData(char *buffer, TagPtr *tag)
-{
- long length;
- TagPtr tmpTag;
-
- length = FixDataMatchingTag(buffer, kXMLTagData);
- if (length == -1) return -1;
-
- tmpTag = NewTag();
- if (tmpTag == 0) return -1;
-
- tmpTag->type = kTagTypeData;
- tmpTag->string = 0;
- tmpTag->tag = 0;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return length;
-}
-
-
-static long ParseTagDate(char *buffer, TagPtr *tag)
-{
- long length;
- TagPtr tmpTag;
-
- length = FixDataMatchingTag(buffer, kXMLTagDate);
- if (length == -1) return -1;
-
- tmpTag = NewTag();
- if (tmpTag == 0) return -1;
-
- tmpTag->type = kTagTypeDate;
- tmpTag->string = 0;
- tmpTag->tag = 0;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return length;
-}
-
-
-static long ParseTagBoolean(char *buffer, TagPtr *tag, long type)
-{
- TagPtr tmpTag;
-
- tmpTag = NewTag();
- if (tmpTag == 0) return -1;
-
- tmpTag->type = type;
- tmpTag->string = 0;
- tmpTag->tag = 0;
- tmpTag->tagNext = 0;
-
- *tag = tmpTag;
-
- return 0;
-}
-
-
-static long GetNextTag(char *buffer, char **tag, long *start)
-{
- long cnt, cnt2;
-
- if (tag == 0) return -1;
-
- // Find the start of the tag.
- cnt = 0;
- while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
- if (buffer[cnt] == '\0') return -1;
-
- // Find the end of the tag.
- cnt2 = cnt + 1;
- while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++;
- if (buffer[cnt2] == '\0') return -1;
-
- // Fix the tag data.
- *tag = buffer + cnt + 1;
- buffer[cnt2] = '\0';
- if (start) *start = cnt;
-
- return cnt2 + 1;
-}
-
-
-static long FixDataMatchingTag(char *buffer, char *tag)
-{
- long length, start, stop;
- char *endTag;
-
- start = 0;
- while (1) {
- length = GetNextTag(buffer + start, &endTag, &stop);
- if (length == -1) return -1;
-
- if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break;
- start += length;
- }
-
- buffer[start + stop] = '\0';
-
- return start + length;
-}
-
-
-#define kTagsPerBlock (0x1000)
-
-static TagPtr gTagsFree;
-
-static TagPtr NewTag(void)
-{
- long cnt;
- TagPtr tag;
-
- if (gTagsFree == 0) {
- tag = (TagPtr)AllocateBootXMemory(kTagsPerBlock * sizeof(Tag));
- if (tag == 0) return 0;
-
- // Initalize the new tags.
- for (cnt = 0; cnt < kTagsPerBlock; cnt++) {
- tag[cnt].type = kTagTypeNone;
- tag[cnt].string = 0;
- tag[cnt].tag = 0;
- tag[cnt].tagNext = tag + cnt + 1;
- }
- tag[kTagsPerBlock - 1].tagNext = 0;
-
- gTagsFree = tag;
- }
-
- tag = gTagsFree;
- gTagsFree = tag->tagNext;
-
- return tag;
-}
-
-
-static void FreeTag(TagPtr tag)
-{
- return;
- if (tag == 0) return;
-
- if (tag->string) FreeSymbol(tag->string);
-
- FreeTag(tag->tag);
- FreeTag(tag->tagNext);
-
- // Clear and free the tag.
- tag->type = kTagTypeNone;
- tag->string = 0;
- tag->tag = 0;
- tag->tagNext = gTagsFree;
- gTagsFree = tag;
-}
-
-
-struct Symbol {
- long refCount;
- struct Symbol *next;
- char string[1];
-};
-typedef struct Symbol Symbol, *SymbolPtr;
-
-static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol);
-
-static SymbolPtr gSymbolsHead;
-
-
-static char *NewSymbol(char *string)
-{
- SymbolPtr symbol;
-
- // Look for string in the list of symbols.
- symbol = FindSymbol(string, 0);
-
- // Add the new symbol.
- if (symbol == 0) {
- symbol = AllocateBootXMemory(sizeof(Symbol) + strlen(string));
- if (symbol == 0) return 0;
-
- // Set the symbol's data.
- symbol->refCount = 0;
- strcpy(symbol->string, string);
-
- // Add the symbol to the list.
- symbol->next = gSymbolsHead;
- gSymbolsHead = symbol;
- }
-
- // Update the refCount and return the string.
- symbol->refCount++;
- return symbol->string;
-}
-
-
-static void FreeSymbol(char *string)
-{
-#if 0
- SymbolPtr symbol, prev;
-
- // Look for string in the list of symbols.
- symbol = FindSymbol(string, &prev);
- if (symbol == 0) return;
-
- // Update the refCount.
- symbol->refCount--;
-
- if (symbol->refCount != 0) return;
-
- // Remove the symbol from the list.
- if (prev != 0) prev->next = symbol->next;
- else gSymbolsHead = symbol->next;
-
- // Free the symbol's memory.
- free(symbol);
-#endif
-}
-
-
-static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol)
-{
- SymbolPtr symbol, prev;
-
- symbol = gSymbolsHead;
- prev = 0;
-
- while (symbol != 0) {
- if (!strcmp(symbol->string, string)) break;
-
- prev = symbol;
- symbol = symbol->next;
- }
-
- if ((symbol != 0) && (prevSymbol != 0)) *prevSymbol = prev;
-
- return symbol;
-}
-
-#if DRIVER_DEBUG
-static void DumpTagDict(TagPtr tag, long depth);
-static void DumpTagKey(TagPtr tag, long depth);
-static void DumpTagString(TagPtr tag, long depth);
-static void DumpTagInteger(TagPtr tag, long depth);
-static void DumpTagData(TagPtr tag, long depth);
-static void DumpTagDate(TagPtr tag, long depth);
-static void DumpTagBoolean(TagPtr tag, long depth);
-static void DumpTagArray(TagPtr tag, long depth);
-static void DumpSpaces(long depth);
-
-static void DumpTag(TagPtr tag, long depth)
-{
- if (tag == 0) return;
-
- switch (tag->type) {
- case kTagTypeDict :
- DumpTagDict(tag, depth);
- break;
-
- case kTagTypeKey :
- DumpTagKey(tag, depth);
- break;
-
- case kTagTypeString :
- DumpTagString(tag, depth);
- break;
-
- case kTagTypeInteger :
- DumpTagInteger(tag, depth);
- break;
-
- case kTagTypeData :
- DumpTagData(tag, depth);
- break;
-
- case kTagTypeDate :
- DumpTagDate(tag, depth);
- break;
-
- case kTagTypeFalse :
- case kTagTypeTrue :
- DumpTagBoolean(tag, depth);
- break;
-
- case kTagTypeArray :
- DumpTagArray(tag, depth);
- break;
-
- default :
- break;
- }
-}
-
-
-static void DumpTagDict(TagPtr tag, long depth)
-{
- TagPtr tagList;
-
- if (tag->tag == 0) {
- DumpSpaces(depth);
- printf("<%s/>\n", kXMLTagDict);
- } else {
- DumpSpaces(depth);
- printf("<%s>\n", kXMLTagDict);
-
- tagList = tag->tag;
- while (tagList) {
- DumpTag(tagList, depth + 1);
- tagList = tagList->tagNext;
- }
-
- DumpSpaces(depth);
- printf("</%s>\n", kXMLTagDict);
- }
-}
-
-
-static void DumpTagKey(TagPtr tag, long depth)
-{
- DumpSpaces(depth);
- printf("<%s>%s</%s>\n", kXMLTagKey, tag->string, kXMLTagKey);
-
- DumpTag(tag->tag, depth);
-}
-
-
-static void DumpTagString(TagPtr tag, long depth)
-{
- DumpSpaces(depth);
- printf("<%s>%s</%s>\n", kXMLTagString, tag->string, kXMLTagString);
-}
-
-
-static void DumpTagInteger(TagPtr tag, long depth)
-{
- DumpSpaces(depth);
- printf("<%s>%x</%s>\n", kXMLTagInteger, tag->string, kXMLTagInteger);
-}
-
-
-static void DumpTagData(TagPtr tag, long depth)
-{
- DumpSpaces(depth);
- printf("<%s>%x</%s>\n", kXMLTagData, tag->string, kXMLTagData);
-}
-
-
-static void DumpTagDate(TagPtr tag, long depth)
-{
- DumpSpaces(depth);
- printf("<%s>%x</%s>\n", kXMLTagDate, tag->string, kXMLTagDate);
-}
-
-
-static void DumpTagBoolean(TagPtr tag, long depth)
-{
- DumpSpaces(depth);
- printf("<%s>\n", (tag->type == kTagTypeTrue) ? kXMLTagTrue : kXMLTagFalse);
-}
-
-
-static void DumpTagArray(TagPtr tag, long depth)
-{
- TagPtr tagList;
-
- if (tag->tag == 0) {
- DumpSpaces(depth);
- printf("<%s/>\n", kXMLTagArray);
- } else {
- DumpSpaces(depth);
- printf("<%s>\n", kXMLTagArray);
-
- tagList = tag->tag;
- while (tagList) {
- DumpTag(tagList, depth + 1);
- tagList = tagList->tagNext;
- }
-
- DumpSpaces(depth);
- printf("</%s>\n", kXMLTagArray);
- }
-}
-
-
-static void DumpSpaces(long depth)
-{
- long cnt;
-
- for (cnt = 0; cnt < (depth * 4); cnt++) putchar(' ');
-}
-#endif
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
long ThinFatBinaryMachO(void **binary, unsigned long *length)
{
- unsigned long nfat, swapped, size;
+ unsigned long nfat, swapped, size = 0;
struct fat_header *fhp = (struct fat_header *)*binary;
struct fat_arch *fap =
(struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
{
struct mach_header *mH;
long ncmds, cmdBase, cmd, cmdsize, headerBase, headerAddr, headerSize;
- long cnt, ret;
+ long cnt, ret = 0;
gPPCAddress = (unsigned long)binary;
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* main.c - Main functions for BootX.
*
- * Copyright (c) 1998-2003 Apple Computer, Inc.
+ * Copyright (c) 1998-2004 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
#include <sl.h>
+#include "aes.h"
static void Start(void *unused1, void *unused2, ClientInterfacePtr ciPtr);
static void Main(ClientInterfacePtr ciPtr);
static long InitEverything(ClientInterfacePtr ciPtr);
-static long DecodeKernel(void);
+static long DecodeKernel(void *binary);
static long SetUpBootArgs(void);
static long CallKernel(void);
static void FailToBoot(long num);
static long GetOFVersion(void);
static long TestForKey(long key);
static long GetBootPaths(void);
+static long ReadBootPlist(char *devSpec);
const unsigned long StartTVector[2] = {(unsigned long)Start, 0};
char gHaveKernelCache = 0;
char gBootDevice[256];
char gBootFile[256];
+TagPtr gBootDict = NULL;
static char gBootKernelCacheFile[512];
static char gExtensionsSpec[4096];
static char gCacheNameAdler[64 + sizeof(gBootFile)];
long *gDeviceTreeMMTmp = 0;
-long gOFVersion;
+long gOFVersion = 0;
char *gKeyMap;
static unsigned long gOFSPRG2Save;
static unsigned long gOFSPRG3Save;
+//int gDebugCount = 0;
+
// Private Functions
static void Start(void *unused1, void *unused2, ClientInterfacePtr ciPtr)
}
+
static void Main(ClientInterfacePtr ciPtr)
{
long ret;
int trycache;
- long flags, cachetime, time;
+ long flags, cachetime, kerneltime, exttime = 0;
+ void *binary = (void *)kLoadAddr;
ret = InitEverything(ciPtr);
if (ret != 0) Exit();
-
+
+
// Get or infer the boot paths.
ret = GetBootPaths();
if (ret != 0) FailToBoot(1);
+#if kFailToBoot
DrawSplashScreen(0);
+#endif
while (ret == 0) {
trycache = (0 == (gBootMode & kBootModeSafe))
if (trycache && (gBootFileType == kBlockDeviceType)) do {
// if we haven't found the kernel yet, don't use the cache
- ret = GetFileInfo(NULL, gBootFile, &flags, &time);
+ ret = GetFileInfo(NULL, gBootFile, &flags, &kerneltime);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
trycache = 0;
break;
}
ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
- || (cachetime < time)) {
+ || (cachetime < kerneltime)) {
trycache = 0;
break;
}
- ret = GetFileInfo(gExtensionsSpec, "Extensions", &flags, &time);
+ ret = GetFileInfo(gExtensionsSpec, "Extensions", &flags, &exttime);
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
- && (cachetime < time)) {
+ && (cachetime < exttime)) {
+ trycache = 0;
+ break;
+ }
+ if (kerneltime > exttime)
+ exttime = kerneltime;
+ if (cachetime != (exttime + 1)) {
trycache = 0;
break;
}
if (trycache) {
ret = LoadFile(gBootKernelCacheFile);
if (ret != -1) {
- ret = DecodeKernel();
+ ret = DecodeKernel(binary);
if (ret != -1) break;
}
}
- ret = LoadFile(gBootFile);
- if (ret != -1)
- ret = DecodeKernel();
+ ret = LoadThinFatFile(gBootFile, &binary);
+ if (ret != -1) ret = DecodeKernel(binary);
if (ret != -1) break;
ret = GetBootPaths();
if (ret != 0) FailToBoot(4);
}
+#if kFailToBoot
DrawSplashScreen(1);
+#endif
ret = SetUpBootArgs();
if (ret != 0) FailToBoot(5);
FailToBoot(6);
}
+static uint32_t UnescapeData(const uint8_t * src,
+ uint32_t srcLen,
+ uint8_t * dst,
+ uint32_t dstMaxLen)
+{
+ uint32_t cnt, cnt2, dstLen = 0;
+ uint8_t byte;
+
+ for (cnt = 0; cnt < srcLen;) {
+ byte = src[cnt++];
+ if (byte == 0xFF) {
+ byte = src[cnt++];
+ cnt2 = byte & 0x7F;
+ byte = (byte & 0x80) ? 0xFF : 0x00;
+ } else
+ cnt2 = 1;
+ while (cnt2--) {
+ if (dstLen >= dstMaxLen)
+ return (-1);
+ dst[dstLen++] = byte;
+ }
+ }
+ return (dstLen);
+}
static long InitEverything(ClientInterfacePtr ciPtr)
{
// printf now works.
printf("\n\nMac OS X Loader\n");
- // Test for Safe Boot Mode.
- if (((gBootMode & kBootModeSecure) == 0) && TestForKey(kShiftKey)) {
+ // Test for Safe Boot Mode; Shift and not Delete.
+ if (((gBootMode & kBootModeSecure) == 0)
+ && TestForKey(kShiftKey) && !TestForKey(kDeleteKey)) {
gBootMode |= kBootModeSafe;
}
-
- // Claim memory for the FS Cache.
- if (Claim(kFSCacheAddr, kFSCacheSize, 0) == 0) {
- printf("Claim for fs cache failed.\n");
- return -1;
- }
-
- // Claim memory for malloc.
- if (Claim(kMallocAddr, kMallocSize, 0) == 0) {
- printf("Claim for malloc failed.\n");
- return -1;
- }
- malloc_init((char *)kMallocAddr, kMallocSize);
-
- // Claim memory for the Load Addr.
- mem_base = Claim(kLoadAddr, kLoadSize, 0);
- if (mem_base == 0) {
- printf("Claim for Load Area failed.\n");
- return -1;
- }
-
- // Claim the memory for the Image Addr
- if (gOFVersion >= kOFVersion3x) {
- mem_base = Claim(kImageAddr, kImageSize, 0);
- if (mem_base == 0) {
- printf("Claim for Image Area failed.\n");
+
+ {
+ // Claim memory for the FS Cache.
+ if (Claim(kFSCacheAddr, kFSCacheSize, 0) == 0) {
+ printf("Claim for fs cache failed.\n");
return -1;
}
- } else {
- // Claim the 1:1 mapped chunks first.
- mem_base = Claim(kImageAddr0, kImageSize0, 0);
- mem_base2 = Claim(kImageAddr2, kImageSize2, 0);
- if ((mem_base == 0) || (mem_base2 == 0)) {
- printf("Claim for Image Area failed.\n");
+
+ // Claim memory for malloc.
+ if (Claim(kMallocAddr, kMallocSize, 0) == 0) {
+ printf("Claim for malloc failed.\n");
return -1;
}
+ malloc_init((char *)kMallocAddr, kMallocSize);
- // Unmap the old xcoff stack.
- CallMethod(2, 0, gMMUIH, "unmap", 0x00380000, 0x00080000);
-
- // Grap the physical memory then the logical.
- CallMethod(3, 1, gMemoryIH, "claim",
- kImageAddr1Phys, kImageSize1, 0, &mem_base);
- CallMethod(3, 1, gMMUIH, "claim",
- kImageAddr1, kImageSize1, 0, &mem_base2);
- if ((mem_base == 0) || (mem_base2 == 0)) {
- printf("Claim for Image Area failed.\n");
+ // Claim memory for the Load Addr.
+ mem_base = Claim(kLoadAddr, kLoadSize, 0);
+ if (mem_base == 0) {
+ printf("Claim for Load Area failed.\n");
return -1;
}
- // Map them together.
- CallMethod(4, 0, gMMUIH, "map",
- kImageAddr1Phys, kImageAddr1, kImageSize1, 0);
- }
-
- bzero((char *)kImageAddr, kImageSize);
-
- // Allocate some space for the Vector Save area.
- gVectorSaveAddr = AllocateBootXMemory(kVectorSize);
- if (gVectorSaveAddr == 0) {
- printf("Allocation for the Vector Save Area failed.\n");
- return -1;
- }
-
- // Find all the displays and set them up.
- ret = InitDisplays();
- if (ret != 0) {
- printf("InitDisplays failed.\n");
- return -1;
- }
+ // Claim the memory for the Image Addr
+ if (gOFVersion >= kOFVersion3x) {
+ mem_base = Claim(kImageAddr, kImageSize, 0);
+ if (mem_base == 0) {
+ printf("Claim for Image Area failed.\n");
+ return -1;
+ }
+ } else {
+ // Claim the 1:1 mapped chunks first.
+ mem_base = Claim(kImageAddr0, kImageSize0, 0);
+ mem_base2 = Claim(kImageAddr2, kImageSize2, 0);
+ if ((mem_base == 0) || (mem_base2 == 0)) {
+ printf("Claim for Image Area failed.\n");
+ return -1;
+ }
+
+ // Unmap the old xcoff stack.
+ CallMethod(2, 0, gMMUIH, "unmap", 0x00380000, 0x00080000);
+
+ // Grab the physical memory then the logical.
+ CallMethod(3, 1, gMemoryIH, "claim",
+ kImageAddr1Phys, kImageSize1, 0, &mem_base);
+ CallMethod(3, 1, gMMUIH, "claim",
+ kImageAddr1, kImageSize1, 0, &mem_base2);
+ if ((mem_base == 0) || (mem_base2 == 0)) {
+ printf("Claim for Image Area failed.\n");
+ return -1;
+ }
+
+ // Map them together.
+ CallMethod(4, 0, gMMUIH, "map",
+ kImageAddr1Phys, kImageAddr1, kImageSize1, 0);
+ }
+
+ bzero((char *)kImageAddr, kImageSize);
+
+ // Allocate some space for the Vector Save area.
+ gVectorSaveAddr = AllocateBootXMemory(kVectorSize);
+ if (gVectorSaveAddr == 0) {
+ printf("Allocation for the Vector Save Area failed.\n");
+ return -1;
+ }
+ // Find all the displays and set them up.
+ ret = InitDisplays(1);
+ if (ret != 0) {
+ printf("InitDisplays failed.\n");
+ return -1;
+ }
+ }
return 0;
}
return ret;
}
-static long DecodeKernel(void)
+static long DecodeKernel(void *binary)
{
- void *binary = (void *)kLoadAddr;
long ret;
- compressed_kernel_header * kernel_header = (compressed_kernel_header *) kLoadAddr;
+ compressed_kernel_header *kernel_header = (compressed_kernel_header *)binary;
u_int32_t size;
if (kernel_header->signature == 'comp') {
return -1;
}
if (kernel_header->adler32 !=
- Alder32(binary, kernel_header->uncompressed_size)) {
+ Adler32(binary, kernel_header->uncompressed_size)) {
printf("adler mismatch\n");
return -1;
}
long graphicsBoot = 1;
long ret, cnt, size, dash;
long sKey, vKey, keyPos;
- char ofBootArgs[128], *ofArgs, tc, keyStr[8];
+ char ofBootArgs[240], *ofArgs, tc, keyStr[8];
unsigned char mem_regs[kMaxDRAMBanks*16];
unsigned long mem_banks, bank_shift;
// Create the command line.
if (gOFVersion < kOFVersion3x) {
ofBootArgs[0] = ' ';
- size = GetProp(gChosenPH, "machargs", ofBootArgs + 1, 126);
+ size = GetProp(gChosenPH, "machargs", ofBootArgs + 1, (sizeof(ofBootArgs) - 2));
if (size == -1) {
- size = GetProp(gOptionsPH, "boot-command", ofBootArgs, 127);
+ size = GetProp(gOptionsPH, "boot-command", ofBootArgs, (sizeof(ofBootArgs) - 1));
if (size == -1) ofBootArgs[0] = '\0';
else ofBootArgs[size] = '\0';
// Look for " bootr" but skip the number.
sprintf(gTempStr, "0 bootr%s", ofBootArgs);
SetProp(gOptionsPH, "boot-command", gTempStr, strlen(gTempStr));
} else {
- size = GetProp(gOptionsPH, "boot-args", ofBootArgs, 127);
+ size = GetProp(gOptionsPH, "boot-args", ofBootArgs, (sizeof(ofBootArgs) - 1));
if (size == -1) ofBootArgs[0] = '\0';
else ofBootArgs[size] = '\0';
}
bzero(args->PhysicalDRAM + mem_banks, (kMaxDRAMBanks - mem_banks) * sizeof(DRAMBank));
// Get the video info
- GetMainScreenPH(&args->Video);
+ GetMainScreenPH(&args->Video, 1);
args->Video.v_display = graphicsBoot;
// Add the DeviceTree to the memory-map.
// Call the Kernel's entry point
(*(void (*)())gKernelEntryPoint)(gBootArgsAddr, kMacOSXSignature);
-
+
// Restore OF's Exception Vectors
bcopy(gOFVectorSave, 0x0, 0x3000);
for (cnt = 0; cnt < kVectorSize; cnt += 0x20) {
static void FailToBoot(long num)
{
+ // useful for those holding down command-v ...
+ printf("FailToBoot: %d\n", num);
#if kFailToBoot
DrawFailedBootPicture();
while (1);
num = 0;
#else
- printf("FailToBoot: %d\n", num);
Enter(); // For debugging
#endif
}
tmpStr = versStr + 15;
} else if (!strncmp(versStr, "OpenFirmware ", 13)) {
tmpStr = versStr + 13;
- } else return -1;
+ } else return -1;
// Clasify by each instance as needed...
switch (*tmpStr) {
case kOptKey : keyNum = 229; break;
case kShiftKey : keyNum = 230; break;
case kControlKey : keyNum = 231; break;
+ case kDeleteKey : keyNum = 45; break;
default : keyNum = -1; break;
}
{
long ret, cnt, cnt2, cnt3, cnt4, size, partNum, bootplen, bsdplen;
unsigned long adler32;
- char *filePath, *buffer;
+ char *filePath, *buffer, uuidStr[64];
if (gBootSourceNumber == -1) {
- // Get the boot-device
+ // Get the boot device and derive its type
+ // (try chosen "bootpath", then boot-device in the options)
size = GetProp(gChosenPH, "bootpath", gBootDevice, 255);
gBootDevice[size] = '\0';
if (gBootDevice[0] == '\0') {
size = GetProp(gOptionsPH, "boot-device", gBootDevice, 255);
gBootDevice[size] = '\0';
}
- gBootDeviceType = GetDeviceType(gBootDevice);
+// hardcode to my Apple_Boot before my Apple_RAID
+// debug: override boot device to boot from disk even if OF used TFTP
+//printf("old gBootDevice: %s\n", gBootDevice);
+//strcpy(gBootDevice, "fw/node@d0010100007a9d/sbp-2@c000/@0:12"); // SmartDisk
+//strcpy(gBootDevice, "fw/node@d04b491d060252/sbp-2@c000/@0:9"); // mconcatI
+//strcpy(gBootDevice, "fw/node@d04b491d060252/sbp-2@c000/@0:11"); // mconcatI
+//strcpy(gBootDevice, "fw/node@d04b491d075f57/sbp-2@c000/@0:2"); // mconcatII
+//strcpy(gBootDevice, "fw/node@d04b491d075f57/sbp-2@c000/@0:4"); // mconcatII
+//strcpy(gBootDevice, "fw/node@50770e0000676f/sbp-2@4000/@0:3"); // m120
+//strcpy(gBootDevice, "fw/node@50770e0000725b/sbp-2@4000/@0:3"); // m120
+
+
+ // Look for Boot.plist-based booter stuff (like RAID :)
+ ret = ReadBootPlist(gBootDevice);
+ if (ret == 0) {
+ // success -> gBootDevice = "AppleRAID/#:0,\\\\:tbxi"
+ (void)LookForRAID(gBootDict); // could take gBootDevice?
+ }
- // Get the boot-file
+
+ // note RAID itself is of "block" type like members
+ gBootDeviceType = GetDeviceType(gBootDevice);
+ if(gBootDeviceType == -1) {
+ printf("Could not find boot device %s\n", gBootDevice);
+ return -1;
+ }
+
+
+ // Get the boot file (e.g. mach_kernel)
size = GetProp(gChosenPH, "bootargs", gBootFile, 256);
gBootFile[size] = '\0';
}
}
}
+// gBootSourceNumberMax = 2; // helpful to prevent lots of probing
if (gBootFileType == kNetworkDeviceType) {
SetProp(Peer(0), "net-boot", NULL, 0);
bzero(gCacheNameAdler + 64, sizeof(gBootFile));
strcpy(gCacheNameAdler + 64, gBootFile);
- adler32 = Alder32(gCacheNameAdler, sizeof(gCacheNameAdler));
+ adler32 = Adler32(gCacheNameAdler, sizeof(gCacheNameAdler));
strncpy(gBootKernelCacheFile, gBootDevice, cnt + 1);
sprintf(gBootKernelCacheFile + cnt + 1,
// Figure out the root dir.
ret = ConvertFileSpec(gBootFile, gExtensionsSpec, &filePath);
- if (ret == -1) return -1;
+ if (ret == -1) {
+ printf("Failed to determine root directory\n");
+ return -1;
+ }
strcat(gExtensionsSpec, ",");
strcpy(gExtensionsSpec + cnt, "System\\Library\\");
}
+ // technically could just do this once at the end
SetProp(gChosenPH, "rootpath", gBootFile, strlen(gBootFile) + 1);
+
+ if (GetFSUUID(gBootFile, uuidStr) == 0) {
+ printf("setting boot-uuid to: %s\n", uuidStr);
+ SetProp(gChosenPH, "boot-uuid", uuidStr, strlen(uuidStr) + 1);
+ }
gBootSourceNumber++;
return 0;
}
+#define BOOTPLIST_PATH "com.apple.Boot.plist"
+
+// ReadBootPlist could live elsewhere
+static long ReadBootPlist(char *devSpec)
+{
+ char plistSpec[256];
+ int len;
+
+ do {
+ // construct the Boot.plist spec
+ if (ConvertFileSpec(devSpec, plistSpec, NULL)) break;
+ strncat(plistSpec, ",\\\\", 255-strlen(plistSpec));
+ strncat(plistSpec, BOOTPLIST_PATH, 255-strlen(plistSpec));
+
+ // load the contents
+ if ((len = LoadFile(plistSpec)) < 0) break;
+ // we could try for the root as well as the blessed folder
+ *((char*)kLoadAddr + len) = '\0'; // terminate for parser safety
+
+ if (ParseXML((char*)kLoadAddr, &gBootDict) < 0 || !gBootDict) {
+ printf("couldn't parse %s\n", BOOTPLIST_PATH);
+ break;
+ }
+
+ return 0;
+ } while(0);
+
+ return -1;
+}
+
// Public Functions
long GetDeviceType(char *devSpec)
long size;
char deviceType[32];
+ if (isRAIDPath(devSpec))
+ return kBlockDeviceType;
+
ph = FindDevice(devSpec);
if (ph == -1) return -1;
return 0;
}
+#define BASE 65521L /* largest prime smaller than 65536 */
+#define NMAX 5000
+// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
+
+#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
+#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
+#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
+#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
+#define DO16(buf) DO8(buf,0); DO8(buf,8);
-unsigned long Alder32(unsigned char *buffer, long length)
+unsigned long Adler32(unsigned char *buf, long len)
{
- long cnt;
- unsigned long result, lowHalf, highHalf;
-
- lowHalf = 1;
- highHalf = 0;
-
- for (cnt = 0; cnt < length; cnt++) {
- if ((cnt % 5000) == 0) {
- lowHalf %= 65521L;
- highHalf %= 65521L;
- }
-
- lowHalf += buffer[cnt];
- highHalf += lowHalf;
- }
+ unsigned long s1 = 1; // adler & 0xffff;
+ unsigned long s2 = 0; // (adler >> 16) & 0xffff;
+ int k;
- lowHalf %= 65521L;
- highHalf %= 65521L;
-
- result = (highHalf << 16) | lowHalf;
-
- return result;
+ while (len > 0) {
+ k = len < NMAX ? len : NMAX;
+ len -= k;
+ while (k >= 16) {
+ DO16(buf);
+ buf += 16;
+ k -= 16;
+ }
+ if (k != 0) do {
+ s1 += *buf++;
+ s2 += s1;
+ } while (--k);
+ s1 %= BASE;
+ s2 %= BASE;
+ }
+ return (s2 << 16) | s1;
}
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
--- /dev/null
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * plist.c - plist parsing functions
+ *
+ * Copyright (c) 2000-2005 Apple Computer, Inc.
+ *
+ * DRI: Josh de Cesare
+ * code split out from drivers.c by Soren Spies, 2005
+ */
+
+#include <sl.h>
+
+#define kXMLTagPList "plist"
+#define kXMLTagDict "dict"
+#define kXMLTagKey "key"
+#define kXMLTagString "string"
+#define kXMLTagInteger "integer"
+#define kXMLTagData "data"
+#define kXMLTagDate "date"
+#define kXMLTagFalse "false/"
+#define kXMLTagTrue "true/"
+#define kXMLTagArray "array"
+// for back-references used by libkern serializer
+#define kXMLTagReference "reference"
+#define kXMLTagID "ID="
+#define kXMLTagIDREF "IDREF="
+
+static long ParseNextTag(char *buffer, TagPtr *tag);
+static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty);
+static long ParseTagKey(char *buffer, TagPtr *tag);
+static long ParseTagString(char *buffer, TagPtr *tag);
+static long ParseTagInteger(char *buffer, TagPtr *tag);
+static long ParseTagData(char *buffer, TagPtr *tag);
+static long ParseTagDate(char *buffer, TagPtr *tag);
+static long ParseTagBoolean(char *buffer, TagPtr *tag, long type);
+static long GetNextTag(char *buffer, char **tag, long *start, long *empty);
+static long FixDataMatchingTag(char *buffer, char *tag);
+static TagPtr NewTag(void);
+static char *NewSymbol(char *string);
+static void FreeSymbol(char *string);
+
+#if PLIST_DEBUG
+// for debugging parsing failures
+static int gTagsParsed;
+static char *gLastTag;
+#endif
+
+TagPtr GetProperty(TagPtr dict, char *key)
+{
+ TagPtr tagList, tag;
+
+ if (dict->type != kTagTypeDict) return 0;
+
+ tag = 0; // ?
+ tagList = dict->tag;
+ while (tagList) {
+ tag = tagList;
+ tagList = tag->tagNext;
+
+ if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue;
+
+ if (!strcmp(tag->string, key)) {
+ return tag->tag;
+ }
+ }
+
+ return 0;
+}
+
+// intended to look for two versions of the tag; now just for sizeof
+#define MATCHTAG(parsedTag, keyTag) \
+ (!strncmp(parsedTag, keyTag, sizeof(keyTag)-1))
+
+// a tag cache for iokit's super-plists (alas, to merge w/"Symbol" cache?)
+// we're not going to use the 0th element; it's used by the whole dict anyway
+static int lastid;
+static int numids = 0; // skipping 0th
+static TagPtr *idtags;
+
+#define INITIALIDS 10
+static long InitTagCache()
+{
+ long rval = -1;
+
+ do {
+ lastid = 0;
+ numids = INITIALIDS;
+ idtags = (TagPtr*)malloc(numids * sizeof(*idtags));
+ if (!idtags) break;
+ bzero(idtags, numids * sizeof(*idtags));
+
+ rval = 0;
+ } while(0);
+
+ return rval;
+}
+
+static void FreeTagCache()
+{
+ if (idtags)
+ free(idtags);
+ idtags = NULL;
+}
+
+// get the number from (e.g.): ID="3"
+static int ExtractID(char *tagName, int tagLen)
+{
+ char *idptr = tagName + tagLen;
+ int rval = 0;
+
+ while(*idptr != '>') {
+ idptr++;
+ if (MATCHTAG(idptr, kXMLTagID)) {
+ rval = strtol(idptr + sizeof(kXMLTagID)-1+1, 0, 0); // -NUL +"
+ break;
+ } else if (MATCHTAG(idptr, kXMLTagIDREF)) {
+ rval = strtol(idptr + sizeof(kXMLTagIDREF)-1+1, 0, 0); // -NUL +"
+ break;
+ }
+ // there can be multiple modifiers (integers have 'size' first)
+ while(*idptr != ' ' && *idptr != '>') idptr++;
+ }
+
+ return rval;
+}
+
+static TagPtr TagFromRef(char *tagName, int tagLen)
+{
+ int refidx = ExtractID(tagName, tagLen);
+ TagPtr rval = NULL;
+
+ if (refidx <= lastid)
+ rval = idtags[refidx];
+
+ return rval;
+}
+
+static long SaveTagRef(TagPtr tag, int tagid)
+{
+
+ // bumped any time we skip an unsupported tag
+ if (tagid != ++lastid) {
+ if (tagid > lastid) {
+ lastid = tagid;
+ }
+ else {
+ printf("invalid plist: tagid (%d) < lastid (%d)??\n", tagid, lastid);
+ return -1;
+ }
+ }
+
+ // upsize idtags if needed
+ if (numids <= lastid) {
+ while(numids <= lastid)
+ numids *= 2;
+ idtags = (TagPtr*)realloc(idtags, numids * sizeof(*idtags));
+ if (!idtags) return -1;
+ }
+
+ // and record for later
+ idtags[lastid] = tag;
+
+ return 0;
+}
+
+long ParseXML(char *buffer, TagPtr *dict)
+{
+ long length, pos;
+ TagPtr moduleDict;
+
+#if PLIST_DEBUG
+ gTagsParsed = 0;
+ gLastTag = NULL;
+#endif
+ if (InitTagCache()) return -1;
+ pos = 0;
+ while (1) {
+ moduleDict = (TagPtr)-1; // have to detect changes to by-ref parameter
+ length = ParseNextTag(buffer + pos, &moduleDict);
+ if (length == -1) break;
+ pos += length;
+
+ if (moduleDict == 0) continue;
+
+ // did we actually create anything?
+ if (moduleDict != (TagPtr)-1) {
+ if (moduleDict->type == kTagTypeDict) break;
+ if (moduleDict->type == kTagTypeArray) break;
+
+ FreeTag(moduleDict);
+ }
+ }
+
+ *dict = moduleDict;
+
+#if PLIST_DEBUG
+ if (length == -1)
+ printf("ParseXML gagged (-1) after %s (%d tags); buf+pos: %s\n",
+ gLastTag,gTagsParsed,buffer+pos);
+#endif
+
+ // for tidyness even though kext parsing resets all of malloc
+ FreeTagCache();
+
+ // return 0 for no error
+ return (length != -1) ? 0 : -1;
+}
+
+#define PARSESTASHINGTAG(tagBuf, keyTag, parseFunc) do { \
+ TagPtr extantTag = TagFromRef(tagBuf, sizeof(keyTag)-1); \
+ if (extantTag) { \
+ *tag = extantTag; \
+ length = 0; \
+ } else { \
+ int tagid = ExtractID(tagName, sizeof(keyTag)-1); \
+ length = parseFunc(buffer + pos, tag); \
+ if (tagid && length != -1) \
+ if (-1 == SaveTagRef(*tag, tagid)) \
+ return -1; \
+ } \
+ } while(0)
+
+static long ParseNextTag(char *buffer, TagPtr *tag)
+{
+ long length, pos, empty = 0;
+ char *tagName;
+ TagPtr refTag;
+
+ length = GetNextTag(buffer, &tagName, 0, &empty);
+ if (length == -1) return -1;
+#if PLIST_DEBUG
+ gLastTag = tagName;
+ gTagsParsed++;
+#endif
+
+ pos = length;
+ if (MATCHTAG(tagName, kXMLTagPList)) {
+ length = 0; // just a header; nothing to parse
+ // return-via-reference tag should be left alone
+ } else if (MATCHTAG(tagName, kXMLTagDict)) {
+ length = ParseTagList(buffer + pos, tag, kTagTypeDict, empty);
+ } else if (!strcmp(tagName, kXMLTagKey)) {
+ length = ParseTagKey(buffer + pos, tag);
+ } else if (MATCHTAG(tagName, kXMLTagReference) &&
+ (refTag = TagFromRef(tagName, sizeof(kXMLTagReference)-1))) {
+ *tag = refTag;
+ length = 0;
+ } else if (MATCHTAG(tagName, kXMLTagString)) {
+ PARSESTASHINGTAG(tagName, kXMLTagString, ParseTagString);
+ } else if (MATCHTAG(tagName, kXMLTagInteger)) {
+ PARSESTASHINGTAG(tagName, kXMLTagInteger, ParseTagInteger);
+ } else if (!strcmp(tagName, kXMLTagData)) {
+ length = ParseTagData(buffer + pos, tag);
+ } else if (!strcmp(tagName, kXMLTagDate)) {
+ length = ParseTagDate(buffer + pos, tag);
+ } else if (!strcmp(tagName, kXMLTagFalse)) {
+ length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
+ } else if (!strcmp(tagName, kXMLTagTrue)) {
+ length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
+ } else if (MATCHTAG(tagName, kXMLTagArray)) {
+ length = ParseTagList(buffer + pos, tag, kTagTypeArray, empty);
+ } else {
+ // it wasn't parsed so we consumed no additional characters
+ length = 0;
+ if (tagName[0] == '/') // was it an end tag (indicated w/*tag = 0)
+ *tag = 0;
+ else {
+//printf("ignored plist tag: %s (*tag: %x)\n", tagName, *tag);
+ *tag = (TagPtr)-1; // we're *not* returning a tag
+ }
+ }
+
+ if (length == -1) return -1;
+
+ return pos + length;
+}
+
+static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty)
+{
+ long length, pos;
+ TagPtr tagList, tmpTag = (TagPtr)-1;
+
+ tagList = 0;
+ pos = 0;
+
+ if (!empty) {
+ while (1) {
+ tmpTag = (TagPtr)-1;
+ length = ParseNextTag(buffer + pos, &tmpTag);
+ if (length == -1) break;
+ pos += length;
+
+ // detect end of list
+ if (tmpTag == 0) break;
+
+ // if we made a new tag, insert into list
+ if (tmpTag != (TagPtr)-1) {
+ tmpTag->tagNext = tagList;
+ tagList = tmpTag;
+ }
+ }
+
+ if (length == -1) {
+ FreeTag(tagList);
+ return -1;
+ }
+ }
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) {
+ FreeTag(tagList);
+ return -1;
+ }
+
+ tmpTag->type = type;
+ tmpTag->string = 0;
+ tmpTag->tag = tagList;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return pos;
+}
+
+
+static long ParseTagKey(char *buffer, TagPtr *tag)
+{
+ long length, length2;
+ char *string;
+ TagPtr tmpTag, subTag = (TagPtr)-1; // eliminate possible stale tag
+
+ length = FixDataMatchingTag(buffer, kXMLTagKey);
+ if (length == -1) return -1;
+
+ length2 = ParseNextTag(buffer + length, &subTag);
+ if (length2 == -1) return -1;
+
+ // XXXX revisit 4063982 if FreeTag becomes real
+ if(subTag == (TagPtr)-1)
+ subTag = NULL;
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) {
+ FreeTag(subTag);
+ return -1;
+ }
+
+ string = NewSymbol(buffer);
+ if (string == 0) {
+ FreeTag(subTag);
+ FreeTag(tmpTag);
+ return -1;
+ }
+
+ tmpTag->type = kTagTypeKey;
+ tmpTag->string = string;
+ tmpTag->tag = subTag;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return length + length2;
+}
+
+
+static long ParseTagString(char *buffer, TagPtr *tag)
+{
+ long length;
+ char *string;
+ TagPtr tmpTag;
+
+ length = FixDataMatchingTag(buffer, kXMLTagString);
+ if (length == -1) return -1;
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) return -1;
+
+ string = NewSymbol(buffer);
+ if (string == 0) {
+ FreeTag(tmpTag);
+ return -1;
+ }
+
+ tmpTag->type = kTagTypeString;
+ tmpTag->string = string;
+ tmpTag->tag = 0;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return length;
+}
+
+
+static long ParseTagInteger(char *buffer, TagPtr *tag)
+{
+ long length;
+ char *intString;
+ TagPtr tmpTag;
+
+ length = FixDataMatchingTag(buffer, kXMLTagInteger);
+ if (length == -1) return -1;
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) return -1;
+
+ intString = NewSymbol(buffer);
+ if (intString == 0) {
+ FreeTag(tmpTag);
+ return -1;
+ }
+
+ tmpTag->type = kTagTypeInteger;
+ tmpTag->string = intString;
+ tmpTag->tag = 0;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return length;
+}
+
+
+static long ParseTagData(char *buffer, TagPtr *tag)
+{
+ long length;
+ TagPtr tmpTag;
+
+ length = FixDataMatchingTag(buffer, kXMLTagData);
+ if (length == -1) return -1;
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) return -1;
+
+ tmpTag->type = kTagTypeData;
+ tmpTag->string = 0;
+ tmpTag->tag = 0;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return length;
+}
+
+
+static long ParseTagDate(char *buffer, TagPtr *tag)
+{
+ long length;
+ TagPtr tmpTag;
+
+ length = FixDataMatchingTag(buffer, kXMLTagDate);
+ if (length == -1) return -1;
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) return -1;
+
+ tmpTag->type = kTagTypeDate;
+ tmpTag->string = 0;
+ tmpTag->tag = 0;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return length;
+}
+
+
+static long ParseTagBoolean(char *buffer, TagPtr *tag, long type)
+{
+ TagPtr tmpTag;
+
+ tmpTag = NewTag();
+ if (tmpTag == 0) return -1;
+
+ tmpTag->type = type;
+ tmpTag->string = 0;
+ tmpTag->tag = 0;
+ tmpTag->tagNext = 0;
+
+ *tag = tmpTag;
+
+ return 0;
+}
+
+
+static long GetNextTag(char *buffer, char **tag, long *start, long *empty)
+{
+ long cnt, cnt2;
+
+ if (tag == 0) return -1;
+
+ // Find the start of the tag.
+ cnt = 0;
+ while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
+ if (buffer[cnt] == '\0') return -1;
+
+ // Find the end of the tag.
+ cnt2 = cnt + 1;
+ while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++;
+ if (buffer[cnt2] == '\0') return -1;
+ if (empty && cnt2 > 1)
+ *empty = buffer[cnt2-1] == '/';
+
+ // Fix the tag data.
+ *tag = buffer + cnt + 1;
+ buffer[cnt2] = '\0';
+ if (start) *start = cnt;
+
+ return cnt2 + 1;
+}
+
+
+static long FixDataMatchingTag(char *buffer, char *tag)
+{
+ long length, start, stop;
+ char *endTag;
+
+ start = 0;
+ while (1) {
+ length = GetNextTag(buffer + start, &endTag, &stop, NULL);
+ if (length == -1) return -1;
+
+ if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break;
+ start += length;
+ }
+
+ buffer[start + stop] = '\0';
+
+ return start + length;
+}
+
+
+#define kTagsPerBlock (0x1000)
+
+static TagPtr gTagsFree;
+
+static TagPtr NewTag(void)
+{
+ long cnt;
+ TagPtr tag;
+
+ if (gTagsFree == 0) {
+ tag = (TagPtr)AllocateBootXMemory(kTagsPerBlock * sizeof(Tag));
+ if (tag == 0) return 0;
+
+ // Initalize the new tags.
+ for (cnt = 0; cnt < kTagsPerBlock; cnt++) {
+ tag[cnt].type = kTagTypeNone;
+ tag[cnt].string = 0;
+ tag[cnt].tag = 0;
+ tag[cnt].tagNext = tag + cnt + 1;
+ }
+ tag[kTagsPerBlock - 1].tagNext = 0;
+
+ gTagsFree = tag;
+ }
+
+ tag = gTagsFree;
+ gTagsFree = tag->tagNext;
+
+ return tag;
+}
+
+
+// currently a no-op
+void FreeTag(TagPtr tag)
+{
+ return; // XXXX revisit callers, particularly ParseTagKey (4063982)
+ if (tag == 0) return;
+
+ if (tag->string) FreeSymbol(tag->string);
+
+ FreeTag(tag->tag);
+ FreeTag(tag->tagNext);
+
+ // Clear and free the tag.
+ tag->type = kTagTypeNone;
+ tag->string = 0;
+ tag->tag = 0;
+ tag->tagNext = gTagsFree;
+ gTagsFree = tag;
+}
+
+
+struct Symbol {
+ long refCount;
+ struct Symbol *next;
+ char string[1];
+};
+typedef struct Symbol Symbol, *SymbolPtr;
+
+static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol);
+
+static SymbolPtr gSymbolsHead;
+
+
+static char *NewSymbol(char *string)
+{
+ SymbolPtr symbol;
+
+ // Look for string in the list of symbols.
+ symbol = FindSymbol(string, 0);
+
+ // Add the new symbol.
+ if (symbol == 0) {
+ symbol = AllocateBootXMemory(sizeof(Symbol) + strlen(string));
+ if (symbol == 0) return 0;
+
+ // Set the symbol's data.
+ symbol->refCount = 0;
+ strcpy(symbol->string, string);
+
+ // Add the symbol to the list.
+ symbol->next = gSymbolsHead;
+ gSymbolsHead = symbol;
+ }
+
+ // Update the refCount and return the string.
+ symbol->refCount++;
+ return symbol->string;
+}
+
+
+// currently a no-op
+static void FreeSymbol(char *string)
+{
+#if 0
+ SymbolPtr symbol, prev;
+
+ // Look for string in the list of symbols.
+ symbol = FindSymbol(string, &prev);
+ if (symbol == 0) return;
+
+ // Update the refCount.
+ symbol->refCount--;
+
+ if (symbol->refCount != 0) return;
+
+ // Remove the symbol from the list.
+ if (prev != 0) prev->next = symbol->next;
+ else gSymbolsHead = symbol->next;
+
+ // Free the symbol's memory.
+ free(symbol);
+#endif
+}
+
+
+static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol)
+{
+ SymbolPtr symbol, prev;
+
+ symbol = gSymbolsHead;
+ prev = 0;
+
+ while (symbol != 0) {
+ if (!strcmp(symbol->string, string)) break;
+
+ prev = symbol;
+ symbol = symbol->next;
+ }
+
+ if ((symbol != 0) && (prevSymbol != 0)) *prevSymbol = prev;
+
+ return symbol;
+}
+
+#if PLIST_DEBUG
+static void DumpTagDict(TagPtr tag, long depth);
+static void DumpTagKey(TagPtr tag, long depth);
+static void DumpTagString(TagPtr tag, long depth);
+static void DumpTagInteger(TagPtr tag, long depth);
+static void DumpTagData(TagPtr tag, long depth);
+static void DumpTagDate(TagPtr tag, long depth);
+static void DumpTagBoolean(TagPtr tag, long depth);
+static void DumpTagArray(TagPtr tag, long depth);
+static void DumpSpaces(long depth);
+
+void DumpTag(TagPtr tag, long depth)
+{
+ if (tag == 0) return;
+
+ switch (tag->type) {
+ case kTagTypeDict :
+ DumpTagDict(tag, depth);
+ break;
+
+ case kTagTypeKey :
+ DumpTagKey(tag, depth);
+ break;
+
+ case kTagTypeString :
+ DumpTagString(tag, depth);
+ break;
+
+ case kTagTypeInteger :
+ DumpTagInteger(tag, depth);
+ break;
+
+ case kTagTypeData :
+ DumpTagData(tag, depth);
+ break;
+
+ case kTagTypeDate :
+ DumpTagDate(tag, depth);
+ break;
+
+ case kTagTypeFalse :
+ case kTagTypeTrue :
+ DumpTagBoolean(tag, depth);
+ break;
+
+ case kTagTypeArray :
+ DumpTagArray(tag, depth);
+ break;
+
+ default :
+ break;
+ }
+}
+
+
+static void DumpTagDict(TagPtr tag, long depth)
+{
+ TagPtr tagList;
+
+ if (tag->tag == 0) {
+ DumpSpaces(depth);
+ printf("<%s/>\n", kXMLTagDict);
+ } else {
+ DumpSpaces(depth);
+ printf("<%s>\n", kXMLTagDict);
+
+ tagList = tag->tag;
+ while (tagList) {
+ DumpTag(tagList, depth + 1);
+ tagList = tagList->tagNext;
+ }
+
+ DumpSpaces(depth);
+ printf("</%s>\n", kXMLTagDict);
+ }
+}
+
+
+static void DumpTagKey(TagPtr tag, long depth)
+{
+ DumpSpaces(depth);
+ printf("<%s>%s</%s>\n", kXMLTagKey, tag->string, kXMLTagKey);
+
+ DumpTag(tag->tag, depth);
+}
+
+
+static void DumpTagString(TagPtr tag, long depth)
+{
+ DumpSpaces(depth);
+ printf("<%s>%s</%s>\n", kXMLTagString, tag->string, kXMLTagString);
+}
+
+
+/* integers used to live as char*s but we need 64 bit ints */
+static void DumpTagInteger(TagPtr tag, long depth)
+{
+ DumpSpaces(depth);
+ printf("<%s>%s</%s>\n", kXMLTagInteger, tag->string, kXMLTagInteger);
+}
+
+
+static void DumpTagData(TagPtr tag, long depth)
+{
+ DumpSpaces(depth);
+ printf("<%s>%x</%s>\n", kXMLTagData, tag->string, kXMLTagData);
+}
+
+
+static void DumpTagDate(TagPtr tag, long depth)
+{
+ DumpSpaces(depth);
+ printf("<%s>%x</%s>\n", kXMLTagDate, tag->string, kXMLTagDate);
+}
+
+
+static void DumpTagBoolean(TagPtr tag, long depth)
+{
+ DumpSpaces(depth);
+ printf("<%s>\n", (tag->type == kTagTypeTrue) ? kXMLTagTrue : kXMLTagFalse);
+}
+
+
+static void DumpTagArray(TagPtr tag, long depth)
+{
+ TagPtr tagList;
+
+ if (tag->tag == 0) {
+ DumpSpaces(depth);
+ printf("<%s/>\n", kXMLTagArray);
+ } else {
+ DumpSpaces(depth);
+ printf("<%s>\n", kXMLTagArray);
+
+ tagList = tag->tag;
+ while (tagList) {
+ DumpTag(tagList, depth + 1);
+ tagList = tagList->tagNext;
+ }
+
+ DumpSpaces(depth);
+ printf("</%s>\n", kXMLTagArray);
+ }
+}
+
+
+static void DumpSpaces(long depth)
+{
+ long cnt;
+
+ for (cnt = 0; cnt < (depth * 4); cnt++) putchar(' ');
+}
+#endif
--- /dev/null
+
+/*
+ * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
+ *
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * raid.c - Main functions for BootX.
+ *
+ * Copyright (c) 1998-2005 Apple Computer, Inc.
+ *
+ * DRI: Josh de Cesare (BootX), Soren Spies (RAID support)
+ */
+
+
+#include <sl.h>
+#include <IOKit/IOKitKeys.h>
+
+typedef unsigned long long UInt64;
+#define KERNEL
+#include <IOKit/storage/RAID/AppleRAIDUserLib.h> // hooray
+//#include "/System/Library/Frameworks/IOKit.framework/Versions/A/PrivateHeaders/storage/RAID/AppleRAIDUserLib.h"
+
+/* things we could probably get from elsewhere */
+typedef enum RAIDType {
+ kRAIDTypeUseless = -1,
+ kRAIDTypeMirror,
+ kRAIDTypeStripe,
+ kRAIDTypeConcat,
+ // kRAIDTypeFive,
+} RAIDType;
+
+
+/* stolen from AppleRAIDMember.h */
+
+#define kAppleRAIDSignature "AppleRAIDHeader"
+#define kAppleRAIDHeaderSize 0x1000
+
+#define ARHEADER_OFFSET(s) ((UInt64)(s) / kAppleRAIDHeaderSize * kAppleRAIDHeaderSize - kAppleRAIDHeaderSize )
+
+struct AppleRAIDHeaderV2 {
+ char raidSignature[16];
+ char raidUUID[64];
+ char memberUUID[64];
+ UInt64 size;
+ char plist[0];
+};
+typedef struct AppleRAIDHeaderV2 AppleRAIDHeaderV2;
+
+
+/* our data structure */
+typedef struct RAIDMember {
+ // our providers
+ char path[256]; // sized like gBootDevice
+ UInt64 size; // becomes data-bearing portion once known
+ union { // switch on totMembers
+ struct RAIDMember **members; // dynamic array of pointers
+ // totMembers big; curMembers elements
+ CICell ih; // after we Open() path; NULL if useless
+ };
+
+
+ // --- everything below here used for members; not leaves ---
+ UInt64 curOffset; // absolute for Seek/RAIDRead()
+ int curMembers; // updated as we add members and do I/O
+
+ // derived from the header(s - struct and plist) stored in the providers
+ char setUUID[64]; // id used (w/seqNum) to find other members
+ RAIDType type; // mirror, stripe, concat
+ int seqNum; // member generation id
+ int totMembers; // total members in set
+ UInt64 chunkSize; // stripe width
+ UInt64 chunkCount; // number of chunks (unused?)
+} RAIDDevice; // *RAIDDevicePtr;
+
+/* for our paths */
+#define kAppleRAIDOFPathPrefix "AppleRAID/"
+
+/* -- static variables -- */
+static int gMaxMembers;
+static int gTotalMembers;
+static struct RAIDMember *gMembers; // an array of structs
+static RAIDDevicePtr gRAIDMaster = NULL;
+
+/* -- internal helper prototypes -- */
+static long FillInLeaf(TagPtr tagElem, RAIDDevicePtr member);
+static long AssimilateMember(RAIDDevicePtr member);
+static RAIDDevicePtr DetermineParent(TagPtr candidateDict, AppleRAIDHeaderV2*);
+static long AdoptChild(RAIDDevicePtr parent, RAIDDevicePtr child, TagPtr cDict);
+static long isComplete(RAIDDevicePtr member);
+static long NextPartition(char *loaderDev, char *memberDev); // XX share?
+// must call these with non-"-1" offsets
+static long ReadMirror(RAIDDevicePtr raid, long buf, long nbytes,UInt64 offset);
+static long ReadStripe(RAIDDevicePtr raid, long buf, long nbytes,UInt64 offset);
+static long ReadConcat(RAIDDevicePtr raid, long buf, long nbytes,UInt64 offset);
+
+/* -- accessors -- */
+static RAIDType GetRAIDType(TagPtr dict);
+static long long GetWholeNumber(TagPtr dict, char *key);
+
+/* -- cruft XX :) -- */
+static void problemCode(); // need to isolate crasher
+
+/* -- public helpers -- */
+int isRAIDPath(char *devSpec)
+{
+ int rval;
+
+ rval = (devSpec && !strncmp(devSpec, kAppleRAIDOFPathPrefix,
+ sizeof(kAppleRAIDOFPathPrefix)-1));
+ return rval;
+}
+
+/* only publicly a RAID device if it has members */
+/* we could have magic in our struct to be really sure :) */
+int isRAIDDevice(void *ih)
+{
+ int rval;
+
+ if(!ih) return 0;
+
+ RAIDDevicePtr p = (RAIDDevicePtr)ih;
+ // is the pointer within range
+ rval = (p >= &gMembers[0] && p < &gMembers[gTotalMembers] && p->curMembers);
+
+ return rval;
+}
+
+// --- open/close/read/!/seek ---
+
+// RAIDClose()
+void RAIDClose(RAIDDevicePtr raid)
+{
+ int i = raid->totMembers;
+ RAIDDevicePtr mem;
+
+ if(raid->curMembers) {
+ while(i-- > 0) {
+ mem = raid->members[i];
+ if(mem) {
+ RAIDClose(mem);
+ raid->members[i] = NULL;
+ if(raid->curMembers)
+ raid->curMembers--;
+ }
+ }
+ }
+ else if(raid->ih)
+ Close(raid->ih);
+}
+
+// RAIDOpen()
+RAIDDevicePtr RAIDOpen(char *devSpec)
+{
+ // steal RAID "devices"
+ int ridx;
+ char *p = devSpec, *endp;
+ RAIDDevicePtr rval = NULL;
+
+ if(!devSpec) return NULL;
+
+ // walk past kAppleRAIDOFPathPrefix
+ while (*p && *(p++) != '/');
+ if(*p) {
+ ridx = strtol(p, &endp, 10);
+ if(ridx < gTotalMembers)
+ rval = &gMembers[ridx];
+ }
+
+ return rval;
+}
+
+// RAIDSeek()
+long RAIDSeek(RAIDDevicePtr raid, long long position)
+{
+ if(!raid) return -1;
+ if(position < 0) return -1;
+
+ raid->curOffset = position;
+ return position;
+}
+
+// RAIDRead()
+long RAIDRead(RAIDDevicePtr raid, long buf, long nbytes, long long offset)
+{
+ long rval = -1;
+static long logs = 0;
+
+ // only RAIDRead() supports offset == -1 -> curOffset
+ if(offset == -1)
+ offset = raid->curOffset;
+
+ if(offset > raid->size) {
+ printf("RAIDRead() error: offset (%x%x) > raid->size (%x%x)\n",
+ offset, raid->size);
+ return -1;
+ }
+
+ if(raid->totMembers) {
+if(++logs < 15)
+printf("RAIDRead(%x (curMembers: %d), %x, %d, %x%x)\n",
+raid, raid->curMembers, buf, nbytes, offset);
+ switch(raid->type) {
+ case kRAIDTypeMirror:
+ rval = ReadMirror(raid, buf, nbytes, offset);
+ break;
+
+ case kRAIDTypeStripe:
+ rval = ReadStripe(raid, buf, nbytes, offset);
+ break;
+
+ case kRAIDTypeConcat:
+ rval = ReadConcat(raid, buf, nbytes, offset);
+ break;
+
+ // case kRAIDTypeFive:
+ default:
+ printf("unsupported RAID type id: %d\n", raid->type); // XX -> isComplete?
+ rval = -1;
+ }
+ }
+ else { // leaf member, read from the CI; we open on demand
+ do {
+ if(!raid->ih) {
+ // open underlying device
+ if(!(raid->ih = Open(raid->path))) break;
+ }
+ if(Seek(raid->ih, offset) < 0) break;
+//if(logs < 25)
+//printf("(RR): calling CI (%x from %x @ %x)\n", nbytes, raid->ih, (int)offset);
+ rval = Read(raid->ih, buf, nbytes);
+ } while(0);
+ }
+
+//if((raid->curMembers && logs < 15) || rval != nbytes)
+//printf("RAIDRead() returning %d (vs. %d)\n", rval, nbytes);
+
+ return rval;
+}
+
+// read-only, man
+// ! long WriteToRAID(RAIDDevicePtr ... )
+
+
+// simple for now (could spare out errors, etc)
+static long ReadMirror(RAIDDevicePtr raid, long buf, long nbytes, UInt64 offset)
+{
+ int ridx = 0;
+
+ // find a working member
+ while(ridx < raid->totMembers) {
+ if(raid->members[ridx])
+ break;
+ else
+ ridx++;
+ }
+
+ if(ridx == raid->totMembers)
+ return -1;
+
+ return RAIDRead(raid->members[ridx], buf, nbytes, offset);
+}
+
+static long ReadStripe(RAIDDevicePtr raid, long buf, long nbytes, UInt64 offset)
+{
+ UInt64 chunkSize = raid->chunkSize;
+ int nMems = raid->totMembers;
+ UInt64 subChunkStart = offset % chunkSize; // where in the final chunk?
+
+ UInt64 chunkIdx = offset / chunkSize; // which chunk of all of them?
+ int midx = chunkIdx % nMems; // on which member?
+ UInt64 mChunk = chunkIdx / nMems; // which chunk in the member?
+ UInt64 mChunkOffset = mChunk * chunkSize; // which offset in the member?
+
+ long thisTime, totalRead = 0;
+ long bytesRead, bytesLeft = nbytes;
+
+ long bufp = buf;
+
+ if(subChunkStart + nbytes > chunkSize)
+ thisTime = chunkSize - subChunkStart;
+ else
+ thisTime = nbytes; // nbytes is within the chunk
+
+ // tempting to do a partial read here ...
+
+ while(bytesLeft /* ALT: bufp < buf + nbytes */) {
+ bytesRead = RAIDRead(raid->members[midx], bufp, thisTime, mChunkOffset+subChunkStart);
+ if(bytesRead == -1) goto fail;
+ totalRead += bytesRead; // record what we read
+ bytesLeft -= bytesRead;
+ if(bytesRead != thisTime) break; // detect partial read and return
+
+ // set up for next read
+
+ // effect "chunkIdx++" by walking across the members
+ midx++; // next member
+ if(midx % nMems == 0) { // did we wrap?
+ midx = 0; // back to 0th member
+ mChunkOffset += chunkSize; // next chunk ("mChunk++")
+ }
+
+ // adjust other parameters
+ bufp += bytesRead; // bytesRead == thisTime
+ if(bytesLeft > chunkSize) // are we in the last chunk yet?
+ thisTime = chunkSize;
+ else
+ thisTime = bytesLeft;
+ subChunkStart = 0; // reset after first read (& beyond :P)
+ }
+
+ return totalRead;
+
+fail:
+ totalRead = -1;
+ return totalRead;
+}
+
+// XX okay to compare UInt64 values to -1?
+static long ReadConcat(RAIDDevicePtr raid, long buf, long nbytes, UInt64 offset)
+{
+//static UInt64 predoffset = -1;
+ int midx;
+ UInt64 nextStart = 0, curStart = 0;
+ long totalRead = 0, bytesRead;
+
+ // assume curMembers!=0 since RAIDRead() should be our only caller
+ for(midx = 0; midx < raid->curMembers; midx++) {
+ nextStart = curStart + raid->members[midx]->size;
+
+ // are we in range yet?
+ if(offset < nextStart) {
+ long thisTime;
+ UInt64 curOffset = offset - curStart;
+
+ // make sure we aren't reading out too far
+ if(offset + nbytes < nextStart)
+ thisTime = nbytes;
+ else
+ thisTime = nextStart - offset; // distance to the end
+
+ bytesRead = RAIDRead(raid->members[midx],buf,thisTime,curOffset);
+ if(bytesRead == -1) goto fail;
+ totalRead += bytesRead; // record what was read
+ if(bytesRead != thisTime) break; // detect partial read and return
+
+ // XX need to lay out a volume to test crossing boundary in one read
+ if(thisTime != nbytes) {
+printf("ReadConcat crossing a boundary in a single read\n");
+ offset = nextStart;
+ nbytes -= thisTime;
+ buf += thisTime;
+ continue; // take another spin around the loop
+ }
+ break; // exit from the enclosing loop
+ }
+ curStart = nextStart;
+ }
+
+ return totalRead;
+
+fail:
+printf("ReadConcat: %d for %x%x (ended %x%x..%x%x)\n",
+totalRead, offset, curStart, nextStart);
+ totalRead = -1;
+ return totalRead;
+}
+
+
+// --- seek out RAID members and build sets ---
+
+/*
+ How we find and build RAID sets (not our first stab :):
+ if(have Boot.plist)
+ 1) initialize with the OF paths in Boot.plist (Tiger)
+ else
+ *) there is no else until we find a way to divine partition sizes
+
+ while(unread potential members)
+ 3) read new members and populate structs
+ 4) assimilate them ("resistance is futile!")
+ * DetermineParent() looks through existing sets and creates on demand
+ * give the child to the parent for adoption
+ * if the parent becomes complete, proactively probe it as a member
+*/
+
+// process gBootDict looking for path/size pairs where we can sniff for RAID
+// allocate gMembers (3x the number of members)
+// make some stub members pointing to these paths
+long LookForRAID(TagPtr bootDict)
+{
+ TagPtr partSpec;
+int nsuccesses = 0;
+
+ do {
+ // count and allocate gMembers array
+ // assume no Apple_RAID could contribute > 2 members
+ if(bootDict->type == kTagTypeArray)
+ for(partSpec = bootDict->tag; partSpec; partSpec = partSpec->tagNext)
+ gMaxMembers += 3; // XX [re]think degraded mirrors trying to stack
+ else
+ gMaxMembers = 3;
+
+ gMembers = AllocateBootXMemory(gMaxMembers*sizeof(RAIDDevice));
+ if(!gMembers) break;
+ bzero(gMembers, gMaxMembers*sizeof(RAIDDevice));
+
+ // walk list of potential members, skipping on error
+ // FillInLeaf() on each
+ // AssimilateMember() on each
+ if(bootDict->type == kTagTypeArray) {
+ char masterMemberPath[256];
+
+ if(NextPartition(gBootDevice, masterMemberPath)) break;
+
+ for(partSpec = bootDict->tag; partSpec; partSpec = partSpec->tagNext) {
+ RAIDDevicePtr newLeaf = &gMembers[gTotalMembers++]; // burn entries
+ if(FillInLeaf(partSpec, newLeaf)) continue;
+
+ // is this the master (from whose Apple_Boot we loaded?
+ if(FindDevice(newLeaf->path) == FindDevice(masterMemberPath)) {
+printf("raid: found member affiliated with our boot device\n");
+ gRAIDMaster = newLeaf;
+ }
+
+ // assertion: leaves are always complete
+printf("raid: assimilating leaf %x\n", newLeaf);
+ if(AssimilateMember(newLeaf)) continue;
+nsuccesses++;
+ }
+ }
+ // even degraded mirror (one member) is in an array
+ else if(bootDict->type == kTagTypeDict) {
+ if(FillInLeaf(bootDict, &gMembers[0])) break;
+ if(AssimilateMember(&gMembers[0])) break;
+ gRAIDMaster = &gMembers[1];
+ }
+ else
+ break;
+
+printf("LookForRAID() made %d happy structs ", nsuccesses);
+printf("which resulted in %d total objects\n", gTotalMembers);
+
+ if(isComplete(gRAIDMaster)) {
+ int masteridx = gRAIDMaster - gMembers;
+ sprintf(gBootDevice, "%s%d:0,\\\\tbxi",kAppleRAIDOFPathPrefix,masteridx);
+printf("raid: set gBootDevice to %s\n", gBootDevice);
+ } else {
+ if(!gRAIDMaster)
+ printf("raid: boot-device didn't lead to a RAID device\n");
+ else
+ printf("raid: master RAID device %x missing members (has %d of %d)\n",
+ gRAIDMaster, gRAIDMaster->curMembers, gRAIDMaster->totMembers);
+ break;
+ }
+
+ return 0;
+ } while(0);
+
+ return -1;
+}
+
+// FillInLeaf() fills in a member's struct so the partition can later be probed
+// (just need the path and size)
+static long FillInLeaf(TagPtr partSpec, RAIDDevicePtr newMember)
+{
+ TagPtr prop;
+ long long size;
+ char *path;
+ long rval = -1;
+
+ do {
+ prop = GetProperty(partSpec, kIOBootDevicePathKey);
+ if(!prop || prop->type != kTagTypeString) break;
+ path = prop->string + sizeof(kIODeviceTreePlane); // +1(':') -1('\0')
+ if((size = GetWholeNumber(partSpec, kIOBootDeviceSizeKey)) < 0) break;
+
+//printf("got path and size (%x%x)\n", size);
+
+ // and copy in the values
+ if(!strcpy(newMember->path, path)) break;
+ newMember->size = size;
+
+ // gMembers got the big bzero() so all else is fine
+
+ rval = 0;
+ } while(0);
+
+ return rval;
+}
+
+// need to extract logical bits so we can find a parent
+static long AssimilateMember(RAIDDevicePtr candidate)
+{
+ TagPtr candDict = NULL;
+ void *bufp = (char*)kLoadAddr;
+ AppleRAIDHeaderV2 *cHeader = (AppleRAIDHeaderV2*)bufp;
+ RAIDDevicePtr parent = NULL;
+ long rval = -1;
+
+ do {
+ // suck headers from candidate
+ if(RAIDRead(candidate, (long)bufp, kAppleRAIDHeaderSize,
+ ARHEADER_OFFSET(candidate->size)) != kAppleRAIDHeaderSize) break;
+printf("raid: checking for magic: %s\n", bufp); // should point to magic
+
+ // validate the magic
+ if(strcmp(kAppleRAIDSignature, bufp)) {
+ printf("RAID magic not found in member %x\n", candidate);
+ break;
+ }
+//printf("raid set UUID: %s\n", cHeader->raidUUID);
+//printf("memberUUID: %s\n", cHeader->memberUUID);
+
+ // batten down the size to hide the header
+printf("raid: member size (%x%x) -> data size (%x%x)\n",candidate->size,
+cHeader->size);
+ candidate->size = cHeader->size; // -msoft-flaot required!
+
+ // and skip to and parse the embedded plist (to get the type, etc)
+ bufp += sizeof(AppleRAIDHeaderV2);
+//printf("bufp: %s\n", bufp);
+ if((ParseXML(bufp, &candDict) < 0) || !candDict) break;
+//printf("parsed RAID member dict (%x):\n", candDict);
+//DumpTag(candDict, 0);
+//printf("\n");
+
+ // DetermineParent will create a parent if it didn't already exist
+ if(!(parent = DetermineParent(candDict, cHeader))) break;
+printf("raid: %x being given to %x for adoption\n", candidate, parent);
+ if(AdoptChild(parent, candidate, candDict)) break;
+
+printf("raid: checking if set is ready to be probed...\n");
+ if(isComplete(parent))
+ (void)AssimilateMember(parent); // we might be done ...
+
+ rval = 0;
+ } while(0);
+
+ return rval;
+}
+
+static long AdoptChild(RAIDDevicePtr parent, RAIDDevicePtr child, TagPtr cDict)
+{
+ int candIdx, childSeq;
+ long rval = -1;
+
+ do {
+ if((childSeq = GetWholeNumber(cDict, kAppleRAIDSequenceNumberKey)) < 0)
+ break;
+
+ // check for "one"ness early (the child might be otherwise unwanted)
+ if(child == gRAIDMaster) {
+printf("raid: SUCCESSION %x was master; now to parent %x\n", child, parent);
+ gRAIDMaster = parent;
+ }
+
+ // do per-type actions (e.g. adjust size, cast out degraded mirrors, etc)
+ switch(parent->type) {
+ case kRAIDTypeMirror:
+ // only want the most up to date n-way twins (n=1..k)
+ if(childSeq < parent->seqNum) {
+printf("child seq # (%d) < parent's (%d) skip\n",childSeq,parent->seqNum);
+ return 0;
+ }
+ if(childSeq > parent->seqNum) {
+ int midx;
+ // more recent; take the new seqNum and cast out old members
+printf("child seq (%d) > parent's (%d) update\n",childSeq,parent->seqNum);
+ parent->seqNum = childSeq;
+ for(midx = 0; midx < parent->totMembers; midx++)
+ parent->members[midx] = NULL;
+ parent->curMembers = 0;
+ }
+ parent->size = child->size;
+
+ break;
+
+ case kRAIDTypeStripe:
+printf("st parent->size(%x%x) += child->size(%x%x)\n",parent->size,child->size);
+ parent->size += child->size;
+ /* could validate that sizes/#totMembers match */
+
+ break;
+
+ // yes, concat and stripe are the same for now
+ case kRAIDTypeConcat:
+ parent->size += child->size;
+
+ break;
+
+ case kRAIDTypeUseless: return -1; // yuck
+ }
+
+ // get the index of this member in the set
+ if((candIdx = GetWholeNumber(cDict, kAppleRAIDMemberIndexKey)) == -1) break;
+
+ // just in case we find the same member twice?
+ // invariant: curMembers == PopCount(members)
+ if(!parent->members[candIdx])
+ parent->curMembers++;
+ else
+printf("raid: members[%d] non-NULL: %x\n", candIdx, parent->members[candIdx]);
+
+printf("raid: assigning %x to parent->members[%d]\n", child, candIdx);
+ parent->members[candIdx] = child;
+
+ rval = 0;
+ } while(0);
+
+ return rval;
+}
+
+// aka "MakeNewParent()" if parent doesn't exist
+static RAIDDevicePtr DetermineParent(TagPtr cDict, AppleRAIDHeaderV2 *cHeader)
+{
+ int ridx;
+ RAIDDevicePtr rval = NULL;
+ int seqNum = GetWholeNumber(cDict, kAppleRAIDSequenceNumberKey);
+ int candIdx = GetWholeNumber(cDict, kAppleRAIDMemberIndexKey);
+
+ if(seqNum == -1 || candIdx == -1) return rval;
+
+ // search all non-leaf parents for a potential match
+ for(ridx = 0; ridx < gTotalMembers; ridx++) {
+ RAIDDevicePtr potential = &gMembers[ridx];
+ if(!potential->totMembers) continue; // not interested in children
+ if(potential->totMembers <= candIdx) continue; // no slot for child
+ if(potential->type != kRAIDTypeMirror) // mirrors will consider any child
+ if(potential->seqNum != seqNum) continue; // wrong generation
+
+ // XX could check for UUID in members-UUID array
+
+ // if the IDs match, hooray
+ if(!strcmp(cHeader->raidUUID, potential->setUUID)) {
+printf("raid: matched a child to a parent in %s\n", cHeader->raidUUID);
+ rval = potential;
+ break;
+ }
+ }
+
+
+ // If we didn't find a parent, make one
+ if(ridx == gTotalMembers)
+ // get values, minimally validate, and populate new parent
+ do {
+ RAIDDevicePtr parent = &gMembers[gTotalMembers++];
+ int totMembers = 0;
+ RAIDType type;
+ TagPtr prop;
+ UInt64 chunkSize = 0;
+ UInt64 chunkCount = 0;
+
+printf("raid: making new parent %x\n", parent);
+ // count up totMembers
+ prop = GetProperty(cDict, kAppleRAIDMembersKey);
+ if(!prop || prop->type != kTagTypeArray) break;
+//printf("cDict->raidMembers:\n");
+//DumpTag(prop, 0);
+//printf("\n");
+
+ // count elements of the array
+ prop = prop->tag;
+ while(prop) {
+ totMembers++;
+ prop = prop->tagNext;
+ }
+printf("raid: parent->totMembers: %d\n", totMembers);
+ if(totMembers <= candIdx) {
+printf("raid: candidate claims index %d in a %d-member set; ignoring\n",
+candIdx, totMembers);
+ break;
+ }
+
+ // grab type, chunk info from child dict (sequence # above)
+ type = GetRAIDType(cDict);
+ if(type == kRAIDTypeUseless) break;
+ if(type == kRAIDTypeStripe) {
+ chunkSize = GetWholeNumber(cDict, kAppleRAIDChunkSizeKey);
+ if(chunkSize == -1) break;
+ chunkCount = GetWholeNumber(cDict, kAppleRAIDChunkCountKey);
+ if(chunkCount == -1) break;
+ }
+
+ // and set up the parent structure's values
+ parent->size = 0; // let AssimilateMember increment the size
+
+ parent->members = AllocateBootXMemory(totMembers*sizeof(RAIDDevicePtr));
+ if(!parent->members) break;
+ bzero(parent->members, totMembers*sizeof(RAIDDevicePtr));
+
+ // curMembers, curOffset == 0 from initial bzero()
+
+ if(!strcpy(parent->setUUID, cHeader->raidUUID)) break;
+ parent->type = type;
+ parent->seqNum = seqNum;
+ parent->totMembers = totMembers;
+ if(type == kRAIDTypeStripe) {
+ parent->chunkSize = chunkSize;
+ parent->chunkCount = chunkCount;
+//printf("stripe: size * count %x%x vs. size %x%x\n", chunkSize * chunkCount, cHeader->size);
+ }
+
+ rval = parent;
+ } while(0);
+
+ return rval;
+}
+
+static long NextPartition(char *loaderDev, char *memberDev)
+{
+ int cnt, cnt2, partNum;
+ // stolen from main.c
+
+ // Find the first ':'.
+ cnt = 0;
+ while ((loaderDev[cnt] != '\0') && (loaderDev[cnt] != ':')) cnt++;
+ if (loaderDev[cnt] == '\0') return -1;
+
+ // Find the comma after the ':'.
+ cnt2 = cnt + 1;
+ while ((loaderDev[cnt2] != '\0') && (loaderDev[cnt] != ',')) cnt2++;
+
+ // Get just the partition number
+ strncpy(memberDev, loaderDev + cnt + 1, cnt2 - cnt - 1);
+ partNum = strtol(memberDev, 0, 10);
+ if (partNum == 0) partNum = strtol(gBootFile, 0, 16);
+
+ // looking for the Apple_RAID following the Apple_Boot
+ partNum++;
+
+ // Construct the boot-file
+ strncpy(memberDev, loaderDev, cnt + 1);
+ sprintf(memberDev + cnt + 1, "%d", partNum);
+
+ return 0;
+}
+
+static long isComplete(RAIDDevicePtr member)
+{
+ int rval = 0;
+
+ do {
+ if(!member || !member->curMembers) break;
+
+ switch(member->type) {
+ case kRAIDTypeMirror:
+ rval = (member->curMembers > 0);
+ break;
+
+ case kRAIDTypeStripe:
+ case kRAIDTypeConcat:
+ rval = (member->curMembers == member->totMembers);
+
+ default:
+ break;
+ }
+ } while(0);
+
+printf("raid: isComplete on %x (type %d, #mems %d): %d\n",
+member, member->type, member->curMembers, rval);
+ return rval;
+}
+
+
+// --- dictionary accessors ---
+static RAIDType GetRAIDType(TagPtr dict)
+{
+ RAIDType type = kRAIDTypeUseless;
+ TagPtr prop;
+ char *typeString;
+
+ do {
+ prop = GetProperty(dict, kAppleRAIDLevelNameKey);
+ if(!prop || prop->type != kTagTypeString) break;
+ typeString = prop->string;
+ switch(typeString[0]) {
+ case 'M': type = kRAIDTypeMirror; break;
+ case 'S': type = kRAIDTypeStripe; break;
+ case 'C': type = kRAIDTypeConcat; break;
+ default:
+printf("raid: didn't like level: %s\n", typeString);
+ type = kRAIDTypeUseless;
+ }
+ } while(0);
+
+ return type;
+}
+
+// "whole numbers are the counting numbers plus zero" - math team coach
+// -1 indicates an error
+static long long GetWholeNumber(TagPtr dict, char *key)
+{
+ long long num = -1;
+ char *endp;
+ TagPtr prop;
+
+ do {
+ prop = GetProperty(dict, key);
+ if(!prop || prop->type != kTagTypeInteger) break;
+ num = strtouq(prop->string, &endp, 0); // as long as not > #mems :)
+ if(*endp != '\0') {
+ num = -1;
+ }
+ } while(0);
+
+ return num;
+}
+
+
+// -- cruft --
+static void problemCode()
+{
+ RAIDDevice rmem, *tmem = &rmem;
+ AppleRAIDHeaderV2 rheader, *theader = &rheader;
+ void *fp = &problemCode;
+
+printf("\n ... calling probleCode() ...\n");
+ fp += 1;
+printf("populating a size member\n");
+ theader->size = 123456789;
+//printf("trying to copy tmem->size = theader->size");
+ tmem->size = theader->size;
+printf("dumping size: %x,%x\n", (int)(tmem->size>>32), (int)tmem);
+}
--- /dev/null
+Package: bootx
+Maintainer: Darwin Developers <darwin-development@public.lists.apple.com>
+Vendor: Apple Computer, Inc.
+Build-Depends: build-base
+Description: Darwin booter.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
*
* @APPLE_LICENSE_HEADER_START@
*
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
+ * The contents of this file constitute Original Code as defined in and
+ * are subject to the Apple Public Source License Version 1.1 (the
+ * "License"). You may not use this file except in compliance with the
+ * License. Please obtain a copy of the License at
+ * http://www.apple.com/publicsource and read it before using this file.
*
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
- *
- * The Original Code and all software distributed under the License are
- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * This Original Code and all software distributed under the License are
+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- * Please see the License for the specific language governing rights and
- * limitations under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/