libcaes-20240413/ 0000755 0001750 0001750 00000000000 14606477654 014236 5 ustar 00lordyesta lordyesta libcaes-20240413/COPYING 0000644 0001750 0001750 00000104515 14606473411 015262 0 ustar 00lordyesta lordyesta GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
libcaes-20240413/install-sh 0000755 0001750 0001750 00000035776 14606477627 016264 0 ustar 00lordyesta lordyesta #!/bin/sh
# install - install a program, script, or datafile
scriptversion=2020-11-14.01; # UTC
# This originates from X11R5 (mit/util/scripts/install.sh), which was
# later released in X11R6 (xc/config/util/install.sh) with the
# following copyright and license.
#
# Copyright (C) 1994 X Consortium
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of the X Consortium shall not
# be used in advertising or otherwise to promote the sale, use or other deal-
# ings in this Software without prior written authorization from the X Consor-
# tium.
#
#
# FSF changes to this file are in the public domain.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# 'make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch.
tab=' '
nl='
'
IFS=" $tab$nl"
# Set DOITPROG to "echo" to test this script.
doit=${DOITPROG-}
doit_exec=${doit:-exec}
# Put in absolute file names if you don't have them in your path;
# or use environment vars.
chgrpprog=${CHGRPPROG-chgrp}
chmodprog=${CHMODPROG-chmod}
chownprog=${CHOWNPROG-chown}
cmpprog=${CMPPROG-cmp}
cpprog=${CPPROG-cp}
mkdirprog=${MKDIRPROG-mkdir}
mvprog=${MVPROG-mv}
rmprog=${RMPROG-rm}
stripprog=${STRIPPROG-strip}
posix_mkdir=
# Desired mode of installed file.
mode=0755
# Create dirs (including intermediate dirs) using mode 755.
# This is like GNU 'install' as of coreutils 8.32 (2020).
mkdir_umask=22
backupsuffix=
chgrpcmd=
chmodcmd=$chmodprog
chowncmd=
mvcmd=$mvprog
rmcmd="$rmprog -f"
stripcmd=
src=
dst=
dir_arg=
dst_arg=
copy_on_change=false
is_target_a_directory=possibly
usage="\
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
or: $0 [OPTION]... SRCFILES... DIRECTORY
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
or: $0 [OPTION]... -d DIRECTORIES...
In the 1st form, copy SRCFILE to DSTFILE.
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
In the 4th, create DIRECTORIES.
Options:
--help display this help and exit.
--version display version info and exit.
-c (ignored)
-C install only if different (preserve data modification time)
-d create directories instead of installing files.
-g GROUP $chgrpprog installed files to GROUP.
-m MODE $chmodprog installed files to MODE.
-o USER $chownprog installed files to USER.
-p pass -p to $cpprog.
-s $stripprog installed files.
-S SUFFIX attempt to back up existing files, with suffix SUFFIX.
-t DIRECTORY install into DIRECTORY.
-T report an error if DSTFILE is a directory.
Environment variables override the default commands:
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
RMPROG STRIPPROG
By default, rm is invoked with -f; when overridden with RMPROG,
it's up to you to specify -f if you want it.
If -S is not specified, no backups are attempted.
Email bug reports to bug-automake@gnu.org.
Automake home page: https://www.gnu.org/software/automake/
"
while test $# -ne 0; do
case $1 in
-c) ;;
-C) copy_on_change=true;;
-d) dir_arg=true;;
-g) chgrpcmd="$chgrpprog $2"
shift;;
--help) echo "$usage"; exit $?;;
-m) mode=$2
case $mode in
*' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
echo "$0: invalid mode: $mode" >&2
exit 1;;
esac
shift;;
-o) chowncmd="$chownprog $2"
shift;;
-p) cpprog="$cpprog -p";;
-s) stripcmd=$stripprog;;
-S) backupsuffix="$2"
shift;;
-t)
is_target_a_directory=always
dst_arg=$2
# Protect names problematic for 'test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
shift;;
-T) is_target_a_directory=never;;
--version) echo "$0 $scriptversion"; exit $?;;
--) shift
break;;
-*) echo "$0: invalid option: $1" >&2
exit 1;;
*) break;;
esac
shift
done
# We allow the use of options -d and -T together, by making -d
# take the precedence; this is for compatibility with GNU install.
if test -n "$dir_arg"; then
if test -n "$dst_arg"; then
echo "$0: target directory not allowed when installing a directory." >&2
exit 1
fi
fi
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
# When -d is used, all remaining arguments are directories to create.
# When -t is used, the destination is already specified.
# Otherwise, the last argument is the destination. Remove it from $@.
for arg
do
if test -n "$dst_arg"; then
# $@ is not empty: it contains at least $arg.
set fnord "$@" "$dst_arg"
shift # fnord
fi
shift # arg
dst_arg=$arg
# Protect names problematic for 'test' and other utilities.
case $dst_arg in
-* | [=\(\)!]) dst_arg=./$dst_arg;;
esac
done
fi
if test $# -eq 0; then
if test -z "$dir_arg"; then
echo "$0: no input file specified." >&2
exit 1
fi
# It's OK to call 'install-sh -d' without argument.
# This can happen when creating conditional directories.
exit 0
fi
if test -z "$dir_arg"; then
if test $# -gt 1 || test "$is_target_a_directory" = always; then
if test ! -d "$dst_arg"; then
echo "$0: $dst_arg: Is not a directory." >&2
exit 1
fi
fi
fi
if test -z "$dir_arg"; then
do_exit='(exit $ret); exit $ret'
trap "ret=129; $do_exit" 1
trap "ret=130; $do_exit" 2
trap "ret=141; $do_exit" 13
trap "ret=143; $do_exit" 15
# Set umask so as not to create temps with too-generous modes.
# However, 'strip' requires both read and write access to temps.
case $mode in
# Optimize common cases.
*644) cp_umask=133;;
*755) cp_umask=22;;
*[0-7])
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw='% 200'
fi
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
*)
if test -z "$stripcmd"; then
u_plus_rw=
else
u_plus_rw=,u+rw
fi
cp_umask=$mode$u_plus_rw;;
esac
fi
for src
do
# Protect names problematic for 'test' and other utilities.
case $src in
-* | [=\(\)!]) src=./$src;;
esac
if test -n "$dir_arg"; then
dst=$src
dstdir=$dst
test -d "$dstdir"
dstdir_status=$?
# Don't chown directories that already exist.
if test $dstdir_status = 0; then
chowncmd=""
fi
else
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if test ! -f "$src" && test ! -d "$src"; then
echo "$0: $src does not exist." >&2
exit 1
fi
if test -z "$dst_arg"; then
echo "$0: no destination specified." >&2
exit 1
fi
dst=$dst_arg
# If destination is a directory, append the input filename.
if test -d "$dst"; then
if test "$is_target_a_directory" = never; then
echo "$0: $dst_arg: Is a directory" >&2
exit 1
fi
dstdir=$dst
dstbase=`basename "$src"`
case $dst in
*/) dst=$dst$dstbase;;
*) dst=$dst/$dstbase;;
esac
dstdir_status=0
else
dstdir=`dirname "$dst"`
test -d "$dstdir"
dstdir_status=$?
fi
fi
case $dstdir in
*/) dstdirslash=$dstdir;;
*) dstdirslash=$dstdir/;;
esac
obsolete_mkdir_used=false
if test $dstdir_status != 0; then
case $posix_mkdir in
'')
# With -d, create the new directory with the user-specified mode.
# Otherwise, rely on $mkdir_umask.
if test -n "$dir_arg"; then
mkdir_mode=-m$mode
else
mkdir_mode=
fi
posix_mkdir=false
# The $RANDOM variable is not portable (e.g., dash). Use it
# here however when possible just to lower collision chance.
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
trap '
ret=$?
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
exit $ret
' 0
# Because "mkdir -p" follows existing symlinks and we likely work
# directly in world-writeable /tmp, make sure that the '$tmpdir'
# directory is successfully created first before we actually test
# 'mkdir -p'.
if (umask $mkdir_umask &&
$mkdirprog $mkdir_mode "$tmpdir" &&
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
then
if test -z "$dir_arg" || {
# Check for POSIX incompatibilities with -m.
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
# other-writable bit of parent directory when it shouldn't.
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
test_tmpdir="$tmpdir/a"
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
case $ls_ld_tmpdir in
d????-?r-*) different_mode=700;;
d????-?--*) different_mode=755;;
*) false;;
esac &&
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
}
}
then posix_mkdir=:
fi
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
else
# Remove any dirs left behind by ancient mkdir implementations.
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
fi
trap '' 0;;
esac
if
$posix_mkdir && (
umask $mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
)
then :
else
# mkdir does not conform to POSIX,
# or it failed possibly due to a race condition. Create the
# directory the slow way, step by step, checking for races as we go.
case $dstdir in
/*) prefix='/';;
[-=\(\)!]*) prefix='./';;
*) prefix='';;
esac
oIFS=$IFS
IFS=/
set -f
set fnord $dstdir
shift
set +f
IFS=$oIFS
prefixes=
for d
do
test X"$d" = X && continue
prefix=$prefix$d
if test -d "$prefix"; then
prefixes=
else
if $posix_mkdir; then
(umask $mkdir_umask &&
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
# Don't fail if two instances are running concurrently.
test -d "$prefix" || exit 1
else
case $prefix in
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
*) qprefix=$prefix;;
esac
prefixes="$prefixes '$qprefix'"
fi
fi
prefix=$prefix/
done
if test -n "$prefixes"; then
# Don't fail if two instances are running concurrently.
(umask $mkdir_umask &&
eval "\$doit_exec \$mkdirprog $prefixes") ||
test -d "$dstdir" || exit 1
obsolete_mkdir_used=true
fi
fi
fi
if test -n "$dir_arg"; then
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
else
# Make a couple of temp file names in the proper directory.
dsttmp=${dstdirslash}_inst.$$_
rmtmp=${dstdirslash}_rm.$$_
# Trap to clean up those temp files at exit.
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
# Copy the file name to the temp name.
(umask $cp_umask &&
{ test -z "$stripcmd" || {
# Create $dsttmp read-write so that cp doesn't create it read-only,
# which would cause strip to fail.
if test -z "$doit"; then
: >"$dsttmp" # No need to fork-exec 'touch'.
else
$doit touch "$dsttmp"
fi
}
} &&
$doit_exec $cpprog "$src" "$dsttmp") &&
# and set any options; do chmod last to preserve setuid bits.
#
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $cpprog $src $dsttmp" command.
#
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
# If -C, don't bother to copy if it wouldn't change the file.
if $copy_on_change &&
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
set -f &&
set X $old && old=:$2:$4:$5:$6 &&
set X $new && new=:$2:$4:$5:$6 &&
set +f &&
test "$old" = "$new" &&
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
then
rm -f "$dsttmp"
else
# If $backupsuffix is set, and the file being installed
# already exists, attempt a backup. Don't worry if it fails,
# e.g., if mv doesn't support -f.
if test -n "$backupsuffix" && test -f "$dst"; then
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
fi
# Rename the file to the real destination.
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
# The rename failed, perhaps because mv can't rename something else
# to itself, or perhaps because mv is so ancient that it does not
# support -f.
{
# Now remove or move aside any old file at destination location.
# We try this two ways since rm can't unlink itself on some
# systems and the destination file might be busy for other
# reasons. In this case, the final cleanup might fail but the new
# file should still install successfully.
{
test ! -f "$dst" ||
$doit $rmcmd "$dst" 2>/dev/null ||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
} ||
{ echo "$0: cannot unlink or rename $dst" >&2
(exit 1); exit 1
}
} &&
# Now rename the file to the real destination.
$doit $mvcmd "$dsttmp" "$dst"
}
fi || exit 1
trap '' 0
fi
done
# Local variables:
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC0"
# time-stamp-end: "; # UTC"
# End:
libcaes-20240413/NEWS 0000644 0001750 0001750 00000000000 14606473411 014706 0 ustar 00lordyesta lordyesta libcaes-20240413/depcomp 0000755 0001750 0001750 00000056020 14606477627 015616 0 ustar 00lordyesta lordyesta #! /bin/sh
# depcomp - compile a program generating dependencies as side-effects
scriptversion=2018-03-07.03; # UTC
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# Originally written by Alexandre Oliva .
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
Run PROGRAMS ARGS to compile a file, generating dependencies
as side-effects.
Environment variables:
depmode Dependency tracking mode.
source Source file read by 'PROGRAMS ARGS'.
object Object file output by 'PROGRAMS ARGS'.
DEPDIR directory where to store dependencies.
depfile Dependency file to output.
tmpdepfile Temporary file to use when outputting dependencies.
libtool Whether libtool is used (yes/no).
Report bugs to .
EOF
exit $?
;;
-v | --v*)
echo "depcomp $scriptversion"
exit $?
;;
esac
# Get the directory component of the given path, and save it in the
# global variables '$dir'. Note that this directory component will
# be either empty or ending with a '/' character. This is deliberate.
set_dir_from ()
{
case $1 in
*/*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
*) dir=;;
esac
}
# Get the suffix-stripped basename of the given path, and save it the
# global variable '$base'.
set_base_from ()
{
base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
}
# If no dependency file was actually created by the compiler invocation,
# we still have to create a dummy depfile, to avoid errors with the
# Makefile "include basename.Plo" scheme.
make_dummy_depfile ()
{
echo "#dummy" > "$depfile"
}
# Factor out some common post-processing of the generated depfile.
# Requires the auxiliary global variable '$tmpdepfile' to be set.
aix_post_process_depfile ()
{
# If the compiler actually managed to produce a dependency file,
# post-process it.
if test -f "$tmpdepfile"; then
# Each line is of the form 'foo.o: dependency.h'.
# Do two passes, one to just change these to
# $object: dependency.h
# and one to simply output
# dependency.h:
# which is needed to avoid the deleted-header problem.
{ sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
} > "$depfile"
rm -f "$tmpdepfile"
else
make_dummy_depfile
fi
}
# A tabulation character.
tab=' '
# A newline character.
nl='
'
# Character ranges might be problematic outside the C locale.
# These definitions help.
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
lower=abcdefghijklmnopqrstuvwxyz
digits=0123456789
alpha=${upper}${lower}
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
echo "depcomp: Variables source, object and depmode must be set" 1>&2
exit 1
fi
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
depfile=${depfile-`echo "$object" |
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
rm -f "$tmpdepfile"
# Avoid interferences from the environment.
gccflag= dashmflag=
# Some modes work just like other modes, but use different flags. We
# parameterize here, but still list the modes in the big case below,
# to make depend.m4 easier to write. Note that we *cannot* use a case
# here, because this file can only contain one case statement.
if test "$depmode" = hp; then
# HP compiler uses -M and no extra arg.
gccflag=-M
depmode=gcc
fi
if test "$depmode" = dashXmstdout; then
# This is just like dashmstdout with a different argument.
dashmflag=-xM
depmode=dashmstdout
fi
cygpath_u="cygpath -u -f -"
if test "$depmode" = msvcmsys; then
# This is just like msvisualcpp but w/o cygpath translation.
# Just convert the backslash-escaped backslashes to single forward
# slashes to satisfy depend.m4
cygpath_u='sed s,\\\\,/,g'
depmode=msvisualcpp
fi
if test "$depmode" = msvc7msys; then
# This is just like msvc7 but w/o cygpath translation.
# Just convert the backslash-escaped backslashes to single forward
# slashes to satisfy depend.m4
cygpath_u='sed s,\\\\,/,g'
depmode=msvc7
fi
if test "$depmode" = xlc; then
# IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
gccflag=-qmakedep=gcc,-MF
depmode=gcc
fi
case "$depmode" in
gcc3)
## gcc 3 implements dependency tracking that does exactly what
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
## it if -MD -MP comes after the -MF stuff. Hmm.
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
## the command line argument order; so add the flags where they
## appear in depend2.am. Note that the slowdown incurred here
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
for arg
do
case $arg in
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
*) set fnord "$@" "$arg" ;;
esac
shift # fnord
shift # $arg
done
"$@"
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
mv "$tmpdepfile" "$depfile"
;;
gcc)
## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
## (see the conditional assignment to $gccflag above).
## There are various ways to get dependency output from gcc. Here's
## why we pick this rather obscure method:
## - Don't want to use -MD because we'd like the dependencies to end
## up in a subdir. Having to rename by hand is ugly.
## (We might end up doing this anyway to support other compilers.)
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
## -MM, not -M (despite what the docs say). Also, it might not be
## supported by the other compilers which use the 'gcc' depmode.
## - Using -M directly means running the compiler twice (even worse
## than renaming).
if test -z "$gccflag"; then
gccflag=-MD,
fi
"$@" -Wp,"$gccflag$tmpdepfile"
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
# The second -e expression handles DOS-style file names with drive
# letters.
sed -e 's/^[^:]*: / /' \
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
## This next piece of magic avoids the "deleted header file" problem.
## The problem is that when a header file which appears in a .P file
## is deleted, the dependency causes make to die (because there is
## typically no way to rebuild the header). We avoid this by adding
## dummy dependencies for each header file. Too bad gcc doesn't do
## this for us directly.
## Some versions of gcc put a space before the ':'. On the theory
## that the space means something, we add a space to the output as
## well. hp depmode also adds that space, but also prefixes the VPATH
## to the object. Take care to not repeat it in the output.
## Some versions of the HPUX 10.20 sed can't process this invocation
## correctly. Breaking it into two sed invocations is a workaround.
tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
| sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
sgi)
if test "$libtool" = yes; then
"$@" "-Wp,-MDupdate,$tmpdepfile"
else
"$@" -MDupdate "$tmpdepfile"
fi
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
echo "$object : \\" > "$depfile"
# Clip off the initial element (the dependent). Don't try to be
# clever and replace this with sed code, as IRIX sed won't handle
# lines with more than a fixed number of characters (4096 in
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
# the IRIX cc adds comments like '#:fec' to the end of the
# dependency line.
tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
| tr "$nl" ' ' >> "$depfile"
echo >> "$depfile"
# The second pass generates a dummy entry for each header file.
tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
>> "$depfile"
else
make_dummy_depfile
fi
rm -f "$tmpdepfile"
;;
xlc)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
aix)
# The C for AIX Compiler uses -M and outputs the dependencies
# in a .u file. In older versions, this file always lives in the
# current directory. Also, the AIX compiler puts '$object:' at the
# start of each line; $object doesn't have directory information.
# Version 6 uses the directory in both cases.
set_dir_from "$object"
set_base_from "$object"
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.u
tmpdepfile2=$base.u
tmpdepfile3=$dir.libs/$base.u
"$@" -Wc,-M
else
tmpdepfile1=$dir$base.u
tmpdepfile2=$dir$base.u
tmpdepfile3=$dir$base.u
"$@" -M
fi
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
do
test -f "$tmpdepfile" && break
done
aix_post_process_depfile
;;
tcc)
# tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
# FIXME: That version still under development at the moment of writing.
# Make that this statement remains true also for stable, released
# versions.
# It will wrap lines (doesn't matter whether long or short) with a
# trailing '\', as in:
#
# foo.o : \
# foo.c \
# foo.h \
#
# It will put a trailing '\' even on the last line, and will use leading
# spaces rather than leading tabs (at least since its commit 0394caf7
# "Emit spaces for -MD").
"$@" -MD -MF "$tmpdepfile"
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
# Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
# We have to change lines of the first kind to '$object: \'.
sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
# And for each line of the second kind, we have to emit a 'dep.h:'
# dummy dependency, to avoid the deleted-header problem.
sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
rm -f "$tmpdepfile"
;;
## The order of this option in the case statement is important, since the
## shell code in configure will try each of these formats in the order
## listed in this file. A plain '-MD' option would be understood by many
## compilers, so we must ensure this comes after the gcc and icc options.
pgcc)
# Portland's C compiler understands '-MD'.
# Will always output deps to 'file.d' where file is the root name of the
# source file under compilation, even if file resides in a subdirectory.
# The object file name does not affect the name of the '.d' file.
# pgcc 10.2 will output
# foo.o: sub/foo.c sub/foo.h
# and will wrap long lines using '\' :
# foo.o: sub/foo.c ... \
# sub/foo.h ... \
# ...
set_dir_from "$object"
# Use the source, not the object, to determine the base name, since
# that's sadly what pgcc will do too.
set_base_from "$source"
tmpdepfile=$base.d
# For projects that build the same source file twice into different object
# files, the pgcc approach of using the *source* file root name can cause
# problems in parallel builds. Use a locking strategy to avoid stomping on
# the same $tmpdepfile.
lockdir=$base.d-lock
trap "
echo '$0: caught signal, cleaning up...' >&2
rmdir '$lockdir'
exit 1
" 1 2 13 15
numtries=100
i=$numtries
while test $i -gt 0; do
# mkdir is a portable test-and-set.
if mkdir "$lockdir" 2>/dev/null; then
# This process acquired the lock.
"$@" -MD
stat=$?
# Release the lock.
rmdir "$lockdir"
break
else
# If the lock is being held by a different process, wait
# until the winning process is done or we timeout.
while test -d "$lockdir" && test $i -gt 0; do
sleep 1
i=`expr $i - 1`
done
fi
i=`expr $i - 1`
done
trap - 1 2 13 15
if test $i -le 0; then
echo "$0: failed to acquire lock after $numtries attempts" >&2
echo "$0: check lockdir '$lockdir'" >&2
exit 1
fi
if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
# Each line is of the form `foo.o: dependent.h',
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
# Do two passes, one to just change these to
# `$object: dependent.h' and one to simply `dependent.h:'.
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process this invocation
# correctly. Breaking it into two sed invocations is a workaround.
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
| sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
hp2)
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
# compilers, which have integrated preprocessors. The correct option
# to use with these is +Maked; it writes dependencies to a file named
# 'foo.d', which lands next to the object file, wherever that
# happens to be.
# Much of this is similar to the tru64 case; see comments there.
set_dir_from "$object"
set_base_from "$object"
if test "$libtool" = yes; then
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir.libs/$base.d
"$@" -Wc,+Maked
else
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir$base.d
"$@" +Maked
fi
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile1" "$tmpdepfile2"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
do
test -f "$tmpdepfile" && break
done
if test -f "$tmpdepfile"; then
sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
# Add 'dependent.h:' lines.
sed -ne '2,${
s/^ *//
s/ \\*$//
s/$/:/
p
}' "$tmpdepfile" >> "$depfile"
else
make_dummy_depfile
fi
rm -f "$tmpdepfile" "$tmpdepfile2"
;;
tru64)
# The Tru64 compiler uses -MD to generate dependencies as a side
# effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
# dependencies in 'foo.d' instead, so we check for that too.
# Subdirectories are respected.
set_dir_from "$object"
set_base_from "$object"
if test "$libtool" = yes; then
# Libtool generates 2 separate objects for the 2 libraries. These
# two compilations output dependencies in $dir.libs/$base.o.d and
# in $dir$base.o.d. We have to check for both files, because
# one of the two compilations can be disabled. We should prefer
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
# automatically cleaned when .libs/ is deleted, while ignoring
# the former would cause a distcleancheck panic.
tmpdepfile1=$dir$base.o.d # libtool 1.5
tmpdepfile2=$dir.libs/$base.o.d # Likewise.
tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
"$@" -Wc,-MD
else
tmpdepfile1=$dir$base.d
tmpdepfile2=$dir$base.d
tmpdepfile3=$dir$base.d
"$@" -MD
fi
stat=$?
if test $stat -ne 0; then
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
exit $stat
fi
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
do
test -f "$tmpdepfile" && break
done
# Same post-processing that is required for AIX mode.
aix_post_process_depfile
;;
msvc7)
if test "$libtool" = yes; then
showIncludes=-Wc,-showIncludes
else
showIncludes=-showIncludes
fi
"$@" $showIncludes > "$tmpdepfile"
stat=$?
grep -v '^Note: including file: ' "$tmpdepfile"
if test $stat -ne 0; then
rm -f "$tmpdepfile"
exit $stat
fi
rm -f "$depfile"
echo "$object : \\" > "$depfile"
# The first sed program below extracts the file names and escapes
# backslashes for cygpath. The second sed program outputs the file
# name when reading, but also accumulates all include files in the
# hold buffer in order to output them again at the end. This only
# works with sed implementations that can handle large buffers.
sed < "$tmpdepfile" -n '
/^Note: including file: *\(.*\)/ {
s//\1/
s/\\/\\\\/g
p
}' | $cygpath_u | sort -u | sed -n '
s/ /\\ /g
s/\(.*\)/'"$tab"'\1 \\/p
s/.\(.*\) \\/\1:/
H
$ {
s/.*/'"$tab"'/
G
p
}' >> "$depfile"
echo >> "$depfile" # make sure the fragment doesn't end with a backslash
rm -f "$tmpdepfile"
;;
msvc7msys)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
#nosideeffect)
# This comment above is used by automake to tell side-effect
# dependency tracking mechanisms from slower ones.
dashmstdout)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout, regardless of -o.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test "X$1" != 'X--mode=compile'; do
shift
done
shift
fi
# Remove '-o $object'.
IFS=" "
for arg
do
case $arg in
-o)
shift
;;
$object)
shift
;;
*)
set fnord "$@" "$arg"
shift # fnord
shift # $arg
;;
esac
done
test -z "$dashmflag" && dashmflag=-M
# Require at least two characters before searching for ':'
# in the target name. This is to cope with DOS-style filenames:
# a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
"$@" $dashmflag |
sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
rm -f "$depfile"
cat < "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process this sed invocation
# correctly. Breaking it into two sed invocations is a workaround.
tr ' ' "$nl" < "$tmpdepfile" \
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
| sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
dashXmstdout)
# This case only exists to satisfy depend.m4. It is never actually
# run, as this mode is specially recognized in the preamble.
exit 1
;;
makedepend)
"$@" || exit $?
# Remove any Libtool call
if test "$libtool" = yes; then
while test "X$1" != 'X--mode=compile'; do
shift
done
shift
fi
# X makedepend
shift
cleared=no eat=no
for arg
do
case $cleared in
no)
set ""; shift
cleared=yes ;;
esac
if test $eat = yes; then
eat=no
continue
fi
case "$arg" in
-D*|-I*)
set fnord "$@" "$arg"; shift ;;
# Strip any option that makedepend may not understand. Remove
# the object too, otherwise makedepend will parse it as a source file.
-arch)
eat=yes ;;
-*|$object)
;;
*)
set fnord "$@" "$arg"; shift ;;
esac
done
obj_suffix=`echo "$object" | sed 's/^.*\././'`
touch "$tmpdepfile"
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
rm -f "$depfile"
# makedepend may prepend the VPATH from the source file name to the object.
# No need to regex-escape $object, excess matching of '.' is harmless.
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
# Some versions of the HPUX 10.20 sed can't process the last invocation
# correctly. Breaking it into two sed invocations is a workaround.
sed '1,2d' "$tmpdepfile" \
| tr ' ' "$nl" \
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
| sed -e 's/$/ :/' >> "$depfile"
rm -f "$tmpdepfile" "$tmpdepfile".bak
;;
cpp)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test "X$1" != 'X--mode=compile'; do
shift
done
shift
fi
# Remove '-o $object'.
IFS=" "
for arg
do
case $arg in
-o)
shift
;;
$object)
shift
;;
*)
set fnord "$@" "$arg"
shift # fnord
shift # $arg
;;
esac
done
"$@" -E \
| sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
| sed '$ s: \\$::' > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
cat < "$tmpdepfile" >> "$depfile"
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
rm -f "$tmpdepfile"
;;
msvisualcpp)
# Important note: in order to support this mode, a compiler *must*
# always write the preprocessed file to stdout.
"$@" || exit $?
# Remove the call to Libtool.
if test "$libtool" = yes; then
while test "X$1" != 'X--mode=compile'; do
shift
done
shift
fi
IFS=" "
for arg
do
case "$arg" in
-o)
shift
;;
$object)
shift
;;
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
set fnord "$@"
shift
shift
;;
*)
set fnord "$@" "$arg"
shift
shift
;;
esac
done
"$@" -E 2>/dev/null |
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
rm -f "$depfile"
echo "$object : \\" > "$depfile"
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
echo "$tab" >> "$depfile"
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
rm -f "$tmpdepfile"
;;
msvcmsys)
# This case exists only to let depend.m4 do its work. It works by
# looking at the text of this script. This case will never be run,
# since it is checked for above.
exit 1
;;
none)
exec "$@"
;;
*)
echo "Unknown depmode $depmode" 1>&2
exit 1
;;
esac
exit 0
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'before-save-hook 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC0"
# time-stamp-end: "; # UTC"
# End:
libcaes-20240413/libcaes/ 0000755 0001750 0001750 00000000000 14606477653 015637 5 ustar 00lordyesta lordyesta libcaes-20240413/libcaes/libcaes_unused.h 0000644 0001750 0001750 00000002570 14606473412 020766 0 ustar 00lordyesta lordyesta /*
* Definitions to silence compiler warnings about unused function attributes/parameters.
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_UNUSED_H )
#define _LIBCAES_UNUSED_H
#include
#if !defined( LIBCAES_ATTRIBUTE_UNUSED )
#if defined( __GNUC__ ) && __GNUC__ >= 3
#define LIBCAES_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#else
#define LIBCAES_ATTRIBUTE_UNUSED
#endif
#endif
#if defined( _MSC_VER )
#define LIBCAES_UNREFERENCED_PARAMETER( parameter ) \
UNREFERENCED_PARAMETER( parameter );
#else
#define LIBCAES_UNREFERENCED_PARAMETER( parameter ) \
/* parameter */
#endif
#endif /* !defined( _LIBCAES_UNUSED_H ) */
libcaes-20240413/libcaes/libcaes.c 0000644 0001750 0001750 00000003431 14606473412 017373 0 ustar 00lordyesta lordyesta /*
* Library to support cross-platform AES encryption
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#include
#if defined( WINAPI )
#include
#endif
#include "libcaes_unused.h"
/* Define HAVE_LOCAL_LIBCAES for local use of libcaes
*/
#if !defined( HAVE_LOCAL_LIBCAES )
#if defined( WINAPI ) && defined( HAVE_DLLMAIN )
#if defined( _MANAGED )
#pragma managed( push, off )
#endif
/* Defines the entry point for the DLL
*/
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved )
{
LIBCAES_UNREFERENCED_PARAMETER( lpvReserved )
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(
hinstDLL );
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return( TRUE );
}
/* Function that indicates the library is a DLL
* Returns 1
*/
int libcaes_is_dll(
void )
{
return( 1 );
}
#endif /* defined( WINAPI ) && defined( HAVE_DLLMAIN ) */
#endif /* !defined( HAVE_LOCAL_LIBCAES ) */
libcaes-20240413/libcaes/libcaes_tweaked_context.h 0000644 0001750 0001750 00000005505 14606473412 022654 0 ustar 00lordyesta lordyesta /*
* AES tweaked de/encryption context functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_TWEAKED_CONTEXT_H )
#define _LIBCAES_TWEAKED_CONTEXT_H
#include
#include
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H )
#include
#endif
#include "libcaes_extern.h"
#include "libcaes_libcerror.h"
#include "libcaes_types.h"
#if defined( __cplusplus )
extern "C" {
#endif
typedef struct libcaes_internal_tweaked_context libcaes_internal_tweaked_context_t;
struct libcaes_internal_tweaked_context
{
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
/* The EVP cipher context
*/
#if defined( HAVE_EVP_CIPHER_CTX_INIT )
EVP_CIPHER_CTX internal_evp_cipher_context;
#endif
EVP_CIPHER_CTX *evp_cipher_context;
/* The key
*/
uint8_t key[ 64 ];
/* The key bit size
*/
size_t key_bit_size;
#else
/* The main de/encryption context
*/
libcaes_context_t *main_context;
/* The tweak encryption context
*/
libcaes_context_t *tweak_context;
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS ) */
};
LIBCAES_EXTERN \
int libcaes_tweaked_context_initialize(
libcaes_tweaked_context_t **tweaked_context,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_tweaked_context_free(
libcaes_tweaked_context_t **tweaked_context,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_tweaked_context_set_keys(
libcaes_tweaked_context_t *tweaked_context,
int mode,
const uint8_t *key,
size_t key_bit_size,
const uint8_t *tweak_key,
size_t tweak_key_bit_size,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_crypt_xts(
libcaes_tweaked_context_t *tweaked_context,
int mode,
const uint8_t *tweak_value,
size_t tweak_value_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error );
#ifdef __cplusplus
}
#endif
#endif /* !defined( _LIBCAES_TWEAKED_CONTEXT_H ) */
libcaes-20240413/libcaes/libcaes_context.h 0000644 0001750 0001750 00000010560 14606473412 021145 0 ustar 00lordyesta lordyesta /*
* AES de/encryption context functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_CONTEXT_H )
#define _LIBCAES_CONTEXT_H
#include
#include
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H )
#include
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H )
#include
#endif
#include "libcaes_extern.h"
#include "libcaes_libcerror.h"
#include "libcaes_types.h"
#if defined( __cplusplus )
extern "C" {
#endif
typedef struct libcaes_internal_context libcaes_internal_context_t;
struct libcaes_internal_context
{
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) )
/* The AES key
*/
AES_KEY key;
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && ( defined( HAVE_EVP_CRYPTO_AES_CBC ) || defined( HAVE_EVP_CRYPTO_AES_ECB ) )
/* The EVP cipher context
*/
#if defined( HAVE_EVP_CIPHER_CTX_INIT )
EVP_CIPHER_CTX internal_evp_cipher_context;
#endif
EVP_CIPHER_CTX *evp_cipher_context;
/* The key
*/
uint8_t key[ 32 ];
/* The key bit size
*/
size_t key_bit_size;
#else
/* The number of round keys
*/
uint8_t number_of_round_keys;
/* The round keys
*/
uint32_t *round_keys;
/* The round keys data
*/
uint32_t round_keys_data[ 68 ];
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) ) */
};
LIBCAES_EXTERN \
int libcaes_context_initialize(
libcaes_context_t **context,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_context_free(
libcaes_context_t **context,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_context_set_key(
libcaes_context_t *context,
int mode,
const uint8_t *key,
size_t key_bit_size,
libcerror_error_t **error );
#if !defined( LIBCAES_HAVE_AES_SUPPORT )
int libcaes_initialize_tables(
libcerror_error_t **error );
int libcaes_internal_context_set_decryption_key(
libcaes_internal_context_t *internal_context,
const uint8_t *key,
size_t key_bit_size,
libcerror_error_t **error );
int libcaes_internal_context_set_encryption_key(
libcaes_internal_context_t *internal_context,
const uint8_t *key,
size_t key_bit_size,
libcerror_error_t **error );
#endif /* !defined( LIBCAES_HAVE_AES_SUPPORT ) */
LIBCAES_EXTERN \
int libcaes_crypt_cbc(
libcaes_context_t *context,
int mode,
const uint8_t *initialization_vector,
size_t initialization_vector_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_crypt_ccm(
libcaes_context_t *context,
int mode,
const uint8_t *nonce,
size_t nonce_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_crypt_cfb(
libcaes_context_t *context,
int mode,
const uint8_t *initialization_vector,
size_t initialization_vector_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error );
LIBCAES_EXTERN \
int libcaes_crypt_ecb(
libcaes_context_t *context,
int mode,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error );
#ifdef __cplusplus
}
#endif
#endif /* !defined( _LIBCAES_CONTEXT_H ) */
libcaes-20240413/libcaes/libcaes_error.c 0000644 0001750 0001750 00000005520 14606473412 020605 0 ustar 00lordyesta lordyesta /*
* Error functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include "libcaes_error.h"
#include "libcaes_libcerror.h"
#if !defined( HAVE_LOCAL_LIBCAES )
/* Free an error and its elements
*/
void libcaes_error_free(
libcaes_error_t **error )
{
libcerror_error_free(
(libcerror_error_t **) error );
}
/* Prints a descriptive string of the error to the stream
* Returns the number of printed characters if successful or -1 on error
*/
int libcaes_error_fprint(
libcaes_error_t *error,
FILE *stream )
{
int print_count = 0;
print_count = libcerror_error_fprint(
(libcerror_error_t *) error,
stream );
return( print_count );
}
/* Prints a descriptive string of the error to the string
* The end-of-string character is not included in the return value
* Returns the number of printed characters if successful or -1 on error
*/
int libcaes_error_sprint(
libcaes_error_t *error,
char *string,
size_t size )
{
int print_count = 0;
print_count = libcerror_error_sprint(
(libcerror_error_t *) error,
string,
size );
return( print_count );
}
/* Prints a backtrace of the error to the stream
* Returns the number of printed characters if successful or -1 on error
*/
int libcaes_error_backtrace_fprint(
libcaes_error_t *error,
FILE *stream )
{
int print_count = 0;
print_count = libcerror_error_backtrace_fprint(
(libcerror_error_t *) error,
stream );
return( print_count );
}
/* Prints a backtrace of the error to the string
* The end-of-string character is not included in the return value
* Returns the number of printed characters if successful or -1 on error
*/
int libcaes_error_backtrace_sprint(
libcaes_error_t *error,
char *string,
size_t size )
{
int print_count = 0;
print_count = libcerror_error_backtrace_sprint(
(libcerror_error_t *) error,
string,
size );
return( print_count );
}
#endif /* !defined( HAVE_LOCAL_LIBCAES ) */
libcaes-20240413/libcaes/libcaes_context.c 0000644 0001750 0001750 00000241270 14606473412 021144 0 ustar 00lordyesta lordyesta /*
* AES de/encryption context functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H )
#include
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H )
#include
#include
#endif
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
#include
#endif
#include "libcaes_context.h"
#include "libcaes_definitions.h"
#include "libcaes_libcerror.h"
#include "libcaes_types.h"
#if !defined( LIBCAES_HAVE_AES_SUPPORT )
/* FIPS-197 compliant AES encryption functions
*
* The AES block cipher was designed by Vincent Rijmen and Joan Daemen.
*
* http://csrc.nist.gov/encryption/aes/rijndael/Rijndael.pdf
* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
*/
#define libcaes_calculate_forward_substitution_value( value, index0, index1, index2, index3 ) \
value = libcaes_forward_substitution_box[ index3 ]; \
value <<= 8; \
value |= libcaes_forward_substitution_box[ index2 ]; \
value <<= 8; \
value |= libcaes_forward_substitution_box[ index1 ]; \
value <<= 8; \
value |= libcaes_forward_substitution_box[ index0 ];
#define libcaes_calculate_forward_table_value( value, index0, index1, index2, index3 ) \
value = libcaes_forward_table0[ index0 ]; \
value ^= libcaes_forward_table1[ index1 ]; \
value ^= libcaes_forward_table2[ index2 ]; \
value ^= libcaes_forward_table3[ index3 ];
#define libcaes_calculate_reverse_substitution_value( value, index0, index1, index2, index3 ) \
value = libcaes_reverse_substitution_box[ index3 ]; \
value <<= 8; \
value |= libcaes_reverse_substitution_box[ index2 ]; \
value <<= 8; \
value |= libcaes_reverse_substitution_box[ index1 ]; \
value <<= 8; \
value |= libcaes_reverse_substitution_box[ index0 ];
#define libcaes_calculate_reverse_table_value( value, index0, index1, index2, index3 ) \
value = libcaes_reverse_table0[ index0 ]; \
value ^= libcaes_reverse_table1[ index1 ]; \
value ^= libcaes_reverse_table2[ index2 ]; \
value ^= libcaes_reverse_table3[ index3 ];
#define libcaes_calculate_forward_substitution_round( round_keys, values_32bit, cipher_values_32bit, substitution_value ) \
libcaes_calculate_forward_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 0 ] & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 0 ] = round_keys[ 0 ] ^ substitution_value; \
\
libcaes_calculate_forward_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 1 ] & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 1 ] = round_keys[ 1 ] ^ substitution_value; \
\
libcaes_calculate_forward_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 2 ] & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 2 ] = round_keys[ 2 ] ^ substitution_value; \
\
libcaes_calculate_forward_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 3 ] & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 3 ] = round_keys[ 3 ] ^ substitution_value;
#define libcaes_calculate_forward_table_round( round_keys, values_32bit, cipher_values_32bit, table_value ) \
libcaes_calculate_forward_table_value( \
table_value, \
( cipher_values_32bit[ 0 ] & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 0 ] = round_keys[ 0 ] ^ table_value; \
\
libcaes_calculate_forward_table_value( \
table_value, \
( cipher_values_32bit[ 1 ] & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 1 ] = round_keys[ 1 ] ^ table_value; \
\
libcaes_calculate_forward_table_value( \
table_value, \
( cipher_values_32bit[ 2 ] & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 2 ] = round_keys[ 2 ] ^ table_value; \
\
libcaes_calculate_forward_table_value( \
table_value, \
( cipher_values_32bit[ 3 ] & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 3 ] = round_keys[ 3 ] ^ table_value;
#define libcaes_calculate_reverse_substitution_round( round_keys, values_32bit, cipher_values_32bit, substitution_value ) \
libcaes_calculate_reverse_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 0 ] & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 0 ] = round_keys[ 0 ] ^ substitution_value; \
\
libcaes_calculate_reverse_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 1 ] & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 1 ] = round_keys[ 1 ] ^ substitution_value; \
\
libcaes_calculate_reverse_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 2 ] & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 2 ] = round_keys[ 2 ] ^ substitution_value; \
\
libcaes_calculate_reverse_substitution_value( \
substitution_value, \
( cipher_values_32bit[ 3 ] & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 3 ] = round_keys[ 3 ] ^ substitution_value;
#define libcaes_calculate_reverse_table_round( round_keys, values_32bit, cipher_values_32bit, table_value ) \
libcaes_calculate_reverse_table_value( \
table_value, \
( cipher_values_32bit[ 0 ] & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 0 ] = round_keys[ 0 ] ^ table_value; \
\
libcaes_calculate_reverse_table_value( \
table_value, \
( cipher_values_32bit[ 1 ] & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 1 ] = round_keys[ 1 ] ^ table_value; \
\
libcaes_calculate_reverse_table_value( \
table_value, \
( cipher_values_32bit[ 2 ] & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 3 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 2 ] = round_keys[ 2 ] ^ table_value; \
\
libcaes_calculate_reverse_table_value( \
table_value, \
( cipher_values_32bit[ 3 ] & 0xff ), \
( ( cipher_values_32bit[ 2 ] >> 8 ) & 0xff ), \
( ( cipher_values_32bit[ 1 ] >> 16 ) & 0xff ), \
( ( cipher_values_32bit[ 0 ] >> 24 ) & 0xff ) ); \
\
values_32bit[ 3 ] = round_keys[ 3 ] ^ table_value;
/* Forward S-box & tables
*/
static uint8_t libcaes_forward_substitution_box[ 256 ];
static uint32_t libcaes_forward_table0[ 256 ];
static uint32_t libcaes_forward_table1[ 256 ];
static uint32_t libcaes_forward_table2[ 256 ];
static uint32_t libcaes_forward_table3[ 256 ];
/* Reverse S-box & tables
*/
static uint8_t libcaes_reverse_substitution_box[ 256 ];
static uint32_t libcaes_reverse_table0[ 256 ];
static uint32_t libcaes_reverse_table1[ 256 ];
static uint32_t libcaes_reverse_table2[ 256 ];
static uint32_t libcaes_reverse_table3[ 256 ];
/* Round constants
*/
static uint32_t libcaes_round_constants[ 10 ];
static int libcaes_tables_initialized = 0;
#endif /* !defined( LIBCAES_HAVE_AES_SUPPORT ) */
/* Creates a context
* Make sure the value context is referencing, is set to NULL
* Returns 1 if successful or -1 on error
*/
int libcaes_context_initialize(
libcaes_context_t **context,
libcerror_error_t **error )
{
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_context_initialize";
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && ( defined( HAVE_EVP_CRYPTO_AES_CBC ) || defined( HAVE_EVP_CRYPTO_AES_ECB ) )
char error_string[ 256 ];
unsigned long error_code = 0;
#endif
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
if( *context != NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
"%s: invalid context value already set.",
function );
return( -1 );
}
internal_context = memory_allocate_structure(
libcaes_internal_context_t );
if( internal_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
"%s: unable to create context.",
function );
goto on_error;
}
if( memory_set(
internal_context,
0,
sizeof( libcaes_internal_context_t ) ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear context.",
function );
goto on_error;
}
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) )
/* No additional initialization necessary */
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && ( defined( HAVE_EVP_CRYPTO_AES_CBC ) || defined( HAVE_EVP_CRYPTO_AES_ECB ) )
#if defined( HAVE_EVP_CIPHER_CTX_INIT )
EVP_CIPHER_CTX_init(
&( internal_context->internal_evp_cipher_context ) );
internal_context->evp_cipher_context = &( internal_context->internal_evp_cipher_context );
#else
internal_context->evp_cipher_context = EVP_CIPHER_CTX_new();
if( internal_context->evp_cipher_context == NULL )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to create EVP cipher context with error: %s.",
function,
error_string );
goto on_error;
}
#endif /* defined( HAVE_EVP_CIPHER_CTX_INIT ) */
#else
if( libcaes_tables_initialized == 0 )
{
if( libcaes_initialize_tables(
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize tables.",
function );
goto on_error;
}
libcaes_tables_initialized = 1;
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) ) */
*context = (libcaes_context_t *) internal_context;
return( 1 );
on_error:
if( internal_context != NULL )
{
memory_free(
internal_context );
}
return( -1 );
}
/* Frees a context
* Returns 1 if successful or -1 on error
*/
int libcaes_context_free(
libcaes_context_t **context,
libcerror_error_t **error )
{
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_context_free";
int result = 1;
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_EVP_CIPHER_CTX_CLEANUP )
char error_string[ 256 ];
unsigned long error_code = 0;
#endif
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
if( *context != NULL )
{
internal_context = (libcaes_internal_context_t *) *context;
*context = NULL;
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) )
/* No additional clean up necessary */
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && ( defined( HAVE_EVP_CRYPTO_AES_CBC ) || defined( HAVE_EVP_CRYPTO_AES_ECB ) )
#if defined( HAVE_EVP_CIPHER_CTX_CLEANUP )
if( EVP_CIPHER_CTX_cleanup(
&( internal_context->internal_evp_cipher_context ) ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
"%s: unable to clean up EVP cipher context with error: %s.",
function,
error_string );
result = -1;
}
/* Make sure the error state is removed otherwise OpenSSL will leak memory
*/
ERR_remove_thread_state(
NULL );
#else
EVP_CIPHER_CTX_free(
internal_context->evp_cipher_context );
#endif /* defined( HAVE_EVP_CIPHER_CTX_CLEANUP ) */
internal_context->evp_cipher_context = NULL;
#else
/* No additional clean up necessary */
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) ) */
memory_free(
internal_context );
}
return( result );
}
/* Sets the key
* Returns 1 if successful or -1 on error
*/
int libcaes_context_set_key(
libcaes_context_t *context,
int mode,
const uint8_t *key,
size_t key_bit_size,
libcerror_error_t **error )
{
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_context_set_key";
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
internal_context = (libcaes_internal_context_t *) context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( ( key_bit_size != 128 )
&& ( key_bit_size != 192 )
&& ( key_bit_size != 256 ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported key bit size.",
function );
return( -1 );
}
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) )
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
if( AES_set_encrypt_key(
(unsigned char *) key,
(int) key_bit_size,
&( internal_context->key ) ) != 0 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set encryption key.",
function );
return( -1 );
}
}
else
{
if( AES_set_decrypt_key(
(unsigned char *) key,
(int) key_bit_size,
&( internal_context->key ) ) != 0 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set decryption key.",
function );
return( -1 );
}
}
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && ( defined( HAVE_EVP_CRYPTO_AES_CBC ) || defined( HAVE_EVP_CRYPTO_AES_ECB ) )
if( key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid key.",
function );
return( -1 );
}
if( memory_copy(
internal_context->key,
key,
key_bit_size / 8 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy key.",
function );
return( -1 );
}
internal_context->key_bit_size = key_bit_size;
#else
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
if( libcaes_internal_context_set_encryption_key(
internal_context,
key,
key_bit_size,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set encryption key.",
function );
return( -1 );
}
}
else
{
if( libcaes_internal_context_set_decryption_key(
internal_context,
key,
key_bit_size,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set decryption key.",
function );
return( -1 );
}
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && ( defined( HAVE_AES_CBC_ENCRYPT ) || defined( HAVE_AES_ECB_ENCRYPT ) ) */
return( 1 );
}
#if !defined( LIBCAES_HAVE_AES_SUPPORT )
/* Initializes the AES encryption and decryption tables
* Returns 1 if successful or -1 on error
*/
int libcaes_initialize_tables(
libcerror_error_t **error )
{
uint8_t logs_table[ 256 ];
uint8_t powers_table[ 256 ];
static char *function = "libcaes_initialize_tables";
uint16_t byte_index = 0;
uint16_t table_index = 0;
uint8_t byte_value = 0;
uint8_t round_constant_index = 0;
uint8_t substitution_value = 0;
if( memory_set(
logs_table,
0,
sizeof( uint8_t ) * 256 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear logs table.",
function );
return( -1 );
}
/* Fill the powers and logs tables over GF( 2^8 )
*/
byte_value = 1;
for( byte_index = 0;
byte_index < 256;
byte_index++ )
{
powers_table[ byte_index ] = byte_value;
logs_table[ byte_value ] = (uint8_t) byte_index;
if( ( byte_value & 0x80 ) == 0 )
{
byte_value ^= ( byte_value << 1 ) & 0xff;
}
else
{
byte_value ^= ( ( byte_value << 1 ) & 0xff ) ^ 0x1b;
}
}
/* Fill the round constants
*/
byte_value = 1;
for( round_constant_index = 0;
round_constant_index < 10;
round_constant_index++ )
{
libcaes_round_constants[ round_constant_index ] = (uint32_t) byte_value;
if( ( byte_value & 0x80 ) == 0 )
{
byte_value = ( byte_value << 1 ) & 0xff;
}
else
{
byte_value = ( ( byte_value << 1 ) & 0xff ) ^ 0x1b;
}
}
/* Fill the forward and reverse S-boxes
*/
libcaes_forward_substitution_box[ 0x00 ] = 0x63;
libcaes_reverse_substitution_box[ 0x63 ] = 0x00;
for( byte_index = 1;
byte_index < 256;
byte_index++ )
{
table_index = 255 - logs_table[ byte_index ];
byte_value = powers_table[ table_index ];
substitution_value = ( ( byte_value << 1 ) & 0xff )
| ( byte_value >> 7 );
byte_value ^= substitution_value;
substitution_value = ( ( substitution_value << 1 ) & 0xff )
| ( substitution_value >> 7 );
byte_value ^= substitution_value;
substitution_value = ( ( substitution_value << 1 ) & 0xff )
| ( substitution_value >> 7 );
byte_value ^= substitution_value;
substitution_value = ( ( substitution_value << 1 ) & 0xff )
| ( substitution_value >> 7 );
substitution_value ^= byte_value ^ 0x63;
libcaes_forward_substitution_box[ byte_index ] = substitution_value;
libcaes_reverse_substitution_box[ substitution_value ] = (uint8_t) byte_index;
}
/* Fill the forward and reverse tables
*/
for( byte_index = 0;
byte_index < 256;
byte_index++ )
{
byte_value = libcaes_forward_substitution_box[ byte_index ];
if( ( byte_value & 0x80 ) == 0 )
{
substitution_value = ( byte_value << 1 ) & 0xff;
}
else
{
substitution_value = ( ( byte_value << 1 ) & 0xff ) ^ 0x1b;
}
libcaes_forward_table0[ byte_index ] = byte_value ^ substitution_value;
libcaes_forward_table0[ byte_index ] <<= 8;
libcaes_forward_table0[ byte_index ] |= byte_value;
libcaes_forward_table0[ byte_index ] <<= 8;
libcaes_forward_table0[ byte_index ] |= byte_value;
libcaes_forward_table0[ byte_index ] <<= 8;
libcaes_forward_table0[ byte_index ] |= substitution_value;
libcaes_forward_table1[ byte_index ] = byte_stream_bit_rotate_left(
libcaes_forward_table0[ byte_index ],
8 );
libcaes_forward_table2[ byte_index ] = byte_stream_bit_rotate_left(
libcaes_forward_table1[ byte_index ],
8 );
libcaes_forward_table3[ byte_index ] = byte_stream_bit_rotate_left(
libcaes_forward_table2[ byte_index ],
8 );
substitution_value = libcaes_reverse_substitution_box[ byte_index ];
libcaes_reverse_table0[ byte_index ] = 0;
if( substitution_value != 0 )
{
table_index = logs_table[ 0x0b ];
table_index += logs_table[ substitution_value ];
table_index %= 255;
libcaes_reverse_table0[ byte_index ] ^= powers_table[ table_index ];
libcaes_reverse_table0[ byte_index ] <<= 8;
table_index = logs_table[ 0x0d ];
table_index += logs_table[ substitution_value ];
table_index %= 255;
libcaes_reverse_table0[ byte_index ] ^= powers_table[ table_index ];
libcaes_reverse_table0[ byte_index ] <<= 8;
table_index = logs_table[ 0x09 ];
table_index += logs_table[ substitution_value ];
table_index %= 255;
libcaes_reverse_table0[ byte_index ] ^= powers_table[ table_index ];
libcaes_reverse_table0[ byte_index ] <<= 8;
table_index = logs_table[ 0x0e ];
table_index += logs_table[ substitution_value ];
table_index %= 255;
libcaes_reverse_table0[ byte_index ] ^= powers_table[ table_index ];
}
libcaes_reverse_table1[ byte_index ] = byte_stream_bit_rotate_left(
libcaes_reverse_table0[ byte_index ],
8 );
libcaes_reverse_table2[ byte_index ] = byte_stream_bit_rotate_left(
libcaes_reverse_table1[ byte_index ],
8 );
libcaes_reverse_table3[ byte_index ] = byte_stream_bit_rotate_left(
libcaes_reverse_table2[ byte_index ],
8 );
}
return( 1 );
}
/* Sets the AES decryption key
* Returns 1 if successful or -1 on error
*/
int libcaes_internal_context_set_decryption_key(
libcaes_internal_context_t *internal_context,
const uint8_t *key,
size_t key_bit_size,
libcerror_error_t **error )
{
libcaes_internal_context_t *encryption_context = NULL;
static char *function = "libcaes_internal_context_set_decryption_key";
uint32_t *encryption_round_keys = NULL;
uint32_t *round_keys = NULL;
size_t round_keys_byte_offset = 0;
uint8_t byte_value0 = 0;
uint8_t byte_value1 = 0;
uint8_t byte_value2 = 0;
uint8_t byte_value3 = 0;
int round_key_iterator = 0;
if( internal_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
if( key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid key.",
function );
return( -1 );
}
if( ( key_bit_size != 128 )
&& ( key_bit_size != 192 )
&& ( key_bit_size != 256 ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported key bit size.",
function );
return( -1 );
}
if( key_bit_size == 128 )
{
internal_context->number_of_round_keys = 10;
}
else if( key_bit_size == 192 )
{
internal_context->number_of_round_keys = 12;
}
else if( key_bit_size == 256 )
{
internal_context->number_of_round_keys = 14;
}
/* Align the buffer to next 16-byte blocks
*/
internal_context->round_keys = (uint32_t *) ( 16 + ( (intptr_t) internal_context->round_keys_data & ~( 15 ) ) );
round_keys = internal_context->round_keys;
if( libcaes_context_initialize(
(libcaes_context_t **) &encryption_context,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to create encryption context.",
function );
goto on_error;
}
if( libcaes_internal_context_set_encryption_key(
encryption_context,
key,
key_bit_size,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set encryption key.",
function );
goto on_error;
}
/* Point to the end of the round keys
*/
round_keys_byte_offset = encryption_context->number_of_round_keys * sizeof( uint32_t );
encryption_round_keys = &( encryption_context->round_keys[ round_keys_byte_offset ] );
round_keys[ 0 ] = encryption_round_keys[ 0 ];
round_keys[ 1 ] = encryption_round_keys[ 1 ];
round_keys[ 2 ] = encryption_round_keys[ 2 ];
round_keys[ 3 ] = encryption_round_keys[ 3 ];
round_keys += 4;
encryption_round_keys -= 4;
for( round_key_iterator = internal_context->number_of_round_keys;
round_key_iterator > 1;
round_key_iterator-- )
{
byte_value0 = ( encryption_round_keys[ 0 ] & 0xff );
byte_value1 = ( ( encryption_round_keys[ 0 ] >> 8 ) & 0xff );
byte_value2 = ( ( encryption_round_keys[ 0 ] >> 16 ) & 0xff );
byte_value3 = ( ( encryption_round_keys[ 0 ] >> 24 ) & 0xff );
byte_value0 = libcaes_forward_substitution_box[ byte_value0 ];
byte_value1 = libcaes_forward_substitution_box[ byte_value1 ];
byte_value2 = libcaes_forward_substitution_box[ byte_value2 ];
byte_value3 = libcaes_forward_substitution_box[ byte_value3 ];
round_keys[ 0 ] = libcaes_reverse_table0[ byte_value0 ]
^ libcaes_reverse_table1[ byte_value1 ]
^ libcaes_reverse_table2[ byte_value2 ]
^ libcaes_reverse_table3[ byte_value3 ];
byte_value0 = ( encryption_round_keys[ 1 ] & 0xff );
byte_value1 = ( ( encryption_round_keys[ 1 ] >> 8 ) & 0xff );
byte_value2 = ( ( encryption_round_keys[ 1 ] >> 16 ) & 0xff );
byte_value3 = ( ( encryption_round_keys[ 1 ] >> 24 ) & 0xff );
byte_value0 = libcaes_forward_substitution_box[ byte_value0 ];
byte_value1 = libcaes_forward_substitution_box[ byte_value1 ];
byte_value2 = libcaes_forward_substitution_box[ byte_value2 ];
byte_value3 = libcaes_forward_substitution_box[ byte_value3 ];
round_keys[ 1 ] = libcaes_reverse_table0[ byte_value0 ]
^ libcaes_reverse_table1[ byte_value1 ]
^ libcaes_reverse_table2[ byte_value2 ]
^ libcaes_reverse_table3[ byte_value3 ];
byte_value0 = ( encryption_round_keys[ 2 ] & 0xff );
byte_value1 = ( ( encryption_round_keys[ 2 ] >> 8 ) & 0xff );
byte_value2 = ( ( encryption_round_keys[ 2 ] >> 16 ) & 0xff );
byte_value3 = ( ( encryption_round_keys[ 2 ] >> 24 ) & 0xff );
byte_value0 = libcaes_forward_substitution_box[ byte_value0 ];
byte_value1 = libcaes_forward_substitution_box[ byte_value1 ];
byte_value2 = libcaes_forward_substitution_box[ byte_value2 ];
byte_value3 = libcaes_forward_substitution_box[ byte_value3 ];
round_keys[ 2 ] = libcaes_reverse_table0[ byte_value0 ]
^ libcaes_reverse_table1[ byte_value1 ]
^ libcaes_reverse_table2[ byte_value2 ]
^ libcaes_reverse_table3[ byte_value3 ];
byte_value0 = ( encryption_round_keys[ 3 ] & 0xff );
byte_value1 = ( ( encryption_round_keys[ 3 ] >> 8 ) & 0xff );
byte_value2 = ( ( encryption_round_keys[ 3 ] >> 16 ) & 0xff );
byte_value3 = ( ( encryption_round_keys[ 3 ] >> 24 ) & 0xff );
byte_value0 = libcaes_forward_substitution_box[ byte_value0 ];
byte_value1 = libcaes_forward_substitution_box[ byte_value1 ];
byte_value2 = libcaes_forward_substitution_box[ byte_value2 ];
byte_value3 = libcaes_forward_substitution_box[ byte_value3 ];
round_keys[ 3 ] = libcaes_reverse_table0[ byte_value0 ]
^ libcaes_reverse_table1[ byte_value1 ]
^ libcaes_reverse_table2[ byte_value2 ]
^ libcaes_reverse_table3[ byte_value3 ];
round_keys += 4;
encryption_round_keys -= 4;
}
round_keys[ 0 ] = encryption_round_keys[ 0 ];
round_keys[ 1 ] = encryption_round_keys[ 1 ];
round_keys[ 2 ] = encryption_round_keys[ 2 ];
round_keys[ 3 ] = encryption_round_keys[ 3 ];
if( libcaes_context_free(
(libcaes_context_t **) &encryption_context,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
"%s: unable to free encryption context.",
function );
goto on_error;
}
return( 1 );
on_error:
if( encryption_context != NULL )
{
libcaes_context_free(
(libcaes_context_t **) &encryption_context,
NULL );
}
return( -1 );
}
/* Sets the AES encryption key
* Returns 1 if successful or -1 on error
*/
int libcaes_internal_context_set_encryption_key(
libcaes_internal_context_t *internal_context,
const uint8_t *key,
size_t key_bit_size,
libcerror_error_t **error )
{
static char *function = "libcaes_internal_context_set_encryption_key";
uint32_t *round_keys = NULL;
size_t key_index = 0;
int round_constant_index = 0;
if( internal_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
if( key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid key.",
function );
return( -1 );
}
if( ( key_bit_size != 128 )
&& ( key_bit_size != 192 )
&& ( key_bit_size != 256 ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported key bit size.",
function );
return( -1 );
}
/* Align the buffer to next 16-byte blocks
*/
internal_context->round_keys = (uint32_t *) ( 16 + ( (intptr_t) internal_context->round_keys_data & ~( 15 ) ) );
round_keys = internal_context->round_keys;
for( key_index = 0;
key_index < key_bit_size / 8;
key_index += 4 )
{
byte_stream_copy_to_uint32_little_endian(
&( key[ key_index ] ),
round_keys[ round_constant_index ] );
round_constant_index++;
}
if( key_bit_size == 128 )
{
internal_context->number_of_round_keys = 10;
for( round_constant_index = 0;
round_constant_index < 10;
round_constant_index++ )
{
round_keys[ 4 ] = libcaes_round_constants[ round_constant_index ];
round_keys[ 4 ] ^= round_keys[ 0 ];
round_keys[ 4 ] ^= (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 3 ] >> 8 ) & 0xff ];
round_keys[ 4 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 3 ] >> 16 ) & 0xff ] ) << 8;
round_keys[ 4 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 3 ] >> 24 ) & 0xff ] ) << 16;
round_keys[ 4 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 3 ] ) & 0xff ] ) << 24;
round_keys[ 5 ] = round_keys[ 1 ] ^ round_keys[ 4 ];
round_keys[ 6 ] = round_keys[ 2 ] ^ round_keys[ 5 ];
round_keys[ 7 ] = round_keys[ 3 ] ^ round_keys[ 6 ];
round_keys += 4;
}
}
else if( key_bit_size == 192 )
{
internal_context->number_of_round_keys = 12;
for( round_constant_index = 0;
round_constant_index < 8;
round_constant_index++ )
{
round_keys[ 6 ] = libcaes_round_constants[ round_constant_index ];
round_keys[ 6 ] ^= round_keys[ 0 ];
round_keys[ 6 ] ^= (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 5 ] >> 8 ) & 0xff ];
round_keys[ 6 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 5 ] >> 16 ) & 0xff ] ) << 8;
round_keys[ 6 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 5 ] >> 24 ) & 0xff ] ) << 16;
round_keys[ 6 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 5 ] ) & 0xff ] ) << 24;
round_keys[ 7 ] = round_keys[ 1 ] ^ round_keys[ 6 ];
round_keys[ 8 ] = round_keys[ 2 ] ^ round_keys[ 7 ];
round_keys[ 9 ] = round_keys[ 3 ] ^ round_keys[ 8 ];
round_keys[ 10 ] = round_keys[ 4 ] ^ round_keys[ 9 ];
round_keys[ 11 ] = round_keys[ 5 ] ^ round_keys[ 10 ];
round_keys += 6;
}
}
else if( key_bit_size == 256 )
{
internal_context->number_of_round_keys = 14;
for( round_constant_index = 0;
round_constant_index < 7;
round_constant_index++ )
{
round_keys[ 8 ] = libcaes_round_constants[ round_constant_index ];
round_keys[ 8 ] ^= round_keys[ 0 ];
round_keys[ 8 ] ^= (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 7 ] >> 8 ) & 0xff ];
round_keys[ 8 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 7 ] >> 16 ) & 0xff ] ) << 8;
round_keys[ 8 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 7 ] >> 24 ) & 0xff ] ) << 16;
round_keys[ 8 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 7 ] ) & 0xff ] ) << 24;
round_keys[ 9 ] = round_keys[ 1 ] ^ round_keys[ 8 ];
round_keys[ 10 ] = round_keys[ 2 ] ^ round_keys[ 9 ];
round_keys[ 11 ] = round_keys[ 3 ] ^ round_keys[ 10 ];
round_keys[ 12 ] = round_keys[ 4 ];
round_keys[ 12 ] ^= (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 11 ] ) & 0xff ];
round_keys[ 12 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 11 ] >> 8 ) & 0xff ] ) << 8;
round_keys[ 12 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 11 ] >> 16 ) & 0xff ] ) << 16;
round_keys[ 12 ] ^= ( (uint32_t) libcaes_forward_substitution_box[ ( round_keys[ 11 ] >> 24 ) & 0xff ] ) << 24;
round_keys[ 13 ] = round_keys[ 5 ] ^ round_keys[ 12 ];
round_keys[ 14 ] = round_keys[ 6 ] ^ round_keys[ 13 ];
round_keys[ 15 ] = round_keys[ 7 ] ^ round_keys[ 14 ];
round_keys += 8;
}
}
return( 1 );
}
#endif /* !defined( LIBCAES_HAVE_AES_SUPPORT ) */
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && defined( HAVE_AES_CBC_ENCRYPT )
/* De- or encrypts a block of data using AES-CBC (Cipher Block Chaining) using OpenSSL
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_cbc(
libcaes_context_t *context,
int mode,
const uint8_t *initialization_vector,
size_t initialization_vector_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t safe_initialization_vector[ 16 ];
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_crypt_cbc";
int safe_mode = 0;
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
internal_context = (libcaes_internal_context_t *) context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( initialization_vector == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid initialization vector.",
function );
return( -1 );
}
if( initialization_vector_size != 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid initialization vector size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
/* Check if the input data size is a multitude of 16-byte
*/
if( ( ( input_data_size & (size_t) 0x0f ) != 0 )
|| ( input_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
safe_mode = AES_ENCRYPT;
}
else
{
safe_mode = AES_DECRYPT;
}
/* AES_cbc_encrypt overwrites the data in the initialization vector
*/
if( memory_copy(
safe_initialization_vector,
initialization_vector,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy initialization vector.",
function );
return( -1 );
}
AES_cbc_encrypt(
(unsigned char *) input_data,
(unsigned char *) output_data,
input_data_size,
&( internal_context->key ),
(unsigned char *) safe_initialization_vector,
safe_mode );
if( memory_set(
safe_initialization_vector,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear initialization vector.",
function );
return( -1 );
}
return( 1 );
}
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_CBC )
/* De- or encrypts a block of data using AES-CBC (Cipher Block Chaining) using OpenSSL EVP
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_cbc(
libcaes_context_t *context,
int mode,
const uint8_t *initialization_vector,
size_t initialization_vector_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t block_data[ EVP_MAX_BLOCK_LENGTH ];
char error_string[ 256 ];
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
OSSL_PARAM parameters[2];
EVP_CIPHER *cipher = NULL;
const char *cipher_string = NULL;
unsigned int padding = 0;
#else
const EVP_CIPHER *cipher = NULL;
#endif
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_crypt_cbc";
unsigned long error_code = 0;
int safe_output_data_size = 0;
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
internal_context = (libcaes_internal_context_t *) context;
if( ( internal_context->key_bit_size != 128 )
&& ( internal_context->key_bit_size != 192 )
&& ( internal_context->key_bit_size != 256 ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: invalid context - unsupported key bit size.",
function );
return( -1 );
}
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( initialization_vector == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid initialization vector.",
function );
return( -1 );
}
if( initialization_vector_size != 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid initialization vector size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
/* Check if the input data size is a multitude of 16-byte
*/
if( ( ( input_data_size & (size_t) 0x0f ) != 0 )
|| ( input_data_size > (size_t) INT_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) INT_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
if( memory_set(
block_data,
0,
EVP_MAX_BLOCK_LENGTH ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear input block data.",
function );
goto on_error;
}
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
if( EVP_CIPHER_CTX_reset(
internal_context->evp_cipher_context ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to reset cipher context with error: %s.",
function,
error_string );
goto on_error;
}
if( internal_context->key_bit_size == 128 )
{
cipher_string = "AES-128-CBC";
}
else if( internal_context->key_bit_size == 192 )
{
cipher_string = "AES-192-CBC";
}
else if( internal_context->key_bit_size == 256 )
{
cipher_string = "AES-256-CBC";
}
cipher = EVP_CIPHER_fetch(
NULL,
cipher_string,
NULL );
if( cipher == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: missing cipher.",
function );
goto on_error;
}
parameters[0] = OSSL_PARAM_construct_uint(
OSSL_CIPHER_PARAM_PADDING,
&padding );
parameters[1] = OSSL_PARAM_construct_end();
if( EVP_CipherInit_ex2(
internal_context->evp_cipher_context,
cipher,
(unsigned char *) internal_context->key,
(unsigned char *) initialization_vector,
mode,
parameters ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize cipher with error: %s.",
function,
error_string );
goto on_error;
}
#else
if( internal_context->key_bit_size == 128 )
{
cipher = EVP_aes_128_cbc();
}
else if( internal_context->key_bit_size == 192 )
{
cipher = EVP_aes_192_cbc();
}
else if( internal_context->key_bit_size == 256 )
{
cipher = EVP_aes_256_cbc();
}
if( EVP_CipherInit_ex(
internal_context->evp_cipher_context,
cipher,
NULL,
(unsigned char *) internal_context->key,
(unsigned char *) initialization_vector,
mode ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize cipher with error: %s.",
function,
error_string );
goto on_error;
}
if( EVP_CIPHER_CTX_set_padding(
internal_context->evp_cipher_context,
1 ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set padding in context with error: %s.",
function,
error_string );
goto on_error;
}
#endif /* defined( HAVE_EVP_CIPHERINIT_EX2 ) */
if( EVP_CipherUpdate(
internal_context->evp_cipher_context,
(unsigned char *) output_data,
&safe_output_data_size,
(unsigned char *) input_data,
input_data_size ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to update cipher with error: %s.",
function,
error_string );
goto on_error;
}
/* Just ignore the output of this function
*/
EVP_CipherFinal_ex(
internal_context->evp_cipher_context,
(unsigned char *) block_data,
&safe_output_data_size );
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
EVP_CIPHER_free(
cipher );
#endif
return( 1 );
on_error:
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
if( cipher != NULL )
{
EVP_CIPHER_free(
cipher );
}
#endif
return( -1 );
}
#else
/* De- or encrypts a block of data using AES-CBC (Cipher Block Chaining) using fallback implementation
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_cbc(
libcaes_context_t *context,
int mode,
const uint8_t *initialization_vector,
size_t initialization_vector_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t internal_initialization_vector[ 16 ];
static char *function = "libcaes_crypt_cbc";
size_t data_offset = 0;
#if !defined( LIBCAES_UNFOLLED_LOOPS )
uint8_t block_index = 0;
#endif
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( initialization_vector == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid initialization vector.",
function );
return( -1 );
}
if( initialization_vector_size != 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid initialization vector size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
/* Check if the input data size is a multitude of 16-byte
*/
if( ( ( input_data_size & (size_t) 0x0f ) != 0 )
|| ( input_data_size < 16 )
|| ( input_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value of bounds.",
function );
return( -1 );
}
if( memory_copy(
internal_initialization_vector,
initialization_vector,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy initialization vector.",
function );
goto on_error;
}
if( ( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
&& ( output_data != input_data ) )
{
if( memory_copy(
output_data,
input_data,
input_data_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy input data to output data.",
function );
goto on_error;
}
}
while( data_offset <= ( input_data_size - 16 ) )
{
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= internal_initialization_vector[ 0 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 1 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 2 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 3 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 4 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 5 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 6 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 7 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 8 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 9 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 10 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 11 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 12 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 13 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 14 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= internal_initialization_vector[ block_index ];
}
#endif
data_offset -= 16;
if( libcaes_crypt_ecb(
context,
LIBCAES_CRYPT_MODE_ENCRYPT,
&( output_data[ data_offset ] ),
16,
&( output_data[ data_offset ] ),
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_ENCRYPT_FAILED,
"%s: unable to encrypt output data.",
function );
goto on_error;
}
if( memory_copy(
internal_initialization_vector,
&( output_data[ data_offset ] ),
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy enrypted output data to initialization vector.",
function );
goto on_error;
}
}
else
{
if( libcaes_crypt_ecb(
context,
LIBCAES_CRYPT_MODE_DECRYPT,
&( input_data[ data_offset ] ),
16,
&( output_data[ data_offset ] ),
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_GENERIC,
"%s: unable to decrypt output data.",
function );
goto on_error;
}
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= internal_initialization_vector[ 0 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 1 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 2 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 3 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 4 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 5 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 6 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 7 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 8 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 9 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 10 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 11 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 12 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 13 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 14 ];
output_data[ data_offset++ ] ^= internal_initialization_vector[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= internal_initialization_vector[ block_index ];
}
#endif
data_offset -= 16;
if( memory_copy(
internal_initialization_vector,
&( input_data[ data_offset ] ),
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy enrypted input data to initialization vector.",
function );
goto on_error;
}
}
data_offset += 16;
}
if( memory_set(
internal_initialization_vector,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear initialization vector.",
function );
goto on_error;
}
return( 1 );
on_error:
memory_set(
internal_initialization_vector,
0,
16 );
return( -1 );
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && defined( HAVE_AES_CBC_ENCRYPT ) */
/* De- or encrypts a block of data using AES-CCM (Counter with CBC-MAC)
* Note that the key must be set in encryption mode (LIBCAES_CRYPT_MODE_ENCRYPT) for both de- and encryption.
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_ccm(
libcaes_context_t *context,
int mode,
const uint8_t *nonce,
size_t nonce_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t block_data[ 16 ];
uint8_t internal_initialization_vector[ 16 ];
static char *function = "libcaes_crypt_ccm";
size_t data_offset = 0;
size_t remaining_data_size = 0;
uint8_t block_index = 0;
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( nonce == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid nonce.",
function );
return( -1 );
}
if( nonce_size >= (size_t) 15 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid nonce size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
if( ( input_data_size < 16 )
|| ( input_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
/* The IV consists of:
* 1 byte size value formatted as: 15 - nonce size - 1
* a maximum of 14 bytes containing nonce bytes
* 1 byte counter
*/
if( memory_set(
internal_initialization_vector,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear initialization vector.",
function );
goto on_error;
}
if( memory_copy(
&( internal_initialization_vector[ 1 ] ),
nonce,
nonce_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy nonce to initialization vector.",
function );
goto on_error;
}
internal_initialization_vector[ 0 ] = 15 - (uint8_t) nonce_size - 1;
if( memory_copy(
output_data,
input_data,
input_data_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy input data to output data.",
function );
goto on_error;
}
while( data_offset <= ( input_data_size - 16 ) )
{
if( libcaes_crypt_ecb(
context,
LIBCAES_CRYPT_MODE_ENCRYPT,
internal_initialization_vector,
16,
block_data,
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_ENCRYPT_FAILED,
"%s: unable to encrypt initialization vector.",
function );
goto on_error;
}
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= block_data[ 0 ];
output_data[ data_offset++ ] ^= block_data[ 1 ];
output_data[ data_offset++ ] ^= block_data[ 2 ];
output_data[ data_offset++ ] ^= block_data[ 3 ];
output_data[ data_offset++ ] ^= block_data[ 4 ];
output_data[ data_offset++ ] ^= block_data[ 5 ];
output_data[ data_offset++ ] ^= block_data[ 6 ];
output_data[ data_offset++ ] ^= block_data[ 7 ];
output_data[ data_offset++ ] ^= block_data[ 8 ];
output_data[ data_offset++ ] ^= block_data[ 9 ];
output_data[ data_offset++ ] ^= block_data[ 10 ];
output_data[ data_offset++ ] ^= block_data[ 11 ];
output_data[ data_offset++ ] ^= block_data[ 12 ];
output_data[ data_offset++ ] ^= block_data[ 13 ];
output_data[ data_offset++ ] ^= block_data[ 14 ];
output_data[ data_offset++ ] ^= block_data[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= block_data[ block_index ];
}
#endif
internal_initialization_vector[ 15 ] += 1;
}
if( data_offset < input_data_size )
{
remaining_data_size = input_data_size - data_offset;
if( libcaes_crypt_ecb(
context,
LIBCAES_CRYPT_MODE_ENCRYPT,
internal_initialization_vector,
16,
block_data,
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_ENCRYPT_FAILED,
"%s: unable to encrypt initialization vector.",
function );
goto on_error;
}
for( block_index = 0;
block_index < (uint8_t) remaining_data_size;
block_index++ )
{
output_data[ data_offset++ ] ^= block_data[ block_index ];
}
}
if( memory_set(
block_data,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear block data.",
function );
goto on_error;
}
if( memory_set(
internal_initialization_vector,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear initialization vector.",
function );
goto on_error;
}
return( 1 );
on_error:
memory_set(
block_data,
0,
16 );
memory_set(
internal_initialization_vector,
0,
16 );
return( -1 );
}
/* De- or encrypts a block of data using AES-CFB (Cipher Feedback Mode)
* Note that the key must be set with mode LIBCAES_CRYPT_MODE_ENCRYPT
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_cfb(
libcaes_context_t *context,
int mode,
const uint8_t *initialization_vector,
size_t initialization_vector_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t internal_initialization_vector[ 16 ];
static char *function = "libcaes_crypt_cfb";
size_t data_offset = 0;
size_t initialization_vector_index = 0;
uint8_t byte_value = 0;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( initialization_vector == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid initialization vector.",
function );
return( -1 );
}
if( initialization_vector_size != 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid initialization vector size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
/* Check if the input data size is a multitude of 16-byte
*/
if( ( ( input_data_size & (size_t) 0x0f ) != 0 )
|| ( input_data_size < 16 )
|| ( input_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
if( memory_copy(
internal_initialization_vector,
initialization_vector,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy initialization vector.",
function );
goto on_error;
}
initialization_vector_index = 16;
for( data_offset = 0;
data_offset < input_data_size;
data_offset++ )
{
if( initialization_vector_index > 15 )
{
if( libcaes_crypt_ecb(
context,
LIBCAES_CRYPT_MODE_ENCRYPT,
internal_initialization_vector,
initialization_vector_size,
internal_initialization_vector,
initialization_vector_size,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_GENERIC,
"%s: unable to de/encrypt initialization vector.",
function );
goto on_error;
}
initialization_vector_index = 0;
}
output_data[ data_offset ] = input_data[ data_offset ] ^ internal_initialization_vector[ initialization_vector_index ];
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
byte_value = output_data[ data_offset ];
}
else
{
byte_value = input_data[ data_offset ];
}
internal_initialization_vector[ initialization_vector_index++ ] = byte_value;
}
if( memory_set(
internal_initialization_vector,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear initialization vector.",
function );
goto on_error;
}
return( 1 );
on_error:
memory_set(
internal_initialization_vector,
0,
16 );
return( -1 );
}
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && defined( HAVE_AES_ECB_ENCRYPT )
/* De- or encrypts a block of data using AES-ECB (Electronic CodeBook) using OpenSSL
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_ecb(
libcaes_context_t *context,
int mode,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_crypt_ecb";
int result = 1;
int safe_mode = 0;
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
internal_context = (libcaes_internal_context_t *) context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
if( ( input_data_size < 16 )
|| ( input_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
safe_mode = AES_ENCRYPT;
}
else
{
safe_mode = AES_DECRYPT;
}
AES_ecb_encrypt(
(unsigned char *) input_data,
(unsigned char *) output_data,
&( internal_context->key ),
safe_mode );
return( result );
}
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_ECB )
/* De- or encrypts a block of data using AES-ECB (Electronic CodeBook) using OpenSSL EVP
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_ecb(
libcaes_context_t *context,
int mode,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t block_data[ EVP_MAX_BLOCK_LENGTH ];
char error_string[ 256 ];
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
OSSL_PARAM parameters[2];
EVP_CIPHER *cipher = NULL;
const char *cipher_string = NULL;
unsigned int padding = 0;
#else
const EVP_CIPHER *cipher = NULL;
#endif
libcaes_internal_context_t *internal_context = NULL;
static char *function = "libcaes_crypt_ecb";
unsigned long error_code = 0;
int safe_output_data_size = 0;
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
internal_context = (libcaes_internal_context_t *) context;
if( ( internal_context->key_bit_size != 128 )
&& ( internal_context->key_bit_size != 192 )
&& ( internal_context->key_bit_size != 256 ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: invalid context - unsupported key bit size.",
function );
return( -1 );
}
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
if( ( input_data_size < 16 )
|| ( input_data_size > (size_t) INT_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) INT_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
if( memory_set(
block_data,
0,
EVP_MAX_BLOCK_LENGTH ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear block data.",
function );
goto on_error;
}
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
if( EVP_CIPHER_CTX_reset(
internal_context->evp_cipher_context ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to reset cipher context with error: %s.",
function,
error_string );
goto on_error;
}
if( internal_context->key_bit_size == 128 )
{
cipher_string = "AES-128-ECB";
}
else if( internal_context->key_bit_size == 192 )
{
cipher_string = "AES-192-ECB";
}
else if( internal_context->key_bit_size == 256 )
{
cipher_string = "AES-256-ECB";
}
cipher = EVP_CIPHER_fetch(
NULL,
cipher_string,
NULL );
if( cipher == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: missing cipher.",
function );
goto on_error;
}
parameters[0] = OSSL_PARAM_construct_uint(
OSSL_CIPHER_PARAM_PADDING,
&padding );
parameters[1] = OSSL_PARAM_construct_end();
if( EVP_CipherInit_ex2(
internal_context->evp_cipher_context,
cipher,
(unsigned char *) internal_context->key,
NULL,
mode,
parameters ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize cipher with error: %s.",
function,
error_string );
goto on_error;
}
#else
if( internal_context->key_bit_size == 128 )
{
cipher = EVP_aes_128_ecb();
}
else if( internal_context->key_bit_size == 192 )
{
cipher = EVP_aes_192_ecb();
}
else if( internal_context->key_bit_size == 256 )
{
cipher = EVP_aes_256_ecb();
}
if( EVP_CipherInit_ex(
internal_context->evp_cipher_context,
cipher,
NULL,
(unsigned char *) internal_context->key,
NULL,
mode ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize cipher with error: %s.",
function,
error_string );
goto on_error;
}
if( EVP_CIPHER_CTX_set_padding(
internal_context->evp_cipher_context,
1 ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set padding in context with error: %s.",
function,
error_string );
goto on_error;
}
#endif /* defined( HAVE_EVP_CIPHERINIT_EX2 ) */
if( EVP_CipherUpdate(
internal_context->evp_cipher_context,
(unsigned char *) output_data,
&safe_output_data_size,
(unsigned char *) input_data,
16 ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to update cipher with error: %s.",
function,
error_string );
goto on_error;
}
/* Just ignore the output of this function
*/
EVP_CipherFinal_ex(
internal_context->evp_cipher_context,
(unsigned char *) block_data,
&safe_output_data_size );
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
EVP_CIPHER_free(
cipher );
#endif
return( 1 );
on_error:
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
if( cipher != NULL )
{
EVP_CIPHER_free(
cipher );
}
#endif
return( -1 );
}
#else
/* De- or encrypts a block of data using AES-ECB (Electronic CodeBook) using fallback implementation
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_ecb(
libcaes_context_t *context,
int mode,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint32_t cipher_values_32bit[ 4 ];
uint32_t values_32bit[ 4 ];
libcaes_internal_context_t *internal_context = NULL;
uint32_t *round_keys = NULL;
static char *function = "libcaes_crypt_ecb";
size_t data_offset = 0;
uint32_t substitution_value = 0;
uint32_t table_value = 0;
int result = 1;
int round_key_iterator = 0;
if( context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid context.",
function );
return( -1 );
}
internal_context = (libcaes_internal_context_t *) context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
/* Check if the input data size is a multitude of 16-byte
*/
if( ( ( input_data_size & (size_t) 0x0f ) != 0 )
|| ( input_data_size < 16 )
|| ( input_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid input data size value out of bounds.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( ( output_data_size < input_data_size )
|| ( output_data_size > (size_t) SSIZE_MAX ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid output data size value out of bounds.",
function );
return( -1 );
}
while( data_offset < input_data_size )
{
byte_stream_copy_to_uint32_little_endian(
&( input_data[ data_offset ] ),
values_32bit[ 0 ] );
byte_stream_copy_to_uint32_little_endian(
&( input_data[ data_offset + 4 ] ),
values_32bit[ 1 ] );
byte_stream_copy_to_uint32_little_endian(
&( input_data[ data_offset + 8 ] ),
values_32bit[ 2 ] );
byte_stream_copy_to_uint32_little_endian(
&( input_data[ data_offset + 12 ] ),
values_32bit[ 3 ] );
round_keys = internal_context->round_keys;
values_32bit[ 0 ] ^= round_keys[ 0 ];
values_32bit[ 1 ] ^= round_keys[ 1 ];
values_32bit[ 2 ] ^= round_keys[ 2 ];
values_32bit[ 3 ] ^= round_keys[ 3 ];
round_keys += 4;
if( mode == LIBCAES_CRYPT_MODE_ENCRYPT )
{
for( round_key_iterator = ( internal_context->number_of_round_keys / 2 );
round_key_iterator > 1;
round_key_iterator-- )
{
libcaes_calculate_forward_table_round(
round_keys,
cipher_values_32bit,
values_32bit,
table_value );
round_keys += 4;
libcaes_calculate_forward_table_round(
round_keys,
values_32bit,
cipher_values_32bit,
table_value );
round_keys += 4;
}
libcaes_calculate_forward_table_round(
round_keys,
cipher_values_32bit,
values_32bit,
table_value );
round_keys += 4;
libcaes_calculate_forward_substitution_round(
round_keys,
values_32bit,
cipher_values_32bit,
substitution_value );
}
else
{
for( round_key_iterator = ( internal_context->number_of_round_keys / 2 );
round_key_iterator > 1;
round_key_iterator-- )
{
libcaes_calculate_reverse_table_round(
round_keys,
cipher_values_32bit,
values_32bit,
table_value );
round_keys += 4;
libcaes_calculate_reverse_table_round(
round_keys,
values_32bit,
cipher_values_32bit,
table_value );
round_keys += 4;
}
libcaes_calculate_reverse_table_round(
round_keys,
cipher_values_32bit,
values_32bit,
table_value );
round_keys += 4;
libcaes_calculate_reverse_substitution_round(
round_keys,
values_32bit,
cipher_values_32bit,
table_value );
}
byte_stream_copy_from_uint32_little_endian(
&( output_data[ data_offset ] ),
values_32bit[ 0 ] );
byte_stream_copy_from_uint32_little_endian(
&( output_data[ data_offset + 4 ] ),
values_32bit[ 1 ] );
byte_stream_copy_from_uint32_little_endian(
&( output_data[ data_offset + 8 ] ),
values_32bit[ 2 ] );
byte_stream_copy_from_uint32_little_endian(
&( output_data[ data_offset + 12 ] ),
values_32bit[ 3 ] );
if( memory_set(
values_32bit,
0,
sizeof( uint32_t ) * 4 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear values 32-bit.",
function );
result = -1;
}
if( memory_set(
cipher_values_32bit,
0,
sizeof( uint32_t ) * 4 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear cipher values 32-bit.",
function );
result = -1;
}
data_offset += 16;
}
return( result );
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H ) && defined( HAVE_AES_ECB_ENCRYPT ) */
libcaes-20240413/libcaes/libcaes_definitions.h 0000644 0001750 0001750 00000003317 14606477645 022012 0 ustar 00lordyesta lordyesta /*
* The internal definitions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( LIBCAES_INTERNAL_DEFINITIONS_H )
#define LIBCAES_INTERNAL_DEFINITIONS_H
#include
#include
/* Define HAVE_LOCAL_LIBCAES for local use of libcaes
*/
#if !defined( HAVE_LOCAL_LIBCAES )
#include
/* The definitions in are copied here
* for local use of libcaes
*/
#else
#define LIBCAES_VERSION 20240413
/* The libcaes version string
*/
#define LIBCAES_VERSION_STRING "20240413"
/* The crypt modes
*/
enum LIBCAES_CRYPT_MODES
{
LIBCAES_CRYPT_MODE_DECRYPT = 0,
LIBCAES_CRYPT_MODE_ENCRYPT = 1
};
#endif /* !defined( HAVE_LOCAL_LIBCAES ) */
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H )
#define LIBCAES_HAVE_AES_SUPPORT
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H )
#define LIBCAES_HAVE_AES_SUPPORT
#endif
#define LIBCAES_UNFOLLED_LOOPS
#endif /* !defined( LIBCAES_INTERNAL_DEFINITIONS_H ) */
libcaes-20240413/libcaes/libcaes.rc 0000644 0001750 0001750 00000002063 14606477645 017571 0 ustar 00lordyesta lordyesta #include
#ifdef GCC_WINDRES
VS_VERSION_INFO VERSIONINFO
#else
VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
#endif
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "FileDescription", "Library to support cross-platform AES encryption\0"
VALUE "FileVersion", "20240413" "\0"
VALUE "InternalName", "libcaes.dll\0"
VALUE "LegalCopyright", "(C) 2011-2024, Joachim Metz \0"
VALUE "OriginalFilename", "libcaes.dll\0"
VALUE "ProductName", "libcaes\0"
VALUE "ProductVersion", "20240413" "\0"
VALUE "Comments", "For more information visit https://github.com/libyal/libcaes/\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
libcaes-20240413/libcaes/Makefile.am 0000644 0001750 0001750 00000001736 14606475165 017676 0 ustar 00lordyesta lordyesta AM_CPPFLAGS = \
-I../include -I$(top_srcdir)/include \
-I../common -I$(top_srcdir)/common \
@LIBCERROR_CPPFLAGS@ \
@LIBCRYPTO_CPPFLAGS@ \
@LIBCAES_DLL_EXPORT@
lib_LTLIBRARIES = libcaes.la
libcaes_la_SOURCES = \
libcaes.c \
libcaes_context.c libcaes_context.h \
libcaes_definitions.h \
libcaes_extern.h \
libcaes_error.c libcaes_error.h \
libcaes_libcerror.h \
libcaes_support.c libcaes_support.h \
libcaes_tweaked_context.c libcaes_tweaked_context.h \
libcaes_types.h \
libcaes_unused.h
libcaes_la_LIBADD = \
@LIBCERROR_LIBADD@ \
@LIBCRYPTO_LIBADD@ \
@LIBDL_LIBADD@
libcaes_la_LDFLAGS = -no-undefined -version-info 1:0:0
EXTRA_DIST = \
libcaes_definitions.h.in \
libcaes.rc \
libcaes.rc.in
DISTCLEANFILES = \
libcaes_definitions.h \
libcaes.rc \
Makefile \
Makefile.in
sources-local: $(BUILT_SOURCES)
splint-local:
@echo "Running splint on libcaes ..."
-splint -preproc -redef $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(libcaes_la_SOURCES)
libcaes-20240413/libcaes/libcaes_definitions.h.in 0000644 0001750 0001750 00000003321 14606473412 022376 0 ustar 00lordyesta lordyesta /*
* The internal definitions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( LIBCAES_INTERNAL_DEFINITIONS_H )
#define LIBCAES_INTERNAL_DEFINITIONS_H
#include
#include
/* Define HAVE_LOCAL_LIBCAES for local use of libcaes
*/
#if !defined( HAVE_LOCAL_LIBCAES )
#include
/* The definitions in are copied here
* for local use of libcaes
*/
#else
#define LIBCAES_VERSION @VERSION@
/* The libcaes version string
*/
#define LIBCAES_VERSION_STRING "@VERSION@"
/* The crypt modes
*/
enum LIBCAES_CRYPT_MODES
{
LIBCAES_CRYPT_MODE_DECRYPT = 0,
LIBCAES_CRYPT_MODE_ENCRYPT = 1
};
#endif /* !defined( HAVE_LOCAL_LIBCAES ) */
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_AES_H )
#define LIBCAES_HAVE_AES_SUPPORT
#elif defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H )
#define LIBCAES_HAVE_AES_SUPPORT
#endif
#define LIBCAES_UNFOLLED_LOOPS
#endif /* !defined( LIBCAES_INTERNAL_DEFINITIONS_H ) */
libcaes-20240413/libcaes/libcaes_error.h 0000644 0001750 0001750 00000003354 14606473412 020615 0 ustar 00lordyesta lordyesta /*
* Error functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_INTERNAL_ERROR_H )
#define _LIBCAES_INTERNAL_ERROR_H
#include
#include
#include
#if !defined( HAVE_LOCAL_LIBCAES )
#include
#endif
#include "libcaes_extern.h"
#if defined( __cplusplus )
extern "C" {
#endif
#if !defined( HAVE_LOCAL_LIBCAES )
LIBCAES_EXTERN \
void libcaes_error_free(
libcaes_error_t **error );
LIBCAES_EXTERN \
int libcaes_error_fprint(
libcaes_error_t *error,
FILE *stream );
LIBCAES_EXTERN \
int libcaes_error_sprint(
libcaes_error_t *error,
char *string,
size_t size );
LIBCAES_EXTERN \
int libcaes_error_backtrace_fprint(
libcaes_error_t *error,
FILE *stream );
LIBCAES_EXTERN \
int libcaes_error_backtrace_sprint(
libcaes_error_t *error,
char *string,
size_t size );
#endif /* !defined( HAVE_LOCAL_LIBCAES ) */
#if defined( __cplusplus )
}
#endif
#endif /* !defined( _LIBCAES_INTERNAL_ERROR_H ) */
libcaes-20240413/libcaes/libcaes_types.h 0000644 0001750 0001750 00000003110 14606473412 020616 0 ustar 00lordyesta lordyesta /*
* The internal type definitions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_INTERNAL_TYPES_H )
#define _LIBCAES_INTERNAL_TYPES_H
#include
#include
/* Define HAVE_LOCAL_LIBCAES for local use of libcaes
* The definitions in are copied here
* for local use of libcaes
*/
#if defined( HAVE_LOCAL_LIBCAES )
/* The following type definitions hide internal data structures
*/
#if defined( HAVE_DEBUG_OUTPUT ) && !defined( WINAPI )
typedef struct libcaes_context {} libcaes_context_t;
typedef struct libcaes_tweaked_context {} libcaes_tweaked_context_t;
#else
typedef intptr_t libcaes_context_t;
typedef intptr_t libcaes_tweaked_context_t;
#endif /* defined( HAVE_DEBUG_OUTPUT ) && !defined( WINAPI ) */
#endif /* defined( HAVE_LOCAL_LIBCAES ) */
#endif /* !defined( _LIBCAES_INTERNAL_TYPES_H ) */
libcaes-20240413/libcaes/libcaes_extern.h 0000644 0001750 0001750 00000002540 14606473412 020765 0 ustar 00lordyesta lordyesta /*
* The internal extern definition
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_INTERNAL_EXTERN_H )
#define _LIBCAES_INTERNAL_EXTERN_H
#include
/* Define HAVE_LOCAL_LIBCAES for local use of libcaes
*/
#if !defined( HAVE_LOCAL_LIBCAES )
#include
#if defined( __CYGWIN__ ) || defined( __MINGW32__ )
#define LIBCAES_EXTERN_VARIABLE extern
#else
#define LIBCAES_EXTERN_VARIABLE LIBCAES_EXTERN
#endif
#else
#define LIBCAES_EXTERN /* extern */
#define LIBCAES_EXTERN_VARIABLE extern
#endif /* !defined( HAVE_LOCAL_LIBCAES ) */
#endif /* !defined( _LIBCAES_INTERNAL_EXTERN_H ) */
libcaes-20240413/libcaes/libcaes_support.h 0000644 0001750 0001750 00000002241 14606473412 021172 0 ustar 00lordyesta lordyesta /*
* Support functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_SUPPORT_H )
#define _LIBCAES_SUPPORT_H
#include
#include
#include "libcaes_extern.h"
#if defined( __cplusplus )
extern "C" {
#endif
#if !defined( HAVE_LOCAL_LIBCAES )
LIBCAES_EXTERN \
const char *libcaes_get_version(
void );
#endif
#if defined( __cplusplus )
}
#endif
#endif /* !defined( _LIBCAES_SUPPORT_H ) */
libcaes-20240413/libcaes/libcaes.rc.in 0000644 0001750 0001750 00000002065 14606473412 020164 0 ustar 00lordyesta lordyesta #include
#ifdef GCC_WINDRES
VS_VERSION_INFO VERSIONINFO
#else
VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE
#endif
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "FileDescription", "Library to support cross-platform AES encryption\0"
VALUE "FileVersion", "@VERSION@" "\0"
VALUE "InternalName", "libcaes.dll\0"
VALUE "LegalCopyright", "(C) 2011-2024, Joachim Metz \0"
VALUE "OriginalFilename", "libcaes.dll\0"
VALUE "ProductName", "libcaes\0"
VALUE "ProductVersion", "@VERSION@" "\0"
VALUE "Comments", "For more information visit https://github.com/libyal/libcaes/\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1200
END
END
libcaes-20240413/libcaes/libcaes_libcerror.h 0000644 0001750 0001750 00000002633 14606473412 021446 0 ustar 00lordyesta lordyesta /*
* The libcerror header wrapper
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#if !defined( _LIBCAES_LIBCERROR_H )
#define _LIBCAES_LIBCERROR_H
#include
/* Define HAVE_LOCAL_LIBCERROR for local use of libcerror
*/
#if defined( HAVE_LOCAL_LIBCERROR )
#include
#include
#include
#include
#else
/* If libtool DLL support is enabled set LIBCERROR_DLL_IMPORT
* before including libcerror.h
*/
#if defined( _WIN32 ) && defined( DLL_IMPORT )
#define LIBCERROR_DLL_IMPORT
#endif
#include
#endif /* defined( HAVE_LOCAL_LIBCERROR ) */
#endif /* !defined( _LIBCAES_LIBCERROR_H ) */
libcaes-20240413/libcaes/libcaes_support.c 0000644 0001750 0001750 00000002125 14606473412 021166 0 ustar 00lordyesta lordyesta /*
* Support functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#include
#include
#include "libcaes_definitions.h"
#include "libcaes_support.h"
#if !defined( HAVE_LOCAL_LIBCAES )
/* Returns the library version as a string
*/
const char *libcaes_get_version(
void )
{
return( (const char *) LIBCAES_VERSION_STRING );
}
#endif
libcaes-20240413/libcaes/Makefile.in 0000644 0001750 0001750 00000062564 14606477627 017722 0 ustar 00lordyesta lordyesta # Makefile.in generated by automake 1.16.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2021 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
false; \
elif test -n '$(MAKE_HOST)'; then \
true; \
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
true; \
else \
false; \
fi; \
}
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = libcaes
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/common.m4 \
$(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/host-cpu-c-abi.m4 \
$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/intlmacosx.m4 \
$(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \
$(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libcerror.m4 \
$(top_srcdir)/m4/libcrypto.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/m4/python.m4 \
$(top_srcdir)/m4/tests.m4 $(top_srcdir)/m4/types.m4 \
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/common/config.h
CONFIG_CLEAN_FILES = libcaes_definitions.h libcaes.rc
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
am__install_max = 40
am__nobase_strip_setup = \
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
am__nobase_strip = \
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
am__nobase_list = $(am__nobase_strip_setup); \
for p in $$list; do echo "$$p $$p"; done | \
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
if (++n[$$2] == $(am__install_max)) \
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
END { for (dir in files) print dir, files[dir] }'
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libcaes_la_DEPENDENCIES =
am_libcaes_la_OBJECTS = libcaes.lo libcaes_context.lo libcaes_error.lo \
libcaes_support.lo libcaes_tweaked_context.lo
libcaes_la_OBJECTS = $(am_libcaes_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
libcaes_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libcaes_la_LDFLAGS) $(LDFLAGS) -o $@
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/common
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/libcaes.Plo \
./$(DEPDIR)/libcaes_context.Plo ./$(DEPDIR)/libcaes_error.Plo \
./$(DEPDIR)/libcaes_support.Plo \
./$(DEPDIR)/libcaes_tweaked_context.Plo
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(libcaes_la_SOURCES)
DIST_SOURCES = $(libcaes_la_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__extra_recursive_targets = sources-recursive splint-recursive
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '\
BEGIN { nonempty = 0; } \
{ items[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in items) print i; }; } \
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files = \
list='$(am__tagged_files)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/libcaes.rc.in \
$(srcdir)/libcaes_definitions.h.in $(top_srcdir)/depcomp
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CSCOPE = @CSCOPE@
CTAGS = @CTAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DPKG_DATE = @DPKG_DATE@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
FILECMD = @FILECMD@
GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
GREP = @GREP@
HAVE_DLLMAIN = @HAVE_DLLMAIN@
HAVE_INTTYPES_H = @HAVE_INTTYPES_H@
HAVE_LIBCERROR = @HAVE_LIBCERROR@
HAVE_LOCAL_LIBCERROR = @HAVE_LOCAL_LIBCERROR@
HAVE_OFF64_T = @HAVE_OFF64_T@
HAVE_OPENSSL_EVP_H = @HAVE_OPENSSL_EVP_H@
HAVE_SIZE32_T = @HAVE_SIZE32_T@
HAVE_SIZE64_T = @HAVE_SIZE64_T@
HAVE_SSIZE32_T = @HAVE_SSIZE32_T@
HAVE_SSIZE64_T = @HAVE_SSIZE64_T@
HAVE_STDINT_H = @HAVE_STDINT_H@
HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@
HAVE_WCHAR_H = @HAVE_WCHAR_H@
HAVE_WIDE_CHARACTER_TYPE = @HAVE_WIDE_CHARACTER_TYPE@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INTLLIBS = @INTLLIBS@
INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBCAES_DLL_EXPORT = @LIBCAES_DLL_EXPORT@
LIBCAES_DLL_IMPORT = @LIBCAES_DLL_IMPORT@
LIBCERROR_CPPFLAGS = @LIBCERROR_CPPFLAGS@
LIBCERROR_LIBADD = @LIBCERROR_LIBADD@
LIBCRYPTO_CPPFLAGS = @LIBCRYPTO_CPPFLAGS@
LIBCRYPTO_LIBADD = @LIBCRYPTO_LIBADD@
LIBDL_LIBADD = @LIBDL_LIBADD@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIB_FUZZING_ENGINE = @LIB_FUZZING_ENGINE@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBICONV = @LTLIBICONV@
LTLIBINTL = @LTLIBINTL@
LTLIBOBJS = @LTLIBOBJS@
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MSGFMT = @MSGFMT@
MSGMERGE = @MSGMERGE@
MSGMERGE_FOR_MSGFMT_OPTION = @MSGMERGE_FOR_MSGFMT_OPTION@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKGCONFIG = @PKGCONFIG@
PKG_CONFIG = @PKG_CONFIG@
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
POSUB = @POSUB@
PYTHON = @PYTHON@
PYTHON_CONFIG = @PYTHON_CONFIG@
PYTHON_CPPFLAGS = @PYTHON_CPPFLAGS@
PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
PYTHON_LDFLAGS = @PYTHON_LDFLAGS@
PYTHON_LIBRARY_DIR = @PYTHON_LIBRARY_DIR@
PYTHON_PACKAGE_DIR = @PYTHON_PACKAGE_DIR@
PYTHON_PLATFORM = @PYTHON_PLATFORM@
PYTHON_PREFIX = @PYTHON_PREFIX@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SPEC_DATE = @SPEC_DATE@
STRIP = @STRIP@
USE_NLS = @USE_NLS@
VERSION = @VERSION@
XGETTEXT = @XGETTEXT@
XGETTEXT_015 = @XGETTEXT_015@
XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
ax_libcerror_pc_libs_private = @ax_libcerror_pc_libs_private@
ax_libcerror_spec_build_requires = @ax_libcerror_spec_build_requires@
ax_libcerror_spec_requires = @ax_libcerror_spec_requires@
ax_libcrypto_pc_libs_private = @ax_libcrypto_pc_libs_private@
ax_libcrypto_spec_build_requires = @ax_libcrypto_spec_build_requires@
ax_libcrypto_spec_requires = @ax_libcrypto_spec_requires@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libcaes_spec_requires = @libcaes_spec_requires@
libcerror_CFLAGS = @libcerror_CFLAGS@
libcerror_LIBS = @libcerror_LIBS@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
openssl_CFLAGS = @openssl_CFLAGS@
openssl_LIBS = @openssl_LIBS@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
pyexecdir = @pyexecdir@
pythondir = @pythondir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AM_CPPFLAGS = \
-I../include -I$(top_srcdir)/include \
-I../common -I$(top_srcdir)/common \
@LIBCERROR_CPPFLAGS@ \
@LIBCRYPTO_CPPFLAGS@ \
@LIBCAES_DLL_EXPORT@
lib_LTLIBRARIES = libcaes.la
libcaes_la_SOURCES = \
libcaes.c \
libcaes_context.c libcaes_context.h \
libcaes_definitions.h \
libcaes_extern.h \
libcaes_error.c libcaes_error.h \
libcaes_libcerror.h \
libcaes_support.c libcaes_support.h \
libcaes_tweaked_context.c libcaes_tweaked_context.h \
libcaes_types.h \
libcaes_unused.h
libcaes_la_LIBADD = \
@LIBCERROR_LIBADD@ \
@LIBCRYPTO_LIBADD@ \
@LIBDL_LIBADD@
libcaes_la_LDFLAGS = -no-undefined -version-info 1:0:0
EXTRA_DIST = \
libcaes_definitions.h.in \
libcaes.rc \
libcaes.rc.in
DISTCLEANFILES = \
libcaes_definitions.h \
libcaes.rc \
Makefile \
Makefile.in
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libcaes/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --gnu libcaes/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
libcaes_definitions.h: $(top_builddir)/config.status $(srcdir)/libcaes_definitions.h.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
libcaes.rc: $(top_builddir)/config.status $(srcdir)/libcaes.rc.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
list2=; for p in $$list; do \
if test -f $$p; then \
list2="$$list2 $$p"; \
else :; fi; \
done; \
test -z "$$list2" || { \
echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
$(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
}
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
for p in $$list; do \
$(am__strip_dir) \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; \
locs=`for p in $$list; do echo $$p; done | \
sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
sort -u`; \
test -z "$$locs" || { \
echo rm -f $${locs}; \
rm -f $${locs}; \
}
libcaes.la: $(libcaes_la_OBJECTS) $(libcaes_la_DEPENDENCIES) $(EXTRA_libcaes_la_DEPENDENCIES)
$(AM_V_CCLD)$(libcaes_la_LINK) -rpath $(libdir) $(libcaes_la_OBJECTS) $(libcaes_la_LIBADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcaes.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcaes_context.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcaes_error.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcaes_support.Plo@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcaes_tweaked_context.Plo@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@echo '# dummy' >$@-t && $(am__mv) $@-t $@
am--depfiles: $(am__depfiles_remade)
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
sources-local:
splint-local:
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
TAGS: tags
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
$(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: ctags-am
CTAGS: ctags
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
$(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
cscopelist: cscopelist-am
cscopelist-am: $(am__tagged_files)
list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
esac; \
for i in $$list; do \
if test -f "$$i"; then \
echo "$(subdir)/$$i"; \
else \
echo "$$sdir/$$i"; \
fi; \
done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) distdir-am
distdir-am: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES)
installdirs:
for dir in "$(DESTDIR)$(libdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
-test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/libcaes.Plo
-rm -f ./$(DEPDIR)/libcaes_context.Plo
-rm -f ./$(DEPDIR)/libcaes_error.Plo
-rm -f ./$(DEPDIR)/libcaes_support.Plo
-rm -f ./$(DEPDIR)/libcaes_tweaked_context.Plo
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am: install-libLTLIBRARIES
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/libcaes.Plo
-rm -f ./$(DEPDIR)/libcaes_context.Plo
-rm -f ./$(DEPDIR)/libcaes_error.Plo
-rm -f ./$(DEPDIR)/libcaes_support.Plo
-rm -f ./$(DEPDIR)/libcaes_tweaked_context.Plo
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
sources: sources-am
sources-am: sources-local
splint: splint-am
splint-am: splint-local
uninstall-am: uninstall-libLTLIBRARIES
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
clean-generic clean-libLTLIBRARIES clean-libtool cscopelist-am \
ctags ctags-am distclean distclean-compile distclean-generic \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-data \
install-data-am install-dvi install-dvi-am install-exec \
install-exec-am install-html install-html-am install-info \
install-info-am install-libLTLIBRARIES install-man install-pdf \
install-pdf-am install-ps install-ps-am install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
sources-am sources-local splint-am splint-local tags tags-am \
uninstall uninstall-am uninstall-libLTLIBRARIES
.PRECIOUS: Makefile
sources-local: $(BUILT_SOURCES)
splint-local:
@echo "Running splint on libcaes ..."
-splint -preproc -redef $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(libcaes_la_SOURCES)
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
libcaes-20240413/libcaes/libcaes_tweaked_context.c 0000644 0001750 0001750 00000100517 14606473412 022646 0 ustar 00lordyesta lordyesta /*
* AES encryption functions
*
* Copyright (C) 2011-2024, Joachim Metz
*
* Refer to AUTHORS for acknowledgements.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#include
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H )
#include
#include
#endif
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
#include
#endif
#include "libcaes_context.h"
#include "libcaes_definitions.h"
#include "libcaes_libcerror.h"
#include "libcaes_tweaked_context.h"
#include "libcaes_types.h"
/* Creates a tweaked context
* Make sure the value context is referencing, is set to NULL
* Returns 1 if successful or -1 on error
*/
int libcaes_tweaked_context_initialize(
libcaes_tweaked_context_t **tweaked_context,
libcerror_error_t **error )
{
libcaes_internal_tweaked_context_t *internal_tweaked_context = NULL;
static char *function = "libcaes_tweaked_context_initialize";
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
char error_string[ 256 ];
unsigned long error_code = 0;
#endif
if( tweaked_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweaked context.",
function );
return( -1 );
}
if( *tweaked_context != NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
"%s: invalid tweaked context value already set.",
function );
return( -1 );
}
internal_tweaked_context = memory_allocate_structure(
libcaes_internal_tweaked_context_t );
if( internal_tweaked_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
"%s: unable to create tweaked context.",
function );
goto on_error;
}
if( memory_set(
internal_tweaked_context,
0,
sizeof( libcaes_internal_tweaked_context_t ) ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear tweaked context.",
function );
memory_free(
internal_tweaked_context );
return( -1 );
}
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
#if defined( HAVE_EVP_CIPHER_CTX_INIT )
EVP_CIPHER_CTX_init(
&( internal_tweaked_context->internal_evp_cipher_context ) );
internal_tweaked_context->evp_cipher_context = &( internal_tweaked_context->internal_evp_cipher_context );
#else
internal_tweaked_context->evp_cipher_context = EVP_CIPHER_CTX_new();
if( internal_tweaked_context->evp_cipher_context == NULL )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to create EVP cipher context with error: %s.",
function,
error_string );
goto on_error;
}
#endif /* defined( HAVE_EVP_CIPHER_CTX_INIT ) */
#else
if( libcaes_context_initialize(
&( internal_tweaked_context->main_context ),
error ) != 1)
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize main context.",
function );
goto on_error;
}
if( libcaes_context_initialize(
&( internal_tweaked_context->tweak_context ),
error ) != 1)
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize tweak context.",
function );
goto on_error;
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS ) */
*tweaked_context = (libcaes_tweaked_context_t *) internal_tweaked_context;
return( 1 );
on_error:
if( internal_tweaked_context != NULL )
{
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
/* No additional clean up necessary */
#else
if( internal_tweaked_context->main_context != NULL )
{
libcaes_context_free(
&( internal_tweaked_context->main_context ),
NULL );
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS ) */
memory_free(
internal_tweaked_context );
}
return( -1 );
}
/* Frees a tweaked context
* Returns 1 if successful or -1 on error
*/
int libcaes_tweaked_context_free(
libcaes_tweaked_context_t **tweaked_context,
libcerror_error_t **error )
{
libcaes_internal_tweaked_context_t *internal_tweaked_context = NULL;
static char *function = "libcaes_tweaked_context_free";
int result = 1;
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_EVP_CIPHER_CTX_CLEANUP )
char error_string[ 256 ];
unsigned long error_code = 0;
#endif
if( tweaked_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweaked context.",
function );
return( -1 );
}
if( *tweaked_context != NULL )
{
internal_tweaked_context = (libcaes_internal_tweaked_context_t *) *tweaked_context;
*tweaked_context = NULL;
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
#if defined( HAVE_EVP_CIPHER_CTX_CLEANUP )
if( EVP_CIPHER_CTX_cleanup(
&( internal_tweaked_context->internal_evp_cipher_context ) ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
"%s: unable to clean up EVP cipher context with error: %s.",
function,
error_string );
result = -1;
}
/* Make sure the error state is removed otherwise OpenSSL will leak memory
*/
ERR_remove_thread_state(
NULL );
#else
EVP_CIPHER_CTX_free(
internal_tweaked_context->evp_cipher_context );
#endif /* defined( HAVE_EVP_CIPHER_CTX_CLEANUP ) */
internal_tweaked_context->evp_cipher_context = NULL;
#else
if( libcaes_context_free(
&( internal_tweaked_context->tweak_context ),
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
"%s: unable to free tweak context.",
function );
result = -1;
}
if( libcaes_context_free(
&( internal_tweaked_context->main_context ),
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
"%s: unable to free main context.",
function );
result = -1;
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS ) */
memory_free(
internal_tweaked_context );
}
return( result );
}
/* Sets the keys
* Returns 1 if successful or -1 on error
*/
int libcaes_tweaked_context_set_keys(
libcaes_tweaked_context_t *tweaked_context,
int mode,
const uint8_t *key,
size_t key_bit_size,
const uint8_t *tweak_key,
size_t tweak_key_bit_size,
libcerror_error_t **error )
{
libcaes_internal_tweaked_context_t *internal_tweaked_context = NULL;
static char *function = "libcaes_tweaked_context_set_key";
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
size_t key_byte_size = 0;
#endif
if( tweaked_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweaked context.",
function );
return( -1 );
}
internal_tweaked_context = (libcaes_internal_tweaked_context_t *) tweaked_context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( ( key_bit_size != 128 )
&& ( key_bit_size != 256 ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported key bit size.",
function );
return( -1 );
}
if( tweak_key_bit_size != key_bit_size )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported tweak key bit size.",
function );
return( -1 );
}
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
if( key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid key.",
function );
return( -1 );
}
if( tweak_key == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweak key.",
function );
return( -1 );
}
key_byte_size = key_bit_size / 8;
if( memory_copy(
internal_tweaked_context->key,
key,
key_byte_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy key.",
function );
return( -1 );
}
if( memory_copy(
&( internal_tweaked_context->key[ key_byte_size ] ),
tweak_key,
key_byte_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy tweak key.",
function );
return( -1 );
}
internal_tweaked_context->key_bit_size = key_bit_size;
#else
if( libcaes_context_set_key(
internal_tweaked_context->main_context,
mode,
key,
key_bit_size,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set key in main context.",
function );
return( -1 );
}
if( libcaes_context_set_key(
internal_tweaked_context->tweak_context,
LIBCAES_CRYPT_MODE_ENCRYPT,
tweak_key,
tweak_key_bit_size,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set tweak key in tweak context.",
function );
return( -1 );
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS ) */
return( 1 );
}
#if defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS )
/* De- or encrypts a block of data using AES-XTS (XEX-based tweaked-codebook mode with ciphertext stealing) using OpenSSL EVP
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_xts(
libcaes_tweaked_context_t *tweaked_context,
int mode,
const uint8_t *tweak_value,
size_t tweak_value_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t block_data[ EVP_MAX_BLOCK_LENGTH ];
char error_string[ 256 ];
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
OSSL_PARAM parameters[2];
EVP_CIPHER *cipher = NULL;
const char *cipher_string = NULL;
unsigned int padding = 0;
#else
const EVP_CIPHER *cipher = NULL;
#endif
libcaes_internal_tweaked_context_t *internal_tweaked_context = NULL;
static char *function = "libcaes_crypt_xts";
unsigned long error_code = 0;
int safe_output_data_size = 0;
if( tweaked_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweaked context.",
function );
return( -1 );
}
internal_tweaked_context = (libcaes_internal_tweaked_context_t *) tweaked_context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( tweak_value == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweak value.",
function );
return( -1 );
}
if( tweak_value_size != 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid tweak value size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
if( input_data_size > (size_t) INT_MAX )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid input data size value exceeds maximum.",
function );
return( -1 );
}
if( input_data_size < 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
"%s: invalid input data size value too small.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( output_data_size > (size_t) INT_MAX )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid output data size value exceeds maximum.",
function );
return( -1 );
}
if( output_data_size < input_data_size )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid ouput data size smaller than input data size.",
function );
return( -1 );
}
if( memory_set(
block_data,
0,
EVP_MAX_BLOCK_LENGTH ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear input block data.",
function );
goto on_error;
}
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
if( EVP_CIPHER_CTX_reset(
internal_tweaked_context->evp_cipher_context ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to reset cipher context with error: %s.",
function,
error_string );
goto on_error;
}
if( internal_tweaked_context->key_bit_size == 128 )
{
cipher_string = "AES-128-XTS";
}
else if( internal_tweaked_context->key_bit_size == 256 )
{
cipher_string = "AES-256-XTS";
}
cipher = EVP_CIPHER_fetch(
NULL,
cipher_string,
NULL );
if( cipher == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: missing cipher.",
function );
goto on_error;
}
parameters[0] = OSSL_PARAM_construct_uint(
OSSL_CIPHER_PARAM_PADDING,
&padding );
parameters[1] = OSSL_PARAM_construct_end();
if( EVP_CipherInit_ex2(
internal_tweaked_context->evp_cipher_context,
cipher,
(unsigned char *) internal_tweaked_context->key,
(unsigned char *) tweak_value,
mode,
parameters ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize cipher with error: %s.",
function,
error_string );
goto on_error;
}
#else
if( internal_tweaked_context->key_bit_size == 128 )
{
cipher = EVP_aes_128_xts();
}
else if( internal_tweaked_context->key_bit_size == 256 )
{
cipher = EVP_aes_256_xts();
}
if( EVP_CipherInit_ex(
internal_tweaked_context->evp_cipher_context,
cipher,
NULL,
(unsigned char *) internal_tweaked_context->key,
(unsigned char *) tweak_value,
mode ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
"%s: unable to initialize cipher with error: %s.",
function,
error_string );
goto on_error;
}
if( EVP_CIPHER_CTX_set_padding(
internal_tweaked_context->evp_cipher_context,
1 ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set padding in context with error: %s.",
function,
error_string );
goto on_error;
}
#endif /* defined( HAVE_EVP_CIPHERINIT_EX2 ) */
if( EVP_CipherUpdate(
internal_tweaked_context->evp_cipher_context,
(unsigned char *) output_data,
&safe_output_data_size,
(unsigned char *) input_data,
input_data_size ) != 1 )
{
error_code = ERR_get_error();
ERR_error_string_n(
error_code,
error_string,
256 );
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to update cipher with error: %s.",
function,
error_string );
goto on_error;
}
/* Just ignore the output of this function
*/
EVP_CipherFinal_ex(
internal_tweaked_context->evp_cipher_context,
(unsigned char *) block_data,
&safe_output_data_size );
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
EVP_CIPHER_free(
cipher );
#endif
return( 1 );
on_error:
#if defined( HAVE_EVP_CIPHERINIT_EX2 )
if( cipher != NULL )
{
EVP_CIPHER_free(
cipher );
}
#endif
return( -1 );
}
#else
/* De- or encrypts a block of data using AES-XTS (XEX-based tweaked-codebook mode with ciphertext stealing) using fallback implementation
* The size must be a multitude of the AES block size (16 byte)
* Returns 1 if successful or -1 on error
*/
int libcaes_crypt_xts(
libcaes_tweaked_context_t *tweaked_context,
int mode,
const uint8_t *tweak_value,
size_t tweak_value_size,
const uint8_t *input_data,
size_t input_data_size,
uint8_t *output_data,
size_t output_data_size,
libcerror_error_t **error )
{
uint8_t encrypted_tweak_value[ 16 ];
uint8_t encrypted_tweak_value_copy[ 16 ];
libcaes_internal_tweaked_context_t *internal_tweaked_context = NULL;
static char *function = "libcaes_crypt_xts";
size_t data_offset = 0;
size_t remaining_data_size = 0;
uint8_t block_index = 0;
uint8_t byte_value = 0;
uint8_t carry_bit = 0;
if( tweaked_context == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweaked context.",
function );
return( -1 );
}
internal_tweaked_context = (libcaes_internal_tweaked_context_t *) tweaked_context;
if( ( mode != LIBCAES_CRYPT_MODE_DECRYPT )
&& ( mode != LIBCAES_CRYPT_MODE_ENCRYPT ) )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
"%s: unsupported mode.",
function );
return( -1 );
}
if( tweak_value == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid tweak value.",
function );
return( -1 );
}
if( tweak_value_size != 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid tweak value size value out of bounds.",
function );
return( -1 );
}
if( input_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid input data.",
function );
return( -1 );
}
if( input_data_size < 16 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
"%s: invalid input data size value too small.",
function );
return( -1 );
}
if( input_data_size > (size_t) SSIZE_MAX )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid input data size value exceeds maximum.",
function );
return( -1 );
}
if( output_data == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid output data.",
function );
return( -1 );
}
if( output_data_size > (size_t) SSIZE_MAX )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid output data size value exceeds maximum.",
function );
return( -1 );
}
if( output_data_size < input_data_size )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS,
"%s: invalid ouput data size smaller than input data size.",
function );
return( -1 );
}
if( libcaes_crypt_ecb(
internal_tweaked_context->tweak_context,
LIBCAES_CRYPT_MODE_ENCRYPT,
tweak_value,
16,
encrypted_tweak_value,
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_GENERIC,
"%s: unable to encrypt tweak value.",
function );
goto on_error;
}
if( memory_copy(
output_data,
input_data,
input_data_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy input data to output data.",
function );
return( -1 );
}
remaining_data_size = input_data_size;
while( data_offset <= ( input_data_size - 16 ) )
{
if( ( remaining_data_size < 32 )
&& ( remaining_data_size != 16 ) )
{
/* If the input data size is not a multitude of 16 the remaining data needs to be handled differently
*/
if( mode == LIBCAES_CRYPT_MODE_DECRYPT )
{
if( memory_copy(
encrypted_tweak_value_copy,
encrypted_tweak_value,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy encrypted tweak value.",
function );
goto on_error;
}
/* Update the encrypted tweak value for the next 16-byte block
*/
carry_bit = 0;
for( block_index = 0;
block_index < 16;
block_index++ )
{
byte_value = ( encrypted_tweak_value[ block_index ] << 1 ) | carry_bit;
carry_bit = encrypted_tweak_value[ block_index ] >> 7;
encrypted_tweak_value[ block_index ] = byte_value;
}
if( carry_bit > 0 )
{
encrypted_tweak_value[ 0 ] ^= 0x87;
}
}
}
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 0 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 1 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 2 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 3 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 4 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 5 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 6 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 7 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 8 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 9 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 10 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 11 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 12 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 13 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 14 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= encrypted_tweak_value[ block_index ];
}
#endif
data_offset -= 16;
if( libcaes_crypt_ecb(
internal_tweaked_context->main_context,
mode,
&( output_data[ data_offset ] ),
16,
&( output_data[ data_offset ] ),
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_GENERIC,
"%s: unable to de/encrypt data.",
function );
goto on_error;
}
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 0 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 1 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 2 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 3 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 4 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 5 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 6 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 7 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 8 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 9 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 10 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 11 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 12 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 13 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 14 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= encrypted_tweak_value[ block_index ];
}
#endif
remaining_data_size -= 16;
/* Update the encrypted tweak value for the next 16-byte block
*/
carry_bit = 0;
for( block_index = 0;
block_index < 16;
block_index++ )
{
byte_value = ( encrypted_tweak_value[ block_index ] << 1 ) | carry_bit;
carry_bit = encrypted_tweak_value[ block_index ] >> 7;
encrypted_tweak_value[ block_index ] = byte_value;
}
if( carry_bit > 0 )
{
encrypted_tweak_value[ 0 ] ^= 0x87;
}
}
/* Any remaining data needs to be handled differently
*/
if( remaining_data_size > 0 )
{
if( mode == LIBCAES_CRYPT_MODE_DECRYPT )
{
if( memory_copy(
encrypted_tweak_value,
encrypted_tweak_value_copy,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy encrypted tweak value.",
function );
goto on_error;
}
if( memory_set(
encrypted_tweak_value_copy,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear encrypted tweak value copy.",
function );
goto on_error;
}
}
/* Swap the data of the last 16-byte block with the remaining data
*/
data_offset -= 16;
if( memory_copy(
&( output_data[ data_offset + 16 ] ),
&( output_data[ data_offset ] ),
remaining_data_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy remaining output data.",
function );
goto on_error;
}
if( memory_copy(
&( output_data[ data_offset ] ),
&( input_data[ data_offset + 16 ] ),
remaining_data_size ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_COPY_FAILED,
"%s: unable to copy input data to block data.",
function );
goto on_error;
}
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 0 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 1 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 2 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 3 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 4 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 5 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 6 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 7 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 8 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 9 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 10 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 11 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 12 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 13 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 14 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= encrypted_tweak_value[ block_index ];
}
#endif
data_offset -= 16;
if( libcaes_crypt_ecb(
internal_tweaked_context->main_context,
mode,
&( output_data[ data_offset ] ),
16,
&( output_data[ data_offset ] ),
16,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ENCRYPTION,
LIBCERROR_ENCRYPTION_ERROR_GENERIC,
"%s: unable to de/encrypt data.",
function );
goto on_error;
}
#if defined( LIBCAES_UNFOLLED_LOOPS )
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 0 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 1 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 2 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 3 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 4 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 5 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 6 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 7 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 8 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 9 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 10 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 11 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 12 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 13 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 14 ];
output_data[ data_offset++ ] ^= encrypted_tweak_value[ 15 ];
#else
for( block_index = 0;
block_index < 16;
block_index++ )
{
output_data[ data_offset++ ] ^= encrypted_tweak_value[ block_index ];
}
#endif
}
if( memory_set(
encrypted_tweak_value,
0,
16 ) == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_MEMORY,
LIBCERROR_MEMORY_ERROR_SET_FAILED,
"%s: unable to clear encrypted tweak value.",
function );
goto on_error;
}
return( 1 );
on_error:
memory_set(
encrypted_tweak_value_copy,
0,
16 );
memory_set(
encrypted_tweak_value,
0,
16 );
return( -1 );
}
#endif /* defined( HAVE_LIBCRYPTO ) && defined( HAVE_OPENSSL_EVP_H ) && defined( HAVE_EVP_CRYPTO_AES_XTS ) */
libcaes-20240413/libcaes.spec.in 0000644 0001750 0001750 00000004050 14606473411 017103 0 ustar 00lordyesta lordyesta Name: libcaes
Version: @VERSION@
Release: 1
Summary: Library to support cross-platform AES encryption
Group: System Environment/Libraries
License: LGPL-3.0-or-later
Source: %{name}-%{version}.tar.gz
URL: https://github.com/libyal/libcaes
@libcaes_spec_requires@ @ax_libcerror_spec_requires@ @ax_libcrypto_spec_requires@
BuildRequires: gcc @ax_libcerror_spec_build_requires@ @ax_libcrypto_spec_build_requires@
%description -n libcaes
Library to support cross-platform AES encryption
%package -n libcaes-static
Summary: Library to support cross-platform AES encryption
Group: Development/Libraries
Requires: libcaes = %{version}-%{release}
%description -n libcaes-static
Static library version of libcaes.
%package -n libcaes-devel
Summary: Header files and libraries for developing applications for libcaes
Group: Development/Libraries
Requires: libcaes = %{version}-%{release}
%description -n libcaes-devel
Header files and libraries for developing applications for libcaes.
%package -n libcaes-python3
Summary: Python 3 bindings for libcaes
Group: System Environment/Libraries
Requires: libcaes = %{version}-%{release} python3
BuildRequires: python3-devel python3-setuptools
%description -n libcaes-python3
Python 3 bindings for libcaes
%prep
%setup -q
%build
%configure --prefix=/usr --libdir=%{_libdir} --mandir=%{_mandir} --enable-python
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
%make_install
%clean
rm -rf %{buildroot}
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files -n libcaes
%license COPYING COPYING.LESSER
%doc AUTHORS README
%{_libdir}/*.so.*
%files -n libcaes-static
%license COPYING COPYING.LESSER
%doc AUTHORS README
%{_libdir}/*.a
%files -n libcaes-devel
%license COPYING COPYING.LESSER
%doc AUTHORS README
%{_libdir}/*.so
%{_libdir}/pkgconfig/libcaes.pc
%{_includedir}/*
%{_mandir}/man3/*
%files -n libcaes-python3
%license COPYING COPYING.LESSER
%doc AUTHORS README
%{_libdir}/python3*/site-packages/*.a
%{_libdir}/python3*/site-packages/*.so
%changelog
* @SPEC_DATE@ Joachim Metz @VERSION@-1
- Auto-generated
libcaes-20240413/m4/ 0000755 0001750 0001750 00000000000 14606477653 014555 5 ustar 00lordyesta lordyesta libcaes-20240413/m4/tests.m4 0000644 0001750 0001750 00000001364 14533041421 016140 0 ustar 00lordyesta lordyesta dnl Functions for testing
dnl
dnl Version: 20200712
dnl Function to detect if tests dependencies are available
AC_DEFUN([AX_TESTS_CHECK_LOCAL],
[AC_CHECK_HEADERS([dlfcn.h])
AC_CHECK_FUNCS([fmemopen getopt mkstemp setenv tzset unlink])
AC_CHECK_LIB(
dl,
dlsym)
AS_IF(
[test "x$lt_cv_prog_gnu_ld" = xyes && test "x$ac_cv_lib_dl_dlsym" = xyes],
[AC_DEFINE(
[HAVE_GNU_DL_DLSYM],
[1],
[Define to 1 if dlsym function is available in GNU dl.])
])
])
dnl Function to detect if OSS-Fuzz build environment is available
AC_DEFUN([AX_TESTS_CHECK_OSSFUZZ],
[AM_CONDITIONAL(
HAVE_LIB_FUZZING_ENGINE,
[test "x${LIB_FUZZING_ENGINE}" != x])
AC_SUBST(
[LIB_FUZZING_ENGINE],
["${LIB_FUZZING_ENGINE}"])
])
libcaes-20240413/m4/lib-prefix.m4 0000644 0001750 0001750 00000027250 14533041421 017041 0 ustar 00lordyesta lordyesta # lib-prefix.m4 serial 17
dnl Copyright (C) 2001-2005, 2008-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
dnl to access previously installed libraries. The basic assumption is that
dnl a user will want packages to use other packages he previously installed
dnl with the same --prefix option.
dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
dnl libraries, but is otherwise very convenient.
AC_DEFUN([AC_LIB_PREFIX],
[
AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_HOST])
AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
dnl By default, look in $includedir and $libdir.
use_additional=yes
AC_LIB_WITH_FINAL_PREFIX([
eval additional_includedir=\"$includedir\"
eval additional_libdir=\"$libdir\"
])
AC_ARG_WITH([lib-prefix],
[[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
--without-lib-prefix don't search for libraries in includedir and libdir]],
[
if test "X$withval" = "Xno"; then
use_additional=no
else
if test "X$withval" = "X"; then
AC_LIB_WITH_FINAL_PREFIX([
eval additional_includedir=\"$includedir\"
eval additional_libdir=\"$libdir\"
])
else
additional_includedir="$withval/include"
additional_libdir="$withval/$acl_libdirstem"
fi
fi
])
if test $use_additional = yes; then
dnl Potentially add $additional_includedir to $CPPFLAGS.
dnl But don't add it
dnl 1. if it's the standard /usr/include,
dnl 2. if it's already present in $CPPFLAGS,
dnl 3. if it's /usr/local/include and we are using GCC on Linux,
dnl 4. if it doesn't exist as a directory.
if test "X$additional_includedir" != "X/usr/include"; then
haveit=
for x in $CPPFLAGS; do
AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
if test "X$x" = "X-I$additional_includedir"; then
haveit=yes
break
fi
done
if test -z "$haveit"; then
if test "X$additional_includedir" = "X/usr/local/include"; then
if test -n "$GCC"; then
case $host_os in
linux* | gnu* | k*bsd*-gnu) haveit=yes;;
esac
fi
fi
if test -z "$haveit"; then
if test -d "$additional_includedir"; then
dnl Really add $additional_includedir to $CPPFLAGS.
CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
fi
fi
fi
fi
dnl Potentially add $additional_libdir to $LDFLAGS.
dnl But don't add it
dnl 1. if it's the standard /usr/lib,
dnl 2. if it's already present in $LDFLAGS,
dnl 3. if it's /usr/local/lib and we are using GCC on Linux,
dnl 4. if it doesn't exist as a directory.
if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
haveit=
for x in $LDFLAGS; do
AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
if test "X$x" = "X-L$additional_libdir"; then
haveit=yes
break
fi
done
if test -z "$haveit"; then
if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
if test -n "$GCC"; then
case $host_os in
linux*) haveit=yes;;
esac
fi
fi
if test -z "$haveit"; then
if test -d "$additional_libdir"; then
dnl Really add $additional_libdir to $LDFLAGS.
LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
fi
fi
fi
fi
fi
])
dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
dnl acl_final_exec_prefix, containing the values to which $prefix and
dnl $exec_prefix will expand at the end of the configure script.
AC_DEFUN([AC_LIB_PREPARE_PREFIX],
[
dnl Unfortunately, prefix and exec_prefix get only finally determined
dnl at the end of configure.
if test "X$prefix" = "XNONE"; then
acl_final_prefix="$ac_default_prefix"
else
acl_final_prefix="$prefix"
fi
if test "X$exec_prefix" = "XNONE"; then
acl_final_exec_prefix='${prefix}'
else
acl_final_exec_prefix="$exec_prefix"
fi
acl_save_prefix="$prefix"
prefix="$acl_final_prefix"
eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
prefix="$acl_save_prefix"
])
dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
dnl variables prefix and exec_prefix bound to the values they will have
dnl at the end of the configure script.
AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
[
acl_save_prefix="$prefix"
prefix="$acl_final_prefix"
acl_save_exec_prefix="$exec_prefix"
exec_prefix="$acl_final_exec_prefix"
$1
exec_prefix="$acl_save_exec_prefix"
prefix="$acl_save_prefix"
])
dnl AC_LIB_PREPARE_MULTILIB creates
dnl - a function acl_is_expected_elfclass, that tests whether standard input
dn; has a 32-bit or 64-bit ELF header, depending on the host CPU ABI,
dnl - 3 variables acl_libdirstem, acl_libdirstem2, acl_libdirstem3, containing
dnl the basename of the libdir to try in turn, either "lib" or "lib64" or
dnl "lib/64" or "lib32" or "lib/sparcv9" or "lib/amd64" or similar.
AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
[
dnl There is no formal standard regarding lib, lib32, and lib64.
dnl On most glibc systems, the current practice is that on a system supporting
dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. However, on
dnl Arch Linux based distributions, it's the opposite: 32-bit libraries go
dnl under $prefix/lib32 and 64-bit libraries go under $prefix/lib.
dnl We determine the compiler's default mode by looking at the compiler's
dnl library search path. If at least one of its elements ends in /lib64 or
dnl points to a directory whose absolute pathname ends in /lib64, we use that
dnl for 64-bit ABIs. Similarly for 32-bit ABIs. Otherwise we use the default,
dnl namely "lib".
dnl On Solaris systems, the current practice is that on a system supporting
dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
AC_REQUIRE([AC_CANONICAL_HOST])
AC_REQUIRE([gl_HOST_CPU_C_ABI_32BIT])
AC_CACHE_CHECK([for ELF binary format], [gl_cv_elf],
[AC_EGREP_CPP([Extensible Linking Format],
[#ifdef __ELF__
Extensible Linking Format
#endif
],
[gl_cv_elf=yes],
[gl_cv_elf=no])
])
if test $gl_cv_elf; then
# Extract the ELF class of a file (5th byte) in decimal.
# Cf. https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header
if od -A x < /dev/null >/dev/null 2>/dev/null; then
# Use POSIX od.
func_elfclass ()
{
od -A n -t d1 -j 4 -N 1
}
else
# Use BSD hexdump.
func_elfclass ()
{
dd bs=1 count=1 skip=4 2>/dev/null | hexdump -e '1/1 "%3d "'
echo
}
fi
changequote(,)dnl
case $HOST_CPU_C_ABI_32BIT in
yes)
# 32-bit ABI.
acl_is_expected_elfclass ()
{
test "`func_elfclass | sed -e 's/[ ]//g'`" = 1
}
;;
no)
# 64-bit ABI.
acl_is_expected_elfclass ()
{
test "`func_elfclass | sed -e 's/[ ]//g'`" = 2
}
;;
*)
# Unknown.
acl_is_expected_elfclass ()
{
:
}
;;
esac
changequote([,])dnl
else
acl_is_expected_elfclass ()
{
:
}
fi
dnl Allow the user to override the result by setting acl_cv_libdirstems.
AC_CACHE_CHECK([for the common suffixes of directories in the library search path],
[acl_cv_libdirstems],
[dnl Try 'lib' first, because that's the default for libdir in GNU, see
dnl .
acl_libdirstem=lib
acl_libdirstem2=
acl_libdirstem3=
case "$host_os" in
solaris*)
dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
dnl .
dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
dnl symlink is missing, so we set acl_libdirstem2 too.
if test $HOST_CPU_C_ABI_32BIT = no; then
acl_libdirstem2=lib/64
case "$host_cpu" in
sparc*) acl_libdirstem3=lib/sparcv9 ;;
i*86 | x86_64) acl_libdirstem3=lib/amd64 ;;
esac
fi
;;
*)
dnl If $CC generates code for a 32-bit ABI, the libraries are
dnl surely under $prefix/lib or $prefix/lib32, not $prefix/lib64.
dnl Similarly, if $CC generates code for a 64-bit ABI, the libraries
dnl are surely under $prefix/lib or $prefix/lib64, not $prefix/lib32.
dnl Find the compiler's search path. However, non-system compilers
dnl sometimes have odd library search paths. But we can't simply invoke
dnl '/usr/bin/gcc -print-search-dirs' because that would not take into
dnl account the -m32/-m31 or -m64 options from the $CC or $CFLAGS.
searchpath=`(LC_ALL=C $CC $CPPFLAGS $CFLAGS -print-search-dirs) 2>/dev/null \
| sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
if test $HOST_CPU_C_ABI_32BIT != no; then
# 32-bit or unknown ABI.
if test -d /usr/lib32; then
acl_libdirstem2=lib32
fi
fi
if test $HOST_CPU_C_ABI_32BIT != yes; then
# 64-bit or unknown ABI.
if test -d /usr/lib64; then
acl_libdirstem3=lib64
fi
fi
if test -n "$searchpath"; then
acl_save_IFS="${IFS= }"; IFS=":"
for searchdir in $searchpath; do
if test -d "$searchdir"; then
case "$searchdir" in
*/lib32/ | */lib32 ) acl_libdirstem2=lib32 ;;
*/lib64/ | */lib64 ) acl_libdirstem3=lib64 ;;
*/../ | */.. )
# Better ignore directories of this form. They are misleading.
;;
*) searchdir=`cd "$searchdir" && pwd`
case "$searchdir" in
*/lib32 ) acl_libdirstem2=lib32 ;;
*/lib64 ) acl_libdirstem3=lib64 ;;
esac ;;
esac
fi
done
IFS="$acl_save_IFS"
if test $HOST_CPU_C_ABI_32BIT = yes; then
# 32-bit ABI.
acl_libdirstem3=
fi
if test $HOST_CPU_C_ABI_32BIT = no; then
# 64-bit ABI.
acl_libdirstem2=
fi
fi
;;
esac
test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
test -n "$acl_libdirstem3" || acl_libdirstem3="$acl_libdirstem"
acl_cv_libdirstems="$acl_libdirstem,$acl_libdirstem2,$acl_libdirstem3"
])
dnl Decompose acl_cv_libdirstems into acl_libdirstem, acl_libdirstem2, and
dnl acl_libdirstem3.
changequote(,)dnl
acl_libdirstem=`echo "$acl_cv_libdirstems" | sed -e 's/,.*//'`
acl_libdirstem2=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,//' -e 's/,.*//'`
acl_libdirstem3=`echo "$acl_cv_libdirstems" | sed -e 's/^[^,]*,[^,]*,//' -e 's/,.*//'`
changequote([,])dnl
])
libcaes-20240413/m4/progtest.m4 0000644 0001750 0001750 00000006022 14533041421 016641 0 ustar 00lordyesta lordyesta # progtest.m4 serial 8 (gettext-0.20.2)
dnl Copyright (C) 1996-2003, 2005, 2008-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl
dnl This file can be used in projects which are not available under
dnl the GNU General Public License or the GNU Lesser General Public
dnl License but which still want to provide support for the GNU gettext
dnl functionality.
dnl Please note that the actual code of the GNU gettext library is covered
dnl by the GNU Lesser General Public License, and the rest of the GNU
dnl gettext package is covered by the GNU General Public License.
dnl They are *not* in the public domain.
dnl Authors:
dnl Ulrich Drepper , 1996.
AC_PREREQ([2.50])
# Search path for a program which passes the given test.
dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
dnl TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
AC_DEFUN([AM_PATH_PROG_WITH_TEST],
[
# Prepare PATH_SEPARATOR.
# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
# Determine PATH_SEPARATOR by trying to find /bin/sh in a PATH which
# contains only /bin. Note that ksh looks also at the FPATH variable,
# so we have to set that as well for the test.
PATH_SEPARATOR=:
(PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
&& { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
|| PATH_SEPARATOR=';'
}
fi
# Find out how to test for executable files. Don't use a zero-byte file,
# as systems may use methods other than mode bits to determine executability.
cat >conf$$.file <<_ASEOF
#! /bin/sh
exit 0
_ASEOF
chmod +x conf$$.file
if test -x conf$$.file >/dev/null 2>&1; then
ac_executable_p="test -x"
else
ac_executable_p="test -f"
fi
rm -f conf$$.file
# Extract the first word of "$2", so it can be a program name with args.
set dummy $2; ac_word=[$]2
AC_MSG_CHECKING([for $ac_word])
AC_CACHE_VAL([ac_cv_path_$1],
[case "[$]$1" in
[[\\/]]* | ?:[[\\/]]*)
ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
;;
*)
ac_save_IFS="$IFS"; IFS=$PATH_SEPARATOR
for ac_dir in ifelse([$5], , $PATH, [$5]); do
IFS="$ac_save_IFS"
test -z "$ac_dir" && ac_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if $ac_executable_p "$ac_dir/$ac_word$ac_exec_ext"; then
echo "$as_me: trying $ac_dir/$ac_word..." >&AS_MESSAGE_LOG_FD
if [$3]; then
ac_cv_path_$1="$ac_dir/$ac_word$ac_exec_ext"
break 2
fi
fi
done
done
IFS="$ac_save_IFS"
dnl If no 4th arg is given, leave the cache variable unset,
dnl so AC_PATH_PROGS will keep looking.
ifelse([$4], , , [ test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
])dnl
;;
esac])dnl
$1="$ac_cv_path_$1"
if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
AC_MSG_RESULT([$][$1])
else
AC_MSG_RESULT([no])
fi
AC_SUBST([$1])dnl
])
libcaes-20240413/m4/gettext.m4 0000644 0001750 0001750 00000034230 14533041421 016460 0 ustar 00lordyesta lordyesta # gettext.m4 serial 71 (gettext-0.20.2)
dnl Copyright (C) 1995-2014, 2016, 2018-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl
dnl This file can be used in projects which are not available under
dnl the GNU General Public License or the GNU Lesser General Public
dnl License but which still want to provide support for the GNU gettext
dnl functionality.
dnl Please note that the actual code of the GNU gettext library is covered
dnl by the GNU Lesser General Public License, and the rest of the GNU
dnl gettext package is covered by the GNU General Public License.
dnl They are *not* in the public domain.
dnl Authors:
dnl Ulrich Drepper , 1995-2000.
dnl Bruno Haible , 2000-2006, 2008-2010.
dnl Macro to add for using GNU gettext.
dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
dnl INTLSYMBOL must be one of 'external', 'use-libtool'.
dnl INTLSYMBOL should be 'external' for packages other than GNU gettext, and
dnl 'use-libtool' for the packages 'gettext-runtime' and 'gettext-tools'.
dnl If INTLSYMBOL is 'use-libtool', then a libtool library
dnl $(top_builddir)/intl/libintl.la will be created (shared and/or static,
dnl depending on --{enable,disable}-{shared,static} and on the presence of
dnl AM-DISABLE-SHARED).
dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
dnl implementations (in libc or libintl) without the ngettext() function
dnl will be ignored. If NEEDSYMBOL is specified and is
dnl 'need-formatstring-macros', then GNU gettext implementations that don't
dnl support the ISO C 99 formatstring macros will be ignored.
dnl INTLDIR is used to find the intl libraries. If empty,
dnl the value '$(top_builddir)/intl/' is used.
dnl
dnl The result of the configuration is one of three cases:
dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
dnl and used.
dnl Catalog format: GNU --> install in $(datadir)
dnl Catalog extension: .mo after installation, .gmo in source tree
dnl 2) GNU gettext has been found in the system's C library.
dnl Catalog format: GNU --> install in $(datadir)
dnl Catalog extension: .mo after installation, .gmo in source tree
dnl 3) No internationalization, always use English msgid.
dnl Catalog format: none
dnl Catalog extension: none
dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
dnl The use of .gmo is historical (it was needed to avoid overwriting the
dnl GNU format catalogs when building on a platform with an X/Open gettext),
dnl but we keep it in order not to force irrelevant filename changes on the
dnl maintainers.
dnl
AC_DEFUN([AM_GNU_GETTEXT],
[
dnl Argument checking.
ifelse([$1], [], , [ifelse([$1], [external], , [ifelse([$1], [use-libtool], ,
[errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
])])])])
ifelse(ifelse([$1], [], [old])[]ifelse([$1], [no-libtool], [old]), [old],
[errprint([ERROR: Use of AM_GNU_GETTEXT without [external] argument is no longer supported.
])])
ifelse([$2], [], , [ifelse([$2], [need-ngettext], , [ifelse([$2], [need-formatstring-macros], ,
[errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
])])])])
define([gt_included_intl],
ifelse([$1], [external], [no], [yes]))
gt_NEEDS_INIT
AM_GNU_GETTEXT_NEED([$2])
AC_REQUIRE([AM_PO_SUBDIRS])dnl
ifelse(gt_included_intl, yes, [
AC_REQUIRE([AM_INTL_SUBDIR])dnl
])
dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
AC_REQUIRE([AC_LIB_RPATH])
dnl Sometimes libintl requires libiconv, so first search for libiconv.
dnl Ideally we would do this search only after the
dnl if test "$USE_NLS" = "yes"; then
dnl if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
dnl tests. But if configure.in invokes AM_ICONV after AM_GNU_GETTEXT
dnl the configure script would need to contain the same shell code
dnl again, outside any 'if'. There are two solutions:
dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
dnl Since AC_PROVIDE_IFELSE is not documented, we avoid it.
ifelse(gt_included_intl, yes, , [
AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
])
dnl Sometimes, on Mac OS X, libintl requires linking with CoreFoundation.
gt_INTL_MACOSX
dnl Set USE_NLS.
AC_REQUIRE([AM_NLS])
ifelse(gt_included_intl, yes, [
BUILD_INCLUDED_LIBINTL=no
USE_INCLUDED_LIBINTL=no
])
LIBINTL=
LTLIBINTL=
POSUB=
dnl Add a version number to the cache macros.
case " $gt_needs " in
*" need-formatstring-macros "*) gt_api_version=3 ;;
*" need-ngettext "*) gt_api_version=2 ;;
*) gt_api_version=1 ;;
esac
gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
dnl If we use NLS figure out what method
if test "$USE_NLS" = "yes"; then
gt_use_preinstalled_gnugettext=no
ifelse(gt_included_intl, yes, [
AC_MSG_CHECKING([whether included gettext is requested])
AC_ARG_WITH([included-gettext],
[ --with-included-gettext use the GNU gettext library included here],
nls_cv_force_use_gnu_gettext=$withval,
nls_cv_force_use_gnu_gettext=no)
AC_MSG_RESULT([$nls_cv_force_use_gnu_gettext])
nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
])
dnl User does not insist on using GNU NLS library. Figure out what
dnl to use. If GNU gettext is available we use this. Else we have
dnl to fall back to GNU NLS library.
if test $gt_api_version -ge 3; then
gt_revision_test_code='
#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
#define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
#endif
changequote(,)dnl
typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
changequote([,])dnl
'
else
gt_revision_test_code=
fi
if test $gt_api_version -ge 2; then
gt_expression_test_code=' + * ngettext ("", "", 0)'
else
gt_expression_test_code=
fi
AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
[AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include
#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
extern int _nl_msg_cat_cntr;
extern int *_nl_domain_bindings;
#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_domain_bindings)
#else
#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
#endif
$gt_revision_test_code
]],
[[
bindtextdomain ("", "");
return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
]])],
[eval "$gt_func_gnugettext_libc=yes"],
[eval "$gt_func_gnugettext_libc=no"])])
if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
dnl Sometimes libintl requires libiconv, so first search for libiconv.
ifelse(gt_included_intl, yes, , [
AM_ICONV_LINK
])
dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
dnl even if libiconv doesn't exist.
AC_LIB_LINKFLAGS_BODY([intl])
AC_CACHE_CHECK([for GNU gettext in libintl],
[$gt_func_gnugettext_libintl],
[gt_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $INCINTL"
gt_save_LIBS="$LIBS"
LIBS="$LIBS $LIBINTL"
dnl Now see whether libintl exists and does not depend on libiconv.
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include
#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
extern int _nl_msg_cat_cntr;
extern
#ifdef __cplusplus
"C"
#endif
const char *_nl_expand_alias (const char *);
#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
#else
#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
#endif
$gt_revision_test_code
]],
[[
bindtextdomain ("", "");
return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
]])],
[eval "$gt_func_gnugettext_libintl=yes"],
[eval "$gt_func_gnugettext_libintl=no"])
dnl Now see whether libintl exists and depends on libiconv.
if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } && test -n "$LIBICONV"; then
LIBS="$LIBS $LIBICONV"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[
#include
#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
extern int _nl_msg_cat_cntr;
extern
#ifdef __cplusplus
"C"
#endif
const char *_nl_expand_alias (const char *);
#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
#else
#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
#endif
$gt_revision_test_code
]],
[[
bindtextdomain ("", "");
return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
]])],
[LIBINTL="$LIBINTL $LIBICONV"
LTLIBINTL="$LTLIBINTL $LTLIBICONV"
eval "$gt_func_gnugettext_libintl=yes"
])
fi
CPPFLAGS="$gt_save_CPPFLAGS"
LIBS="$gt_save_LIBS"])
fi
dnl If an already present or preinstalled GNU gettext() is found,
dnl use it. But if this macro is used in GNU gettext, and GNU
dnl gettext is already preinstalled in libintl, we update this
dnl libintl. (Cf. the install rule in intl/Makefile.in.)
if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
|| { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
&& test "$PACKAGE" != gettext-runtime \
&& test "$PACKAGE" != gettext-tools; }; then
gt_use_preinstalled_gnugettext=yes
else
dnl Reset the values set by searching for libintl.
LIBINTL=
LTLIBINTL=
INCINTL=
fi
ifelse(gt_included_intl, yes, [
if test "$gt_use_preinstalled_gnugettext" != "yes"; then
dnl GNU gettext is not found in the C library.
dnl Fall back on included GNU gettext library.
nls_cv_use_gnu_gettext=yes
fi
fi
if test "$nls_cv_use_gnu_gettext" = "yes"; then
dnl Mark actions used to generate GNU NLS library.
BUILD_INCLUDED_LIBINTL=yes
USE_INCLUDED_LIBINTL=yes
LIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LIBICONV $LIBTHREAD"
LTLIBINTL="ifelse([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LTLIBICONV $LTLIBTHREAD"
LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
fi
CATOBJEXT=
if test "$gt_use_preinstalled_gnugettext" = "yes" \
|| test "$nls_cv_use_gnu_gettext" = "yes"; then
dnl Mark actions to use GNU gettext tools.
CATOBJEXT=.gmo
fi
])
if test -n "$INTL_MACOSX_LIBS"; then
if test "$gt_use_preinstalled_gnugettext" = "yes" \
|| test "$nls_cv_use_gnu_gettext" = "yes"; then
dnl Some extra flags are needed during linking.
LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
fi
fi
if test "$gt_use_preinstalled_gnugettext" = "yes" \
|| test "$nls_cv_use_gnu_gettext" = "yes"; then
AC_DEFINE([ENABLE_NLS], [1],
[Define to 1 if translation of program messages to the user's native language
is requested.])
else
USE_NLS=no
fi
fi
AC_MSG_CHECKING([whether to use NLS])
AC_MSG_RESULT([$USE_NLS])
if test "$USE_NLS" = "yes"; then
AC_MSG_CHECKING([where the gettext function comes from])
if test "$gt_use_preinstalled_gnugettext" = "yes"; then
if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
gt_source="external libintl"
else
gt_source="libc"
fi
else
gt_source="included intl directory"
fi
AC_MSG_RESULT([$gt_source])
fi
if test "$USE_NLS" = "yes"; then
if test "$gt_use_preinstalled_gnugettext" = "yes"; then
if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
AC_MSG_CHECKING([how to link with libintl])
AC_MSG_RESULT([$LIBINTL])
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
fi
dnl For backward compatibility. Some packages may be using this.
AC_DEFINE([HAVE_GETTEXT], [1],
[Define if the GNU gettext() function is already present or preinstalled.])
AC_DEFINE([HAVE_DCGETTEXT], [1],
[Define if the GNU dcgettext() function is already present or preinstalled.])
fi
dnl We need to process the po/ directory.
POSUB=po
fi
ifelse(gt_included_intl, yes, [
dnl In GNU gettext we have to set BUILD_INCLUDED_LIBINTL to 'yes'
dnl because some of the testsuite requires it.
BUILD_INCLUDED_LIBINTL=yes
dnl Make all variables we use known to autoconf.
AC_SUBST([BUILD_INCLUDED_LIBINTL])
AC_SUBST([USE_INCLUDED_LIBINTL])
AC_SUBST([CATOBJEXT])
])
dnl For backward compatibility. Some Makefiles may be using this.
INTLLIBS="$LIBINTL"
AC_SUBST([INTLLIBS])
dnl Make all documented variables known to autoconf.
AC_SUBST([LIBINTL])
AC_SUBST([LTLIBINTL])
AC_SUBST([POSUB])
])
dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
m4_define([gt_NEEDS_INIT],
[
m4_divert_text([DEFAULTS], [gt_needs=])
m4_define([gt_NEEDS_INIT], [])
])
dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
AC_DEFUN([AM_GNU_GETTEXT_NEED],
[
m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
])
dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
dnl Usage: AM_GNU_GETTEXT_REQUIRE_VERSION([gettext-version])
AC_DEFUN([AM_GNU_GETTEXT_REQUIRE_VERSION], [])
libcaes-20240413/m4/lib-ld.m4 0000644 0001750 0001750 00000012372 14533041421 016142 0 ustar 00lordyesta lordyesta # lib-ld.m4 serial 9
dnl Copyright (C) 1996-2003, 2009-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl Subroutines of libtool.m4,
dnl with replacements s/_*LT_PATH/AC_LIB_PROG/ and s/lt_/acl_/ to avoid
dnl collision with libtool.m4.
dnl From libtool-2.4. Sets the variable with_gnu_ld to yes or no.
AC_DEFUN([AC_LIB_PROG_LD_GNU],
[AC_CACHE_CHECK([if the linker ($LD) is GNU ld], [acl_cv_prog_gnu_ld],
[# I'd rather use --version here, but apparently some GNU lds only accept -v.
case `$LD -v 2>&1 /dev/null 2>&1 \
&& { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 \
|| PATH_SEPARATOR=';'
}
fi
if test -n "$LD"; then
AC_MSG_CHECKING([for ld])
elif test "$GCC" = yes; then
AC_MSG_CHECKING([for ld used by $CC])
elif test "$with_gnu_ld" = yes; then
AC_MSG_CHECKING([for GNU ld])
else
AC_MSG_CHECKING([for non-GNU ld])
fi
if test -n "$LD"; then
# Let the user override the test with a path.
:
else
AC_CACHE_VAL([acl_cv_path_LD],
[
acl_cv_path_LD= # Final result of this test
ac_prog=ld # Program to search in $PATH
if test "$GCC" = yes; then
# Check if gcc -print-prog-name=ld gives a path.
case $host in
*-*-mingw*)
# gcc leaves a trailing carriage return which upsets mingw
acl_output=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
*)
acl_output=`($CC -print-prog-name=ld) 2>&5` ;;
esac
case $acl_output in
# Accept absolute paths.
[[\\/]]* | ?:[[\\/]]*)
re_direlt='/[[^/]][[^/]]*/\.\./'
# Canonicalize the pathname of ld
acl_output=`echo "$acl_output" | sed 's%\\\\%/%g'`
while echo "$acl_output" | grep "$re_direlt" > /dev/null 2>&1; do
acl_output=`echo $acl_output | sed "s%$re_direlt%/%"`
done
# Got the pathname. No search in PATH is needed.
acl_cv_path_LD="$acl_output"
ac_prog=
;;
"")
# If it fails, then pretend we aren't using GCC.
;;
*)
# If it is relative, then search for the first ld in PATH.
with_gnu_ld=unknown
;;
esac
fi
if test -n "$ac_prog"; then
# Search for $ac_prog in $PATH.
acl_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
for ac_dir in $PATH; do
IFS="$acl_save_ifs"
test -z "$ac_dir" && ac_dir=.
if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
acl_cv_path_LD="$ac_dir/$ac_prog"
# Check to see if the program is GNU ld. I'd rather use --version,
# but apparently some variants of GNU ld only accept -v.
# Break only if it was the GNU/non-GNU ld that we prefer.
case `"$acl_cv_path_LD" -v 2>&1